b;
6 |
7 | [numthreads(3,5,7)]
8 | void main(uint3 tid : SV_DispatchThreadID)
9 | {
10 | b[tid.x] = b[tid.x + 1] + 1.0f;
11 | }
--------------------------------------------------------------------------------
/tests/cross-compile/gl-layer-pick-version.slang:
--------------------------------------------------------------------------------
1 | //TEST_DISABLED:CROSS_COMPILE: -profile ps_5_0 -entry main -target spirv-assembly
2 |
3 | struct VS_OUT
4 | {
5 | nointerpolation uint layerID : SV_RenderTargetArrayIndex;
6 | };
7 |
8 | float4 main(VS_OUT vsOut) : SV_Target
9 | {
10 | return float4(float(vsOut.layerID));
11 | }
12 |
--------------------------------------------------------------------------------
/tests/reflection/explicit-register-space.slang:
--------------------------------------------------------------------------------
1 | // explicit-register-space.slang
2 | //TEST:REFLECTION:-profile ps_5_1 -target hlsl
3 |
4 | // Confirm that we handle explicit register spaces
5 | // on global shader parameters.
6 |
7 | Texture2D tx : register(t1, space2);
8 |
9 | float4 main() : SV_Target
10 | {
11 | return 0.0;
12 | }
--------------------------------------------------------------------------------
/tests/cross-compile/glsl-empty-struct-param-field.slang:
--------------------------------------------------------------------------------
1 | //TEST:CROSS_COMPILE:-target spirv-assembly -entry main -profile ps_5_0
2 |
3 | struct E
4 | {
5 | };
6 |
7 | struct P
8 | {
9 | E em;
10 | float4 param;
11 | };
12 | ParameterBlock pblock;
13 |
14 | float4 main(float4 pos : SV_POSITION)
15 | {
16 | return pblock.param;
17 | }
--------------------------------------------------------------------------------
/tests/diagnostics/command-line/unknown-codegen-target.slang.expected:
--------------------------------------------------------------------------------
1 | result code = 1
2 | standard error = {
3 | (1): error 13: unknown code generation target 'z80'
4 | tests/diagnostics/command-line/unknown-codegen-target.slang -target z80
5 | ^
6 | }
7 | standard output = {
8 | }
9 |
--------------------------------------------------------------------------------
/tests/diagnostics/undefined-in-preprocessor-conditional.slang.expected:
--------------------------------------------------------------------------------
1 | result code = 0
2 | standard error = {
3 | tests/diagnostics/undefined-in-preprocessor-conditional.slang(8): warning 15205: undefined identifier 'BART' in preprocessor expression will evaluate to zero
4 | #if FOO && BART
5 | ^~~~
6 | }
7 | standard output = {
8 | }
9 |
--------------------------------------------------------------------------------
/tests/diagnostics/command-line/pass-through-no-stage.hlsl:
--------------------------------------------------------------------------------
1 | // pass-through-no-stage.hlsl
2 |
3 | // Trying to compile in `-pass-through` mode without
4 | // specifying a stage is an error, because the downstream
5 | // compilers don't support inferring the stage from
6 | // an attribute.
7 |
8 | //DIAGNOSTIC_TEST:SIMPLE:-pass-through fxc -entry main
9 |
--------------------------------------------------------------------------------
/tests/preprocessor/define-redefine.slang.expected:
--------------------------------------------------------------------------------
1 | result code = 0
2 | standard error = {
3 | tests/preprocessor/define-redefine.slang(10): warning 15400: redefinition of macro 'FOO'
4 | #define FOO 2.0f
5 | ^~~
6 | tests/preprocessor/define-redefine.slang(6): note: see previous definition of 'FOO'
7 | }
8 | standard output = {
9 | }
10 |
--------------------------------------------------------------------------------
/tests/preprocessor/preproc-pound-pound-1.slang:
--------------------------------------------------------------------------------
1 | //DIAGNOSTIC_TEST:SIMPLE:-E
2 |
3 | // GCC: :1:9: error: '##' cannot appear at either end of a macro expansion.
4 | // Clang: :1:21: error: '##' cannot appear at start of macro expansion
5 | // Old Slang outputs Hello ## There;
6 | #define POUND_POUND ##
7 |
8 | Hello POUND_POUND There;
9 |
--------------------------------------------------------------------------------
/tests/bindings/glsl-parameter-blocks.slang:
--------------------------------------------------------------------------------
1 | //TEST:CROSS_COMPILE: -profile ps_5_0 -entry main -target spirv-assembly
2 |
3 | struct Test
4 | {
5 | float4 a;
6 | Texture2D t;
7 | SamplerState s;
8 | };
9 |
10 | ParameterBlock gTest;
11 |
12 | float4 main(float2 uv : UV)
13 | {
14 | return gTest.a + gTest.t.Sample(gTest.s, uv);
15 | }
16 |
--------------------------------------------------------------------------------
/tests/bugs/preproc-lex-failure-2.slang.expected:
--------------------------------------------------------------------------------
1 | result code = 0
2 | standard error = {
3 | tests/bugs/preproc-lex-failure-2.slang(4): warning 10002: '0' prefix indicates octal literal
4 | 000
5 | ^~~
6 | tests/bugs/preproc-lex-failure-2.slang(5): error 10005: newline in literal
7 |
8 | ^
9 | }
10 | standard output = {
11 | 000 "Hello!
12 | }
13 |
--------------------------------------------------------------------------------
/tests/cross-compile/sv-coverage.slang.glsl:
--------------------------------------------------------------------------------
1 | // sv-coverage.slang.glsl
2 | #version 450
3 |
4 | layout(location = 0)
5 | out vec4 _S1;
6 |
7 | layout(location = 0)
8 | in vec4 _S2;
9 |
10 | void main()
11 | {
12 | uint _S3 = uint(gl_SampleMaskIn[0]) ^ uint(1);
13 | _S1 = _S2;
14 | gl_SampleMask[0] = int(_S3);
15 | return;
16 | }
17 |
--------------------------------------------------------------------------------
/tests/pipeline/rasterization/conservative-rasterization/inner-coverage.slang:
--------------------------------------------------------------------------------
1 | // inner-coverage.slang
2 |
3 | //TEST:CROSS_COMPILE:-target spirv -entry main -stage fragment
4 |
5 | [shader("fragment")]
6 | void main(
7 | uint innerCoverage : SV_InnerCoverage,
8 | out float4 result : SV_Target)
9 | {
10 | result = innerCoverage;
11 | }
12 |
--------------------------------------------------------------------------------
/tests/rewriter/varying-struct.slang:
--------------------------------------------------------------------------------
1 | //TEST_IGNORE_FILE:
2 |
3 | struct VS_IN
4 | {
5 | float4 x : X;
6 | float4 y : Y;
7 | };
8 |
9 | struct VS_OUT
10 | {
11 | float4 color : COLOR;
12 | float4 posH : SV_Position;
13 | };
14 |
15 | VS_OUT doIt(VS_IN i)
16 | {
17 | VS_OUT o;
18 | o.color = i.x;
19 | o.posH = i.y;
20 | return o;
21 | }
22 |
--------------------------------------------------------------------------------
/tools/render-test/png-serialize-util.h:
--------------------------------------------------------------------------------
1 | // png-serialize-util.h
2 | #pragma once
3 |
4 | #include "core/slang-blob.h"
5 |
6 | namespace renderer_test {
7 |
8 | struct PngSerializeUtil
9 | {
10 | static Slang::Result write(const char* filename, ISlangBlob* pixels, uint32_t width, uint32_t height);
11 |
12 | };
13 |
14 | } // renderer_test
15 |
--------------------------------------------------------------------------------
/source/slang/slang-ir-entry-point-raw-ptr-params.h:
--------------------------------------------------------------------------------
1 | // slang-ir-entry-point-raw-ptr-params.h
2 | #pragma once
3 |
4 | namespace Slang
5 | {
6 | struct IRModule;
7 |
8 | /// Convert any entry-point parameters that use pointer types to use raw pointers (`void*`)
9 | void convertEntryPointPtrParamsToRawPtrs(
10 | IRModule* module);
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/source/slang/slang-value-reflect.h:
--------------------------------------------------------------------------------
1 | // slang-value-reflect.h
2 |
3 | #ifndef SLANG_VALUE_REFLECT_H
4 | #define SLANG_VALUE_REFLECT_H
5 |
6 | #include "slang-generated-value.h"
7 | #include "slang-generated-value-macro.h"
8 |
9 | // Create the functions to automatically convert between value types
10 |
11 |
12 |
13 | #endif // SLANG_VALUE_REFLECT_H
14 |
--------------------------------------------------------------------------------
/tests/cross-compile/c-simple.slang:
--------------------------------------------------------------------------------
1 | //DISABLE_TEST:SIMPLE: -profile ps_5_0 -entry main -target c
2 |
3 | //Texture2D t;
4 | //SamplerState s;
5 |
6 | float4 main(float2 uv) : SV_Target
7 | {
8 | float4 result = 1;
9 |
10 | result.x += uv.x;
11 | result.y += uv.y;
12 | result.z -= uv.x;
13 | result.w -= uv.y;
14 |
15 | return result;
16 | }
17 |
--------------------------------------------------------------------------------
/tests/diagnostics/entry-point-stage-mismatch.slang.expected:
--------------------------------------------------------------------------------
1 | result code = 0
2 | standard error = {
3 | tests/diagnostics/entry-point-stage-mismatch.slang(9): warning 38006: entry point 'main' being compiled for the 'vertex' stage has a '[shader(...)]' attribute that specifies the 'compute' stage
4 | void main()
5 | ^~~~
6 | }
7 | standard output = {
8 | }
9 |
--------------------------------------------------------------------------------
/tests/pipeline/rasterization/conservative-rasterization/inner-coverage.slang.glsl:
--------------------------------------------------------------------------------
1 | #version 450
2 |
3 | #extension GL_NV_conservative_raster_underestimation : require
4 |
5 | layout(location = 0)
6 | out vec4 _S1;
7 |
8 | void main()
9 | {
10 | vec4 _S2;
11 | _S2 = vec4(uint(gl_FragFullyCoveredNV));
12 | _S1 = _S2;
13 | return;
14 | }
15 |
--------------------------------------------------------------------------------
/tests/preprocessor/special-macro-redefine-function.slang.expected:
--------------------------------------------------------------------------------
1 | result code = 0
2 | standard error = {
3 | tests/preprocessor/special-macro-redefine-function.slang(7): warning 15404: Redefinition of builtin macro '__FILE__'
4 | #define __FILE__(x) "Is" x
5 | ^~~~~~~~
6 | }
7 | standard output = {
8 | "Is" "Anybody" "Is" There __FILE__
9 | }
10 |
--------------------------------------------------------------------------------
/tests/reflection/reflect-imported-code.slang:
--------------------------------------------------------------------------------
1 | //TEST_IGNORE_FILE:
2 |
3 | // Imported code used by `reflect-imported-code.hlsl`
4 |
5 | float4 use(float4 val) { return val; };
6 | float4 use(Texture2D t, SamplerState s) { return t.Sample(s, 0.0); }
7 |
8 | Texture2D t_i;
9 | SamplerState s_i;
10 |
11 | cbuffer C_i
12 | {
13 | float c_i;
14 | }
15 |
--------------------------------------------------------------------------------
/tests/diagnostics/command-line/option-missing-argument.slang.expected:
--------------------------------------------------------------------------------
1 | result code = 1
2 | standard error = {
3 | (1): error 13: unknown code generation target '-profile'
4 | tests/diagnostics/command-line/option-missing-argument.slang -target -profile ps_4_0
5 | ^
6 | }
7 | standard output = {
8 | }
9 |
--------------------------------------------------------------------------------
/tests/preprocessor/line.slang:
--------------------------------------------------------------------------------
1 | //TEST:SIMPLE:
2 | // #line support
3 |
4 | FooA a() { return 0; }
5 |
6 | #line 99 "b.slang"
7 | FooB b() { return 0; }
8 |
9 | #line default
10 | FooC c() { return 0; }
11 |
12 | #line 603 "d.slang"
13 | FooD d() { return 0; }
14 |
15 | #line 40
16 | FooE e() { return 0; }
17 |
18 | #line
19 | FooF f() { return 0; }
20 |
--------------------------------------------------------------------------------
/tests/preprocessor/preproc-concat-3.slang.expected:
--------------------------------------------------------------------------------
1 | result code = 0
2 | standard error = {
3 | tests/preprocessor/preproc-concat-3.slang(5): warning 15503: toking pasting with '##' resulted in the invalid token ')CONCAT'
4 | #define CONCAT(a, b) a ## b
5 | ^~
6 | }
7 | standard output = {
8 | CONCAT ( a , a ) CONCAT ( b , b ) ;
9 | }
10 |
--------------------------------------------------------------------------------
/tests/preprocessor/preproc-detail-3.slang:
--------------------------------------------------------------------------------
1 | //DIAGNOSTIC_TEST:SIMPLE:-E
2 |
3 | // Undefining a macro that is not defined within C/C++ is defined as *not* an error or a warning.
4 | // On checking with DXC/FXC they also have this behavior (ie they don't output anything)
5 | // It's arguable if Slang should match this behavior - at least it is a warning.
6 |
7 | #undef C
--------------------------------------------------------------------------------
/external/spirv-tools-generated/spv-amd-gcn-shader.insts.inc:
--------------------------------------------------------------------------------
1 |
2 |
3 | static const spv_ext_inst_desc_t spv_amd_gcn_shader_entries[] = {
4 | {"CubeFaceIndexAMD", 1, 0, nullptr, {SPV_OPERAND_TYPE_ID, SPV_OPERAND_TYPE_NONE}},
5 | {"CubeFaceCoordAMD", 2, 0, nullptr, {SPV_OPERAND_TYPE_ID, SPV_OPERAND_TYPE_NONE}},
6 | {"TimeAMD", 3, 0, nullptr, {SPV_OPERAND_TYPE_NONE}}
7 | };
--------------------------------------------------------------------------------
/source/slang/slang-ir-bind-existentials.h:
--------------------------------------------------------------------------------
1 | // slang-ir-bind-existentials.h
2 | #pragma once
3 |
4 | namespace Slang
5 | {
6 |
7 | class DiagnosticSink;
8 | struct IRModule;
9 |
10 | /// Bind concrete types to paameters that use existential slots.
11 | void bindExistentialSlots(
12 | IRModule* module,
13 | DiagnosticSink* sink);
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/source/slang/slang-ir-lower-existential.h:
--------------------------------------------------------------------------------
1 | // slang-ir-lower-existential.h
2 | #pragma once
3 |
4 | namespace Slang
5 | {
6 | struct SharedGenericsLoweringContext;
7 |
8 | /// Lower existential types and related instructions to Tuple types.
9 | void lowerExistentials(
10 | SharedGenericsLoweringContext* sharedContext);
11 |
12 | }
13 |
14 |
--------------------------------------------------------------------------------
/tests/preprocessor/repeated-macro-expansion.slang:
--------------------------------------------------------------------------------
1 | // macro-expansion.slang
2 | //
3 | //TEST:SIMPLE:
4 |
5 | // Test a bug where macro expansion isn't being
6 | // triggered for back-to-back uses of a function-like
7 | // macro.
8 |
9 | #define IGNORE(THING) /* empty */
10 |
11 | void test()
12 | {
13 | IGNORE(badStuff)
14 | IGNORE(moreBad)
15 | ;
16 | }
17 |
--------------------------------------------------------------------------------
/tests/diagnostics/command-line/entry-point-redundant-stage.slang.expected:
--------------------------------------------------------------------------------
1 | result code = -1
2 | standard error = {
3 | (0): warning 30: the stage 'vertex' was specified more than once for entry point 'main'
4 | tests/diagnostics/command-line/entry-point-redundant-stage.slang(6): error 38000: no function found matching entry point name 'main'
5 | }
6 | standard output = {
7 | }
8 |
--------------------------------------------------------------------------------
/tests/diagnostics/command-line/explicit-implicit-stage-mismatch.vert.expected:
--------------------------------------------------------------------------------
1 | result code = -1
2 | standard error = {
3 | (0): warning 32: the stage specified for entry point 'main' ('pixel') does not match the stage implied by the source file name ('vertex')
4 | (0): error 11: the Slang compiler does not support GLSL as a source language
5 | }
6 | standard output = {
7 | }
8 |
--------------------------------------------------------------------------------
/tests/diagnostics/command-line/unknown-pass-through-target.slang.expected:
--------------------------------------------------------------------------------
1 | result code = 1
2 | standard error = {
3 | (1): error 16: unknown pass-through target 'subcon'
4 | tests/diagnostics/command-line/unknown-pass-through-target.slang -pass-through subcon
5 | ^
6 | }
7 | standard output = {
8 | }
9 |
--------------------------------------------------------------------------------
/source/slang/slang-ir-lower-tuple-types.h:
--------------------------------------------------------------------------------
1 | // slang-ir-lower-tuple-types.h
2 | #pragma once
3 |
4 | #include "slang-ir.h"
5 |
6 | namespace Slang
7 | {
8 | struct IRModule;
9 | class DiagnosticSink;
10 |
11 | /// Lower tuple types to ordinary `struct`s.
12 | void lowerTuples(
13 | IRModule* module,
14 | DiagnosticSink* sink);
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/tests/cross-compile/early-depth-stencil.hlsl.glsl:
--------------------------------------------------------------------------------
1 | //TEST_IGNORE_FILE:
2 | #version 450
3 | layout(row_major) uniform;
4 | layout(row_major) buffer;
5 |
6 | #line 5 0
7 | layout(location = 0)
8 | out vec4 _S1;
9 |
10 | #line 5
11 | layout(early_fragment_tests) in;
12 | void main()
13 | {
14 | _S1 = vec4(float(1), float(0), float(0), float(1));
15 | return;
16 | }
17 |
--------------------------------------------------------------------------------
/tests/cross-compile/matrix-mult.slang:
--------------------------------------------------------------------------------
1 | //TEST_DISABLED:CROSS_COMPILE: -profile ps_5_0 -entry main -target spirv-assembly
2 |
3 | // Confirm that order of arguments to matrix-vector
4 | // multiplication gets reversed when generating GLSL.
5 |
6 | cbuffer C
7 | {
8 | float4x3 m;
9 | };
10 |
11 | float4 main(float3 v) : SV_Target
12 | {
13 | return mul(m, v);
14 | }
15 |
--------------------------------------------------------------------------------
/tests/cross-compile/sv-coverage.slang:
--------------------------------------------------------------------------------
1 | // sv-coverage.slang
2 |
3 | //TEST:CROSS_COMPILE:-target spirv-assembly -entry main -stage fragment
4 |
5 | float4 main(
6 | in float4 color : COLOR,
7 | in uint inputCoverage : SV_Coverage,
8 | out uint outputCoverage : SV_Coverage)
9 | : SV_Target
10 | {
11 | outputCoverage = inputCoverage ^ 1;
12 | return color;
13 | }
14 |
--------------------------------------------------------------------------------
/tests/diagnostics/accessors.slang:
--------------------------------------------------------------------------------
1 | // properties.slang
2 |
3 | // Diagnostic messages related to property/subscript accessor declarations.
4 |
5 | //DIAGNOSTIC_TEST:SIMPLE:
6 |
7 | struct Test
8 | {
9 | property p : int
10 | {
11 | get(a) { return 0; }
12 |
13 | set(a, b) { }
14 | }
15 |
16 | property q : float
17 | {
18 | set(c : int) { }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/tests/diagnostics/command-line/entry-point-redundant-stage.slang.1.expected:
--------------------------------------------------------------------------------
1 | result code = -1
2 | standard error = {
3 | (0): warning 30: the stage 'vertex' was specified more than once for entry point 'vsMain'
4 | tests/diagnostics/command-line/entry-point-redundant-stage.slang(6): error 38000: no function found matching entry point name 'vsMain'
5 | }
6 | standard output = {
7 | }
8 |
--------------------------------------------------------------------------------
/tests/diagnostics/entry-point-no-stage.slang.expected:
--------------------------------------------------------------------------------
1 | result code = -1
2 | standard error = {
3 | tests/diagnostics/entry-point-no-stage.slang(9): error 38007: no stage specified for entry point 'main'; use either a '[shader("name")]' function attribute or the '-stage ' command-line option to specify a stage
4 | void main()
5 | ^~~~
6 | }
7 | standard output = {
8 | }
9 |
--------------------------------------------------------------------------------
/tests/language-feature/extensions/extension-import.slang:
--------------------------------------------------------------------------------
1 | // extension-import.slang
2 |
3 | // Confirm that visibility of extensions through `import` is working.
4 |
5 | //TEST:SIMPLE:
6 |
7 | import extension_import_helper;
8 |
9 | float test(T value)
10 | {
11 | return value.getValue();
12 | }
13 |
14 | float id(float x)
15 | {
16 | return test(x);
17 | }
--------------------------------------------------------------------------------
/tests/cross-compile/rw-buffer.slang:
--------------------------------------------------------------------------------
1 | // rw-buffer.slang
2 |
3 | // Confirm that writing into a `RWBuffer` generates appropriate GLSL/SPIR-V.
4 |
5 | //TEST:CROSS_COMPILE: -profile ps_5_0 -entry main -target spirv-assembly
6 |
7 | RWBuffer buffer;
8 |
9 |
10 | float4 main(float u : U, int idx : IDX) : SV_Target
11 | {
12 | buffer[idx] = u;
13 | return u;
14 | }
15 |
--------------------------------------------------------------------------------
/tests/diagnostics/single-target-intrinsic.slang.expected:
--------------------------------------------------------------------------------
1 | result code = -1
2 | standard error = {
3 | tests/diagnostics/single-target-intrinsic.slang(13): error 30201: function 'doThing' already has a body
4 | T doThing(T in);
5 | ^~~~~~~
6 | tests/diagnostics/single-target-intrinsic.slang(10): note: see previous definition of 'doThing'
7 | }
8 | standard output = {
9 | }
10 |
--------------------------------------------------------------------------------
/tools/slang-cpp-extractor/diagnostics.cpp:
--------------------------------------------------------------------------------
1 | #include "diagnostics.h"
2 |
3 | namespace CppExtract {
4 |
5 | namespace CPPDiagnostics
6 | {
7 | using namespace Slang;
8 |
9 | #define DIAGNOSTIC(id, severity, name, messageFormat) const DiagnosticInfo name = { id, Severity::severity, #name, messageFormat };
10 | #include "diagnostic-defs.h"
11 | }
12 |
13 | } // namespace CppExtract
14 |
--------------------------------------------------------------------------------
/examples/hello-world/hello-world.slang:
--------------------------------------------------------------------------------
1 | // hello-world.slang
2 | StructuredBuffer buffer0;
3 | StructuredBuffer buffer1;
4 | RWStructuredBuffer result;
5 |
6 | [shader("compute")]
7 | [numthreads(1,1,1)]
8 | void computeMain(uint3 threadId : SV_DispatchThreadID)
9 | {
10 | uint index = threadId.x;
11 | result[index] = buffer0[index] + buffer1[index];
12 | }
13 |
--------------------------------------------------------------------------------
/tests/cross-compile/fxc-error.hlsl:
--------------------------------------------------------------------------------
1 | //TEST(fxc):SIMPLE:-pass-through fxc -target dxbc -entry computeMain -stage compute -profile sm_5_1
2 |
3 | [numthreads(4, 1, 1)]
4 | void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
5 | {
6 | uint tid = dispatchThreadID.x;
7 | // Error should be here... as gOutputBuffer is not defined...
8 | gOutputBuffer[tid] = dispatchThreadID.x * 0.5f;
9 | }
--------------------------------------------------------------------------------
/tests/diagnostics/overlapping-bindings.slang.expected:
--------------------------------------------------------------------------------
1 | result code = 0
2 | standard error = {
3 | tests/diagnostics/overlapping-bindings.slang(9): warning 39001: explicit binding for parameter 'b' overlaps with parameter 'a'
4 | Texture2D b : register(t0);
5 | ^
6 | tests/diagnostics/overlapping-bindings.slang(7): note: see declaration of 'a'
7 | }
8 | standard output = {
9 | }
10 |
--------------------------------------------------------------------------------
/source/core/slang-basic.h:
--------------------------------------------------------------------------------
1 | #ifndef SLANG_CORE_BASIC_H
2 | #define SLANG_CORE_BASIC_H
3 |
4 | #include "slang-common.h"
5 | #include "slang-math.h"
6 | #include "slang-string.h"
7 | #include "slang-array.h"
8 | #include "slang-list.h"
9 | #include "slang-short-list.h"
10 | #include "slang-smart-pointer.h"
11 | #include "slang-exception.h"
12 | #include "slang-dictionary.h"
13 |
14 | #endif
15 |
--------------------------------------------------------------------------------
/tests/bugs/gh-449.slang.expected:
--------------------------------------------------------------------------------
1 | result code = -1
2 | standard error = {
3 | tests/bugs/gh-449.slang(18): error 30019: expected an expression of type 'S', got 'vector'
4 | foo(a + b);
5 | ^
6 | tests/bugs/gh-449.slang(24): error 30019: expected an expression of type 'S', got 'vector'
7 | foo(u + f);
8 | ^
9 | }
10 | standard output = {
11 | }
12 |
--------------------------------------------------------------------------------
/tests/diagnostics/command-line/unknown-line-directive-mode.slang.expected:
--------------------------------------------------------------------------------
1 | result code = 1
2 | standard error = {
3 | (1): error 24: unknown '#line' directive mode 'quizzical'
4 | tests/diagnostics/command-line/unknown-line-directive-mode.slang -line-directive-mode quizzical
5 | ^
6 | }
7 | standard output = {
8 | }
9 |
--------------------------------------------------------------------------------
/tests/parser/incomplete-member-decl.slang.expected:
--------------------------------------------------------------------------------
1 | result code = -1
2 | standard error = {
3 | tests/parser/incomplete-member-decl.slang(19): error 20001: unexpected identifier, expected '('
4 | int MyType inner;
5 | ^~~~~
6 | tests/parser/incomplete-member-decl.slang(20): error 20001: unexpected end of file, expected identifier
7 | }
8 | standard output = {
9 | }
10 |
--------------------------------------------------------------------------------
/tests/reflection/sample-index-input.hlsl:
--------------------------------------------------------------------------------
1 | //TEST:REFLECTION:-profile ps_5_0 -target hlsl
2 |
3 | // Confirm that we register a shader as sample-rate when
4 | // it declares `SV_SampleIndex` as an input.
5 |
6 | struct PSInput
7 | {
8 | float4 color : COLOR;
9 | uint sampleIndex : SV_SampleIndex;
10 | };
11 |
12 | float4 main(PSInput input) : SV_Target
13 | {
14 | return input.color;
15 | }
--------------------------------------------------------------------------------
/tests/serialization/extern/module-a.slang:
--------------------------------------------------------------------------------
1 | //TEST_IGNORE_FILE:
2 |
3 | // module-a.slang
4 |
5 | struct Thing
6 | {
7 | int a;
8 | int b;
9 | };
10 |
11 | Thing makeThing(int a, int b)
12 | {
13 | Thing thing;
14 | thing.a = a;
15 | thing.b = b;
16 | return thing;
17 | }
18 |
19 | int foo(Thing thing)
20 | {
21 | return thing.a + thing.b * 2;
22 | }
23 |
24 |
--------------------------------------------------------------------------------
/docs/language-reference/03-preprocessor.md:
--------------------------------------------------------------------------------
1 | Preprocessor
2 | ============
3 |
4 | Slang supports a C-style preprocessor with the following directives:
5 |
6 | * `#include`
7 | * `#define`
8 | * `#undef`
9 | * `#if`, `#ifdef`, `#ifndef`
10 | * `#else`, `#elif`
11 | * `#endif`
12 | * `#error`
13 | * `#warning`
14 | * `#line`
15 | * `#pragma`
16 |
17 | > Note: This section is not yet complete.
18 |
--------------------------------------------------------------------------------
/tests/cross-compile/precise-keyword.slang.hlsl:
--------------------------------------------------------------------------------
1 | // precise-keyword.slang.hlsl
2 | //TEST_IGNORE_FILE:
3 |
4 | float4 main(float2 v_0 : V) : SV_TARGET
5 | {
6 | precise float z_0;
7 |
8 | if(v_0.x > (float) 0)
9 | {
10 | z_0 = v_0.x * v_0.y + v_0.x;
11 | }
12 | else
13 | {
14 | z_0 = v_0.y * v_0.x + v_0.y;
15 | }
16 |
17 | return (float4) z_0;
18 | }
--------------------------------------------------------------------------------
/tests/diagnostics/command-line/stage-ignored.slang:
--------------------------------------------------------------------------------
1 | // stage-ignored.slang
2 |
3 | // Cases where a `-stage` option gets ignored
4 | // because it doesn't apply to any entry point.
5 |
6 | // A `-stage` option before any `-entry`, possibly because
7 | // the user is specifying things in the wrong order.
8 | //
9 | //DIAGNOSTIC_TEST:SIMPLE:-stage vertex -entry vsMain -stage fragment -entry psMain
10 |
--------------------------------------------------------------------------------
/tests/reflection/global-uniforms.hlsl:
--------------------------------------------------------------------------------
1 | //TEST_IGNORE_FILE
2 | //TEST:REFLECTION:-profile ps_4_0 -target hlsl
3 |
4 | // Confirm that we handle uniforms at global scope
5 |
6 |
7 | float4 u;
8 |
9 | Texture2D t;
10 | SamplerState s;
11 |
12 | cbuffer CB
13 | {
14 | float4 v;
15 | }
16 |
17 | float4 w;
18 |
19 | float4 main() : SV_Target
20 | {
21 | return u + v + w + t.Sample(s, u.xy);
22 | }
--------------------------------------------------------------------------------
/tests/serialization/extern/module-b.slang:
--------------------------------------------------------------------------------
1 | //TEST_IGNORE_FILE:
2 |
3 | // module-b.slang
4 |
5 | // This looks like a definition (and it is) but with [__extern] it's definition will be replaced at link time with a defintion
6 | [__extern] struct Thing {};
7 | [__extern] int foo(Thing thing);
8 |
9 | int doSomething(Thing a, Thing b)
10 | {
11 | return foo(a) + foo(b);
12 | }
13 |
14 |
15 |
--------------------------------------------------------------------------------
/tests/cross-compile/dxc-error.hlsl:
--------------------------------------------------------------------------------
1 | //DIAGNOSTIC_TEST(dxc):SIMPLE:-pass-through dxc -target dxil -entry computeMain -stage compute -profile sm_6_1
2 |
3 | [numthreads(4, 1, 1)]
4 | void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
5 | {
6 | uint tid = dispatchThreadID.x;
7 | // Error should be here... as gOutputBuffer is not defined...
8 | gOutputBuffer[tid] = dispatchThreadID.x * 0.5f;
9 | }
--------------------------------------------------------------------------------
/tests/cross-compile/sign.slang:
--------------------------------------------------------------------------------
1 | // sign.slang
2 |
3 | //TEST:CROSS_COMPILE:-target spirv-assembly -entry main -stage fragment
4 | //TEST:CROSS_COMPILE:-target dxil-assembly -entry main -stage fragment -profile sm_6_0
5 |
6 | // Test cross compilation of the sign function
7 |
8 | float4 main() : SV_Target
9 | {
10 | float4 s = sign(float4(1.5, 1.0, -1.5, -1.0));
11 | return s;
12 | }
13 |
14 |
--------------------------------------------------------------------------------
/tests/diagnostics/single-target-intrinsic.slang:
--------------------------------------------------------------------------------
1 | //DIAGNOSTIC_TEST(windows):SIMPLE:
2 |
3 |
4 | T doThing(T in)
5 | {
6 | return in;
7 | }
8 |
9 | __target_intrinsic(hlsl, "doSomethingIntrinsically($0)")
10 | T doThing(T in);
11 |
12 | __target_intrinsic(hlsl, "letsRedefineIt($0)")
13 | T doThing(T in);
14 |
15 | void test()
16 | {
17 | int a = 5;
18 | int b = doThing(a);
19 | }
--------------------------------------------------------------------------------
/tests/preprocessor/include-search-path.slang:
--------------------------------------------------------------------------------
1 | //TEST:SIMPLE: -Itests/preprocessor/include
2 | // #include support
3 |
4 | int foo() { return 0; }
5 |
6 | #include "pragma-once-c.h"
7 |
8 | // If include worked this will be defined
9 | #ifndef ONLY_DEFINED_ONCE_C
10 | // And so hitting this indicates and error (and will fail as bar isn't defined)
11 | int baz() { return bar(); }
12 | #endif
13 |
14 |
--------------------------------------------------------------------------------
/tests/rewriter/gh-160.hlsl:
--------------------------------------------------------------------------------
1 | // Disabled because Slang should give the error, not downstream compiler
2 | //TEST_IGNORE_FILE
3 | //TEST:COMPARE_HLSL: -profile ps_4_0 -entry main
4 |
5 | #ifdef __SLANG__
6 | __import gh_160;
7 | #endif
8 |
9 | vec4 main(VS_OUT vOut) : SV_TARGET
10 | {
11 | float3 color = float3(1,0,0);
12 |
13 | vec4 finalColor = vec4(color, 1.f);
14 | return finalColor;
15 | }
--------------------------------------------------------------------------------
/tests/diagnostics/gh-38-vs.hlsl:
--------------------------------------------------------------------------------
1 | //DIAGNOSTIC_TEST:SIMPLE: -profile sm_5_0 -entry main -stage vertex tests/diagnostics/gh-38-fs.hlsl -entry main -stage fragment -no-codegen
2 |
3 | // Ensure that we catch errors with overlapping or conflicting parameter bindings.
4 |
5 | Texture2D overlappingA : register(t0);
6 |
7 | Texture2D conflicting : register(t1);
8 |
9 | float4 main() : SV_Position { return 0; }
10 |
--------------------------------------------------------------------------------
/tests/diagnostics/gh-38-vs.hlsl.expected:
--------------------------------------------------------------------------------
1 | result code = 0
2 | standard error = {
3 | tests/diagnostics/gh-38-fs.hlsl(5): warning 39001: explicit binding for parameter 'overlappingB' overlaps with parameter 'overlappingA'
4 | Texture2D overlappingB : register(t0);
5 | ^~~~~~~~~~~~
6 | tests/diagnostics/gh-38-vs.hlsl(5): note: see declaration of 'overlappingA'
7 | }
8 | standard output = {
9 | }
10 |
--------------------------------------------------------------------------------
/tests/preprocessor/define-function-like.slang.expected:
--------------------------------------------------------------------------------
1 | result code = -1
2 | standard error = {
3 | tests/preprocessor/define-function-like.slang(16): error 30015: undefined identifier 'x'.
4 | #define M (x) - (x)
5 | ^
6 | tests/preprocessor/define-function-like.slang(16): error 30015: undefined identifier 'x'.
7 | #define M (x) - (x)
8 | ^
9 | }
10 | standard output = {
11 | }
12 |
--------------------------------------------------------------------------------
/source/slang/slang-ir-lower-generic-call.h:
--------------------------------------------------------------------------------
1 | // slang-ir-lower-generic-call.h
2 | #pragma once
3 |
4 | namespace Slang
5 | {
6 | struct SharedGenericsLoweringContext;
7 |
8 | /// Lower generic and interface-based code to ordinary types and functions using
9 | /// dynamic dispatch mechanisms.
10 | void lowerGenericCalls(
11 | SharedGenericsLoweringContext* sharedContext);
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/tests/diagnostics/x-macro-line-continuation.slang:
--------------------------------------------------------------------------------
1 | // x-macro-line-continuation.slang
2 | //TEST:SIMPLE:
3 |
4 | // Tests line continuations on diagnostic output of macros
5 |
6 | #define X(M) \
7 | M(0) \
8 | M(1) \
9 | M(2) \
10 | M(3) \
11 | M(4, 4) \
12 | M(5) \
13 | M(6) \
14 | M(7)
15 |
16 | #define A(x) + x + x + x
17 |
18 | int sum()
19 | {
20 | return X(A);
21 | }
22 |
--------------------------------------------------------------------------------
/tests/doc/doc-req.slang.expected:
--------------------------------------------------------------------------------
1 | result code = 0
2 | standard error = {
3 | --------------------------------------------------------------------------------
4 | # `doThing`
5 |
6 | ## Signature
7 |
8 | ```
9 | void doThing();
10 | ```
11 |
12 | ## Availability
13 |
14 | **GLSL** `GL_EXT_NiftyExtension`, `SPIR-V 1.3` **HLSL** `NVAPI` **CPP** **CUDA** `SM 2.0`
15 |
16 | }
17 | standard output = {
18 | }
19 |
--------------------------------------------------------------------------------
/tests/hlsl-intrinsic/texture/gather-texture2darray.slang.hlsl:
--------------------------------------------------------------------------------
1 | // gather-texture2darray.slang.hlsl
2 |
3 | //TEST_IGNORE_FILE:
4 |
5 | Texture2DArray t_0;
6 | SamplerState s_0;
7 | RWBuffer b_0;
8 |
9 | // Attribute not understood by fxc
10 | //[shader("compute")]
11 | [numthreads(32, 1, 1)]
12 | void main(uint3 tid : SV_DISPATCHTHREADID)
13 | {
14 | b_0[tid.x] = t_0.Gather(s_0, tid);
15 | }
16 |
--------------------------------------------------------------------------------
/tests/hlsl/simple/compute-numthreads.hlsl:
--------------------------------------------------------------------------------
1 | //TEST:COMPARE_HLSL:-no-mangle -profile cs_5_0 -entry main
2 |
3 | // Confirm that we properly pass along the `numthreads` attribute on an entry point.
4 |
5 | #ifndef __SLANG__
6 | #define b b_0
7 | #endif
8 |
9 | RWStructuredBuffer b;
10 |
11 | [numthreads(32,1,1)]
12 | void main(uint3 tid : SV_DispatchThreadID)
13 | {
14 | b[tid.x] = b[tid.x + 1] + 1.0f;
15 | }
--------------------------------------------------------------------------------
/tests/vkray/callable.slang:
--------------------------------------------------------------------------------
1 | // callable.slang
2 |
3 | //TEST:CROSS_COMPILE: -profile glsl_460+spirv_1_4 -stage callable -entry main -target spirv-assembly
4 |
5 | import callable_shared;
6 |
7 | Texture2D gAlbedoMap;
8 | SamplerState gSampler;
9 |
10 | void main(in out MaterialPayload ioPayload)
11 | {
12 | ioPayload.albedo = gAlbedoMap.SampleLevel(
13 | gSampler,
14 | ioPayload.uv,
15 | 0);
16 | }
17 |
--------------------------------------------------------------------------------
/tests/diagnostics/extension-visibility.slang.expected:
--------------------------------------------------------------------------------
1 | result code = -1
2 | standard error = {
3 | tests/diagnostics/extension-visibility.slang(17): error 39999: could not specialize generic for arguments of type (MyThing)
4 | return helper(thing);
5 | ^
6 | tests/diagnostics/extension-visibility-a.slang(14): note 39999: see declaration of func helper(T) -> int
7 | }
8 | standard output = {
9 | }
10 |
--------------------------------------------------------------------------------
/tests/diagnostics/interface-requirement-not-satisfied.slang.expected:
--------------------------------------------------------------------------------
1 | result code = -1
2 | standard error = {
3 | tests/diagnostics/interface-requirement-not-satisfied.slang(10): error 38100: type 'T' does not provide required interface member 'bar'
4 | struct T : IFoo
5 | ^~~~
6 | tests/diagnostics/interface-requirement-not-satisfied.slang(7): note: see declaration of 'bar'
7 | }
8 | standard output = {
9 | }
10 |
--------------------------------------------------------------------------------
/tests/diagnostics/void-function-returning-value.slang.expected:
--------------------------------------------------------------------------------
1 | result code = -1
2 | standard error = {
3 | tests/diagnostics/void-function-returning-value.slang(16): error 30019: expected an expression of type 'void', got 'int'
4 | return 1;
5 | ^
6 | tests/diagnostics/void-function-returning-value.slang(16): note: explicit conversion from 'int' to 'void' is possible
7 | }
8 | standard output = {
9 | }
10 |
--------------------------------------------------------------------------------
/tests/pipeline/ray-tracing/raygen.slang:
--------------------------------------------------------------------------------
1 | // raygen.slang
2 |
3 | //TEST(optix):COMPARE_COMPUTE_EX:-cuda -rt -output-using-type -compute-dispatch 4,1,1
4 |
5 | //TEST_INPUT:ubuffer(data=[0 0 0 0],stride=4):name gOutput,out
6 |
7 | RWStructuredBuffer gOutput;
8 |
9 | [shader("raygeneration")]
10 | void raygenMain()
11 | {
12 | uint3 tid = DispatchRaysIndex();
13 |
14 | gOutput[tid.x] = tid.x*11;
15 | }
16 |
--------------------------------------------------------------------------------
/tests/preprocessor/if-ignore.slang:
--------------------------------------------------------------------------------
1 | //TEST:SIMPLE:
2 | // Check #if expression is ignored if outer #if/#ifndef means it is skipped
3 |
4 | #if 0
5 | BadThing thatWontCompile;
6 | #if a + b == 27
7 | BadThing thatWontCompile;
8 | #endif
9 | BadThing thatWontCompile;
10 | #endif
11 |
12 | #ifdef SOMETHING_SILLY
13 | BadThing thatWontCompile;
14 | #if SOMETHING_SILLY
15 | BadThing thatWontCompile;
16 | #endif
17 | #endif
18 |
--------------------------------------------------------------------------------
/tests/preprocessor/preproc-concat-3.slang:
--------------------------------------------------------------------------------
1 | //DIAGNOSTIC_TEST:SIMPLE:-E
2 |
3 | #define CONCAT(a, b) a ## b
4 |
5 | #define A a
6 | #define B b
7 |
8 | #define A2 A
9 | #define B2 B
10 |
11 | // Gives error (as trys to concat unexpanded input)
12 | // :11:1: error: pasting formed ')CONCAT', an invalid preprocessing token
13 | //
14 | // Old Slang output: aabb ;
15 |
16 | CONCAT(CONCAT(A2, A2), CONCAT(B2, B2));
17 |
--------------------------------------------------------------------------------
/tests/reflection/sample-rate-input.hlsl:
--------------------------------------------------------------------------------
1 | //TEST:REFLECTION:-profile ps_5_0 -target hlsl
2 |
3 | // Confirm that we register a shader as sample-rate when
4 | // it declares (not necessarly *uses*) a `sample` qualified input
5 |
6 | struct PSInput
7 | {
8 | float4 extra : EXTRA;
9 | sample float4 color : COLOR;
10 | };
11 |
12 | float4 main(PSInput input) : SV_Target
13 | {
14 | return input.extra + input.color;
15 | }
--------------------------------------------------------------------------------
/source/slang/slang-ir-explicit-global-context.h:
--------------------------------------------------------------------------------
1 | // slang-ir-explicit-global-context.h
2 | #pragma once
3 |
4 | #include "slang-compiler.h"
5 |
6 | namespace Slang
7 | {
8 | struct IRModule;
9 |
10 | /// Collect global-scope variables/paramters to form an explicit context that gets threaded through
11 | void introduceExplicitGlobalContext(
12 | IRModule* module,
13 | CodeGenTarget target);
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/tests/bugs/gh-941.slang:
--------------------------------------------------------------------------------
1 | //TEST:CROSS_COMPILE: -profile ps_5_0 -entry main -target spirv-assembly
2 |
3 | // Ensure that we add the `GL_EXT_nonuniform_qualifier` extension for any code that uses unbounded-size arrays of resources.
4 |
5 | Texture2D t[];
6 | SamplerState s;
7 |
8 | cbuffer C
9 | {
10 | float2 uv;
11 | uint index;
12 | }
13 |
14 | float4 main() : SV_Target
15 | {
16 | return t[index].Sample(s, uv);
17 | }
18 |
--------------------------------------------------------------------------------
/tests/cross-compile/sign.slang.glsl:
--------------------------------------------------------------------------------
1 | //TEST_IGNORE_FILE:
2 | #version 450
3 | layout(row_major) uniform;
4 | layout(row_major) buffer;
5 |
6 | #line 8 0
7 | layout(location = 0)
8 | out vec4 _S1;
9 |
10 |
11 | #line 8
12 | void main()
13 | {
14 | ivec4 _S2 = ivec4(sign(vec4(1.50000000000000000000, 1.00000000000000000000, -1.50000000000000000000, -1.00000000000000000000)));
15 | _S1 = vec4(_S2);
16 | return;
17 | }
--------------------------------------------------------------------------------
/tests/diagnostics/parameter-already-defined.slang.expected:
--------------------------------------------------------------------------------
1 | result code = -1
2 | standard error = {
3 | tests/diagnostics/parameter-already-defined.slang(4): error 30200: declaration of 'a' conflicts with existing declaration
4 | int foo( int a, float a ) { return 0; }
5 | ^
6 | tests/diagnostics/parameter-already-defined.slang(4): note: see previous declaration of 'a'
7 | }
8 | standard output = {
9 | }
10 |
--------------------------------------------------------------------------------
/tests/reflection/resource-in-cbuffer.hlsl:
--------------------------------------------------------------------------------
1 | //TEST(smoke):REFLECTION:-profile ps_4_0 -target hlsl
2 |
3 | // Confirm that we can generate reflection
4 | // information for resources nested inside
5 | // a cbuffer:
6 |
7 | cbuffer MyConstantBuffer
8 | {
9 | float3 v;
10 |
11 | Texture2D myTexture;
12 |
13 | float c;
14 |
15 | SamplerState mySampler;
16 | }
17 |
18 | float4 main() : SV_Target
19 | {
20 | return 0.0;
21 | }
--------------------------------------------------------------------------------
/tests/bugs/gh-133.slang:
--------------------------------------------------------------------------------
1 | //TEST_DISABLED:CROSS_COMPILE: -profile ps_5_0 -entry main -target spirv-assembly
2 |
3 | // Ensure that an integer output from
4 | // a fragment shader doesn't get a `flat` qualifier
5 |
6 | struct Fragment
7 | {
8 | uint foo;
9 | };
10 |
11 | cbuffer U
12 | {
13 | uint bar;
14 | }
15 |
16 | Fragment main() : SV_Target
17 | {
18 | Fragment result;
19 | result.foo = bar;
20 | return result;
21 | }
22 |
--------------------------------------------------------------------------------
/tests/bugs/keyword-undefined-identifier.slang.expected:
--------------------------------------------------------------------------------
1 | result code = -1
2 | standard error = {
3 | tests/bugs/keyword-undefined-identifier.slang(29): error 30015: undefined identifier 'instance'.
4 | return instance;
5 | ^~~~~~~~
6 | tests/bugs/keyword-undefined-identifier.slang(34): error 30015: undefined identifier 'triangle'.
7 | return triangle;
8 | ^~~~~~~~
9 | }
10 | standard output = {
11 | }
12 |
--------------------------------------------------------------------------------
/tests/diagnostics/global-uniform.slang:
--------------------------------------------------------------------------------
1 | // global-uniform.slang
2 | //DIAGNOSTIC_TEST:SIMPLE:-target hlsl
3 | //DIAGNOSTIC_TEST:COMMAND_LINE_SIMPLE:-target hlsl
4 |
5 | // An attempt to declare a global variable that actually declares a
6 | // global shader parameter should be diagnosed, unless `uniform` was used.
7 |
8 | uniform float a;
9 |
10 | const uint4 b = uint4(0,1,2,3);
11 |
12 | struct C { float x; int y; };
13 | C c;
14 |
--------------------------------------------------------------------------------
/tests/diagnostics/missing-return.slang.expected:
--------------------------------------------------------------------------------
1 | result code = 0
2 | standard error = {
3 | tests/diagnostics/missing-return.slang(7): warning 41010: control flow may reach end of non-'void' function
4 | int bad(int a, int b)
5 | ^~~
6 | tests/diagnostics/missing-return.slang(14): warning 41010: control flow may reach end of non-'void' function
7 | int alsoBad(int a, int b)
8 | ^~~~~~~
9 | }
10 | standard output = {
11 | }
12 |
--------------------------------------------------------------------------------
/tests/diagnostics/vk-bindings.slang:
--------------------------------------------------------------------------------
1 | // vk-bindings.slang
2 |
3 | //DIAGNOSTIC_TEST:SIMPLE:-target spirv
4 |
5 | // D3D `register` without VK binding
6 | Texture2D t : register(t0);
7 |
8 | [[vk::binding(3)]]
9 | Texture2D t1 : register(t3);
10 |
11 | struct S { float4 a; };
12 |
13 | // Parameter block with non-zero binding:
14 | [[vk::binding(2,1)]]
15 | ParameterBlock b;
16 |
17 | [shader("compute")]
18 | void main()
19 | {}
--------------------------------------------------------------------------------
/tests/preprocessor/if-macro-token-paste.slang:
--------------------------------------------------------------------------------
1 | // if-macro.slang
2 |
3 | //TEST:SIMPLE:
4 |
5 | // Test that a `#if` test can invoke a function-like macro.
6 | //
7 | // Note: this test is a reproducer for a bug reported by a user.
8 |
9 | #define is_valid_TEST 1
10 | #define isValid(name) (is_valid_##name != 0)
11 | int test() {
12 | #if isValid(TEST)
13 | return 1;
14 | #else
15 | return NO_SUCH_SYMBOL;
16 | #endif
17 | }
--------------------------------------------------------------------------------
/source/slang/slang-ir-lower-bit-cast.h:
--------------------------------------------------------------------------------
1 | // slang-ir-lower-bit-cast.h
2 | #pragma once
3 |
4 | // This file defines an IR pass that lowers a BitCast(U) operation, where T and U are struct types,
5 | // into a series of bit-cast operations on basic-typed elements.
6 |
7 | namespace Slang
8 | {
9 |
10 | struct IRModule;
11 | class TargetRequest;
12 |
13 | void lowerBitCast(TargetRequest* targetReq, IRModule* module);
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/tests/reflection/reflection0.hlsl:
--------------------------------------------------------------------------------
1 | //TEST:REFLECTION:-profile ps_4_0 -target hlsl
2 |
3 | // Confirm that basic reflection info can be output
4 |
5 | float4 use(float4 val) { return val; };
6 | float4 use(Texture2D t, SamplerState s) { return t.Sample(s, 0.0); }
7 |
8 | Texture2D t;
9 | SamplerState s;
10 |
11 | cbuffer C
12 | {
13 | float c;
14 | }
15 |
16 | float4 main() : SV_Target
17 | {
18 | return use(t,s) + use(c);
19 | }
--------------------------------------------------------------------------------
/tests/bugs/array-size-static-const.hlsl:
--------------------------------------------------------------------------------
1 | // array-size-static-const.hlsl
2 | //TEST:COMPARE_HLSL: -profile cs_5_0
3 |
4 | // The bug in this case is that were have a (hidden)
5 | // cast from the `uint` constant to `int` to get
6 | // the size of the array, and this cast was tripping
7 | // up the constant-folding logic.
8 |
9 | static const uint n = 16;
10 | groupshared float b[n];
11 |
12 | [numthreads(1,1,1)]
13 | void main()
14 | {}
15 |
--------------------------------------------------------------------------------