From 1c8499e6e3e55d27af33803f12148d341adcae73 Mon Sep 17 00:00:00 2001 From: ahbejarano Date: Sun, 13 Sep 2020 19:19:50 +0200 Subject: [PATCH] Refactor --- .../java/org/vulkanb/eng/graph/Render.java | 11 +++----- .../org/vulkanb/eng/graph/TextureCache.java | 4 +-- .../geometry/GeometryRenderActivity.java | 11 +++----- .../lighting/LightingRenderActivity.java | 10 +++----- .../java/org/vulkanb/eng/graph/vk/Device.java | 10 +++++++- .../vulkanb/eng/graph/vk/MemoryAllocator.java | 23 +++++------------ .../org/vulkanb/eng/graph/vk/Texture.java | 9 +++---- .../vulkanb/eng/graph/vk/VulkanBuffer.java | 14 +++++------ .../org/vulkanb/eng/graph/vk/VulkanMesh.java | 25 +++++++++---------- 9 files changed, 52 insertions(+), 65 deletions(-) diff --git a/booksamples/chapter-12/src/main/java/org/vulkanb/eng/graph/Render.java b/booksamples/chapter-12/src/main/java/org/vulkanb/eng/graph/Render.java index d44a7396..392c5113 100644 --- a/booksamples/chapter-12/src/main/java/org/vulkanb/eng/graph/Render.java +++ b/booksamples/chapter-12/src/main/java/org/vulkanb/eng/graph/Render.java @@ -19,7 +19,6 @@ public class Render { private Queue.GraphicsQueue graphQueue; private Instance instance; private LightingRenderActivity lightingRenderActivity; - private MemoryAllocator memoryAllocator; private List meshList; private PhysicalDevice physicalDevice; private PipelineCache pipelineCache; @@ -40,7 +39,6 @@ public void cleanup() { commandPool.cleanup(); swapChain.cleanup(); surface.cleanup(); - memoryAllocator.cleanUp(); device.cleanup(); physicalDevice.cleanup(); instance.cleanup(); @@ -50,8 +48,7 @@ public void init(Window window, Scene scene) { EngineProperties engProps = EngineProperties.getInstance(); instance = new Instance(engProps.isValidate()); physicalDevice = PhysicalDevice.createPhysicalDevice(instance, engProps.getPhysDeviceName()); - device = new Device(physicalDevice); - memoryAllocator = new MemoryAllocator(instance, device); + device = new Device(instance, physicalDevice); surface = new Surface(physicalDevice, window.getWindowHandle()); graphQueue = new Queue.GraphicsQueue(device, 0); presentQueue = new Queue.PresentQueue(device, surface, 0); @@ -61,14 +58,14 @@ public void init(Window window, Scene scene) { pipelineCache = new PipelineCache(device); meshList = new ArrayList<>(); textureCache = new TextureCache(); - geometryRenderActivity = new GeometryRenderActivity(memoryAllocator, swapChain, commandPool, pipelineCache, scene); - lightingRenderActivity = new LightingRenderActivity(memoryAllocator, swapChain, commandPool, pipelineCache, + geometryRenderActivity = new GeometryRenderActivity(swapChain, commandPool, pipelineCache, scene); + lightingRenderActivity = new LightingRenderActivity(swapChain, commandPool, pipelineCache, geometryRenderActivity.getAttachments(), scene); } public void loadMeshes(MeshData[] meshDataList) { LOGGER.debug("Loading {} meshe(s)", meshDataList.length); - VulkanMesh[] meshes = VulkanMesh.loadMeshes(memoryAllocator, textureCache, commandPool, graphQueue, meshDataList); + VulkanMesh[] meshes = VulkanMesh.loadMeshes(textureCache, commandPool, graphQueue, meshDataList); LOGGER.debug("Loaded {} meshe(s)", meshes.length); meshList.addAll(Arrays.asList(meshes)); diff --git a/booksamples/chapter-12/src/main/java/org/vulkanb/eng/graph/TextureCache.java b/booksamples/chapter-12/src/main/java/org/vulkanb/eng/graph/TextureCache.java index 5090b7a4..cc06c65f 100644 --- a/booksamples/chapter-12/src/main/java/org/vulkanb/eng/graph/TextureCache.java +++ b/booksamples/chapter-12/src/main/java/org/vulkanb/eng/graph/TextureCache.java @@ -20,7 +20,7 @@ public void cleanup() { textureMap.clear(); } - public Texture createTexture(MemoryAllocator memoryAllocator, String texturePath, int format) { + public Texture createTexture(Device device, String texturePath, int format) { String path = texturePath; if (texturePath == null || texturePath.trim().isEmpty()) { EngineProperties engProperties = EngineProperties.getInstance(); @@ -28,7 +28,7 @@ public Texture createTexture(MemoryAllocator memoryAllocator, String texturePath } Texture texture = textureMap.get(path); if (texture == null) { - texture = new Texture(memoryAllocator, path, format); + texture = new Texture(device, path, format); textureMap.put(path, texture); } return texture; diff --git a/booksamples/chapter-12/src/main/java/org/vulkanb/eng/graph/geometry/GeometryRenderActivity.java b/booksamples/chapter-12/src/main/java/org/vulkanb/eng/graph/geometry/GeometryRenderActivity.java index a57c0fc1..e5b74ec7 100644 --- a/booksamples/chapter-12/src/main/java/org/vulkanb/eng/graph/geometry/GeometryRenderActivity.java +++ b/booksamples/chapter-12/src/main/java/org/vulkanb/eng/graph/geometry/GeometryRenderActivity.java @@ -33,7 +33,6 @@ public class GeometryRenderActivity { private VulkanBuffer materialsBuffer; private MaterialDescriptorSet materialsDescriptorSet; private MatrixDescriptorSetLayout matrixDescriptorSetLayout; - private MemoryAllocator memoryAllocator; private Pipeline pipeLine; private PipelineCache pipelineCache; private MatrixDescriptorSet projMatrixDescriptorSet; @@ -45,9 +44,7 @@ public class GeometryRenderActivity { private VulkanBuffer[] viewMatricesBuffer; private MatrixDescriptorSet[] viewMatricesDescriptorSets; - public GeometryRenderActivity(MemoryAllocator memoryAllocator, SwapChain swapChain, CommandPool commandPool, - PipelineCache pipelineCache, Scene scene) { - this.memoryAllocator = memoryAllocator; + public GeometryRenderActivity(SwapChain swapChain, CommandPool commandPool, PipelineCache pipelineCache, Scene scene) { this.swapChain = swapChain; this.pipelineCache = pipelineCache; device = swapChain.getDevice(); @@ -112,18 +109,18 @@ private void createDescriptorSets(int numImages) { EngineProperties engineProps = EngineProperties.getInstance(); descriptorSetMap = new HashMap<>(); textureSampler = new TextureSampler(device, 1); - projMatrixUniform = new VulkanBuffer(memoryAllocator, GraphConstants.MAT4X4_SIZE, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, + projMatrixUniform = new VulkanBuffer(device, GraphConstants.MAT4X4_SIZE, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, 0); projMatrixDescriptorSet = new MatrixDescriptorSet(descriptorPool, matrixDescriptorSetLayout, projMatrixUniform, 0); viewMatricesDescriptorSets = new MatrixDescriptorSet[numImages]; viewMatricesBuffer = new VulkanBuffer[numImages]; - materialsBuffer = new VulkanBuffer(memoryAllocator, (long) materialDescriptorSetLayout.getMaterialSize() * engineProps.getMaxMaterials(), + materialsBuffer = new VulkanBuffer(device, (long) materialDescriptorSetLayout.getMaterialSize() * engineProps.getMaxMaterials(), VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, 0); materialsDescriptorSet = new MaterialDescriptorSet(descriptorPool, materialDescriptorSetLayout, materialsBuffer, 0); for (int i = 0; i < numImages; i++) { - viewMatricesBuffer[i] = new VulkanBuffer(memoryAllocator, GraphConstants.MAT4X4_SIZE, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, + viewMatricesBuffer[i] = new VulkanBuffer(device, GraphConstants.MAT4X4_SIZE, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, 0); viewMatricesDescriptorSets[i] = new MatrixDescriptorSet(descriptorPool, matrixDescriptorSetLayout, viewMatricesBuffer[i], 0); diff --git a/booksamples/chapter-12/src/main/java/org/vulkanb/eng/graph/lighting/LightingRenderActivity.java b/booksamples/chapter-12/src/main/java/org/vulkanb/eng/graph/lighting/LightingRenderActivity.java index aa6624ee..c3912f7a 100644 --- a/booksamples/chapter-12/src/main/java/org/vulkanb/eng/graph/lighting/LightingRenderActivity.java +++ b/booksamples/chapter-12/src/main/java/org/vulkanb/eng/graph/lighting/LightingRenderActivity.java @@ -40,16 +40,14 @@ public class LightingRenderActivity { private LightsDescriptorSetLayout lightsDescriptorSetLayout; private LightsDescriptorSet[] lightsDescriptorSets; private MatrixDescriptorSetLayout matrixDescriptorSetLayout; - private MemoryAllocator memoryAllocator; private Pipeline pipeline; private PipelineCache pipelineCache; private ShaderProgram shaderProgram; private SpecializationConstants specializationConstants; private SwapChain swapChain; - public LightingRenderActivity(MemoryAllocator memoryAllocator, SwapChain swapChain, CommandPool commandPool, - PipelineCache pipelineCache, Attachment[] attachments, Scene scene) { - this.memoryAllocator = memoryAllocator; + public LightingRenderActivity(SwapChain swapChain, CommandPool commandPool, PipelineCache pipelineCache, + Attachment[] attachments, Scene scene) { this.swapChain = swapChain; device = swapChain.getDevice(); this.pipelineCache = pipelineCache; @@ -152,12 +150,12 @@ private void createShaders(int numSamples) { } private void createUniforms(int numImages) { - invProjBuffer = new VulkanBuffer(memoryAllocator, GraphConstants.MAT4X4_SIZE, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, + invProjBuffer = new VulkanBuffer(device, GraphConstants.MAT4X4_SIZE, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, 0); lightsBuffers = new VulkanBuffer[numImages]; for (int i = 0; i < numImages; i++) { - lightsBuffers[i] = new VulkanBuffer(memoryAllocator, + lightsBuffers[i] = new VulkanBuffer(device, GraphConstants.INT_LENGTH * 4 + GraphConstants.VEC4_SIZE * 2 * GraphConstants.MAX_LIGHTS + GraphConstants.VEC4_SIZE, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, 0); diff --git a/booksamples/chapter-12/src/main/java/org/vulkanb/eng/graph/vk/Device.java b/booksamples/chapter-12/src/main/java/org/vulkanb/eng/graph/vk/Device.java index 5eb7bd26..019cb0a6 100644 --- a/booksamples/chapter-12/src/main/java/org/vulkanb/eng/graph/vk/Device.java +++ b/booksamples/chapter-12/src/main/java/org/vulkanb/eng/graph/vk/Device.java @@ -13,12 +13,13 @@ public class Device { private static final Logger LOGGER = LogManager.getLogger(); + private MemoryAllocator memoryAllocator; private PhysicalDevice physicalDevice; private boolean sampleRateShading; private boolean samplerAnisotropy; private VkDevice vkDevice; - public Device(PhysicalDevice physicalDevice) { + public Device(Instance instance, PhysicalDevice physicalDevice) { LOGGER.debug("Creating device"); this.physicalDevice = physicalDevice; @@ -62,14 +63,21 @@ public Device(PhysicalDevice physicalDevice) { vkCheck(vkCreateDevice(physicalDevice.getVkPhysicalDevice(), deviceCreateInfo, null, pp), "Failed to create device"); vkDevice = new VkDevice(pp.get(0), physicalDevice.getVkPhysicalDevice(), deviceCreateInfo); + + memoryAllocator = new MemoryAllocator(instance, physicalDevice, vkDevice); } } public void cleanup() { LOGGER.debug("Destroying Vulkan device"); + memoryAllocator.cleanUp(); vkDestroyDevice(vkDevice, null); } + public MemoryAllocator getMemoryAllocator() { + return memoryAllocator; + } + public PhysicalDevice getPhysicalDevice() { return physicalDevice; } diff --git a/booksamples/chapter-12/src/main/java/org/vulkanb/eng/graph/vk/MemoryAllocator.java b/booksamples/chapter-12/src/main/java/org/vulkanb/eng/graph/vk/MemoryAllocator.java index eaff704d..aa1872cf 100644 --- a/booksamples/chapter-12/src/main/java/org/vulkanb/eng/graph/vk/MemoryAllocator.java +++ b/booksamples/chapter-12/src/main/java/org/vulkanb/eng/graph/vk/MemoryAllocator.java @@ -3,28 +3,25 @@ import org.lwjgl.PointerBuffer; import org.lwjgl.system.MemoryStack; import org.lwjgl.util.vma.*; +import org.lwjgl.vulkan.VkDevice; import static org.lwjgl.util.vma.Vma.*; import static org.vulkanb.eng.graph.vk.VulkanUtils.vkCheck; public class MemoryAllocator { - private Device device; private long vmaAllocator; - public MemoryAllocator(Instance instance, Device device) { - this.device = device; + public MemoryAllocator(Instance instance, PhysicalDevice physicalDevice, VkDevice vkDevice) { try (MemoryStack stack = MemoryStack.stackPush()) { PointerBuffer pAllocator = stack.mallocPointer(1); VmaVulkanFunctions vmaVulkanFunctions = VmaVulkanFunctions.callocStack(stack) - .set(instance.getVkInstance(), device.getVkDevice()); + .set(instance.getVkInstance(), vkDevice); VmaAllocatorCreateInfo createInfo = VmaAllocatorCreateInfo.callocStack(stack) - .flags(bitIf(VMA_ALLOCATOR_CREATE_KHR_DEDICATED_ALLOCATION_BIT, - device.getVkDevice().getCapabilities().VK_KHR_dedicated_allocation)) - .device(device.getVkDevice()) - .physicalDevice(device.getPhysicalDevice().getVkPhysicalDevice()) + .device(vkDevice) + .physicalDevice(physicalDevice.getVkPhysicalDevice()) .pVulkanFunctions(vmaVulkanFunctions); vkCheck(vmaCreateAllocator(createInfo, pAllocator), "Failed to create VMA allocator"); @@ -33,16 +30,8 @@ public MemoryAllocator(Instance instance, Device device) { } } - private static int bitIf(int bit, boolean condition) { - return condition ? bit : 0; - } - public void cleanUp() { - vmaDestroyAllocator(this.vmaAllocator); - } - - public Device getDevice() { - return device; + vmaDestroyAllocator(vmaAllocator); } public long getVmaAllocator() { diff --git a/booksamples/chapter-12/src/main/java/org/vulkanb/eng/graph/vk/Texture.java b/booksamples/chapter-12/src/main/java/org/vulkanb/eng/graph/vk/Texture.java index ea566fd1..7572da02 100644 --- a/booksamples/chapter-12/src/main/java/org/vulkanb/eng/graph/vk/Texture.java +++ b/booksamples/chapter-12/src/main/java/org/vulkanb/eng/graph/vk/Texture.java @@ -23,7 +23,7 @@ public class Texture { private VulkanBuffer stgBuffer; private int width; - public Texture(MemoryAllocator memoryAllocator, String fileName, int imageFormat) { + public Texture(Device device, String fileName, int imageFormat) { LOGGER.debug("Creating texture [{}]", fileName); this.fileName = fileName; ByteBuffer buf; @@ -42,8 +42,7 @@ public Texture(MemoryAllocator memoryAllocator, String fileName, int imageFormat height = h.get(); mipLevels = (int) Math.floor(log2(Math.min(width, height))) + 1; - createStgBuffer(memoryAllocator, buf); - Device device = memoryAllocator.getDevice(); + createStgBuffer(device, buf); image = new Image(device, width, height, imageFormat, VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT, mipLevels, 1); @@ -66,9 +65,9 @@ public void cleanupStgBuffer() { } } - private void createStgBuffer(MemoryAllocator memoryAllocator, ByteBuffer data) { + private void createStgBuffer(Device device, ByteBuffer data) { int size = width * height * BYTES_PER_PIXEL; - stgBuffer = new VulkanBuffer(memoryAllocator, size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, + stgBuffer = new VulkanBuffer(device, size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); long mappedMemory = stgBuffer.map(); ByteBuffer buffer = MemoryUtil.memByteBuffer(mappedMemory, (int) stgBuffer.getRequestedSize()); diff --git a/booksamples/chapter-12/src/main/java/org/vulkanb/eng/graph/vk/VulkanBuffer.java b/booksamples/chapter-12/src/main/java/org/vulkanb/eng/graph/vk/VulkanBuffer.java index 73984604..5681384a 100644 --- a/booksamples/chapter-12/src/main/java/org/vulkanb/eng/graph/vk/VulkanBuffer.java +++ b/booksamples/chapter-12/src/main/java/org/vulkanb/eng/graph/vk/VulkanBuffer.java @@ -16,14 +16,14 @@ public class VulkanBuffer { private long allocation; private long buffer; + private Device device; private long mappedMemory; - private MemoryAllocator memoryAllocator; private PointerBuffer pb; private long requestedSize; - public VulkanBuffer(MemoryAllocator memoryAllocator, long size, int bufferUsage, int memoryUsage, + public VulkanBuffer(Device device, long size, int bufferUsage, int memoryUsage, int requiredFlags) { - this.memoryAllocator = memoryAllocator; + this.device = device; requestedSize = size; try (MemoryStack stack = MemoryStack.stackPush()) { VkBufferCreateInfo bufferCreateInfo = VkBufferCreateInfo.callocStack(stack) @@ -38,7 +38,7 @@ public VulkanBuffer(MemoryAllocator memoryAllocator, long size, int bufferUsage, PointerBuffer pAllocation = stack.callocPointer(1); LongBuffer lp = stack.mallocLong(1); - vkCheck(vmaCreateBuffer(memoryAllocator.getVmaAllocator(), bufferCreateInfo, allocInfo, lp, + vkCheck(vmaCreateBuffer(device.getMemoryAllocator().getVmaAllocator(), bufferCreateInfo, allocInfo, lp, pAllocation, null), "Failed to create buffer"); buffer = lp.get(0); allocation = pAllocation.get(0); @@ -49,7 +49,7 @@ public VulkanBuffer(MemoryAllocator memoryAllocator, long size, int bufferUsage, public void cleanup() { pb.free(); unMap(); - vmaDestroyBuffer(memoryAllocator.getVmaAllocator(), buffer, allocation); + vmaDestroyBuffer(device.getMemoryAllocator().getVmaAllocator(), buffer, allocation); } public long getBuffer() { @@ -62,7 +62,7 @@ public long getRequestedSize() { public long map() { if (mappedMemory == NULL) { - vkCheck(vmaMapMemory(memoryAllocator.getVmaAllocator(), allocation, pb), + vkCheck(vmaMapMemory(device.getMemoryAllocator().getVmaAllocator(), allocation, pb), "Failed to map allocation"); mappedMemory = pb.get(0); } @@ -71,7 +71,7 @@ public long map() { public void unMap() { if (mappedMemory != NULL) { - vmaUnmapMemory(memoryAllocator.getVmaAllocator(), allocation); + vmaUnmapMemory(device.getMemoryAllocator().getVmaAllocator(), allocation); mappedMemory = NULL; } } diff --git a/booksamples/chapter-12/src/main/java/org/vulkanb/eng/graph/vk/VulkanMesh.java b/booksamples/chapter-12/src/main/java/org/vulkanb/eng/graph/vk/VulkanMesh.java index 605de196..a4d6f344 100644 --- a/booksamples/chapter-12/src/main/java/org/vulkanb/eng/graph/vk/VulkanMesh.java +++ b/booksamples/chapter-12/src/main/java/org/vulkanb/eng/graph/vk/VulkanMesh.java @@ -32,14 +32,14 @@ public VulkanMesh(String id, VulkanBuffer verticesBuffer, VulkanBuffer indicesBu this.material = material; } - private static TransferBuffers createIndicesBuffers(MemoryAllocator memoryAllocator, MeshData meshData) { + private static TransferBuffers createIndicesBuffers(Device device, MeshData meshData) { int[] indices = meshData.indices(); int numIndices = indices.length; int bufferSize = numIndices * GraphConstants.INT_LENGTH; - VulkanBuffer srcBuffer = new VulkanBuffer(memoryAllocator, bufferSize, + VulkanBuffer srcBuffer = new VulkanBuffer(device, bufferSize, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); - VulkanBuffer dstBuffer = new VulkanBuffer(memoryAllocator, bufferSize, + VulkanBuffer dstBuffer = new VulkanBuffer(device, bufferSize, VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_INDEX_BUFFER_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, 0); long mapppedMemory = srcBuffer.map(); @@ -50,7 +50,7 @@ private static TransferBuffers createIndicesBuffers(MemoryAllocator memoryAlloca return new TransferBuffers(srcBuffer, dstBuffer); } - private static TransferBuffers createVerticesBuffers(MemoryAllocator memoryAllocator, MeshData meshData) { + private static TransferBuffers createVerticesBuffers(Device device, MeshData meshData) { float[] positions = meshData.positions(); float[] normals = meshData.normals(); float[] tangents = meshData.tangents(); @@ -62,9 +62,9 @@ private static TransferBuffers createVerticesBuffers(MemoryAllocator memoryAlloc int numElements = positions.length + normals.length + +tangents.length + biTangents.length + textCoords.length; int bufferSize = numElements * GraphConstants.FLOAT_LENGTH; - VulkanBuffer srcBuffer = new VulkanBuffer(memoryAllocator, bufferSize, + VulkanBuffer srcBuffer = new VulkanBuffer(device, bufferSize, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); - VulkanBuffer dstBuffer = new VulkanBuffer(memoryAllocator, bufferSize, + VulkanBuffer dstBuffer = new VulkanBuffer(device, bufferSize, VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, 0); long mappedMemory = srcBuffer.map(); @@ -95,8 +95,7 @@ private static TransferBuffers createVerticesBuffers(MemoryAllocator memoryAlloc return new TransferBuffers(srcBuffer, dstBuffer); } - public static VulkanMesh[] loadMeshes(MemoryAllocator memoryAllocator, TextureCache textureCache, - CommandPool commandPool, Queue queue, MeshData[] meshDataList) { + public static VulkanMesh[] loadMeshes(TextureCache textureCache, CommandPool commandPool, Queue queue, MeshData[] meshDataList) { int numMeshes = meshDataList != null ? meshDataList.length : 0; VulkanMesh[] meshes = new VulkanMesh[numMeshes]; @@ -109,21 +108,21 @@ public static VulkanMesh[] loadMeshes(MemoryAllocator memoryAllocator, TextureCa VulkanBuffer[] indicesTransferBuffers = new VulkanBuffer[numMeshes]; for (int i = 0; i < numMeshes; i++) { MeshData meshData = meshDataList[i]; - TransferBuffers verticesBuffers = createVerticesBuffers(memoryAllocator, meshData); - TransferBuffers indicesBuffers = createIndicesBuffers(memoryAllocator, meshData); + TransferBuffers verticesBuffers = createVerticesBuffers(device, meshData); + TransferBuffers indicesBuffers = createIndicesBuffers(device, meshData); positionTransferBuffers[i] = verticesBuffers.srcBuffer(); indicesTransferBuffers[i] = indicesBuffers.srcBuffer(); Material material = meshData.material(); String texturePath = material != null ? material.getTexturePath() : null; - Texture texture = textureCache.createTexture(memoryAllocator, texturePath, VK_FORMAT_R8G8B8A8_SRGB); + Texture texture = textureCache.createTexture(device, texturePath, VK_FORMAT_R8G8B8A8_SRGB); String normalMapPath = material != null ? material.getNormalMapPath() : null; - Texture normalMapTexture = textureCache.createTexture(memoryAllocator, normalMapPath, VK_FORMAT_R8G8B8A8_UNORM); + Texture normalMapTexture = textureCache.createTexture(device, normalMapPath, VK_FORMAT_R8G8B8A8_UNORM); String metalRoughPath = material != null ? material.getMetalRoughPath() : null; - Texture metalRougTexture = textureCache.createTexture(memoryAllocator, metalRoughPath, VK_FORMAT_R8G8B8A8_SRGB); + Texture metalRougTexture = textureCache.createTexture(device, metalRoughPath, VK_FORMAT_R8G8B8A8_SRGB); meshes[i] = new VulkanMesh(meshData.id(), verticesBuffers.dstBuffer(), indicesBuffers.dstBuffer(), meshData.indices().length, texture, normalMapTexture, metalRougTexture, material);