Edit

kc3-lang/angle/src/libANGLE/renderer/vulkan/ShaderVk.cpp

Branch :

  • Show log

    Commit

  • Author : Shahbaz Youssefi
    Date : 2021-06-11 16:36:32
    Hash : 153240b2
    Message : Vulkan: SPIR-V Gen: Support loops Loops are similar to if-else in that they generate a number of blocks where the first block specifies divergence (OpLoopMerge) and the merge block. Differently from if-else, there is a block where the condition is evaluated and a block which `continue;` leads to (this last block is the only one allowed to back-jump to the beginning of the loop). Bug: angleproject:4889 Change-Id: Ic59f4bf3e05fbf93cb5af85acd3bc4b0da8412af Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2957809 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Tim Van Patten <timvp@google.com>

  • src/libANGLE/renderer/vulkan/ShaderVk.cpp
  • //
    // Copyright 2016 The ANGLE Project Authors. All rights reserved.
    // Use of this source code is governed by a BSD-style license that can be
    // found in the LICENSE file.
    //
    // ShaderVk.cpp:
    //    Implements the class methods for ShaderVk.
    //
    
    #include "libANGLE/renderer/vulkan/ShaderVk.h"
    
    #include "common/debug.h"
    #include "libANGLE/Context.h"
    #include "libANGLE/renderer/vulkan/ContextVk.h"
    #include "platform/FeaturesVk.h"
    
    namespace rx
    {
    
    ShaderVk::ShaderVk(const gl::ShaderState &state) : ShaderImpl(state) {}
    
    ShaderVk::~ShaderVk() {}
    
    std::shared_ptr<WaitableCompileEvent> ShaderVk::compile(const gl::Context *context,
                                                            gl::ShCompilerInstance *compilerInstance,
                                                            ShCompileOptions options)
    {
        ShCompileOptions compileOptions = 0;
    
        ContextVk *contextVk = vk::GetImpl(context);
    
        bool isWebGL = context->getExtensions().webglCompatibility;
    
        if (isWebGL)
        {
            // Only webgl requires initialization of local variables, others don't.
            // Extra initialization in spirv shader may affect performance.
            compileOptions |= SH_INITIALIZE_UNINITIALIZED_LOCALS;
    
            // WebGL shaders may contain OOB array accesses which in turn cause undefined behavior,
            // which may result in security issues. See https://crbug.com/1189110.
            compileOptions |= SH_CLAMP_INDIRECT_ARRAY_BOUNDS;
    
            if (mState.getShaderType() != gl::ShaderType::Compute)
            {
                compileOptions |= SH_INIT_OUTPUT_VARIABLES;
            }
        }
    
        if (contextVk->getFeatures().clampPointSize.enabled)
        {
            compileOptions |= SH_CLAMP_POINT_SIZE;
        }
    
        if (contextVk->getFeatures().basicGLLineRasterization.enabled)
        {
            compileOptions |= SH_ADD_BRESENHAM_LINE_RASTER_EMULATION;
        }
    
        if (contextVk->emulateSeamfulCubeMapSampling())
        {
            compileOptions |= SH_EMULATE_SEAMFUL_CUBE_MAP_SAMPLING;
        }
    
        if (!contextVk->getFeatures().enablePrecisionQualifiers.enabled)
        {
            compileOptions |= SH_IGNORE_PRECISION_QUALIFIERS;
        }
    
        if (contextVk->getFeatures().forceFragmentShaderPrecisionHighpToMediump.enabled)
        {
            compileOptions |= SH_FORCE_SHADER_PRECISION_HIGHP_TO_MEDIUMP;
        }
    
        // Let compiler detect and emit early fragment test execution mode. We will remove it if
        // context state does not allow it
        compileOptions |= SH_EARLY_FRAGMENT_TESTS_OPTIMIZATION;
    
        // Let compiler use specialized constant for pre-rotation.
        if (!contextVk->getFeatures().forceDriverUniformOverSpecConst.enabled)
        {
            compileOptions |= SH_USE_SPECIALIZATION_CONSTANT;
        }
    
        if (contextVk->getFeatures().enablePreRotateSurfaces.enabled ||
            contextVk->getFeatures().emulatedPrerotation90.enabled ||
            contextVk->getFeatures().emulatedPrerotation180.enabled ||
            contextVk->getFeatures().emulatedPrerotation270.enabled)
        {
            // Let compiler insert pre-rotation code.
            compileOptions |= SH_ADD_PRE_ROTATION;
        }
    
        if (contextVk->getFeatures().supportsTransformFeedbackExtension.enabled)
        {
            compileOptions |= SH_ADD_VULKAN_XFB_EXTENSION_SUPPORT_CODE;
        }
        else if (mState.getShaderType() == gl::ShaderType::Vertex &&
                 contextVk->getFeatures().emulateTransformFeedback.enabled)
        {
            compileOptions |= SH_ADD_VULKAN_XFB_EMULATION_SUPPORT_CODE;
        }
    
        if (contextVk->getFeatures().directSPIRVGeneration.enabled)
        {
            compileOptions |= SH_GENERATE_SPIRV_DIRECTLY;
    
            if (contextVk->getFeatures().directSPIRVGenerationWorkarounds.enabled)
            {
                compileOptions |= SH_GENERATE_SPIRV_WORKAROUNDS;
            }
        }
    
        return compileImpl(context, compilerInstance, mState.getSource(), compileOptions | options);
    }
    
    std::string ShaderVk::getDebugInfo() const
    {
        return mState.getCompiledBinary().empty() ? "" : "<binary blob>";
    }
    
    }  // namespace rx