From 474bb507abbc7679238710f2f0b5833370980a92 Mon Sep 17 00:00:00 2001 From: SuellaSun Date: Tue, 22 Jul 2025 14:52:34 +0800 Subject: [PATCH] support SampleGather. Signed-off-by: SuellaSun --- m133/src/sksl/SkSLIntrinsicList.h | 1 + .../src/sksl/codegen/SkSLSPIRVCodeGenerator.cpp | 17 +++++++++++++++++ m133/src/sksl/sksl_ext.sksl.h | 4 ++++ src/sksl/SkSLIntrinsicList.h | 1 + src/sksl/codegen/SkSLSPIRVCodeGenerator.cpp | 16 ++++++++++++++++ src/sksl/codegen/SkSLSPIRVCodeGenerator.h | 1 + src/sksl/sksl_ext.sksl.h | 4 ++++ 7 files changed, 44 insertions(+) diff --git a/m133/src/sksl/SkSLIntrinsicList.h b/m133/src/sksl/SkSLIntrinsicList.h index cf6750f49b..265b14bd72 100644 --- a/m133/src/sksl/SkSLIntrinsicList.h +++ b/m133/src/sksl/SkSLIntrinsicList.h @@ -124,6 +124,7 @@ #define SKSL_INTRINSIC_LIST \ SKSL_INTRINSIC_LIST_BASE \ SKSL_INTRINSIC(textureSize) \ + SKSL_INTRINSIC(sampleGather) \ SKSL_INTRINSIC(nonuniformEXT) #else // SKSL_EXT #define SKSL_INTRINSIC_LIST SKSL_INTRINSIC_LIST_BASE diff --git a/m133/src/sksl/codegen/SkSLSPIRVCodeGenerator.cpp b/m133/src/sksl/codegen/SkSLSPIRVCodeGenerator.cpp index cf89700e46..651c26095e 100644 --- a/m133/src/sksl/codegen/SkSLSPIRVCodeGenerator.cpp +++ b/m133/src/sksl/codegen/SkSLSPIRVCodeGenerator.cpp @@ -233,6 +233,7 @@ private: kWorkgroupBarrier_SpecialIntrinsic, #ifdef SKSL_EXT kTextureSize_SpecialIntrinsic, + kSampleGather_SpecialIntrinsic, kNonuniformEXT_SpecialIntrinsic, #endif }; @@ -980,6 +981,7 @@ SPIRVCodeGenerator::Intrinsic SPIRVCodeGenerator::getIntrinsic(IntrinsicKind ik) case k_workgroupBarrier_IntrinsicKind: return SPECIAL(WorkgroupBarrier); #ifdef SKSL_EXT case k_textureSize_IntrinsicKind: return SPECIAL(TextureSize); + case k_sampleGather_IntrinsicKind: return SPECIAL(SampleGather); case k_nonuniformEXT_IntrinsicKind: return SPECIAL(NonuniformEXT); #endif default: @@ -2502,6 +2504,21 @@ SpvId SPIRVCodeGenerator::writeSpecialIntrinsic(const FunctionCall& c, SpecialIn this->writeInstruction(SpvOpImageQuerySizeLod, dimsType, result, image, lod, out); break; } + case kSampleGather_SpecialIntrinsic: { + SpvOp_ op = SpvOpImageGather; + SpvId type = this->getType(callType); + SpvId sampler = this->writeExpression(*arguments[0], out); + SpvId uv = this->writeExpression(*arguments[1], out); + SpvId comp; + if (arguments.size() == 3) { + comp = this->writeExpression(*arguments[2], out); + } else { + SkASSERT(arguments.size() == 2); + comp = this->writeLiteral(0, *fContext.fTypes.fInt); + } + this->writeInstruction(op, type, result, sampler, uv, comp, out); + break; + } case kNonuniformEXT_SpecialIntrinsic: { fCapabilitiesExt.insert(SpvCapabilityShaderNonUniform); SpvId dimsType = this->getType(*fContext.fTypes.fUInt); diff --git a/m133/src/sksl/sksl_ext.sksl.h b/m133/src/sksl/sksl_ext.sksl.h index 731ef32d11..751eebf0a0 100644 --- a/m133/src/sksl/sksl_ext.sksl.h +++ b/m133/src/sksl/sksl_ext.sksl.h @@ -385,6 +385,10 @@ $pure float coverage_bias(float scale) { // add the support of textureSize int2 textureSize(sampler2D x, int y); +// add the support of textureGather +half4 sampleGather(sampler2D s, float2 p); +half4 sampleGather(sampler2D s, float2 p, int comp); + // add the support of nonuniformEXT uint nonuniformEXT(uint x); )"}, diff --git a/src/sksl/SkSLIntrinsicList.h b/src/sksl/SkSLIntrinsicList.h index c8060d9e8d..334181aa76 100644 --- a/src/sksl/SkSLIntrinsicList.h +++ b/src/sksl/SkSLIntrinsicList.h @@ -109,6 +109,7 @@ #define SKSL_INTRINSIC_LIST \ SKSL_INTRINSIC_LIST_BASE \ SKSL_INTRINSIC(textureSize) \ + SKSL_INTRINSIC(sampleGather) \ SKSL_INTRINSIC(nonuniformEXT) #else // SKSL_EXT #define SKSL_INTRINSIC_LIST SKSL_INTRINSIC_LIST_BASE diff --git a/src/sksl/codegen/SkSLSPIRVCodeGenerator.cpp b/src/sksl/codegen/SkSLSPIRVCodeGenerator.cpp index 3b93f6baba..a8e693f8a8 100644 --- a/src/sksl/codegen/SkSLSPIRVCodeGenerator.cpp +++ b/src/sksl/codegen/SkSLSPIRVCodeGenerator.cpp @@ -209,6 +209,7 @@ void SPIRVCodeGenerator::setupIntrinsics() { SpvOpUndef); #ifdef SKSL_EXT fIntrinsicMap[k_textureSize_IntrinsicKind] = SPECIAL(TextureSize); + fIntrinsicMap[k_sampleGather_IntrinsicKind] = SPECIAL(SampleGather); fIntrinsicMap[k_nonuniformEXT_IntrinsicKind] = SPECIAL(NonuniformEXT); #endif // interpolateAt* not yet supported... @@ -1284,6 +1285,21 @@ SpvId SPIRVCodeGenerator::writeSpecialIntrinsic(const FunctionCall& c, SpecialIn this->writeInstruction(SpvOpImageQuerySizeLod, dimsType, result, image, lod, out); break; } + case kSampleGather_SpecialIntrinsic: { + SpvOp_ op = SpvOpImageGather; + SpvId type = this->getType(callType); + SpvId sampler = this->writeExpression(*arguments[0], out); + SpvId uv = this->writeExpression(*arguments[1], out); + SpvId comp; + if (arguments.size() == 3) { + comp = this->writeExpression(*arguments[2], out); + } else { + SkASSERT(arguments.size() == 2); + comp = this->writeLiteral(0, *fContext.fTypes.fInt); + } + this->writeInstruction(op, type, result, sampler, uv, comp, out); + break; + } case kNonuniformEXT_SpecialIntrinsic: { fCapabilitiesExt.insert(SpvCapabilityShaderNonUniform); SpvId dimsType = this->getType(*fContext.fTypes.fUInt); diff --git a/src/sksl/codegen/SkSLSPIRVCodeGenerator.h b/src/sksl/codegen/SkSLSPIRVCodeGenerator.h index 6738d96d36..eb4b768a65 100644 --- a/src/sksl/codegen/SkSLSPIRVCodeGenerator.h +++ b/src/sksl/codegen/SkSLSPIRVCodeGenerator.h @@ -167,6 +167,7 @@ private: kTexture_SpecialIntrinsic, #ifdef SKSL_EXT kTextureSize_SpecialIntrinsic, + kSampleGather_SpecialIntrinsic, kNonuniformEXT_SpecialIntrinsic, #endif }; diff --git a/src/sksl/sksl_ext.sksl.h b/src/sksl/sksl_ext.sksl.h index c2e5b33f3d..8c62a95466 100644 --- a/src/sksl/sksl_ext.sksl.h +++ b/src/sksl/sksl_ext.sksl.h @@ -560,6 +560,10 @@ half cross(half2 a, half2 b) { // add the support of textureSize int2 textureSize(sampler2D x, int y); +// add the support of textureGather +half4 sampleGather(sampler2D s, float2 p); +half4 sampleGather(sampler2D s, float2 p, int comp); + // add the support of nonuniformEXT uint nonuniformEXT(uint x); )"} -- Gitee