improved client build and updated build guide

This commit is contained in:
myT 2024-01-14 01:34:01 +01:00
parent 599f8ea12f
commit c5bb9c7495
13 changed files with 1248 additions and 6121 deletions

View file

@ -4,7 +4,7 @@
There are 3 supported build toolchains: There are 3 supported build toolchains:
- Visual C++ on Windows x64 and x86 - Visual C++ on Windows x64
- GCC or Clang on Linux x64 - GCC or Clang on Linux x64
- Clang or GCC on FreeBSD x64 - Clang or GCC on FreeBSD x64
@ -16,15 +16,15 @@ There are 3 supported build toolchains:
| .build | intermediate build files | | .build | intermediate build files |
| .bin | final executables (and symbol database files on Windows) | | .bin | final executables (and symbol database files on Windows) |
## Building on Windows with Visual C++ 2013 or later ## Building on Windows with Visual C++ 2019 or later
**Requirements** **Requirements**
- The %QUAKE3DIR% environment variable must be defined to the absolute path to copy the .exe and .pdb files to - The %QUAKE3DIR% environment variable must be defined to the absolute path to copy the .exe and .pdb files to
- NASM.exe is in your path for building the client - nasm.exe (Netwide Assembler) is in your path for building the client
- One of the following is true: - One of the following is true for building the client:
- The %FXCPATH% environment variable contains the full path to fxc.exe - The %DXCPATH% environment variable contains the full path to dxc.exe
- The June 2010 DirectX SDK is installed - dxc.exe is already in your %PATH%
**Options** **Options**
@ -32,7 +32,8 @@ There are 3 supported build toolchains:
**Build steps** **Build steps**
- Open makefiles\windows_vs2013\cnq3.sln - Set the %QUAKE3DIR% environment variable
- Open makefiles\windows_vs2019\cnq3.sln or makefiles\windows_vs2022\cnq3.sln
- Build - Build
**Notes** **Notes**
@ -41,25 +42,21 @@ There are 3 supported build toolchains:
- Instead, we recomment you set them for the Visual Studio process only - Instead, we recomment you set them for the Visual Studio process only
Here's an example batch script for opening the Visual Studio solution: Here's an example batch script for opening the Visual Studio solution:
``` ```batch
cd cnq3\makefiles\windows_vs2013 cd cnq3\makefiles\windows_vs2022
set QUAKE3DIR=G:\CPMA_tests set QUAKE3DIR=C:\Programs\Q3\Dev
set CPMADIR=cpma_dev set CPMADIR=cpma_dev
set FXCPATH=C:\Program Files (x86)\Windows Kits\8.1\bin\x64\fxc.exe set DXCPATH=C:\Programs\dxc\bin\x64\dxc.exe
cnq3.sln start "" cnq3.sln
exit
``` ```
With this set-up, you can press F5 and run the engine through the Visual C++ debugger on the right q3 install and right mod folder immediately. With this set-up, you can press F5 and run the engine through the Visual C++ debugger on the right q3 install and right mod folder immediately.
## Building on Linux / FreeBSD with GCC ## Building on Linux / FreeBSD with GCC / Clang
**Requirements** **Requirements**
| Name | Server | Client | Debian package | FreeBSD package | - On FreeBSD, we link against libexecinfo for the backtrace functions. We thus require FreeBSD 10.0 or later.
|:------|:------:|:------:|:---------------|:----------------|
| NASM | X | X | nasm | nasm |
| SDL 2 | | X | libsdl2-dev | sdl2 |
On FreeBSD, we link against libexecinfo for the backtrace functions. We thus require FreeBSD 10.0 or later.
**Options** **Options**
@ -68,7 +65,7 @@ On FreeBSD, we link against libexecinfo for the backtrace functions. We thus req
**Build steps** **Build steps**
- Navigate to the root of the repository - Navigate to the root of the repository
- Run `make [config=debug|release] all|client|server` to build on Linux - Run `make [config=debug|release] all|server` to build on Linux
For FreeBSD, use `gmake` instead of `make` For FreeBSD, use `gmake` instead of `make`
**Notes** **Notes**
@ -86,30 +83,15 @@ On FreeBSD, we link against libexecinfo for the backtrace functions. We thus req
There are 3 environment variables used for compiling and debugging: There are 3 environment variables used for compiling and debugging:
| Env. Var. | Meaning | Example | | Env. Var. | Meaning | Example |
|:----------|:------------------------|:--------------------------------------------------------| |:----------|:------------------------|:--------------------------------|
| QUAKE3DIR | absolute directory path | C:\Games\Q3 | | QUAKE3DIR | absolute directory path | C:\Programs\Q3 |
| CPMADIR | mod folder name | cpma | | CPMADIR | mod folder name | cpma |
| FXCPATH | full fxc.exe file path | C:\Program Files (x86)\Windows Kits\8.1\bin\x64\fxc.exe | | DXCPATH | full dxc.exe file path | C:\Programs\dxc\bin\x64\dxc.exe |
| Env. Var. | Windows | Linux / FreeBSD | | Env. Var. | Windows | Linux / FreeBSD |
|:----------|:-------------------------|:----------------------| |:----------|:-------------------------|:----------------------|
| QUAKE3DIR | required for building | optional for building | | QUAKE3DIR | required for building | optional for building |
| CPMADIR | required for debugging | unused | | CPMADIR | required for debugging | unused |
| FXCPATH | required for building(1) | unused | | DXCPATH | optional for building(1) | unused |
1) FXCPATH is optional if you have the June 2010 DirectX SDK installed. 1) DXCPATH is optional if you already have dxc.exe in your PATH
## Building with other compilers
While it's not officially supported, you can modify the premake Lua script and run premake on it to generate new makefiles for your own needs.
## Bonus: Building SDL 2 from source on Linux
- Download the sources of the latest stable release
- Extract to sdl-src
- Create sdl-build next to sdl-src (it *has* to be out-of-tree)
- Navigate to the sdl-build directory with `cd`
- Run `../sdl-src/configure`
- Run `make`
- As superuser, run `make install` (or `sudo make install`)
- Run `ldconfig` to update the library paths

View file

@ -1,34 +0,0 @@
//*********************************************************
//
// 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"
#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__

View file

@ -1,192 +0,0 @@
//*********************************************************
//
// 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_ ID3D12Resource* pResourceBefore,
_In_ 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_ 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__

View file

