Adding basic memory resource

This commit is contained in:
Dynamitos
2025-03-20 20:15:38 +01:00
parent 51d759639e
commit e7ba74e258
47 changed files with 398 additions and 300 deletions
+2 -3
View File
@@ -120,7 +120,7 @@ uint32_t find_msb_64(uint64_t x) {
CPUMesh Seele::generateCPUMesh(uint32 cbtNumElements) {
CPUMesh result;
result.totalNumElements = edges.size() + cbtNumElements;
result.totalNumElements = (uint32)edges.size() + cbtNumElements;
result.heapIDArray.resize(result.totalNumElements);
result.neighborsArray.resize(result.totalNumElements);
@@ -193,7 +193,6 @@ Matrix3 decodeSubdivisionMatrix(uint64 heapID) {
void LebMatrixCache::init(Gfx::PGraphics graphics, uint32 depth) {
cacheDepth = depth;
uint32 matrixCount = 2ULL << cacheDepth;
Matrix3 m;
std::vector<Matrix3> table(matrixCount);
table[0] = Matrix3({1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f});
for (uint64 heapID = 1ULL; heapID < (2ULL << cacheDepth); ++heapID) {
@@ -799,7 +798,7 @@ void MeshUpdater::update(CBTMesh& mesh, Gfx::PDescriptorSet viewParamsSet, Gfx::
}
void MeshUpdater::validation(CBTMesh& mesh, Gfx::PUniformBuffer geometryCB) {
uint32 numGroups = (mesh.totalNumElements + WORKGROUP_SIZE - 1) / WORKGROUP_SIZE;
//uint32 numGroups = (mesh.totalNumElements + WORKGROUP_SIZE - 1) / WORKGROUP_SIZE;
/*Gfx::PDescriptorSet set = layout->allocateDescriptorSet();
set->updateBuffer(GEOMETRY_CB, 0, geometryCB);
+1 -1
View File
@@ -1,4 +1,4 @@
add_subdirectory(CBT/)
#add_subdirectory(CBT/)
target_sources(Engine
PRIVATE
+1 -1
View File
@@ -25,7 +25,7 @@ void buildAdjacency(const uint32 numVerts, const Array<uint32>& indices, Adjacen
triangleOffset += info.trianglesPerVertex[j];
}
uint32 numTriangles = indices.size() / 3;
uint32 numTriangles = (uint32)indices.size() / 3;
info.triangleData.resize(triangleOffset);
Array<uint32> offsets = info.indexBufferOffset;
for (uint32 k = 0; k < numTriangles; ++k) {
+5 -7
View File
@@ -200,8 +200,7 @@ void BasePass::render() {
.attachmentCount = 1,
},
};
Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo));
command->bindPipeline(pipeline);
command->bindPipeline(graphics->createGraphicsPipeline(std::move(pipelineInfo)));
} else {
Gfx::LegacyPipelineCreateInfo pipelineInfo = {
.vertexShader = collection->vertexShader,
@@ -221,8 +220,7 @@ void BasePass::render() {
.attachmentCount = 1,
},
};
Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo));
command->bindPipeline(pipeline);
command->bindPipeline(graphics->createGraphicsPipeline(std::move(pipelineInfo)));
}
command->bindDescriptor({viewParamsSet, vertexData->getVertexDataSet(), vertexData->getInstanceDataSet(),
scene->getLightEnvironment()->getDescriptorSet(), Material::getDescriptorSet(), opaqueCulling});
@@ -231,7 +229,7 @@ void BasePass::render() {
Gfx::SE_SHADER_STAGE_FRAGMENT_BIT,
0, sizeof(VertexData::DrawCallOffsets), &drawCall.offsets);
if (graphics->supportMeshShading()) {
command->drawMesh(drawCall.instanceMeshData.size(), 1, 1);
command->drawMesh((uint32)drawCall.instanceMeshData.size(), 1, 1);
} else {
command->bindIndexBuffer(vertexData->getIndexBuffer());
for (const auto& meshData : drawCall.instanceMeshData) {
@@ -252,7 +250,7 @@ void BasePass::render() {
{
Gfx::ORenderCommand skyboxCommand = graphics->createRenderCommand("SkyboxRender");
skyboxCommand->setViewport(viewport);
skyboxCommand->bindPipeline(pipeline);
skyboxCommand->bindPipeline(skyboxPipeline);
skyboxCommand->bindDescriptor({viewParamsSet, skyboxDataSet, textureSet});
skyboxCommand->draw(36, 1, 0, 0);
graphics->executeCommands(std::move(skyboxCommand));
@@ -623,6 +621,6 @@ void BasePass::createRenderPass() {
.attachmentCount = 1,
},
};
pipeline = graphics->createGraphicsPipeline(std::move(gfxInfo));
skyboxPipeline = graphics->createGraphicsPipeline(std::move(gfxInfo));
}
}
+2 -3
View File
@@ -2,7 +2,6 @@
#include "MinimalEngine.h"
#include "RenderPass.h"
#include "WaterRenderer.h"
#include "TerrainRenderer.h"
namespace Seele {
DECLARE_REF(CameraActor)
@@ -56,7 +55,7 @@ class BasePass : public RenderPass {
Gfx::PShaderBuffer cullingBuffer;
//OWaterRenderer waterRenderer;
OTerrainRenderer terrainRenderer;
//OTerrainRenderer terrainRenderer;
// Debug rendering
Gfx::OVertexInput debugVertexInput;
@@ -74,7 +73,7 @@ class BasePass : public RenderPass {
Gfx::OVertexShader vertexShader;
Gfx::OFragmentShader fragmentShader;
Gfx::OPipelineLayout pipelineLayout;
Gfx::PGraphicsPipeline pipeline;
Gfx::PGraphicsPipeline skyboxPipeline;
Gfx::OSampler skyboxSampler;
struct SkyboxData {
Matrix4 transformMatrix;
@@ -15,8 +15,8 @@ target_sources(Engine
RenderGraphResources.cpp
RenderPass.h
RenderPass.cpp
TerrainRenderer.h
TerrainRenderer.cpp
#TerrainRenderer.h
#TerrainRenderer.cpp
ToneMappingPass.h
ToneMappingPass.cpp
UIPass.h
@@ -38,6 +38,6 @@ target_sources(Engine
RenderGraph.h
RenderGraphResources.h
RenderPass.h
TerrainRenderer.h
#TerrainRenderer.h
UIPass.h
VisibilityPass.h)
@@ -111,7 +111,7 @@ void CachedDepthPass::render() {
command->pushConstants(Gfx::SE_SHADER_STAGE_TASK_BIT_EXT | Gfx::SE_SHADER_STAGE_VERTEX_BIT, 0, sizeof(VertexData::DrawCallOffsets),
&offsets);
if (graphics->supportMeshShading()) {
command->drawMesh(vertexData->getNumInstances(), 1, 1);
command->drawMesh((uint32)vertexData->getNumInstances(), 1, 1);
} else {
const auto& materials = vertexData->getMaterialData();
for (const auto& materialData : materials) {
@@ -185,7 +185,7 @@ void DepthCullingPass::render() {
command->pushConstants(Gfx::SE_SHADER_STAGE_TASK_BIT_EXT | Gfx::SE_SHADER_STAGE_VERTEX_BIT, 0, sizeof(VertexData::DrawCallOffsets),
&offsets);
if (graphics->supportMeshShading()) {
command->drawMesh(vertexData->getNumInstances(), 1, 1);
command->drawMesh((uint32)vertexData->getNumInstances(), 1, 1);
} else {
const auto& materials = vertexData->getMaterialData();
for (const auto& materialData : materials) {
@@ -278,7 +278,7 @@ void LightCullingPass::setupFrustums() {
frustumBuffer->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT, Gfx::SE_ACCESS_SHADER_WRITE_BIT,
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
Gfx::PDescriptorSet dispatchParamsSet = dispatchParamsLayout->allocateDescriptorSet();
dispatchParamsSet = dispatchParamsLayout->allocateDescriptorSet();
dispatchParamsSet->updateConstants("numThreadGroups", 0, &numThreadGroups);
dispatchParamsSet->updateConstants("numThreads", 0, &numThreads);
dispatchParamsSet->updateBuffer(FRUSTUMBUFFER_NAME, 0, frustumBuffer);
@@ -292,8 +292,5 @@ void LightCullingPass::setupFrustums() {
commands.add(std::move(command));
graphics->executeCommands(std::move(commands));
frustumBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
Frustum* frustums = (Frustum*)frustumBuffer->map();
graphics->waitDeviceIdle();
Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
}
@@ -25,7 +25,7 @@ TerrainRenderer::TerrainRenderer(Gfx::PGraphics graphics, PScene scene, Gfx::PDe
plainMesh.gpuCBT.bufferCount = 2;
for (uint32 i = 0; i < 2; ++i) {
uint32 bufferSize = cbt.bufferSize(i);
uint32 elementSize = cbt.elementSize(i);
//uint32 elementSize = cbt.elementSize(i);
plainMesh.gpuCBT.bufferArray[i] = graphics->createShaderBuffer(ShaderBufferCreateInfo{
.sourceData =
{
@@ -189,7 +189,7 @@ TerrainRenderer::TerrainRenderer(Gfx::PGraphics graphics, PScene scene, Gfx::PDe
baseMesh.vertexBuffer->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT,
Gfx::SE_ACCESS_SHADER_READ_BIT | Gfx::SE_ACCESS_SHADER_WRITE_BIT,
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
uint32 indexBufferSize = cpuMesh.totalNumElements * sizeof(UVector);
//uint32 indexBufferSize = cpuMesh.totalNumElements * sizeof(UVector);
Array<uint32> indices;
for (uint32 i = 0; i < cpuMesh.totalNumElements * 3; ++i)
indices.add(i);
+3 -3
View File
@@ -62,9 +62,9 @@ void UIPass::beginFrame(const Component::Camera& cam) {
float x = render.position.x;
float y = render.position.y;
//todo: convert using actual tree depth
uint32 textureIndex = -1ul;
uint32 textureIndex = std::numeric_limits<uint32>::max();
if (render.backgroundTexture != nullptr) {
textureIndex = usedTextures.size();
textureIndex = (uint32)usedTextures.size();
usedTextures.add(render.backgroundTexture);
}
elements.add(RenderElementStyle{
@@ -112,7 +112,7 @@ void UIPass::render() {
command->setViewport(viewport);
command->bindPipeline(uiPipeline);
command->bindDescriptor({viewParamsSet, uiDescriptorSet});
command->draw(4, elements.size(), 0, 0);
command->draw(4, (uint32)elements.size(), 0, 0);
commands.add(std::move(command));
graphics->executeCommands(std::move(commands));
graphics->endRenderPass();
+1 -1
View File
@@ -42,7 +42,7 @@ class UIPass : public RenderPass {
Vector color;
float opacity = 1;
float z = 0;
uint32 textureIndex = -1ul;
uint32 textureIndex = std::numeric_limits<uint32>::max();
uint32 pad0;
uint32 pad1;
};
+1 -1
View File
@@ -245,7 +245,7 @@ void StaticMeshVertexData::updateBuffers() {
descriptorSet->updateBuffer(TANGENTS_NAME, 0, tangents);
descriptorSet->updateBuffer(BITANGENTS_NAME, 0, biTangents);
descriptorSet->updateBuffer(COLORS_NAME, 0, colors);
for (size_t i = 0; i < MAX_TEXCOORDS; ++i) {
for (uint32 i = 0; i < MAX_TEXCOORDS; ++i) {
descriptorSet->updateBuffer(TEXCOORDS_NAME, i, texCoords[i]);
}
descriptorSet->writeChanges();
+1 -3
View File
@@ -5,7 +5,6 @@
#include "VertexData.h"
#include "entt/entt.hpp"
namespace Seele {
class StaticMeshVertexData : public VertexData {
public:
@@ -39,7 +38,6 @@ class StaticMeshVertexData : public VertexData {
virtual void resizeBuffers() override;
virtual void updateBuffers() override;
Gfx::OShaderBuffer positions;
constexpr static const char* POSITIONS_NAME = "positions";
Gfx::OShaderBuffer texCoords[MAX_TEXCOORDS];
@@ -52,7 +50,7 @@ class StaticMeshVertexData : public VertexData {
constexpr static const char* BITANGENTS_NAME = "biTangents";
Gfx::OShaderBuffer colors;
constexpr static const char* COLORS_NAME = "colors";
Array<PositionType> posData;
Array<PositionType> posData{debug_resource::get("VertexPositions")};
Array<TexCoordType> texData[MAX_TEXCOORDS];
Array<NormalType> norData;
Array<TangentType> tanData;
+6 -6
View File
@@ -90,7 +90,7 @@ void VertexData::createDescriptors() {
Array<uint32> cullingOffsets;
for (auto& mat : materialData) {
for (auto& instance : mat.instances) {
instance.offsets.instanceOffset = instanceData.size();
instance.offsets.instanceOffset = (uint32)instanceData.size();
MaterialOffsets offsets = instance.materialInstance->getMaterialOffsets();
instance.offsets.textureOffset = offsets.textureOffset;
instance.offsets.samplerOffset = offsets.samplerOffset;
@@ -104,7 +104,7 @@ void VertexData::createDescriptors() {
}
}
for (uint32 i = 0; i < transparentData.size(); ++i) {
transparentData[i].offsets.instanceOffset = instanceData.size();
transparentData[i].offsets.instanceOffset = (uint32)instanceData.size();
cullingOffsets.add(transparentData[i].cullingOffset);
instanceData.add(transparentData[i].instanceData);
instanceMeshData.add(transparentData[i].meshData);
@@ -139,17 +139,17 @@ void VertexData::createDescriptors() {
void VertexData::loadMesh(MeshId id, Array<uint32> loadedIndices, Array<Meshlet> loadedMeshlets) {
std::unique_lock l(vertexDataLock);
for (auto&& chunk : loadedMeshlets | std::views::chunk(2048)) {
uint32 meshletOffset = meshlets.size();
uint32 meshletOffset = (uint32)meshlets.size();
AABB meshAABB;
uint32 numMeshlets = 0;
for (auto&& m : chunk) {
numMeshlets++;
//...
meshAABB = meshAABB.combine(m.boundingBox);
uint32 vertexOffset = vertexIndices.size();
uint32 vertexOffset = (uint32)vertexIndices.size();
vertexIndices.resize(vertexOffset + m.numVertices);
std::memcpy(vertexIndices.data() + vertexOffset, m.uniqueVertices, m.numVertices * sizeof(uint32));
uint32 primitiveOffset = primitiveIndices.size();
uint32 primitiveOffset = (uint32)primitiveIndices.size();
primitiveIndices.resize(primitiveOffset + (m.numPrimitives * 3));
std::memcpy(primitiveIndices.data() + primitiveOffset, m.primitiveLayout, m.numPrimitives * 3 * sizeof(uint8));
meshlets.add(MeshletDescription{
@@ -349,7 +349,7 @@ void VertexData::destroy() {
}
uint32 VertexData::addCullingMapping(MeshId id) {
uint32 result = meshletCount;
uint32 result = (uint32)meshletCount;
for (const auto& md : getMeshData(id)) {
meshletCount += md.numMeshlets;
}
+4 -5
View File
@@ -8,7 +8,7 @@
#include "Meshlet.h"
#include <entt/entt.hpp>
constexpr uint64 MAX_TEXCOORDS = 8;
constexpr uint32 MAX_TEXCOORDS = 8;
namespace Seele {
DECLARE_REF(MaterialInstance)
@@ -77,10 +77,8 @@ class VertexData {
const Array<TransparentDraw>& getTransparentData() const { return transparentData; }
const Array<Gfx::PBottomLevelAS>& getRayTracingData() const { return rayTracingScene; }
const Array<MeshData>& getMeshData(MeshId id) const { return meshData[id]; }
void registerBottomLevelAccelerationStructure(Gfx::PBottomLevelAS blas) {
dataToBuild.add(blas);
}
uint64 getIndicesOffset(uint32 meshletIndex) { return meshlets[meshletIndex].indicesOffset; }
void registerBottomLevelAccelerationStructure(Gfx::PBottomLevelAS blas) { dataToBuild.add(blas); }
uint32 getIndicesOffset(uint32 meshletIndex) { return meshlets[meshletIndex].indicesOffset; }
uint64 getNumInstances() const { return instanceData.size(); }
static List<VertexData*> getList();
static VertexData* findByTypeName(std::string name);
@@ -110,6 +108,7 @@ class VertexData {
uint32 indicesOffset = 0;
};
std::mutex materialDataLock;
debug_resource vertexDataResource = {"VertexData"};
Array<MaterialData> materialData;
Array<TransparentDraw> transparentData;
+2 -2
View File
@@ -51,11 +51,11 @@ void DescriptorLayout::create() {
constantsSize += gfxBinding.uniformLength;
constantsStages |= gfxBinding.shaderStages;
} else {
mappings[gfxBinding.name] = {
mappings[gfxBinding.name] = DescriptorMapping{
.binding = (uint32)bindings.size(),
.type = cast(gfxBinding.descriptorType),
};
bindings.add({
bindings.add(VkDescriptorSetLayoutBinding{
.binding = (uint32)bindings.size(),
.descriptorType = cast(gfxBinding.descriptorType),
.descriptorCount = gfxBinding.descriptorCount,
+2 -5
View File
@@ -321,7 +321,7 @@ Gfx::OPipelineStatisticsQuery Graphics::createPipelineStatisticsQuery(const std:
return new PipelineStatisticsQuery(this, name);
}
Gfx::OTimestampQuery Graphics::createTimestampQuery(uint64 numTimestamps, const std::string& name) {
Gfx::OTimestampQuery Graphics::createTimestampQuery(uint64, const std::string& name) {
return new TimestampQuery(this, name);
}
@@ -457,9 +457,6 @@ void Graphics::buildBottomLevelAccelerationStructures(Array<Gfx::PBottomLevelAS>
// For the sake of simplicity we won't stage the vertex data to the GPU memory
// Note that the buffer usage flags for buffers consumed by the bottom level acceleration structure require special flags
const VkBufferUsageFlags buffer_usage_flags = VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_BIT_KHR |
VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT;
VkBufferCreateInfo transformBufferInfo = {
.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
.pNext = nullptr,
@@ -593,7 +590,7 @@ void Graphics::buildBottomLevelAccelerationStructures(Array<Gfx::PBottomLevelAS>
}
PCommand cmd = graphicsCommands->getCommands();
vkCmdBuildAccelerationStructuresKHR(cmd->getHandle(), buildGeometries.size(), buildGeometries.data(), buildRangePointers.data());
vkCmdBuildAccelerationStructuresKHR(cmd->getHandle(), (uint32)buildGeometries.size(), buildGeometries.data(), buildRangePointers.data());
cmd->bindResource(PBufferAllocation(transformBuffer));
destructionManager->queueResourceForDestruction(std::move(transformBuffer));
for (auto& scratchAlloc : scratchBuffers) {
+3 -3
View File
@@ -508,7 +508,7 @@ PRayTracingPipeline PipelineCache::createPipeline(Gfx::RayTracingPipelineCreateI
uint32 intersectionIndex = VK_SHADER_UNUSED_KHR;
if (hitgroup.anyHitShader != nullptr) {
auto anyHit = hitgroup.anyHitShader.cast<AnyHitShader>();
anyHitIndex = shaderStages.size();
anyHitIndex = (uint32)shaderStages.size();
shaderStages.add(VkPipelineShaderStageCreateInfo{
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
.pNext = nullptr,
@@ -521,7 +521,7 @@ PRayTracingPipeline PipelineCache::createPipeline(Gfx::RayTracingPipelineCreateI
}
if (hitgroup.intersectionShader != nullptr) {
auto intersect = hitgroup.intersectionShader.cast<IntersectionShader>();
intersectionIndex = shaderGroups.size();
intersectionIndex = (uint32)shaderGroups.size();
shaderStages.add(VkPipelineShaderStageCreateInfo{
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
.pNext = nullptr,
@@ -674,7 +674,7 @@ PRayTracingPipeline PipelineCache::createPipeline(Gfx::RayTracingPipelineCreateI
Gfx::QueueType::GRAPHICS, sbtAlignment);
Array<uint8> sbt(sbtSize);
vkGetRayTracingShaderGroupHandlesKHR(graphics->getDevice(), pipelineHandle, 0, shaderGroups.size(), sbtSize, sbt.data());
vkGetRayTracingShaderGroupHandlesKHR(graphics->getDevice(), pipelineHandle, 0, (uint32)shaderGroups.size(), sbtSize, sbt.data());
uint64 sbtOffset = 0;
Array<uint8> rayGenSbt(rayGenStride);
+1 -1
View File
@@ -106,7 +106,7 @@ TopLevelAS::TopLevelAS(PGraphics graphics, const Gfx::TopLevelASCreateInfo& crea
.pGeometries = &geometry,
};
const uint32 primitiveCount = instances.size();
const uint32 primitiveCount = (uint32)instances.size();
VkAccelerationStructureBuildSizesInfoKHR buildSizesInfo = {
.sType = VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_BUILD_SIZES_INFO_KHR,
+2 -2
View File
@@ -77,7 +77,7 @@ void Seele::beginCompilation(const ShaderCompilationInfo& info, SlangCompileTarg
};
sessionDesc.compilerOptionEntries = option.data();
sessionDesc.compilerOptionEntryCount = option.size();
sessionDesc.compilerOptionEntryCount = (uint32)option.size();
sessionDesc.defaultMatrixLayoutMode = SLANG_MATRIX_LAYOUT_COLUMN_MAJOR;
Array<slang::PreprocessorMacroDesc> macros;
for (const auto& [key, val] : info.defines) {
@@ -140,7 +140,7 @@ void Seele::beginCompilation(const ShaderCompilationInfo& info, SlangCompileTarg
slang::ProgramLayout* signature = specializedComponent->getLayout(0, diagnostics.writeRef());
CHECK_DIAGNOSTICS();
std::cout << info.name << std::endl;
for (size_t i = 0; i < signature->getParameterCount(); ++i) {
for (uint32 i = 0; i < signature->getParameterCount(); ++i) {
auto param = signature->getParameterByIndex(i);
layout->addMapping(param->getName(), param->getBindingIndex());
//std::cout << param->getName() << ": " << param->getBindingIndex() << std::endl;