Implemented basic occlusions queries

This commit is contained in:
Dynamitos
2024-06-11 16:55:20 +02:00
parent 52c4f11d28
commit df7fbef8bd
20 changed files with 221 additions and 156 deletions
@@ -20,6 +20,8 @@ target_sources(Engine
Pipeline.cpp
PipelineCache.h
PipelineCache.cpp
Query.h
Query.cpp
Queue.h
Queue.cpp
RayTracing.h
@@ -48,6 +50,7 @@ target_sources(Engine
Graphics.h
Pipeline.h
PipelineCache.h
Query.h
Queue.h
RayTracing.h
RenderPass.h
+2 -2
View File
@@ -181,8 +181,8 @@ void RenderCommand::begin(PRenderPass renderPass, PFramebuffer framebuffer) {
.renderPass = renderPass->getHandle(),
.subpass = 0,
.framebuffer = framebuffer->getHandle(),
.occlusionQueryEnable = 0,
.queryFlags = 0,
.occlusionQueryEnable = 1,
.queryFlags = VK_QUERY_CONTROL_PRECISE_BIT,
.pipelineStatistics = 0,
};
VkCommandBufferBeginInfo beginInfo = {
+4 -2
View File
@@ -12,6 +12,7 @@
#include "RayTracing.h"
#include "RenderPass.h"
#include "Shader.h"
#include "Query.h"
#include "Window.h"
#include <GLFW/glfw3.h>
#include <cstring>
@@ -96,7 +97,6 @@ void Graphics::beginRenderPass(Gfx::PRenderPass renderPass) {
void Graphics::endRenderPass() {
getGraphicsCommands()->getCommands()->endRenderPass();
getGraphicsCommands()->submitCommands();
}
void Graphics::waitDeviceIdle() { vkDeviceWaitIdle(handle); }
@@ -195,6 +195,8 @@ Gfx::OPipelineLayout Graphics::createPipelineLayout(const std::string& name, Gfx
Gfx::OVertexInput Graphics::createVertexInput(VertexInputStateCreateInfo createInfo) { return new VertexInput(createInfo); }
Gfx::OOcclusionQuery Graphics::createOcclusionQuery() { return new OcclusionQuery(this); }
void Graphics::resolveTexture(Gfx::PTexture source, Gfx::PTexture destination) {
PTextureBase sourceTex = source.cast<TextureBase>();
PTextureBase destinationTex = destination.cast<TextureBase>();
@@ -396,7 +398,6 @@ void Graphics::pickPhysicalDevice() {
features.pNext = &robustness;
robustness.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ROBUSTNESS_2_FEATURES_EXT;
robustness.pNext = &features11;
robustness.nullDescriptor = true;
features11.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_FEATURES;
features11.pNext = &features12;
features12.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES;
@@ -425,6 +426,7 @@ void Graphics::pickPhysicalDevice() {
vkGetPhysicalDeviceProperties(physicalDevice, &props);
vkGetPhysicalDeviceFeatures2(physicalDevice, &features);
features.features.robustBufferAccess = 0;
features.features.inheritedQueries = true;
if (Gfx::useMeshShading) {
uint32 count = 0;
vkEnumerateDeviceExtensionProperties(physicalDevice, NULL, &count, nullptr);
+2
View File
@@ -65,6 +65,8 @@ class Graphics : public Gfx::Graphics {
virtual Gfx::OVertexInput createVertexInput(VertexInputStateCreateInfo createInfo) override;
virtual Gfx::OOcclusionQuery createOcclusionQuery() override;
virtual void resolveTexture(Gfx::PTexture source, Gfx::PTexture destination) override;
virtual void copyTexture(Gfx::PTexture src, Gfx::PTexture dst) override;
+32
View File
@@ -0,0 +1,32 @@
#include "Query.h"
#include "Command.h"
using namespace Seele;
using namespace Seele::Vulkan;
OcclusionQuery::OcclusionQuery(PGraphics graphics) :graphics(graphics){
VkQueryPoolCreateInfo info = {
.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO,
.pNext = nullptr,
.flags = 0,
.queryType = VK_QUERY_TYPE_OCCLUSION,
.queryCount = 1,
.pipelineStatistics = 0,
};
VK_CHECK(vkCreateQueryPool(graphics->getDevice(), &info, nullptr, &handle));
}
OcclusionQuery::~OcclusionQuery() { vkDestroyQueryPool(graphics->getDevice(), handle, nullptr); }
void OcclusionQuery::beginQuery() { vkCmdBeginQuery(graphics->getGraphicsCommands()->getCommands()->getHandle(), handle, 0, VK_QUERY_CONTROL_PRECISE_BIT); }
void OcclusionQuery::endQuery() { vkCmdEndQuery(graphics->getGraphicsCommands()->getCommands()->getHandle(), handle, 0); }
void OcclusionQuery::resetQuery() { vkResetQueryPool(graphics->getDevice(), handle, 0, 1); }
uint64 OcclusionQuery::getResults() {
graphics->getGraphicsCommands()->submitCommands();
uint64 result;
vkGetQueryPoolResults(graphics->getDevice(), handle, 0, 1, sizeof(uint64), &result, sizeof(uint64), VK_QUERY_RESULT_64_BIT | VK_QUERY_RESULT_WAIT_BIT);
return result;
}
+22
View File
@@ -0,0 +1,22 @@
#pragma once
#include "Enums.h"
#include "Graphics.h"
#include "Graphics/Query.h"
namespace Seele {
namespace Vulkan {
class OcclusionQuery : public Gfx::OcclusionQuery {
public:
OcclusionQuery(PGraphics graphics);
virtual ~OcclusionQuery();
virtual void beginQuery() override;
virtual void endQuery() override;
virtual void resetQuery() override;
virtual uint64 getResults() override;
private:
PGraphics graphics;
VkQueryPool handle;
};
DEFINE_REF(OcclusionQuery)
} // namespace Vulkan
} // namespace Seele