Explorar o código

Added SDL_PROP_RENDERER_GPU_DEVICE_POINTER

Fixes https://github.com/libsdl-org/SDL/issues/11600
Sam Lantinga hai 3 meses
pai
achega
969f03d9f0
Modificáronse 3 ficheiros con 12 adicións e 0 borrados
  1. 6 0
      include/SDL3/SDL_render.h
  2. 2 0
      src/render/gpu/SDL_render_gpu.c
  3. 4 0
      src/test/SDL_test_common.c

+ 6 - 0
include/SDL3/SDL_render.h

@@ -441,6 +441,11 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetRendererName(SDL_Renderer *rende
  *   swapchain images, or potential frames in flight, used by the Vulkan
  *   renderer
  *
+ * With the gpu renderer:
+ *
+ * - `SDL_PROP_RENDERER_GPU_DEVICE_POINTER`: the SDL_GPUDevice associated
+ *   with the renderer
+ *
  * \param renderer the rendering context.
  * \returns a valid property ID on success or 0 on failure; call
  *          SDL_GetError() for more information.
@@ -474,6 +479,7 @@ extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetRendererProperties(SDL_Rende
 #define SDL_PROP_RENDERER_VULKAN_GRAPHICS_QUEUE_FAMILY_INDEX_NUMBER "SDL.renderer.vulkan.graphics_queue_family_index"
 #define SDL_PROP_RENDERER_VULKAN_PRESENT_QUEUE_FAMILY_INDEX_NUMBER  "SDL.renderer.vulkan.present_queue_family_index"
 #define SDL_PROP_RENDERER_VULKAN_SWAPCHAIN_IMAGE_COUNT_NUMBER       "SDL.renderer.vulkan.swapchain_image_count"
+#define SDL_PROP_RENDERER_GPU_DEVICE_POINTER                        "SDL.renderer.gpu.device"
 
 /**
  * Get the output size in pixels of a rendering context.

+ 2 - 0
src/render/gpu/SDL_render_gpu.c

@@ -1284,6 +1284,8 @@ static bool GPU_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_P
         return false;
     }
 
+    SDL_SetPointerProperty(SDL_GetRendererProperties(renderer), SDL_PROP_RENDERER_GPU_DEVICE_POINTER, data->device);
+
     return true;
 }
 

+ 4 - 0
src/test/SDL_test_common.c

@@ -1093,6 +1093,10 @@ static void SDLTest_PrintRenderer(SDL_Renderer *renderer)
     name = SDL_GetRendererName(renderer);
 
     SDL_Log("  Renderer %s:\n", name);
+    if (SDL_strcmp(name, "gpu") == 0) {
+        SDL_GPUDevice *device = SDL_GetPointerProperty(SDL_GetRendererProperties(renderer), SDL_PROP_RENDERER_GPU_DEVICE_POINTER, NULL);
+        SDL_Log("    Driver: %s\n", SDL_GetGPUDeviceDriver(device));
+    }
     SDL_Log("    VSync: %d\n", (int)SDL_GetNumberProperty(SDL_GetRendererProperties(renderer), SDL_PROP_RENDERER_VSYNC_NUMBER, 0));
 
     texture_formats = (const SDL_PixelFormat *)SDL_GetPointerProperty(SDL_GetRendererProperties(renderer), SDL_PROP_RENDERER_TEXTURE_FORMATS_POINTER, NULL);