diff --git a/include/slang-rhi.h b/include/slang-rhi.h index 4d52a5bd..5a5aa7ed 100644 --- a/include/slang-rhi.h +++ b/include/slang-rhi.h @@ -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 @@ -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; @@ -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; diff --git a/src/command-writer.h b/src/command-writer.h index 9f13a5ec..0a0a537d 100644 --- a/src/command-writer.h +++ b/src/command-writer.h @@ -18,7 +18,6 @@ enum class CommandName EndRenderPass, SetViewports, SetScissorRects, - SetPrimitiveTopology, SetVertexBuffers, SetIndexBuffer, Draw, @@ -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; diff --git a/src/d3d/d3d-util.cpp b/src/d3d/d3d-util.cpp index b6739e45..46159c92 100644 --- a/src/d3d/d3d-util.cpp +++ b/src/d3d/d3d-util.cpp @@ -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; diff --git a/src/d3d/d3d-util.h b/src/d3d/d3d-util.h index db63ae87..28d74208 100644 --- a/src/d3d/d3d-util.h +++ b/src/d3d/d3d-util.h @@ -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); diff --git a/src/d3d11/d3d11-device.cpp b/src/d3d11/d3d11-device.cpp index 579419e3..fbf30382 100644 --- a/src/d3d11/d3d11-device.cpp +++ b/src/d3d11/d3d11-device.cpp @@ -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, @@ -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 diff --git a/src/d3d11/d3d11-device.h b/src/d3d11/d3d11-device.h index 44d7683c..59fb2613 100644 --- a/src/d3d11/d3d11-device.h +++ b/src/d3d11/d3d11-device.h @@ -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, diff --git a/src/d3d12/d3d12-command-encoder.cpp b/src/d3d12/d3d12-command-encoder.cpp index 75e731a1..2fe10827 100644 --- a/src/d3d12/d3d12-command-encoder.cpp +++ b/src/d3d12/d3d12-command-encoder.cpp @@ -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; @@ -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, @@ -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 { diff --git a/src/d3d12/d3d12-command-encoder.h b/src/d3d12/d3d12-command-encoder.h index 3282c326..2d08c6b2 100644 --- a/src/d3d12/d3d12-command-encoder.h +++ b/src/d3d12/d3d12-command-encoder.h @@ -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, @@ -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; diff --git a/src/d3d12/d3d12-pipeline.cpp b/src/d3d12/d3d12-pipeline.cpp index eaaf95aa..8d85b684 100644 --- a/src/d3d12/d3d12-pipeline.cpp +++ b/src/d3d12/d3d12-pipeline.cpp @@ -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; @@ -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()) diff --git a/src/debug-layer/debug-command-encoder.cpp b/src/debug-layer/debug-command-encoder.cpp index 84dfb767..967b9722 100644 --- a/src/debug-layer/debug-command-encoder.cpp +++ b/src/debug-layer/debug-command-encoder.cpp @@ -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, diff --git a/src/debug-layer/debug-command-encoder.h b/src/debug-layer/debug-command-encoder.h index 298a0abd..9928e78c 100644 --- a/src/debug-layer/debug-command-encoder.h +++ b/src/debug-layer/debug-command-encoder.h @@ -155,7 +155,6 @@ class DebugRenderCommandEncoder : public UnownedDebugObjectsetScissorRects(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 @@ -570,9 +566,6 @@ class CommandBufferImpl : public ICommandBuffer, public ComObject case CommandName::SetScissorRects: m_device->setScissorRects((UInt)cmd.operands[0], m_writer.getData(cmd.operands[1])); break; - case CommandName::SetPrimitiveTopology: - m_device->setPrimitiveTopology((PrimitiveTopology)cmd.operands[0]); - break; case CommandName::SetVertexBuffers: { short_vector buffers; diff --git a/src/immediate-device.h b/src/immediate-device.h index 70b1ff6b..b1212496 100644 --- a/src/immediate-device.h +++ b/src/immediate-device.h @@ -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, @@ -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, diff --git a/src/metal/metal-command-encoder.cpp b/src/metal/metal-command-encoder.cpp index 081181a4..10f0e41b 100644 --- a/src/metal/metal-command-encoder.cpp +++ b/src/metal/metal-command-encoder.cpp @@ -327,6 +327,8 @@ void RenderCommandEncoderImpl::endEncoding() Result RenderCommandEncoderImpl::bindPipeline(IPipeline* pipeline, IShaderObject** outRootObject) { + m_primitiveType = + MetalUtil::translatePrimitiveType(static_cast(pipeline)->desc.graphics.primitiveTopology); return setPipelineImpl(pipeline, outRootObject); } @@ -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, diff --git a/src/metal/metal-command-encoder.h b/src/metal/metal-command-encoder.h index 94cc4faf..8c10766c 100644 --- a/src/metal/metal-command-encoder.h +++ b/src/metal/metal-command-encoder.h @@ -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; diff --git a/src/metal/metal-pipeline.cpp b/src/metal/metal-pipeline.cpp index 37e18c3d..5e7b1cc6 100644 --- a/src/metal/metal-pipeline.cpp +++ b/src/metal/metal-pipeline.cpp @@ -74,7 +74,7 @@ Result PipelineImpl::createMetalRenderPipelineState() NS::SharedPtr 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 diff --git a/src/metal/metal-util.cpp b/src/metal/metal-util.cpp index 0457fc2a..3653256b 100644 --- a/src/metal/metal-util.cpp +++ b/src/metal/metal-util.cpp @@ -442,34 +442,37 @@ MTL::PrimitiveType MetalUtil::translatePrimitiveType(PrimitiveTopology topology) { switch (topology) { - case PrimitiveTopology::TriangleList: - return MTL::PrimitiveTypeTriangle; - case PrimitiveTopology::TriangleStrip: - return MTL::PrimitiveTypeTriangleStrip; case PrimitiveTopology::PointList: return MTL::PrimitiveTypePoint; case PrimitiveTopology::LineList: return MTL::PrimitiveTypeLine; case PrimitiveTopology::LineStrip: return MTL::PrimitiveTypeLineStrip; + case PrimitiveTopology::TriangleList: + return MTL::PrimitiveTypeTriangle; + case PrimitiveTopology::TriangleStrip: + return MTL::PrimitiveTypeTriangleStrip; + case PrimitiveTopology::PatchList: default: return MTL::PrimitiveType(0); } } -MTL::PrimitiveTopologyClass MetalUtil::translatePrimitiveTopologyClass(PrimitiveType type) +MTL::PrimitiveTopologyClass MetalUtil::translatePrimitiveTopologyClass(PrimitiveTopology topology) { - switch (type) + switch (topology) { - case PrimitiveType::Point: + case PrimitiveTopology::PointList: return MTL::PrimitiveTopologyClassPoint; - case PrimitiveType::Line: + case PrimitiveTopology::LineList: + case PrimitiveTopology::LineStrip: return MTL::PrimitiveTopologyClassLine; - case PrimitiveType::Triangle: + case PrimitiveTopology::TriangleList: + case PrimitiveTopology::TriangleStrip: return MTL::PrimitiveTopologyClassTriangle; - case PrimitiveType::Patch: + case PrimitiveTopology::PatchList: default: - return MTL::PrimitiveTopologyClassUnspecified; + return MTL::PrimitiveTopologyClass(0); } } diff --git a/src/metal/metal-util.h b/src/metal/metal-util.h index 2138c5f7..7b1e303f 100644 --- a/src/metal/metal-util.h +++ b/src/metal/metal-util.h @@ -41,7 +41,7 @@ struct MetalUtil static MTL::VertexStepFunction translateVertexStepFunction(InputSlotClass slotClass); static MTL::PrimitiveType translatePrimitiveType(PrimitiveTopology topology); - static MTL::PrimitiveTopologyClass translatePrimitiveTopologyClass(PrimitiveType type); + static MTL::PrimitiveTopologyClass translatePrimitiveTopologyClass(PrimitiveTopology topology); static MTL::BlendFactor translateBlendFactor(BlendFactor factor); static MTL::BlendOperation translateBlendOperation(BlendOp op); diff --git a/src/vulkan/vk-command-encoder.cpp b/src/vulkan/vk-command-encoder.cpp index 237b35d3..4127a0ff 100644 --- a/src/vulkan/vk-command-encoder.cpp +++ b/src/vulkan/vk-command-encoder.cpp @@ -1167,29 +1167,6 @@ void RenderCommandEncoderImpl::setScissorRects(GfxCount count, const ScissorRect api.vkCmdSetScissor(m_vkCommandBuffer, 0, uint32_t(m_scissorRects.size()), m_scissorRects.data()); } -void RenderCommandEncoderImpl::setPrimitiveTopology(PrimitiveTopology topology) -{ - auto& api = *m_api; - if (api.vkCmdSetPrimitiveTopologyEXT) - { - api.vkCmdSetPrimitiveTopologyEXT(m_vkCommandBuffer, VulkanUtil::getVkPrimitiveTopology(topology)); - } - else - { - switch (topology) - { - case PrimitiveTopology::TriangleList: - break; - default: - // We are using a non-list topology, but we don't have dynmaic state - // extension, error out. - SLANG_RHI_ASSERT_FAILURE("Non-list topology requires VK_EXT_extended_dynamic_states, which is not present." - ); - break; - } - } -} - void RenderCommandEncoderImpl::setVertexBuffers( GfxIndex startSlot, GfxCount slotCount, diff --git a/src/vulkan/vk-command-encoder.h b/src/vulkan/vk-command-encoder.h index 6ad38e3d..5a8fc841 100644 --- a/src/vulkan/vk-command-encoder.h +++ b/src/vulkan/vk-command-encoder.h @@ -200,8 +200,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; diff --git a/src/vulkan/vk-pipeline.cpp b/src/vulkan/vk-pipeline.cpp index 00f9fedb..216ee407 100644 --- a/src/vulkan/vk-pipeline.cpp +++ b/src/vulkan/vk-pipeline.cpp @@ -93,7 +93,7 @@ Result PipelineImpl::createVKGraphicsPipeline() VkPipelineInputAssemblyStateCreateInfo inputAssembly = {}; inputAssembly.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; // All other forms of primitive toplogies are specified via dynamic state. - inputAssembly.topology = VulkanUtil::translatePrimitiveTypeToListTopology(desc.graphics.primitiveType); + inputAssembly.topology = VulkanUtil::translatePrimitiveListTopology(desc.graphics.primitiveTopology); inputAssembly.primitiveRestartEnable = VK_FALSE; // TODO: Currently unsupported VkViewport viewport = {}; diff --git a/src/vulkan/vk-util.cpp b/src/vulkan/vk-util.cpp index 5d165345..71378b34 100644 --- a/src/vulkan/vk-util.cpp +++ b/src/vulkan/vk-util.cpp @@ -456,17 +456,21 @@ VkBlendOp VulkanUtil::translateBlendOp(BlendOp op) } } -VkPrimitiveTopology VulkanUtil::translatePrimitiveTypeToListTopology(PrimitiveType primitiveType) +VkPrimitiveTopology VulkanUtil::translatePrimitiveListTopology(PrimitiveTopology topology) { - switch (primitiveType) + switch (topology) { - case PrimitiveType::Point: + case PrimitiveTopology::PointList: return VK_PRIMITIVE_TOPOLOGY_POINT_LIST; - case PrimitiveType::Line: + case PrimitiveTopology::LineList: return VK_PRIMITIVE_TOPOLOGY_LINE_LIST; - case PrimitiveType::Triangle: + case PrimitiveTopology::LineStrip: + return VK_PRIMITIVE_TOPOLOGY_LINE_STRIP; + case PrimitiveTopology::TriangleList: return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; - case PrimitiveType::Patch: + case PrimitiveTopology::TriangleStrip: + return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP; + case PrimitiveTopology::PatchList: return VK_PRIMITIVE_TOPOLOGY_PATCH_LIST; default: SLANG_RHI_ASSERT_FAILURE("Unknown topology type."); diff --git a/src/vulkan/vk-util.h b/src/vulkan/vk-util.h index 962a20c2..b4718d9f 100644 --- a/src/vulkan/vk-util.h +++ b/src/vulkan/vk-util.h @@ -113,7 +113,7 @@ struct VulkanUtil static VkBlendOp translateBlendOp(BlendOp op); - static VkPrimitiveTopology translatePrimitiveTypeToListTopology(PrimitiveType primitiveType); + static VkPrimitiveTopology translatePrimitiveListTopology(PrimitiveTopology topology); static VkStencilOp translateStencilOp(StencilOp op); diff --git a/src/wgpu/wgpu-command-encoder.cpp b/src/wgpu/wgpu-command-encoder.cpp index aa26342e..b7e9dfd5 100644 --- a/src/wgpu/wgpu-command-encoder.cpp +++ b/src/wgpu/wgpu-command-encoder.cpp @@ -414,8 +414,6 @@ void RenderCommandEncoderImpl::setScissorRects(GfxCount count, const ScissorRect ); } -void RenderCommandEncoderImpl::setPrimitiveTopology(PrimitiveTopology topology) {} - void RenderCommandEncoderImpl::setVertexBuffers( GfxIndex startSlot, GfxCount slotCount, diff --git a/src/wgpu/wgpu-command-encoder.h b/src/wgpu/wgpu-command-encoder.h index 532101a9..e2bb985c 100644 --- a/src/wgpu/wgpu-command-encoder.h +++ b/src/wgpu/wgpu-command-encoder.h @@ -152,8 +152,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; diff --git a/src/wgpu/wgpu-pipeline.cpp b/src/wgpu/wgpu-pipeline.cpp index ca3d08a3..b5c6fc0f 100644 --- a/src/wgpu/wgpu-pipeline.cpp +++ b/src/wgpu/wgpu-pipeline.cpp @@ -63,7 +63,7 @@ Result PipelineImpl::createRenderPipeline() pipelineDesc.vertex.buffers = inputLayout->m_vertexBufferLayouts.data(); pipelineDesc.vertex.bufferCount = (uint32_t)inputLayout->m_vertexBufferLayouts.size(); - pipelineDesc.primitive.topology = translatePrimitiveTopology(desc.graphics.primitiveType); + pipelineDesc.primitive.topology = translatePrimitiveTopology(desc.graphics.primitiveTopology); // TODO support strip topologies pipelineDesc.primitive.stripIndexFormat = WGPUIndexFormat_Undefined; pipelineDesc.primitive.frontFace = translateFrontFace(desc.graphics.rasterizer.frontFace); diff --git a/src/wgpu/wgpu-util.cpp b/src/wgpu/wgpu-util.cpp index 03fe22df..121b080a 100644 --- a/src/wgpu/wgpu-util.cpp +++ b/src/wgpu/wgpu-util.cpp @@ -458,18 +458,22 @@ WGPUCompareFunction translateCompareFunction(ComparisonFunc func) } } -WGPUPrimitiveTopology translatePrimitiveTopology(PrimitiveType type) +WGPUPrimitiveTopology translatePrimitiveTopology(PrimitiveTopology topology) { - switch (type) + switch (topology) { - case PrimitiveType::Point: + case PrimitiveTopology::PointList: return WGPUPrimitiveTopology_PointList; - case PrimitiveType::Line: + case PrimitiveTopology::LineList: return WGPUPrimitiveTopology_LineList; - case PrimitiveType::Triangle: + case PrimitiveTopology::LineStrip: + return WGPUPrimitiveTopology_LineStrip; + case PrimitiveTopology::TriangleList: return WGPUPrimitiveTopology_TriangleList; - case PrimitiveType::Patch: - SLANG_RHI_ASSERT_FAILURE("Patch topology not supported."); + case PrimitiveTopology::TriangleStrip: + return WGPUPrimitiveTopology_TriangleStrip; + case PrimitiveTopology::PatchList: + SLANG_RHI_ASSERT_FAILURE("Patch tlist opology not supported."); default: return WGPUPrimitiveTopology_Undefined; } diff --git a/src/wgpu/wgpu-util.h b/src/wgpu/wgpu-util.h index 7f2c3c15..bdc7ee91 100644 --- a/src/wgpu/wgpu-util.h +++ b/src/wgpu/wgpu-util.h @@ -18,7 +18,7 @@ WGPUFilterMode translateFilterMode(TextureFilteringMode mode); WGPUMipmapFilterMode translateMipmapFilterMode(TextureFilteringMode mode); WGPUCompareFunction translateCompareFunction(ComparisonFunc func); -WGPUPrimitiveTopology translatePrimitiveTopology(PrimitiveType type); +WGPUPrimitiveTopology translatePrimitiveTopology(PrimitiveTopology topology); WGPUFrontFace translateFrontFace(FrontFaceMode mode); WGPUCullMode translateCullMode(CullMode mode); WGPUStencilOperation translateStencilOp(StencilOp op); diff --git a/tests/test-instanced-draw.cpp b/tests/test-instanced-draw.cpp index 41672da0..4cd6f35b 100644 --- a/tests/test-instanced-draw.cpp +++ b/tests/test-instanced-draw.cpp @@ -241,7 +241,6 @@ struct DrawInstancedTest : BaseDrawTest encoder->setVertexBuffer(0, vertexBuffer); encoder->setVertexBuffer(1, instanceBuffer); - encoder->setPrimitiveTopology(PrimitiveTopology::TriangleList); encoder->drawInstanced(kVertexCount, kInstanceCount, startVertex, startInstanceLocation); encoder->endEncoding(); @@ -302,7 +301,6 @@ struct DrawIndexedInstancedTest : BaseDrawTest encoder->setVertexBuffer(0, vertexBuffer); encoder->setVertexBuffer(1, instanceBuffer); encoder->setIndexBuffer(indexBuffer, IndexFormat::UInt32); - encoder->setPrimitiveTopology(PrimitiveTopology::TriangleList); encoder->drawIndexedInstanced(kIndexCount, kInstanceCount, startIndex, startVertex, startInstanceLocation); encoder->endEncoding(); @@ -382,7 +380,6 @@ struct DrawIndirectTest : BaseDrawTest encoder->setVertexBuffer(0, vertexBuffer); encoder->setVertexBuffer(1, instanceBuffer); - encoder->setPrimitiveTopology(PrimitiveTopology::TriangleList); uint32_t maxDrawCount = 1; Offset argOffset = offsetof(IndirectArgData, args); @@ -467,7 +464,6 @@ struct DrawIndexedIndirectTest : BaseDrawTest encoder->setVertexBuffer(0, vertexBuffer); encoder->setVertexBuffer(1, instanceBuffer); encoder->setIndexBuffer(indexBuffer, IndexFormat::UInt32); - encoder->setPrimitiveTopology(PrimitiveTopology::TriangleList); uint32_t maxDrawCount = 1; Offset argOffset = offsetof(IndexedIndirectArgData, args); @@ -514,6 +510,7 @@ TEST_CASE("draw-instanced") DeviceType::D3D12, DeviceType::Vulkan, DeviceType::Metal, + DeviceType::WGPU, } ); } diff --git a/tests/test-resolve-resource-tests.cpp b/tests/test-resolve-resource-tests.cpp index 1f5fe462..b1d95287 100644 --- a/tests/test-resolve-resource-tests.cpp +++ b/tests/test-resolve-resource-tests.cpp @@ -184,7 +184,6 @@ struct BaseResolveResourceTest renderEncoder->setViewportAndScissor(viewport); renderEncoder->setVertexBuffer(0, vertexBuffer); - renderEncoder->setPrimitiveTopology(PrimitiveTopology::TriangleList); renderEncoder->draw(kVertexCount, 0); renderEncoder->endEncoding(); diff --git a/tests/test-shader-cache.cpp b/tests/test-shader-cache.cpp index 888a04c0..9aab10ee 100644 --- a/tests/test-shader-cache.cpp +++ b/tests/test-shader-cache.cpp @@ -813,7 +813,6 @@ struct ShaderCacheTestGraphics : ShaderCacheTest encoder->setViewportAndScissor(viewport); encoder->setVertexBuffer(0, vertexBuffer); - encoder->setPrimitiveTopology(PrimitiveTopology::TriangleList); encoder->draw(3); encoder->endEncoding(); diff --git a/tests/test-texture-types.cpp b/tests/test-texture-types.cpp index f75ce2a2..9434b18c 100644 --- a/tests/test-texture-types.cpp +++ b/tests/test-texture-types.cpp @@ -409,7 +409,6 @@ struct RenderTargetTests : TextureTest renderEncoder->setViewportAndScissor(viewport); renderEncoder->setVertexBuffer(0, vertexBuffer); - renderEncoder->setPrimitiveTopology(PrimitiveTopology::TriangleList); renderEncoder->draw(kVertexCount, 0); renderEncoder->endEncoding();