Skip to content

Commit

Permalink
Fix bad cast from an Allocation to a VmaAllocationInfo (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
RowDaBoat authored Jul 27, 2024
1 parent 86232f9 commit 6fce369
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 35 deletions.
6 changes: 6 additions & 0 deletions src/org/lwjgl/demo/vulkan/VKUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.lwjgl.PointerBuffer;
import org.lwjgl.system.*;
import org.lwjgl.util.shaderc.*;
import org.lwjgl.util.vma.VmaAllocationInfo;
import org.lwjgl.vulkan.*;

/**
Expand Down Expand Up @@ -231,4 +232,9 @@ public static PointerBuffer pointersOfElements(MemoryStack stack, CustomBuffer<?
}
return pointerBuffer;
}

public static void validateAlignment(VmaAllocationInfo pAllocationInfo, long alignment) {
if ((pAllocationInfo.offset() % alignment) != 0)
throw new AssertionError("Illegal offset alignment");
}
}
9 changes: 4 additions & 5 deletions src/org/lwjgl/demo/vulkan/raytracing/HybridMagicaVoxel.java
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,8 @@ private static AllocationAndBuffer createBuffer(int usageFlags, long size, ByteB
// create the final destination buffer
LongBuffer pBuffer = stack.mallocLong(1);
PointerBuffer pAllocation = stack.mallocPointer(1);
VmaAllocationInfo pAllocationInfo = VmaAllocationInfo.malloc(stack);

_CHECK_(vmaCreateBuffer(vmaAllocator,
VkBufferCreateInfo
.calloc(stack)
Expand All @@ -1095,13 +1097,10 @@ private static AllocationAndBuffer createBuffer(int usageFlags, long size, ByteB
.usage(usageFlags | (data != null ? VK_BUFFER_USAGE_TRANSFER_DST_BIT : 0)),
VmaAllocationCreateInfo
.calloc(stack)
.usage(VMA_MEMORY_USAGE_AUTO), pBuffer, pAllocation, null),
.usage(VMA_MEMORY_USAGE_AUTO), pBuffer, pAllocation, pAllocationInfo),
"Failed to allocate buffer");

// validate alignment
VmaAllocationInfo ai = VmaAllocationInfo.create(pAllocation.get(0));
if ((ai.offset() % alignment) != 0)
throw new AssertionError("Illegal offset alignment");
validateAlignment(pAllocationInfo, alignment);

// if we have data to upload, use a staging buffer
if (data != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,7 @@ private static AllocationAndBuffer createBuffer(int usageFlags, long size, ByteB
// create the final destination buffer
LongBuffer pBuffer = stack.mallocLong(1);
PointerBuffer pAllocation = stack.mallocPointer(1);
VmaAllocationInfo pAllocationInfo = VmaAllocationInfo.malloc(stack);
_CHECK_(vmaCreateBuffer(vmaAllocator,
VkBufferCreateInfo
.calloc(stack)
Expand All @@ -891,13 +892,10 @@ private static AllocationAndBuffer createBuffer(int usageFlags, long size, ByteB
.usage(usageFlags | (data != null ? VK_BUFFER_USAGE_TRANSFER_DST_BIT : 0)),
VmaAllocationCreateInfo
.calloc(stack)
.usage(VMA_MEMORY_USAGE_AUTO), pBuffer, pAllocation, null),
.usage(VMA_MEMORY_USAGE_AUTO), pBuffer, pAllocation, pAllocationInfo),
"Failed to allocate buffer");

// validate alignment
VmaAllocationInfo ai = VmaAllocationInfo.create(pAllocation.get(0));
if ((ai.offset() % alignment) != 0)
throw new AssertionError("Illegal offset alignment");
validateAlignment(pAllocationInfo, alignment);

// if we have data to upload, use a staging buffer
if (data != null) {
Expand Down
8 changes: 3 additions & 5 deletions src/org/lwjgl/demo/vulkan/raytracing/SdfBricks.java
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,7 @@ private static AllocationAndBuffer createBuffer(int usageFlags, long size, ByteB
// create the final destination buffer
LongBuffer pBuffer = stack.mallocLong(1);
PointerBuffer pAllocation = stack.mallocPointer(1);
VmaAllocationInfo pAllocationInfo = VmaAllocationInfo.malloc(stack);
_CHECK_(vmaCreateBuffer(vmaAllocator,
VkBufferCreateInfo
.calloc(stack)
Expand All @@ -886,13 +887,10 @@ private static AllocationAndBuffer createBuffer(int usageFlags, long size, ByteB
.usage(usageFlags | (data != null ? VK_BUFFER_USAGE_TRANSFER_DST_BIT : 0)),
VmaAllocationCreateInfo
.calloc(stack)
.usage(VMA_MEMORY_USAGE_AUTO), pBuffer, pAllocation, null),
.usage(VMA_MEMORY_USAGE_AUTO), pBuffer, pAllocation, pAllocationInfo),
"Failed to allocate buffer");

// validate alignment
VmaAllocationInfo ai = VmaAllocationInfo.create(pAllocation.get(0));
if ((ai.offset() % alignment) != 0)
throw new AssertionError("Illegal offset alignment");
validateAlignment(pAllocationInfo, alignment);

// if we have data to upload, use a staging buffer
if (data != null) {
Expand Down
8 changes: 3 additions & 5 deletions src/org/lwjgl/demo/vulkan/raytracing/SimpleSphere.java
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,7 @@ private static AllocationAndBuffer createBuffer(int usageFlags, long size, ByteB
// create the final destination buffer
LongBuffer pBuffer = stack.mallocLong(1);
PointerBuffer pAllocation = stack.mallocPointer(1);
VmaAllocationInfo pAllocationInfo = VmaAllocationInfo.malloc(stack);
_CHECK_(vmaCreateBuffer(vmaAllocator,
VkBufferCreateInfo
.calloc(stack)
Expand All @@ -847,13 +848,10 @@ private static AllocationAndBuffer createBuffer(int usageFlags, long size, ByteB
.usage(usageFlags | (data != null ? VK_BUFFER_USAGE_TRANSFER_DST_BIT : 0)),
VmaAllocationCreateInfo
.calloc(stack)
.usage(VMA_MEMORY_USAGE_AUTO), pBuffer, pAllocation, null),
.usage(VMA_MEMORY_USAGE_AUTO), pBuffer, pAllocation, pAllocationInfo),
"Failed to allocate buffer");

// validate alignment
VmaAllocationInfo ai = VmaAllocationInfo.create(pAllocation.get(0));
if ((ai.offset() % alignment) != 0)
throw new AssertionError("Illegal offset alignment");
validateAlignment(pAllocationInfo, alignment);

// if we have data to upload, use a staging buffer
if (data != null) {
Expand Down
8 changes: 3 additions & 5 deletions src/org/lwjgl/demo/vulkan/raytracing/SimpleTriangle.java
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,7 @@ private static AllocationAndBuffer createBuffer(int usageFlags, long size, ByteB
// create the final destination buffer
LongBuffer pBuffer = stack.mallocLong(1);
PointerBuffer pAllocation = stack.mallocPointer(1);
VmaAllocationInfo pAllocationInfo = VmaAllocationInfo.malloc(stack);
_CHECK_(vmaCreateBuffer(vmaAllocator,
VkBufferCreateInfo
.calloc(stack)
Expand All @@ -851,13 +852,10 @@ private static AllocationAndBuffer createBuffer(int usageFlags, long size, ByteB
.usage(usageFlags | (data != null ? VK_BUFFER_USAGE_TRANSFER_DST_BIT : 0)),
VmaAllocationCreateInfo
.calloc(stack)
.usage(VMA_MEMORY_USAGE_AUTO), pBuffer, pAllocation, null),
.usage(VMA_MEMORY_USAGE_AUTO), pBuffer, pAllocation, pAllocationInfo),
"Failed to allocate buffer");

// validate alignment
VmaAllocationInfo ai = VmaAllocationInfo.create(pAllocation.get(0));
if ((ai.offset() % alignment) != 0)
throw new AssertionError("Illegal offset alignment");
validateAlignment(pAllocationInfo, alignment);

// if we have data to upload, use a staging buffer
if (data != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,7 @@ private static AllocationAndBuffer createBuffer(int usageFlags, long size, ByteB
// create the final destination buffer
LongBuffer pBuffer = stack.mallocLong(1);
PointerBuffer pAllocation = stack.mallocPointer(1);
VmaAllocationInfo pAllocationInfo = VmaAllocationInfo.malloc(stack);
_CHECK_(vmaCreateBuffer(vmaAllocator,
VkBufferCreateInfo
.calloc(stack)
Expand All @@ -844,13 +845,10 @@ private static AllocationAndBuffer createBuffer(int usageFlags, long size, ByteB
.usage(usageFlags | (data != null ? VK_BUFFER_USAGE_TRANSFER_DST_BIT : 0)),
VmaAllocationCreateInfo
.calloc(stack)
.usage(VMA_MEMORY_USAGE_AUTO), pBuffer, pAllocation, null),
.usage(VMA_MEMORY_USAGE_AUTO), pBuffer, pAllocation, pAllocationInfo),
"Failed to allocate buffer");

// validate alignment
VmaAllocationInfo ai = VmaAllocationInfo.create(pAllocation.get(0));
if ((ai.offset() % alignment) != 0)
throw new AssertionError("Illegal offset alignment");
validateAlignment(pAllocationInfo, alignment);

// if we have data to upload, use a staging buffer
if (data != null) {
Expand Down
8 changes: 3 additions & 5 deletions src/org/lwjgl/demo/vulkan/raytracing/VoxelChunks.java
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,7 @@ private static AllocationAndBuffer createBuffer(int usageFlags, long size, ByteB
// create the final destination buffer
LongBuffer pBuffer = stack.mallocLong(1);
PointerBuffer pAllocation = stack.mallocPointer(1);
VmaAllocationInfo pAllocationInfo = VmaAllocationInfo.malloc(stack);
_CHECK_(vmaCreateBuffer(vmaAllocator,
VkBufferCreateInfo
.calloc(stack)
Expand All @@ -923,13 +924,10 @@ private static AllocationAndBuffer createBuffer(int usageFlags, long size, ByteB
.usage(usageFlags | (data != null ? VK_BUFFER_USAGE_TRANSFER_DST_BIT : 0)),
VmaAllocationCreateInfo
.calloc(stack)
.usage(VMA_MEMORY_USAGE_AUTO), pBuffer, pAllocation, null),
.usage(VMA_MEMORY_USAGE_AUTO), pBuffer, pAllocation, pAllocationInfo),
"Failed to allocate buffer");

// validate alignment
VmaAllocationInfo ai = VmaAllocationInfo.create(pAllocation.get(0));
if ((ai.offset() % alignment) != 0)
throw new AssertionError("Illegal offset alignment");
validateAlignment(pAllocationInfo, alignment);

// if we have data to upload, use a staging buffer
if (data != null) {
Expand Down

0 comments on commit 6fce369

Please sign in to comment.