From c163c33664af1a68613ecbf0c4e747ad3ee3dbb1 Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Tue, 20 Jun 2017 09:24:31 -0700 Subject: Fix types for `InputPatch` and `OutputPatch` Fixes #34. I'd declared these as if they were `InputPatch`, but they are really `InputPatch`. This change fixes the declarations, and makes these types no longer inherit from the contrived `BuiltinGenericType`. Instead they are more-or-less ordinary `DeclRefType`s using the same approach that `MatrixExpressionType` uses. --- source/slang/slang-stdlib.cpp | 4 ++-- source/slang/syntax.cpp | 31 +++++++++++++++++++++++++++++-- source/slang/syntax.h | 11 +++++++++-- 3 files changed, 40 insertions(+), 6 deletions(-) (limited to 'source') diff --git a/source/slang/slang-stdlib.cpp b/source/slang/slang-stdlib.cpp index 9ff8a1078..19827285c 100644 --- a/source/slang/slang-stdlib.cpp +++ b/source/slang/slang-stdlib.cpp @@ -78,12 +78,12 @@ __generic __magic_type(HLSLConsumeStructuredBufferType) struct ConsumeStructu out uint stride); }; -__generic __magic_type(HLSLInputPatchType) struct InputPatch +__generic __magic_type(HLSLInputPatchType) struct InputPatch { __intrinsic __subscript(uint index) -> T; }; -__generic __magic_type(HLSLOutputPatchType) struct OutputPatch +__generic __magic_type(HLSLOutputPatchType) struct OutputPatch { __intrinsic __subscript(uint index) -> T { set; } }; diff --git a/source/slang/syntax.cpp b/source/slang/syntax.cpp index d37f782f6..f78d3c8ec 100644 --- a/source/slang/syntax.cpp +++ b/source/slang/syntax.cpp @@ -525,6 +525,22 @@ namespace Slang return textureType; } + // TODO: eventually everything should follow this pattern, + // and we can drive the dispatch with a table instead + // of this ridiculously slow `if` cascade. + + #define CASE(n,T) \ + else if(magicMod->name == #n) { \ + auto type = new T(); \ + type->declRef = declRef; \ + return type; \ + } + + CASE(HLSLInputPatchType, HLSLInputPatchType) + CASE(HLSLOutputPatchType, HLSLOutputPatchType) + + #undef CASE + #define CASE(n,T) \ else if(magicMod->name == #n) { \ assert(subst && subst->args.Count() == 1); \ @@ -550,8 +566,6 @@ namespace Slang CASE(HLSLRWStructuredBufferType, HLSLRWStructuredBufferType) CASE(HLSLAppendStructuredBufferType, HLSLAppendStructuredBufferType) CASE(HLSLConsumeStructuredBufferType, HLSLConsumeStructuredBufferType) - CASE(HLSLInputPatchType, HLSLInputPatchType) - CASE(HLSLOutputPatchType, HLSLOutputPatchType) CASE(HLSLPointStreamType, HLSLPointStreamType) CASE(HLSLLineStreamType, HLSLPointStreamType) @@ -1470,4 +1484,17 @@ namespace Slang return IntrinsicOp::Unknown; } + // + + // HLSLPatchType + + ExpressionType* HLSLPatchType::getElementType() + { + return this->declRef.substitutions->args[0].As().Ptr(); + } + + IntVal* HLSLPatchType::getElementCount() + { + return this->declRef.substitutions->args[1].As().Ptr(); + } } \ No newline at end of file diff --git a/source/slang/syntax.h b/source/slang/syntax.h index 56574d124..66eddc536 100644 --- a/source/slang/syntax.h +++ b/source/slang/syntax.h @@ -1044,8 +1044,15 @@ namespace Slang class HLSLAppendStructuredBufferType : public BuiltinGenericType {}; class HLSLConsumeStructuredBufferType : public BuiltinGenericType {}; - class HLSLInputPatchType : public BuiltinGenericType {}; - class HLSLOutputPatchType : public BuiltinGenericType {}; + class HLSLPatchType : public DeclRefType + { + public: + ExpressionType* getElementType(); + IntVal* getElementCount(); + }; + + class HLSLInputPatchType : public HLSLPatchType {}; + class HLSLOutputPatchType : public HLSLPatchType {}; // HLSL geometry shader output stream types -- cgit v1.2.3