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
+2
View File
@@ -26,7 +26,9 @@ void taskMain(
uint cull = p.cullingOffset + i; uint cull = p.cullingOffset + i;
MeshletDescription meshlet = pScene.meshletInfos[m]; MeshletDescription meshlet = pScene.meshletInfos[m];
MeshletCullingInfo culling = pScene.cullingInfos[cull]; MeshletCullingInfo culling = pScene.cullingInfos[cull];
#ifdef DEPTH_CULLING
if(culling.anyVisible()) if(culling.anyVisible())
#endif
{ {
uint index; uint index;
InterlockedAdd(head, 1, index); InterlockedAdd(head, 1, index);
-49
View File
@@ -1,49 +0,0 @@
import Common;
import Scene;
groupshared MeshPayload p;
groupshared uint head;
groupshared Frustum viewFrustum;
[numthreads(TASK_GROUP_SIZE, 1, 1)]
[shader("amplification")]
void taskMain(
uint threadID: SV_GroupIndex,
uint groupID: SV_GroupID
){
InstanceData instance = pScene.instances[pOffsets.instanceOffset + groupID];
MeshData mesh = pScene.meshData[pOffsets.instanceOffset + groupID];
if(threadID == 0)
{
head = 0;
float3 origin = viewToModel(instance.inverseTransformMatrix, float4(0, 0, 0, 1)).xyz;
const float offset = 0.0f;
float3 corners[4] = {
screenToModel(instance.inverseTransformMatrix, float4(offset, offset, -1.0f, 1.0f)).xyz,
screenToModel(instance.inverseTransformMatrix, float4(pViewParams.screenDimensions.x - offset, offset, -1.0f, 1.0f)).xyz,
screenToModel(instance.inverseTransformMatrix, float4(offset, pViewParams.screenDimensions.y - offset, -1.0f, 1.0f)).xyz,
screenToModel(instance.inverseTransformMatrix, float4(pViewParams.screenDimensions - float2(offset, offset), -1.0f, 1.0f)).xyz
};
viewFrustum.sides[0] = computePlane(origin, corners[2], corners[0]);
viewFrustum.sides[1] = computePlane(origin, corners[1], corners[3]);
viewFrustum.sides[2] = computePlane(origin, corners[0], corners[1]);
viewFrustum.sides[3] = computePlane(origin, corners[3], corners[2]);
p.instanceId = pOffsets.instanceOffset + groupID;
}
GroupMemoryBarrierWithGroupSync();
for(uint i = threadID; i < mesh.numMeshlets; i += TASK_GROUP_SIZE)
{
uint m = mesh.meshletOffset + i;
MeshletDescription meshlet = pScene.meshletInfos[m];
#ifdef VIEW_CULLING
if(meshlet.bounding.insideFrustum(viewFrustum))
#endif
{
uint index;
InterlockedAdd(head, 1, index);
p.culledMeshlets[index] = m;
}
}
GroupMemoryBarrierWithGroupSync();
DispatchMesh(head, 1, 1, p);
}
+3
View File
@@ -19,6 +19,8 @@ target_sources(Engine
Meshlet.cpp Meshlet.cpp
Pipeline.h Pipeline.h
Pipeline.cpp Pipeline.cpp
Query.h
Query.cpp
RayTracing.h RayTracing.h
RayTracing.cpp RayTracing.cpp
RenderTarget.h RenderTarget.h
@@ -52,6 +54,7 @@ target_sources(Engine
Meshlet.h Meshlet.h
MeshData.h MeshData.h
Pipeline.h Pipeline.h
Query.h
RayTracing.h RayTracing.h
RenderTarget.h RenderTarget.h
Resources.h Resources.h
+3
View File
@@ -30,6 +30,7 @@ DECLARE_REF(GraphicsPipeline)
DECLARE_REF(ComputePipeline) DECLARE_REF(ComputePipeline)
DECLARE_REF(RenderCommand) DECLARE_REF(RenderCommand)
DECLARE_REF(ComputeCommand) DECLARE_REF(ComputeCommand)
DECLARE_REF(OcclusionQuery)
DECLARE_REF(BottomLevelAS) DECLARE_REF(BottomLevelAS)
DECLARE_REF(TopLevelAS) DECLARE_REF(TopLevelAS)
class Graphics { class Graphics {
@@ -79,6 +80,8 @@ class Graphics {
virtual OVertexInput createVertexInput(VertexInputStateCreateInfo createInfo) = 0; virtual OVertexInput createVertexInput(VertexInputStateCreateInfo createInfo) = 0;
virtual Gfx::OOcclusionQuery createOcclusionQuery() = 0;
virtual void resolveTexture(PTexture source, PTexture destination) = 0; virtual void resolveTexture(PTexture source, PTexture destination) = 0;
virtual void copyTexture(PTexture src, PTexture dst) = 0; virtual void copyTexture(PTexture src, PTexture dst) = 0;
+10
View File
@@ -0,0 +1,10 @@
#include "Query.h"
using namespace Seele;
using namespace Seele::Gfx;
OcclusionQuery::OcclusionQuery()
{}
OcclusionQuery::~OcclusionQuery()
{}
+19
View File
@@ -0,0 +1,19 @@
#pragma once
#include "MinimalEngine.h"
namespace Seele {
namespace Gfx {
class OcclusionQuery {
public:
OcclusionQuery();
virtual ~OcclusionQuery();
virtual void beginQuery() = 0;
virtual void endQuery() = 0;
virtual void resetQuery() = 0;
virtual uint64 getResults() = 0;
private:
};
DEFINE_REF(OcclusionQuery)
} // namespace Gfx
} // namespace Seele
+1 -3
View File
@@ -16,8 +16,6 @@
using namespace Seele; using namespace Seele;
extern bool useViewCulling;
BasePass::BasePass(Gfx::PGraphics graphics, PScene scene) : RenderPass(graphics, scene) { BasePass::BasePass(Gfx::PGraphics graphics, PScene scene) : RenderPass(graphics, scene) {
basePassLayout = graphics->createPipelineLayout("BasePassLayout"); basePassLayout = graphics->createPipelineLayout("BasePassLayout");
@@ -93,7 +91,7 @@ void BasePass::render() {
Array<Gfx::ORenderCommand> commands; Array<Gfx::ORenderCommand> commands;
Gfx::ShaderPermutation permutation = graphics->getShaderCompiler()->getTemplate("BasePass"); Gfx::ShaderPermutation permutation = graphics->getShaderCompiler()->getTemplate("BasePass");
permutation.setViewCulling(useViewCulling); permutation.setDepthCulling(true); // always use the culling info
for (VertexData* vertexData : VertexData::getList()) { for (VertexData* vertexData : VertexData::getList()) {
vertexData->getInstanceDataSet()->updateBuffer(6, cullingBuffer); vertexData->getInstanceDataSet()->updateBuffer(6, cullingBuffer);
vertexData->getInstanceDataSet()->writeChanges(); vertexData->getInstanceDataSet()->writeChanges();
@@ -4,7 +4,7 @@
using namespace Seele; using namespace Seele;
extern bool usePositionOnly; extern bool usePositionOnly;
extern bool useViewCulling; extern bool useDepthCulling;
CachedDepthPass::CachedDepthPass(Gfx::PGraphics graphics, PScene scene) : RenderPass(graphics, scene) { CachedDepthPass::CachedDepthPass(Gfx::PGraphics graphics, PScene scene) : RenderPass(graphics, scene) {
depthPrepassLayout = graphics->createPipelineLayout("CachedDepthLayout"); depthPrepassLayout = graphics->createPipelineLayout("CachedDepthLayout");
@@ -45,13 +45,17 @@ CachedDepthPass::~CachedDepthPass() {}
void CachedDepthPass::beginFrame(const Component::Camera& cam) { RenderPass::beginFrame(cam); } void CachedDepthPass::beginFrame(const Component::Camera& cam) { RenderPass::beginFrame(cam); }
uint64 numFragments = 0;
void CachedDepthPass::render() { void CachedDepthPass::render() {
occlusionQuery->resetQuery();
occlusionQuery->beginQuery();
graphics->beginRenderPass(renderPass); graphics->beginRenderPass(renderPass);
Array<Gfx::ORenderCommand> commands; Array<Gfx::ORenderCommand> commands;
Gfx::ShaderPermutation permutation = graphics->getShaderCompiler()->getTemplate("CachedDepthPass"); Gfx::ShaderPermutation permutation = graphics->getShaderCompiler()->getTemplate("CachedDepthPass");
permutation.setPositionOnly(usePositionOnly); permutation.setPositionOnly(usePositionOnly);
permutation.setViewCulling(useViewCulling); permutation.setDepthCulling(useDepthCulling);
for (VertexData* vertexData : VertexData::getList()) { for (VertexData* vertexData : VertexData::getList()) {
permutation.setVertexData(vertexData->getTypeName()); permutation.setVertexData(vertexData->getTypeName());
vertexData->getInstanceDataSet()->updateBuffer(6, cullingBuffer); vertexData->getInstanceDataSet()->updateBuffer(6, cullingBuffer);
@@ -141,11 +145,14 @@ void CachedDepthPass::render() {
graphics->executeCommands(std::move(commands)); graphics->executeCommands(std::move(commands));
graphics->endRenderPass(); graphics->endRenderPass();
occlusionQuery->endQuery();
numFragments = occlusionQuery->getResults();
} }
void CachedDepthPass::endFrame() {} void CachedDepthPass::endFrame() {}
void CachedDepthPass::publishOutputs() { void CachedDepthPass::publishOutputs() {
occlusionQuery = graphics->createOcclusionQuery();
// If we render to a part of an image, the depth buffer itself must // If we render to a part of an image, the depth buffer itself must
// still match the size of the whole image or their coordinate systems go out of sync // still match the size of the whole image or their coordinate systems go out of sync
TextureCreateInfo depthBufferInfo = { TextureCreateInfo depthBufferInfo = {
@@ -1,5 +1,6 @@
#pragma once #pragma once
#include "RenderPass.h" #include "RenderPass.h"
#include "Graphics/Query.h"
namespace Seele { namespace Seele {
class CachedDepthPass : public RenderPass { class CachedDepthPass : public RenderPass {
@@ -21,6 +22,7 @@ class CachedDepthPass : public RenderPass {
Gfx::OTexture2D visibilityBuffer; Gfx::OTexture2D visibilityBuffer;
Gfx::OPipelineLayout depthPrepassLayout; Gfx::OPipelineLayout depthPrepassLayout;
Gfx::OOcclusionQuery occlusionQuery;
Gfx::PShaderBuffer cullingBuffer; Gfx::PShaderBuffer cullingBuffer;
}; };
DEFINE_REF(CachedDepthPass) DEFINE_REF(CachedDepthPass)
@@ -4,7 +4,7 @@
using namespace Seele; using namespace Seele;
extern bool usePositionOnly; extern bool usePositionOnly;
extern bool useViewCulling; extern bool useDepthCulling;
DepthCullingPass::DepthCullingPass(Gfx::PGraphics graphics, PScene scene) : RenderPass(graphics, scene) { DepthCullingPass::DepthCullingPass(Gfx::PGraphics graphics, PScene scene) : RenderPass(graphics, scene) {
depthTextureLayout = graphics->createDescriptorLayout("pDepthAttachment"); depthTextureLayout = graphics->createDescriptorLayout("pDepthAttachment");
@@ -54,6 +54,8 @@ DepthCullingPass::~DepthCullingPass() {}
void DepthCullingPass::beginFrame(const Component::Camera& cam) { RenderPass::beginFrame(cam); } void DepthCullingPass::beginFrame(const Component::Camera& cam) { RenderPass::beginFrame(cam); }
extern uint64 numFragments;
void DepthCullingPass::render() { void DepthCullingPass::render() {
depthAttachment.getTexture()->changeLayout(Gfx::SE_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, depthAttachment.getTexture()->changeLayout(Gfx::SE_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
Gfx::SE_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT, Gfx::SE_ACCESS_TRANSFER_READ_BIT, Gfx::SE_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT, Gfx::SE_ACCESS_TRANSFER_READ_BIT,
@@ -76,100 +78,107 @@ void DepthCullingPass::render() {
set->updateTexture(0, Gfx::PTexture2D(depthMipTexture)); set->updateTexture(0, Gfx::PTexture2D(depthMipTexture));
set->writeChanges(); set->writeChanges();
occlusionQuery->resetQuery();
occlusionQuery->beginQuery();
graphics->beginRenderPass(renderPass); graphics->beginRenderPass(renderPass);
Array<Gfx::ORenderCommand> commands; if (useDepthCulling) {
Gfx::ShaderPermutation permutation = graphics->getShaderCompiler()->getTemplate("DepthPass"); Array<Gfx::ORenderCommand> commands;
permutation.setPositionOnly(usePositionOnly);
permutation.setViewCulling(useViewCulling);
for (VertexData* vertexData : VertexData::getList()) {
permutation.setVertexData(vertexData->getTypeName());
vertexData->getInstanceDataSet()->updateBuffer(6, cullingBuffer);
vertexData->getInstanceDataSet()->writeChanges();
// Create Pipeline(VertexData)
// Descriptors:
// ViewData => global, static
// VertexData => per meshtype
// SceneData => per meshtype
Gfx::PermutationId id(permutation);
Gfx::ORenderCommand command = graphics->createRenderCommand("DepthRender"); Gfx::ShaderPermutation permutation = graphics->getShaderCompiler()->getTemplate("DepthPass");
command->setViewport(viewport); permutation.setPositionOnly(usePositionOnly);
permutation.setDepthCulling(useDepthCulling);
for (VertexData* vertexData : VertexData::getList()) {
permutation.setVertexData(vertexData->getTypeName());
vertexData->getInstanceDataSet()->updateBuffer(6, cullingBuffer);
vertexData->getInstanceDataSet()->writeChanges();
// Create Pipeline(VertexData)
// Descriptors:
// ViewData => global, static
// VertexData => per meshtype
// SceneData => per meshtype
Gfx::PermutationId id(permutation);
const Gfx::ShaderCollection* collection = graphics->getShaderCompiler()->findShaders(id); Gfx::ORenderCommand command = graphics->createRenderCommand("DepthRender");
assert(collection != nullptr); command->setViewport(viewport);
if (graphics->supportMeshShading()) {
Gfx::MeshPipelineCreateInfo pipelineInfo = { const Gfx::ShaderCollection* collection = graphics->getShaderCompiler()->findShaders(id);
.taskShader = collection->taskShader, assert(collection != nullptr);
.meshShader = collection->meshShader, if (graphics->supportMeshShading()) {
.fragmentShader = collection->fragmentShader, Gfx::MeshPipelineCreateInfo pipelineInfo = {
.renderPass = renderPass, .taskShader = collection->taskShader,
.pipelineLayout = collection->pipelineLayout, .meshShader = collection->meshShader,
.multisampleState = .fragmentShader = collection->fragmentShader,
{ .renderPass = renderPass,
.samples = viewport->getSamples(), .pipelineLayout = collection->pipelineLayout,
}, .multisampleState =
.depthStencilState = {
{ .samples = viewport->getSamples(),
.depthCompareOp = Gfx::SE_COMPARE_OP_GREATER, },
}, .depthStencilState =
.colorBlend = {
{ .depthCompareOp = Gfx::SE_COMPARE_OP_GREATER,
.attachmentCount = 1, },
}, .colorBlend =
}; {
Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo)); .attachmentCount = 1,
command->bindPipeline(pipeline); },
} else { };
Gfx::LegacyPipelineCreateInfo pipelineInfo = { Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo));
.vertexShader = collection->vertexShader, command->bindPipeline(pipeline);
.fragmentShader = collection->fragmentShader, } else {
.renderPass = renderPass, Gfx::LegacyPipelineCreateInfo pipelineInfo = {
.pipelineLayout = collection->pipelineLayout, .vertexShader = collection->vertexShader,
.multisampleState = .fragmentShader = collection->fragmentShader,
{ .renderPass = renderPass,
.samples = viewport->getSamples(), .pipelineLayout = collection->pipelineLayout,
}, .multisampleState =
.depthStencilState = {
{ .samples = viewport->getSamples(),
.depthCompareOp = Gfx::SE_COMPARE_OP_GREATER, },
}, .depthStencilState =
.colorBlend = {
{ .depthCompareOp = Gfx::SE_COMPARE_OP_GREATER,
.attachmentCount = 1, },
}, .colorBlend =
}; {
Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo)); .attachmentCount = 1,
command->bindPipeline(pipeline); },
} };
command->bindDescriptor({viewParamsSet, vertexData->getVertexDataSet(), vertexData->getInstanceDataSet(), set}); Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo));
uint32 offset = 0; command->bindPipeline(pipeline);
command->pushConstants(Gfx::SE_SHADER_STAGE_TASK_BIT_EXT | Gfx::SE_SHADER_STAGE_VERTEX_BIT, 0, sizeof(VertexData::DrawCallOffsets), }
&offset); command->bindDescriptor({viewParamsSet, vertexData->getVertexDataSet(), vertexData->getInstanceDataSet(), set});
if (graphics->supportMeshShading()) { uint32 offset = 0;
command->drawMesh(vertexData->getNumInstances(), 1, 1); command->pushConstants(Gfx::SE_SHADER_STAGE_TASK_BIT_EXT | Gfx::SE_SHADER_STAGE_VERTEX_BIT, 0,
} else { sizeof(VertexData::DrawCallOffsets), &offset);
const auto& materials = vertexData->getMaterialData(); if (graphics->supportMeshShading()) {
for (const auto& materialData : materials) { command->drawMesh(vertexData->getNumInstances(), 1, 1);
for (const auto& drawCall : materialData.instances) { } else {
// material not used for any active meshes, skip const auto& materials = vertexData->getMaterialData();
if (materialData.instances.size() == 0) for (const auto& materialData : materials) {
continue; for (const auto& drawCall : materialData.instances) {
command->bindIndexBuffer(vertexData->getIndexBuffer()); // material not used for any active meshes, skip
uint32 inst = drawCall.offsets.instanceOffset; if (materialData.instances.size() == 0)
for (const auto& meshData : drawCall.instanceMeshData) { continue;
// all meshlets of a mesh share the same indices offset command->bindIndexBuffer(vertexData->getIndexBuffer());
command->drawIndexed(meshData.numIndices, 1, meshData.firstIndex, uint32 inst = drawCall.offsets.instanceOffset;
vertexData->getIndicesOffset(meshData.meshletOffset), inst++); for (const auto& meshData : drawCall.instanceMeshData) {
// all meshlets of a mesh share the same indices offset
command->drawIndexed(meshData.numIndices, 1, meshData.firstIndex,
vertexData->getIndicesOffset(meshData.meshletOffset), inst++);
}
} }
} }
} }
commands.add(std::move(command));
} }
commands.add(std::move(command));
}
graphics->executeCommands(std::move(commands)); graphics->executeCommands(std::move(commands));
}
graphics->endRenderPass(); graphics->endRenderPass();
occlusionQuery->endQuery();
std::cout << "Occlusion fragments: " << occlusionQuery->getResults() + numFragments << std::endl;
// Sync depth read/write with compute read // Sync depth read/write with compute read
depthAttachment.getTexture()->pipelineBarrier( depthAttachment.getTexture()->pipelineBarrier(
Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
@@ -183,6 +192,8 @@ void DepthCullingPass::render() {
void DepthCullingPass::endFrame() {} void DepthCullingPass::endFrame() {}
void DepthCullingPass::publishOutputs() { void DepthCullingPass::publishOutputs() {
occlusionQuery = graphics->createOcclusionQuery();
uint32 width = viewport->getOwner()->getFramebufferWidth(); uint32 width = viewport->getOwner()->getFramebufferWidth();
uint32 height = viewport->getOwner()->getFramebufferHeight(); uint32 height = viewport->getOwner()->getFramebufferHeight();
uint32 mipLevels = static_cast<uint32_t>(std::floor(std::log2(std::max(width, height)))) + 1; uint32 mipLevels = static_cast<uint32_t>(std::floor(std::log2(std::max(width, height)))) + 1;
@@ -1,6 +1,7 @@
#pragma once #pragma once
#include "MinimalEngine.h" #include "MinimalEngine.h"
#include "RenderPass.h" #include "RenderPass.h"
#include "Graphics/Query.h"
namespace Seele { namespace Seele {
class DepthCullingPass : public RenderPass { class DepthCullingPass : public RenderPass {
@@ -22,6 +23,7 @@ class DepthCullingPass : public RenderPass {
Gfx::ODescriptorLayout depthTextureLayout; Gfx::ODescriptorLayout depthTextureLayout;
Gfx::OPipelineLayout depthPrepassLayout; Gfx::OPipelineLayout depthPrepassLayout;
Gfx::OOcclusionQuery occlusionQuery;
Gfx::PShaderBuffer cullingBuffer; Gfx::PShaderBuffer cullingBuffer;
}; };
DEFINE_REF(DepthCullingPass) DEFINE_REF(DepthCullingPass)
+4 -4
View File
@@ -60,7 +60,7 @@ void ShaderCompiler::compile() {
work.add([=]() { work.add([=]() {
ShaderPermutation permutation = getTemplate(name); ShaderPermutation permutation = getTemplate(name);
permutation.setPositionOnly(x); permutation.setPositionOnly(x);
permutation.setViewCulling(y); permutation.setDepthCulling(y);
permutation.setVertexData(vd->getTypeName()); permutation.setVertexData(vd->getTypeName());
OPipelineLayout layout = graphics->createPipelineLayout(pass.baseLayout->getName(), pass.baseLayout); OPipelineLayout layout = graphics->createPipelineLayout(pass.baseLayout->getName(), pass.baseLayout);
layout->addDescriptorLayout(vd->getVertexDataLayout()); layout->addDescriptorLayout(vd->getVertexDataLayout());
@@ -78,7 +78,7 @@ void ShaderCompiler::compile() {
work.add([=]() { work.add([=]() {
ShaderPermutation permutation = getTemplate(name); ShaderPermutation permutation = getTemplate(name);
permutation.setPositionOnly(x); permutation.setPositionOnly(x);
permutation.setViewCulling(y); permutation.setDepthCulling(y);
permutation.setVertexData(vd->getTypeName()); permutation.setVertexData(vd->getTypeName());
OPipelineLayout layout = graphics->createPipelineLayout(pass.baseLayout->getName(), pass.baseLayout); OPipelineLayout layout = graphics->createPipelineLayout(pass.baseLayout->getName(), pass.baseLayout);
layout->addDescriptorLayout(vd->getVertexDataLayout()); layout->addDescriptorLayout(vd->getVertexDataLayout());
@@ -113,8 +113,8 @@ void ShaderCompiler::createShaders(ShaderPermutation permutation, Gfx::OPipeline
if (permutation.positionOnly) { if (permutation.positionOnly) {
createInfo.defines["POS_ONLY"] = "1"; createInfo.defines["POS_ONLY"] = "1";
} }
if (permutation.viewCulling) { if (permutation.depthCulling) {
createInfo.defines["VIEW_CULLING"] = "1"; createInfo.defines["DEPTH_CULLING"] = "1";
} }
if (permutation.visibilityPass) { if (permutation.visibilityPass) {
createInfo.defines["VISIBILITY"] = "1"; createInfo.defines["VISIBILITY"] = "1";
+2 -2
View File
@@ -55,7 +55,7 @@ struct ShaderPermutation {
uint8 hasTaskShader; uint8 hasTaskShader;
uint8 useMaterial; uint8 useMaterial;
uint8 positionOnly; uint8 positionOnly;
uint8 viewCulling; uint8 depthCulling;
uint8 visibilityPass; uint8 visibilityPass;
// TODO: lightmapping etc // TODO: lightmapping etc
ShaderPermutation() { std::memset(this, 0, sizeof(ShaderPermutation)); } ShaderPermutation() { std::memset(this, 0, sizeof(ShaderPermutation)); }
@@ -89,7 +89,7 @@ struct ShaderPermutation {
strncpy(materialName, name.data(), sizeof(materialName)); strncpy(materialName, name.data(), sizeof(materialName));
} }
void setPositionOnly(bool enable) { positionOnly = enable; } void setPositionOnly(bool enable) { positionOnly = enable; }
void setViewCulling(bool enable) { viewCulling = enable; } void setDepthCulling(bool enable) { depthCulling = enable; }
void setVisibilityPass(bool enable) { visibilityPass = enable; } void setVisibilityPass(bool enable) { visibilityPass = enable; }
}; };
// Hashed ShaderPermutation for fast lookup // Hashed ShaderPermutation for fast lookup
@@ -20,6 +20,8 @@ target_sources(Engine
Pipeline.cpp Pipeline.cpp
PipelineCache.h PipelineCache.h
PipelineCache.cpp PipelineCache.cpp
Query.h
Query.cpp
Queue.h Queue.h
Queue.cpp Queue.cpp
RayTracing.h RayTracing.h
@@ -48,6 +50,7 @@ target_sources(Engine
Graphics.h Graphics.h
Pipeline.h Pipeline.h
PipelineCache.h PipelineCache.h
Query.h
Queue.h Queue.h
RayTracing.h RayTracing.h
RenderPass.h RenderPass.h
+2 -2
View File
@@ -181,8 +181,8 @@ void RenderCommand::begin(PRenderPass renderPass, PFramebuffer framebuffer) {
.renderPass = renderPass->getHandle(), .renderPass = renderPass->getHandle(),
.subpass = 0, .subpass = 0,
.framebuffer = framebuffer->getHandle(), .framebuffer = framebuffer->getHandle(),
.occlusionQueryEnable = 0, .occlusionQueryEnable = 1,
.queryFlags = 0, .queryFlags = VK_QUERY_CONTROL_PRECISE_BIT,
.pipelineStatistics = 0, .pipelineStatistics = 0,
}; };
VkCommandBufferBeginInfo beginInfo = { VkCommandBufferBeginInfo beginInfo = {
+4 -2
View File
@@ -12,6 +12,7 @@
#include "RayTracing.h" #include "RayTracing.h"
#include "RenderPass.h" #include "RenderPass.h"
#include "Shader.h" #include "Shader.h"
#include "Query.h"
#include "Window.h" #include "Window.h"
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
#include <cstring> #include <cstring>
@@ -96,7 +97,6 @@ void Graphics::beginRenderPass(Gfx::PRenderPass renderPass) {
void Graphics::endRenderPass() { void Graphics::endRenderPass() {
getGraphicsCommands()->getCommands()->endRenderPass(); getGraphicsCommands()->getCommands()->endRenderPass();
getGraphicsCommands()->submitCommands();
} }
void Graphics::waitDeviceIdle() { vkDeviceWaitIdle(handle); } 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::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) { void Graphics::resolveTexture(Gfx::PTexture source, Gfx::PTexture destination) {
PTextureBase sourceTex = source.cast<TextureBase>(); PTextureBase sourceTex = source.cast<TextureBase>();
PTextureBase destinationTex = destination.cast<TextureBase>(); PTextureBase destinationTex = destination.cast<TextureBase>();
@@ -396,7 +398,6 @@ void Graphics::pickPhysicalDevice() {
features.pNext = &robustness; features.pNext = &robustness;
robustness.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ROBUSTNESS_2_FEATURES_EXT; robustness.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ROBUSTNESS_2_FEATURES_EXT;
robustness.pNext = &features11; robustness.pNext = &features11;
robustness.nullDescriptor = true;
features11.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_FEATURES; features11.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_FEATURES;
features11.pNext = &features12; features11.pNext = &features12;
features12.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES; features12.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES;
@@ -425,6 +426,7 @@ void Graphics::pickPhysicalDevice() {
vkGetPhysicalDeviceProperties(physicalDevice, &props); vkGetPhysicalDeviceProperties(physicalDevice, &props);
vkGetPhysicalDeviceFeatures2(physicalDevice, &features); vkGetPhysicalDeviceFeatures2(physicalDevice, &features);
features.features.robustBufferAccess = 0; features.features.robustBufferAccess = 0;
features.features.inheritedQueries = true;
if (Gfx::useMeshShading) { if (Gfx::useMeshShading) {
uint32 count = 0; uint32 count = 0;
vkEnumerateDeviceExtensionProperties(physicalDevice, NULL, &count, nullptr); 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::OVertexInput createVertexInput(VertexInputStateCreateInfo createInfo) override;
virtual Gfx::OOcclusionQuery createOcclusionQuery() override;
virtual void resolveTexture(Gfx::PTexture source, Gfx::PTexture destination) override; virtual void resolveTexture(Gfx::PTexture source, Gfx::PTexture destination) override;
virtual void copyTexture(Gfx::PTexture src, Gfx::PTexture dst) 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
+3 -7
View File
@@ -18,9 +18,8 @@
using namespace Seele; using namespace Seele;
bool usePositionOnly = false; bool usePositionOnly = false;
bool useViewCulling = false; bool useDepthCulling = false;
bool useLightCulling = false; bool useLightCulling = false;
bool resetVisibility = false;
GameView::GameView(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo& createInfo, std::string dllPath) GameView::GameView(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo& createInfo, std::string dllPath)
: View(graphics, window, createInfo, "Game"), scene(new Scene(graphics)), gameInterface(dllPath) { : View(graphics, window, createInfo, "Game"), scene(new Scene(graphics)), gameInterface(dllPath) {
@@ -92,16 +91,13 @@ void GameView::keyCallback(KeyCode code, InputAction action, KeyModifier modifie
std::cout << "Use Pos only " << usePositionOnly << std::endl; std::cout << "Use Pos only " << usePositionOnly << std::endl;
} }
if (code == KeyCode::KEY_O && action == InputAction::RELEASE) { if (code == KeyCode::KEY_O && action == InputAction::RELEASE) {
useViewCulling = !useViewCulling; useDepthCulling = !useDepthCulling;
std::cout << "Use View Culling " << useViewCulling << std::endl; std::cout << "Use Depth Culling " << useDepthCulling << std::endl;
} }
if (code == KeyCode::KEY_L && action == InputAction::RELEASE) { if (code == KeyCode::KEY_L && action == InputAction::RELEASE) {
useLightCulling = !useLightCulling; useLightCulling = !useLightCulling;
std::cout << "Use Light Culling " << useLightCulling << std::endl; std::cout << "Use Light Culling " << useLightCulling << std::endl;
} }
if (code == KeyCode::KEY_R && action == InputAction::RELEASE) {
resetVisibility = true;
}
} }
void GameView::mouseMoveCallback(double xPos, double yPos) { keyboardSystem->mouseCallback(xPos, yPos); } void GameView::mouseMoveCallback(double xPos, double yPos) { keyboardSystem->mouseCallback(xPos, yPos); }