diff options
| author | lucy96chen <47800040+lucy96chen@users.noreply.github.com> | 2022-01-10 11:00:50 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-01-10 11:00:50 -0800 |
| commit | aee4aa3528072e4b5e95ccc4e571868716b47d50 (patch) | |
| tree | 3621d7e5cd67e09581d7fe001e359df12167889b /tools/gfx/open-gl/render-gl.cpp | |
| parent | 8919c19440dea9a62578905d365fe80bcd58e316 (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/open-gl/render-gl.cpp')
| -rw-r--r-- | tools/gfx/open-gl/render-gl.cpp | 61 |
1 files changed, 50 insertions, 11 deletions
diff --git a/tools/gfx/open-gl/render-gl.cpp b/tools/gfx/open-gl/render-gl.cpp index e7573e232..da62e7702 100644 --- a/tools/gfx/open-gl/render-gl.cpp +++ b/tools/gfx/open-gl/render-gl.cpp @@ -133,8 +133,7 @@ public: IBufferResource* buffer, IResourceView::Desc const& desc, IResourceView** outView) override; virtual SLANG_NO_THROW Result SLANG_MCALL createInputLayout( - const InputElementDesc* inputElements, - UInt inputElementCount, + IInputLayout::Desc const& desc, IInputLayout** outLayout) override; virtual Result createShaderObjectLayout( @@ -169,7 +168,6 @@ public: uint32_t startSlot, uint32_t slotCount, IBufferResource* const* buffers, - const uint32_t* strides, const uint32_t* offsets) override; virtual void setIndexBuffer( IBufferResource* buffer, Format indexFormat, uint32_t offset) override; @@ -179,6 +177,17 @@ public: virtual void draw(uint32_t vertexCount, uint32_t startVertex) override; virtual void drawIndexed( uint32_t indexCount, uint32_t startIndex, uint32_t baseVertex) override; + virtual void drawInstanced( + uint32_t vertexCount, + uint32_t instanceCount, + uint32_t startVertex, + uint32_t startInstanceLocation) override; + virtual void drawIndexedInstanced( + uint32_t indexCount, + uint32_t instanceCount, + uint32_t startIndexLocation, + int32_t baseVertexLocation, + uint32_t startInstanceLocation) override; virtual void dispatchCompute(int x, int y, int z) override; virtual void submitGpuWork() override {} virtual void waitForGpu() override {} @@ -206,6 +215,7 @@ public: protected: enum { + kMaxVertexAttributes = 16, kMaxVertexStreams = 16, kMaxDescriptorSetCount = 8, }; @@ -226,8 +236,10 @@ public: class InputLayoutImpl : public InputLayoutBase { public: - VertexAttributeDesc m_attributes[kMaxVertexStreams]; + VertexAttributeDesc m_attributes[kMaxVertexAttributes]; + VertexStreamDesc m_streams[kMaxVertexStreams]; UInt m_attributeCount = 0; + UInt m_streamCount = 0; }; class BufferResourceImpl: public BufferResource @@ -1590,7 +1602,6 @@ public: GLenum m_boundPrimitiveTopology = GL_TRIANGLES; GLuint m_boundVertexStreamBuffers[kMaxVertexStreams]; - UInt m_boundVertexStreamStrides[kMaxVertexStreams]; UInt m_boundVertexStreamOffsets[kMaxVertexStreams]; GLuint m_boundIndexBuffer = 0; UInt m_boundIndexBufferOffset = 0; @@ -1702,6 +1713,8 @@ void GLDevice::flushStateForDraw() auto streamIndex = attr.streamIndex; + auto stride = inputLayout->m_streams[streamIndex].stride; + glBindBuffer(GL_ARRAY_BUFFER, m_boundVertexStreamBuffers[streamIndex]); glVertexAttribPointer( @@ -1709,7 +1722,7 @@ void GLDevice::flushStateForDraw() attr.format.componentCount, attr.format.componentType, attr.format.normalized, - (GLsizei)m_boundVertexStreamStrides[streamIndex], + (GLsizei)stride, (GLvoid*)(attr.offset + m_boundVertexStreamOffsets[streamIndex])); glEnableVertexAttribArray((GLuint)ii); @@ -2534,21 +2547,30 @@ SLANG_NO_THROW Result SLANG_MCALL GLDevice::createBufferView( } SLANG_NO_THROW Result SLANG_MCALL GLDevice::createInputLayout( - const InputElementDesc* inputElements, UInt inputElementCount, IInputLayout** outLayout) + IInputLayout::Desc const& desc, IInputLayout** outLayout) { RefPtr<InputLayoutImpl> inputLayout = new InputLayoutImpl; + auto inputElements = desc.inputElements; + Int inputElementCount = desc.inputElementCount; inputLayout->m_attributeCount = inputElementCount; - for (UInt ii = 0; ii < inputElementCount; ++ii) + for (Int ii = 0; ii < inputElementCount; ++ii) { auto& inputAttr = inputElements[ii]; auto& glAttr = inputLayout->m_attributes[ii]; - glAttr.streamIndex = 0; + glAttr.streamIndex = (GLuint)inputAttr.bufferSlotIndex; glAttr.format = getVertexAttributeFormat(inputAttr.format); glAttr.offset = (GLsizei)inputAttr.offset; } + Int inputStreamCount = desc.vertexStreamCount; + inputLayout->m_streamCount = inputStreamCount; + for (Int i = 0; i < inputStreamCount; ++i) + { + inputLayout->m_streams[i].stride = desc.vertexStreams[i].stride; + } + returnComPtr(outLayout, inputLayout); return SLANG_OK; } @@ -2602,7 +2624,6 @@ void GLDevice::setVertexBuffers( uint32_t startSlot, uint32_t slotCount, IBufferResource* const* buffers, - const uint32_t* strides, const uint32_t* offsets) { for (UInt ii = 0; ii < slotCount; ++ii) @@ -2613,7 +2634,6 @@ void GLDevice::setVertexBuffers( GLuint bufferID = buffer ? buffer->m_handle : 0; m_boundVertexStreamBuffers[slot] = bufferID; - m_boundVertexStreamStrides[slot] = strides[ii]; m_boundVertexStreamOffsets[slot] = offsets[ii]; } } @@ -2696,6 +2716,25 @@ void GLDevice::drawIndexed(uint32_t indexCount, uint32_t startIndex, uint32_t ba (GLint)baseVertex); } +void GLDevice::drawInstanced( + uint32_t vertexCount, + uint32_t instanceCount, + uint32_t startVertex, + uint32_t startInstanceLocation) +{ + SLANG_UNIMPLEMENTED_X("drawInstanced"); +} + +void GLDevice::drawIndexedInstanced( + uint32_t indexCount, + uint32_t instanceCount, + uint32_t startIndexLocation, + int32_t baseVertexLocation, + uint32_t startInstanceLocation) +{ + SLANG_UNIMPLEMENTED_X("drawIndexedInstanced"); +} + void GLDevice::dispatchCompute(int x, int y, int z) { glDispatchCompute(x, y, z); |
