From ff2d490dc120708a2fcb6eea5880a6b7c6586a4b Mon Sep 17 00:00:00 2001 From: Dietrich Geisler Date: Mon, 17 Aug 2020 12:50:44 -0400 Subject: GPU Foreach Loop (#1498) * GPU Foreach Loop This PR introduces the completed GPU foreach loop and updates the heterogeneous-hello-world example to use it. This PR builds on the previous introduction of the GPU Foreach loop parsing and semantic checking PR (#1482) by introducing IR lowering and emmitting. THe new feature can be used by having a GPU_Foreach loop interacting with a named non-CPP entry point, and using the -heterogeneous flag. * Fix to path Co-authored-by: Tim Foley --- examples/heterogeneous-hello-world/main.cpp | 35 ++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 10 deletions(-) (limited to 'examples/heterogeneous-hello-world/main.cpp') diff --git a/examples/heterogeneous-hello-world/main.cpp b/examples/heterogeneous-hello-world/main.cpp index 6bb1bc071..6159f8d44 100644 --- a/examples/heterogeneous-hello-world/main.cpp +++ b/examples/heterogeneous-hello-world/main.cpp @@ -66,12 +66,11 @@ bool executeComputation_0(); extern unsigned char __computeMain[]; extern size_t __computeMainSize; -gfx::ShaderProgram* loadShaderProgram(gfx::Renderer* renderer) +gfx::ShaderProgram* loadShaderProgram(gfx::Renderer* renderer, unsigned char computeCode[], size_t computeCodeSize) { // We extract the begin/end pointers to the output code buffers directly // - char unsigned const* computeCode = __computeMain; - char unsigned const* computeCodeEnd = computeCode + __computeMainSize; + char unsigned const* computeCodeEnd = computeCode + computeCodeSize; // Now we use the operations of the example graphics API abstraction // layer to load shader code into the underlying API. @@ -87,7 +86,7 @@ gfx::ShaderProgram* loadShaderProgram(gfx::Renderer* renderer) gfx::ShaderProgram::Desc programDesc; programDesc.pipelineType = gfx::PipelineType::Compute; programDesc.kernels = &kernelDescs[0]; - programDesc.kernelCount = 2; + programDesc.kernelCount = 1; gShaderProgram = renderer->createProgram(programDesc); @@ -242,13 +241,16 @@ void dispatchComputation( gfx::Renderer* gRenderer, gfx::PipelineState* gPipelineState, gfx::PipelineLayout* gPipelineLayout, - gfx::DescriptorSet* gDescriptorSet) + gfx::DescriptorSet* gDescriptorSet, + unsigned int gridDimsX, + unsigned int gridDimsY, + unsigned int gridDimsZ) { gRenderer->setPipelineState(PipelineType::Compute, gPipelineState); gRenderer->setDescriptorSet(PipelineType::Compute, gPipelineLayout, 0, gDescriptorSet); - gRenderer->dispatchCompute(4, 1, 1); + gRenderer->dispatchCompute(gridDimsX, gridDimsY, gridDimsZ); } void print_output( @@ -286,9 +288,9 @@ gfx_BufferResource_0* createStructuredBuffer_0(gfx_Renderer_0* _0, FixedArray _0, int32_t _1) printInitialValues((float*)&_0, _1); } -void dispatchComputation_0(gfx_Renderer_0* _0, gfx_PipelineState_0* _1, gfx_PipelineLayout_0* _2, gfx_DescriptorSet_0* _3) +void dispatchComputation_0(gfx_Renderer_0* _0, gfx_PipelineState_0* _1, gfx_PipelineLayout_0* _2, gfx_DescriptorSet_0* _3, unsigned int gridDimsX, unsigned int gridDimsY, unsigned int gridDimsZ) { dispatchComputation( (gfx::Renderer*)_0, (gfx::PipelineState*)_1, (gfx::PipelineLayout*)_2, - (gfx::DescriptorSet*)_3); + (gfx::DescriptorSet*)_3, + gridDimsX, + gridDimsY, + gridDimsZ); +} + +RWStructuredBuffer convertBuffer_0(gfx_BufferResource_0* _0) { + RWStructuredBuffer result; + result.data = (float*)_0; + return result; +} + +gfx_BufferResource_0* unconvertBuffer_0(RWStructuredBuffer _0) { + return (gfx_BufferResource_0*)(_0.data); } void print_output_0(gfx_Renderer_0* _0, gfx_BufferResource_0* _1, int32_t _2) -- cgit v1.2.3