Skip to content

Create Pipeline Layouts from Shader Reflection#68

Merged
crud89 merged 19 commits intomainfrom
shader-reflection
Aug 3, 2022
Merged

Create Pipeline Layouts from Shader Reflection#68
crud89 merged 19 commits intomainfrom
shader-reflection

Conversation

@crud89
Copy link
Copy Markdown
Owner

@crud89 crud89 commented Aug 2, 2022

Describe the pull request

This PR adds support for creating pipeline layouts from shader reflection. Currently pipeline layouts need to be explicitly defined in code:

SharedPtr<ShaderProgram> shaderProgram = device->buildShaderProgram()
    .withVertexShaderModule("shaders/basic_vs." + FileExtensions<TRenderBackend>::SHADER)
    .withFragmentShaderModule("shaders/basic_fs." + FileExtensions<TRenderBackend>::SHADER)); 

UniquePtr<RenderPipeline> renderPipeline = device->buildRenderPipeline(*renderPass, "Pipeline")
    .layout(device->buildPipelineLayout()
        .descriptorSet(DescriptorSets::Constant, ShaderStage::Vertex | ShaderStage::Fragment)
            .withUniform(0, sizeof(CameraBuffer))
            .add()
        .descriptorSet(DescriptorSets::PerFrame, ShaderStage::Vertex)
            .withUniform(0, sizeof(TransformBuffer))
            .add())
    .shaderProgram(shaderProgram);

With this PR, it is possible to generate a layout directly from the shader program by calling reflectPipelineLayout on it:

SharedPtr<ShaderProgram> shaderProgram = device->buildShaderProgram()
    .withVertexShaderModule("shaders/basic_vs." + FileExtensions<TRenderBackend>::SHADER)
    .withFragmentShaderModule("shaders/basic_fs." + FileExtensions<TRenderBackend>::SHADER)); 

UniquePtr<RenderPipeline> renderPipeline = device->buildRenderPipeline(*renderPass, "Pipeline")
    .layout(shaderProgram->reflectPipelineLayout())
    .shaderProgram(shaderProgram);

Additionally, in DirectX, it is not possible to define input attachments as subpass references. Instead the engine automatically defines a static sampler at register s0 of space 0. With reflection, render targets are being treated as normal texture descriptors, since it is not possible to tell them apart based on their usage. The static sampler, however, is currently not supported to be de-serialized. To solve this, the pipeline layout is improved with support for static samplers.

Related issues

A designated topic regarding shaders can be found in the project wiki.

@crud89 crud89 added Priority: Medium A issue with normal priority. Type: Requirement Vulkan 🌋 The issue involves the Vulkan backend. DX12 ❎ The issue involves the DX12 backend. labels Aug 2, 2022
@crud89 crud89 added this to the Alpha #03 milestone Aug 2, 2022
@crud89 crud89 self-assigned this Aug 2, 2022
@crud89 crud89 marked this pull request as ready for review August 3, 2022 11:04
@crud89 crud89 merged commit 312b64b into main Aug 3, 2022
@crud89 crud89 deleted the shader-reflection branch August 10, 2022 06:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

DX12 ❎ The issue involves the DX12 backend. Priority: Medium A issue with normal priority. Vulkan 🌋 The issue involves the Vulkan backend.

Projects

Status: v0.3.1

Development

Successfully merging this pull request may close these issues.

Support static/immutable Samplers Allow descriptor set to be build from shader reflection

1 participant