summaryrefslogtreecommitdiffstats
path: root/tools/gfx/renderer-shared.cpp
diff options
context:
space:
mode:
authorTim Foley <tfoleyNV@users.noreply.github.com>2021-01-26 13:32:03 -0800
committerGitHub <noreply@github.com>2021-01-26 13:32:03 -0800
commita90c850735664e2928e4cc961442a126c6859b97 (patch)
tree8b5e12113319ae87c57f5e616408eb955fe85a2c /tools/gfx/renderer-shared.cpp
parent50676c741e10ffe6f710c5de86387eaacd274a9a (diff)
Integrate reflection more deeply into gfx layer (#1677)
Diffstat (limited to 'tools/gfx/renderer-shared.cpp')
-rw-r--r--tools/gfx/renderer-shared.cpp68
1 files changed, 68 insertions, 0 deletions
diff --git a/tools/gfx/renderer-shared.cpp b/tools/gfx/renderer-shared.cpp
index 94154bc42..2072d52ef 100644
--- a/tools/gfx/renderer-shared.cpp
+++ b/tools/gfx/renderer-shared.cpp
@@ -1,6 +1,8 @@
#include "renderer-shared.h"
#include "render-graphics-common.h"
+using namespace Slang;
+
namespace gfx
{
@@ -27,5 +29,71 @@ IResource* TextureResource::getInterface(const Slang::Guid& guid)
SLANG_NO_THROW IResource::Type SLANG_MCALL TextureResource::getType() { return m_type; }
SLANG_NO_THROW ITextureResource::Desc* SLANG_MCALL TextureResource::getDesc() { return &m_desc; }
+gfx::StageType mapStage(SlangStage stage)
+{
+ switch( stage )
+ {
+ default:
+ return gfx::StageType::Unknown;
+
+ case SLANG_STAGE_AMPLIFICATION: return gfx::StageType::Amplification;
+ case SLANG_STAGE_ANY_HIT: return gfx::StageType::AnyHit;
+ case SLANG_STAGE_CALLABLE: return gfx::StageType::Callable;
+ case SLANG_STAGE_CLOSEST_HIT: return gfx::StageType::ClosestHit;
+ case SLANG_STAGE_COMPUTE: return gfx::StageType::Compute;
+ case SLANG_STAGE_DOMAIN: return gfx::StageType::Domain;
+ case SLANG_STAGE_FRAGMENT: return gfx::StageType::Fragment;
+ case SLANG_STAGE_GEOMETRY: return gfx::StageType::Geometry;
+ case SLANG_STAGE_HULL: return gfx::StageType::Hull;
+ case SLANG_STAGE_INTERSECTION: return gfx::StageType::Intersection;
+ case SLANG_STAGE_MESH: return gfx::StageType::Mesh;
+ case SLANG_STAGE_MISS: return gfx::StageType::Miss;
+ case SLANG_STAGE_RAY_GENERATION: return gfx::StageType::RayGeneration;
+ case SLANG_STAGE_VERTEX: return gfx::StageType::Vertex;
+ }
+}
+
+Result createProgramFromSlang(IRenderer* renderer, IShaderProgram::Desc const& originalDesc, IShaderProgram** outProgram)
+{
+ SlangInt targetIndex = 0;
+ auto slangProgram = originalDesc.slangProgram;
+
+ auto programLayout = slangProgram->getLayout(targetIndex);
+ if(!programLayout)
+ return SLANG_FAIL;
+
+ Int entryPointCount = (Int) programLayout->getEntryPointCount();
+ if(entryPointCount == 0)
+ return SLANG_FAIL;
+
+ List<IShaderProgram::KernelDesc> kernelDescs;
+ List<ComPtr<slang::IBlob>> kernelBlobs;
+ for( Int i = 0; i < entryPointCount; ++i )
+ {
+ ComPtr<slang::IBlob> entryPointCodeBlob;
+ SLANG_RETURN_ON_FAIL(slangProgram->getEntryPointCode(i, targetIndex, entryPointCodeBlob.writeRef()));
+
+ auto entryPointLayout = programLayout->getEntryPointByIndex(i);
+
+ kernelBlobs.add(entryPointCodeBlob);
+
+ IShaderProgram::KernelDesc kernelDesc;
+ kernelDesc.codeBegin = entryPointCodeBlob->getBufferPointer();
+ kernelDesc.codeEnd = (const char*) kernelDesc.codeBegin + entryPointCodeBlob->getBufferSize();
+ kernelDesc.entryPointName = entryPointLayout->getName();
+ kernelDesc.stage = mapStage(entryPointLayout->getStage());
+
+ kernelDescs.add(kernelDesc);
+ }
+ SLANG_ASSERT(kernelDescs.getCount() == entryPointCount);
+
+ IShaderProgram::Desc programDesc;
+ programDesc.pipelineType = originalDesc.pipelineType;
+ programDesc.slangProgram = slangProgram;
+ programDesc.kernelCount = kernelDescs.getCount();
+ programDesc.kernels = kernelDescs.getBuffer();
+
+ return renderer->createProgram(programDesc, outProgram);
+}
} // namespace gfx