Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit fd41d87

Browse files
johnstiles-googleSkia Commit-Bot
authored and
Skia Commit-Bot
committed
Fix SPIR-V and Metal support for enum types.
SPIR-V previously didn't know what to think when it encountered a Type with a typeKind of kEnum, and would abort. These are now treated as 32-bit signed integers. Metal previously emitted the SkSL enum typename, which is meaningless to Metal since we do not emit the enum itself anywhere. Metal now emits "int" for an enum-typed variable. (GLSL already correctly emits "int" for enum types.) Change-Id: I05975a2a399f9c4a22c00c90be0dccacd99d793b Bug: skia:11003 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/338856 Auto-Submit: John Stiles <[email protected]> Reviewed-by: Brian Osman <[email protected]> Commit-Queue: John Stiles <[email protected]>
1 parent 21f5f45 commit fd41d87

8 files changed

+3350
-1
lines changed

gn/sksl_tests.gni

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ sksl_blend_tests = [
330330
"$_tests/sksl/blend/BlendDstIn.sksl",
331331
"$_tests/sksl/blend/BlendDstOut.sksl",
332332
"$_tests/sksl/blend/BlendDstOver.sksl",
333+
"$_tests/sksl/blend/BlendEnum.sksl",
333334
"$_tests/sksl/blend/BlendExclusion.sksl",
334335
"$_tests/sksl/blend/BlendHardLight.sksl",
335336
"$_tests/sksl/blend/BlendHue.sksl",

src/sksl/SkSLMetalCodeGenerator.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ String MetalCodeGenerator::typeName(const Type& type) {
9898
to_string(type.rows());
9999
case Type::TypeKind::kSampler:
100100
return "texture2d<float>"; // FIXME - support other texture types;
101+
case Type::TypeKind::kEnum:
102+
return "int";
101103
default:
102104
if (type == *fContext.fHalf_Type) {
103105
// FIXME - Currently only supporting floats in MSL to avoid type coercion issues.

src/sksl/SkSLSPIRVCodeGenerator.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,9 @@ SpvId SPIRVCodeGenerator::getType(const Type& rawType, const MemoryLayout& layou
502502
SkASSERT(false);
503503
}
504504
break;
505+
case Type::TypeKind::kEnum:
506+
this->writeInstruction(SpvOpTypeInt, result, 32, 1, fConstantBuffer);
507+
break;
505508
case Type::TypeKind::kVector:
506509
this->writeInstruction(SpvOpTypeVector, result,
507510
this->getType(type.componentType(), layout),
@@ -2547,7 +2550,7 @@ SpvId SPIRVCodeGenerator::writeBoolLiteral(const BoolLiteral& b) {
25472550
SpvId SPIRVCodeGenerator::writeIntLiteral(const IntLiteral& i) {
25482551
const Type& type = i.type();
25492552
ConstantType constantType;
2550-
if (type == *fContext.fInt_Type) {
2553+
if (type == *fContext.fInt_Type || type.typeKind() == Type::TypeKind::kEnum) {
25512554
constantType = ConstantType::kInt;
25522555
} else if (type == *fContext.fUInt_Type) {
25532556
constantType = ConstantType::kUInt;

tests/sksl/blend/BlendEnum.sksl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/*#pragma settings Default*/
2+
3+
in half4 src, dst;
4+
5+
void main() {
6+
sk_FragColor = blend(SkBlendMode::kModulate, src, dst);
7+
}

0 commit comments

Comments
 (0)