mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-22 20:41:20 +00:00
[vulkan] Correct the semantics of QFV_NextOffset
I'm not at all sure what I was thinking when I designed it, but I certainly designed it wrong (to the point of being fairly useless). It turns out memory requirements are already aligned in size (so just multiplying is fine), and what I really wanted was to get the next offset aligned to the given requirements.
This commit is contained in:
parent
36e0d857a2
commit
743a732bd7
4 changed files with 7 additions and 9 deletions
|
@ -45,7 +45,7 @@ VkBufferView QFV_CreateBufferView (struct qfv_device_s *device,
|
|||
VkBuffer buffer, VkFormat format,
|
||||
VkDeviceSize offset, VkDeviceSize size);
|
||||
|
||||
VkDeviceSize QFV_NextOffset (VkDeviceSize current, VkDeviceSize count,
|
||||
VkDeviceSize QFV_NextOffset (VkDeviceSize current,
|
||||
const VkMemoryRequirements *requirements)
|
||||
__attribute__((pure));
|
||||
|
||||
|
|
|
@ -111,7 +111,7 @@ Vulkan_Mod_SpriteLoadFrames (mod_sprite_ctx_t *sprite_ctx, vulkan_ctx_t *ctx)
|
|||
dfunc->vkGetImageMemoryRequirements (device->dev, sprite->image, &ireq);
|
||||
VkMemoryRequirements vreq;
|
||||
dfunc->vkGetBufferMemoryRequirements (device->dev, sprite->verts, &vreq);
|
||||
size_t size = QFV_NextOffset (QFV_NextOffset (0, 1, &vreq), 1, &ireq);
|
||||
size_t size = QFV_NextOffset (vreq.size, &ireq) + ireq.size;
|
||||
|
||||
sprite->memory = QFV_AllocBufferMemory (device, sprite->verts,
|
||||
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
|
||||
|
@ -122,7 +122,7 @@ Vulkan_Mod_SpriteLoadFrames (mod_sprite_ctx_t *sprite_ctx, vulkan_ctx_t *ctx)
|
|||
|
||||
QFV_BindBufferMemory (device, sprite->verts, sprite->memory, 0);
|
||||
QFV_BindImageMemory (device, sprite->image, sprite->memory,
|
||||
QFV_NextOffset (0, 1, &vreq));
|
||||
QFV_NextOffset (vreq.size, &ireq));
|
||||
sprite->view = QFV_CreateImageView (device, sprite->image,
|
||||
VK_IMAGE_VIEW_TYPE_2D_ARRAY,
|
||||
VK_FORMAT_R8G8B8A8_UNORM,
|
||||
|
|
|
@ -164,10 +164,8 @@ QFV_CreateBufferView (qfv_device_t *device, VkBuffer buffer, VkFormat format,
|
|||
}
|
||||
|
||||
VkDeviceSize
|
||||
QFV_NextOffset (VkDeviceSize current, VkDeviceSize count,
|
||||
const VkMemoryRequirements *requirements)
|
||||
QFV_NextOffset (VkDeviceSize current, const VkMemoryRequirements *requirements)
|
||||
{
|
||||
VkDeviceSize align = requirements->alignment - 1;
|
||||
VkDeviceSize size = (requirements->size + align) & ~align;
|
||||
return ((current + align) & ~align) + count * size;
|
||||
return ((current + align) & ~align);
|
||||
}
|
||||
|
|
|
@ -334,7 +334,7 @@ Vulkan_Lighting_Init (vulkan_ctx_t *ctx)
|
|||
&requirements);
|
||||
lctx->light_memory = QFV_AllocBufferMemory (device, lbuffers->a[0],
|
||||
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
|
||||
QFV_NextOffset (0, frames, &requirements), 0);
|
||||
frames * requirements.size, 0);
|
||||
QFV_duSetObjectName (device, VK_OBJECT_TYPE_DEVICE_MEMORY,
|
||||
lctx->light_memory, "memory:lighting");
|
||||
|
||||
|
@ -389,7 +389,7 @@ Vulkan_Lighting_Init (vulkan_ctx_t *ctx)
|
|||
lframe->light_buffer = lbuffers->a[i];
|
||||
QFV_BindBufferMemory (device, lbuffers->a[i], lctx->light_memory,
|
||||
light_offset);
|
||||
light_offset = QFV_NextOffset (light_offset, 1, &requirements);
|
||||
light_offset += requirements.size;
|
||||
|
||||
QFV_duSetObjectName (device, VK_OBJECT_TYPE_COMMAND_BUFFER,
|
||||
lframe->cmd, "cmd:lighting");
|
||||
|
|
Loading…
Reference in a new issue