diff options
| author | Yong He <yonghe@outlook.com> | 2022-08-16 17:11:54 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-08-16 17:11:54 -0700 |
| commit | 42f49937ffa69c82e333e886952eed027e12340e (patch) | |
| tree | 08e3e9821dd40e23476060215d589e29092adb53 /source | |
| parent | e68fab2bda5d979f8d991fc41122bb9aa71849a6 (diff) | |
Add gfx interface definition in Slang. (#2364)
* Add gfx interface definition in Slang.
- add gfx interface definitons in Slang.
- fix slang compiler to correctly type-check `out` interface argument.
- modify gfx interface to be fully COM compatible
- add convenient ShaderProgram creation methods to gfx.
* Fix compile errors and warnings.
* Update project files
* Fix cuda.
* Properly implement queryInterface in command encoder impls.
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source')
| -rw-r--r-- | source/slang/core.meta.slang | 77 | ||||
| -rw-r--r-- | source/slang/slang-ast-type.h | 7 | ||||
| -rw-r--r-- | source/slang/slang-check-decl.cpp | 30 | ||||
| -rw-r--r-- | source/slang/slang-check-overload.cpp | 9 | ||||
| -rwxr-xr-x | source/slang/slang-compiler.h | 15 | ||||
| -rw-r--r-- | source/slang/slang-diagnostic-defs.h | 3 | ||||
| -rw-r--r-- | source/slang/slang-lower-to-ir.cpp | 20 |
7 files changed, 149 insertions, 12 deletions
diff --git a/source/slang/core.meta.slang b/source/slang/core.meta.slang index d912fe8ce..42295eeca 100644 --- a/source/slang/core.meta.slang +++ b/source/slang/core.meta.slang @@ -428,6 +428,9 @@ extension bool __implicit_conversion($(kConversionCost_PtrToBool)) __intrinsic_op($(kIROp_CastPtrToBool)) __init(Ptr<T> ptr); + + static bool maxValue = true; + static bool minValue = false; } extension uint64_t @@ -435,6 +438,9 @@ extension uint64_t __generic<T> __intrinsic_op($(kIROp_Construct)) __init(Ptr<T> ptr); + + static uint64_t maxValue = 0xFFFFFFFFFFFFFFFFULL; + static uint64_t minValue = 0; } extension int64_t @@ -442,6 +448,9 @@ extension int64_t __generic<T> __intrinsic_op($(kIROp_Construct)) __init(Ptr<T> ptr); + + static int64_t maxValue = 0x7FFFFFFFFFFFFFFFLL; + static int64_t minValue = -0x8000000000000000LL; } __generic<T> @@ -509,6 +518,28 @@ bool operator!=(__none_t noneVal, Optional<T> val) return val.hasValue; } +__generic<T> +__magic_type(NativeRefType) +__intrinsic_type($(kIROp_NativePtrType)) +struct NativeRef +{ + __intrinsic_op($(kIROp_GetNativePtr)) + __init(T val); +}; + +__generic<T> +__intrinsic_op($(kIROp_ManagedPtrAttach)) +void __managed_ptr_attach(__ref T val, NativeRef<T> nativeVal); + +__generic<T> +[__unsafeForceInlineEarly] +T __attachToNativeRef(NativeRef<T> nativeVal) +{ + T result; + __managed_ptr_attach(result, nativeVal); + return result; +} + __magic_type(StringType) __intrinsic_type($(kIROp_StringType)) struct String @@ -524,6 +555,52 @@ __intrinsic_type($(kIROp_DynamicType)) struct __Dynamic {}; +extension float +{ + static float maxValue = 340282346638528859811704183484516925440.0f; +} + +extension double +{ + static double maxValue = 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.0; +} + +extension int +{ + static int maxValue = 2147483647; + static int minValue = -2147483648; +} + +extension uint +{ + static uint maxValue = 4294967295; + static uint minValue = 0; +} + +extension int8_t +{ + static int8_t maxValue = 127; + static int8_t minValue = -128; +} + +extension uint16_t +{ + static uint16_t maxValue = 255; + static uint16_t minValue = 0; +} + +extension int16_t +{ + static int16_t maxValue = 32767; + static int16_t minValue = -32768; +} + +extension uint16_t +{ + static uint16_t maxValue = 65535; + static uint16_t minValue = 0; +} + /// An `N` component vector with elements of type `T`. __generic<T = float, let N : int = 4> __magic_type(Vector) diff --git a/source/slang/slang-ast-type.h b/source/slang/slang-ast-type.h index 0ee0fce2c..458c24a23 100644 --- a/source/slang/slang-ast-type.h +++ b/source/slang/slang-ast-type.h @@ -583,6 +583,13 @@ class OptionalType : public BuiltinType Type* getValueType(); }; +// A raw-pointer reference to an managed value. +class NativeRefType : public BuiltinType +{ + SLANG_AST_CLASS(NativeRefType) + Type* getValueType(); +}; + // A type alias of some kind (e.g., via `typedef`) class NamedExpressionType : public Type { diff --git a/source/slang/slang-check-decl.cpp b/source/slang/slang-check-decl.cpp index 22567c889..f2a339643 100644 --- a/source/slang/slang-check-decl.cpp +++ b/source/slang/slang-check-decl.cpp @@ -3063,10 +3063,37 @@ namespace Slang InheritanceDecl* inheritanceDecl, ContainerDecl* parentDecl) { + auto superType = inheritanceDecl->base.type; + if( auto declRefType = as<DeclRefType>(subType) ) { auto declRef = declRefType->declRef; + if (auto superDeclRefType = as<DeclRefType>(superType)) + { + auto superTypeDecl = superDeclRefType->declRef.getDecl(); + if (superTypeDecl->findModifier<ComInterfaceAttribute>()) + { + // A struct cannot implement a COM Interface. + if (auto classDecl = as<ClassDecl>(superTypeDecl)) + { + // OK. + SLANG_UNUSED(classDecl); + } + else if (auto subInterfaceDecl = as<InterfaceDecl>(superTypeDecl)) + { + if (!subInterfaceDecl->findModifier<ComInterfaceAttribute>()) + { + getSink()->diagnose(inheritanceDecl, Diagnostics::interfaceInheritingComMustBeCom); + } + } + else if (auto structDecl = as<StructDecl>(superTypeDecl)) + { + getSink()->diagnose(inheritanceDecl, Diagnostics::structCannotImplementComInterface); + } + } + } + // Don't check conformances for abstract types that // are being used to express *required* conformances. if (auto assocTypeDeclRef = declRef.as<AssocTypeDecl>()) @@ -3089,11 +3116,12 @@ namespace Slang // code to work. return true; } + + } // Look at the type being inherited from, and validate // appropriately. - auto superType = inheritanceDecl->base.type; DeclaredSubtypeWitness* subIsSuperWitness = m_astBuilder->create<DeclaredSubtypeWitness>(); subIsSuperWitness->declRef = makeDeclRef(inheritanceDecl); diff --git a/source/slang/slang-check-overload.cpp b/source/slang/slang-check-overload.cpp index 879c49da0..36c93a2e2 100644 --- a/source/slang/slang-check-overload.cpp +++ b/source/slang/slang-check-overload.cpp @@ -1443,8 +1443,15 @@ namespace Slang arg = maybeOpenRef(arg); } - for (auto& arg : expr->arguments) + auto funcType = as<FuncType>(funcExprType); + for (Index i = 0; i < expr->arguments.getCount(); i++) { + auto& arg = expr->arguments[i]; + if (funcType && i < (Index)funcType->getParamCount()) + { + if (funcType->getParamDirection(i) == kParameterDirection_Out) + continue; + } arg = maybeOpenExistential(arg); } diff --git a/source/slang/slang-compiler.h b/source/slang/slang-compiler.h index 97111f540..0dbaa9099 100755 --- a/source/slang/slang-compiler.h +++ b/source/slang/slang-compiler.h @@ -1210,6 +1210,21 @@ namespace Slang return SLANG_OK; } + virtual SlangInt32 SLANG_MCALL getDefinedEntryPointCount() override + { + return (SlangInt32)m_entryPoints.getCount(); + } + + virtual SlangResult SLANG_MCALL getDefinedEntryPoint(SlangInt32 index, slang::IEntryPoint** outEntryPoint) override + { + if (index < 0 || index >= m_entryPoints.getCount()) + return SLANG_E_INVALID_ARG; + + ComPtr<slang::IEntryPoint> entryPoint(m_entryPoints[index].Ptr()); + *outEntryPoint = entryPoint.detach(); + return SLANG_OK; + } + // /// Create a module (initially empty). diff --git a/source/slang/slang-diagnostic-defs.h b/source/slang/slang-diagnostic-defs.h index 6acd27e40..0fa5d64a7 100644 --- a/source/slang/slang-diagnostic-defs.h +++ b/source/slang/slang-diagnostic-defs.h @@ -324,6 +324,9 @@ DIAGNOSTIC(31121, Error, anyValueSizeExceedsLimit, "'anyValueSize' cannot exceed DIAGNOSTIC(31122, Error, associatedTypeNotAllowInComInterface, "associatedtype not allowed in a [COM] interface") DIAGNOSTIC(31123, Error, invalidGUID, "'$0' is not a valid GUID") +DIAGNOSTIC(31124, Error, structCannotImplementComInterface, "a struct type cannot implement a [COM] interface") +DIAGNOSTIC(31124, Error, interfaceInheritingComMustBeCom, "an interface type that inherits from a [COM] interface must itself be a [COM] interface") + // Enums diff --git a/source/slang/slang-lower-to-ir.cpp b/source/slang/slang-lower-to-ir.cpp index 81ea93f77..1f3da064a 100644 --- a/source/slang/slang-lower-to-ir.cpp +++ b/source/slang/slang-lower-to-ir.cpp @@ -8180,16 +8180,16 @@ bool canDeclLowerToAGeneric(Decl* decl) static bool isInterfaceRequirement(Decl* decl) { - auto ancestor = decl->parentDecl; - for(; ancestor; ancestor = ancestor->parentDecl ) - { - if(as<InterfaceDecl>(ancestor)) - return true; - - if(as<ExtensionDecl>(ancestor)) - return false; - } - return false; + auto ancestor = decl->parentDecl; + for (; ancestor; ancestor = ancestor->parentDecl) + { + if (as<InterfaceDecl>(ancestor)) + return true; + + if (as<ExtensionDecl>(ancestor)) + return false; + } + return false; } /// Add flattened "leaf" elements from `val` to the `ioArgs` list |
