Fixed by initializing the data.
This commit is contained in:
parent
c905ef9ca7
commit
6d29fb718b
1 changed files with 15 additions and 16 deletions
|
|
@ -36,6 +36,7 @@ void VulkanEngine::init()
|
|||
init_descriptors();
|
||||
init_pipelines();
|
||||
_gui.init_imgui(VulkanEngine::Get());
|
||||
init_default_data();
|
||||
|
||||
//everything went fine
|
||||
_isInitialized = true;
|
||||
|
|
@ -183,7 +184,7 @@ void VulkanEngine::draw_geometry(VkCommandBuffer cmd)
|
|||
|
||||
VkViewport viewport{
|
||||
.x = 0,
|
||||
.y = 0,
|
||||
.y = 0,
|
||||
.width = (float)_drawExtent.width,
|
||||
.height = (float)_drawExtent.height,
|
||||
.minDepth = 0.0f,
|
||||
|
|
@ -208,7 +209,7 @@ void VulkanEngine::draw_geometry(VkCommandBuffer cmd)
|
|||
.vertexBuffer = rectangle.vertexBufferAddress,
|
||||
};
|
||||
|
||||
vkCmdPushConstants(cmd, _meshPipelineLayout, VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(GPUDrawPushConstants),
|
||||
vkCmdPushConstants(cmd, _meshPipelineLayout, VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(GPUDrawPushConstants),
|
||||
&push_constants);
|
||||
vkCmdBindIndexBuffer(cmd, rectangle.indexBuffer.buffer, 0, VK_INDEX_TYPE_UINT32);
|
||||
|
||||
|
|
@ -259,14 +260,14 @@ void VulkanEngine::init_vulkan() {
|
|||
.synchronization2 = true,
|
||||
.dynamicRendering = true,
|
||||
};
|
||||
|
||||
|
||||
//vulkan 1.2 features
|
||||
VkPhysicalDeviceVulkan12Features features12{
|
||||
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES,
|
||||
.descriptorIndexing = true,
|
||||
.bufferDeviceAddress = true,
|
||||
};
|
||||
|
||||
|
||||
// use vkbootstrap to select a gpu
|
||||
// We want a gpu that can write to the SDL surface
|
||||
vkb::PhysicalDeviceSelector selector{ vkb_inst };
|
||||
|
|
@ -294,7 +295,7 @@ void VulkanEngine::init_vulkan() {
|
|||
.device = _device,
|
||||
.instance = _instance,
|
||||
};
|
||||
|
||||
|
||||
vmaCreateAllocator(&allocatorInfo, &_allocator);
|
||||
|
||||
_mainDeletionQueue.push_function([&]() {
|
||||
|
|
@ -345,7 +346,7 @@ void VulkanEngine::init_swapchain() {
|
|||
_drawImage.imageFormat = VK_FORMAT_R16G16B16A16_SFLOAT;
|
||||
_drawImage.imageExtent = drawImageExtent;
|
||||
|
||||
VkImageUsageFlags drawImageUsages =
|
||||
VkImageUsageFlags drawImageUsages =
|
||||
VK_IMAGE_USAGE_TRANSFER_SRC_BIT
|
||||
| VK_IMAGE_USAGE_TRANSFER_DST_BIT
|
||||
| VK_IMAGE_USAGE_STORAGE_BIT
|
||||
|
|
@ -357,7 +358,7 @@ void VulkanEngine::init_swapchain() {
|
|||
.usage = VMA_MEMORY_USAGE_GPU_ONLY,
|
||||
.requiredFlags = VkMemoryPropertyFlags(VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT),
|
||||
};
|
||||
|
||||
|
||||
//allocate and create the image
|
||||
vmaCreateImage(_allocator, &rimg_info, &rimg_allocinfo, &_drawImage.image, &_drawImage.allocation, nullptr);
|
||||
|
||||
|
|
@ -454,7 +455,7 @@ void VulkanEngine::init_descriptors() {
|
|||
.imageView = _drawImage.imageView,
|
||||
.imageLayout = VK_IMAGE_LAYOUT_GENERAL,
|
||||
};
|
||||
|
||||
|
||||
VkWriteDescriptorSet drawImageWrite{
|
||||
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
|
||||
.dstSet = _drawImageDescriptors,
|
||||
|
|
@ -521,7 +522,7 @@ void VulkanEngine::init_background_pipelines()
|
|||
.offset = 0,
|
||||
.size = sizeof(ComputePushConstants),
|
||||
};
|
||||
|
||||
|
||||
VkPipelineLayoutCreateInfo computeLayout{
|
||||
.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
|
||||
.setLayoutCount = 1,
|
||||
|
|
@ -529,7 +530,7 @@ void VulkanEngine::init_background_pipelines()
|
|||
.pushConstantRangeCount = 1,
|
||||
.pPushConstantRanges = &pushConstant,
|
||||
};
|
||||
|
||||
|
||||
VK_CHECK(vkCreatePipelineLayout(_device, &computeLayout, nullptr, &_gradientPipelineLayout));
|
||||
|
||||
// final cleanup
|
||||
|
|
@ -577,7 +578,7 @@ void VulkanEngine::immediate_submit(std::function<void(VkCommandBuffer cmd)>&& f
|
|||
VkSubmitInfo2 submit = vkinit::submit_info(&cmdinfo, nullptr, nullptr);
|
||||
|
||||
VK_CHECK(vkQueueSubmit2(_graphicsQueue, 1, &submit, _immFence));
|
||||
VK_CHECK(vkWaitForFences(_device, 1, &_immFence, true,9999999999));
|
||||
VK_CHECK(vkWaitForFences(_device, 1, &_immFence, true,9999999999));
|
||||
}
|
||||
|
||||
void VulkanEngine::init_mesh_pipeline()
|
||||
|
|
@ -705,7 +706,7 @@ AllocatedBuffer VulkanEngine::create_buffer(size_t allocSize, VkBufferUsageFlags
|
|||
return newBuffer;
|
||||
}
|
||||
|
||||
void VulkanEngine::destroy_buffer(const AllocatedBuffer& buffer)
|
||||
void VulkanEngine::destroy_buffer(const AllocatedBuffer& buffer)
|
||||
{
|
||||
vmaDestroyBuffer(_allocator, buffer.buffer, buffer.allocation);
|
||||
}
|
||||
|
|
@ -734,7 +735,7 @@ GPUMeshBuffers VulkanEngine::uploadMesh(std::span<uint32_t> indices, std::span<V
|
|||
|
||||
newSurface.indexBuffer = create_buffer(indexBufferSize,
|
||||
VK_BUFFER_USAGE_INDEX_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT,
|
||||
VMA_MEMORY_USAGE_GPU_ONLY);
|
||||
VMA_MEMORY_USAGE_GPU_ONLY);
|
||||
|
||||
AllocatedBuffer staging = create_buffer(vertexBufferSize + indexBufferSize, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VMA_MEMORY_USAGE_CPU_ONLY);
|
||||
|
||||
|
|
@ -750,7 +751,7 @@ GPUMeshBuffers VulkanEngine::uploadMesh(std::span<uint32_t> indices, std::span<V
|
|||
.size = vertexBufferSize,
|
||||
};
|
||||
|
||||
vkCmdCopyBuffer(cmd, staging.buffer,
|
||||
vkCmdCopyBuffer(cmd, staging.buffer,
|
||||
newSurface.vertexBuffer.buffer, 1,
|
||||
&vertexCopy);
|
||||
|
||||
|
|
@ -800,5 +801,3 @@ void VulkanEngine::init_default_data() {
|
|||
destroy_buffer(rectangle.vertexBuffer);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue