mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-16 08:27:05 +00:00
D3D12: Enable external texture reuse
This change allows multiple Dawn textures to be created from the same D3D11 resource. This avoids re-opening the shared handle by caching the D3D12 resource outside of the Dawn texture. Re-opening the handle costs 5-10% of CPU cycles per frame, which far exceeded syncronization costs. In a future change, WrapSharedHandle will be depreciated. BUG=dawn:625 Change-Id: If0d2dc9b7445ec3ae718bc5305164db88057c4ea Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/42140 Commit-Queue: Bryan Bernhart <bryan.bernhart@intel.com> Reviewed-by: Austin Eng <enga@chromium.org> Reviewed-by: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
committed by
Commit Bot service account
parent
4d9f2ca07d
commit
9c3aefa4bd
@@ -19,10 +19,14 @@
|
||||
#include <dawn_native/DawnNative.h>
|
||||
|
||||
#include <DXGI1_4.h>
|
||||
#include <d3d12.h>
|
||||
#include <windows.h>
|
||||
#include <wrl/client.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
struct ID3D12Device;
|
||||
struct ID3D12Resource;
|
||||
|
||||
namespace dawn_native { namespace d3d12 {
|
||||
DAWN_NATIVE_EXPORT Microsoft::WRL::ComPtr<ID3D12Device> GetD3D12Device(WGPUDevice device);
|
||||
@@ -45,10 +49,46 @@ namespace dawn_native { namespace d3d12 {
|
||||
ExternalImageDescriptorDXGISharedHandle();
|
||||
|
||||
HANDLE sharedHandle;
|
||||
|
||||
// Warning: depreciated, replaced by ExternalImageAccessDescriptorDXGIKeyedMutex.
|
||||
uint64_t acquireMutexKey;
|
||||
bool isSwapChainTexture = false;
|
||||
};
|
||||
|
||||
struct DAWN_NATIVE_EXPORT ExternalImageAccessDescriptorDXGIKeyedMutex
|
||||
: ExternalImageAccessDescriptor {
|
||||
public:
|
||||
uint64_t acquireMutexKey;
|
||||
bool isSwapChainTexture = false;
|
||||
};
|
||||
|
||||
class DAWN_NATIVE_EXPORT ExternalImageDXGI {
|
||||
public:
|
||||
// Note: SharedHandle must be a handle to a texture object.
|
||||
static std::unique_ptr<ExternalImageDXGI> Create(
|
||||
WGPUDevice device,
|
||||
const ExternalImageDescriptorDXGISharedHandle* descriptor);
|
||||
|
||||
WGPUTexture ProduceTexture(WGPUDevice device,
|
||||
const ExternalImageAccessDescriptorDXGIKeyedMutex* descriptor);
|
||||
|
||||
private:
|
||||
ExternalImageDXGI(Microsoft::WRL::ComPtr<ID3D12Resource> d3d12Resource,
|
||||
const WGPUTextureDescriptor* descriptor);
|
||||
|
||||
Microsoft::WRL::ComPtr<ID3D12Resource> mD3D12Resource;
|
||||
|
||||
// Contents of WGPUTextureDescriptor are stored individually since the descriptor
|
||||
// could outlive this image.
|
||||
WGPUTextureUsageFlags mUsage;
|
||||
WGPUTextureDimension mDimension;
|
||||
WGPUExtent3D mSize;
|
||||
WGPUTextureFormat mFormat;
|
||||
uint32_t mMipLevelCount;
|
||||
uint32_t mSampleCount;
|
||||
};
|
||||
|
||||
// Warning: depreciated, replaced by ExternalImageDXGI::Create.
|
||||
// Note: SharedHandle must be a handle to a texture object.
|
||||
DAWN_NATIVE_EXPORT WGPUTexture
|
||||
WrapSharedHandle(WGPUDevice device, const ExternalImageDescriptorDXGISharedHandle* descriptor);
|
||||
|
||||
@@ -228,6 +228,11 @@ namespace dawn_native {
|
||||
ExternalImageDescriptor(ExternalImageType type);
|
||||
};
|
||||
|
||||
struct DAWN_NATIVE_EXPORT ExternalImageAccessDescriptor {
|
||||
public:
|
||||
bool isInitialized; // Whether the texture is initialized on import
|
||||
};
|
||||
|
||||
struct DAWN_NATIVE_EXPORT ExternalImageExportInfo {
|
||||
public:
|
||||
const ExternalImageType type;
|
||||
|
||||
Reference in New Issue
Block a user