Skip to content

Commit

Permalink
fix pass structure
Browse files Browse the repository at this point in the history
  • Loading branch information
thatcosmonaut committed Mar 27, 2024
1 parent 5710f5e commit 848e200
Showing 1 changed file with 53 additions and 16 deletions.
69 changes: 53 additions & 16 deletions src/FNA3D_Driver_SDL.c
Original file line number Diff line number Diff line change
Expand Up @@ -1094,6 +1094,8 @@ typedef struct SDLGPU_Renderer
uint8_t renderPassInProgress;
uint8_t needNewRenderPass;

uint8_t copyPassInProgress;

uint8_t shouldClearColorOnBeginPass;
uint8_t shouldClearDepthOnBeginPass;
uint8_t shouldClearStencilOnBeginPass;
Expand Down Expand Up @@ -1232,9 +1234,37 @@ static void SDLGPU_ResetCommandBufferState(
);
}

static void SDLGPU_INTERNAL_EndPass(
SDLGPU_Renderer *renderer
) {
if (renderer->renderPassInProgress)
{
SDL_GpuEndRenderPass(
renderer->device,
renderer->commandBuffer
);
}

if (renderer->copyPassInProgress)
{
SDL_GpuEndCopyPass(
renderer->device,
renderer->commandBuffer
);
}

renderer->renderPassInProgress = 0;
renderer->copyPassInProgress = 0;
renderer->needNewRenderPass = 1;
renderer->currentGraphicsPipeline = NULL;
renderer->needNewGraphicsPipeline = 1;
}

static void SDLGPU_INTERNAL_FlushCommandsAndStall(
SDLGPU_Renderer *renderer
) {
SDLGPU_INTERNAL_EndPass(renderer);

SDL_GpuFence *fence = SDL_GpuSubmitAndAcquireFence(
renderer->device,
renderer->commandBuffer
Expand All @@ -1258,6 +1288,7 @@ static void SDLGPU_INTERNAL_FlushCommandsAndStall(
static void SDLGPU_INTERNAL_FlushCommands(
SDLGPU_Renderer *renderer
) {
SDLGPU_INTERNAL_EndPass(renderer);
SDL_GpuSubmit(renderer->device, renderer->commandBuffer);
SDLGPU_ResetCommandBufferState(renderer);
}
Expand All @@ -1275,6 +1306,8 @@ static void SDLGPU_SwapBuffers(
SDL_GpuTextureRegion dstRegion;
uint32_t width, height;

SDLGPU_INTERNAL_EndPass(renderer);

swapchainTexture = SDL_GpuAcquireSwapchainTexture(
renderer->device,
renderer->commandBuffer,
Expand Down Expand Up @@ -1477,22 +1510,6 @@ static void SDLGPU_Clear(
);
}

static void SDLGPU_INTERNAL_EndPass(
SDLGPU_Renderer *renderer
) {
if (renderer->renderPassInProgress)
{
SDL_GpuEndRenderPass(
renderer->device,
renderer->commandBuffer
);

renderer->currentGraphicsPipeline = NULL;
renderer->needNewGraphicsPipeline = 1;
renderer->renderPassInProgress = 0;
}
}

static void SDLGPU_INTERNAL_BeginRenderPass(
SDLGPU_Renderer *renderer
) {
Expand Down Expand Up @@ -3049,6 +3066,22 @@ static void SDLGPU_AddDisposeRenderbuffer(
SDL_free(renderbufferHandle);
}

static void SDLGPU_INTERNAL_BeginCopyPass(
SDLGPU_Renderer *renderer
) {
if (!renderer->copyPassInProgress)
{
SDLGPU_INTERNAL_EndPass(renderer);

SDL_GpuBeginCopyPass(
renderer->device,
renderer->commandBuffer
);

renderer->copyPassInProgress = 1;
}
}

static void SDLGPU_INTERNAL_SetTextureData(
SDLGPU_Renderer *renderer,
SDL_GpuTexture *texture,
Expand All @@ -3067,6 +3100,8 @@ static void SDLGPU_INTERNAL_SetTextureData(
SDL_GpuTextureRegion textureRegion;
SDL_GpuBufferImageCopy textureCopyParams;

SDLGPU_INTERNAL_BeginCopyPass(renderer);

/* Recreate transfer buffer if necessary */
if (renderer->textureUploadBufferOffset + dataLength >= renderer->textureUploadBufferSize)
{
Expand Down Expand Up @@ -3421,6 +3456,8 @@ static void SDLGPU_INTERNAL_SetBufferData(
SDL_GpuBufferCopy transferCopyParams;
SDL_GpuBufferCopy uploadParams;

SDLGPU_INTERNAL_BeginCopyPass(renderer);

/* Recreate transfer buffer if necessary */
if (renderer->bufferUploadBufferOffset + dataLength >= renderer->bufferUploadBufferSize)
{
Expand Down

0 comments on commit 848e200

Please sign in to comment.