@ -1,996 +0,0 @@
//*********************************************************
//
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License (MIT).
//
//*********************************************************
#pragma once
#ifndef __cplusplus
#error D3DX12 requires C++
#endif
#include "d3d12.h"
//================================================================================================
// D3DX12 Check Feature Support
//================================================================================================
#include <vector>
class CD3DX12FeatureSupport
{
public: // Function declaration
// Default constructor that creates an empty object
CD3DX12FeatureSupport() noexcept;
// Initialize data from the given device
HRESULT Init(ID3D12Device* pDevice);
// Retreives the status of the object. If an error occurred in the initialization process, the function returns the error code.
HRESULT GetStatus() const noexcept { return m_hStatus; }
// Getter functions for each feature class
// D3D12_OPTIONS
BOOL DoublePrecisionFloatShaderOps() const noexcept;
BOOL OutputMergerLogicOp() const noexcept;
D3D12_SHADER_MIN_PRECISION_SUPPORT MinPrecisionSupport() const noexcept;
D3D12_TILED_RESOURCES_TIER TiledResourcesTier() const noexcept;
D3D12_RESOURCE_BINDING_TIER ResourceBindingTier() const noexcept;
BOOL PSSpecifiedStencilRefSupported() const noexcept;
BOOL TypedUAVLoadAdditionalFormats() const noexcept;
BOOL ROVsSupported() const noexcept;
D3D12_CONSERVATIVE_RASTERIZATION_TIER ConservativeRasterizationTier() const noexcept;
BOOL StandardSwizzle64KBSupported() const noexcept;
BOOL CrossAdapterRowMajorTextureSupported() const noexcept;
BOOL VPAndRTArrayIndexFromAnyShaderFeedingRasterizerSupportedWithoutGSEmulation() const noexcept;
D3D12_RESOURCE_HEAP_TIER ResourceHeapTier() const noexcept;
D3D12_CROSS_NODE_SHARING_TIER CrossNodeSharingTier() const noexcept;
UINT MaxGPUVirtualAddressBitsPerResource() const noexcept;
// FEATURE_LEVELS
D3D_FEATURE_LEVEL MaxSupportedFeatureLevel() const noexcept;
// FORMAT_SUPPORT
HRESULT FormatSupport(DXGI_FORMAT Format, D3D12_FORMAT_SUPPORT1& Support1, D3D12_FORMAT_SUPPORT2& Support2) const;
// MUTLTISAMPLE_QUALITY_LEVELS
HRESULT MultisampleQualityLevels(DXGI_FORMAT Format, UINT SampleCount, D3D12_MULTISAMPLE_QUALITY_LEVEL_FLAGS Flags, UINT& NumQualityLevels) const;
// FORMAT_INFO
HRESULT FormatInfo(DXGI_FORMAT Format, UINT8& PlaneCount) const;
// GPU_VIRTUAL_ADDRESS_SUPPORT
UINT MaxGPUVirtualAddressBitsPerProcess() const noexcept;
// SHADER_MODEL
D3D_SHADER_MODEL HighestShaderModel() const noexcept;
// D3D12_OPTIONS1
BOOL WaveOps() const noexcept;
UINT WaveLaneCountMin() const noexcept;
UINT WaveLaneCountMax() const noexcept;
UINT TotalLaneCount() const noexcept;
BOOL ExpandedComputeResourceStates() const noexcept;
BOOL Int64ShaderOps() const noexcept;
// PROTECTED_RESOURCE_SESSION_SUPPORT
D3D12_PROTECTED_RESOURCE_SESSION_SUPPORT_FLAGS ProtectedResourceSessionSupport(UINT NodeIndex = 0) const;
// ROOT_SIGNATURE
D3D_ROOT_SIGNATURE_VERSION HighestRootSignatureVersion() const noexcept;
// ARCHITECTURE1
BOOL TileBasedRenderer(UINT NodeIndex = 0) const;
BOOL UMA(UINT NodeIndex = 0) const;
BOOL CacheCoherentUMA(UINT NodeIndex = 0) const;
BOOL IsolatedMMU(UINT NodeIndex = 0) const;
// D3D12_OPTIONS2
BOOL DepthBoundsTestSupported() const noexcept;
D3D12_PROGRAMMABLE_SAMPLE_POSITIONS_TIER ProgrammableSamplePositionsTier() const noexcept;
// SHADER_CACHE
D3D12_SHADER_CACHE_SUPPORT_FLAGS ShaderCacheSupportFlags() const noexcept;
// COMMAND_QUEUE_PRIORITY
BOOL CommandQueuePrioritySupported(D3D12_COMMAND_LIST_TYPE CommandListType, UINT Priority);
// D3D12_OPTIONS3
BOOL CopyQueueTimestampQueriesSupported() const noexcept;
BOOL CastingFullyTypedFormatSupported() const noexcept;
D3D12_COMMAND_LIST_SUPPORT_FLAGS WriteBufferImmediateSupportFlags() const noexcept;
D3D12_VIEW_INSTANCING_TIER ViewInstancingTier() const noexcept;
BOOL BarycentricsSupported() const noexcept;
// EXISTING_HEAPS
BOOL ExistingHeapsSupported() const noexcept;
// D3D12_OPTIONS4
BOOL MSAA64KBAlignedTextureSupported() const noexcept;
D3D12_SHARED_RESOURCE_COMPATIBILITY_TIER SharedResourceCompatibilityTier() const noexcept;
BOOL Native16BitShaderOpsSupported() const noexcept;
// SERIALIZATION
D3D12_HEAP_SERIALIZATION_TIER HeapSerializationTier(UINT NodeIndex = 0) const;
// CROSS_NODE
// CrossNodeSharingTier handled in D3D12Options
BOOL CrossNodeAtomicShaderInstructions() const noexcept;
// D3D12_OPTIONS5
BOOL SRVOnlyTiledResourceTier3() const noexcept;
D3D12_RENDER_PASS_TIER RenderPassesTier() const noexcept;
D3D12_RAYTRACING_TIER RaytracingTier() const noexcept;
#if defined(D3D12_SDK_VERSION) && (D3D12_SDK_VERSION >= 4)
// DISPLAYABLE
BOOL DisplayableTexture() const noexcept;
// SharedResourceCompatibilityTier handled in D3D12Options4
#endif
// D3D12_OPTIONS6
BOOL AdditionalShadingRatesSupported() const noexcept;
BOOL PerPrimitiveShadingRateSupportedWithViewportIndexing() const noexcept;
D3D12_VARIABLE_SHADING_RATE_TIER VariableShadingRateTier() const noexcept;
UINT ShadingRateImageTileSize() const noexcept;
BOOL BackgroundProcessingSupported() const noexcept;
// QUERY_META_COMMAND
HRESULT QueryMetaCommand(D3D12_FEATURE_DATA_QUERY_META_COMMAND& dQueryMetaCommand) const;
// D3D12_OPTIONS7
D3D12_MESH_SHADER_TIER MeshShaderTier() const noexcept;
D3D12_SAMPLER_FEEDBACK_TIER SamplerFeedbackTier() const noexcept;
// PROTECTED_RESOURCE_SESSION_TYPE_COUNT
UINT ProtectedResourceSessionTypeCount(UINT NodeIndex = 0) const;
// PROTECTED_RESOURCE_SESSION_TYPES
std::vector<GUID> ProtectedResourceSessionTypes(UINT NodeIndex = 0) const;
#if defined(D3D12_SDK_VERSION) && (D3D12_SDK_VERSION >= 3)
// D3D12_OPTIONS8
BOOL UnalignedBlockTexturesSupported() const noexcept;
// D3D12_OPTIONS9
BOOL MeshShaderPipelineStatsSupported() const noexcept;
BOOL MeshShaderSupportsFullRangeRenderTargetArrayIndex() const noexcept;
BOOL AtomicInt64OnTypedResourceSupported() const noexcept;
BOOL AtomicInt64OnGroupSharedSupported() const noexcept;
BOOL DerivativesInMeshAndAmplificationShadersSupported() const noexcept;
D3D12_WAVE_MMA_TIER WaveMMATier() const noexcept;
#endif
#if defined(D3D12_SDK_VERSION) && (D3D12_SDK_VERSION >= 4)
// D3D12_OPTIONS10
BOOL VariableRateShadingSumCombinerSupported() const noexcept;
BOOL MeshShaderPerPrimitiveShadingRateSupported() const noexcept;
// D3D12_OPTIONS11
BOOL AtomicInt64OnDescriptorHeapResourceSupported() const noexcept;
#endif
#if defined(D3D12_SDK_VERSION) && (D3D12_SDK_VERSION >= 600)
// D3D12_OPTIONS12
D3D12_TRI_STATE MSPrimitivesPipelineStatisticIncludesCulledPrimitives() const noexcept;
BOOL EnhancedBarriersSupported() const noexcept;
BOOL RelaxedFormatCastingSupported() const noexcept;
#endif
#if defined(D3D12_SDK_VERSION) && (D3D12_SDK_VERSION >= 602)
// D3D12_OPTIONS13
BOOL UnrestrictedBufferTextureCopyPitchSupported() const noexcept;
BOOL UnrestrictedVertexElementAlignmentSupported() const noexcept;
BOOL InvertedViewportHeightFlipsYSupported() const noexcept;
BOOL InvertedViewportDepthFlipsZSupported() const noexcept;
BOOL TextureCopyBetweenDimensionsSupported() const noexcept;
BOOL AlphaBlendFactorSupported() const noexcept;
#endif
#if defined(D3D12_SDK_VERSION) && (D3D12_SDK_VERSION >= 606)
// D3D12_OPTIONS14
BOOL AdvancedTextureOpsSupported() const noexcept;
BOOL WriteableMSAATexturesSupported() const noexcept;
BOOL IndependentFrontAndBackStencilRefMaskSupported() const noexcept;
// D3D12_OPTIONS15
BOOL TriangleFanSupported() const noexcept;
BOOL DynamicIndexBufferStripCutSupported() const noexcept;
#endif
#if defined(D3D12_SDK_VERSION) && (D3D12_SDK_VERSION >= 608)
// D3D12_OPTIONS16
BOOL DynamicDepthBiasSupported() const noexcept;
#endif
private: // Private structs and helpers declaration
struct ProtectedResourceSessionTypesLocal : D3D12_FEATURE_DATA_PROTECTED_RESOURCE_SESSION_TYPES
{
std::vector<GUID> TypeVec;
};
// Helper function to decide the highest shader model supported by the system
// Stores the result in m_dShaderModel
// Must be updated whenever a new shader model is added to the d3d12.h header
HRESULT QueryHighestShaderModel();
// Helper function to decide the highest root signature supported
// Must be updated whenever a new root signature version is added to the d3d12.h header
HRESULT QueryHighestRootSignatureVersion();
// Helper funcion to decide the highest feature level
HRESULT QueryHighestFeatureLevel();
// Helper function to initialize local protected resource session types structs
HRESULT QueryProtectedResourceSessionTypes(UINT NodeIndex, UINT Count);
private: // Member data
// Pointer to the underlying device
ID3D12Device* m_pDevice;
// Stores the error code from initialization
HRESULT m_hStatus;
// Feature support data structs
D3D12_FEATURE_DATA_D3D12_OPTIONS m_dOptions;
D3D_FEATURE_LEVEL m_eMaxFeatureLevel;
D3D12_FEATURE_DATA_GPU_VIRTUAL_ADDRESS_SUPPORT m_dGPUVASupport;
D3D12_FEATURE_DATA_SHADER_MODEL m_dShaderModel;
D3D12_FEATURE_DATA_D3D12_OPTIONS1 m_dOptions1;
std::vector<D3D12_FEATURE_DATA_PROTECTED_RESOURCE_SESSION_SUPPORT> m_dProtectedResourceSessionSupport;
D3D12_FEATURE_DATA_ROOT_SIGNATURE m_dRootSignature;
std::vector<D3D12_FEATURE_DATA_ARCHITECTURE1> m_dArchitecture1;
D3D12_FEATURE_DATA_D3D12_OPTIONS2 m_dOptions2;
D3D12_FEATURE_DATA_SHADER_CACHE m_dShaderCache;
D3D12_FEATURE_DATA_COMMAND_QUEUE_PRIORITY m_dCommandQueuePriority;
D3D12_FEATURE_DATA_D3D12_OPTIONS3 m_dOptions3;
D3D12_FEATURE_DATA_EXISTING_HEAPS m_dExistingHeaps;
D3D12_FEATURE_DATA_D3D12_OPTIONS4 m_dOptions4;
std::vector<D3D12_FEATURE_DATA_SERIALIZATION> m_dSerialization; // Cat2 NodeIndex
D3D12_FEATURE_DATA_CROSS_NODE m_dCrossNode;
D3D12_FEATURE_DATA_D3D12_OPTIONS5 m_dOptions5;
#if defined(D3D12_SDK_VERSION) && (D3D12_SDK_VERSION >= 4)
D3D12_FEATURE_DATA_DISPLAYABLE m_dDisplayable;
#endif
D3D12_FEATURE_DATA_D3D12_OPTIONS6 m_dOptions6;
D3D12_FEATURE_DATA_D3D12_OPTIONS7 m_dOptions7;
std::vector<D3D12_FEATURE_DATA_PROTECTED_RESOURCE_SESSION_TYPE_COUNT> m_dProtectedResourceSessionTypeCount; // Cat2 NodeIndex
std::vector<ProtectedResourceSessionTypesLocal> m_dProtectedResourceSessionTypes; // Cat3
#if defined(D3D12_SDK_VERSION) && (D3D12_SDK_VERSION >= 3)
D3D12_FEATURE_DATA_D3D12_OPTIONS8 m_dOptions8;
D3D12_FEATURE_DATA_D3D12_OPTIONS9 m_dOptions9;
#endif
#if defined(D3D12_SDK_VERSION) && (D3D12_SDK_VERSION >= 4)
D3D12_FEATURE_DATA_D3D12_OPTIONS10 m_dOptions10;
D3D12_FEATURE_DATA_D3D12_OPTIONS11 m_dOptions11;
#endif
#if defined(D3D12_SDK_VERSION) && (D3D12_SDK_VERSION >= 600)
D3D12_FEATURE_DATA_D3D12_OPTIONS12 m_dOptions12;
#endif
#if defined(D3D12_SDK_VERSION) && (D3D12_SDK_VERSION >= 602)
D3D12_FEATURE_DATA_D3D12_OPTIONS13 m_dOptions13;
#endif
#if defined(D3D12_SDK_VERSION) && (D3D12_SDK_VERSION >= 606)
D3D12_FEATURE_DATA_D3D12_OPTIONS14 m_dOptions14;
D3D12_FEATURE_DATA_D3D12_OPTIONS15 m_dOptions15;
#endif
#if defined(D3D12_SDK_VERSION) && (D3D12_SDK_VERSION >= 608)
D3D12_FEATURE_DATA_D3D12_OPTIONS16 m_dOptions16;
#endif
};
// Implementations for CD3DX12FeatureSupport functions
// Macro to set up a getter function for each entry in feature support data
// The getter function will have the same name as the feature option name
#define FEATURE_SUPPORT_GET(RETTYPE,FEATURE,OPTION) \
inline RETTYPE CD3DX12FeatureSupport::OPTION() const noexcept \
{ \
return FEATURE.OPTION; \
}
// Macro to set up a getter function for each entry in feature support data
// Also specifies the name for the function which can be different from the feature name
#define FEATURE_SUPPORT_GET_NAME(RETTYPE,FEATURE,OPTION,NAME) \
inline RETTYPE CD3DX12FeatureSupport::NAME() const noexcept \
{\
return FEATURE.OPTION; \
}
// Macro to set up a getter function for feature data indexed by the graphics node ID
// The default parameter is 0, or the first availabe graphics device node
#define FEATURE_SUPPORT_GET_NODE_INDEXED(RETTYPE,FEATURE,OPTION) \
inline RETTYPE CD3DX12FeatureSupport::OPTION(UINT NodeIndex) const \
{\
return FEATURE[NodeIndex].OPTION; \
}
// Macro to set up a getter function for feature data indexed by NodeIndex
// Allows a custom name for the getter function
#define FEATURE_SUPPORT_GET_NODE_INDEXED_NAME(RETTYPE,FEATURE,OPTION,NAME) \
inline RETTYPE CD3DX12FeatureSupport::NAME(UINT NodeIndex) const \
{\
return FEATURE[NodeIndex].OPTION; \
}
inline CD3DX12FeatureSupport::CD3DX12FeatureSupport() noexcept
: m_pDevice(nullptr)
, m_hStatus(E_INVALIDARG)
, m_dOptions{}
, m_eMaxFeatureLevel{}
, m_dGPUVASupport{}
, m_dShaderModel{}
, m_dOptions1{}
, m_dRootSignature{}
, m_dOptions2{}
, m_dShaderCache{}
, m_dCommandQueuePriority{}
, m_dOptions3{}
, m_dExistingHeaps{}
, m_dOptions4{}
, m_dCrossNode{}
, m_dOptions5{}
#if defined(D3D12_SDK_VERSION) && (D3D12_SDK_VERSION >= 4)
, m_dDisplayable{}
#endif
, m_dOptions6{}
, m_dOptions7{}
#if defined(D3D12_SDK_VERSION) && (D3D12_SDK_VERSION >= 3)
, m_dOptions8{}
, m_dOptions9{}
#endif
#if defined(D3D12_SDK_VERSION) && (D3D12_SDK_VERSION >= 4)
, m_dOptions10{}
, m_dOptions11{}
#endif
#if defined(D3D12_SDK_VERSION) && (D3D12_SDK_VERSION >= 600)
, m_dOptions12{}
#endif
#if defined(D3D12_SDK_VERSION) && (D3D12_SDK_VERSION >= 602)
, m_dOptions13{}
#endif
#if defined(D3D12_SDK_VERSION) && (D3D12_SDK_VERSION >= 606)
, m_dOptions14{}
, m_dOptions15{}
#endif
#if defined(D3D12_SDK_VERSION) && (D3D12_SDK_VERSION >= 608)
, m_dOptions16{}
#endif
{}
inline HRESULT CD3DX12FeatureSupport::Init(ID3D12Device* pDevice)
{
if (!pDevice)
{
m_hStatus = E_INVALIDARG;
return m_hStatus;
}
m_pDevice = pDevice;
// Initialize static feature support data structures
if (FAILED(m_pDevice->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS, &m_dOptions, sizeof(m_dOptions))))
{
m_dOptions = {};
}
if (FAILED(m_pDevice->CheckFeatureSupport(D3D12_FEATURE_GPU_VIRTUAL_ADDRESS_SUPPORT, &m_dGPUVASupport, sizeof(m_dGPUVASupport))))
{
m_dGPUVASupport = {};
}
if (FAILED(m_pDevice->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS1, &m_dOptions1, sizeof(m_dOptions1))))
{
m_dOptions1 = {};
}
if (FAILED(m_pDevice->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS2, &m_dOptions2, sizeof(m_dOptions2))))
{
m_dOptions2 = {};
}
if (FAILED(m_pDevice->CheckFeatureSupport(D3D12_FEATURE_SHADER_CACHE, &m_dShaderCache, sizeof(m_dShaderCache))))
{
m_dShaderCache = {};
}
if (FAILED(m_pDevice->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS3, &m_dOptions3, sizeof(m_dOptions3))))
{
m_dOptions3 = {};
}
if (FAILED(m_pDevice->CheckFeatureSupport(D3D12_FEATURE_EXISTING_HEAPS, &m_dExistingHeaps, sizeof(m_dExistingHeaps))))
{
m_dExistingHeaps = {};
}
if (FAILED(m_pDevice->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS4, &m_dOptions4, sizeof(m_dOptions4))))
{
m_dOptions4 = {};
}
if (FAILED(m_pDevice->CheckFeatureSupport(D3D12_FEATURE_CROSS_NODE, &m_dCrossNode, sizeof(m_dCrossNode))))
{
m_dCrossNode = {};
}
if (FAILED(m_pDevice->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS5, &m_dOptions5, sizeof(m_dOptions5))))
{
m_dOptions5 = {};
}
#if defined(D3D12_SDK_VERSION) && (D3D12_SDK_VERSION >= 4)
if (FAILED(m_pDevice->CheckFeatureSupport(D3D12_FEATURE_DISPLAYABLE, &m_dDisplayable, sizeof(m_dDisplayable))))
{
m_dDisplayable = {};
}
#endif
if (FAILED(m_pDevice->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS6, &m_dOptions6, sizeof(m_dOptions6))))
{
m_dOptions6 = {};
}
if (FAILED(m_pDevice->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS7, &m_dOptions7, sizeof(m_dOptions7))))
{
m_dOptions7 = {};
}
#if defined(D3D12_SDK_VERSION) && (D3D12_SDK_VERSION >= 3)
if (FAILED(m_pDevice->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS8, &m_dOptions8, sizeof(m_dOptions8))))
{
m_dOptions8 = {};
}
if (FAILED(m_pDevice->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS9, &m_dOptions9, sizeof(m_dOptions9))))
{
m_dOptions9 = {};
}
#endif
#if defined(D3D12_SDK_VERSION) && (D3D12_SDK_VERSION >= 4)
if (FAILED(m_pDevice->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS10, &m_dOptions10, sizeof(m_dOptions10))))
{
m_dOptions10 = {};
}
if (FAILED(m_pDevice->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS11, &m_dOptions11, sizeof(m_dOptions11))))
{
m_dOptions11 = {};
}
#endif
#if defined(D3D12_SDK_VERSION) && (D3D12_SDK_VERSION >= 600)
if (FAILED(m_pDevice->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS12, &m_dOptions12, sizeof(m_dOptions12))))
{
m_dOptions12 = {};
m_dOptions12.MSPrimitivesPipelineStatisticIncludesCulledPrimitives = D3D12_TRI_STATE::D3D12_TRI_STATE_UNKNOWN;
}
#endif
#if defined(D3D12_SDK_VERSION) && (D3D12_SDK_VERSION >= 602)
if (FAILED(m_pDevice->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS13, &m_dOptions13, sizeof(m_dOptions13))))
{
m_dOptions13 = {};
}
#endif
#if defined(D3D12_SDK_VERSION) && (D3D12_SDK_VERSION >= 606)
if (FAILED(m_pDevice->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS14, &m_dOptions14, sizeof(m_dOptions14))))
{
m_dOptions14 = {};
}
if (FAILED(m_pDevice->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS15, &m_dOptions15, sizeof(m_dOptions15))))
{
m_dOptions15 = {};
}
#endif
#if defined(D3D12_SDK_VERSION) && (D3D12_SDK_VERSION >= 608)
if (FAILED(m_pDevice->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS16, &m_dOptions16, sizeof(m_dOptions16))))
{
m_dOptions16 = {};
}
#endif
// Initialize per-node feature support data structures
const UINT uNodeCount = m_pDevice->GetNodeCount();
m_dProtectedResourceSessionSupport.resize(uNodeCount);
m_dArchitecture1.resize(uNodeCount);
m_dSerialization.resize(uNodeCount);
m_dProtectedResourceSessionTypeCount.resize(uNodeCount);
m_dProtectedResourceSessionTypes.resize(uNodeCount);
for (UINT NodeIndex = 0; NodeIndex < uNodeCount; NodeIndex++)
{
m_dProtectedResourceSessionSupport[NodeIndex].NodeIndex = NodeIndex;
if (FAILED(m_pDevice->CheckFeatureSupport(D3D12_FEATURE_PROTECTED_RESOURCE_SESSION_SUPPORT, &m_dProtectedResourceSessionSupport[NodeIndex], sizeof(m_dProtectedResourceSessionSupport[NodeIndex]))))
{
m_dProtectedResourceSessionSupport[NodeIndex].Support = D3D12_PROTECTED_RESOURCE_SESSION_SUPPORT_FLAG_NONE;
}
m_dArchitecture1[NodeIndex].NodeIndex = NodeIndex;
if (FAILED(m_pDevice->CheckFeatureSupport(D3D12_FEATURE_ARCHITECTURE1, &m_dArchitecture1[NodeIndex], sizeof(m_dArchitecture1[NodeIndex]))))
{
D3D12_FEATURE_DATA_ARCHITECTURE dArchLocal = {};
dArchLocal.NodeIndex = NodeIndex;
if (FAILED(m_pDevice->CheckFeatureSupport(D3D12_FEATURE_ARCHITECTURE, &dArchLocal, sizeof(dArchLocal))))
{
dArchLocal.TileBasedRenderer = false;
dArchLocal.UMA = false;
dArchLocal.CacheCoherentUMA = false;
}
m_dArchitecture1[NodeIndex].TileBasedRenderer = dArchLocal.TileBasedRenderer;
m_dArchitecture1[NodeIndex].UMA = dArchLocal.UMA;
m_dArchitecture1[NodeIndex].CacheCoherentUMA = dArchLocal.CacheCoherentUMA;
m_dArchitecture1[NodeIndex].IsolatedMMU = false;
}
m_dSerialization[NodeIndex].NodeIndex = NodeIndex;
if (FAILED(m_pDevice->CheckFeatureSupport(D3D12_FEATURE_SERIALIZATION, &m_dSerialization[NodeIndex], sizeof(m_dSerialization[NodeIndex]))))
{
m_dSerialization[NodeIndex].HeapSerializationTier = D3D12_HEAP_SERIALIZATION_TIER_0;
}
m_dProtectedResourceSessionTypeCount[NodeIndex].NodeIndex = NodeIndex;
if (FAILED(m_pDevice->CheckFeatureSupport(D3D12_FEATURE_PROTECTED_RESOURCE_SESSION_TYPE_COUNT, &m_dProtectedResourceSessionTypeCount[NodeIndex], sizeof(m_dProtectedResourceSessionTypeCount[NodeIndex]))))
{
m_dProtectedResourceSessionTypeCount[NodeIndex].Count = 0;
}
// Special procedure to initialize local protected resource session types structs
// Must wait until session type count initialized
QueryProtectedResourceSessionTypes(NodeIndex, m_dProtectedResourceSessionTypeCount[NodeIndex].Count);
}
// Initialize features that requires highest version check
if (FAILED(m_hStatus = QueryHighestShaderModel()))
{
return m_hStatus;
}
if (FAILED(m_hStatus = QueryHighestRootSignatureVersion()))
{
return m_hStatus;
}
// Initialize Feature Levels data
if (FAILED(m_hStatus = QueryHighestFeatureLevel()))
{
return m_hStatus;
}
return m_hStatus;
}
// 0: D3D12_OPTIONS
FEATURE_SUPPORT_GET(BOOL, m_dOptions, DoublePrecisionFloatShaderOps);
FEATURE_SUPPORT_GET(BOOL, m_dOptions, OutputMergerLogicOp);
FEATURE_SUPPORT_GET(D3D12_SHADER_MIN_PRECISION_SUPPORT, m_dOptions, MinPrecisionSupport);
FEATURE_SUPPORT_GET(D3D12_TILED_RESOURCES_TIER, m_dOptions, TiledResourcesTier);
FEATURE_SUPPORT_GET(D3D12_RESOURCE_BINDING_TIER, m_dOptions, ResourceBindingTier);
FEATURE_SUPPORT_GET(BOOL, m_dOptions, PSSpecifiedStencilRefSupported);
FEATURE_SUPPORT_GET(BOOL, m_dOptions, TypedUAVLoadAdditionalFormats);
FEATURE_SUPPORT_GET(BOOL, m_dOptions, ROVsSupported);
FEATURE_SUPPORT_GET(D3D12_CONSERVATIVE_RASTERIZATION_TIER, m_dOptions, ConservativeRasterizationTier);
FEATURE_SUPPORT_GET(BOOL, m_dOptions, StandardSwizzle64KBSupported);
FEATURE_SUPPORT_GET(BOOL, m_dOptions, CrossAdapterRowMajorTextureSupported);
FEATURE_SUPPORT_GET(BOOL, m_dOptions, VPAndRTArrayIndexFromAnyShaderFeedingRasterizerSupportedWithoutGSEmulation);
FEATURE_SUPPORT_GET(D3D12_RESOURCE_HEAP_TIER, m_dOptions, ResourceHeapTier);
// Special procedure for handling caps that is also part of other features
inline D3D12_CROSS_NODE_SHARING_TIER CD3DX12FeatureSupport::CrossNodeSharingTier() const noexcept
{
if (m_dCrossNode.SharingTier > D3D12_CROSS_NODE_SHARING_TIER_NOT_SUPPORTED)
{
return m_dCrossNode.SharingTier;
}
else
{
return m_dOptions.CrossNodeSharingTier;
}
}
inline UINT CD3DX12FeatureSupport::MaxGPUVirtualAddressBitsPerResource() const noexcept
{
if (m_dOptions.MaxGPUVirtualAddressBitsPerResource > 0)
{
return m_dOptions.MaxGPUVirtualAddressBitsPerResource;
}
else
{
return m_dGPUVASupport.MaxGPUVirtualAddressBitsPerResource;
}
}
// 1: Architecture
// Combined with Architecture1
// 2: Feature Levels
// Simply returns the highest supported feature level
inline D3D_FEATURE_LEVEL CD3DX12FeatureSupport::MaxSupportedFeatureLevel() const noexcept
{
return m_eMaxFeatureLevel;
}
// 3: Feature Format Support
inline HRESULT CD3DX12FeatureSupport::FormatSupport(DXGI_FORMAT Format, D3D12_FORMAT_SUPPORT1& Support1, D3D12_FORMAT_SUPPORT2& Support2) const
{
D3D12_FEATURE_DATA_FORMAT_SUPPORT dFormatSupport;
dFormatSupport.Format = Format;
// It is possible that the function call returns an error
HRESULT result = m_pDevice->CheckFeatureSupport(D3D12_FEATURE_FORMAT_SUPPORT, &dFormatSupport, sizeof(D3D12_FEATURE_DATA_FORMAT_SUPPORT));
Support1 = dFormatSupport.Support1;
Support2 = dFormatSupport.Support2; // Two outputs. Probably better just to take in the struct as an argument?
return result;
}
// 4: Multisample Quality Levels
inline HRESULT CD3DX12FeatureSupport::MultisampleQualityLevels(DXGI_FORMAT Format, UINT SampleCount, D3D12_MULTISAMPLE_QUALITY_LEVEL_FLAGS Flags, UINT& NumQualityLevels) const
{
D3D12_FEATURE_DATA_MULTISAMPLE_QUALITY_LEVELS dMultisampleQualityLevels;
dMultisampleQualityLevels.Format = Format;
dMultisampleQualityLevels.SampleCount = SampleCount;
dMultisampleQualityLevels.Flags = Flags;
HRESULT result = m_pDevice->CheckFeatureSupport(D3D12_FEATURE_MULTISAMPLE_QUALITY_LEVELS, &dMultisampleQualityLevels, sizeof(D3D12_FEATURE_DATA_MULTISAMPLE_QUALITY_LEVELS));
if (SUCCEEDED(result))
{
NumQualityLevels = dMultisampleQualityLevels.NumQualityLevels;
}
else
{
NumQualityLevels = 0;
}
return result;
}
// 5: Format Info
inline HRESULT CD3DX12FeatureSupport::FormatInfo(DXGI_FORMAT Format, UINT8& PlaneCount) const
{
D3D12_FEATURE_DATA_FORMAT_INFO dFormatInfo;
dFormatInfo.Format = Format;
HRESULT result = m_pDevice->CheckFeatureSupport(D3D12_FEATURE_FORMAT_INFO, &dFormatInfo, sizeof(D3D12_FEATURE_DATA_FORMAT_INFO));
if (FAILED(result))
{
PlaneCount = 0;
}
else
{
PlaneCount = dFormatInfo.PlaneCount;
}
return result;
}
// 6: GPU Virtual Address Support
// MaxGPUVirtualAddressBitsPerResource handled in D3D12Options
FEATURE_SUPPORT_GET(UINT, m_dGPUVASupport, MaxGPUVirtualAddressBitsPerProcess);
// 7: Shader Model
inline D3D_SHADER_MODEL CD3DX12FeatureSupport::HighestShaderModel() const noexcept
{
return m_dShaderModel.HighestShaderModel;
}
// 8: D3D12 Options1
FEATURE_SUPPORT_GET(BOOL, m_dOptions1, WaveOps);
FEATURE_SUPPORT_GET(UINT, m_dOptions1, WaveLaneCountMin);
FEATURE_SUPPORT_GET(UINT, m_dOptions1, WaveLaneCountMax);
FEATURE_SUPPORT_GET(UINT, m_dOptions1, TotalLaneCount);
FEATURE_SUPPORT_GET(BOOL, m_dOptions1, ExpandedComputeResourceStates);
FEATURE_SUPPORT_GET(BOOL, m_dOptions1, Int64ShaderOps);
// 10: Protected Resource Session Support
inline D3D12_PROTECTED_RESOURCE_SESSION_SUPPORT_FLAGS CD3DX12FeatureSupport::ProtectedResourceSessionSupport(UINT NodeIndex) const
{
return m_dProtectedResourceSessionSupport[NodeIndex].Support;
}
// 12: Root Signature
inline D3D_ROOT_SIGNATURE_VERSION CD3DX12FeatureSupport::HighestRootSignatureVersion() const noexcept
{
return m_dRootSignature.HighestVersion;
}
// 16: Architecture1
// Same data fields can be queried from m_dArchitecture
FEATURE_SUPPORT_GET_NODE_INDEXED(BOOL, m_dArchitecture1, TileBasedRenderer);
FEATURE_SUPPORT_GET_NODE_INDEXED(BOOL, m_dArchitecture1, UMA);
FEATURE_SUPPORT_GET_NODE_INDEXED(BOOL, m_dArchitecture1, CacheCoherentUMA);
FEATURE_SUPPORT_GET_NODE_INDEXED(BOOL, m_dArchitecture1, IsolatedMMU);
// 18: D3D12 Options2
FEATURE_SUPPORT_GET(BOOL, m_dOptions2, DepthBoundsTestSupported);
FEATURE_SUPPORT_GET(D3D12_PROGRAMMABLE_SAMPLE_POSITIONS_TIER, m_dOptions2, ProgrammableSamplePositionsTier);
// 19: Shader Cache
FEATURE_SUPPORT_GET_NAME(D3D12_SHADER_CACHE_SUPPORT_FLAGS, m_dShaderCache, SupportFlags, ShaderCacheSupportFlags);
// 20: Command Queue Priority
inline BOOL CD3DX12FeatureSupport::CommandQueuePrioritySupported(D3D12_COMMAND_LIST_TYPE CommandListType, UINT Priority)
{
m_dCommandQueuePriority.CommandListType = CommandListType;
m_dCommandQueuePriority.Priority = Priority;
if (FAILED(m_pDevice->CheckFeatureSupport(D3D12_FEATURE_COMMAND_QUEUE_PRIORITY, &m_dCommandQueuePriority, sizeof(D3D12_FEATURE_DATA_COMMAND_QUEUE_PRIORITY))))
{
return false;
}
return m_dCommandQueuePriority.PriorityForTypeIsSupported;
}
// 21: D3D12 Options3
FEATURE_SUPPORT_GET(BOOL, m_dOptions3, CopyQueueTimestampQueriesSupported);
FEATURE_SUPPORT_GET(BOOL, m_dOptions3, CastingFullyTypedFormatSupported);
FEATURE_SUPPORT_GET(D3D12_COMMAND_LIST_SUPPORT_FLAGS, m_dOptions3, WriteBufferImmediateSupportFlags);
FEATURE_SUPPORT_GET(D3D12_VIEW_INSTANCING_TIER, m_dOptions3, ViewInstancingTier);
FEATURE_SUPPORT_GET(BOOL, m_dOptions3, BarycentricsSupported);
// 22: Existing Heaps
FEATURE_SUPPORT_GET_NAME(BOOL, m_dExistingHeaps, Supported, ExistingHeapsSupported);
// 23: D3D12 Options4
FEATURE_SUPPORT_GET(BOOL, m_dOptions4, MSAA64KBAlignedTextureSupported);
FEATURE_SUPPORT_GET(D3D12_SHARED_RESOURCE_COMPATIBILITY_TIER, m_dOptions4, SharedResourceCompatibilityTier);
FEATURE_SUPPORT_GET(BOOL, m_dOptions4, Native16BitShaderOpsSupported);
// 24: Serialization
FEATURE_SUPPORT_GET_NODE_INDEXED(D3D12_HEAP_SERIALIZATION_TIER, m_dSerialization, HeapSerializationTier);
// 25: Cross Node
// CrossNodeSharingTier handled in D3D12Options
FEATURE_SUPPORT_GET_NAME(BOOL, m_dCrossNode, AtomicShaderInstructions, CrossNodeAtomicShaderInstructions);
// 27: D3D12 Options5
FEATURE_SUPPORT_GET(BOOL, m_dOptions5, SRVOnlyTiledResourceTier3);
FEATURE_SUPPORT_GET(D3D12_RENDER_PASS_TIER, m_dOptions5, RenderPassesTier);
FEATURE_SUPPORT_GET(D3D12_RAYTRACING_TIER, m_dOptions5, RaytracingTier);
#if defined(D3D12_SDK_VERSION) && (D3D12_SDK_VERSION >= 4)
// 28: Displayable
FEATURE_SUPPORT_GET(BOOL, m_dDisplayable, DisplayableTexture);
// SharedResourceCompatibilityTier handled in D3D12Options4
#endif
// 30: D3D12 Options6
FEATURE_SUPPORT_GET(BOOL, m_dOptions6, AdditionalShadingRatesSupported);
FEATURE_SUPPORT_GET(BOOL, m_dOptions6, PerPrimitiveShadingRateSupportedWithViewportIndexing);
FEATURE_SUPPORT_GET(D3D12_VARIABLE_SHADING_RATE_TIER, m_dOptions6, VariableShadingRateTier);
FEATURE_SUPPORT_GET(UINT, m_dOptions6, ShadingRateImageTileSize);
FEATURE_SUPPORT_GET(BOOL, m_dOptions6, BackgroundProcessingSupported);
// 31: Query Meta Command
// Keep the original call routine
inline HRESULT CD3DX12FeatureSupport::QueryMetaCommand(D3D12_FEATURE_DATA_QUERY_META_COMMAND& dQueryMetaCommand) const
{
return m_pDevice->CheckFeatureSupport(D3D12_FEATURE_QUERY_META_COMMAND, &dQueryMetaCommand, sizeof(D3D12_FEATURE_DATA_QUERY_META_COMMAND));
}
// 32: D3D12 Options7
FEATURE_SUPPORT_GET(D3D12_MESH_SHADER_TIER, m_dOptions7, MeshShaderTier);
FEATURE_SUPPORT_GET(D3D12_SAMPLER_FEEDBACK_TIER, m_dOptions7, SamplerFeedbackTier);
// 33: Protected Resource Session Type Count
FEATURE_SUPPORT_GET_NODE_INDEXED_NAME(UINT, m_dProtectedResourceSessionTypeCount, Count, ProtectedResourceSessionTypeCount);
// 34: Protected Resource Session Types
FEATURE_SUPPORT_GET_NODE_INDEXED_NAME(std::vector<GUID>, m_dProtectedResourceSessionTypes, TypeVec, ProtectedResourceSessionTypes);
#if defined(D3D12_SDK_VERSION) && (D3D12_SDK_VERSION >= 3)
// 36: Options8
FEATURE_SUPPORT_GET(BOOL, m_dOptions8, UnalignedBlockTexturesSupported);
// 37: Options9
FEATURE_SUPPORT_GET(BOOL, m_dOptions9, MeshShaderPipelineStatsSupported);
FEATURE_SUPPORT_GET(BOOL, m_dOptions9, MeshShaderSupportsFullRangeRenderTargetArrayIndex);
FEATURE_SUPPORT_GET(BOOL, m_dOptions9, AtomicInt64OnTypedResourceSupported);
FEATURE_SUPPORT_GET(BOOL, m_dOptions9, AtomicInt64OnGroupSharedSupported);
FEATURE_SUPPORT_GET(BOOL, m_dOptions9, DerivativesInMeshAndAmplificationShadersSupported);
FEATURE_SUPPORT_GET(D3D12_WAVE_MMA_TIER, m_dOptions9, WaveMMATier);
#endif
#if defined(D3D12_SDK_VERSION) && (D3D12_SDK_VERSION >= 4)
// 39: Options10
FEATURE_SUPPORT_GET(BOOL, m_dOptions10, VariableRateShadingSumCombinerSupported);
FEATURE_SUPPORT_GET(BOOL, m_dOptions10, MeshShaderPerPrimitiveShadingRateSupported);
// 40: Options11
FEATURE_SUPPORT_GET(BOOL, m_dOptions11, AtomicInt64OnDescriptorHeapResourceSupported);
#endif
#if defined(D3D12_SDK_VERSION) && (D3D12_SDK_VERSION >= 600)
// 41: Options12
FEATURE_SUPPORT_GET(D3D12_TRI_STATE, m_dOptions12, MSPrimitivesPipelineStatisticIncludesCulledPrimitives);
FEATURE_SUPPORT_GET(BOOL, m_dOptions12, EnhancedBarriersSupported);
FEATURE_SUPPORT_GET(BOOL, m_dOptions12, RelaxedFormatCastingSupported);
#endif
#if defined(D3D12_SDK_VERSION) && (D3D12_SDK_VERSION >= 602)
// 42: Options13
FEATURE_SUPPORT_GET(BOOL, m_dOptions13, UnrestrictedBufferTextureCopyPitchSupported);
FEATURE_SUPPORT_GET(BOOL, m_dOptions13, UnrestrictedVertexElementAlignmentSupported);
FEATURE_SUPPORT_GET(BOOL, m_dOptions13, InvertedViewportHeightFlipsYSupported);
FEATURE_SUPPORT_GET(BOOL, m_dOptions13, InvertedViewportDepthFlipsZSupported);
FEATURE_SUPPORT_GET(BOOL, m_dOptions13, TextureCopyBetweenDimensionsSupported);
FEATURE_SUPPORT_GET(BOOL, m_dOptions13, AlphaBlendFactorSupported);
#endif
#if defined(D3D12_SDK_VERSION) && (D3D12_SDK_VERSION >= 606)
// 43: Options14
FEATURE_SUPPORT_GET(BOOL, m_dOptions14, AdvancedTextureOpsSupported);
FEATURE_SUPPORT_GET(BOOL, m_dOptions14, WriteableMSAATexturesSupported);
FEATURE_SUPPORT_GET(BOOL, m_dOptions14, IndependentFrontAndBackStencilRefMaskSupported);
// 44: Options15
FEATURE_SUPPORT_GET(BOOL, m_dOptions15, TriangleFanSupported);
FEATURE_SUPPORT_GET(BOOL, m_dOptions15, DynamicIndexBufferStripCutSupported);
#endif
#if defined(D3D12_SDK_VERSION) && (D3D12_SDK_VERSION >= 608)
// 45: Options16
FEATURE_SUPPORT_GET(BOOL, m_dOptions16, DynamicDepthBiasSupported);
#endif
// Helper function to decide the highest shader model supported by the system
// Stores the result in m_dShaderModel
// Must be updated whenever a new shader model is added to the d3d12.h header
inline HRESULT CD3DX12FeatureSupport::QueryHighestShaderModel()
{
// Check support in descending order
HRESULT result;
const D3D_SHADER_MODEL allModelVersions[] =
{
#if defined(D3D12_SDK_VERSION) && (D3D12_SDK_VERSION >= 606)
D3D_SHADER_MODEL_6_8,
#endif
#if defined(D3D12_SDK_VERSION) && (D3D12_SDK_VERSION >= 3)
D3D_SHADER_MODEL_6_7,
#endif
D3D_SHADER_MODEL_6_6,
D3D_SHADER_MODEL_6_5,
D3D_SHADER_MODEL_6_4,
D3D_SHADER_MODEL_6_3,
D3D_SHADER_MODEL_6_2,
D3D_SHADER_MODEL_6_1,
D3D_SHADER_MODEL_6_0,
D3D_SHADER_MODEL_5_1
};
constexpr size_t numModelVersions = sizeof(allModelVersions) / sizeof(D3D_SHADER_MODEL);
for (size_t i = 0; i < numModelVersions; i++)
{
m_dShaderModel.HighestShaderModel = allModelVersions[i];
result = m_pDevice->CheckFeatureSupport(D3D12_FEATURE_SHADER_MODEL, &m_dShaderModel, sizeof(D3D12_FEATURE_DATA_SHADER_MODEL));
if (result != E_INVALIDARG)
{
// Indicates that the version is recognizable by the runtime and stored in the struct
// Also terminate on unexpected error code
if (FAILED(result))
{
m_dShaderModel.HighestShaderModel = static_cast<D3D_SHADER_MODEL>(0);
}
return result;
}
}
// Shader model may not be supported. Continue the rest initializations
m_dShaderModel.HighestShaderModel = static_cast<D3D_SHADER_MODEL>(0);
return S_OK;
}
// Helper function to decide the highest root signature supported
// Must be updated whenever a new root signature version is added to the d3d12.h header
inline HRESULT CD3DX12FeatureSupport::QueryHighestRootSignatureVersion()
{
HRESULT result;
const D3D_ROOT_SIGNATURE_VERSION allRootSignatureVersions[] =
{
D3D_ROOT_SIGNATURE_VERSION_1_1,
D3D_ROOT_SIGNATURE_VERSION_1_0,
D3D_ROOT_SIGNATURE_VERSION_1,
};
constexpr size_t numRootSignatureVersions = sizeof(allRootSignatureVersions) / sizeof(D3D_ROOT_SIGNATURE_VERSION);
for (size_t i = 0; i < numRootSignatureVersions; i++)
{
m_dRootSignature.HighestVersion = allRootSignatureVersions[i];
result = m_pDevice->CheckFeatureSupport(D3D12_FEATURE_ROOT_SIGNATURE, &m_dRootSignature, sizeof(D3D12_FEATURE_DATA_ROOT_SIGNATURE));
if (result != E_INVALIDARG)
{
if (FAILED(result))
{
m_dRootSignature.HighestVersion = static_cast<D3D_ROOT_SIGNATURE_VERSION>(0);
}
// If succeeded, the highest version is already written into the member struct
return result;
}
}
// No version left. Set to invalid value and continue.
m_dRootSignature.HighestVersion = static_cast<D3D_ROOT_SIGNATURE_VERSION>(0);
return S_OK;
}
// Helper funcion to decide the highest feature level
inline HRESULT CD3DX12FeatureSupport::QueryHighestFeatureLevel()
{
HRESULT result;
// Check against a list of all feature levels present in d3dcommon.h
// Needs to be updated for future feature levels
const D3D_FEATURE_LEVEL allLevels[] =
{
#if defined(D3D12_SDK_VERSION) && (D3D12_SDK_VERSION >= 3)
D3D_FEATURE_LEVEL_12_2,
#endif
D3D_FEATURE_LEVEL_12_1,
D3D_FEATURE_LEVEL_12_0,
D3D_FEATURE_LEVEL_11_1,
D3D_FEATURE_LEVEL_11_0,
D3D_FEATURE_LEVEL_10_1,
D3D_FEATURE_LEVEL_10_0,
D3D_FEATURE_LEVEL_9_3,
D3D_FEATURE_LEVEL_9_2,
D3D_FEATURE_LEVEL_9_1,
D3D_FEATURE_LEVEL_1_0_CORE
};
D3D12_FEATURE_DATA_FEATURE_LEVELS dFeatureLevel;
dFeatureLevel.NumFeatureLevels = static_cast<UINT>(sizeof(allLevels) / sizeof(D3D_FEATURE_LEVEL));
dFeatureLevel.pFeatureLevelsRequested = allLevels;
result = m_pDevice->CheckFeatureSupport(D3D12_FEATURE_FEATURE_LEVELS, &dFeatureLevel, sizeof(D3D12_FEATURE_DATA_FEATURE_LEVELS));
if (SUCCEEDED(result))
{
m_eMaxFeatureLevel = dFeatureLevel.MaxSupportedFeatureLevel;
}
else
{
m_eMaxFeatureLevel = static_cast<D3D_FEATURE_LEVEL>(0);
if (result == DXGI_ERROR_UNSUPPORTED)
{
// Indicates that none supported. Continue initialization
result = S_OK;
}
}
return result;
}
// Helper function to initialize local protected resource session types structs
inline HRESULT CD3DX12FeatureSupport::QueryProtectedResourceSessionTypes(UINT NodeIndex, UINT Count)
{
auto& CurrentPRSTypes = m_dProtectedResourceSessionTypes[NodeIndex];
CurrentPRSTypes.NodeIndex = NodeIndex;
CurrentPRSTypes.Count = Count;
CurrentPRSTypes.TypeVec.resize(CurrentPRSTypes.Count);
CurrentPRSTypes.pTypes = CurrentPRSTypes.TypeVec.data();
HRESULT result = m_pDevice->CheckFeatureSupport(D3D12_FEATURE_PROTECTED_RESOURCE_SESSION_TYPES, &m_dProtectedResourceSessionTypes[NodeIndex], sizeof(D3D12_FEATURE_DATA_PROTECTED_RESOURCE_SESSION_TYPES));
if (FAILED(result))
{
// Resize TypeVec to empty
CurrentPRSTypes.TypeVec.clear();
}
return result;
}
#undef FEATURE_SUPPORT_GET
#undef FEATURE_SUPPORT_GET_NAME
#undef FEATURE_SUPPORT_GET_NODE_INDEXED
#undef FEATURE_SUPPORT_GET_NODE_INDEXED_NAME
// end CD3DX12FeatureSupport

