Skip to content

Commit

Permalink
reduce to PrimitiveTopology (#52)
Browse files Browse the repository at this point in the history
* reduce to PrimitiveTopology

* fix d3d

* fix again

* try again
  • Loading branch information
skallweitNV authored Sep 25, 2024
1 parent f9f47a5 commit 439b0ae
Show file tree
Hide file tree
Showing 34 changed files with 83 additions and 173 deletions.
19 changes: 5 additions & 14 deletions include/slang-rhi.h
Original file line number Diff line number Diff line change
Expand Up @@ -312,21 +312,14 @@ enum class InputSlotClass
PerInstance
};

enum class PrimitiveType
{
Point,
Line,
Triangle,
Patch
};

enum class PrimitiveTopology
{
TriangleList,
TriangleStrip,
PointList,
LineList,
LineStrip
LineStrip,
TriangleList,
TriangleStrip,
PatchList,
};

enum class ResourceState
Expand Down Expand Up @@ -1242,7 +1235,7 @@ struct RenderPipelineDesc
IShaderProgram* program = nullptr;

IInputLayout* inputLayout = nullptr;
PrimitiveType primitiveType = PrimitiveType::Triangle;
PrimitiveTopology primitiveTopology = PrimitiveTopology::TriangleList;
ColorTargetState* targets = nullptr;
GfxCount targetCount = 0;
DepthStencilState depthStencil;
Expand Down Expand Up @@ -1652,8 +1645,6 @@ class IRenderCommandEncoder : public ICommandEncoder
setScissorRects(1, &rect);
}

virtual SLANG_NO_THROW void SLANG_MCALL setPrimitiveTopology(PrimitiveTopology topology) = 0;

virtual SLANG_NO_THROW void SLANG_MCALL
setVertexBuffers(GfxIndex startSlot, GfxCount slotCount, IBuffer* const* buffers, const Offset* offsets) = 0;

Expand Down
6 changes: 0 additions & 6 deletions src/command-writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ enum class CommandName
EndRenderPass,
SetViewports,
SetScissorRects,
SetPrimitiveTopology,
SetVertexBuffers,
SetIndexBuffer,
Draw,
Expand Down Expand Up @@ -211,11 +210,6 @@ class CommandWriter
m_commands.push_back(Command(CommandName::SetScissorRects, (uint32_t)count, (uint32_t)offset));
}

void setPrimitiveTopology(PrimitiveTopology topology)
{
m_commands.push_back(Command(CommandName::SetPrimitiveTopology, (uint32_t)topology));
}

void setVertexBuffers(GfxIndex startSlot, GfxCount slotCount, IBuffer* const* buffers, const Offset* offsets)
{
Offset bufferOffset = 0;
Expand Down
40 changes: 12 additions & 28 deletions src/d3d/d3d-util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,51 +24,35 @@ D3D_PRIMITIVE_TOPOLOGY D3DUtil::getPrimitiveTopology(PrimitiveTopology topology)
{
switch (topology)
{
case PrimitiveTopology::TriangleList:
return D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
case PrimitiveTopology::TriangleStrip:
return D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP;
case PrimitiveTopology::PointList:
return D3D_PRIMITIVE_TOPOLOGY_POINTLIST;
case PrimitiveTopology::LineList:
return D3D_PRIMITIVE_TOPOLOGY_LINELIST;
case PrimitiveTopology::LineStrip:
return D3D_PRIMITIVE_TOPOLOGY_LINESTRIP;
case PrimitiveTopology::PointList:
return D3D_PRIMITIVE_TOPOLOGY_POINTLIST;
case PrimitiveTopology::TriangleList:
return D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
case PrimitiveTopology::TriangleStrip:
return D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP;
default:
break;
}
return D3D_PRIMITIVE_TOPOLOGY_UNDEFINED;
}

D3D12_PRIMITIVE_TOPOLOGY_TYPE D3DUtil::getPrimitiveType(PrimitiveTopology topology)
D3D12_PRIMITIVE_TOPOLOGY_TYPE D3DUtil::getPrimitiveTopologyType(PrimitiveTopology topology)
{
switch (topology)
{
case PrimitiveTopology::TriangleList:
case PrimitiveTopology::TriangleStrip:
return D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE;
case PrimitiveTopology::LineList:
case PrimitiveTopology::LineStrip:
return D3D12_PRIMITIVE_TOPOLOGY_TYPE_LINE;
case PrimitiveTopology::PointList:
return D3D12_PRIMITIVE_TOPOLOGY_TYPE_POINT;
default:
break;
}
return D3D12_PRIMITIVE_TOPOLOGY_TYPE_UNDEFINED;
}

D3D12_PRIMITIVE_TOPOLOGY_TYPE D3DUtil::getPrimitiveType(PrimitiveType type)
{
switch (type)
{
case PrimitiveType::Point:
return D3D12_PRIMITIVE_TOPOLOGY_TYPE_POINT;
case PrimitiveType::Line:
case PrimitiveTopology::LineList:
case PrimitiveTopology::LineStrip:
return D3D12_PRIMITIVE_TOPOLOGY_TYPE_LINE;
case PrimitiveType::Triangle:
case PrimitiveTopology::TriangleList:
case PrimitiveTopology::TriangleStrip:
return D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE;
case PrimitiveType::Patch:
case PrimitiveTopology::PatchList:
return D3D12_PRIMITIVE_TOPOLOGY_TYPE_PATCH;
default:
break;
Expand Down
4 changes: 1 addition & 3 deletions src/d3d/d3d-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ class D3DUtil
/// Get primitive topology as D3D primitive topology
static D3D_PRIMITIVE_TOPOLOGY getPrimitiveTopology(PrimitiveTopology prim);

static D3D12_PRIMITIVE_TOPOLOGY_TYPE getPrimitiveType(PrimitiveType type);

static D3D12_PRIMITIVE_TOPOLOGY_TYPE getPrimitiveType(PrimitiveTopology topology);
static D3D12_PRIMITIVE_TOPOLOGY_TYPE getPrimitiveTopologyType(PrimitiveTopology topology);

static D3D12_COMPARISON_FUNC getComparisonFunc(ComparisonFunc func);

Expand Down
9 changes: 4 additions & 5 deletions src/d3d11/d3d11-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -949,11 +949,6 @@ void D3D11Device::setInputLayout(InputLayout* inputLayoutIn)
}
#endif

void DeviceImpl::setPrimitiveTopology(PrimitiveTopology topology)
{
m_immediateContext->IASetPrimitiveTopology(D3DUtil::getPrimitiveTopology(topology));
}

void DeviceImpl::setVertexBuffers(
GfxIndex startSlot,
GfxCount slotCount,
Expand Down Expand Up @@ -1056,6 +1051,10 @@ void DeviceImpl::setPipeline(IPipeline* state)

m_immediateContext->IASetInputLayout(stateImpl->m_inputLayout->m_layout);

m_immediateContext->IASetPrimitiveTopology(
D3DUtil::getPrimitiveTopology(stateImpl->desc.graphics.primitiveTopology)
);

// VS

// TODO(tfoley): Why the conditional here? If somebody is trying to disable the VS or PS, shouldn't we respect
Expand Down
2 changes: 0 additions & 2 deletions src/d3d11/d3d11-device.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ class DeviceImpl : public ImmediateDevice
readTexture(ITexture* texture, ResourceState state, ISlangBlob** outBlob, size_t* outRowPitch, size_t* outPixelSize)
override;

virtual void setPrimitiveTopology(PrimitiveTopology topology) override;

virtual void setVertexBuffers(
GfxIndex startSlot,
GfxCount slotCount,
Expand Down
10 changes: 1 addition & 9 deletions src/d3d12/d3d12-command-encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -811,8 +811,6 @@ void RenderCommandEncoderImpl::init(
m_transientHeap = transientHeap;
m_boundVertexBuffers.clear();
m_boundIndexBuffer = nullptr;
m_primitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE;
m_primitiveTopology = D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
m_boundIndexFormat = DXGI_FORMAT_UNKNOWN;
m_boundIndexOffset = 0;
m_currentPipeline = nullptr;
Expand Down Expand Up @@ -964,12 +962,6 @@ void RenderCommandEncoderImpl::setScissorRects(GfxCount count, const ScissorRect
m_d3dCmdList->RSSetScissorRects(UINT(count), m_scissorRects);
}

void RenderCommandEncoderImpl::setPrimitiveTopology(PrimitiveTopology topology)
{
m_primitiveTopologyType = D3DUtil::getPrimitiveType(topology);
m_primitiveTopology = D3DUtil::getPrimitiveTopology(topology);
}

void RenderCommandEncoderImpl::setVertexBuffers(
GfxIndex startSlot,
GfxCount slotCount,
Expand Down Expand Up @@ -1017,7 +1009,7 @@ Result RenderCommandEncoderImpl::prepareDraw()
SLANG_RETURN_ON_FAIL(_bindRenderState(&submitter, newPipeline));
}

m_d3dCmdList->IASetPrimitiveTopology(m_primitiveTopology);
m_d3dCmdList->IASetPrimitiveTopology(D3DUtil::getPrimitiveTopology(pipeline->desc.graphics.primitiveTopology));

// Set up vertex buffer views
{
Expand Down
5 changes: 0 additions & 5 deletions src/d3d12/d3d12-command-encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,6 @@ class RenderCommandEncoderImpl : public IRenderCommandEncoder, public CommandEnc
DXGI_FORMAT m_boundIndexFormat;
UINT m_boundIndexOffset;

D3D12_PRIMITIVE_TOPOLOGY_TYPE m_primitiveTopologyType;
D3D12_PRIMITIVE_TOPOLOGY m_primitiveTopology;

void init(
DeviceImpl* device,
TransientResourceHeapImpl* transientHeap,
Expand All @@ -207,8 +204,6 @@ class RenderCommandEncoderImpl : public IRenderCommandEncoder, public CommandEnc

virtual SLANG_NO_THROW void SLANG_MCALL setScissorRects(GfxCount count, const ScissorRect* rects) override;

virtual SLANG_NO_THROW void SLANG_MCALL setPrimitiveTopology(PrimitiveTopology topology) override;

virtual SLANG_NO_THROW void SLANG_MCALL
setVertexBuffers(GfxIndex startSlot, GfxCount slotCount, IBuffer* const* buffers, const Offset* offsets) override;

Expand Down
4 changes: 2 additions & 2 deletions src/d3d12/d3d12-pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Result PipelineImpl::ensureAPIPipelineCreated()
{
psoDesc.pRootSignature = programImpl->m_rootObjectLayout->m_rootSignature;

psoDesc.PrimitiveTopologyType = D3DUtil::getPrimitiveType(desc.graphics.primitiveType);
psoDesc.PrimitiveTopologyType = D3DUtil::getPrimitiveTopologyType(desc.graphics.primitiveTopology);

const int numRenderTargets = desc.graphics.targetCount;

Expand Down Expand Up @@ -159,7 +159,7 @@ Result PipelineImpl::ensureAPIPipelineCreated()
ds.BackFace = D3DUtil::translateStencilOpDesc(desc.graphics.depthStencil.backFace);
}

psoDesc.PrimitiveTopologyType = D3DUtil::getPrimitiveType(desc.graphics.primitiveType);
psoDesc.PrimitiveTopologyType = D3DUtil::getPrimitiveTopologyType(desc.graphics.primitiveTopology);
};

if (m_program->isMeshShaderProgram())
Expand Down
6 changes: 0 additions & 6 deletions src/debug-layer/debug-command-encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,6 @@ void DebugRenderCommandEncoder::setScissorRects(GfxCount count, const ScissorRec
baseObject->setScissorRects(count, scissors);
}

void DebugRenderCommandEncoder::setPrimitiveTopology(PrimitiveTopology topology)
{
SLANG_RHI_API_FUNC;
baseObject->setPrimitiveTopology(topology);
}

void DebugRenderCommandEncoder::setVertexBuffers(
GfxIndex startSlot,
GfxCount slotCount,
Expand Down
1 change: 0 additions & 1 deletion src/debug-layer/debug-command-encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ class DebugRenderCommandEncoder : public UnownedDebugObject<IRenderCommandEncode
bindPipelineWithRootObject(IPipeline* state, IShaderObject* rootObject) override;
virtual SLANG_NO_THROW void SLANG_MCALL setViewports(GfxCount count, const Viewport* viewports) override;
virtual SLANG_NO_THROW void SLANG_MCALL setScissorRects(GfxCount count, const ScissorRect* scissors) override;
virtual SLANG_NO_THROW void SLANG_MCALL setPrimitiveTopology(PrimitiveTopology topology) override;
virtual SLANG_NO_THROW void SLANG_MCALL
setVertexBuffers(GfxIndex startSlot, GfxCount slotCount, IBuffer* const* buffers, const Offset* offsets) override;
virtual SLANG_NO_THROW void SLANG_MCALL
Expand Down
22 changes: 13 additions & 9 deletions src/enum-strings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,18 +325,22 @@ const char* enumToString(InputSlotClass value)
return kInvalid;
}

const char* enumToString(PrimitiveType value)
const char* enumToString(PrimitiveTopology value)
{
switch (value)
{
case PrimitiveType::Point:
return "Point";
case PrimitiveType::Line:
return "Line";
case PrimitiveType::Triangle:
return "Triangle";
case PrimitiveType::Patch:
return "Patch";
case PrimitiveTopology::PointList:
return "PointList";
case PrimitiveTopology::LineList:
return "LineList";
case PrimitiveTopology::LineStrip:
return "LineStrip";
case PrimitiveTopology::TriangleList:
return "TriangleList";
case PrimitiveTopology::TriangleStrip:
return "TriangleStrip";
case PrimitiveTopology::PatchList:
return "PatchList";
}
return kInvalid;
}
Expand Down
2 changes: 1 addition & 1 deletion src/enum-strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ const char* enumToString(TextureAddressingMode value);
const char* enumToString(ComparisonFunc value);
const char* enumToString(TextureReductionOp value);
const char* enumToString(InputSlotClass value);
const char* enumToString(PrimitiveType value);
const char* enumToString(PrimitiveTopology value);

} // namespace rhi
7 changes: 0 additions & 7 deletions src/immediate-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,6 @@ class CommandBufferImpl : public ICommandBuffer, public ComObject
{
m_writer->setScissorRects(count, scissors);
}
virtual SLANG_NO_THROW void SLANG_MCALL setPrimitiveTopology(PrimitiveTopology topology) override
{
m_writer->setPrimitiveTopology(topology);
}
virtual SLANG_NO_THROW void SLANG_MCALL
setVertexBuffers(GfxIndex startSlot, GfxCount slotCount, IBuffer* const* buffers, const Offset* offsets)
override
Expand Down Expand Up @@ -570,9 +566,6 @@ class CommandBufferImpl : public ICommandBuffer, public ComObject
case CommandName::SetScissorRects:
m_device->setScissorRects((UInt)cmd.operands[0], m_writer.getData<ScissorRect>(cmd.operands[1]));
break;
case CommandName::SetPrimitiveTopology:
m_device->setPrimitiveTopology((PrimitiveTopology)cmd.operands[0]);
break;
case CommandName::SetVertexBuffers:
{
short_vector<IBuffer*> buffers;
Expand Down
2 changes: 0 additions & 2 deletions src/immediate-device.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ class ImmediateDevice : public Device
virtual void endRenderPass() = 0;
virtual void setViewports(GfxCount count, const Viewport* viewports) = 0;
virtual void setScissorRects(GfxCount count, const ScissorRect* scissors) = 0;
virtual void setPrimitiveTopology(PrimitiveTopology topology) = 0;
virtual void setVertexBuffers(
GfxIndex startSlot,
GfxCount slotCount,
Expand Down Expand Up @@ -120,7 +119,6 @@ class ImmediateComputeDeviceBase : public ImmediateDevice
SLANG_UNUSED(count);
SLANG_UNUSED(scissors);
}
virtual void setPrimitiveTopology(PrimitiveTopology topology) override { SLANG_UNUSED(topology); }
virtual void setVertexBuffers(
GfxIndex startSlot,
GfxCount slotCount,
Expand Down
7 changes: 2 additions & 5 deletions src/metal/metal-command-encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,8 @@ void RenderCommandEncoderImpl::endEncoding()

Result RenderCommandEncoderImpl::bindPipeline(IPipeline* pipeline, IShaderObject** outRootObject)
{
m_primitiveType =
MetalUtil::translatePrimitiveType(static_cast<PipelineImpl*>(pipeline)->desc.graphics.primitiveTopology);
return setPipelineImpl(pipeline, outRootObject);
}

Expand Down Expand Up @@ -365,11 +367,6 @@ void RenderCommandEncoderImpl::setScissorRects(GfxCount count, const ScissorRect
}
}

void RenderCommandEncoderImpl::setPrimitiveTopology(PrimitiveTopology topology)
{
m_primitiveType = MetalUtil::translatePrimitiveType(topology);
}

void RenderCommandEncoderImpl::setVertexBuffers(
GfxIndex startSlot,
GfxCount slotCount,
Expand Down
2 changes: 0 additions & 2 deletions src/metal/metal-command-encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,6 @@ class RenderCommandEncoderImpl : public IRenderCommandEncoder, public CommandEnc

virtual SLANG_NO_THROW void SLANG_MCALL setScissorRects(GfxCount count, const ScissorRect* rects) override;

virtual SLANG_NO_THROW void SLANG_MCALL setPrimitiveTopology(PrimitiveTopology topology) override;

virtual SLANG_NO_THROW void SLANG_MCALL
setVertexBuffers(GfxIndex startSlot, GfxCount slotCount, IBuffer* const* buffers, const Offset* offsets) override;

Expand Down
2 changes: 1 addition & 1 deletion src/metal/metal-pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Result PipelineImpl::createMetalRenderPipelineState()
NS::SharedPtr<MTL::VertexDescriptor> vertexDescriptor =
inputLayoutImpl->createVertexDescriptor(m_vertexBufferOffset);
pd->setVertexDescriptor(vertexDescriptor.get());
pd->setInputPrimitiveTopology(MetalUtil::translatePrimitiveTopologyClass(desc.graphics.primitiveType));
pd->setInputPrimitiveTopology(MetalUtil::translatePrimitiveTopologyClass(desc.graphics.primitiveTopology));

pd->setAlphaToCoverageEnabled(desc.graphics.multisample.alphaToCoverageEnable);
// pd->setAlphaToOneEnabled(); // Currently not supported by rhi
Expand Down
Loading

0 comments on commit 439b0ae

Please sign in to comment.