Skip to content

Commit

Permalink
v1.137:
Browse files Browse the repository at this point in the history
HIGHLIGHTS:
- bug fixes and improvements
- baby steps towards better memory allocation & binding

DETAILS:
- updated version!
- D3D12/VK: reduced code entropy around "MemoryType"
- D3D12: fixed validation error: some heap flags can't be passed into "CreateCommitedResource" (STATE_CREATION ERROR #640)
- D3D12: if D3D12_RESOURCE_HEAP_TIER_2 is available, prefer to merge all resources into one heap (matches VK behavior)
- updated AMDAGS
  • Loading branch information
dzhdanNV committed Jul 21, 2024
1 parent 9d765f0 commit 5967fc3
Show file tree
Hide file tree
Showing 17 changed files with 154 additions and 154 deletions.
2 changes: 1 addition & 1 deletion External/amdags
4 changes: 2 additions & 2 deletions Include/NRI.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ Non-goals:
#include <stddef.h>

#define NRI_VERSION_MAJOR 1
#define NRI_VERSION_MINOR 135
#define NRI_VERSION_DATE "27 May 2024"
#define NRI_VERSION_MINOR 137
#define NRI_VERSION_DATE "21 July 2024"

#ifdef _WIN32
#define NRI_CALL __fastcall
Expand Down
2 changes: 1 addition & 1 deletion Resources/Version.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#define STR(x) STR_HELPER(x)

#define VERSION_MAJOR 1
#define VERSION_MINOR 135
#define VERSION_MINOR 137
#define VERSION_BUILD 0
#define VERSION_REVISION 0

Expand Down
5 changes: 1 addition & 4 deletions Source/D3D12/AccelerationStructureD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@ Result AccelerationStructureD3D12::Create(const AccelerationStructureDesc& accel
}

void AccelerationStructureD3D12::GetMemoryInfo(MemoryDesc& memoryDesc) const {
memoryDesc.size = m_PrebuildInfo.ResultDataMaxSizeInBytes;
memoryDesc.alignment = D3D12_RAYTRACING_ACCELERATION_STRUCTURE_BYTE_ALIGNMENT;
memoryDesc.type = GetMemoryType(D3D12_HEAP_TYPE_DEFAULT, D3D12_HEAP_FLAG_ALLOW_ONLY_BUFFERS);
memoryDesc.mustBeDedicated = false;
m_Device.GetMemoryInfoForAccelerationStructure(m_PrebuildInfo.ResultDataMaxSizeInBytes, memoryDesc);
}

