1#include "dri_query_renderer.h"
2
3#include "util/u_inlines.h"
4#include "frontend/drm_driver.h"
5
6#include "utils.h"
7#include "dri_screen.h"
8#include "dri_query_renderer.h"
9#include "pipe-loader/pipe_loader.h"
10
11static int
12dri2_query_renderer_integer(__DRIscreen *_screen, int param,
13                            unsigned int *value)
14{
15   struct dri_screen *screen = dri_screen(_screen);
16
17   switch (param) {
18   case __DRI2_RENDERER_VENDOR_ID:
19      value[0] =
20         (unsigned int)screen->base.screen->get_param(screen->base.screen,
21                                                      PIPE_CAP_VENDOR_ID);
22      return 0;
23   case __DRI2_RENDERER_DEVICE_ID:
24      value[0] =
25         (unsigned int)screen->base.screen->get_param(screen->base.screen,
26                                                      PIPE_CAP_DEVICE_ID);
27      return 0;
28   case __DRI2_RENDERER_ACCELERATED:
29      value[0] =
30         (unsigned int)screen->base.screen->get_param(screen->base.screen,
31                                                      PIPE_CAP_ACCELERATED);
32      return 0;
33
34   case __DRI2_RENDERER_VIDEO_MEMORY: {
35      int ov = driQueryOptioni(&screen->dev->option_cache, "override_vram_size");
36      value[0] =
37         (unsigned int)screen->base.screen->get_param(screen->base.screen,
38                                                      PIPE_CAP_VIDEO_MEMORY);
39      if (ov >= 0)
40         value[0] = MIN2(ov, value[0]);
41      return 0;
42   }
43
44   case __DRI2_RENDERER_UNIFIED_MEMORY_ARCHITECTURE:
45      value[0] =
46         (unsigned int)screen->base.screen->get_param(screen->base.screen,
47                                                      PIPE_CAP_UMA);
48      return 0;
49
50   case __DRI2_RENDERER_HAS_TEXTURE_3D:
51      value[0] =
52         screen->base.screen->get_param(screen->base.screen,
53                                        PIPE_CAP_MAX_TEXTURE_3D_LEVELS) != 0;
54      return 0;
55
56   case __DRI2_RENDERER_HAS_FRAMEBUFFER_SRGB:
57      value[0] =
58         screen->base.screen->is_format_supported(screen->base.screen,
59                                                  PIPE_FORMAT_B8G8R8A8_SRGB,
60                                                  PIPE_TEXTURE_2D, 0, 0,
61                                                  PIPE_BIND_RENDER_TARGET);
62      return 0;
63   case __DRI2_RENDERER_HAS_CONTEXT_PRIORITY:
64      value[0] =
65         screen->base.screen->get_param(screen->base.screen,
66                                        PIPE_CAP_CONTEXT_PRIORITY_MASK);
67      if (!value[0])
68         return -1;
69      return 0;
70   case __DRI2_RENDERER_HAS_PROTECTED_CONTENT:
71      value[0] =
72         screen->base.screen->get_param(screen->base.screen,
73                                        PIPE_CAP_DEVICE_PROTECTED_CONTENT);
74      if (!value[0])
75         return -1;
76      return 0;
77   case __DRI2_RENDERER_PREFER_BACK_BUFFER_REUSE:
78      value[0] =
79         screen->base.screen->get_param(screen->base.screen,
80                                        PIPE_CAP_PREFER_BACK_BUFFER_REUSE);
81      return 0;
82   default:
83      return driQueryRendererIntegerCommon(_screen, param, value);
84   }
85}
86
87static int
88dri2_query_renderer_string(__DRIscreen *_screen, int param,
89                           const char **value)
90{
91   struct dri_screen *screen = dri_screen(_screen);
92
93   switch (param) {
94   case __DRI2_RENDERER_VENDOR_ID:
95      value[0] = screen->base.screen->get_vendor(screen->base.screen);
96      return 0;
97   case __DRI2_RENDERER_DEVICE_ID:
98      value[0] = screen->base.screen->get_name(screen->base.screen);
99      return 0;
100   default:
101      return -1;
102   }
103}
104
105const __DRI2rendererQueryExtension dri2RendererQueryExtension = {
106    .base = { __DRI2_RENDERER_QUERY, 1 },
107
108    .queryInteger         = dri2_query_renderer_integer,
109    .queryString          = dri2_query_renderer_string
110};
111