diff --git a/src/FNA3D_Driver_SDL.c b/src/FNA3D_Driver_SDL.c index 94b4bc3e..6d8368e6 100644 --- a/src/FNA3D_Driver_SDL.c +++ b/src/FNA3D_Driver_SDL.c @@ -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; @@ -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( @@ -811,6 +826,8 @@ static void SDLGPU_INTERNAL_BeginRenderPass( SDL_GPUDepthStencilTargetInfo depthStencilAttachmentInfo; uint32_t i; + SDLGPU_INTERNAL_ThreadCheck(renderer); + if (!renderer->needNewRenderPass) { return; @@ -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; @@ -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! */ @@ -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, @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; @@ -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();