Skip to content

gpuav: Use push constant inside shader#12461

Open
spencer-lunarg wants to merge 1 commit into
KhronosGroup:mainfrom
spencer-lunarg:spencer-lunarg-push-constant-hacking-30000-feet-in-the-air-like-a-compiler-engineer-i-guess
Open

gpuav: Use push constant inside shader#12461
spencer-lunarg wants to merge 1 commit into
KhronosGroup:mainfrom
spencer-lunarg:spencer-lunarg-push-constant-hacking-30000-feet-in-the-air-like-a-compiler-engineer-i-guess

Conversation

@spencer-lunarg

Copy link
Copy Markdown
Contributor

So this saves us from currently copying the entire push data/constant range EVERY draw/dispatch to a SSBO buffer... instead since we are in the shader, I just read the actual push constant data!

When the user has a layout(push_constant) already, we can't create our own block and instead use Untyped pointers to do type punning

... only issue (which will probably fail CI) is that you hit this VU in self validation

Validation Error: [ VUID-vkCmdDispatch-None-11376 ] | MessageID = 0xb40dc3ee
[Self Validation] vkCmdDispatch(): shader [VK_SHADER_STAGE_COMPUTE_BIT] uses push-constant statically at range [0, 256), but vkCmdPushDataEXT was never called for range [0, 79).
The Vulkan spec states: If a bound shader was created as a VkShaderEXT with the VK_SHADER_CREATE_DESCRIPTOR_HEAP_BIT_EXT flag or as part of a pipeline with the VK_PIPELINE_CREATE_2_DESCRIPTOR_HEAP_BIT_EXT flag, and that shader statically uses a push constant value, that value must have been set by vkCmdPushDataEXT (https://docs.vulkan.org/spec/latest/chapters/dispatch.html#VUID-vkCmdDispatch-None-11376)

which I think is a bit non-sense so raised https://gitlab.khronos.org/vulkan/vulkan/-/issues/4869 to figure out what is "actually" allowed or not

@spencer-lunarg spencer-lunarg requested a review from a team as a code owner June 15, 2026 19:08
@ci-tester-lunarg

Copy link
Copy Markdown
Collaborator

CI Vulkan-ValidationLayers build queued with queue ID 5287.

@ci-tester-lunarg

Copy link
Copy Markdown
Collaborator

CI Vulkan-ValidationLayers build # 23620 running.

@ci-tester-lunarg

Copy link
Copy Markdown
Collaborator

CI Vulkan-ValidationLayers build # 23620 failed.


// will generate [OpCompositeConstruct, OpBitcast, OpConvertUToPtr] which should be fine as a compromise keeping the push_data in a uint array
uint64_t indirect_address = packUint2x32(uvec2(gpuav.push_data[push_offset], gpuav.push_data[push_offset + 1]));
uint64_t indirect_address = packUint2x32(uvec2(indirect_address_hi, indirect_address_low));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

According to https://registry.khronos.org/OpenGL/extensions/ARB/ARB_gpu_shader_int64.txt
it should be uvec2(low, high), it is reversed here. But then it should have exploded somehow?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah yes looking at:

        const uint32_t indirect_address_hi = GetInternalPushData(block, inst_it, push_offset);
        const uint32_t indirect_address_low = GetInternalPushData(block, inst_it, push_offset + 1);

high and low are inverted

}

// Just currently always make a new one
const Type& TypeManager::GetTypeUntypedPointer(spv::StorageClass storage_class) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

what a name

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.

3 participants