From a22b7520745334ecef3cbd920a0331f01c905935 Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Thu, 8 Mar 2018 12:35:00 -0800 Subject: Cleanups on slang-generate (#437) * Cleanups on slang-generate There is nothing too significant in these changes, but I'm trying to get things in place so that we can: - Clean up the stdlib code to do less explicit `StringBuilder` operations and instead to use more of the "template engine" approach - Start using slang-generate for code other than the slang stdlib, so that we can generate more of our boilerplate. The main new functionality here is that in a template/meta file, you can now enclose an expression in `$(...)` to indicate that is should be spliced into the result. E.g. instead of: class ${{ sb << someClassName; }} { ... } We can now write: class $(someClassName) { ... } The other bit of new functionality is support for a whole-line statement escape, so that instead of: ${{ for( auto a : someCollection ) { }} void $(a)() { ... } ${{ } }} We can instead write: $: for(auto a : someCollection) { void $(a)() { ... } $: } I haven't yet tried to use that functionality in the stdlib meta-code, but doing so would be an obvious next step. * Fixup: change some $P to $p The capitalization on some of the GLSL intrinsic mappings got messed up during a find-and-replace operation when removing the double `$` that used to be required to escape things. --- source/core/slang-string.cpp | 20 + source/core/slang-string.h | 11 + source/slang/core.meta.slang | 53 +- source/slang/core.meta.slang.h | 131 ++- source/slang/glsl.meta.slang | 5 +- source/slang/glsl.meta.slang.h | 12 +- source/slang/hlsl.meta.slang | 20 +- source/slang/hlsl.meta.slang.h | 2116 ++++++++++++++++++++-------------------- source/slang/slang-stdlib.cpp | 3 + 9 files changed, 1181 insertions(+), 1190 deletions(-) (limited to 'source') diff --git a/source/core/slang-string.cpp b/source/core/slang-string.cpp index 460a077b5..2420cb7d7 100644 --- a/source/core/slang-string.cpp +++ b/source/core/slang-string.cpp @@ -43,6 +43,26 @@ namespace Slang return endData ? endData : kEmptyOSString; } + // UnownedStringSlice + + bool UnownedStringSlice::endsWith(UnownedStringSlice const& other) const + { + UInt thisSize = size(); + UInt otherSize = other.size(); + + if (otherSize > thisSize) + return false; + + return UnownedStringSlice( + end() - otherSize, end()) == other; + } + + bool UnownedStringSlice::endsWith(char const* str) const + { + return endsWith(UnownedTerminatedStringSlice(str)); + } + + // StringSlice StringSlice::StringSlice() diff --git a/source/core/slang-string.h b/source/core/slang-string.h index a0f2b48a1..7d8d3eb81 100644 --- a/source/core/slang-string.h +++ b/source/core/slang-string.h @@ -170,11 +170,22 @@ namespace Slang return (*this) == UnownedStringSlice(str, str + strlen(str)); } + bool endsWith(UnownedStringSlice const& other) const; + bool endsWith(char const* str) const; + private: char const* beginData; char const* endData; }; + struct UnownedTerminatedStringSlice : public UnownedStringSlice + { + public: + UnownedTerminatedStringSlice(char const* b) + : UnownedStringSlice(b, b + strlen(b)) + {} + }; + struct StringSlice { public: diff --git a/source/slang/core.meta.slang b/source/slang/core.meta.slang index e4fd8291b..b0b233b1d 100644 --- a/source/slang/core.meta.slang +++ b/source/slang/core.meta.slang @@ -97,7 +97,6 @@ for (int tt = 0; tt < kBaseTypeCount; ++tt) // Declare built-in pointer type // (eventually we can have the traditional syntax sugar for this) - }}}} __generic @@ -116,8 +115,6 @@ struct InOut {}; ${{{{ - - // Declare vector and matrix types sb << "__generic __magic_type(Vector) struct vector\n{\n"; @@ -132,8 +129,6 @@ sb << " __init(T value);\n"; sb << " __init(vector value);\n"; sb << "};\n"; - -// TODO: Probably need to do similar }}}} __generic @@ -141,9 +136,6 @@ __magic_type(Matrix) struct matrix {}; ${{{{ - - - static const struct { char const* name; char const* glslPrefix; @@ -475,7 +467,7 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) lodStr.append(")"); } - String opStr = " = textureSize($$P" + lodStr; + String opStr = " = textureSize($P" + lodStr; switch( access ) { case SLANG_RESOURCE_ACCESS_READ_WRITE: @@ -522,12 +514,12 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) if(isMultisample) { - sb << ", ($" << aa++ << " = textureSamples($$P))"; + sb << ", ($" << aa++ << " = textureSamples($P))"; } if (includeMipInfo) { - sb << ", ($" << aa++ << " = textureQueryLevels($$P))"; + sb << ", ($" << aa++ << " = textureQueryLevels($P))"; } @@ -599,11 +591,11 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) if (isMultisample) { - sb << "__target_intrinsic(glsl, \"texelFetch($$P, $1, $3)\")\n"; + sb << "__target_intrinsic(glsl, \"texelFetch($P, $1, $3)\")\n"; } else { - sb << "__target_intrinsic(glsl, \"texelFetch($$P, ($1)." << kGLSLLoadCoordsSwizzle[loadCoordCount] << ", ($1)." << kGLSLLoadLODSwizzle[loadCoordCount] << ")\")\n"; + sb << "__target_intrinsic(glsl, \"texelFetch($P, ($1)." << kGLSLLoadCoordsSwizzle[loadCoordCount] << ", ($1)." << kGLSLLoadLODSwizzle[loadCoordCount] << ")\")\n"; } sb << "T Load("; sb << "int" << loadCoordCount << " location"; @@ -615,11 +607,11 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) if (isMultisample) { - sb << "__target_intrinsic(glsl, \"texelFetchOffset($$P, $0, $1, $2)\")\n"; + sb << "__target_intrinsic(glsl, \"texelFetchOffset($P, $0, $1, $2)\")\n"; } else { - sb << "__target_intrinsic(glsl, \"texelFetch($$P, ($1)." << kGLSLLoadCoordsSwizzle[loadCoordCount] << ", ($1)." << kGLSLLoadLODSwizzle[loadCoordCount] << ", $2)\")\n"; + sb << "__target_intrinsic(glsl, \"texelFetch($P, ($1)." << kGLSLLoadCoordsSwizzle[loadCoordCount] << ", ($1)." << kGLSLLoadLODSwizzle[loadCoordCount] << ", $2)\")\n"; } sb << "T Load("; sb << "int" << loadCoordCount << " location"; @@ -655,7 +647,7 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) // subscript operator sb << "__subscript(" << uintN << " location) -> T {\n"; - sb << "__target_intrinsic(glsl, \"texelFetch($$P, " << ivecN << "($1)"; + sb << "__target_intrinsic(glsl, \"texelFetch($P, " << ivecN << "($1)"; if( !isMultisample ) { @@ -667,7 +659,7 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) sb << ", 0"; } - sb << ")$$z\") get;\n"; + sb << ")$z\") get;\n"; // Depending on the access level of the texture type, // we either have just a getter (the default), or both @@ -690,7 +682,7 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) { // `Sample()` - sb << "__target_intrinsic(glsl, \"texture($$p, $2)\")\n"; + sb << "__target_intrinsic(glsl, \"texture($p, $2)\")\n"; // TODO: only enable if IR is being used? // sb << "__intrinsic_op(sample)\n"; @@ -700,7 +692,7 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) if( baseShape != TextureFlavor::Shape::ShapeCube ) { - sb << "__target_intrinsic(glsl, \"textureOffset($$p, $2, $3)\")\n"; + sb << "__target_intrinsic(glsl, \"textureOffset($p, $2, $3)\")\n"; sb << "T Sample(SamplerState s, "; sb << "float" << kBaseTextureTypes[tt].coordCount + isArray << " location, "; sb << "constexpr int" << kBaseTextureTypes[tt].coordCount << " offset);\n"; @@ -724,13 +716,13 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) // `SampleBias()` - sb << "__target_intrinsic(glsl, \"texture($$p, $2, $3)\")\n"; + sb << "__target_intrinsic(glsl, \"texture($p, $2, $3)\")\n"; sb << "T SampleBias(SamplerState s, "; sb << "float" << kBaseTextureTypes[tt].coordCount + isArray << " location, float bias);\n"; if( baseShape != TextureFlavor::Shape::ShapeCube ) { - sb << "__target_intrinsic(glsl, \"textureOffset($$p, $2, $3, $4)\")\n"; + sb << "__target_intrinsic(glsl, \"textureOffset($p, $2, $3, $4)\")\n"; sb << "T SampleBias(SamplerState s, "; sb << "float" << kBaseTextureTypes[tt].coordCount + isArray << " location, float bias, "; sb << "constexpr int" << kBaseTextureTypes[tt].coordCount << " offset);\n"; @@ -751,7 +743,7 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) if (extCoordCount < 3) extCoordCount = 3; - sb << "__target_intrinsic(glsl, \"textureLod($$p, "; + sb << "__target_intrinsic(glsl, \"textureLod($p, "; sb << "vec" << extCoordCount << "($2,"; for (int ii = arrCoordCount; ii < extCoordCount - 1; ++ii) @@ -769,7 +761,7 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) if (extCoordCount < 3) extCoordCount = 3; - sb << "__target_intrinsic(glsl, \"textureGrad($$p, "; + sb << "__target_intrinsic(glsl, \"textureGrad($p, "; sb << "vec" << extCoordCount << "($2,"; for (int ii = arrCoordCount; ii < extCoordCount - 1; ++ii) @@ -809,7 +801,7 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) } - sb << "__target_intrinsic(glsl, \"textureGrad($$p, $2, $3, $4)\")\n"; + sb << "__target_intrinsic(glsl, \"textureGrad($p, $2, $3, $4)\")\n"; // sb << "__intrinsic_op(sampleGrad)\n"; sb << "T SampleGrad(SamplerState s, "; sb << "float" << kBaseTextureTypes[tt].coordCount + isArray << " location, "; @@ -819,7 +811,7 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) if( baseShape != TextureFlavor::Shape::ShapeCube ) { - sb << "__target_intrinsic(glsl, \"textureGradOffset($$p, $2, $3, $4, $5)\")\n"; + sb << "__target_intrinsic(glsl, \"textureGradOffset($p, $2, $3, $4, $5)\")\n"; // sb << "__intrinsic_op(sampleGrad)\n"; sb << "T SampleGrad(SamplerState s, "; sb << "float" << kBaseTextureTypes[tt].coordCount + isArray << " location, "; @@ -830,14 +822,14 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) // `SampleLevel` - sb << "__target_intrinsic(glsl, \"textureLod($$p, $2, $3)\")\n"; + sb << "__target_intrinsic(glsl, \"textureLod($p, $2, $3)\")\n"; sb << "T SampleLevel(SamplerState s, "; sb << "float" << kBaseTextureTypes[tt].coordCount + isArray << " location, "; sb << "float level);\n"; if( baseShape != TextureFlavor::Shape::ShapeCube ) { - sb << "__target_intrinsic(glsl, \"textureLodOffset($$p, $2, $3, $4)\")\n"; + sb << "__target_intrinsic(glsl, \"textureLodOffset($p, $2, $3, $4)\")\n"; sb << "T SampleLevel(SamplerState s, "; sb << "float" << kBaseTextureTypes[tt].coordCount + isArray << " location, "; sb << "float level, "; @@ -904,12 +896,12 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) EMIT_LINE_DIRECTIVE(); - sb << "__target_intrinsic(glsl, \"textureGather($$p, $2, " << componentIndex << ")\")\n"; + sb << "__target_intrinsic(glsl, \"textureGather($p, $2, " << componentIndex << ")\")\n"; sb << "vector Gather" << componentName << "(SamplerState s, "; sb << "float" << kBaseTextureTypes[tt].coordCount << " location);\n"; EMIT_LINE_DIRECTIVE(); - sb << "__target_intrinsic(glsl, \"textureGatherOffset($$p, $2, $3, " << componentIndex << ")\")\n"; + sb << "__target_intrinsic(glsl, \"textureGatherOffset($p, $2, $3, " << componentIndex << ")\")\n"; sb << "vector Gather" << componentName << "(SamplerState s, "; sb << "float" << kBaseTextureTypes[tt].coordCount << " location, "; sb << "constexpr int" << kBaseTextureTypes[tt].coordCount << " offset);\n"; @@ -921,7 +913,7 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) sb << "out uint status);\n"; EMIT_LINE_DIRECTIVE(); - sb << "__target_intrinsic(glsl, \"textureGatherOffsets($$p, $2, int" << kBaseTextureTypes[tt].coordCount << "[]($3, $4, $5, $6), " << componentIndex << ")\")\n"; + sb << "__target_intrinsic(glsl, \"textureGatherOffsets($p, $2, int" << kBaseTextureTypes[tt].coordCount << "[]($3, $4, $5, $6), " << componentIndex << ")\")\n"; sb << "vector Gather" << componentName << "(SamplerState s, "; sb << "float" << kBaseTextureTypes[tt].coordCount << " location, "; sb << "int" << kBaseTextureTypes[tt].coordCount << " offset1, "; @@ -1035,5 +1027,4 @@ for (auto op : binaryOps) sb << "__intrinsic_op(" << int(op.opCode) << ") matrix<" << resultType << ",N,M> operator" << op.opName << "(" << leftQual << "matrix<" << leftType << ",N,M> left, " << rightType << " right);\n"; } } - }}}} diff --git a/source/slang/core.meta.slang.h b/source/slang/core.meta.slang.h index 1e1c25788..974607a75 100644 --- a/source/slang/core.meta.slang.h +++ b/source/slang/core.meta.slang.h @@ -1,39 +1,38 @@ -sb << "// Slang `core` library\n"; -sb << "\n"; -sb << "// Modifier for variables that must resolve to compile-time constants\n"; -sb << "// as part of translation.\n"; -sb << "syntax constexpr : ConstExprModifier;\n"; -sb << "\n"; -sb << "// A type that can be used as an operand for builtins\n"; -sb << "interface __BuiltinType {}\n"; -sb << "\n"; -sb << "// A type that can be used for arithmetic operations\n"; -sb << "interface __BuiltinArithmeticType : __BuiltinType {}\n"; -sb << "\n"; -sb << "// A type that logically has a sign (positive/negative/zero)\n"; -sb << "interface __BuiltinSignedArithmeticType : __BuiltinArithmeticType {}\n"; -sb << "\n"; -sb << "// A type that can represent integers\n"; -sb << "interface __BuiltinIntegerType : __BuiltinArithmeticType\n"; -sb << "{}\n"; -sb << "\n"; -sb << "// A type that can represent non-integers\n"; -sb << "interface __BuiltinRealType : __BuiltinArithmeticType {}\n"; -sb << "\n"; -sb << "// A type that uses a floating-point representation\n"; -sb << "interface __BuiltinFloatingPointType : __BuiltinRealType, __BuiltinSignedArithmeticType\n"; -sb << "{\n"; -sb << " // A builtin floating-point type must have an initializer that takes\n"; -sb << " // a floating-point value...\n"; -sb << " __init(float value);\n"; -sb << "}\n"; -sb << "\n"; -sb << "__generic __intrinsic_op(Sequence) U operator,(T left, U right);\n"; -sb << "\n"; -sb << "__generic __intrinsic_op(select) T operator?:(bool condition, T ifTrue, T ifFalse);\n"; -sb << "__generic __intrinsic_op(select) vector operator?:(vector condition, vector ifTrue, vector ifFalse);\n"; -sb << "\n"; -sb << ""; +SLANG_RAW("// Slang `core` library\n") +SLANG_RAW("\n") +SLANG_RAW("// Modifier for variables that must resolve to compile-time constants\n") +SLANG_RAW("// as part of translation.\n") +SLANG_RAW("syntax constexpr : ConstExprModifier;\n") +SLANG_RAW("\n") +SLANG_RAW("// A type that can be used as an operand for builtins\n") +SLANG_RAW("interface __BuiltinType {}\n") +SLANG_RAW("\n") +SLANG_RAW("// A type that can be used for arithmetic operations\n") +SLANG_RAW("interface __BuiltinArithmeticType : __BuiltinType {}\n") +SLANG_RAW("\n") +SLANG_RAW("// A type that logically has a sign (positive/negative/zero)\n") +SLANG_RAW("interface __BuiltinSignedArithmeticType : __BuiltinArithmeticType {}\n") +SLANG_RAW("\n") +SLANG_RAW("// A type that can represent integers\n") +SLANG_RAW("interface __BuiltinIntegerType : __BuiltinArithmeticType\n") +SLANG_RAW("{}\n") +SLANG_RAW("\n") +SLANG_RAW("// A type that can represent non-integers\n") +SLANG_RAW("interface __BuiltinRealType : __BuiltinArithmeticType {}\n") +SLANG_RAW("\n") +SLANG_RAW("// A type that uses a floating-point representation\n") +SLANG_RAW("interface __BuiltinFloatingPointType : __BuiltinRealType, __BuiltinSignedArithmeticType\n") +SLANG_RAW("{\n") +SLANG_RAW(" // A builtin floating-point type must have an initializer that takes\n") +SLANG_RAW(" // a floating-point value...\n") +SLANG_RAW(" __init(float value);\n") +SLANG_RAW("}\n") +SLANG_RAW("\n") +SLANG_RAW("__generic __intrinsic_op(Sequence) U operator,(T left, U right);\n") +SLANG_RAW("\n") +SLANG_RAW("__generic __intrinsic_op(select) T operator?:(bool condition, T ifTrue, T ifFalse);\n") +SLANG_RAW("__generic __intrinsic_op(select) vector operator?:(vector condition, vector ifTrue, vector ifFalse);\n") +SLANG_RAW("\n") // We are going to use code generation to produce the // declarations for all of our base types. @@ -98,27 +97,23 @@ for (int tt = 0; tt < kBaseTypeCount; ++tt) // Declare built-in pointer type // (eventually we can have the traditional syntax sugar for this) - -sb << "\n"; -sb << "\n"; -sb << "__generic\n"; -sb << "__magic_type(PtrType)\n"; -sb << "struct Ptr\n"; -sb << "{};\n"; -sb << "\n"; -sb << "__generic\n"; -sb << "__magic_type(OutType)\n"; -sb << "struct Out\n"; -sb << "{};\n"; -sb << "\n"; -sb << "__generic\n"; -sb << "__magic_type(InOutType)\n"; -sb << "struct InOut\n"; -sb << "{};\n"; -sb << "\n"; -sb << ""; - - +SLANG_RAW("\n") +SLANG_RAW("\n") +SLANG_RAW("__generic\n") +SLANG_RAW("__magic_type(PtrType)\n") +SLANG_RAW("struct Ptr\n") +SLANG_RAW("{};\n") +SLANG_RAW("\n") +SLANG_RAW("__generic\n") +SLANG_RAW("__magic_type(OutType)\n") +SLANG_RAW("struct Out\n") +SLANG_RAW("{};\n") +SLANG_RAW("\n") +SLANG_RAW("__generic\n") +SLANG_RAW("__magic_type(InOutType)\n") +SLANG_RAW("struct InOut\n") +SLANG_RAW("{};\n") +SLANG_RAW("\n") // Declare vector and matrix types @@ -134,18 +129,12 @@ sb << " __init(T value);\n"; sb << " __init(vector value);\n"; sb << "};\n"; - -// TODO: Probably need to do similar -sb << "\n"; -sb << "\n"; -sb << "__generic\n"; -sb << "__magic_type(Matrix)\n"; -sb << "struct matrix {};\n"; -sb << "\n"; -sb << ""; - - - +SLANG_RAW("\n") +SLANG_RAW("\n") +SLANG_RAW("__generic\n") +SLANG_RAW("__magic_type(Matrix)\n") +SLANG_RAW("struct matrix {};\n") +SLANG_RAW("\n") static const struct { char const* name; @@ -1038,6 +1027,4 @@ for (auto op : binaryOps) sb << "__intrinsic_op(" << int(op.opCode) << ") matrix<" << resultType << ",N,M> operator" << op.opName << "(" << leftQual << "matrix<" << leftType << ",N,M> left, " << rightType << " right);\n"; } } - -sb << "\n"; -sb << ""; +SLANG_RAW("\n") diff --git a/source/slang/glsl.meta.slang b/source/slang/glsl.meta.slang index ffbb6b670..a1ee2d9cf 100644 --- a/source/slang/glsl.meta.slang +++ b/source/slang/glsl.meta.slang @@ -1,7 +1,6 @@ // Slang GLSL compatibility library ${{{{ - static const struct { char const* name; char const* glslPrefix; @@ -199,7 +198,5 @@ sb << "syntax writeonly : GLSLWriteOnlyModifier;\n"; // We will treat `subroutine` as a qualifier for now sb << "syntax subroutine : SimpleModifier;\n"; +}}}} - - -}}}} \ No newline at end of file diff --git a/source/slang/glsl.meta.slang.h b/source/slang/glsl.meta.slang.h index e50c11ec6..f7634db31 100644 --- a/source/slang/glsl.meta.slang.h +++ b/source/slang/glsl.meta.slang.h @@ -1,7 +1,5 @@ -sb << "// Slang GLSL compatibility library\n"; -sb << "\n"; -sb << ""; - +SLANG_RAW("// Slang GLSL compatibility library\n") +SLANG_RAW("\n") static const struct { char const* name; @@ -200,7 +198,5 @@ sb << "syntax writeonly : GLSLWriteOnlyModifier;\n"; // We will treat `subroutine` as a qualifier for now sb << "syntax subroutine : SimpleModifier;\n"; - - - -sb << ""; +SLANG_RAW("\n") +SLANG_RAW("\n") diff --git a/source/slang/hlsl.meta.slang b/source/slang/hlsl.meta.slang index 03b48e805..15579e512 100644 --- a/source/slang/hlsl.meta.slang +++ b/source/slang/hlsl.meta.slang @@ -31,10 +31,7 @@ __magic_type(HLSLByteAddressBufferType) struct ByteAddressBuffer __generic __magic_type(HLSLStructuredBufferType) -__intrinsic_type(${{ - // TODO: we really need a simple way to write an "expression splice" - sb << kIROp_structuredBufferType; -}}) +__intrinsic_type($(kIROp_structuredBufferType)) struct StructuredBuffer { void GetDimensions( @@ -181,10 +178,7 @@ __magic_type(HLSLRWByteAddressBufferType) struct RWByteAddressBuffer __generic __magic_type(HLSLRWStructuredBufferType) -__intrinsic_type(${{ - // TODO: we really need a simple way to write an "expression splice" - sb << kIROp_readWriteStructuredBufferType; -}}) +__intrinsic_type($(kIROp_readWriteStructuredBufferType)) struct RWStructuredBuffer { uint DecrementCounter(); @@ -265,7 +259,7 @@ __target_intrinsic(glsl, "bool($0)") bool any(T x); __generic -__target_intrinsic(glsl, "any(bvec$$N0($0))") +__target_intrinsic(glsl, "any(bvec$N0($0))") bool any(vector x); __generic @@ -1053,7 +1047,6 @@ __generic matrix WaveReadLan typedef Texture2D texture2D; ${{{{ - // Component-wise multiplication ops for(auto op : binaryOps) { @@ -1109,14 +1102,14 @@ for (int aa = 0; aa < kBaseBufferAccessLevelCount; ++aa) sb << "void GetDimensions(out uint dim);\n"; - sb << "__target_intrinsic(glsl, \"texelFetch($$P, $1)$$z\")\n"; + sb << "__target_intrinsic(glsl, \"texelFetch($P, $1)$z\")\n"; sb << "T Load(int location);\n"; sb << "T Load(int location, out uint status);\n"; sb << "__subscript(uint index) -> T {\n"; - sb << "__target_intrinsic(glsl, \"texelFetch($$P, int($1))$$z\") get;\n"; + sb << "__target_intrinsic(glsl, \"texelFetch($P, int($1))$z\") get;\n"; if (kBaseBufferAccessLevels[aa].access != SLANG_RESOURCE_ACCESS_READ) { @@ -1127,5 +1120,4 @@ for (int aa = 0; aa < kBaseBufferAccessLevelCount; ++aa) sb << "};\n"; } - -}}}} \ No newline at end of file +}}}} diff --git a/source/slang/hlsl.meta.slang.h b/source/slang/hlsl.meta.slang.h index 6351f2c8b..d35f96ba3 100644 --- a/source/slang/hlsl.meta.slang.h +++ b/source/slang/hlsl.meta.slang.h @@ -1,1062 +1,1057 @@ -sb << "// Slang HLSL compatibility library\n"; -sb << "\n"; -sb << "typedef uint UINT;\n"; -sb << "\n"; -sb << "__generic __magic_type(HLSLAppendStructuredBufferType) struct AppendStructuredBuffer\n"; -sb << "{\n"; -sb << " void Append(T value);\n"; -sb << "\n"; -sb << " void GetDimensions(\n"; -sb << " out uint numStructs,\n"; -sb << " out uint stride);\n"; -sb << "};\n"; -sb << "\n"; -sb << "__magic_type(HLSLByteAddressBufferType) struct ByteAddressBuffer\n"; -sb << "{\n"; -sb << " void GetDimensions(\n"; -sb << " out uint dim);\n"; -sb << "\n"; -sb << " uint Load(int location);\n"; -sb << " uint Load(int location, out uint status);\n"; -sb << "\n"; -sb << " uint2 Load2(int location);\n"; -sb << " uint2 Load2(int location, out uint status);\n"; -sb << "\n"; -sb << " uint3 Load3(int location);\n"; -sb << " uint3 Load3(int location, out uint status);\n"; -sb << "\n"; -sb << " uint4 Load4(int location);\n"; -sb << " uint4 Load4(int location, out uint status);\n"; -sb << "};\n"; -sb << "\n"; -sb << "__generic\n"; -sb << "__magic_type(HLSLStructuredBufferType)\n"; -sb << "__intrinsic_type("; - - // TODO: we really need a simple way to write an "expression splice" - sb << kIROp_structuredBufferType; -sb << ")\n"; -sb << "struct StructuredBuffer\n"; -sb << "{\n"; -sb << " void GetDimensions(\n"; -sb << " out uint numStructs,\n"; -sb << " out uint stride);\n"; -sb << "\n"; -sb << " T Load(int location);\n"; -sb << " T Load(int location, out uint status);\n"; -sb << "\n"; -sb << " __subscript(uint index) -> T { __intrinsic_op(bufferLoad) get; };\n"; -sb << "};\n"; -sb << "\n"; -sb << "__generic __magic_type(HLSLConsumeStructuredBufferType) struct ConsumeStructuredBuffer\n"; -sb << "{\n"; -sb << " T Consume();\n"; -sb << "\n"; -sb << " void GetDimensions(\n"; -sb << " out uint numStructs,\n"; -sb << " out uint stride);\n"; -sb << "};\n"; -sb << "\n"; -sb << "__generic __magic_type(HLSLInputPatchType) struct InputPatch\n"; -sb << "{\n"; -sb << " __subscript(uint index) -> T;\n"; -sb << "};\n"; -sb << "\n"; -sb << "__generic __magic_type(HLSLOutputPatchType) struct OutputPatch\n"; -sb << "{\n"; -sb << " __subscript(uint index) -> T;\n"; -sb << "};\n"; -sb << "\n"; -sb << "__magic_type(HLSLRWByteAddressBufferType) struct RWByteAddressBuffer\n"; -sb << "{\n"; -sb << " // Note(tfoley): supports alll operations from `ByteAddressBuffer`\n"; -sb << " // TODO(tfoley): can this be made a sub-type?\n"; -sb << "\n"; -sb << " void GetDimensions(\n"; -sb << " out uint dim);\n"; -sb << "\n"; -sb << " uint Load(int location);\n"; -sb << " uint Load(int location, out uint status);\n"; -sb << "\n"; -sb << " uint2 Load2(int location);\n"; -sb << " uint2 Load2(int location, out uint status);\n"; -sb << "\n"; -sb << " uint3 Load3(int location);\n"; -sb << " uint3 Load3(int location, out uint status);\n"; -sb << "\n"; -sb << " uint4 Load4(int location);\n"; -sb << " uint4 Load4(int location, out uint status);\n"; -sb << "\n"; -sb << " // Added operations:\n"; -sb << "\n"; -sb << " void InterlockedAdd(\n"; -sb << " UINT dest,\n"; -sb << " UINT value,\n"; -sb << " out UINT original_value);\n"; -sb << " void InterlockedAdd(\n"; -sb << " UINT dest,\n"; -sb << " UINT value);\n"; -sb << "\n"; -sb << " void InterlockedAnd(\n"; -sb << " UINT dest,\n"; -sb << " UINT value,\n"; -sb << " out UINT original_value);\n"; -sb << " void InterlockedAnd(\n"; -sb << " UINT dest,\n"; -sb << " UINT value);\n"; -sb << "\n"; -sb << " void InterlockedCompareExchange(\n"; -sb << " UINT dest,\n"; -sb << " UINT compare_value,\n"; -sb << " UINT value,\n"; -sb << " out UINT original_value);\n"; -sb << " void InterlockedCompareExchange(\n"; -sb << " UINT dest,\n"; -sb << " UINT compare_value,\n"; -sb << " UINT value);\n"; -sb << "\n"; -sb << " void InterlockedCompareStore(\n"; -sb << " UINT dest,\n"; -sb << " UINT compare_value,\n"; -sb << " UINT value);\n"; -sb << " void InterlockedCompareStore(\n"; -sb << " UINT dest,\n"; -sb << " UINT compare_value);\n"; -sb << "\n"; -sb << " void InterlockedExchange(\n"; -sb << " UINT dest,\n"; -sb << " UINT value,\n"; -sb << " out UINT original_value);\n"; -sb << " void InterlockedExchange(\n"; -sb << " UINT dest,\n"; -sb << " UINT value);\n"; -sb << "\n"; -sb << " void InterlockedMax(\n"; -sb << " UINT dest,\n"; -sb << " UINT value,\n"; -sb << " out UINT original_value);\n"; -sb << " void InterlockedMax(\n"; -sb << " UINT dest,\n"; -sb << " UINT value);\n"; -sb << "\n"; -sb << " void InterlockedMin(\n"; -sb << " UINT dest,\n"; -sb << " UINT value,\n"; -sb << " out UINT original_value);\n"; -sb << " void InterlockedMin(\n"; -sb << " UINT dest,\n"; -sb << " UINT value);\n"; -sb << "\n"; -sb << " void InterlockedOr(\n"; -sb << " UINT dest,\n"; -sb << " UINT value,\n"; -sb << " out UINT original_value);\n"; -sb << " void InterlockedOr(\n"; -sb << " UINT dest,\n"; -sb << " UINT value);\n"; -sb << "\n"; -sb << " void InterlockedXor(\n"; -sb << " UINT dest,\n"; -sb << " UINT value,\n"; -sb << " out UINT original_value);\n"; -sb << " void InterlockedXor(\n"; -sb << " UINT dest,\n"; -sb << " UINT value);\n"; -sb << "\n"; -sb << " void Store(\n"; -sb << " uint address,\n"; -sb << " uint value);\n"; -sb << "\n"; -sb << " void Store2(\n"; -sb << " uint address,\n"; -sb << " uint2 value);\n"; -sb << "\n"; -sb << " void Store3(\n"; -sb << " uint address,\n"; -sb << " uint3 value);\n"; -sb << "\n"; -sb << " void Store4(\n"; -sb << " uint address,\n"; -sb << " uint4 value);\n"; -sb << "};\n"; -sb << "\n"; -sb << "__generic\n"; -sb << "__magic_type(HLSLRWStructuredBufferType)\n"; -sb << "__intrinsic_type("; - - // TODO: we really need a simple way to write an "expression splice" - sb << kIROp_readWriteStructuredBufferType; -sb << ")\n"; -sb << "struct RWStructuredBuffer\n"; -sb << "{\n"; -sb << " uint DecrementCounter();\n"; -sb << "\n"; -sb << " void GetDimensions(\n"; -sb << " out uint numStructs,\n"; -sb << " out uint stride);\n"; -sb << "\n"; -sb << " uint IncrementCounter();\n"; -sb << "\n"; -sb << " T Load(int location);\n"; -sb << " T Load(int location, out uint status);\n"; -sb << "\n"; -sb << "\t__subscript(uint index) -> T\n"; -sb << "\t{\n"; -sb << " __intrinsic_op(bufferElementRef)\n"; -sb << " ref;\n"; -sb << "\t}\n"; -sb << "};\n"; -sb << "\n"; -sb << "__generic __magic_type(HLSLPointStreamType) struct PointStream\n"; -sb << "{\n"; -sb << " __target_intrinsic(glsl, \"EmitVertex()\")\n"; -sb << " void Append(T value);\n"; -sb << "\n"; -sb << " __target_intrinsic(glsl, \"EndPrimitive()\")\n"; -sb << " void RestartStrip();\n"; -sb << "};\n"; -sb << "\n"; -sb << "__generic __magic_type(HLSLLineStreamType) struct LineStream\n"; -sb << "{\n"; -sb << " __target_intrinsic(glsl, \"EmitVertex()\")\n"; -sb << " void Append(T value);\n"; -sb << "\n"; -sb << " __target_intrinsic(glsl, \"EndPrimitive()\")\n"; -sb << " void RestartStrip();\n"; -sb << "};\n"; -sb << "\n"; -sb << "__generic __magic_type(HLSLTriangleStreamType) struct TriangleStream\n"; -sb << "{\n"; -sb << " __target_intrinsic(glsl, \"EmitVertex()\")\n"; -sb << " void Append(T value);\n"; -sb << "\n"; -sb << " __target_intrinsic(glsl, \"EndPrimitive()\")\n"; -sb << " void RestartStrip();\n"; -sb << "};\n"; -sb << "\n"; -sb << "// Note(tfoley): Trying to systematically add all the HLSL builtins\n"; -sb << "\n"; -sb << "// Try to terminate the current draw or dispatch call (HLSL SM 4.0)\n"; -sb << "void abort();\n"; -sb << "\n"; -sb << "// Absolute value (HLSL SM 1.0)\n"; -sb << "__generic T abs(T x);\n"; -sb << "__generic vector abs(vector x);\n"; -sb << "__generic matrix abs(matrix x);\n"; -sb << "\n"; -sb << "// Inverse cosine (HLSL SM 1.0)\n"; -sb << "__generic T acos(T x);\n"; -sb << "__generic vector acos(vector x);\n"; -sb << "__generic matrix acos(matrix x);\n"; -sb << "\n"; -sb << "// Test if all components are non-zero (HLSL SM 1.0)\n"; -sb << "__generic bool all(T x);\n"; -sb << "__generic bool all(vector x);\n"; -sb << "__generic bool all(matrix x);\n"; -sb << "\n"; -sb << "// Barrier for writes to all memory spaces (HLSL SM 5.0)\n"; -sb << "void AllMemoryBarrier();\n"; -sb << "\n"; -sb << "// Thread-group sync and barrier for writes to all memory spaces (HLSL SM 5.0)\n"; -sb << "void AllMemoryBarrierWithGroupSync();\n"; -sb << "\n"; -sb << "// Test if any components is non-zero (HLSL SM 1.0)\n"; -sb << "\n"; -sb << "__generic\n"; -sb << "__target_intrinsic(glsl, \"bool($0)\")\n"; -sb << "bool any(T x);\n"; -sb << "\n"; -sb << "__generic\n"; -sb << "__target_intrinsic(glsl, \"any(bvec$"; -sb << "N0($0))\")\n"; -sb << "bool any(vector x);\n"; -sb << "\n"; -sb << "__generic\n"; -sb << "// TODO: need to define GLSL mapping\n"; -sb << "bool any(matrix x);\n"; -sb << "\n"; -sb << "\n"; -sb << "// Reinterpret bits as a double (HLSL SM 5.0)\n"; -sb << "double asdouble(uint lowbits, uint highbits);\n"; -sb << "\n"; -sb << "// Reinterpret bits as a float (HLSL SM 4.0)\n"; -sb << "float asfloat( int x);\n"; -sb << "float asfloat(uint x);\n"; -sb << "__generic vector asfloat(vector< int,N> x);\n"; -sb << "__generic vector asfloat(vector x);\n"; -sb << "__generic matrix asfloat(matrix< int,N,M> x);\n"; -sb << "__generic matrix asfloat(matrix x);\n"; -sb << "\n"; -sb << "\n"; -sb << "// Inverse sine (HLSL SM 1.0)\n"; -sb << "__generic T asin(T x);\n"; -sb << "__generic vector asin(vector x);\n"; -sb << "__generic matrix asin(matrix x);\n"; -sb << "\n"; -sb << "// Reinterpret bits as an int (HLSL SM 4.0)\n"; -sb << "int asint(float x);\n"; -sb << "int asint(uint x);\n"; -sb << "__generic vector asint(vector x);\n"; -sb << "__generic vector asint(vector x);\n"; -sb << "__generic matrix asint(matrix x);\n"; -sb << "__generic matrix asint(matrix x);\n"; -sb << "\n"; -sb << "// Reinterpret bits of double as a uint (HLSL SM 5.0)\n"; -sb << "void asuint(double value, out uint lowbits, out uint highbits);\n"; -sb << "\n"; -sb << "// Reinterpret bits as a uint (HLSL SM 4.0)\n"; -sb << "uint asuint(float x);\n"; -sb << "uint asuint(int x);\n"; -sb << "__generic vector asuint(vector x);\n"; -sb << "__generic vector asuint(vector x);\n"; -sb << "__generic matrix asuint(matrix x);\n"; -sb << "__generic matrix asuint(matrix x);\n"; -sb << "\n"; -sb << "// Inverse tangent (HLSL SM 1.0)\n"; -sb << "__generic T atan(T x);\n"; -sb << "__generic vector atan(vector x);\n"; -sb << "__generic matrix atan(matrix x);\n"; -sb << "\n"; -sb << "__generic\n"; -sb << "__target_intrinsic(glsl,\"atan($0,$1)\")\n"; -sb << "T atan2(T y, T x);\n"; -sb << "\n"; -sb << "__generic\n"; -sb << "__target_intrinsic(glsl,\"atan($0,$1)\")\n"; -sb << "vector atan2(vector y, vector x);\n"; -sb << "\n"; -sb << "__generic\n"; -sb << "__target_intrinsic(glsl,\"atan($0,$1)\")\n"; -sb << "matrix atan2(matrix y, matrix x);\n"; -sb << "\n"; -sb << "// Ceiling (HLSL SM 1.0)\n"; -sb << "__generic T ceil(T x);\n"; -sb << "__generic vector ceil(vector x);\n"; -sb << "__generic matrix ceil(matrix x);\n"; -sb << "\n"; -sb << "\n"; -sb << "// Check access status to tiled resource\n"; -sb << "bool CheckAccessFullyMapped(uint status);\n"; -sb << "\n"; -sb << "// Clamp (HLSL SM 1.0)\n"; -sb << "__generic T clamp(T x, T min, T max);\n"; -sb << "__generic vector clamp(vector x, vector min, vector max);\n"; -sb << "__generic matrix clamp(matrix x, matrix min, matrix max);\n"; -sb << "\n"; -sb << "// Clip (discard) fragment conditionally\n"; -sb << "__generic void clip(T x);\n"; -sb << "__generic void clip(vector x);\n"; -sb << "__generic void clip(matrix x);\n"; -sb << "\n"; -sb << "// Cosine\n"; -sb << "__generic T cos(T x);\n"; -sb << "__generic vector cos(vector x);\n"; -sb << "__generic matrix cos(matrix x);\n"; -sb << "\n"; -sb << "// Hyperbolic cosine\n"; -sb << "__generic T cosh(T x);\n"; -sb << "__generic vector cosh(vector x);\n"; -sb << "__generic matrix cosh(matrix x);\n"; -sb << "\n"; -sb << "// Population count\n"; -sb << "__target_intrinsic(glsl, \"bitCount\")\n"; -sb << "uint countbits(uint value);\n"; -sb << "\n"; -sb << "// Cross product\n"; -sb << "__generic vector cross(vector x, vector y);\n"; -sb << "\n"; -sb << "// Convert encoded color\n"; -sb << "int4 D3DCOLORtoUBYTE4(float4 x);\n"; -sb << "\n"; -sb << "// Partial-difference derivatives\n"; -sb << "__generic\n"; -sb << "__target_intrinsic(glsl, dFdx)\n"; -sb << "T ddx(T x);\n"; -sb << "\n"; -sb << "__generic\n"; -sb << "__target_intrinsic(glsl, dFdx)\n"; -sb << "vector ddx(vector x);\n"; -sb << "\n"; -sb << "__generic\n"; -sb << "__target_intrinsic(glsl, dFdx)\n"; -sb << "matrix ddx(matrix x);\n"; -sb << "\n"; -sb << "__generic\n"; -sb << "__glsl_extension(GL_ARB_derivative_control)\n"; -sb << "__target_intrinsic(glsl, dFdxCoarse)\n"; -sb << "T ddx_coarse(T x);\n"; -sb << "\n"; -sb << "__generic\n"; -sb << "__glsl_extension(GL_ARB_derivative_control)\n"; -sb << "__target_intrinsic(glsl, dFdxCoarse)\n"; -sb << "vector ddx_coarse(vector x);\n"; -sb << "\n"; -sb << "__generic\n"; -sb << "__glsl_extension(GL_ARB_derivative_control)\n"; -sb << "__target_intrinsic(glsl, dFdxCoarse)\n"; -sb << "matrix ddx_coarse(matrix x);\n"; -sb << "\n"; -sb << "__generic\n"; -sb << "__glsl_extension(GL_ARB_derivative_control)\n"; -sb << "__target_intrinsic(glsl, dFdxFine)\n"; -sb << "T ddx_fine(T x);\n"; -sb << "\n"; -sb << "__generic\n"; -sb << "__glsl_extension(GL_ARB_derivative_control)\n"; -sb << "__target_intrinsic(glsl, dFdxFine)\n"; -sb << "vector ddx_fine(vector x);\n"; -sb << "\n"; -sb << "__generic\n"; -sb << "__glsl_extension(GL_ARB_derivative_control)\n"; -sb << "__target_intrinsic(glsl, dFdxFine)\n"; -sb << "matrix ddx_fine(matrix x);\n"; -sb << "\n"; -sb << "__generic\n"; -sb << "__target_intrinsic(glsl, dFdy)\n"; -sb << "T ddy(T x);\n"; -sb << "\n"; -sb << "__generic\n"; -sb << "__target_intrinsic(glsl, dFdy)\n"; -sb << "vector ddy(vector x);\n"; -sb << "\n"; -sb << "__generic\n"; -sb << "__target_intrinsic(glsl, dFdy)\n"; -sb << " matrix ddy(matrix x);\n"; -sb << "\n"; -sb << "__generic\n"; -sb << "__glsl_extension(GL_ARB_derivative_control)\n"; -sb << "__target_intrinsic(glsl, dFdyCoarse)\n"; -sb << "T ddy_coarse(T x);\n"; -sb << "\n"; -sb << "__generic\n"; -sb << "__glsl_extension(GL_ARB_derivative_control)\n"; -sb << "__target_intrinsic(glsl, dFdyCoarse)\n"; -sb << "vector ddy_coarse(vector x);\n"; -sb << "\n"; -sb << "__generic\n"; -sb << "__glsl_extension(GL_ARB_derivative_control)\n"; -sb << "__target_intrinsic(glsl, dFdyCoarse)\n"; -sb << "matrix ddy_coarse(matrix x);\n"; -sb << "\n"; -sb << "__generic\n"; -sb << "__glsl_extension(GL_ARB_derivative_control)\n"; -sb << "__target_intrinsic(glsl, dFdyFine)\n"; -sb << "T ddy_fine(T x);\n"; -sb << "\n"; -sb << "__generic\n"; -sb << "__glsl_extension(GL_ARB_derivative_control)\n"; -sb << "__target_intrinsic(glsl, dFdyFine)\n"; -sb << "vector ddy_fine(vector x);\n"; -sb << "\n"; -sb << "__generic\n"; -sb << "__glsl_extension(GL_ARB_derivative_control)\n"; -sb << "__target_intrinsic(glsl, dFdyFine)\n"; -sb << "matrix ddy_fine(matrix x);\n"; -sb << "\n"; -sb << "\n"; -sb << "// Radians to degrees\n"; -sb << "__generic T degrees(T x);\n"; -sb << "__generic vector degrees(vector x);\n"; -sb << "__generic matrix degrees(matrix x);\n"; -sb << "\n"; -sb << "// Matrix determinant\n"; -sb << "\n"; -sb << "__generic T determinant(matrix m);\n"; -sb << "\n"; -sb << "// Barrier for device memory\n"; -sb << "void DeviceMemoryBarrier();\n"; -sb << "void DeviceMemoryBarrierWithGroupSync();\n"; -sb << "\n"; -sb << "// Vector distance\n"; -sb << "\n"; -sb << "__generic T distance(vector x, vector y);\n"; -sb << "\n"; -sb << "// Vector dot product\n"; -sb << "\n"; -sb << "__generic T dot(vector x, vector y);\n"; -sb << "\n"; -sb << "// Helper for computing distance terms for lighting (obsolete)\n"; -sb << "\n"; -sb << "__generic vector dst(vector x, vector y);\n"; -sb << "\n"; -sb << "// Error message\n"; -sb << "\n"; -sb << "// void errorf( string format, ... );\n"; -sb << "\n"; -sb << "// Attribute evaluation\n"; -sb << "\n"; -sb << "__generic T EvaluateAttributeAtCentroid(T x);\n"; -sb << "__generic vector EvaluateAttributeAtCentroid(vector x);\n"; -sb << "__generic matrix EvaluateAttributeAtCentroid(matrix x);\n"; -sb << "\n"; -sb << "__generic T EvaluateAttributeAtSample(T x, uint sampleindex);\n"; -sb << "__generic vector EvaluateAttributeAtSample(vector x, uint sampleindex);\n"; -sb << "__generic matrix EvaluateAttributeAtSample(matrix x, uint sampleindex);\n"; -sb << "\n"; -sb << "__generic T EvaluateAttributeSnapped(T x, int2 offset);\n"; -sb << "__generic vector EvaluateAttributeSnapped(vector x, int2 offset);\n"; -sb << "__generic matrix EvaluateAttributeSnapped(matrix x, int2 offset);\n"; -sb << "\n"; -sb << "// Base-e exponent\n"; -sb << "__generic T exp(T x);\n"; -sb << "__generic vector exp(vector x);\n"; -sb << "__generic matrix exp(matrix x);\n"; -sb << "\n"; -sb << "// Base-2 exponent\n"; -sb << "__generic T exp2(T x);\n"; -sb << "__generic vector exp2(vector x);\n"; -sb << "__generic matrix exp2(matrix x);\n"; -sb << "\n"; -sb << "// Convert 16-bit float stored in low bits of integer\n"; -sb << "float f16tof32(uint value);\n"; -sb << "__generic vector f16tof32(vector value);\n"; -sb << "\n"; -sb << "// Convert to 16-bit float stored in low bits of integer\n"; -sb << "uint f32tof16(float value);\n"; -sb << "__generic vector f32tof16(vector value);\n"; -sb << "\n"; -sb << "// Flip surface normal to face forward, if needed\n"; -sb << "__generic vector faceforward(vector n, vector i, vector ng);\n"; -sb << "\n"; -sb << "// Find first set bit starting at high bit and working down\n"; -sb << "__target_intrinsic(glsl,\"findMSB\")\n"; -sb << "int firstbithigh(int value);\n"; -sb << "\n"; -sb << "__target_intrinsic(glsl,\"findMSB\")\n"; -sb << "__generic vector firstbithigh(vector value);\n"; -sb << "\n"; -sb << "__target_intrinsic(glsl,\"findMSB\")\n"; -sb << "uint firstbithigh(uint value);\n"; -sb << "\n"; -sb << "__target_intrinsic(glsl,\"findMSB\")\n"; -sb << "__generic vector firstbithigh(vector value);\n"; -sb << "\n"; -sb << "// Find first set bit starting at low bit and working up\n"; -sb << "__target_intrinsic(glsl,\"findLSB\")\n"; -sb << "int firstbitlow(int value);\n"; -sb << "\n"; -sb << "__target_intrinsic(glsl,\"findLSB\")\n"; -sb << "__generic vector firstbitlow(vector value);\n"; -sb << "\n"; -sb << "__target_intrinsic(glsl,\"findLSB\")\n"; -sb << "uint firstbitlow(uint value);\n"; -sb << "\n"; -sb << "__target_intrinsic(glsl,\"findLSB\")\n"; -sb << "__generic vector firstbitlow(vector value);\n"; -sb << "\n"; -sb << "// Floor (HLSL SM 1.0)\n"; -sb << "__generic T floor(T x);\n"; -sb << "__generic vector floor(vector x);\n"; -sb << "__generic matrix floor(matrix x);\n"; -sb << "\n"; -sb << "// Fused multiply-add for doubles\n"; -sb << "double fma(double a, double b, double c);\n"; -sb << "__generic vector fma(vector a, vector b, vector c);\n"; -sb << "__generic matrix fma(matrix a, matrix b, matrix c);\n"; -sb << "\n"; -sb << "// Floating point remainder of x/y\n"; -sb << "__generic T fmod(T x, T y);\n"; -sb << "__generic vector fmod(vector x, vector y);\n"; -sb << "__generic matrix fmod(matrix x, matrix y);\n"; -sb << "\n"; -sb << "// Fractional part\n"; -sb << "__generic\n"; -sb << "__target_intrinsic(glsl, fract)\n"; -sb << "T frac(T x);\n"; -sb << "\n"; -sb << "__generic\n"; -sb << "__target_intrinsic(glsl, fract)\n"; -sb << "vector frac(vector x);\n"; -sb << "\n"; -sb << "__generic\n"; -sb << "__target_intrinsic(glsl, fract)\n"; -sb << "matrix frac(matrix x);\n"; -sb << "\n"; -sb << "// Split float into mantissa and exponent\n"; -sb << "__generic T frexp(T x, out T exp);\n"; -sb << "__generic vector frexp(vector x, out vector exp);\n"; -sb << "__generic matrix frexp(matrix x, out matrix exp);\n"; -sb << "\n"; -sb << "// Texture filter width\n"; -sb << "__generic T fwidth(T x);\n"; -sb << "__generic vector fwidth(vector x);\n"; -sb << "__generic matrix fwidth(matrix x);\n"; -sb << "\n"; -sb << "// Get number of samples in render target\n"; -sb << "uint GetRenderTargetSampleCount();\n"; -sb << "\n"; -sb << "// Get position of given sample\n"; -sb << "float2 GetRenderTargetSamplePosition(int Index);\n"; -sb << "\n"; -sb << "// Group memory barrier\n"; -sb << "__target_intrinsic(glsl, \"groupMemoryBarrier\")\n"; -sb << "void GroupMemoryBarrier();\n"; -sb << "\n"; -sb << "__target_intrinsic(glsl, \"groupMemoryBarrier(); barrier()\")\n"; -sb << "void GroupMemoryBarrierWithGroupSync();\n"; -sb << "\n"; -sb << "// Atomics\n"; -sb << "void InterlockedAdd(in out int dest, int value, out int original_value);\n"; -sb << "void InterlockedAdd(in out uint dest, uint value, out uint original_value);\n"; -sb << "\n"; -sb << "void InterlockedAnd(in out int dest, int value, out int original_value);\n"; -sb << "void InterlockedAnd(in out uint dest, uint value, out uint original_value);\n"; -sb << "\n"; -sb << "void InterlockedCompareExchange(in out int dest, int compare_value, int value, out int original_value);\n"; -sb << "void InterlockedCompareExchange(in out uint dest, uint compare_value, uint value, out uint original_value);\n"; -sb << "\n"; -sb << "void InterlockedCompareStore(in out int dest, int compare_value, int value);\n"; -sb << "void InterlockedCompareStore(in out uint dest, uint compare_value, uint value);\n"; -sb << "\n"; -sb << "void InterlockedExchange(in out int dest, int value, out int original_value);\n"; -sb << "void InterlockedExchange(in out uint dest, uint value, out uint original_value);\n"; -sb << "\n"; -sb << "void InterlockedMax(in out int dest, int value, out int original_value);\n"; -sb << "void InterlockedMax(in out uint dest, uint value, out uint original_value);\n"; -sb << "\n"; -sb << "void InterlockedMin(in out int dest, int value, out int original_value);\n"; -sb << "void InterlockedMin(in out uint dest, uint value, out uint original_value);\n"; -sb << "\n"; -sb << "void InterlockedOr(in out int dest, int value, out int original_value);\n"; -sb << "void InterlockedOr(in out uint dest, uint value, out uint original_value);\n"; -sb << "\n"; -sb << "void InterlockedXor(in out int dest, int value, out int original_value);\n"; -sb << "void InterlockedXor(in out uint dest, uint value, out uint original_value);\n"; -sb << "\n"; -sb << "// Is floating-point value finite?\n"; -sb << "__generic bool isfinite(T x);\n"; -sb << "__generic vector isfinite(vector x);\n"; -sb << "__generic matrix isfinite(matrix x);\n"; -sb << "\n"; -sb << "// Is floating-point value infinite?\n"; -sb << "__generic bool isinf(T x);\n"; -sb << "__generic vector isinf(vector x);\n"; -sb << "__generic matrix isinf(matrix x);\n"; -sb << "\n"; -sb << "// Is floating-point value not-a-number?\n"; -sb << "__generic bool isnan(T x);\n"; -sb << "__generic vector isnan(vector x);\n"; -sb << "__generic matrix isnan(matrix x);\n"; -sb << "\n"; -sb << "// Construct float from mantissa and exponent\n"; -sb << "__generic T ldexp(T x, T exp);\n"; -sb << "__generic vector ldexp(vector x, vector exp);\n"; -sb << "__generic matrix ldexp(matrix x, matrix exp);\n"; -sb << "\n"; -sb << "// Vector length\n"; -sb << "__generic T length(vector x);\n"; -sb << "\n"; -sb << "// Linear interpolation\n"; -sb << "__generic\n"; -sb << "__target_intrinsic(glsl, mix)\n"; -sb << "T lerp(T x, T y, T s);\n"; -sb << "\n"; -sb << "__generic\n"; -sb << "__target_intrinsic(glsl, mix)\n"; -sb << "vector lerp(vector x, vector y, vector s);\n"; -sb << "\n"; -sb << "__generic\n"; -sb << "__target_intrinsic(glsl, mix)\n"; -sb << "matrix lerp(matrix x, matrix y, matrix s);\n"; -sb << "\n"; -sb << "// Legacy lighting function (obsolete)\n"; -sb << "float4 lit(float n_dot_l, float n_dot_h, float m);\n"; -sb << "\n"; -sb << "// Base-e logarithm\n"; -sb << "__generic T log(T x);\n"; -sb << "__generic vector log(vector x);\n"; -sb << "__generic matrix log(matrix x);\n"; -sb << "\n"; -sb << "// Base-10 logarithm\n"; -sb << "__generic T log10(T x);\n"; -sb << "__generic vector log10(vector x);\n"; -sb << "__generic matrix log10(matrix x);\n"; -sb << "\n"; -sb << "// Base-2 logarithm\n"; -sb << "__generic T log2(T x);\n"; -sb << "__generic vector log2(vector x);\n"; -sb << "__generic matrix log2(matrix x);\n"; -sb << "\n"; -sb << "// multiply-add\n"; -sb << "__generic T mad(T mvalue, T avalue, T bvalue);\n"; -sb << "__generic vector mad(vector mvalue, vector avalue, vector bvalue);\n"; -sb << "__generic matrix mad(matrix mvalue, matrix avalue, matrix bvalue);\n"; -sb << "\n"; -sb << "// maximum\n"; -sb << "__generic T max(T x, T y);\n"; -sb << "__generic vector max(vector x, vector y);\n"; -sb << "__generic matrix max(matrix x, matrix y);\n"; -sb << "\n"; -sb << "// minimum\n"; -sb << "__generic T min(T x, T y);\n"; -sb << "__generic vector min(vector x, vector y);\n"; -sb << "__generic matrix min(matrix x, matrix y);\n"; -sb << "\n"; -sb << "// split into integer and fractional parts (both with same sign)\n"; -sb << "__generic T modf(T x, out T ip);\n"; -sb << "__generic vector modf(vector x, out vector ip);\n"; -sb << "__generic matrix modf(matrix x, out matrix ip);\n"; -sb << "\n"; -sb << "// msad4 (whatever that is)\n"; -sb << "uint4 msad4(uint reference, uint2 source, uint4 accum);\n"; -sb << "\n"; -sb << "// General inner products\n"; -sb << "\n"; -sb << "// scalar-scalar\n"; -sb << "__generic T mul(T x, T y);\n"; -sb << "\n"; -sb << "// scalar-vector and vector-scalar\n"; -sb << "__generic vector mul(vector x, T y);\n"; -sb << "__generic vector mul(T x, vector y);\n"; -sb << "\n"; -sb << "// scalar-matrix and matrix-scalar\n"; -sb << "__generic matrix mul(matrix x, T y);\n"; -sb << "__generic matrix mul(T x, matrix y);\n"; -sb << "\n"; -sb << "// vector-vector (dot product)\n"; -sb << "__generic __intrinsic_op(dot) T mul(vector x, vector y);\n"; -sb << "\n"; -sb << "// vector-matrix\n"; -sb << "__generic __intrinsic_op(mulVectorMatrix) vector mul(vector x, matrix y);\n"; -sb << "\n"; -sb << "// matrix-vector\n"; -sb << "__generic __intrinsic_op(mulMatrixVector) vector mul(matrix x, vector y);\n"; -sb << "\n"; -sb << "// matrix-matrix\n"; -sb << "__generic __intrinsic_op(mulMatrixMatrix) matrix mul(matrix x, matrix y);\n"; -sb << "\n"; -sb << "// noise (deprecated)\n"; -sb << "float noise(float x);\n"; -sb << "__generic float noise(vector x);\n"; -sb << "\n"; -sb << "// Normalize a vector\n"; -sb << "__generic vector normalize(vector x);\n"; -sb << "\n"; -sb << "// Raise to a power\n"; -sb << "__generic T pow(T x, T y);\n"; -sb << "__generic vector pow(vector x, vector y);\n"; -sb << "__generic matrix pow(matrix x, matrix y);\n"; -sb << "\n"; -sb << "// Output message\n"; -sb << "\n"; -sb << "// void printf( string format, ... );\n"; -sb << "\n"; -sb << "// Tessellation factor fixup routines\n"; -sb << "\n"; -sb << "void Process2DQuadTessFactorsAvg(\n"; -sb << " in float4 RawEdgeFactors,\n"; -sb << " in float2 InsideScale,\n"; -sb << " out float4 RoundedEdgeTessFactors,\n"; -sb << " out float2 RoundedInsideTessFactors,\n"; -sb << " out float2 UnroundedInsideTessFactors);\n"; -sb << "\n"; -sb << "void Process2DQuadTessFactorsMax(\n"; -sb << " in float4 RawEdgeFactors,\n"; -sb << " in float2 InsideScale,\n"; -sb << " out float4 RoundedEdgeTessFactors,\n"; -sb << " out float2 RoundedInsideTessFactors,\n"; -sb << " out float2 UnroundedInsideTessFactors);\n"; -sb << "\n"; -sb << "void Process2DQuadTessFactorsMin(\n"; -sb << " in float4 RawEdgeFactors,\n"; -sb << " in float2 InsideScale,\n"; -sb << " out float4 RoundedEdgeTessFactors,\n"; -sb << " out float2 RoundedInsideTessFactors,\n"; -sb << " out float2 UnroundedInsideTessFactors);\n"; -sb << "\n"; -sb << "void ProcessIsolineTessFactors(\n"; -sb << " in float RawDetailFactor,\n"; -sb << " in float RawDensityFactor,\n"; -sb << " out float RoundedDetailFactor,\n"; -sb << " out float RoundedDensityFactor);\n"; -sb << "\n"; -sb << "void ProcessQuadTessFactorsAvg(\n"; -sb << " in float4 RawEdgeFactors,\n"; -sb << " in float InsideScale,\n"; -sb << " out float4 RoundedEdgeTessFactors,\n"; -sb << " out float2 RoundedInsideTessFactors,\n"; -sb << " out float2 UnroundedInsideTessFactors);\n"; -sb << "\n"; -sb << "void ProcessQuadTessFactorsMax(\n"; -sb << " in float4 RawEdgeFactors,\n"; -sb << " in float InsideScale,\n"; -sb << " out float4 RoundedEdgeTessFactors,\n"; -sb << " out float2 RoundedInsideTessFactors,\n"; -sb << " out float2 UnroundedInsideTessFactors);\n"; -sb << "\n"; -sb << "void ProcessQuadTessFactorsMin(\n"; -sb << " in float4 RawEdgeFactors,\n"; -sb << " in float InsideScale,\n"; -sb << " out float4 RoundedEdgeTessFactors,\n"; -sb << " out float2 RoundedInsideTessFactors,\n"; -sb << " out float2 UnroundedInsideTessFactors);\n"; -sb << "\n"; -sb << "void ProcessTriTessFactorsAvg(\n"; -sb << " in float3 RawEdgeFactors,\n"; -sb << " in float InsideScale,\n"; -sb << " out float3 RoundedEdgeTessFactors,\n"; -sb << " out float RoundedInsideTessFactor,\n"; -sb << " out float UnroundedInsideTessFactor);\n"; -sb << "\n"; -sb << "void ProcessTriTessFactorsMax(\n"; -sb << " in float3 RawEdgeFactors,\n"; -sb << " in float InsideScale,\n"; -sb << " out float3 RoundedEdgeTessFactors,\n"; -sb << " out float RoundedInsideTessFactor,\n"; -sb << " out float UnroundedInsideTessFactor);\n"; -sb << "\n"; -sb << "void ProcessTriTessFactorsMin(\n"; -sb << " in float3 RawEdgeFactors,\n"; -sb << " in float InsideScale,\n"; -sb << " out float3 RoundedEdgeTessFactors,\n"; -sb << " out float RoundedInsideTessFactors,\n"; -sb << " out float UnroundedInsideTessFactors);\n"; -sb << "\n"; -sb << "// Degrees to radians\n"; -sb << "__generic T radians(T x);\n"; -sb << "__generic vector radians(vector x);\n"; -sb << "__generic matrix radians(matrix x);\n"; -sb << "\n"; -sb << "// Approximate reciprocal\n"; -sb << "__generic T rcp(T x);\n"; -sb << "__generic vector rcp(vector x);\n"; -sb << "__generic matrix rcp(matrix x);\n"; -sb << "\n"; -sb << "// Reflect incident vector across plane with given normal\n"; -sb << "__generic\n"; -sb << "vector reflect(vector i, vector n);\n"; -sb << "\n"; -sb << "// Refract incident vector given surface normal and index of refraction\n"; -sb << "__generic\n"; -sb << "vector refract(vector i, vector n, float eta);\n"; -sb << "\n"; -sb << "// Reverse order of bits\n"; -sb << "__target_intrinsic(glsl, \"bitfieldReverse\")\n"; -sb << "uint reversebits(uint value);\n"; -sb << "\n"; -sb << "__target_intrinsic(glsl, \"bitfieldReverse\")\n"; -sb << "__generic vector reversebits(vector value);\n"; -sb << "\n"; -sb << "// Round-to-nearest\n"; -sb << "__generic T round(T x);\n"; -sb << "__generic vector round(vector x);\n"; -sb << "__generic matrix round(matrix x);\n"; -sb << "\n"; -sb << "// Reciprocal of square root\n"; -sb << "__generic T rsqrt(T x);\n"; -sb << "__generic vector rsqrt(vector x);\n"; -sb << "__generic matrix rsqrt(matrix x);\n"; -sb << "\n"; -sb << "// Clamp value to [0,1] range\n"; -sb << "__generic\n"; -sb << "__target_intrinsic(glsl, \"clamp($0, 0, 1)\")\n"; -sb << "T saturate(T x);\n"; -sb << "\n"; -sb << "__generic\n"; -sb << "__target_intrinsic(glsl, \"clamp($0, 0, 1)\")\n"; -sb << "vector saturate(vector x);\n"; -sb << "\n"; -sb << "__generic\n"; -sb << "__target_intrinsic(glsl, \"clamp($0, 0, 1)\")\n"; -sb << "matrix saturate(matrix x);\n"; -sb << "\n"; -sb << "__generic\n"; -sb << "__specialized_for_target(glsl)\n"; -sb << "T saturate(T x)\n"; -sb << "{\n"; -sb << " return clamp(x, T(0), T(1));\n"; -sb << "}\n"; -sb << "\n"; -sb << "__generic\n"; -sb << "__specialized_for_target(glsl)\n"; -sb << "vector saturate(vector x)\n"; -sb << "{\n"; -sb << " return clamp(x,\n"; -sb << " vector(T(0)),\n"; -sb << " vector(T(1)));\n"; -sb << "}\n"; -sb << "\n"; -sb << "// HACK: need a helper to turn a scalar into a matrix,\n"; -sb << "// because GLSL and HLSL disagree on the semantics of\n"; -sb << "// constructing a matrix from a single scalar.\n"; -sb << "__generic\n"; -sb << "matrix __scalarToMatrix(T value);\n"; -sb << "\n"; -sb << "__generic\n"; -sb << "__specialized_for_target(glsl)\n"; -sb << "matrix saturate(matrix x)\n"; -sb << "{\n"; -sb << " return clamp(x,\n"; -sb << " __scalarToMatrix(T(0)),\n"; -sb << " __scalarToMatrix(T(1)));\n"; -sb << "}\n"; -sb << "\n"; -sb << "\n"; -sb << "// Extract sign of value\n"; -sb << "__generic int sign(T x);\n"; -sb << "__generic vector sign(vector x);\n"; -sb << "__generic matrix sign(matrix x);\n"; -sb << "\n"; -sb << "\n"; -sb << "// Sine\n"; -sb << "__generic T sin(T x);\n"; -sb << "__generic vector sin(vector x);\n"; -sb << "__generic matrix sin(matrix x);\n"; -sb << "\n"; -sb << "// Sine and cosine\n"; -sb << "__generic void sincos(T x, out T s, out T c);\n"; -sb << "__generic void sincos(vector x, out vector s, out vector c);\n"; -sb << "__generic void sincos(matrix x, out matrix s, out matrix c);\n"; -sb << "\n"; -sb << "// Hyperbolic Sine\n"; -sb << "__generic T sinh(T x);\n"; -sb << "__generic vector sinh(vector x);\n"; -sb << "__generic matrix sinh(matrix x);\n"; -sb << "\n"; -sb << "// Smooth step (Hermite interpolation)\n"; -sb << "__generic T smoothstep(T min, T max, T x);\n"; -sb << "__generic vector smoothstep(vector min, vector max, vector x);\n"; -sb << "__generic matrix smoothstep(matrix min, matrix max, matrix x);\n"; -sb << "\n"; -sb << "// Square root\n"; -sb << "__generic T sqrt(T x);\n"; -sb << "__generic vector sqrt(vector x);\n"; -sb << "__generic matrix sqrt(matrix x);\n"; -sb << "\n"; -sb << "// Step function\n"; -sb << "__generic T step(T y, T x);\n"; -sb << "__generic vector step(vector y, vector x);\n"; -sb << "__generic matrix step(matrix y, matrix x);\n"; -sb << "\n"; -sb << "// Tangent\n"; -sb << "__generic T tan(T x);\n"; -sb << "__generic vector tan(vector x);\n"; -sb << "__generic matrix tan(matrix x);\n"; -sb << "\n"; -sb << "// Hyperbolic tangent\n"; -sb << "__generic T tanh(T x);\n"; -sb << "__generic vector tanh(vector x);\n"; -sb << "__generic matrix tanh(matrix x);\n"; -sb << "\n"; -sb << "// Legacy texture-fetch operations\n"; -sb << "\n"; -sb << "/*\n"; -sb << "float4 tex1D(sampler1D s, float t);\n"; -sb << "float4 tex1D(sampler1D s, float t, float ddx, float ddy);\n"; -sb << "float4 tex1Dbias(sampler1D s, float4 t);\n"; -sb << "float4 tex1Dgrad(sampler1D s, float t, float ddx, float ddy);\n"; -sb << "float4 tex1Dlod(sampler1D s, float4 t);\n"; -sb << "float4 tex1Dproj(sampler1D s, float4 t);\n"; -sb << "\n"; -sb << "float4 tex2D(sampler2D s, float2 t);\n"; -sb << "float4 tex2D(sampler2D s, float2 t, float2 ddx, float2 ddy);\n"; -sb << "float4 tex2Dbias(sampler2D s, float4 t);\n"; -sb << "float4 tex2Dgrad(sampler2D s, float2 t, float2 ddx, float2 ddy);\n"; -sb << "float4 tex2Dlod(sampler2D s, float4 t);\n"; -sb << "float4 tex2Dproj(sampler2D s, float4 t);\n"; -sb << "\n"; -sb << "float4 tex3D(sampler3D s, float3 t);\n"; -sb << "float4 tex3D(sampler3D s, float3 t, float3 ddx, float3 ddy);\n"; -sb << "float4 tex3Dbias(sampler3D s, float4 t);\n"; -sb << "float4 tex3Dgrad(sampler3D s, float3 t, float3 ddx, float3 ddy);\n"; -sb << "float4 tex3Dlod(sampler3D s, float4 t);\n"; -sb << "float4 tex3Dproj(sampler3D s, float4 t);\n"; -sb << "\n"; -sb << "float4 texCUBE(samplerCUBE s, float3 t);\n"; -sb << "float4 texCUBE(samplerCUBE s, float3 t, float3 ddx, float3 ddy);\n"; -sb << "float4 texCUBEbias(samplerCUBE s, float4 t);\n"; -sb << "float4 texCUBEgrad(samplerCUBE s, float3 t, float3 ddx, float3 ddy);\n"; -sb << "float4 texCUBElod(samplerCUBE s, float4 t);\n"; -sb << "float4 texCUBEproj(samplerCUBE s, float4 t);\n"; -sb << "*/\n"; -sb << "\n"; -sb << "// Matrix transpose\n"; -sb << "__generic matrix transpose(matrix x);\n"; -sb << "\n"; -sb << "// Truncate to integer\n"; -sb << "__generic T trunc(T x);\n"; -sb << "__generic vector trunc(vector x);\n"; -sb << "__generic matrix trunc(matrix x);\n"; -sb << "\n"; -sb << "// Shader model 6.0 stuff\n"; -sb << "\n"; -sb << "uint GlobalOrderedCountIncrement(uint countToAppendForThisLane);\n"; -sb << "\n"; -sb << "__generic T QuadReadLaneAt(T sourceValue, int quadLaneID);\n"; -sb << "__generic vector QuadReadLaneAt(vector sourceValue, int quadLaneID);\n"; -sb << "__generic matrix QuadReadLaneAt(matrix sourceValue, int quadLaneID);\n"; -sb << "\n"; -sb << "__generic T QuadSwapX(T localValue);\n"; -sb << "__generic vector QuadSwapX(vector localValue);\n"; -sb << "__generic matrix QuadSwapX(matrix localValue);\n"; -sb << "\n"; -sb << "__generic T QuadSwapY(T localValue);\n"; -sb << "__generic vector QuadSwapY(vector localValue);\n"; -sb << "__generic matrix QuadSwapY(matrix localValue);\n"; -sb << "\n"; -sb << "__generic T WaveAllBitAnd(T expr);\n"; -sb << "__generic vector WaveAllBitAnd(vector expr);\n"; -sb << "__generic matrix WaveAllBitAnd(matrix expr);\n"; -sb << "\n"; -sb << "__generic T WaveAllBitOr(T expr);\n"; -sb << "__generic vector WaveAllBitOr(vector expr);\n"; -sb << "__generic matrix WaveAllBitOr(matrix expr);\n"; -sb << "\n"; -sb << "__generic T WaveAllBitXor(T expr);\n"; -sb << "__generic vector WaveAllBitXor(vector expr);\n"; -sb << "__generic matrix WaveAllBitXor(matrix expr);\n"; -sb << "\n"; -sb << "__generic T WaveAllMax(T expr);\n"; -sb << "__generic vector WaveAllMax(vector expr);\n"; -sb << "__generic matrix WaveAllMax(matrix expr);\n"; -sb << "\n"; -sb << "__generic T WaveAllMin(T expr);\n"; -sb << "__generic vector WaveAllMin(vector expr);\n"; -sb << "__generic matrix WaveAllMin(matrix expr);\n"; -sb << "\n"; -sb << "__generic T WaveAllProduct(T expr);\n"; -sb << "__generic vector WaveAllProduct(vector expr);\n"; -sb << "__generic matrix WaveAllProduct(matrix expr);\n"; -sb << "\n"; -sb << "__generic T WaveAllSum(T expr);\n"; -sb << "__generic vector WaveAllSum(vector expr);\n"; -sb << "__generic matrix WaveAllSum(matrix expr);\n"; -sb << "\n"; -sb << "bool WaveAllEqual(bool expr);\n"; -sb << "bool WaveAllTrue(bool expr);\n"; -sb << "bool WaveAnyTrue(bool expr);\n"; -sb << "\n"; -sb << "uint64_t WaveBallot(bool expr);\n"; -sb << "\n"; -sb << "uint WaveGetLaneCount();\n"; -sb << "uint WaveGetLaneIndex();\n"; -sb << "uint WaveGetOrderedIndex();\n"; -sb << "\n"; -sb << "bool WaveIsHelperLane();\n"; -sb << "\n"; -sb << "bool WaveOnce();\n"; -sb << "\n"; -sb << "__generic T WavePrefixProduct(T expr);\n"; -sb << "__generic vector WavePrefixProduct(vector expr);\n"; -sb << "__generic matrix WavePrefixProduct(matrix expr);\n"; -sb << "\n"; -sb << "__generic T WavePrefixSum(T expr);\n"; -sb << "__generic vector WavePrefixSum(vector expr);\n"; -sb << "__generic matrix WavePrefixSum(matrix expr);\n"; -sb << "\n"; -sb << "__generic T WaveReadFirstLane(T expr);\n"; -sb << "__generic vector WaveReadFirstLane(vector expr);\n"; -sb << "__generic matrix WaveReadFirstLane(matrix expr);\n"; -sb << "\n"; -sb << "__generic T WaveReadLaneAt(T expr, int laneIndex);\n"; -sb << "__generic vector WaveReadLaneAt(vector expr, int laneIndex);\n"; -sb << "__generic matrix WaveReadLaneAt(matrix expr, int laneIndex);\n"; -sb << "\n"; -sb << "// `typedef`s to help with the fact that HLSL has been sorta-kinda case insensitive at various points\n"; -sb << "typedef Texture2D texture2D;\n"; -sb << "\n"; -sb << ""; - +SLANG_RAW("// Slang HLSL compatibility library\n") +SLANG_RAW("\n") +SLANG_RAW("typedef uint UINT;\n") +SLANG_RAW("\n") +SLANG_RAW("__generic __magic_type(HLSLAppendStructuredBufferType) struct AppendStructuredBuffer\n") +SLANG_RAW("{\n") +SLANG_RAW(" void Append(T value);\n") +SLANG_RAW("\n") +SLANG_RAW(" void GetDimensions(\n") +SLANG_RAW(" out uint numStructs,\n") +SLANG_RAW(" out uint stride);\n") +SLANG_RAW("};\n") +SLANG_RAW("\n") +SLANG_RAW("__magic_type(HLSLByteAddressBufferType) struct ByteAddressBuffer\n") +SLANG_RAW("{\n") +SLANG_RAW(" void GetDimensions(\n") +SLANG_RAW(" out uint dim);\n") +SLANG_RAW("\n") +SLANG_RAW(" uint Load(int location);\n") +SLANG_RAW(" uint Load(int location, out uint status);\n") +SLANG_RAW("\n") +SLANG_RAW(" uint2 Load2(int location);\n") +SLANG_RAW(" uint2 Load2(int location, out uint status);\n") +SLANG_RAW("\n") +SLANG_RAW(" uint3 Load3(int location);\n") +SLANG_RAW(" uint3 Load3(int location, out uint status);\n") +SLANG_RAW("\n") +SLANG_RAW(" uint4 Load4(int location);\n") +SLANG_RAW(" uint4 Load4(int location, out uint status);\n") +SLANG_RAW("};\n") +SLANG_RAW("\n") +SLANG_RAW("__generic\n") +SLANG_RAW("__magic_type(HLSLStructuredBufferType)\n") +SLANG_RAW("__intrinsic_type(") +SLANG_SPLICE(kIROp_structuredBufferType +) +SLANG_RAW(")\n") +SLANG_RAW("struct StructuredBuffer\n") +SLANG_RAW("{\n") +SLANG_RAW(" void GetDimensions(\n") +SLANG_RAW(" out uint numStructs,\n") +SLANG_RAW(" out uint stride);\n") +SLANG_RAW("\n") +SLANG_RAW(" T Load(int location);\n") +SLANG_RAW(" T Load(int location, out uint status);\n") +SLANG_RAW("\n") +SLANG_RAW(" __subscript(uint index) -> T { __intrinsic_op(bufferLoad) get; };\n") +SLANG_RAW("};\n") +SLANG_RAW("\n") +SLANG_RAW("__generic __magic_type(HLSLConsumeStructuredBufferType) struct ConsumeStructuredBuffer\n") +SLANG_RAW("{\n") +SLANG_RAW(" T Consume();\n") +SLANG_RAW("\n") +SLANG_RAW(" void GetDimensions(\n") +SLANG_RAW(" out uint numStructs,\n") +SLANG_RAW(" out uint stride);\n") +SLANG_RAW("};\n") +SLANG_RAW("\n") +SLANG_RAW("__generic __magic_type(HLSLInputPatchType) struct InputPatch\n") +SLANG_RAW("{\n") +SLANG_RAW(" __subscript(uint index) -> T;\n") +SLANG_RAW("};\n") +SLANG_RAW("\n") +SLANG_RAW("__generic __magic_type(HLSLOutputPatchType) struct OutputPatch\n") +SLANG_RAW("{\n") +SLANG_RAW(" __subscript(uint index) -> T;\n") +SLANG_RAW("};\n") +SLANG_RAW("\n") +SLANG_RAW("__magic_type(HLSLRWByteAddressBufferType) struct RWByteAddressBuffer\n") +SLANG_RAW("{\n") +SLANG_RAW(" // Note(tfoley): supports alll operations from `ByteAddressBuffer`\n") +SLANG_RAW(" // TODO(tfoley): can this be made a sub-type?\n") +SLANG_RAW("\n") +SLANG_RAW(" void GetDimensions(\n") +SLANG_RAW(" out uint dim);\n") +SLANG_RAW("\n") +SLANG_RAW(" uint Load(int location);\n") +SLANG_RAW(" uint Load(int location, out uint status);\n") +SLANG_RAW("\n") +SLANG_RAW(" uint2 Load2(int location);\n") +SLANG_RAW(" uint2 Load2(int location, out uint status);\n") +SLANG_RAW("\n") +SLANG_RAW(" uint3 Load3(int location);\n") +SLANG_RAW(" uint3 Load3(int location, out uint status);\n") +SLANG_RAW("\n") +SLANG_RAW(" uint4 Load4(int location);\n") +SLANG_RAW(" uint4 Load4(int location, out uint status);\n") +SLANG_RAW("\n") +SLANG_RAW(" // Added operations:\n") +SLANG_RAW("\n") +SLANG_RAW(" void InterlockedAdd(\n") +SLANG_RAW(" UINT dest,\n") +SLANG_RAW(" UINT value,\n") +SLANG_RAW(" out UINT original_value);\n") +SLANG_RAW(" void InterlockedAdd(\n") +SLANG_RAW(" UINT dest,\n") +SLANG_RAW(" UINT value);\n") +SLANG_RAW("\n") +SLANG_RAW(" void InterlockedAnd(\n") +SLANG_RAW(" UINT dest,\n") +SLANG_RAW(" UINT value,\n") +SLANG_RAW(" out UINT original_value);\n") +SLANG_RAW(" void InterlockedAnd(\n") +SLANG_RAW(" UINT dest,\n") +SLANG_RAW(" UINT value);\n") +SLANG_RAW("\n") +SLANG_RAW(" void InterlockedCompareExchange(\n") +SLANG_RAW(" UINT dest,\n") +SLANG_RAW(" UINT compare_value,\n") +SLANG_RAW(" UINT value,\n") +SLANG_RAW(" out UINT original_value);\n") +SLANG_RAW(" void InterlockedCompareExchange(\n") +SLANG_RAW(" UINT dest,\n") +SLANG_RAW(" UINT compare_value,\n") +SLANG_RAW(" UINT value);\n") +SLANG_RAW("\n") +SLANG_RAW(" void InterlockedCompareStore(\n") +SLANG_RAW(" UINT dest,\n") +SLANG_RAW(" UINT compare_value,\n") +SLANG_RAW(" UINT value);\n") +SLANG_RAW(" void InterlockedCompareStore(\n") +SLANG_RAW(" UINT dest,\n") +SLANG_RAW(" UINT compare_value);\n") +SLANG_RAW("\n") +SLANG_RAW(" void InterlockedExchange(\n") +SLANG_RAW(" UINT dest,\n") +SLANG_RAW(" UINT value,\n") +SLANG_RAW(" out UINT original_value);\n") +SLANG_RAW(" void InterlockedExchange(\n") +SLANG_RAW(" UINT dest,\n") +SLANG_RAW(" UINT value);\n") +SLANG_RAW("\n") +SLANG_RAW(" void InterlockedMax(\n") +SLANG_RAW(" UINT dest,\n") +SLANG_RAW(" UINT value,\n") +SLANG_RAW(" out UINT original_value);\n") +SLANG_RAW(" void InterlockedMax(\n") +SLANG_RAW(" UINT dest,\n") +SLANG_RAW(" UINT value);\n") +SLANG_RAW("\n") +SLANG_RAW(" void InterlockedMin(\n") +SLANG_RAW(" UINT dest,\n") +SLANG_RAW(" UINT value,\n") +SLANG_RAW(" out UINT original_value);\n") +SLANG_RAW(" void InterlockedMin(\n") +SLANG_RAW(" UINT dest,\n") +SLANG_RAW(" UINT value);\n") +SLANG_RAW("\n") +SLANG_RAW(" void InterlockedOr(\n") +SLANG_RAW(" UINT dest,\n") +SLANG_RAW(" UINT value,\n") +SLANG_RAW(" out UINT original_value);\n") +SLANG_RAW(" void InterlockedOr(\n") +SLANG_RAW(" UINT dest,\n") +SLANG_RAW(" UINT value);\n") +SLANG_RAW("\n") +SLANG_RAW(" void InterlockedXor(\n") +SLANG_RAW(" UINT dest,\n") +SLANG_RAW(" UINT value,\n") +SLANG_RAW(" out UINT original_value);\n") +SLANG_RAW(" void InterlockedXor(\n") +SLANG_RAW(" UINT dest,\n") +SLANG_RAW(" UINT value);\n") +SLANG_RAW("\n") +SLANG_RAW(" void Store(\n") +SLANG_RAW(" uint address,\n") +SLANG_RAW(" uint value);\n") +SLANG_RAW("\n") +SLANG_RAW(" void Store2(\n") +SLANG_RAW(" uint address,\n") +SLANG_RAW(" uint2 value);\n") +SLANG_RAW("\n") +SLANG_RAW(" void Store3(\n") +SLANG_RAW(" uint address,\n") +SLANG_RAW(" uint3 value);\n") +SLANG_RAW("\n") +SLANG_RAW(" void Store4(\n") +SLANG_RAW(" uint address,\n") +SLANG_RAW(" uint4 value);\n") +SLANG_RAW("};\n") +SLANG_RAW("\n") +SLANG_RAW("__generic\n") +SLANG_RAW("__magic_type(HLSLRWStructuredBufferType)\n") +SLANG_RAW("__intrinsic_type(") +SLANG_SPLICE(kIROp_readWriteStructuredBufferType +) +SLANG_RAW(")\n") +SLANG_RAW("struct RWStructuredBuffer\n") +SLANG_RAW("{\n") +SLANG_RAW(" uint DecrementCounter();\n") +SLANG_RAW("\n") +SLANG_RAW(" void GetDimensions(\n") +SLANG_RAW(" out uint numStructs,\n") +SLANG_RAW(" out uint stride);\n") +SLANG_RAW("\n") +SLANG_RAW(" uint IncrementCounter();\n") +SLANG_RAW("\n") +SLANG_RAW(" T Load(int location);\n") +SLANG_RAW(" T Load(int location, out uint status);\n") +SLANG_RAW("\n") +SLANG_RAW("\t__subscript(uint index) -> T\n") +SLANG_RAW("\t{\n") +SLANG_RAW(" __intrinsic_op(bufferElementRef)\n") +SLANG_RAW(" ref;\n") +SLANG_RAW("\t}\n") +SLANG_RAW("};\n") +SLANG_RAW("\n") +SLANG_RAW("__generic __magic_type(HLSLPointStreamType) struct PointStream\n") +SLANG_RAW("{\n") +SLANG_RAW(" __target_intrinsic(glsl, \"EmitVertex()\")\n") +SLANG_RAW(" void Append(T value);\n") +SLANG_RAW("\n") +SLANG_RAW(" __target_intrinsic(glsl, \"EndPrimitive()\")\n") +SLANG_RAW(" void RestartStrip();\n") +SLANG_RAW("};\n") +SLANG_RAW("\n") +SLANG_RAW("__generic __magic_type(HLSLLineStreamType) struct LineStream\n") +SLANG_RAW("{\n") +SLANG_RAW(" __target_intrinsic(glsl, \"EmitVertex()\")\n") +SLANG_RAW(" void Append(T value);\n") +SLANG_RAW("\n") +SLANG_RAW(" __target_intrinsic(glsl, \"EndPrimitive()\")\n") +SLANG_RAW(" void RestartStrip();\n") +SLANG_RAW("};\n") +SLANG_RAW("\n") +SLANG_RAW("__generic __magic_type(HLSLTriangleStreamType) struct TriangleStream\n") +SLANG_RAW("{\n") +SLANG_RAW(" __target_intrinsic(glsl, \"EmitVertex()\")\n") +SLANG_RAW(" void Append(T value);\n") +SLANG_RAW("\n") +SLANG_RAW(" __target_intrinsic(glsl, \"EndPrimitive()\")\n") +SLANG_RAW(" void RestartStrip();\n") +SLANG_RAW("};\n") +SLANG_RAW("\n") +SLANG_RAW("// Note(tfoley): Trying to systematically add all the HLSL builtins\n") +SLANG_RAW("\n") +SLANG_RAW("// Try to terminate the current draw or dispatch call (HLSL SM 4.0)\n") +SLANG_RAW("void abort();\n") +SLANG_RAW("\n") +SLANG_RAW("// Absolute value (HLSL SM 1.0)\n") +SLANG_RAW("__generic T abs(T x);\n") +SLANG_RAW("__generic vector abs(vector x);\n") +SLANG_RAW("__generic matrix abs(matrix x);\n") +SLANG_RAW("\n") +SLANG_RAW("// Inverse cosine (HLSL SM 1.0)\n") +SLANG_RAW("__generic T acos(T x);\n") +SLANG_RAW("__generic vector acos(vector x);\n") +SLANG_RAW("__generic matrix acos(matrix x);\n") +SLANG_RAW("\n") +SLANG_RAW("// Test if all components are non-zero (HLSL SM 1.0)\n") +SLANG_RAW("__generic bool all(T x);\n") +SLANG_RAW("__generic bool all(vector x);\n") +SLANG_RAW("__generic bool all(matrix x);\n") +SLANG_RAW("\n") +SLANG_RAW("// Barrier for writes to all memory spaces (HLSL SM 5.0)\n") +SLANG_RAW("void AllMemoryBarrier();\n") +SLANG_RAW("\n") +SLANG_RAW("// Thread-group sync and barrier for writes to all memory spaces (HLSL SM 5.0)\n") +SLANG_RAW("void AllMemoryBarrierWithGroupSync();\n") +SLANG_RAW("\n") +SLANG_RAW("// Test if any components is non-zero (HLSL SM 1.0)\n") +SLANG_RAW("\n") +SLANG_RAW("__generic\n") +SLANG_RAW("__target_intrinsic(glsl, \"bool($0)\")\n") +SLANG_RAW("bool any(T x);\n") +SLANG_RAW("\n") +SLANG_RAW("__generic\n") +SLANG_RAW("__target_intrinsic(glsl, \"any(bvec$N0($0))\")\n") +SLANG_RAW("bool any(vector x);\n") +SLANG_RAW("\n") +SLANG_RAW("__generic\n") +SLANG_RAW("// TODO: need to define GLSL mapping\n") +SLANG_RAW("bool any(matrix x);\n") +SLANG_RAW("\n") +SLANG_RAW("\n") +SLANG_RAW("// Reinterpret bits as a double (HLSL SM 5.0)\n") +SLANG_RAW("double asdouble(uint lowbits, uint highbits);\n") +SLANG_RAW("\n") +SLANG_RAW("// Reinterpret bits as a float (HLSL SM 4.0)\n") +SLANG_RAW("float asfloat( int x);\n") +SLANG_RAW("float asfloat(uint x);\n") +SLANG_RAW("__generic vector asfloat(vector< int,N> x);\n") +SLANG_RAW("__generic vector asfloat(vector x);\n") +SLANG_RAW("__generic matrix asfloat(matrix< int,N,M> x);\n") +SLANG_RAW("__generic matrix asfloat(matrix x);\n") +SLANG_RAW("\n") +SLANG_RAW("\n") +SLANG_RAW("// Inverse sine (HLSL SM 1.0)\n") +SLANG_RAW("__generic T asin(T x);\n") +SLANG_RAW("__generic vector asin(vector x);\n") +SLANG_RAW("__generic matrix asin(matrix x);\n") +SLANG_RAW("\n") +SLANG_RAW("// Reinterpret bits as an int (HLSL SM 4.0)\n") +SLANG_RAW("int asint(float x);\n") +SLANG_RAW("int asint(uint x);\n") +SLANG_RAW("__generic vector asint(vector x);\n") +SLANG_RAW("__generic vector asint(vector x);\n") +SLANG_RAW("__generic matrix asint(matrix x);\n") +SLANG_RAW("__generic matrix asint(matrix x);\n") +SLANG_RAW("\n") +SLANG_RAW("// Reinterpret bits of double as a uint (HLSL SM 5.0)\n") +SLANG_RAW("void asuint(double value, out uint lowbits, out uint highbits);\n") +SLANG_RAW("\n") +SLANG_RAW("// Reinterpret bits as a uint (HLSL SM 4.0)\n") +SLANG_RAW("uint asuint(float x);\n") +SLANG_RAW("uint asuint(int x);\n") +SLANG_RAW("__generic vector asuint(vector x);\n") +SLANG_RAW("__generic vector asuint(vector x);\n") +SLANG_RAW("__generic matrix asuint(matrix x);\n") +SLANG_RAW("__generic matrix asuint(matrix x);\n") +SLANG_RAW("\n") +SLANG_RAW("// Inverse tangent (HLSL SM 1.0)\n") +SLANG_RAW("__generic T atan(T x);\n") +SLANG_RAW("__generic vector atan(vector x);\n") +SLANG_RAW("__generic matrix atan(matrix x);\n") +SLANG_RAW("\n") +SLANG_RAW("__generic\n") +SLANG_RAW("__target_intrinsic(glsl,\"atan($0,$1)\")\n") +SLANG_RAW("T atan2(T y, T x);\n") +SLANG_RAW("\n") +SLANG_RAW("__generic\n") +SLANG_RAW("__target_intrinsic(glsl,\"atan($0,$1)\")\n") +SLANG_RAW("vector atan2(vector y, vector x);\n") +SLANG_RAW("\n") +SLANG_RAW("__generic\n") +SLANG_RAW("__target_intrinsic(glsl,\"atan($0,$1)\")\n") +SLANG_RAW("matrix atan2(matrix y, matrix x);\n") +SLANG_RAW("\n") +SLANG_RAW("// Ceiling (HLSL SM 1.0)\n") +SLANG_RAW("__generic T ceil(T x);\n") +SLANG_RAW("__generic vector ceil(vector x);\n") +SLANG_RAW("__generic matrix ceil(matrix x);\n") +SLANG_RAW("\n") +SLANG_RAW("\n") +SLANG_RAW("// Check access status to tiled resource\n") +SLANG_RAW("bool CheckAccessFullyMapped(uint status);\n") +SLANG_RAW("\n") +SLANG_RAW("// Clamp (HLSL SM 1.0)\n") +SLANG_RAW("__generic T clamp(T x, T min, T max);\n") +SLANG_RAW("__generic vector clamp(vector x, vector min, vector max);\n") +SLANG_RAW("__generic matrix clamp(matrix x, matrix min, matrix max);\n") +SLANG_RAW("\n") +SLANG_RAW("// Clip (discard) fragment conditionally\n") +SLANG_RAW("__generic void clip(T x);\n") +SLANG_RAW("__generic void clip(vector x);\n") +SLANG_RAW("__generic void clip(matrix x);\n") +SLANG_RAW("\n") +SLANG_RAW("// Cosine\n") +SLANG_RAW("__generic T cos(T x);\n") +SLANG_RAW("__generic vector cos(vector x);\n") +SLANG_RAW("__generic matrix cos(matrix x);\n") +SLANG_RAW("\n") +SLANG_RAW("// Hyperbolic cosine\n") +SLANG_RAW("__generic T cosh(T x);\n") +SLANG_RAW("__generic vector cosh(vector x);\n") +SLANG_RAW("__generic matrix cosh(matrix x);\n") +SLANG_RAW("\n") +SLANG_RAW("// Population count\n") +SLANG_RAW("__target_intrinsic(glsl, \"bitCount\")\n") +SLANG_RAW("uint countbits(uint value);\n") +SLANG_RAW("\n") +SLANG_RAW("// Cross product\n") +SLANG_RAW("__generic vector cross(vector x, vector y);\n") +SLANG_RAW("\n") +SLANG_RAW("// Convert encoded color\n") +SLANG_RAW("int4 D3DCOLORtoUBYTE4(float4 x);\n") +SLANG_RAW("\n") +SLANG_RAW("// Partial-difference derivatives\n") +SLANG_RAW("__generic\n") +SLANG_RAW("__target_intrinsic(glsl, dFdx)\n") +SLANG_RAW("T ddx(T x);\n") +SLANG_RAW("\n") +SLANG_RAW("__generic\n") +SLANG_RAW("__target_intrinsic(glsl, dFdx)\n") +SLANG_RAW("vector ddx(vector x);\n") +SLANG_RAW("\n") +SLANG_RAW("__generic\n") +SLANG_RAW("__target_intrinsic(glsl, dFdx)\n") +SLANG_RAW("matrix ddx(matrix x);\n") +SLANG_RAW("\n") +SLANG_RAW("__generic\n") +SLANG_RAW("__glsl_extension(GL_ARB_derivative_control)\n") +SLANG_RAW("__target_intrinsic(glsl, dFdxCoarse)\n") +SLANG_RAW("T ddx_coarse(T x);\n") +SLANG_RAW("\n") +SLANG_RAW("__generic\n") +SLANG_RAW("__glsl_extension(GL_ARB_derivative_control)\n") +SLANG_RAW("__target_intrinsic(glsl, dFdxCoarse)\n") +SLANG_RAW("vector ddx_coarse(vector x);\n") +SLANG_RAW("\n") +SLANG_RAW("__generic\n") +SLANG_RAW("__glsl_extension(GL_ARB_derivative_control)\n") +SLANG_RAW("__target_intrinsic(glsl, dFdxCoarse)\n") +SLANG_RAW("matrix ddx_coarse(matrix x);\n") +SLANG_RAW("\n") +SLANG_RAW("__generic\n") +SLANG_RAW("__glsl_extension(GL_ARB_derivative_control)\n") +SLANG_RAW("__target_intrinsic(glsl, dFdxFine)\n") +SLANG_RAW("T ddx_fine(T x);\n") +SLANG_RAW("\n") +SLANG_RAW("__generic\n") +SLANG_RAW("__glsl_extension(GL_ARB_derivative_control)\n") +SLANG_RAW("__target_intrinsic(glsl, dFdxFine)\n") +SLANG_RAW("vector ddx_fine(vector x);\n") +SLANG_RAW("\n") +SLANG_RAW("__generic\n") +SLANG_RAW("__glsl_extension(GL_ARB_derivative_control)\n") +SLANG_RAW("__target_intrinsic(glsl, dFdxFine)\n") +SLANG_RAW("matrix ddx_fine(matrix x);\n") +SLANG_RAW("\n") +SLANG_RAW("__generic\n") +SLANG_RAW("__target_intrinsic(glsl, dFdy)\n") +SLANG_RAW("T ddy(T x);\n") +SLANG_RAW("\n") +SLANG_RAW("__generic\n") +SLANG_RAW("__target_intrinsic(glsl, dFdy)\n") +SLANG_RAW("vector ddy(vector x);\n") +SLANG_RAW("\n") +SLANG_RAW("__generic\n") +SLANG_RAW("__target_intrinsic(glsl, dFdy)\n") +SLANG_RAW(" matrix ddy(matrix x);\n") +SLANG_RAW("\n") +SLANG_RAW("__generic\n") +SLANG_RAW("__glsl_extension(GL_ARB_derivative_control)\n") +SLANG_RAW("__target_intrinsic(glsl, dFdyCoarse)\n") +SLANG_RAW("T ddy_coarse(T x);\n") +SLANG_RAW("\n") +SLANG_RAW("__generic\n") +SLANG_RAW("__glsl_extension(GL_ARB_derivative_control)\n") +SLANG_RAW("__target_intrinsic(glsl, dFdyCoarse)\n") +SLANG_RAW("vector ddy_coarse(vector x);\n") +SLANG_RAW("\n") +SLANG_RAW("__generic\n") +SLANG_RAW("__glsl_extension(GL_ARB_derivative_control)\n") +SLANG_RAW("__target_intrinsic(glsl, dFdyCoarse)\n") +SLANG_RAW("matrix ddy_coarse(matrix x);\n") +SLANG_RAW("\n") +SLANG_RAW("__generic\n") +SLANG_RAW("__glsl_extension(GL_ARB_derivative_control)\n") +SLANG_RAW("__target_intrinsic(glsl, dFdyFine)\n") +SLANG_RAW("T ddy_fine(T x);\n") +SLANG_RAW("\n") +SLANG_RAW("__generic\n") +SLANG_RAW("__glsl_extension(GL_ARB_derivative_control)\n") +SLANG_RAW("__target_intrinsic(glsl, dFdyFine)\n") +SLANG_RAW("vector ddy_fine(vector x);\n") +SLANG_RAW("\n") +SLANG_RAW("__generic\n") +SLANG_RAW("__glsl_extension(GL_ARB_derivative_control)\n") +SLANG_RAW("__target_intrinsic(glsl, dFdyFine)\n") +SLANG_RAW("matrix ddy_fine(matrix x);\n") +SLANG_RAW("\n") +SLANG_RAW("\n") +SLANG_RAW("// Radians to degrees\n") +SLANG_RAW("__generic T degrees(T x);\n") +SLANG_RAW("__generic vector degrees(vector x);\n") +SLANG_RAW("__generic matrix degrees(matrix x);\n") +SLANG_RAW("\n") +SLANG_RAW("// Matrix determinant\n") +SLANG_RAW("\n") +SLANG_RAW("__generic T determinant(matrix m);\n") +SLANG_RAW("\n") +SLANG_RAW("// Barrier for device memory\n") +SLANG_RAW("void DeviceMemoryBarrier();\n") +SLANG_RAW("void DeviceMemoryBarrierWithGroupSync();\n") +SLANG_RAW("\n") +SLANG_RAW("// Vector distance\n") +SLANG_RAW("\n") +SLANG_RAW("__generic T distance(vector x, vector y);\n") +SLANG_RAW("\n") +SLANG_RAW("// Vector dot product\n") +SLANG_RAW("\n") +SLANG_RAW("__generic T dot(vector x, vector y);\n") +SLANG_RAW("\n") +SLANG_RAW("// Helper for computing distance terms for lighting (obsolete)\n") +SLANG_RAW("\n") +SLANG_RAW("__generic vector dst(vector x, vector y);\n") +SLANG_RAW("\n") +SLANG_RAW("// Error message\n") +SLANG_RAW("\n") +SLANG_RAW("// void errorf( string format, ... );\n") +SLANG_RAW("\n") +SLANG_RAW("// Attribute evaluation\n") +SLANG_RAW("\n") +SLANG_RAW("__generic T EvaluateAttributeAtCentroid(T x);\n") +SLANG_RAW("__generic vector EvaluateAttributeAtCentroid(vector x);\n") +SLANG_RAW("__generic matrix EvaluateAttributeAtCentroid(matrix x);\n") +SLANG_RAW("\n") +SLANG_RAW("__generic T EvaluateAttributeAtSample(T x, uint sampleindex);\n") +SLANG_RAW("__generic vector EvaluateAttributeAtSample(vector x, uint sampleindex);\n") +SLANG_RAW("__generic matrix EvaluateAttributeAtSample(matrix x, uint sampleindex);\n") +SLANG_RAW("\n") +SLANG_RAW("__generic T EvaluateAttributeSnapped(T x, int2 offset);\n") +SLANG_RAW("__generic vector EvaluateAttributeSnapped(vector x, int2 offset);\n") +SLANG_RAW("__generic matrix EvaluateAttributeSnapped(matrix x, int2 offset);\n") +SLANG_RAW("\n") +SLANG_RAW("// Base-e exponent\n") +SLANG_RAW("__generic T exp(T x);\n") +SLANG_RAW("__generic vector exp(vector x);\n") +SLANG_RAW("__generic matrix exp(matrix x);\n") +SLANG_RAW("\n") +SLANG_RAW("// Base-2 exponent\n") +SLANG_RAW("__generic T exp2(T x);\n") +SLANG_RAW("__generic vector exp2(vector x);\n") +SLANG_RAW("__generic matrix exp2(matrix x);\n") +SLANG_RAW("\n") +SLANG_RAW("// Convert 16-bit float stored in low bits of integer\n") +SLANG_RAW("float f16tof32(uint value);\n") +SLANG_RAW("__generic vector f16tof32(vector value);\n") +SLANG_RAW("\n") +SLANG_RAW("// Convert to 16-bit float stored in low bits of integer\n") +SLANG_RAW("uint f32tof16(float value);\n") +SLANG_RAW("__generic vector f32tof16(vector value);\n") +SLANG_RAW("\n") +SLANG_RAW("// Flip surface normal to face forward, if needed\n") +SLANG_RAW("__generic vector faceforward(vector n, vector i, vector ng);\n") +SLANG_RAW("\n") +SLANG_RAW("// Find first set bit starting at high bit and working down\n") +SLANG_RAW("__target_intrinsic(glsl,\"findMSB\")\n") +SLANG_RAW("int firstbithigh(int value);\n") +SLANG_RAW("\n") +SLANG_RAW("__target_intrinsic(glsl,\"findMSB\")\n") +SLANG_RAW("__generic vector firstbithigh(vector value);\n") +SLANG_RAW("\n") +SLANG_RAW("__target_intrinsic(glsl,\"findMSB\")\n") +SLANG_RAW("uint firstbithigh(uint value);\n") +SLANG_RAW("\n") +SLANG_RAW("__target_intrinsic(glsl,\"findMSB\")\n") +SLANG_RAW("__generic vector firstbithigh(vector value);\n") +SLANG_RAW("\n") +SLANG_RAW("// Find first set bit starting at low bit and working up\n") +SLANG_RAW("__target_intrinsic(glsl,\"findLSB\")\n") +SLANG_RAW("int firstbitlow(int value);\n") +SLANG_RAW("\n") +SLANG_RAW("__target_intrinsic(glsl,\"findLSB\")\n") +SLANG_RAW("__generic vector firstbitlow(vector value);\n") +SLANG_RAW("\n") +SLANG_RAW("__target_intrinsic(glsl,\"findLSB\")\n") +SLANG_RAW("uint firstbitlow(uint value);\n") +SLANG_RAW("\n") +SLANG_RAW("__target_intrinsic(glsl,\"findLSB\")\n") +SLANG_RAW("__generic vector firstbitlow(vector value);\n") +SLANG_RAW("\n") +SLANG_RAW("// Floor (HLSL SM 1.0)\n") +SLANG_RAW("__generic T floor(T x);\n") +SLANG_RAW("__generic vector floor(vector x);\n") +SLANG_RAW("__generic matrix floor(matrix x);\n") +SLANG_RAW("\n") +SLANG_RAW("// Fused multiply-add for doubles\n") +SLANG_RAW("double fma(double a, double b, double c);\n") +SLANG_RAW("__generic vector fma(vector a, vector b, vector c);\n") +SLANG_RAW("__generic matrix fma(matrix a, matrix b, matrix c);\n") +SLANG_RAW("\n") +SLANG_RAW("// Floating point remainder of x/y\n") +SLANG_RAW("__generic T fmod(T x, T y);\n") +SLANG_RAW("__generic vector fmod(vector x, vector y);\n") +SLANG_RAW("__generic matrix fmod(matrix x, matrix y);\n") +SLANG_RAW("\n") +SLANG_RAW("// Fractional part\n") +SLANG_RAW("__generic\n") +SLANG_RAW("__target_intrinsic(glsl, fract)\n") +SLANG_RAW("T frac(T x);\n") +SLANG_RAW("\n") +SLANG_RAW("__generic\n") +SLANG_RAW("__target_intrinsic(glsl, fract)\n") +SLANG_RAW("vector frac(vector x);\n") +SLANG_RAW("\n") +SLANG_RAW("__generic\n") +SLANG_RAW("__target_intrinsic(glsl, fract)\n") +SLANG_RAW("matrix frac(matrix x);\n") +SLANG_RAW("\n") +SLANG_RAW("// Split float into mantissa and exponent\n") +SLANG_RAW("__generic T frexp(T x, out T exp);\n") +SLANG_RAW("__generic vector frexp(vector x, out vector exp);\n") +SLANG_RAW("__generic matrix frexp(matrix x, out matrix exp);\n") +SLANG_RAW("\n") +SLANG_RAW("// Texture filter width\n") +SLANG_RAW("__generic T fwidth(T x);\n") +SLANG_RAW("__generic vector fwidth(vector x);\n") +SLANG_RAW("__generic matrix fwidth(matrix x);\n") +SLANG_RAW("\n") +SLANG_RAW("// Get number of samples in render target\n") +SLANG_RAW("uint GetRenderTargetSampleCount();\n") +SLANG_RAW("\n") +SLANG_RAW("// Get position of given sample\n") +SLANG_RAW("float2 GetRenderTargetSamplePosition(int Index);\n") +SLANG_RAW("\n") +SLANG_RAW("// Group memory barrier\n") +SLANG_RAW("__target_intrinsic(glsl, \"groupMemoryBarrier\")\n") +SLANG_RAW("void GroupMemoryBarrier();\n") +SLANG_RAW("\n") +SLANG_RAW("__target_intrinsic(glsl, \"groupMemoryBarrier(); barrier()\")\n") +SLANG_RAW("void GroupMemoryBarrierWithGroupSync();\n") +SLANG_RAW("\n") +SLANG_RAW("// Atomics\n") +SLANG_RAW("void InterlockedAdd(in out int dest, int value, out int original_value);\n") +SLANG_RAW("void InterlockedAdd(in out uint dest, uint value, out uint original_value);\n") +SLANG_RAW("\n") +SLANG_RAW("void InterlockedAnd(in out int dest, int value, out int original_value);\n") +SLANG_RAW("void InterlockedAnd(in out uint dest, uint value, out uint original_value);\n") +SLANG_RAW("\n") +SLANG_RAW("void InterlockedCompareExchange(in out int dest, int compare_value, int value, out int original_value);\n") +SLANG_RAW("void InterlockedCompareExchange(in out uint dest, uint compare_value, uint value, out uint original_value);\n") +SLANG_RAW("\n") +SLANG_RAW("void InterlockedCompareStore(in out int dest, int compare_value, int value);\n") +SLANG_RAW("void InterlockedCompareStore(in out uint dest, uint compare_value, uint value);\n") +SLANG_RAW("\n") +SLANG_RAW("void InterlockedExchange(in out int dest, int value, out int original_value);\n") +SLANG_RAW("void InterlockedExchange(in out uint dest, uint value, out uint original_value);\n") +SLANG_RAW("\n") +SLANG_RAW("void InterlockedMax(in out int dest, int value, out int original_value);\n") +SLANG_RAW("void InterlockedMax(in out uint dest, uint value, out uint original_value);\n") +SLANG_RAW("\n") +SLANG_RAW("void InterlockedMin(in out int dest, int value, out int original_value);\n") +SLANG_RAW("void InterlockedMin(in out uint dest, uint value, out uint original_value);\n") +SLANG_RAW("\n") +SLANG_RAW("void InterlockedOr(in out int dest, int value, out int original_value);\n") +SLANG_RAW("void InterlockedOr(in out uint dest, uint value, out uint original_value);\n") +SLANG_RAW("\n") +SLANG_RAW("void InterlockedXor(in out int dest, int value, out int original_value);\n") +SLANG_RAW("void InterlockedXor(in out uint dest, uint value, out uint original_value);\n") +SLANG_RAW("\n") +SLANG_RAW("// Is floating-point value finite?\n") +SLANG_RAW("__generic bool isfinite(T x);\n") +SLANG_RAW("__generic vector isfinite(vector x);\n") +SLANG_RAW("__generic matrix isfinite(matrix x);\n") +SLANG_RAW("\n") +SLANG_RAW("// Is floating-point value infinite?\n") +SLANG_RAW("__generic bool isinf(T x);\n") +SLANG_RAW("__generic vector isinf(vector x);\n") +SLANG_RAW("__generic matrix isinf(matrix x);\n") +SLANG_RAW("\n") +SLANG_RAW("// Is floating-point value not-a-number?\n") +SLANG_RAW("__generic bool isnan(T x);\n") +SLANG_RAW("__generic vector isnan(vector x);\n") +SLANG_RAW("__generic matrix isnan(matrix x);\n") +SLANG_RAW("\n") +SLANG_RAW("// Construct float from mantissa and exponent\n") +SLANG_RAW("__generic T ldexp(T x, T exp);\n") +SLANG_RAW("__generic vector ldexp(vector x, vector exp);\n") +SLANG_RAW("__generic matrix ldexp(matrix x, matrix exp);\n") +SLANG_RAW("\n") +SLANG_RAW("// Vector length\n") +SLANG_RAW("__generic T length(vector x);\n") +SLANG_RAW("\n") +SLANG_RAW("// Linear interpolation\n") +SLANG_RAW("__generic\n") +SLANG_RAW("__target_intrinsic(glsl, mix)\n") +SLANG_RAW("T lerp(T x, T y, T s);\n") +SLANG_RAW("\n") +SLANG_RAW("__generic\n") +SLANG_RAW("__target_intrinsic(glsl, mix)\n") +SLANG_RAW("vector lerp(vector x, vector y, vector s);\n") +SLANG_RAW("\n") +SLANG_RAW("__generic\n") +SLANG_RAW("__target_intrinsic(glsl, mix)\n") +SLANG_RAW("matrix lerp(matrix x, matrix y, matrix s);\n") +SLANG_RAW("\n") +SLANG_RAW("// Legacy lighting function (obsolete)\n") +SLANG_RAW("float4 lit(float n_dot_l, float n_dot_h, float m);\n") +SLANG_RAW("\n") +SLANG_RAW("// Base-e logarithm\n") +SLANG_RAW("__generic T log(T x);\n") +SLANG_RAW("__generic vector log(vector x);\n") +SLANG_RAW("__generic matrix log(matrix x);\n") +SLANG_RAW("\n") +SLANG_RAW("// Base-10 logarithm\n") +SLANG_RAW("__generic T log10(T x);\n") +SLANG_RAW("__generic vector log10(vector x);\n") +SLANG_RAW("__generic matrix log10(matrix x);\n") +SLANG_RAW("\n") +SLANG_RAW("// Base-2 logarithm\n") +SLANG_RAW("__generic T log2(T x);\n") +SLANG_RAW("__generic vector log2(vector x);\n") +SLANG_RAW("__generic matrix log2(matrix x);\n") +SLANG_RAW("\n") +SLANG_RAW("// multiply-add\n") +SLANG_RAW("__generic T mad(T mvalue, T avalue, T bvalue);\n") +SLANG_RAW("__generic vector mad(vector mvalue, vector avalue, vector bvalue);\n") +SLANG_RAW("__generic matrix mad(matrix mvalue, matrix avalue, matrix bvalue);\n") +SLANG_RAW("\n") +SLANG_RAW("// maximum\n") +SLANG_RAW("__generic T max(T x, T y);\n") +SLANG_RAW("__generic vector max(vector x, vector y);\n") +SLANG_RAW("__generic matrix max(matrix x, matrix y);\n") +SLANG_RAW("\n") +SLANG_RAW("// minimum\n") +SLANG_RAW("__generic T min(T x, T y);\n") +SLANG_RAW("__generic vector min(vector x, vector y);\n") +SLANG_RAW("__generic matrix min(matrix x, matrix y);\n") +SLANG_RAW("\n") +SLANG_RAW("// split into integer and fractional parts (both with same sign)\n") +SLANG_RAW("__generic T modf(T x, out T ip);\n") +SLANG_RAW("__generic vector modf(vector x, out vector ip);\n") +SLANG_RAW("__generic matrix modf(matrix x, out matrix ip);\n") +SLANG_RAW("\n") +SLANG_RAW("// msad4 (whatever that is)\n") +SLANG_RAW("uint4 msad4(uint reference, uint2 source, uint4 accum);\n") +SLANG_RAW("\n") +SLANG_RAW("// General inner products\n") +SLANG_RAW("\n") +SLANG_RAW("// scalar-scalar\n") +SLANG_RAW("__generic T mul(T x, T y);\n") +SLANG_RAW("\n") +SLANG_RAW("// scalar-vector and vector-scalar\n") +SLANG_RAW("__generic vector mul(vector x, T y);\n") +SLANG_RAW("__generic vector mul(T x, vector y);\n") +SLANG_RAW("\n") +SLANG_RAW("// scalar-matrix and matrix-scalar\n") +SLANG_RAW("__generic matrix mul(matrix x, T y);\n") +SLANG_RAW("__generic matrix mul(T x, matrix y);\n") +SLANG_RAW("\n") +SLANG_RAW("// vector-vector (dot product)\n") +SLANG_RAW("__generic __intrinsic_op(dot) T mul(vector x, vector y);\n") +SLANG_RAW("\n") +SLANG_RAW("// vector-matrix\n") +SLANG_RAW("__generic __intrinsic_op(mulVectorMatrix) vector mul(vector x, matrix y);\n") +SLANG_RAW("\n") +SLANG_RAW("// matrix-vector\n") +SLANG_RAW("__generic __intrinsic_op(mulMatrixVector) vector mul(matrix x, vector y);\n") +SLANG_RAW("\n") +SLANG_RAW("// matrix-matrix\n") +SLANG_RAW("__generic __intrinsic_op(mulMatrixMatrix) matrix mul(matrix x, matrix y);\n") +SLANG_RAW("\n") +SLANG_RAW("// noise (deprecated)\n") +SLANG_RAW("float noise(float x);\n") +SLANG_RAW("__generic float noise(vector x);\n") +SLANG_RAW("\n") +SLANG_RAW("// Normalize a vector\n") +SLANG_RAW("__generic vector normalize(vector x);\n") +SLANG_RAW("\n") +SLANG_RAW("// Raise to a power\n") +SLANG_RAW("__generic T pow(T x, T y);\n") +SLANG_RAW("__generic vector pow(vector x, vector y);\n") +SLANG_RAW("__generic matrix pow(matrix x, matrix y);\n") +SLANG_RAW("\n") +SLANG_RAW("// Output message\n") +SLANG_RAW("\n") +SLANG_RAW("// void printf( string format, ... );\n") +SLANG_RAW("\n") +SLANG_RAW("// Tessellation factor fixup routines\n") +SLANG_RAW("\n") +SLANG_RAW("void Process2DQuadTessFactorsAvg(\n") +SLANG_RAW(" in float4 RawEdgeFactors,\n") +SLANG_RAW(" in float2 InsideScale,\n") +SLANG_RAW(" out float4 RoundedEdgeTessFactors,\n") +SLANG_RAW(" out float2 RoundedInsideTessFactors,\n") +SLANG_RAW(" out float2 UnroundedInsideTessFactors);\n") +SLANG_RAW("\n") +SLANG_RAW("void Process2DQuadTessFactorsMax(\n") +SLANG_RAW(" in float4 RawEdgeFactors,\n") +SLANG_RAW(" in float2 InsideScale,\n") +SLANG_RAW(" out float4 RoundedEdgeTessFactors,\n") +SLANG_RAW(" out float2 RoundedInsideTessFactors,\n") +SLANG_RAW(" out float2 UnroundedInsideTessFactors);\n") +SLANG_RAW("\n") +SLANG_RAW("void Process2DQuadTessFactorsMin(\n") +SLANG_RAW(" in float4 RawEdgeFactors,\n") +SLANG_RAW(" in float2 InsideScale,\n") +SLANG_RAW(" out float4 RoundedEdgeTessFactors,\n") +SLANG_RAW(" out float2 RoundedInsideTessFactors,\n") +SLANG_RAW(" out float2 UnroundedInsideTessFactors);\n") +SLANG_RAW("\n") +SLANG_RAW("void ProcessIsolineTessFactors(\n") +SLANG_RAW(" in float RawDetailFactor,\n") +SLANG_RAW(" in float RawDensityFactor,\n") +SLANG_RAW(" out float RoundedDetailFactor,\n") +SLANG_RAW(" out float RoundedDensityFactor);\n") +SLANG_RAW("\n") +SLANG_RAW("void ProcessQuadTessFactorsAvg(\n") +SLANG_RAW(" in float4 RawEdgeFactors,\n") +SLANG_RAW(" in float InsideScale,\n") +SLANG_RAW(" out float4 RoundedEdgeTessFactors,\n") +SLANG_RAW(" out float2 RoundedInsideTessFactors,\n") +SLANG_RAW(" out float2 UnroundedInsideTessFactors);\n") +SLANG_RAW("\n") +SLANG_RAW("void ProcessQuadTessFactorsMax(\n") +SLANG_RAW(" in float4 RawEdgeFactors,\n") +SLANG_RAW(" in float InsideScale,\n") +SLANG_RAW(" out float4 RoundedEdgeTessFactors,\n") +SLANG_RAW(" out float2 RoundedInsideTessFactors,\n") +SLANG_RAW(" out float2 UnroundedInsideTessFactors);\n") +SLANG_RAW("\n") +SLANG_RAW("void ProcessQuadTessFactorsMin(\n") +SLANG_RAW(" in float4 RawEdgeFactors,\n") +SLANG_RAW(" in float InsideScale,\n") +SLANG_RAW(" out float4 RoundedEdgeTessFactors,\n") +SLANG_RAW(" out float2 RoundedInsideTessFactors,\n") +SLANG_RAW(" out float2 UnroundedInsideTessFactors);\n") +SLANG_RAW("\n") +SLANG_RAW("void ProcessTriTessFactorsAvg(\n") +SLANG_RAW(" in float3 RawEdgeFactors,\n") +SLANG_RAW(" in float InsideScale,\n") +SLANG_RAW(" out float3 RoundedEdgeTessFactors,\n") +SLANG_RAW(" out float RoundedInsideTessFactor,\n") +SLANG_RAW(" out float UnroundedInsideTessFactor);\n") +SLANG_RAW("\n") +SLANG_RAW("void ProcessTriTessFactorsMax(\n") +SLANG_RAW(" in float3 RawEdgeFactors,\n") +SLANG_RAW(" in float InsideScale,\n") +SLANG_RAW(" out float3 RoundedEdgeTessFactors,\n") +SLANG_RAW(" out float RoundedInsideTessFactor,\n") +SLANG_RAW(" out float UnroundedInsideTessFactor);\n") +SLANG_RAW("\n") +SLANG_RAW("void ProcessTriTessFactorsMin(\n") +SLANG_RAW(" in float3 RawEdgeFactors,\n") +SLANG_RAW(" in float InsideScale,\n") +SLANG_RAW(" out float3 RoundedEdgeTessFactors,\n") +SLANG_RAW(" out float RoundedInsideTessFactors,\n") +SLANG_RAW(" out float UnroundedInsideTessFactors);\n") +SLANG_RAW("\n") +SLANG_RAW("// Degrees to radians\n") +SLANG_RAW("__generic T radians(T x);\n") +SLANG_RAW("__generic vector radians(vector x);\n") +SLANG_RAW("__generic matrix radians(matrix x);\n") +SLANG_RAW("\n") +SLANG_RAW("// Approximate reciprocal\n") +SLANG_RAW("__generic T rcp(T x);\n") +SLANG_RAW("__generic vector rcp(vector x);\n") +SLANG_RAW("__generic matrix rcp(matrix x);\n") +SLANG_RAW("\n") +SLANG_RAW("// Reflect incident vector across plane with given normal\n") +SLANG_RAW("__generic\n") +SLANG_RAW("vector reflect(vector i, vector n);\n") +SLANG_RAW("\n") +SLANG_RAW("// Refract incident vector given surface normal and index of refraction\n") +SLANG_RAW("__generic\n") +SLANG_RAW("vector refract(vector i, vector n, float eta);\n") +SLANG_RAW("\n") +SLANG_RAW("// Reverse order of bits\n") +SLANG_RAW("__target_intrinsic(glsl, \"bitfieldReverse\")\n") +SLANG_RAW("uint reversebits(uint value);\n") +SLANG_RAW("\n") +SLANG_RAW("__target_intrinsic(glsl, \"bitfieldReverse\")\n") +SLANG_RAW("__generic vector reversebits(vector value);\n") +SLANG_RAW("\n") +SLANG_RAW("// Round-to-nearest\n") +SLANG_RAW("__generic T round(T x);\n") +SLANG_RAW("__generic vector round(vector x);\n") +SLANG_RAW("__generic matrix round(matrix x);\n") +SLANG_RAW("\n") +SLANG_RAW("// Reciprocal of square root\n") +SLANG_RAW("__generic T rsqrt(T x);\n") +SLANG_RAW("__generic vector rsqrt(vector x);\n") +SLANG_RAW("__generic matrix rsqrt(matrix x);\n") +SLANG_RAW("\n") +SLANG_RAW("// Clamp value to [0,1] range\n") +SLANG_RAW("__generic\n") +SLANG_RAW("__target_intrinsic(glsl, \"clamp($0, 0, 1)\")\n") +SLANG_RAW("T saturate(T x);\n") +SLANG_RAW("\n") +SLANG_RAW("__generic\n") +SLANG_RAW("__target_intrinsic(glsl, \"clamp($0, 0, 1)\")\n") +SLANG_RAW("vector saturate(vector x);\n") +SLANG_RAW("\n") +SLANG_RAW("__generic\n") +SLANG_RAW("__target_intrinsic(glsl, \"clamp($0, 0, 1)\")\n") +SLANG_RAW("matrix saturate(matrix x);\n") +SLANG_RAW("\n") +SLANG_RAW("__generic\n") +SLANG_RAW("__specialized_for_target(glsl)\n") +SLANG_RAW("T saturate(T x)\n") +SLANG_RAW("{\n") +SLANG_RAW(" return clamp(x, T(0), T(1));\n") +SLANG_RAW("}\n") +SLANG_RAW("\n") +SLANG_RAW("__generic\n") +SLANG_RAW("__specialized_for_target(glsl)\n") +SLANG_RAW("vector saturate(vector x)\n") +SLANG_RAW("{\n") +SLANG_RAW(" return clamp(x,\n") +SLANG_RAW(" vector(T(0)),\n") +SLANG_RAW(" vector(T(1)));\n") +SLANG_RAW("}\n") +SLANG_RAW("\n") +SLANG_RAW("// HACK: need a helper to turn a scalar into a matrix,\n") +SLANG_RAW("// because GLSL and HLSL disagree on the semantics of\n") +SLANG_RAW("// constructing a matrix from a single scalar.\n") +SLANG_RAW("__generic\n") +SLANG_RAW("matrix __scalarToMatrix(T value);\n") +SLANG_RAW("\n") +SLANG_RAW("__generic\n") +SLANG_RAW("__specialized_for_target(glsl)\n") +SLANG_RAW("matrix saturate(matrix x)\n") +SLANG_RAW("{\n") +SLANG_RAW(" return clamp(x,\n") +SLANG_RAW(" __scalarToMatrix(T(0)),\n") +SLANG_RAW(" __scalarToMatrix(T(1)));\n") +SLANG_RAW("}\n") +SLANG_RAW("\n") +SLANG_RAW("\n") +SLANG_RAW("// Extract sign of value\n") +SLANG_RAW("__generic int sign(T x);\n") +SLANG_RAW("__generic vector sign(vector x);\n") +SLANG_RAW("__generic matrix sign(matrix x);\n") +SLANG_RAW("\n") +SLANG_RAW("\n") +SLANG_RAW("// Sine\n") +SLANG_RAW("__generic T sin(T x);\n") +SLANG_RAW("__generic vector sin(vector x);\n") +SLANG_RAW("__generic matrix sin(matrix x);\n") +SLANG_RAW("\n") +SLANG_RAW("// Sine and cosine\n") +SLANG_RAW("__generic void sincos(T x, out T s, out T c);\n") +SLANG_RAW("__generic void sincos(vector x, out vector s, out vector c);\n") +SLANG_RAW("__generic void sincos(matrix x, out matrix s, out matrix c);\n") +SLANG_RAW("\n") +SLANG_RAW("// Hyperbolic Sine\n") +SLANG_RAW("__generic T sinh(T x);\n") +SLANG_RAW("__generic vector sinh(vector x);\n") +SLANG_RAW("__generic matrix sinh(matrix x);\n") +SLANG_RAW("\n") +SLANG_RAW("// Smooth step (Hermite interpolation)\n") +SLANG_RAW("__generic T smoothstep(T min, T max, T x);\n") +SLANG_RAW("__generic vector smoothstep(vector min, vector max, vector x);\n") +SLANG_RAW("__generic matrix smoothstep(matrix min, matrix max, matrix x);\n") +SLANG_RAW("\n") +SLANG_RAW("// Square root\n") +SLANG_RAW("__generic T sqrt(T x);\n") +SLANG_RAW("__generic vector sqrt(vector x);\n") +SLANG_RAW("__generic matrix sqrt(matrix x);\n") +SLANG_RAW("\n") +SLANG_RAW("// Step function\n") +SLANG_RAW("__generic T step(T y, T x);\n") +SLANG_RAW("__generic vector step(vector y, vector x);\n") +SLANG_RAW("__generic matrix step(matrix y, matrix x);\n") +SLANG_RAW("\n") +SLANG_RAW("// Tangent\n") +SLANG_RAW("__generic T tan(T x);\n") +SLANG_RAW("__generic vector tan(vector x);\n") +SLANG_RAW("__generic matrix tan(matrix x);\n") +SLANG_RAW("\n") +SLANG_RAW("// Hyperbolic tangent\n") +SLANG_RAW("__generic T tanh(T x);\n") +SLANG_RAW("__generic vector tanh(vector x);\n") +SLANG_RAW("__generic matrix tanh(matrix x);\n") +SLANG_RAW("\n") +SLANG_RAW("// Legacy texture-fetch operations\n") +SLANG_RAW("\n") +SLANG_RAW("/*\n") +SLANG_RAW("float4 tex1D(sampler1D s, float t);\n") +SLANG_RAW("float4 tex1D(sampler1D s, float t, float ddx, float ddy);\n") +SLANG_RAW("float4 tex1Dbias(sampler1D s, float4 t);\n") +SLANG_RAW("float4 tex1Dgrad(sampler1D s, float t, float ddx, float ddy);\n") +SLANG_RAW("float4 tex1Dlod(sampler1D s, float4 t);\n") +SLANG_RAW("float4 tex1Dproj(sampler1D s, float4 t);\n") +SLANG_RAW("\n") +SLANG_RAW("float4 tex2D(sampler2D s, float2 t);\n") +SLANG_RAW("float4 tex2D(sampler2D s, float2 t, float2 ddx, float2 ddy);\n") +SLANG_RAW("float4 tex2Dbias(sampler2D s, float4 t);\n") +SLANG_RAW("float4 tex2Dgrad(sampler2D s, float2 t, float2 ddx, float2 ddy);\n") +SLANG_RAW("float4 tex2Dlod(sampler2D s, float4 t);\n") +SLANG_RAW("float4 tex2Dproj(sampler2D s, float4 t);\n") +SLANG_RAW("\n") +SLANG_RAW("float4 tex3D(sampler3D s, float3 t);\n") +SLANG_RAW("float4 tex3D(sampler3D s, float3 t, float3 ddx, float3 ddy);\n") +SLANG_RAW("float4 tex3Dbias(sampler3D s, float4 t);\n") +SLANG_RAW("float4 tex3Dgrad(sampler3D s, float3 t, float3 ddx, float3 ddy);\n") +SLANG_RAW("float4 tex3Dlod(sampler3D s, float4 t);\n") +SLANG_RAW("float4 tex3Dproj(sampler3D s, float4 t);\n") +SLANG_RAW("\n") +SLANG_RAW("float4 texCUBE(samplerCUBE s, float3 t);\n") +SLANG_RAW("float4 texCUBE(samplerCUBE s, float3 t, float3 ddx, float3 ddy);\n") +SLANG_RAW("float4 texCUBEbias(samplerCUBE s, float4 t);\n") +SLANG_RAW("float4 texCUBEgrad(samplerCUBE s, float3 t, float3 ddx, float3 ddy);\n") +SLANG_RAW("float4 texCUBElod(samplerCUBE s, float4 t);\n") +SLANG_RAW("float4 texCUBEproj(samplerCUBE s, float4 t);\n") +SLANG_RAW("*/\n") +SLANG_RAW("\n") +SLANG_RAW("// Matrix transpose\n") +SLANG_RAW("__generic matrix transpose(matrix x);\n") +SLANG_RAW("\n") +SLANG_RAW("// Truncate to integer\n") +SLANG_RAW("__generic T trunc(T x);\n") +SLANG_RAW("__generic vector trunc(vector x);\n") +SLANG_RAW("__generic matrix trunc(matrix x);\n") +SLANG_RAW("\n") +SLANG_RAW("// Shader model 6.0 stuff\n") +SLANG_RAW("\n") +SLANG_RAW("uint GlobalOrderedCountIncrement(uint countToAppendForThisLane);\n") +SLANG_RAW("\n") +SLANG_RAW("__generic T QuadReadLaneAt(T sourceValue, int quadLaneID);\n") +SLANG_RAW("__generic vector QuadReadLaneAt(vector sourceValue, int quadLaneID);\n") +SLANG_RAW("__generic matrix QuadReadLaneAt(matrix sourceValue, int quadLaneID);\n") +SLANG_RAW("\n") +SLANG_RAW("__generic T QuadSwapX(T localValue);\n") +SLANG_RAW("__generic vector QuadSwapX(vector localValue);\n") +SLANG_RAW("__generic matrix QuadSwapX(matrix localValue);\n") +SLANG_RAW("\n") +SLANG_RAW("__generic T QuadSwapY(T localValue);\n") +SLANG_RAW("__generic vector QuadSwapY(vector localValue);\n") +SLANG_RAW("__generic matrix QuadSwapY(matrix localValue);\n") +SLANG_RAW("\n") +SLANG_RAW("__generic T WaveAllBitAnd(T expr);\n") +SLANG_RAW("__generic vector WaveAllBitAnd(vector expr);\n") +SLANG_RAW("__generic matrix WaveAllBitAnd(matrix expr);\n") +SLANG_RAW("\n") +SLANG_RAW("__generic T WaveAllBitOr(T expr);\n") +SLANG_RAW("__generic vector WaveAllBitOr(vector expr);\n") +SLANG_RAW("__generic matrix WaveAllBitOr(matrix expr);\n") +SLANG_RAW("\n") +SLANG_RAW("__generic T WaveAllBitXor(T expr);\n") +SLANG_RAW("__generic vector WaveAllBitXor(vector expr);\n") +SLANG_RAW("__generic matrix WaveAllBitXor(matrix expr);\n") +SLANG_RAW("\n") +SLANG_RAW("__generic T WaveAllMax(T expr);\n") +SLANG_RAW("__generic vector WaveAllMax(vector expr);\n") +SLANG_RAW("__generic matrix WaveAllMax(matrix expr);\n") +SLANG_RAW("\n") +SLANG_RAW("__generic T WaveAllMin(T expr);\n") +SLANG_RAW("__generic vector WaveAllMin(vector expr);\n") +SLANG_RAW("__generic matrix WaveAllMin(matrix expr);\n") +SLANG_RAW("\n") +SLANG_RAW("__generic T WaveAllProduct(T expr);\n") +SLANG_RAW("__generic vector WaveAllProduct(vector expr);\n") +SLANG_RAW("__generic matrix WaveAllProduct(matrix expr);\n") +SLANG_RAW("\n") +SLANG_RAW("__generic T WaveAllSum(T expr);\n") +SLANG_RAW("__generic vector WaveAllSum(vector expr);\n") +SLANG_RAW("__generic matrix WaveAllSum(matrix expr);\n") +SLANG_RAW("\n") +SLANG_RAW("bool WaveAllEqual(bool expr);\n") +SLANG_RAW("bool WaveAllTrue(bool expr);\n") +SLANG_RAW("bool WaveAnyTrue(bool expr);\n") +SLANG_RAW("\n") +SLANG_RAW("uint64_t WaveBallot(bool expr);\n") +SLANG_RAW("\n") +SLANG_RAW("uint WaveGetLaneCount();\n") +SLANG_RAW("uint WaveGetLaneIndex();\n") +SLANG_RAW("uint WaveGetOrderedIndex();\n") +SLANG_RAW("\n") +SLANG_RAW("bool WaveIsHelperLane();\n") +SLANG_RAW("\n") +SLANG_RAW("bool WaveOnce();\n") +SLANG_RAW("\n") +SLANG_RAW("__generic T WavePrefixProduct(T expr);\n") +SLANG_RAW("__generic vector WavePrefixProduct(vector expr);\n") +SLANG_RAW("__generic matrix WavePrefixProduct(matrix expr);\n") +SLANG_RAW("\n") +SLANG_RAW("__generic T WavePrefixSum(T expr);\n") +SLANG_RAW("__generic vector WavePrefixSum(vector expr);\n") +SLANG_RAW("__generic matrix WavePrefixSum(matrix expr);\n") +SLANG_RAW("\n") +SLANG_RAW("__generic T WaveReadFirstLane(T expr);\n") +SLANG_RAW("__generic vector WaveReadFirstLane(vector expr);\n") +SLANG_RAW("__generic matrix WaveReadFirstLane(matrix expr);\n") +SLANG_RAW("\n") +SLANG_RAW("__generic T WaveReadLaneAt(T expr, int laneIndex);\n") +SLANG_RAW("__generic vector WaveReadLaneAt(vector expr, int laneIndex);\n") +SLANG_RAW("__generic matrix WaveReadLaneAt(matrix expr, int laneIndex);\n") +SLANG_RAW("\n") +SLANG_RAW("// `typedef`s to help with the fact that HLSL has been sorta-kinda case insensitive at various points\n") +SLANG_RAW("typedef Texture2D texture2D;\n") +SLANG_RAW("\n") // Component-wise multiplication ops for(auto op : binaryOps) @@ -1131,5 +1126,4 @@ for (int aa = 0; aa < kBaseBufferAccessLevelCount; ++aa) sb << "};\n"; } - -sb << ""; +SLANG_RAW("\n") diff --git a/source/slang/slang-stdlib.cpp b/source/slang/slang-stdlib.cpp index bee823d69..69ae36a3f 100644 --- a/source/slang/slang-stdlib.cpp +++ b/source/slang/slang-stdlib.cpp @@ -246,6 +246,9 @@ namespace Slang String path = getStdlibPath(); +#define SLANG_RAW(TEXT) sb << TEXT; +#define SLANG_SPLICE(EXPR) sb << (EXPR); + #define EMIT_LINE_DIRECTIVE() sb << "#line " << (__LINE__+1) << " \"" << path << "\"\n" #include "core.meta.slang.h" -- cgit v1.2.3