Skip to content

Conversation

SaschaWillems
Copy link
Collaborator

@SaschaWillems SaschaWillems commented Aug 30, 2025

Description

Important note: If you compile shaders locally, you have to use a very recent version of the slang compiler. The one shipped with the SDK is outdated and broken. Make sure to grab the latest one from https://github.com/shader-slang/slang/releases

This adds Slang shaders to additional samples:

  1. buffer device address
  2. calibrated timestamps
  3. color write enable
  4. compute nbody
  5. compute nbody (hpp)
  6. conservative rasterization
  7. conditional rendering
  8. debug utils
  9. descriptor buffer basic
  10. descriptor indexing
  11. dynamic blending
  12. dynamic line rasterization
  13. dynamic multisample rasterization
  14. dynamic primitive clipping
  15. dynamic uniform buffers
  16. dynamic uniform buffers (hpp)
  17. extended dynamic state2
  18. fragment shader barycentric
  19. fragment shading rate
  20. graphics pipeline library
  21. gshader to mshader
  22. hdr
  23. hdr (hpp)
  24. host image copy
  25. instancing
  26. instancing (hpp)
  27. logic op dynamic state
  28. memory budget
  29. mesh shading
  30. mesh shading (hpp)
  31. open cl interop
  32. open gl interop
  33. patch control points
  34. push descriptors
  35. push descriptors (hpp)
  36. portability
  37. ray queries
  38. ray tracing basics
  39. ray tracing extended
  40. ray tracing position fetch
  41. separte image sampler
  42. separte image sampler (hpp)
  43. shader debug printf
  44. sparse image
  45. synchronization 2
  46. terrain tessellation
  47. terrain tessellation (hpp)
  48. texture compression basisu
  49. texture loading
  50. texture loading (hpp)
  51. texture mipmap generation
  52. texture mipmap generation (hpp)
  53. timeline semaphores
  54. timestamp queries
  55. timestamp queries (hpp)
  56. vertex dynamic state

Also enables SPIR-V 1.4 at framework level when using Slang.

Additional notes:

  • Adds a new option VKB_SKIP_SLANG_SHADER_COMPILATION to skip compilation of Slang shaders (you can still use Slang shaders via the precompiled SPIR-V files)
  • Disables Slang offline compilation in CI for MacOS/iOS due to broken Slang compiler in SDK (this step is unnecessary anyway)
  • Some samples may look slightly different than their GLSL counterparts, that's not (easily) fixable

Refs #1385

General Checklist:

Please ensure the following points are checked:

  • My code follows the coding style
  • I have reviewed file licenses
  • I have commented any added functions (in line with Doxygen)
  • I have commented any code that could be hard to understand
  • My changes do not add any new compiler warnings
  • My changes do not add any new validation layer errors or warnings
  • I have used existing framework/helper functions where possible
  • My changes do not add any regressions
  • I have tested every sample to ensure everything runs correctly
  • This PR describes the scope and expected impact of the changes I am making

Note: The Samples CI runs a number of checks including:

  • I have updated the header Copyright to reflect the current year (CI build will fail if Copyright is out of date)
  • My changes build on Windows, Linux, macOS and Android. Otherwise I have documented any exceptions

If this PR contains framework changes:

  • I did a full batch run using the batch command line argument to make sure all samples still work properly

This is needed to get proper support for SPIR-V compiled from Slang shaders
- instancing
- conditional rendering
- conservative rasterization
- dynamic uniform buffers
- descriptor buffer basic
- fragment shading rate
- hdr (+hpp)
- graphics pipeline library
- mesh shading (+hpp)
- texture loading (+hpp)
- push descriptors (+hpp
- open cl interop
- separte image sampler (+hpp)
- texture mipmap generation (+hpp)
- shader debug printf
- texture compression basisu
- compute nbody (+hpp)
- dynamic primitive clipping
- logic op dynamic state
- sparse image
- color write enable
- debug utils
- dynamic line rasterization
- ray queries
- ray tracing basics
- ray tracing extended
- ray tracing position fetch
- terrain tessellation
- patch control points
- synchronization 2
- vertex dynamic state
@SRSaunders
Copy link
Contributor

It looks like two issues are occurring here with Apple CI:

  1. PR Update Apple min deployment versions and iOS Simulator build config #1405 will fix CI issues with macOS (and iOS) when using runners with the latest Sequoia SDKs, as is here.
  2. The iOS CI is also failing because it has access to slang from the Vulkan SDK, and generates an error when compiling the sparse image shader (note: sparse images are not yet supported on Apple):

/Users/runner/work/Vulkan-Samples/Vulkan-Samples/shaders/sparse_image/slang/sparse.frag.slang(45): error 36107: entrypoint 'main' does not support compilation target 'spirv' with stage 'fragment'
float4 main(VSOutput input)
^~~~
/Users/runner/work/Vulkan-Samples/Vulkan-Samples/shaders/sparse_image/slang/sparse.frag.slang(56): note: see using of 'CheckAccessFullyMapped'
} while (!CheckAccessFullyMapped(residencyCode));
** BUILD FAILED **
^~~~~~~~~~~~~~~~~~~~~~

Also note that macOS CI does not access the VulkanSDK and will not try to compile any slang shaders, but would likely fail on the same sparse image shader if it did.

@SaschaWillems
Copy link
Collaborator Author

It's a draft for a reason.

@SRSaunders
Copy link
Contributor

SRSaunders commented Sep 1, 2025

Understood - just trying to help out re issue #1405 since this has nothing to do with your PR, only the Apple CI.

@SaschaWillems
Copy link
Collaborator Author

SaschaWillems commented Sep 1, 2025

You're welcome. We discussed that on one of our calls, and having each CI step rebuild the SPIR-V files that are already part of the repo doesn't make sense anyway. Esp. as the SDK tends to include broken/outdated compilers.

@SRSaunders
Copy link
Contributor

SRSaunders commented Sep 1, 2025

having each CI step rebuild the SPIR-V files that are already part of the repo doesn't make sense anyway

I agree.

However, the scope of the problem may be limited to iOS. At this point iOS seems to be the only CI target that requires and accesses the Vulkan SDK for static linkage to the MoltenVK framework. I believe all other CI targets depend on Vulkan-Headers only without need for the SDK (or compilers), assuming dynamic linkage to the Vulkan runtime library.

@SaschaWillems
Copy link
Collaborator Author

Should put that in a separate issue.

I'd like the comments section of this PR related to the actual PR if possible.

- descriptor indexing
- dyamic blending
- time stamp queries (+hpp)
- host image copy
- fragment shader barycentric
- memory budget
- calibrated timestamps
- dynamic multisample rasterization
- open gl interop
- portability
@SRSaunders
Copy link
Contributor

The Slang compiler in the latest SDK is downright broken.

I get it. However, if you merge this PR all Apple interactive builds will be broken. Could you at least fix this by disabling slangc all the time on Apple?

@SaschaWillems
Copy link
Collaborator Author

This won't be merged until we (inside the samples group) agree. This includes the apple platform discussion.

@SaschaWillems
Copy link
Collaborator Author

Created #1409 to make sure your remarks won't get lost.

@SRSaunders
Copy link
Contributor

Thanks. I too am in favour of a general solution that works across platforms and shading languages.

@gary-sweet
Copy link
Contributor

I don't have a local slang compiler, so I should be running against the pre-built versions.

