Reland "Vulkan:Include precision qualifier in GLSL"

Currently still ignoring precision qualifiers for Vulkan shaders by
default, but have added feature "enablePrecisionQualifiers" that can be
enabled in order to include precision qualifiers.

With this initial implementation, it's possible to get precision
qualifier mis-matches in the generated GLSL 4.50. According to the
spec this is allowed. From GLSLangSpec 4.50 section 4.7 "Precision and
Precision Qualifiers":

For the purposes of determining if an output from one shader stage
matches an input of the next stage, the precision qualifier need not
match.

However, when converted to SPIR-V and run through the shader validation
any mismatches will cause shader validation errors. Initially just
ignoring those errors with this commit.

Bug: angleproject:3078
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2057749
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Tobin Ehlis <tobine@google.com>
Reviewed-by: Tim Van Patten <timvp@google.com>
Commit-Queue: Tobin Ehlis <tobine@google.com>
Change-Id: Ieecca604bb2c834c9b1c2bcab85279d1f8755dfa
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2086280
This commit is contained in:
Tobin Ehlis 2020-02-25 12:02:31 -07:00 коммит произвёл Commit Bot
Родитель 7455b54401
Коммит 1a5c7a16ba
9 изменённых файлов: 57 добавлений и 6 удалений

Просмотреть файл

@ -333,6 +333,9 @@ const ShCompileOptions SH_DISABLE_ARB_TEXTURE_RECTANGLE = UINT64_C(1) << 52;
// as column-major in ESSL 3.00 and greater shaders. // as column-major in ESSL 3.00 and greater shaders.
const ShCompileOptions SH_REWRITE_ROW_MAJOR_MATRICES = UINT64_C(1) << 53; const ShCompileOptions SH_REWRITE_ROW_MAJOR_MATRICES = UINT64_C(1) << 53;
// Drop any explicit precision qualifiers from shader.
const ShCompileOptions SH_IGNORE_PRECISION_QUALIFIERS = UINT64_C(1) << 54;
// Defines alternate strategies for implementing array index clamping. // Defines alternate strategies for implementing array index clamping.
enum ShArrayIndexClampingStrategy enum ShArrayIndexClampingStrategy
{ {

Просмотреть файл

@ -263,6 +263,11 @@ struct FeaturesVk : FeatureSetBase
Feature enableFramebufferVkCache = { Feature enableFramebufferVkCache = {
"enable_framebuffer_vk_cache", FeatureCategory::VulkanFeatures, "enable_framebuffer_vk_cache", FeatureCategory::VulkanFeatures,
"Enable FramebufferVk objects to be cached", &members, "http://anglebug.com/4442"}; "Enable FramebufferVk objects to be cached", &members, "http://anglebug.com/4442"};
// Enable precision qualifiers for shaders generated by Vulkan backend http://anglebug.com/3078
Feature enablePrecisionQualifiers = {
"enable_precision_qualifiers", FeatureCategory::VulkanFeatures,
"Enable precision qualifiers in shaders", &members, "http://anglebug.com/3078"};
}; };
inline FeaturesVk::FeaturesVk() = default; inline FeaturesVk::FeaturesVk() = default;

Просмотреть файл

