Skip to content

Commit

Permalink
D3DExt changes:
Browse files Browse the repository at this point in the history
- fixed compilation with "NRI_ENABLE_EXTERNAL_LIBRARIES = OFF"
- PIX: doesn't depend on "NRI_ENABLE_EXTERNAL_LIBRARIES"
- PIX: added function table validation
- D3D11: removed dummy D3D12 funcs
- D3D12: removed dummy D3D11 funcs
- camel case related refactoring
  • Loading branch information
dzhdanNV committed Dec 24, 2024
1 parent ba32ff6 commit d25c56e
Show file tree
Hide file tree
Showing 11 changed files with 211 additions and 141 deletions.
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ 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
# Options: D3D11/D3D12 specific (PIX events are always enabled if "WinPixEventRuntime.dll" is nearby)
option (NRI_ENABLE_EXTERNAL_LIBRARIES "Enable vendor specific extension libraries (NVAPI and AMD AGS)" ON)

# Is submodule?
Expand Down Expand Up @@ -98,7 +98,7 @@ if (WIN32)
find_library (INPUT_LIB_D3D11 NAMES d3d11 HINTS ${WINDOWS_SDK_LIB_PATH} REQUIRED)
find_library (INPUT_LIB_D3D12 NAMES d3d12 HINTS ${WINDOWS_SDK_LIB_PATH} REQUIRED)
find_library (INPUT_LIB_DXGI NAMES dxgi HINTS ${WINDOWS_SDK_LIB_PATH} REQUIRED)
find_library (INPUT_LIB_DXGUID NAMES dxguid HINTS ${WINDOWS_SDK_LIB_PATH} REQUIRED)
find_library (INPUT_LIB_DXGUID NAMES dxguid HINTS ${WINDOWS_SDK_LIB_PATH} REQUIRED) # for nriReportLiveObjects
endif ()

# Globals?
Expand Down Expand Up @@ -325,7 +325,7 @@ target_compile_options (${PROJECT_NAME} PRIVATE ${COMPILE_OPTIONS})

