From 108cb0cfa37518be2b957bca540d1e6bc0faf5b7 Mon Sep 17 00:00:00 2001 From: John Stiles Date: Mon, 11 Oct 2021 12:31:28 -0400 Subject: [PATCH] Add nonconstant-array-index-support shader caps bit. This will be used to allow us to safely make shaders which index into arrays using expressions which cannot be determined at compile-time. (ES2 cannot do this.) Change-Id: Id291aa69bfb7cbc366de17013ee19a9061db3bf2 Bug: skia:8401 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/457196 Auto-Submit: John Stiles Reviewed-by: Brian Osman Commit-Queue: John Stiles --- src/gpu/GrShaderCaps.cpp | 2 ++ src/gpu/GrShaderCaps.h | 7 +++++++ src/gpu/d3d/GrD3DCaps.cpp | 1 + src/gpu/gl/GrGLCaps.cpp | 5 +++-- src/gpu/mtl/GrMtlCaps.mm | 1 + src/gpu/vk/GrVkCaps.cpp | 1 + 6 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/gpu/GrShaderCaps.cpp b/src/gpu/GrShaderCaps.cpp index 42097d0e79..0ff144b7f8 100644 --- a/src/gpu/GrShaderCaps.cpp +++ b/src/gpu/GrShaderCaps.cpp @@ -54,6 +54,7 @@ GrShaderCaps::GrShaderCaps(const GrContextOptions& options) { fExternalTextureSupport = false; fVertexIDSupport = false; fInfinitySupport = false; + fNonconstantArrayIndexSupport = false; fBitManipulationSupport = false; fFloatIs32Bits = true; fHalfIs32Bits = false; @@ -139,6 +140,7 @@ void GrShaderCaps::dumpJSON(SkJSONWriter* writer) const { writer->appendBool("External texture support", fExternalTextureSupport); writer->appendBool("sk_VertexID support", fVertexIDSupport); writer->appendBool("Infinity support", fInfinitySupport); + writer->appendBool("Non-constant array index support", fNonconstantArrayIndexSupport); writer->appendBool("Bit manipulation support", fBitManipulationSupport); writer->appendBool("float == fp32", fFloatIs32Bits); writer->appendBool("half == fp32", fHalfIs32Bits); diff --git a/src/gpu/GrShaderCaps.h b/src/gpu/GrShaderCaps.h index f99ff64b37..d2770eacde 100644 --- a/src/gpu/GrShaderCaps.h +++ b/src/gpu/GrShaderCaps.h @@ -82,6 +82,12 @@ public: // isinf() is defined, and floating point infinities are handled according to IEEE standards. bool infinitySupport() const { return fInfinitySupport; } + // Returns true if `expr` in `myArray[expr]` can be any integer expression. If false, `expr` + // must be a constant-index-expression as defined in the OpenGL ES2 specification, Appendix A.5. + bool nonconstantArrayIndexSupport() const { + return fNonconstantArrayIndexSupport; + } + // frexp(), ldexp(), findMSB(), findLSB(). bool bitManipulationSupport() const { return fBitManipulationSupport; } @@ -289,6 +295,7 @@ private: bool fExternalTextureSupport : 1; bool fVertexIDSupport : 1; bool fInfinitySupport : 1; + bool fNonconstantArrayIndexSupport : 1; bool fBitManipulationSupport : 1; bool fFloatIs32Bits : 1; bool fHalfIs32Bits : 1; diff --git a/src/gpu/d3d/GrD3DCaps.cpp b/src/gpu/d3d/GrD3DCaps.cpp index b89e0807d4..39093b8bd2 100644 --- a/src/gpu/d3d/GrD3DCaps.cpp +++ b/src/gpu/d3d/GrD3DCaps.cpp @@ -245,6 +245,7 @@ void GrD3DCaps::initShaderCaps(int vendorID, const D3D12_FEATURE_DATA_D3D12_OPTI shaderCaps->fInverseHyperbolicSupport = false; shaderCaps->fVertexIDSupport = true; shaderCaps->fInfinitySupport = true; + shaderCaps->fNonconstantArrayIndexSupport = true; shaderCaps->fBitManipulationSupport = true; shaderCaps->fFloatIs32Bits = true; diff --git a/src/gpu/gl/GrGLCaps.cpp b/src/gpu/gl/GrGLCaps.cpp index a085c44a8c..11597d0de7 100644 --- a/src/gpu/gl/GrGLCaps.cpp +++ b/src/gpu/gl/GrGLCaps.cpp @@ -972,10 +972,11 @@ void GrGLCaps::initGLSL(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli } if (GR_IS_GR_GL(standard)) { - shaderCaps->fInfinitySupport = true; + shaderCaps->fInfinitySupport = shaderCaps->fNonconstantArrayIndexSupport = true; } else if (GR_IS_GR_GL_ES(standard) || GR_IS_GR_WEBGL(standard)) { // Desktop GLSL 3.30 == ES GLSL 3.00. - shaderCaps->fInfinitySupport = ctxInfo.glslGeneration() >= k330_GrGLSLGeneration; + shaderCaps->fInfinitySupport = shaderCaps->fNonconstantArrayIndexSupport = + (ctxInfo.glslGeneration() >= k330_GrGLSLGeneration); } if (GR_IS_GR_GL(standard)) { diff --git a/src/gpu/mtl/GrMtlCaps.mm b/src/gpu/mtl/GrMtlCaps.mm index 0f7d71054d..e842082b16 100644 --- a/src/gpu/mtl/GrMtlCaps.mm +++ b/src/gpu/mtl/GrMtlCaps.mm @@ -514,6 +514,7 @@ void GrMtlCaps::initShaderCaps() { shaderCaps->fInverseHyperbolicSupport = true; shaderCaps->fVertexIDSupport = true; shaderCaps->fInfinitySupport = true; + shaderCaps->fNonconstantArrayIndexSupport = true; // Metal uses IEEE float and half floats so assuming those values here. shaderCaps->fFloatIs32Bits = true; diff --git a/src/gpu/vk/GrVkCaps.cpp b/src/gpu/vk/GrVkCaps.cpp index 073fd0b108..64ec728f0a 100644 --- a/src/gpu/vk/GrVkCaps.cpp +++ b/src/gpu/vk/GrVkCaps.cpp @@ -709,6 +709,7 @@ void GrVkCaps::initShaderCaps(const VkPhysicalDeviceProperties& properties, shaderCaps->fInverseHyperbolicSupport = true; shaderCaps->fVertexIDSupport = true; shaderCaps->fInfinitySupport = true; + shaderCaps->fNonconstantArrayIndexSupport = true; shaderCaps->fBitManipulationSupport = true; // Assume the minimum precisions mandated by the SPIR-V spec.