Skip to content

Conversation

@s-perron
Copy link
Contributor

@s-perron s-perron commented Nov 7, 2025

This commit introduces support for specialization constants in the Vulkan backend.

Key changes:

  • Added struct to to represent a specialization constant with its ID, type, and value.
  • Updated YAML mapping in to parse specialization constants from the test configuration.
  • Modified to create and use when creating the compute pipeline, allowing specialization constants to be passed to the shader.
  • Added a new test case in to verify the functionality of specialization constants with various data types (bool, int, uint, float).

Fixes llvm/llvm-project#142992

This commit introduces support for specialization constants in the Vulkan backend.

Key changes:
- Added  struct to  to represent a specialization constant with its ID, type, and value.
- Updated YAML mapping in  to parse specialization constants from the test configuration.
- Modified  to create and use  when creating the compute pipeline, allowing specialization constants to be passed to the shader.
- Added a new test case in  to verify the functionality of specialization constants with various data types (bool, int, uint, float).

Fixes llvm/llvm-project#142992
@s-perron s-perron requested a review from Keenuts November 7, 2025 20:50
case DataFormat::Float32: {
float Value = 0.0f;
double Tmp = 0.0;
llvm::StringRef(SpecConst.Value).getAsDouble(Tmp);
Copy link
Contributor

Choose a reason for hiding this comment

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

If the string is not a valid number, this seem to return true. Shall this be checked and reported as fatal instead of silently keeping the default of 0.0f?

llvm::SmallVector<char> SpecData;
VkSpecializationInfo SpecInfo = {};
if (!Shader.SpecializationConstants.empty()) {
for (const auto &SpecConst : Shader.SpecializationConstants) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Vulkan requires the constant ID to be unique (VUID-VkSpecializationInfo-constantID-04911). Seems like this is not enforced here, so a bad config file could lead to problems/UB at runtime depending on the VK implementation no?

@@ -0,0 +1,87 @@
#--- simple.hlsl
Copy link
Contributor

Choose a reason for hiding this comment

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

you should test we can reuse the same spec-id on the HLSL/SPIR-V side, but not in the YAML config (or at least that we correctly emit an error or something loud)

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.

[HLSL] Add vk::constant_id tests to the offload test suite

2 participants