Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 12 additions & 15 deletions src/graphics/vulkan/pipelines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,35 @@ void GLTFMetallic_Roughness::build_pipelines(VulkanEngine* engine) {

create_material_layout(engine);
VkPipelineLayout newLayout = create_pipeline_layout(engine);

device = static_cast<VkDevice>(engine->device);
opaquePipeline.layout = newLayout;
transparentPipeline.layout = newLayout;

build_opaque_pipeline(engine, meshVertexShader, meshFragShader, newLayout);
build_transparent_pipeline(engine, meshVertexShader, meshFragShader,
newLayout);

vkDestroyShaderModule(engine->_device, meshFragShader, nullptr);
vkDestroyShaderModule(engine->_device, meshVertexShader, nullptr);
vkDestroyShaderModule(static_cast<VkDevice>(engine->device), meshFragShader, nullptr);
vkDestroyShaderModule(static_cast<VkDevice>(engine->device), meshVertexShader, nullptr);
}

VkShaderModule GLTFMetallic_Roughness::load_shader(VulkanEngine* engine,
const char* relative_path,
const char* type) {
VkShaderModule shaderModule;
if (!vkutil::load_shader_module(relative_path, engine->_device,
if (!vkutil::load_shader_module(relative_path, static_cast<VkDevice>(engine->device),
&shaderModule)) {
fmt::println("Error when building the {} shader module", type);
}
return shaderModule;
}

void GLTFMetallic_Roughness::create_material_layout(VulkanEngine* engine) {
DescriptorLayoutBuilder layoutBuilder;
layoutBuilder.add_binding(0, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
layoutBuilder.add_binding(1, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER);
layoutBuilder.add_binding(2, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER);

materialLayout = layoutBuilder.build(
engine->_device,
VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT);
materialLayout.create(static_cast<VkDevice>(engine->device),
VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT,
{{0, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER},
{1, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER},
{2, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER}});
}

VkPipelineLayout GLTFMetallic_Roughness::create_pipeline_layout(
Expand All @@ -60,7 +57,7 @@ VkPipelineLayout GLTFMetallic_Roughness::create_pipeline_layout(
mesh_layout_info.pushConstantRangeCount = 1;

VkPipelineLayout newLayout;
VK_CHECK(vkCreatePipelineLayout(engine->_device, &mesh_layout_info, nullptr,
VK_CHECK(vkCreatePipelineLayout(static_cast<VkDevice>(engine->device), &mesh_layout_info, nullptr,
&newLayout));

return newLayout;
Expand All @@ -82,7 +79,7 @@ void GLTFMetallic_Roughness::build_opaque_pipeline(VulkanEngine* engine,
pipelineBuilder.set_depth_format(engine->_depthImage->get().imageFormat);
pipelineBuilder._pipelineLayout = layout;

opaquePipeline.pipeline = pipelineBuilder.build_pipeline(engine->_device);
opaquePipeline.pipeline = pipelineBuilder.build_pipeline(static_cast<VkDevice>(engine->device));
}

void GLTFMetallic_Roughness::build_transparent_pipeline(
Expand All @@ -95,7 +92,7 @@ void GLTFMetallic_Roughness::build_transparent_pipeline(
pipelineBuilder._pipelineLayout = layout;

transparentPipeline.pipeline =
pipelineBuilder.build_pipeline(engine->_device);
pipelineBuilder.build_pipeline(static_cast<VkDevice>(engine->device));
}

MaterialInstance GLTFMetallic_Roughness::write_material(
Expand Down
16 changes: 8 additions & 8 deletions src/graphics/vulkan/vk_command_buffers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,31 @@ void CommandBuffers::init_commands(VulkanEngine* vk_engine) {

for (auto& _frame : vk_engine->command_buffers_container._frames) {
VkCommandPool commandPool;
VK_CHECK(vkCreateCommandPool(vk_engine->_device, &commandPoolInfo,
VK_CHECK(vkCreateCommandPool(static_cast<VkDevice>(vk_engine->device), &commandPoolInfo,
nullptr,
&commandPool));

_frame._commandPool = std::make_unique<VulkanCommandPool>(vk_engine->_device, commandPool);
_frame._commandPool = std::make_unique<VulkanCommandPool>(static_cast<VkDevice>(vk_engine->device), commandPool);

// allocate the default command buffer that we will use for rendering
VkCommandBufferAllocateInfo cmdAllocInfo =
vkinit::command_buffer_allocate_info(_frame._commandPool->get(), 1);

VK_CHECK(vkAllocateCommandBuffers(vk_engine->_device, &cmdAllocInfo,
VK_CHECK(vkAllocateCommandBuffers(static_cast<VkDevice>(vk_engine->device), &cmdAllocInfo,
&_frame._mainCommandBuffer));
}

VkCommandPool immCommandPool;
VK_CHECK(vkCreateCommandPool(vk_engine->_device, &commandPoolInfo, nullptr,
VK_CHECK(vkCreateCommandPool(static_cast<VkDevice>(vk_engine->device), &commandPoolInfo, nullptr,
&immCommandPool));

vk_engine->command_buffers_container._immCommandPool = std::make_unique<VulkanCommandPool>(vk_engine->_device, immCommandPool);
vk_engine->command_buffers_container._immCommandPool = std::make_unique<VulkanCommandPool>(static_cast<VkDevice>(vk_engine->device), immCommandPool);

// allocate the command buffer for immediate submits
const VkCommandBufferAllocateInfo cmdAllocInfo =
vkinit::command_buffer_allocate_info(vk_engine->command_buffers_container._immCommandPool->get(), 1);

VK_CHECK(vkAllocateCommandBuffers(vk_engine->_device, &cmdAllocInfo,
VK_CHECK(vkAllocateCommandBuffers(static_cast<VkDevice>(vk_engine->device), &cmdAllocInfo,
&(vk_engine->command_buffers_container._immCommandBuffer)));

// Smart pointer will automatically handle cleanup - no need for deletion queue
Expand All @@ -46,7 +46,7 @@ void CommandBuffers::init_commands(VulkanEngine* vk_engine) {
void CommandBuffers::immediate_submit(
std::function<void(VkCommandBuffer cmd)>&& function,
VulkanEngine* vk_engine) const {
VK_CHECK(vkResetFences(vk_engine->_device, 1, vk_engine->command_buffers_container._immFence->getPtr()));
VK_CHECK(vkResetFences(static_cast<VkDevice>(vk_engine->device), 1, vk_engine->command_buffers_container._immFence->getPtr()));
VK_CHECK(vkResetCommandBuffer(vk_engine->command_buffers_container._immCommandBuffer, 0));

const VkCommandBuffer cmd = vk_engine->command_buffers_container._immCommandBuffer;
Expand All @@ -71,6 +71,6 @@ void CommandBuffers::immediate_submit(
VK_CHECK(vkQueueSubmit2(vk_engine->_graphicsQueue, 1, &submit,
vk_engine->command_buffers_container._immFence->get()));

VK_CHECK(vkWaitForFences(vk_engine->_device, 1, vk_engine->command_buffers_container._immFence->getPtr(), true,
VK_CHECK(vkWaitForFences(static_cast<VkDevice>(vk_engine->device), 1, vk_engine->command_buffers_container._immFence->getPtr(), true,
9999999999));
}
18 changes: 9 additions & 9 deletions src/graphics/vulkan/vk_command_buffers_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ void CommandBuffersContainer::init_sync_structures(VulkanEngine* vk_engine) {

for (auto& _frame : _frames) {
VkFence renderFence;
VK_CHECK(vkCreateFence(vk_engine->_device, &fenceCreateInfo, nullptr, &renderFence));
_frame._renderFence = std::make_unique<VulkanFence>(vk_engine->_device, renderFence);
VK_CHECK(vkCreateFence(static_cast<VkDevice>(vk_engine->device), &fenceCreateInfo, nullptr, &renderFence));
_frame._renderFence = std::make_unique<VulkanFence>(static_cast<VkDevice>(vk_engine->device), renderFence);

VkSemaphore swapchainSemaphore, renderSemaphore;
VK_CHECK(vkCreateSemaphore(vk_engine->_device, &semaphoreCreateInfo, nullptr, &swapchainSemaphore));
VK_CHECK(vkCreateSemaphore(vk_engine->_device, &semaphoreCreateInfo, nullptr, &renderSemaphore));
_frame._swapchainSemaphore = std::make_unique<VulkanSemaphore>(vk_engine->_device, swapchainSemaphore);
_frame._renderSemaphore = std::make_unique<VulkanSemaphore>(vk_engine->_device, renderSemaphore);
VK_CHECK(vkCreateSemaphore(static_cast<VkDevice>(vk_engine->device), &semaphoreCreateInfo, nullptr, &swapchainSemaphore));
VK_CHECK(vkCreateSemaphore(static_cast<VkDevice>(vk_engine->device), &semaphoreCreateInfo, nullptr, &renderSemaphore));

_frame._swapchainSemaphore = std::make_unique<VulkanSemaphore>(static_cast<VkDevice>(vk_engine->device), swapchainSemaphore);
_frame._renderSemaphore = std::make_unique<VulkanSemaphore>(static_cast<VkDevice>(vk_engine->device), renderSemaphore);
}

VkFence immFence;
VK_CHECK(vkCreateFence(vk_engine->_device, &fenceCreateInfo, nullptr, &immFence));
_immFence = std::make_unique<VulkanFence>(vk_engine->_device, immFence);
VK_CHECK(vkCreateFence(static_cast<VkDevice>(vk_engine->device), &fenceCreateInfo, nullptr, &immFence));
_immFence = std::make_unique<VulkanFence>(static_cast<VkDevice>(vk_engine->device), immFence);
}
Loading
Loading