From 7f7864e80e8b5631ba5ec1aa9657fdaf1b4adb06 Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Wed, 21 Jun 2017 10:43:25 -0700 Subject: Support texture `Gather*()` operations The catch with these operations is that they return a vector based on the scalar of the element type of the texture. That is, given `Texture2D t` the operation `t.GatherRed(...)` should return a `float4`. The ideal way to solve this would use associated types, but we aren't there yet, so I am using extension declarations. An extension can "capture" the identity of the element type, like so: __generic __extension Texture2D > { ... } That extension will match `Texture2D` and correctly capture `T == float`, so that we can use it in other operations. Getting this working required a bunch of changes: - Actually emit the relevant extension declarations in the stdlib - Fix the parser to be able to parse `Texture2D >` (that is, a nested generic app). - I actually went ahead and significantly overhauled the expression parser while I was there, because I just couldn't deal with the existing code any longer. - Added support for general-case lookup to look through `__extension` declarations. I had logic in place to special-case this for looking up "constructors" but hadn't done anything for general member lookup yet. - This required some annoying holes to be punched through the layers, because lookup might need to invoke semantic analysis to ensure that an extension has been checked. - There is some first-pass code trying to support looking up a `typedef` nested inside the `vector` type. This is a nice idea in principle, but the problem is that the `Texture2D` definition would be looking up `T.Element` and not `float4.Element`, and that means we'd need machinery for doing lookup *through* interface conformances for a type parameter like `T` The big gotcha here is that none of this logic applies to `Texture2D` (the original case I mentioned) because I am matching vector types and not scalars. Matching scalars *should* be as easy as: __generic __extension Texture2D { ... } But I'd need to confirm that interface constraints like that actually work, or else that extension would *also* apply to `Texture2D` and break everything. --- source/slang/syntax.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'source/slang/syntax.h') diff --git a/source/slang/syntax.h b/source/slang/syntax.h index 66eddc536..5eb62462e 100644 --- a/source/slang/syntax.h +++ b/source/slang/syntax.h @@ -632,7 +632,7 @@ namespace Slang class Decl : public DeclBase { public: - ContainerDecl* ParentDecl; + ContainerDecl* ParentDecl = nullptr; Token Name; String const& getName() { return Name.Content; } @@ -1883,12 +1883,16 @@ namespace Slang bool isOverloaded() const { return items.Count() > 1; } }; + class SemanticsVisitor; + struct LookupRequest { - RefPtr scope = nullptr; - RefPtr endScope = nullptr; + SemanticsVisitor* semantics = nullptr; + + RefPtr scope = nullptr; + RefPtr endScope = nullptr; - LookupMask mask = LookupMask::All; + LookupMask mask = LookupMask::All; }; // An expression that references an overloaded set of declarations -- cgit v1.2.3