Skip to content

Commit 82cef16

Browse files
committed
Changed device memory setup to use the deviceMemoryBufferPools
1 parent 2572514 commit 82cef16

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/vsg/state/Buffer.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,21 @@ ref_ptr<Buffer> vsg::createBufferAndMemory(Device* device, VkDeviceSize size, Vk
159159
buffer->compile(device);
160160

161161
auto memRequirements = buffer->getMemoryRequirements(device->deviceID);
162-
auto memory = vsg::DeviceMemory::create(device, memRequirements, memoryProperties, pNextAllocInfo);
163162

163+
if ((memoryProperties & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) != 0)
164+
{
165+
auto deviceMemoryBufferPools = device->deviceMemoryBufferPools.ref_ptr();
166+
if (deviceMemoryBufferPools)
167+
{
168+
auto [memory, offset] = deviceMemoryBufferPools->reserveMemory(memRequirements, memoryProperties);
169+
170+
buffer->bind(memory, offset);
171+
return buffer;
172+
}
173+
}
174+
175+
auto memory = vsg::DeviceMemory::create(device, memRequirements, memoryProperties, pNextAllocInfo);
164176
buffer->bind(memory, 0);
177+
165178
return buffer;
166179
}

src/vsg/state/Image.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,25 @@ VkResult Image::bind(DeviceMemory* deviceMemory, VkDeviceSize memoryOffset)
157157
VkResult Image::allocateAndBindMemory(Device* device, VkMemoryPropertyFlags memoryProperties, void* pNextAllocInfo)
158158
{
159159
auto memRequirements = getMemoryRequirements(device->deviceID);
160+
161+
if ((memoryProperties & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) != 0)
162+
{
163+
auto deviceMemoryBufferPools = device->deviceMemoryBufferPools.ref_ptr();
164+
if (deviceMemoryBufferPools)
165+
{
166+
auto [memory, offset] = deviceMemoryBufferPools->reserveMemory(memRequirements, memoryProperties);
167+
168+
return bind(memory, offset);
169+
}
170+
}
171+
160172
auto memory = DeviceMemory::create(device, memRequirements, memoryProperties, pNextAllocInfo);
161173
auto [allocated, offset] = memory->reserve(memRequirements.size);
162174
if (!allocated)
163175
{
164176
throw Exception{"Error: Failed to allocate DeviceMemory."};
165177
}
178+
166179
return bind(memory, offset);
167180
}
168181

0 commit comments

Comments
 (0)