View Frustum culling for mesh shading
This commit is contained in:
@@ -329,6 +329,7 @@ void MeshLoader::import(MeshImportArgs args, PMeshAsset meshAsset)
|
||||
meshAsset->setStatus(Asset::Status::Loading);
|
||||
Assimp::Importer importer;
|
||||
importer.ReadFile(args.filePath.string().c_str(), (uint32)(
|
||||
aiProcess_ImproveCacheLocality |
|
||||
aiProcess_FlipUVs |
|
||||
aiProcess_Triangulate |
|
||||
aiProcess_SortByPType |
|
||||
|
||||
@@ -12,7 +12,7 @@ Camera::Camera()
|
||||
, bNeedsViewBuild(false)
|
||||
, cameraPos(Vector())
|
||||
{
|
||||
yaw = 3.1415f/2;
|
||||
yaw = -3.1415f/2;
|
||||
pitch = 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -165,7 +165,7 @@ typedef uint32 KeyModifierFlags;
|
||||
namespace Gfx
|
||||
{
|
||||
static constexpr bool useAsyncCompute = true;
|
||||
static constexpr bool waitIdleOnSubmit = true;
|
||||
static constexpr bool waitIdleOnSubmit = false;
|
||||
static constexpr bool useMeshShading = true;
|
||||
static constexpr uint32 numFramesBuffered = 3;
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ void VertexData::updateMesh(PMesh mesh, Component::Transform& transform)
|
||||
.instance = InstanceData {
|
||||
.transformMatrix = transform.toMatrix(),
|
||||
},
|
||||
.data = data
|
||||
.data = data,
|
||||
});
|
||||
}
|
||||
matInstanceData.materialInstance = mesh->referencedMaterial->getHandle();
|
||||
@@ -109,10 +109,12 @@ void VertexData::loadMesh(MeshId id, Array<uint32> loadedIndices, Array<Meshlet>
|
||||
primitiveIndices.resize(primitiveOffset + (m.numPrimitives * 3));
|
||||
std::memcpy(primitiveIndices.data() + primitiveOffset, m.primitiveLayout, m.numPrimitives * 3 * sizeof(uint8));
|
||||
meshlets.add(MeshletDescription{
|
||||
.boundingBox = m.boundingBox,
|
||||
.vertexCount = m.numVertices,
|
||||
.primitiveCount = m.numPrimitives,
|
||||
.vertexOffset = vertexOffset,
|
||||
.primitiveOffset = primitiveOffset,
|
||||
.color = Vector((float)rand() / RAND_MAX, (float)rand() / RAND_MAX, (float)rand() / RAND_MAX),
|
||||
});
|
||||
}
|
||||
meshData[id].add(MeshData{
|
||||
|
||||
@@ -98,6 +98,8 @@ protected:
|
||||
uint32_t primitiveCount;
|
||||
uint32_t vertexOffset;
|
||||
uint32_t primitiveOffset;
|
||||
Vector color;
|
||||
float pad0;
|
||||
};
|
||||
Map<std::string, MaterialData> materialData;
|
||||
Map<MeshId, Array<MeshData>> meshData;
|
||||
|
||||
@@ -216,23 +216,35 @@ OSubAllocation Allocator::allocate(const VkMemoryRequirements2 &memRequirements2
|
||||
return heaps[heapIndex].allocations.back()->getSuballocation(requirements.size, requirements.alignment);
|
||||
}
|
||||
|
||||
void Allocator::free(PAllocation allocation)
|
||||
void Allocator::free()
|
||||
{
|
||||
//std::cout << "Freeing allocation" << std::endl;
|
||||
for (uint32 heapIndex = 0; heapIndex < heaps.size(); ++heapIndex)
|
||||
{
|
||||
for (uint32 alloc = 0; alloc < heaps[heapIndex].allocations.size(); ++alloc)
|
||||
{
|
||||
if (heaps[heapIndex].allocations[alloc] == allocation)
|
||||
if (heaps[heapIndex].allocations[alloc]->bytesUsed == 0)
|
||||
{
|
||||
heaps[heapIndex].inUse -= allocation->bytesAllocated;
|
||||
heaps[heapIndex].inUse -= heaps[heapIndex].allocations[alloc]->bytesAllocated;
|
||||
std::cout << "Heap " << heapIndex << ": " << (float)heaps[heapIndex].inUse / heaps[heapIndex].maxSize * 100 << "%" << std::endl;
|
||||
heaps[heapIndex].allocations.removeAt(alloc, false);
|
||||
return;
|
||||
alloc--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Allocator::print()
|
||||
{
|
||||
for (uint32 heapIndex = 0; heapIndex < heaps.size(); ++heapIndex)
|
||||
{
|
||||
std::cout << "Heap " << heapIndex << std::endl;
|
||||
for (uint32 alloc = 0; alloc < heaps[heapIndex].allocations.size(); ++alloc)
|
||||
{
|
||||
std::cout << "[" << alloc << "]: " << (float)heaps[heapIndex].allocations[alloc]->bytesUsed / heaps[heapIndex].allocations[alloc]->bytesAllocated << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint32 Allocator::findMemoryType(uint32 typeFilter, VkMemoryPropertyFlags properties)
|
||||
{
|
||||
for (uint32 i = 0; i < memProperties.memoryTypeCount; i++)
|
||||
|
||||
@@ -122,7 +122,8 @@ public:
|
||||
return allocate(requirements, props, &allocInfo);
|
||||
}
|
||||
|
||||
void free(PAllocation allocation);
|
||||
void free();
|
||||
void print();
|
||||
private:
|
||||
static constexpr VkDeviceSize DEFAULT_ALLOCATION = 16 * 1024 * 1024; // 16MB
|
||||
struct HeapInfo
|
||||
|
||||
@@ -448,7 +448,7 @@ void Graphics::pickPhysicalDevice()
|
||||
{
|
||||
if (std::strcmp(VK_EXT_MESH_SHADER_EXTENSION_NAME, extensionProps[i].extensionName) == 0)
|
||||
{
|
||||
//meshShadingEnabled = true;
|
||||
meshShadingEnabled = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,4 +170,5 @@ void DestructionManager::notifyCmdComplete(PCommand cmd)
|
||||
sems[cmd].clear();
|
||||
renderPasses[cmd].clear();
|
||||
allocs[cmd].clear();
|
||||
//graphics->getAllocator()->free();
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
#include "System/LightGather.h"
|
||||
#include "System/MeshUpdater.h"
|
||||
#include "System/CameraUpdater.h"
|
||||
#include "Graphics/Vulkan/Graphics.h"
|
||||
#include "Graphics/Vulkan/Allocator.h"
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
@@ -96,6 +98,10 @@ void GameView::reloadGame()
|
||||
|
||||
void GameView::keyCallback(KeyCode code, InputAction action, KeyModifier modifier)
|
||||
{
|
||||
if (code == KeyCode::KEY_P && action == InputAction::PRESS)
|
||||
{
|
||||
((Vulkan::Graphics*)graphics.getHandle())->getAllocator()->print();
|
||||
}
|
||||
keyboardSystem->keyCallback(code, action, modifier);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user