diff --git a/.vscode/settings.json b/.vscode/settings.json index 091b4a86..b44b6f1c 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -81,6 +81,25 @@ "unordered_set": "cpp", "valarray": "cpp", "variant": "cpp", - "algorithm": "cpp" + "algorithm": "cpp", + "bit": "cpp", + "*.tcc": "cpp", + "chrono": "cpp", + "cinttypes": "cpp", + "compare": "cpp", + "concepts": "cpp", + "expected": "cpp", + "functional": "cpp", + "iterator": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "random": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "format": "cpp", + "ranges": "cpp", + "stop_token": "cpp", + "cfenv": "cpp" }, } \ No newline at end of file diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index b32d842a..548c2e45 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -23,9 +23,10 @@ android:theme="@style/Application.Fullscreen"> diff --git a/src/Application.cpp b/src/Application.cpp index a745bc33..0525f50f 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -67,6 +67,9 @@ Assets::UniformBufferObject NextRendererApplication::GetUniformBufferO extent.width / static_cast(extent.height), 0.1f, 10000.0f); ubo.Projection[1][1] *= -1; #if ANDROID + ubo.Projection = glm::perspective(glm::radians(userSettings_.FieldOfView), + extent.height / static_cast(extent.width), 0.1f, 10000.0f); + ubo.Projection[1][1] *= -1; ubo.Projection = pre_rotate_mat * ubo.Projection; #endif // Inverting Y for Vulkan, https://matthewwellings.com/blog/the-new-vulkan-coordinate-system/ @@ -233,6 +236,7 @@ void NextRendererApplication::Render(VkCommandBuffer commandBuffer, co Statistics stats = {}; stats.FramebufferSize = Renderer::Window().FramebufferSize(); stats.FrameRate = frameRate; + stats.FrameTime = static_cast(timeDelta * 1000); stats.CamPosX = modelViewController_.Position()[0]; stats.CamPosY = modelViewController_.Position()[1]; @@ -254,7 +258,7 @@ void NextRendererApplication::Render(VkCommandBuffer commandBuffer, co stats.TotalSamples = totalNumberOfSamples_; } - userInterface_->Render(commandBuffer, Renderer::SwapChainFrameBuffer(imageIndex), stats); + userInterface_->Render(commandBuffer, Renderer::SwapChainFrameBuffer(imageIndex), stats, Renderer::GpuTimer()); } template diff --git a/src/Options.cpp b/src/Options.cpp index 91f40221..a11b4279 100644 --- a/src/Options.cpp +++ b/src/Options.cpp @@ -48,6 +48,7 @@ Options::Options(const int argc, const char* argv[]) ("help", "Display help message.") ("benchmark", bool_switch(&Benchmark)->default_value(false), "Run the application in benchmark mode.") ("savefile", bool_switch(&SaveFile)->default_value(false), "Save screenshot every benchmark finish.") + ("renderdoc", bool_switch(&RenderDoc)->default_value(false), "Attach renderdoc if avaliable.") ; desc.add(benchmark); diff --git a/src/Options.hpp b/src/Options.hpp index 354a1814..4df60914 100644 --- a/src/Options.hpp +++ b/src/Options.hpp @@ -22,6 +22,7 @@ class Options final // Application options. bool Benchmark{}; bool SaveFile{}; + bool RenderDoc{}; // Benchmark options. bool BenchmarkNextScenes{}; diff --git a/src/UserInterface.cpp b/src/UserInterface.cpp index 38a68bc8..be2d0305 100644 --- a/src/UserInterface.cpp +++ b/src/UserInterface.cpp @@ -24,6 +24,7 @@ #include #include "Utilities/FileHelper.hpp" +#include "Vulkan/VulkanBaseRenderer.hpp" namespace { @@ -94,7 +95,7 @@ UserInterface::UserInterface( // Window scaling and style. #if ANDROID - const auto scaleFactor = 4.0; + const auto scaleFactor = 1.5; #else const auto scaleFactor = 1.0;//window.ContentScale(); #endif @@ -130,7 +131,7 @@ UserInterface::~UserInterface() ImGui::DestroyContext(); } -void UserInterface::Render(VkCommandBuffer commandBuffer, const Vulkan::FrameBuffer& frameBuffer, const Statistics& statistics) +void UserInterface::Render(VkCommandBuffer commandBuffer, const Vulkan::FrameBuffer& frameBuffer, const Statistics& statistics, Vulkan::VulkanGpuTimer* gpuTimer) { #if !ANDROID ImGui_ImplGlfw_NewFrame(); @@ -143,7 +144,7 @@ void UserInterface::Render(VkCommandBuffer commandBuffer, const Vulkan::FrameBuf #if !ANDROID DrawSettings(); #endif - DrawOverlay(statistics); + DrawOverlay(statistics, gpuTimer); //ImGui::ShowStyleEditor(); ImGui::Render(); @@ -258,7 +259,7 @@ void UserInterface::DrawSettings() ImGui::End(); } -void UserInterface::DrawOverlay(const Statistics& statistics) +void UserInterface::DrawOverlay(const Statistics& statistics, Vulkan::VulkanGpuTimer* gpuTimer) { if (!Settings().ShowOverlay) { @@ -267,8 +268,13 @@ void UserInterface::DrawOverlay(const Statistics& statistics) const auto& io = ImGui::GetIO(); const float distance = 10.0f; +#if ANDROID + const ImVec2 pos = ImVec2(distance, distance); + const ImVec2 posPivot = ImVec2(0.0f, 0.0f); +#else const ImVec2 pos = ImVec2(io.DisplaySize.x - distance, distance); const ImVec2 posPivot = ImVec2(1.0f, 0.0f); +#endif ImGui::SetNextWindowPos(pos, ImGuiCond_Always, posPivot); ImGui::SetNextWindowBgAlpha(0.3f); // Transparent background @@ -285,11 +291,17 @@ void UserInterface::DrawOverlay(const Statistics& statistics) ImGui::Text("Statistics (%dx%d):", statistics.FramebufferSize.width, statistics.FramebufferSize.height); ImGui::Separator(); ImGui::Text("Frame rate: %.0f fps", statistics.FrameRate); - ImGui::Text("Primary ray rate: %.2f Gr/s", statistics.RayRate); - ImGui::Text("Accumulated samples: %u", statistics.TotalSamples); ImGui::Text("Campos: %.2f %.2f %.2f", statistics.CamPosX, statistics.CamPosY, statistics.CamPosZ); ImGui::Text("Tris: %d", statistics.TriCount); ImGui::Text("Instance: %d", statistics.InstanceCount); + + ImGui::Text("frametime: %.2fms", statistics.FrameTime); + // auto fetch timer & display + auto times = gpuTimer->FetchAllTimes(); + for(auto& time : times) + { + ImGui::Text("%s: %.2fms", std::get<0>(time).c_str(), std::get<1>(time)); + } } ImGui::End(); } diff --git a/src/UserInterface.hpp b/src/UserInterface.hpp index d07dfb0c..13bd2e23 100644 --- a/src/UserInterface.hpp +++ b/src/UserInterface.hpp @@ -10,6 +10,7 @@ namespace Vulkan class FrameBuffer; class RenderPass; class SwapChain; + class VulkanGpuTimer; } struct UserSettings; @@ -18,6 +19,7 @@ struct Statistics final { VkExtent2D FramebufferSize; float FrameRate; + float FrameTime; float RayRate; uint32_t TotalSamples; float CamPosX; @@ -42,7 +44,7 @@ class UserInterface final UserSettings& userSettings); ~UserInterface(); - void Render(VkCommandBuffer commandBuffer, const Vulkan::FrameBuffer& frameBuffer, const Statistics& statistics); + void Render(VkCommandBuffer commandBuffer, const Vulkan::FrameBuffer& frameBuffer, const Statistics& statistics, Vulkan::VulkanGpuTimer* gpuTimer); bool WantsToCaptureKeyboard() const; bool WantsToCaptureMouse() const; @@ -52,7 +54,7 @@ class UserInterface final private: void DrawSettings(); - void DrawOverlay(const Statistics& statistics); + void DrawOverlay(const Statistics& statistics, Vulkan::VulkanGpuTimer* gpuTimer); std::unique_ptr descriptorPool_; std::unique_ptr renderPass_; diff --git a/src/Vulkan/Device.cpp b/src/Vulkan/Device.cpp index 62498a51..f83cbb2a 100644 --- a/src/Vulkan/Device.cpp +++ b/src/Vulkan/Device.cpp @@ -120,6 +120,8 @@ Device::Device( vkGetDeviceQueue(device_, computeFamilyIndex_, 0, &computeQueue_); vkGetDeviceQueue(device_, presentFamilyIndex_, 0, &presentQueue_); //vkGetDeviceQueue(device_, transferFamilyIndex_, 0, &transferQueue_); + + vkGetPhysicalDeviceProperties(PhysicalDevice(), &deviceProp_); } Device::~Device() diff --git a/src/Vulkan/Device.hpp b/src/Vulkan/Device.hpp index 3c34a821..418cb35d 100644 --- a/src/Vulkan/Device.hpp +++ b/src/Vulkan/Device.hpp @@ -38,6 +38,8 @@ namespace Vulkan VkQueue PresentQueue() const { return presentQueue_; } //VkQueue TransferQueue() const { return transferQueue_; } + VkPhysicalDeviceProperties DeviceProperties() const { return deviceProp_; } + void WaitIdle() const; private: @@ -60,6 +62,8 @@ namespace Vulkan VkQueue computeQueue_{}; VkQueue presentQueue_{}; //VkQueue transferQueue_{}; + + VkPhysicalDeviceProperties deviceProp_; }; } diff --git a/src/Vulkan/LegacyDeferred/LegacyDeferredRenderer.cpp b/src/Vulkan/LegacyDeferred/LegacyDeferredRenderer.cpp index 4a41a8e6..625f9a64 100644 --- a/src/Vulkan/LegacyDeferred/LegacyDeferredRenderer.cpp +++ b/src/Vulkan/LegacyDeferred/LegacyDeferredRenderer.cpp @@ -150,54 +150,63 @@ void LegacyDeferredRenderer::Render(VkCommandBuffer commandBuffer, uint32_t imag renderPassInfo.renderArea.extent = SwapChain().Extent(); renderPassInfo.clearValueCount = static_cast(clearValues.size()); renderPassInfo.pClearValues = clearValues.data(); - - // make it to generate gbuffer - vkCmdBeginRenderPass(commandBuffer, &renderPassInfo, VK_SUBPASS_CONTENTS_INLINE); + { - const auto& scene = GetScene(); - - VkDescriptorSet descriptorSets[] = { gbufferPipeline_->DescriptorSet(imageIndex) }; - VkBuffer vertexBuffers[] = { scene.VertexBuffer().Handle() }; - const VkBuffer indexBuffer = scene.IndexBuffer().Handle(); - VkDeviceSize offsets[] = { 0 }; - - vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, gbufferPipeline_->Handle()); - vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, gbufferPipeline_->PipelineLayout().Handle(), 0, 1, descriptorSets, 0, nullptr); - vkCmdBindVertexBuffers(commandBuffer, 0, 1, vertexBuffers, offsets); - vkCmdBindIndexBuffer(commandBuffer, indexBuffer, 0, VK_INDEX_TYPE_UINT32); - - // indirect draw - vkCmdDrawIndexedIndirect(commandBuffer, scene.IndirectDrawBuffer().Handle(), 0, scene.GetIndirectDrawBatchCount(), sizeof(VkDrawIndexedIndirectCommand)); - } - vkCmdEndRenderPass(commandBuffer); - - ImageMemoryBarrier::Insert(commandBuffer, outputImage_->Handle(), subresourceRange, - 0, VK_ACCESS_SHADER_WRITE_BIT, VK_IMAGE_LAYOUT_UNDEFINED, + SCOPED_GPU_TIMER("drawpass"); + vkCmdBeginRenderPass(commandBuffer, &renderPassInfo, VK_SUBPASS_CONTENTS_INLINE); + { + const auto& scene = GetScene(); + + VkDescriptorSet descriptorSets[] = { gbufferPipeline_->DescriptorSet(imageIndex) }; + VkBuffer vertexBuffers[] = { scene.VertexBuffer().Handle() }; + const VkBuffer indexBuffer = scene.IndexBuffer().Handle(); + VkDeviceSize offsets[] = { 0 }; + + vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, gbufferPipeline_->Handle()); + vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, gbufferPipeline_->PipelineLayout().Handle(), 0, 1, descriptorSets, 0, nullptr); + vkCmdBindVertexBuffers(commandBuffer, 0, 1, vertexBuffers, offsets); + vkCmdBindIndexBuffer(commandBuffer, indexBuffer, 0, VK_INDEX_TYPE_UINT32); + + // indirect draw + vkCmdDrawIndexedIndirect(commandBuffer, scene.IndirectDrawBuffer().Handle(), 0, scene.GetIndirectDrawBatchCount(), sizeof(VkDrawIndexedIndirectCommand)); + } + vkCmdEndRenderPass(commandBuffer); + + ImageMemoryBarrier::Insert(commandBuffer, outputImage_->Handle(), subresourceRange, + 0, VK_ACCESS_SHADER_WRITE_BIT, VK_IMAGE_LAYOUT_UNDEFINED, + VK_IMAGE_LAYOUT_GENERAL); + ImageMemoryBarrier::Insert(commandBuffer, gbuffer0BufferImage_->Handle(), subresourceRange, + VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_SHADER_READ_BIT, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, + VK_IMAGE_LAYOUT_GENERAL); + ImageMemoryBarrier::Insert(commandBuffer, gbuffer1BufferImage_->Handle(), subresourceRange, + VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_SHADER_READ_BIT, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, VK_IMAGE_LAYOUT_GENERAL); - ImageMemoryBarrier::Insert(commandBuffer, gbuffer0BufferImage_->Handle(), subresourceRange, + ImageMemoryBarrier::Insert(commandBuffer, gbuffer2BufferImage_->Handle(), subresourceRange, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_SHADER_READ_BIT, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, VK_IMAGE_LAYOUT_GENERAL); - ImageMemoryBarrier::Insert(commandBuffer, gbuffer1BufferImage_->Handle(), subresourceRange, - VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_SHADER_READ_BIT, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, - VK_IMAGE_LAYOUT_GENERAL); - ImageMemoryBarrier::Insert(commandBuffer, gbuffer2BufferImage_->Handle(), subresourceRange, - VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_SHADER_READ_BIT, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, - VK_IMAGE_LAYOUT_GENERAL); - // cs shading pass - VkDescriptorSet denoiserDescriptorSets[] = {deferredShadingPipeline_->DescriptorSet(imageIndex)}; - vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, deferredShadingPipeline_->Handle()); - vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, - deferredShadingPipeline_->PipelineLayout().Handle(), 0, 1, denoiserDescriptorSets, 0, nullptr); - vkCmdDispatch(commandBuffer, SwapChain().Extent().width / 8 / ( CheckerboxRendering() ? 2 : 1 ), SwapChain().Extent().height / 4, 1); + } - // copy to swap-buffer - ImageMemoryBarrier::Insert(commandBuffer, outputImage_->Handle(), subresourceRange, - VK_ACCESS_SHADER_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT, VK_IMAGE_LAYOUT_GENERAL, - VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL); - - ImageMemoryBarrier::Insert(commandBuffer, SwapChain().Images()[imageIndex], subresourceRange, 0, - VK_ACCESS_TRANSFER_WRITE_BIT, VK_IMAGE_LAYOUT_UNDEFINED, - VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); + + { + SCOPED_GPU_TIMER("shadingpass"); + + // cs shading pass + VkDescriptorSet denoiserDescriptorSets[] = {deferredShadingPipeline_->DescriptorSet(imageIndex)}; + vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, deferredShadingPipeline_->Handle()); + vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, + deferredShadingPipeline_->PipelineLayout().Handle(), 0, 1, denoiserDescriptorSets, 0, nullptr); + vkCmdDispatch(commandBuffer, SwapChain().Extent().width / 8 / ( CheckerboxRendering() ? 2 : 1 ), SwapChain().Extent().height / 4, 1); + + // copy to swap-buffer + ImageMemoryBarrier::Insert(commandBuffer, outputImage_->Handle(), subresourceRange, + VK_ACCESS_SHADER_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT, VK_IMAGE_LAYOUT_GENERAL, + VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL); + + ImageMemoryBarrier::Insert(commandBuffer, SwapChain().Images()[imageIndex], subresourceRange, 0, + VK_ACCESS_TRANSFER_WRITE_BIT, VK_IMAGE_LAYOUT_UNDEFINED, + VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); + } + // Copy output image into swap-chain image. VkImageCopy copyRegion; diff --git a/src/Vulkan/ModernDeferred/ModernDeferredRenderer.cpp b/src/Vulkan/ModernDeferred/ModernDeferredRenderer.cpp index 2ced5794..42400d00 100644 --- a/src/Vulkan/ModernDeferred/ModernDeferredRenderer.cpp +++ b/src/Vulkan/ModernDeferred/ModernDeferredRenderer.cpp @@ -99,7 +99,8 @@ void ModernDeferredRenderer::DeleteSwapChain() } void ModernDeferredRenderer::Render(VkCommandBuffer commandBuffer, uint32_t imageIndex) -{ +{ + VkImageSubresourceRange subresourceRange = {}; subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; subresourceRange.baseMipLevel = 0; @@ -124,53 +125,59 @@ void ModernDeferredRenderer::Render(VkCommandBuffer commandBuffer, uint32_t imag renderPassInfo.clearValueCount = static_cast(clearValues.size()); renderPassInfo.pClearValues = clearValues.data(); - // make it to generate gbuffer - vkCmdBeginRenderPass(commandBuffer, &renderPassInfo, VK_SUBPASS_CONTENTS_INLINE); - { - const auto& scene = GetScene(); - - VkDescriptorSet descriptorSets[] = { visibilityPipeline_->DescriptorSet(imageIndex) }; - VkBuffer vertexBuffers[] = { scene.VertexBuffer().Handle() }; - const VkBuffer indexBuffer = scene.IndexBuffer().Handle(); - VkDeviceSize offsets[] = { 0 }; - - vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, visibilityPipeline_->Handle()); - vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, visibilityPipeline_->PipelineLayout().Handle(), 0, 1, descriptorSets, 0, nullptr); - vkCmdBindVertexBuffers(commandBuffer, 0, 1, vertexBuffers, offsets); - vkCmdBindIndexBuffer(commandBuffer, indexBuffer, 0, VK_INDEX_TYPE_UINT32); - - // indirect draw - vkCmdDrawIndexedIndirect(commandBuffer, scene.IndirectDrawBuffer().Handle(), 0, scene.GetIndirectDrawBatchCount(), sizeof(VkDrawIndexedIndirectCommand)); - } - vkCmdEndRenderPass(commandBuffer); - ImageMemoryBarrier::Insert(commandBuffer, outputImage_->Handle(), subresourceRange, - 0, VK_ACCESS_SHADER_WRITE_BIT, VK_IMAGE_LAYOUT_UNDEFINED, - VK_IMAGE_LAYOUT_GENERAL); - ImageMemoryBarrier::Insert(commandBuffer, motionVectorImage_->Handle(), subresourceRange, - 0, VK_ACCESS_SHADER_WRITE_BIT, VK_IMAGE_LAYOUT_UNDEFINED, + { + SCOPED_GPU_TIMER("drawpass"); + // make it to generate gbuffer + vkCmdBeginRenderPass(commandBuffer, &renderPassInfo, VK_SUBPASS_CONTENTS_INLINE); + { + const auto& scene = GetScene(); + + VkDescriptorSet descriptorSets[] = { visibilityPipeline_->DescriptorSet(imageIndex) }; + VkBuffer vertexBuffers[] = { scene.VertexBuffer().Handle() }; + const VkBuffer indexBuffer = scene.IndexBuffer().Handle(); + VkDeviceSize offsets[] = { 0 }; + + vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, visibilityPipeline_->Handle()); + vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, visibilityPipeline_->PipelineLayout().Handle(), 0, 1, descriptorSets, 0, nullptr); + vkCmdBindVertexBuffers(commandBuffer, 0, 1, vertexBuffers, offsets); + vkCmdBindIndexBuffer(commandBuffer, indexBuffer, 0, VK_INDEX_TYPE_UINT32); + + // indirect draw + vkCmdDrawIndexedIndirect(commandBuffer, scene.IndirectDrawBuffer().Handle(), 0, scene.GetIndirectDrawBatchCount(), sizeof(VkDrawIndexedIndirectCommand)); + } + vkCmdEndRenderPass(commandBuffer); + + ImageMemoryBarrier::Insert(commandBuffer, outputImage_->Handle(), subresourceRange, + 0, VK_ACCESS_SHADER_WRITE_BIT, VK_IMAGE_LAYOUT_UNDEFINED, + VK_IMAGE_LAYOUT_GENERAL); + ImageMemoryBarrier::Insert(commandBuffer, motionVectorImage_->Handle(), subresourceRange, + 0, VK_ACCESS_SHADER_WRITE_BIT, VK_IMAGE_LAYOUT_UNDEFINED, + VK_IMAGE_LAYOUT_GENERAL); + ImageMemoryBarrier::Insert(commandBuffer, visibilityBufferImage_->Handle(), subresourceRange, + VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_SHADER_READ_BIT, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, VK_IMAGE_LAYOUT_GENERAL); - ImageMemoryBarrier::Insert(commandBuffer, visibilityBufferImage_->Handle(), subresourceRange, - VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_SHADER_READ_BIT, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, - VK_IMAGE_LAYOUT_GENERAL); + } - // cs shading pass { + SCOPED_GPU_TIMER("shadingpass"); + // cs shading pass VkDescriptorSet DescriptorSets[] = {deferredShadingPipeline_->DescriptorSet(imageIndex)}; vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, deferredShadingPipeline_->Handle()); vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, deferredShadingPipeline_->PipelineLayout().Handle(), 0, 1, DescriptorSets, 0, nullptr); vkCmdDispatch(commandBuffer, SwapChain().Extent().width / 8 / ( CheckerboxRendering() ? 2 : 1 ), SwapChain().Extent().height / 4, 1); - } - - ImageMemoryBarrier::Insert(commandBuffer, outputImage_->Handle(), subresourceRange, - VK_ACCESS_SHADER_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT, VK_IMAGE_LAYOUT_GENERAL, - VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL); - ImageMemoryBarrier::Insert(commandBuffer, SwapChain().Images()[imageIndex], subresourceRange, 0, - VK_ACCESS_TRANSFER_WRITE_BIT, VK_IMAGE_LAYOUT_UNDEFINED, - VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); + ImageMemoryBarrier::Insert(commandBuffer, outputImage_->Handle(), subresourceRange, + VK_ACCESS_SHADER_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT, VK_IMAGE_LAYOUT_GENERAL, + VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL); + + ImageMemoryBarrier::Insert(commandBuffer, SwapChain().Images()[imageIndex], subresourceRange, 0, + VK_ACCESS_TRANSFER_WRITE_BIT, VK_IMAGE_LAYOUT_UNDEFINED, + VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); + } + // Copy output image into swap-chain image. VkImageCopy copyRegion; copyRegion.srcSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1}; diff --git a/src/Vulkan/RayTracing/RayTracingRenderer.cpp b/src/Vulkan/RayTracing/RayTracingRenderer.cpp index e8d7e399..82e11b7f 100644 --- a/src/Vulkan/RayTracing/RayTracingRenderer.cpp +++ b/src/Vulkan/RayTracing/RayTracingRenderer.cpp @@ -252,11 +252,11 @@ namespace Vulkan::RayTracing 0, VK_ACCESS_SHADER_WRITE_BIT, VK_IMAGE_LAYOUT_UNDEFINED,VK_IMAGE_LAYOUT_GENERAL); ImageMemoryBarrier::Insert(commandBuffer, visibilityBufferImage_->Handle(), subresourceRange, - 0, VK_ACCESS_SHADER_WRITE_BIT, VK_IMAGE_LAYOUT_UNDEFINED,VK_IMAGE_LAYOUT_GENERAL); + 0, VK_ACCESS_SHADER_WRITE_BIT, VK_IMAGE_LAYOUT_UNDEFINED,VK_IMAGE_LAYOUT_GENERAL); ImageMemoryBarrier::Insert(commandBuffer, visibility1BufferImage_->Handle(), subresourceRange, -0, VK_ACCESS_SHADER_WRITE_BIT, VK_IMAGE_LAYOUT_UNDEFINED,VK_IMAGE_LAYOUT_GENERAL); + 0, VK_ACCESS_SHADER_WRITE_BIT, VK_IMAGE_LAYOUT_UNDEFINED,VK_IMAGE_LAYOUT_GENERAL); ImageMemoryBarrier::Insert(commandBuffer, validateImage_->Handle(), subresourceRange, -0, VK_ACCESS_SHADER_WRITE_BIT, VK_IMAGE_LAYOUT_UNDEFINED,VK_IMAGE_LAYOUT_GENERAL); + 0, VK_ACCESS_SHADER_WRITE_BIT, VK_IMAGE_LAYOUT_UNDEFINED,VK_IMAGE_LAYOUT_GENERAL); // Bind ray tracing pipeline. vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR, rayTracingPipeline_->Handle()); @@ -282,32 +282,35 @@ namespace Vulkan::RayTracing VkStridedDeviceAddressRegionKHR callableShaderBindingTable = {}; // Execute ray tracing shaders. - deviceProcedures_->vkCmdTraceRaysKHR(commandBuffer, - &raygenShaderBindingTable, &missShaderBindingTable, &hitShaderBindingTable, - &callableShaderBindingTable, - CheckerboxRendering() ? extent.width / 2 : extent.width, extent.height, 1); - - - ImageMemoryBarrier::Insert(commandBuffer, pingpongImage0_->Handle(), subresourceRange, 0, - VK_ACCESS_SHADER_WRITE_BIT, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL); - - ImageMemoryBarrier::Insert(commandBuffer, gbufferImage_->Handle(), subresourceRange, - VK_ACCESS_SHADER_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT, VK_IMAGE_LAYOUT_GENERAL, - VK_IMAGE_LAYOUT_GENERAL); - - ImageMemoryBarrier::Insert(commandBuffer, albedoImage_->Handle(), subresourceRange, - VK_ACCESS_SHADER_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT, VK_IMAGE_LAYOUT_GENERAL, - VK_IMAGE_LAYOUT_GENERAL); - - // accumulate with reproject - ImageMemoryBarrier::Insert(commandBuffer, motionVectorImage_->Handle(), subresourceRange, - VK_ACCESS_SHADER_WRITE_BIT, VK_ACCESS_SHADER_WRITE_BIT, VK_IMAGE_LAYOUT_GENERAL, - VK_IMAGE_LAYOUT_GENERAL); + { + SCOPED_GPU_TIMER("rt pass"); + deviceProcedures_->vkCmdTraceRaysKHR(commandBuffer, + &raygenShaderBindingTable, &missShaderBindingTable, &hitShaderBindingTable, + &callableShaderBindingTable, + CheckerboxRendering() ? extent.width / 2 : extent.width, extent.height, 1); + + ImageMemoryBarrier::Insert(commandBuffer, pingpongImage0_->Handle(), subresourceRange, 0, + VK_ACCESS_SHADER_WRITE_BIT, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL); + + ImageMemoryBarrier::Insert(commandBuffer, gbufferImage_->Handle(), subresourceRange, + VK_ACCESS_SHADER_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT, VK_IMAGE_LAYOUT_GENERAL, + VK_IMAGE_LAYOUT_GENERAL); + + ImageMemoryBarrier::Insert(commandBuffer, albedoImage_->Handle(), subresourceRange, + VK_ACCESS_SHADER_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT, VK_IMAGE_LAYOUT_GENERAL, + VK_IMAGE_LAYOUT_GENERAL); + + // accumulate with reproject + ImageMemoryBarrier::Insert(commandBuffer, motionVectorImage_->Handle(), subresourceRange, + VK_ACCESS_SHADER_WRITE_BIT, VK_ACCESS_SHADER_WRITE_BIT, VK_IMAGE_LAYOUT_GENERAL, + VK_IMAGE_LAYOUT_GENERAL); + } // accumulate with reproject // frame0: new + image 0 -> image 1 // frame1: new + image 1 -> image 0 { + SCOPED_GPU_TIMER("reproject pass"); VkDescriptorSet DescriptorSets[] = {accumulatePipeline_->DescriptorSet(imageIndex)}; vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, accumulatePipeline_->Handle()); vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, @@ -348,6 +351,8 @@ namespace Vulkan::RayTracing // compose with first bounce { + SCOPED_GPU_TIMER("compose pass"); + DenoiserPushConstantData pushData; pushData.pingpong = frameCount_ % 2; pushData.stepsize = 1; @@ -360,16 +365,17 @@ namespace Vulkan::RayTracing vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, composePipeline_->PipelineLayout().Handle(), 0, 1, denoiserDescriptorSets, 0, nullptr); vkCmdDispatch(commandBuffer, extent.width / 8, extent.height / 4, 1); - } + - // Acquire output image and swap-chain image for copying. - ImageMemoryBarrier::Insert(commandBuffer, outputImage_->Handle(), subresourceRange, - VK_ACCESS_SHADER_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT, VK_IMAGE_LAYOUT_GENERAL, - VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL); + // Acquire output image and swap-chain image for copying. + ImageMemoryBarrier::Insert(commandBuffer, outputImage_->Handle(), subresourceRange, + VK_ACCESS_SHADER_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT, VK_IMAGE_LAYOUT_GENERAL, + VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL); - ImageMemoryBarrier::Insert(commandBuffer, SwapChain().Images()[imageIndex], subresourceRange, 0, - VK_ACCESS_TRANSFER_WRITE_BIT, VK_IMAGE_LAYOUT_UNDEFINED, - VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); + ImageMemoryBarrier::Insert(commandBuffer, SwapChain().Images()[imageIndex], subresourceRange, 0, + VK_ACCESS_TRANSFER_WRITE_BIT, VK_IMAGE_LAYOUT_UNDEFINED, + VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); + } // Copy output image into swap-chain image. VkImageCopy copyRegion; diff --git a/src/Vulkan/SwapChain.cpp b/src/Vulkan/SwapChain.cpp index 6cdc02d9..9b820273 100644 --- a/src/Vulkan/SwapChain.cpp +++ b/src/Vulkan/SwapChain.cpp @@ -30,9 +30,15 @@ SwapChain::SwapChain(const class Device& device, const VkPresentModeKHR presentM const auto surfaceFormat = ChooseSwapSurfaceFormat(details.Formats); const auto actualPresentMode = ChooseSwapPresentMode(details.PresentModes, presentMode); - const auto extent = ChooseSwapExtent(window, details.Capabilities); + auto extent = ChooseSwapExtent(window, details.Capabilities); const auto imageCount = ChooseImageCount(details.Capabilities); +#if ANDROID + float aspect = extent.width / static_cast(extent.height); + extent.height = 1920; + extent.width = floorf(1920 * aspect); +#endif + VkSwapchainCreateInfoKHR createInfo = {}; createInfo.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; createInfo.surface = surface.Handle(); diff --git a/src/Vulkan/Vulkan.hpp b/src/Vulkan/Vulkan.hpp index d11cf56b..92d03957 100644 --- a/src/Vulkan/Vulkan.hpp +++ b/src/Vulkan/Vulkan.hpp @@ -13,6 +13,12 @@ typedef ANativeWindow GLFWwindow; #endif #undef APIENTRY +#define DEFAULT_NON_COPIABLE(ClassName) \ +ClassName(const ClassName&) = delete; \ +ClassName(ClassName&&) = delete; \ +ClassName& operator = (const ClassName&) = delete; \ +ClassName& operator = (ClassName&&) = delete; \ + #define VULKAN_NON_COPIABLE(ClassName) \ ClassName(const ClassName&) = delete; \ ClassName(ClassName&&) = delete; \ diff --git a/src/Vulkan/VulkanBaseRenderer.cpp b/src/Vulkan/VulkanBaseRenderer.cpp index 67f46e5d..e9d75068 100644 --- a/src/Vulkan/VulkanBaseRenderer.cpp +++ b/src/Vulkan/VulkanBaseRenderer.cpp @@ -40,6 +40,26 @@ VulkanBaseRenderer::VulkanBaseRenderer(const WindowConfig& windowConfig, const V supportScreenShot_ = windowConfig.NeedScreenShot; } +VulkanGpuTimer::VulkanGpuTimer(VkDevice device, uint32_t totalCount, const VkPhysicalDeviceProperties& prop) +{ + device_ = device; + time_stamps.resize(totalCount); + timeStampPeriod_ = prop.limits.timestampPeriod; + // Create the query pool object used to get the GPU time tamps + VkQueryPoolCreateInfo query_pool_info{}; + query_pool_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO; + // We need to specify the query type for this pool, which in our case is for time stamps + query_pool_info.queryType = VK_QUERY_TYPE_TIMESTAMP; + // Set the no. of queries in this pool + query_pool_info.queryCount = static_cast(time_stamps.size()); + Check( vkCreateQueryPool(device, &query_pool_info, nullptr, &query_pool_timestamps), "create timestamp pool"); +} + +VulkanGpuTimer::~VulkanGpuTimer() +{ + vkDestroyQueryPool(device_, query_pool_timestamps, nullptr); +} + VulkanBaseRenderer::~VulkanBaseRenderer() { VulkanBaseRenderer::DeleteSwapChain(); @@ -126,6 +146,7 @@ void VulkanBaseRenderer::Start() void VulkanBaseRenderer::End() { device_->WaitIdle(); + gpuTimer_.reset(); } bool VulkanBaseRenderer::Tick() @@ -158,10 +179,15 @@ void VulkanBaseRenderer::SetPhysicalDeviceImpl( bufferDeviceAddressFeatures.pNext = &indexingFeatures; bufferDeviceAddressFeatures.bufferDeviceAddress = true; + VkPhysicalDeviceHostQueryResetFeaturesEXT hostQueryResetFeatures = {}; + hostQueryResetFeatures.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_HOST_QUERY_RESET_FEATURES_EXT; + hostQueryResetFeatures.pNext = &bufferDeviceAddressFeatures; + hostQueryResetFeatures.hostQueryReset = true; - - device_.reset(new class Device(physicalDevice, *surface_, requiredExtensions, deviceFeatures, &bufferDeviceAddressFeatures)); + device_.reset(new class Device(physicalDevice, *surface_, requiredExtensions, deviceFeatures, &hostQueryResetFeatures)); commandPool_.reset(new class CommandPool(*device_, device_->GraphicsFamilyIndex(), true)); + + gpuTimer_.reset(new VulkanGpuTimer(device_->Handle(), 10 * 2, device_->DeviceProperties())); } void VulkanBaseRenderer::OnDeviceSet() @@ -247,9 +273,16 @@ void VulkanBaseRenderer::DrawFrame() Throw(std::runtime_error(std::string("failed to acquire next image (") + ToString(result) + ")")); } + + const auto commandBuffer = commandBuffers_->Begin(imageIndex); - Render(commandBuffer, imageIndex); + gpuTimer_->Reset(commandBuffer); + { + SCOPED_GPU_TIMER("full"); + Render(commandBuffer, imageIndex); + } + // screenshot swapchain image if (supportScreenShot_) { @@ -287,7 +320,6 @@ void VulkanBaseRenderer::DrawFrame() VK_ACCESS_TRANSFER_READ_BIT, 0, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR); } - commandBuffers_->End(imageIndex); UpdateUniformBuffer(imageIndex); @@ -325,6 +357,8 @@ void VulkanBaseRenderer::DrawFrame() result = vkQueuePresentKHR(device_->PresentQueue(), &presentInfo); + gpuTimer_->FrameEnd(commandBuffer); + if (result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_SUBOPTIMAL_KHR) { RecreateSwapChain(); diff --git a/src/Vulkan/VulkanBaseRenderer.hpp b/src/Vulkan/VulkanBaseRenderer.hpp index 914f9697..2f59eaaa 100644 --- a/src/Vulkan/VulkanBaseRenderer.hpp +++ b/src/Vulkan/VulkanBaseRenderer.hpp @@ -3,10 +3,14 @@ #include "FrameBuffer.hpp" #include "WindowConfig.hpp" #include +#include #include - +#include +#include #include "Image.hpp" +#define SCOPED_GPU_TIMER(name) ScopedGpuTimer scopedGpuTimer(commandBuffer, GpuTimer(), name) + namespace Assets { class Scene; @@ -16,6 +20,120 @@ namespace Assets namespace Vulkan { + class VulkanGpuTimer + { + public: + DEFAULT_NON_COPIABLE(VulkanGpuTimer) + + VulkanGpuTimer(VkDevice device, uint32_t totalCount, const VkPhysicalDeviceProperties& prop); + virtual ~VulkanGpuTimer(); + + void Reset(VkCommandBuffer commandBuffer) + { + vkCmdResetQueryPool(commandBuffer, query_pool_timestamps, 0, time_stamps.size()); + queryIdx = 0; + } + + void FrameEnd(VkCommandBuffer commandBuffer) + { + uint32_t count = static_cast(time_stamps.size()); + + // Fetch the time stamp results written in the command buffer submissions + // A note on the flags used: + // VK_QUERY_RESULT_64_BIT: Results will have 64 bits. As time stamp values are on nano-seconds, this flag should always be used to avoid 32 bit overflows + // VK_QUERY_RESULT_WAIT_BIT: Since we want to immediately display the results, we use this flag to have the CPU wait until the results are available + vkGetQueryPoolResults( + device_, + query_pool_timestamps, + 0, + queryIdx, + time_stamps.size() * sizeof(uint64_t), + time_stamps.data(), + sizeof(uint64_t), + VK_QUERY_RESULT_64_BIT | VK_QUERY_RESULT_WAIT_BIT); + } + + void Start(VkCommandBuffer commandBuffer, const char* name) + { + if( timer_query_map.find(name) == timer_query_map.end()) + { + timer_query_map[name] = std::make_tuple(0, 0); + } + vkCmdWriteTimestamp(commandBuffer, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, query_pool_timestamps, queryIdx); + std::get<0>(timer_query_map[name]) = queryIdx; + queryIdx++; + } + void End(VkCommandBuffer commandBuffer, const char* name) + { + assert( timer_query_map.find(name) != timer_query_map.end() ); + vkCmdWriteTimestamp(commandBuffer, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, query_pool_timestamps, queryIdx); + std::get<1>(timer_query_map[name]) = queryIdx; + queryIdx++; + } + float GetTime(const char* name) + { + if(timer_query_map.find(name) == timer_query_map.end()) + { + return 0; + } + return (time_stamps[ std::get<1>(timer_query_map[name]) ] - time_stamps[ std::get<0>(timer_query_map[name])]) * timeStampPeriod_ * 1e-6f; + } + std::vector > FetchAllTimes() + { + std::list > order_list; + std::vector > result; + for(auto& [name, query] : timer_query_map) + { + order_list.insert(order_list.begin(), (std::make_tuple(name, GetTime(name.c_str()), std::get<0>(query), std::get<1>(query)))); + } + + // sort by tuple 2 + order_list.sort([](const std::tuple& a, const std::tuple& b) -> bool + { + return std::get<2>(a) < std::get<2>(b); + }); + + int last_order = 99; + std::string prefix = ""; + for(auto& [name, time, startIdx, endIdx] : order_list) + { + if( startIdx < last_order) + { + prefix += " "; + last_order = endIdx; + } + result.push_back(std::make_tuple(prefix + name, time)); + } + + return result; + } + + VkQueryPool query_pool_timestamps = VK_NULL_HANDLE; + std::vector time_stamps{}; + std::unordered_map > timer_query_map{}; + VkDevice device_ = VK_NULL_HANDLE; + uint64_t queryIdx = 0; + float timeStampPeriod_ = 1; + }; + + class ScopedGpuTimer + { + public: + DEFAULT_NON_COPIABLE(ScopedGpuTimer) + + ScopedGpuTimer(VkCommandBuffer commandBuffer, VulkanGpuTimer* timer, const char* name ):commandBuffer_(commandBuffer),timer_(timer), name_(name) + { + timer_->Start(commandBuffer_, name_.c_str()); + } + virtual ~ScopedGpuTimer() + { + timer_->End(commandBuffer_, name_.c_str()); + } + VkCommandBuffer commandBuffer_; + VulkanGpuTimer* timer_; + std::string name_; + }; + class VulkanBaseRenderer { public: @@ -52,6 +170,7 @@ namespace Vulkan const class GraphicsPipeline& GraphicsPipeline() const { return *graphicsPipeline_; } const class FrameBuffer& SwapChainFrameBuffer(const size_t i) const { return swapChainFramebuffers_[i]; } const bool CheckerboxRendering() {return checkerboxRendering_;} + class VulkanGpuTimer* GpuTimer() const {return gpuTimer_.get();} virtual const Assets::Scene& GetScene() const = 0; virtual Assets::UniformBufferObject GetUniformBufferObject(VkExtent2D extent) const = 0; @@ -110,12 +229,11 @@ namespace Vulkan std::unique_ptr screenShotImage_; std::unique_ptr screenShotImageMemory_; std::unique_ptr screenShotImageView_; + + std::unique_ptr gpuTimer_; size_t currentFrame_{}; - Fence* fence; - - }; } diff --git a/src/Vulkan/Window.cpp b/src/Vulkan/Window.cpp index f38089b3..c6b0ef84 100644 --- a/src/Vulkan/Window.cpp +++ b/src/Vulkan/Window.cpp @@ -147,7 +147,8 @@ VkExtent2D Window::FramebufferSize() const glfwGetFramebufferSize(window_, &width, &height); return VkExtent2D{ static_cast(width), static_cast(height) }; #else - return VkExtent2D{ (uint32_t)ANativeWindow_getWidth(window_), (uint32_t)ANativeWindow_getHeight(window_) }; + float aspect = ANativeWindow_getWidth(window_) / static_cast(ANativeWindow_getHeight(window_)); + return VkExtent2D{ static_cast(floorf(1920 * aspect)), 1920 }; #endif } diff --git a/src/main.cpp b/src/main.cpp index 1df80ec6..72dba2c7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -12,6 +12,7 @@ #include #if ANDROID +#include #include #include #endif @@ -99,12 +100,52 @@ void handle_cmd(android_app* app, int32_t cmd) { } } +// static int32_t engine_handle_input(struct android_app* app) { +// ImGuiIO& io = ImGui::GetIO(); +// auto* engine = (struct engine*)app->userData; +// auto ib = android_app_swap_input_buffers(app); +// if (ib && ib->motionEventsCount) { +// for (int i = 0; i < ib->motionEventsCount; i++) { +// auto *event = &ib->motionEvents[i]; +// int32_t ptrIdx = 0; +// switch (event->action & AMOTION_EVENT_ACTION_MASK) { +// case AMOTION_EVENT_ACTION_POINTER_DOWN: +// case AMOTION_EVENT_ACTION_POINTER_UP: +// // Retrieve the index for the starting and the ending of any secondary pointers +// ptrIdx = (event->action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> +// AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT; +// case AMOTION_EVENT_ACTION_DOWN: +// case AMOTION_EVENT_ACTION_UP: +// engine->state.x = GameActivityPointerAxes_getAxisValue( +// &event->pointers[ptrIdx], AMOTION_EVENT_AXIS_X); +// engine->state.y = GameActivityPointerAxes_getAxisValue( +// &event->pointers[ptrIdx], AMOTION_EVENT_AXIS_Y); +// break; +// case AMOTION_EVENT_ACTION_MOVE: +// // Process the move action: the new coordinates for all active touch pointers +// // are inside the event->pointers[]. Compare with our internally saved +// // coordinates to find out which pointers are actually moved. Note that there is +// // no index embedded inside event->action for AMOTION_EVENT_ACTION_MOVE (there +// // might be multiple pointers moved at the same time). +// //... +// break; +// } +// } +// android_app_clear_motion_events(ib); +// } +// +// // Process the KeyEvent in a similar way. +// //... +// +// return 0; +// } + void android_main(struct android_app* app) { app->onAppCmd = handle_cmd; - + //app->onInputEvent = handleInputEvent; // Used to poll the events in the main loop int events; android_poll_source* source; @@ -116,6 +157,8 @@ void android_main(struct android_app* app) if (source != NULL) source->process(app, source); } + //engine_handle_input(state); + // render if vulkan is ready if (GApplication != nullptr) { GApplication->Tick(); @@ -145,19 +188,22 @@ int main(int argc, const char* argv[]) noexcept uint32_t rendererType = options.RendererType; + + if(options.RenderDoc) + { #if __linux__ - setenv("ENABLE_VULKAN_RENDERDOC_CAPTURE", "1", 1); + setenv("ENABLE_VULKAN_RENDERDOC_CAPTURE", "1", 1); #endif #if __APPLE__ - setenv("MVK_CONFIG_USE_METAL_ARGUMENT_BUFFERS", "1", 1); - setenv("MVK_CONFIG_AUTO_GPU_CAPTURE_OUTPUT_FILE", "~/capture/cap.gputrace", 1); - setenv("MVK_CONFIG_DEFAULT_GPU_CAPTURE_SCOPE_QUEUE_FAMILY_INDEX", "0", 1); - setenv("MVK_CONFIG_DEFAULT_GPU_CAPTURE_SCOPE_QUEUE_INDEX", "0", 1); - setenv("MTL_CAPTURE_ENABLED", "1", 1); - setenv("MVK_CONFIG_AUTO_GPU_CAPTURE_SCOPE","2",1); - if( rendererType == 0 ) rendererType = 2; + setenv("MVK_CONFIG_USE_METAL_ARGUMENT_BUFFERS", "1", 1); + setenv("MVK_CONFIG_AUTO_GPU_CAPTURE_OUTPUT_FILE", "~/capture/cap.gputrace", 1); + setenv("MVK_CONFIG_DEFAULT_GPU_CAPTURE_SCOPE_QUEUE_FAMILY_INDEX", "0", 1); + setenv("MVK_CONFIG_DEFAULT_GPU_CAPTURE_SCOPE_QUEUE_INDEX", "0", 1); + setenv("MTL_CAPTURE_ENABLED", "1", 1); + setenv("MVK_CONFIG_AUTO_GPU_CAPTURE_SCOPE","2",1); #endif + } StartApplication(rendererType, windowConfig, userSettings, options);