Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allocate DescriptorBuffer memory from pools #943

Merged
merged 1 commit into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/vsg/state/BufferInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ void BufferInfo::copyDataToBuffer(uint32_t deviceID)
}

void* buffer_data;
VkResult result = dm->map(offset, range, 0, &buffer_data);
VkResult result = dm->map(buffer->getMemoryOffset(deviceID) + offset, range, 0, &buffer_data);
if (result != 0)
{
warn("BufferInfo::copyDataToBuffer() cannot copy data. vkMapMemory(..) failed with result = ", result);
Expand Down
12 changes: 7 additions & 5 deletions src/vsg/state/DescriptorBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
</editor-fold> */

#include <vsg/core/compare.h>
#include <vsg/core/Exception.h>
#include <vsg/io/Logger.h>
#include <vsg/io/Options.h>
#include <vsg/state/DescriptorBuffer.h>
Expand Down Expand Up @@ -177,15 +178,16 @@ void DescriptorBuffer::compile(Context& context)
if (bufferInfo->buffer->getDeviceMemory(deviceID) == nullptr)
{
auto memRequirements = bufferInfo->buffer->getMemoryRequirements(deviceID);
auto memory = vsg::DeviceMemory::create(context.device, memRequirements, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
auto [allocated, offset] = memory->reserve(bufferInfo->buffer->size);
if (allocated)
auto [deviceMemory, offset]
= context.deviceMemoryBufferPools->reserveMemory(memRequirements,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
if (deviceMemory)
{
bufferInfo->buffer->bind(memory, offset);
bufferInfo->buffer->bind(deviceMemory, offset);
}
else
{
warn("DescriptorBuffer::compile(..) unable to allocate buffer within associated DeviceMemory.");
throw Exception{"Error: DescriptorBuffer::compile(..) unable to allocate buffer."};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are to throw an exception then the returning a relevant Vulkan error would be helpful.

Alternatively we could use vsg::fatal().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are to throw an exception then the returning a relevant Vulkan error would be helpful.

I agree. That would require changing the memory pool interface, but perhaps that is desirable.

Alternatively we could use vsg::fatal().

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This close to a release I want to avoid getting diverted into lots of other work - occasionally I need to get some paid work done :-)

}
}
}
Expand Down
Loading