diff options
| author | David Siher <32305650+dsiher@users.noreply.github.com> | 2022-02-03 19:16:54 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-02-03 19:16:54 -0800 |
| commit | 5eb835f0332868fd56ac14ce7560e0ae9cfafec9 (patch) | |
| tree | 67ed2ae3b2527e8cfa66f835062490decf3052ad /source/slang/slang-emit-cpp.cpp | |
| parent | 1eda86377847155ed3f0e0b2e40a105af35bd387 (diff) | |
Fixed naming conflicts in heterogeneous-hello-world (#2114)
* Fixed naming conflicts in heterogeneous-hello-world
Added 3 new modifiers (`__unmangled`, `__exportDirectly`, `__externLib`)
`__unmangled` causes mangleName() to return the normal name of the decl.
`__exportDirectly` changes parent decl name concatenation behavior to use
"::" instead of "." (for Name Hint) and emits the name hint when it exists,
otherwise it emits the mangled name.
`__externLib` stops Slang from emitting the corresponding struct.
Also made necessary changes to heterogeneous-hello-world so that this new
functionality is shown off.
* Undo unintentional formatting changes
Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'source/slang/slang-emit-cpp.cpp')
| -rw-r--r-- | source/slang/slang-emit-cpp.cpp | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/source/slang/slang-emit-cpp.cpp b/source/slang/slang-emit-cpp.cpp index cb6c210be..e06aa8372 100644 --- a/source/slang/slang-emit-cpp.cpp +++ b/source/slang/slang-emit-cpp.cpp @@ -2709,26 +2709,43 @@ void CPPSourceEmitter::emitModuleImpl(IRModule* module, DiagnosticSink* sink) } } } + // Hardcode in (for now) an include for slang-gfx.h so that we can make use + // of the gfx namespace + // + // TODO: Aside from making sure this approach is viable, it would also be + // much better to allow this to be done by the programmer in the Slang file. + m_writer->emit("#include \"slang-gfx.h\"\n\n"); + + // Emit boilerplate that requires gfx. + // This is required by the wrapper, so that will be the next place to look + // as far as removing boilerplate goes. + m_writer->emit("gfx::IShaderProgram* loadShaderProgram(gfx::IDevice* _0, char* _1, char* _2);\n"); + m_writer->emit("gfx::ITransientResourceHeap* buildTransientHeap(gfx::IDevice* _0);\n"); + m_writer->emit("gfx::IPipelineState* buildPipelineState(gfx::IDevice* _0, gfx::IShaderProgram* _1);\n"); + m_writer->emit("void dispatchComputation(gfx::IDevice* _0, gfx::ITransientResourceHeap* _1, gfx::IPipelineState* _2, gfx::IResourceView* _3, uint32_t gridDimsX, uint32_t gridDimsY, uint32_t gridDimsZ);\n"); + m_writer->emit("gfx::IResourceView* createBufferView(gfx::IDevice* _0, gfx::IBufferResource* _1);\n"); + m_writer->emit("gfx::IBufferResource* unconvertBuffer(RWStructuredBuffer<float> _0);\n\n"); + // Emit a wrapper function for calling the shader blob m_writer->emit("void "); m_writer->emit(entryPointName); - m_writer->emit("_wrapper(gfx_Device_0* device, Vector<uint32_t, 3> gridDims, \n"); + m_writer->emit("_wrapper(gfx::IDevice* device, Vector<uint32_t, 3> gridDims, \n"); m_writer->emit("\tRWStructuredBuffer<float> buffer)\n{"); /* m_writer->emit("\n\tgfx_ShaderProgram_0* shaderProgram = loadShaderProgram_0(device, __"); m_writer->emit(entryPointName); m_writer->emit(", __"); m_writer->emit(entryPointName); m_writer->emit("Size);");*/ - m_writer->emit("\n\tgfx_ShaderProgram_0* shaderProgram = loadShaderProgram_0(device, \""); + m_writer->emit("\n\tgfx::IShaderProgram* shaderProgram = loadShaderProgram(device, \""); m_writer->emit(entryPointName); m_writer->emit("\", \""); m_writer->emit(moduleName); m_writer->emit("\");"); - m_writer->emit("\n\tgfx_TransientResourceHeap_0* transientHeap = buildTransientHeap_0(device);"); - m_writer->emit("\n\tgfx_PipelineState_0* pipelineState = "); - m_writer->emit("buildPipelineState_0(device, shaderProgram);"); - m_writer->emit("\n\tgfx_ResourceView_0* bufferView = createBufferView_0(device, unconvertBuffer_0(buffer));"); - m_writer->emit("\n\tdispatchComputation_0(device, transientHeap, pipelineState, "); + m_writer->emit("\n\tgfx::ITransientResourceHeap* transientHeap = buildTransientHeap(device);"); + m_writer->emit("\n\tgfx::IPipelineState* pipelineState = "); + m_writer->emit("buildPipelineState(device, shaderProgram);"); + m_writer->emit("\n\tgfx::IResourceView* bufferView = createBufferView(device, unconvertBuffer(buffer));"); + m_writer->emit("\n\tdispatchComputation(device, transientHeap, pipelineState, "); m_writer->emit("bufferView, gridDims.x, gridDims.y, gridDims.z);"); m_writer->emit("\n}\n"); } |
