Skip to content

Commit

Permalink
Add point_size fixup for MSL+sdlgpu
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSpydog committed Nov 4, 2024
1 parent 32ae391 commit afc2d73
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions mojoshader_sdlgpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,8 @@ static MOJOSHADER_sdlProgram *compile_program(
return NULL;
} // if

const char *vshaderSource = vshader->parseData->output;
const char *pshaderSource = pshader->parseData->output;
size_t vshaderCodeSize = vshader->parseData->output_len;
size_t pshaderCodeSize = pshader->parseData->output_len;

Expand Down Expand Up @@ -645,9 +647,33 @@ static MOJOSHADER_sdlProgram *compile_program(
vshaderCodeSize -= sizeof(SpirvPatchTable);
pshaderCodeSize -= sizeof(SpirvPatchTable);
}
else if (shader_format == SDL_GPU_SHADERFORMAT_MSL)
{
// Handle texcoord0 -> point_coord conversion
if (strstr(vshaderSource, "[[point_size]]"))
{
pshaderSource = strdup(pshader->parseData->output);

// !!! FIXME: This assumes all texcoord0 attributes in the effect are
// !!! FIXME: actually point coords! It ain't necessarily so! -caleb
const char *repl = "[[ point_coord ]]";
char *ptr;
while ((ptr = strstr(pshaderSource, "[[user(texcoord0)]]")))
{
memcpy(ptr, repl, strlen(repl));

// "float4" -> "float2"
int spaces = 0;
while (spaces < 2)
if (*(ptr--) == ' ')
spaces++;
memcpy(ptr, "2", sizeof(char));
} // while
} // if
}

SDL_zero(createInfo);
createInfo.code = (const Uint8*) vshader->parseData->output;
createInfo.code = (const Uint8*) vshaderSource;
createInfo.code_size = vshaderCodeSize;
createInfo.entrypoint = vshader->parseData->mainfn;
createInfo.format = shader_format;
Expand All @@ -667,7 +693,7 @@ static MOJOSHADER_sdlProgram *compile_program(
return NULL;
} // if

createInfo.code = (const Uint8*) pshader->parseData->output;
createInfo.code = (const Uint8*) pshaderSource;
createInfo.code_size = pshaderCodeSize;
createInfo.entrypoint = pshader->parseData->mainfn;
createInfo.format = shader_format;
Expand Down

0 comments on commit afc2d73

Please sign in to comment.