Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Pipeline Layouts from Shader Reflection #68

Merged
merged 19 commits into from
Aug 3, 2022
Merged

Conversation

crud89
Copy link
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 An implementation is required before the next release. Module: Vulkan 🌋 The issue involves the Vulkan backend. Module: 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
Module: DX12 ❎ The issue involves the DX12 backend. Module: Vulkan 🌋 The issue involves the Vulkan backend. Priority: Medium A issue with normal priority. Type: Requirement An implementation is required before the next release.
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