diff options
| author | Yong He <yonghe@outlook.com> | 2021-10-21 15:51:18 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-10-21 15:51:18 -0700 |
| commit | 9304c2d04c9bfbae33cc328d404b24aba375aa4f (patch) | |
| tree | 88473d2ca0b03341f84bca17b359ae45c4becfaa /examples | |
| parent | 66e319e34b99eff0a8d27be524ab4a831437ac1b (diff) | |
Diagnostic for no type conformance + bug fix. (#1985)
* Diagnostic for no type conformance + bug fix.
* Fixes.
* Fix.
* Include heterogeneous example only with --enable-experimental-projects premake flag
Co-authored-by: Yong He <yhe@nvidia.com>
Co-authored-by: jsmall-nvidia <jsmall@nvidia.com>
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/heterogeneous-hello-world/shader.cpp | 181 |
1 files changed, 1 insertions, 180 deletions
diff --git a/examples/heterogeneous-hello-world/shader.cpp b/examples/heterogeneous-hello-world/shader.cpp index 3f08af05f..b1fff29f6 100644 --- a/examples/heterogeneous-hello-world/shader.cpp +++ b/examples/heterogeneous-hello-world/shader.cpp @@ -1,180 +1 @@ -#include "../../prelude/slang-cpp-prelude.h" - - -#ifdef SLANG_PRELUDE_NAMESPACE -using namespace SLANG_PRELUDE_NAMESPACE; -#endif - -Vector<uint32_t, 3> operator+(Vector<uint32_t, 3> a, Vector<uint32_t, 3> b) -{ - Vector<uint32_t, 3> r; - r.x = a.x + b.x; - r.y = a.y + b.y; - r.z = a.z + b.z; - return r; -} - -Vector<uint32_t, 3> operator*(Vector<uint32_t, 3> a, Vector<uint32_t, 3> b) -{ - Vector<uint32_t, 3> r; - r.x = a.x * b.x; - r.y = a.y * b.y; - r.z = a.z * b.z; - return r; -} - -Vector<uint32_t, 3> make_VecU3(uint32_t a, uint32_t b, uint32_t c) -{ - return Vector<uint32_t, 3>{ a, b, c}; -} - -void computeMain_wrapper(gfx_Device_0* device, Vector<uint32_t, 3> gridDims, - RWStructuredBuffer<float> buffer) -{ - gfx_ShaderProgram_0* shaderProgram = loadShaderProgram_0(device, "computeMain", "shader"); - gfx_TransientResourceHeap_0* transientHeap = buildTransientHeap_0(device); - gfx_PipelineState_0* pipelineState = buildPipelineState_0(device, shaderProgram); - gfx_ResourceView_0* bufferView = createBufferView_0(device, unconvertBuffer_0(buffer)); - dispatchComputation_0(device, transientHeap, pipelineState, bufferView, gridDims.x, gridDims.y, gridDims.z); -} - -#line 8 "../../../examples/heterogeneous-hello-world/shader.slang" -struct EntryPointParams_0 -{ - RWStructuredBuffer<float> ioBuffer_0; -}; - - -#line 21 -struct gfx_Device_0 -{ -}; - - -#line 22 -struct gfx_BufferResource_0 -{ -}; - - -#line 23 -struct gfx_ResourceView_0 -{ -}; - - -#line 8 -void _computeMain(void* _S1, void* entryPointParams_0, void* _S2) -{ - -#line 8 - ComputeThreadVaryingInput* _S3 = (slang_bit_cast<ComputeThreadVaryingInput*>(_S1)); - - uint32_t tid_0 = (*(&_S3->groupID) * make_VecU3(4U, 1U, 1U) + *(&_S3->groupThreadID)).x; - - float* _S4 = &(*(&(slang_bit_cast<EntryPointParams_0*>(entryPointParams_0))->ioBuffer_0))[tid_0]; - -#line 12 - float i_0 = *_S4; - bool _S5 = i_0 < 0.50000000000000000000f; - -#line 13 - float _S6 = i_0 + i_0; - -#line 13 - float _S7 = (F32_sqrt((i_0))); - -#line 13 - float o_0 = _S5 ? _S6 : _S7; - - float* _S8 = &(*(&(slang_bit_cast<EntryPointParams_0*>(entryPointParams_0))->ioBuffer_0))[tid_0]; - -#line 15 - *_S8 = o_0; - return; -} - - -#line 31 -gfx_Device_0* createDevice_0(); - -gfx_BufferResource_0* createStructuredBuffer_0(gfx_Device_0* _0, FixedArray<float, 4> _1); - - -gfx_ResourceView_0* createBufferView_0(gfx_Device_0* _0, gfx_BufferResource_0* _1); - - -#line 4 -RWStructuredBuffer<float> convertBuffer_0(gfx_BufferResource_0* _0); - - -#line 44 -void printInitialValues_0(FixedArray<float, 4> _0, int32_t _1); - - -#line 50 -bool printOutputValues_0(gfx_Device_0* _0, gfx_BufferResource_0* _1, int32_t _2); - - - - -bool executeComputation_0() -{ - - FixedArray<float, 4> initialArray_0 = { 3.00000000000000000000f, -20.00000000000000000000f, -6.00000000000000000000f, 8.00000000000000000000f }; - - - gfx_Device_0* _S9 = createDevice_0(); - gfx_BufferResource_0* _S10 = createStructuredBuffer_0(_S9, initialArray_0); - gfx_ResourceView_0* _S11 = createBufferView_0(_S9, _S10); - Vector<uint32_t, 3> _S12 = make_VecU3(uint32_t(int(4)), uint32_t(int(1)), uint32_t(int(1))); - RWStructuredBuffer<float> _S13 = convertBuffer_0(_S10); - -#line 64 - computeMain_wrapper(_S9, _S12, _S13); - - printInitialValues_0(initialArray_0, int(4)); - bool _S14 = printOutputValues_0(_S9, _S10, int(4)); - - - return true; -} - -// [numthreads(4, 1, 1)] -SLANG_PRELUDE_EXPORT -void computeMain_Thread(ComputeThreadVaryingInput* varyingInput, void* entryPointParams, void* globalParams) -{ - _computeMain(varyingInput, entryPointParams, globalParams); -} -// [numthreads(4, 1, 1)] -SLANG_PRELUDE_EXPORT -void computeMain_Group(ComputeVaryingInput* varyingInput, void* entryPointParams, void* globalParams) -{ - ComputeThreadVaryingInput threadInput = {}; - threadInput.groupID = varyingInput->startGroupID; - for (uint32_t x = 0; x < 4; ++x) - { - threadInput.groupThreadID.x = x; - _computeMain(&threadInput, entryPointParams, globalParams); - } -} -// [numthreads(4, 1, 1)] -SLANG_PRELUDE_EXPORT -void computeMain(ComputeVaryingInput* varyingInput, void* entryPointParams, void* globalParams) -{ - ComputeVaryingInput vi = *varyingInput; - ComputeVaryingInput groupVaryingInput = {}; - for (uint32_t z = vi.startGroupID.z; z < vi.endGroupID.z; ++z) - { - groupVaryingInput.startGroupID.z = z; - for (uint32_t y = vi.startGroupID.y; y < vi.endGroupID.y; ++y) - { - groupVaryingInput.startGroupID.y = y; - for (uint32_t x = vi.startGroupID.x; x < vi.endGroupID.x; ++x) - { - groupVaryingInput.startGroupID.x = x; - computeMain_Group(&groupVaryingInput, entryPointParams, globalParams); - } - } - } -} +// This is a placeholder. The contents will be generated during build.
\ No newline at end of file |
