summaryrefslogtreecommitdiffstats
path: root/tools/gfx/renderer-shared.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2022-08-16 17:11:54 -0700
committerGitHub <noreply@github.com>2022-08-16 17:11:54 -0700
commit42f49937ffa69c82e333e886952eed027e12340e (patch)
tree08e3e9821dd40e23476060215d589e29092adb53 /tools/gfx/renderer-shared.cpp
parente68fab2bda5d979f8d991fc41122bb9aa71849a6 (diff)
Add gfx interface definition in Slang. (#2364)
* Add gfx interface definition in Slang. - add gfx interface definitons in Slang. - fix slang compiler to correctly type-check `out` interface argument. - modify gfx interface to be fully COM compatible - add convenient ShaderProgram creation methods to gfx. * Fix compile errors and warnings. * Update project files * Fix cuda. * Properly implement queryInterface in command encoder impls. Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'tools/gfx/renderer-shared.cpp')
-rw-r--r--tools/gfx/renderer-shared.cpp62
1 files changed, 61 insertions, 1 deletions
diff --git a/tools/gfx/renderer-shared.cpp b/tools/gfx/renderer-shared.cpp
index 5d62f7fba..2e5454851 100644
--- a/tools/gfx/renderer-shared.cpp
+++ b/tools/gfx/renderer-shared.cpp
@@ -26,7 +26,11 @@ const Slang::Guid GfxGUID::IID_IDevice = SLANG_UUID_IDevice;
const Slang::Guid GfxGUID::IID_IShaderObject = SLANG_UUID_IShaderObject;
const Slang::Guid GfxGUID::IID_IRenderPassLayout = SLANG_UUID_IRenderPassLayout;
-const Slang::Guid GfxGUID::IID_IRayTracingCommandEncoder = SLANG_UUID_IRayTracingCommandEncoder;
+const Slang::Guid GfxGUID::IID_IRayTracingCommandEncoder = IRayTracingCommandEncoder::getTypeGuid();
+const Slang::Guid GfxGUID::IID_IResourceCommandEncoder = IResourceCommandEncoder::getTypeGuid();
+const Slang::Guid GfxGUID::IID_IComputeCommandEncoder = IComputeCommandEncoder::getTypeGuid();
+const Slang::Guid GfxGUID::IID_IRenderCommandEncoder = IRenderCommandEncoder::getTypeGuid();
+
const Slang::Guid GfxGUID::IID_ICommandBuffer = SLANG_UUID_ICommandBuffer;
const Slang::Guid GfxGUID::IID_ICommandBufferD3D12 = SLANG_UUID_ICommandBufferD3D12;
@@ -462,6 +466,62 @@ SLANG_NO_THROW Result SLANG_MCALL RendererBase::createMutableShaderObject(
return createMutableShaderObject(shaderObjectLayout, outObject);
}
+Result RendererBase::createProgram2(
+ const IShaderProgram::CreateDesc2& desc,
+ IShaderProgram** outProgram,
+ ISlangBlob** outDiagnostic)
+{
+ auto slangSession = slangContext.session.get();
+
+ SLANG_RELEASE_ASSERT(desc.sourceType == ShaderModuleSourceType::SlangSourceFile);
+
+ auto fileName = (char*)desc.sourceData;
+ ComPtr<slang::IBlob> diagnosticsBlob;
+ slang::IModule* module = slangSession->loadModule(fileName, diagnosticsBlob.writeRef());
+ if (!module)
+ return SLANG_FAIL;
+
+ Slang::List<ComPtr<slang::IComponentType>> componentTypes;
+ componentTypes.add(ComPtr<slang::IComponentType>(module));
+
+ if (desc.entryPointCount == 0)
+ {
+ for (SlangInt32 i = 0; i < module->getDefinedEntryPointCount(); i++)
+ {
+ ComPtr<slang::IEntryPoint> entryPoint;
+ SLANG_RETURN_ON_FAIL(module->getDefinedEntryPoint(i, entryPoint.writeRef()));
+ componentTypes.add(ComPtr<slang::IComponentType>(entryPoint.get()));
+ }
+ }
+ else
+ {
+ for (GfxCount i = 0; i < desc.entryPointCount; i++)
+ {
+ ComPtr<slang::IEntryPoint> entryPoint;
+ SLANG_RETURN_ON_FAIL(module->findEntryPointByName(desc.entryPointNames[i], entryPoint.writeRef()));
+ componentTypes.add(ComPtr<slang::IComponentType>(entryPoint.get()));
+ }
+ }
+
+ Slang::List<slang::IComponentType*> rawComponentTypes;
+ for (auto& compType : componentTypes)
+ rawComponentTypes.add(compType.get());
+
+ ComPtr<slang::IComponentType> linkedProgram;
+ SlangResult result = slangSession->createCompositeComponentType(
+ rawComponentTypes.getBuffer(),
+ rawComponentTypes.getCount(),
+ linkedProgram.writeRef(),
+ diagnosticsBlob.writeRef());
+ SLANG_RETURN_ON_FAIL(result);
+
+ gfx::IShaderProgram::Desc programDesc = {};
+ programDesc.slangGlobalScope = linkedProgram;
+ SLANG_RETURN_ON_FAIL(createProgram(programDesc, outProgram, outDiagnostic));
+
+ return SLANG_OK;
+}
+
SLANG_NO_THROW Result SLANG_MCALL RendererBase::createShaderObjectFromTypeLayout(
slang::TypeLayoutReflection* typeLayout, IShaderObject** outObject)
{