@ -27,6 +27,8 @@ TOutputVulkanGLSL::TOutputVulkanGLSL(TInfoSinkBase &objSink,
sh::GLenum shaderType, sh::GLenum shaderType,
int shaderVersion, int shaderVersion,
ShShaderOutput output, ShShaderOutput output,
bool forceHighp,
bool enablePrecision,
ShCompileOptions compileOptions) ShCompileOptions compileOptions)
: TOutputGLSL(objSink, : TOutputGLSL(objSink,
clampingStrategy, clampingStrategy,
@ -39,7 +41,9 @@ TOutputVulkanGLSL::TOutputVulkanGLSL(TInfoSinkBase &objSink,
compileOptions), compileOptions),
mNextUnusedBinding(0), mNextUnusedBinding(0),
mNextUnusedInputLocation(0), mNextUnusedInputLocation(0),
mNextUnusedOutputLocation(0) mNextUnusedOutputLocation(0),
mForceHighp(forceHighp),
mEnablePrecision(enablePrecision)
{} {}
void TOutputVulkanGLSL::writeLayoutQualifier(TIntermTyped *variable) void TOutputVulkanGLSL::writeLayoutQualifier(TIntermTyped *variable)
@ -168,4 +172,17 @@ void TOutputVulkanGLSL::writeStructType(const TStructure *structure)
} }
} }
bool TOutputVulkanGLSL::writeVariablePrecision(TPrecision precision)
{
if ((precision == EbpUndefined) || !mEnablePrecision)
return false;
TInfoSinkBase &out = objSink();
if (mForceHighp)
out << getPrecisionString(EbpHigh);
else
out << getPrecisionString(precision);
return true;
}
} // namespace sh } // namespace sh

Просмотреть файл

@ -25,6 +25,8 @@ class TOutputVulkanGLSL : public TOutputGLSL
sh::GLenum shaderType, sh::GLenum shaderType,
int shaderVersion, int shaderVersion,
ShShaderOutput output, ShShaderOutput output,
bool forceHighp,
bool enablePrecision,
ShCompileOptions compileOptions); ShCompileOptions compileOptions);
void writeStructType(const TStructure *structure); void writeStructType(const TStructure *structure);
@ -48,6 +50,7 @@ class TOutputVulkanGLSL : public TOutputGLSL
void writeVariableType(const TType &type, void writeVariableType(const TType &type,
const TSymbol *symbol, const TSymbol *symbol,
bool isFunctionArgument) override; bool isFunctionArgument) override;
bool writeVariablePrecision(TPrecision) override;
// Every resource that requires set & binding layout qualifiers is assigned set 0 and an // Every resource that requires set & binding layout qualifiers is assigned set 0 and an
// arbitrary binding when outputting GLSL. Every input/output that requires a location // arbitrary binding when outputting GLSL. Every input/output that requires a location
@ -57,6 +60,10 @@ class TOutputVulkanGLSL : public TOutputGLSL
uint32_t mNextUnusedBinding; uint32_t mNextUnusedBinding;
uint32_t mNextUnusedInputLocation; uint32_t mNextUnusedInputLocation;
uint32_t mNextUnusedOutputLocation; uint32_t mNextUnusedOutputLocation;
private:
bool mForceHighp;
bool mEnablePrecision;
}; };
} // namespace sh } // namespace sh

Просмотреть файл

@ -71,6 +71,8 @@ TOutputVulkanGLSLForMetal::TOutputVulkanGLSLForMetal(TInfoSinkBase &objSink,
shaderType, shaderType,
shaderVersion, shaderVersion,
output, output,
false,
true,
compileOptions) compileOptions)
{} {}

Просмотреть файл

