Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/.patches/dawn.diff
Original file line number Diff line number Diff line change
Expand Up @@ -491,14 +491,14 @@ index 214fa67f8..d909d4d2a 100644
+
+ gpgmm::d3d12::ALLOCATOR_DESC allocatorDesc = {};
+ allocatorDesc.Adapter = adapter->GetHardwareAdapter();
+ allocatorDesc.Device = mD3d12Device;
+ allocatorDesc.Device = mD3d12Device.Get();
+ allocatorDesc.ResourceHeapTier =
+ static_cast<D3D12_RESOURCE_HEAP_TIER>(adapter->GetDeviceInfo().resourceHeapTier);
+ allocatorDesc.PreferredResourceHeapSize = 4ll * 1024ll * 1024ll; // 4MB
+
+ gpgmm::d3d12::RESIDENCY_DESC residencyDesc = {};
+ residencyDesc.Adapter = adapter->GetHardwareAdapter();
+ residencyDesc.Device = mD3d12Device;
+ residencyDesc.Device = mD3d12Device.Get();
+ residencyDesc.IsUMA = adapter->GetDeviceInfo().isUMA;
+
+ if (IsToggleEnabled(Toggle::UseD3D12SmallResidencyBudgetForTesting)) {
Expand Down
9 changes: 4 additions & 5 deletions include/gpgmm_d3d12.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@

#ifndef GPGMM_WINDOWS_HEADERS_ALREADY_INCLUDED
# include <windows.h> // for DEFINE_ENUM_FLAG_OPERATORS
# include <wrl.h> // for Microsoft::WRL::ComPtr
#endif

#define GPGMM_INTERFACE struct
Expand Down Expand Up @@ -317,15 +316,15 @@ namespace gpgmm::d3d12 {
/** \brief Specifies the device used by this residency manager.
Required parameter. Use CreateDevice get the device.
*/
Microsoft::WRL::ComPtr<ID3D12Device> Device;
ID3D12Device* Device;

/** \brief Specifies the adapter used by this residency manager.

Requires DXGI 1.4 due to IDXGIAdapter3::QueryVideoMemoryInfo.

Required parameter. Use EnumAdapters to get the adapter.
*/
Microsoft::WRL::ComPtr<IDXGIAdapter3> Adapter;
IDXGIAdapter3* Adapter;

/** \brief Specifies if unified memory architecture (UMA) is enabled.

Expand Down Expand Up @@ -785,7 +784,7 @@ namespace gpgmm::d3d12 {

Required parameter. Use CreateDevice get the device.
*/
Microsoft::WRL::ComPtr<ID3D12Device> Device;
ID3D12Device* Device;

/** \brief Specifies the adapter used by this allocator.

Expand All @@ -795,7 +794,7 @@ namespace gpgmm::d3d12 {

Optional parameter. Use EnumAdapters to get the adapter.
*/
Microsoft::WRL::ComPtr<IDXGIAdapter> Adapter;
IDXGIAdapter* Adapter;

/** \brief Specifies allocator options.

Expand Down
27 changes: 10 additions & 17 deletions src/fuzzers/D3D12Fuzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,20 @@ uint64_t UInt8ToUInt64(const uint8_t* src) {
return dst;
}

HRESULT CreateResourceAllocatorDesc(gpgmm::d3d12::ALLOCATOR_DESC* allocatorDesc) {
HRESULT CreateResourceAllocatorDesc(gpgmm::d3d12::ALLOCATOR_DESC* pAllocatorDesc,
ID3D12Device** ppDeviceOut,
IDXGIAdapter3** ppAdapterOut) {
gpgmm::d3d12::ALLOCATOR_DESC allocatorDescOut = {};

// Populate the device
ComPtr<ID3D12Device> d3dDevice;
if (FAILED(D3D12CreateDevice(nullptr, D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&d3dDevice)))) {
if (FAILED(D3D12CreateDevice(nullptr, D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(ppDeviceOut)))) {
return E_FAIL;
}

allocatorDescOut.Device = d3dDevice;
allocatorDescOut.Device = *ppDeviceOut;

// Populate the adapter
LUID adapterLUID = d3dDevice->GetAdapterLuid();
LUID adapterLUID = allocatorDescOut.Device->GetAdapterLuid();
ComPtr<IDXGIFactory1> dxgiFactory;
if (FAILED(CreateDXGIFactory1(IID_PPV_ARGS(&dxgiFactory)))) {
return E_FAIL;
Expand All @@ -43,25 +44,17 @@ HRESULT CreateResourceAllocatorDesc(gpgmm::d3d12::ALLOCATOR_DESC* allocatorDesc)
return E_FAIL;
}

ComPtr<IDXGIAdapter3> dxgiAdapter;
if (FAILED(dxgiFactory4->EnumAdapterByLuid(adapterLUID, IID_PPV_ARGS(&dxgiAdapter)))) {
if (FAILED(dxgiFactory4->EnumAdapterByLuid(adapterLUID, IID_PPV_ARGS(ppAdapterOut)))) {
return E_FAIL;
}

allocatorDescOut.Adapter = dxgiAdapter;
allocatorDescOut.Adapter = *ppAdapterOut;

// Configure options
D3D12_FEATURE_DATA_D3D12_OPTIONS options = {};
if (FAILED(d3dDevice->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS, &options,
sizeof(options)))) {
return E_FAIL;
}

allocatorDescOut.ResourceHeapTier = options.ResourceHeapTier;
allocatorDescOut.MinLogLevel = D3D12_MESSAGE_SEVERITY_MESSAGE;

if (allocatorDesc != nullptr) {
*allocatorDesc = allocatorDescOut;
if (pAllocatorDesc != nullptr) {
*pAllocatorDesc = allocatorDescOut;
}

return S_OK;
Expand Down
6 changes: 5 additions & 1 deletion src/fuzzers/D3D12Fuzzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@

#include <gpgmm_d3d12.h>

#include <wrl.h>

using Microsoft::WRL::ComPtr;

uint64_t UInt8ToUInt64(const uint8_t* src);

HRESULT CreateResourceAllocatorDesc(gpgmm::d3d12::ALLOCATOR_DESC* allocatorDesc);
HRESULT CreateResourceAllocatorDesc(gpgmm::d3d12::ALLOCATOR_DESC* allocatorDesc,
ID3D12Device** ppDeviceOut,
IDXGIAdapter3** ppAdapterOut);

D3D12_RESOURCE_DESC CreateBufferDesc(uint64_t width, uint64_t alignment = 0);

Expand Down
9 changes: 6 additions & 3 deletions src/fuzzers/D3D12ResidencyManagerFuzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@

namespace {

ComPtr<ID3D12Device> gDevice;
ComPtr<IDXGIAdapter3> gAdapter;

ComPtr<gpgmm::d3d12::IResourceAllocator> gResourceAllocator;
ComPtr<gpgmm::d3d12::IResidencyManager> gResidencyManager;
std::vector<ComPtr<gpgmm::d3d12::IResourceAllocation>> gAllocationsBelowBudget = {};
Expand All @@ -41,7 +44,7 @@ namespace {

extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv) {
gpgmm::d3d12::ALLOCATOR_DESC allocatorDesc = {};
if (FAILED(CreateResourceAllocatorDesc(&allocatorDesc))) {
if (FAILED(CreateResourceAllocatorDesc(&allocatorDesc, &gDevice, &gAdapter))) {
return 0;
}

Expand All @@ -50,11 +53,11 @@ extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv) {
gpgmm::d3d12::RESIDENCY_DESC residencyDesc = {};

ComPtr<IDXGIAdapter3> adapter3;
if (FAILED(allocatorDesc.Adapter.As(&adapter3))) {
if (FAILED(allocatorDesc.Adapter->QueryInterface(IID_PPV_ARGS(&adapter3)))) {
return 0;
}

residencyDesc.Adapter = adapter3;
residencyDesc.Adapter = adapter3.Get();
residencyDesc.Device = allocatorDesc.Device;
residencyDesc.MinLogLevel = D3D12_MESSAGE_SEVERITY_MESSAGE;

Expand Down
5 changes: 4 additions & 1 deletion src/fuzzers/D3D12ResourceAllocatorFuzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@

namespace {

ComPtr<ID3D12Device> gDevice;
ComPtr<IDXGIAdapter3> gAdapter;

ComPtr<gpgmm::d3d12::IResourceAllocator> gResourceAllocator;

} // namespace

extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv) {
gpgmm::d3d12::ALLOCATOR_DESC allocatorDesc = {};
if (FAILED(CreateResourceAllocatorDesc(&allocatorDesc))) {
if (FAILED(CreateResourceAllocatorDesc(&allocatorDesc, &gDevice, &gAdapter))) {
return 0;
}

Expand Down
3 changes: 1 addition & 2 deletions src/gpgmm/d3d12/ResidencyManagerD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,7 @@ namespace gpgmm::d3d12 {
std::unique_ptr<Caps> caps;
{
Caps* ptr = nullptr;
ReturnIfFailed(
Caps::CreateCaps(descriptor.Device.Get(), descriptor.Adapter.Get(), &ptr));
ReturnIfFailed(Caps::CreateCaps(descriptor.Device, descriptor.Adapter, &ptr));
caps.reset(ptr);
}

Expand Down
10 changes: 5 additions & 5 deletions src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,14 +393,14 @@ namespace gpgmm::d3d12 {
residencyDesc.Device = allocatorDescriptor.Device;

if (allocatorDescriptor.Adapter != nullptr) {
ReturnIfFailed(allocatorDescriptor.Adapter.As(&residencyDesc.Adapter));
ReturnIfFailed(allocatorDescriptor.Adapter->QueryInterface(
IID_PPV_ARGS(&residencyDesc.Adapter)));
}

std::unique_ptr<Caps> caps;
{
Caps* ptr = nullptr;
ReturnIfFailed(Caps::CreateCaps(residencyDesc.Device.Get(),
residencyDesc.Adapter.Get(), &ptr));
ReturnIfFailed(Caps::CreateCaps(residencyDesc.Device, residencyDesc.Adapter, &ptr));
caps.reset(ptr);
}

Expand Down Expand Up @@ -437,8 +437,8 @@ namespace gpgmm::d3d12 {
std::unique_ptr<Caps> caps;
{
Caps* ptr = nullptr;
ReturnIfFailed(Caps::CreateCaps(allocatorDescriptor.Device.Get(),
allocatorDescriptor.Adapter.Get(), &ptr));
ReturnIfFailed(
Caps::CreateCaps(allocatorDescriptor.Device, allocatorDescriptor.Adapter, &ptr));
caps.reset(ptr);
}

Expand Down
3 changes: 2 additions & 1 deletion src/mvi/gpgmm_d3d12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,8 @@ namespace gpgmm::d3d12 {
residencyDesc.Device = allocatorDescriptor.Device;

if (allocatorDescriptor.Adapter != nullptr) {
ReturnIfFailed(allocatorDescriptor.Adapter.As(&residencyDesc.Adapter));
ReturnIfFailed(allocatorDescriptor.Adapter->QueryInterface(
IID_PPV_ARGS(&residencyDesc.Adapter)));
}

D3D12_FEATURE_DATA_ARCHITECTURE arch = {};
Expand Down
2 changes: 2 additions & 0 deletions src/mvi/gpgmm_d3d12.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@

#include "gpgmm.h"

#include <wrl.h> // for Microsoft::WRL::ComPtr

namespace gpgmm::d3d12 {

class Unknown : public IUnknown {
Expand Down
4 changes: 2 additions & 2 deletions src/samples/D3D12Sample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ HRESULT Init() {
}

gpgmm::d3d12::ALLOCATOR_DESC desc = {};
desc.Adapter = adapter3;
desc.Device = device;
desc.Adapter = adapter3.Get();
desc.Device = device.Get();
desc.ResourceHeapTier = options.ResourceHeapTier;

Microsoft::WRL::ComPtr<gpgmm::d3d12::IResourceAllocator> resourceAllocator;
Expand Down
8 changes: 4 additions & 4 deletions src/tests/D3D12Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ namespace gpgmm::d3d12 {
ALLOCATOR_DESC desc = {};

// Required parameters.
desc.Adapter = mAdapter;
desc.Device = mDevice;
desc.Adapter = mAdapter.Get();
desc.Device = mDevice.Get();
desc.ResourceHeapTier = mCaps->GetMaxResourceHeapTierSupported();

desc.MinLogLevel = GetMessageSeverity(GetLogLevel());
Expand All @@ -127,8 +127,8 @@ namespace gpgmm::d3d12 {
RESIDENCY_DESC D3D12TestBase::CreateBasicResidencyDesc() const {
RESIDENCY_DESC desc = {};
// Required
desc.Adapter = mAdapter;
desc.Device = mDevice;
desc.Adapter = mAdapter.Get();
desc.Device = mDevice.Get();
desc.IsUMA = mCaps->IsAdapterUMA();

desc.MinLogLevel = GetMessageSeverity(GetLogLevel());
Expand Down
4 changes: 2 additions & 2 deletions src/tests/end2end/D3D12ResourceAllocatorTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ TEST_F(D3D12ResourceAllocatorTests, CreateResourceAllocator) {
// Creating an allocator without the resource heap tier specified should always succeed.
{
ALLOCATOR_DESC desc = {};
desc.Device = mDevice;
desc.Adapter = mAdapter;
desc.Device = mDevice.Get();
desc.Adapter = mAdapter.Get();

ComPtr<IResourceAllocator> resourceAllocator;
EXPECT_SUCCEEDED(CreateResourceAllocator(desc, &resourceAllocator, nullptr));
Expand Down