src/third_party/angle/src/libANGLE/renderer/vulkan/UtilsVk.cpp
// Creates a shader that looks like the following, based on the number and types of unresolve
// attachments.
//
//     #version 450 core
//     #extension GL_ARB_shader_stencil_export : require
//
//     layout(location = 0) out vec4 colorOut0;
//     layout(location = 1) out ivec4 colorOut1;
//     layout(location = 2) out uvec4 colorOut2;
//     layout(input_attachment_index = 0, set = 0, binding = 0) uniform subpassInput colorIn0;
//     layout(input_attachment_index = 1, set = 0, binding = 1) uniform isubpassInput colorIn1;
//     layout(input_attachment_index = 2, set = 0, binding = 2) uniform usubpassInput colorIn2;
//     layout(input_attachment_index = 3, set = 0, binding = 3) uniform subpassInput depthIn;
//     layout(input_attachment_index = 3, set = 0, binding = 4) uniform usubpassInput stencilIn;
//
//     void main()
//     {
//         colorOut0 = subpassLoad(colorIn0);
//         colorOut1 = subpassLoad(colorIn1);
//         colorOut2 = subpassLoad(colorIn2);
//         gl_FragDepth = subpassLoad(depthIn).x;
//         gl_FragStencilRefARB = int(subpassLoad(stencilIn).x);
//     }
Creates a shader that looks like the following, based on the number and types of unresolve
attachments.

version 450 core
extension GL_ARB_shader_stencil_export : require




Creates a shader that looks like the following based on the number and types of unresolve attachments . version 450 core extension GL_ARB_shader_stencil_export : require
angle::Result MakeUnresolveFragShader(
    vk::Context *context,
    uint32_t colorAttachmentCount,
    gl::DrawBuffersArray<UnresolveColorAttachmentType> &colorAttachmentTypes,
    bool unresolveDepth,
    bool unresolveStencil,
    SpirvBlob *spirvBlobOut)
{
    std::ostringstream source;
    source << "#version 450 core\n";
    if (unresolveStencil)
    {
        source << "#extension GL_ARB_shader_stencil_export : require\n";
    }
    for (uint32_t attachmentIndex = 0; attachmentIndex < colorAttachmentCount; ++attachmentIndex)
    {
        const UnresolveColorAttachmentType type = colorAttachmentTypes[attachmentIndex];
        ASSERT(type != kUnresolveTypeUnused);
        const char *prefix =
            type == kUnresolveTypeUint ? "u" : type == kUnresolveTypeSint ? "i" : "";
        source << "layout(location=" << attachmentIndex << ") out " << prefix << "vec4 colorOut"
               << attachmentIndex << ";\n";
        source << "layout(input_attachment_index=" << attachmentIndex
               << ", set=" << DescriptorSetIndex::InternalShader << ", binding=" << attachmentIndex
               << ") uniform " << prefix << "subpassInput colorIn" << attachmentIndex << ";\n";
    }
    const uint32_t depthStencilInputIndex = colorAttachmentCount;
    uint32_t depthStencilBindingIndex     = colorAttachmentCount;
    if (unresolveDepth)
    {
        source << "layout(input_attachment_index=" << depthStencilInputIndex
               << ", set=" << DescriptorSetIndex::InternalShader
               << ", binding=" << depthStencilBindingIndex << ") uniform subpassInput depthIn;\n";
        ++depthStencilBindingIndex;
    }
    if (unresolveStencil)
    {
        source << "layout(input_attachment_index=" << depthStencilInputIndex
               << ", set=" << DescriptorSetIndex::InternalShader
               << ", binding=" << depthStencilBindingIndex
               << ") uniform usubpassInput stencilIn;\n";
    }
    source << "void main(){\n";
    for (uint32_t attachmentIndex = 0; attachmentIndex < colorAttachmentCount; ++attachmentIndex)
    {
        source << "colorOut" << attachmentIndex << " = subpassLoad(colorIn" << attachmentIndex
               << ");\n";
    }
    if (unresolveDepth)
    {
        source << "gl_FragDepth = subpassLoad(depthIn).x;\n";
    }
    if (unresolveStencil)
    {
        source << "gl_FragStencilRefARB = int(subpassLoad(stencilIn).x);\n";
    }
    source << "}\n";
    return GlslangWrapperVk::CompileShaderOneOff(context, gl::ShaderType::Fragment, source.str(),
                                                 spirvBlobOut);
}
angle :: Result MakeUnresolveFragShader ( vk :: Context * context , uint32_t colorAttachmentCount , gl :: DrawBuffersArray < UnresolveColorAttachmentType > & colorAttachmentTypes , bool unresolveDepth , bool unresolveStencil , SpirvBlob * spirvBlobOut ) { std :: ostringstream source ; source << " \n " ; if ( unresolveStencil ) { source << " \n " ; } for ( uint32_t attachmentIndex = 0 ; attachmentIndex < colorAttachmentCount ; ++ attachmentIndex ) { const UnresolveColorAttachmentType type = colorAttachmentTypes [ attachmentIndex ] ; ASSERT ( type != kUnresolveTypeUnused ) ; const char * prefix = type == kUnresolveTypeUint ? " " : type == kUnresolveTypeSint ? " " : " " ; source << " " << attachmentIndex << " " << prefix << " " << attachmentIndex << " \n " ; source << " " << attachmentIndex << " " << DescriptorSetIndex :: InternalShader << " " << attachmentIndex << " " << prefix << " " << attachmentIndex << " \n " ; } const uint32_t depthStencilInputIndex = colorAttachmentCount ; uint32_t depthStencilBindingIndex = colorAttachmentCount ; if ( unresolveDepth ) { source << " " << depthStencilInputIndex << " " << DescriptorSetIndex :: InternalShader << " " << depthStencilBindingIndex << " \n " ; ++ depthStencilBindingIndex ; } if ( unresolveStencil ) { source << " " << depthStencilInputIndex << " " << DescriptorSetIndex :: InternalShader << " " << depthStencilBindingIndex << " \n " ; } source << " \n " ; for ( uint32_t attachmentIndex = 0 ; attachmentIndex < colorAttachmentCount ; ++ attachmentIndex ) { source << " " << attachmentIndex << " " << attachmentIndex << " \n " ; } if ( unresolveDepth ) { source << " \n " ; } if ( unresolveStencil ) { source << " \n " ; } source << " \n " ; return GlslangWrapperVk :: CompileShaderOneOff ( context , gl :: ShaderType :: Fragment , source . str ( ) , spirvBlobOut ) ; }
Creates a shader that looks like the following, based on the number and types of unresolve
attachments.
Creates a shader that looks like the following based on the number and types of unresolve attachments .