uint64_t AccelerationStructureD3D12::GetUpdateScratchBufferSize() const {
Expand Down
15 changes: 10 additions & 5 deletions Source/D3D12/BufferD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,18 @@ Result BufferD3D12::Create(const BufferD3D12Desc& bufferDesc) {
}

Result BufferD3D12::BindMemory(const MemoryD3D12* memory, uint64_t offset, bool isAccelerationStructureBuffer) {
MaybeUnused(isAccelerationStructureBuffer);
const D3D12_HEAP_DESC& heapDesc = memory->GetHeapDesc();

// Buffer was already created externally
if (m_Buffer)
return Result::SUCCESS;

const D3D12_HEAP_DESC& heapDesc = memory->GetHeapDesc();

// STATE_CREATION ERROR #640: CREATERESOURCEANDHEAP_INVALIDHEAPMISCFLAGS
D3D12_HEAP_FLAGS heapFlagsFixed = heapDesc.Flags & ~(D3D12_HEAP_FLAG_DENY_NON_RT_DS_TEXTURES | D3D12_HEAP_FLAG_DENY_RT_DS_TEXTURES | D3D12_HEAP_FLAG_DENY_BUFFERS);

#ifdef NRI_USE_AGILITY_SDK
MaybeUnused(isAccelerationStructureBuffer);

if (m_Device.GetVersion() >= 10) {
D3D12_RESOURCE_DESC1 desc1 = {};
GetResourceDesc((D3D12_RESOURCE_DESC*)&desc1, m_Desc);
Expand All @@ -54,7 +58,7 @@ Result BufferD3D12::BindMemory(const MemoryD3D12* memory, uint64_t offset, bool

if (memory->RequiresDedicatedAllocation()) {
HRESULT hr = m_Device->CreateCommittedResource3(
&heapDesc.Properties, heapDesc.Flags, &desc1, D3D12_BARRIER_LAYOUT_UNDEFINED, nullptr, nullptr, castableFormatNum, castableFormats, IID_PPV_ARGS(&m_Buffer));
&heapDesc.Properties, heapFlagsFixed, &desc1, D3D12_BARRIER_LAYOUT_UNDEFINED, nullptr, nullptr, castableFormatNum, castableFormats, IID_PPV_ARGS(&m_Buffer));
RETURN_ON_BAD_HRESULT(&m_Device, hr, "ID3D12Device10::CreateCommittedResource3()");
} else {
HRESULT hr =
Expand All @@ -72,11 +76,12 @@ Result BufferD3D12::BindMemory(const MemoryD3D12* memory, uint64_t offset, bool
initialState |= D3D12_RESOURCE_STATE_GENERIC_READ;
else if (heapDesc.Properties.Type == D3D12_HEAP_TYPE_READBACK)
initialState |= D3D12_RESOURCE_STATE_COPY_DEST;

if (isAccelerationStructureBuffer)
initialState |= D3D12_RESOURCE_STATE_RAYTRACING_ACCELERATION_STRUCTURE;

if (memory->RequiresDedicatedAllocation()) {
HRESULT hr = m_Device->CreateCommittedResource(&heapDesc.Properties, heapDesc.Flags, &desc, initialState, nullptr, IID_PPV_ARGS(&m_Buffer));
HRESULT hr = m_Device->CreateCommittedResource(&heapDesc.Properties, heapFlagsFixed, &desc, initialState, nullptr, IID_PPV_ARGS(&m_Buffer));
RETURN_ON_BAD_HRESULT(&m_Device, hr, "ID3D12Device::CreateCommittedResource()");
} else {
HRESULT hr = m_Device->CreatePlacedResource(*memory, offset, &desc, initialState, nullptr, IID_PPV_ARGS(&m_Buffer));
Expand Down
62 changes: 51 additions & 11 deletions Source/D3D12/DeviceD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ void DeviceD3D12::FillDesc(bool enableDrawParametersEmulation) {
hr = m_Device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS, &options, sizeof(options));
if (FAILED(hr))
REPORT_WARNING(this, "ID3D12Device::CheckFeatureSupport(options) failed, result = 0x%08X!", hr);
m_IsResourceHeapTier2Supported = options.ResourceHeapTier == D3D12_RESOURCE_HEAP_TIER_2;

D3D12_FEATURE_DATA_D3D12_OPTIONS1 options1 = {};
hr = m_Device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS1, &options1, sizeof(options1));
Expand Down Expand Up @@ -650,23 +651,66 @@ DescriptorPointerCPU DeviceD3D12::GetDescriptorPointerCPU(const DescriptorHandle
return descriptorPointer;
}

constexpr std::array<D3D12_HEAP_TYPE, (uint32_t)MemoryLocation::MAX_NUM> HEAP_TYPES = {
D3D12_HEAP_TYPE_DEFAULT, // DEVICE
#ifdef NRI_USE_AGILITY_SDK
// Prerequisite: D3D12_FEATURE_D3D12_OPTIONS16
D3D12_HEAP_TYPE_GPU_UPLOAD, // DEVICE_UPLOAD
#else
D3D12_HEAP_TYPE_UPLOAD, // DEVICE_UPLOAD (silent fallback to HOST_UPLOAD)
#endif
D3D12_HEAP_TYPE_UPLOAD, // HOST_UPLOAD
D3D12_HEAP_TYPE_READBACK, // HOST_READBACK
};

static inline MemoryType ConstructMemoryType(D3D12_HEAP_TYPE heapType, D3D12_HEAP_FLAGS heapFlags) {
return ((uint32_t)heapFlags) | ((uint32_t)heapType << 16);
}

void DeviceD3D12::GetMemoryInfo(MemoryLocation memoryLocation, const D3D12_RESOURCE_DESC& resourceDesc, MemoryDesc& memoryDesc) const {
if (memoryLocation == MemoryLocation::DEVICE_UPLOAD && m_Desc.deviceUploadHeapSize == 0)
memoryLocation = MemoryLocation::HOST_UPLOAD;

memoryDesc.type = GetMemoryType(memoryLocation, resourceDesc);
D3D12_HEAP_TYPE heapType = HEAP_TYPES[(uint32_t)memoryLocation];
D3D12_HEAP_FLAGS heapFlags = D3D12_HEAP_FLAG_ALLOW_ALL_BUFFERS_AND_TEXTURES;

if (!m_IsResourceHeapTier2Supported) {
if (resourceDesc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER)
heapFlags = D3D12_HEAP_FLAG_ALLOW_ONLY_BUFFERS;
else if (resourceDesc.Flags & (D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET | D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL))
heapFlags = D3D12_HEAP_FLAG_ALLOW_ONLY_RT_DS_TEXTURES;
else
heapFlags = D3D12_HEAP_FLAG_ALLOW_ONLY_NON_RT_DS_TEXTURES;
}

D3D12_RESOURCE_ALLOCATION_INFO resourceAllocationInfo = m_Device->GetResourceAllocationInfo(NRI_NODE_MASK, 1, &resourceDesc);
MemoryType memoryType = ConstructMemoryType(heapType, heapFlags);

memoryDesc.size = (uint64_t)resourceAllocationInfo.SizeInBytes;
memoryDesc.alignment = (uint32_t)resourceAllocationInfo.Alignment;
memoryDesc.type = memoryType;
memoryDesc.mustBeDedicated = IsDedicated(memoryType);
}

void DeviceD3D12::GetMemoryInfoForAccelerationStructure(uint64_t size, MemoryDesc& memoryDesc) const {
D3D12_HEAP_FLAGS heapFlags = m_IsResourceHeapTier2Supported ? D3D12_HEAP_FLAG_ALLOW_ALL_BUFFERS_AND_TEXTURES : D3D12_HEAP_FLAG_ALLOW_ONLY_BUFFERS;

memoryDesc.size = size;
memoryDesc.alignment = D3D12_RAYTRACING_ACCELERATION_STRUCTURE_BYTE_ALIGNMENT;
memoryDesc.type = ConstructMemoryType(D3D12_HEAP_TYPE_DEFAULT, heapFlags);
memoryDesc.mustBeDedicated = false;
}

bool DeviceD3D12::IsDedicated(MemoryType memoryType) const {
D3D12_HEAP_FLAGS heapFlags = GetHeapFlags(memoryType);
bool isRtDs = (heapFlags & D3D12_HEAP_FLAG_ALLOW_ONLY_RT_DS_TEXTURES) == D3D12_HEAP_FLAG_ALLOW_ONLY_RT_DS_TEXTURES;

memoryDesc.mustBeDedicated = RequiresDedicatedAllocation(memoryDesc.type);
return !m_IsResourceHeapTier2Supported && isRtDs;
}

ComPtr<ID3D12CommandSignature> DeviceD3D12::CreateCommandSignature(
D3D12_INDIRECT_ARGUMENT_TYPE indirectArgumentType, uint32_t stride, ID3D12RootSignature* rootSignature, bool enableDrawParametersEmulation) {
const bool isDrawArgument =
enableDrawParametersEmulation && (indirectArgumentType == D3D12_INDIRECT_ARGUMENT_TYPE_DRAW || indirectArgumentType == D3D12_INDIRECT_ARGUMENT_TYPE_DRAW_INDEXED);
D3D12_INDIRECT_ARGUMENT_TYPE type, uint32_t stride, ID3D12RootSignature* rootSignature, bool enableDrawParametersEmulation) {
const bool isDrawArgument = enableDrawParametersEmulation && (type == D3D12_INDIRECT_ARGUMENT_TYPE_DRAW || type == D3D12_INDIRECT_ARGUMENT_TYPE_DRAW_INDEXED);

D3D12_INDIRECT_ARGUMENT_DESC indirectArgumentDescs[2] = {};
if (isDrawArgument) {
Expand All @@ -677,9 +721,9 @@ ComPtr<ID3D12CommandSignature> DeviceD3D12::CreateCommandSignature(
indirectArgumentDescs[0].Constant.DestOffsetIn32BitValues = 0;
indirectArgumentDescs[0].Constant.Num32BitValuesToSet = 2;

indirectArgumentDescs[1].Type = indirectArgumentType;
indirectArgumentDescs[1].Type = type;
} else
indirectArgumentDescs[0].Type = indirectArgumentType;
indirectArgumentDescs[0].Type = type;

D3D12_COMMAND_SIGNATURE_DESC commandSignatureDesc = {};
commandSignatureDesc.NumArgumentDescs = isDrawArgument ? 2 : 1;
Expand Down Expand Up @@ -738,10 +782,6 @@ ID3D12CommandSignature* DeviceD3D12::GetDispatchCommandSignature() const {
return m_DispatchCommandSignature.GetInterface();
}

MemoryType DeviceD3D12::GetMemoryType(MemoryLocation memoryLocation, const D3D12_RESOURCE_DESC& resourceDesc) const {
return ::GetMemoryType(memoryLocation, resourceDesc);
}

//================================================================================================================
// DeviceBase
//================================================================================================================
Expand Down
6 changes: 4 additions & 2 deletions Source/D3D12/DeviceD3D12.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ struct DeviceD3D12 final : public DeviceBase {
Result GetDescriptorHandle(D3D12_DESCRIPTOR_HEAP_TYPE type, DescriptorHandle& descriptorHandle);
DescriptorPointerCPU GetDescriptorPointerCPU(const DescriptorHandle& descriptorHandle);
void GetMemoryInfo(MemoryLocation memoryLocation, const D3D12_RESOURCE_DESC& resourceDesc, MemoryDesc& memoryDesc) const;
void GetMemoryInfoForAccelerationStructure(uint64_t size, MemoryDesc& memoryDesc) const;
bool IsDedicated(MemoryType memoryType) const;

ID3D12CommandSignature* GetDrawCommandSignature(uint32_t stride, ID3D12RootSignature* rootSignature);
ID3D12CommandSignature* GetDrawIndexedCommandSignature(uint32_t stride, ID3D12RootSignature* rootSignature);
Expand Down Expand Up @@ -149,9 +151,8 @@ struct DeviceD3D12 final : public DeviceBase {

private:
void FillDesc(bool enableDrawParametersEmulation);
MemoryType GetMemoryType(MemoryLocation memoryLocation, const D3D12_RESOURCE_DESC& resourceDesc) const;
ComPtr<ID3D12CommandSignature> CreateCommandSignature(
D3D12_INDIRECT_ARGUMENT_TYPE indirectArgumentType, uint32_t stride, ID3D12RootSignature* rootSignature, bool enableDrawParametersEmulation = false);
D3D12_INDIRECT_ARGUMENT_TYPE type, uint32_t stride, ID3D12RootSignature* rootSignature, bool enableDrawParametersEmulation = false);

private:
d3d12::Ext m_Ext = {}; // don't sort: destructor must be called last!
Expand All @@ -169,6 +170,7 @@ struct DeviceD3D12 final : public DeviceBase {
CoreInterface m_CoreInterface = {};
uint8_t m_Version = 0;
bool m_IsWrapped = false;
bool m_IsResourceHeapTier2Supported = false;
std::array<Lock, DESCRIPTOR_HEAP_TYPE_NUM> m_FreeDescriptorLocks;
Lock m_DescriptorHeapLock;
Lock m_QueueLock;
Expand Down
6 changes: 5 additions & 1 deletion Source/D3D12/MemoryD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

using namespace nri;

static inline D3D12_HEAP_TYPE GetHeapType(MemoryType memoryType) {
return (D3D12_HEAP_TYPE)(memoryType >> 16);
}

Result MemoryD3D12::Create(const MemoryType memoryType, uint64_t size) {
D3D12_HEAP_DESC heapDesc = {};
heapDesc.SizeInBytes = size;
Expand All @@ -17,7 +21,7 @@ Result MemoryD3D12::Create(const MemoryType memoryType, uint64_t size) {
heapDesc.Alignment = 0;
heapDesc.Flags = (size ? GetHeapFlags(memoryType) : D3D12_HEAP_FLAG_NONE) | D3D12_HEAP_FLAG_CREATE_NOT_ZEROED;

if (!::RequiresDedicatedAllocation(memoryType)) {
if (!m_Device.IsDedicated(memoryType)) {
HRESULT hr = m_Device->CreateHeap(&heapDesc, IID_PPV_ARGS(&m_Heap));
RETURN_ON_BAD_HRESULT(&m_Device, hr, "ID3D12Device::CreateHeap()");
}
Expand Down
44 changes: 0 additions & 44 deletions Source/D3D12/SharedD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,54 +16,10 @@ D3D12_COMMAND_LIST_TYPE nri::GetCommandListType(CommandQueueType commandQueueTyp
return COMMAND_LIST_TYPES[(uint32_t)commandQueueType];
}

constexpr std::array<D3D12_HEAP_TYPE, (uint32_t)MemoryLocation::MAX_NUM> HEAP_TYPES = {
D3D12_HEAP_TYPE_DEFAULT, // DEVICE
#ifdef NRI_USE_AGILITY_SDK
// Prerequisite: D3D12_FEATURE_D3D12_OPTIONS16
D3D12_HEAP_TYPE_GPU_UPLOAD, // DEVICE_UPLOAD
#else
D3D12_HEAP_TYPE_UPLOAD, // DEVICE_UPLOAD (silent fallback to HOST_UPLOAD)
#endif
D3D12_HEAP_TYPE_UPLOAD, // HOST_UPLOAD
D3D12_HEAP_TYPE_READBACK, // HOST_READBACK
};

MemoryType nri::GetMemoryType(D3D12_HEAP_TYPE heapType, D3D12_HEAP_FLAGS heapFlags) {
return ((uint32_t)heapFlags) | ((uint32_t)heapType << 16);
}

MemoryType nri::GetMemoryType(MemoryLocation memoryLocation, const D3D12_RESOURCE_DESC& resourceDesc) {
D3D12_HEAP_TYPE heapType = HEAP_TYPES[(uint32_t)memoryLocation];
D3D12_HEAP_FLAGS heapFlags = D3D12_HEAP_FLAG_NONE;

// Required for Tier 1 resource heaps https://msdn.microsoft.com/en-us/library/windows/desktop/dn986743(v=vs.85).aspx
if (resourceDesc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER)
heapFlags = D3D12_HEAP_FLAG_ALLOW_ONLY_BUFFERS;
else if (resourceDesc.Flags & D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET || resourceDesc.Flags & D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL)
heapFlags = D3D12_HEAP_FLAG_ALLOW_ONLY_RT_DS_TEXTURES;
else
heapFlags = D3D12_HEAP_FLAG_ALLOW_ONLY_NON_RT_DS_TEXTURES;

return GetMemoryType(heapType, heapFlags);
}

D3D12_HEAP_TYPE nri::GetHeapType(MemoryType memoryType) {
return (D3D12_HEAP_TYPE)(memoryType >> 16);
}

D3D12_HEAP_FLAGS nri::GetHeapFlags(MemoryType memoryType) {
return (D3D12_HEAP_FLAGS)(memoryType & 0xffff);
}

bool nri::RequiresDedicatedAllocation(MemoryType memoryType) {
D3D12_HEAP_FLAGS heapFlags = GetHeapFlags(memoryType);

if ((heapFlags & D3D12_HEAP_FLAG_ALLOW_ONLY_RT_DS_TEXTURES) == D3D12_HEAP_FLAG_ALLOW_ONLY_RT_DS_TEXTURES)
return true;

return false;
}

D3D12_RESOURCE_FLAGS nri::GetBufferFlags(BufferUsageBits bufferUsageMask) {
D3D12_RESOURCE_FLAGS flags = D3D12_RESOURCE_FLAG_NONE;

Expand Down
5 changes: 0 additions & 5 deletions Source/D3D12/SharedD3D12.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,13 @@ struct DescriptorHeapDesc {
uint32_t descriptorSize;
};

MemoryType GetMemoryType(D3D12_HEAP_TYPE heapType, D3D12_HEAP_FLAGS heapFlags);
MemoryType GetMemoryType(MemoryLocation memoryLocation, const D3D12_RESOURCE_DESC& resourceDesc);

D3D12_RAYTRACING_ACCELERATION_STRUCTURE_TYPE GetAccelerationStructureType(AccelerationStructureType accelerationStructureType);
D3D12_RAYTRACING_ACCELERATION_STRUCTURE_BUILD_FLAGS GetAccelerationStructureBuildFlags(AccelerationStructureBuildBits accelerationStructureBuildFlags);
D3D12_RAYTRACING_ACCELERATION_STRUCTURE_COPY_MODE GetCopyMode(CopyMode copyMode);

D3D12_RESOURCE_FLAGS GetBufferFlags(BufferUsageBits bufferUsageMask);
D3D12_RESOURCE_FLAGS GetTextureFlags(TextureUsageBits textureUsageMask);

bool RequiresDedicatedAllocation(MemoryType memoryType);
void ConvertGeometryDescs(D3D12_RAYTRACING_GEOMETRY_DESC* geometryDescs, const GeometryObject* geometryObjects, uint32_t geometryObjectNum);
void ConvertRects(D3D12_RECT* rectsD3D12, const Rect* rects, uint32_t rectNum);
bool GetTextureDesc(const TextureD3D12Desc& textureD3D12Desc, TextureDesc& textureDesc);
Expand All @@ -55,7 +51,6 @@ D3D12_TEXTURE_ADDRESS_MODE GetAddressMode(AddressMode addressMode);
D3D12_COMPARISON_FUNC GetComparisonFunc(CompareFunc compareFunc);
D3D12_COMMAND_LIST_TYPE GetCommandListType(CommandQueueType commandQueueType);
D3D12_DESCRIPTOR_HEAP_TYPE GetDescriptorHeapType(DescriptorType descriptorType);
D3D12_HEAP_TYPE GetHeapType(MemoryType memoryType);
D3D12_HEAP_FLAGS GetHeapFlags(MemoryType memoryType);
D3D12_PRIMITIVE_TOPOLOGY_TYPE GetPrimitiveTopologyType(Topology topology);
D3D_PRIMITIVE_TOPOLOGY GetPrimitiveTopology(Topology topology, uint8_t tessControlPointNum);
Expand Down
9 changes: 6 additions & 3 deletions Source/D3D12/TextureD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ Result TextureD3D12::BindMemory(const MemoryD3D12* memory, uint64_t offset) {
if (m_Texture)
return Result::SUCCESS;

const D3D12_HEAP_DESC& heapDesc = memory->GetHeapDesc();
D3D12_CLEAR_VALUE clearValue = {GetDxgiFormat(m_Desc.format).typed};
const D3D12_HEAP_DESC& heapDesc = memory->GetHeapDesc();

// STATE_CREATION ERROR #640: CREATERESOURCEANDHEAP_INVALIDHEAPMISCFLAGS
D3D12_HEAP_FLAGS heapFlagsFixed = heapDesc.Flags & ~(D3D12_HEAP_FLAG_DENY_NON_RT_DS_TEXTURES | D3D12_HEAP_FLAG_DENY_RT_DS_TEXTURES | D3D12_HEAP_FLAG_DENY_BUFFERS);

#ifdef NRI_USE_AGILITY_SDK
if (m_Device.GetVersion() >= 10) {
Expand All @@ -58,7 +61,7 @@ Result TextureD3D12::BindMemory(const MemoryD3D12* memory, uint64_t offset) {
DXGI_FORMAT* castableFormats = nullptr; // TODO: add castable formats, see options12.RelaxedFormatCastingSupported

if (memory->RequiresDedicatedAllocation()) {
HRESULT hr = m_Device->CreateCommittedResource3(&heapDesc.Properties, heapDesc.Flags, &desc1, initialLayout, isRenderableSurface ? &clearValue : nullptr, nullptr,
HRESULT hr = m_Device->CreateCommittedResource3(&heapDesc.Properties, heapFlagsFixed, &desc1, initialLayout, isRenderableSurface ? &clearValue : nullptr, nullptr,
castableFormatNum, castableFormats, IID_PPV_ARGS(&m_Texture));
RETURN_ON_BAD_HRESULT(&m_Device, hr, "ID3D12Device10::CreateCommittedResource3()");
} else {
Expand All @@ -76,7 +79,7 @@ Result TextureD3D12::BindMemory(const MemoryD3D12* memory, uint64_t offset) {

if (memory->RequiresDedicatedAllocation()) {
HRESULT hr = m_Device->CreateCommittedResource(
&heapDesc.Properties, heapDesc.Flags, &desc, D3D12_RESOURCE_STATE_COMMON, isRenderableSurface ? &clearValue : nullptr, IID_PPV_ARGS(&m_Texture));
&heapDesc.Properties, heapFlagsFixed, &desc, D3D12_RESOURCE_STATE_COMMON, isRenderableSurface ? &clearValue : nullptr, IID_PPV_ARGS(&m_Texture));
RETURN_ON_BAD_HRESULT(&m_Device, hr, "ID3D12Device::CreateCommittedResource()");
} else {
HRESULT hr = m_Device->CreatePlacedResource(*memory, offset, &desc, D3D12_RESOURCE_STATE_COMMON, isRenderableSurface ? &clearValue : nullptr, IID_PPV_ARGS(&m_Texture));
Expand Down
Loading

0 comments on commit 5967fc3

Please sign in to comment.