Skip to content

Commit

Permalink
GPU: More robust error reporting (libsdl-org#10958)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Ethan Lee <flibitijibibo@gmail.com>
Co-authored-by: Caleb Cornett <caleb.cornett@outlook.com>
  • Loading branch information
3 people authored Sep 27, 2024
1 parent 48e213b commit be401dd
Show file tree
Hide file tree
Showing 11 changed files with 816 additions and 855 deletions.
63 changes: 33 additions & 30 deletions include/SDL3/SDL_gpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -877,15 +877,15 @@ typedef enum SDL_GPUSamplerAddressMode
* - VSYNC: Waits for vblank before presenting. No tearing is possible. If
* there is a pending image to present, the new image is enqueued for
* presentation. Disallows tearing at the cost of visual latency. When using
* this present mode, AcquireSwapchainTexture will block if too many frames
* this present mode, AcquireGPUSwapchainTexture will block if too many frames
* are in flight.
* - IMMEDIATE: Immediately presents. Lowest latency option, but tearing may
* occur. When using this mode, AcquireSwapchainTexture will return NULL if
* occur. When using this mode, AcquireGPUSwapchainTexture will return NULL if
* too many frames are in flight.
* - MAILBOX: Waits for vblank before presenting. No tearing is possible. If
* there is a pending image to present, the pending image is replaced by the
* new image. Similar to VSYNC, but with reduced visual latency. When using
* this mode, AcquireSwapchainTexture will return NULL if too many frames
* this mode, AcquireGPUSwapchainTexture will return NULL if too many frames
* are in flight.
*
* \since This enum is available since SDL 3.0.0
Expand Down Expand Up @@ -1623,6 +1623,7 @@ typedef struct SDL_GPUBlitInfo {
Uint8 padding2;
Uint8 padding3;
} SDL_GPUBlitInfo;

/* Binding structs */

/**
Expand Down Expand Up @@ -1731,7 +1732,7 @@ extern SDL_DECLSPEC bool SDLCALL SDL_GPUSupportsProperties(
* \param debug_mode enable debug mode properties and validations.
* \param name the preferred GPU driver, or NULL to let SDL pick the optimal
* driver.
* \returns a GPU context on success or NULL on failure.
* \returns a GPU context on success or NULL on failure; call SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
*
Expand Down Expand Up @@ -1778,7 +1779,7 @@ extern SDL_DECLSPEC SDL_GPUDevice *SDLCALL SDL_CreateGPUDevice(
* use for all vertex semantics, default is "TEXCOORD".
*
* \param props the properties to use.
* \returns a GPU context on success or NULL on failure.
* \returns a GPU context on success or NULL on failure; call SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
*
Expand Down Expand Up @@ -1904,7 +1905,7 @@ extern SDL_DECLSPEC SDL_GPUShaderFormat SDLCALL SDL_GetGPUShaderFormats(SDL_GPUD
* \param device a GPU Context.
* \param createinfo a struct describing the state of the compute pipeline to
* create.
* \returns a compute pipeline object on success, or NULL on failure.
* \returns a compute pipeline object on success, or NULL on failure; call SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
*
Expand All @@ -1921,7 +1922,7 @@ extern SDL_DECLSPEC SDL_GPUComputePipeline *SDLCALL SDL_CreateGPUComputePipeline
* \param device a GPU Context.
* \param createinfo a struct describing the state of the graphics pipeline to
* create.
* \returns a graphics pipeline object on success, or NULL on failure.
* \returns a graphics pipeline object on success, or NULL on failure; call SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
*
Expand All @@ -1939,7 +1940,7 @@ extern SDL_DECLSPEC SDL_GPUGraphicsPipeline *SDLCALL SDL_CreateGPUGraphicsPipeli
*
* \param device a GPU Context.
* \param createinfo a struct describing the state of the sampler to create.
* \returns a sampler object on success, or NULL on failure.
* \returns a sampler object on success, or NULL on failure; call SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
*
Expand Down Expand Up @@ -2008,7 +2009,7 @@ extern SDL_DECLSPEC SDL_GPUSampler *SDLCALL SDL_CreateGPUSampler(
*
* \param device a GPU Context.
* \param createinfo a struct describing the state of the shader to create.
* \returns a shader object on success, or NULL on failure.
* \returns a shader object on success, or NULL on failure; call SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
*
Expand All @@ -2034,7 +2035,7 @@ extern SDL_DECLSPEC SDL_GPUShader *SDLCALL SDL_CreateGPUShader(
*
* \param device a GPU Context.
* \param createinfo a struct describing the state of the texture to create.
* \returns a texture object on success, or NULL on failure.
* \returns a texture object on success, or NULL on failure; call SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
*
Expand Down Expand Up @@ -2064,7 +2065,7 @@ extern SDL_DECLSPEC SDL_GPUTexture *SDLCALL SDL_CreateGPUTexture(
*
* \param device a GPU Context.
* \param createinfo a struct describing the state of the buffer to create.
* \returns a buffer object on success, or NULL on failure.
* \returns a buffer object on success, or NULL on failure; call SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
*
Expand Down Expand Up @@ -2093,7 +2094,7 @@ extern SDL_DECLSPEC SDL_GPUBuffer *SDLCALL SDL_CreateGPUBuffer(
* \param device a GPU Context.
* \param createinfo a struct describing the state of the transfer buffer to
* create.
* \returns a transfer buffer on success, or NULL on failure.
* \returns a transfer buffer on success, or NULL on failure; call SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
*
Expand Down Expand Up @@ -2301,7 +2302,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_ReleaseGPUGraphicsPipeline(
* acquired on.
*
* \param device a GPU context.
* \returns a command buffer.
* \returns a command buffer, or NULL on failure; call SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
*
Expand Down Expand Up @@ -2967,7 +2968,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_EndGPUComputePass(
* \param device a GPU context.
* \param transfer_buffer a transfer buffer.
* \param cycle if true, cycles the transfer buffer if it is already bound.
* \returns the address of the mapped transfer buffer memory.
* \returns the address of the mapped transfer buffer memory, or NULL on failure; call SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
*/
Expand Down Expand Up @@ -3183,7 +3184,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_BlitGPUTexture(
* \param device a GPU context.
* \param window an SDL_Window.
* \param swapchain_composition the swapchain composition to check.
* \returns true if supported, false if unsupported (or on error).
* \returns true if supported, false if unsupported.
*
* \since This function is available since SDL 3.0.0.
*
Expand All @@ -3202,7 +3203,7 @@ extern SDL_DECLSPEC bool SDLCALL SDL_WindowSupportsGPUSwapchainComposition(
* \param device a GPU context.
* \param window an SDL_Window.
* \param present_mode the presentation mode to check.
* \returns true if supported, false if unsupported (or on error).
* \returns true if supported, false if unsupported.
*
* \since This function is available since SDL 3.0.0.
*
Expand All @@ -3226,7 +3227,7 @@ extern SDL_DECLSPEC bool SDLCALL SDL_WindowSupportsGPUPresentMode(
*
* \param device a GPU context.
* \param window an SDL_Window.
* \returns true on success, otherwise false.
* \returns true on success, or false on failure; call SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
*
Expand Down Expand Up @@ -3283,6 +3284,7 @@ extern SDL_DECLSPEC bool SDLCALL SDL_SetGPUSwapchainParameters(

/**
* Obtains the texture format of the swapchain for the given window.
* Note that this format can change if the swapchain parameters change.
*
* \param device a GPU context.
* \param window an SDL_Window that has been claimed.
Expand All @@ -3300,28 +3302,26 @@ extern SDL_DECLSPEC SDL_GPUTextureFormat SDLCALL SDL_GetGPUSwapchainTextureForma
* When a swapchain texture is acquired on a command buffer, it will
* automatically be submitted for presentation when the command buffer is
* submitted. The swapchain texture should only be referenced by the command
* buffer used to acquire it. May return NULL under certain conditions. This
* is not necessarily an error. This texture is managed by the implementation
* and must not be freed by the user. You MUST NOT call this function from any
* buffer used to acquire it. The swapchain texture handle can be NULL under certain conditions. This
* is not necessarily an error. If this function returns false then there is an error. This texture is managed by the implementation
* and must not be freed by the user. The texture dimensions will be the height and width of the claimed window. You MUST NOT call this function from any
* thread other than the one that created the window.
*
* \param command_buffer a command buffer.
* \param window a window that has been claimed.
* \param w a pointer filled in with the swapchain width.
* \param h a pointer filled in with the swapchain height.
* \returns a swapchain texture.
* \param swapchainTexture a pointer filled in with a swapchain texture handle
* \returns true on success, false on error.
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_ClaimWindowForGPUDevice
* \sa SDL_SubmitGPUCommandBuffer
* \sa SDL_SubmitGPUCommandBufferAndAcquireFence
*/
extern SDL_DECLSPEC SDL_GPUTexture *SDLCALL SDL_AcquireGPUSwapchainTexture(
extern SDL_DECLSPEC bool SDLCALL SDL_AcquireGPUSwapchainTexture(
SDL_GPUCommandBuffer *command_buffer,
SDL_Window *window,
Uint32 *w,
Uint32 *h);
SDL_GPUTexture **swapchainTexture);

/**
* Submits a command buffer so its commands can be processed on the GPU.
Expand All @@ -3334,14 +3334,15 @@ extern SDL_DECLSPEC SDL_GPUTexture *SDLCALL SDL_AcquireGPUSwapchainTexture(
* command in a subsequent submission begins executing.
*
* \param command_buffer a command buffer.
* \returns true on success, false on failure; call SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_AcquireGPUCommandBuffer
* \sa SDL_AcquireGPUSwapchainTexture
* \sa SDL_SubmitGPUCommandBufferAndAcquireFence
*/
extern SDL_DECLSPEC void SDLCALL SDL_SubmitGPUCommandBuffer(
extern SDL_DECLSPEC bool SDLCALL SDL_SubmitGPUCommandBuffer(
SDL_GPUCommandBuffer *command_buffer);

/**
Expand All @@ -3357,7 +3358,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_SubmitGPUCommandBuffer(
* command in a subsequent submission begins executing.
*
* \param command_buffer a command buffer.
* \returns a fence associated with the command buffer.
* \returns a fence associated with the command buffer, or NULL on failure; call SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
*
Expand All @@ -3373,12 +3374,13 @@ extern SDL_DECLSPEC SDL_GPUFence *SDLCALL SDL_SubmitGPUCommandBufferAndAcquireFe
* Blocks the thread until the GPU is completely idle.
*
* \param device a GPU context.
* \returns true on success, false on failure; call SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_WaitForGPUFences
*/
extern SDL_DECLSPEC void SDLCALL SDL_WaitForGPUIdle(
extern SDL_DECLSPEC bool SDLCALL SDL_WaitForGPUIdle(
SDL_GPUDevice *device);

/**
Expand All @@ -3389,13 +3391,14 @@ extern SDL_DECLSPEC void SDLCALL SDL_WaitForGPUIdle(
* fences to be signaled.
* \param fences an array of fences to wait on.
* \param num_fences the number of fences in the fences array.
* \returns true on success, false on failure; call SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_SubmitGPUCommandBufferAndAcquireFence
* \sa SDL_WaitForGPUIdle
*/
extern SDL_DECLSPEC void SDLCALL SDL_WaitForGPUFences(
extern SDL_DECLSPEC bool SDLCALL SDL_WaitForGPUFences(
SDL_GPUDevice *device,
bool wait_all,
SDL_GPUFence *const *fences,
Expand Down
8 changes: 4 additions & 4 deletions src/dynapi/SDL_dynapi_procs.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ SDL_DYNAPI_PROC(int,SDL_swprintf,(SDL_OUT_Z_CAP(b) wchar_t *a, size_t b, SDL_PRI
// New API symbols are added at the end
SDL_DYNAPI_PROC(SDL_Surface*,SDL_AcquireCameraFrame,(SDL_Camera *a, Uint64 *b),(a,b),return)
SDL_DYNAPI_PROC(SDL_GPUCommandBuffer*,SDL_AcquireGPUCommandBuffer,(SDL_GPUDevice *a),(a),return)
SDL_DYNAPI_PROC(SDL_GPUTexture*,SDL_AcquireGPUSwapchainTexture,(SDL_GPUCommandBuffer *a, SDL_Window *b, Uint32 *c, Uint32 *d),(a,b,c,d),return)
SDL_DYNAPI_PROC(bool,SDL_AcquireGPUSwapchainTexture,(SDL_GPUCommandBuffer *a, SDL_Window *b, SDL_GPUTexture **c),(a,b,c),return)
SDL_DYNAPI_PROC(int,SDL_AddAtomicInt,(SDL_AtomicInt *a, int b),(a,b),return)
SDL_DYNAPI_PROC(bool,SDL_AddEventWatch,(SDL_EventFilter a, void *b),(a,b),return)
SDL_DYNAPI_PROC(int,SDL_AddGamepadMapping,(const char *a),(a),return)
Expand Down Expand Up @@ -953,7 +953,7 @@ SDL_DYNAPI_PROC(bool,SDL_StopHapticRumble,(SDL_Haptic *a),(a),return)
SDL_DYNAPI_PROC(bool,SDL_StopTextInput,(SDL_Window *a),(a),return)
SDL_DYNAPI_PROC(bool,SDL_StorageReady,(SDL_Storage *a),(a),return)
SDL_DYNAPI_PROC(SDL_GUID,SDL_StringToGUID,(const char *a),(a),return)
SDL_DYNAPI_PROC(void,SDL_SubmitGPUCommandBuffer,(SDL_GPUCommandBuffer *a),(a),)
SDL_DYNAPI_PROC(bool,SDL_SubmitGPUCommandBuffer,(SDL_GPUCommandBuffer *a),(a),return)
SDL_DYNAPI_PROC(SDL_GPUFence*,SDL_SubmitGPUCommandBufferAndAcquireFence,(SDL_GPUCommandBuffer *a),(a),return)
SDL_DYNAPI_PROC(bool,SDL_SurfaceHasAlternateImages,(SDL_Surface *a),(a),return)
SDL_DYNAPI_PROC(bool,SDL_SurfaceHasColorKey,(SDL_Surface *a),(a),return)
Expand Down Expand Up @@ -1006,8 +1006,8 @@ SDL_DYNAPI_PROC(void,SDL_WaitCondition,(SDL_Condition *a, SDL_Mutex *b),(a,b),)
SDL_DYNAPI_PROC(bool,SDL_WaitConditionTimeout,(SDL_Condition *a, SDL_Mutex *b, Sint32 c),(a,b,c),return)
SDL_DYNAPI_PROC(bool,SDL_WaitEvent,(SDL_Event *a),(a),return)
SDL_DYNAPI_PROC(bool,SDL_WaitEventTimeout,(SDL_Event *a, Sint32 b),(a,b),return)
SDL_DYNAPI_PROC(void,SDL_WaitForGPUFences,(SDL_GPUDevice *a, bool b, SDL_GPUFence *const *c, Uint32 d),(a,b,c,d),)
SDL_DYNAPI_PROC(void,SDL_WaitForGPUIdle,(SDL_GPUDevice *a),(a),)
SDL_DYNAPI_PROC(bool,SDL_WaitForGPUFences,(SDL_GPUDevice *a, bool b, SDL_GPUFence *const *c, Uint32 d),(a,b,c,d),return)
SDL_DYNAPI_PROC(bool,SDL_WaitForGPUIdle,(SDL_GPUDevice *a),(a),return)
SDL_DYNAPI_PROC(bool,SDL_WaitProcess,(SDL_Process *a, bool b, int *c),(a,b,c),return)
SDL_DYNAPI_PROC(void,SDL_WaitSemaphore,(SDL_Semaphore *a),(a),)
SDL_DYNAPI_PROC(bool,SDL_WaitSemaphoreTimeout,(SDL_Semaphore *a, Sint32 b),(a,b),return)
Expand Down
Loading

0 comments on commit be401dd

Please sign in to comment.