diff --git a/Application/main.cpp b/Application/main.cpp index 6df57d3..ce01480 100644 --- a/Application/main.cpp +++ b/Application/main.cpp @@ -31,7 +31,7 @@ int main(int ac, char** av) Scop::SceneDescriptor main_scene_desc; main_scene_desc.fragment_shader = Scop::RenderCore::Get().GetDefaultFragmentShader(); - main_scene_desc.camera = std::make_shared(Scop::Vec3f{ -10.0f, 0.0f, 0.0f }); + main_scene_desc.camera = std::make_shared(Scop::Vec3f{ -10.0f, 0.0f, 0.0f }, 80.f); Scop::Scene& main_scene = splash_scene->AddChildScene("main", std::move(main_scene_desc)); Scop::Vec2ui32 skybox_size; diff --git a/ScopEngine/Runtime/Includes/Maths/Mat4.inl b/ScopEngine/Runtime/Includes/Maths/Mat4.inl index 7f67930..b7c7ff8 100644 --- a/ScopEngine/Runtime/Includes/Maths/Mat4.inl +++ b/ScopEngine/Runtime/Includes/Maths/Mat4.inl @@ -776,7 +776,7 @@ namespace Scop { angle /= T(2.0); - T yScale = angle.GetTan(); + T yScale = std::abs(angle.GetTan()); return Mat4( T(1.0) / (ratio * yScale), T(0.0), T(0.0), T(0.0), diff --git a/ScopEngine/Runtime/Includes/Renderer/Image.h b/ScopEngine/Runtime/Includes/Renderer/Image.h index 79288f4..1741a66 100644 --- a/ScopEngine/Runtime/Includes/Renderer/Image.h +++ b/ScopEngine/Runtime/Includes/Renderer/Image.h @@ -80,8 +80,8 @@ namespace Scop std::vector candidates = { VK_FORMAT_D32_SFLOAT, VK_FORMAT_D32_SFLOAT_S8_UINT, VK_FORMAT_D24_UNORM_S8_UINT }; VkFormat format = kvfFindSupportFormatInCandidates(RenderCore::Get().GetDevice(), candidates.data(), candidates.size(), VK_IMAGE_TILING_OPTIMAL, VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT); Image::Init(ImageType::Depth, width, height, format, VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, is_multisampled); - Image::CreateImageView(VK_IMAGE_VIEW_TYPE_2D, VK_IMAGE_ASPECT_DEPTH_BIT); Image::TransitionLayout(VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL); + Image::CreateImageView(VK_IMAGE_VIEW_TYPE_2D, VK_IMAGE_ASPECT_DEPTH_BIT); } ~DepthImage() = default; }; diff --git a/ScopEngine/Runtime/Sources/Graphics/Scene.cpp b/ScopEngine/Runtime/Sources/Graphics/Scene.cpp index 49cd2e1..5613789 100644 --- a/ScopEngine/Runtime/Sources/Graphics/Scene.cpp +++ b/ScopEngine/Runtime/Sources/Graphics/Scene.cpp @@ -108,6 +108,7 @@ namespace Scop void Scene::Destroy() { + RenderCore::Get().WaitDeviceIdle(); p_skybox.reset(); m_depth.Destroy(); m_actors.clear(); diff --git a/ScopEngine/Runtime/Sources/Renderer/Buffer.cpp b/ScopEngine/Runtime/Sources/Renderer/Buffer.cpp index 4b1d2f7..56ca372 100644 --- a/ScopEngine/Runtime/Sources/Renderer/Buffer.cpp +++ b/ScopEngine/Runtime/Sources/Renderer/Buffer.cpp @@ -97,6 +97,7 @@ namespace Scop { if(m_buffer == VK_NULL_HANDLE) return; + RenderCore::Get().WaitDeviceIdle(); RenderCore::Get().vkDestroyBuffer(RenderCore::Get().GetDevice(), m_buffer, nullptr); RenderCore::Get().GetAllocator().Deallocate(m_memory); m_buffer = VK_NULL_HANDLE; diff --git a/ScopEngine/Runtime/Sources/Renderer/Image.cpp b/ScopEngine/Runtime/Sources/Renderer/Image.cpp index 2d8a348..03db6cc 100644 --- a/ScopEngine/Runtime/Sources/Renderer/Image.cpp +++ b/ScopEngine/Runtime/Sources/Renderer/Image.cpp @@ -80,6 +80,8 @@ namespace Scop default: break; } kvfTransitionImageLayout(RenderCore::Get().GetDevice(), m_image, kvf_type, cmd, m_format, m_layout, new_layout, is_single_time_cmd_buffer); + if(is_single_time_cmd_buffer) + kvfDestroyCommandBuffer(RenderCore::Get().GetDevice(), cmd); m_layout = new_layout; } @@ -94,8 +96,8 @@ namespace Scop if(m_type == ImageType::Color || m_type == ImageType::Cube) { VkImageLayout old_layout = m_layout; - TransitionLayout(VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, cmd); subresource_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + TransitionLayout(VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, cmd); VkClearColorValue clear_color = VkClearColorValue({ { color.x, color.y, color.z, color.w } }); RenderCore::Get().vkCmdClearColorImage(cmd, m_image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &clear_color, 1, &subresource_range); TransitionLayout(old_layout, cmd); @@ -126,6 +128,7 @@ namespace Scop void Image::Destroy() noexcept { + RenderCore::Get().WaitDeviceIdle(); DestroySampler(); DestroyImageView(); diff --git a/ScopEngine/Runtime/Sources/Renderer/Pipelines/Graphics.cpp b/ScopEngine/Runtime/Sources/Renderer/Pipelines/Graphics.cpp index e3c3865..2d2d284 100644 --- a/ScopEngine/Runtime/Sources/Renderer/Pipelines/Graphics.cpp +++ b/ScopEngine/Runtime/Sources/Renderer/Pipelines/Graphics.cpp @@ -26,7 +26,6 @@ namespace Scop set_layouts.insert(set_layouts.end(), p_fragment_shader->GetPipelineLayout().set_layouts.begin(), p_fragment_shader->GetPipelineLayout().set_layouts.end()); m_pipeline_layout = kvfCreatePipelineLayout(RenderCore::Get().GetDevice(), set_layouts.data(), set_layouts.size(), push_constants.data(), push_constants.size()); - TransitionAttachments(); CreateFramebuffers(m_attachments, descriptor.clear_color_attachments); VkPhysicalDeviceFeatures features{}; @@ -66,6 +65,7 @@ namespace Scop bool GraphicPipeline::BindPipeline(VkCommandBuffer command_buffer, std::size_t framebuffer_index, std::array clear) noexcept { TransitionAttachments(command_buffer); + VkFramebuffer fb = m_framebuffers[framebuffer_index]; VkExtent2D fb_extent = kvfGetFramebufferSize(fb); @@ -128,6 +128,8 @@ namespace Scop void GraphicPipeline::CreateFramebuffers(const std::vector>& render_targets, bool clear_attachments) { + TransitionAttachments(); + std::vector attachments; std::vector attachment_views; if(p_renderer) @@ -138,13 +140,13 @@ namespace Scop for(NonOwningPtr image : render_targets) { - attachments.push_back(kvfBuildAttachmentDescription((kvfIsDepthFormat(image->GetFormat()) ? KVF_IMAGE_DEPTH : KVF_IMAGE_COLOR), image->GetFormat(), image->GetLayout(), image->GetLayout(), clear_attachments, VK_SAMPLE_COUNT_1_BIT)); + attachments.push_back(kvfBuildAttachmentDescription(KVF_IMAGE_COLOR, image->GetFormat(), image->GetLayout(), image->GetLayout(), clear_attachments, VK_SAMPLE_COUNT_1_BIT)); attachment_views.push_back(image->GetImageView()); } if(p_depth) { - attachments.push_back(kvfBuildAttachmentDescription((kvfIsDepthFormat(p_depth->GetFormat()) ? KVF_IMAGE_DEPTH : KVF_IMAGE_COLOR), p_depth->GetFormat(), p_depth->GetLayout(), p_depth->GetLayout(), clear_attachments, VK_SAMPLE_COUNT_1_BIT)); + attachments.push_back(kvfBuildAttachmentDescription(KVF_IMAGE_DEPTH, p_depth->GetFormat(), p_depth->GetLayout(), p_depth->GetLayout(), clear_attachments, VK_SAMPLE_COUNT_1_BIT)); attachment_views.push_back(p_depth->GetImageView()); } diff --git a/ScopEngine/Runtime/Sources/Renderer/Pipelines/Shader.cpp b/ScopEngine/Runtime/Sources/Renderer/Pipelines/Shader.cpp index 61a8da8..1cb03fb 100644 --- a/ScopEngine/Runtime/Sources/Renderer/Pipelines/Shader.cpp +++ b/ScopEngine/Runtime/Sources/Renderer/Pipelines/Shader.cpp @@ -12,7 +12,6 @@ namespace Scop case ShaderType::Vertex : m_stage = VK_SHADER_STAGE_VERTEX_BIT; break; case ShaderType::Fragment : m_stage = VK_SHADER_STAGE_FRAGMENT_BIT; break; case ShaderType::Compute : m_stage = VK_SHADER_STAGE_COMPUTE_BIT; break; - default : FatalError("wtf"); break; } m_module = kvfCreateShaderModule(RenderCore::Get().GetDevice(), m_bytecode.data(), m_bytecode.size()); @@ -56,6 +55,8 @@ namespace Scop void Shader::Destroy() { + if(m_module == VK_NULL_HANDLE) + return; kvfDestroyShaderModule(RenderCore::Get().GetDevice(), m_module); m_module = VK_NULL_HANDLE; Message("Vulkan: shader module destroyed"); @@ -68,8 +69,7 @@ namespace Scop Shader::~Shader() { - if(m_module != VK_NULL_HANDLE) - Destroy(); + Destroy(); } std::shared_ptr LoadShaderFromFile(const std::filesystem::path& filepath, ShaderType type, ShaderLayout layout) diff --git a/ScopEngine/ThirdParty/KVF/kvf.h b/ScopEngine/ThirdParty/KVF/kvf.h index 98f237b..dca0eb8 100755 --- a/ScopEngine/ThirdParty/KVF/kvf.h +++ b/ScopEngine/ThirdParty/KVF/kvf.h @@ -2544,7 +2544,7 @@ VkAttachmentDescription kvfBuildAttachmentDescription(KvfImageType type, VkForma __KvfSwapchain* kvf_swapchain = __kvfGetKvfSwapchainFromVkSwapchainKHR(swapchain); KVF_ASSERT(kvf_swapchain != NULL); KVF_ASSERT(kvf_swapchain->images_count != 0); - return kvfBuildAttachmentDescription(KVF_IMAGE_COLOR, kvf_swapchain->images_format, VK_IMAGE_LAYOUT_UNDEFINED,VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, clear, VK_SAMPLE_COUNT_1_BIT); + return kvfBuildAttachmentDescription(KVF_IMAGE_COLOR, kvf_swapchain->images_format, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, clear, VK_SAMPLE_COUNT_1_BIT); } #endif