File diff suppressed because it is too large Load diff

View file

@ -1,12 +0,0 @@
//*********************************************************
//
// 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

View file

@ -1,57 +0,0 @@
//*********************************************************
//
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License (MIT).
//
//*********************************************************
#pragma once
#ifndef __cplusplus
#error D3DX12 requires C++
#endif
#include "d3d12.h"
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;
if (a.Type == D3D12_RENDER_PASS_BEGINNING_ACCESS_TYPE_CLEAR && !(a.Clear == b.Clear)) return false;
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;
if (a.Type == D3D12_RENDER_PASS_ENDING_ACCESS_TYPE_RESOLVE && !(a.Resolve == b.Resolve)) return false;
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;
}

View file

@ -1,400 +0,0 @@
//*********************************************************
//
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License (MIT).
//
//*********************************************************
#pragma once
#ifndef __cplusplus
#error D3DX12 requires C++
#endif
#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)
{
return D3DX12ConditionallyExpandAPIDesc(static_cast<CD3DX12_RESOURCE_DESC1&>(LclDesc), static_cast<const CD3DX12_RESOURCE_DESC1*>(pDesc));
}

View file

@ -1,973 +0,0 @@
//*********************************************************
//
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License (MIT).
//
//*********************************************************
#pragma once
#ifndef __cplusplus
#error D3DX12 requires C++
#endif
#include "d3d12.h"
#include "d3dx12_default.h"
//------------------------------------------------------------------------------------------------
struct CD3DX12_DESCRIPTOR_RANGE : public D3D12_DESCRIPTOR_RANGE
{
CD3DX12_DESCRIPTOR_RANGE() = default;
explicit CD3DX12_DESCRIPTOR_RANGE(const D3D12_DESCRIPTOR_RANGE &o) noexcept :
D3D12_DESCRIPTOR_RANGE(o)
{}
CD3DX12_DESCRIPTOR_RANGE(
D3D12_DESCRIPTOR_RANGE_TYPE rangeType,
UINT numDescriptors,
UINT baseShaderRegister,
UINT registerSpace = 0,
UINT offsetInDescriptorsFromTableStart =
D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND) noexcept
{
Init(rangeType, numDescriptors, baseShaderRegister, registerSpace, offsetInDescriptorsFromTableStart);
}
inline void Init(
D3D12_DESCRIPTOR_RANGE_TYPE rangeType,
UINT numDescriptors,
UINT baseShaderRegister,
UINT registerSpace = 0,
UINT offsetInDescriptorsFromTableStart =
D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND) noexcept
{
Init(*this, rangeType, numDescriptors, baseShaderRegister, registerSpace, offsetInDescriptorsFromTableStart);
}
static inline void Init(
_Out_ D3D12_DESCRIPTOR_RANGE &range,
D3D12_DESCRIPTOR_RANGE_TYPE rangeType,
UINT numDescriptors,
UINT baseShaderRegister,
UINT registerSpace = 0,
UINT offsetInDescriptorsFromTableStart =
D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND) noexcept
{
range.RangeType = rangeType;
range.NumDescriptors = numDescriptors;
range.BaseShaderRegister = baseShaderRegister;
range.RegisterSpace = registerSpace;
range.OffsetInDescriptorsFromTableStart = offsetInDescriptorsFromTableStart;
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_ROOT_DESCRIPTOR_TABLE : public D3D12_ROOT_DESCRIPTOR_TABLE
{
CD3DX12_ROOT_DESCRIPTOR_TABLE() = default;
explicit CD3DX12_ROOT_DESCRIPTOR_TABLE(const D3D12_ROOT_DESCRIPTOR_TABLE &o) noexcept :
D3D12_ROOT_DESCRIPTOR_TABLE(o)
{}
CD3DX12_ROOT_DESCRIPTOR_TABLE(
UINT numDescriptorRanges,
_In_reads_opt_(numDescriptorRanges) const D3D12_DESCRIPTOR_RANGE* _pDescriptorRanges) noexcept
{
Init(numDescriptorRanges, _pDescriptorRanges);
}
inline void Init(
UINT numDescriptorRanges,
_In_reads_opt_(numDescriptorRanges) const D3D12_DESCRIPTOR_RANGE* _pDescriptorRanges) noexcept
{
Init(*this, numDescriptorRanges, _pDescriptorRanges);
}
static inline void Init(
_Out_ D3D12_ROOT_DESCRIPTOR_TABLE &rootDescriptorTable,
UINT numDescriptorRanges,
_In_reads_opt_(numDescriptorRanges) const D3D12_DESCRIPTOR_RANGE* _pDescriptorRanges) noexcept
{
rootDescriptorTable.NumDescriptorRanges = numDescriptorRanges;
rootDescriptorTable.pDescriptorRanges = _pDescriptorRanges;
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_ROOT_CONSTANTS : public D3D12_ROOT_CONSTANTS
{
CD3DX12_ROOT_CONSTANTS() = default;
explicit CD3DX12_ROOT_CONSTANTS(const D3D12_ROOT_CONSTANTS &o) noexcept :
D3D12_ROOT_CONSTANTS(o)
{}
CD3DX12_ROOT_CONSTANTS(
UINT num32BitValues,
UINT shaderRegister,
UINT registerSpace = 0) noexcept
{
Init(num32BitValues, shaderRegister, registerSpace);
}
inline void Init(
UINT num32BitValues,
UINT shaderRegister,
UINT registerSpace = 0) noexcept
{
Init(*this, num32BitValues, shaderRegister, registerSpace);
}
static inline void Init(
_Out_ D3D12_ROOT_CONSTANTS &rootConstants,
UINT num32BitValues,
UINT shaderRegister,
UINT registerSpace = 0) noexcept
{
rootConstants.Num32BitValues = num32BitValues;
rootConstants.ShaderRegister = shaderRegister;
rootConstants.RegisterSpace = registerSpace;
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_ROOT_DESCRIPTOR : public D3D12_ROOT_DESCRIPTOR
{
CD3DX12_ROOT_DESCRIPTOR() = default;
explicit CD3DX12_ROOT_DESCRIPTOR(const D3D12_ROOT_DESCRIPTOR &o) noexcept :
D3D12_ROOT_DESCRIPTOR(o)
{}
CD3DX12_ROOT_DESCRIPTOR(
UINT shaderRegister,
UINT registerSpace = 0) noexcept
{
Init(shaderRegister, registerSpace);
}
inline void Init(
UINT shaderRegister,
UINT registerSpace = 0) noexcept
{
Init(*this, shaderRegister, registerSpace);
}
static inline void Init(_Out_ D3D12_ROOT_DESCRIPTOR &table, UINT shaderRegister, UINT registerSpace = 0) noexcept
{
table.ShaderRegister = shaderRegister;
table.RegisterSpace = registerSpace;
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_ROOT_PARAMETER : public D3D12_ROOT_PARAMETER
{
CD3DX12_ROOT_PARAMETER() = default;
explicit CD3DX12_ROOT_PARAMETER(const D3D12_ROOT_PARAMETER &o) noexcept :
D3D12_ROOT_PARAMETER(o)
{}
static inline void InitAsDescriptorTable(
_Out_ D3D12_ROOT_PARAMETER &rootParam,
UINT numDescriptorRanges,
_In_reads_(numDescriptorRanges) const D3D12_DESCRIPTOR_RANGE* pDescriptorRanges,
D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL) noexcept
{
rootParam.ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE;
rootParam.ShaderVisibility = visibility;
CD3DX12_ROOT_DESCRIPTOR_TABLE::Init(rootParam.DescriptorTable, numDescriptorRanges, pDescriptorRanges);
}
static inline void InitAsConstants(
_Out_ D3D12_ROOT_PARAMETER &rootParam,
UINT num32BitValues,
UINT shaderRegister,
UINT registerSpace = 0,
D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL) noexcept
{
rootParam.ParameterType = D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS;
rootParam.ShaderVisibility = visibility;
CD3DX12_ROOT_CONSTANTS::Init(rootParam.Constants, num32BitValues, shaderRegister, registerSpace);
}
static inline void InitAsConstantBufferView(
_Out_ D3D12_ROOT_PARAMETER &rootParam,
UINT shaderRegister,
UINT registerSpace = 0,
D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL) noexcept
{
rootParam.ParameterType = D3D12_ROOT_PARAMETER_TYPE_CBV;
rootParam.ShaderVisibility = visibility;
CD3DX12_ROOT_DESCRIPTOR::Init(rootParam.Descriptor, shaderRegister, registerSpace);
}
static inline void InitAsShaderResourceView(
_Out_ D3D12_ROOT_PARAMETER &rootParam,
UINT shaderRegister,
UINT registerSpace = 0,
D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL) noexcept
{
rootParam.ParameterType = D3D12_ROOT_PARAMETER_TYPE_SRV;
rootParam.ShaderVisibility = visibility;
CD3DX12_ROOT_DESCRIPTOR::Init(rootParam.Descriptor, shaderRegister, registerSpace);
}
static inline void InitAsUnorderedAccessView(
_Out_ D3D12_ROOT_PARAMETER &rootParam,
UINT shaderRegister,
UINT registerSpace = 0,
D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL) noexcept
{
rootParam.ParameterType = D3D12_ROOT_PARAMETER_TYPE_UAV;
rootParam.ShaderVisibility = visibility;
CD3DX12_ROOT_DESCRIPTOR::Init(rootParam.Descriptor, shaderRegister, registerSpace);
}
inline void InitAsDescriptorTable(
UINT numDescriptorRanges,
_In_reads_(numDescriptorRanges) const D3D12_DESCRIPTOR_RANGE* pDescriptorRanges,
D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL) noexcept
{
InitAsDescriptorTable(*this, numDescriptorRanges, pDescriptorRanges, visibility);
}
inline void InitAsConstants(
UINT num32BitValues,
UINT shaderRegister,
UINT registerSpace = 0,
D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL) noexcept
{
InitAsConstants(*this, num32BitValues, shaderRegister, registerSpace, visibility);
}
inline void InitAsConstantBufferView(
UINT shaderRegister,
UINT registerSpace = 0,
D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL) noexcept
{
InitAsConstantBufferView(*this, shaderRegister, registerSpace, visibility);
}
inline void InitAsShaderResourceView(
UINT shaderRegister,
UINT registerSpace = 0,
D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL) noexcept
{
InitAsShaderResourceView(*this, shaderRegister, registerSpace, visibility);
}
inline void InitAsUnorderedAccessView(
UINT shaderRegister,
UINT registerSpace = 0,
D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL) noexcept
{
InitAsUnorderedAccessView(*this, shaderRegister, registerSpace, visibility);
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_STATIC_SAMPLER_DESC : public D3D12_STATIC_SAMPLER_DESC
{
CD3DX12_STATIC_SAMPLER_DESC() = default;
explicit CD3DX12_STATIC_SAMPLER_DESC(const D3D12_STATIC_SAMPLER_DESC &o) noexcept :
D3D12_STATIC_SAMPLER_DESC(o)
{}
CD3DX12_STATIC_SAMPLER_DESC(
UINT shaderRegister,
D3D12_FILTER filter = D3D12_FILTER_ANISOTROPIC,
D3D12_TEXTURE_ADDRESS_MODE addressU = D3D12_TEXTURE_ADDRESS_MODE_WRAP,
D3D12_TEXTURE_ADDRESS_MODE addressV = D3D12_TEXTURE_ADDRESS_MODE_WRAP,
D3D12_TEXTURE_ADDRESS_MODE addressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP,
FLOAT mipLODBias = 0,
UINT maxAnisotropy = 16,
D3D12_COMPARISON_FUNC comparisonFunc = D3D12_COMPARISON_FUNC_LESS_EQUAL,
D3D12_STATIC_BORDER_COLOR borderColor = D3D12_STATIC_BORDER_COLOR_OPAQUE_WHITE,
FLOAT minLOD = 0.f,
FLOAT maxLOD = D3D12_FLOAT32_MAX,
D3D12_SHADER_VISIBILITY shaderVisibility = D3D12_SHADER_VISIBILITY_ALL,
UINT registerSpace = 0) noexcept
{
Init(
shaderRegister,
filter,
addressU,
addressV,
addressW,
mipLODBias,
maxAnisotropy,
comparisonFunc,
borderColor,
minLOD,
maxLOD,
shaderVisibility,
registerSpace);
}
static inline void Init(
_Out_ D3D12_STATIC_SAMPLER_DESC &samplerDesc,
UINT shaderRegister,
D3D12_FILTER filter = D3D12_FILTER_ANISOTROPIC,
D3D12_TEXTURE_ADDRESS_MODE addressU = D3D12_TEXTURE_ADDRESS_MODE_WRAP,
D3D12_TEXTURE_ADDRESS_MODE addressV = D3D12_TEXTURE_ADDRESS_MODE_WRAP,
D3D12_TEXTURE_ADDRESS_MODE addressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP,
FLOAT mipLODBias = 0,
UINT maxAnisotropy = 16,
D3D12_COMPARISON_FUNC comparisonFunc = D3D12_COMPARISON_FUNC_LESS_EQUAL,
D3D12_STATIC_BORDER_COLOR borderColor = D3D12_STATIC_BORDER_COLOR_OPAQUE_WHITE,
FLOAT minLOD = 0.f,
FLOAT maxLOD = D3D12_FLOAT32_MAX,
D3D12_SHADER_VISIBILITY shaderVisibility = D3D12_SHADER_VISIBILITY_ALL,
UINT registerSpace = 0) noexcept
{
samplerDesc.ShaderRegister = shaderRegister;
samplerDesc.Filter = filter;
samplerDesc.AddressU = addressU;
samplerDesc.AddressV = addressV;
samplerDesc.AddressW = addressW;
samplerDesc.MipLODBias = mipLODBias;
samplerDesc.MaxAnisotropy = maxAnisotropy;
samplerDesc.ComparisonFunc = comparisonFunc;
samplerDesc.BorderColor = borderColor;
samplerDesc.MinLOD = minLOD;
samplerDesc.MaxLOD = maxLOD;
samplerDesc.ShaderVisibility = shaderVisibility;
samplerDesc.RegisterSpace = registerSpace;
}
inline void Init(
UINT shaderRegister,
D3D12_FILTER filter = D3D12_FILTER_ANISOTROPIC,
D3D12_TEXTURE_ADDRESS_MODE addressU = D3D12_TEXTURE_ADDRESS_MODE_WRAP,
D3D12_TEXTURE_ADDRESS_MODE addressV = D3D12_TEXTURE_ADDRESS_MODE_WRAP,
D3D12_TEXTURE_ADDRESS_MODE addressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP,
FLOAT mipLODBias = 0,
UINT maxAnisotropy = 16,
D3D12_COMPARISON_FUNC comparisonFunc = D3D12_COMPARISON_FUNC_LESS_EQUAL,
D3D12_STATIC_BORDER_COLOR borderColor = D3D12_STATIC_BORDER_COLOR_OPAQUE_WHITE,
FLOAT minLOD = 0.f,
FLOAT maxLOD = D3D12_FLOAT32_MAX,
D3D12_SHADER_VISIBILITY shaderVisibility = D3D12_SHADER_VISIBILITY_ALL,
UINT registerSpace = 0) noexcept
{
Init(
*this,
shaderRegister,
filter,
addressU,
addressV,
addressW,
mipLODBias,
maxAnisotropy,
comparisonFunc,
borderColor,
minLOD,
maxLOD,
shaderVisibility,
registerSpace);
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_ROOT_SIGNATURE_DESC : public D3D12_ROOT_SIGNATURE_DESC
{
CD3DX12_ROOT_SIGNATURE_DESC() = default;
explicit CD3DX12_ROOT_SIGNATURE_DESC(const D3D12_ROOT_SIGNATURE_DESC &o) noexcept :
D3D12_ROOT_SIGNATURE_DESC(o)
{}
CD3DX12_ROOT_SIGNATURE_DESC(
UINT numParameters,
_In_reads_opt_(numParameters) const D3D12_ROOT_PARAMETER* _pParameters,
UINT numStaticSamplers = 0,
_In_reads_opt_(numStaticSamplers) const D3D12_STATIC_SAMPLER_DESC* _pStaticSamplers = nullptr,
D3D12_ROOT_SIGNATURE_FLAGS flags = D3D12_ROOT_SIGNATURE_FLAG_NONE) noexcept
{
Init(numParameters, _pParameters, numStaticSamplers, _pStaticSamplers, flags);
}
CD3DX12_ROOT_SIGNATURE_DESC(CD3DX12_DEFAULT) noexcept
{
Init(0, nullptr, 0, nullptr, D3D12_ROOT_SIGNATURE_FLAG_NONE);
}
inline void Init(
UINT numParameters,
_In_reads_opt_(numParameters) const D3D12_ROOT_PARAMETER* _pParameters,
UINT numStaticSamplers = 0,
_In_reads_opt_(numStaticSamplers) const D3D12_STATIC_SAMPLER_DESC* _pStaticSamplers = nullptr,
D3D12_ROOT_SIGNATURE_FLAGS flags = D3D12_ROOT_SIGNATURE_FLAG_NONE) noexcept
{
Init(*this, numParameters, _pParameters, numStaticSamplers, _pStaticSamplers, flags);
}
static inline void Init(
_Out_ D3D12_ROOT_SIGNATURE_DESC &desc,
UINT numParameters,
_In_reads_opt_(numParameters) const D3D12_ROOT_PARAMETER* _pParameters,
UINT numStaticSamplers = 0,
_In_reads_opt_(numStaticSamplers) const D3D12_STATIC_SAMPLER_DESC* _pStaticSamplers = nullptr,
D3D12_ROOT_SIGNATURE_FLAGS flags = D3D12_ROOT_SIGNATURE_FLAG_NONE) noexcept
{
desc.NumParameters = numParameters;
desc.pParameters = _pParameters;
desc.NumStaticSamplers = numStaticSamplers;
desc.pStaticSamplers = _pStaticSamplers;
desc.Flags = flags;
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_DESCRIPTOR_RANGE1 : public D3D12_DESCRIPTOR_RANGE1
{
CD3DX12_DESCRIPTOR_RANGE1() = default;
explicit CD3DX12_DESCRIPTOR_RANGE1(const D3D12_DESCRIPTOR_RANGE1 &o) noexcept :
D3D12_DESCRIPTOR_RANGE1(o)
{}
CD3DX12_DESCRIPTOR_RANGE1(
D3D12_DESCRIPTOR_RANGE_TYPE rangeType,
UINT numDescriptors,
UINT baseShaderRegister,
UINT registerSpace = 0,
D3D12_DESCRIPTOR_RANGE_FLAGS flags = D3D12_DESCRIPTOR_RANGE_FLAG_NONE,
UINT offsetInDescriptorsFromTableStart =
D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND) noexcept
{
Init(rangeType, numDescriptors, baseShaderRegister, registerSpace, flags, offsetInDescriptorsFromTableStart);
}
inline void Init(
D3D12_DESCRIPTOR_RANGE_TYPE rangeType,
UINT numDescriptors,
UINT baseShaderRegister,
UINT registerSpace = 0,
D3D12_DESCRIPTOR_RANGE_FLAGS flags = D3D12_DESCRIPTOR_RANGE_FLAG_NONE,
UINT offsetInDescriptorsFromTableStart =
D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND) noexcept
{
Init(*this, rangeType, numDescriptors, baseShaderRegister, registerSpace, flags, offsetInDescriptorsFromTableStart);
}
static inline void Init(
_Out_ D3D12_DESCRIPTOR_RANGE1 &range,
D3D12_DESCRIPTOR_RANGE_TYPE rangeType,
UINT numDescriptors,
UINT baseShaderRegister,
UINT registerSpace = 0,
D3D12_DESCRIPTOR_RANGE_FLAGS flags = D3D12_DESCRIPTOR_RANGE_FLAG_NONE,
UINT offsetInDescriptorsFromTableStart =
D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND) noexcept
{
range.RangeType = rangeType;
range.NumDescriptors = numDescriptors;
range.BaseShaderRegister = baseShaderRegister;
range.RegisterSpace = registerSpace;
range.Flags = flags;
range.OffsetInDescriptorsFromTableStart = offsetInDescriptorsFromTableStart;
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_ROOT_DESCRIPTOR_TABLE1 : public D3D12_ROOT_DESCRIPTOR_TABLE1
{
CD3DX12_ROOT_DESCRIPTOR_TABLE1() = default;
explicit CD3DX12_ROOT_DESCRIPTOR_TABLE1(const D3D12_ROOT_DESCRIPTOR_TABLE1 &o) noexcept :
D3D12_ROOT_DESCRIPTOR_TABLE1(o)
{}
CD3DX12_ROOT_DESCRIPTOR_TABLE1(
UINT numDescriptorRanges,
_In_reads_opt_(numDescriptorRanges) const D3D12_DESCRIPTOR_RANGE1* _pDescriptorRanges) noexcept
{
Init(numDescriptorRanges, _pDescriptorRanges);
}
inline void Init(
UINT numDescriptorRanges,
_In_reads_opt_(numDescriptorRanges) const D3D12_DESCRIPTOR_RANGE1* _pDescriptorRanges) noexcept
{
Init(*this, numDescriptorRanges, _pDescriptorRanges);
}
static inline void Init(
_Out_ D3D12_ROOT_DESCRIPTOR_TABLE1 &rootDescriptorTable,
UINT numDescriptorRanges,
_In_reads_opt_(numDescriptorRanges) const D3D12_DESCRIPTOR_RANGE1* _pDescriptorRanges) noexcept
{
rootDescriptorTable.NumDescriptorRanges = numDescriptorRanges;
rootDescriptorTable.pDescriptorRanges = _pDescriptorRanges;
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_ROOT_DESCRIPTOR1 : public D3D12_ROOT_DESCRIPTOR1
{
CD3DX12_ROOT_DESCRIPTOR1() = default;
explicit CD3DX12_ROOT_DESCRIPTOR1(const D3D12_ROOT_DESCRIPTOR1 &o) noexcept :
D3D12_ROOT_DESCRIPTOR1(o)
{}
CD3DX12_ROOT_DESCRIPTOR1(
UINT shaderRegister,
UINT registerSpace = 0,
D3D12_ROOT_DESCRIPTOR_FLAGS flags = D3D12_ROOT_DESCRIPTOR_FLAG_NONE) noexcept
{
Init(shaderRegister, registerSpace, flags);
}
inline void Init(
UINT shaderRegister,
UINT registerSpace = 0,
D3D12_ROOT_DESCRIPTOR_FLAGS flags = D3D12_ROOT_DESCRIPTOR_FLAG_NONE) noexcept
{
Init(*this, shaderRegister, registerSpace, flags);
}
static inline void Init(
_Out_ D3D12_ROOT_DESCRIPTOR1 &table,
UINT shaderRegister,
UINT registerSpace = 0,
D3D12_ROOT_DESCRIPTOR_FLAGS flags = D3D12_ROOT_DESCRIPTOR_FLAG_NONE) noexcept
{
table.ShaderRegister = shaderRegister;
table.RegisterSpace = registerSpace;
table.Flags = flags;
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_ROOT_PARAMETER1 : public D3D12_ROOT_PARAMETER1
{
CD3DX12_ROOT_PARAMETER1() = default;
explicit CD3DX12_ROOT_PARAMETER1(const D3D12_ROOT_PARAMETER1 &o) noexcept :
D3D12_ROOT_PARAMETER1(o)
{}
static inline void InitAsDescriptorTable(
_Out_ D3D12_ROOT_PARAMETER1 &rootParam,
UINT numDescriptorRanges,
_In_reads_(numDescriptorRanges) const D3D12_DESCRIPTOR_RANGE1* pDescriptorRanges,
D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL) noexcept
{
rootParam.ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE;
rootParam.ShaderVisibility = visibility;
CD3DX12_ROOT_DESCRIPTOR_TABLE1::Init(rootParam.DescriptorTable, numDescriptorRanges, pDescriptorRanges);
}
static inline void InitAsConstants(
_Out_ D3D12_ROOT_PARAMETER1 &rootParam,
UINT num32BitValues,
UINT shaderRegister,
UINT registerSpace = 0,
D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL) noexcept
{
rootParam.ParameterType = D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS;
rootParam.ShaderVisibility = visibility;
CD3DX12_ROOT_CONSTANTS::Init(rootParam.Constants, num32BitValues, shaderRegister, registerSpace);
}
static inline void InitAsConstantBufferView(
_Out_ D3D12_ROOT_PARAMETER1 &rootParam,
UINT shaderRegister,
UINT registerSpace = 0,
D3D12_ROOT_DESCRIPTOR_FLAGS flags = D3D12_ROOT_DESCRIPTOR_FLAG_NONE,
D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL) noexcept
{
rootParam.ParameterType = D3D12_ROOT_PARAMETER_TYPE_CBV;
rootParam.ShaderVisibility = visibility;
CD3DX12_ROOT_DESCRIPTOR1::Init(rootParam.Descriptor, shaderRegister, registerSpace, flags);
}
static inline void InitAsShaderResourceView(
_Out_ D3D12_ROOT_PARAMETER1 &rootParam,
UINT shaderRegister,
UINT registerSpace = 0,
D3D12_ROOT_DESCRIPTOR_FLAGS flags = D3D12_ROOT_DESCRIPTOR_FLAG_NONE,
D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL) noexcept
{
rootParam.ParameterType = D3D12_ROOT_PARAMETER_TYPE_SRV;
rootParam.ShaderVisibility = visibility;
CD3DX12_ROOT_DESCRIPTOR1::Init(rootParam.Descriptor, shaderRegister, registerSpace, flags);
}
static inline void InitAsUnorderedAccessView(
_Out_ D3D12_ROOT_PARAMETER1 &rootParam,
UINT shaderRegister,
UINT registerSpace = 0,
D3D12_ROOT_DESCRIPTOR_FLAGS flags = D3D12_ROOT_DESCRIPTOR_FLAG_NONE,
D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL) noexcept
{
rootParam.ParameterType = D3D12_ROOT_PARAMETER_TYPE_UAV;
rootParam.ShaderVisibility = visibility;
CD3DX12_ROOT_DESCRIPTOR1::Init(rootParam.Descriptor, shaderRegister, registerSpace, flags);
}
inline void InitAsDescriptorTable(
UINT numDescriptorRanges,
_In_reads_(numDescriptorRanges) const D3D12_DESCRIPTOR_RANGE1* pDescriptorRanges,
D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL) noexcept
{
InitAsDescriptorTable(*this, numDescriptorRanges, pDescriptorRanges, visibility);
}
inline void InitAsConstants(
UINT num32BitValues,
UINT shaderRegister,
UINT registerSpace = 0,
D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL) noexcept
{
InitAsConstants(*this, num32BitValues, shaderRegister, registerSpace, visibility);
}
inline void InitAsConstantBufferView(
UINT shaderRegister,
UINT registerSpace = 0,
D3D12_ROOT_DESCRIPTOR_FLAGS flags = D3D12_ROOT_DESCRIPTOR_FLAG_NONE,
D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL) noexcept
{
InitAsConstantBufferView(*this, shaderRegister, registerSpace, flags, visibility);
}
inline void InitAsShaderResourceView(
UINT shaderRegister,
UINT registerSpace = 0,
D3D12_ROOT_DESCRIPTOR_FLAGS flags = D3D12_ROOT_DESCRIPTOR_FLAG_NONE,
D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL) noexcept
{
InitAsShaderResourceView(*this, shaderRegister, registerSpace, flags, visibility);
}
inline void InitAsUnorderedAccessView(
UINT shaderRegister,
UINT registerSpace = 0,
D3D12_ROOT_DESCRIPTOR_FLAGS flags = D3D12_ROOT_DESCRIPTOR_FLAG_NONE,
D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL) noexcept
{
InitAsUnorderedAccessView(*this, shaderRegister, registerSpace, flags, visibility);
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_VERSIONED_ROOT_SIGNATURE_DESC : public D3D12_VERSIONED_ROOT_SIGNATURE_DESC
{
CD3DX12_VERSIONED_ROOT_SIGNATURE_DESC() = default;
explicit CD3DX12_VERSIONED_ROOT_SIGNATURE_DESC(const D3D12_VERSIONED_ROOT_SIGNATURE_DESC &o) noexcept :
D3D12_VERSIONED_ROOT_SIGNATURE_DESC(o)
{}
explicit CD3DX12_VERSIONED_ROOT_SIGNATURE_DESC(const D3D12_ROOT_SIGNATURE_DESC &o) noexcept
{
Version = D3D_ROOT_SIGNATURE_VERSION_1_0;
Desc_1_0 = o;
}
explicit CD3DX12_VERSIONED_ROOT_SIGNATURE_DESC(const D3D12_ROOT_SIGNATURE_DESC1 &o) noexcept
{
Version = D3D_ROOT_SIGNATURE_VERSION_1_1;
Desc_1_1 = o;
}
CD3DX12_VERSIONED_ROOT_SIGNATURE_DESC(
UINT numParameters,
_In_reads_opt_(numParameters) const D3D12_ROOT_PARAMETER* _pParameters,
UINT numStaticSamplers = 0,
_In_reads_opt_(numStaticSamplers) const D3D12_STATIC_SAMPLER_DESC* _pStaticSamplers = nullptr,
D3D12_ROOT_SIGNATURE_FLAGS flags = D3D12_ROOT_SIGNATURE_FLAG_NONE) noexcept
{
Init_1_0(numParameters, _pParameters, numStaticSamplers, _pStaticSamplers, flags);
}
CD3DX12_VERSIONED_ROOT_SIGNATURE_DESC(
UINT numParameters,
_In_reads_opt_(numParameters) const D3D12_ROOT_PARAMETER1* _pParameters,
UINT numStaticSamplers = 0,
_In_reads_opt_(numStaticSamplers) const D3D12_STATIC_SAMPLER_DESC* _pStaticSamplers = nullptr,
D3D12_ROOT_SIGNATURE_FLAGS flags = D3D12_ROOT_SIGNATURE_FLAG_NONE) noexcept
{
Init_1_1(numParameters, _pParameters, numStaticSamplers, _pStaticSamplers, flags);
}
CD3DX12_VERSIONED_ROOT_SIGNATURE_DESC(CD3DX12_DEFAULT) noexcept
{
Init_1_1(0, nullptr, 0, nullptr, D3D12_ROOT_SIGNATURE_FLAG_NONE);
}
inline void Init_1_0(
UINT numParameters,
_In_reads_opt_(numParameters) const D3D12_ROOT_PARAMETER* _pParameters,
UINT numStaticSamplers = 0,
_In_reads_opt_(numStaticSamplers) const D3D12_STATIC_SAMPLER_DESC* _pStaticSamplers = nullptr,
D3D12_ROOT_SIGNATURE_FLAGS flags = D3D12_ROOT_SIGNATURE_FLAG_NONE) noexcept
{
Init_1_0(*this, numParameters, _pParameters, numStaticSamplers, _pStaticSamplers, flags);
}
static inline void Init_1_0(
_Out_ D3D12_VERSIONED_ROOT_SIGNATURE_DESC &desc,
UINT numParameters,
_In_reads_opt_(numParameters) const D3D12_ROOT_PARAMETER* _pParameters,
UINT numStaticSamplers = 0,
_In_reads_opt_(numStaticSamplers) const D3D12_STATIC_SAMPLER_DESC* _pStaticSamplers = nullptr,
D3D12_ROOT_SIGNATURE_FLAGS flags = D3D12_ROOT_SIGNATURE_FLAG_NONE) noexcept
{
desc.Version = D3D_ROOT_SIGNATURE_VERSION_1_0;
desc.Desc_1_0.NumParameters = numParameters;
desc.Desc_1_0.pParameters = _pParameters;
desc.Desc_1_0.NumStaticSamplers = numStaticSamplers;
desc.Desc_1_0.pStaticSamplers = _pStaticSamplers;
desc.Desc_1_0.Flags = flags;
}
inline void Init_1_1(
UINT numParameters,
_In_reads_opt_(numParameters) const D3D12_ROOT_PARAMETER1* _pParameters,
UINT numStaticSamplers = 0,
_In_reads_opt_(numStaticSamplers) const D3D12_STATIC_SAMPLER_DESC* _pStaticSamplers = nullptr,
D3D12_ROOT_SIGNATURE_FLAGS flags = D3D12_ROOT_SIGNATURE_FLAG_NONE) noexcept
{
Init_1_1(*this, numParameters, _pParameters, numStaticSamplers, _pStaticSamplers, flags);
}
static inline void Init_1_1(
_Out_ D3D12_VERSIONED_ROOT_SIGNATURE_DESC &desc,
UINT numParameters,
_In_reads_opt_(numParameters) const D3D12_ROOT_PARAMETER1* _pParameters,
UINT numStaticSamplers = 0,
_In_reads_opt_(numStaticSamplers) const D3D12_STATIC_SAMPLER_DESC* _pStaticSamplers = nullptr,
D3D12_ROOT_SIGNATURE_FLAGS flags = D3D12_ROOT_SIGNATURE_FLAG_NONE) noexcept
{
desc.Version = D3D_ROOT_SIGNATURE_VERSION_1_1;
desc.Desc_1_1.NumParameters = numParameters;
desc.Desc_1_1.pParameters = _pParameters;
desc.Desc_1_1.NumStaticSamplers = numStaticSamplers;
desc.Desc_1_1.pStaticSamplers = _pStaticSamplers;
desc.Desc_1_1.Flags = flags;
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_CPU_DESCRIPTOR_HANDLE : public D3D12_CPU_DESCRIPTOR_HANDLE
{
CD3DX12_CPU_DESCRIPTOR_HANDLE() = default;
explicit CD3DX12_CPU_DESCRIPTOR_HANDLE(const D3D12_CPU_DESCRIPTOR_HANDLE &o) noexcept :
D3D12_CPU_DESCRIPTOR_HANDLE(o)
{}
CD3DX12_CPU_DESCRIPTOR_HANDLE(CD3DX12_DEFAULT) noexcept { ptr = 0; }
CD3DX12_CPU_DESCRIPTOR_HANDLE(_In_ const D3D12_CPU_DESCRIPTOR_HANDLE &other, INT offsetScaledByIncrementSize) noexcept
{
InitOffsetted(other, offsetScaledByIncrementSize);
}
CD3DX12_CPU_DESCRIPTOR_HANDLE(_In_ const D3D12_CPU_DESCRIPTOR_HANDLE &other, INT offsetInDescriptors, UINT descriptorIncrementSize) noexcept
{
InitOffsetted(other, offsetInDescriptors, descriptorIncrementSize);
}
CD3DX12_CPU_DESCRIPTOR_HANDLE& Offset(INT offsetInDescriptors, UINT descriptorIncrementSize) noexcept
{
ptr = SIZE_T(INT64(ptr) + INT64(offsetInDescriptors) * INT64(descriptorIncrementSize));
return *this;
}
CD3DX12_CPU_DESCRIPTOR_HANDLE& Offset(INT offsetScaledByIncrementSize) noexcept
{
ptr = SIZE_T(INT64(ptr) + INT64(offsetScaledByIncrementSize));
return *this;
}
bool operator==(_In_ const D3D12_CPU_DESCRIPTOR_HANDLE& other) const noexcept
{
return (ptr == other.ptr);
}
bool operator!=(_In_ const D3D12_CPU_DESCRIPTOR_HANDLE& other) const noexcept
{
return (ptr != other.ptr);
}
CD3DX12_CPU_DESCRIPTOR_HANDLE &operator=(const D3D12_CPU_DESCRIPTOR_HANDLE &other) noexcept
{
ptr = other.ptr;
return *this;
}
inline void InitOffsetted(_In_ const D3D12_CPU_DESCRIPTOR_HANDLE &base, INT offsetScaledByIncrementSize) noexcept
{
InitOffsetted(*this, base, offsetScaledByIncrementSize);
}
inline void InitOffsetted(_In_ const D3D12_CPU_DESCRIPTOR_HANDLE &base, INT offsetInDescriptors, UINT descriptorIncrementSize) noexcept
{
InitOffsetted(*this, base, offsetInDescriptors, descriptorIncrementSize);
}
static inline void InitOffsetted(_Out_ D3D12_CPU_DESCRIPTOR_HANDLE &handle, _In_ const D3D12_CPU_DESCRIPTOR_HANDLE &base, INT offsetScaledByIncrementSize) noexcept
{
handle.ptr = SIZE_T(INT64(base.ptr) + INT64(offsetScaledByIncrementSize));
}
static inline void InitOffsetted(_Out_ D3D12_CPU_DESCRIPTOR_HANDLE &handle, _In_ const D3D12_CPU_DESCRIPTOR_HANDLE &base, INT offsetInDescriptors, UINT descriptorIncrementSize) noexcept
{
handle.ptr = SIZE_T(INT64(base.ptr) + INT64(offsetInDescriptors) * INT64(descriptorIncrementSize));
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_GPU_DESCRIPTOR_HANDLE : public D3D12_GPU_DESCRIPTOR_HANDLE
{
CD3DX12_GPU_DESCRIPTOR_HANDLE() = default;
explicit CD3DX12_GPU_DESCRIPTOR_HANDLE(const D3D12_GPU_DESCRIPTOR_HANDLE &o) noexcept :
D3D12_GPU_DESCRIPTOR_HANDLE(o)
{}
CD3DX12_GPU_DESCRIPTOR_HANDLE(CD3DX12_DEFAULT) noexcept { ptr = 0; }
CD3DX12_GPU_DESCRIPTOR_HANDLE(_In_ const D3D12_GPU_DESCRIPTOR_HANDLE &other, INT offsetScaledByIncrementSize) noexcept
{
InitOffsetted(other, offsetScaledByIncrementSize);
}
CD3DX12_GPU_DESCRIPTOR_HANDLE(_In_ const D3D12_GPU_DESCRIPTOR_HANDLE &other, INT offsetInDescriptors, UINT descriptorIncrementSize) noexcept
{
InitOffsetted(other, offsetInDescriptors, descriptorIncrementSize);
}
CD3DX12_GPU_DESCRIPTOR_HANDLE& Offset(INT offsetInDescriptors, UINT descriptorIncrementSize) noexcept
{
ptr = UINT64(INT64(ptr) + INT64(offsetInDescriptors) * INT64(descriptorIncrementSize));
return *this;
}
CD3DX12_GPU_DESCRIPTOR_HANDLE& Offset(INT offsetScaledByIncrementSize) noexcept
{
ptr = UINT64(INT64(ptr) + INT64(offsetScaledByIncrementSize));
return *this;
}
inline bool operator==(_In_ const D3D12_GPU_DESCRIPTOR_HANDLE& other) const noexcept
{
return (ptr == other.ptr);
}
inline bool operator!=(_In_ const D3D12_GPU_DESCRIPTOR_HANDLE& other) const noexcept
{
return (ptr != other.ptr);
}
CD3DX12_GPU_DESCRIPTOR_HANDLE &operator=(const D3D12_GPU_DESCRIPTOR_HANDLE &other) noexcept
{
ptr = other.ptr;
return *this;
}
inline void InitOffsetted(_In_ const D3D12_GPU_DESCRIPTOR_HANDLE &base, INT offsetScaledByIncrementSize) noexcept
{
InitOffsetted(*this, base, offsetScaledByIncrementSize);
}
inline void InitOffsetted(_In_ const D3D12_GPU_DESCRIPTOR_HANDLE &base, INT offsetInDescriptors, UINT descriptorIncrementSize) noexcept
{
InitOffsetted(*this, base, offsetInDescriptors, descriptorIncrementSize);
}
static inline void InitOffsetted(_Out_ D3D12_GPU_DESCRIPTOR_HANDLE &handle, _In_ const D3D12_GPU_DESCRIPTOR_HANDLE &base, INT offsetScaledByIncrementSize) noexcept
{
handle.ptr = UINT64(INT64(base.ptr) + INT64(offsetScaledByIncrementSize));
}
static inline void InitOffsetted(_Out_ D3D12_GPU_DESCRIPTOR_HANDLE &handle, _In_ const D3D12_GPU_DESCRIPTOR_HANDLE &base, INT offsetInDescriptors, UINT descriptorIncrementSize) noexcept
{
handle.ptr = UINT64(INT64(base.ptr) + INT64(offsetInDescriptors) * INT64(descriptorIncrementSize));
}
};
//------------------------------------------------------------------------------------------------
// D3D12 exports a new method for serializing root signatures in the Windows 10 Anniversary Update.
// To help enable root signature 1.1 features when they are available and not require maintaining
// two code paths for building root signatures, this helper method reconstructs a 1.0 signature when
// 1.1 is not supported.
inline HRESULT D3DX12SerializeVersionedRootSignature(
_In_ const D3D12_VERSIONED_ROOT_SIGNATURE_DESC* pRootSignatureDesc,
D3D_ROOT_SIGNATURE_VERSION MaxVersion,
_Outptr_ ID3DBlob** ppBlob,
_Always_(_Outptr_opt_result_maybenull_) ID3DBlob** ppErrorBlob) noexcept
{
if (ppErrorBlob != nullptr)
{
*ppErrorBlob = nullptr;
}
switch (MaxVersion)
{
case D3D_ROOT_SIGNATURE_VERSION_1_0:
switch (pRootSignatureDesc->Version)
{
case D3D_ROOT_SIGNATURE_VERSION_1_0:
return D3D12SerializeRootSignature(&pRootSignatureDesc->Desc_1_0, D3D_ROOT_SIGNATURE_VERSION_1, ppBlob, ppErrorBlob);
case D3D_ROOT_SIGNATURE_VERSION_1_1:
{
HRESULT hr = S_OK;
const D3D12_ROOT_SIGNATURE_DESC1& desc_1_1 = pRootSignatureDesc->Desc_1_1;
const SIZE_T ParametersSize = sizeof(D3D12_ROOT_PARAMETER) * desc_1_1.NumParameters;
void* pParameters = (ParametersSize > 0) ? HeapAlloc(GetProcessHeap(), 0, ParametersSize) : nullptr;
if (ParametersSize > 0 && pParameters == nullptr)
{
hr = E_OUTOFMEMORY;
}
auto pParameters_1_0 = static_cast<D3D12_ROOT_PARAMETER*>(pParameters);
if (SUCCEEDED(hr))
{
for (UINT n = 0; n < desc_1_1.NumParameters; n++)
{
__analysis_assume(ParametersSize == sizeof(D3D12_ROOT_PARAMETER) * desc_1_1.NumParameters);
pParameters_1_0[n].ParameterType = desc_1_1.pParameters[n].ParameterType;
pParameters_1_0[n].ShaderVisibility = desc_1_1.pParameters[n].ShaderVisibility;
switch (desc_1_1.pParameters[n].ParameterType)
{
case D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS:
pParameters_1_0[n].Constants.Num32BitValues = desc_1_1.pParameters[n].Constants.Num32BitValues;
pParameters_1_0[n].Constants.RegisterSpace = desc_1_1.pParameters[n].Constants.RegisterSpace;
pParameters_1_0[n].Constants.ShaderRegister = desc_1_1.pParameters[n].Constants.ShaderRegister;
break;
case D3D12_ROOT_PARAMETER_TYPE_CBV:
case D3D12_ROOT_PARAMETER_TYPE_SRV:
case D3D12_ROOT_PARAMETER_TYPE_UAV:
pParameters_1_0[n].Descriptor.RegisterSpace = desc_1_1.pParameters[n].Descriptor.RegisterSpace;
pParameters_1_0[n].Descriptor.ShaderRegister = desc_1_1.pParameters[n].Descriptor.ShaderRegister;
break;
case D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE:
const D3D12_ROOT_DESCRIPTOR_TABLE1& table_1_1 = desc_1_1.pParameters[n].DescriptorTable;
const SIZE_T DescriptorRangesSize = sizeof(D3D12_DESCRIPTOR_RANGE) * table_1_1.NumDescriptorRanges;
void* pDescriptorRanges = (DescriptorRangesSize > 0 && SUCCEEDED(hr)) ? HeapAlloc(GetProcessHeap(), 0, DescriptorRangesSize) : nullptr;
if (DescriptorRangesSize > 0 && pDescriptorRanges == nullptr)
{
hr = E_OUTOFMEMORY;
}
auto pDescriptorRanges_1_0 = static_cast<D3D12_DESCRIPTOR_RANGE*>(pDescriptorRanges);
if (SUCCEEDED(hr))
{
for (UINT x = 0; x < table_1_1.NumDescriptorRanges; x++)
{
__analysis_assume(DescriptorRangesSize == sizeof(D3D12_DESCRIPTOR_RANGE) * table_1_1.NumDescriptorRanges);
pDescriptorRanges_1_0[x].BaseShaderRegister = table_1_1.pDescriptorRanges[x].BaseShaderRegister;
pDescriptorRanges_1_0[x].NumDescriptors = table_1_1.pDescriptorRanges[x].NumDescriptors;
pDescriptorRanges_1_0[x].OffsetInDescriptorsFromTableStart = table_1_1.pDescriptorRanges[x].OffsetInDescriptorsFromTableStart;
pDescriptorRanges_1_0[x].RangeType = table_1_1.pDescriptorRanges[x].RangeType;
pDescriptorRanges_1_0[x].RegisterSpace = table_1_1.pDescriptorRanges[x].RegisterSpace;
}
}
D3D12_ROOT_DESCRIPTOR_TABLE& table_1_0 = pParameters_1_0[n].DescriptorTable;
table_1_0.NumDescriptorRanges = table_1_1.NumDescriptorRanges;
table_1_0.pDescriptorRanges = pDescriptorRanges_1_0;
}
}
}
if (SUCCEEDED(hr))
{
const CD3DX12_ROOT_SIGNATURE_DESC desc_1_0(desc_1_1.NumParameters, pParameters_1_0, desc_1_1.NumStaticSamplers, desc_1_1.pStaticSamplers, desc_1_1.Flags);
hr = D3D12SerializeRootSignature(&desc_1_0, D3D_ROOT_SIGNATURE_VERSION_1, ppBlob, ppErrorBlob);
}
if (pParameters)
{
for (UINT n = 0; n < desc_1_1.NumParameters; n++)
{
if (desc_1_1.pParameters[n].ParameterType == D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE)
{
auto pDescriptorRanges_1_0 = pParameters_1_0[n].DescriptorTable.pDescriptorRanges;
HeapFree(GetProcessHeap(), 0, reinterpret_cast<void*>(const_cast<D3D12_DESCRIPTOR_RANGE*>(pDescriptorRanges_1_0)));
}
}
HeapFree(GetProcessHeap(), 0, pParameters);
}
return hr;
}
}
break;
case D3D_ROOT_SIGNATURE_VERSION_1_1:
return D3D12SerializeVersionedRootSignature(pRootSignatureDesc, ppBlob, ppErrorBlob);
}
return E_INVALIDARG;
}

View file

@ -1,790 +0,0 @@
//*********************************************************
//
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License (MIT).
//
//*********************************************************
#pragma once
#ifndef __cplusplus
#error D3DX12 requires C++
#endif
#include "d3d12.h"
//================================================================================================
// D3DX12 State Object Creation Helpers
//
// Helper classes for creating new style state objects out of an arbitrary set of subobjects.
// Uses STL
//
// Start by instantiating CD3DX12_STATE_OBJECT_DESC (see its public methods).
// One of its methods is CreateSubobject(), which has a comment showing a couple of options for
// defining subobjects using the helper classes for each subobject (CD3DX12_DXIL_LIBRARY_SUBOBJECT
// etc.). The subobject helpers each have methods specific to the subobject for configuring its
// contents.
//
//================================================================================================
#include <list>
#include <memory>
#include <string>
#include <vector>
#ifndef D3DX12_USE_ATL
#include <wrl/client.h>
#define D3DX12_COM_PTR Microsoft::WRL::ComPtr
#define D3DX12_COM_PTR_GET(x) x.Get()
#define D3DX12_COM_PTR_ADDRESSOF(x) x.GetAddressOf()
#else
#include <atlbase.h>
#define D3DX12_COM_PTR ATL::CComPtr
#define D3DX12_COM_PTR_GET(x) x.p
#define D3DX12_COM_PTR_ADDRESSOF(x) &x.p
#endif
//------------------------------------------------------------------------------------------------
class CD3DX12_STATE_OBJECT_DESC
{
public:
CD3DX12_STATE_OBJECT_DESC() noexcept
{
Init(D3D12_STATE_OBJECT_TYPE_COLLECTION);
}
CD3DX12_STATE_OBJECT_DESC(D3D12_STATE_OBJECT_TYPE Type) noexcept
{
Init(Type);
}
void SetStateObjectType(D3D12_STATE_OBJECT_TYPE Type) noexcept { m_Desc.Type = Type; }
operator const D3D12_STATE_OBJECT_DESC&()
{
// Do final preparation work
m_RepointedAssociations.clear();
m_SubobjectArray.clear();
m_SubobjectArray.reserve(m_Desc.NumSubobjects);
// Flatten subobjects into an array (each flattened subobject still has a
// member that's a pointer to its desc that's not flattened)
for (auto Iter = m_SubobjectList.begin();
Iter != m_SubobjectList.end(); Iter++)
{
m_SubobjectArray.push_back(*Iter);
// Store new location in array so we can redirect pointers contained in subobjects
Iter->pSubobjectArrayLocation = &m_SubobjectArray.back();
}
// For subobjects with pointer fields, create a new copy of those subobject definitions
// with fixed pointers
for (UINT i = 0; i < m_Desc.NumSubobjects; i++)
{
if (m_SubobjectArray[i].Type == D3D12_STATE_SUBOBJECT_TYPE_SUBOBJECT_TO_EXPORTS_ASSOCIATION)
{
auto pOriginalSubobjectAssociation =
static_cast<const D3D12_SUBOBJECT_TO_EXPORTS_ASSOCIATION*>(m_SubobjectArray[i].pDesc);
D3D12_SUBOBJECT_TO_EXPORTS_ASSOCIATION Repointed = *pOriginalSubobjectAssociation;
auto pWrapper =
static_cast<const SUBOBJECT_WRAPPER*>(pOriginalSubobjectAssociation->pSubobjectToAssociate);
Repointed.pSubobjectToAssociate = pWrapper->pSubobjectArrayLocation;
m_RepointedAssociations.push_back(Repointed);
m_SubobjectArray[i].pDesc = &m_RepointedAssociations.back();
}
}
// Below: using ugly way to get pointer in case .data() is not defined
m_Desc.pSubobjects = m_Desc.NumSubobjects ? &m_SubobjectArray[0] : nullptr;
return m_Desc;
}
operator const D3D12_STATE_OBJECT_DESC*()
{
// Cast calls the above final preparation work
return &static_cast<const D3D12_STATE_OBJECT_DESC&>(*this);
}
// CreateSubobject creates a sububject helper (e.g. CD3DX12_HIT_GROUP_SUBOBJECT)
// whose lifetime is owned by this class.
// e.g.
//
// CD3DX12_STATE_OBJECT_DESC Collection1(D3D12_STATE_OBJECT_TYPE_COLLECTION);
// auto Lib0 = Collection1.CreateSubobject<CD3DX12_DXIL_LIBRARY_SUBOBJECT>();
// Lib0->SetDXILLibrary(&pMyAppDxilLibs[0]);
// Lib0->DefineExport(L"rayGenShader0"); // in practice these export listings might be
// // data/engine driven
// etc.
//
// Alternatively, users can instantiate sububject helpers explicitly, such as via local
// variables instead, passing the state object desc that should point to it into the helper
// constructor (or call mySubobjectHelper.AddToStateObject(Collection1)).
// In this alternative scenario, the user must keep the subobject alive as long as the state
// object it is associated with is alive, else its pointer references will be stale.
// e.g.
//
// CD3DX12_STATE_OBJECT_DESC RaytracingState2(D3D12_STATE_OBJECT_TYPE_RAYTRACING_PIPELINE);
// CD3DX12_DXIL_LIBRARY_SUBOBJECT LibA(RaytracingState2);
// LibA.SetDXILLibrary(&pMyAppDxilLibs[4]); // not manually specifying exports
// // - meaning all exports in the libraries
// // are exported
// etc.
template<typename T>
T* CreateSubobject()
{
T* pSubobject = new T(*this);
m_OwnedSubobjectHelpers.emplace_back(pSubobject);
return pSubobject;
}
private:
D3D12_STATE_SUBOBJECT* TrackSubobject(D3D12_STATE_SUBOBJECT_TYPE Type, void* pDesc)
{
SUBOBJECT_WRAPPER Subobject;
Subobject.pSubobjectArrayLocation = nullptr;
Subobject.Type = Type;
Subobject.pDesc = pDesc;
m_SubobjectList.push_back(Subobject);
m_Desc.NumSubobjects++;
return &m_SubobjectList.back();
}
void Init(D3D12_STATE_OBJECT_TYPE Type) noexcept
{
SetStateObjectType(Type);
m_Desc.pSubobjects = nullptr;
m_Desc.NumSubobjects = 0;
m_SubobjectList.clear();
m_SubobjectArray.clear();
m_RepointedAssociations.clear();
}
typedef struct SUBOBJECT_WRAPPER : public D3D12_STATE_SUBOBJECT
{
D3D12_STATE_SUBOBJECT* pSubobjectArrayLocation; // new location when flattened into array
// for repointing pointers in subobjects
} SUBOBJECT_WRAPPER;
D3D12_STATE_OBJECT_DESC m_Desc;
std::list<SUBOBJECT_WRAPPER> m_SubobjectList; // Pointers to list nodes handed out so
// these can be edited live
std::vector<D3D12_STATE_SUBOBJECT> m_SubobjectArray; // Built at the end, copying list contents
std::list<D3D12_SUBOBJECT_TO_EXPORTS_ASSOCIATION>
m_RepointedAssociations; // subobject type that contains pointers to other subobjects,
// repointed to flattened array
class StringContainer
{
public:
LPCWSTR LocalCopy(LPCWSTR string, bool bSingleString = false)
{
if (string)
{
if (bSingleString)
{
m_Strings.clear();
m_Strings.push_back(string);
}
else
{
m_Strings.push_back(string);
}
return m_Strings.back().c_str();
}
else
{
return nullptr;
}
}
void clear() noexcept { m_Strings.clear(); }
private:
std::list<std::wstring> m_Strings;
};
class SUBOBJECT_HELPER_BASE
{
public:
SUBOBJECT_HELPER_BASE() noexcept { Init(); }
virtual ~SUBOBJECT_HELPER_BASE() = default;
virtual D3D12_STATE_SUBOBJECT_TYPE Type() const noexcept = 0;
void AddToStateObject(CD3DX12_STATE_OBJECT_DESC& ContainingStateObject)
{
m_pSubobject = ContainingStateObject.TrackSubobject(Type(), Data());
}
protected:
virtual void* Data() noexcept = 0;
void Init() noexcept { m_pSubobject = nullptr; }
D3D12_STATE_SUBOBJECT* m_pSubobject;
};
#if(__cplusplus >= 201103L)
std::list<std::unique_ptr<const SUBOBJECT_HELPER_BASE>> m_OwnedSubobjectHelpers;
#else
class OWNED_HELPER
{
public:
OWNED_HELPER(const SUBOBJECT_HELPER_BASE* pHelper) noexcept { m_pHelper = pHelper; }
~OWNED_HELPER() { delete m_pHelper; }
const SUBOBJECT_HELPER_BASE* m_pHelper;
};
std::list<OWNED_HELPER> m_OwnedSubobjectHelpers;
#endif
friend class CD3DX12_DXIL_LIBRARY_SUBOBJECT;
friend class CD3DX12_EXISTING_COLLECTION_SUBOBJECT;
friend class CD3DX12_SUBOBJECT_TO_EXPORTS_ASSOCIATION_SUBOBJECT;
friend class CD3DX12_DXIL_SUBOBJECT_TO_EXPORTS_ASSOCIATION;
friend class CD3DX12_HIT_GROUP_SUBOBJECT;
friend class CD3DX12_RAYTRACING_SHADER_CONFIG_SUBOBJECT;
friend class CD3DX12_RAYTRACING_PIPELINE_CONFIG_SUBOBJECT;
friend class CD3DX12_RAYTRACING_PIPELINE_CONFIG1_SUBOBJECT;
friend class CD3DX12_GLOBAL_ROOT_SIGNATURE_SUBOBJECT;
friend class CD3DX12_LOCAL_ROOT_SIGNATURE_SUBOBJECT;
friend class CD3DX12_STATE_OBJECT_CONFIG_SUBOBJECT;
friend class CD3DX12_NODE_MASK_SUBOBJECT;
};
//------------------------------------------------------------------------------------------------
class CD3DX12_DXIL_LIBRARY_SUBOBJECT
: public CD3DX12_STATE_OBJECT_DESC::SUBOBJECT_HELPER_BASE
{
public:
CD3DX12_DXIL_LIBRARY_SUBOBJECT() noexcept
{
Init();
}
CD3DX12_DXIL_LIBRARY_SUBOBJECT(CD3DX12_STATE_OBJECT_DESC& ContainingStateObject)
{
Init();
AddToStateObject(ContainingStateObject);
}
void SetDXILLibrary(const D3D12_SHADER_BYTECODE* pCode) noexcept
{
static const D3D12_SHADER_BYTECODE Default = {};
m_Desc.DXILLibrary = pCode ? *pCode : Default;
}
void DefineExport(
LPCWSTR Name,
LPCWSTR ExportToRename = nullptr,
D3D12_EXPORT_FLAGS Flags = D3D12_EXPORT_FLAG_NONE)
{
D3D12_EXPORT_DESC Export;
Export.Name = m_Strings.LocalCopy(Name);
Export.ExportToRename = m_Strings.LocalCopy(ExportToRename);
Export.Flags = Flags;
m_Exports.push_back(Export);
m_Desc.pExports = &m_Exports[0]; // using ugly way to get pointer in case .data() is not defined
m_Desc.NumExports = static_cast<UINT>(m_Exports.size());
}
template<size_t N>
void DefineExports(LPCWSTR(&Exports)[N])
{
for (UINT i = 0; i < N; i++)
{
DefineExport(Exports[i]);
}
}
void DefineExports(const LPCWSTR* Exports, UINT N)
{
for (UINT i = 0; i < N; i++)
{
DefineExport(Exports[i]);
}
}
D3D12_STATE_SUBOBJECT_TYPE Type() const noexcept override
{
return D3D12_STATE_SUBOBJECT_TYPE_DXIL_LIBRARY;
}
operator const D3D12_STATE_SUBOBJECT&() const noexcept { return *m_pSubobject; }
operator const D3D12_DXIL_LIBRARY_DESC&() const noexcept { return m_Desc; }
private:
void Init() noexcept
{
SUBOBJECT_HELPER_BASE::Init();
m_Desc = {};
m_Strings.clear();
m_Exports.clear();
}
void* Data() noexcept override { return &m_Desc; }
D3D12_DXIL_LIBRARY_DESC m_Desc;
CD3DX12_STATE_OBJECT_DESC::StringContainer m_Strings;
std::vector<D3D12_EXPORT_DESC> m_Exports;
};
//------------------------------------------------------------------------------------------------
class CD3DX12_EXISTING_COLLECTION_SUBOBJECT
: public CD3DX12_STATE_OBJECT_DESC::SUBOBJECT_HELPER_BASE
{
public:
CD3DX12_EXISTING_COLLECTION_SUBOBJECT() noexcept
{
Init();
}
CD3DX12_EXISTING_COLLECTION_SUBOBJECT(CD3DX12_STATE_OBJECT_DESC& ContainingStateObject)
{
Init();
AddToStateObject(ContainingStateObject);
}
void SetExistingCollection(ID3D12StateObject*pExistingCollection) noexcept
{
m_Desc.pExistingCollection = pExistingCollection;
m_CollectionRef = pExistingCollection;
}
void DefineExport(
LPCWSTR Name,
LPCWSTR ExportToRename = nullptr,
D3D12_EXPORT_FLAGS Flags = D3D12_EXPORT_FLAG_NONE)
{
D3D12_EXPORT_DESC Export;
Export.Name = m_Strings.LocalCopy(Name);
Export.ExportToRename = m_Strings.LocalCopy(ExportToRename);
Export.Flags = Flags;
m_Exports.push_back(Export);
m_Desc.pExports = &m_Exports[0]; // using ugly way to get pointer in case .data() is not defined
m_Desc.NumExports = static_cast<UINT>(m_Exports.size());
}
template<size_t N>
void DefineExports(LPCWSTR(&Exports)[N])
{
for (UINT i = 0; i < N; i++)
{
DefineExport(Exports[i]);
}
}
void DefineExports(const LPCWSTR* Exports, UINT N)
{
for (UINT i = 0; i < N; i++)
{
DefineExport(Exports[i]);
}
}
D3D12_STATE_SUBOBJECT_TYPE Type() const noexcept override
{
return D3D12_STATE_SUBOBJECT_TYPE_EXISTING_COLLECTION;
}
operator const D3D12_STATE_SUBOBJECT&() const noexcept { return *m_pSubobject; }
operator const D3D12_EXISTING_COLLECTION_DESC&() const noexcept { return m_Desc; }
private:
void Init() noexcept
{
SUBOBJECT_HELPER_BASE::Init();
m_Desc = {};
m_CollectionRef = nullptr;
m_Strings.clear();
m_Exports.clear();
}
void* Data() noexcept override { return &m_Desc; }
D3D12_EXISTING_COLLECTION_DESC m_Desc;
D3DX12_COM_PTR<ID3D12StateObject> m_CollectionRef;
CD3DX12_STATE_OBJECT_DESC::StringContainer m_Strings;
std::vector<D3D12_EXPORT_DESC> m_Exports;
};
//------------------------------------------------------------------------------------------------
class CD3DX12_SUBOBJECT_TO_EXPORTS_ASSOCIATION_SUBOBJECT
: public CD3DX12_STATE_OBJECT_DESC::SUBOBJECT_HELPER_BASE
{
public:
CD3DX12_SUBOBJECT_TO_EXPORTS_ASSOCIATION_SUBOBJECT() noexcept
{
Init();
}
CD3DX12_SUBOBJECT_TO_EXPORTS_ASSOCIATION_SUBOBJECT(CD3DX12_STATE_OBJECT_DESC& ContainingStateObject)
{
Init();
AddToStateObject(ContainingStateObject);
}
void SetSubobjectToAssociate(const D3D12_STATE_SUBOBJECT& SubobjectToAssociate) noexcept
{
m_Desc.pSubobjectToAssociate = &SubobjectToAssociate;
}
void AddExport(LPCWSTR Export)
{
m_Desc.NumExports++;
m_Exports.push_back(m_Strings.LocalCopy(Export));
m_Desc.pExports = &m_Exports[0]; // using ugly way to get pointer in case .data() is not defined
}
template<size_t N>
void AddExports(LPCWSTR (&Exports)[N])
{
for (UINT i = 0; i < N; i++)
{
AddExport(Exports[i]);
}
}
void AddExports(const LPCWSTR* Exports, UINT N)
{
for (UINT i = 0; i < N; i++)
{
AddExport(Exports[i]);
}
}
D3D12_STATE_SUBOBJECT_TYPE Type() const noexcept override
{
return D3D12_STATE_SUBOBJECT_TYPE_SUBOBJECT_TO_EXPORTS_ASSOCIATION;
}
operator const D3D12_STATE_SUBOBJECT&() const noexcept { return *m_pSubobject; }
operator const D3D12_SUBOBJECT_TO_EXPORTS_ASSOCIATION&() const noexcept { return m_Desc; }
private:
void Init() noexcept
{
SUBOBJECT_HELPER_BASE::Init();
m_Desc = {};
m_Strings.clear();
m_Exports.clear();
}
void* Data() noexcept override { return &m_Desc; }
D3D12_SUBOBJECT_TO_EXPORTS_ASSOCIATION m_Desc;
CD3DX12_STATE_OBJECT_DESC::StringContainer m_Strings;
std::vector<LPCWSTR> m_Exports;
};
//------------------------------------------------------------------------------------------------
class CD3DX12_DXIL_SUBOBJECT_TO_EXPORTS_ASSOCIATION
: public CD3DX12_STATE_OBJECT_DESC::SUBOBJECT_HELPER_BASE
{
public:
CD3DX12_DXIL_SUBOBJECT_TO_EXPORTS_ASSOCIATION() noexcept
{
Init();
}
CD3DX12_DXIL_SUBOBJECT_TO_EXPORTS_ASSOCIATION(CD3DX12_STATE_OBJECT_DESC& ContainingStateObject)
{
Init();
AddToStateObject(ContainingStateObject);
}
void SetSubobjectNameToAssociate(LPCWSTR SubobjectToAssociate)
{
m_Desc.SubobjectToAssociate = m_SubobjectName.LocalCopy(SubobjectToAssociate, true);
}
void AddExport(LPCWSTR Export)
{
m_Desc.NumExports++;
m_Exports.push_back(m_Strings.LocalCopy(Export));
m_Desc.pExports = &m_Exports[0]; // using ugly way to get pointer in case .data() is not defined
}
template<size_t N>
void AddExports(LPCWSTR (&Exports)[N])
{
for (UINT i = 0; i < N; i++)
{
AddExport(Exports[i]);
}
}
void AddExports(const LPCWSTR* Exports, UINT N)
{
for (UINT i = 0; i < N; i++)
{
AddExport(Exports[i]);
}
}
D3D12_STATE_SUBOBJECT_TYPE Type() const noexcept override
{
return D3D12_STATE_SUBOBJECT_TYPE_DXIL_SUBOBJECT_TO_EXPORTS_ASSOCIATION;
}
operator const D3D12_STATE_SUBOBJECT&() const noexcept { return *m_pSubobject; }
operator const D3D12_DXIL_SUBOBJECT_TO_EXPORTS_ASSOCIATION&() const noexcept { return m_Desc; }
private:
void Init() noexcept
{
SUBOBJECT_HELPER_BASE::Init();
m_Desc = {};
m_Strings.clear();
m_SubobjectName.clear();
m_Exports.clear();
}
void* Data() noexcept override { return &m_Desc; }
D3D12_DXIL_SUBOBJECT_TO_EXPORTS_ASSOCIATION m_Desc;
CD3DX12_STATE_OBJECT_DESC::StringContainer m_Strings;
CD3DX12_STATE_OBJECT_DESC::StringContainer m_SubobjectName;
std::vector<LPCWSTR> m_Exports;
};
//------------------------------------------------------------------------------------------------
class CD3DX12_HIT_GROUP_SUBOBJECT
: public CD3DX12_STATE_OBJECT_DESC::SUBOBJECT_HELPER_BASE
{
public:
CD3DX12_HIT_GROUP_SUBOBJECT() noexcept
{
Init();
}
CD3DX12_HIT_GROUP_SUBOBJECT(CD3DX12_STATE_OBJECT_DESC& ContainingStateObject)
{
Init();
AddToStateObject(ContainingStateObject);
}
void SetHitGroupExport(LPCWSTR exportName)
{
m_Desc.HitGroupExport = m_Strings[0].LocalCopy(exportName, true);
}
void SetHitGroupType(D3D12_HIT_GROUP_TYPE Type) noexcept { m_Desc.Type = Type; }
void SetAnyHitShaderImport(LPCWSTR importName)
{
m_Desc.AnyHitShaderImport = m_Strings[1].LocalCopy(importName, true);
}
void SetClosestHitShaderImport(LPCWSTR importName)
{
m_Desc.ClosestHitShaderImport = m_Strings[2].LocalCopy(importName, true);
}
void SetIntersectionShaderImport(LPCWSTR importName)
{
m_Desc.IntersectionShaderImport = m_Strings[3].LocalCopy(importName, true);
}
D3D12_STATE_SUBOBJECT_TYPE Type() const noexcept override
{
return D3D12_STATE_SUBOBJECT_TYPE_HIT_GROUP;
}
operator const D3D12_STATE_SUBOBJECT&() const noexcept { return *m_pSubobject; }
operator const D3D12_HIT_GROUP_DESC&() const noexcept { return m_Desc; }
private:
void Init() noexcept
{
SUBOBJECT_HELPER_BASE::Init();
m_Desc = {};
for (UINT i = 0; i < m_NumStrings; i++)
{
m_Strings[i].clear();
}
}
void* Data() noexcept override { return &m_Desc; }
D3D12_HIT_GROUP_DESC m_Desc;
static constexpr UINT m_NumStrings = 4;
CD3DX12_STATE_OBJECT_DESC::StringContainer
m_Strings[m_NumStrings]; // one string for every entrypoint name
};
//------------------------------------------------------------------------------------------------
class CD3DX12_RAYTRACING_SHADER_CONFIG_SUBOBJECT
: public CD3DX12_STATE_OBJECT_DESC::SUBOBJECT_HELPER_BASE
{
public:
CD3DX12_RAYTRACING_SHADER_CONFIG_SUBOBJECT() noexcept
{
Init();
}
CD3DX12_RAYTRACING_SHADER_CONFIG_SUBOBJECT(CD3DX12_STATE_OBJECT_DESC& ContainingStateObject)
{
Init();
AddToStateObject(ContainingStateObject);
}
void Config(UINT MaxPayloadSizeInBytes, UINT MaxAttributeSizeInBytes) noexcept
{
m_Desc.MaxPayloadSizeInBytes = MaxPayloadSizeInBytes;
m_Desc.MaxAttributeSizeInBytes = MaxAttributeSizeInBytes;
}
D3D12_STATE_SUBOBJECT_TYPE Type() const noexcept override
{
return D3D12_STATE_SUBOBJECT_TYPE_RAYTRACING_SHADER_CONFIG;
}
operator const D3D12_STATE_SUBOBJECT&() const noexcept { return *m_pSubobject; }
operator const D3D12_RAYTRACING_SHADER_CONFIG&() const noexcept { return m_Desc; }
private:
void Init() noexcept
{
SUBOBJECT_HELPER_BASE::Init();
m_Desc = {};
}
void* Data() noexcept override { return &m_Desc; }
D3D12_RAYTRACING_SHADER_CONFIG m_Desc;
};
//------------------------------------------------------------------------------------------------
class CD3DX12_RAYTRACING_PIPELINE_CONFIG_SUBOBJECT
: public CD3DX12_STATE_OBJECT_DESC::SUBOBJECT_HELPER_BASE
{
public:
CD3DX12_RAYTRACING_PIPELINE_CONFIG_SUBOBJECT() noexcept
{
Init();
}
CD3DX12_RAYTRACING_PIPELINE_CONFIG_SUBOBJECT(CD3DX12_STATE_OBJECT_DESC& ContainingStateObject)
{
Init();
AddToStateObject(ContainingStateObject);
}
void Config(UINT MaxTraceRecursionDepth) noexcept
{
m_Desc.MaxTraceRecursionDepth = MaxTraceRecursionDepth;
}
D3D12_STATE_SUBOBJECT_TYPE Type() const noexcept override
{
return D3D12_STATE_SUBOBJECT_TYPE_RAYTRACING_PIPELINE_CONFIG;
}
operator const D3D12_STATE_SUBOBJECT&() const noexcept { return *m_pSubobject; }
operator const D3D12_RAYTRACING_PIPELINE_CONFIG&() const noexcept { return m_Desc; }
private:
void Init() noexcept
{
SUBOBJECT_HELPER_BASE::Init();
m_Desc = {};
}
void* Data() noexcept override { return &m_Desc; }
D3D12_RAYTRACING_PIPELINE_CONFIG m_Desc;
};
//------------------------------------------------------------------------------------------------
class CD3DX12_RAYTRACING_PIPELINE_CONFIG1_SUBOBJECT
: public CD3DX12_STATE_OBJECT_DESC::SUBOBJECT_HELPER_BASE
{
public:
CD3DX12_RAYTRACING_PIPELINE_CONFIG1_SUBOBJECT() noexcept
{
Init();
}
CD3DX12_RAYTRACING_PIPELINE_CONFIG1_SUBOBJECT(CD3DX12_STATE_OBJECT_DESC& ContainingStateObject)
{
Init();
AddToStateObject(ContainingStateObject);
}
void Config(UINT MaxTraceRecursionDepth, D3D12_RAYTRACING_PIPELINE_FLAGS Flags) noexcept
{
m_Desc.MaxTraceRecursionDepth = MaxTraceRecursionDepth;
m_Desc.Flags = Flags;
}
D3D12_STATE_SUBOBJECT_TYPE Type() const noexcept override
{
return D3D12_STATE_SUBOBJECT_TYPE_RAYTRACING_PIPELINE_CONFIG1;
}
operator const D3D12_STATE_SUBOBJECT&() const noexcept { return *m_pSubobject; }
operator const D3D12_RAYTRACING_PIPELINE_CONFIG1&() const noexcept { return m_Desc; }
private:
void Init() noexcept
{
SUBOBJECT_HELPER_BASE::Init();
m_Desc = {};
}
void* Data() noexcept override { return &m_Desc; }
D3D12_RAYTRACING_PIPELINE_CONFIG1 m_Desc;
};
//------------------------------------------------------------------------------------------------
class CD3DX12_GLOBAL_ROOT_SIGNATURE_SUBOBJECT
: public CD3DX12_STATE_OBJECT_DESC::SUBOBJECT_HELPER_BASE
{
public:
CD3DX12_GLOBAL_ROOT_SIGNATURE_SUBOBJECT() noexcept
{
Init();
}
CD3DX12_GLOBAL_ROOT_SIGNATURE_SUBOBJECT(CD3DX12_STATE_OBJECT_DESC& ContainingStateObject)
{
Init();
AddToStateObject(ContainingStateObject);
}
void SetRootSignature(ID3D12RootSignature* pRootSig) noexcept
{
m_pRootSig = pRootSig;
}
D3D12_STATE_SUBOBJECT_TYPE Type() const noexcept override
{
return D3D12_STATE_SUBOBJECT_TYPE_GLOBAL_ROOT_SIGNATURE;
}
operator const D3D12_STATE_SUBOBJECT&() const noexcept { return *m_pSubobject; }
operator ID3D12RootSignature*() const noexcept { return D3DX12_COM_PTR_GET(m_pRootSig); }
private:
void Init() noexcept
{
SUBOBJECT_HELPER_BASE::Init();
m_pRootSig = nullptr;
}
void* Data() noexcept override { return D3DX12_COM_PTR_ADDRESSOF(m_pRootSig); }
D3DX12_COM_PTR<ID3D12RootSignature> m_pRootSig;
};
//------------------------------------------------------------------------------------------------
class CD3DX12_LOCAL_ROOT_SIGNATURE_SUBOBJECT
: public CD3DX12_STATE_OBJECT_DESC::SUBOBJECT_HELPER_BASE
{
public:
CD3DX12_LOCAL_ROOT_SIGNATURE_SUBOBJECT() noexcept
{
Init();
}
CD3DX12_LOCAL_ROOT_SIGNATURE_SUBOBJECT(CD3DX12_STATE_OBJECT_DESC& ContainingStateObject)
{
Init();
AddToStateObject(ContainingStateObject);
}
void SetRootSignature(ID3D12RootSignature* pRootSig) noexcept
{
m_pRootSig = pRootSig;
}
D3D12_STATE_SUBOBJECT_TYPE Type() const noexcept override
{
return D3D12_STATE_SUBOBJECT_TYPE_LOCAL_ROOT_SIGNATURE;
}
operator const D3D12_STATE_SUBOBJECT&() const noexcept { return *m_pSubobject; }
operator ID3D12RootSignature*() const noexcept { return D3DX12_COM_PTR_GET(m_pRootSig); }
private:
void Init() noexcept
{
SUBOBJECT_HELPER_BASE::Init();
m_pRootSig = nullptr;
}
void* Data() noexcept override { return D3DX12_COM_PTR_ADDRESSOF(m_pRootSig); }
D3DX12_COM_PTR<ID3D12RootSignature> m_pRootSig;
};
//------------------------------------------------------------------------------------------------
class CD3DX12_STATE_OBJECT_CONFIG_SUBOBJECT
: public CD3DX12_STATE_OBJECT_DESC::SUBOBJECT_HELPER_BASE
{
public:
CD3DX12_STATE_OBJECT_CONFIG_SUBOBJECT() noexcept
{
Init();
}
CD3DX12_STATE_OBJECT_CONFIG_SUBOBJECT(CD3DX12_STATE_OBJECT_DESC& ContainingStateObject)
{
Init();
AddToStateObject(ContainingStateObject);
}
void SetFlags(D3D12_STATE_OBJECT_FLAGS Flags) noexcept
{
m_Desc.Flags = Flags;
}
D3D12_STATE_SUBOBJECT_TYPE Type() const noexcept override
{
return D3D12_STATE_SUBOBJECT_TYPE_STATE_OBJECT_CONFIG;
}
operator const D3D12_STATE_SUBOBJECT&() const noexcept { return *m_pSubobject; }
operator const D3D12_STATE_OBJECT_CONFIG&() const noexcept { return m_Desc; }
private:
void Init() noexcept
{
SUBOBJECT_HELPER_BASE::Init();
m_Desc = {};
}
void* Data() noexcept override { return &m_Desc; }
D3D12_STATE_OBJECT_CONFIG m_Desc;
};
//------------------------------------------------------------------------------------------------
class CD3DX12_NODE_MASK_SUBOBJECT
: public CD3DX12_STATE_OBJECT_DESC::SUBOBJECT_HELPER_BASE
{
public:
CD3DX12_NODE_MASK_SUBOBJECT() noexcept
{
Init();
}
CD3DX12_NODE_MASK_SUBOBJECT(CD3DX12_STATE_OBJECT_DESC& ContainingStateObject)
{
Init();
AddToStateObject(ContainingStateObject);
}
void SetNodeMask(UINT NodeMask) noexcept
{
m_Desc.NodeMask = NodeMask;
}
D3D12_STATE_SUBOBJECT_TYPE Type() const noexcept override
{
return D3D12_STATE_SUBOBJECT_TYPE_NODE_MASK;
}
operator const D3D12_STATE_SUBOBJECT&() const noexcept { return *m_pSubobject; }
operator const D3D12_NODE_MASK&() const noexcept { return m_Desc; }
private:
void Init() noexcept
{
SUBOBJECT_HELPER_BASE::Init();
m_Desc = {};
}
void* Data() noexcept override { return &m_Desc; }
D3D12_NODE_MASK m_Desc;
};
#undef D3DX12_COM_PTR
#undef D3DX12_COM_PTR_GET
#undef D3DX12_COM_PTR_ADDRESSOF

1218
code/renderer/d3d12/dxcapi.h Normal file

File diff suppressed because it is too large Load diff

View file

@ -159,8 +159,10 @@ D3D(DXGIGetDebugInterface1(0, IID_PPV_ARGS(&graphicsAnalysis)));
#include <Windows.h> #include <Windows.h>
#include "d3d12/d3d12.h" #include "d3d12/d3d12.h"
#include <dxgi1_6.h> #include <dxgi1_6.h>
#if defined(D3D_DEBUG)
#include <dxgidebug.h> #include <dxgidebug.h>
#include <dxcapi.h> #endif
#include "d3d12/dxcapi.h"
#include <dwmapi.h> // for DwmGetCompositionTimingInfo #include <dwmapi.h> // for DwmGetCompositionTimingInfo
#define D3D12MA_D3D12_HEADERS_ALREADY_INCLUDED #define D3D12MA_D3D12_HEADERS_ALREADY_INCLUDED
#include "D3D12MemAlloc.h" #include "D3D12MemAlloc.h"
@ -612,8 +614,8 @@ namespace RHI
ID3D12Debug* debug; // can be NULL ID3D12Debug* debug; // can be NULL
ID3D12InfoQueue* infoQueue; // can be NULL ID3D12InfoQueue* infoQueue; // can be NULL
IDXGIInfoQueue* dxgiInfoQueue; // can be NULL
#if defined(D3D_DEBUG) #if defined(D3D_DEBUG)
IDXGIInfoQueue* dxgiInfoQueue; // can be NULL
IDXGIFactory2* factory; IDXGIFactory2* factory;
#else #else
IDXGIFactory1* factory; IDXGIFactory1* factory;
@ -3467,7 +3469,9 @@ namespace RHI
COM_RELEASE(rhi.device); COM_RELEASE(rhi.device);
COM_RELEASE(rhi.adapter); COM_RELEASE(rhi.adapter);
COM_RELEASE(rhi.factory); COM_RELEASE(rhi.factory);
#if defined(D3D_DEBUG)
COM_RELEASE(rhi.dxgiInfoQueue); COM_RELEASE(rhi.dxgiInfoQueue);
#endif
COM_RELEASE(rhi.debug); COM_RELEASE(rhi.debug);
FreeLibrary(rhi.dxilModule); FreeLibrary(rhi.dxilModule);