mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-10-03 16:36:25 +00:00
render: Update GPU backend to use the new present workflow
This commit is contained in:

committed by
Sam Lantinga

parent
a0e537b9c0
commit
cc24518c41
@@ -41,7 +41,6 @@ typedef struct GPU_RenderData
|
|||||||
SDL_GPUDevice *device;
|
SDL_GPUDevice *device;
|
||||||
GPU_Shaders shaders;
|
GPU_Shaders shaders;
|
||||||
GPU_PipelineCache pipeline_cache;
|
GPU_PipelineCache pipeline_cache;
|
||||||
SDL_GPUFence *present_fence;
|
|
||||||
|
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
@@ -959,16 +958,13 @@ static bool GPU_RenderPresent(SDL_Renderer *renderer)
|
|||||||
|
|
||||||
SDL_GPUTexture *swapchain;
|
SDL_GPUTexture *swapchain;
|
||||||
Uint32 swapchain_texture_width, swapchain_texture_height;
|
Uint32 swapchain_texture_width, swapchain_texture_height;
|
||||||
bool result = SDL_AcquireGPUSwapchainTexture(data->state.command_buffer, renderer->window, &swapchain, &swapchain_texture_width, &swapchain_texture_height);
|
bool result = SDL_WaitAndAcquireGPUSwapchainTexture(data->state.command_buffer, renderer->window, &swapchain, &swapchain_texture_width, &swapchain_texture_height);
|
||||||
|
|
||||||
if (!result) {
|
if (!result) {
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_RENDER, "Failed to acquire swapchain texture: %s", SDL_GetError());
|
SDL_LogError(SDL_LOG_CATEGORY_RENDER, "Failed to acquire swapchain texture: %s", SDL_GetError());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (swapchain == NULL) {
|
if (swapchain != NULL) {
|
||||||
goto submit;
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_GPUBlitInfo blit_info;
|
SDL_GPUBlitInfo blit_info;
|
||||||
SDL_zero(blit_info);
|
SDL_zero(blit_info);
|
||||||
|
|
||||||
@@ -983,28 +979,15 @@ static bool GPU_RenderPresent(SDL_Renderer *renderer)
|
|||||||
|
|
||||||
SDL_BlitGPUTexture(data->state.command_buffer, &blit_info);
|
SDL_BlitGPUTexture(data->state.command_buffer, &blit_info);
|
||||||
|
|
||||||
// *** FIXME ***
|
|
||||||
// This is going to block if there is ever a frame in flight.
|
|
||||||
// We should do something similar to FNA3D
|
|
||||||
// where we keep track of MAX_FRAMES_IN_FLIGHT number of fences
|
|
||||||
// and only block if we have maxed out the backpressure.
|
|
||||||
// -cosmonaut
|
|
||||||
submit:
|
|
||||||
#if 1
|
|
||||||
if (data->present_fence) {
|
|
||||||
SDL_WaitForGPUFences(data->device, true, &data->present_fence, 1);
|
|
||||||
SDL_ReleaseGPUFence(data->device, data->present_fence);
|
|
||||||
}
|
|
||||||
|
|
||||||
data->present_fence = SDL_SubmitGPUCommandBufferAndAcquireFence(data->state.command_buffer);
|
|
||||||
#else
|
|
||||||
SDL_SubmitGPUCommandBuffer(data->state.command_buffer);
|
SDL_SubmitGPUCommandBuffer(data->state.command_buffer);
|
||||||
#endif
|
|
||||||
|
|
||||||
if (swapchain != NULL && (swapchain_texture_width != data->backbuffer.width || swapchain_texture_height != data->backbuffer.height)) {
|
if (swapchain_texture_width != data->backbuffer.width || swapchain_texture_height != data->backbuffer.height) {
|
||||||
SDL_ReleaseGPUTexture(data->device, data->backbuffer.texture);
|
SDL_ReleaseGPUTexture(data->device, data->backbuffer.texture);
|
||||||
CreateBackbuffer(data, swapchain_texture_width, swapchain_texture_height, SDL_GetGPUSwapchainTextureFormat(data->device, renderer->window));
|
CreateBackbuffer(data, swapchain_texture_width, swapchain_texture_height, SDL_GetGPUSwapchainTextureFormat(data->device, renderer->window));
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
SDL_SubmitGPUCommandBuffer(data->state.command_buffer);
|
||||||
|
}
|
||||||
|
|
||||||
data->state.command_buffer = SDL_AcquireGPUCommandBuffer(data->device);
|
data->state.command_buffer = SDL_AcquireGPUCommandBuffer(data->device);
|
||||||
|
|
||||||
@@ -1038,11 +1021,6 @@ static void GPU_DestroyRenderer(SDL_Renderer *renderer)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data->present_fence) {
|
|
||||||
SDL_WaitForGPUFences(data->device, true, &data->present_fence, 1);
|
|
||||||
SDL_ReleaseGPUFence(data->device, data->present_fence);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data->state.command_buffer) {
|
if (data->state.command_buffer) {
|
||||||
SDL_SubmitGPUCommandBuffer(data->state.command_buffer);
|
SDL_SubmitGPUCommandBuffer(data->state.command_buffer);
|
||||||
data->state.command_buffer = NULL;
|
data->state.command_buffer = NULL;
|
||||||
@@ -1262,6 +1240,8 @@ static bool GPU_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_P
|
|||||||
|
|
||||||
SDL_SetGPUSwapchainParameters(data->device, window, data->swapchain.composition, data->swapchain.present_mode);
|
SDL_SetGPUSwapchainParameters(data->device, window, data->swapchain.composition, data->swapchain.present_mode);
|
||||||
|
|
||||||
|
SDL_SetGPUAllowedFramesInFlight(data->device, 1);
|
||||||
|
|
||||||
SDL_AddSupportedTextureFormat(renderer, SDL_PIXELFORMAT_RGBA32);
|
SDL_AddSupportedTextureFormat(renderer, SDL_PIXELFORMAT_RGBA32);
|
||||||
SDL_AddSupportedTextureFormat(renderer, SDL_PIXELFORMAT_BGRA32);
|
SDL_AddSupportedTextureFormat(renderer, SDL_PIXELFORMAT_BGRA32);
|
||||||
SDL_AddSupportedTextureFormat(renderer, SDL_PIXELFORMAT_RGBX32);
|
SDL_AddSupportedTextureFormat(renderer, SDL_PIXELFORMAT_RGBX32);
|
||||||
|
Reference in New Issue
Block a user