mirror of
https://github.com/jmarshall23/DoomRTX.git
synced 2026-08-19 04:04:54 +02:00
Added modelviewer.
Added neural network code(turned off by default). Lots of editor and rendering fixes.
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
//*********************************************************
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License (MIT).
|
||||
//
|
||||
//*********************************************************
|
||||
|
||||
#ifndef __D3DX12_H__
|
||||
#define __D3DX12_H__
|
||||
|
||||
#include "d3d12.h"
|
||||
|
||||
#if defined( __cplusplus )
|
||||
|
||||
#include "d3dx12_barriers.h"
|
||||
#include "d3dx12_core.h"
|
||||
#include "d3dx12_default.h"
|
||||
#include "d3dx12_pipeline_state_stream.h"
|
||||
#include "d3dx12_render_pass.h"
|
||||
#include "d3dx12_resource_helpers.h"
|
||||
#include "d3dx12_root_signature.h"
|
||||
#include "d3dx12_property_format_table.h"
|
||||
|
||||
#ifndef D3DX12_NO_STATE_OBJECT_HELPERS
|
||||
#include "d3dx12_state_object.h"
|
||||
#endif // !D3DX12_NO_STATE_OBJECT_HELPERS
|
||||
|
||||
#ifndef D3DX12_NO_CHECK_FEATURE_SUPPORT_CLASS
|
||||
#include "d3dx12_check_feature_support.h"
|
||||
#endif // !D3DX12_NO_CHECK_FEATURE_SUPPORT_CLASS
|
||||
|
||||
#endif // defined( __cplusplus )
|
||||
|
||||
#endif //__D3DX12_H__
|
||||
@@ -0,0 +1,192 @@
|
||||
//*********************************************************
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License (MIT).
|
||||
//
|
||||
//*********************************************************
|
||||
|
||||
#ifndef __D3DX12_BARRIERS_H__
|
||||
#define __D3DX12_BARRIERS_H__
|
||||
|
||||
#if defined( __cplusplus )
|
||||
|
||||
#include "d3d12.h"
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
struct CD3DX12_RESOURCE_BARRIER : public D3D12_RESOURCE_BARRIER
|
||||
{
|
||||
CD3DX12_RESOURCE_BARRIER() = default;
|
||||
explicit CD3DX12_RESOURCE_BARRIER(const D3D12_RESOURCE_BARRIER &o) noexcept :
|
||||
D3D12_RESOURCE_BARRIER(o)
|
||||
{}
|
||||
static inline CD3DX12_RESOURCE_BARRIER Transition(
|
||||
_In_ ID3D12Resource* pResource,
|
||||
D3D12_RESOURCE_STATES stateBefore,
|
||||
D3D12_RESOURCE_STATES stateAfter,
|
||||
UINT subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES,
|
||||
D3D12_RESOURCE_BARRIER_FLAGS flags = D3D12_RESOURCE_BARRIER_FLAG_NONE) noexcept
|
||||
{
|
||||
CD3DX12_RESOURCE_BARRIER result = {};
|
||||
D3D12_RESOURCE_BARRIER &barrier = result;
|
||||
result.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
|
||||
result.Flags = flags;
|
||||
barrier.Transition.pResource = pResource;
|
||||
barrier.Transition.StateBefore = stateBefore;
|
||||
barrier.Transition.StateAfter = stateAfter;
|
||||
barrier.Transition.Subresource = subresource;
|
||||
return result;
|
||||
}
|
||||
static inline CD3DX12_RESOURCE_BARRIER Aliasing(
|
||||
_In_opt_ ID3D12Resource* pResourceBefore,
|
||||
_In_opt_ ID3D12Resource* pResourceAfter) noexcept
|
||||
{
|
||||
CD3DX12_RESOURCE_BARRIER result = {};
|
||||
D3D12_RESOURCE_BARRIER &barrier = result;
|
||||
result.Type = D3D12_RESOURCE_BARRIER_TYPE_ALIASING;
|
||||
barrier.Aliasing.pResourceBefore = pResourceBefore;
|
||||
barrier.Aliasing.pResourceAfter = pResourceAfter;
|
||||
return result;
|
||||
}
|
||||
static inline CD3DX12_RESOURCE_BARRIER UAV(
|
||||
_In_opt_ ID3D12Resource* pResource) noexcept
|
||||
{
|
||||
CD3DX12_RESOURCE_BARRIER result = {};
|
||||
D3D12_RESOURCE_BARRIER &barrier = result;
|
||||
result.Type = D3D12_RESOURCE_BARRIER_TYPE_UAV;
|
||||
barrier.UAV.pResource = pResource;
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
#if defined(D3D12_SDK_VERSION) && (D3D12_SDK_VERSION >= 608)
|
||||
|
||||
//================================================================================================
|
||||
// D3DX12 Enhanced Barrier Helpers
|
||||
//================================================================================================
|
||||
|
||||
class CD3DX12_BARRIER_SUBRESOURCE_RANGE : public D3D12_BARRIER_SUBRESOURCE_RANGE
|
||||
{
|
||||
public:
|
||||
CD3DX12_BARRIER_SUBRESOURCE_RANGE() = default;
|
||||
CD3DX12_BARRIER_SUBRESOURCE_RANGE(const D3D12_BARRIER_SUBRESOURCE_RANGE &o) noexcept :
|
||||
D3D12_BARRIER_SUBRESOURCE_RANGE(o)
|
||||
{}
|
||||
explicit CD3DX12_BARRIER_SUBRESOURCE_RANGE(UINT Subresource) noexcept :
|
||||
D3D12_BARRIER_SUBRESOURCE_RANGE{ Subresource, 0, 0, 0, 0, 0 }
|
||||
{}
|
||||
CD3DX12_BARRIER_SUBRESOURCE_RANGE(
|
||||
UINT firstMipLevel,
|
||||
UINT numMips,
|
||||
UINT firstArraySlice,
|
||||
UINT numArraySlices,
|
||||
UINT firstPlane = 0,
|
||||
UINT numPlanes = 1) noexcept :
|
||||
D3D12_BARRIER_SUBRESOURCE_RANGE
|
||||
{
|
||||
firstMipLevel,
|
||||
numMips,
|
||||
firstArraySlice,
|
||||
numArraySlices,
|
||||
firstPlane,
|
||||
numPlanes
|
||||
}
|
||||
{}
|
||||
};
|
||||
|
||||
class CD3DX12_GLOBAL_BARRIER : public D3D12_GLOBAL_BARRIER
|
||||
{
|
||||
public:
|
||||
CD3DX12_GLOBAL_BARRIER() = default;
|
||||
CD3DX12_GLOBAL_BARRIER(const D3D12_GLOBAL_BARRIER &o) noexcept : D3D12_GLOBAL_BARRIER(o){}
|
||||
CD3DX12_GLOBAL_BARRIER(
|
||||
D3D12_BARRIER_SYNC syncBefore,
|
||||
D3D12_BARRIER_SYNC syncAfter,
|
||||
D3D12_BARRIER_ACCESS accessBefore,
|
||||
D3D12_BARRIER_ACCESS accessAfter) noexcept : D3D12_GLOBAL_BARRIER {
|
||||
syncBefore,
|
||||
syncAfter,
|
||||
accessBefore,
|
||||
accessAfter
|
||||
}
|
||||
{}
|
||||
};
|
||||
|
||||
class CD3DX12_BUFFER_BARRIER : public D3D12_BUFFER_BARRIER
|
||||
{
|
||||
public:
|
||||
CD3DX12_BUFFER_BARRIER() = default;
|
||||
CD3DX12_BUFFER_BARRIER(const D3D12_BUFFER_BARRIER &o) noexcept : D3D12_BUFFER_BARRIER(o){}
|
||||
CD3DX12_BUFFER_BARRIER(
|
||||
D3D12_BARRIER_SYNC syncBefore,
|
||||
D3D12_BARRIER_SYNC syncAfter,
|
||||
D3D12_BARRIER_ACCESS accessBefore,
|
||||
D3D12_BARRIER_ACCESS accessAfter,
|
||||
ID3D12Resource *pRes) noexcept : D3D12_BUFFER_BARRIER {
|
||||
syncBefore,
|
||||
syncAfter,
|
||||
accessBefore,
|
||||
accessAfter,
|
||||
pRes,
|
||||
0, ULLONG_MAX
|
||||
}
|
||||
{}
|
||||
};
|
||||
|
||||
class CD3DX12_TEXTURE_BARRIER : public D3D12_TEXTURE_BARRIER
|
||||
{
|
||||
public:
|
||||
CD3DX12_TEXTURE_BARRIER() = default;
|
||||
CD3DX12_TEXTURE_BARRIER(const D3D12_TEXTURE_BARRIER &o) noexcept : D3D12_TEXTURE_BARRIER(o){}
|
||||
CD3DX12_TEXTURE_BARRIER(
|
||||
D3D12_BARRIER_SYNC syncBefore,
|
||||
D3D12_BARRIER_SYNC syncAfter,
|
||||
D3D12_BARRIER_ACCESS accessBefore,
|
||||
D3D12_BARRIER_ACCESS accessAfter,
|
||||
D3D12_BARRIER_LAYOUT layoutBefore,
|
||||
D3D12_BARRIER_LAYOUT layoutAfter,
|
||||
ID3D12Resource *pRes,
|
||||
const D3D12_BARRIER_SUBRESOURCE_RANGE &subresources,
|
||||
D3D12_TEXTURE_BARRIER_FLAGS flag = D3D12_TEXTURE_BARRIER_FLAG_NONE) noexcept : D3D12_TEXTURE_BARRIER {
|
||||
syncBefore,
|
||||
syncAfter,
|
||||
accessBefore,
|
||||
accessAfter,
|
||||
layoutBefore,
|
||||
layoutAfter,
|
||||
pRes,
|
||||
subresources,
|
||||
flag
|
||||
}
|
||||
{}
|
||||
};
|
||||
|
||||
class CD3DX12_BARRIER_GROUP : public D3D12_BARRIER_GROUP
|
||||
{
|
||||
public:
|
||||
CD3DX12_BARRIER_GROUP() = default;
|
||||
CD3DX12_BARRIER_GROUP(const D3D12_BARRIER_GROUP &o) noexcept : D3D12_BARRIER_GROUP(o){}
|
||||
CD3DX12_BARRIER_GROUP(UINT32 numBarriers, const D3D12_BUFFER_BARRIER *pBarriers) noexcept
|
||||
{
|
||||
Type = D3D12_BARRIER_TYPE_BUFFER;
|
||||
NumBarriers = numBarriers;
|
||||
pBufferBarriers = pBarriers;
|
||||
}
|
||||
CD3DX12_BARRIER_GROUP(UINT32 numBarriers, const D3D12_TEXTURE_BARRIER *pBarriers) noexcept
|
||||
{
|
||||
Type = D3D12_BARRIER_TYPE_TEXTURE;
|
||||
NumBarriers = numBarriers;
|
||||
pTextureBarriers = pBarriers;
|
||||
}
|
||||
CD3DX12_BARRIER_GROUP(UINT32 numBarriers, const D3D12_GLOBAL_BARRIER *pBarriers) noexcept
|
||||
{
|
||||
Type = D3D12_BARRIER_TYPE_GLOBAL;
|
||||
NumBarriers = numBarriers;
|
||||
pGlobalBarriers = pBarriers;
|
||||
}
|
||||
};
|
||||
#endif // D3D12_SDK_VERSION >= 608
|
||||
|
||||
|
||||
#endif // defined( __cplusplus )
|
||||
|
||||
#endif // __D3DX12_BARRIERS_H__
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,12 @@
|
||||
//*********************************************************
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License (MIT).
|
||||
//
|
||||
//*********************************************************
|
||||
|
||||
#pragma once
|
||||
|
||||
struct CD3DX12_DEFAULT {};
|
||||
extern const DECLSPEC_SELECTANY CD3DX12_DEFAULT D3D12_DEFAULT;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,128 @@
|
||||
//*********************************************************
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License (MIT).
|
||||
//
|
||||
//*********************************************************
|
||||
#ifndef __D3D12_PROPERTY_LAYOUT_FORMAT_TABLE_H__
|
||||
#define __D3D12_PROPERTY_LAYOUT_FORMAT_TABLE_H__
|
||||
#include "d3d12.h"
|
||||
#define MAP_ALIGN_REQUIREMENT 16 // Map is required to return 16-byte aligned addresses
|
||||
|
||||
struct D3D12_PROPERTY_LAYOUT_FORMAT_TABLE
|
||||
{
|
||||
public:
|
||||
// ----------------------------------------------------------------------------
|
||||
// Information describing everything about a D3D Resource Format
|
||||
// ----------------------------------------------------------------------------
|
||||
typedef struct FORMAT_DETAIL
|
||||
{
|
||||
DXGI_FORMAT DXGIFormat;
|
||||
DXGI_FORMAT ParentFormat;
|
||||
const DXGI_FORMAT* pDefaultFormatCastSet; // This is dependent on FL/driver version, but is here to save a lot of space
|
||||
UINT8 BitsPerComponent[4]; // only used for D3DFTL_PARTIAL_TYPE or FULL_TYPE
|
||||
UINT8 BitsPerUnit;
|
||||
BYTE SRGBFormat : 1;
|
||||
UINT WidthAlignment : 4; // number of texels to align to in a mip level.
|
||||
UINT HeightAlignment : 4; // Top level dimensions must be a multiple of these
|
||||
UINT DepthAlignment : 1; // values.
|
||||
D3D_FORMAT_LAYOUT Layout : 1;
|
||||
D3D_FORMAT_TYPE_LEVEL TypeLevel : 2;
|
||||
D3D_FORMAT_COMPONENT_NAME ComponentName0 : 3; // RED ... only used for D3DFTL_PARTIAL_TYPE or FULL_TYPE
|
||||
D3D_FORMAT_COMPONENT_NAME ComponentName1 : 3; // GREEN ... only used for D3DFTL_PARTIAL_TYPE or FULL_TYPE
|
||||
D3D_FORMAT_COMPONENT_NAME ComponentName2 : 3; // BLUE ... only used for D3DFTL_PARTIAL_TYPE or FULL_TYPE
|
||||
D3D_FORMAT_COMPONENT_NAME ComponentName3 : 3; // ALPHA ... only used for D3DFTL_PARTIAL_TYPE or FULL_TYPE
|
||||
D3D_FORMAT_COMPONENT_INTERPRETATION ComponentInterpretation0 : 3; // only used for D3DFTL_FULL_TYPE
|
||||
D3D_FORMAT_COMPONENT_INTERPRETATION ComponentInterpretation1 : 3; // only used for D3DFTL_FULL_TYPE
|
||||
D3D_FORMAT_COMPONENT_INTERPRETATION ComponentInterpretation2 : 3; // only used for D3DFTL_FULL_TYPE
|
||||
D3D_FORMAT_COMPONENT_INTERPRETATION ComponentInterpretation3 : 3; // only used for D3DFTL_FULL_TYPE
|
||||
bool bDX9VertexOrIndexFormat : 1;
|
||||
bool bDX9TextureFormat : 1;
|
||||
bool bFloatNormFormat : 1;
|
||||
bool bPlanar : 1;
|
||||
bool bYUV : 1;
|
||||
bool bDependantFormatCastSet : 1; // This indicates that the format cast set is dependent on FL/driver version
|
||||
bool bInternal : 1;
|
||||
} FORMAT_DETAIL;
|
||||
|
||||
private:
|
||||
static const FORMAT_DETAIL s_FormatDetail[];
|
||||
static const UINT s_NumFormats;
|
||||
static const LPCSTR s_FormatNames[]; // separate from above structure so it can be compiled out of runtime.
|
||||
public:
|
||||
static UINT GetNumFormats();
|
||||
static const FORMAT_DETAIL* GetFormatTable();
|
||||
static D3D_FEATURE_LEVEL GetHighestDefinedFeatureLevel();
|
||||
|
||||
static DXGI_FORMAT GetFormat (SIZE_T Index);
|
||||
static bool FormatExists (DXGI_FORMAT Format);
|
||||
static bool FormatExistsInHeader (DXGI_FORMAT Format, bool bExternalHeader = true);
|
||||
static UINT GetByteAlignment (DXGI_FORMAT Format);
|
||||
static bool IsBlockCompressFormat (DXGI_FORMAT Format);
|
||||
static LPCSTR GetName (DXGI_FORMAT Format, bool bHideInternalFormats = true);
|
||||
static bool IsSRGBFormat (DXGI_FORMAT Format);
|
||||
static UINT GetBitsPerStencil (DXGI_FORMAT Format);
|
||||
static UINT GetBitsPerDepth (DXGI_FORMAT Format);
|
||||
static void GetFormatReturnTypes (DXGI_FORMAT Format, D3D_FORMAT_COMPONENT_INTERPRETATION* pInterpretations); // return array of 4 components
|
||||
static UINT GetNumComponentsInFormat(DXGI_FORMAT Format);
|
||||
static UINT GetMinNumComponentsInFormats(DXGI_FORMAT FormatA, DXGI_FORMAT FormatB);
|
||||
|
||||
// Converts the sequential component index (range from 0 to GetNumComponentsInFormat()) to
|
||||
// the absolute component index (range 0 to 3).
|
||||
static UINT Sequential2AbsoluteComponentIndex (DXGI_FORMAT Format, UINT SequentialComponentIndex);
|
||||
static bool CanBeCastEvenFullyTyped (DXGI_FORMAT Format, D3D_FEATURE_LEVEL fl);
|
||||
static UINT8 GetAddressingBitsPerAlignedSize (DXGI_FORMAT Format);
|
||||
static DXGI_FORMAT GetParentFormat (DXGI_FORMAT Format);
|
||||
static const DXGI_FORMAT* GetFormatCastSet (DXGI_FORMAT Format);
|
||||
static D3D_FORMAT_LAYOUT GetLayout (DXGI_FORMAT Format);
|
||||
static D3D_FORMAT_TYPE_LEVEL GetTypeLevel (DXGI_FORMAT Format);
|
||||
static UINT GetBitsPerUnit (DXGI_FORMAT Format);
|
||||
static UINT GetBitsPerUnitThrow (DXGI_FORMAT Format);
|
||||
static UINT GetBitsPerElement (DXGI_FORMAT Format); // Legacy function used to support D3D10on9 only. Do not use.
|
||||
static UINT GetWidthAlignment (DXGI_FORMAT Format);
|
||||
static UINT GetHeightAlignment (DXGI_FORMAT Format);
|
||||
static UINT GetDepthAlignment (DXGI_FORMAT Format);
|
||||
static BOOL Planar (DXGI_FORMAT Format);
|
||||
static BOOL NonOpaquePlanar (DXGI_FORMAT Format);
|
||||
static BOOL YUV (DXGI_FORMAT Format);
|
||||
static BOOL Opaque (DXGI_FORMAT Format);
|
||||
static bool FamilySupportsStencil (DXGI_FORMAT Format);
|
||||
static UINT NonOpaquePlaneCount (DXGI_FORMAT Format);
|
||||
static BOOL DX9VertexOrIndexFormat (DXGI_FORMAT Format);
|
||||
static BOOL DX9TextureFormat (DXGI_FORMAT Format);
|
||||
static BOOL FloatNormTextureFormat (DXGI_FORMAT Format);
|
||||
static bool DepthOnlyFormat (DXGI_FORMAT format);
|
||||
static UINT8 GetPlaneCount (DXGI_FORMAT Format);
|
||||
static bool MotionEstimatorAllowedInputFormat (DXGI_FORMAT Format);
|
||||
static bool SupportsSamplerFeedback (DXGI_FORMAT Format);
|
||||
static bool DecodeHistogramAllowedForOutputFormatSupport(DXGI_FORMAT Format);
|
||||
static UINT8 GetPlaneSliceFromViewFormat (DXGI_FORMAT ResourceFormat, DXGI_FORMAT ViewFormat);
|
||||
static bool FloatAndNotFloatFormats (DXGI_FORMAT FormatA, DXGI_FORMAT FormatB);
|
||||
static bool SNORMAndUNORMFormats (DXGI_FORMAT FormatA, DXGI_FORMAT FormatB);
|
||||
static bool ValidCastToR32UAV (DXGI_FORMAT from, DXGI_FORMAT to);
|
||||
static bool IsSupportedTextureDisplayableFormat (DXGI_FORMAT, bool bMediaFormatOnly);
|
||||
static D3D_FORMAT_COMPONENT_INTERPRETATION GetFormatComponentInterpretation (DXGI_FORMAT Format, UINT AbsoluteComponentIndex);
|
||||
static UINT GetBitsPerComponent (DXGI_FORMAT Format, UINT AbsoluteComponentIndex);
|
||||
static D3D_FORMAT_COMPONENT_NAME GetComponentName (DXGI_FORMAT Format, UINT AbsoluteComponentIndex);
|
||||
static HRESULT CalculateExtraPlanarRows (DXGI_FORMAT format, UINT plane0Height, _Out_ UINT& totalHeight);
|
||||
static HRESULT CalculateMinimumRowMajorRowPitch (DXGI_FORMAT Format, UINT Width, _Out_ UINT& RowPitch);
|
||||
static HRESULT CalculateMinimumRowMajorSlicePitch (DXGI_FORMAT Format, UINT ContextBasedRowPitch, UINT Height, _Out_ UINT& SlicePitch);
|
||||
static void GetYCbCrChromaSubsampling (DXGI_FORMAT Format, _Out_ UINT& HorizontalSubsampling, _Out_ UINT& VerticalSubsampling);
|
||||
|
||||
static HRESULT CalculateResourceSize (UINT width, UINT height, UINT depth, DXGI_FORMAT format, UINT mipLevels, UINT subresources, _Out_ SIZE_T& totalByteSize, _Out_writes_opt_(subresources) D3D12_MEMCPY_DEST* pDst = nullptr);
|
||||
static void GetTileShape (D3D12_TILE_SHAPE* pTileShape, DXGI_FORMAT Format, D3D12_RESOURCE_DIMENSION Dimension, UINT SampleCount);
|
||||
static void Get4KTileShape (D3D12_TILE_SHAPE* pTileShape, DXGI_FORMAT Format, D3D12_RESOURCE_DIMENSION Dimension, UINT SampleCount);
|
||||
static void GetMipDimensions (UINT8 mipSlice, _Inout_ UINT64* pWidth, _Inout_opt_ UINT64* pHeight = nullptr, _Inout_opt_ UINT64* pDepth = nullptr);
|
||||
static void GetPlaneSubsampledSizeAndFormatForCopyableLayout(UINT PlaneSlice, DXGI_FORMAT Format, UINT Width, UINT Height, _Out_ DXGI_FORMAT& PlaneFormat, _Out_ UINT& MinPlanePitchWidth, _Out_ UINT& PlaneWidth, _Out_ UINT& PlaneHeight);
|
||||
|
||||
static UINT GetDetailTableIndex (DXGI_FORMAT Format);
|
||||
static UINT GetDetailTableIndexNoThrow (DXGI_FORMAT Format);
|
||||
static UINT GetDetailTableIndexThrow (DXGI_FORMAT Format);
|
||||
static bool SupportsDepth (DXGI_FORMAT Format);
|
||||
static bool SupportsStencil (DXGI_FORMAT Format);
|
||||
private:
|
||||
static const FORMAT_DETAIL* GetFormatDetail (DXGI_FORMAT Format);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,105 @@
|
||||
//*********************************************************
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License (MIT).
|
||||
//
|
||||
//*********************************************************
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __cplusplus
|
||||
#error D3DX12 requires C++
|
||||
#endif
|
||||
|
||||
#include "d3d12.h"
|
||||
#if defined(D3D12_SDK_VERSION) && (D3D12_SDK_VERSION >= 609)
|
||||
inline bool operator==(const D3D12_RENDER_PASS_BEGINNING_ACCESS_PRESERVE_LOCAL_PARAMETERS& a, const D3D12_RENDER_PASS_ENDING_ACCESS_PRESERVE_LOCAL_PARAMETERS& b) noexcept
|
||||
{
|
||||
return ((a.AdditionalWidth == b.AdditionalWidth) && (a.AdditionalHeight == b.AdditionalHeight));
|
||||
}
|
||||
|
||||
inline bool operator==(const D3D12_RENDER_PASS_BEGINNING_ACCESS_PRESERVE_LOCAL_PARAMETERS& a, const D3D12_RENDER_PASS_BEGINNING_ACCESS_PRESERVE_LOCAL_PARAMETERS& b) noexcept
|
||||
{
|
||||
return ((a.AdditionalWidth == b.AdditionalWidth) && (a.AdditionalHeight == b.AdditionalHeight));
|
||||
}
|
||||
|
||||
inline bool operator==(const D3D12_RENDER_PASS_ENDING_ACCESS_PRESERVE_LOCAL_PARAMETERS& a, const D3D12_RENDER_PASS_ENDING_ACCESS_PRESERVE_LOCAL_PARAMETERS& b) noexcept
|
||||
{
|
||||
return ((a.AdditionalWidth == b.AdditionalWidth) && (a.AdditionalHeight == b.AdditionalHeight));
|
||||
}
|
||||
#endif
|
||||
|
||||
inline bool operator==( const D3D12_RENDER_PASS_BEGINNING_ACCESS_CLEAR_PARAMETERS &a, const D3D12_RENDER_PASS_BEGINNING_ACCESS_CLEAR_PARAMETERS &b) noexcept
|
||||
{
|
||||
return a.ClearValue == b.ClearValue;
|
||||
}
|
||||
|
||||
inline bool operator==( const D3D12_RENDER_PASS_ENDING_ACCESS_RESOLVE_PARAMETERS &a, const D3D12_RENDER_PASS_ENDING_ACCESS_RESOLVE_PARAMETERS &b) noexcept
|
||||
{
|
||||
if (a.pSrcResource != b.pSrcResource) return false;
|
||||
if (a.pDstResource != b.pDstResource) return false;
|
||||
if (a.SubresourceCount != b.SubresourceCount) return false;
|
||||
if (a.Format != b.Format) return false;
|
||||
if (a.ResolveMode != b.ResolveMode) return false;
|
||||
if (a.PreserveResolveSource != b.PreserveResolveSource) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool operator==( const D3D12_RENDER_PASS_BEGINNING_ACCESS &a, const D3D12_RENDER_PASS_BEGINNING_ACCESS &b) noexcept
|
||||
{
|
||||
if (a.Type != b.Type) return false;
|
||||
switch (a.Type)
|
||||
{
|
||||
case D3D12_RENDER_PASS_BEGINNING_ACCESS_TYPE_CLEAR:
|
||||
if (!(a.Clear == b.Clear)) return false;
|
||||
break;
|
||||
#if defined(D3D12_SDK_VERSION) && (D3D12_SDK_VERSION >= 609)
|
||||
case D3D12_RENDER_PASS_BEGINNING_ACCESS_TYPE_PRESERVE_LOCAL_RENDER:
|
||||
case D3D12_RENDER_PASS_BEGINNING_ACCESS_TYPE_PRESERVE_LOCAL_SRV:
|
||||
case D3D12_RENDER_PASS_BEGINNING_ACCESS_TYPE_PRESERVE_LOCAL_UAV:
|
||||
if (!(a.PreserveLocal == b.PreserveLocal)) return false;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool operator==(const D3D12_RENDER_PASS_ENDING_ACCESS& a, const D3D12_RENDER_PASS_ENDING_ACCESS& b) noexcept
|
||||
{
|
||||
if (a.Type != b.Type) return false;
|
||||
switch (a.Type)
|
||||
{
|
||||
case D3D12_RENDER_PASS_ENDING_ACCESS_TYPE_RESOLVE:
|
||||
if (!(a.Resolve == b.Resolve)) return false;
|
||||
break;
|
||||
#if defined(D3D12_SDK_VERSION) && (D3D12_SDK_VERSION >= 609)
|
||||
case D3D12_RENDER_PASS_ENDING_ACCESS_TYPE_PRESERVE_LOCAL_RENDER:
|
||||
case D3D12_RENDER_PASS_ENDING_ACCESS_TYPE_PRESERVE_LOCAL_SRV:
|
||||
case D3D12_RENDER_PASS_ENDING_ACCESS_TYPE_PRESERVE_LOCAL_UAV:
|
||||
if (!(a.PreserveLocal == b.PreserveLocal)) return false;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool operator==( const D3D12_RENDER_PASS_RENDER_TARGET_DESC &a, const D3D12_RENDER_PASS_RENDER_TARGET_DESC &b) noexcept
|
||||
{
|
||||
if (a.cpuDescriptor.ptr != b.cpuDescriptor.ptr) return false;
|
||||
if (!(a.BeginningAccess == b.BeginningAccess)) return false;
|
||||
if (!(a.EndingAccess == b.EndingAccess)) return false;
|
||||
return true;
|
||||
}
|
||||
inline bool operator==( const D3D12_RENDER_PASS_DEPTH_STENCIL_DESC &a, const D3D12_RENDER_PASS_DEPTH_STENCIL_DESC &b) noexcept
|
||||
{
|
||||
if (a.cpuDescriptor.ptr != b.cpuDescriptor.ptr) return false;
|
||||
if (!(a.DepthBeginningAccess == b.DepthBeginningAccess)) return false;
|
||||
if (!(a.StencilBeginningAccess == b.StencilBeginningAccess)) return false;
|
||||
if (!(a.DepthEndingAccess == b.DepthEndingAccess)) return false;
|
||||
if (!(a.StencilEndingAccess == b.StencilEndingAccess)) return false;
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,611 @@
|
||||
//*********************************************************
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License (MIT).
|
||||
//
|
||||
//*********************************************************
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __cplusplus
|
||||
#error D3DX12 requires C++
|
||||
#endif
|
||||
|
||||
#include "d3dx12_property_format_table.h"
|
||||
#include "d3d12.h"
|
||||
#include "d3dx12_core.h"
|
||||
//------------------------------------------------------------------------------------------------
|
||||
template <typename T, typename U, typename V>
|
||||
inline void D3D12DecomposeSubresource( UINT Subresource, UINT MipLevels, UINT ArraySize, _Out_ T& MipSlice, _Out_ U& ArraySlice, _Out_ V& PlaneSlice ) noexcept
|
||||
{
|
||||
MipSlice = static_cast<T>(Subresource % MipLevels);
|
||||
ArraySlice = static_cast<U>((Subresource / MipLevels) % ArraySize);
|
||||
PlaneSlice = static_cast<V>(Subresource / (MipLevels * ArraySize));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
// Row-by-row memcpy
|
||||
inline void MemcpySubresource(
|
||||
_In_ const D3D12_MEMCPY_DEST* pDest,
|
||||
_In_ const D3D12_SUBRESOURCE_DATA* pSrc,
|
||||
SIZE_T RowSizeInBytes,
|
||||
UINT NumRows,
|
||||
UINT NumSlices) noexcept
|
||||
{
|
||||
for (UINT z = 0; z < NumSlices; ++z)
|
||||
{
|
||||
auto pDestSlice = static_cast<BYTE*>(pDest->pData) + pDest->SlicePitch * z;
|
||||
auto pSrcSlice = static_cast<const BYTE*>(pSrc->pData) + pSrc->SlicePitch * LONG_PTR(z);
|
||||
for (UINT y = 0; y < NumRows; ++y)
|
||||
{
|
||||
memcpy(pDestSlice + pDest->RowPitch * y,
|
||||
pSrcSlice + pSrc->RowPitch * LONG_PTR(y),
|
||||
RowSizeInBytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
// Row-by-row memcpy
|
||||
inline void MemcpySubresource(
|
||||
_In_ const D3D12_MEMCPY_DEST* pDest,
|
||||
_In_ const void* pResourceData,
|
||||
_In_ const D3D12_SUBRESOURCE_INFO* pSrc,
|
||||
SIZE_T RowSizeInBytes,
|
||||
UINT NumRows,
|
||||
UINT NumSlices) noexcept
|
||||
{
|
||||
for (UINT z = 0; z < NumSlices; ++z)
|
||||
{
|
||||
auto pDestSlice = static_cast<BYTE*>(pDest->pData) + pDest->SlicePitch * z;
|
||||
auto pSrcSlice = (static_cast<const BYTE*>(pResourceData) + pSrc->Offset) + pSrc->DepthPitch * ULONG_PTR(z);
|
||||
for (UINT y = 0; y < NumRows; ++y)
|
||||
{
|
||||
memcpy(pDestSlice + pDest->RowPitch * y,
|
||||
pSrcSlice + pSrc->RowPitch * ULONG_PTR(y),
|
||||
RowSizeInBytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
// Returns required size of a buffer to be used for data upload
|
||||
inline UINT64 GetRequiredIntermediateSize(
|
||||
_In_ ID3D12Resource* pDestinationResource,
|
||||
_In_range_(0,D3D12_REQ_SUBRESOURCES) UINT FirstSubresource,
|
||||
_In_range_(0,D3D12_REQ_SUBRESOURCES-FirstSubresource) UINT NumSubresources) noexcept
|
||||
{
|
||||
#if defined(_MSC_VER) || !defined(_WIN32)
|
||||
const auto Desc = pDestinationResource->GetDesc();
|
||||
#else
|
||||
D3D12_RESOURCE_DESC tmpDesc;
|
||||
const auto& Desc = *pDestinationResource->GetDesc(&tmpDesc);
|
||||
#endif
|
||||
UINT64 RequiredSize = 0;
|
||||
|
||||
ID3D12Device* pDevice = nullptr;
|
||||
pDestinationResource->GetDevice(IID_ID3D12Device, reinterpret_cast<void**>(&pDevice));
|
||||
pDevice->GetCopyableFootprints(&Desc, FirstSubresource, NumSubresources, 0, nullptr, nullptr, nullptr, &RequiredSize);
|
||||
pDevice->Release();
|
||||
|
||||
return RequiredSize;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
// All arrays must be populated (e.g. by calling GetCopyableFootprints)
|
||||
inline UINT64 UpdateSubresources(
|
||||
_In_ ID3D12GraphicsCommandList* pCmdList,
|
||||
_In_ ID3D12Resource* pDestinationResource,
|
||||
_In_ ID3D12Resource* pIntermediate,
|
||||
_In_range_(0,D3D12_REQ_SUBRESOURCES) UINT FirstSubresource,
|
||||
_In_range_(0,D3D12_REQ_SUBRESOURCES-FirstSubresource) UINT NumSubresources,
|
||||
UINT64 RequiredSize,
|
||||
_In_reads_(NumSubresources) const D3D12_PLACED_SUBRESOURCE_FOOTPRINT* pLayouts,
|
||||
_In_reads_(NumSubresources) const UINT* pNumRows,
|
||||
_In_reads_(NumSubresources) const UINT64* pRowSizesInBytes,
|
||||
_In_reads_(NumSubresources) const D3D12_SUBRESOURCE_DATA* pSrcData) noexcept
|
||||
{
|
||||
// Minor validation
|
||||
#if defined(_MSC_VER) || !defined(_WIN32)
|
||||
const auto IntermediateDesc = pIntermediate->GetDesc();
|
||||
const auto DestinationDesc = pDestinationResource->GetDesc();
|
||||
#else
|
||||
D3D12_RESOURCE_DESC tmpDesc1, tmpDesc2;
|
||||
const auto& IntermediateDesc = *pIntermediate->GetDesc(&tmpDesc1);
|
||||
const auto& DestinationDesc = *pDestinationResource->GetDesc(&tmpDesc2);
|
||||
#endif
|
||||
if (IntermediateDesc.Dimension != D3D12_RESOURCE_DIMENSION_BUFFER ||
|
||||
IntermediateDesc.Width < RequiredSize + pLayouts[0].Offset ||
|
||||
RequiredSize > SIZE_T(-1) ||
|
||||
(DestinationDesc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER &&
|
||||
(FirstSubresource != 0 || NumSubresources != 1)))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
BYTE* pData;
|
||||
HRESULT hr = pIntermediate->Map(0, nullptr, reinterpret_cast<void**>(&pData));
|
||||
if (FAILED(hr))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (UINT i = 0; i < NumSubresources; ++i)
|
||||
{
|
||||
if (pRowSizesInBytes[i] > SIZE_T(-1)) return 0;
|
||||
D3D12_MEMCPY_DEST DestData = { pData + pLayouts[i].Offset, pLayouts[i].Footprint.RowPitch, SIZE_T(pLayouts[i].Footprint.RowPitch) * SIZE_T(pNumRows[i]) };
|
||||
MemcpySubresource(&DestData, &pSrcData[i], static_cast<SIZE_T>(pRowSizesInBytes[i]), pNumRows[i], pLayouts[i].Footprint.Depth);
|
||||
}
|
||||
pIntermediate->Unmap(0, nullptr);
|
||||
|
||||
if (DestinationDesc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER)
|
||||
{
|
||||
pCmdList->CopyBufferRegion(
|
||||
pDestinationResource, 0, pIntermediate, pLayouts[0].Offset, pLayouts[0].Footprint.Width);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (UINT i = 0; i < NumSubresources; ++i)
|
||||
{
|
||||
const CD3DX12_TEXTURE_COPY_LOCATION Dst(pDestinationResource, i + FirstSubresource);
|
||||
const CD3DX12_TEXTURE_COPY_LOCATION Src(pIntermediate, pLayouts[i]);
|
||||
pCmdList->CopyTextureRegion(&Dst, 0, 0, 0, &Src, nullptr);
|
||||
}
|
||||
}
|
||||
return RequiredSize;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
// All arrays must be populated (e.g. by calling GetCopyableFootprints)
|
||||
inline UINT64 UpdateSubresources(
|
||||
_In_ ID3D12GraphicsCommandList* pCmdList,
|
||||
_In_ ID3D12Resource* pDestinationResource,
|
||||
_In_ ID3D12Resource* pIntermediate,
|
||||
_In_range_(0,D3D12_REQ_SUBRESOURCES) UINT FirstSubresource,
|
||||
_In_range_(0,D3D12_REQ_SUBRESOURCES-FirstSubresource) UINT NumSubresources,
|
||||
UINT64 RequiredSize,
|
||||
_In_reads_(NumSubresources) const D3D12_PLACED_SUBRESOURCE_FOOTPRINT* pLayouts,
|
||||
_In_reads_(NumSubresources) const UINT* pNumRows,
|
||||
_In_reads_(NumSubresources) const UINT64* pRowSizesInBytes,
|
||||
_In_ const void* pResourceData,
|
||||
_In_reads_(NumSubresources) const D3D12_SUBRESOURCE_INFO* pSrcData) noexcept
|
||||
{
|
||||
// Minor validation
|
||||
#if defined(_MSC_VER) || !defined(_WIN32)
|
||||
const auto IntermediateDesc = pIntermediate->GetDesc();
|
||||
const auto DestinationDesc = pDestinationResource->GetDesc();
|
||||
#else
|
||||
D3D12_RESOURCE_DESC tmpDesc1, tmpDesc2;
|
||||
const auto& IntermediateDesc = *pIntermediate->GetDesc(&tmpDesc1);
|
||||
const auto& DestinationDesc = *pDestinationResource->GetDesc(&tmpDesc2);
|
||||
#endif
|
||||
if (IntermediateDesc.Dimension != D3D12_RESOURCE_DIMENSION_BUFFER ||
|
||||
IntermediateDesc.Width < RequiredSize + pLayouts[0].Offset ||
|
||||
RequiredSize > SIZE_T(-1) ||
|
||||
(DestinationDesc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER &&
|
||||
(FirstSubresource != 0 || NumSubresources != 1)))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
BYTE* pData;
|
||||
HRESULT hr = pIntermediate->Map(0, nullptr, reinterpret_cast<void**>(&pData));
|
||||
if (FAILED(hr))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (UINT i = 0; i < NumSubresources; ++i)
|
||||
{
|
||||
if (pRowSizesInBytes[i] > SIZE_T(-1)) return 0;
|
||||
D3D12_MEMCPY_DEST DestData = { pData + pLayouts[i].Offset, pLayouts[i].Footprint.RowPitch, SIZE_T(pLayouts[i].Footprint.RowPitch) * SIZE_T(pNumRows[i]) };
|
||||
MemcpySubresource(&DestData, pResourceData, &pSrcData[i], static_cast<SIZE_T>(pRowSizesInBytes[i]), pNumRows[i], pLayouts[i].Footprint.Depth);
|
||||
}
|
||||
pIntermediate->Unmap(0, nullptr);
|
||||
|
||||
if (DestinationDesc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER)
|
||||
{
|
||||
pCmdList->CopyBufferRegion(
|
||||
pDestinationResource, 0, pIntermediate, pLayouts[0].Offset, pLayouts[0].Footprint.Width);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (UINT i = 0; i < NumSubresources; ++i)
|
||||
{
|
||||
const CD3DX12_TEXTURE_COPY_LOCATION Dst(pDestinationResource, i + FirstSubresource);
|
||||
const CD3DX12_TEXTURE_COPY_LOCATION Src(pIntermediate, pLayouts[i]);
|
||||
pCmdList->CopyTextureRegion(&Dst, 0, 0, 0, &Src, nullptr);
|
||||
}
|
||||
}
|
||||
return RequiredSize;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
// Heap-allocating UpdateSubresources implementation
|
||||
inline UINT64 UpdateSubresources(
|
||||
_In_ ID3D12GraphicsCommandList* pCmdList,
|
||||
_In_ ID3D12Resource* pDestinationResource,
|
||||
_In_ ID3D12Resource* pIntermediate,
|
||||
UINT64 IntermediateOffset,
|
||||
_In_range_(0,D3D12_REQ_SUBRESOURCES) UINT FirstSubresource,
|
||||
_In_range_(0,D3D12_REQ_SUBRESOURCES-FirstSubresource) UINT NumSubresources,
|
||||
_In_reads_(NumSubresources) const D3D12_SUBRESOURCE_DATA* pSrcData) noexcept
|
||||
{
|
||||
UINT64 RequiredSize = 0;
|
||||
const auto MemToAlloc = static_cast<UINT64>(sizeof(D3D12_PLACED_SUBRESOURCE_FOOTPRINT) + sizeof(UINT) + sizeof(UINT64)) * NumSubresources;
|
||||
if (MemToAlloc > SIZE_MAX)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
void* pMem = HeapAlloc(GetProcessHeap(), 0, static_cast<SIZE_T>(MemToAlloc));
|
||||
if (pMem == nullptr)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
auto pLayouts = static_cast<D3D12_PLACED_SUBRESOURCE_FOOTPRINT*>(pMem);
|
||||
auto pRowSizesInBytes = reinterpret_cast<UINT64*>(pLayouts + NumSubresources);
|
||||
auto pNumRows = reinterpret_cast<UINT*>(pRowSizesInBytes + NumSubresources);
|
||||
|
||||
#if defined(_MSC_VER) || !defined(_WIN32)
|
||||
const auto Desc = pDestinationResource->GetDesc();
|
||||
#else
|
||||
D3D12_RESOURCE_DESC tmpDesc;
|
||||
const auto& Desc = *pDestinationResource->GetDesc(&tmpDesc);
|
||||
#endif
|
||||
ID3D12Device* pDevice = nullptr;
|
||||
pDestinationResource->GetDevice(IID_ID3D12Device, reinterpret_cast<void**>(&pDevice));
|
||||
pDevice->GetCopyableFootprints(&Desc, FirstSubresource, NumSubresources, IntermediateOffset, pLayouts, pNumRows, pRowSizesInBytes, &RequiredSize);
|
||||
pDevice->Release();
|
||||
|
||||
const UINT64 Result = UpdateSubresources(pCmdList, pDestinationResource, pIntermediate, FirstSubresource, NumSubresources, RequiredSize, pLayouts, pNumRows, pRowSizesInBytes, pSrcData);
|
||||
HeapFree(GetProcessHeap(), 0, pMem);
|
||||
return Result;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
// Heap-allocating UpdateSubresources implementation
|
||||
inline UINT64 UpdateSubresources(
|
||||
_In_ ID3D12GraphicsCommandList* pCmdList,
|
||||
_In_ ID3D12Resource* pDestinationResource,
|
||||
_In_ ID3D12Resource* pIntermediate,
|
||||
UINT64 IntermediateOffset,
|
||||
_In_range_(0,D3D12_REQ_SUBRESOURCES) UINT FirstSubresource,
|
||||
_In_range_(0,D3D12_REQ_SUBRESOURCES-FirstSubresource) UINT NumSubresources,
|
||||
_In_ const void* pResourceData,
|
||||
_In_reads_(NumSubresources) const D3D12_SUBRESOURCE_INFO* pSrcData) noexcept
|
||||
{
|
||||
UINT64 RequiredSize = 0;
|
||||
const auto MemToAlloc = static_cast<UINT64>(sizeof(D3D12_PLACED_SUBRESOURCE_FOOTPRINT) + sizeof(UINT) + sizeof(UINT64)) * NumSubresources;
|
||||
if (MemToAlloc > SIZE_MAX)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
void* pMem = HeapAlloc(GetProcessHeap(), 0, static_cast<SIZE_T>(MemToAlloc));
|
||||
if (pMem == nullptr)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
auto pLayouts = static_cast<D3D12_PLACED_SUBRESOURCE_FOOTPRINT*>(pMem);
|
||||
auto pRowSizesInBytes = reinterpret_cast<UINT64*>(pLayouts + NumSubresources);
|
||||
auto pNumRows = reinterpret_cast<UINT*>(pRowSizesInBytes + NumSubresources);
|
||||
|
||||
#if defined(_MSC_VER) || !defined(_WIN32)
|
||||
const auto Desc = pDestinationResource->GetDesc();
|
||||
#else
|
||||
D3D12_RESOURCE_DESC tmpDesc;
|
||||
const auto& Desc = *pDestinationResource->GetDesc(&tmpDesc);
|
||||
#endif
|
||||
ID3D12Device* pDevice = nullptr;
|
||||
pDestinationResource->GetDevice(IID_ID3D12Device, reinterpret_cast<void**>(&pDevice));
|
||||
pDevice->GetCopyableFootprints(&Desc, FirstSubresource, NumSubresources, IntermediateOffset, pLayouts, pNumRows, pRowSizesInBytes, &RequiredSize);
|
||||
pDevice->Release();
|
||||
|
||||
const UINT64 Result = UpdateSubresources(pCmdList, pDestinationResource, pIntermediate, FirstSubresource, NumSubresources, RequiredSize, pLayouts, pNumRows, pRowSizesInBytes, pResourceData, pSrcData);
|
||||
HeapFree(GetProcessHeap(), 0, pMem);
|
||||
return Result;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
// Stack-allocating UpdateSubresources implementation
|
||||
template <UINT MaxSubresources>
|
||||
inline UINT64 UpdateSubresources(
|
||||
_In_ ID3D12GraphicsCommandList* pCmdList,
|
||||
_In_ ID3D12Resource* pDestinationResource,
|
||||
_In_ ID3D12Resource* pIntermediate,
|
||||
UINT64 IntermediateOffset,
|
||||
_In_range_(0,MaxSubresources) UINT FirstSubresource,
|
||||
_In_range_(1,MaxSubresources-FirstSubresource) UINT NumSubresources,
|
||||
_In_reads_(NumSubresources) const D3D12_SUBRESOURCE_DATA* pSrcData) noexcept
|
||||
{
|
||||
UINT64 RequiredSize = 0;
|
||||
D3D12_PLACED_SUBRESOURCE_FOOTPRINT Layouts[MaxSubresources];
|
||||
UINT NumRows[MaxSubresources];
|
||||
UINT64 RowSizesInBytes[MaxSubresources];
|
||||
|
||||
#if defined(_MSC_VER) || !defined(_WIN32)
|
||||
const auto Desc = pDestinationResource->GetDesc();
|
||||
#else
|
||||
D3D12_RESOURCE_DESC tmpDesc;
|
||||
const auto& Desc = *pDestinationResource->GetDesc(&tmpDesc);
|
||||
#endif
|
||||
ID3D12Device* pDevice = nullptr;
|
||||
pDestinationResource->GetDevice(IID_ID3D12Device, reinterpret_cast<void**>(&pDevice));
|
||||
pDevice->GetCopyableFootprints(&Desc, FirstSubresource, NumSubresources, IntermediateOffset, Layouts, NumRows, RowSizesInBytes, &RequiredSize);
|
||||
pDevice->Release();
|
||||
|
||||
return UpdateSubresources(pCmdList, pDestinationResource, pIntermediate, FirstSubresource, NumSubresources, RequiredSize, Layouts, NumRows, RowSizesInBytes, pSrcData);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
// Stack-allocating UpdateSubresources implementation
|
||||
template <UINT MaxSubresources>
|
||||
inline UINT64 UpdateSubresources(
|
||||
_In_ ID3D12GraphicsCommandList* pCmdList,
|
||||
_In_ ID3D12Resource* pDestinationResource,
|
||||
_In_ ID3D12Resource* pIntermediate,
|
||||
UINT64 IntermediateOffset,
|
||||
_In_range_(0,MaxSubresources) UINT FirstSubresource,
|
||||
_In_range_(1,MaxSubresources-FirstSubresource) UINT NumSubresources,
|
||||
_In_ const void* pResourceData,
|
||||
_In_reads_(NumSubresources) const D3D12_SUBRESOURCE_INFO* pSrcData) noexcept
|
||||
{
|
||||
UINT64 RequiredSize = 0;
|
||||
D3D12_PLACED_SUBRESOURCE_FOOTPRINT Layouts[MaxSubresources];
|
||||
UINT NumRows[MaxSubresources];
|
||||
UINT64 RowSizesInBytes[MaxSubresources];
|
||||
|
||||
#if defined(_MSC_VER) || !defined(_WIN32)
|
||||
const auto Desc = pDestinationResource->GetDesc();
|
||||
#else
|
||||
D3D12_RESOURCE_DESC tmpDesc;
|
||||
const auto& Desc = *pDestinationResource->GetDesc(&tmpDesc);
|
||||
#endif
|
||||
ID3D12Device* pDevice = nullptr;
|
||||
pDestinationResource->GetDevice(IID_ID3D12Device, reinterpret_cast<void**>(&pDevice));
|
||||
pDevice->GetCopyableFootprints(&Desc, FirstSubresource, NumSubresources, IntermediateOffset, Layouts, NumRows, RowSizesInBytes, &RequiredSize);
|
||||
pDevice->Release();
|
||||
|
||||
return UpdateSubresources(pCmdList, pDestinationResource, pIntermediate, FirstSubresource, NumSubresources, RequiredSize, Layouts, NumRows, RowSizesInBytes, pResourceData, pSrcData);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
constexpr bool D3D12IsLayoutOpaque( D3D12_TEXTURE_LAYOUT Layout ) noexcept
|
||||
{ return Layout == D3D12_TEXTURE_LAYOUT_UNKNOWN || Layout == D3D12_TEXTURE_LAYOUT_64KB_UNDEFINED_SWIZZLE; }
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
template< typename T >
|
||||
inline T D3DX12Align(T uValue, T uAlign)
|
||||
{
|
||||
// Assert power of 2 alignment
|
||||
D3DX12_ASSERT(0 == (uAlign & (uAlign - 1)));
|
||||
T uMask = uAlign - 1;
|
||||
T uResult = (uValue + uMask) & ~uMask;
|
||||
D3DX12_ASSERT(uResult >= uValue);
|
||||
D3DX12_ASSERT(0 == (uResult % uAlign));
|
||||
return uResult;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
template< typename T >
|
||||
inline T D3DX12AlignAtLeast(T uValue, T uAlign)
|
||||
{
|
||||
T aligned = D3DX12Align(uValue, uAlign);
|
||||
return aligned > uAlign ? aligned : uAlign;
|
||||
}
|
||||
|
||||
inline const CD3DX12_RESOURCE_DESC1* D3DX12ConditionallyExpandAPIDesc(
|
||||
D3D12_RESOURCE_DESC1& LclDesc,
|
||||
const D3D12_RESOURCE_DESC1* pDesc,
|
||||
const bool tightAlignmentSupported = false,
|
||||
const bool alignAsCommitted = false)
|
||||
{
|
||||
return D3DX12ConditionallyExpandAPIDesc(static_cast<CD3DX12_RESOURCE_DESC1&>(LclDesc), static_cast<const CD3DX12_RESOURCE_DESC1*>(pDesc), tightAlignmentSupported, alignAsCommitted);
|
||||
}
|
||||
|
||||
#if defined(D3D12_SDK_VERSION) && (D3D12_SDK_VERSION >= 606)
|
||||
//------------------------------------------------------------------------------------------------
|
||||
// The difference between D3DX12GetCopyableFootprints and ID3D12Device::GetCopyableFootprints
|
||||
// is that this one loses a lot of error checking by assuming the arguments are correct
|
||||
inline bool D3DX12GetCopyableFootprints(
|
||||
_In_ const D3D12_RESOURCE_DESC1& ResourceDesc,
|
||||
_In_range_(0, D3D12_REQ_SUBRESOURCES) UINT FirstSubresource,
|
||||
_In_range_(0, D3D12_REQ_SUBRESOURCES - FirstSubresource) UINT NumSubresources,
|
||||
UINT64 BaseOffset,
|
||||
_Out_writes_opt_(NumSubresources) D3D12_PLACED_SUBRESOURCE_FOOTPRINT* pLayouts,
|
||||
_Out_writes_opt_(NumSubresources) UINT* pNumRows,
|
||||
_Out_writes_opt_(NumSubresources) UINT64* pRowSizeInBytes,
|
||||
_Out_opt_ UINT64* pTotalBytes)
|
||||
{
|
||||
constexpr UINT64 uint64_max = ~0ull;
|
||||
UINT64 TotalBytes = uint64_max;
|
||||
UINT uSubRes = 0;
|
||||
|
||||
bool bResourceOverflow = false;
|
||||
TotalBytes = 0;
|
||||
|
||||
const DXGI_FORMAT Format = ResourceDesc.Format;
|
||||
|
||||
CD3DX12_RESOURCE_DESC1 LresourceDesc;
|
||||
const CD3DX12_RESOURCE_DESC1& resourceDesc = *D3DX12ConditionallyExpandAPIDesc(LresourceDesc, &ResourceDesc);
|
||||
|
||||
// Check if its a valid format
|
||||
D3DX12_ASSERT(D3D12_PROPERTY_LAYOUT_FORMAT_TABLE::FormatExists(Format));
|
||||
|
||||
// D3DX12GetCopyableFootprints does not support buffers with width larger than UINT_MAX.
|
||||
if (ResourceDesc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER && ResourceDesc.Width >= UINT_MAX)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
const UINT WidthAlignment = D3D12_PROPERTY_LAYOUT_FORMAT_TABLE::GetWidthAlignment( Format );
|
||||
const UINT HeightAlignment = D3D12_PROPERTY_LAYOUT_FORMAT_TABLE::GetHeightAlignment( Format );
|
||||
const UINT16 DepthAlignment = UINT16( D3D12_PROPERTY_LAYOUT_FORMAT_TABLE::GetDepthAlignment( Format ) );
|
||||
|
||||
for (; uSubRes < NumSubresources; ++uSubRes)
|
||||
{
|
||||
bool bOverflow = false;
|
||||
UINT Subresource = FirstSubresource + uSubRes;
|
||||
|
||||
D3DX12_ASSERT(resourceDesc.MipLevels != 0);
|
||||
UINT subresourceCount = resourceDesc.MipLevels * resourceDesc.ArraySize() * D3D12_PROPERTY_LAYOUT_FORMAT_TABLE::GetPlaneCount(resourceDesc.Format);
|
||||
|
||||
if (Subresource > subresourceCount)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
TotalBytes = D3DX12Align< UINT64 >( TotalBytes, D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT );
|
||||
|
||||
UINT MipLevel, ArraySlice, PlaneSlice;
|
||||
D3D12DecomposeSubresource(Subresource, resourceDesc.MipLevels, resourceDesc.ArraySize(), /*_Out_*/MipLevel, /*_Out_*/ArraySlice, /*_Out_*/PlaneSlice);
|
||||
|
||||
const UINT64 Width = D3DX12AlignAtLeast<UINT64>(resourceDesc.Width >> MipLevel, WidthAlignment);
|
||||
const UINT Height = D3DX12AlignAtLeast(resourceDesc.Height >> MipLevel, HeightAlignment);
|
||||
const UINT16 Depth = D3DX12AlignAtLeast<UINT16>(resourceDesc.Depth() >> MipLevel, DepthAlignment);
|
||||
|
||||
// Adjust for the current PlaneSlice. Most formats have only one plane.
|
||||
DXGI_FORMAT PlaneFormat;
|
||||
UINT32 MinPlanePitchWidth, PlaneWidth, PlaneHeight;
|
||||
D3D12_PROPERTY_LAYOUT_FORMAT_TABLE::GetPlaneSubsampledSizeAndFormatForCopyableLayout(PlaneSlice, Format, (UINT)Width, Height, /*_Out_*/ PlaneFormat, /*_Out_*/ MinPlanePitchWidth, /* _Out_ */ PlaneWidth, /*_Out_*/ PlaneHeight);
|
||||
|
||||
D3D12_SUBRESOURCE_FOOTPRINT LocalPlacement = {};
|
||||
auto& Placement = pLayouts ? pLayouts[uSubRes].Footprint : LocalPlacement;
|
||||
Placement.Format = PlaneFormat;
|
||||
Placement.Width = PlaneWidth;
|
||||
Placement.Height = PlaneHeight;
|
||||
Placement.Depth = Depth;
|
||||
|
||||
// Calculate row pitch
|
||||
UINT MinPlaneRowPitch = 0;
|
||||
D3D12_PROPERTY_LAYOUT_FORMAT_TABLE::CalculateMinimumRowMajorRowPitch(PlaneFormat, MinPlanePitchWidth, MinPlaneRowPitch);
|
||||
|
||||
// Formats with more than one plane choose a larger pitch alignment to ensure that each plane begins on the row
|
||||
// immediately following the previous plane while still adhering to subresource alignment restrictions.
|
||||
static_assert( D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT >= D3D12_TEXTURE_DATA_PITCH_ALIGNMENT
|
||||
&& ((D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT % D3D12_TEXTURE_DATA_PITCH_ALIGNMENT) == 0),
|
||||
"D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT must be >= and evenly divisible by D3D12_TEXTURE_DATA_PITCH_ALIGNMENT." );
|
||||
|
||||
Placement.RowPitch = D3D12_PROPERTY_LAYOUT_FORMAT_TABLE::Planar(Format)
|
||||
? D3DX12Align< UINT >( MinPlaneRowPitch, D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT )
|
||||
: D3DX12Align< UINT >( MinPlaneRowPitch, D3D12_TEXTURE_DATA_PITCH_ALIGNMENT );
|
||||
|
||||
if (pRowSizeInBytes)
|
||||
{
|
||||
UINT PlaneRowSize = 0;
|
||||
D3D12_PROPERTY_LAYOUT_FORMAT_TABLE::CalculateMinimumRowMajorRowPitch(PlaneFormat, PlaneWidth, PlaneRowSize);
|
||||
|
||||
pRowSizeInBytes[uSubRes] = PlaneRowSize;
|
||||
}
|
||||
|
||||
// Number of rows (accounting for block compression and additional planes)
|
||||
UINT NumRows = 0;
|
||||
if (D3D12_PROPERTY_LAYOUT_FORMAT_TABLE::Planar(Format))
|
||||
{
|
||||
NumRows = PlaneHeight;
|
||||
}
|
||||
else
|
||||
{
|
||||
D3DX12_ASSERT(Height % HeightAlignment == 0);
|
||||
NumRows = Height / HeightAlignment;
|
||||
}
|
||||
|
||||
if (pNumRows)
|
||||
{
|
||||
pNumRows[uSubRes] = NumRows;
|
||||
}
|
||||
|
||||
// Offsetting
|
||||
if (pLayouts)
|
||||
{
|
||||
pLayouts[uSubRes].Offset = (bOverflow ? uint64_max : TotalBytes + BaseOffset);
|
||||
}
|
||||
|
||||
const UINT16 NumSlices = Depth;
|
||||
const UINT64 SubresourceSize = (NumRows * NumSlices - 1) * Placement.RowPitch + MinPlaneRowPitch;
|
||||
|
||||
// uint64 addition with overflow checking
|
||||
TotalBytes = TotalBytes + SubresourceSize;
|
||||
if(TotalBytes < SubresourceSize)
|
||||
{
|
||||
TotalBytes = uint64_max;
|
||||
}
|
||||
bResourceOverflow = bResourceOverflow || bOverflow;
|
||||
}
|
||||
|
||||
// Overflow error
|
||||
if (bResourceOverflow)
|
||||
{
|
||||
TotalBytes = uint64_max;
|
||||
}
|
||||
|
||||
|
||||
if (pLayouts)
|
||||
{
|
||||
memset( pLayouts + uSubRes, -1, sizeof( *pLayouts ) * (NumSubresources - uSubRes) );
|
||||
}
|
||||
if (pNumRows)
|
||||
{
|
||||
memset(pNumRows + uSubRes, -1, sizeof(*pNumRows) * (NumSubresources - uSubRes));
|
||||
}
|
||||
if (pRowSizeInBytes)
|
||||
{
|
||||
memset(pRowSizeInBytes + uSubRes, -1, sizeof(*pRowSizeInBytes) * (NumSubresources - uSubRes));
|
||||
}
|
||||
if (pTotalBytes)
|
||||
{
|
||||
*pTotalBytes = TotalBytes;
|
||||
}
|
||||
if(TotalBytes == uint64_max)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
inline D3D12_RESOURCE_DESC1 D3DX12ResourceDesc0ToDesc1(D3D12_RESOURCE_DESC const& desc0)
|
||||
{
|
||||
D3D12_RESOURCE_DESC1 desc1;
|
||||
desc1.Dimension = desc0.Dimension;
|
||||
desc1.Alignment = desc0.Alignment;
|
||||
desc1.Width = desc0.Width;
|
||||
desc1.Height = desc0.Height;
|
||||
desc1.DepthOrArraySize = desc0.DepthOrArraySize;
|
||||
desc1.MipLevels = desc0.MipLevels;
|
||||
desc1.Format = desc0.Format;
|
||||
desc1.SampleDesc.Count = desc0.SampleDesc.Count;
|
||||
desc1.SampleDesc.Quality = desc0.SampleDesc.Quality;
|
||||
desc1.Layout = desc0.Layout;
|
||||
desc1.Flags = desc0.Flags;
|
||||
desc1.SamplerFeedbackMipRegion.Width = 0;
|
||||
desc1.SamplerFeedbackMipRegion.Height = 0;
|
||||
desc1.SamplerFeedbackMipRegion.Depth = 0;
|
||||
return desc1;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
inline bool D3DX12GetCopyableFootprints(
|
||||
_In_ const D3D12_RESOURCE_DESC& pResourceDesc,
|
||||
_In_range_(0, D3D12_REQ_SUBRESOURCES) UINT FirstSubresource,
|
||||
_In_range_(0, D3D12_REQ_SUBRESOURCES - FirstSubresource) UINT NumSubresources,
|
||||
UINT64 BaseOffset,
|
||||
_Out_writes_opt_(NumSubresources) D3D12_PLACED_SUBRESOURCE_FOOTPRINT* pLayouts,
|
||||
_Out_writes_opt_(NumSubresources) UINT* pNumRows,
|
||||
_Out_writes_opt_(NumSubresources) UINT64* pRowSizeInBytes,
|
||||
_Out_opt_ UINT64* pTotalBytes)
|
||||
{
|
||||
// From D3D12_RESOURCE_DESC to D3D12_RESOURCE_DESC1
|
||||
D3D12_RESOURCE_DESC1 desc = D3DX12ResourceDesc0ToDesc1(pResourceDesc);
|
||||
return D3DX12GetCopyableFootprints(
|
||||
*static_cast<CD3DX12_RESOURCE_DESC1*>(&desc),// From D3D12_RESOURCE_DESC1 to CD3DX12_RESOURCE_DESC1
|
||||
FirstSubresource,
|
||||
NumSubresources,
|
||||
BaseOffset,
|
||||
pLayouts,
|
||||
pNumRows,
|
||||
pRowSizeInBytes,
|
||||
pTotalBytes);
|
||||
}
|
||||
|
||||
#endif // D3D12_SDK_VERSION >= 606
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user