diff options
author | Jonathan Gray <jsg@cvs.openbsd.org> | 2015-02-22 09:30:35 +0000 |
---|---|---|
committer | Jonathan Gray <jsg@cvs.openbsd.org> | 2015-02-22 09:30:35 +0000 |
commit | 75620c712f0c4aa5f59ebcf3a88f798af6af6f57 (patch) | |
tree | 6c7d9e250bf1b35ef23809673021b277ea731071 | |
parent | faa4cb8a1ef3c84f1956c6c777f9e5e4addbe0e7 (diff) |
Backport support for GLX_MESA_query_renderer for non Intel drivers.
This is desirable as the chromium port now uses this extension to
obtain pci vendor/device ids for use in feature/extension blacklists.
Prompted by a mail from byrnet@, tested on r600g by krw@
The newly added os_get_total_physical_memory() was passing the length of
a pointer rather than the type which made the sysctl call fail on
non 64 bit archs. And it was passing the wrong pointer for the result.
Fixes for these problems have been submitted back upstream.
28 files changed, 640 insertions, 110 deletions
diff --git a/dist/Mesa/src/gallium/auxiliary/os/os_misc.c b/dist/Mesa/src/gallium/auxiliary/os/os_misc.c index 447e7208f..ec57d6d86 100644 --- a/dist/Mesa/src/gallium/auxiliary/os/os_misc.c +++ b/dist/Mesa/src/gallium/auxiliary/os/os_misc.c @@ -47,6 +47,19 @@ #endif +#if defined(PIPE_OS_LINUX) +# include <unistd.h> +#elif defined(PIPE_OS_APPLE) || defined(PIPE_OS_BSD) +# include <sys/sysctl.h> +#elif defined(PIPE_OS_HAIKU) +# include <kernel/OS.h> +#elif defined(PIPE_OS_WINDOWS) +# include <windows.h> +#else +#error unexpected platform in os_sysinfo.c +#endif + + void os_log_message(const char *message) { @@ -89,3 +102,54 @@ os_get_option(const char *name) return getenv(name); } + +/** + * Return the size of the total physical memory. + * \param size returns the size of the total physical memory + * \return true for success, or false on failure + */ +bool +os_get_total_physical_memory(uint64_t *size) +{ +#if defined(PIPE_OS_LINUX) + const long phys_pages = sysconf(_SC_PHYS_PAGES); + const long page_size = sysconf(_SC_PAGE_SIZE); + + *size = phys_pages * page_size; + return (phys_pages > 0 && page_size > 0); +#elif defined(PIPE_OS_APPLE) || defined(PIPE_OS_BSD) + size_t len = sizeof(*size); + int mib[2]; + + mib[0] = CTL_HW; +#if defined(PIPE_OS_APPLE) + mib[1] = HW_MEMSIZE; +#elif defined(PIPE_OS_NETBSD) || defined(PIPE_OS_OPENBSD) + mib[1] = HW_PHYSMEM64; +#elif defined(PIPE_OS_FREEBSD) + mib[1] = HW_REALMEM; +#else +#error Unsupported *BSD +#endif + + return (sysctl(mib, 2, size, &len, NULL, 0) == 0); +#elif defined(PIPE_OS_HAIKU) + system_info info; + status_t ret; + + ret = get_system_info(&info); + *size = info.max_pages * B_PAGE_SIZE; + return (ret == B_OK); +#elif defined(PIPE_OS_WINDOWS) + MEMORYSTATUSEX status; + BOOL ret; + + status.dwLength = sizeof(status); + ret = GlobalMemoryStatusEx(&status); + *size = status.ullTotalPhys; + return (ret == TRUE); +#else +#error unexpected platform in os_sysinfo.c + return false; +#endif +} diff --git a/dist/Mesa/src/gallium/auxiliary/os/os_misc.h b/dist/Mesa/src/gallium/auxiliary/os/os_misc.h index 582931fe9..403c8ee6e 100644 --- a/dist/Mesa/src/gallium/auxiliary/os/os_misc.h +++ b/dist/Mesa/src/gallium/auxiliary/os/os_misc.h @@ -87,6 +87,13 @@ const char * os_get_option(const char *name); +/* + * Get the total amount of physical memory available on the system. + */ +bool +os_get_total_physical_memory(uint64_t *size); + + #ifdef __cplusplus } #endif diff --git a/dist/Mesa/src/gallium/docs/source/screen.rst b/dist/Mesa/src/gallium/docs/source/screen.rst index e22435cd4..2532638ab 100644 --- a/dist/Mesa/src/gallium/docs/source/screen.rst +++ b/dist/Mesa/src/gallium/docs/source/screen.rst @@ -200,6 +200,14 @@ The integer capabilities: * ``PIPE_CAP_SAMPLE_SHADING``: Whether there is support for per-sample shading. The context->set_min_samples function will be expected to be implemented. +* ``PIPE_CAP_VENDOR_ID``: The vendor ID of the underlying hardware. If it's + not available one should return 0xFFFFFFFF. +* ``PIPE_CAP_DEVICE_ID``: The device ID (PCI ID) of the underlying hardware. + 0xFFFFFFFF if not available. +* ``PIPE_CAP_ACCELERATED``: Whether the renderer is hardware accelerated. +* ``PIPE_CAP_VIDEO_MEMORY``: The amount of video memory in megabytes. +* ``PIPE_CAP_UMA``: If the device has a unified memory architecture or on-card + memory and GART. .. _pipe_capf: diff --git a/dist/Mesa/src/gallium/drivers/llvmpipe/lp_screen.c b/dist/Mesa/src/gallium/drivers/llvmpipe/lp_screen.c index 98dbab784..bd90d82a9 100644 --- a/dist/Mesa/src/gallium/drivers/llvmpipe/lp_screen.c +++ b/dist/Mesa/src/gallium/drivers/llvmpipe/lp_screen.c @@ -37,6 +37,7 @@ #include "draw/draw_context.h" #include "gallivm/lp_bld_type.h" +#include "os/os_misc.h" #include "os/os_time.h" #include "lp_texture.h" #include "lp_fence.h" @@ -245,6 +246,24 @@ llvmpipe_get_param(struct pipe_screen *screen, enum pipe_cap param) return 0; case PIPE_CAP_FAKE_SW_MSAA: return 1; + + case PIPE_CAP_VENDOR_ID: + return 0xFFFFFFFF; + case PIPE_CAP_DEVICE_ID: + return 0xFFFFFFFF; + case PIPE_CAP_ACCELERATED: + return 0; + case PIPE_CAP_VIDEO_MEMORY: { + /* XXX: Do we want to return the full amount fo system memory ? */ + uint64_t system_memory; + + if (!os_get_total_physical_memory(&system_memory)) + return 0; + + return (int)(system_memory >> 20); + } + case PIPE_CAP_UMA: + return 0; } /* should only get here on unhandled cases */ debug_printf("Unexpected PIPE_CAP %d query\n", param); diff --git a/dist/Mesa/src/gallium/drivers/r300/r300_screen.c b/dist/Mesa/src/gallium/drivers/r300/r300_screen.c index d57051422..d0b0222fd 100644 --- a/dist/Mesa/src/gallium/drivers/r300/r300_screen.c +++ b/dist/Mesa/src/gallium/drivers/r300/r300_screen.c @@ -204,6 +204,17 @@ static int r300_get_param(struct pipe_screen* pscreen, enum pipe_cap param) case PIPE_CAP_MAX_VIEWPORTS: return 1; + + case PIPE_CAP_VENDOR_ID: + return 0x1002; + case PIPE_CAP_DEVICE_ID: + return r300screen->info.pci_id; + case PIPE_CAP_ACCELERATED: + return 1; + case PIPE_CAP_VIDEO_MEMORY: + return r300screen->info.vram_size >> 20; + case PIPE_CAP_UMA: + return 0; } return 0; } diff --git a/dist/Mesa/src/gallium/drivers/r600/r600_pipe.c b/dist/Mesa/src/gallium/drivers/r600/r600_pipe.c index 0668b27f4..4f471b861 100644 --- a/dist/Mesa/src/gallium/drivers/r600/r600_pipe.c +++ b/dist/Mesa/src/gallium/drivers/r600/r600_pipe.c @@ -373,6 +373,17 @@ static int r600_get_param(struct pipe_screen* pscreen, enum pipe_cap param) return PIPE_QUIRK_TEXTURE_BORDER_COLOR_SWIZZLE_R600; case PIPE_CAP_ENDIANNESS: return PIPE_ENDIAN_LITTLE; + + case PIPE_CAP_VENDOR_ID: + return 0x1002; + case PIPE_CAP_DEVICE_ID: + return rscreen->b.info.pci_id; + case PIPE_CAP_ACCELERATED: + return 1; + case PIPE_CAP_VIDEO_MEMORY: + return rscreen->b.info.vram_size >> 20; + case PIPE_CAP_UMA: + return 0; } return 0; } diff --git a/dist/Mesa/src/gallium/drivers/radeonsi/si_pipe.c b/dist/Mesa/src/gallium/drivers/radeonsi/si_pipe.c index 8c12bf7cf..52cf43745 100644 --- a/dist/Mesa/src/gallium/drivers/radeonsi/si_pipe.c +++ b/dist/Mesa/src/gallium/drivers/radeonsi/si_pipe.c @@ -23,6 +23,7 @@ #include "si_pipe.h" #include "si_public.h" +#include "sid.h" #include "radeon/radeon_uvd.h" #include "util/u_blitter.h" @@ -39,6 +40,8 @@ static void si_destroy_context(struct pipe_context *context) si_release_all_descriptors(sctx); + pipe_resource_reference(&sctx->esgs_ring.buffer, NULL); + pipe_resource_reference(&sctx->gsvs_ring.buffer, NULL); pipe_resource_reference(&sctx->null_const_buf.buffer, NULL); r600_resource_reference(&sctx->border_color_table, NULL); @@ -105,10 +108,10 @@ static struct pipe_context *si_create_context(struct pipe_screen *screen, void * /* Initialize cache_flush. */ sctx->cache_flush = si_atom_cache_flush; - sctx->atoms.cache_flush = &sctx->cache_flush; + sctx->atoms.s.cache_flush = &sctx->cache_flush; - sctx->atoms.streamout_begin = &sctx->b.streamout.begin_atom; - sctx->atoms.streamout_enable = &sctx->b.streamout.enable_atom; + sctx->atoms.s.streamout_begin = &sctx->b.streamout.begin_atom; + sctx->atoms.s.streamout_enable = &sctx->b.streamout.enable_atom; switch (sctx->b.chip_class) { case SI: @@ -296,6 +299,17 @@ static int si_get_param(struct pipe_screen* pscreen, enum pipe_cap param) return 7; case PIPE_CAP_ENDIANNESS: return PIPE_ENDIAN_LITTLE; + + case PIPE_CAP_VENDOR_ID: + return 0x1002; + case PIPE_CAP_DEVICE_ID: + return sscreen->b.info.pci_id; + case PIPE_CAP_ACCELERATED: + return 1; + case PIPE_CAP_VIDEO_MEMORY: + return sscreen->b.info.vram_size >> 20; + case PIPE_CAP_UMA: + return 0; } return 0; } @@ -384,6 +398,57 @@ static void si_destroy_screen(struct pipe_screen* pscreen) r600_destroy_common_screen(&sscreen->b); } +#define SI_TILE_MODE_COLOR_2D_8BPP 14 + +/* Initialize pipe config. This is especially important for GPUs + * with 16 pipes and more where it's initialized incorrectly by + * the TILING_CONFIG ioctl. */ +static bool si_initialize_pipe_config(struct si_screen *sscreen) +{ + unsigned mode2d; + + /* This is okay, because there can be no 2D tiling without + * the tile mode array, so we won't need the pipe config. + * Return "success". + */ + if (!sscreen->b.info.si_tile_mode_array_valid) + return true; + + /* The same index is used for the 2D mode on CIK too. */ + mode2d = sscreen->b.info.si_tile_mode_array[SI_TILE_MODE_COLOR_2D_8BPP]; + + switch (G_009910_PIPE_CONFIG(mode2d)) { + case V_02803C_ADDR_SURF_P2: + sscreen->b.tiling_info.num_channels = 2; + break; + case V_02803C_X_ADDR_SURF_P4_8X16: + case V_02803C_X_ADDR_SURF_P4_16X16: + case V_02803C_X_ADDR_SURF_P4_16X32: + case V_02803C_X_ADDR_SURF_P4_32X32: + sscreen->b.tiling_info.num_channels = 4; + break; + case V_02803C_X_ADDR_SURF_P8_16X16_8X16: + case V_02803C_X_ADDR_SURF_P8_16X32_8X16: + case V_02803C_X_ADDR_SURF_P8_32X32_8X16: + case V_02803C_X_ADDR_SURF_P8_16X32_16X16: + case V_02803C_X_ADDR_SURF_P8_32X32_16X16: + case V_02803C_X_ADDR_SURF_P8_32X32_16X32: + case V_02803C_X_ADDR_SURF_P8_32X64_32X32: + sscreen->b.tiling_info.num_channels = 8; + break; + case V_02803C_X_ADDR_SURF_P16_32X32_8X16: + case V_02803C_X_ADDR_SURF_P16_32X32_16X16: + sscreen->b.tiling_info.num_channels = 16; + break; + default: + assert(0); + fprintf(stderr, "radeonsi: Unknown pipe config %i.\n", + G_009910_PIPE_CONFIG(mode2d)); + return false; + } + return true; +} + struct pipe_screen *radeonsi_screen_create(struct radeon_winsys *ws) { struct si_screen *sscreen = CALLOC_STRUCT(si_screen); @@ -399,7 +464,8 @@ struct pipe_screen *radeonsi_screen_create(struct radeon_winsys *ws) sscreen->b.b.is_format_supported = si_is_format_supported; sscreen->b.b.resource_create = r600_resource_create_common; - if (!r600_common_screen_init(&sscreen->b, ws)) { + if (!r600_common_screen_init(&sscreen->b, ws) || + !si_initialize_pipe_config(sscreen)) { FREE(sscreen); return NULL; } diff --git a/dist/Mesa/src/gallium/drivers/softpipe/sp_screen.c b/dist/Mesa/src/gallium/drivers/softpipe/sp_screen.c index e7c331967..324cfa433 100644 --- a/dist/Mesa/src/gallium/drivers/softpipe/sp_screen.c +++ b/dist/Mesa/src/gallium/drivers/softpipe/sp_screen.c @@ -30,6 +30,7 @@ #include "util/u_format.h" #include "util/u_format_s3tc.h" #include "util/u_video.h" +#include "os/os_misc.h" #include "os/os_time.h" #include "pipe/p_defines.h" #include "pipe/p_screen.h" @@ -196,6 +197,24 @@ softpipe_get_param(struct pipe_screen *screen, enum pipe_cap param) case PIPE_CAP_MIN_TEXTURE_GATHER_OFFSET: case PIPE_CAP_MAX_TEXTURE_GATHER_OFFSET: return 0; + + case PIPE_CAP_VENDOR_ID: + return 0xFFFFFFFF; + case PIPE_CAP_DEVICE_ID: + return 0xFFFFFFFF; + case PIPE_CAP_ACCELERATED: + return 0; + case PIPE_CAP_VIDEO_MEMORY: { + /* XXX: Do we want to return the full amount fo system memory ? */ + uint64_t system_memory; + + if (!os_get_total_physical_memory(&system_memory)) + return 0; + + return (int)(system_memory >> 20); + } + case PIPE_CAP_UMA: + return 0; } /* should only get here on unhandled cases */ debug_printf("Unexpected PIPE_CAP %d query\n", param); diff --git a/dist/Mesa/src/gallium/include/pipe/p_defines.h b/dist/Mesa/src/gallium/include/pipe/p_defines.h index 9436e7e42..dc31ce0b0 100644 --- a/dist/Mesa/src/gallium/include/pipe/p_defines.h +++ b/dist/Mesa/src/gallium/include/pipe/p_defines.h @@ -557,6 +557,11 @@ enum pipe_cap { PIPE_CAP_MIN_TEXTURE_GATHER_OFFSET = 95, PIPE_CAP_MAX_TEXTURE_GATHER_OFFSET = 96, PIPE_CAP_SAMPLE_SHADING = 97, + PIPE_CAP_VENDOR_ID = 103, + PIPE_CAP_DEVICE_ID = 104, + PIPE_CAP_ACCELERATED = 105, + PIPE_CAP_VIDEO_MEMORY = 106, + PIPE_CAP_UMA = 107, }; #define PIPE_QUIRK_TEXTURE_BORDER_COLOR_SWIZZLE_NV50 (1 << 0) diff --git a/dist/Mesa/src/gallium/state_trackers/dri/dri_query_renderer.c b/dist/Mesa/src/gallium/state_trackers/dri/dri_query_renderer.c new file mode 100644 index 000000000..4a28ac37b --- /dev/null +++ b/dist/Mesa/src/gallium/state_trackers/dri/dri_query_renderer.c @@ -0,0 +1,73 @@ +#include "dri_query_renderer.h" + +#include "util/u_inlines.h" +#include "state_tracker/drm_driver.h" + +#include "utils.h" +#include "dri_screen.h" +#include "dri_query_renderer.h" + +static int +dri2_query_renderer_integer(__DRIscreen *_screen, int param, + unsigned int *value) +{ + struct dri_screen *screen = dri_screen(_screen); + + switch (param) { + case __DRI2_RENDERER_VENDOR_ID: + value[0] = + (unsigned int)screen->base.screen->get_param(screen->base.screen, + PIPE_CAP_VENDOR_ID); + return 0; + case __DRI2_RENDERER_DEVICE_ID: + value[0] = + (unsigned int)screen->base.screen->get_param(screen->base.screen, + PIPE_CAP_DEVICE_ID); + return 0; + case __DRI2_RENDERER_ACCELERATED: + value[0] = + (unsigned int)screen->base.screen->get_param(screen->base.screen, + PIPE_CAP_ACCELERATED); + return 0; + + case __DRI2_RENDERER_VIDEO_MEMORY: + value[0] = + (unsigned int)screen->base.screen->get_param(screen->base.screen, + PIPE_CAP_VIDEO_MEMORY); + return 0; + + case __DRI2_RENDERER_UNIFIED_MEMORY_ARCHITECTURE: + value[0] = + (unsigned int)screen->base.screen->get_param(screen->base.screen, + PIPE_CAP_UMA); + return 0; + + default: + return driQueryRendererIntegerCommon(_screen, param, value); + } +} + +static int +dri2_query_renderer_string(__DRIscreen *_screen, int param, + const char **value) +{ + struct dri_screen *screen = dri_screen(_screen); + + switch (param) { + case __DRI2_RENDERER_VENDOR_ID: + value[0] = screen->base.screen->get_vendor(screen->base.screen); + return 0; + case __DRI2_RENDERER_DEVICE_ID: + value[0] = screen->base.screen->get_name(screen->base.screen); + return 0; + default: + return -1; + } +} + +const __DRI2rendererQueryExtension dri2RendererQueryExtension = { + .base = { __DRI2_RENDERER_QUERY, 1 }, + + .queryInteger = dri2_query_renderer_integer, + .queryString = dri2_query_renderer_string +}; diff --git a/dist/Mesa/src/gallium/state_trackers/dri/dri_query_renderer.h b/dist/Mesa/src/gallium/state_trackers/dri/dri_query_renderer.h new file mode 100644 index 000000000..59b3ff8e5 --- /dev/null +++ b/dist/Mesa/src/gallium/state_trackers/dri/dri_query_renderer.h @@ -0,0 +1,9 @@ +#ifndef DRI_QUERY_RENDERER_H +#define DRI_QUERY_RENDERER_H + +#include "dri_util.h" + +extern const +__DRI2rendererQueryExtension dri2RendererQueryExtension; + +#endif diff --git a/dist/Mesa/src/gallium/state_trackers/dri/drm/dri2.c b/dist/Mesa/src/gallium/state_trackers/dri/drm/dri2.c index 7dccc5e0e..d02736a06 100644 --- a/dist/Mesa/src/gallium/state_trackers/dri/drm/dri2.c +++ b/dist/Mesa/src/gallium/state_trackers/dri/drm/dri2.c @@ -41,6 +41,7 @@ #include "dri_screen.h" #include "dri_context.h" #include "dri_drawable.h" +#include "dri_query_renderer.h" #include "dri2_buffer.h" static int convert_fourcc(int format, int *dri_components_p) @@ -1060,6 +1061,7 @@ static const __DRIextension *dri_screen_extensions[] = { &driTexBufferExtension.base, &dri2FlushExtension.base, &dri2ImageExtension.base, + &dri2RendererQueryExtension.base, &dri2ConfigQueryExtension.base, &dri2ThrottleExtension.base, NULL diff --git a/dist/Mesa/src/gallium/state_trackers/dri/sw/drisw.c b/dist/Mesa/src/gallium/state_trackers/dri/sw/drisw.c index 6f50b05c2..4754cafd1 100644 --- a/dist/Mesa/src/gallium/state_trackers/dri/sw/drisw.c +++ b/dist/Mesa/src/gallium/state_trackers/dri/sw/drisw.c @@ -45,6 +45,7 @@ #include "dri_screen.h" #include "dri_context.h" #include "dri_drawable.h" +#include "dri_query_renderer.h" DEBUG_GET_ONCE_BOOL_OPTION(swrast_no_present, "SWRAST_NO_PRESENT", FALSE); static boolean swrast_no_present = FALSE; @@ -331,6 +332,7 @@ drisw_update_tex_buffer(struct dri_drawable *drawable, static const __DRIextension *drisw_screen_extensions[] = { &driTexBufferExtension.base, + &dri2RendererQueryExtension.base, NULL }; diff --git a/dist/Mesa/src/glx/dri2_query_renderer.c b/dist/Mesa/src/glx/dri2_query_renderer.c index c1e877239..247ec1ca6 100644 --- a/dist/Mesa/src/glx/dri2_query_renderer.c +++ b/dist/Mesa/src/glx/dri2_query_renderer.c @@ -31,36 +31,39 @@ #if defined(HAVE_DRI3) #include "dri3_priv.h" #endif +#include "drisw_priv.h" + +#define __RENDERER(attrib) \ + { GLX_RENDERER_##attrib##_MESA, __DRI2_RENDERER_##attrib } + +static const struct { + unsigned int glx_attrib, dri2_attrib; +} query_renderer_map[] = { + __RENDERER(VENDOR_ID), + __RENDERER(DEVICE_ID), + __RENDERER(VERSION), + __RENDERER(ACCELERATED), + __RENDERER(VIDEO_MEMORY), + __RENDERER(UNIFIED_MEMORY_ARCHITECTURE), + __RENDERER(PREFERRED_PROFILE), + __RENDERER(OPENGL_CORE_PROFILE_VERSION), + __RENDERER(OPENGL_COMPATIBILITY_PROFILE_VERSION), + __RENDERER(OPENGL_ES_PROFILE_VERSION), + __RENDERER(OPENGL_ES2_PROFILE_VERSION), +}; + +#undef __RENDERER static int dri2_convert_glx_query_renderer_attribs(int attribute) { - switch (attribute) { - case GLX_RENDERER_VENDOR_ID_MESA: - return __DRI2_RENDERER_VENDOR_ID; - case GLX_RENDERER_DEVICE_ID_MESA: - return __DRI2_RENDERER_DEVICE_ID; - case GLX_RENDERER_VERSION_MESA: - return __DRI2_RENDERER_VERSION; - case GLX_RENDERER_ACCELERATED_MESA: - return __DRI2_RENDERER_ACCELERATED; - case GLX_RENDERER_VIDEO_MEMORY_MESA: - return __DRI2_RENDERER_VIDEO_MEMORY; - case GLX_RENDERER_UNIFIED_MEMORY_ARCHITECTURE_MESA: - return __DRI2_RENDERER_UNIFIED_MEMORY_ARCHITECTURE; - case GLX_RENDERER_PREFERRED_PROFILE_MESA: - return __DRI2_RENDERER_PREFERRED_PROFILE; - case GLX_RENDERER_OPENGL_CORE_PROFILE_VERSION_MESA: - return __DRI2_RENDERER_OPENGL_CORE_PROFILE_VERSION; - case GLX_RENDERER_OPENGL_COMPATIBILITY_PROFILE_VERSION_MESA: - return __DRI2_RENDERER_OPENGL_COMPATIBILITY_PROFILE_VERSION; - case GLX_RENDERER_OPENGL_ES_PROFILE_VERSION_MESA: - return __DRI2_RENDERER_OPENGL_ES_PROFILE_VERSION; - case GLX_RENDERER_OPENGL_ES2_PROFILE_VERSION_MESA: - return __DRI2_RENDERER_OPENGL_ES2_PROFILE_VERSION; - default: - return -1; - } + int i; + + for (i = 0; i < ARRAY_SIZE(query_renderer_map); i++) + if (query_renderer_map[i].glx_attrib == attribute) + return query_renderer_map[i].dri2_attrib; + + return -1; } _X_HIDDEN int @@ -141,4 +144,43 @@ dri3_query_renderer_string(struct glx_screen *base, int attribute, } #endif /* HAVE_DRI3 */ +_X_HIDDEN int +drisw_query_renderer_integer(struct glx_screen *base, int attribute, + unsigned int *value) +{ + struct drisw_screen *const psc = (struct drisw_screen *) base; + + /* Even though there are invalid values (and + * dri2_convert_glx_query_renderer_attribs may return -1), the higher level + * GLX code is required to perform the filtering. Assume that we got a + * good value. + */ + const int dri_attribute = dri2_convert_glx_query_renderer_attribs(attribute); + + if (psc->rendererQuery == NULL) + return -1; + + return psc->rendererQuery->queryInteger(psc->driScreen, dri_attribute, + value); +} + +_X_HIDDEN int +drisw_query_renderer_string(struct glx_screen *base, int attribute, + const char **value) +{ + struct drisw_screen *const psc = (struct drisw_screen *) base; + + /* Even though queryString only accepts a subset of the possible GLX + * queries, the higher level GLX code is required to perform the filtering. + * Assume that we got a good value. + */ + const int dri_attribute = dri2_convert_glx_query_renderer_attribs(attribute); + + if (psc->rendererQuery == NULL) + return -1; + + return psc->rendererQuery->queryString(psc->driScreen, dri_attribute, value); +} + + #endif /* GLX_DIRECT_RENDERING */ diff --git a/dist/Mesa/src/glx/drisw_glx.c b/dist/Mesa/src/glx/drisw_glx.c index 5885b6635..b26542378 100644 --- a/dist/Mesa/src/glx/drisw_glx.c +++ b/dist/Mesa/src/glx/drisw_glx.c @@ -27,46 +27,7 @@ #include "glxclient.h" #include <dlfcn.h> #include "dri_common.h" - -struct drisw_display -{ - __GLXDRIdisplay base; -}; - -struct drisw_context -{ - struct glx_context base; - __DRIcontext *driContext; - -}; - -struct drisw_screen -{ - struct glx_screen base; - - __DRIscreen *driScreen; - __GLXDRIscreen vtable; - const __DRIcoreExtension *core; - const __DRIswrastExtension *swrast; - const __DRItexBufferExtension *texBuffer; - const __DRIcopySubBufferExtension *copySubBuffer; - - const __DRIconfig **driver_configs; - - void *driver; -}; - -struct drisw_drawable -{ - __GLXDRIdrawable base; - - GC gc; - GC swapgc; - - __DRIdrawable *driDrawable; - XVisualInfo *visinfo; - XImage *ximage; -}; +#include "drisw_priv.h" static Bool XCreateDrawable(struct drisw_drawable * pdp, @@ -638,8 +599,8 @@ driOpenSwrast(void) static const struct glx_screen_vtable drisw_screen_vtable = { .create_context = drisw_create_context, .create_context_attribs = drisw_create_context_attribs, - .query_renderer_integer = NULL, - .query_renderer_string = NULL, + .query_renderer_integer = drisw_query_renderer_integer, + .query_renderer_string = drisw_query_renderer_string, }; static void @@ -668,6 +629,14 @@ driswBindExtensions(struct drisw_screen *psc, const __DRIextension **extensions) psc->texBuffer = (__DRItexBufferExtension *) extensions[i]; __glXEnableDirectExtension(&psc->base, "GLX_EXT_texture_from_pixmap"); } + /* DRISW version 3 is also required because GLX_MESA_query_renderer + * requires GLX_ARB_create_context_profile. + */ + if (psc->swrast->base.version >= 3 + && strcmp(extensions[i]->name, __DRI2_RENDERER_QUERY) == 0) { + psc->rendererQuery = (__DRI2rendererQueryExtension *) extensions[i]; + __glXEnableDirectExtension(&psc->base, "GLX_MESA_query_renderer"); + } } } diff --git a/dist/Mesa/src/glx/drisw_priv.h b/dist/Mesa/src/glx/drisw_priv.h new file mode 100644 index 000000000..5d4790031 --- /dev/null +++ b/dist/Mesa/src/glx/drisw_priv.h @@ -0,0 +1,72 @@ +/* This file was derived from drisw_glx.c which carries the following + * copyright: + * + * Copyright 2008 George Sapountzis + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +struct drisw_display +{ + __GLXDRIdisplay base; +}; + +struct drisw_context +{ + struct glx_context base; + __DRIcontext *driContext; + +}; + +struct drisw_screen +{ + struct glx_screen base; + + __DRIscreen *driScreen; + __GLXDRIscreen vtable; + const __DRIcoreExtension *core; + const __DRIswrastExtension *swrast; + const __DRItexBufferExtension *texBuffer; + const __DRIcopySubBufferExtension *copySubBuffer; + const __DRI2rendererQueryExtension *rendererQuery; + + const __DRIconfig **driver_configs; + + void *driver; +}; + +struct drisw_drawable +{ + __GLXDRIdrawable base; + + GC gc; + GC swapgc; + + __DRIdrawable *driDrawable; + XVisualInfo *visinfo; + XImage *ximage; +}; + +_X_HIDDEN int +drisw_query_renderer_integer(struct glx_screen *base, int attribute, + unsigned int *value); +_X_HIDDEN int +drisw_query_renderer_string(struct glx_screen *base, int attribute, + const char **value); diff --git a/dist/Mesa/src/mesa/drivers/dri/common/utils.c b/dist/Mesa/src/mesa/drivers/dri/common/utils.c index eee77ec69..e0b3db8cf 100644 --- a/dist/Mesa/src/mesa/drivers/dri/common/utils.c +++ b/dist/Mesa/src/mesa/drivers/dri/common/utils.c @@ -519,6 +519,10 @@ driQueryRendererIntegerCommon(__DRIscreen *psp, int param, unsigned int *value) value[2] = v[2]; return 0; } + case __DRI2_RENDERER_PREFERRED_PROFILE: + value[0] = (psp->max_gl_core_version != 0) + ? (1U << __DRI_API_OPENGL_CORE) : (1U << __DRI_API_OPENGL); + return 0; case __DRI2_RENDERER_OPENGL_CORE_PROFILE_VERSION: value[0] = psp->max_gl_core_version / 10; value[1] = psp->max_gl_core_version % 10; diff --git a/dist/Mesa/src/mesa/drivers/dri/i915/intel_screen.c b/dist/Mesa/src/mesa/drivers/dri/i915/intel_screen.c index 159fb884b..00d85805d 100644 --- a/dist/Mesa/src/mesa/drivers/dri/i915/intel_screen.c +++ b/dist/Mesa/src/mesa/drivers/dri/i915/intel_screen.c @@ -750,9 +750,6 @@ i915_query_renderer_integer(__DRIscreen *psp, int param, unsigned int *value) case __DRI2_RENDERER_UNIFIED_MEMORY_ARCHITECTURE: value[0] = 1; return 0; - case __DRI2_RENDERER_PREFERRED_PROFILE: - value[0] = (1U << __DRI_API_OPENGL); - return 0; default: return driQueryRendererIntegerCommon(psp, param, value); } diff --git a/dist/Mesa/src/mesa/drivers/dri/i965/intel_screen.c b/dist/Mesa/src/mesa/drivers/dri/i965/intel_screen.c index 8299d3d16..d7eb34618 100644 --- a/dist/Mesa/src/mesa/drivers/dri/i965/intel_screen.c +++ b/dist/Mesa/src/mesa/drivers/dri/i965/intel_screen.c @@ -845,10 +845,6 @@ brw_query_renderer_integer(__DRIscreen *psp, int param, unsigned int *value) case __DRI2_RENDERER_UNIFIED_MEMORY_ARCHITECTURE: value[0] = 1; return 0; - case __DRI2_RENDERER_PREFERRED_PROFILE: - value[0] = (psp->max_gl_core_version != 0) - ? (1U << __DRI_API_OPENGL_CORE) : (1U << __DRI_API_OPENGL); - return 0; default: return driQueryRendererIntegerCommon(psp, param, value); } diff --git a/dist/Mesa/src/mesa/drivers/dri/radeon/radeon_common_context.c b/dist/Mesa/src/mesa/drivers/dri/radeon/radeon_common_context.c index 54db9d549..06b606e8a 100644 --- a/dist/Mesa/src/mesa/drivers/dri/radeon/radeon_common_context.c +++ b/dist/Mesa/src/mesa/drivers/dri/radeon/radeon_common_context.c @@ -70,44 +70,47 @@ static const char* get_chip_family_name(int chip_family) } } +const char const *radeonVendorString = "Mesa Project"; -/* Return various strings for glGetString(). +/* Return complete renderer string. */ -static const GLubyte *radeonGetString(struct gl_context * ctx, GLenum name) +const char *radeonGetRendererString(radeonScreenPtr radeonScreen) { - radeonContextPtr radeon = RADEON_CONTEXT(ctx); static char buffer[128]; + char hardwarename[32]; - switch (name) { - case GL_VENDOR: - return (GLubyte *) "Mesa Project"; - - case GL_RENDERER: - { - unsigned offset; - GLuint agp_mode = (radeon->radeonScreen->card_type==RADEON_CARD_PCI) ? 0 : - radeon->radeonScreen->AGPMode; - char hardwarename[32]; + GLuint agp_mode = (radeonScreen->card_type==RADEON_CARD_PCI) ? 0 : + radeonScreen->AGPMode; - sprintf(hardwarename, "%s (%s %04X)", + snprintf(hardwarename, sizeof(hardwarename), "%s (%s %04X)", #if defined(RADEON_R100) - "R100", + "R100", #elif defined(RADEON_R200) - "R200", + "R200", #endif - get_chip_family_name(radeon->radeonScreen->chip_family), - radeon->radeonScreen->device_id); + get_chip_family_name(radeonScreen->chip_family), + radeonScreen->device_id); - offset = driGetRendererString(buffer, hardwarename, agp_mode); + driGetRendererString(buffer, hardwarename, agp_mode); - sprintf(&buffer[offset], " %sTCL", - !(radeon->TclFallback & RADEON_TCL_FALLBACK_TCL_DISABLE) - ? "" : "NO-"); + strcat(buffer, " DRI2"); - strcat(buffer, " DRI2"); + return buffer; +} - return (GLubyte *) buffer; - } + +/* Return various strings for glGetString(). + */ +static const GLubyte *radeonGetString(struct gl_context * ctx, GLenum name) +{ + radeonContextPtr radeon = RADEON_CONTEXT(ctx); + + switch (name) { + case GL_VENDOR: + return (GLubyte *) radeonVendorString; + + case GL_RENDERER: + return (GLubyte *) radeonGetRendererString(radeon->radeonScreen); default: return NULL; diff --git a/dist/Mesa/src/mesa/drivers/dri/radeon/radeon_common_context.h b/dist/Mesa/src/mesa/drivers/dri/radeon/radeon_common_context.h index ac3e7b529..2a95d61d6 100644 --- a/dist/Mesa/src/mesa/drivers/dri/radeon/radeon_common_context.h +++ b/dist/Mesa/src/mesa/drivers/dri/radeon/radeon_common_context.h @@ -515,6 +515,10 @@ static inline __DRIdrawable* radeon_get_readable(radeonContextPtr radeon) return radeon->dri.context->driReadablePriv; } +extern const char const *radeonVendorString; + +const char *radeonGetRendererString(radeonScreenPtr radeonScreen); + GLboolean radeonInitContext(radeonContextPtr radeon, gl_api api, struct dd_function_table* functions, diff --git a/dist/Mesa/src/mesa/drivers/dri/radeon/radeon_screen.c b/dist/Mesa/src/mesa/drivers/dri/radeon/radeon_screen.c index fe72b7752..9a6fbbdb0 100644 --- a/dist/Mesa/src/mesa/drivers/dri/radeon/radeon_screen.c +++ b/dist/Mesa/src/mesa/drivers/dri/radeon/radeon_screen.c @@ -481,6 +481,73 @@ static int radeon_set_screen_flags(radeonScreenPtr screen, int device_id) return 0; } +static int +radeonQueryRendererInteger(__DRIscreen *psp, int param, + unsigned int *value) +{ + radeonScreenPtr screen = (radeonScreenPtr)psp->driverPrivate; + + switch (param) { + case __DRI2_RENDERER_VENDOR_ID: + value[0] = 0x1002; + return 0; + case __DRI2_RENDERER_DEVICE_ID: + value[0] = screen->device_id; + return 0; + case __DRI2_RENDERER_ACCELERATED: + value[0] = 1; + return 0; + case __DRI2_RENDERER_VIDEO_MEMORY: { + struct drm_radeon_gem_info gem_info; + int retval; + memset(&gem_info, 0, sizeof(gem_info)); + + /* Get GEM info. */ + retval = drmCommandWriteRead(psp->fd, DRM_RADEON_GEM_INFO, &gem_info, + sizeof(gem_info)); + + if (retval) { + fprintf(stderr, "radeon: Failed to get MM info, error number %d\n", + retval); + return -1; + + } + /* XXX: Do we want to return vram_size or vram_visible ? */ + value[0] = gem_info.vram_size >> 20; + return 0; + } + case __DRI2_RENDERER_UNIFIED_MEMORY_ARCHITECTURE: + value[0] = 0; + return 0; + default: + return driQueryRendererIntegerCommon(psp, param, value); + } +} + +static int +radeonQueryRendererString(__DRIscreen *psp, int param, const char **value) +{ + radeonScreenPtr screen = (radeonScreenPtr)psp->driverPrivate; + + switch (param) { + case __DRI2_RENDERER_VENDOR_ID: + value[0] = radeonVendorString; + return 0; + case __DRI2_RENDERER_DEVICE_ID: + value[0] = radeonGetRendererString(screen); + return 0; + default: + return -1; + } +} + +static const __DRI2rendererQueryExtension radeonRendererQueryExtension = { + .base = { __DRI2_RENDERER_QUERY, 1 }, + + .queryInteger = radeonQueryRendererInteger, + .queryString = radeonQueryRendererString +}; + static const __DRIextension *radeon_screen_extensions[] = { &dri2ConfigQueryExtension.base, @@ -491,6 +558,7 @@ static const __DRIextension *radeon_screen_extensions[] = { #endif &radeonFlushExtension.base, &radeonImageExtension.base, + &radeonRendererQueryExtension.base, NULL }; diff --git a/dist/Mesa/src/mesa/drivers/dri/radeon/radeon_screen.h b/dist/Mesa/src/mesa/drivers/dri/radeon/radeon_screen.h index 76fa1ec05..9b77627b8 100644 --- a/dist/Mesa/src/mesa/drivers/dri/radeon/radeon_screen.h +++ b/dist/Mesa/src/mesa/drivers/dri/radeon/radeon_screen.h @@ -209,6 +209,8 @@ struct __DRIimageRec { #define untile_image r200_untile_image #define set_re_cntl_d3d r200_set_re_cntl_d3d #define radeonDestroyBuffer r200_radeonDestroyBuffer +#define radeonVendorString r200_radeonVendorString +#define radeonGetRendererString r200_radeonGetRendererString #endif extern void radeonDestroyBuffer(__DRIdrawable *driDrawPriv); diff --git a/dist/Mesa/src/mesa/drivers/dri/swrast/swrast.c b/dist/Mesa/src/mesa/drivers/dri/swrast/swrast.c index 888138115..e28991b0c 100644 --- a/dist/Mesa/src/mesa/drivers/dri/swrast/swrast.c +++ b/dist/Mesa/src/mesa/drivers/dri/swrast/swrast.c @@ -61,6 +61,9 @@ const __DRIextension **__driDriverGetExtensions_swrast(void); +const char const *swrast_vendor_string = "Mesa Project"; +const char const *swrast_renderer_string = "Software Rasterizer"; + /** * Screen and config-related functions */ @@ -117,8 +120,74 @@ static const __DRItexBufferExtension swrastTexBufferExtension = { .releaseTexBuffer = NULL, }; + +static int +swrast_query_renderer_integer(__DRIscreen *psp, int param, + unsigned int *value) +{ + switch (param) { + case __DRI2_RENDERER_VENDOR_ID: + case __DRI2_RENDERER_DEVICE_ID: + /* Return 0xffffffff for both vendor and device id */ + value[0] = 0xffffffff; + return 0; + case __DRI2_RENDERER_ACCELERATED: + value[0] = 0; + return 0; + case __DRI2_RENDERER_VIDEO_MEMORY: { + /* XXX: Do we want to return the full amount of system memory ? */ + const long system_memory_pages = sysconf(_SC_PHYS_PAGES); + const long system_page_size = sysconf(_SC_PAGE_SIZE); + + if (system_memory_pages <= 0 || system_page_size <= 0) + return -1; + + const uint64_t system_memory_bytes = (uint64_t) system_memory_pages + * (uint64_t) system_page_size; + + const unsigned system_memory_megabytes = + (unsigned) (system_memory_bytes / (1024 * 1024)); + + value[0] = system_memory_megabytes; + return 0; + } + case __DRI2_RENDERER_UNIFIED_MEMORY_ARCHITECTURE: + /** + * XXX: Perhaps we should return 1 ? + * See issue #7 from the spec, currently UNRESOLVED. + */ + value[0] = 0; + return 0; + default: + return driQueryRendererIntegerCommon(psp, param, value); + } +} + +static int +swrast_query_renderer_string(__DRIscreen *psp, int param, const char **value) +{ + switch (param) { + case __DRI2_RENDERER_VENDOR_ID: + value[0] = swrast_vendor_string; + return 0; + case __DRI2_RENDERER_DEVICE_ID: + value[0] = swrast_renderer_string; + return 0; + default: + return -1; + } +} + +static const __DRI2rendererQueryExtension swrast_query_renderer_extension = { + .base = { __DRI2_RENDERER_QUERY, 1 }, + + .queryInteger = swrast_query_renderer_integer, + .queryString = swrast_query_renderer_string +}; + static const __DRIextension *dri_screen_extensions[] = { &swrastTexBufferExtension.base, + &swrast_query_renderer_extension.base, NULL }; @@ -599,9 +668,9 @@ get_string(struct gl_context *ctx, GLenum pname) (void) ctx; switch (pname) { case GL_VENDOR: - return (const GLubyte *) "Mesa Project"; + return (const GLubyte *) swrast_vendor_string; case GL_RENDERER: - return (const GLubyte *) "Software Rasterizer"; + return (const GLubyte *) swrast_renderer_string; default: return NULL; } diff --git a/lib/libGL/dri/r300g/Makefile b/lib/libGL/dri/r300g/Makefile index 238b5f73d..a78002d1f 100644 --- a/lib/libGL/dri/r300g/Makefile +++ b/lib/libGL/dri/r300g/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.7 2015/02/20 23:31:05 jsg Exp $ +# $OpenBSD: Makefile,v 1.8 2015/02/22 09:30:33 jsg Exp $ LIB= r300_dri.so @@ -26,6 +26,7 @@ DRIVER_DEFINES = \ DRIDRM_SOURCES = \ dri_context.c \ dri_drawable.c \ + dri_query_renderer.c \ dri_screen.c \ dri2.c @@ -53,6 +54,7 @@ LDADD= \ .include "../../gallium/Makefile.inc" .include <bsd.xorg.mk> +.PATH: ${GALLIUM}/state_trackers/dri .PATH: ${GALLIUM}/state_trackers/dri/common .PATH: ${GALLIUM}/state_trackers/dri/drm .PATH: ${GALLIUM}/targets/r300/common diff --git a/lib/libGL/dri/r600g/Makefile b/lib/libGL/dri/r600g/Makefile index 146f3f28c..e378f50fe 100644 --- a/lib/libGL/dri/r600g/Makefile +++ b/lib/libGL/dri/r600g/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.7 2015/02/20 23:31:05 jsg Exp $ +# $OpenBSD: Makefile,v 1.8 2015/02/22 09:30:33 jsg Exp $ LIB= r600_dri.so @@ -27,6 +27,7 @@ DRIVER_DEFINES = \ DRIDRM_SOURCES = \ dri_context.c \ dri_drawable.c \ + dri_query_renderer.c \ dri_screen.c \ dri2.c @@ -54,6 +55,7 @@ LDADD= \ .include "../../gallium/Makefile.inc" .include <bsd.xorg.mk> +.PATH: ${GALLIUM}/state_trackers/dri .PATH: ${GALLIUM}/state_trackers/dri/common .PATH: ${GALLIUM}/state_trackers/dri/drm .PATH: ${GALLIUM}/targets/r600/common diff --git a/lib/libGL/dri/radeonsi/Makefile b/lib/libGL/dri/radeonsi/Makefile index 1872feb5e..cc5e5a63e 100644 --- a/lib/libGL/dri/radeonsi/Makefile +++ b/lib/libGL/dri/radeonsi/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.5 2015/02/20 23:31:05 jsg Exp $ +# $OpenBSD: Makefile,v 1.6 2015/02/22 09:30:33 jsg Exp $ LIB= radeonsi_dri.so @@ -27,6 +27,7 @@ DRIVER_DEFINES = \ DRIDRM_SOURCES = \ dri_context.c \ dri_drawable.c \ + dri_query_renderer.c \ dri_screen.c \ dri2.c @@ -54,6 +55,7 @@ LDADD= \ .include "../../gallium/Makefile.inc" .include <bsd.xorg.mk> +.PATH: ${GALLIUM}/state_trackers/dri .PATH: ${GALLIUM}/state_trackers/dri/common .PATH: ${GALLIUM}/state_trackers/dri/drm .PATH: ${GALLIUM}/targets/radeonsi/common diff --git a/lib/libGL/dri/swrastg/Makefile b/lib/libGL/dri/swrastg/Makefile index ae0cefbef..0903ed5ba 100644 --- a/lib/libGL/dri/swrastg/Makefile +++ b/lib/libGL/dri/swrastg/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.12 2015/02/20 23:31:05 jsg Exp $ +# $OpenBSD: Makefile,v 1.13 2015/02/22 09:30:33 jsg Exp $ .include <bsd.xconf.mk> LIB= swrast_dri.so @@ -34,6 +34,7 @@ WINSYS_SOURCES = \ DRISW_SOURCES = \ dri_context.c \ dri_drawable.c \ + dri_query_renderer.c \ dri_screen.c \ drisw.c @@ -61,6 +62,7 @@ LDADD= \ .include "../../gallium/Makefile.inc" .include <bsd.xorg.mk> +.PATH: ${GALLIUM}/state_trackers/dri .PATH: ${GALLIUM}/state_trackers/dri/common .PATH: ${GALLIUM}/state_trackers/dri/sw .PATH: ${GALLIUM}/targets/dri-swrast |