Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/FNA3D_Driver_SDL.c
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,10 @@ typedef struct SDLGPU_Renderer
SDL_GPUCommandBuffer *renderCommandBuffer;
SDL_GPUCommandBuffer *uploadCommandBuffer;

#ifndef NDEBUG
SDL_ThreadID ownerThreadID;
#endif

SDL_GPURenderPass *renderPass;
uint8_t needNewRenderPass;

Expand Down Expand Up @@ -677,6 +681,17 @@ static inline SDL_GPUTextureFormat XNAToSDL_DepthFormat(
}
}

static inline void SDLGPU_INTERNAL_ThreadCheck(
SDLGPU_Renderer* renderer
) {
#ifndef NDEBUG
if (renderer)
{
SDL_assert(SDL_GetCurrentThreadID() == renderer->ownerThreadID);
}
#endif
}

/* Submission / Presentation */

static void SDLGPU_INTERNAL_BeginCopyPass(
Expand Down Expand Up @@ -811,6 +826,8 @@ static void SDLGPU_INTERNAL_BeginRenderPass(
SDL_GPUDepthStencilTargetInfo depthStencilAttachmentInfo;
uint32_t i;

SDLGPU_INTERNAL_ThreadCheck(renderer);

if (!renderer->needNewRenderPass)
{
return;
Expand Down Expand Up @@ -1297,6 +1314,7 @@ static void SDLGPU_Clear(
int32_t stencil
) {
SDLGPU_Renderer *renderer = (SDLGPU_Renderer*) driverData;
SDLGPU_INTERNAL_ThreadCheck(renderer);
uint8_t clearColor = (options & FNA3D_CLEAROPTIONS_TARGET) == FNA3D_CLEAROPTIONS_TARGET;
uint8_t clearDepth = (options & FNA3D_CLEAROPTIONS_DEPTHBUFFER) == FNA3D_CLEAROPTIONS_DEPTHBUFFER;
uint8_t clearStencil = (options & FNA3D_CLEAROPTIONS_STENCIL) == FNA3D_CLEAROPTIONS_STENCIL;
Expand Down Expand Up @@ -2468,6 +2486,7 @@ static void SDLGPU_DrawInstancedPrimitives(
FNA3D_IndexElementSize indexElementSize
) {
SDLGPU_Renderer *renderer = (SDLGPU_Renderer*) driverData;
SDLGPU_INTERNAL_ThreadCheck(renderer);

/* Note that minVertexIndex/numVertices are NOT used! */

Expand Down Expand Up @@ -2525,6 +2544,7 @@ static void SDLGPU_DrawPrimitives(
int32_t primitiveCount
) {
SDLGPU_Renderer *renderer = (SDLGPU_Renderer*) driverData;
SDLGPU_INTERNAL_ThreadCheck(renderer);

SDLGPU_INTERNAL_BindDeferredState(
renderer,
Expand Down Expand Up @@ -2606,6 +2626,7 @@ static SDLGPU_TextureHandle* SDLGPU_INTERNAL_CreateTextureWithHandle(
SDL_GPUTextureUsageFlags usageFlags,
SDL_GPUSampleCount sampleCount
) {
SDLGPU_INTERNAL_ThreadCheck(renderer);
SDL_GPUTextureCreateInfo textureCreateInfo;
SDL_GPUTexture *texture;
SDLGPU_TextureHandle *textureHandle;
Expand Down Expand Up @@ -3010,6 +3031,7 @@ static void SDLGPU_INTERNAL_SetTextureData(
uint32_t dataLength,
bool cycleTexture
) {
SDLGPU_INTERNAL_ThreadCheck(renderer);
SDL_LockMutex(renderer->copyPassMutex);

SDL_GPUTextureRegion textureRegion;
Expand Down Expand Up @@ -3359,6 +3381,7 @@ static void SDLGPU_INTERNAL_SetBufferData(
uint32_t dataLength,
bool cycle
) {
SDLGPU_INTERNAL_ThreadCheck(renderer);
SDL_LockMutex(renderer->copyPassMutex);

SDL_GPUTransferBufferCreateInfo transferBufferCreateInfo;
Expand Down Expand Up @@ -3524,6 +3547,7 @@ static void SDLGPU_INTERNAL_GetTextureData(
void* data,
uint32_t dataLength
) {
SDLGPU_INTERNAL_ThreadCheck(renderer);
SDL_GPUTextureRegion region;
SDL_GPUTextureTransferInfo textureCopyParams;
SDL_GPUTransferBufferCreateInfo transferBufferCreateInfo;
Expand Down Expand Up @@ -3606,6 +3630,7 @@ static void SDLGPU_INTERNAL_GetBufferData(
void *data,
uint32_t dataLength
) {
SDLGPU_INTERNAL_ThreadCheck(renderer);
SDL_GPUBufferRegion bufferRegion;
SDL_GPUTransferBufferLocation transferLocation;
SDL_GPUTransferBufferCreateInfo transferBufferCreateInfo;
Expand Down Expand Up @@ -3919,6 +3944,7 @@ static void SDLGPU_ApplyEffect(
MOJOSHADER_effectStateChanges *stateChanges
) {
SDLGPU_Renderer *renderer = (SDLGPU_Renderer*) driverData;
SDLGPU_INTERNAL_ThreadCheck(renderer);
SDLGPU_Effect *gpuEffect = (SDLGPU_Effect*) effect;
MOJOSHADER_effect *effectData = gpuEffect->effect;
const MOJOSHADER_effectTechnique *technique = gpuEffect->effect->current_technique;
Expand Down Expand Up @@ -4321,6 +4347,9 @@ static FNA3D_Device* SDLGPU_CreateDevice(
renderer = SDL_malloc(sizeof(SDLGPU_Renderer));
SDL_memset(renderer, '\0', sizeof(SDLGPU_Renderer));

#ifndef NDEBUG
renderer->ownerThreadID = SDL_GetCurrentThreadID();
#endif
renderer->device = device;
renderer->copyPassMutex = SDL_CreateMutex();

Expand Down
Loading