Skip to content

Commit fb6df93

Browse files
GPU: Add name properties to resources (#11946)
1 parent a2b0ddc commit fb6df93

File tree

7 files changed

+441
-301
lines changed

7 files changed

+441
-301
lines changed

include/SDL3/SDL_gpu.h

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,6 @@ typedef struct SDL_GPUDevice SDL_GPUDevice;
334334
* \since This struct is available since SDL 3.1.3
335335
*
336336
* \sa SDL_CreateGPUBuffer
337-
* \sa SDL_SetGPUBufferName
338337
* \sa SDL_UploadToGPUBuffer
339338
* \sa SDL_DownloadFromGPUBuffer
340339
* \sa SDL_CopyGPUBufferToBuffer
@@ -374,7 +373,6 @@ typedef struct SDL_GPUTransferBuffer SDL_GPUTransferBuffer;
374373
* \since This struct is available since SDL 3.1.3
375374
*
376375
* \sa SDL_CreateGPUTexture
377-
* \sa SDL_SetGPUTextureName
378376
* \sa SDL_UploadToGPUTexture
379377
* \sa SDL_DownloadFromGPUTexture
380378
* \sa SDL_CopyGPUTextureToTexture
@@ -2247,6 +2245,10 @@ extern SDL_DECLSPEC SDL_GPUShaderFormat SDLCALL SDL_GetGPUShaderFormats(SDL_GPUD
22472245
* - [[texture]]: Sampled textures, followed by read-only storage textures,
22482246
* followed by read-write storage textures
22492247
*
2248+
* There are optional properties that can be provided through `props`. These are the supported properties:
2249+
*
2250+
* - `SDL_PROP_GPU_COMPUTEPIPELINE_CREATE_NAME_STRING`: a name that can be displayed in debugging tools.
2251+
*
22502252
* \param device a GPU Context.
22512253
* \param createinfo a struct describing the state of the compute pipeline to
22522254
* create.
@@ -2262,9 +2264,15 @@ extern SDL_DECLSPEC SDL_GPUComputePipeline *SDLCALL SDL_CreateGPUComputePipeline
22622264
SDL_GPUDevice *device,
22632265
const SDL_GPUComputePipelineCreateInfo *createinfo);
22642266

2267+
#define SDL_PROP_GPU_COMPUTEPIPELINE_CREATE_NAME_STRING "SDL.gpu.computepipeline.create.name"
2268+
22652269
/**
22662270
* Creates a pipeline object to be used in a graphics workflow.
22672271
*
2272+
* There are optional properties that can be provided through `props`. These are the supported properties:
2273+
*
2274+
* - `SDL_PROP_GPU_GRAPHICSPIPELINE_CREATE_NAME_STRING`: a name that can be displayed in debugging tools.
2275+
*
22682276
* \param device a GPU Context.
22692277
* \param createinfo a struct describing the state of the graphics pipeline to
22702278
* create.
@@ -2281,10 +2289,16 @@ extern SDL_DECLSPEC SDL_GPUGraphicsPipeline *SDLCALL SDL_CreateGPUGraphicsPipeli
22812289
SDL_GPUDevice *device,
22822290
const SDL_GPUGraphicsPipelineCreateInfo *createinfo);
22832291

2292+
#define SDL_PROP_GPU_GRAPHICSPIPELINE_CREATE_NAME_STRING "SDL.gpu.graphicspipeline.create.name"
2293+
22842294
/**
22852295
* Creates a sampler object to be used when binding textures in a graphics
22862296
* workflow.
22872297
*
2298+
* There are optional properties that can be provided through `props`. These are the supported properties:
2299+
*
2300+
* - `SDL_PROP_GPU_SAMPLER_CREATE_NAME_STRING`: a name that can be displayed in debugging tools.
2301+
*
22882302
* \param device a GPU Context.
22892303
* \param createinfo a struct describing the state of the sampler to create.
22902304
* \returns a sampler object on success, or NULL on failure; call
@@ -2300,6 +2314,8 @@ extern SDL_DECLSPEC SDL_GPUSampler *SDLCALL SDL_CreateGPUSampler(
23002314
SDL_GPUDevice *device,
23012315
const SDL_GPUSamplerCreateInfo *createinfo);
23022316

2317+
#define SDL_PROP_GPU_SAMPLER_CREATE_NAME_STRING "SDL.gpu.sampler.create.name"
2318+
23032319
/**
23042320
* Creates a shader to be used when creating a graphics pipeline.
23052321
*
@@ -2357,6 +2373,10 @@ extern SDL_DECLSPEC SDL_GPUSampler *SDLCALL SDL_CreateGPUSampler(
23572373
* SDL_PROP_GPU_DEVICE_CREATE_D3D12_SEMANTIC_NAME_STRING with
23582374
* SDL_CreateGPUDeviceWithProperties().
23592375
*
2376+
* There are optional properties that can be provided through `props`. These are the supported properties:
2377+
*
2378+
* - `SDL_PROP_GPU_SHADER_CREATE_NAME_STRING`: a name that can be displayed in debugging tools.
2379+
*
23602380
* \param device a GPU Context.
23612381
* \param createinfo a struct describing the state of the shader to create.
23622382
* \returns a shader object on success, or NULL on failure; call
@@ -2371,6 +2391,8 @@ extern SDL_DECLSPEC SDL_GPUShader *SDLCALL SDL_CreateGPUShader(
23712391
SDL_GPUDevice *device,
23722392
const SDL_GPUShaderCreateInfo *createinfo);
23732393

2394+
#define SDL_PROP_GPU_SHADER_CREATE_NAME_STRING "SDL.gpu.shader.create.name"
2395+
23742396
/**
23752397
* Creates a texture object to be used in graphics or compute workflows.
23762398
*
@@ -2408,6 +2430,7 @@ extern SDL_DECLSPEC SDL_GPUShader *SDLCALL SDL_CreateGPUShader(
24082430
* - `SDL_PROP_GPU_CREATETEXTURE_D3D12_CLEAR_STENCIL_UINT8`: (Direct3D 12
24092431
* only) if the texture usage is SDL_GPU_TEXTUREUSAGE_DEPTH_STENCIL_TARGET,
24102432
* clear the texture to a stencil of this value. Defaults to zero.
2433+
* - `SDL_PROP_GPU_TEXTURE_CREATE_NAME_STRING`: a name that can be displayed in debugging tools.
24112434
*
24122435
* \param device a GPU Context.
24132436
* \param createinfo a struct describing the state of the texture to create.
@@ -2437,7 +2460,7 @@ extern SDL_DECLSPEC SDL_GPUTexture *SDLCALL SDL_CreateGPUTexture(
24372460
#define SDL_PROP_GPU_CREATETEXTURE_D3D12_CLEAR_A_FLOAT "SDL.gpu.createtexture.d3d12.clear.a"
24382461
#define SDL_PROP_GPU_CREATETEXTURE_D3D12_CLEAR_DEPTH_FLOAT "SDL.gpu.createtexture.d3d12.clear.depth"
24392462
#define SDL_PROP_GPU_CREATETEXTURE_D3D12_CLEAR_STENCIL_UINT8 "SDL.gpu.createtexture.d3d12.clear.stencil"
2440-
2463+
#define SDL_PROP_GPU_TEXTURE_CREATE_NAME_STRING "SDL.gpu.texture.create.name"
24412464

24422465
/**
24432466
* Creates a buffer object to be used in graphics or compute workflows.
@@ -2453,14 +2476,17 @@ extern SDL_DECLSPEC SDL_GPUTexture *SDLCALL SDL_CreateGPUTexture(
24532476
* [this blog post](https://moonside.games/posts/sdl-gpu-concepts-cycling/)
24542477
* .
24552478
*
2479+
* There are optional properties that can be provided through `props`. These are the supported properties:
2480+
*
2481+
* - `SDL_PROP_GPU_BUFFER_CREATE_NAME_STRING`: a name that can be displayed in debugging tools.
2482+
*
24562483
* \param device a GPU Context.
24572484
* \param createinfo a struct describing the state of the buffer to create.
24582485
* \returns a buffer object on success, or NULL on failure; call
24592486
* SDL_GetError() for more information.
24602487
*
24612488
* \since This function is available since SDL 3.1.3.
24622489
*
2463-
* \sa SDL_SetGPUBufferName
24642490
* \sa SDL_UploadToGPUBuffer
24652491
* \sa SDL_DownloadFromGPUBuffer
24662492
* \sa SDL_CopyGPUBufferToBuffer
@@ -2478,13 +2504,19 @@ extern SDL_DECLSPEC SDL_GPUBuffer *SDLCALL SDL_CreateGPUBuffer(
24782504
SDL_GPUDevice *device,
24792505
const SDL_GPUBufferCreateInfo *createinfo);
24802506

2507+
#define SDL_PROP_GPU_BUFFER_CREATE_NAME_STRING "SDL.gpu.buffer.create.name"
2508+
24812509
/**
24822510
* Creates a transfer buffer to be used when uploading to or downloading from
24832511
* graphics resources.
24842512
*
24852513
* Download buffers can be particularly expensive to create, so it is good
24862514
* practice to reuse them if data will be downloaded regularly.
24872515
*
2516+
* There are optional properties that can be provided through `props`. These are the supported properties:
2517+
*
2518+
* - `SDL_PROP_GPU_TRANSFERBUFFER_CREATE_NAME_STRING`: a name that can be displayed in debugging tools.
2519+
*
24882520
* \param device a GPU Context.
24892521
* \param createinfo a struct describing the state of the transfer buffer to
24902522
* create.
@@ -2503,21 +2535,24 @@ extern SDL_DECLSPEC SDL_GPUTransferBuffer *SDLCALL SDL_CreateGPUTransferBuffer(
25032535
SDL_GPUDevice *device,
25042536
const SDL_GPUTransferBufferCreateInfo *createinfo);
25052537

2538+
#define SDL_PROP_GPU_TRANSFERBUFFER_CREATE_NAME_STRING "SDL.gpu.transferbuffer.create.name"
2539+
25062540
/* Debug Naming */
25072541

25082542
/**
25092543
* Sets an arbitrary string constant to label a buffer.
25102544
*
2511-
* Useful for debugging.
2545+
* You should use SDL_PROP_GPU_BUFFER_CREATE_NAME_STRING with SDL_CreateGPUBuffer instead of this function to avoid thread safety issues.
25122546
*
25132547
* \param device a GPU Context.
25142548
* \param buffer a buffer to attach the name to.
25152549
* \param text a UTF-8 string constant to mark as the name of the buffer.
25162550
*
2517-
* \threadsafety This function is not thread safe, you must synchronize calls
2518-
* to this function.
2551+
* \threadsafety This function is not thread safe, you must make sure the buffer is not simultaneously used by any other thread.
25192552
*
25202553
* \since This function is available since SDL 3.1.3.
2554+
*
2555+
* \sa SDL_CreateGPUBuffer
25212556
*/
25222557
extern SDL_DECLSPEC void SDLCALL SDL_SetGPUBufferName(
25232558
SDL_GPUDevice *device,
@@ -2527,16 +2562,17 @@ extern SDL_DECLSPEC void SDLCALL SDL_SetGPUBufferName(
25272562
/**
25282563
* Sets an arbitrary string constant to label a texture.
25292564
*
2530-
* Useful for debugging.
2565+
* You should use SDL_PROP_GPU_TEXTURE_CREATE_NAME_STRING with SDL_CreateGPUTexture instead of this function to avoid thread safety issues.
25312566
*
25322567
* \param device a GPU Context.
25332568
* \param texture a texture to attach the name to.
25342569
* \param text a UTF-8 string constant to mark as the name of the texture.
25352570
*
2536-
* \threadsafety This function is not thread safe, you must synchronize calls
2537-
* to this function.
2571+
* \threadsafety This function is not thread safe, you must make sure the texture is not simultaneously used by any other thread.
25382572
*
25392573
* \since This function is available since SDL 3.1.3.
2574+
*
2575+
* \sa SDL_CreateGPUTexture
25402576
*/
25412577
extern SDL_DECLSPEC void SDLCALL SDL_SetGPUTextureName(
25422578
SDL_GPUDevice *device,

src/gpu/SDL_gpu.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,10 +1055,13 @@ SDL_GPUBuffer *SDL_CreateGPUBuffer(
10551055
return NULL;
10561056
}
10571057

1058+
const char *debugName = SDL_GetStringProperty(createinfo->props, SDL_PROP_GPU_BUFFER_CREATE_NAME_STRING, NULL);
1059+
10581060
return device->CreateBuffer(
10591061
device->driverData,
10601062
createinfo->usage,
1061-
createinfo->size);
1063+
createinfo->size,
1064+
debugName);
10621065
}
10631066

10641067
SDL_GPUTransferBuffer *SDL_CreateGPUTransferBuffer(
@@ -1071,10 +1074,13 @@ SDL_GPUTransferBuffer *SDL_CreateGPUTransferBuffer(
10711074
return NULL;
10721075
}
10731076

1077+
const char *debugName = SDL_GetStringProperty(createinfo->props, SDL_PROP_GPU_TRANSFERBUFFER_CREATE_NAME_STRING, NULL);
1078+
10741079
return device->CreateTransferBuffer(
10751080
device->driverData,
10761081
createinfo->usage,
1077-
createinfo->size);
1082+
createinfo->size,
1083+
debugName);
10781084
}
10791085

10801086
// Debug Naming

src/gpu/SDL_sysgpu.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -474,12 +474,14 @@ struct SDL_GPUDevice
474474
SDL_GPUBuffer *(*CreateBuffer)(
475475
SDL_GPURenderer *driverData,
476476
SDL_GPUBufferUsageFlags usageFlags,
477-
Uint32 size);
477+
Uint32 size,
478+
const char *debugName);
478479

479480
SDL_GPUTransferBuffer *(*CreateTransferBuffer)(
480481
SDL_GPURenderer *driverData,
481482
SDL_GPUTransferBufferUsage usage,
482-
Uint32 size);
483+
Uint32 size,
484+
const char *debugName);
483485

484486
// Debug Naming
485487

0 commit comments

Comments
 (0)