@ -67,9 +67,10 @@ bool TranslatorMetal::translate(TIntermBlock *root,
PerformanceDiagnostics *perfDiagnostics) PerformanceDiagnostics *perfDiagnostics)
{ {
TInfoSinkBase &sink = getInfoSink().obj; TInfoSinkBase &sink = getInfoSink().obj;
TOutputVulkanGLSL outputGLSL(sink, getArrayIndexClampingStrategy(), getHashFunction(), TOutputVulkanGLSL outputGLSL(sink, getArrayIndexClampingStrategy(), getHashFunction(),
getNameMap(), &getSymbolTable(), getShaderType(), getNameMap(), &getSymbolTable(), getShaderType(),
getShaderVersion(), getOutputType(), compileOptions); getShaderVersion(), getOutputType(), false, true, compileOptions);
const TVariable *driverUniforms = nullptr; const TVariable *driverUniforms = nullptr;
if (!TranslatorVulkan::translateImpl(root, compileOptions, perfDiagnostics, &driverUniforms, if (!TranslatorVulkan::translateImpl(root, compileOptions, perfDiagnostics, &driverUniforms,

Просмотреть файл

@ -1043,9 +1043,17 @@ bool TranslatorVulkan::translate(TIntermBlock *root,
{ {
TInfoSinkBase &sink = getInfoSink().obj; TInfoSinkBase &sink = getInfoSink().obj;
bool precisionEmulation = false;
if (!emulatePrecisionIfNeeded(root, sink, &precisionEmulation, SH_GLSL_VULKAN_OUTPUT))
return false;
bool enablePrecision = ((compileOptions & SH_IGNORE_PRECISION_QUALIFIERS) == 0);
TOutputVulkanGLSL outputGLSL(sink, getArrayIndexClampingStrategy(), getHashFunction(), TOutputVulkanGLSL outputGLSL(sink, getArrayIndexClampingStrategy(), getHashFunction(),
getNameMap(), &getSymbolTable(), getShaderType(), getNameMap(), &getSymbolTable(), getShaderType(),
getShaderVersion(), getOutputType(), compileOptions); getShaderVersion(), getOutputType(), precisionEmulation,
enablePrecision, compileOptions);
if (!translateImpl(root, compileOptions, perfDiagnostics, nullptr, &outputGLSL)) if (!translateImpl(root, compileOptions, perfDiagnostics, nullptr, &outputGLSL))
{ {

Просмотреть файл

@ -124,9 +124,9 @@ constexpr const char *kSkippedMessages[] = {
"VUID-vkDestroySemaphore-semaphore-parameter", "VUID-vkDestroySemaphore-semaphore-parameter",
// http://anglebug.com/4063 // http://anglebug.com/4063
"VUID-VkDeviceCreateInfo-pNext-pNext", "VUID-VkDeviceCreateInfo-pNext-pNext",
"VUID-VkPipelineRasterizationStateCreateInfo-pNext-pNext", "VUID-VkPipelineRasterizationStateCreateInfo-pNext-pNext", "VUID_Undefined",
"VUID_Undefined", // http://anglebug.com/3078
}; "UNASSIGNED-CoreValidation-Shader-InterfaceTypeMismatch"};
// Suppress validation errors that are known // Suppress validation errors that are known
// return "true" if given code/prefix/message is known, else return "false" // return "true" if given code/prefix/message is known, else return "false"
@ -1673,6 +1673,9 @@ void RendererVk::initFeatures(DisplayVk *displayVk, const ExtensionNameList &dev
// Currently disable FramebufferVk cache on Apple: http://anglebug.com/4442 // Currently disable FramebufferVk cache on Apple: http://anglebug.com/4442
ANGLE_FEATURE_CONDITION((&mFeatures), enableFramebufferVkCache, !IsApple()); ANGLE_FEATURE_CONDITION((&mFeatures), enableFramebufferVkCache, !IsApple());
// Currently disabled by default: http://anglebug.com/3078
ANGLE_FEATURE_CONDITION((&mFeatures), enablePrecisionQualifiers, false);
angle::PlatformMethods *platform = ANGLEPlatformCurrent(); angle::PlatformMethods *platform = ANGLEPlatformCurrent();
platform->overrideFeaturesVk(platform, &mFeatures); platform->overrideFeaturesVk(platform, &mFeatures);

Просмотреть файл

@ -55,6 +55,11 @@ std::shared_ptr<WaitableCompileEvent> ShaderVk::compile(const gl::Context *conte
compileOptions |= SH_USE_OLD_REWRITE_STRUCT_SAMPLERS; compileOptions |= SH_USE_OLD_REWRITE_STRUCT_SAMPLERS;
} }
if (!contextVk->getFeatures().enablePrecisionQualifiers.enabled)
{
compileOptions |= SH_IGNORE_PRECISION_QUALIFIERS;
}
return compileImpl(context, compilerInstance, mData.getSource(), compileOptions | options); return compileImpl(context, compilerInstance, mData.getSource(), compileOptions | options);
} }