Commit 93577b20 by Jamie Madill Committed by Commit Bot

Vulkan: Move "null" buffer to RendererVk.

This will allow the TransformFeedback and other classes to share the same buffer. Also should save a bit of memory. Bug: chromium:1086532 Change-Id: I198170b4e09165a4770b68af6df9aa7b690e8d66 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2219138 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarTim Van Patten <timvp@google.com> Reviewed-by: 's avatarCourtney Goeltzenleuchter <courtneygo@google.com>
parent 5e13757b
...@@ -504,6 +504,7 @@ void RendererVk::onDestroy() ...@@ -504,6 +504,7 @@ void RendererVk::onDestroy()
mPipelineCache.destroy(mDevice); mPipelineCache.destroy(mDevice);
mSamplerCache.destroy(this); mSamplerCache.destroy(this);
mTheNullBuffer.destroy(this);
mAllocator.destroy(); mAllocator.destroy();
...@@ -830,6 +831,16 @@ angle::Result RendererVk::initialize(DisplayVk *displayVk, ...@@ -830,6 +831,16 @@ angle::Result RendererVk::initialize(DisplayVk *displayVk,
// Store the physical device memory properties so we can find the right memory pools. // Store the physical device memory properties so we can find the right memory pools.
mMemoryProperties.init(mPhysicalDevice); mMemoryProperties.init(mPhysicalDevice);
// Must be initialized after the allocator and memory properties.
{
VkBufferCreateInfo bufferCreateInfo = {};
bufferCreateInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
bufferCreateInfo.size = 16;
bufferCreateInfo.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT;
ANGLE_TRY(
mTheNullBuffer.init(displayVk, bufferCreateInfo, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT));
}
if (!mGlslangInitialized) if (!mGlslangInitialized)
{ {
GlslangInitialize(); GlslangInitialize();
......
...@@ -256,6 +256,8 @@ class RendererVk : angle::NonCopyable ...@@ -256,6 +256,8 @@ class RendererVk : angle::NonCopyable
} }
void waitForWorkerThreadIdle() { mCommandProcessor.waitForWorkComplete(); } void waitForWorkerThreadIdle() { mCommandProcessor.waitForWorkComplete(); }
vk::BufferHelper &getNullBuffer() { return mTheNullBuffer; }
private: private:
angle::Result initializeDevice(DisplayVk *displayVk, uint32_t queueFamilyIndex); angle::Result initializeDevice(DisplayVk *displayVk, uint32_t queueFamilyIndex);
void ensureCapsInitialized() const; void ensureCapsInitialized() const;
...@@ -379,6 +381,9 @@ class RendererVk : angle::NonCopyable ...@@ -379,6 +381,9 @@ class RendererVk : angle::NonCopyable
vk::Allocator mAllocator; vk::Allocator mAllocator;
SamplerCache mSamplerCache; SamplerCache mSamplerCache;
vk::ActiveHandleCounter mActiveHandleCounts; vk::ActiveHandleCounter mActiveHandleCounts;
// Vulkan does not allow binding a null vertex buffer. We use a dummy as a placeholder.
vk::BufferHelper mTheNullBuffer;
}; };
} // namespace rx } // namespace rx
......
...@@ -123,16 +123,12 @@ VertexArrayVk::VertexArrayVk(ContextVk *contextVk, const gl::VertexArrayState &s ...@@ -123,16 +123,12 @@ VertexArrayVk::VertexArrayVk(ContextVk *contextVk, const gl::VertexArrayState &s
{ {
RendererVk *renderer = contextVk->getRenderer(); RendererVk *renderer = contextVk->getRenderer();
VkBufferCreateInfo createInfo = {}; vk::BufferHelper &nullBuffer = renderer->getNullBuffer();
createInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
createInfo.size = 16;
createInfo.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT;
(void)mTheNullBuffer.init(contextVk, createInfo, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
mCurrentArrayBufferHandles.fill(mTheNullBuffer.getBuffer().getHandle()); mCurrentArrayBufferHandles.fill(nullBuffer.getBuffer().getHandle());
mCurrentArrayBufferOffsets.fill(0); mCurrentArrayBufferOffsets.fill(0);
mCurrentArrayBufferRelativeOffsets.fill(0); mCurrentArrayBufferRelativeOffsets.fill(0);
mCurrentArrayBuffers.fill(&mTheNullBuffer); mCurrentArrayBuffers.fill(&nullBuffer);
mDynamicVertexData.init(renderer, vk::kVertexBufferUsageFlags, vk::kVertexBufferAlignment, mDynamicVertexData.init(renderer, vk::kVertexBufferUsageFlags, vk::kVertexBufferAlignment,
kDynamicVertexDataSize, true); kDynamicVertexDataSize, true);
...@@ -155,8 +151,6 @@ void VertexArrayVk::destroy(const gl::Context *context) ...@@ -155,8 +151,6 @@ void VertexArrayVk::destroy(const gl::Context *context)
RendererVk *renderer = contextVk->getRenderer(); RendererVk *renderer = contextVk->getRenderer();
mTheNullBuffer.release(renderer);
mDynamicVertexData.release(renderer); mDynamicVertexData.release(renderer);
mDynamicIndexData.release(renderer); mDynamicIndexData.release(renderer);
mTranslatedByteIndexData.release(renderer); mTranslatedByteIndexData.release(renderer);
...@@ -557,9 +551,9 @@ angle::Result VertexArrayVk::syncDirtyAttrib(ContextVk *contextVk, ...@@ -557,9 +551,9 @@ angle::Result VertexArrayVk::syncDirtyAttrib(ContextVk *contextVk,
size_t attribIndex, size_t attribIndex,
bool bufferOnly) bool bufferOnly)
{ {
RendererVk *renderer = contextVk->getRenderer();
if (attrib.enabled) if (attrib.enabled)
{ {
RendererVk *renderer = contextVk->getRenderer();
const vk::Format &vertexFormat = renderer->getFormat(attrib.format->id); const vk::Format &vertexFormat = renderer->getFormat(attrib.format->id);
GLuint stride; GLuint stride;
...@@ -621,9 +615,10 @@ angle::Result VertexArrayVk::syncDirtyAttrib(ContextVk *contextVk, ...@@ -621,9 +615,10 @@ angle::Result VertexArrayVk::syncDirtyAttrib(ContextVk *contextVk,
{ {
if (bufferVk->getSize() == 0) if (bufferVk->getSize() == 0)
{ {
mCurrentArrayBuffers[attribIndex] = &mTheNullBuffer; vk::BufferHelper &nullBuffer = renderer->getNullBuffer();
mCurrentArrayBufferHandles[attribIndex] =
mTheNullBuffer.getBuffer().getHandle(); mCurrentArrayBuffers[attribIndex] = &nullBuffer;
mCurrentArrayBufferHandles[attribIndex] = nullBuffer.getBuffer().getHandle();
mCurrentArrayBufferOffsets[attribIndex] = 0; mCurrentArrayBufferOffsets[attribIndex] = 0;
stride = 0; stride = 0;
} }
...@@ -644,8 +639,9 @@ angle::Result VertexArrayVk::syncDirtyAttrib(ContextVk *contextVk, ...@@ -644,8 +639,9 @@ angle::Result VertexArrayVk::syncDirtyAttrib(ContextVk *contextVk,
} }
else else
{ {
mCurrentArrayBuffers[attribIndex] = &mTheNullBuffer; vk::BufferHelper &nullBuffer = renderer->getNullBuffer();
mCurrentArrayBufferHandles[attribIndex] = mTheNullBuffer.getBuffer().getHandle(); mCurrentArrayBuffers[attribIndex] = &nullBuffer;
mCurrentArrayBufferHandles[attribIndex] = nullBuffer.getBuffer().getHandle();
mCurrentArrayBufferOffsets[attribIndex] = 0; mCurrentArrayBufferOffsets[attribIndex] = 0;
// Client side buffer will be transfered to a tightly packed buffer later // Client side buffer will be transfered to a tightly packed buffer later
stride = vertexFormat.actualBufferFormat().pixelBytes; stride = vertexFormat.actualBufferFormat().pixelBytes;
...@@ -675,8 +671,9 @@ angle::Result VertexArrayVk::syncDirtyAttrib(ContextVk *contextVk, ...@@ -675,8 +671,9 @@ angle::Result VertexArrayVk::syncDirtyAttrib(ContextVk *contextVk,
contextVk->invalidateDefaultAttribute(attribIndex); contextVk->invalidateDefaultAttribute(attribIndex);
// These will be filled out by the ContextVk. // These will be filled out by the ContextVk.
mCurrentArrayBuffers[attribIndex] = &mTheNullBuffer; vk::BufferHelper &nullBuffer = renderer->getNullBuffer();
mCurrentArrayBufferHandles[attribIndex] = mTheNullBuffer.getBuffer().getHandle(); mCurrentArrayBuffers[attribIndex] = &nullBuffer;
mCurrentArrayBufferHandles[attribIndex] = nullBuffer.getBuffer().getHandle();
mCurrentArrayBufferOffsets[attribIndex] = 0; mCurrentArrayBufferOffsets[attribIndex] = 0;
mCurrentArrayBufferStrides[attribIndex] = 0; mCurrentArrayBufferStrides[attribIndex] = 0;
mCurrentArrayBufferRelativeOffsets[attribIndex] = 0; mCurrentArrayBufferRelativeOffsets[attribIndex] = 0;
......
...@@ -158,9 +158,6 @@ class VertexArrayVk : public VertexArrayImpl ...@@ -158,9 +158,6 @@ class VertexArrayVk : public VertexArrayImpl
Optional<size_t> mLineLoopBufferLastIndex; Optional<size_t> mLineLoopBufferLastIndex;
bool mDirtyLineLoopTranslation; bool mDirtyLineLoopTranslation;
// Vulkan does not allow binding a null vertex buffer. We use a dummy as a placeholder.
vk::BufferHelper mTheNullBuffer;
// Track client and/or emulated attribs that we have to stream their buffer contents // Track client and/or emulated attribs that we have to stream their buffer contents
gl::AttributesMask mStreamingVertexAttribsMask; gl::AttributesMask mStreamingVertexAttribsMask;
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment