Skip to content

Require Vulkan 1.1 for wave intrinsics#138

Open
jcaw wants to merge 1 commit into
libsdl-org:mainfrom
jcaw:wave-intrisics-fix
Open

Require Vulkan 1.1 for wave intrinsics#138
jcaw wants to merge 1 commit into
libsdl-org:mainfrom
jcaw:wave-intrisics-fix

Conversation

@jcaw

@jcaw jcaw commented May 14, 2025

Copy link
Copy Markdown

Shader Model 6.0 has support for GPU features such as wave intrinsics, e.g. WaveGetLaneCount, WaveActiveSum and WaveGetLaneIndex. Shadercross currently compiles HLSL shaders for SM 6.0:

if (info->shader_stage == SDL_SHADERCROSS_SHADERSTAGE_VERTEX) {
args[argCount++] = (LPCWSTR)L"-T";
args[argCount++] = (LPCWSTR)L"vs_6_0";
} else if (info->shader_stage == SDL_SHADERCROSS_SHADERSTAGE_FRAGMENT) {
args[argCount++] = (LPCWSTR)L"-T";
args[argCount++] = (LPCWSTR)L"ps_6_0";
} else { // compute
args[argCount++] = (LPCWSTR)L"-T";
args[argCount++] = (LPCWSTR)L"cs_6_0";
}

In order to support cross-compilation of HLSL shaders utilising these features to SPIR-V, spirv-cross requires a minimum of Vulkan 1.1. If this is not set explicitly, it will complain and refuse to compile the shader - this currently makes wave intrinsics unusable.

In order to specify the target environment, we need to pass -fspv-target-env as a command line parameter to spirv-cross. This PR passes Vulkan 1.1 as the target environment when compiling to SPIR-V, to support these Shader Model 6.0 features.

I have tested this support with b0nes164's implementation of GPU Prefix Sum, which utilizes wave intrinsics, and with Vulkan 1.1 required, these shaders compile to SPIR-V and execute successfully.

@thatcosmonaut

Copy link
Copy Markdown
Collaborator

This should definitely be optional since SDL GPU only requires Vulkan 1.0 conformance.

Shader Model 6.0 has support for GPU features such as wave intrinsics,
e.g. `WaveGetLaneCount`, `WaveActiveSum` and `WaveGetLaneIndex`.
Shadercross currently compiles HLSL shaders under SM 6.0.

In order to support cross-compilation of HLSL shaders utilising these
features to SPIR-V, spirv-cross requires a minimum of Vulkan 1.1. If
this is not set explicitly, it will complain and refuse to compile the
shader - this makes wave intrinsics unusable.

In order to specify the target environment, we need to pass
`-fspv-target-env` as a command line parameter to spirv-cross. This
commit passes Vulkan 1.1 as the target environment when compiling to
SPIR-V, to support these Shader Model 6.0 features.

I have tested this support with b0nes164's implementation of GPU Prefix
Sum[1], which utilizes wave intrinsics to increase performance, and with
Vulkan 1.1 required, these shaders compile to SPIR-V and execute
successfully.

  [1] https://github.com/b0nes164/GPUPrefixSums/tree/98d93a4e9ed2f3c8353119515bf9be90a2e137ad/GPUPrefixSumsD3D12
@jcaw jcaw force-pushed the wave-intrisics-fix branch from 71d25b3 to 31e42bb Compare October 23, 2025 17:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants