summaryrefslogtreecommitdiffstats
path: root/tools/gfx/d3d12/render-d3d12.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2020-08-21 16:04:42 -0400
committerGitHub <noreply@github.com>2020-08-21 13:04:42 -0700
commitfcac02e405661de311b5ceebbd6d3e2c78bf8aea (patch)
tree6e79865b39f0739d2ac9c3f91cc4129c244b6977 /tools/gfx/d3d12/render-d3d12.cpp
parent49067fd2e97b40649df3fa2ce096f78c2e45da5a (diff)
Vulkan update/NVAPI support (#1511)
* First pass at incorporating nvapi into test harness. * D3d12 Atomic Float Add via NVAPI working * Dx12 atomic float appears to work. * Atomic float add on Dx12. * Added atomic64 feature addition to vk. Fix correct output for atomic-float-byte-address.slang * Disable atomic float failing tests. * Upgraded VK headers. * Detect atomic float availability on VK. * Try to get test working for in64 atomic. * Made HLSL prelude controlled via the render-test requirements. * Added -enable-nvapi to premake. * Fix D3D12Renderer when NVAPI is not available. * Small improvements to VKRenderer. * Improve atomic documentation in target-compatibility.md.
Diffstat (limited to 'tools/gfx/d3d12/render-d3d12.cpp')
-rw-r--r--tools/gfx/d3d12/render-d3d12.cpp74
1 files changed, 70 insertions, 4 deletions
diff --git a/tools/gfx/d3d12/render-d3d12.cpp b/tools/gfx/d3d12/render-d3d12.cpp
index ba9bde63a..ca44aa04d 100644
--- a/tools/gfx/d3d12/render-d3d12.cpp
+++ b/tools/gfx/d3d12/render-d3d12.cpp
@@ -23,7 +23,16 @@
#include <dxgi1_4.h>
#include <d3d12.h>
-#include <d3dcompiler.h>
+//#include <d3dcompiler.h>
+
+#ifndef __ID3D12GraphicsCommandList1_FWD_DEFINED__
+// If can't find a definition of CommandList1, just use an empty definition
+struct ID3D12GraphicsCommandList1 {};
+#endif
+
+#ifdef GFX_NVAPI
+# include "../nvapi/nvapi-include.h"
+#endif
#include "../../slang-com-ptr.h"
#include "../flag-combiner.h"
@@ -34,6 +43,8 @@
#include "../d3d/d3d-util.h"
+#include "../nvapi/nvapi-util.h"
+
// We will use the C standard library just for printing error messages.
#include <stdio.h>
@@ -690,6 +701,8 @@ protected:
HWND m_hwnd = nullptr;
List<String> m_features;
+
+ bool m_nvapi = false;
};
Renderer* createD3D12Renderer()
@@ -1589,6 +1602,30 @@ Result D3D12Renderer::initialize(const Desc& desc, void* inWindowHandle)
return SLANG_FAIL;
}
+ // NVAPI
+ {
+ const char* features[] = { "nvapi", "atomic-float", "atomic-int64" };
+ bool needsNvapi = false;
+ for (Index i = 0; i < SLANG_COUNT_OF(features); ++i)
+ {
+ if (desc.requiredFeatures.indexOf(features[i]) >= 0)
+ {
+ needsNvapi = true;
+ break;
+ }
+ }
+
+ if (needsNvapi && SLANG_SUCCEEDED(NVAPIUtil::initialize()))
+ {
+ // TODO(JS): We should test for specific features here.
+ for (Index i = 0; i < SLANG_COUNT_OF(features); ++i)
+ {
+ m_features.add(features[i]);
+ }
+ m_nvapi = true;
+ }
+ }
+
// Set the device
m_device = m_deviceInfo.m_device;
@@ -3209,7 +3246,7 @@ void D3D12Renderer::DescriptorSetImpl::setRootConstants(
// have been a root-constant range for this call to be
// valid.
//
- SLANG_ASSERT(range < m_layout->m_ranges.getCount());
+ SLANG_ASSERT(range < UInt(m_layout->m_ranges.getCount()));
auto& rangeInfo = m_layout->m_ranges[range];
SLANG_ASSERT(rangeInfo.type == DescriptorSlotType::RootConstant);
@@ -3222,7 +3259,7 @@ void D3D12Renderer::DescriptorSetImpl::setRootConstants(
SLANG_ASSERT(rootConstantIndex >= 0);
SLANG_ASSERT(rootConstantIndex < m_layout->m_rootConstantRanges.getCount());
auto& rootConstantRangeInfo = m_layout->m_rootConstantRanges[rootConstantIndex];
- SLANG_ASSERT(offset + size <= rootConstantRangeInfo.size);
+ SLANG_ASSERT(offset + size <= UInt(rootConstantRangeInfo.size));
memcpy((char*)m_rootConstantData.getBuffer() + rootConstantRangeInfo.offset + offset, data, size);
}
@@ -3951,7 +3988,36 @@ Result D3D12Renderer::createComputePipelineState(const ComputePipelineStateDesc&
computeDesc.CS = { programImpl->m_computeShader.getBuffer(), SIZE_T(programImpl->m_computeShader.getCount()) };
ComPtr<ID3D12PipelineState> pipelineState;
- SLANG_RETURN_ON_FAIL(m_device->CreateComputePipelineState(&computeDesc, IID_PPV_ARGS(pipelineState.writeRef())));
+
+#ifdef GFX_NVAPI
+ if (m_nvapi)
+ {
+ // Also fill the extension structure.
+ // Use the same UAV slot index and register space that are declared in the shader.
+
+ // For simplicities sake we just use u0
+ NVAPI_D3D12_PSO_SET_SHADER_EXTENSION_SLOT_DESC extensionDesc;
+ extensionDesc.baseVersion = NV_PSO_EXTENSION_DESC_VER;
+ extensionDesc.version = NV_SET_SHADER_EXTENSION_SLOT_DESC_VER;
+ extensionDesc.uavSlot = 0;
+ extensionDesc.registerSpace = 0;
+
+ // Put the pointer to the extension into an array - there can be multiple extensions enabled at once.
+ const NVAPI_D3D12_PSO_EXTENSION_DESC* extensions[] = { &extensionDesc };
+
+ // Now create the PSO.
+ const NvAPI_Status nvapiStatus = NvAPI_D3D12_CreateComputePipelineState(m_device, &computeDesc, SLANG_COUNT_OF(extensions), extensions, pipelineState.writeRef());
+
+ if (nvapiStatus != NVAPI_OK)
+ {
+ return SLANG_FAIL;
+ }
+ }
+ else
+#endif
+ {
+ SLANG_RETURN_ON_FAIL(m_device->CreateComputePipelineState(&computeDesc, IID_PPV_ARGS(pipelineState.writeRef())));
+ }
RefPtr<PipelineStateImpl> pipelineStateImpl = new PipelineStateImpl();
pipelineStateImpl->m_pipelineType = PipelineType::Compute;