aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/sksl/SkSLSPIRVCodeGenerator.cpp
diff options
context:
space:
mode:
authorGravatar Ethan Nicholas <ethannicholas@google.com>2017-05-03 11:03:44 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-05-03 18:45:21 +0000
commit0187ae65845ec1922d7417b3c29dd4596e0c950d (patch)
tree065d60cdcf6742781534514526dae81d6b8e1f03 /src/sksl/SkSLSPIRVCodeGenerator.cpp
parent581e69865ef5425aa5c9dba173b346dff1ec5652 (diff)
sksl SPIR-V sampledBuffer support
Bug: skia: Change-Id: I9bf936857b61d3bb5a165f7a11e53d25069b53c2 Reviewed-on: https://skia-review.googlesource.com/15192 Reviewed-by: Greg Daniel <egdaniel@google.com> Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Diffstat (limited to 'src/sksl/SkSLSPIRVCodeGenerator.cpp')
-rw-r--r--src/sksl/SkSLSPIRVCodeGenerator.cpp140
1 files changed, 84 insertions, 56 deletions
diff --git a/src/sksl/SkSLSPIRVCodeGenerator.cpp b/src/sksl/SkSLSPIRVCodeGenerator.cpp
index 24f3d91993..1cbd1274fc 100644
--- a/src/sksl/SkSLSPIRVCodeGenerator.cpp
+++ b/src/sksl/SkSLSPIRVCodeGenerator.cpp
@@ -64,12 +64,12 @@ void SPIRVCodeGenerator::setupIntrinsics() {
fIntrinsicMap[String("determinant")] = ALL_GLSL(Determinant);
fIntrinsicMap[String("matrixInverse")] = ALL_GLSL(MatrixInverse);
fIntrinsicMap[String("mod")] = std::make_tuple(kSPIRV_IntrinsicKind, SpvOpFMod,
- SpvOpSMod, SpvOpUMod, SpvOpUndef);
+ SpvOpSMod, SpvOpUMod, SpvOpUndef);
fIntrinsicMap[String("min")] = BY_TYPE_GLSL(FMin, SMin, UMin);
fIntrinsicMap[String("max")] = BY_TYPE_GLSL(FMax, SMax, UMax);
fIntrinsicMap[String("clamp")] = BY_TYPE_GLSL(FClamp, SClamp, UClamp);
fIntrinsicMap[String("dot")] = std::make_tuple(kSPIRV_IntrinsicKind, SpvOpDot,
- SpvOpUndef, SpvOpUndef, SpvOpUndef);
+ SpvOpUndef, SpvOpUndef, SpvOpUndef);
fIntrinsicMap[String("mix")] = ALL_GLSL(FMix);
fIntrinsicMap[String("step")] = ALL_GLSL(Step);
fIntrinsicMap[String("smoothstep")] = ALL_GLSL(SmoothStep);
@@ -95,44 +95,44 @@ void SPIRVCodeGenerator::setupIntrinsics() {
fIntrinsicMap[String("findLSB")] = ALL_GLSL(FindILsb);
fIntrinsicMap[String("findMSB")] = BY_TYPE_GLSL(FindSMsb, FindSMsb, FindUMsb);
fIntrinsicMap[String("dFdx")] = std::make_tuple(kSPIRV_IntrinsicKind, SpvOpDPdx,
- SpvOpUndef, SpvOpUndef, SpvOpUndef);
+ SpvOpUndef, SpvOpUndef, SpvOpUndef);
fIntrinsicMap[String("dFdy")] = std::make_tuple(kSPIRV_IntrinsicKind, SpvOpDPdy,
- SpvOpUndef, SpvOpUndef, SpvOpUndef);
+ SpvOpUndef, SpvOpUndef, SpvOpUndef);
fIntrinsicMap[String("dFdy")] = std::make_tuple(kSPIRV_IntrinsicKind, SpvOpDPdy,
- SpvOpUndef, SpvOpUndef, SpvOpUndef);
+ SpvOpUndef, SpvOpUndef, SpvOpUndef);
fIntrinsicMap[String("texture")] = SPECIAL(Texture);
-
+ fIntrinsicMap[String("texelFetch")] = SPECIAL(TexelFetch);
fIntrinsicMap[String("subpassLoad")] = SPECIAL(SubpassLoad);
fIntrinsicMap[String("any")] = std::make_tuple(kSPIRV_IntrinsicKind, SpvOpUndef,
- SpvOpUndef, SpvOpUndef, SpvOpAny);
+ SpvOpUndef, SpvOpUndef, SpvOpAny);
fIntrinsicMap[String("all")] = std::make_tuple(kSPIRV_IntrinsicKind, SpvOpUndef,
- SpvOpUndef, SpvOpUndef, SpvOpAll);
+ SpvOpUndef, SpvOpUndef, SpvOpAll);
fIntrinsicMap[String("equal")] = std::make_tuple(kSPIRV_IntrinsicKind,
- SpvOpFOrdEqual, SpvOpIEqual,
- SpvOpIEqual, SpvOpLogicalEqual);
+ SpvOpFOrdEqual, SpvOpIEqual,
+ SpvOpIEqual, SpvOpLogicalEqual);
fIntrinsicMap[String("notEqual")] = std::make_tuple(kSPIRV_IntrinsicKind,
- SpvOpFOrdNotEqual, SpvOpINotEqual,
- SpvOpINotEqual,
- SpvOpLogicalNotEqual);
+ SpvOpFOrdNotEqual, SpvOpINotEqual,
+ SpvOpINotEqual,
+ SpvOpLogicalNotEqual);
fIntrinsicMap[String("lessThan")] = std::make_tuple(kSPIRV_IntrinsicKind,
- SpvOpSLessThan, SpvOpULessThan,
- SpvOpFOrdLessThan, SpvOpUndef);
+ SpvOpSLessThan, SpvOpULessThan,
+ SpvOpFOrdLessThan, SpvOpUndef);
fIntrinsicMap[String("lessThanEqual")] = std::make_tuple(kSPIRV_IntrinsicKind,
- SpvOpSLessThanEqual,
- SpvOpULessThanEqual,
- SpvOpFOrdLessThanEqual,
- SpvOpUndef);
+ SpvOpSLessThanEqual,
+ SpvOpULessThanEqual,
+ SpvOpFOrdLessThanEqual,
+ SpvOpUndef);
fIntrinsicMap[String("greaterThan")] = std::make_tuple(kSPIRV_IntrinsicKind,
- SpvOpSGreaterThan,
- SpvOpUGreaterThan,
- SpvOpFOrdGreaterThan,
- SpvOpUndef);
+ SpvOpSGreaterThan,
+ SpvOpUGreaterThan,
+ SpvOpFOrdGreaterThan,
+ SpvOpUndef);
fIntrinsicMap[String("greaterThanEqual")] = std::make_tuple(kSPIRV_IntrinsicKind,
- SpvOpSGreaterThanEqual,
- SpvOpUGreaterThanEqual,
- SpvOpFOrdGreaterThanEqual,
- SpvOpUndef);
+ SpvOpSGreaterThanEqual,
+ SpvOpUGreaterThanEqual,
+ SpvOpFOrdGreaterThanEqual,
+ SpvOpUndef);
// interpolateAt* not yet supported...
}
@@ -1091,11 +1091,15 @@ SpvId SPIRVCodeGenerator::getType(const Type& type, const MemoryLayout& layout)
if (SpvDimSubpassData != type.dimensions()) {
image = this->nextId();
}
+ if (SpvDimBuffer == type.dimensions()) {
+ fCapabilities |= (((uint64_t) 1) << SpvCapabilitySampledBuffer);
+ }
this->writeInstruction(SpvOpTypeImage, image,
this->getType(*fContext.fFloat_Type, layout),
type.dimensions(), type.isDepth(), type.isArrayed(),
type.isMultisampled(), type.isSampled() ? 1 : 2,
SpvImageFormatUnknown, fConstantBuffer);
+ fImageTypeMap[key] = image;
if (SpvDimSubpassData != type.dimensions()) {
this->writeInstruction(SpvOpTypeSampledImage, result, image, fConstantBuffer);
}
@@ -1114,6 +1118,14 @@ SpvId SPIRVCodeGenerator::getType(const Type& type, const MemoryLayout& layout)
return entry->second;
}
+SpvId SPIRVCodeGenerator::getImageType(const Type& type) {
+ ASSERT(type.kind() == Type::kSampler_Kind);
+ this->getType(type);
+ String key = type.name() + to_string((int) fDefaultLayout.fStd);
+ ASSERT(fImageTypeMap.find(key) != fImageTypeMap.end());
+ return fImageTypeMap[key];
+}
+
SpvId SPIRVCodeGenerator::getFunctionType(const FunctionDeclaration& function) {
String key = function.fReturnType.description() + "(";
String separator;
@@ -1295,7 +1307,51 @@ SpvId SPIRVCodeGenerator::writeSpecialIntrinsic(const FunctionCall& c, SpecialIn
for (SpvId id : arguments) {
this->writeWord(id, out);
}
- return result;
+ break;
+ }
+ case kSubpassLoad_SpecialIntrinsic: {
+ SpvId img = this->writeExpression(*c.fArguments[0], out);
+ std::vector<std::unique_ptr<Expression>> args;
+ args.emplace_back(new FloatLiteral(fContext, Position(), 0.0));
+ args.emplace_back(new FloatLiteral(fContext, Position(), 0.0));
+ Constructor ctor(Position(), *fContext.fVec2_Type, std::move(args));
+ SpvId coords = this->writeConstantVector(ctor);
+ if (1 == c.fArguments.size()) {
+ this->writeInstruction(SpvOpImageRead,
+ this->getType(c.fType),
+ result,
+ img,
+ coords,
+ out);
+ } else {
+ ASSERT(2 == c.fArguments.size());
+ SpvId sample = this->writeExpression(*c.fArguments[1], out);
+ this->writeInstruction(SpvOpImageRead,
+ this->getType(c.fType),
+ result,
+ img,
+ coords,
+ SpvImageOperandsSampleMask,
+ sample,
+ out);
+ }
+ break;
+ }
+ case kTexelFetch_SpecialIntrinsic: {
+ ASSERT(c.fArguments.size() == 2);
+ SpvId image = this->nextId();
+ this->writeInstruction(SpvOpImage,
+ this->getImageType(c.fArguments[0]->fType),
+ image,
+ this->writeExpression(*c.fArguments[0], out),
+ out);
+ this->writeInstruction(SpvOpImageFetch,
+ this->getType(c.fType),
+ result,
+ image,
+ this->writeExpression(*c.fArguments[1], out),
+ out);
+ break;
}
case kTexture_SpecialIntrinsic: {
SpvOp_ op = SpvOpImageSampleImplicitLod;
@@ -1342,34 +1398,6 @@ SpvId SPIRVCodeGenerator::writeSpecialIntrinsic(const FunctionCall& c, SpecialIn
}
break;
}
- case kSubpassLoad_SpecialIntrinsic: {
- SpvId img = this->writeExpression(*c.fArguments[0], out);
- std::vector<std::unique_ptr<Expression>> args;
- args.emplace_back(new FloatLiteral(fContext, Position(), 0.0));
- args.emplace_back(new FloatLiteral(fContext, Position(), 0.0));
- Constructor ctor(Position(), *fContext.fVec2_Type, std::move(args));
- SpvId coords = this->writeConstantVector(ctor);
- if (1 == c.fArguments.size()) {
- this->writeInstruction(SpvOpImageRead,
- this->getType(c.fType),
- result,
- img,
- coords,
- out);
- } else {
- ASSERT(2 == c.fArguments.size());
- SpvId sample = this->writeExpression(*c.fArguments[1], out);
- this->writeInstruction(SpvOpImageRead,
- this->getType(c.fType),
- result,
- img,
- coords,
- SpvImageOperandsSampleMask,
- sample,
- out);
- }
- break;
- }
}
return result;
}