From 5a3aa6159e0ef0241b528812e1d138f0d7055f22 Mon Sep 17 00:00:00 2001 From: lucy96chen <47800040+lucy96chen@users.noreply.github.com> Date: Tue, 17 May 2022 10:56:14 -0700 Subject: Split render-d3d12.h/cpp into a set of smaller files (#2231) * Split render-d3d12 into numerous smaller files to make the code easier to parse * Added all new D3D12 files created from splitting render-d3d12 * Fixed several uses of attachment still floating around; Changed resource-d3d12 and descriptor-heap-d3d12 to match naming conventions of new d3d12 implementation header files * Readded files with name changes because changing them from inside VS apparently results in them being treated as new files * Merged in externals changes from master * Small cleanup changes * Rerun CI Co-authored-by: Theresa Foley <10618364+tangent-vector@users.noreply.github.com> --- tools/gfx/d3d12/d3d12-texture.cpp | 58 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 tools/gfx/d3d12/d3d12-texture.cpp (limited to 'tools/gfx/d3d12/d3d12-texture.cpp') diff --git a/tools/gfx/d3d12/d3d12-texture.cpp b/tools/gfx/d3d12/d3d12-texture.cpp new file mode 100644 index 000000000..4f1898ef7 --- /dev/null +++ b/tools/gfx/d3d12/d3d12-texture.cpp @@ -0,0 +1,58 @@ +// d3d12-texture.cpp +#include "d3d12-texture.h" + +namespace gfx +{ +namespace d3d12 +{ + +using namespace Slang; + +TextureResourceImpl::TextureResourceImpl(const Desc& desc) + : Parent(desc) + , m_defaultState(D3DUtil::getResourceState(desc.defaultState)) +{} + +TextureResourceImpl::~TextureResourceImpl() +{ + if (sharedHandle.handleValue != 0) + { + CloseHandle((HANDLE)sharedHandle.handleValue); + } +} + +Result TextureResourceImpl::getNativeResourceHandle(InteropHandle* outHandle) +{ + outHandle->handleValue = (uint64_t)m_resource.getResource(); + outHandle->api = InteropHandleAPI::D3D12; + return SLANG_OK; +} + +Result TextureResourceImpl::getSharedHandle(InteropHandle* outHandle) +{ + // Check if a shared handle already exists for this resource. + if (sharedHandle.handleValue != 0) + { + *outHandle = sharedHandle; + return SLANG_OK; + } + + // If a shared handle doesn't exist, create one and store it. + ComPtr pDevice; + auto pResource = m_resource.getResource(); + pResource->GetDevice(IID_PPV_ARGS(pDevice.writeRef())); + SLANG_RETURN_ON_FAIL(pDevice->CreateSharedHandle( + pResource, NULL, GENERIC_ALL, nullptr, (HANDLE*)&outHandle->handleValue)); + outHandle->api = InteropHandleAPI::D3D12; + return SLANG_OK; +} + +Result TextureResourceImpl::setDebugName(const char* name) +{ + Parent::setDebugName(name); + m_resource.setDebugName(name); + return SLANG_OK; +} + +} // namespace d3d12 +} // namespace gfx -- cgit v1.2.3