GPU: Add swapchain dimension out params (#11003)

This commit is contained in:
Evan Hemsley
2024-09-30 10:23:19 -07:00
committed by GitHub
parent b3388d5753
commit afdf325fb4
11 changed files with 347 additions and 285 deletions

View File

@@ -957,7 +957,8 @@ static bool GPU_RenderPresent(SDL_Renderer *renderer)
GPU_RenderData *data = (GPU_RenderData *)renderer->internal;
SDL_GPUTexture *swapchain;
bool result = SDL_AcquireGPUSwapchainTexture(data->state.command_buffer, renderer->window, &swapchain);
Uint32 swapchain_texture_width, swapchain_texture_height;
bool result = SDL_AcquireGPUSwapchainTexture(data->state.command_buffer, renderer->window, &swapchain, &swapchain_texture_width, &swapchain_texture_height);
if (!result) {
SDL_LogError(SDL_LOG_CATEGORY_RENDER, "Failed to acquire swapchain texture: %s", SDL_GetError());
@@ -967,8 +968,6 @@ static bool GPU_RenderPresent(SDL_Renderer *renderer)
goto submit;
}
SDL_GPUTextureFormat swapchain_fmt = SDL_GetGPUSwapchainTextureFormat(data->device, renderer->window);
SDL_GPUBlitInfo blit_info;
SDL_zero(blit_info);
@@ -976,18 +975,13 @@ static bool GPU_RenderPresent(SDL_Renderer *renderer)
blit_info.source.w = data->backbuffer.width;
blit_info.source.h = data->backbuffer.height;
blit_info.destination.texture = swapchain;
blit_info.destination.w = renderer->output_pixel_w;
blit_info.destination.h = renderer->output_pixel_h;
blit_info.destination.w = swapchain_texture_width;
blit_info.destination.h = swapchain_texture_height;
blit_info.load_op = SDL_GPU_LOADOP_DONT_CARE;
blit_info.filter = SDL_GPU_FILTER_LINEAR;
SDL_BlitGPUTexture(data->state.command_buffer, &blit_info);
if (renderer->output_pixel_w != data->backbuffer.width || renderer->output_pixel_h != data->backbuffer.height || swapchain_fmt != data->backbuffer.format) {
SDL_ReleaseGPUTexture(data->device, data->backbuffer.texture);
CreateBackbuffer(data, renderer->output_pixel_w, renderer->output_pixel_h, swapchain_fmt);
}
// *** FIXME ***
// This is going to block if there is ever a frame in flight.
// We should do something similar to FNA3D
@@ -1006,6 +1000,11 @@ submit:
SDL_SubmitGPUCommandBuffer(data->state.command_buffer);
#endif
if (swapchain != NULL && (swapchain_texture_width != data->backbuffer.width || swapchain_texture_height != data->backbuffer.height)) {
SDL_ReleaseGPUTexture(data->device, data->backbuffer.texture);
CreateBackbuffer(data, swapchain_texture_width, swapchain_texture_height, SDL_GetGPUSwapchainTextureFormat(data->device, renderer->window));
}
data->state.command_buffer = SDL_AcquireGPUCommandBuffer(data->device);
return true;