From 749634a2a6e03acf435c39f78b933a01b90a7440 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Wed, 17 Jul 2019 10:26:37 -0400 Subject: Slang -> C++ -> SharedLibrary -> Test (#999) * WIP: Adding support for C/C++ compilation to slang API. * Removed BackEndType in test harness -> use SlangPassThrough to identify backends Only require stage for targets that require it. Detection of all different backends. * Windows/Unix create temporary filename. * WIP: Output CPU binaries. * Added a pass-through c/c++ test. * Compile C++/C and store in temporary file. * Read the binary back into memory. * Set debug info and optimization flags for C/C++. Make the CPPCompiler debug/optimization levels match slangs. * Handling of include paths and math precision. * Dumping c++/c source and exe/shared library. * Put hex dump into own util. * End to end pass through c compilation test. * WIP: Simple execute test working on Linux/Unix. * Fix typo on linux. * WIP: To compile slang to cpp shared library. Report backend compiler errors. * Compiles slang -> cpp and loads as shared library. * Fix problem on c-cross-compile test because prelude is now included with <> quotes. * Run slang generated cpp code - using hard coded data. * Added cpp-execute-simple, and test output. * Fix warning that broke win32 build. * Fix compilation problem on osx. --- tests/cross-compile/cpp-execute.slang | 106 ++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 tests/cross-compile/cpp-execute.slang (limited to 'tests/cross-compile/cpp-execute.slang') diff --git a/tests/cross-compile/cpp-execute.slang b/tests/cross-compile/cpp-execute.slang new file mode 100644 index 000000000..1c90c8dd2 --- /dev/null +++ b/tests/cross-compile/cpp-execute.slang @@ -0,0 +1,106 @@ +//TEST:CPU_EXECUTE: -profile cs_5_0 -entry computeMain -target sharedlib + +enum Color +{ + Red, + Green = 2, + Blue, +} + +int test(int val) +{ + Color c = Color.Red; + + if(val > 1) + { + c = Color.Green; + } + + if(c == Color.Red) + { + if(val & 1) + { + c = Color.Blue; + } + } + + switch(c) + { + case Color.Red: + val = 1; + break; + + case Color.Green: + val = 2; + break; + + case Color.Blue: + val = 3; + break; + + default: + val = -1; + break; + } + + return (val << 4) + int(c); +} + +float sum(float a[3]) +{ + float total = a[0]; + for (int i = 1; i < 3; ++i) + { + total += a[i]; + } + return total; +} + +struct Thing +{ + int a; + float b; +}; + +[numthreads(4, 1, 1)] +void computeMain( + uint3 dispatchThreadID : SV_DispatchThreadID, +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):dxbinding(0),glbinding(0),out + RWStructuredBuffer outputBuffer) +{ + uint tid = dispatchThreadID.x; + + Thing thing = { 10, -1.0 }; + + float array[3] = { thing.a, 2, 3}; + + float anotherArray[] = { 1, 2, 5 }; + + array[0] += anotherArray[1]; + + matrix mat = { { sum(array), 1, 2 }, { 3, 4, 5} }; + vector vec = { float(tid + 1), float(tid + 2) }; + + vector vec2 = max(sin(mul(vec, mat)), float3(1, 2, -1)); + vector vec3 = mul(vec, mat); + + float3 vec4 = lerp(vec2, vec3, float3(tid * (1.0f / 4), 1, 1)); + + float3 crossVec = normalize(cross(vec4, vec4)); + + vec2.x = fmod(crossVec.y, crossVec.x); + + vec2 = fmod(vec2, crossVec); + + vec2 += (-vec2.zyx) * 2 + crossVec * length(crossVec) + reflect(vec4, normalize(crossVec)); + + vector z = vec2 > 0; + + int val = (int(tid) + (any(z) ? 1 : 0) + (all(z) ? 2 : 0)) % 100; + + val = asint(asfloat(asuint(asfloat(val)))); + + val = test(val); + + outputBuffer[tid] = val + int(dot(vec2, vec4)); +} \ No newline at end of file -- cgit v1.2.3