Fixed unsupported type errors in pure DSL
Change-Id: I5a57e2db46734ca08825e6aef7a6363bcaada45a Reviewed-on: https://skia-review.googlesource.com/c/skia/+/453759 Commit-Queue: Ethan Nicholas <ethannicholas@google.com> Reviewed-by: Brian Osman <brianosman@google.com> Reviewed-by: John Stiles <johnstiles@google.com>
This commit is contained in:
parent
a7d1e5c11c
commit
de42a9d2fc
@ -155,20 +155,22 @@ public:
|
||||
template<typename... Args>
|
||||
static DSLExpression Construct(DSLType type, DSLVarBase& var, Args&&... args) {
|
||||
DSLExpression argArray[] = {var, args...};
|
||||
return Construct(type, SkMakeSpan(argArray));
|
||||
return Construct(type, SkMakeSpan(argArray), PositionInfo());
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
static DSLExpression Construct(DSLType type, DSLExpression expr, Args&&... args) {
|
||||
DSLExpression argArray[] = {std::move(expr), std::move(args)...};
|
||||
return Construct(type, SkMakeSpan(argArray));
|
||||
return Construct(type, SkMakeSpan(argArray), PositionInfo());
|
||||
}
|
||||
|
||||
static DSLExpression Construct(DSLType type, SkSpan<DSLExpression> argArray);
|
||||
static DSLExpression Construct(DSLType type, SkSpan<DSLExpression> argArray, PositionInfo pos);
|
||||
|
||||
private:
|
||||
const SkSL::Type& skslType() const;
|
||||
|
||||
void reportIllegalTypes(PositionInfo pos) const;
|
||||
|
||||
const SkSL::Type* fSkSLType = nullptr;
|
||||
|
||||
TypeConstant fTypeConstant = kPoison_Type;
|
||||
@ -176,6 +178,7 @@ private:
|
||||
friend DSLType Array(const DSLType& base, int count, PositionInfo pos);
|
||||
friend DSLType Struct(skstd::string_view name, SkSpan<DSLField> fields, PositionInfo pos);
|
||||
friend class DSLCore;
|
||||
friend class DSLField;
|
||||
friend class DSLFunction;
|
||||
friend class DSLVarBase;
|
||||
friend class DSLWriter;
|
||||
@ -232,7 +235,9 @@ public:
|
||||
: fModifiers(modifiers)
|
||||
, fType(type)
|
||||
, fName(name)
|
||||
, fPosition(pos) {}
|
||||
, fPosition(pos) {
|
||||
type.reportIllegalTypes(pos);
|
||||
}
|
||||
|
||||
private:
|
||||
DSLModifiers fModifiers;
|
||||
|
@ -231,7 +231,8 @@ public:
|
||||
const SkSL::Type* structType = DSLWriter::SymbolTable()->takeOwnershipOfSymbol(
|
||||
SkSL::Type::MakeStructType(pos.line(), typeName, std::move(skslFields)));
|
||||
DSLType varType = arraySize > 0 ? Array(structType, arraySize) : DSLType(structType);
|
||||
DSLGlobalVar var(modifiers, varType, !varName.empty() ? varName : typeName);
|
||||
DSLGlobalVar var(modifiers, varType, !varName.empty() ? varName : typeName, DSLExpression(),
|
||||
pos);
|
||||
// Interface blocks can't be declared, so we always need to mark the var declared ourselves.
|
||||
// We do this only when fDSLMarkVarDeclared is false, so we don't double-declare it.
|
||||
if (!DSLWriter::Settings().fDSLMarkVarsDeclared) {
|
||||
|
@ -15,33 +15,22 @@ namespace SkSL {
|
||||
|
||||
namespace dsl {
|
||||
|
||||
static const Type* find_type(skstd::string_view name, PositionInfo pos) {
|
||||
static const SkSL::Type* find_type(skstd::string_view name, PositionInfo pos) {
|
||||
const Symbol* symbol = (*DSLWriter::SymbolTable())[name];
|
||||
if (!symbol) {
|
||||
DSLWriter::ReportError(String::printf("no symbol named '%.*s'", (int)name.length(),
|
||||
name.data()), pos);
|
||||
return nullptr;
|
||||
}
|
||||
if (!symbol->is<Type>()) {
|
||||
if (!symbol->is<SkSL::Type>()) {
|
||||
DSLWriter::ReportError(String::printf("symbol '%.*s' is not a type", (int)name.length(),
|
||||
name.data()), pos);
|
||||
return nullptr;
|
||||
}
|
||||
const Type& result = symbol->as<Type>();
|
||||
if (!DSLWriter::IsModule()) {
|
||||
if (result.containsPrivateFields()) {
|
||||
DSLWriter::ReportError("type '" + String(name) + "' is private", pos);
|
||||
return nullptr;
|
||||
}
|
||||
if (DSLWriter::Context().fConfig->strictES2Mode() && !result.allowedInES2()) {
|
||||
DSLWriter::ReportError("type '" + String(name) + "' is not supported", pos);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
return &result;
|
||||
return &symbol->as<SkSL::Type>();
|
||||
}
|
||||
|
||||
static const Type* find_type(skstd::string_view name, Modifiers* modifiers,
|
||||
static const SkSL::Type* find_type(skstd::string_view name, Modifiers* modifiers,
|
||||
PositionInfo pos) {
|
||||
const Type* type = find_type(name, pos);
|
||||
if (!type) {
|
||||
@ -216,8 +205,25 @@ const SkSL::Type& DSLType::skslType() const {
|
||||
}
|
||||
}
|
||||
|
||||
DSLExpression DSLType::Construct(DSLType type, SkSpan<DSLExpression> argArray) {
|
||||
return DSLWriter::Construct(type.skslType(), std::move(argArray));
|
||||
void DSLType::reportIllegalTypes(PositionInfo pos) const {
|
||||
if (!DSLWriter::IsModule()) {
|
||||
const SkSL::Type* type = &this->skslType();
|
||||
while (type->isArray()) {
|
||||
type = &type->componentType();
|
||||
}
|
||||
if (type->containsPrivateFields()) {
|
||||
DSLWriter::ReportError("type '" + String(type->name()) + "' is private", pos);
|
||||
}
|
||||
if (DSLWriter::Context().fConfig->strictES2Mode() && !type->allowedInES2()) {
|
||||
DSLWriter::ReportError("type '" + String(type->name()) + "' is not supported", pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DSLExpression DSLType::Construct(DSLType type, SkSpan<DSLExpression> argArray, PositionInfo pos) {
|
||||
const SkSL::Type& skslType = type.skslType();
|
||||
type.reportIllegalTypes(pos);
|
||||
return DSLExpression(DSLWriter::Construct(skslType, std::move(argArray)), pos);
|
||||
}
|
||||
|
||||
DSLType Array(const DSLType& base, int count, PositionInfo pos) {
|
||||
|
@ -41,6 +41,7 @@ DSLVarBase::DSLVarBase(const DSLModifiers& modifiers, DSLType type, skstd::strin
|
||||
, fInitialValue(std::move(initialValue))
|
||||
, fDeclared(DSLWriter::MarkVarsDeclared())
|
||||
, fPosition(pos) {
|
||||
type.reportIllegalTypes(pos);
|
||||
if (fModifiers.fModifiers.fFlags & Modifiers::kUniform_Flag) {
|
||||
#if SK_SUPPORT_GPU && !defined(SKSL_STANDALONE)
|
||||
if (DSLWriter::InFragmentProcessor()) {
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
#include "include/private/SkSLIRNode.h"
|
||||
#include "include/sksl/DSL.h"
|
||||
#include "include/sksl/DSLRuntimeEffects.h"
|
||||
#include "src/gpu/GrDirectContextPriv.h"
|
||||
#include "src/gpu/GrGpu.h"
|
||||
#include "src/sksl/SkSLIRGenerator.h"
|
||||
@ -2147,3 +2148,28 @@ DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLModifiersDeclaration, r, ctxInfo) {
|
||||
REPORTER_ASSERT(r, DSLWriter::ProgramElements().size() == 1);
|
||||
EXPECT_EQUAL(*DSLWriter::ProgramElements()[0], "layout(blend_support_all_equations) out;");
|
||||
}
|
||||
|
||||
DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLES3Types, r, ctxInfo) {
|
||||
StartRuntimeShader(ctxInfo.directContext()->priv().getGpu()->shaderCompiler());
|
||||
{
|
||||
ExpectError error(r, "type 'uint' is not supported");
|
||||
Var u(kUInt_Type, "u");
|
||||
}
|
||||
{
|
||||
ExpectError error(r, "type 'float3x2' is not supported");
|
||||
Float3x2(1).release();
|
||||
}
|
||||
{
|
||||
ExpectError error(r, "type 'uint' is not supported");
|
||||
Var u(kUInt_Type, "u");
|
||||
}
|
||||
{
|
||||
ExpectError error(r, "type '$genType' is private");
|
||||
Var g(DSLType("$genType"), "g");
|
||||
}
|
||||
Parameter p(kFloat2_Type, "p");
|
||||
Function(kHalf4_Type, "main", p).define(
|
||||
Return(Half4(0))
|
||||
);
|
||||
EndRuntimeShader();
|
||||
}
|
||||
|
@ -1,7 +1,8 @@
|
||||
### Compilation failed:
|
||||
|
||||
error: 2: type '$mat' is private
|
||||
error: 1: type 'InterfaceBlock' is private
|
||||
error: 6: type '$bvec' is private
|
||||
error: 9: type '$ivec' is private
|
||||
error: 10: type '$genType' is private
|
||||
4 errors
|
||||
5 errors
|
||||
|
Loading…
Reference in New Issue
Block a user