summaryrefslogtreecommitdiffstats
path: root/examples/heterogeneous-hello-world/main.cpp
diff options
context:
space:
mode:
authorDietrich Geisler <dag368@cornell.edu>2020-08-17 12:50:44 -0400
committerGitHub <noreply@github.com>2020-08-17 09:50:44 -0700
commitff2d490dc120708a2fcb6eea5880a6b7c6586a4b (patch)
tree4bab7a7353ed5e9149510a48227da029d40d9d97 /examples/heterogeneous-hello-world/main.cpp
parent0640a10ab85f8be3c3c925cb70711560265e6548 (diff)
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 <tfoleyNV@users.noreply.github.com>
Diffstat (limited to 'examples/heterogeneous-hello-world/main.cpp')
-rw-r--r--examples/heterogeneous-hello-world/main.cpp35
1 files changed, 25 insertions, 10 deletions
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<fl
return (gfx_BufferResource_0*)createStructuredBuffer((gfx::Renderer*)_0, (float*)&_1);
}
-gfx_ShaderProgram_0* loadShaderProgram_0(gfx_Renderer_0* _0)
+gfx_ShaderProgram_0* loadShaderProgram_0(gfx_Renderer_0* _0, unsigned char _1[], size_t _2)
{
- return (gfx_ShaderProgram_0*)loadShaderProgram((gfx::Renderer*)_0);
+ return (gfx_ShaderProgram_0*)loadShaderProgram((gfx::Renderer*)_0, _1, _2);
}
gfx_DescriptorSetLayout_0* buildDescriptorSetLayout_0(gfx_Renderer_0* _0)
@@ -322,13 +324,26 @@ void printInitialValues_0(FixedArray<float, 4> _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<float> convertBuffer_0(gfx_BufferResource_0* _0) {
+ RWStructuredBuffer<float> result;
+ result.data = (float*)_0;
+ return result;
+}
+
+gfx_BufferResource_0* unconvertBuffer_0(RWStructuredBuffer<float> _0) {
+ return (gfx_BufferResource_0*)(_0.data);
}
void print_output_0(gfx_Renderer_0* _0, gfx_BufferResource_0* _1, int32_t _2)