target_link_libraries (${PROJECT_NAME} PRIVATE NRI_Shared NRI_Validation)
if (WIN32)
target_link_libraries (${PROJECT_NAME} PRIVATE ${INPUT_LIB_DXGI} ${INPUT_LIB_DXGUID}) # for nriReportLiveObjects
target_link_libraries (${PROJECT_NAME} PRIVATE ${INPUT_LIB_DXGI} ${INPUT_LIB_DXGUID})
else ()
target_link_libraries (${PROJECT_NAME} PRIVATE ${CMAKE_DL_LIBS})
endif ()
Expand Down
2 changes: 1 addition & 1 deletion Source/D3D11/CommandBufferD3D11.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ NRI_INLINE void CommandBufferD3D11::BeginRendering(const AttachmentsDesc& attach

// Shading rate
#if NRI_USE_EXT_LIBS
if (m_Device.GetExt()->HasNVAPI() && m_Device.GetDesc().shadingRateTier >= 2) {
if (m_Device.GetExt()->HasNvapi() && m_Device.GetDesc().shadingRateTier >= 2) {
ID3D11NvShadingRateResourceView* shadingRateImage = nullptr;
if (attachmentsDesc.shadingRate) {
const DescriptorD3D11& descriptor = *(DescriptorD3D11*)attachmentsDesc.shadingRate;
Expand Down
2 changes: 1 addition & 1 deletion Source/D3D11/DescriptorD3D11.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ Result DescriptorD3D11::Create(const Texture2DViewDesc& textureViewDesc) {
}
case Texture2DViewType::SHADING_RATE_ATTACHMENT: {
#if NRI_USE_EXT_LIBS
if (m_Device.GetExt()->HasNVAPI()) {
if (m_Device.GetExt()->HasNvapi()) {
NV_D3D11_SHADING_RATE_RESOURCE_VIEW_DESC desc = {NV_D3D11_SHADING_RATE_RESOURCE_VIEW_DESC_VER};
desc.Format = format;
desc.ViewDimension = NV_SRRV_DIMENSION_TEXTURE2D;
Expand Down
22 changes: 11 additions & 11 deletions Source/D3D11/DeviceD3D11.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ 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);
if (m_Ext.HasAgs() && !m_IsWrapped)
m_Ext.m_Ags.DestroyDeviceD3D11(m_Ext.m_AgsContext, m_Device, nullptr, m_ImmediateContext, nullptr);
#endif

for (CommandQueueD3D11* commandQueue : m_CommandQueues) {
Expand Down Expand Up @@ -85,9 +85,9 @@ Result DeviceD3D11::Create(const DeviceCreationDesc& deviceCreationDesc, ID3D11D

// Extensions
if (m_Desc.adapterDesc.vendor == Vendor::NVIDIA)
m_Ext.InitializeNVExt(this, isNVAPILoadedInApp, device != nullptr);
m_Ext.InitializeNvExt(this, isNVAPILoadedInApp, device != nullptr);
else if (m_Desc.adapterDesc.vendor == Vendor::AMD)
m_Ext.InitializeAMDExt(this, agsContext, device != nullptr);
m_Ext.InitializeAmdExt(this, agsContext, device != nullptr);

// Device
ComPtr<ID3D11DeviceBest> deviceTemp = (ID3D11DeviceBest*)device;
Expand All @@ -101,7 +101,7 @@ Result DeviceD3D11::Create(const DeviceCreationDesc& deviceCreationDesc, ID3D11D

#if NRI_USE_EXT_LIBS
uint32_t shaderExtRegister = deviceCreationDesc.shaderExtRegister ? deviceCreationDesc.shaderExtRegister : 63;
if (m_Ext.HasAGS()) {
if (m_Ext.HasAgs()) {
AGSDX11DeviceCreationParams deviceCreationParams = {};
deviceCreationParams.pAdapter = m_Adapter;
deviceCreationParams.DriverType = D3D_DRIVER_TYPE_UNKNOWN;
Expand All @@ -114,11 +114,11 @@ Result DeviceD3D11::Create(const DeviceCreationDesc& deviceCreationDesc, ID3D11D
extensionsParams.uavSlot = shaderExtRegister;

AGSDX11ReturnedParams agsParams = {};
AGSReturnCode result = m_Ext.m_AGS.CreateDeviceD3D11(m_Ext.m_AGSContext, &deviceCreationParams, &extensionsParams, &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
deviceCreationParams.Flags = 0;
result = m_Ext.m_AGS.CreateDeviceD3D11(m_Ext.m_AGSContext, &deviceCreationParams, &extensionsParams, &agsParams);
result = m_Ext.m_Ags.CreateDeviceD3D11(m_Ext.m_AgsContext, &deviceCreationParams, &extensionsParams, &agsParams);
}

RETURN_ON_FAILURE(this, result == AGS_SUCCESS, Result::FAILURE, "agsDriverExtensionsDX11_CreateDevice() returned %d", (int32_t)result);
Expand All @@ -138,7 +138,7 @@ Result DeviceD3D11::Create(const DeviceCreationDesc& deviceCreationDesc, ID3D11D
RETURN_ON_BAD_HRESULT(this, hr, "D3D11CreateDevice()");

#if NRI_USE_EXT_LIBS
if (m_Ext.HasNVAPI()) {
if (m_Ext.HasNvapi()) {
REPORT_ERROR_ON_BAD_STATUS(this, NvAPI_D3D_RegisterDevice(deviceTemp));
REPORT_ERROR_ON_BAD_STATUS(this, NvAPI_D3D11_SetNvShaderExtnSlot(deviceTemp, shaderExtRegister));
REPORT_ERROR_ON_BAD_STATUS(this, NvAPI_D3D11_IsNvShaderExtnOpCodeSupported(deviceTemp, NV_EXTN_OP_UINT64_ATOMIC, &isShaderAtomicsI64Supported));
Expand Down Expand Up @@ -173,7 +173,7 @@ Result DeviceD3D11::Create(const DeviceCreationDesc& deviceCreationDesc, ID3D11D
if (FAILED(hr) || !threadingCaps.DriverConcurrentCreates)
REPORT_WARNING(this, "Concurrent resource creation is not supported by the driver!");

m_IsDeferredContextEmulated = !m_Ext.HasNVAPI() || deviceCreationDesc.enableD3D11CommandBufferEmulation;
m_IsDeferredContextEmulated = !m_Ext.HasNvapi() || deviceCreationDesc.enableD3D11CommandBufferEmulation;
if (!threadingCaps.DriverCommandLists) {
REPORT_WARNING(this, "Deferred Contexts are not supported by the driver and will be emulated!");
m_IsDeferredContextEmulated = true;
Expand Down Expand Up @@ -358,7 +358,7 @@ void DeviceD3D11::FillDesc() {
NV_D3D11_FEATURE_DATA_RASTERIZER_SUPPORT rasterizerFeatures = {};
NV_D3D1x_GRAPHICS_CAPS caps = {};

if (m_Ext.HasNVAPI()) {
if (m_Ext.HasNvapi()) {
REPORT_ERROR_ON_BAD_STATUS(this, NvAPI_D3D11_IsNvShaderExtnOpCodeSupported(m_Device, NV_EXTN_OP_FP16_ATOMIC, &isShaderAtomicsF16Supported));
REPORT_ERROR_ON_BAD_STATUS(this, NvAPI_D3D11_IsNvShaderExtnOpCodeSupported(m_Device, NV_EXTN_OP_FP32_ATOMIC, &isShaderAtomicsF32Supported));
REPORT_ERROR_ON_BAD_STATUS(this, NvAPI_D3D11_CheckFeatureSupport(m_Device, NV_D3D11_FEATURE_RASTERIZER, &rasterizerFeatures, sizeof(rasterizerFeatures)));
Expand Down Expand Up @@ -386,7 +386,7 @@ void DeviceD3D11::FillDesc() {
m_Desc.isShaderAtomicsF32Supported = isShaderAtomicsF32Supported;

m_Desc.isSwapChainSupported = HasOutput();
m_Desc.isLowLatencySupported = m_Ext.HasNVAPI();
m_Desc.isLowLatencySupported = m_Ext.HasNvapi();
}

void DeviceD3D11::GetMemoryDesc(const BufferDesc& bufferDesc, MemoryLocation memoryLocation, MemoryDesc& memoryDesc) const {
Expand Down
2 changes: 1 addition & 1 deletion Source/D3D11/PipelineD3D11.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ void PipelineD3D11::ChangeSamplePositions(ID3D11DeviceContextBest* deferredConte
m_RasterizerDesc.SamplePositionsY[j] = samplePositionState.positions[j].y + 8;
}

if (m_Device.GetExt()->HasNVAPI())
if (m_Device.GetExt()->HasNvapi())
REPORT_ERROR_ON_BAD_STATUS(&m_Device, NvAPI_D3D11_CreateRasterizerState(m_Device.GetNativeObject(), &m_RasterizerDesc, (ID3D11RasterizerState**)&newState.ptr));

if (newState.ptr)
Expand Down
2 changes: 1 addition & 1 deletion Source/D3D11/SwapChainD3D11.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ Result SwapChainD3D11::Create(const SwapChainDesc& swapChainDesc) {
m_Flags = desc.Flags;
m_Desc = swapChainDesc;
m_Desc.textureNum = 1; // IMPORTANT: only 1 texture is available in D3D11
m_Desc.allowLowLatency = swapChainDesc.allowLowLatency && m_Device.GetExt()->HasNVAPI();
m_Desc.allowLowLatency = swapChainDesc.allowLowLatency && m_Device.GetExt()->HasNvapi();

m_Textures.reserve(m_Desc.textureNum);
for (uint32_t i = 0; i < m_Desc.textureNum; i++) {
Expand Down
6 changes: 3 additions & 3 deletions Source/D3D12/CommandBufferD3D12.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -933,21 +933,21 @@ NRI_INLINE void CommandBufferD3D12::CopyQueries(const QueryPool& queryPool, uint
}

NRI_INLINE void CommandBufferD3D12::BeginAnnotation(const char* name, uint32_t bgra) {
if (m_Device.GetExt()->m_Pix.BeginEventOnCommandList)
if (m_Device.GetExt()->HasPix())
m_Device.GetExt()->m_Pix.BeginEventOnCommandList(m_GraphicsCommandList, bgra, name);
else
PIXBeginEvent(m_GraphicsCommandList, bgra, name);
}

NRI_INLINE void CommandBufferD3D12::EndAnnotation() {
if (m_Device.GetExt()->m_Pix.EndEventOnCommandList)
if (m_Device.GetExt()->HasPix())
m_Device.GetExt()->m_Pix.EndEventOnCommandList(m_GraphicsCommandList);
else
PIXEndEvent(m_GraphicsCommandList);
}

NRI_INLINE void CommandBufferD3D12::Annotation(const char* name, uint32_t bgra) {
if (m_Device.GetExt()->m_Pix.SetMarkerOnCommandList)
if (m_Device.GetExt()->HasPix())
m_Device.GetExt()->m_Pix.SetMarkerOnCommandList(m_GraphicsCommandList, bgra, name);
else
PIXSetMarker(m_GraphicsCommandList, bgra, name);
Expand Down
18 changes: 9 additions & 9 deletions Source/D3D12/DeviceD3D12.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ DeviceD3D12::~DeviceD3D12() {
}

#if NRI_USE_EXT_LIBS
if (m_Ext.HasAGS() && !m_IsWrapped)
m_Ext.m_AGS.DestroyDeviceD3D12(m_Ext.m_AGSContext, m_Device, nullptr);
if (m_Ext.HasAgs() && !m_IsWrapped)
m_Ext.m_Ags.DestroyDeviceD3D12(m_Ext.m_AgsContext, m_Device, nullptr);
#endif
}

Expand Down Expand Up @@ -120,17 +120,17 @@ Result DeviceD3D12::Create(const DeviceCreationDesc& deviceCreationDesc, const D
// Extensions
m_Ext.InitializePixExt();
if (m_Desc.adapterDesc.vendor == Vendor::NVIDIA)
m_Ext.InitializeNVExt(this, deviceCreationD3D12Desc.isNVAPILoaded, deviceCreationD3D12Desc.d3d12Device != nullptr);
m_Ext.InitializeNvExt(this, deviceCreationD3D12Desc.isNVAPILoaded, deviceCreationD3D12Desc.d3d12Device != nullptr);
else if (m_Desc.adapterDesc.vendor == Vendor::AMD)
m_Ext.InitializeAMDExt(this, deviceCreationD3D12Desc.agsContext, deviceCreationD3D12Desc.d3d12Device != nullptr);
m_Ext.InitializeAmdExt(this, deviceCreationD3D12Desc.agsContext, deviceCreationD3D12Desc.d3d12Device != nullptr);

// Device
ComPtr<ID3D12DeviceBest> 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()) {
if (m_Ext.HasAgs()) {
AGSDX12DeviceCreationParams deviceCreationParams = {};
deviceCreationParams.pAdapter = m_Adapter;
deviceCreationParams.iid = __uuidof(ID3D12DeviceBest);
Expand All @@ -140,7 +140,7 @@ Result DeviceD3D12::Create(const DeviceCreationDesc& deviceCreationDesc, const D
extensionsParams.uavSlot = shaderExtRegister;

AGSDX12ReturnedParams agsParams = {};
AGSReturnCode result = m_Ext.m_AGS.CreateDeviceD3D12(m_Ext.m_AGSContext, &deviceCreationParams, &extensionsParams, &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;
Expand All @@ -151,7 +151,7 @@ Result DeviceD3D12::Create(const DeviceCreationDesc& deviceCreationDesc, const D
RETURN_ON_BAD_HRESULT(this, hr, "D3D12CreateDevice()");

#if NRI_USE_EXT_LIBS
if (m_Ext.HasNVAPI()) {
if (m_Ext.HasNvapi()) {
REPORT_ERROR_ON_BAD_STATUS(this, NvAPI_D3D12_SetNvShaderExtnSlotSpace(deviceTemp, shaderExtRegister, deviceCreationDesc.shaderExtSpace));
REPORT_ERROR_ON_BAD_STATUS(this, NvAPI_D3D12_IsNvShaderExtnOpCodeSupported(deviceTemp, NV_EXTN_OP_UINT64_ATOMIC, &isShaderAtomicsI64Supported));
}
Expand Down Expand Up @@ -537,7 +537,7 @@ void DeviceD3D12::FillDesc(const DeviceCreationDesc& deviceCreationDesc) {
bool isShaderAtomicsF16Supported = false;
bool isShaderAtomicsF32Supported = false;
#if NRI_USE_EXT_LIBS
if (m_Ext.HasNVAPI()) {
if (m_Ext.HasNvapi()) {
REPORT_ERROR_ON_BAD_STATUS(this, NvAPI_D3D12_IsNvShaderExtnOpCodeSupported(m_Device, NV_EXTN_OP_FP16_ATOMIC, &isShaderAtomicsF16Supported));
REPORT_ERROR_ON_BAD_STATUS(this, NvAPI_D3D12_IsNvShaderExtnOpCodeSupported(m_Device, NV_EXTN_OP_FP32_ATOMIC, &isShaderAtomicsF32Supported));
}
Expand All @@ -553,7 +553,7 @@ void DeviceD3D12::FillDesc(const DeviceCreationDesc& deviceCreationDesc) {
m_Desc.isDrawParametersEmulationEnabled = deviceCreationDesc.enableD3D12DrawParametersEmulation && shaderModel.HighestShaderModel <= D3D_SHADER_MODEL_6_7;

m_Desc.isSwapChainSupported = HasOutput();
m_Desc.isLowLatencySupported = m_Ext.HasNVAPI();
m_Desc.isLowLatencySupported = m_Ext.HasNvapi();
}

Result DeviceD3D12::CreateCpuOnlyVisibleDescriptorHeap(D3D12_DESCRIPTOR_HEAP_TYPE type) {
Expand Down
2 changes: 1 addition & 1 deletion Source/D3D12/SwapChainD3D12.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ Result SwapChainD3D12::Create(const SwapChainDesc& swapChainDesc) {
m_PresentId = GetSwapChainId();
m_Flags = desc.Flags;
m_Desc = swapChainDesc;
m_Desc.allowLowLatency = swapChainDesc.allowLowLatency && m_Device.GetExt()->HasNVAPI();
m_Desc.allowLowLatency = swapChainDesc.allowLowLatency && m_Device.GetExt()->HasNvapi();

m_Textures.reserve(m_Desc.textureNum);
for (uint32_t i = 0; i < m_Desc.textureNum; i++) {
Expand Down
Loading

0 comments on commit d25c56e

Please sign in to comment.