summaryrefslogtreecommitdiff
path: root/tools/gfx/d3d12/render-d3d12.cpp
diff options
context:
space:
mode:
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);