Skip to content

Commit

Permalink
DXIL: GDK cannot do roundtrips to SPIR-V, compile HLSL directly
Browse files Browse the repository at this point in the history
  • Loading branch information
flibitijibibo committed Dec 21, 2024
1 parent 2a504a4 commit 36a5ef5
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/SDL_shadercross.c
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,9 @@ void *SDL_ShaderCross_CompileDXILFromHLSL(
const SDL_ShaderCross_HLSL_Info *info,
size_t *size)
{
#if SDL_PLATFORM_GDK
return SDL_ShaderCross_INTERNAL_CompileUsingDXC(info, false, size);

This comment has been minimized.

Copy link
@thatcosmonaut

thatcosmonaut Dec 21, 2024

Collaborator

The reason we do a roundtrip is that HLSL features like RWStructuredBuffer require declarations in the buffer that would be troublesome to expose in SDL. The SPIRV-Cross roundtrip converts the RWStructuredBuffer to a byte-addressed buffer which doesn't require these declarations. With this change if the client uses this feature in a shader it will break their application on Xbox.

We might want to have a think about how to work around this or at the very least document that using certain HLSL features requires offline compilation on Xbox.

This comment has been minimized.

Copy link
@flibitijibibo

flibitijibibo Dec 21, 2024

Author Collaborator

Yeah let's document this - this should be easier to ignore once SM7 is out anyway.

This comment has been minimized.

Copy link
@TheSpydog

TheSpydog Dec 21, 2024

Collaborator

Just a thought, we may be able to sidestep the round trip for DXIL specifically if we encourage the use of these DXC functions instead of StructuredBuffers: https://github.com/microsoft/DirectXShaderCompiler/wiki/ByteAddressBuffer-Load-Store-Additions

Basically these provide reasonable ergonomics for working with ByteAddressBuffers rather than manually specifying byte offsets.

FXC of course doesn’t support these functions so we’d still need the sanitization trip through SPIR-V for DXBC.

#else
// Roundtrip to SPIR-V to support things like Structured Buffers.
size_t spirvSize;
void *spirv = SDL_ShaderCross_CompileSPIRVFromHLSL(
Expand Down Expand Up @@ -594,6 +597,7 @@ void *SDL_ShaderCross_CompileDXILFromHLSL(
&translatedHlslInfo,
false,
size);
#endif
}

void *SDL_ShaderCross_CompileSPIRVFromHLSL(
Expand Down

0 comments on commit 36a5ef5

Please sign in to comment.