зеркало из https://github.com/AvaloniaUI/angle.git
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:
Родитель
7455b54401
Коммит
1a5c7a16ba
|
@ -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.
|
||||
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.
|
||||
enum ShArrayIndexClampingStrategy
|
||||
{
|
||||
|
|
|
@ -263,6 +263,11 @@ struct FeaturesVk : FeatureSetBase
|
|||
Feature enableFramebufferVkCache = {
|
||||
"enable_framebuffer_vk_cache", FeatureCategory::VulkanFeatures,
|
||||
"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;
|
||||
|
|
|
@ -27,6 +27,8 @@ TOutputVulkanGLSL::TOutputVulkanGLSL(TInfoSinkBase &objSink,
|
|||
sh::GLenum shaderType,
|
||||
int shaderVersion,
|
||||
ShShaderOutput output,
|
||||
bool forceHighp,
|
||||
bool enablePrecision,
|
||||
ShCompileOptions compileOptions)
|
||||
: TOutputGLSL(objSink,
|
||||
clampingStrategy,
|
||||
|
@ -39,7 +41,9 @@ TOutputVulkanGLSL::TOutputVulkanGLSL(TInfoSinkBase &objSink,
|
|||
compileOptions),
|
||||
mNextUnusedBinding(0),
|
||||
mNextUnusedInputLocation(0),
|
||||
mNextUnusedOutputLocation(0)
|
||||
mNextUnusedOutputLocation(0),
|
||||
mForceHighp(forceHighp),
|
||||
mEnablePrecision(enablePrecision)
|
||||
{}
|
||||
|
||||
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
|
||||
|
|
|
@ -25,6 +25,8 @@ class TOutputVulkanGLSL : public TOutputGLSL
|
|||
sh::GLenum shaderType,
|
||||
int shaderVersion,
|
||||
ShShaderOutput output,
|
||||
bool forceHighp,
|
||||
bool enablePrecision,
|
||||
ShCompileOptions compileOptions);
|
||||
|
||||
void writeStructType(const TStructure *structure);
|
||||
|
@ -48,6 +50,7 @@ class TOutputVulkanGLSL : public TOutputGLSL
|
|||
void writeVariableType(const TType &type,
|
||||
const TSymbol *symbol,
|
||||
bool isFunctionArgument) override;
|
||||
bool writeVariablePrecision(TPrecision) override;
|
||||
|
||||
// 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
|
||||
|
@ -57,6 +60,10 @@ class TOutputVulkanGLSL : public TOutputGLSL
|
|||
uint32_t mNextUnusedBinding;
|
||||
uint32_t mNextUnusedInputLocation;
|
||||
uint32_t mNextUnusedOutputLocation;
|
||||
|
||||
private:
|
||||
bool mForceHighp;
|
||||
bool mEnablePrecision;
|
||||
};
|
||||
|
||||
} // namespace sh
|
||||
|
|
|
@ -71,6 +71,8 @@ TOutputVulkanGLSLForMetal::TOutputVulkanGLSLForMetal(TInfoSinkBase &objSink,
|
|||
shaderType,
|
||||
shaderVersion,
|
||||
output,
|
||||
false,
|
||||
true,
|
||||
compileOptions)
|
||||
{}
|
||||
|
||||
|
|
|
@ -67,9 +67,10 @@ bool TranslatorMetal::translate(TIntermBlock *root,
|
|||
PerformanceDiagnostics *perfDiagnostics)
|
||||
{
|
||||
TInfoSinkBase &sink = getInfoSink().obj;
|
||||
|
||||
TOutputVulkanGLSL outputGLSL(sink, getArrayIndexClampingStrategy(), getHashFunction(),
|
||||
getNameMap(), &getSymbolTable(), getShaderType(),
|
||||
getShaderVersion(), getOutputType(), compileOptions);
|
||||
getShaderVersion(), getOutputType(), false, true, compileOptions);
|
||||
|
||||
const TVariable *driverUniforms = nullptr;
|
||||
if (!TranslatorVulkan::translateImpl(root, compileOptions, perfDiagnostics, &driverUniforms,
|
||||
|
|
|
@ -1043,9 +1043,17 @@ bool TranslatorVulkan::translate(TIntermBlock *root,
|
|||
{
|
||||
|
||||
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(),
|
||||
getNameMap(), &getSymbolTable(), getShaderType(),
|
||||
getShaderVersion(), getOutputType(), compileOptions);
|
||||
getShaderVersion(), getOutputType(), precisionEmulation,
|
||||
enablePrecision, compileOptions);
|
||||
|
||||
if (!translateImpl(root, compileOptions, perfDiagnostics, nullptr, &outputGLSL))
|
||||
{
|
||||
|
|
|
@ -124,9 +124,9 @@ constexpr const char *kSkippedMessages[] = {
|
|||
"VUID-vkDestroySemaphore-semaphore-parameter",
|
||||
// http://anglebug.com/4063
|
||||
"VUID-VkDeviceCreateInfo-pNext-pNext",
|
||||
"VUID-VkPipelineRasterizationStateCreateInfo-pNext-pNext",
|
||||
"VUID_Undefined",
|
||||
};
|
||||
"VUID-VkPipelineRasterizationStateCreateInfo-pNext-pNext", "VUID_Undefined",
|
||||
// http://anglebug.com/3078
|
||||
"UNASSIGNED-CoreValidation-Shader-InterfaceTypeMismatch"};
|
||||
|
||||
// Suppress validation errors that are known
|
||||
// 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
|
||||
ANGLE_FEATURE_CONDITION((&mFeatures), enableFramebufferVkCache, !IsApple());
|
||||
|
||||
// Currently disabled by default: http://anglebug.com/3078
|
||||
ANGLE_FEATURE_CONDITION((&mFeatures), enablePrecisionQualifiers, false);
|
||||
|
||||
angle::PlatformMethods *platform = ANGLEPlatformCurrent();
|
||||
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;
|
||||
}
|
||||
|
||||
if (!contextVk->getFeatures().enablePrecisionQualifiers.enabled)
|
||||
{
|
||||
compileOptions |= SH_IGNORE_PRECISION_QUALIFIERS;
|
||||
}
|
||||
|
||||
return compileImpl(context, compilerInstance, mData.getSource(), compileOptions | options);
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче