Skip to content

Fix: Push constants to perform compile-time validation #42

Description

@mrparmesan01

Issue Overview

Push constants have a minimum guarantee of pushing data transfers quickly up to 128 bytes to the GPU. Currently, there is an existing bug.

vk::pipeline::push_constant does not guarantee the data being pushed is 128 bytes or less. This should have some static_assert to ensure this is known to the user at compile-time.

What does the fix for this look like?

I am proposing this to be changed to using a template. Where we use a static_assert to determine the data being pushed does not exceed the minimum guarantee amount of bytes of data over to the GPU.

Example Implementation

An example implementation, I could see being done to the implementation of the function would be done similar to the following.

template<typename T>
void pipeline::push_constant(const VkCommandBuffer& p_current,
        shader_stage p_stage,
        const T& p_data,
        uint32_t p_offset=0) {

    vkCmdPushConstants(p_current,
        m_pipeline_layout,
        static_cast<VkShaderStageFlags>(p_stage),
        p_offset,
        sizeof(T), // size of bytes of data being pushed
        &p_data // pointer to the data pushed
    );

}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ✨improvementImproving existing designs.💳 Tech DebtTasks that have some kind of user API tech debt

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions