diff options
| author | lucy96chen <47800040+lucy96chen@users.noreply.github.com> | 2021-09-23 12:19:49 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-09-23 12:19:49 -0700 |
| commit | f2a3c933bc11a498c622fa18694c84beca8ca031 (patch) | |
| tree | 8420310733f50c9d8d4765c6dd3022b7be08eae3 | |
| parent | b9b398d038b524f15a86ff27cd6888d54e8754e0 (diff) | |
Add method to retrieve native handles (#1944)
* Added a getNativeHandle() method that retrieves the natively created handles; Modified RendererBase, VKDevice, D3D12Device, and DebugDevice to implement this new method
* Moved ExistingDeviceHandles out of Desc directly inside IDevice and renamed to NativeHandles; Modified calls accessing the struct accordingly in RendererBase, DebugDevice, VKDevice, and D3D12Device
* Minor cleanup changes (renames, etc.)
| -rw-r--r-- | slang-gfx.h | 70 | ||||
| -rw-r--r-- | tools/gfx/d3d12/render-d3d12.cpp | 8 | ||||
| -rw-r--r-- | tools/gfx/debug-layer.cpp | 5 | ||||
| -rw-r--r-- | tools/gfx/debug-layer.h | 1 | ||||
| -rw-r--r-- | tools/gfx/renderer-shared.cpp | 6 | ||||
| -rw-r--r-- | tools/gfx/renderer-shared.h | 1 | ||||
| -rw-r--r-- | tools/gfx/vulkan/render-vk.cpp | 12 |
7 files changed, 68 insertions, 35 deletions
diff --git a/slang-gfx.h b/slang-gfx.h index c7a2e6346..1f51e5d34 100644 --- a/slang-gfx.h +++ b/slang-gfx.h @@ -1418,45 +1418,47 @@ public: SlangLineDirectiveMode lineDirectiveMode = SLANG_LINE_DIRECTIVE_MODE_DEFAULT; }; + struct NativeHandle + { + public: + // The following functions create an ExistingDeviceHandles object containing the provided handles. + static NativeHandle fromVulkanHandles(uint64_t instance, uint64_t physicalDevice, uint64_t device) + { + NativeHandle handles = {}; + handles.values[0] = instance; + handles.values[1] = physicalDevice; + handles.values[2] = device; + return handles; + } + + static NativeHandle fromD3D12Handle(void* device) + { + NativeHandle handles = {}; + handles.values[0] = (uint64_t)device; + return handles; + } + + // The following functions provide a way of getting handles from values. + uint64_t getD3D12Device() const { return values[0]; } + + uint64_t getVkInstance() const { return values[0]; } + uint64_t getVkPhysicalDevice() const { return values[1]; } + uint64_t getVkDevice() const { return values[2]; } + + private: + // For D3D12, this only contains a single value for the ID3D12Device. + // For Vulkan, the first value is the VkInstance, the second is the VkPhysicalDevice, and the third is the VkDevice. + uint64_t values[3] = { 0 }; + }; + struct Desc { // The underlying API/Platform of the device. DeviceType deviceType = DeviceType::Default; + // The device's handles (if they exist). + NativeHandle existingDeviceHandles = {}; // Name to identify the adapter to use const char* adapter = nullptr; - // Device handles (if they already exist) - struct ExistingDeviceHandles - { - public: - // The following functions create an ExistingDeviceHandles object containing the provided handles. - static ExistingDeviceHandles fromVulkanHandles(uint64_t instance, uint64_t physicalDevice, uint64_t device) - { - ExistingDeviceHandles handles = {}; - handles.values[0] = instance; - handles.values[1] = physicalDevice; - handles.values[2] = device; - return handles; - } - - static ExistingDeviceHandles fromD3D12Handle(void* device) - { - ExistingDeviceHandles handles = {}; - handles.values[0] = (uint64_t)device; - return handles; - } - - // The following functions provide a way of getting handles from values. - uint64_t getD3D12Device() const { return values[0]; } - - uint64_t getVkInstance() const { return values[0]; } - uint64_t getVkPhysicalDevice() const { return values[1]; } - uint64_t getVkDevice() const { return values[2]; } - - private: - // For D3D12, this only contains a single value for the ID3D12Device. - // For Vulkan, the first value is the VkInstance, the second is the VkPhysicalDevice, and the third is the VkDevice. - uint64_t values[3] = { 0 }; - } existingDeviceHandles; // Number of required features. int requiredFeatureCount = 0; // Array of required feature names, whose size is `requiredFeatureCount`. @@ -1470,6 +1472,8 @@ public: SlangDesc slang = {}; }; + virtual SLANG_NO_THROW Result SLANG_MCALL getNativeHandle(NativeHandle* outHandle) = 0; + virtual SLANG_NO_THROW bool SLANG_MCALL hasFeature(const char* feature) = 0; /// Returns a list of features supported by the renderer. diff --git a/tools/gfx/d3d12/render-d3d12.cpp b/tools/gfx/d3d12/render-d3d12.cpp index 22f846ded..b9419c0f1 100644 --- a/tools/gfx/d3d12/render-d3d12.cpp +++ b/tools/gfx/d3d12/render-d3d12.cpp @@ -146,6 +146,8 @@ public: return m_info; } + virtual SLANG_NO_THROW Result SLANG_MCALL getNativeHandle(NativeHandle* outHandle) override; + ~D3D12Device(); #if SLANG_GFX_HAS_DXR_SUPPORT @@ -4115,6 +4117,12 @@ Result D3D12Device::captureTextureToSurface( // !!!!!!!!!!!!!!!!!!!!!!!!!!!! Renderer interface !!!!!!!!!!!!!!!!!!!!!!!!!! +Result D3D12Device::getNativeHandle(NativeHandle* outHandle) +{ + *outHandle = NativeHandle::fromD3D12Handle(m_device); + return SLANG_OK; +} + Result D3D12Device::_createDevice(DeviceCheckFlags deviceCheckFlags, const UnownedStringSlice& nameMatch, D3D_FEATURE_LEVEL featureLevel, DeviceInfo& outDeviceInfo) { outDeviceInfo.clear(); diff --git a/tools/gfx/debug-layer.cpp b/tools/gfx/debug-layer.cpp index 50cacc6c2..91757a501 100644 --- a/tools/gfx/debug-layer.cpp +++ b/tools/gfx/debug-layer.cpp @@ -285,6 +285,11 @@ void validateAccelerationStructureBuildInputs( } } +Result DebugDevice::getNativeHandle(NativeHandle* outHandle) +{ + return baseObject->getNativeHandle(outHandle); +} + Result DebugDevice::getFeatures(const char** outFeatures, UInt bufferSize, UInt* outFeatureCount) { SLANG_GFX_API_FUNC; diff --git a/tools/gfx/debug-layer.h b/tools/gfx/debug-layer.h index c7de48149..1494fec58 100644 --- a/tools/gfx/debug-layer.h +++ b/tools/gfx/debug-layer.h @@ -40,6 +40,7 @@ public: public: DebugDevice(); IDevice* getInterface(const Slang::Guid& guid); + virtual SLANG_NO_THROW Result SLANG_MCALL getNativeHandle(NativeHandle* outHandle) override; virtual SLANG_NO_THROW bool SLANG_MCALL hasFeature(const char* feature) override; virtual SLANG_NO_THROW Result SLANG_MCALL getFeatures(const char** outFeatures, UInt bufferSize, UInt* outFeatureCount) override; diff --git a/tools/gfx/renderer-shared.cpp b/tools/gfx/renderer-shared.cpp index bb80c4f53..18f99ad1b 100644 --- a/tools/gfx/renderer-shared.cpp +++ b/tools/gfx/renderer-shared.cpp @@ -248,6 +248,12 @@ SLANG_NO_THROW Result SLANG_MCALL RendererBase::initialize(const Desc& desc) return SLANG_OK; } +SLANG_NO_THROW Result SLANG_MCALL RendererBase::getNativeHandle(NativeHandle* outHandle) +{ + *outHandle = {}; + return SLANG_OK; +} + SLANG_NO_THROW Result SLANG_MCALL RendererBase::getFeatures( const char** outFeatures, UInt bufferSize, UInt* outFeatureCount) { diff --git a/tools/gfx/renderer-shared.h b/tools/gfx/renderer-shared.h index 31a7566a2..5710bc74e 100644 --- a/tools/gfx/renderer-shared.h +++ b/tools/gfx/renderer-shared.h @@ -1079,6 +1079,7 @@ class RendererBase : public IDevice, public Slang::ComObject public: SLANG_COM_OBJECT_IUNKNOWN_ALL + virtual SLANG_NO_THROW Result SLANG_MCALL getNativeHandle(NativeHandle* outHandle) SLANG_OVERRIDE; virtual SLANG_NO_THROW Result SLANG_MCALL getFeatures( const char** outFeatures, UInt bufferSize, UInt* outFeatureCount) SLANG_OVERRIDE; virtual SLANG_NO_THROW bool SLANG_MCALL hasFeature(const char* featureName) SLANG_OVERRIDE; diff --git a/tools/gfx/vulkan/render-vk.cpp b/tools/gfx/vulkan/render-vk.cpp index e67f86217..70eb8de03 100644 --- a/tools/gfx/vulkan/render-vk.cpp +++ b/tools/gfx/vulkan/render-vk.cpp @@ -53,7 +53,7 @@ public: kMaxDescriptorSets = 8, }; // Renderer implementation - Result initVulkanInstanceAndDevice(Desc::ExistingDeviceHandles handles, bool useValidationLayer); + Result initVulkanInstanceAndDevice(NativeHandle handles, bool useValidationLayer); virtual SLANG_NO_THROW Result SLANG_MCALL initialize(const Desc& desc) override; virtual SLANG_NO_THROW Result SLANG_MCALL createTransientResourceHeap( const ITransientResourceHeap::Desc& desc, @@ -134,6 +134,8 @@ public: { return m_info; } + + virtual SLANG_NO_THROW Result SLANG_MCALL getNativeHandle(NativeHandle* outHandle) override; /// Dtor ~VKDevice(); @@ -5222,7 +5224,13 @@ VkPipelineShaderStageCreateInfo VKDevice::compileEntryPoint( // !!!!!!!!!!!!!!!!!!!!!!!!!!!! Renderer interface !!!!!!!!!!!!!!!!!!!!!!!!!! -Result VKDevice::initVulkanInstanceAndDevice(const Desc::ExistingDeviceHandles handles, bool useValidationLayer) +Result VKDevice::getNativeHandle(NativeHandle* outHandle) +{ + *outHandle = NativeHandle::fromVulkanHandles((uint64_t)m_api.m_instance, (uint64_t)m_api.m_physicalDevice, (uint64_t)m_api.m_device); + return SLANG_OK; +} + +Result VKDevice::initVulkanInstanceAndDevice(const NativeHandle handles, bool useValidationLayer) { m_features.clear(); |
