Skip to content

Commit

Permalink
Expose enough SysRenderer gunk for the user to be able to create SDL …
Browse files Browse the repository at this point in the history
…textures

Implement SysTexture for SDL_GPU backend
Add some asserts
Update for typo fix in SDL_GPU headers
  • Loading branch information
kg committed Jan 1, 2025
1 parent c3d99b9 commit 162c1c3
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 7 deletions.
21 changes: 21 additions & 0 deletions include/FNA3D_SysRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,20 @@ typedef struct FNA3D_SysRendererEXT
uint32_t queueFamilyIndex;
} vulkan;
#endif /* FNA3D_DRIVER_VULKAN */
#if FNA3D_DRIVER_SDL
struct
{
// FIXME: This definition is incomplete! -kg
SDL_GPUDevice *device;
// Reserved pointers to create space for things we need to expose later, for compatibility
void *reserved1,
*reserved2,
*reserved3,
*reserved4,
*reserved5,
*reserved6;
} sdl;
#endif
uint8_t filler[64];
} renderer;
} FNA3D_SysRendererEXT;
Expand Down Expand Up @@ -131,6 +145,13 @@ typedef struct FNA3D_SysTextureEXT
FNA3D_VULKAN_HANDLE_TYPE view; /* VkImageView */
} vulkan;
#endif /* FNA3D_DRIVER_VULKAN */
#if FNA3D_DRIVER_SDL
struct
{
void /* SDL_GPUTexture */ *texture;
void /* SDL_GPUTextureCreateInfo */ *createInfo;
} sdl;
#endif
uint8_t filler[64];
} texture;
} FNA3D_SysTextureEXT;
Expand Down
36 changes: 29 additions & 7 deletions src/FNA3D_Driver_SDL.c
Original file line number Diff line number Diff line change
Expand Up @@ -1377,7 +1377,9 @@ static void SDLGPU_INTERNAL_GenerateVertexInputInfo(
{
element = vertexDeclaration.elements[j];
usage = element.vertexElementUsage;
SDL_assert(usage < MOJOSHADER_USAGE_TOTAL);
index = element.usageIndex;
SDL_assert(index < sizeof(attrUse[usage]));

if (attrUse[usage][index])
{
Expand Down Expand Up @@ -1836,7 +1838,9 @@ static void SDLGPU_VerifyVertexSampler(

if (vertShader)
{
samplerType = MOJOSHADER_sdlGetShaderParseData(vertShader)->samplers[index].type;
MOJOSHADER_parseData *parseData = MOJOSHADER_sdlGetShaderParseData(vertShader);
SDL_assert(parseData);
samplerType = parseData->samplers[index].type;

if (samplerType == MOJOSHADER_SAMPLER_2D)
{
Expand Down Expand Up @@ -1898,7 +1902,9 @@ static void SDLGPU_VerifySampler(

if (fragShader)
{
samplerType = MOJOSHADER_sdlGetShaderParseData(fragShader)->samplers[index].type;
MOJOSHADER_parseData* parseData = MOJOSHADER_sdlGetShaderParseData(fragShader);
SDL_assert(parseData);
samplerType = parseData->samplers[index].type;
if (samplerType == MOJOSHADER_SAMPLER_2D)
{
renderer->fragmentTextureSamplerBindings[index].texture = renderer->dummyTexture2D;
Expand Down Expand Up @@ -2642,7 +2648,7 @@ static void SDLGPU_ResetBackbuffer(
{
if (presentationParameters->backBufferFormat == FNA3D_SURFACEFORMAT_RGBA1010102)
{
swapchainComposition = SDL_GPU_SWAPCHAINCOMPOSITION_HDR10_ST2048;
swapchainComposition = SDL_GPU_SWAPCHAINCOMPOSITION_HDR10_ST2084;
}
else if ( presentationParameters->backBufferFormat == FNA3D_SURFACEFORMAT_HALFVECTOR4 ||
presentationParameters->backBufferFormat == FNA3D_SURFACEFORMAT_HDRBLENDABLE )
Expand Down Expand Up @@ -4037,17 +4043,33 @@ static void SDLGPU_GetSysRenderer(
FNA3D_Renderer *driverData,
FNA3D_SysRendererEXT *sysrenderer
) {
/* TODO */
SDLGPU_Renderer* renderer = (SDLGPU_Renderer*)driverData;

SDL_memset(sysrenderer, '\0', sizeof(FNA3D_SysRendererEXT));
sysrenderer->rendererType = FNA3D_RENDERER_TYPE_SDL_GPU_EXT;
sysrenderer->renderer.sdl.device = renderer->device;
// FIXME: Expose other necessary pointers. -kg
}

static FNA3D_Texture* SDLGPU_CreateSysTexture(
FNA3D_Renderer *driverData,
FNA3D_SysTextureEXT *systexture
) {
/* TODO */
return NULL;
SDLGPU_TextureHandle* result;

if (systexture->rendererType != FNA3D_RENDERER_TYPE_SDL_GPU_EXT)
{
return NULL;
}

result = (SDLGPU_TextureHandle*)SDL_malloc(sizeof(SDLGPU_TextureHandle));
SDL_zerop(result);

result->texture = systexture->texture.sdl.texture;
result->createInfo = *(SDL_GPUTextureCreateInfo *)systexture->texture.sdl.createInfo;
result->boundAsRenderTarget = 0;

return (FNA3D_Texture*)result;
}

/* Destroy */
Expand Down Expand Up @@ -4223,7 +4245,7 @@ static FNA3D_Device* SDLGPU_CreateDevice(
{
if (presentationParameters->backBufferFormat == FNA3D_SURFACEFORMAT_RGBA1010102)
{
swapchainComposition = SDL_GPU_SWAPCHAINCOMPOSITION_HDR10_ST2048;
swapchainComposition = SDL_GPU_SWAPCHAINCOMPOSITION_HDR10_ST2084;
}
else if ( presentationParameters->backBufferFormat == FNA3D_SURFACEFORMAT_HALFVECTOR4 ||
presentationParameters->backBufferFormat == FNA3D_SURFACEFORMAT_HDRBLENDABLE )
Expand Down

0 comments on commit 162c1c3

Please sign in to comment.