From 42f49937ffa69c82e333e886952eed027e12340e Mon Sep 17 00:00:00 2001 From: Yong He Date: Tue, 16 Aug 2022 17:11:54 -0700 Subject: 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 --- tools/gfx/vulkan/vk-command-encoder.h | 50 ++++++++++++++++++++++++++++++++--- 1 file changed, 47 insertions(+), 3 deletions(-) (limited to 'tools/gfx/vulkan/vk-command-encoder.h') diff --git a/tools/gfx/vulkan/vk-command-encoder.h b/tools/gfx/vulkan/vk-command-encoder.h index f71e262c5..0e834a5fb 100644 --- a/tools/gfx/vulkan/vk-command-encoder.h +++ b/tools/gfx/vulkan/vk-command-encoder.h @@ -12,7 +12,7 @@ using namespace Slang; namespace vk { -class PipelineCommandEncoder : public RefObject +class PipelineCommandEncoder : public ComObject { public: CommandBufferImpl* m_commandBuffer; @@ -54,6 +54,25 @@ class ResourceCommandEncoder , public PipelineCommandEncoder { public: + virtual void* getInterface(SlangUUID const& guid) + { + if (guid == GfxGUID::IID_IResourceCommandEncoder || guid == ISlangUnknown::getTypeGuid()) + return this; + return nullptr; + } + virtual SLANG_NO_THROW SlangResult SLANG_MCALL + queryInterface(SlangUUID const& uuid, void** outObject) + { + if (auto ptr = getInterface(uuid)) + { + *outObject = ptr; + return SLANG_OK; + } + return SLANG_E_NO_INTERFACE; + } + virtual SLANG_NO_THROW uint32_t SLANG_MCALL addRef() { return 1; } + virtual SLANG_NO_THROW uint32_t SLANG_MCALL release() { return 1; } + virtual SLANG_NO_THROW void SLANG_MCALL copyBuffer( IBufferResource* dst, Offset dstOffset, @@ -150,8 +169,16 @@ class RenderCommandEncoder : public IRenderCommandEncoder , public ResourceCommandEncoder { -public: SLANG_GFX_FORWARD_RESOURCE_COMMAND_ENCODER_IMPL(ResourceCommandEncoder) + virtual void* getInterface(SlangUUID const& uuid) override + { + if (uuid == GfxGUID::IID_IResourceCommandEncoder || uuid == GfxGUID::IID_IRenderCommandEncoder || uuid == ISlangUnknown::getTypeGuid()) + { + return this; + } + return nullptr; + } + public: List m_viewports; List m_scissorRects; @@ -233,7 +260,15 @@ class ComputeCommandEncoder { public: SLANG_GFX_FORWARD_RESOURCE_COMMAND_ENCODER_IMPL(ResourceCommandEncoder) -public: + virtual void* getInterface(SlangUUID const& uuid) override + { + if (uuid == GfxGUID::IID_IResourceCommandEncoder || uuid == GfxGUID::IID_IComputeCommandEncoder || uuid == ISlangUnknown::getTypeGuid()) + { + return this; + } + return nullptr; + } + virtual SLANG_NO_THROW void SLANG_MCALL endEncoding() override; virtual SLANG_NO_THROW Result SLANG_MCALL @@ -254,7 +289,16 @@ class RayTracingCommandEncoder { public: SLANG_GFX_FORWARD_RESOURCE_COMMAND_ENCODER_IMPL(ResourceCommandEncoder) + virtual void* getInterface(SlangUUID const& uuid) override + { + if (uuid == GfxGUID::IID_IResourceCommandEncoder || uuid == GfxGUID::IID_IRayTracingCommandEncoder || uuid == ISlangUnknown::getTypeGuid()) + { + return this; + } + return nullptr; + } public: + void _memoryBarrier( int count, IAccelerationStructure* const* structures, -- cgit v1.2.3