summaryrefslogtreecommitdiff
path: root/tools/gfx/d3d12/render-d3d12.cpp
diff options
context:
space:
mode:
authorlucy96chen <47800040+lucy96chen@users.noreply.github.com>2022-01-10 11:00:50 -0800
committerGitHub <noreply@github.com>2022-01-10 11:00:50 -0800
commitaee4aa3528072e4b5e95ccc4e571868716b47d50 (patch)
tree3621d7e5cd67e09581d7fe001e359df12167889b /tools/gfx/d3d12/render-d3d12.cpp
parent8919c19440dea9a62578905d365fe80bcd58e316 (diff)
Draw call tests for Vulkan (#2073)
* Added instancing support to Vulkan, drawInstanced() test image is upside-down * Fixed inverted drawInstanced() test output by changing Vulkan viewport convention * Replaced vkCmdDraw with vkCmdDrawIndexed in all non-indirect indexed draws, drawIndexedIndirect test now working for Vulkan * Moved index and vertex buffer binding into setIndexBuffer and setVertexBuffers; Defaulted countBuffer to nullptr and countOffset to 0 and added a check for non-null countBuffer to drawIndirect and drawIndexedIndirect in Vulkan; All Vulkan draw tests working (but D3D12 tests broken) * Added support for drawInstanced and drawIndexedInstanced to D3D11 and added tests for both, however D3D11 tests are currently disabled due to readTextureResource assuming a fixed pixel size (among other possible problems); Fixed issues causing D3D12 tests to fail after major back-end fixes to get Vulkan up and running * Removed testing function for dumping images and some other commented out code * Removed some commented out code * Fix initializer list causing builds to fail (attempt 1) * Removed initializer list for VertexStreamDesc in createInputLayout() and fill in struct fields normally (build fix attempt 2) * Removed default values from VertexStreamDesc and changed all initializer lists to reflect this change * Moved applyBinding before setVertexBuffer in RenderTestApp::renderFrame() to ensure the pipeline has already been bound before vertex buffers are * Changed D3D11's readTextureResource to calculate pixel size using format-specific size information; Removed wrapper around D3D11 instanced and indexed instanced draw tests
Diffstat (limited to 'tools/gfx/d3d12/render-d3d12.cpp')
-rw-r--r--tools/gfx/d3d12/render-d3d12.cpp39
1 files changed, 27 insertions, 12 deletions
diff --git a/tools/gfx/d3d12/render-d3d12.cpp b/tools/gfx/d3d12/render-d3d12.cpp
index 765be5db5..bbfc10f5a 100644
--- a/tools/gfx/d3d12/render-d3d12.cpp
+++ b/tools/gfx/d3d12/render-d3d12.cpp
@@ -120,8 +120,7 @@ public:
IRenderPassLayout** outRenderPassLayout) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createInputLayout(
- const InputElementDesc* inputElements,
- UInt inputElementCount,
+ IInputLayout::Desc const& desc,
IInputLayout** outLayout) override;
virtual Result createShaderObjectLayout(
@@ -395,6 +394,7 @@ public:
{
public:
List<D3D12_INPUT_ELEMENT_DESC> m_elements;
+ List<UINT> m_vertexStreamStrides;
List<char> m_text; ///< Holds all strings to keep in scope
};
@@ -530,7 +530,6 @@ public:
struct BoundVertexBuffer
{
RefPtr<BufferResourceImpl> m_buffer;
- int m_stride;
int m_offset;
};
@@ -3286,7 +3285,6 @@ public:
uint32_t startSlot,
uint32_t slotCount,
IBufferResource* const* buffers,
- const uint32_t* strides,
const uint32_t* offsets) override
{
{
@@ -3303,7 +3301,6 @@ public:
BoundVertexBuffer& boundBuffer = m_boundVertexBuffers[startSlot + i];
boundBuffer.m_buffer = buffer;
- boundBuffer.m_stride = int(strides[i]);
boundBuffer.m_offset = int(offsets[i]);
}
}
@@ -3339,6 +3336,7 @@ public:
// Set up vertex buffer views
{
+ auto inputLayout = (InputLayoutImpl*)pipelineState->inputLayout.Ptr();
int numVertexViews = 0;
D3D12_VERTEX_BUFFER_VIEW vertexViews[16];
for (Index i = 0; i < m_boundVertexBuffers.getCount(); i++)
@@ -3353,7 +3351,7 @@ public:
boundVertexBuffer.m_offset;
vertexView.SizeInBytes =
UINT(buffer->getDesc()->sizeInBytes - boundVertexBuffer.m_offset);
- vertexView.StrideInBytes = UINT(boundVertexBuffer.m_stride);
+ vertexView.StrideInBytes = inputLayout->m_vertexStreamStrides[i];
}
}
m_d3dCmdList->IASetVertexBuffers(0, numVertexViews, vertexViews);
@@ -3449,7 +3447,7 @@ public:
maxDrawCount,
argBufferImpl->m_resource,
argOffset,
- countBufferImpl->m_resource,
+ countBufferImpl ? countBufferImpl->m_resource.getResource() : nullptr,
countOffset);
}
@@ -3470,7 +3468,7 @@ public:
maxDrawCount,
argBufferImpl->m_resource,
argOffset,
- countBufferImpl->m_resource,
+ countBufferImpl ? countBufferImpl->m_resource.getResource() : nullptr,
countOffset);
}
@@ -4573,6 +4571,8 @@ public:
bool m_nvapi = false;
+ // Command signatures required for indirect draws. These indicate the format of the indirect
+ // as well as the command type to be used (DrawInstanced and DrawIndexedInstanced, in this case).
ComPtr<ID3D12CommandSignature> drawIndirectCmdSignature;
ComPtr<ID3D12CommandSignature> drawIndexedIndirectCmdSignature;
};
@@ -5383,6 +5383,8 @@ Result D3D12Device::initialize(const Desc& desc)
profileName,
makeArray(slang::PreprocessorMacroDesc{"__D3D12__", "1"}).getView()));
+ // Allocate a D3D12 "command signature" object that matches the behavior
+ // of a D3D11-style `DrawInstancedIndirect` operation.
{
D3D12_INDIRECT_ARGUMENT_DESC args[1];
args[0].Type = D3D12_INDIRECT_ARGUMENT_TYPE_DRAW;
@@ -5396,6 +5398,8 @@ Result D3D12Device::initialize(const Desc& desc)
SLANG_RETURN_ON_FAIL(m_device->CreateCommandSignature(&desc, nullptr, IID_PPV_ARGS(drawIndirectCmdSignature.writeRef())));
}
+ // Allocate a D3D12 "command signature" object that matches the behavior
+ // of a D3D11-style `DrawIndexedInstancedIndirect` operation.
{
D3D12_INDIRECT_ARGUMENT_DESC args[1];
args[0].Type = D3D12_INDIRECT_ARGUMENT_TYPE_DRAW_INDEXED;
@@ -6274,12 +6278,16 @@ Result D3D12Device::createRenderPassLayout(
return SLANG_OK;
}
-Result D3D12Device::createInputLayout(const InputElementDesc* inputElements, UInt inputElementCount, IInputLayout** outLayout)
+Result D3D12Device::createInputLayout(IInputLayout::Desc const& desc, IInputLayout** outLayout)
{
RefPtr<InputLayoutImpl> layout(new InputLayoutImpl);
// Work out a buffer size to hold all text
size_t textSize = 0;
+ auto inputElementCount = desc.inputElementCount;
+ auto inputElements = desc.inputElements;
+ auto vertexStreamCount = desc.vertexStreamCount;
+ auto vertexStreams = desc.vertexStreams;
for (int i = 0; i < Int(inputElementCount); ++i)
{
const char* text = inputElements[i].semanticName;
@@ -6288,7 +6296,6 @@ Result D3D12Device::createInputLayout(const InputElementDesc* inputElements, UIn
layout->m_text.setCount(textSize);
char* textPos = layout->m_text.getBuffer();
- //
List<D3D12_INPUT_ELEMENT_DESC>& elements = layout->m_elements;
elements.setCount(inputElementCount);
@@ -6296,6 +6303,7 @@ Result D3D12Device::createInputLayout(const InputElementDesc* inputElements, UIn
for (UInt i = 0; i < inputElementCount; ++i)
{
const InputElementDesc& srcEle = inputElements[i];
+ const auto& srcStream = vertexStreams[srcEle.bufferSlotIndex];
D3D12_INPUT_ELEMENT_DESC& dstEle = elements[i];
// Add text to the buffer
@@ -6313,8 +6321,15 @@ Result D3D12Device::createInputLayout(const InputElementDesc* inputElements, UIn
dstEle.Format = D3DUtil::getMapFormat(srcEle.format);
dstEle.InputSlot = (UINT)srcEle.bufferSlotIndex;
dstEle.AlignedByteOffset = (UINT)srcEle.offset;
- dstEle.InputSlotClass = D3DUtil::getInputSlotClass(srcEle.slotClass);
- dstEle.InstanceDataStepRate = (UINT)srcEle.instanceDataStepRate;
+ dstEle.InputSlotClass = D3DUtil::getInputSlotClass(srcStream.slotClass);
+ dstEle.InstanceDataStepRate = (UINT)srcStream.instanceDataStepRate;
+ }
+
+ auto& vertexStreamStrides = layout->m_vertexStreamStrides;
+ vertexStreamStrides.setCount(vertexStreamCount);
+ for (UInt i = 0; i < vertexStreamCount; ++i)
+ {
+ vertexStreamStrides[i] = vertexStreams[i].stride;
}
returnComPtr(outLayout, layout);