Commit a72ebeba by Luc Ferron Committed by Commit Bot

Vulkan: Fix issue in DynamicBuffer

- We weren't keeping track of mSize correctly, causing some very specific index buffer bindings to fail. The size returned when allocating the buffer can be a bit different than the size requested, and that extra space between mSize and the allocated size was not meant to be used, causing errors in the validation layers. Bug: angleproject:2580 Change-Id: I47eb7b8de6f4f657de14385b77ba6a459add599b Reviewed-on: https://chromium-review.googlesource.com/1118607Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Luc Ferron <lucferron@chromium.org>
parent 2b06054d
......@@ -18,7 +18,7 @@
namespace rx
{
BufferVk::BufferVk(const gl::BufferState &state) : BufferImpl(state), mCurrentRequiredSize(0)
BufferVk::BufferVk(const gl::BufferState &state) : BufferImpl(state)
{
}
......@@ -49,7 +49,7 @@ gl::Error BufferVk::setData(const gl::Context *context,
ContextVk *contextVk = vk::GetImpl(context);
VkDevice device = contextVk->getDevice();
if (size > mCurrentRequiredSize)
if (size > static_cast<size_t>(mState.getSize()))
{
// Release and re-create the memory and buffer.
release(contextVk->getRenderer());
......@@ -76,7 +76,7 @@ gl::Error BufferVk::setData(const gl::Context *context,
const VkMemoryPropertyFlags memoryPropertyFlags =
(VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
ANGLE_TRY(vk::AllocateBufferMemory(contextVk->getRenderer(), memoryPropertyFlags, &mBuffer,
&mBufferMemory, &mCurrentRequiredSize));
&mBufferMemory));
}
if (data)
......
......@@ -64,7 +64,6 @@ class BufferVk : public BufferImpl, public vk::CommandGraphResource
vk::Buffer mBuffer;
vk::DeviceMemory mBufferMemory;
size_t mCurrentRequiredSize;
};
} // namespace rx
......
......@@ -422,9 +422,8 @@ gl::Error ProgramVk::initDefaultUniformBlocks(const gl::Context *glContext)
// Assume host visible/coherent memory available.
VkMemoryPropertyFlags flags =
(VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
size_t requiredSize = 0;
ANGLE_TRY(AllocateBufferMemory(renderer, flags, &mEmptyUniformBlockStorage.buffer,
&mEmptyUniformBlockStorage.memory, &requiredSize));
&mEmptyUniformBlockStorage.memory));
}
// Ensure the descriptor set range includes the uniform buffers at position 0.
......
......@@ -149,11 +149,13 @@ Error DynamicBuffer::allocate(RendererVk *renderer,
mRetainedBuffers.emplace_back(std::move(mBuffer), std::move(mMemory));
mSize = std::max(sizeToAllocate, mMinSize);
VkBufferCreateInfo createInfo;
createInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
createInfo.pNext = nullptr;
createInfo.flags = 0;
createInfo.size = std::max(sizeToAllocate, mMinSize);
createInfo.size = mSize;
createInfo.usage = mUsage;
createInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
createInfo.queueFamilyIndexCount = 0;
......@@ -161,7 +163,7 @@ Error DynamicBuffer::allocate(RendererVk *renderer,
ANGLE_TRY(mBuffer.init(device, createInfo));
ANGLE_TRY(AllocateBufferMemory(renderer, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, &mBuffer,
&mMemory, &mSize));
&mMemory));
ANGLE_TRY(mMemory.map(device, 0, mSize, 0, &mMappedMemory));
mNextAllocationOffset = 0;
......@@ -508,7 +510,6 @@ void LineLoopHelper::Draw(uint32_t count, CommandBuffer *commandBuffer)
ImageHelper::ImageHelper()
: mFormat(nullptr),
mSamples(0),
mAllocatedMemorySize(0),
mCurrentLayout(VK_IMAGE_LAYOUT_UNDEFINED),
mLayerCount(0)
{
......@@ -520,7 +521,6 @@ ImageHelper::ImageHelper(ImageHelper &&other)
mExtents(other.mExtents),
mFormat(other.mFormat),
mSamples(other.mSamples),
mAllocatedMemorySize(other.mAllocatedMemorySize),
mCurrentLayout(other.mCurrentLayout),
mLayerCount(other.mLayerCount)
{
......@@ -594,8 +594,7 @@ Error ImageHelper::initMemory(VkDevice device,
VkMemoryPropertyFlags flags)
{
// TODO(jmadill): Memory sub-allocation. http://anglebug.com/2162
ANGLE_TRY(AllocateImageMemory(device, memoryProperties, flags, &mImage, &mDeviceMemory,
&mAllocatedMemorySize));
ANGLE_TRY(AllocateImageMemory(device, memoryProperties, flags, &mImage, &mDeviceMemory));
return NoError();
}
......@@ -747,11 +746,6 @@ GLint ImageHelper::getSamples() const
return mSamples;
}
size_t ImageHelper::getAllocatedMemorySize() const
{
return mAllocatedMemorySize;
}
void ImageHelper::changeLayoutWithStages(VkImageAspectFlags aspectMask,
VkImageLayout newLayout,
VkPipelineStageFlags srcStageMask,
......
......@@ -248,7 +248,6 @@ class ImageHelper final : angle::NonCopyable
gl::Extents mExtents;
const Format *mFormat;
GLint mSamples;
size_t mAllocatedMemorySize;
// Current state.
VkImageLayout mCurrentLayout;
......
......@@ -131,16 +131,12 @@ vk::Error AllocateBufferOrImageMemory(VkDevice device,
const vk::MemoryProperties &memoryProperties,
VkMemoryPropertyFlags memoryPropertyFlags,
T *bufferOrImage,
vk::DeviceMemory *deviceMemoryOut,
size_t *requiredSizeOut)
vk::DeviceMemory *deviceMemoryOut)
{
// Call driver to determine memory requirements.
VkMemoryRequirements memoryRequirements;
bufferOrImage->getMemoryRequirements(device, &memoryRequirements);
// The requirements size is not always equal to the specified API size.
*requiredSizeOut = static_cast<size_t>(memoryRequirements.size);
ANGLE_TRY(FindAndAllocateCompatibleMemory(device, memoryProperties, memoryPropertyFlags,
memoryRequirements, deviceMemoryOut));
ANGLE_TRY(bufferOrImage->bindMemory(device, *deviceMemoryOut));
......@@ -1106,9 +1102,8 @@ vk::Error StagingBuffer::init(ContextVk *contextVk, VkDeviceSize size, StagingUs
(VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
ANGLE_TRY(mBuffer.init(contextVk->getDevice(), createInfo));
ANGLE_TRY(
AllocateBufferMemory(contextVk->getRenderer(), flags, &mBuffer, &mDeviceMemory, &mSize));
ANGLE_TRY(AllocateBufferMemory(contextVk->getRenderer(), flags, &mBuffer, &mDeviceMemory));
mSize = static_cast<size_t>(size);
return vk::NoError();
}
......@@ -1121,25 +1116,23 @@ void StagingBuffer::dumpResources(Serial serial, std::vector<vk::GarbageObject>
Error AllocateBufferMemory(RendererVk *renderer,
VkMemoryPropertyFlags memoryPropertyFlags,
Buffer *buffer,
DeviceMemory *deviceMemoryOut,
size_t *requiredSizeOut)
DeviceMemory *deviceMemoryOut)
{
VkDevice device = renderer->getDevice();
const vk::MemoryProperties &memoryProperties = renderer->getMemoryProperties();
return AllocateBufferOrImageMemory(device, memoryProperties, memoryPropertyFlags, buffer,
deviceMemoryOut, requiredSizeOut);
deviceMemoryOut);
}
Error AllocateImageMemory(VkDevice device,
const MemoryProperties &memoryProperties,
VkMemoryPropertyFlags memoryPropertyFlags,
Image *image,
DeviceMemory *deviceMemoryOut,
size_t *requiredSizeOut)
DeviceMemory *deviceMemoryOut)
{
return AllocateBufferOrImageMemory(device, memoryProperties, memoryPropertyFlags, image,
deviceMemoryOut, requiredSizeOut);
deviceMemoryOut);
}
// GarbageObject implementation.
......
......@@ -657,8 +657,7 @@ class ObjectAndSerial final : angle::NonCopyable
Error AllocateBufferMemory(RendererVk *renderer,
VkMemoryPropertyFlags memoryPropertyFlags,
Buffer *buffer,
DeviceMemory *deviceMemoryOut,
size_t *requiredSizeOut);
DeviceMemory *deviceMemoryOut);
struct BufferAndMemory final : angle::NonCopyable
{
......@@ -675,8 +674,7 @@ Error AllocateImageMemory(VkDevice device,
const MemoryProperties &memoryProperties,
VkMemoryPropertyFlags memoryPropertyFlags,
Image *image,
DeviceMemory *deviceMemoryOut,
size_t *requiredSizeOut);
DeviceMemory *deviceMemoryOut);
using ShaderAndSerial = ObjectAndSerial<ShaderModule>;
......
......@@ -262,9 +262,6 @@
1028 WIN LINUX MAC : dEQP-GLES2.functional.fbo.completeness.renderable.texture.depth.srgb8 = FAIL
// Vulkan failures
2580 VULKAN : dEQP-GLES2.functional.buffer.write.recreate_store.different_size = SKIP
2580 VULKAN : dEQP-GLES2.functional.buffer.write.recreate_store.random_* = SKIP
2580 VULKAN : dEQP-GLES2.functional.buffer.write.random.* = SKIP
2494 VULKAN : dEQP-GLES2.functional.shaders.struct.uniform.sampler_in_function_arg_* = SKIP
2494 VULKAN : dEQP-GLES2.functional.shaders.struct.uniform.sampler_in_array_function_arg_* = SKIP
2592 VULKAN : dEQP-GLES2.functional.shaders.builtin_variable.depth_range* = SKIP
......
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