From 749f869319c6c10634a4dceb03a03d98eb2b2227 Mon Sep 17 00:00:00 2001 From: dzhdan Date: Mon, 27 May 2024 13:17:17 +0800 Subject: [PATCH] Added ability to disable extension libraries (NVAPI and AMD AGS) --- CMakeLists.txt | 59 ++++++++++++++++++++--------- Include/NRI.h | 4 +- Resources/Version.h | 2 +- Source/Creation/Creation.cpp | 16 ++++---- Source/D3D11/CommandBufferD3D11.cpp | 5 ++- Source/D3D11/DeviceD3D11.cpp | 57 +++++++++++++++------------- Source/D3D11/DeviceD3D11.h | 2 +- Source/D3D11/PipelineD3D11.cpp | 25 +++++++----- Source/D3D11/PipelineD3D11.h | 6 ++- Source/D3D11/SharedD3D11.h | 8 ++-- Source/D3D11/SwapChainD3D11.cpp | 26 ++++++++++++- Source/D3D12/DeviceD3D12.cpp | 40 ++++++++++--------- Source/D3D12/DeviceD3D12.h | 2 +- Source/D3D12/SharedD3D12.h | 8 ++-- Source/D3D12/SwapChainD3D12.cpp | 26 ++++++++++++- Source/Shared/D3DExt.h | 52 +++++++++++++++++++++++-- Source/Shared/D3DExt.hpp | 37 +++++++++++++++++- 17 files changed, 274 insertions(+), 101 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 556c8eea..54ba1acc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,9 @@ set (NRI_AGILITY_SDK_PATH "C:/AgilitySDK" CACHE STRING "Path to a directory cont set (NRI_AGILITY_SDK_VERSION "614" CACHE STRING "Agility SDK version") set (NRI_AGILITY_SDK_DIR "AgilitySDK" CACHE STRING "Directory where Agility SDK binaries will be copied to relative to 'CMAKE_RUNTIME_OUTPUT_DIRECTORY'") +# Options: D3D11/D3D12 specific +option (NRI_ENABLE_EXTERNAL_LIBRARIES "Enable vendor specific extension libraries (NVAPI and AMD AGS)" ON) + # Is submodule? if (${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}) set (IS_SUBMODULE OFF) @@ -117,50 +120,70 @@ else () endif () set (COMPILE_DEFINITIONS WIN32_LEAN_AND_MEAN NOMINMAX _CRT_SECURE_NO_WARNINGS) +if (NRI_ENABLE_EXTERNAL_LIBRARIES) + set (COMPILE_DEFINITIONS ${COMPILE_DEFINITIONS} NRI_USE_EXT_LIBS=1) +endif () + +# External libs +if (WIN32 AND NRI_ENABLE_EXTERNAL_LIBRARIES AND (NRI_ENABLE_D3D11_SUPPORT OR NRI_ENABLE_D3D12_SUPPORT)) + # Statically linked + find_library (NVAPI_LIB NAMES nvapi64 nvapi PATHS "External/nvapi/${NVAPI_BIN_ARCHITECTURE}" REQUIRED) + # Dynamically loaded + find_library (AGS_LIB NAMES amd_ags_${BIN_ARCHITECTURE} PATHS "External/amdags/ags_lib/lib" REQUIRED) + + file (GLOB NVAPI_HEADERS "External/nvapi/*.h") + source_group ("External/nvapi" FILES ${NVAPI_HEADERS}) + file (GLOB AMDAGS_HEADERS "External/amdags/ags_lib/inc/*.h") + source_group ("External/amdags" FILES ${AMDAGS_HEADERS}) +endif () # D3D11 if (WIN32 AND NRI_ENABLE_D3D11_SUPPORT) message ("NRI adding backend: D3D11") + set (COMPILE_DEFINITIONS ${COMPILE_DEFINITIONS} NRI_USE_D3D11=1) set (INPUT_LIBS_D3D11 ${INPUT_LIB_D3D11} ${INPUT_LIB_DXGI}) - find_library (INPUT_LIB_NVAPI NAMES nvapi64 nvapi PATHS "External/nvapi/${NVAPI_BIN_ARCHITECTURE}" REQUIRED) - find_library (INPUT_LIB_AGS NAMES amd_ags_${BIN_ARCHITECTURE} PATHS "External/amdags/ags_lib/lib" REQUIRED) - file (GLOB D3D11_SOURCE "Source/D3D11/*.cpp" "Source/D3D11/*.h" "Source/D3D11/*.hpp") source_group ("" FILES ${D3D11_SOURCE}) - file (GLOB D3D11_NVAPI "External/nvapi/*.h") - source_group ("External/nvapi" FILES ${D3D11_NVAPI}) - file (GLOB D3D11_AMDAGS "External/amdags/ags_lib/inc/*.h") - source_group ("External/amdags" FILES ${D3D11_AMDAGS}) - add_library (NRI_D3D11 STATIC ${D3D11_SOURCE} ${D3D11_NVAPI} ${D3D11_AMDAGS}) + + if (NRI_ENABLE_EXTERNAL_LIBRARIES) + add_library (NRI_D3D11 STATIC ${D3D11_SOURCE} ${NVAPI_HEADERS} ${AMDAGS_HEADERS}) + target_link_libraries (NRI_D3D11 PRIVATE ${NVAPI_LIB}) + else () + add_library (NRI_D3D11 STATIC ${D3D11_SOURCE}) + endif () + target_include_directories (NRI_D3D11 PRIVATE "Include" "Source/Shared" "External") target_compile_definitions (NRI_D3D11 PRIVATE ${COMPILE_DEFINITIONS}) target_compile_options (NRI_D3D11 PRIVATE ${COMPILE_OPTIONS}) - target_link_libraries (NRI_D3D11 PRIVATE NRI_Shared ${INPUT_LIBS_D3D11} ${INPUT_LIB_NVAPI} ${INPUT_LIB_DXGUID}) + target_link_libraries (NRI_D3D11 PRIVATE NRI_Shared ${INPUT_LIBS_D3D11} ${INPUT_LIB_DXGUID}) + set_property (TARGET NRI_D3D11 PROPERTY FOLDER ${PROJECT_NAME}) endif () # D3D12 if (WIN32 AND NRI_ENABLE_D3D12_SUPPORT) message ("NRI adding backend: D3D12") + set (COMPILE_DEFINITIONS ${COMPILE_DEFINITIONS} NRI_USE_D3D12=1) set (INPUT_LIBS_D3D12 ${INPUT_LIB_D3D12} ${INPUT_LIB_DXGI}) - find_library (INPUT_LIB_NVAPI NAMES nvapi64 nvapi PATHS "External/nvapi/${NVAPI_BIN_ARCHITECTURE}" REQUIRED) - find_library (INPUT_LIB_AGS NAMES amd_ags_${BIN_ARCHITECTURE} PATHS "External/amdags/ags_lib/lib" REQUIRED) - file (GLOB D3D12_SOURCE "Source/D3D12/*.cpp" "Source/D3D12/*.h" "Source/D3D12/*.hpp") source_group ("" FILES ${D3D12_SOURCE}) - file (GLOB D3D12_NVAPI "External/nvapi/*.h") - source_group ("External/nvapi" FILES ${D3D12_NVAPI}) - file (GLOB D3D12_AMDAGS "External/amdags/ags_lib/inc/*.h") - source_group ("External/amdags" FILES ${D3D12_AMDAGS}) - add_library (NRI_D3D12 STATIC ${D3D12_SOURCE} ${D3D12_NVAPI} ${D3D12_AMDAGS}) + + if (NRI_ENABLE_EXTERNAL_LIBRARIES) + add_library (NRI_D3D12 STATIC ${D3D12_SOURCE} ${NVAPI_HEADERS} ${AMDAGS_HEADERS}) + target_link_libraries (NRI_D3D12 PRIVATE ${NVAPI_LIB}) + else () + add_library (NRI_D3D12 STATIC ${D3D12_SOURCE}) + endif () + target_include_directories (NRI_D3D12 PRIVATE "Include" "Source/Shared" "External") target_compile_definitions (NRI_D3D12 PRIVATE ${COMPILE_DEFINITIONS}) target_compile_options (NRI_D3D12 PRIVATE ${COMPILE_OPTIONS}) - target_link_libraries (NRI_D3D12 PRIVATE NRI_Shared ${INPUT_LIBS_D3D12} ${INPUT_LIB_NVAPI}) + target_link_libraries (NRI_D3D12 PRIVATE NRI_Shared ${INPUT_LIBS_D3D12}) + set_property (TARGET NRI_D3D12 PROPERTY FOLDER ${PROJECT_NAME}) if (NRI_ENABLE_AGILITY_SDK_SUPPORT) diff --git a/Include/NRI.h b/Include/NRI.h index e14916a6..64981013 100644 --- a/Include/NRI.h +++ b/Include/NRI.h @@ -25,8 +25,8 @@ Non-goals: #include #define NRI_VERSION_MAJOR 1 -#define NRI_VERSION_MINOR 134 -#define NRI_VERSION_DATE "21 May 2024" +#define NRI_VERSION_MINOR 135 +#define NRI_VERSION_DATE "27 May 2024" #ifdef _WIN32 #define NRI_CALL __fastcall diff --git a/Resources/Version.h b/Resources/Version.h index 86f33a82..1131a277 100644 --- a/Resources/Version.h +++ b/Resources/Version.h @@ -4,7 +4,7 @@ #define STR(x) STR_HELPER(x) #define VERSION_MAJOR 1 -#define VERSION_MINOR 134 +#define VERSION_MINOR 135 #define VERSION_BUILD 0 #define VERSION_REVISION 0 diff --git a/Source/Creation/Creation.cpp b/Source/Creation/Creation.cpp index 887da468..3d343e72 100644 --- a/Source/Creation/Creation.cpp +++ b/Source/Creation/Creation.cpp @@ -107,17 +107,17 @@ NRI_API Result NRI_CALL nriCreateDevice(const DeviceCreationDesc& deviceCreation CheckAndSetDefaultCallbacks(modifiedDeviceCreationDesc.callbackInterface); CheckAndSetDefaultAllocator(modifiedDeviceCreationDesc.memoryAllocatorInterface); -#if (NRI_USE_D3D11 == 1) +#if NRI_USE_D3D11 if (modifiedDeviceCreationDesc.graphicsAPI == GraphicsAPI::D3D11) result = CreateDeviceD3D11(modifiedDeviceCreationDesc, deviceImpl); #endif -#if (NRI_USE_D3D12 == 1) +#if NRI_USE_D3D12 if (modifiedDeviceCreationDesc.graphicsAPI == GraphicsAPI::D3D12) result = CreateDeviceD3D12(modifiedDeviceCreationDesc, deviceImpl); #endif -#if (NRI_USE_VULKAN == 1) +#if NRI_USE_VULKAN if (modifiedDeviceCreationDesc.graphicsAPI == GraphicsAPI::VULKAN) result = CreateDeviceVK(modifiedDeviceCreationDesc, deviceImpl); #endif @@ -146,7 +146,7 @@ NRI_API Result NRI_CALL nriCreateDeviceFromD3D11Device(const DeviceCreationD3D11 Result result = Result::UNSUPPORTED; DeviceBase* deviceImpl = nullptr; -#if (NRI_USE_D3D11 == 1) +#if NRI_USE_D3D11 result = CreateDeviceD3D11(tempDeviceCreationD3D11Desc, deviceImpl); #endif @@ -174,7 +174,7 @@ NRI_API Result NRI_CALL nriCreateDeviceFromD3D12Device(const DeviceCreationD3D12 Result result = Result::UNSUPPORTED; DeviceBase* deviceImpl = nullptr; -#if (NRI_USE_D3D12 == 1) +#if NRI_USE_D3D12 result = CreateDeviceD3D12(tempDeviceCreationD3D12Desc, deviceImpl); #endif @@ -203,7 +203,7 @@ NRI_API Result NRI_CALL nriCreateDeviceFromVkDevice(const DeviceCreationVKDesc& Result result = Result::UNSUPPORTED; DeviceBase* deviceImpl = nullptr; -#if (NRI_USE_VULKAN == 1) +#if NRI_USE_VULKAN result = CreateDeviceVK(tempDeviceCreationVKDesc, deviceImpl); #endif @@ -228,7 +228,7 @@ NRI_API Format NRI_CALL nriConvertDXGIFormatToNRI(uint32_t dxgiFormat) { NRI_API uint32_t NRI_CALL nriConvertNRIFormatToVK(Format format) { MaybeUnused(format); -#if (NRI_USE_VULKAN == 1) +#if NRI_USE_VULKAN return NRIFormatToVKFormat(format); #else return 0; @@ -238,7 +238,7 @@ NRI_API uint32_t NRI_CALL nriConvertNRIFormatToVK(Format format) { NRI_API uint32_t NRI_CALL nriConvertNRIFormatToDXGI(Format format) { MaybeUnused(format); -#if (NRI_USE_D3D11 == 1 || NRI_USE_D3D12 == 1) +#if (NRI_USE_D3D11 || NRI_USE_D3D12) return NRIFormatToDXGIFormat(format); #else return 0; diff --git a/Source/D3D11/CommandBufferD3D11.cpp b/Source/D3D11/CommandBufferD3D11.cpp index 150058c5..9c11ca6a 100644 --- a/Source/D3D11/CommandBufferD3D11.cpp +++ b/Source/D3D11/CommandBufferD3D11.cpp @@ -145,7 +145,7 @@ void CommandBufferD3D11::SetStencilReference(uint8_t frontRef, uint8_t backRef) } void CommandBufferD3D11::SetSamplePositions(const SamplePosition* positions, Sample_t positionNum, Sample_t sampleNum) { - MaybeUnused(sampleNum); // already have this in "m_RasterizerStateExDesc" + MaybeUnused(sampleNum); // already have this in "m_RasterizerDesc" m_SamplePositionsState.Set(positions, positionNum); @@ -446,6 +446,8 @@ void CommandBufferD3D11::DispatchIndirect(const Buffer& buffer, uint64_t offset) } void CommandBufferD3D11::Barrier(const BarrierGroupDesc& barrierGroupDesc) { + MaybeUnused(barrierGroupDesc); +#if NRI_USE_EXT_LIBS constexpr AccessBits STORAGE_MASK = AccessBits::SHADER_RESOURCE_STORAGE; if (barrierGroupDesc.textureNum == 0 && barrierGroupDesc.bufferNum == 0) @@ -494,6 +496,7 @@ void CommandBufferD3D11::Barrier(const BarrierGroupDesc& barrierGroupDesc) { if (flags) m_Device.GetExt()->WaitForDrain(m_DeferredContext, flags); +#endif } void CommandBufferD3D11::BeginQuery(const QueryPool& queryPool, uint32_t offset) { diff --git a/Source/D3D11/DeviceD3D11.cpp b/Source/D3D11/DeviceD3D11.cpp index e825de05..4590b716 100644 --- a/Source/D3D11/DeviceD3D11.cpp +++ b/Source/D3D11/DeviceD3D11.cpp @@ -94,8 +94,10 @@ DeviceD3D11::~DeviceD3D11() { DeleteCriticalSection(&m_CriticalSection); +#if NRI_USE_EXT_LIBS if (m_Ext.HasAGS() && !m_IsWrapped) m_Ext.m_AGS.DestroyDeviceD3D11(m_Ext.m_AGSContext, m_Device, nullptr, m_ImmediateContext, nullptr); +#endif } Result DeviceD3D11::Create(const DeviceCreationDesc& deviceCreationDesc, ID3D11Device* device, AGSContext* agsContext, bool isNVAPILoadedInApp) { @@ -141,21 +143,17 @@ Result DeviceD3D11::Create(const DeviceCreationDesc& deviceCreationDesc, ID3D11D m_Ext.InitializeAMDExt(this, agsContext, device != nullptr); // Device - AGSDX11ReturnedParams agsParams = {}; - if (m_Desc.adapterDesc.vendor == Vendor::NVIDIA) { // Tricky part: "params" is used to properly propagate exts support - agsParams.extensionsSupported.depthBoundsTest = true; - agsParams.extensionsSupported.depthBoundsDeferredContexts = true; - agsParams.extensionsSupported.uavOverlap = true; - agsParams.extensionsSupported.UAVOverlapDeferredContexts = true; - } - ComPtr deviceTemp = (ID3D11DeviceBest*)device; if (!deviceTemp) { - uint32_t shaderExtRegister = deviceCreationDesc.shaderExtRegister ? deviceCreationDesc.shaderExtRegister : 63; const UINT flags = deviceCreationDesc.enableAPIValidation ? D3D11_CREATE_DEVICE_DEBUG : 0; D3D_FEATURE_LEVEL levels[2] = {D3D_FEATURE_LEVEL_11_1, D3D_FEATURE_LEVEL_11_0}; const uint32_t levelNum = GetCountOf(levels); + bool isDepthBoundsTestSupported = false; + bool isDrawIndirectCountSupported = false; + bool isShaderAtomicsI64Supported = false; +#if NRI_USE_EXT_LIBS + uint32_t shaderExtRegister = deviceCreationDesc.shaderExtRegister ? deviceCreationDesc.shaderExtRegister : 63; if (m_Ext.HasAGS()) { AGSDX11DeviceCreationParams deviceCreationParams = {}; deviceCreationParams.pAdapter = m_Adapter; @@ -168,6 +166,7 @@ Result DeviceD3D11::Create(const DeviceCreationDesc& deviceCreationDesc, ID3D11D AGSDX11ExtensionParams extensionsParams = {}; extensionsParams.uavSlot = shaderExtRegister; + AGSDX11ReturnedParams agsParams = {}; AGSReturnCode result = m_Ext.m_AGS.CreateDeviceD3D11(m_Ext.m_AGSContext, &deviceCreationParams, &extensionsParams, &agsParams); if (flags != 0 && result != AGS_SUCCESS) { // If Debug Layer is not available, try without D3D11_CREATE_DEVICE_DEBUG @@ -178,7 +177,11 @@ Result DeviceD3D11::Create(const DeviceCreationDesc& deviceCreationDesc, ID3D11D RETURN_ON_FAILURE(this, result == AGS_SUCCESS, Result::FAILURE, "agsDriverExtensionsDX11_CreateDevice() failed: %d", (int32_t)result); deviceTemp = (ID3D11DeviceBest*)agsParams.pDevice; + isDepthBoundsTestSupported = agsParams.extensionsSupported.depthBoundsDeferredContexts; + isDrawIndirectCountSupported = agsParams.extensionsSupported.multiDrawIndirectCountIndirect; + isShaderAtomicsI64Supported = agsParams.extensionsSupported.intrinsics19; } else { +#endif hr = D3D11CreateDevice(m_Adapter, D3D_DRIVER_TYPE_UNKNOWN, nullptr, flags, levels, levelNum, D3D11_SDK_VERSION, (ID3D11Device**)&deviceTemp, nullptr, nullptr); if (flags && (uint32_t)hr == 0x887a002d) { // If Debug Layer is not available, try without D3D11_CREATE_DEVICE_DEBUG @@ -187,12 +190,20 @@ Result DeviceD3D11::Create(const DeviceCreationDesc& deviceCreationDesc, ID3D11D RETURN_ON_BAD_HRESULT(this, hr, "D3D11CreateDevice()"); - // Register device +#if NRI_USE_EXT_LIBS if (m_Ext.HasNVAPI()) { NvAPI_D3D_RegisterDevice(m_Device); NvAPI_D3D11_SetNvShaderExtnSlot(m_Device, shaderExtRegister); + NvAPI_D3D11_IsNvShaderExtnOpCodeSupported(m_Device, NV_EXTN_OP_UINT64_ATOMIC, &isShaderAtomicsI64Supported); + isDepthBoundsTestSupported = true; } } +#endif + + // Start filling here to avoid passing additional arguments into "FillDesc" + m_Desc.isDepthBoundsTestSupported = isDepthBoundsTestSupported; + m_Desc.isDrawIndirectCountSupported = isDrawIndirectCountSupported; + m_Desc.isShaderAtomicsI64Supported = isShaderAtomicsI64Supported; } else m_IsWrapped = true; @@ -220,9 +231,6 @@ Result DeviceD3D11::Create(const DeviceCreationDesc& deviceCreationDesc, ID3D11D if (!threadingCaps.DriverCommandLists) { REPORT_WARNING(this, "Deferred Contexts are not supported by the driver and will be emulated!"); m_IsDeferredContextEmulated = true; - - agsParams.extensionsSupported.UAVOverlapDeferredContexts = agsParams.extensionsSupported.uavOverlap; - agsParams.extensionsSupported.depthBoundsDeferredContexts = agsParams.extensionsSupported.depthBoundsTest; } hr = m_ImmediateContext->QueryInterface(IID_PPV_ARGS(&m_Multithread)); @@ -233,7 +241,7 @@ Result DeviceD3D11::Create(const DeviceCreationDesc& deviceCreationDesc, ID3D11D m_Multithread->SetMultithreadProtected(true); // Other - FillDesc(agsParams); + FillDesc(); for (uint32_t i = 0; i < (uint32_t)CommandQueueType::MAX_NUM; i++) m_CommandQueues.emplace_back(*this); @@ -241,7 +249,7 @@ Result DeviceD3D11::Create(const DeviceCreationDesc& deviceCreationDesc, ID3D11D return FillFunctionTable(m_CoreInterface); } -void DeviceD3D11::FillDesc(const AGSDX11ReturnedParams& agsParams) { +void DeviceD3D11::FillDesc() { D3D11_FEATURE_DATA_D3D11_OPTIONS options = {}; HRESULT hr = m_Device->CheckFeatureSupport(D3D11_FEATURE_D3D11_OPTIONS, &options, sizeof(options)); if (FAILED(hr)) @@ -397,33 +405,28 @@ void DeviceD3D11::FillDesc(const AGSDX11ReturnedParams& agsParams) { m_Desc.combinedClipAndCullDistanceMaxNum = D3D11_CLIP_OR_CULL_DISTANCE_COUNT; m_Desc.conservativeRasterTier = (uint8_t)options2.ConservativeRasterizationTier; + bool isShaderAtomicsF16Supported = false; + bool isShaderAtomicsF32Supported = false; +#if NRI_USE_EXT_LIBS + NvAPI_D3D11_IsNvShaderExtnOpCodeSupported(m_Device, NV_EXTN_OP_FP16_ATOMIC, &isShaderAtomicsF16Supported); + NvAPI_D3D11_IsNvShaderExtnOpCodeSupported(m_Device, NV_EXTN_OP_FP32_ATOMIC, &isShaderAtomicsF32Supported); + NV_D3D11_FEATURE_DATA_RASTERIZER_SUPPORT rasterizerFeatures = {}; NvAPI_D3D11_CheckFeatureSupport(m_Device, NV_D3D11_FEATURE_RASTERIZER, &rasterizerFeatures, sizeof(rasterizerFeatures)); m_Desc.programmableSampleLocationsTier = rasterizerFeatures.ProgrammableSamplePositions ? 2 : 0; +#endif m_Desc.isTextureFilterMinMaxSupported = options1.MinMaxFiltering != 0; m_Desc.isLogicOpSupported = options.OutputMergerLogicOp != 0; - m_Desc.isDepthBoundsTestSupported = agsParams.extensionsSupported.depthBoundsDeferredContexts; - m_Desc.isDrawIndirectCountSupported = agsParams.extensionsSupported.multiDrawIndirectCountIndirect; m_Desc.isLineSmoothingSupported = true; m_Desc.isShaderNativeI32Supported = true; m_Desc.isShaderNativeF32Supported = true; m_Desc.isShaderNativeF64Supported = options.ExtendedDoublesShaderInstructions; - bool isShaderAtomicsF16Supported = false; - NvAPI_D3D11_IsNvShaderExtnOpCodeSupported(m_Device, NV_EXTN_OP_FP16_ATOMIC, &isShaderAtomicsF16Supported); - - bool isShaderAtomicsF32Supported = false; - NvAPI_D3D11_IsNvShaderExtnOpCodeSupported(m_Device, NV_EXTN_OP_FP32_ATOMIC, &isShaderAtomicsF32Supported); - - bool isShaderAtomicsI64Supported = false; - NvAPI_D3D11_IsNvShaderExtnOpCodeSupported(m_Device, NV_EXTN_OP_UINT64_ATOMIC, &isShaderAtomicsI64Supported); - m_Desc.isShaderAtomicsF16Supported = isShaderAtomicsF16Supported; m_Desc.isShaderAtomicsI32Supported = true; m_Desc.isShaderAtomicsF32Supported = isShaderAtomicsF32Supported; - m_Desc.isShaderAtomicsI64Supported = (isShaderAtomicsI64Supported || agsParams.extensionsSupported.intrinsics19) ? true : false; m_Desc.isSwapChainSupported = HasOutput(); m_Desc.isLowLatencySupported = m_Ext.HasNVAPI(); diff --git a/Source/D3D11/DeviceD3D11.h b/Source/D3D11/DeviceD3D11.h index 3111a052..07addd4a 100644 --- a/Source/D3D11/DeviceD3D11.h +++ b/Source/D3D11/DeviceD3D11.h @@ -126,7 +126,7 @@ struct DeviceD3D11 final : public DeviceBase { Result FillFunctionTable(StreamerInterface& streamerInterface) const; private: - void FillDesc(const AGSDX11ReturnedParams& agsParams); + void FillDesc(); template Result CreateImplementation(Interface*& entity, const Args&... args); diff --git a/Source/D3D11/PipelineD3D11.cpp b/Source/D3D11/PipelineD3D11.cpp index 40a6bb57..6b0fc6fe 100644 --- a/Source/D3D11/PipelineD3D11.cpp +++ b/Source/D3D11/PipelineD3D11.cpp @@ -121,12 +121,14 @@ Result PipelineD3D11::Create(const GraphicsPipelineDesc& pipelineDesc) { m_RasterizerStates.push_back(rasterizerState); // Ex - memcpy(&m_RasterizerStateExDesc, &rasterizerDesc, sizeof(D3D11_RASTERIZER_DESC)); - m_RasterizerStateExDesc.ForcedSampleCount = sampleNum; - m_RasterizerStateExDesc.ProgrammableSamplePositionsEnable = true; - m_RasterizerStateExDesc.SampleCount = sampleNum; - m_RasterizerStateExDesc.ConservativeRasterEnable = r.conservativeRasterization; - m_RasterizerStateExDesc.TargetIndepentRasterWithDepth = true; + memcpy(&m_RasterizerDesc, &rasterizerDesc, sizeof(D3D11_RASTERIZER_DESC)); +#if NRI_USE_EXT_LIBS + m_RasterizerDesc.ForcedSampleCount = sampleNum; + m_RasterizerDesc.ProgrammableSamplePositionsEnable = true; + m_RasterizerDesc.SampleCount = sampleNum; + m_RasterizerDesc.ConservativeRasterEnable = r.conservativeRasterization; + m_RasterizerDesc.TargetIndepentRasterWithDepth = true; +#endif } { // Depth-stencil @@ -214,6 +216,8 @@ Result PipelineD3D11::Create(const ComputePipelineDesc& pipelineDesc) { } void PipelineD3D11::ChangeSamplePositions(ID3D11DeviceContextBest* deferredContext, const SamplePositionsState& samplePositionState) { + MaybeUnused(deferredContext, samplePositionState); +#if NRI_USE_EXT_LIBS if (IsCompute()) return; @@ -229,14 +233,14 @@ void PipelineD3D11::ChangeSamplePositions(ID3D11DeviceContextBest* deferredConte RasterizerState newState = {}; newState.samplePositionHash = samplePositionState.positionHash; - m_RasterizerStateExDesc.InterleavedSamplingEnable = samplePositionState.positionNum > m_RasterizerStateExDesc.SampleCount; + m_RasterizerDesc.InterleavedSamplingEnable = samplePositionState.positionNum > m_RasterizerDesc.SampleCount; for (uint32_t j = 0; j < samplePositionState.positionNum; j++) { - m_RasterizerStateExDesc.SamplePositionsX[j] = samplePositionState.positions[j].x + 8; - m_RasterizerStateExDesc.SamplePositionsY[j] = samplePositionState.positions[j].y + 8; + m_RasterizerDesc.SamplePositionsX[j] = samplePositionState.positions[j].x + 8; + m_RasterizerDesc.SamplePositionsY[j] = samplePositionState.positions[j].y + 8; } if (m_Device.GetExt()->HasNVAPI()) { - NvAPI_Status result = NvAPI_D3D11_CreateRasterizerState(m_Device.GetNativeObject(), &m_RasterizerStateExDesc, (ID3D11RasterizerState**)&newState.ptr); + NvAPI_Status result = NvAPI_D3D11_CreateRasterizerState(m_Device.GetNativeObject(), &m_RasterizerDesc, (ID3D11RasterizerState**)&newState.ptr); if (result != NVAPI_OK) REPORT_ERROR(&m_Device, "NvAPI_D3D11_CreateRasterizerState() - FAILED!"); } @@ -250,6 +254,7 @@ void PipelineD3D11::ChangeSamplePositions(ID3D11DeviceContextBest* deferredConte // Bind ID3D11RasterizerState2* stateWithPSL = m_RasterizerStates[i].ptr; deferredContext->RSSetState(stateWithPSL); +#endif } void PipelineD3D11::ChangeStencilReference(ID3D11DeviceContextBest* deferredContext, uint8_t stencilRef) { diff --git a/Source/D3D11/PipelineD3D11.h b/Source/D3D11/PipelineD3D11.h index 61895d99..de16ca69 100644 --- a/Source/D3D11/PipelineD3D11.h +++ b/Source/D3D11/PipelineD3D11.h @@ -65,7 +65,11 @@ struct PipelineD3D11 { ComPtr m_InputLayout; ComPtr m_DepthStencilState; ComPtr m_BlendState; - NvAPI_D3D11_RASTERIZER_DESC_EX m_RasterizerStateExDesc = {}; +#if NRI_USE_EXT_LIBS + NvAPI_D3D11_RASTERIZER_DESC_EX m_RasterizerDesc = {}; +#else + D3D11_RASTERIZER_DESC m_RasterizerDesc = {}; +#endif D3D11_PRIMITIVE_TOPOLOGY m_Topology = D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED; uint32_t m_SampleMask = uint32_t(-1); }; diff --git a/Source/D3D11/SharedD3D11.h b/Source/D3D11/SharedD3D11.h index cf18efa5..20dda664 100644 --- a/Source/D3D11/SharedD3D11.h +++ b/Source/D3D11/SharedD3D11.h @@ -185,9 +185,11 @@ struct SamplePositionsState { } // namespace nri -#include "amdags/ags_lib/inc/amd_ags.h" -#include "nvapi/nvapi.h" -#include "nvapi/nvShaderExtnEnums.h" +#if NRI_USE_EXT_LIBS + #include "amdags/ags_lib/inc/amd_ags.h" + #include "nvapi/nvapi.h" + #include "nvapi/nvShaderExtnEnums.h" +#endif namespace d3d11 { #include "D3DExt.h" diff --git a/Source/D3D11/SwapChainD3D11.cpp b/Source/D3D11/SwapChainD3D11.cpp index 4b5c8d77..4a715d55 100644 --- a/Source/D3D11/SwapChainD3D11.cpp +++ b/Source/D3D11/SwapChainD3D11.cpp @@ -191,15 +191,19 @@ inline Result SwapChainD3D11::WaitForPresent() { } inline Result SwapChainD3D11::Present() { +#if NRI_USE_EXT_LIBS if (m_Desc.allowLowLatency) SetLatencyMarker((LatencyMarker)PRESENT_START); +#endif uint32_t flags = (!m_Desc.verticalSyncInterval && (m_Flags & DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING)) ? DXGI_PRESENT_ALLOW_TEARING : 0; HRESULT hr = m_SwapChain->Present(m_Desc.verticalSyncInterval, flags); RETURN_ON_BAD_HRESULT(&m_Device, hr, "IDXGISwapChain::Present()"); +#if NRI_USE_EXT_LIBS if (m_Desc.allowLowLatency) SetLatencyMarker((LatencyMarker)PRESENT_END); +#endif m_PresentId++; @@ -207,6 +211,7 @@ inline Result SwapChainD3D11::Present() { } inline Result SwapChainD3D11::SetLatencySleepMode(const LatencySleepMode& latencySleepMode) { +#if NRI_USE_EXT_LIBS NV_SET_SLEEP_MODE_PARAMS params = {NV_SET_SLEEP_MODE_PARAMS_VER}; params.bLowLatencyMode = latencySleepMode.lowLatencyMode; params.bLowLatencyBoost = latencySleepMode.lowLatencyBoost; @@ -216,9 +221,15 @@ inline Result SwapChainD3D11::SetLatencySleepMode(const LatencySleepMode& latenc NvAPI_Status status = NvAPI_D3D_SetSleepMode(m_Device.GetNativeObject(), ¶ms); return status == NVAPI_OK ? Result::SUCCESS : Result::FAILURE; +#else + MaybeUnused(latencySleepMode); + + return Result::UNSUPPORTED; +#endif } inline Result SwapChainD3D11::SetLatencyMarker(LatencyMarker latencyMarker) { +#if NRI_USE_EXT_LIBS NV_LATENCY_MARKER_PARAMS params = {NV_LATENCY_MARKER_PARAMS_VER}; params.frameID = m_PresentId; params.markerType = (NV_LATENCY_MARKER_TYPE)latencyMarker; @@ -226,19 +237,29 @@ inline Result SwapChainD3D11::SetLatencyMarker(LatencyMarker latencyMarker) { NvAPI_Status status = NvAPI_D3D_SetLatencyMarker(m_Device.GetNativeObject(), ¶ms); return status == NVAPI_OK ? Result::SUCCESS : Result::FAILURE; +#else + MaybeUnused(latencyMarker); + + return Result::UNSUPPORTED; +#endif } inline Result SwapChainD3D11::LatencySleep() { +#if NRI_USE_EXT_LIBS NvAPI_Status status = NvAPI_D3D_Sleep(m_Device.GetNativeObject()); return status == NVAPI_OK ? Result::SUCCESS : Result::FAILURE; +#else + return Result::UNSUPPORTED; +#endif } inline Result SwapChainD3D11::GetLatencyReport(LatencyReport& latencyReport) { + latencyReport = {}; +#if NRI_USE_EXT_LIBS NV_LATENCY_RESULT_PARAMS params = {NV_LATENCY_RESULT_PARAMS_VER}; NvAPI_Status status = NvAPI_D3D_GetLatency(m_Device.GetNativeObject(), ¶ms); - latencyReport = {}; if (status == NVAPI_OK) { const uint32_t i = 63; // the most recent frame latencyReport.inputSampleTimeUs = params.frameReport[i].inputSampleTime; @@ -259,6 +280,9 @@ inline Result SwapChainD3D11::GetLatencyReport(LatencyReport& latencyReport) { } return Result::FAILURE; +#else + return Result::UNSUPPORTED; +#endif } #include "SwapChainD3D11.hpp" diff --git a/Source/D3D12/DeviceD3D12.cpp b/Source/D3D12/DeviceD3D12.cpp index b4c929b2..32b2f08e 100644 --- a/Source/D3D12/DeviceD3D12.cpp +++ b/Source/D3D12/DeviceD3D12.cpp @@ -124,8 +124,10 @@ DeviceD3D12::~DeviceD3D12() { Deallocate(GetStdAllocator(), commandQueueD3D12); } +#if NRI_USE_EXT_LIBS if (m_Ext.HasAGS() && !m_IsWrapped) m_Ext.m_AGS.DestroyDeviceD3D12(m_Ext.m_AGSContext, m_Device, nullptr); +#endif } template @@ -184,11 +186,11 @@ Result DeviceD3D12::Create(const DeviceCreationDesc& deviceCreationDesc, const D m_Ext.InitializeAMDExt(this, deviceCreationD3D12Desc.agsContext, deviceCreationD3D12Desc.d3d12Device != nullptr); // Device - AGSDX12ReturnedParams agsParams = {}; ComPtr deviceTemp = (ID3D12DeviceBest*)deviceCreationD3D12Desc.d3d12Device; if (!deviceTemp) { +#if NRI_USE_EXT_LIBS + bool isShaderAtomicsI64Supported = false; uint32_t shaderExtRegister = deviceCreationDesc.shaderExtRegister ? deviceCreationDesc.shaderExtRegister : 63; - if (m_Ext.HasAGS()) { AGSDX12DeviceCreationParams deviceCreationParams = {}; deviceCreationParams.pAdapter = m_Adapter; @@ -198,20 +200,28 @@ Result DeviceD3D12::Create(const DeviceCreationDesc& deviceCreationDesc, const D AGSDX12ExtensionParams extensionsParams = {}; extensionsParams.uavSlot = shaderExtRegister; + AGSDX12ReturnedParams agsParams = {}; AGSReturnCode result = m_Ext.m_AGS.CreateDeviceD3D12(m_Ext.m_AGSContext, &deviceCreationParams, &extensionsParams, &agsParams); RETURN_ON_FAILURE(this, result == AGS_SUCCESS, Result::FAILURE, "agsDriverExtensionsDX11_CreateDevice() failed: %d", (int32_t)result); deviceTemp = (ID3D12DeviceBest*)agsParams.pDevice; + isShaderAtomicsI64Supported = agsParams.extensionsSupported.intrinsics19; } else { +#endif hr = D3D12CreateDevice(m_Adapter, D3D_FEATURE_LEVEL_12_0, __uuidof(ID3D12Device), (void**)&deviceTemp); RETURN_ON_BAD_HRESULT(this, hr, "D3D12CreateDevice()"); - // Register device - if (m_Ext.HasNVAPI()) +#if NRI_USE_EXT_LIBS + if (m_Ext.HasNVAPI()) { NvAPI_D3D12_SetNvShaderExtnSlotSpace(m_Device, shaderExtRegister, deviceCreationDesc.shaderExtSpace); + NvAPI_D3D12_IsNvShaderExtnOpCodeSupported(m_Device, NV_EXTN_OP_UINT64_ATOMIC, &isShaderAtomicsI64Supported); + } } - } - else + + // Start filling here to avoid passing additional arguments into "FillDesc" + m_Desc.isShaderAtomicsI64Supported = isShaderAtomicsI64Supported; +#endif + } else m_IsWrapped = true; m_Version = QueryLatestDevice(deviceTemp, m_Device); @@ -257,7 +267,7 @@ Result DeviceD3D12::Create(const DeviceCreationDesc& deviceCreationDesc, const D return result; // Fill desc - FillDesc(deviceCreationDesc.enableD3D12DrawParametersEmulation, agsParams); + FillDesc(deviceCreationDesc.enableD3D12DrawParametersEmulation); // Create indirect command signatures m_DispatchCommandSignature = CreateCommandSignature(D3D12_INDIRECT_ARGUMENT_TYPE_DISPATCH, sizeof(DispatchDesc), nullptr); @@ -267,7 +277,7 @@ Result DeviceD3D12::Create(const DeviceCreationDesc& deviceCreationDesc, const D return FillFunctionTable(m_CoreInterface); } -void DeviceD3D12::FillDesc(bool enableDrawParametersEmulation, const AGSDX12ReturnedParams& agsParams) { +void DeviceD3D12::FillDesc(bool enableDrawParametersEmulation) { D3D12_FEATURE_DATA_SHADER_MODEL shaderModel = {D3D_HIGHEST_SHADER_MODEL}; HRESULT hr = m_Device->CheckFeatureSupport(D3D12_FEATURE_SHADER_MODEL, &shaderModel, sizeof(shaderModel)); if (FAILED(hr)) @@ -568,22 +578,18 @@ void DeviceD3D12::FillDesc(bool enableDrawParametersEmulation, const AGSDX12Retu m_Desc.isShaderNativeF64Supported = options.DoublePrecisionFloatShaderOps; bool isShaderAtomicsF16Supported = false; - NvAPI_D3D12_IsNvShaderExtnOpCodeSupported(m_Device, NV_EXTN_OP_FP16_ATOMIC, &isShaderAtomicsF16Supported); - bool isShaderAtomicsF32Supported = false; +#if NRI_USE_EXT_LIBS + NvAPI_D3D12_IsNvShaderExtnOpCodeSupported(m_Device, NV_EXTN_OP_FP16_ATOMIC, &isShaderAtomicsF16Supported); NvAPI_D3D12_IsNvShaderExtnOpCodeSupported(m_Device, NV_EXTN_OP_FP32_ATOMIC, &isShaderAtomicsF32Supported); - - bool isShaderAtomicsI64Supported = false; - NvAPI_D3D12_IsNvShaderExtnOpCodeSupported(m_Device, NV_EXTN_OP_UINT64_ATOMIC, &isShaderAtomicsI64Supported); +#endif m_Desc.isShaderAtomicsF16Supported = isShaderAtomicsF16Supported; m_Desc.isShaderAtomicsI32Supported = true; m_Desc.isShaderAtomicsF32Supported = isShaderAtomicsF32Supported; #ifdef NRI_USE_AGILITY_SDK - m_Desc.isShaderAtomicsI64Supported = isShaderAtomicsI64Supported || agsParams.extensionsSupported.intrinsics19 || options9.AtomicInt64OnTypedResourceSupported || - options9.AtomicInt64OnGroupSharedSupported || options11.AtomicInt64OnDescriptorHeapResourceSupported; -#else - m_Desc.isShaderAtomicsI64Supported = isShaderAtomicsI64Supported || agsParams.extensionsSupported.intrinsics19; + m_Desc.isShaderAtomicsI64Supported = m_Desc.isShaderAtomicsI64Supported || options9.AtomicInt64OnTypedResourceSupported || options9.AtomicInt64OnGroupSharedSupported || + options11.AtomicInt64OnDescriptorHeapResourceSupported; #endif m_Desc.isDrawParametersEmulationEnabled = enableDrawParametersEmulation && shaderModel.HighestShaderModel <= D3D_SHADER_MODEL_6_7; diff --git a/Source/D3D12/DeviceD3D12.h b/Source/D3D12/DeviceD3D12.h index 47a5d30a..6c0dc625 100644 --- a/Source/D3D12/DeviceD3D12.h +++ b/Source/D3D12/DeviceD3D12.h @@ -147,7 +147,7 @@ struct DeviceD3D12 final : public DeviceBase { Result FillFunctionTable(StreamerInterface& streamerInterface) const; private: - void FillDesc(bool enableDrawParametersEmulation, const AGSDX12ReturnedParams& agsParams); + void FillDesc(bool enableDrawParametersEmulation); MemoryType GetMemoryType(MemoryLocation memoryLocation, const D3D12_RESOURCE_DESC& resourceDesc) const; ComPtr CreateCommandSignature( D3D12_INDIRECT_ARGUMENT_TYPE indirectArgumentType, uint32_t stride, ID3D12RootSignature* rootSignature, bool enableDrawParametersEmulation = false); diff --git a/Source/D3D12/SharedD3D12.h b/Source/D3D12/SharedD3D12.h index 6694d25b..d1e4e416 100644 --- a/Source/D3D12/SharedD3D12.h +++ b/Source/D3D12/SharedD3D12.h @@ -71,9 +71,11 @@ D3D12_DESCRIPTOR_RANGE_TYPE GetDescriptorRangesType(DescriptorType descriptorTyp D3D12_RESOURCE_DIMENSION GetResourceDimension(TextureType textureType); } // namespace nri -#include "amdags/ags_lib/inc/amd_ags.h" -#include "nvapi/nvapi.h" -#include "nvapi/nvShaderExtnEnums.h" +#if NRI_USE_EXT_LIBS + #include "amdags/ags_lib/inc/amd_ags.h" + #include "nvapi/nvapi.h" + #include "nvapi/nvShaderExtnEnums.h" +#endif namespace d3d12 { #include "D3DExt.h" diff --git a/Source/D3D12/SwapChainD3D12.cpp b/Source/D3D12/SwapChainD3D12.cpp index 8dc1a320..1fe60101 100644 --- a/Source/D3D12/SwapChainD3D12.cpp +++ b/Source/D3D12/SwapChainD3D12.cpp @@ -193,15 +193,19 @@ inline Result SwapChainD3D12::WaitForPresent() { } inline Result SwapChainD3D12::Present() { +#if NRI_USE_EXT_LIBS if (m_Desc.allowLowLatency) SetLatencyMarker((LatencyMarker)PRESENT_START); +#endif uint32_t flags = (!m_Desc.verticalSyncInterval && (m_Flags & DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING)) ? DXGI_PRESENT_ALLOW_TEARING : 0; HRESULT hr = m_SwapChain->Present(m_Desc.verticalSyncInterval, flags); RETURN_ON_BAD_HRESULT(&m_Device, hr, "IDXGISwapChain::Present()"); +#if NRI_USE_EXT_LIBS if (m_Desc.allowLowLatency) SetLatencyMarker((LatencyMarker)PRESENT_END); +#endif m_PresentId++; @@ -209,6 +213,7 @@ inline Result SwapChainD3D12::Present() { } inline Result SwapChainD3D12::SetLatencySleepMode(const LatencySleepMode& latencySleepMode) { +#if NRI_USE_EXT_LIBS NV_SET_SLEEP_MODE_PARAMS params = {NV_SET_SLEEP_MODE_PARAMS_VER}; params.bLowLatencyMode = latencySleepMode.lowLatencyMode; params.bLowLatencyBoost = latencySleepMode.lowLatencyBoost; @@ -218,9 +223,15 @@ inline Result SwapChainD3D12::SetLatencySleepMode(const LatencySleepMode& latenc NvAPI_Status status = NvAPI_D3D_SetSleepMode(m_Device.GetNativeObject(), ¶ms); return status == NVAPI_OK ? Result::SUCCESS : Result::FAILURE; +#else + MaybeUnused(latencySleepMode); + + return Result::UNSUPPORTED; +#endif } inline Result SwapChainD3D12::SetLatencyMarker(LatencyMarker latencyMarker) { +#if NRI_USE_EXT_LIBS NV_LATENCY_MARKER_PARAMS params = {NV_LATENCY_MARKER_PARAMS_VER}; params.frameID = m_PresentId; params.markerType = (NV_LATENCY_MARKER_TYPE)latencyMarker; @@ -228,19 +239,29 @@ inline Result SwapChainD3D12::SetLatencyMarker(LatencyMarker latencyMarker) { NvAPI_Status status = NvAPI_D3D_SetLatencyMarker(m_Device.GetNativeObject(), ¶ms); return status == NVAPI_OK ? Result::SUCCESS : Result::FAILURE; +#else + MaybeUnused(latencyMarker); + + return Result::UNSUPPORTED; +#endif } inline Result SwapChainD3D12::LatencySleep() { +#if NRI_USE_EXT_LIBS NvAPI_Status status = NvAPI_D3D_Sleep(m_Device.GetNativeObject()); return status == NVAPI_OK ? Result::SUCCESS : Result::FAILURE; +#else + return Result::UNSUPPORTED; +#endif } inline Result SwapChainD3D12::GetLatencyReport(LatencyReport& latencyReport) { + latencyReport = {}; +#if NRI_USE_EXT_LIBS NV_LATENCY_RESULT_PARAMS params = {NV_LATENCY_RESULT_PARAMS_VER}; NvAPI_Status status = NvAPI_D3D_GetLatency(m_Device.GetNativeObject(), ¶ms); - latencyReport = {}; if (status == NVAPI_OK) { const uint32_t i = 63; // the most recent frame latencyReport.inputSampleTimeUs = params.frameReport[i].inputSampleTime; @@ -261,6 +282,9 @@ inline Result SwapChainD3D12::GetLatencyReport(LatencyReport& latencyReport) { } return Result::FAILURE; +#else + return Result::UNSUPPORTED; +#endif } #include "SwapChainD3D12.hpp" diff --git a/Source/Shared/D3DExt.h b/Source/Shared/D3DExt.h index a91102a8..b0ce131d 100644 --- a/Source/Shared/D3DExt.h +++ b/Source/Shared/D3DExt.h @@ -1,5 +1,7 @@ #pragma once +#if NRI_USE_EXT_LIBS + struct AGSFunctionTable { AGS_INITIALIZE Initialize; AGS_DEINITIALIZE Deinitialize; @@ -33,14 +35,16 @@ struct Ext { void InitializeAMDExt(const nri::DeviceBase* deviceBase, AGSContext* agsContext, bool isImported); // D3D11 -#if defined(__d3d11_h__) +# if defined(__d3d11_h__) void BeginUAVOverlap(ID3D11DeviceContext* deviceContext) const; void EndUAVOverlap(ID3D11DeviceContext* deviceContext) const; void WaitForDrain(ID3D11DeviceContext* deviceContext, uint32_t flags) const; void SetDepthBounds(ID3D11DeviceContext* deviceContext, float minBound, float maxBound) const; - void DrawIndirect(ID3D11DeviceContext* deviceContext, ID3D11Buffer* buffer, uint64_t offset, uint32_t drawNum, uint32_t stride, ID3D11Buffer* countBuffer, uint32_t countBufferOffset) const; - void DrawIndexedIndirect(ID3D11DeviceContext* deviceContext, ID3D11Buffer* buffer, uint64_t offset, uint32_t drawNum, uint32_t stride, ID3D11Buffer* countBuffer, uint32_t countBufferOffset) const; -#endif + void DrawIndirect( + ID3D11DeviceContext* deviceContext, ID3D11Buffer* buffer, uint64_t offset, uint32_t drawNum, uint32_t stride, ID3D11Buffer* countBuffer, uint32_t countBufferOffset) const; + void DrawIndexedIndirect( + ID3D11DeviceContext* deviceContext, ID3D11Buffer* buffer, uint64_t offset, uint32_t drawNum, uint32_t stride, ID3D11Buffer* countBuffer, uint32_t countBufferOffset) const; +# endif const nri::DeviceBase* m_DeviceBase = nullptr; AGSContext* m_AGSContext = nullptr; @@ -49,3 +53,43 @@ struct Ext { bool m_IsNvAPIAvailable = false; bool m_IsImported = false; }; + +#else + +struct Ext { + inline bool HasNVAPI() const { + return false; + } + + inline bool HasAGS() const { + return false; + } + + inline void InitializeNVExt(const nri::DeviceBase*, bool, bool) { + } + + inline void InitializeAMDExt(const nri::DeviceBase*, AGSContext*, bool) { + } + + // D3D11 +# if defined(__d3d11_h__) + inline void BeginUAVOverlap(ID3D11DeviceContext*) const { + } + + inline void EndUAVOverlap(ID3D11DeviceContext*) const { + } + + inline void WaitForDrain(ID3D11DeviceContext*, uint32_t) const { + } + + inline void SetDepthBounds(ID3D11DeviceContext*, float, float) const { + } + + void DrawIndirect( + ID3D11DeviceContext* deviceContext, ID3D11Buffer* buffer, uint64_t offset, uint32_t drawNum, uint32_t stride, ID3D11Buffer* countBuffer, uint32_t countBufferOffset) const; + void DrawIndexedIndirect( + ID3D11DeviceContext* deviceContext, ID3D11Buffer* buffer, uint64_t offset, uint32_t drawNum, uint32_t stride, ID3D11Buffer* countBuffer, uint32_t countBufferOffset) const; +# endif +}; + +#endif diff --git a/Source/Shared/D3DExt.hpp b/Source/Shared/D3DExt.hpp index 7346ee8b..78f5d649 100644 --- a/Source/Shared/D3DExt.hpp +++ b/Source/Shared/D3DExt.hpp @@ -1,5 +1,7 @@ // © 2021 NVIDIA Corporation +#if NRI_USE_EXT_LIBS + Ext::~Ext() { if (m_IsNvAPIAvailable) NvAPI_Unload(); @@ -19,7 +21,7 @@ void Ext::InitializeNVExt(const nri::DeviceBase* deviceBase, bool isNVAPILoadedI REPORT_WARNING(deviceBase, "NVAPI is disabled, because RenderDoc library has been loaded"); return; } - + m_DeviceBase = deviceBase; m_IsImported = isImported; @@ -96,7 +98,8 @@ void Ext::InitializeAMDExt(const nri::DeviceBase* deviceBase, AGSContext* agsCon } // D3D11 -#if defined(__d3d11_h__) +# if defined(__d3d11_h__) + void Ext::BeginUAVOverlap(ID3D11DeviceContext* deviceContext) const { if (m_IsNvAPIAvailable) { const NvAPI_Status res = NvAPI_D3D11_BeginUAVOverlap(deviceContext); @@ -187,4 +190,34 @@ void Ext::DrawIndexedIndirect( } } } + +# endif + +#else + +// D3D11 +# if defined(__d3d11_h__) + +void Ext::DrawIndirect( + ID3D11DeviceContext* deviceContext, ID3D11Buffer* buffer, uint64_t offset, uint32_t drawNum, uint32_t stride, ID3D11Buffer* countBuffer, uint32_t) const { + if (!countBuffer) { + for (uint32_t i = 0; i < drawNum; i++) { + deviceContext->DrawInstancedIndirect(buffer, (uint32_t)offset); + offset += stride; + } + } +} + +void Ext::DrawIndexedIndirect( + ID3D11DeviceContext* deviceContext, ID3D11Buffer* buffer, uint64_t offset, uint32_t drawNum, uint32_t stride, ID3D11Buffer* countBuffer, uint32_t) const { + if (!countBuffer) { + for (uint32_t i = 0; i < drawNum; i++) { + deviceContext->DrawIndexedInstancedIndirect(buffer, (uint32_t)offset); + offset += stride; + } + } +} + +# endif + #endif