I am seeing some validation errors (and some other problems which I'll share afterwards). These may, of course, not be anything to do with the slang, but could be compilers problems or spirv-val problems. I thought I'd list them anyway.

compute_nbody
[error] -1307510846 - VUID-StandaloneSpirv-None-10684: vkCreateShaderModule(): pCreateInfo->pCode (spirv-val produced an error): Invalid explicit layout decorations on type for operand '141[%141]' %sharedData = OpVariable %_ptr_Workgroup__arr_v4float_SHARED_DATA_SIZE Workgroup The Vulkan spec states: All variables must have valid explicit layout decorations as described in Shader Interfaces (https://docs.vulkan.org/spec/latest/appendices/spirvenv.html#VUID-StandaloneSpirv-None-10684)

[error] 1132206547 - VUID-VkPipelineShaderStageCreateInfo-pSpecializationInfo-06849: vkCreateComputePipelines(): pCreateInfos[0].stage After specialization was applied, VkShaderModule 0x500000000050 produces a spirv-val error (stage VK_SHADER_STAGE_COMPUTE_BIT): [VUID-StandaloneSpirv-None-10684] Invalid explicit layout decorations on type for operand '141[%141]' %sharedData = OpVariable %_ptr_Workgroup__arr_v4float_SHARED_DATA_SIZE Workgroup The Vulkan spec states: If a shader module identifier is not specified, the shader code used by the pipeline must be valid as described by the Khronos SPIR-V Specification after applying the specializations provided in pSpecializationInfo, if any, and then converting all specialization constants into fixed constants (https://docs.vulkan.org/spec/latest/chapters/pipelines.html#VUID-VkPipelineShaderStageCreateInfo-pSpecializationInfo-06849)

hello_triangle
[error] -1520283006 Validation Layer: Error: VUID-VkShaderModuleCreateInfo-pCode-08737: vkCreateShaderModule(): pCreateInfo->pCode (spirv-val produced an error): Invalid SPIR-V binary version 1.4 for target environment SPIR-V 1.3 (under Vulkan 1.1 semantics). The Vulkan spec states: If pCode is a pointer to SPIR-V code, pCode must adhere to the validation rules described by the Validation Rules within a Module section of the SPIR-V Environment appendix (https://docs.vulkan.org/spec/latest/chapters/shaders.html#VUID-VkShaderModuleCreateInfo-pCode-08737)

hpp_compute_nbody
[error] -1307510846 - VUID-StandaloneSpirv-None-10684: vkCreateShaderModule(): pCreateInfo->pCode (spirv-val produced an error): Invalid explicit layout decorations on type for operand '141[%141]' %sharedData = OpVariable %_ptr_Workgroup__arr_v4float_SHARED_DATA_SIZE Workgroup The Vulkan spec states: All variables must have valid explicit layout decorations as described in Shader Interfaces (https://docs.vulkan.org/spec/latest/appendices/spirvenv.html#VUID-StandaloneSpirv-None-10684)

[error] 1132206547 - VUID-VkPipelineShaderStageCreateInfo-pSpecializationInfo-06849: vkCreateComputePipelines(): pCreateInfos[0].stage After specialization was applied, VkShaderModule 0x500000000050 produces a spirv-val error (stage VK_SHADER_STAGE_COMPUTE_BIT): [VUID-StandaloneSpirv-None-10684] Invalid explicit layout decorations on type for operand '141[%141]' %sharedData = OpVariable %_ptr_Workgroup__arr_v4float_SHARED_DATA_SIZE Workgroup The Vulkan spec states: If a shader module identifier is not specified, the shader code used by the pipeline must be valid as described by the Khronos SPIR-V Specification after applying the specializations provided in pSpecializationInfo, if any, and then converting all specialization constants into fixed constants (https://docs.vulkan.org/spec/latest/chapters/pipelines.html#VUID-VkPipelineShaderStageCreateInfo-pSpecializationInfo-06849)

hpp_texture_mipmap_generation
[error] -1307510846 - VUID-StandaloneSpirv-None-10684: vkCreateShaderModule(): pCreateInfo->pCode (spirv-val produced an error): Invalid explicit layout decorations on type for operand '24[%24]' %samplers = OpVariable %_ptr_UniformConstant__arr_23_int_3 UniformConstant The Vulkan spec states: All variables must have valid explicit layout decorations as described in Shader Interfaces (https://docs.vulkan.org/spec/latest/appendices/spirvenv.html#VUID-StandaloneSpirv-None-10684)

color_write_enable
[error] 115483881 - VUID-VkShaderModuleCreateInfo-pCode-08740: vkCreateShaderModule(): SPIR-V Capability StorageImageReadWithoutFormat was declared, but one of the following requirements is required (VkPhysicalDeviceFeatures::shaderStorageImageReadWithoutFormat OR VK_VERSION_1_3 OR VK_KHR_format_feature_flags2). The Vulkan spec states: If pCode is a pointer to SPIR-V code, and pCode declares any of the capabilities listed in the SPIR-V Environment appendix, one of the corresponding requirements must be satisfied (https://docs.vulkan.org/spec/latest/chapters/shaders.html#VUID-VkShaderModuleCreateInfo-pCode-08740)

synchronization_2
[error] -1307510846 - VUID-StandaloneSpirv-None-10684: vkCreateShaderModule(): pCreateInfo->pCode (spirv-val produced an error): Invalid explicit layout decorations on type for operand '141[%141]' %sharedData = OpVariable %_ptr_Workgroup__arr_v4float_SHARED_DATA_SIZE Workgroup The Vulkan spec states: All variables must have valid explicit layout decorations as described in Shader Interfaces (https://docs.vulkan.org/spec/latest/appendices/spirvenv.html#VUID-StandaloneSpirv-None-10684)

[error] 1132206547 - VUID-VkPipelineShaderStageCreateInfo-pSpecializationInfo-06849: vkCreateComputePipelines(): pCreateInfos[0].stage After specialization was applied, VkShaderModule 0xf2f0000000f2f produces a spirv-val error (stage VK_SHADER_STAGE_COMPUTE_BIT): [VUID-StandaloneSpirv-None-10684] Invalid explicit layout decorations on type for operand '141[%141]' %sharedData = OpVariable %_ptr_Workgroup__arr_v4float_SHARED_DATA_SIZE Workgroup The Vulkan spec states: If a shader module identifier is not specified, the shader code used by the pipeline must be valid as described by the Khronos SPIR-V Specification after applying the specializations provided in pSpecializationInfo, if any, and then converting all specialization constants into fixed constants (https://docs.vulkan.org/spec/latest/chapters/pipelines.html#VUID-VkPipelineShaderStageCreateInfo-pSpecializationInfo-06849)

@SaschaWillems
Copy link
Collaborator Author

Thanks for testing 👍🏻

Most of the validation errors were caused by the Slang version that I used generating invalid SPIR-V. I have recompiled the shaders with a newer versions and most samples should now be free of validation errors.

For some like hello triangle and color write enable, the samples need special handling when using Slang shaders due to a slightly different shading environment.

Will try to fix these next.

@SaschaWillems
Copy link
Collaborator Author

hello_triangle and color_write_enable should also be fixed now.

Copy link
Contributor

@gary-sweet gary-sweet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks much better now, but I did still see conditional rendering looking different. This is why.

gary-sweet
gary-sweet previously approved these changes Sep 23, 2025
Copy link
Contributor

@gary-sweet gary-sweet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

float2 CenterPos;
float PSize : SV_PointSize;
// remove
float PointSize;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would, instead of PSize and PointSize something like
float PointSize : SV_PointSize;
be enough?

{
float4 Pos : SV_POSITION;
float GradientPos;
float2 CenterPos;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is CenterPos some kind of emulation of the gl_PointCoord?
I could not find a lot about the semantic name SV_PointCoord, but would that be the right approach, somehow?

float4 main(VSOutput input)
{
float3 color = samplerGradientRamp.Sample(float2(input.GradientPos, 0.0)).rgb;
float2 PointCoord = (input.Pos.xy - input.CenterPos.xy) / input.PointSize + 0.5;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't follow the math behind PointCoord.
Maybe some comment describing this?

{
float3 Pos;
float3 Normal;
float3 Color;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This Color is not used. Can it be removed?

[shader("fragment")]
float4 main(VSOutput input)
{
return float4(input.Color, 1.0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The corresponding glsl-shader also returns a vec4, but just sets rgb.
Shouldn't we fix that right here?

[shader("fragment")]
float4 main()
{
return float4(1.0, 1.0, 1.0, 1.0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here again, the corresponding glsl-shader returns a vec4, but just sets rgb.
Should be fixed there.

0.0118349786570722,
0.0073599963704157,
0.0043538453346397,
0.0024499299678342};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you change the tab width, you see that those numbers are not aligned any more.



const float blurScale = 0.003;
const float blurStrength = 1.0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These constants are different in the corresponding glsl-shader.

ar = ts.y / ts.x;
}

float2 P = inUV.yx - float2(0, (25 >> 1) * ar * blurScale);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The corresponding glsl-shader uses weights.length(), instead of the magic 25.
Is something like that length() not available in slang (and hlsl as well)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mixing tabs and spaces in this file.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also mixing tabs and spaces here.


switch(object_type) {
case 0: // Skybox
worldPos = mul((float4x3) ubo.skyboxModelview, input.Pos).xyz;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't you cast ubo.skyboxModelView to a float3x3?
Or do not cast at all, but extend input.Pos to a float4?

I don't know, what's more efficient.

output.Pos = mul(ubo.projection, mul(ubo.modelview, float4(localPos, 1.0)));
break;
}
output.Normal = mul((float4x3)ubo.modelview, input.Normal).xyz;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, a float4x3 cast.

output.Normal = mul((float4x3)ubo.modelview, input.Normal).xyz;
output.UV = input.UV;

float3 lightPos = float3(0.0f, -5.0f, 5.0f);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The corresponding glsl-shader calculates a different lightPos.

struct VSOutput
{
float4 Pos : SV_POSITION;
float3 Normal;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Normal isn't used here.

{
float4 Pos : SV_POSITION;
float2 UV;
uint ColorOffset;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the ColorOffset need the nointerpolation interpolation modifier?

float4 color = input.BaseColorFactor;

if (input.BaseTextureIndex != -1)
color = Textures[uint(round(input.BaseTextureIndex))].Sample(input.UV);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know, you did not change that part of the code, but why is it needed to round a not interpolated uint and cast it to an uint again?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some tab-and-space mixing in this file.

float RoughnessFactor;
uint BaseTextureIndex;
uint NormalTextureIndex;
uint MetallicRoughnessTextureIndex;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to mark the last five members as nointerpolation?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, some tab-and-space mixing.

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.

4 participants