Commit 85707f7f by Shahbaz Youssefi Committed by Commit Bot

Vulkan: Pass in SPIR-V transform options in a struct

Clean up change in preparation for changes that add more options. Bug: angleproject:5478 Change-Id: Id35825b337dba153a5c28dfcc311b344ce257f78 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2599941 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarTim Van Patten <timvp@google.com>
parent 41d78ae1
......@@ -53,6 +53,13 @@ struct GlslangSourceOptions
bool emulateBresenhamLines = false;
};
struct GlslangSpirvOptions
{
gl::ShaderType shaderType = gl::ShaderType::InvalidEnum;
bool removeEarlyFragmentTestsOptimization = false;
bool removeDebugInfo = false;
};
using SpirvBlob = std::vector<uint32_t>;
using GlslangErrorCallback = std::function<angle::Result(GlslangError)>;
......@@ -138,9 +145,7 @@ void GlslangGetShaderSource(const GlslangSourceOptions &options,
ShaderMapInterfaceVariableInfoMap *variableInfoMapOut);
angle::Result GlslangTransformSpirvCode(const GlslangErrorCallback &callback,
const gl::ShaderType shaderType,
bool removeEarlyFragmentTestsOptimization,
bool removeDebugInfo,
const GlslangSpirvOptions &options,
const ShaderInterfaceVariableInfoMap &variableInfoMap,
const SpirvBlob &initialSpirvBlob,
SpirvBlob *spirvBlobOut);
......
......@@ -455,13 +455,12 @@ angle::Result GlslangGetShaderSpirvCode(ErrorHandler *context,
for (const gl::ShaderType shaderType : linkedShaderStages)
{
// we pass in false here to skip modifications related to early fragment tests
// optimizations and line rasterization. These are done in the initProgram time since they
// are related to context state. We must keep original untouched spriv blobs here because we
// do not have ability to add back in at initProgram time.
GlslangSpirvOptions options;
options.shaderType = shaderType;
angle::Result status = GlslangTransformSpirvCode(
[context](GlslangError error) { return HandleError(context, error); }, shaderType,
false, false, variableInfoMap[shaderType], initialSpirvBlobs[shaderType],
[context](GlslangError error) { return HandleError(context, error); }, options,
variableInfoMap[shaderType], initialSpirvBlobs[shaderType],
&(*shaderCodeOut)[shaderType]);
if (status != angle::Result::Continue)
{
......
......@@ -84,18 +84,14 @@ angle::Result GlslangWrapperVk::GetShaderCode(vk::Context *context,
// static
angle::Result GlslangWrapperVk::TransformSpirV(
vk::Context *context,
const gl::ShaderType shaderType,
bool removeEarlyFragmentTestsOptimization,
const GlslangSpirvOptions &options,
const ShaderInterfaceVariableInfoMap &variableInfoMap,
const SpirvBlob &initialSpirvBlob,
SpirvBlob *shaderCodeOut)
{
const bool removeDebugInfo = !context->getRenderer()->getEnableValidationLayers();
return GlslangTransformSpirvCode(
[context](GlslangError error) { return ErrorHandler(context, error); }, shaderType,
removeEarlyFragmentTestsOptimization, removeDebugInfo, variableInfoMap, initialSpirvBlob,
shaderCodeOut);
[context](GlslangError error) { return ErrorHandler(context, error); }, options,
variableInfoMap, initialSpirvBlob, shaderCodeOut);
}
// static
......
......@@ -44,8 +44,7 @@ class GlslangWrapperVk
gl::ShaderMap<std::vector<uint32_t>> *shaderCodesOut);
static angle::Result TransformSpirV(vk::Context *context,
const gl::ShaderType shaderType,
bool removeEarlyFragmentTestsOptimization,
const GlslangSpirvOptions &options,
const ShaderInterfaceVariableInfoMap &variableInfoMap,
const SpirvBlob &initialSpirvBlob,
SpirvBlob *shaderCodeOut);
......
......@@ -30,10 +30,13 @@ bool ValidateTransformedSpirV(ContextVk *contextVk,
{
for (gl::ShaderType shaderType : linkedShaderStages)
{
GlslangSpirvOptions options;
options.shaderType = shaderType;
options.removeDebugInfo = true;
SpirvBlob transformed;
if (GlslangWrapperVk::TransformSpirV(
contextVk, shaderType, false,
executableVk->getShaderInterfaceVariableInfoMap()[shaderType],
contextVk, options, executableVk->getShaderInterfaceVariableInfoMap()[shaderType],
spirvBlobs[shaderType], &transformed) != angle::Result::Continue)
{
return false;
......@@ -121,14 +124,17 @@ angle::Result ProgramInfo::initProgram(ContextVk *contextVk,
executableVk->getShaderInterfaceVariableInfoMap();
const gl::ShaderMap<SpirvBlob> &originalSpirvBlobs = shaderInfo.getSpirvBlobs();
const SpirvBlob &originalSpirvBlob = originalSpirvBlobs[shaderType];
bool removeEarlyFragmentTestsOptimization =
(shaderType == gl::ShaderType::Fragment && optionBits.removeEarlyFragmentTestsOptimization);
gl::ShaderMap<SpirvBlob> transformedSpirvBlobs;
SpirvBlob &transformedSpirvBlob = transformedSpirvBlobs[shaderType];
ANGLE_TRY(GlslangWrapperVk::TransformSpirV(
contextVk, shaderType, removeEarlyFragmentTestsOptimization, variableInfoMap[shaderType],
originalSpirvBlob, &transformedSpirvBlob));
GlslangSpirvOptions options;
options.shaderType = shaderType;
options.removeEarlyFragmentTestsOptimization =
shaderType == gl::ShaderType::Fragment && optionBits.removeEarlyFragmentTestsOptimization;
options.removeDebugInfo = !contextVk->getRenderer()->getEnableValidationLayers();
ANGLE_TRY(GlslangWrapperVk::TransformSpirV(contextVk, options, variableInfoMap[shaderType],
originalSpirvBlob, &transformedSpirvBlob));
ANGLE_TRY(vk::InitShaderAndSerial(contextVk, &mShaders[shaderType].get(),
transformedSpirvBlob.data(),
transformedSpirvBlob.size() * sizeof(uint32_t)));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment