aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/sksl
diff options
context:
space:
mode:
authorGravatar Ruiqi Mao <ruiqimao@google.com>2018-07-17 10:19:38 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-07-17 15:08:40 +0000
commitb609e6dc6a02336aed04caaddcdd5ccfbe7ba9ec (patch)
tree052d6e5c5c7835481f5a0e0bead6ec575679b76f /src/sksl
parent6dd4b209091b876832218e8adf1909669960bf98 (diff)
added byte and ubyte types to SKSL
created new GMs for skinning Bug: skia: Change-Id: I15fb2bd02fba8beb6dd2dd3f3716da016ea92192 Reviewed-on: https://skia-review.googlesource.com/140241 Commit-Queue: Ruiqi Mao <ruiqimao@google.com> Reviewed-by: Brian Osman <brianosman@google.com> Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Diffstat (limited to 'src/sksl')
-rw-r--r--src/sksl/SkSLCPPCodeGenerator.cpp4
-rw-r--r--src/sksl/SkSLCompiler.cpp10
-rw-r--r--src/sksl/SkSLContext.h24
-rw-r--r--src/sksl/SkSLGLSLCodeGenerator.cpp21
-rw-r--r--src/sksl/SkSLHCodeGenerator.cpp4
-rw-r--r--src/sksl/SkSLJIT.cpp10
-rw-r--r--src/sksl/SkSLSPIRVCodeGenerator.cpp56
-rw-r--r--src/sksl/ir/SkSLSwizzle.h12
-rw-r--r--src/sksl/ir/SkSLType.cpp22
9 files changed, 136 insertions, 27 deletions
diff --git a/src/sksl/SkSLCPPCodeGenerator.cpp b/src/sksl/SkSLCPPCodeGenerator.cpp
index fe2dc701dc..be402088cc 100644
--- a/src/sksl/SkSLCPPCodeGenerator.cpp
+++ b/src/sksl/SkSLCPPCodeGenerator.cpp
@@ -177,7 +177,9 @@ void CPPCodeGenerator::writeRuntimeValue(const Type& type, const Layout& layout,
} else if (type.kind() == Type::kEnum_Kind) {
this->write("%d");
fFormatArgs.push_back("(int) " + cppCode);
- } else if (type == *fContext.fInt4_Type || type == *fContext.fShort4_Type) {
+ } else if (type == *fContext.fInt4_Type ||
+ type == *fContext.fShort4_Type ||
+ type == *fContext.fByte4_Type) {
this->write(type.name() + "(%d, %d, %d, %d)");
fFormatArgs.push_back(cppCode + ".left()");
fFormatArgs.push_back(cppCode + ".top()");
diff --git a/src/sksl/SkSLCompiler.cpp b/src/sksl/SkSLCompiler.cpp
index 0cf55c26d0..feaafebc79 100644
--- a/src/sksl/SkSLCompiler.cpp
+++ b/src/sksl/SkSLCompiler.cpp
@@ -100,6 +100,14 @@ Compiler::Compiler(Flags flags)
ADD_TYPE(UShort2);
ADD_TYPE(UShort3);
ADD_TYPE(UShort4);
+ ADD_TYPE(Byte);
+ ADD_TYPE(Byte2);
+ ADD_TYPE(Byte3);
+ ADD_TYPE(Byte4);
+ ADD_TYPE(UByte);
+ ADD_TYPE(UByte2);
+ ADD_TYPE(UByte3);
+ ADD_TYPE(UByte4);
ADD_TYPE(Bool);
ADD_TYPE(Bool2);
ADD_TYPE(Bool3);
@@ -149,6 +157,8 @@ Compiler::Compiler(Flags flags)
ADD_TYPE(UVec);
ADD_TYPE(SVec);
ADD_TYPE(USVec);
+ ADD_TYPE(ByteVec);
+ ADD_TYPE(UByteVec);
ADD_TYPE(BVec);
ADD_TYPE(Sampler1D);
diff --git a/src/sksl/SkSLContext.h b/src/sksl/SkSLContext.h
index 61dd8042e4..ef2aef089e 100644
--- a/src/sksl/SkSLContext.h
+++ b/src/sksl/SkSLContext.h
@@ -49,6 +49,14 @@ public:
, fShort2_Type(new Type("short2", *fShort_Type, 2))
, fShort3_Type(new Type("short3", *fShort_Type, 3))
, fShort4_Type(new Type("short4", *fShort_Type, 4))
+ , fUByte_Type(new Type("ubyte", Type::kUnsigned_NumberKind, 0))
+ , fUByte2_Type(new Type("ubyte2", *fUByte_Type, 2))
+ , fUByte3_Type(new Type("ubyte3", *fUByte_Type, 3))
+ , fUByte4_Type(new Type("ubyte4", *fUByte_Type, 4))
+ , fByte_Type(new Type("byte", Type::kSigned_NumberKind, 0))
+ , fByte2_Type(new Type("byte2", *fByte_Type, 2))
+ , fByte3_Type(new Type("byte3", *fByte_Type, 3))
+ , fByte4_Type(new Type("byte4", *fByte_Type, 4))
, fBool_Type(new Type("bool", Type::kNonnumeric_NumberKind, -1))
, fBool2_Type(new Type("bool2", *fBool_Type, 2))
, fBool3_Type(new Type("bool3", *fBool_Type, 3))
@@ -180,6 +188,10 @@ public:
fShort3_Type.get(), fShort4_Type.get() }))
, fUSVec_Type(new Type("$usvec", { fInvalid_Type.get(), fUShort2_Type.get(),
fUShort3_Type.get(), fUShort4_Type.get() }))
+ , fByteVec_Type(new Type("$bytevec", { fInvalid_Type.get(), fByte2_Type.get(),
+ fByte3_Type.get(), fByte4_Type.get() }))
+ , fUByteVec_Type(new Type("$ubytevec", { fInvalid_Type.get(), fUByte2_Type.get(),
+ fUByte3_Type.get(), fUByte4_Type.get() }))
, fBVec_Type(new Type("$bvec", { fInvalid_Type.get(), fBool2_Type.get(),
fBool3_Type.get(), fBool4_Type.get() }))
, fSkCaps_Type(new Type("$sk_Caps"))
@@ -230,6 +242,16 @@ public:
const std::unique_ptr<Type> fShort3_Type;
const std::unique_ptr<Type> fShort4_Type;
+ const std::unique_ptr<Type> fUByte_Type;
+ const std::unique_ptr<Type> fUByte2_Type;
+ const std::unique_ptr<Type> fUByte3_Type;
+ const std::unique_ptr<Type> fUByte4_Type;
+
+ const std::unique_ptr<Type> fByte_Type;
+ const std::unique_ptr<Type> fByte2_Type;
+ const std::unique_ptr<Type> fByte3_Type;
+ const std::unique_ptr<Type> fByte4_Type;
+
const std::unique_ptr<Type> fBool_Type;
const std::unique_ptr<Type> fBool2_Type;
const std::unique_ptr<Type> fBool3_Type;
@@ -328,6 +350,8 @@ public:
const std::unique_ptr<Type> fUVec_Type;
const std::unique_ptr<Type> fSVec_Type;
const std::unique_ptr<Type> fUSVec_Type;
+ const std::unique_ptr<Type> fByteVec_Type;
+ const std::unique_ptr<Type> fUByteVec_Type;
const std::unique_ptr<Type> fBVec_Type;
diff --git a/src/sksl/SkSLGLSLCodeGenerator.cpp b/src/sksl/SkSLGLSLCodeGenerator.cpp
index aa4f8252d0..5f6fedcdb5 100644
--- a/src/sksl/SkSLGLSLCodeGenerator.cpp
+++ b/src/sksl/SkSLGLSLCodeGenerator.cpp
@@ -82,10 +82,14 @@ String GLSLCodeGenerator::getTypeName(const Type& type) {
else if (component == *fContext.fDouble_Type) {
result = "dvec";
}
- else if (component == *fContext.fInt_Type || component == *fContext.fShort_Type) {
+ else if (component == *fContext.fInt_Type ||
+ component == *fContext.fShort_Type ||
+ component == *fContext.fByte_Type) {
result = "ivec";
}
- else if (component == *fContext.fUInt_Type || component == *fContext.fUShort_Type) {
+ else if (component == *fContext.fUInt_Type ||
+ component == *fContext.fUShort_Type ||
+ component == *fContext.fUByte_Type) {
result = "uvec";
}
else if (component == *fContext.fBool_Type) {
@@ -134,6 +138,12 @@ String GLSLCodeGenerator::getTypeName(const Type& type) {
else if (type == *fContext.fUShort_Type) {
return "uint";
}
+ else if (type == *fContext.fByte_Type) {
+ return "int";
+ }
+ else if (type == *fContext.fUByte_Type) {
+ return "uint";
+ }
else {
return type.name();
}
@@ -857,7 +867,9 @@ void GLSLCodeGenerator::writeIntLiteral(const IntLiteral& i) {
this->write(to_string(i.fValue & 0xffffffff) + "u");
} else if (i.fType == *fContext.fUShort_Type) {
this->write(to_string(i.fValue & 0xffff) + "u");
- } else {
+ } else if (i.fType == *fContext.fUByte_Type) {
+ this->write(to_string(i.fValue & 0xff) + "u");
+ } else {
this->write(to_string((int32_t) i.fValue));
}
}
@@ -1018,7 +1030,8 @@ const char* GLSLCodeGenerator::getTypePrecision(const Type& type) {
if (usesPrecisionModifiers()) {
switch (type.kind()) {
case Type::kScalar_Kind:
- if (type == *fContext.fShort_Type || type == *fContext.fUShort_Type) {
+ if (type == *fContext.fShort_Type || type == *fContext.fUShort_Type ||
+ type == *fContext.fByte_Type || type == *fContext.fUByte_Type) {
if (fProgram.fSettings.fForceHighPrecision ||
fProgram.fSettings.fCaps->incompleteShortIntPrecision()) {
return "highp ";
diff --git a/src/sksl/SkSLHCodeGenerator.cpp b/src/sksl/SkSLHCodeGenerator.cpp
index d6a92d3bac..be0f1ad858 100644
--- a/src/sksl/SkSLHCodeGenerator.cpp
+++ b/src/sksl/SkSLHCodeGenerator.cpp
@@ -33,7 +33,9 @@ String HCodeGenerator::ParameterType(const Context& context, const Type& type,
return "float";
} else if (type == *context.fFloat2_Type || type == *context.fHalf2_Type) {
return "SkPoint";
- } else if (type == *context.fInt4_Type || type == *context.fShort4_Type) {
+ } else if (type == *context.fInt4_Type ||
+ type == *context.fShort4_Type ||
+ type == *context.fByte4_Type) {
return "SkIRect";
} else if (type == *context.fFloat4_Type || type == *context.fHalf4_Type) {
return "SkRect";
diff --git a/src/sksl/SkSLJIT.cpp b/src/sksl/SkSLJIT.cpp
index 57286b53fb..115a6be3ae 100644
--- a/src/sksl/SkSLJIT.cpp
+++ b/src/sksl/SkSLJIT.cpp
@@ -190,13 +190,13 @@ LLVMTypeRef JIT::getType(const Type& type) {
if (type.name() == "float4" || type.name() == "half4") {
return fFloat32Vector4Type;
}
- if (type.name() == "int2" || type.name() == "short2") {
+ if (type.name() == "int2" || type.name() == "short2" || type.name == "byte2") {
return fInt32Vector2Type;
}
- if (type.name() == "int3" || type.name() == "short3") {
+ if (type.name() == "int3" || type.name() == "short3" || type.name == "byte3") {
return fInt32Vector3Type;
}
- if (type.name() == "int4" || type.name() == "short4") {
+ if (type.name() == "int4" || type.name() == "short4" || type.name == "byte3") {
return fInt32Vector4Type;
}
// fall through
@@ -402,9 +402,9 @@ JIT::TypeKind JIT::typeKind(const Type& type) {
if (type.kind() == Type::kVector_Kind) {
return this->typeKind(type.componentType());
}
- if (type.fName == "int" || type.fName == "short") {
+ if (type.fName == "int" || type.fName == "short" || type.fName == "byte") {
return JIT::kInt_TypeKind;
- } else if (type.fName == "uint" || type.fName == "ushort") {
+ } else if (type.fName == "uint" || type.fName == "ushort" || type.fName == "ubyte") {
return JIT::kUInt_TypeKind;
} else if (type.fName == "float" || type.fName == "double") {
return JIT::kFloat_TypeKind;
diff --git a/src/sksl/SkSLSPIRVCodeGenerator.cpp b/src/sksl/SkSLSPIRVCodeGenerator.cpp
index 84a15f1da1..3357faaa6e 100644
--- a/src/sksl/SkSLSPIRVCodeGenerator.cpp
+++ b/src/sksl/SkSLSPIRVCodeGenerator.cpp
@@ -154,14 +154,16 @@ static bool is_signed(const Context& context, const Type& type) {
if (type.kind() == Type::kVector_Kind) {
return is_signed(context, type.componentType());
}
- return type == *context.fInt_Type || type == *context.fShort_Type;
+ return type == *context.fInt_Type || type == *context.fShort_Type ||
+ type == *context.fByte_Type;
}
static bool is_unsigned(const Context& context, const Type& type) {
if (type.kind() == Type::kVector_Kind) {
return is_unsigned(context, type.componentType());
}
- return type == *context.fUInt_Type || type == *context.fUShort_Type;
+ return type == *context.fUInt_Type || type == *context.fUShort_Type ||
+ type == *context.fUByte_Type;
}
static bool is_bool(const Context& context, const Type& type) {
@@ -433,20 +435,22 @@ Type SPIRVCodeGenerator::getActualType(const Type& type) {
if (type == *fContext.fHalf_Type) {
return *fContext.fFloat_Type;
}
- if (type == *fContext.fShort_Type) {
+ if (type == *fContext.fShort_Type || type == *fContext.fByte_Type) {
return *fContext.fInt_Type;
}
- if (type == *fContext.fUShort_Type) {
+ if (type == *fContext.fUShort_Type || type == *fContext.fUByte_Type) {
return *fContext.fUInt_Type;
}
if (type.kind() == Type::kMatrix_Kind || type.kind() == Type::kVector_Kind) {
if (type.componentType() == *fContext.fHalf_Type) {
return fContext.fFloat_Type->toCompound(fContext, type.columns(), type.rows());
}
- if (type.componentType() == *fContext.fShort_Type) {
+ if (type.componentType() == *fContext.fShort_Type ||
+ type.componentType() == *fContext.fByte_Type) {
return fContext.fInt_Type->toCompound(fContext, type.columns(), type.rows());
}
- if (type.componentType() == *fContext.fUShort_Type) {
+ if (type.componentType() == *fContext.fUShort_Type ||
+ type.componentType() == *fContext.fUByte_Type) {
return fContext.fUInt_Type->toCompound(fContext, type.columns(), type.rows());
}
}
@@ -1298,31 +1302,47 @@ SpvId SPIRVCodeGenerator::writeVectorConstructor(const Constructor& c, OutputStr
if (c.fArguments.size() == 1) {
return vec;
}
- } else if (src == *fContext.fInt_Type || src == *fContext.fShort_Type) {
+ } else if (src == *fContext.fInt_Type ||
+ src == *fContext.fShort_Type ||
+ src == *fContext.fByte_Type) {
op = SpvOpConvertSToF;
- } else if (src == *fContext.fUInt_Type || src == *fContext.fUShort_Type) {
+ } else if (src == *fContext.fUInt_Type ||
+ src == *fContext.fUShort_Type ||
+ src == *fContext.fUByte_Type) {
op = SpvOpConvertUToF;
} else {
SkASSERT(false);
}
- } else if (dst == *fContext.fInt_Type || dst == *fContext.fShort_Type) {
+ } else if (dst == *fContext.fInt_Type ||
+ dst == *fContext.fShort_Type ||
+ dst == *fContext.fByte_Type) {
if (src == *fContext.fFloat_Type || src == *fContext.fHalf_Type) {
op = SpvOpConvertFToS;
- } else if (src == *fContext.fInt_Type || src == *fContext.fShort_Type) {
+ } else if (src == *fContext.fInt_Type ||
+ src == *fContext.fShort_Type ||
+ src == *fContext.fByte_Type) {
if (c.fArguments.size() == 1) {
return vec;
}
- } else if (src == *fContext.fUInt_Type || src == *fContext.fUShort_Type) {
+ } else if (src == *fContext.fUInt_Type ||
+ src == *fContext.fUShort_Type ||
+ src == *fContext.fUByte_Type) {
op = SpvOpBitcast;
} else {
SkASSERT(false);
}
- } else if (dst == *fContext.fUInt_Type || dst == *fContext.fUShort_Type) {
+ } else if (dst == *fContext.fUInt_Type ||
+ dst == *fContext.fUShort_Type ||
+ dst == *fContext.fUByte_Type) {
if (src == *fContext.fFloat_Type || src == *fContext.fHalf_Type) {
op = SpvOpConvertFToS;
- } else if (src == *fContext.fInt_Type || src == *fContext.fShort_Type) {
+ } else if (src == *fContext.fInt_Type ||
+ src == *fContext.fShort_Type ||
+ src == *fContext.fByte_Type) {
op = SpvOpBitcast;
- } else if (src == *fContext.fUInt_Type || src == *fContext.fUShort_Type) {
+ } else if (src == *fContext.fUInt_Type ||
+ src == *fContext.fUShort_Type ||
+ src == *fContext.fUByte_Type) {
if (c.fArguments.size() == 1) {
return vec;
}
@@ -1391,9 +1411,13 @@ SpvId SPIRVCodeGenerator::writeConstructor(const Constructor& c, OutputStream& o
}
if (c.fType == *fContext.fFloat_Type || c.fType == *fContext.fHalf_Type) {
return this->writeFloatConstructor(c, out);
- } else if (c.fType == *fContext.fInt_Type || c.fType == *fContext.fShort_Type) {
+ } else if (c.fType == *fContext.fInt_Type ||
+ c.fType == *fContext.fShort_Type ||
+ c.fType == *fContext.fByte_Type) {
return this->writeIntConstructor(c, out);
- } else if (c.fType == *fContext.fUInt_Type || c.fType == *fContext.fUShort_Type) {
+ } else if (c.fType == *fContext.fUInt_Type ||
+ c.fType == *fContext.fUShort_Type ||
+ c.fType == *fContext.fUByte_Type) {
return this->writeUIntConstructor(c, out);
}
switch (c.fType.kind()) {
diff --git a/src/sksl/ir/SkSLSwizzle.h b/src/sksl/ir/SkSLSwizzle.h
index b90b78d916..e713a323b3 100644
--- a/src/sksl/ir/SkSLSwizzle.h
+++ b/src/sksl/ir/SkSLSwizzle.h
@@ -56,6 +56,12 @@ static const Type& get_type(const Context& context, Expression& value, size_t co
case 3: return *context.fShort3_Type;
case 4: return *context.fShort4_Type;
}
+ } else if (base == *context.fByte_Type) {
+ switch (count) {
+ case 2: return *context.fByte2_Type;
+ case 3: return *context.fByte3_Type;
+ case 4: return *context.fByte4_Type;
+ }
} else if (base == *context.fUInt_Type) {
switch (count) {
case 2: return *context.fUInt2_Type;
@@ -68,6 +74,12 @@ static const Type& get_type(const Context& context, Expression& value, size_t co
case 3: return *context.fUShort3_Type;
case 4: return *context.fUShort4_Type;
}
+ } else if (base == *context.fUByte_Type) {
+ switch (count) {
+ case 2: return *context.fUByte2_Type;
+ case 3: return *context.fUByte3_Type;
+ case 4: return *context.fUByte4_Type;
+ }
} else if (base == *context.fBool_Type) {
switch (count) {
case 2: return *context.fBool2_Type;
diff --git a/src/sksl/ir/SkSLType.cpp b/src/sksl/ir/SkSLType.cpp
index d5698189b8..eb3a64f872 100644
--- a/src/sksl/ir/SkSLType.cpp
+++ b/src/sksl/ir/SkSLType.cpp
@@ -169,6 +169,17 @@ const Type& Type::toCompound(const Context& context, int columns, int rows) cons
}
default: ABORT("unsupported row count (%d)", rows);
}
+ } else if (*this == *context.fByte_Type) {
+ switch (rows) {
+ case 1:
+ switch (columns) {
+ case 2: return *context.fByte2_Type;
+ case 3: return *context.fByte3_Type;
+ case 4: return *context.fByte4_Type;
+ default: ABORT("unsupported vector column count (%d)", columns);
+ }
+ default: ABORT("unsupported row count (%d)", rows);
+ }
} else if (*this == *context.fUInt_Type) {
switch (rows) {
case 1:
@@ -191,6 +202,17 @@ const Type& Type::toCompound(const Context& context, int columns, int rows) cons
}
default: ABORT("unsupported row count (%d)", rows);
}
+ } else if (*this == *context.fUByte_Type) {
+ switch (rows) {
+ case 1:
+ switch (columns) {
+ case 2: return *context.fUByte2_Type;
+ case 3: return *context.fUByte3_Type;
+ case 4: return *context.fUByte4_Type;
+ default: ABORT("unsupported vector column count (%d)", columns);
+ }
+ default: ABORT("unsupported row count (%d)", rows);
+ }
} else if (*this == *context.fBool_Type) {
switch (rows) {
case 1: