More Ray tracing changes
This commit is contained in:
Vendored
+1
-1
Submodule external/slang updated: 4b8ceed9d6...f83fe55a8c
@@ -1,5 +1,4 @@
|
||||
#include "Buffer.h"
|
||||
#include "Buffer.h"
|
||||
|
||||
using namespace Seele;
|
||||
using namespace Seele::Gfx;
|
||||
@@ -42,6 +41,7 @@ IndexBuffer::IndexBuffer(QueueFamilyMapping mapping, uint64 size, Gfx::SeIndexTy
|
||||
IndexBuffer::~IndexBuffer()
|
||||
{
|
||||
}
|
||||
|
||||
UniformBuffer::UniformBuffer(QueueFamilyMapping mapping, const DataSource& sourceData)
|
||||
: Buffer(mapping, sourceData.owner)
|
||||
{}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
#include "Resources.h"
|
||||
#include "Initializer.h"
|
||||
|
||||
namespace Seele {
|
||||
namespace Gfx {
|
||||
|
||||
@@ -14,10 +14,13 @@ target_sources(Engine
|
||||
Initializer.h
|
||||
Mesh.h
|
||||
Mesh.cpp
|
||||
MeshData.h
|
||||
Meshlet.h
|
||||
Meshlet.cpp
|
||||
Pipeline.h
|
||||
Pipeline.cpp
|
||||
RayTracing.h
|
||||
RayTracing.cpp
|
||||
RenderTarget.h
|
||||
RenderTarget.cpp
|
||||
Resources.h
|
||||
@@ -47,7 +50,9 @@ target_sources(Engine
|
||||
Initializer.h
|
||||
Mesh.h
|
||||
Meshlet.h
|
||||
MeshData.h
|
||||
Pipeline.h
|
||||
RayTracing.h
|
||||
RenderTarget.h
|
||||
Resources.h
|
||||
Shader.h
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
#include "Enums.h"
|
||||
#include "Resources.h"
|
||||
#include <compare>
|
||||
#include "Initializer.h"
|
||||
|
||||
namespace Seele {
|
||||
namespace Gfx {
|
||||
@@ -19,17 +19,19 @@ DECLARE_REF(DescriptorPool)
|
||||
DECLARE_REF(DescriptorSet)
|
||||
class DescriptorLayout {
|
||||
public:
|
||||
DescriptorLayout(const std::string& name);
|
||||
DescriptorLayout(const DescriptorLayout& other);
|
||||
DescriptorLayout& operator=(const DescriptorLayout& other);
|
||||
DescriptorLayout(const std::string &name);
|
||||
DescriptorLayout(const DescriptorLayout &other);
|
||||
DescriptorLayout &operator=(const DescriptorLayout &other);
|
||||
virtual ~DescriptorLayout();
|
||||
void addDescriptorBinding(DescriptorBinding binding);
|
||||
void reset();
|
||||
PDescriptorSet allocateDescriptorSet();
|
||||
virtual void create() = 0;
|
||||
constexpr const Array<DescriptorBinding>& getBindings() const { return descriptorBindings; }
|
||||
constexpr const Array<DescriptorBinding> &getBindings() const {
|
||||
return descriptorBindings;
|
||||
}
|
||||
constexpr uint32 getHash() const { return hash; }
|
||||
constexpr const std::string& getName() const { return name; }
|
||||
constexpr const std::string &getName() const { return name; }
|
||||
|
||||
protected:
|
||||
Array<DescriptorBinding> descriptorBindings;
|
||||
@@ -61,40 +63,48 @@ public:
|
||||
virtual void writeChanges() = 0;
|
||||
virtual void updateBuffer(uint32 binding, PUniformBuffer uniformBuffer) = 0;
|
||||
virtual void updateBuffer(uint32 binding, PShaderBuffer ShaderBuffer) = 0;
|
||||
virtual void updateBuffer(uint32_t binding, uint32 index, Gfx::PShaderBuffer uniformBuffer) = 0;
|
||||
virtual void updateBuffer(uint32_t binding, uint32 index,
|
||||
Gfx::PShaderBuffer uniformBuffer) = 0;
|
||||
virtual void updateSampler(uint32 binding, PSampler sampler) = 0;
|
||||
virtual void updateTexture(uint32 binding, PTexture texture, PSampler samplerState = nullptr) = 0;
|
||||
virtual void updateTextureArray(uint32_t binding, Array<PTexture> texture) = 0;
|
||||
virtual void updateTexture(uint32 binding, PTexture texture,
|
||||
PSampler samplerState = nullptr) = 0;
|
||||
virtual void updateTextureArray(uint32_t binding,
|
||||
Array<PTexture> texture) = 0;
|
||||
bool operator<(PDescriptorSet other);
|
||||
|
||||
constexpr PDescriptorLayout getLayout() const { return layout; }
|
||||
constexpr const std::string& getName() const { return layout->getName(); }
|
||||
constexpr const std::string &getName() const { return layout->getName(); }
|
||||
|
||||
protected:
|
||||
PDescriptorLayout layout;
|
||||
};
|
||||
DEFINE_REF(DescriptorSet)
|
||||
|
||||
DECLARE_REF(PipelineLayout)
|
||||
class PipelineLayout {
|
||||
public:
|
||||
PipelineLayout(const std::string& name);
|
||||
PipelineLayout(const std::string& name, PPipelineLayout baseLayout);
|
||||
PipelineLayout(const std::string &name);
|
||||
PipelineLayout(const std::string &name, PPipelineLayout baseLayout);
|
||||
virtual ~PipelineLayout();
|
||||
virtual void create() = 0;
|
||||
void addDescriptorLayout(PDescriptorLayout layout);
|
||||
void addPushConstants(const SePushConstantRange& pushConstants);
|
||||
void addPushConstants(const SePushConstantRange &pushConstants);
|
||||
constexpr uint32 getHash() const { return layoutHash; }
|
||||
constexpr const Map<std::string, PDescriptorLayout>& getLayouts() const { return descriptorSetLayouts; }
|
||||
constexpr uint32 findParameter(const std::string& param) const { return parameterMapping[param]; }
|
||||
void addMapping(Map<std::string, uint32> mapping);
|
||||
constexpr std::string getName() const {return name;};
|
||||
constexpr const Map<std::string, PDescriptorLayout> &getLayouts() const {
|
||||
return descriptorSetLayouts;
|
||||
}
|
||||
constexpr uint32 findParameter(const std::string ¶m) const {
|
||||
return parameterMapping[param];
|
||||
}
|
||||
void addMapping(Map<std::string, uint32> mapping);
|
||||
constexpr std::string getName() const { return name; };
|
||||
|
||||
protected:
|
||||
uint32 layoutHash = 0;
|
||||
Map<std::string, PDescriptorLayout> descriptorSetLayouts;
|
||||
Map<std::string, uint32> parameterMapping;
|
||||
Map<std::string, uint32> parameterMapping;
|
||||
Array<SePushConstantRange> pushConstants;
|
||||
std::string name;
|
||||
std::string name;
|
||||
};
|
||||
DEFINE_REF(PipelineLayout)
|
||||
} // namespace Gfx
|
||||
|
||||
@@ -31,6 +31,8 @@ DECLARE_REF(GraphicsPipeline)
|
||||
DECLARE_REF(ComputePipeline)
|
||||
DECLARE_REF(RenderCommand)
|
||||
DECLARE_REF(ComputeCommand)
|
||||
DECLARE_REF(BottomLevelAS)
|
||||
DECLARE_REF(TopLevelAS)
|
||||
class Graphics
|
||||
{
|
||||
public:
|
||||
@@ -88,6 +90,10 @@ public:
|
||||
virtual void resolveTexture(Gfx::PTexture source, Gfx::PTexture destination) = 0;
|
||||
|
||||
bool supportMeshShading() const { return meshShadingEnabled; }
|
||||
|
||||
// Ray Tracing
|
||||
virtual OBottomLevelAS createBottomLevelAccelerationStructure(const BottomLevelASCreateInfo& createInfo) = 0;
|
||||
virtual OTopLevelAS createTopLevelAccelerationStructure(const TopLevelASCreateInfo& createInfo) = 0;
|
||||
protected:
|
||||
QueueFamilyMapping queueMapping;
|
||||
OShaderCompiler shaderCompiler;
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
#include "Enums.h"
|
||||
#include "Containers/Map.h"
|
||||
#include "Math/Math.h"
|
||||
#include "MinimalEngine.h"
|
||||
#include "MeshData.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
@@ -113,6 +115,7 @@ namespace Seele
|
||||
DataSource sourceData = DataSource();
|
||||
uint64 numElements = 1;
|
||||
uint8 dynamic = 0;
|
||||
uint8 vertexBuffer = 0;
|
||||
std::string name = "Unnamed";
|
||||
};
|
||||
DECLARE_NAME_REF(Gfx, PipelineLayout)
|
||||
@@ -144,6 +147,7 @@ namespace Seele
|
||||
Array<VertexInputBinding> bindings;
|
||||
Array<VertexInputAttribute> attributes;
|
||||
};
|
||||
DECLARE_REF(MaterialInstance)
|
||||
namespace Gfx
|
||||
{
|
||||
struct SePushConstantRange
|
||||
@@ -244,5 +248,19 @@ namespace Seele
|
||||
Gfx::PComputeShader computeShader = nullptr;
|
||||
Gfx::PPipelineLayout pipelineLayout = nullptr;
|
||||
};
|
||||
DECLARE_REF(ShaderBuffer)
|
||||
struct BottomLevelASCreateInfo
|
||||
{
|
||||
PShaderBuffer positionBuffer;
|
||||
PShaderBuffer indexBuffer;
|
||||
MeshData meshData;
|
||||
PMaterialInstance material;
|
||||
uint64 verticesOffset;
|
||||
uint64 indicesOffset;
|
||||
};
|
||||
struct TopLevelASCreateInfo
|
||||
{
|
||||
|
||||
};
|
||||
} // namespace Gfx
|
||||
} // namespace Seele
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
#include "Math/AABB.h"
|
||||
namespace Seele
|
||||
{
|
||||
struct MeshData
|
||||
{
|
||||
AABB bounding;
|
||||
uint32 numMeshlets = 0;
|
||||
uint32 meshletOffset = 0;
|
||||
uint32 firstIndex = 0;
|
||||
uint32 numIndices = 0;
|
||||
};
|
||||
struct InstanceData
|
||||
{
|
||||
Matrix4 transformMatrix;
|
||||
Matrix4 inverseTransformMatrix;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
#include "RayTracing.h"
|
||||
|
||||
using namespace Seele::Gfx;
|
||||
|
||||
BottomLevelAS::BottomLevelAS()
|
||||
{}
|
||||
|
||||
BottomLevelAS::~BottomLevelAS()
|
||||
{}
|
||||
|
||||
TopLevelAS::TopLevelAS()
|
||||
{}
|
||||
|
||||
TopLevelAS::~TopLevelAS()
|
||||
{}
|
||||
@@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
#include "Resources.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
namespace Gfx
|
||||
{
|
||||
class BottomLevelAS
|
||||
{
|
||||
public:
|
||||
BottomLevelAS();
|
||||
~BottomLevelAS();
|
||||
private:
|
||||
};
|
||||
DEFINE_REF(BottomLevelAS)
|
||||
class TopLevelAS
|
||||
{
|
||||
public:
|
||||
TopLevelAS();
|
||||
~TopLevelAS();
|
||||
private:
|
||||
};
|
||||
DEFINE_REF(TopLevelAS)
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,16 @@ namespace Seele
|
||||
{
|
||||
class RayTracingPass : public RenderPass
|
||||
{
|
||||
|
||||
public:
|
||||
RayTracingPass(Gfx::PGraphics graphics, PScene scene);
|
||||
RayTracingPass(RayTracingPass&& other) = default;
|
||||
RayTracingPass& operator=(RayTracingPass&& other) = default;
|
||||
virtual void beginFrame(const Component::Camera& cam) override;
|
||||
virtual void render() override;
|
||||
virtual void endFrame() override;
|
||||
virtual void publishOutputs() override;
|
||||
virtual void createRenderPass() override;
|
||||
private:
|
||||
|
||||
};
|
||||
}
|
||||
@@ -2,12 +2,6 @@
|
||||
#include "Math/Math.h"
|
||||
#include "Enums.h"
|
||||
#include "Containers/Array.h"
|
||||
#include "Containers/List.h"
|
||||
#include "Initializer.h"
|
||||
#include "Descriptor.h"
|
||||
#include "CRC.h"
|
||||
#include <functional>
|
||||
|
||||
|
||||
#ifndef ENABLE_VALIDATION
|
||||
#define ENABLE_VALIDATION 1
|
||||
|
||||
@@ -201,9 +201,11 @@ void StaticMeshVertexData::resizeBuffers()
|
||||
},
|
||||
.numElements = verticesAllocated * 3,
|
||||
.dynamic = false,
|
||||
.vertexBuffer = 1,
|
||||
.name = "Positions",
|
||||
};
|
||||
positions = graphics->createShaderBuffer(createInfo);
|
||||
createInfo.vertexBuffer = false;
|
||||
createInfo.name = "Normals";
|
||||
normals = graphics->createShaderBuffer(createInfo);
|
||||
createInfo.name = "Tangents";
|
||||
|
||||
@@ -4,10 +4,9 @@
|
||||
#include "Material/Material.h"
|
||||
#include "Graphics/Graphics.h"
|
||||
#include "Graphics/Descriptor.h"
|
||||
#include "Component/Mesh.h"
|
||||
#include "Graphics/Shader.h"
|
||||
#include "Graphics/Mesh.h"
|
||||
#include "Containers/Set.h"
|
||||
#include "Material/MaterialInstance.h"
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
@@ -114,7 +113,6 @@ void VertexData::createDescriptors()
|
||||
instanceData.clear();
|
||||
instanceMeshData.clear();
|
||||
|
||||
uint32 numMeshlets = 0;
|
||||
Array<uint32> cullingOffsets;
|
||||
for (auto &mat : materialData)
|
||||
{
|
||||
@@ -130,7 +128,6 @@ void VertexData::createDescriptors()
|
||||
instanceMeshData.add(instance.instanceMeshData[i]);
|
||||
// instance.numMeshlets += instance.instanceMeshData[i].numMeshlets;
|
||||
// cullingOffsets.add(numMeshlets);
|
||||
numMeshlets += instance.instanceMeshData[i].numMeshlets;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+120
-141
@@ -1,156 +1,135 @@
|
||||
#pragma once
|
||||
#include "Graphics/Initializer.h"
|
||||
#include "Material/MaterialInstance.h"
|
||||
#include "Component/Transform.h"
|
||||
#include "Containers/List.h"
|
||||
#include "Graphics/Buffer.h"
|
||||
#include "Graphics/Command.h"
|
||||
#include "Graphics/Descriptor.h"
|
||||
#include "Graphics/Buffer.h"
|
||||
#include "MeshData.h"
|
||||
#include "Meshlet.h"
|
||||
#include <entt/entt.hpp>
|
||||
|
||||
|
||||
constexpr uint64 MAX_TEXCOORDS = 8;
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
DECLARE_REF(Mesh)
|
||||
struct MeshId
|
||||
{
|
||||
uint64 id;
|
||||
std::strong_ordering operator<=>(const MeshId &other) const
|
||||
{
|
||||
return id <=> other.id;
|
||||
}
|
||||
bool operator==(const MeshId &other) const
|
||||
{
|
||||
return id == other.id;
|
||||
}
|
||||
namespace Seele {
|
||||
DECLARE_REF(MaterialInstance)
|
||||
DECLARE_REF(Mesh)
|
||||
struct MeshId {
|
||||
uint64 id;
|
||||
std::strong_ordering operator<=>(const MeshId &other) const {
|
||||
return id <=> other.id;
|
||||
}
|
||||
bool operator==(const MeshId &other) const { return id == other.id; }
|
||||
};
|
||||
class VertexData {
|
||||
public:
|
||||
struct DrawCallOffsets {
|
||||
uint32 instanceOffset = 0;
|
||||
};
|
||||
class VertexData
|
||||
{
|
||||
public:
|
||||
struct InstanceData
|
||||
{
|
||||
Matrix4 transformMatrix;
|
||||
Matrix4 inverseTransformMatrix;
|
||||
};
|
||||
struct MeshData
|
||||
{
|
||||
AABB bounding;
|
||||
uint32 numMeshlets = 0;
|
||||
uint32 meshletOffset = 0;
|
||||
uint32 firstIndex = 0;
|
||||
uint32 numIndices = 0;
|
||||
};
|
||||
struct DrawCallOffsets
|
||||
{
|
||||
uint32 instanceOffset = 0;
|
||||
};
|
||||
|
||||
struct MeshletCullingInfo
|
||||
{
|
||||
uint64_t cull[256 / 64];
|
||||
};
|
||||
struct BatchedDrawCall
|
||||
{
|
||||
PMaterialInstance materialInstance;
|
||||
DrawCallOffsets offsets;
|
||||
Array<InstanceData> instanceData;
|
||||
Array<MeshData> instanceMeshData;
|
||||
Array<uint32> cullingOffsets;
|
||||
};
|
||||
struct MaterialData
|
||||
{
|
||||
PMaterial material;
|
||||
Array<BatchedDrawCall> instances;
|
||||
};
|
||||
void resetMeshData();
|
||||
void updateMesh(entt::entity id, uint32 meshIndex, PMesh mesh, Component::Transform &transform);
|
||||
void createDescriptors();
|
||||
void loadMesh(MeshId id, Array<uint32> indices, Array<Meshlet> meshlets);
|
||||
MeshId allocateVertexData(uint64 numVertices);
|
||||
uint64 getMeshOffset(MeshId id);
|
||||
uint64 getMeshVertexCount(MeshId id);
|
||||
virtual void serializeMesh(MeshId id, uint64 numVertices, ArchiveBuffer &buffer) = 0;
|
||||
virtual void deserializeMesh(MeshId id, ArchiveBuffer &buffer) = 0;
|
||||
virtual void bindBuffers(Gfx::PRenderCommand command) = 0;
|
||||
virtual Gfx::PDescriptorLayout getVertexDataLayout() = 0;
|
||||
virtual Gfx::PDescriptorSet getVertexDataSet() = 0;
|
||||
virtual std::string getTypeName() const = 0;
|
||||
Gfx::PIndexBuffer getIndexBuffer() { return indexBuffer; }
|
||||
Gfx::PDescriptorLayout getInstanceDataLayout() { return instanceDataLayout; }
|
||||
Gfx::PDescriptorSet getInstanceDataSet() { return descriptorSet; }
|
||||
const Array<MaterialData> &getMaterialData() const { return materialData; }
|
||||
const MeshData &getMeshData(MeshId id) { return meshData[id]; }
|
||||
uint64 getIndicesOffset(uint32 meshletIndex) { return meshlets[meshletIndex].indicesOffset; }
|
||||
uint64 getNumInstances() const { return instanceData.size(); }
|
||||
static List<VertexData *> getList();
|
||||
static VertexData *findByTypeName(std::string name);
|
||||
virtual void init(Gfx::PGraphics graphics);
|
||||
virtual void destroy();
|
||||
|
||||
struct CullingMapping
|
||||
{
|
||||
uint64 instanceId;
|
||||
uint32 cullingOffset;
|
||||
};
|
||||
static CullingMapping getCullingMapping(entt::entity id, uint32 meshIndex, uint32 numMeshlets);
|
||||
static uint64 getInstanceCount() { return instanceCount; }
|
||||
static uint64 getMeshletCount() { return meshletCount; }
|
||||
|
||||
protected:
|
||||
virtual void resizeBuffers() = 0;
|
||||
virtual void updateBuffers() = 0;
|
||||
VertexData();
|
||||
struct MeshletDescription
|
||||
{
|
||||
AABB bounding;
|
||||
uint32 vertexCount;
|
||||
uint32 primitiveCount;
|
||||
uint32 vertexOffset;
|
||||
uint32 primitiveOffset;
|
||||
Vector color;
|
||||
uint32 indicesOffset = 0;
|
||||
};
|
||||
std::mutex materialDataLock;
|
||||
Array<MaterialData> materialData;
|
||||
std::mutex vertexDataLock;
|
||||
Map<MeshId, MeshData> meshData;
|
||||
Map<MeshId, uint64> meshOffsets;
|
||||
Map<MeshId, uint64> meshVertexCounts;
|
||||
Array<MeshletDescription> meshlets;
|
||||
Array<uint8> primitiveIndices;
|
||||
Array<uint32> vertexIndices;
|
||||
Array<uint32> indices;
|
||||
|
||||
struct MeshMapping
|
||||
{
|
||||
entt::entity id;
|
||||
uint32 meshId;
|
||||
auto operator<=>(const MeshMapping& other) const = default;
|
||||
};
|
||||
static Map<MeshMapping, CullingMapping> instanceIdMap;
|
||||
static uint64 instanceCount;
|
||||
static uint64 meshletCount;
|
||||
|
||||
Gfx::PGraphics graphics;
|
||||
Gfx::ODescriptorLayout instanceDataLayout;
|
||||
// for mesh shading
|
||||
Gfx::OShaderBuffer meshletBuffer;
|
||||
Gfx::OShaderBuffer vertexIndicesBuffer;
|
||||
Gfx::OShaderBuffer primitiveIndicesBuffer;
|
||||
Gfx::OShaderBuffer cullingOffsetBuffer;
|
||||
// for legacy pipeline
|
||||
Gfx::OIndexBuffer indexBuffer;
|
||||
// Material data
|
||||
struct MeshletCullingInfo {
|
||||
uint64_t cull[256 / 64];
|
||||
};
|
||||
struct BatchedDrawCall {
|
||||
PMaterialInstance materialInstance;
|
||||
DrawCallOffsets offsets;
|
||||
Array<InstanceData> instanceData;
|
||||
Gfx::OShaderBuffer instanceBuffer;
|
||||
Array<MeshData> instanceMeshData;
|
||||
Gfx::OShaderBuffer instanceMeshDataBuffer;
|
||||
Gfx::PDescriptorSet descriptorSet;
|
||||
uint64 idCounter;
|
||||
uint64 head;
|
||||
uint64 verticesAllocated;
|
||||
bool dirty;
|
||||
Array<uint32> cullingOffsets;
|
||||
};
|
||||
}
|
||||
struct MaterialData {
|
||||
PMaterial material;
|
||||
Array<BatchedDrawCall> instances;
|
||||
};
|
||||
void resetMeshData();
|
||||
void updateMesh(entt::entity id, uint32 meshIndex, PMesh mesh,
|
||||
Component::Transform &transform);
|
||||
void createDescriptors();
|
||||
void loadMesh(MeshId id, Array<uint32> indices, Array<Meshlet> meshlets);
|
||||
MeshId allocateVertexData(uint64 numVertices);
|
||||
uint64 getMeshOffset(MeshId id);
|
||||
uint64 getMeshVertexCount(MeshId id);
|
||||
virtual void serializeMesh(MeshId id, uint64 numVertices,
|
||||
ArchiveBuffer &buffer) = 0;
|
||||
virtual void deserializeMesh(MeshId id, ArchiveBuffer &buffer) = 0;
|
||||
virtual void bindBuffers(Gfx::PRenderCommand command) = 0;
|
||||
virtual Gfx::PDescriptorLayout getVertexDataLayout() = 0;
|
||||
virtual Gfx::PDescriptorSet getVertexDataSet() = 0;
|
||||
virtual std::string getTypeName() const = 0;
|
||||
Gfx::PIndexBuffer getIndexBuffer() { return indexBuffer; }
|
||||
Gfx::PDescriptorLayout getInstanceDataLayout() { return instanceDataLayout; }
|
||||
Gfx::PDescriptorSet getInstanceDataSet() { return descriptorSet; }
|
||||
const Array<MaterialData> &getMaterialData() const { return materialData; }
|
||||
const MeshData &getMeshData(MeshId id) { return meshData[id]; }
|
||||
uint64 getIndicesOffset(uint32 meshletIndex) {
|
||||
return meshlets[meshletIndex].indicesOffset;
|
||||
}
|
||||
uint64 getNumInstances() const { return instanceData.size(); }
|
||||
static List<VertexData *> getList();
|
||||
static VertexData *findByTypeName(std::string name);
|
||||
virtual void init(Gfx::PGraphics graphics);
|
||||
virtual void destroy();
|
||||
|
||||
struct CullingMapping {
|
||||
uint64 instanceId;
|
||||
uint32 cullingOffset;
|
||||
};
|
||||
static CullingMapping getCullingMapping(entt::entity id, uint32 meshIndex,
|
||||
uint32 numMeshlets);
|
||||
static uint64 getInstanceCount() { return instanceCount; }
|
||||
static uint64 getMeshletCount() { return meshletCount; }
|
||||
|
||||
protected:
|
||||
virtual void resizeBuffers() = 0;
|
||||
virtual void updateBuffers() = 0;
|
||||
VertexData();
|
||||
struct MeshletDescription {
|
||||
AABB bounding;
|
||||
uint32 vertexCount;
|
||||
uint32 primitiveCount;
|
||||
uint32 vertexOffset;
|
||||
uint32 primitiveOffset;
|
||||
Vector color;
|
||||
uint32 indicesOffset = 0;
|
||||
};
|
||||
std::mutex materialDataLock;
|
||||
Array<MaterialData> materialData;
|
||||
std::mutex vertexDataLock;
|
||||
Map<MeshId, MeshData> meshData;
|
||||
Map<MeshId, uint64> meshOffsets;
|
||||
Map<MeshId, uint64> meshVertexCounts;
|
||||
Array<MeshletDescription> meshlets;
|
||||
Array<uint8> primitiveIndices;
|
||||
Array<uint32> vertexIndices;
|
||||
Array<uint32> indices;
|
||||
|
||||
struct MeshMapping {
|
||||
entt::entity id;
|
||||
uint32 meshId;
|
||||
auto operator<=>(const MeshMapping &other) const = default;
|
||||
};
|
||||
static Map<MeshMapping, CullingMapping> instanceIdMap;
|
||||
static uint64 instanceCount;
|
||||
static uint64 meshletCount;
|
||||
|
||||
Gfx::PGraphics graphics;
|
||||
Gfx::ODescriptorLayout instanceDataLayout;
|
||||
// for mesh shading
|
||||
Gfx::OShaderBuffer meshletBuffer;
|
||||
Gfx::OShaderBuffer vertexIndicesBuffer;
|
||||
Gfx::OShaderBuffer primitiveIndicesBuffer;
|
||||
Gfx::OShaderBuffer cullingOffsetBuffer;
|
||||
// for legacy pipeline
|
||||
Gfx::OIndexBuffer indexBuffer;
|
||||
// Material data
|
||||
Array<InstanceData> instanceData;
|
||||
Gfx::OShaderBuffer instanceBuffer;
|
||||
Array<MeshData> instanceMeshData;
|
||||
Gfx::OShaderBuffer instanceMeshDataBuffer;
|
||||
Gfx::PDescriptorSet descriptorSet;
|
||||
uint64 idCounter;
|
||||
uint64 head;
|
||||
uint64 verticesAllocated;
|
||||
bool dirty;
|
||||
};
|
||||
} // namespace Seele
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -16,6 +16,7 @@ public:
|
||||
VmaAllocationInfo info = VmaAllocationInfo();
|
||||
VkMemoryPropertyFlags properties = 0;
|
||||
uint64 size = 0;
|
||||
VkDeviceAddress deviceAddress;
|
||||
};
|
||||
DEFINE_REF(BufferAllocation);
|
||||
class Buffer {
|
||||
@@ -24,6 +25,9 @@ public:
|
||||
Gfx::QueueType &queueType, bool dynamic, std::string name);
|
||||
virtual ~Buffer();
|
||||
VkBuffer getHandle() const { return buffers[currentBuffer]->buffer; }
|
||||
VkDeviceAddress getDeviceAddress() const {
|
||||
return buffers[currentBuffer]->deviceAddress;
|
||||
}
|
||||
PBufferAllocation getAlloc() const { return buffers[currentBuffer]; }
|
||||
uint64 getSize() const { return buffers[currentBuffer]->size; }
|
||||
void *map(bool writeOnly = true);
|
||||
@@ -130,7 +134,8 @@ public:
|
||||
virtual ~ShaderBuffer();
|
||||
virtual void
|
||||
updateContents(const ShaderBufferCreateInfo &createInfo) override;
|
||||
virtual void rotateBuffer(uint64 size, bool preserveContents = false) override;
|
||||
virtual void rotateBuffer(uint64 size,
|
||||
bool preserveContents = false) override;
|
||||
virtual void *mapRegion(uint64 offset, uint64 size, bool writeOnly) override;
|
||||
virtual void unmap() override;
|
||||
|
||||
|
||||
@@ -22,6 +22,8 @@ target_sources(Engine
|
||||
PipelineCache.cpp
|
||||
Queue.h
|
||||
Queue.cpp
|
||||
RayTracing.h
|
||||
RayTracing.cpp
|
||||
RenderPass.h
|
||||
RenderPass.cpp
|
||||
Resources.h
|
||||
@@ -47,6 +49,7 @@ target_sources(Engine
|
||||
Pipeline.h
|
||||
PipelineCache.h
|
||||
Queue.h
|
||||
RayTracing.h
|
||||
RenderPass.h
|
||||
Resources.h
|
||||
Shader.h
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "Command.h"
|
||||
#include "Graphics.h"
|
||||
#include "Texture.h"
|
||||
#include "CRC.h"
|
||||
|
||||
using namespace Seele;
|
||||
using namespace Seele::Vulkan;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "RenderPass.h"
|
||||
#include "Graphics.h"
|
||||
#include "Texture.h"
|
||||
#include "CRC.h"
|
||||
|
||||
using namespace Seele;
|
||||
using namespace Seele::Vulkan;
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
#include "Allocator.h"
|
||||
#include "Buffer.h"
|
||||
#include "Graphics/Enums.h"
|
||||
#include "Graphics/Graphics.h"
|
||||
#include "Graphics/Initializer.h"
|
||||
#include "PipelineCache.h"
|
||||
#include "Command.h"
|
||||
#include "Descriptor.h"
|
||||
@@ -10,6 +12,7 @@
|
||||
#include "RenderPass.h"
|
||||
#include "Framebuffer.h"
|
||||
#include "Shader.h"
|
||||
#include "RayTracing.h"
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <cstring>
|
||||
#include <vulkan/vulkan_core.h>
|
||||
@@ -291,14 +294,24 @@ void Graphics::resolveTexture(Gfx::PTexture source, Gfx::PTexture destination)
|
||||
vkCmdResolveImage(getGraphicsCommands()->getCommands()->getHandle(), sourceTex->getImage(), cast(sourceTex->getLayout()), destinationTex->getImage(), cast(destinationTex->getLayout()), 1, &resolve);
|
||||
}
|
||||
|
||||
void Graphics::vkCmdDrawMeshTasksEXT(VkCommandBuffer handle, uint32 groupX, uint32 groupY, uint32 groupZ)
|
||||
Gfx::OBottomLevelAS Graphics::createBottomLevelAccelerationStructure(const Gfx::BottomLevelASCreateInfo& createInfo)
|
||||
{
|
||||
cmdDrawMeshTasks(handle, groupX, groupY, groupZ);
|
||||
return new BottomLevelAS(this, createInfo);
|
||||
}
|
||||
|
||||
void Graphics::vkCmdDrawMeshTasksIndirectEXT(VkCommandBuffer handle, VkBuffer buffer, uint64 offset, uint32 drawCount, uint32 stride)
|
||||
Gfx::OTopLevelAS Graphics::createTopLevelAccelerationStructure(const Gfx::TopLevelASCreateInfo& createInfo)
|
||||
{
|
||||
cmdDrawMeshTasksIndirect(handle, buffer, offset, drawCount, stride);
|
||||
return new TopLevelAS(this, createInfo);
|
||||
}
|
||||
|
||||
void Graphics::vkCmdDrawMeshTasksEXT(VkCommandBuffer cmd, uint32 groupX, uint32 groupY, uint32 groupZ)
|
||||
{
|
||||
cmdDrawMeshTasks(cmd, groupX, groupY, groupZ);
|
||||
}
|
||||
|
||||
void Graphics::vkCmdDrawMeshTasksIndirectEXT(VkCommandBuffer cmd, VkBuffer buffer, uint64 offset, uint32 drawCount, uint32 stride)
|
||||
{
|
||||
cmdDrawMeshTasksIndirect(cmd, buffer, offset, drawCount, stride);
|
||||
}
|
||||
|
||||
void Graphics::vkSetDebugUtilsObjectNameEXT(VkDebugUtilsObjectNameInfoEXT* info)
|
||||
@@ -395,6 +408,7 @@ void Graphics::initInstance(GraphicsInitializer initInfo)
|
||||
assert(glfwVulkanSupported());
|
||||
VkApplicationInfo appInfo = {
|
||||
.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO,
|
||||
.pNext = nullptr,
|
||||
.pApplicationName = initInfo.applicationName,
|
||||
.applicationVersion = VK_MAKE_VERSION(0, 0, 1),
|
||||
.pEngineName = initInfo.engineName,
|
||||
@@ -415,6 +429,7 @@ void Graphics::initInstance(GraphicsInitializer initInfo)
|
||||
#endif
|
||||
VkInstanceCreateInfo info = {
|
||||
.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
|
||||
.pNext = nullptr,
|
||||
#if __APPLE__
|
||||
.flags = VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR,
|
||||
#endif
|
||||
@@ -562,6 +577,7 @@ void Graphics::createDevice(GraphicsInitializer initializer)
|
||||
.flags = 0,
|
||||
.queueFamilyIndex = familyIndex,
|
||||
.queueCount = numQueuesForFamily,
|
||||
.pQueuePriorities = nullptr,
|
||||
};
|
||||
numPriorities += numQueuesForFamily;
|
||||
queueInfos.add(info);
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#pragma once
|
||||
#include "Enums.h"
|
||||
#include "Graphics/Graphics.h"
|
||||
#include <vk_mem_alloc.h>
|
||||
|
||||
@@ -70,6 +69,10 @@ public:
|
||||
|
||||
virtual void resolveTexture(Gfx::PTexture source, Gfx::PTexture destination) override;
|
||||
|
||||
// Ray Tracing
|
||||
virtual Gfx::OBottomLevelAS createBottomLevelAccelerationStructure(const Gfx::BottomLevelASCreateInfo& createInfo) override;
|
||||
virtual Gfx::OTopLevelAS createTopLevelAccelerationStructure(const Gfx::TopLevelASCreateInfo& createInfo) override;
|
||||
|
||||
void vkCmdDrawMeshTasksEXT(VkCommandBuffer handle, uint32 groupX, uint32 groupY, uint32 groupZ);
|
||||
void vkCmdDrawMeshTasksIndirectEXT(VkCommandBuffer handle, VkBuffer buffer, uint64 offset, uint32 drawCount, uint32 stride);
|
||||
void vkSetDebugUtilsObjectNameEXT(VkDebugUtilsObjectNameInfoEXT* info);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "Graphics.h"
|
||||
#include "Allocator.h"
|
||||
#include "Command.h"
|
||||
#include "Enums.h"
|
||||
|
||||
using namespace Seele;
|
||||
using namespace Seele::Vulkan;
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
#include "RayTracing.h"
|
||||
#include "Buffer.h"
|
||||
#include "Graphics/Initializer.h"
|
||||
#include <vulkan/vulkan_core.h>
|
||||
|
||||
using namespace Seele::Vulkan;
|
||||
|
||||
BottomLevelAS::BottomLevelAS(PGraphics graphics, const Gfx::BottomLevelASCreateInfo& createInfo)
|
||||
{
|
||||
VkDeviceOrHostAddressConstKHR vertexDataDeviceAddress = {
|
||||
.deviceAddress = createInfo.positionBuffer.cast<Buffer>()->getDeviceAddress() + createInfo.verticesOffset,
|
||||
};
|
||||
VkDeviceOrHostAddressConstKHR indexDataDeviceAddress = {
|
||||
.deviceAddress = createInfo.indexBuffer.cast<Buffer>()->getDeviceAddress() + createInfo.indicesOffset,
|
||||
};
|
||||
VkAccelerationStructureGeometryKHR accelerationStructureGeometry = {
|
||||
.sType = VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_GEOMETRY_KHR,
|
||||
.pNext = nullptr,
|
||||
.geometryType = VK_GEOMETRY_TYPE_TRIANGLES_KHR,
|
||||
.geometry = {.triangles = {
|
||||
.sType = VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_GEOMETRY_TRIANGLES_DATA_KHR,
|
||||
.pNext = nullptr,
|
||||
.vertexFormat = VK_FORMAT_R32G32B32_SFLOAT,
|
||||
.vertexData = vertexDataDeviceAddress,
|
||||
.vertexStride = sizeof(Vector),
|
||||
.maxVertex = createInfo.positionBuffer->getNumElements(),
|
||||
.indexType = VK_INDEX_TYPE_UINT32,
|
||||
.indexData = indexDataDeviceAddress,
|
||||
}},
|
||||
.flags = VK_GEOMETRY_OPAQUE_BIT_KHR,
|
||||
};
|
||||
|
||||
VkAccelerationStructureBuildRangeInfoKHR buildRangeInfo = {
|
||||
.primitiveCount = createInfo.meshData.numIndices / 3,
|
||||
.primitiveOffset = 0,
|
||||
.firstVertex = 0,
|
||||
.transformOffset = 0
|
||||
};
|
||||
|
||||
VkAccelerationStructureBuildGeometryInfoKHR buildGeometry = {
|
||||
.sType = VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_BUILD_GEOMETRY_INFO_KHR,
|
||||
.pNext = nullptr,
|
||||
.type = VK_ACCELERATION_STRUCTURE_TYPE_BOTTOM_LEVEL_KHR,
|
||||
.flags = VK_BUILD_ACCELERATION_STRUCTURE_PREFER_FAST_TRACE_BIT_KHR,
|
||||
};
|
||||
|
||||
VkAccelerationStructureCreateInfoKHR info = {
|
||||
.sType = VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_CREATE_INFO_KHR,
|
||||
.pNext = nullptr,
|
||||
.createFlags = 0,
|
||||
};
|
||||
}
|
||||
|
||||
BottomLevelAS::~BottomLevelAS()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
TopLevelAS::TopLevelAS(PGraphics graphics, const Gfx::TopLevelASCreateInfo& createInfo)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
TopLevelAS::~TopLevelAS()
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
#include "Graphics/Initializer.h"
|
||||
#include "Graphics.h"
|
||||
#include "Graphics/RayTracing.h"
|
||||
#include <vulkan/vulkan_core.h>
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
namespace Vulkan
|
||||
{
|
||||
class BottomLevelAS : public Gfx::BottomLevelAS
|
||||
{
|
||||
public:
|
||||
BottomLevelAS(PGraphics graphics, const Gfx::BottomLevelASCreateInfo& createInfo);
|
||||
~BottomLevelAS();
|
||||
private:
|
||||
PGraphics graphics;
|
||||
VkAccelerationStructureKHR handle;
|
||||
};
|
||||
DEFINE_REF(BottomLevelAS)
|
||||
class TopLevelAS : public Gfx::TopLevelAS
|
||||
{
|
||||
public:
|
||||
TopLevelAS(PGraphics graphics, const Gfx::TopLevelASCreateInfo& createInfo);
|
||||
~TopLevelAS();
|
||||
private:
|
||||
PGraphics graphics;
|
||||
VkAccelerationStructureKHR handle;
|
||||
};
|
||||
DEFINE_REF(TopLevelAS)
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "Texture.h"
|
||||
#include "Resources.h"
|
||||
#include "Command.h"
|
||||
#include "CRC.h"
|
||||
|
||||
using namespace Seele;
|
||||
using namespace Seele::Vulkan;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "Texture.h"
|
||||
#include "Command.h"
|
||||
#include "Enums.h"
|
||||
#include <math.h>
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
#include "Initializer.h"
|
||||
#include "Texture.h"
|
||||
#include <functional>
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user