it at least does something

This commit is contained in:
Dynamitos
2025-02-28 16:56:51 +09:00
parent f73cc61693
commit 67b4a533f2
40 changed files with 440 additions and 413 deletions
-2
View File
@@ -18,8 +18,6 @@ struct ViewParameter
float2 invScreenDimensions;
uint frameIndex;
float time;
uint pad0;
uint pad1;
};
layout(set = 0)
ParameterBlock<ViewParameter> pViewParams;
+1
View File
@@ -158,6 +158,7 @@ int main() {
// .numSamples = Gfx::SE_SAMPLE_COUNT_1_BIT,
// });
window->show();
while (windowManager->isActive() && getGlobals().running) {
windowManager->render();
}
+12 -12
View File
@@ -217,7 +217,7 @@ void LebMatrixCache::release() {}
void MeshUpdater::init(Gfx::PGraphics gfx, Gfx::PDescriptorLayout viewParamsLayout) {
graphics = gfx;
layout = graphics->createDescriptorLayout("pParams");
layout->addDescriptorBinding(Gfx::DescriptorBinding{0, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER});
/*layout->addDescriptorBinding(Gfx::DescriptorBinding{0, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER});
layout->addDescriptorBinding(Gfx::DescriptorBinding{1, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER});
layout->addDescriptorBinding(Gfx::DescriptorBinding{2, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER});
layout->addDescriptorBinding(Gfx::DescriptorBinding{3, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER});
@@ -242,7 +242,7 @@ void MeshUpdater::init(Gfx::PGraphics gfx, Gfx::PDescriptorLayout viewParamsLayo
layout->addDescriptorBinding(Gfx::DescriptorBinding{22, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER});
layout->addDescriptorBinding(Gfx::DescriptorBinding{23, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER});
layout->addDescriptorBinding(Gfx::DescriptorBinding{24, Gfx::SE_DESCRIPTOR_TYPE_SAMPLER});
layout->addDescriptorBinding(Gfx::DescriptorBinding{25, Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE});
layout->addDescriptorBinding(Gfx::DescriptorBinding{25, Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE});*/
layout->create();
pipelineLayout = graphics->createPipelineLayout("ComputeLayout");
pipelineLayout->addDescriptorLayout(viewParamsLayout);
@@ -420,7 +420,7 @@ void MeshUpdater::release() {}
void MeshUpdater::evaluateLeb(const BaseMesh& baseMesh, CBTMesh& mesh, Gfx::PDescriptorSet viewParamsSet,
Gfx::PUniformBuffer geometryBuffer, Gfx::PUniformBuffer updateBuffer, Gfx::PShaderBuffer lebMatrixCache,
bool clear, bool complete) {
if (clear) {
/*if (clear) {
graphics->beginDebugRegion("ClearLEB");
Gfx::PDescriptorSet set = layout->allocateDescriptorSet();
set->updateBuffer(GEOMETRY_CB, 0, geometryBuffer);
@@ -456,11 +456,11 @@ void MeshUpdater::evaluateLeb(const BaseMesh& baseMesh, CBTMesh& mesh, Gfx::PDes
graphics->executeCommands(std::move(evalCmd));
mesh.lebVertexBuffer->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);
graphics->endDebugRegion();
graphics->endDebugRegion();*/
}
void MeshUpdater::update(CBTMesh& mesh, Gfx::PDescriptorSet viewParamsSet, Gfx::PUniformBuffer geometryCB, Gfx::PUniformBuffer updateCB) {
uint32 nextNeighborsBufferIdx = (mesh.currentNeighborsBufferIdx + 1) % 2;
/*uint32 nextNeighborsBufferIdx = (mesh.currentNeighborsBufferIdx + 1) % 2;
Gfx::PShaderBuffer currentNeighborsBuffer = mesh.neighborsBuffers[mesh.currentNeighborsBufferIdx];
Gfx::PShaderBuffer nextNeighborsBuffer = mesh.neighborsBuffers[nextNeighborsBufferIdx];
@@ -795,13 +795,13 @@ void MeshUpdater::update(CBTMesh& mesh, Gfx::PDescriptorSet viewParamsSet, Gfx::
mesh.currentNeighborsBufferIdx = nextNeighborsBufferIdx;
prepareIndirection(mesh, geometryCB);
prepareIndirection(mesh, geometryCB);*/
}
void MeshUpdater::validation(CBTMesh& mesh, Gfx::PUniformBuffer geometryCB) {
uint32 numGroups = (mesh.totalNumElements + WORKGROUP_SIZE - 1) / WORKGROUP_SIZE;
Gfx::PDescriptorSet set = layout->allocateDescriptorSet();
/*Gfx::PDescriptorSet set = layout->allocateDescriptorSet();
set->updateBuffer(GEOMETRY_CB, 0, geometryCB);
set->updateBuffer(HEAP_ID_BUFFER, 0, mesh.heapIDBuffer);
@@ -817,11 +817,11 @@ void MeshUpdater::validation(CBTMesh& mesh, Gfx::PUniformBuffer geometryCB) {
graphics->executeCommands(std::move(validateCmd));
validationBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
Gfx::SE_ACCESS_TRANSFER_READ_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT);
graphics->copyBuffer(validationBuffer, validationBufferRB);
graphics->copyBuffer(validationBuffer, validationBufferRB);*/
}
void MeshUpdater::resetBuffers(CBTMesh& mesh) {
graphics->beginDebugRegion("ResetBuffers");
/*graphics->beginDebugRegion("ResetBuffers");
Gfx::PDescriptorSet set = layout->allocateDescriptorSet();
set->updateBuffer(CBT_BUFFER0, 0, mesh.gpuCBT.bufferArray[0]);
set->updateBuffer(CBT_BUFFER1, 0, mesh.gpuCBT.bufferArray[1]);
@@ -850,11 +850,11 @@ void MeshUpdater::resetBuffers(CBTMesh& mesh) {
Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
mesh.indirectDrawBuffer->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);
graphics->endDebugRegion();
graphics->endDebugRegion();*/
}
void MeshUpdater::prepareIndirection(CBTMesh& mesh, Gfx::PUniformBuffer geometryCB) {
uint32 numGroups = (mesh.totalNumElements + WORKGROUP_SIZE - 1) / WORKGROUP_SIZE;
/*uint32 numGroups = (mesh.totalNumElements + WORKGROUP_SIZE - 1) / WORKGROUP_SIZE;
graphics->beginDebugRegion("BisectorIndexation");
{
Gfx::PDescriptorSet set = layout->allocateDescriptorSet();
@@ -899,7 +899,7 @@ void MeshUpdater::prepareIndirection(CBTMesh& mesh, Gfx::PUniformBuffer geometry
mesh.indirectDrawBuffer->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);
}
graphics->endDebugRegion();
graphics->endDebugRegion();*/
}
bool MeshUpdater::checkIfValid() { return true; }
+1 -21
View File
@@ -5,30 +5,10 @@ using namespace Seele::Gfx;
DescriptorLayout::DescriptorLayout(const std::string& name) : name(name) {}
DescriptorLayout::DescriptorLayout(const DescriptorLayout& other) {
descriptorBindings.resize(other.descriptorBindings.size());
for (uint32 i = 0; i < descriptorBindings.size(); ++i) {
descriptorBindings[i] = other.descriptorBindings[i];
}
}
DescriptorLayout& DescriptorLayout::operator=(const DescriptorLayout& other) {
if (this != &other) {
descriptorBindings.resize(other.descriptorBindings.size());
for (uint32 i = 0; i < descriptorBindings.size(); ++i) {
descriptorBindings[i] = other.descriptorBindings[i];
}
}
return *this;
}
DescriptorLayout::~DescriptorLayout() {}
void DescriptorLayout::addDescriptorBinding(DescriptorBinding binding) {
if (descriptorBindings.size() <= binding.binding) {
descriptorBindings.resize(binding.binding + 1);
}
descriptorBindings[binding.binding] = binding;
descriptorBindings.add(binding);
}
PDescriptorSet DescriptorLayout::allocateDescriptorSet() { return pool->allocateDescriptorSet(); }
+13 -15
View File
@@ -6,15 +6,15 @@
namespace Seele {
namespace Gfx {
struct DescriptorBinding {
uint32 binding = 0;
std::string name;
// In Metal uniforms are plain bytes, and for that we need to know the struct size
uint32 uniformLength = 0;
SeDescriptorType descriptorType = SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
SeImageViewType textureType = SE_IMAGE_VIEW_TYPE_2D;
uint32 descriptorCount = 1;
SeDescriptorBindingFlags bindingFlags = 0;
SeShaderStageFlags shaderStages = SE_SHADER_STAGE_ALL;
Gfx::SeDescriptorAccessTypeFlags access = SE_DESCRIPTOR_ACCESS_READ_ONLY_BIT;
// In Metal uniforms are plain bytes, and for that we need to know the struct size
uint32 uniformLength = 0;
SeDescriptorAccessTypeFlags access = SE_DESCRIPTOR_ACCESS_READ_BIT;
};
DECLARE_REF(DescriptorPool)
@@ -22,8 +22,6 @@ DECLARE_REF(DescriptorSet)
class DescriptorLayout {
public:
DescriptorLayout(const std::string& name);
DescriptorLayout(const DescriptorLayout& other);
DescriptorLayout& operator=(const DescriptorLayout& other);
virtual ~DescriptorLayout();
void addDescriptorBinding(DescriptorBinding binding);
void reset();
@@ -65,15 +63,15 @@ class DescriptorSet {
DescriptorSet(PDescriptorLayout layout);
virtual ~DescriptorSet();
virtual void writeChanges() = 0;
virtual void updateBuffer(uint32 binding, uint32 index, Gfx::PUniformBuffer uniformBuffer) = 0;
virtual void updateBuffer(uint32 binding, uint32 index, Gfx::PShaderBuffer shaderBuffer) = 0;
virtual void updateBuffer(uint32 binding, uint32 index, Gfx::PVertexBuffer indexBuffer) = 0;
virtual void updateBuffer(uint32 binding, uint32 index, Gfx::PIndexBuffer indexBuffer) = 0;
virtual void updateSampler(uint32 binding, uint32 index, Gfx::PSampler samplerState) = 0;
virtual void updateTexture(uint32 binding, uint32 index, Gfx::PTexture2D texture) = 0;
virtual void updateTexture(uint32 binding, uint32 index, Gfx::PTexture3D texture) = 0;
virtual void updateTexture(uint32 binding, uint32 index, Gfx::PTextureCube texture) = 0;
virtual void updateAccelerationStructure(uint32 binding, uint32 index, Gfx::PTopLevelAS as) = 0;
virtual void updateConstants(const std::string& name, uint32 offset, void* data) = 0;
virtual void updateBuffer(const std::string& name, uint32 index, Gfx::PShaderBuffer shaderBuffer) = 0;
virtual void updateBuffer(const std::string& name, uint32 index, Gfx::PVertexBuffer indexBuffer) = 0;
virtual void updateBuffer(const std::string& name, uint32 index, Gfx::PIndexBuffer indexBuffer) = 0;
virtual void updateSampler(const std::string& name, uint32 index, Gfx::PSampler samplerState) = 0;
virtual void updateTexture(const std::string& name, uint32 index, Gfx::PTexture2D texture) = 0;
virtual void updateTexture(const std::string& name, uint32 index, Gfx::PTexture3D texture) = 0;
virtual void updateTexture(const std::string& name, uint32 index, Gfx::PTextureCube texture) = 0;
virtual void updateAccelerationStructure(const std::string& name, uint32 index, Gfx::PTopLevelAS as) = 0;
bool operator<(PDescriptorSet other);
constexpr PDescriptorLayout getLayout() const { return layout; }
+4 -4
View File
@@ -1733,11 +1733,11 @@ typedef union SeClearValue {
} SeClearValue;
typedef enum SeDescriptorAccessTypeFlagBits {
SE_DESCRIPTOR_ACCESS_READ_ONLY_BIT = 0x00000001,
SE_DESCRIPTOR_ACCESS_READ_WRITE_BIT = 0x00000002,
SE_DESCRIPTOR_ACCESS_WRITE_ONLY_BIT = 0x00000004,
SE_DESCRIPTOR_ACCESS_READ_BIT = 0x00000001,
SE_DESCRIPTOR_ACCESS_WRITE_BIT = 0x00000002,
SE_DESCRIPTOR_ACCESS_SAMPLE_BIT = 0x00000004,
} SeDescriptorAccessTypeFlagBits;
typedef SeFlags SeDescriptorAccessTypeFlags;
} // namespace Gfx
} // namespace Seele
} // namespace Seele
+9 -6
View File
@@ -10,6 +10,7 @@
#include "Graphics/Resources.h"
#include "Metal/MTLArgumentEncoder.hpp"
#include "Metal/MTLCaptureManager.hpp"
#include "Metal/MTLCommandEncoder.hpp"
#include "Metal/MTLLibrary.hpp"
#include "Metal/MTLRenderCommandEncoder.hpp"
#include "Pipeline.h"
@@ -114,19 +115,20 @@ void RenderCommand::bindDescriptor(Gfx::PDescriptorSet descriptorSet) {
}
for (const auto& write : metalSet->bufferWrites) {
write.apply(metalSet->encoder);
encoder->useResource(write.buffer, write.access);
}
for (const auto& write : metalSet->samplerWrites) {
write.apply(metalSet->encoder);
}
for (const auto& write : metalSet->textureWrites) {
write.apply(metalSet->encoder);
encoder->useResource(write.texture, write.access);
}
for (const auto& write : metalSet->accelerationWrites) {
write.apply(metalSet->encoder);
encoder->useResource(write.accelerationStructure, write.access);
}
encoder->useResource(metalSet->argumentBuffer, MTL::ResourceUsageRead);
encoder->setObjectBuffer(metalSet->argumentBuffer, 0, descriptorIndex);
encoder->setMeshBuffer(metalSet->argumentBuffer, 0, descriptorIndex);
encoder->setVertexBuffer(metalSet->argumentBuffer, 0, descriptorIndex);
@@ -222,19 +224,20 @@ void ComputeCommand::bindDescriptor(Gfx::PDescriptorSet set) {
}
for (const auto& write : metalSet->bufferWrites) {
write.apply(metalSet->encoder);
encoder->useResource(write.buffer, write.access);
}
for (const auto& write : metalSet->samplerWrites) {
write.apply(metalSet->encoder);
}
for (const auto& write : metalSet->textureWrites) {
write.apply(metalSet->encoder);
encoder->useResource(write.texture, write.access);
}
for (const auto& write : metalSet->accelerationWrites) {
write.apply(metalSet->encoder);
encoder->useResource(write.accelerationStructure, write.access);
}
encoder->useResource(metalSet->argumentBuffer, MTL::ResourceUsageRead);
encoder->setBuffer(metalSet->argumentBuffer, 0, descriptorIndex);
}
+24 -16
View File
@@ -8,6 +8,7 @@
#include "Graphics/Metal/Resources.h"
#include "Metal/MTLAccelerationStructure.hpp"
#include "Metal/MTLArgumentEncoder.hpp"
#include "Metal/MTLCommandEncoder.hpp"
#include "Metal/MTLLibrary.hpp"
#include "Metal/MTLResource.hpp"
#include "MinimalEngine.h"
@@ -15,25 +16,30 @@
namespace Seele {
namespace Metal {
DECLARE_REF(Graphics)
struct DescriptorMapping
{
uint32 index;
uint32 constantSize;
MTL::ResourceUsage access;
};
class DescriptorLayout : public Gfx::DescriptorLayout {
public:
DescriptorLayout(PGraphics graphics, const std::string& name);
virtual ~DescriptorLayout();
virtual void create() override;
MTL::ArgumentEncoder* createEncoder();
uint32 getFlattenedIndex(uint32 binding, uint32 arrayIndex) const { return flattenMap.at(flattenIndex(binding, arrayIndex)); }
constexpr uint32 getTotalBindingCount() const { return flattenedBindingCount; }
constexpr bool isPlainDescriptor() const { return plainDescriptor; }
private:
constexpr uint64 flattenIndex(uint32 binding, uint32 arrayIndex) const { return uint64(arrayIndex) << 32 | binding; }
PGraphics graphics;
NS::Array* arguments;
Map<uint64, uint32> flattenMap;
uint32 flattenedBindingCount = 0;
Map<std::string, DescriptorMapping> variableMapping;
uint32 numResources;
// descriptor sets containing only uniform data are not actually argument buffers, so they need to be
// handled separately
bool plainDescriptor = true;
friend class DescriptorSet;
};
DEFINE_REF(DescriptorLayout)
@@ -56,25 +62,24 @@ class DescriptorSet : public Gfx::DescriptorSet, public CommandBoundResource {
public:
DescriptorSet(PGraphics graphics, PDescriptorPool owner);
virtual ~DescriptorSet();
virtual void reset();
virtual void writeChanges() override;
virtual void updateBuffer(uint32 binding, uint32 index, Gfx::PUniformBuffer uniformBuffer) override;
virtual void updateBuffer(uint32 binding, uint32 index, Gfx::PShaderBuffer uniformBuffer) override;
virtual void updateBuffer(uint32 binding, uint32 index, Gfx::PVertexBuffer uniformBuffer) override;
virtual void updateBuffer(uint32 binding, uint32 index, Gfx::PIndexBuffer uniformBuffer) override;
virtual void updateSampler(uint32 binding, uint32 index, Gfx::PSampler samplerState) override;
virtual void updateTexture(uint32 binding, uint32 index, Gfx::PTexture2D texture) override;
virtual void updateTexture(uint32 binding, uint32 index, Gfx::PTexture3D texture) override;
virtual void updateTexture(uint32 binding, uint32 index, Gfx::PTextureCube texture) override;
virtual void updateAccelerationStructure(uint32 binding, uint32 index, Gfx::PTopLevelAS as) override;
virtual void updateConstants(const std::string& name, uint32 offset, void* data) override;
virtual void updateBuffer(const std::string& name, uint32 index, Gfx::PShaderBuffer uniformBuffer) override;
virtual void updateBuffer(const std::string& name, uint32 index, Gfx::PVertexBuffer uniformBuffer) override;
virtual void updateBuffer(const std::string& name, uint32 index, Gfx::PIndexBuffer uniformBuffer) override;
virtual void updateSampler(const std::string& name, uint32 index, Gfx::PSampler samplerState) override;
virtual void updateTexture(const std::string& name, uint32 index, Gfx::PTexture2D texture) override;
virtual void updateTexture(const std::string& name, uint32 index, Gfx::PTexture3D texture) override;
virtual void updateTexture(const std::string& name, uint32 index, Gfx::PTextureCube texture) override;
virtual void updateAccelerationStructure(const std::string& name, uint32 index, Gfx::PTopLevelAS as) override;
constexpr const Array<MTL::Resource*>& getBoundResources() const { return boundResources; }
constexpr bool isPlainDescriptor() const { return owner->getLayout()->isPlainDescriptor(); }
constexpr MTL::ArgumentEncoder* createEncoder() const { return owner->getLayout()->createEncoder(); }
private:
PGraphics graphics;
PDescriptorPool owner;
Array<MTL::Resource*> boundResources;
MTL::Buffer* argumentBuffer = nullptr;
MTL::ArgumentEncoder* encoder = nullptr;
@@ -88,13 +93,15 @@ class DescriptorSet : public Gfx::DescriptorSet, public CommandBoundResource {
struct BufferWriteInfo
{
uint32 index;
MTL::ResourceUsage access;
MTL::Buffer* buffer;
void apply(MTL::ArgumentEncoder* encoder) const { encoder->setBuffer(buffer, 0, 2); }
void apply(MTL::ArgumentEncoder* encoder) const { encoder->setBuffer(buffer, 0, index); }
};
Array<BufferWriteInfo> bufferWrites;
struct TextureWriteInfo
{
uint32 index;
MTL::ResourceUsage access;
MTL::Texture* texture;
void apply(MTL::ArgumentEncoder* encoder) const { encoder->setTexture(texture, index); }
};
@@ -109,6 +116,7 @@ class DescriptorSet : public Gfx::DescriptorSet, public CommandBoundResource {
struct AccelerationStructureWriteInfo
{
uint32 index;
MTL::ResourceUsage access;
MTL::AccelerationStructure* accelerationStructure;
void apply(MTL::ArgumentEncoder* encoder) const { encoder->setAccelerationStructure(accelerationStructure, index); }
};
+46 -36
View File
@@ -32,22 +32,26 @@ void DescriptorLayout::create() {
pool = new DescriptorPool(graphics, this);
hash = CRC::Calculate(descriptorBindings.data(), sizeof(Gfx::DescriptorBinding) * descriptorBindings.size(), CRC::CRC_32());
MTL::ArgumentDescriptor** objects = new MTL::ArgumentDescriptor*[descriptorBindings.size()];
flattenedBindingCount = 0;
uint32 mappingCounter = 0;
for (uint32 i = 0; i < descriptorBindings.size(); ++i) {
if(descriptorBindings[i].descriptorType != Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER) {
if (descriptorBindings[i].descriptorType != Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER) {
plainDescriptor = false;
} else {
objects[i] = MTL::ArgumentDescriptor::alloc()->init();
objects[i]->setIndex(flattenedBindingCount);
objects[i]->setAccess(cast(descriptorBindings[i].access));
objects[i]->setIndex(mappingCounter);
objects[i]->setAccess(MTL::BindingAccessReadOnly);
objects[i]->setArrayLength(descriptorBindings[i].descriptorCount);
objects[i]->setDataType(MTL::DataTypeChar);
objects[i]->setArrayLength(descriptorBindings[i].uniformLength);
}
for(uint32 j = 0; j < descriptorBindings[i].descriptorCount; ++j) {
flattenMap[flattenIndex(i, j)] = flattenedBindingCount++;
}
variableMapping[descriptorBindings[i].name] = DescriptorMapping{
.index = mappingCounter,
.constantSize = descriptorBindings[i].uniformLength,
.access = descriptorBindings[i].access,
};
mappingCounter += descriptorBindings[i].descriptorCount;
}
numResources = mappingCounter;
arguments = NS::Array::array((NS::Object**)objects, descriptorBindings.size());
}
@@ -63,8 +67,8 @@ Gfx::PDescriptorSet DescriptorPool::allocateDescriptorSet() {
// Currently in use, skip
continue;
}
// Found set, stop searching
allocatedSets[setIndex]->reset();
return PDescriptorSet(allocatedSets[setIndex]);
}
allocatedSets.add(new DescriptorSet(graphics, this));
@@ -75,94 +79,100 @@ void DescriptorPool::reset() {}
DescriptorSet::DescriptorSet(PGraphics graphics, PDescriptorPool owner)
: Gfx::DescriptorSet(owner->getLayout()), CommandBoundResource(graphics), graphics(graphics), owner(owner) {
boundResources.resize(owner->getLayout()->getTotalBindingCount());
}
DescriptorSet::~DescriptorSet() {}
void DescriptorSet::reset() {
uniformWrites.clear();
bufferWrites.clear();
textureWrites.clear();
samplerWrites.clear();
accelerationWrites.clear();
}
void DescriptorSet::writeChanges() {}
void DescriptorSet::updateBuffer(uint32 binding, uint32 index, Gfx::PUniformBuffer uniformBuffer) {
uint32 flattenedIndex = owner->getLayout()->getFlattenedIndex(binding, index);
PUniformBuffer buffer = uniformBuffer.cast<UniformBuffer>();
boundResources[flattenedIndex] = nullptr;
void DescriptorSet::updateConstants(const std::string& name, uint32 offset, void* data) {
uint32 flattenedIndex = owner->getLayout()->variableMapping[name].index;
Array<uint8> contents(owner->getLayout()->variableMapping[name].constantSize);
std::memcpy(contents.data(), (uint8*)data + offset, contents.size());
uniformWrites.add(UniformWriteInfo{
.index = flattenedIndex,
.content = buffer->getContents(),
.content = contents,
});
}
void DescriptorSet::updateBuffer(uint32 binding, uint32 index, Gfx::PShaderBuffer uniformBuffer) {
uint32 flattenedIndex = owner->getLayout()->getFlattenedIndex(binding, index);
void DescriptorSet::updateBuffer(const std::string& name, uint32 index, Gfx::PShaderBuffer uniformBuffer) {
uint32 flattenedIndex = owner->getLayout()->variableMapping[name].index + index;
PShaderBuffer buffer = uniformBuffer.cast<ShaderBuffer>();
boundResources[flattenedIndex] = buffer->getHandle();
bufferWrites.add(BufferWriteInfo{
.index = flattenedIndex,
.buffer = buffer->getHandle(),
.access = owner->getLayout()->variableMapping[name].access,
});
}
void DescriptorSet::updateBuffer(uint32 binding, uint32 index, Gfx::PVertexBuffer uniformBuffer) {
uint32 flattenedIndex = owner->getLayout()->getFlattenedIndex(binding, index);
void DescriptorSet::updateBuffer(const std::string& name, uint32 index, Gfx::PVertexBuffer uniformBuffer) {
uint32 flattenedIndex = owner->getLayout()->variableMapping[name].index + index;
PVertexBuffer buffer = uniformBuffer.cast<VertexBuffer>();
boundResources[flattenedIndex] = buffer->getHandle();
bufferWrites.add(BufferWriteInfo{
.index = flattenedIndex,
.buffer = buffer->getHandle(),
.access = owner->getLayout()->variableMapping[name].access,
});
}
void DescriptorSet::updateBuffer(uint32 binding, uint32 index, Gfx::PIndexBuffer uniformBuffer) {
uint32 flattenedIndex = owner->getLayout()->getFlattenedIndex(binding, index);
void DescriptorSet::updateBuffer(const std::string& name, uint32 index, Gfx::PIndexBuffer uniformBuffer) {
uint32 flattenedIndex = owner->getLayout()->variableMapping[name].index + index;
PIndexBuffer buffer = uniformBuffer.cast<IndexBuffer>();
boundResources[flattenedIndex] = buffer->getHandle();
bufferWrites.add(BufferWriteInfo{
.index = flattenedIndex,
.buffer = buffer->getHandle(),
.access = owner->getLayout()->variableMapping[name].access,
});
}
void DescriptorSet::updateSampler(uint32 binding, uint32 index, Gfx::PSampler samplerState) {
uint32 flattenedIndex = owner->getLayout()->getFlattenedIndex(binding, index);
void DescriptorSet::updateSampler(const std::string& name, uint32 index, Gfx::PSampler samplerState) {
uint32 flattenedIndex = owner->getLayout()->variableMapping[name].index + index;
PSampler sampler = samplerState.cast<Sampler>();
boundResources[flattenedIndex] = nullptr;
samplerWrites.add(SamplerWriteInfo{
.index = flattenedIndex,
.sampler = sampler->getHandle(),
});
}
void DescriptorSet::updateTexture(uint32 binding, uint32 index, Gfx::PTexture2D texture) {
uint32 flattenedIndex = owner->getLayout()->getFlattenedIndex(binding, index);
void DescriptorSet::updateTexture(const std::string& name, uint32 index, Gfx::PTexture2D texture) {
uint32 flattenedIndex = owner->getLayout()->variableMapping[name].index + index;
PTextureBase tex = texture.cast<TextureBase>();
boundResources[flattenedIndex] = tex->getImage();
textureWrites.add(TextureWriteInfo{
.index = flattenedIndex,
.texture = tex->getImage(),
.access = owner->getLayout()->variableMapping[name].access,
});
}
void DescriptorSet::updateTexture(uint32 binding, uint32 index, Gfx::PTexture3D texture) {
uint32 flattenedIndex = owner->getLayout()->getFlattenedIndex(binding, index);
void DescriptorSet::updateTexture(const std::string& name, uint32 index, Gfx::PTexture3D texture) {
uint32 flattenedIndex = owner->getLayout()->variableMapping[name].index + index;
PTextureBase tex = texture.cast<TextureBase>();
boundResources[flattenedIndex] = tex->getImage();
textureWrites.add(TextureWriteInfo{
.index = flattenedIndex,
.texture = tex->getImage(),
.access = owner->getLayout()->variableMapping[name].access,
});
}
void DescriptorSet::updateTexture(uint32 binding, uint32 index, Gfx::PTextureCube texture) {
uint32 flattenedIndex = owner->getLayout()->getFlattenedIndex(binding, index);
void DescriptorSet::updateTexture(const std::string& name, uint32 index, Gfx::PTextureCube texture) {
uint32 flattenedIndex = owner->getLayout()->variableMapping[name].index + index;
PTextureBase tex = texture.cast<TextureBase>();
boundResources[flattenedIndex] = tex->getImage();
textureWrites.add(TextureWriteInfo{
.index = flattenedIndex,
.texture = tex->getImage(),
.access = owner->getLayout()->variableMapping[name].access,
});
}
void DescriptorSet::updateAccelerationStructure(uint32 binding, uint32 index, Gfx::PTopLevelAS as) { assert(false && "TODO"); }
void DescriptorSet::updateAccelerationStructure(const std::string& name, uint32 index, Gfx::PTopLevelAS as) { assert(false && "TODO"); }
PipelineLayout::PipelineLayout(PGraphics graphics, const std::string& name, Gfx::PPipelineLayout baseLayout)
: Gfx::PipelineLayout(name, baseLayout), graphics(graphics) {}
+1 -3
View File
@@ -14,8 +14,6 @@ MTL::LoadAction cast(Gfx::SeAttachmentLoadOp loadOp);
Gfx::SeAttachmentLoadOp cast(MTL::LoadAction loadOp);
MTL::StoreAction cast(Gfx::SeAttachmentStoreOp storeOp);
Gfx::SeAttachmentStoreOp cast(MTL::StoreAction storeOp);
MTL::BindingAccess cast(Gfx::SeDescriptorAccessTypeFlags access);
Gfx::SeDescriptorAccessTypeFlags cast(MTL::BindingAccess access);
MTL::SamplerBorderColor cast(Gfx::SeBorderColor color);
Gfx::SeBorderColor cast(MTL::SamplerBorderColor color);
MTL::CompareFunction cast(Gfx::SeCompareOp compare);
@@ -31,4 +29,4 @@ Gfx::SePrimitiveTopology cast(MTL::PrimitiveTopologyClass topology);
MTL::IndexType cast(Gfx::SeIndexType indexType);
Gfx::SeIndexType cast(MTL::IndexType indexType);
} // namespace Metal
} // namespace Seele
} // namespace Seele
-26
View File
@@ -589,32 +589,6 @@ Gfx::SeAttachmentStoreOp Seele::Metal::cast(MTL::StoreAction storeOp) {
}
}
MTL::BindingAccess Seele::Metal::cast(Gfx::SeDescriptorAccessTypeFlags access) {
switch (access) {
case Gfx::SE_DESCRIPTOR_ACCESS_READ_ONLY_BIT:
return MTL::ArgumentAccessReadOnly;
case Gfx::SE_DESCRIPTOR_ACCESS_READ_WRITE_BIT:
return MTL::ArgumentAccessReadWrite;
case Gfx::SE_DESCRIPTOR_ACCESS_WRITE_ONLY_BIT:
return MTL::ArgumentAccessWriteOnly;
default:
throw std::logic_error("Not implemented");
}
}
Gfx::SeDescriptorAccessTypeFlags Seele::Metal::cast(MTL::BindingAccess access) {
switch (access) {
case MTL::ArgumentAccessReadOnly:
return Gfx::SE_DESCRIPTOR_ACCESS_READ_ONLY_BIT;
case MTL::ArgumentAccessReadWrite:
return Gfx::SE_DESCRIPTOR_ACCESS_READ_WRITE_BIT;
case MTL::ArgumentAccessWriteOnly:
return Gfx::SE_DESCRIPTOR_ACCESS_WRITE_ONLY_BIT;
default:
throw std::logic_error("Not implemented");
}
}
MTL::SamplerBorderColor Seele::Metal::cast(Gfx::SeBorderColor color) {
switch (color) {
case Gfx::SE_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK:
+1
View File
@@ -20,6 +20,7 @@ class Window : public Gfx::Window {
public:
Window(PGraphics graphics, const WindowCreateInfo& createInfo);
virtual ~Window();
virtual void show() override;
virtual void pollInput() override;
virtual void beginFrame() override;
virtual void endFrame() override;
+3
View File
@@ -67,6 +67,7 @@ Window::Window(PGraphics graphics, const WindowCreateInfo& createInfo) : graphic
float xscale = 1, yscale = 1;
glfwGetMonitorContentScale(glfwGetPrimaryMonitor(), &xscale, &yscale);
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
GLFWwindow* handle = glfwCreateWindow(createInfo.width / xscale, createInfo.height / yscale, createInfo.title, nullptr, nullptr);
windowHandle = handle;
glfwSetWindowUserPointer(handle, this);
@@ -98,6 +99,8 @@ Window::Window(PGraphics graphics, const WindowCreateInfo& createInfo) : graphic
Window::~Window() { glfwDestroyWindow(static_cast<GLFWwindow*>(windowHandle)); }
void Window::show() { glfwShowWindow(windowHandle); }
void Window::pollInput() { glfwPollEvents(); }
void Window::beginFrame() {
+20 -27
View File
@@ -13,6 +13,7 @@
#include "Graphics/Shader.h"
#include "Graphics/StaticMeshVertexData.h"
#include "Material/MaterialInstance.h"
#include "Math/Matrix.h"
#include "Math/Vector.h"
#include "RenderGraph.h"
#include "Window/Window.h"
@@ -34,14 +35,12 @@ BasePass::BasePass(Gfx::PGraphics graphics, PScene scene) : RenderPass(graphics)
basePassLayout->addDescriptorLayout(Material::getDescriptorLayout());
lightCullingLayout = graphics->createDescriptorLayout("pLightCullingData");
// oLightIndexList
lightCullingLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 0,
.name = LIGHTINDEX_NAME,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
});
// oLightGrid
lightCullingLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 1,
.name = LIGHTGRID_NAME,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_IMAGE,
});
lightCullingLayout->create();
@@ -122,17 +121,15 @@ void BasePass::beginFrame(const Component::Camera& cam) {
skyboxDataLayout->reset();
textureLayout->reset();
skyboxData.transformMatrix = glm::rotate(skyboxData.transformMatrix, (float)(Gfx::getCurrentFrameDelta()), Vector(0, 1, 0));
skyboxBuffer->rotateBuffer(sizeof(SkyboxData));
skyboxBuffer->updateContents(0, sizeof(SkyboxData), &skyboxData);
skyboxBuffer->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT,
Gfx::SE_ACCESS_UNIFORM_READ_BIT, Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
skyboxDataSet = skyboxDataLayout->allocateDescriptorSet();
skyboxDataSet->updateBuffer(0, 0, skyboxBuffer);
skyboxDataSet->updateConstants("transformMatrix", 0, &skyboxData.transformMatrix);
skyboxDataSet->updateConstants("fogBlend", 0, &skyboxData.fogColor);
skyboxDataSet->writeChanges();
textureSet = textureLayout->allocateDescriptorSet();
textureSet->updateTexture(0, 0, skybox.day);
textureSet->updateTexture(1, 0, skybox.night);
textureSet->updateSampler(2, 0, skyboxSampler);
textureSet->updateTexture(SKYBOXDAY_NAME, 0, skybox.day);
textureSet->updateTexture(SKYBOXNIGHT_NAME, 0, skybox.night);
textureSet->updateSampler(SKYBOXSAMPLER_NAME, 0, skyboxSampler);
textureSet->writeChanges();
}
}
@@ -252,7 +249,6 @@ void BasePass::render() {
//commands.add(terrainRenderer->render(viewParamsSet));
*/
// Skybox
graphics->waitDeviceIdle();
graphics->beginRenderPass(renderPass);
{
Gfx::ORenderCommand skyboxCommand = graphics->createRenderCommand("SkyboxRender");
@@ -556,22 +552,27 @@ void BasePass::createRenderPass() {
{
skyboxDataLayout = graphics->createDescriptorLayout("pSkyboxData");
skyboxDataLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 0,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
.uniformLength = sizeof(SkyboxData)
.name = "transformMatrix",
.uniformLength = sizeof(Matrix4)
});
skyboxDataLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.name = "fogBlend",
.uniformLength = sizeof(Vector4)
});
skyboxDataLayout->create();
textureLayout = graphics->createDescriptorLayout("pSkyboxTextures");
textureLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 0,
.name = SKYBOXDAY_NAME,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
.access = Gfx::SE_DESCRIPTOR_ACCESS_SAMPLE_BIT,
});
textureLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 1,
.name = SKYBOXNIGHT_NAME,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
.access = Gfx::SE_DESCRIPTOR_ACCESS_SAMPLE_BIT,
});
textureLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 2,
.name = SKYBOXSAMPLER_NAME,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLER,
});
textureLayout->create();
@@ -582,14 +583,6 @@ void BasePass::createRenderPass() {
skyboxData.fogColor = skybox.fogColor;
skyboxData.blendFactor = skybox.blendFactor;
skyboxBuffer = graphics->createUniformBuffer(UniformBufferCreateInfo{
.sourceData =
{
.size = sizeof(SkyboxData),
.data = (uint8*)&skyboxData,
},
});
pipelineLayout = graphics->createPipelineLayout("SkyboxLayout");
pipelineLayout->addDescriptorLayout(viewParamsLayout);
pipelineLayout->addDescriptorLayout(skyboxDataLayout);
+5 -1
View File
@@ -28,6 +28,8 @@ class BasePass : public RenderPass {
Gfx::PShaderBuffer tLightIndexList;
Gfx::PTexture2D oLightGrid;
Gfx::PTexture2D tLightGrid;
constexpr static std::string LIGHTINDEX_NAME = "lightIndexList";
constexpr static std::string LIGHTGRID_NAME = "lightGrid";
Gfx::PDescriptorSet opaqueCulling;
Gfx::PDescriptorSet transparentCulling;
@@ -76,8 +78,10 @@ class BasePass : public RenderPass {
Vector fogColor;
float blendFactor;
} skyboxData;
Gfx::OUniformBuffer skyboxBuffer;
Component::Skybox skybox;
constexpr static std::string SKYBOXDAY_NAME = "day";
constexpr static std::string SKYBOXNIGHT_NAME = "night";
constexpr static std::string SKYBOXSAMPLER_NAME = "sampler";
PScene scene;
};
DEFINE_REF(BasePass)
@@ -1,18 +1,18 @@
#include "DepthCullingPass.h"
#include "Graphics/Shader.h"
#include <algorithm>
using namespace Seele;
DepthCullingPass::DepthCullingPass(Gfx::PGraphics graphics, PScene scene) : RenderPass(graphics), scene(scene) {
depthAttachmentLayout = graphics->createDescriptorLayout("pDepthAttachment");
depthAttachmentLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 0,
.name = DEPTHTEXTURE_NAME,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
.shaderStages = Gfx::SE_SHADER_STAGE_TASK_BIT_EXT | Gfx::SE_SHADER_STAGE_MESH_BIT_EXT | Gfx::SE_SHADER_STAGE_COMPUTE_BIT,
.access = Gfx::SE_DESCRIPTOR_ACCESS_SAMPLE_BIT,
});
depthAttachmentLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 1,
.name = DEPTHMIP_NAME,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
.shaderStages = Gfx::SE_SHADER_STAGE_TASK_BIT_EXT | Gfx::SE_SHADER_STAGE_COMPUTE_BIT,
});
@@ -75,8 +75,8 @@ void DepthCullingPass::render() {
depthMipBuffer->rotateBuffer(depthMipBuffer->getNumElements() * sizeof(uint32));
Gfx::PDescriptorSet set = depthAttachmentLayout->allocateDescriptorSet();
set->updateTexture(0, 0, depthAttachment.getTexture());
set->updateBuffer(1, 0, depthMipBuffer);
set->updateTexture(DEPTHTEXTURE_NAME, 0, depthAttachment.getTexture());
set->updateBuffer(DEPTHMIP_NAME, 0, depthMipBuffer);
set->writeChanges();
timestamps->write(Gfx::SE_PIPELINE_STAGE_TOP_OF_PIPE_BIT, "MipBegin");
@@ -29,7 +29,9 @@ class DepthCullingPass : public RenderPass {
Array<uint32> mipOffsets;
Array<UVector2> mipDims;
constexpr static std::string DEPTHTEXTURE_NAME = "depthTexture";
Gfx::OShaderBuffer depthMipBuffer;
constexpr static std::string DEPTHMIP_NAME = "depthMip";
Gfx::RenderTargetAttachment depthAttachment;
Gfx::RenderTargetAttachment visibilityAttachment;
Gfx::ODescriptorLayout depthAttachmentLayout;
@@ -3,6 +3,7 @@
#include "Component/Camera.h"
#include "Graphics/Command.h"
#include "Graphics/Graphics.h"
#include "Math/Vector.h"
#include "RenderGraph.h"
#include "Scene/Scene.h"
#include "Graphics/Metal/Descriptor.h"
@@ -82,50 +83,39 @@ void LightCullingPass::publishOutputs() {
setupFrustums();
uint32_t viewportWidth = viewport->getWidth();
uint32_t viewportHeight = viewport->getHeight();
glm::uvec3 numThreadGroups = glm::ceil(glm::vec3(viewportWidth / (float)BLOCK_SIZE, viewportHeight / (float)BLOCK_SIZE, 1));
dispatchParams.numThreadGroups = numThreadGroups;
dispatchParams.numThreads = numThreadGroups * glm::uvec3(BLOCK_SIZE, BLOCK_SIZE, 1);
dispatchParamsBuffer = graphics->createUniformBuffer(UniformBufferCreateInfo{
.sourceData =
{
.size = sizeof(DispatchParams),
.data = (uint8*)&dispatchParams,
.owner = Gfx::QueueType::COMPUTE,
},
.name = "DispatchParams",
});
dispatchParamsBuffer->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT,
Gfx::SE_ACCESS_UNIFORM_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
UVector4 numThreadGroups = glm::ceil(glm::vec4(viewportWidth / (float)BLOCK_SIZE, viewportHeight / (float)BLOCK_SIZE, 1, 0));
UVector4 numThreads = numThreadGroups * glm::uvec4(BLOCK_SIZE, BLOCK_SIZE, 1, 0);
dispatchParamsSet = dispatchParamsLayout->allocateDescriptorSet();
dispatchParamsSet->updateBuffer(0, 0, dispatchParamsBuffer);
dispatchParamsSet->updateBuffer(1, 0, frustumBuffer);
dispatchParamsSet->updateConstants("numThreadGroups", 0, &numThreadGroups);
dispatchParamsSet->updateConstants("numThreads", 0, &numThreads);
dispatchParamsSet->writeChanges();
cullingDescriptorLayout = graphics->createDescriptorLayout("pCullingParams");
// DepthTexture
cullingDescriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 0,
.name = DEPTHATTACHMENT_NAME,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
.access = Gfx::SE_DESCRIPTOR_ACCESS_SAMPLE_BIT,
});
// o_lightIndexCounter
cullingDescriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 1, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER, .access = Gfx::SE_DESCRIPTOR_ACCESS_READ_WRITE_BIT});
.name = OLIGHTINDEXCOUNTER_NAME, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER, .access = Gfx::SE_DESCRIPTOR_ACCESS_READ_BIT | Gfx::SE_DESCRIPTOR_ACCESS_WRITE_BIT,});
// t_lightIndexCounter
cullingDescriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 2, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER, .access = Gfx::SE_DESCRIPTOR_ACCESS_READ_WRITE_BIT});
.name = TLIGHTINDEXCOUNTER_NAME, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER, .access = Gfx::SE_DESCRIPTOR_ACCESS_READ_BIT | Gfx::SE_DESCRIPTOR_ACCESS_WRITE_BIT,});
// o_lightIndexList
cullingDescriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 3, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER, .access = Gfx::SE_DESCRIPTOR_ACCESS_READ_WRITE_BIT});
.name = OLIGHTINDEXLIST_NAME, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER, .access = Gfx::SE_DESCRIPTOR_ACCESS_READ_BIT | Gfx::SE_DESCRIPTOR_ACCESS_WRITE_BIT,});
// t_lightIndexList
cullingDescriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 4, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER, .access = Gfx::SE_DESCRIPTOR_ACCESS_READ_WRITE_BIT});
.name = TLIGHTINDEXLIST_NAME, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER, .access = Gfx::SE_DESCRIPTOR_ACCESS_READ_BIT | Gfx::SE_DESCRIPTOR_ACCESS_WRITE_BIT,});
// o_lightGrid
cullingDescriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 5, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_IMAGE, .access = Gfx::SE_DESCRIPTOR_ACCESS_READ_WRITE_BIT});
.name = OLIGHTGRID_NAME, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_IMAGE, .access = Gfx::SE_DESCRIPTOR_ACCESS_READ_BIT | Gfx::SE_DESCRIPTOR_ACCESS_WRITE_BIT,});
// t_lightGrid
cullingDescriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 6, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_IMAGE, .access = Gfx::SE_DESCRIPTOR_ACCESS_READ_WRITE_BIT});
.name = TLIGHTGRID_NAME, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_IMAGE, .access = Gfx::SE_DESCRIPTOR_ACCESS_READ_BIT | Gfx::SE_DESCRIPTOR_ACCESS_WRITE_BIT,});
cullingDescriptorLayout->create();
@@ -195,8 +185,8 @@ void LightCullingPass::publishOutputs() {
structInfo = {
.sourceData =
{
.size = (uint32)sizeof(uint32) * dispatchParams.numThreadGroups.x * dispatchParams.numThreadGroups.y *
dispatchParams.numThreadGroups.z * 8192,
.size = (uint32)sizeof(uint32) * numThreadGroups.x * numThreadGroups.y *
numThreadGroups.z * 8192,
.data = nullptr,
.owner = Gfx::QueueType::COMPUTE,
},
@@ -210,8 +200,8 @@ void LightCullingPass::publishOutputs() {
TextureCreateInfo textureInfo = {
.format = Gfx::SE_FORMAT_R32G32_UINT,
.width = dispatchParams.numThreadGroups.x,
.height = dispatchParams.numThreadGroups.y,
.width = numThreadGroups.x,
.height = numThreadGroups.y,
.usage = Gfx::SE_IMAGE_USAGE_STORAGE_BIT,
};
oLightGrid = graphics->createTexture2D(textureInfo);
@@ -237,25 +227,24 @@ void LightCullingPass::setupFrustums() {
uint32_t viewportWidth = viewport->getWidth();
uint32_t viewportHeight = viewport->getHeight();
glm::uvec3 numThreads = glm::ceil(glm::vec3(viewportWidth / (float)BLOCK_SIZE, viewportHeight / (float)BLOCK_SIZE, 1));
glm::uvec3 numThreadGroups = glm::ceil(glm::vec3(numThreads.x / (float)BLOCK_SIZE, numThreads.y / (float)BLOCK_SIZE, 1));
glm::uvec4 numThreads = glm::ceil(glm::vec4(viewportWidth / (float)BLOCK_SIZE, viewportHeight / (float)BLOCK_SIZE, 1, 0));
glm::uvec4 numThreadGroups = glm::ceil(glm::vec4(numThreads.x / (float)BLOCK_SIZE, numThreads.y / (float)BLOCK_SIZE, 1, 0));
RenderPass::beginFrame(Component::Camera());
viewParamsBuffer->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT,
Gfx::SE_ACCESS_UNIFORM_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
dispatchParams.numThreads = numThreads;
dispatchParams.numThreadGroups = numThreadGroups;
dispatchParamsLayout = graphics->createDescriptorLayout("pDispatchParams");
dispatchParamsLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 0,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
.uniformLength = sizeof(DispatchParams),
.name = "numThreadGroups",
.uniformLength = sizeof(UVector4),
});
dispatchParamsLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 1,
.name = "numThreads",
.uniformLength = sizeof(UVector4),
});
dispatchParamsLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.name = FRUSTUMBUFFER_NAME,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
.access = Gfx::SE_DESCRIPTOR_ACCESS_WRITE_ONLY_BIT,
.access = Gfx::SE_DESCRIPTOR_ACCESS_WRITE_BIT,
});
dispatchParamsLayout->create();
frustumLayout = graphics->createPipelineLayout("FrustumLayout");
@@ -278,17 +267,6 @@ void LightCullingPass::setupFrustums() {
pipelineInfo.pipelineLayout = frustumLayout;
frustumPipeline = graphics->createComputePipeline(pipelineInfo);
Gfx::OUniformBuffer frustumDispatchParamsBuffer = graphics->createUniformBuffer(UniformBufferCreateInfo{
.sourceData =
{
.size = sizeof(DispatchParams),
.data = (uint8*)&dispatchParams,
.owner = Gfx::QueueType::COMPUTE,
},
.name = "FrustumDispatch",
});
frustumDispatchParamsBuffer->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT,
Gfx::SE_ACCESS_UNIFORM_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
frustumBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
.sourceData =
{
@@ -302,10 +280,10 @@ 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);
graphics->waitDeviceIdle();
Gfx::PDescriptorSet dispatchParamsSet = dispatchParamsLayout->allocateDescriptorSet();
dispatchParamsSet->updateBuffer(0, 0, frustumDispatchParamsBuffer);
dispatchParamsSet->updateBuffer(1, 0, frustumBuffer);
dispatchParamsSet->updateConstants("numThreadGroups", 0, &numThreadGroups);
dispatchParamsSet->updateConstants("numThreads", 0, &numThreads);
dispatchParamsSet->updateBuffer(FRUSTUMBUFFER_NAME, 0, frustumBuffer);
dispatchParamsSet->writeChanges();
Gfx::OComputeCommand command = graphics->createComputeCommand("FrustumCommand");
@@ -25,15 +25,9 @@ class LightCullingPass : public RenderPass {
void setupFrustums();
static constexpr uint32 BLOCK_SIZE = 32;
static constexpr uint32 INDEX_LIGHT_ENV = 1;
struct DispatchParams {
glm::uvec3 numThreadGroups;
uint32_t pad0;
glm::uvec3 numThreads;
uint32_t pad1;
} dispatchParams;
Gfx::OShaderBuffer frustumBuffer;
Gfx::OUniformBuffer dispatchParamsBuffer;
constexpr static std::string FRUSTUMBUFFER_NAME = "frustums";
Gfx::ODescriptorLayout dispatchParamsLayout;
Gfx::PDescriptorSet dispatchParamsSet;
Gfx::OComputeShader frustumShader;
@@ -42,12 +36,19 @@ class LightCullingPass : public RenderPass {
PLightEnvironment lightEnv;
Gfx::PTexture2D depthAttachment;
constexpr static std::string DEPTHATTACHMENT_NAME = "depth";
Gfx::OShaderBuffer oLightIndexCounter;
constexpr static std::string OLIGHTINDEXCOUNTER_NAME = "oLightIndexCounter";
Gfx::OShaderBuffer tLightIndexCounter;
constexpr static std::string TLIGHTINDEXCOUNTER_NAME = "tLightIndexCounter";
Gfx::OShaderBuffer oLightIndexList;
constexpr static std::string OLIGHTINDEXLIST_NAME = "oLightIndexList";
Gfx::OShaderBuffer tLightIndexList;
constexpr static std::string TLIGHTINDEXLIST_NAME = "tLightIndexList";
Gfx::OTexture2D oLightGrid;
constexpr static std::string OLIGHTGRID_NAME = "oLightGrid";
Gfx::OTexture2D tLightGrid;
constexpr static std::string TLIGHTGRID_NAME = "tLightGrid";
Gfx::PDescriptorSet cullingDescriptorSet;
Gfx::ODescriptorLayout cullingDescriptorLayout;
Gfx::OPipelineLayout cullingLayout;
@@ -16,7 +16,7 @@ struct SampleParams {
RayTracingPass::RayTracingPass(Gfx::PGraphics graphics, PScene scene) : RenderPass(graphics), scene(scene) {
paramsLayout = graphics->createDescriptorLayout("pRayTracingParams");
paramsLayout->addDescriptorBinding(Gfx::DescriptorBinding{
/*paramsLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 0,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR,
});
@@ -39,7 +39,7 @@ RayTracingPass::RayTracingPass(Gfx::PGraphics graphics, PScene scene) : RenderPa
paramsLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 5,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLER,
});
});*/
paramsLayout->create();
pipelineLayout = graphics->createPipelineLayout("RayTracing");
pipelineLayout->addDescriptorLayout(viewParamsLayout);
@@ -137,12 +137,12 @@ void RayTracingPass::render() {
.bottomLevelStructures = accelerationStructures,
});
Gfx::PDescriptorSet desc = paramsLayout->allocateDescriptorSet();
desc->updateAccelerationStructure(0, 0, tlas);
/*desc->updateAccelerationStructure(0, 0, tlas);
desc->updateTexture(1, 0, radianceAccumulator);
desc->updateTexture(2, 0, texture);
desc->updateBuffer(3, 0, StaticMeshVertexData::getInstance()->getIndexBuffer());
desc->updateTexture(4, 0, skyBox);
desc->updateSampler(5, 0, skyBoxSampler);
desc->updateSampler(5, 0, skyBoxSampler);*/
desc->writeChanges();
Gfx::ORenderCommand command = graphics->createRenderCommand("RayTracing");
+28 -22
View File
@@ -4,20 +4,20 @@ using namespace Seele;
RenderPass::RenderPass(Gfx::PGraphics graphics) : graphics(graphics) {
viewParamsLayout = graphics->createDescriptorLayout("pViewParams");
viewParamsLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 0,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
.uniformLength = sizeof(ViewParameter),
});
UniformBufferCreateInfo uniformInitializer = {
.sourceData =
{
.size = sizeof(ViewParameter),
.data = (uint8*)&viewParams,
},
.name = "viewParamsBuffer",
};
viewParamsBuffer = graphics->createUniformBuffer(uniformInitializer);
viewParamsLayout->addDescriptorBinding(Gfx::DescriptorBinding{.name = "viewMatrix", .uniformLength = sizeof(Matrix4)});
viewParamsLayout->addDescriptorBinding(Gfx::DescriptorBinding{.name = "inverseViewMatrix", .uniformLength = sizeof(Matrix4)});
viewParamsLayout->addDescriptorBinding(Gfx::DescriptorBinding{.name = "projectionMatrix", .uniformLength = sizeof(Matrix4)});
viewParamsLayout->addDescriptorBinding(Gfx::DescriptorBinding{.name = "inverseProjection", .uniformLength = sizeof(Matrix4)});
viewParamsLayout->addDescriptorBinding(Gfx::DescriptorBinding{.name = "viewProjectionMatrix", .uniformLength = sizeof(Matrix4)});
viewParamsLayout->addDescriptorBinding(Gfx::DescriptorBinding{.name = "inverseViewProjectionMatrix", .uniformLength = sizeof(Matrix4)});
viewParamsLayout->addDescriptorBinding(Gfx::DescriptorBinding{.name = "cameraPosition_WS", .uniformLength = sizeof(Vector4)});
viewParamsLayout->addDescriptorBinding(Gfx::DescriptorBinding{.name = "cameraForward_WS", .uniformLength = sizeof(Vector4)});
viewParamsLayout->addDescriptorBinding(Gfx::DescriptorBinding{.name = "screenDimensions", .uniformLength = sizeof(Vector2)});
viewParamsLayout->addDescriptorBinding(Gfx::DescriptorBinding{.name = "invScreenDimensions", .uniformLength = sizeof(Vector2)});
viewParamsLayout->addDescriptorBinding(Gfx::DescriptorBinding{.name = "frameIndex", .uniformLength = sizeof(uint32)});
viewParamsLayout->addDescriptorBinding(Gfx::DescriptorBinding{.name = "time", .uniformLength = sizeof(float)});
viewParamsLayout->addDescriptorBinding(Gfx::DescriptorBinding{.name = "pad0", .uniformLength = sizeof(float)});
viewParamsLayout->addDescriptorBinding(Gfx::DescriptorBinding{.name = "pad1", .uniformLength = sizeof(float)});
viewParamsLayout->create();
}
@@ -62,16 +62,22 @@ void RenderPass::beginFrame(const Component::Camera& cam) {
//extract_planes_from_view_projection_matrix(viewParams.viewProjectionMatrix, viewParams.viewFrustum);
viewParamsBuffer->rotateBuffer(sizeof(ViewParameter));
viewParamsBuffer->updateContents(0, sizeof(ViewParameter), &viewParams);
viewParamsBuffer->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT,
Gfx::SE_ACCESS_UNIFORM_READ_BIT | Gfx::SE_ACCESS_TRANSFER_WRITE_BIT,
Gfx::SE_PIPELINE_STAGE_TASK_SHADER_BIT_EXT | Gfx::SE_PIPELINE_STAGE_MESH_SHADER_BIT_EXT |
Gfx::SE_PIPELINE_STAGE_VERTEX_SHADER_BIT | Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT |
Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT);
viewParamsLayout->reset();
viewParamsSet = viewParamsLayout->allocateDescriptorSet();
viewParamsSet->updateBuffer(0, 0, viewParamsBuffer);
viewParamsSet->updateConstants("viewMatrix", 0, &viewParams.viewMatrix);
viewParamsSet->updateConstants("inverseViewMatrix", 0, &viewParams.inverseViewMatrix);
viewParamsSet->updateConstants("projectionMatrix", 0, &viewParams.projectionMatrix);
viewParamsSet->updateConstants("inverseProjection", 0, &viewParams.inverseProjection);
viewParamsSet->updateConstants("viewProjectionMatrix", 0, &viewParams.viewProjectionMatrix);
viewParamsSet->updateConstants("inverseViewProjectionMatrix", 0, &viewParams.inverseViewProjectionMatrix);
viewParamsSet->updateConstants("cameraPosition_WS", 0, &viewParams.cameraPosition_WS);
viewParamsSet->updateConstants("cameraForward_WS", 0, &viewParams.cameraForward_WS);
viewParamsSet->updateConstants("screenDimensions", 0, &viewParams.screenDimensions);
viewParamsSet->updateConstants("invScreenDimensions", 0, &viewParams.invScreenDimensions);
viewParamsSet->updateConstants("frameIndex", 0, &viewParams.frameIndex);
viewParamsSet->updateConstants("time", 0, &viewParams.time);
viewParamsSet->updateConstants("pad0", 0, &viewParams.pad0);
viewParamsSet->updateConstants("pad1", 0, &viewParams.pad1);
viewParamsSet->writeChanges();
}
@@ -67,7 +67,6 @@ class RenderPass {
} viewParams;
PRenderGraphResources resources;
Gfx::ODescriptorLayout viewParamsLayout;
Gfx::OUniformBuffer viewParamsBuffer;
Gfx::PDescriptorSet viewParamsSet;
Gfx::ORenderPass renderPass;
Gfx::PGraphics graphics;
@@ -273,10 +273,10 @@ void TerrainRenderer::beginFrame(Gfx::PDescriptorSet viewParamsSet, const Compon
Gfx::ORenderCommand TerrainRenderer::render(Gfx::PDescriptorSet viewParamsSet) {
Gfx::PDescriptorSet set = meshUpdater.layout->allocateDescriptorSet();
set->updateBuffer(CURRENT_VERTEX_BUFFER, 0, plainMesh.currentVertexBuffer);
/*set->updateBuffer(CURRENT_VERTEX_BUFFER, 0, plainMesh.currentVertexBuffer);
set->updateBuffer(INDEXED_BISECTOR_BUFFER, 0, plainMesh.indexedBisectorBuffer);
set->updateSampler(SAMPLER_LOCATION, 0, sampler);
set->updateTexture(DISPLACEMENT_MAP, 0, displacementAsset);
set->updateTexture(DISPLACEMENT_MAP, 0, displacementAsset);*/
set->writeChanges();
Gfx::ORenderCommand command = graphics->createRenderCommand("TerrainRender");
command->setViewport(viewport);
@@ -322,11 +322,11 @@ void TerrainRenderer::setViewport(Gfx::PViewport _viewport, Gfx::PRenderPass ren
void TerrainRenderer::applyDeformation(Gfx::PDescriptorSet viewParamsSet) {
graphics->beginDebugRegion("ApplyDeformation");
Gfx::PDescriptorSet set = meshUpdater.layout->allocateDescriptorSet();
set->updateBuffer(GEOMETRY_CB, 0, geometryBuffer);
/*set->updateBuffer(GEOMETRY_CB, 0, geometryBuffer);
set->updateBuffer(INDIRECT_DRAW_BUFFER, 0, plainMesh.indirectDrawBuffer);
set->updateBuffer(INDEXED_BISECTOR_BUFFER, 0, plainMesh.indexedBisectorBuffer);
set->updateBuffer(LEB_POSITION_BUFFER, 0, plainMesh.lebVertexBuffer);
set->updateBuffer(CURRENT_VERTEX_BUFFER, 0, plainMesh.currentVertexBuffer);
set->updateBuffer(CURRENT_VERTEX_BUFFER, 0, plainMesh.currentVertexBuffer);*/
set->writeChanges();
Gfx::OComputeCommand command = graphics->createComputeCommand("Deform");
command->bindPipeline(deform);
+14 -12
View File
@@ -13,17 +13,18 @@ UIPass::UIPass(Gfx::PGraphics graphics, UI::PSystem system) : RenderPass(graphic
elementBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{.name = "RenderStyleElements"});
textDescriptorLayout = graphics->createDescriptorLayout("pText");
textDescriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 0,
.name = GLYPHINSTANCE_NAME,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
});
textDescriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 1,
.name = GLYPHSAMPLER_NAME,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLER,
});
textDescriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 2,
.name = TEXTURES_NAME,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
.descriptorCount = 1024,
.access = Gfx::SE_DESCRIPTOR_ACCESS_SAMPLE_BIT,
});
textPipelineLayout = graphics->createPipelineLayout("TextPipeline");
textPipelineLayout->addDescriptorLayout(viewParamsLayout);
@@ -31,17 +32,18 @@ UIPass::UIPass(Gfx::PGraphics graphics, UI::PSystem system) : RenderPass(graphic
uiDescriptorLayout = graphics->createDescriptorLayout("pParams");
uiDescriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 0,
.name = GLYPHINSTANCE_NAME,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
});
uiDescriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 1,
.name = GLYPHSAMPLER_NAME,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLER,
});
uiDescriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 2,
.name = TEXTURES_NAME,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
.descriptorCount = 1024,
.access = Gfx::SE_DESCRIPTOR_ACCESS_SAMPLE_BIT,
});
uiPipelineLayout = graphics->createPipelineLayout("UIPipeline");
uiPipelineLayout->addDescriptorLayout(viewParamsLayout);
@@ -81,10 +83,10 @@ void UIPass::beginFrame(const Component::Camera& cam) {
textDescriptorLayout->reset();
textDescriptorSet = textDescriptorLayout->allocateDescriptorSet();
textDescriptorSet->updateBuffer(0, 0, glyphInstanceBuffer);
textDescriptorSet->updateSampler(1, 0, glyphSampler);
textDescriptorSet->updateBuffer(GLYPHINSTANCE_NAME, 0, glyphInstanceBuffer);
textDescriptorSet->updateSampler(GLYPHSAMPLER_NAME, 0, glyphSampler);
for (uint32 i = 0; i < usedTextures.size(); ++i) {
textDescriptorSet->updateTexture(2, i, usedTextures[i]);
textDescriptorSet->updateTexture(TEXTURES_NAME, i, usedTextures[i]);
}
textDescriptorSet->writeChanges();
@@ -94,10 +96,10 @@ void UIPass::beginFrame(const Component::Camera& cam) {
Gfx::SE_PIPELINE_STAGE_VERTEX_SHADER_BIT);
uiDescriptorLayout->reset();
uiDescriptorSet = uiDescriptorLayout->allocateDescriptorSet();
uiDescriptorSet->updateBuffer(0, 0, elementBuffer);
uiDescriptorSet->updateSampler(1, 0, glyphSampler);
uiDescriptorSet->updateBuffer(ELEMENT_NAME, 0, elementBuffer);
uiDescriptorSet->updateSampler(GLYPHSAMPLER_NAME, 0, glyphSampler);
for (uint32 i = 0; i < usedTextures.size(); ++i) {
uiDescriptorSet->updateTexture(2, i, usedTextures[i]);
uiDescriptorSet->updateTexture(TEXTURES_NAME, i, usedTextures[i]);
}
uiDescriptorSet->writeChanges();
}
+4
View File
@@ -72,9 +72,13 @@ class UIPass : public RenderPass {
Array<GlyphInstanceData> glyphs;
Array<RenderElementStyle> elements;
Gfx::OShaderBuffer glyphInstanceBuffer;
constexpr static std::string GLYPHINSTANCE_NAME = "glyphData";
Gfx::OShaderBuffer elementBuffer;
constexpr static std::string ELEMENT_NAME = "elements";
Gfx::OSampler glyphSampler;
constexpr static std::string GLYPHSAMPLER_NAME = "glyphSampler";
Array<Gfx::PTexture2D> usedTextures;
constexpr static std::string TEXTURES_NAME = "textures";
};
DEFINE_REF(UIPass);
} // namespace Seele
@@ -21,8 +21,8 @@ void VisibilityPass::render() {
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
visibilityDescriptor->reset();
visibilitySet = visibilityDescriptor->allocateDescriptorSet();
visibilitySet->updateTexture(0, 0, visibilityAttachment.getTexture());
visibilitySet->updateBuffer(1, 0, cullingBuffer);
visibilitySet->updateTexture(VISIBILITY_NAME, 0, visibilityAttachment.getTexture());
visibilitySet->updateBuffer(CULLINGBUFFER_NAME, 0, cullingBuffer);
visibilitySet->writeChanges();
query->beginQuery();
@@ -49,13 +49,14 @@ void VisibilityPass::publishOutputs() {
threadGroupSize = glm::ceil(glm::vec3(viewportWidth / (float)BLOCK_SIZE, viewportHeight / (float)BLOCK_SIZE, 1));
visibilityDescriptor = graphics->createDescriptorLayout("pVisibilityParams");
visibilityDescriptor->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 0,
.name = VISIBILITY_NAME,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
.access = Gfx::SE_DESCRIPTOR_ACCESS_SAMPLE_BIT,
});
visibilityDescriptor->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 1,
.name = CULLINGBUFFER_NAME,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
.access = Gfx::SE_DESCRIPTOR_ACCESS_READ_WRITE_BIT,
.access = Gfx::SE_DESCRIPTOR_ACCESS_READ_BIT | Gfx::SE_DESCRIPTOR_ACCESS_WRITE_BIT,
});
visibilityDescriptor->create();
@@ -1,5 +1,6 @@
#pragma once
#include "Graphics/Query.h"
#include "Math/Vector.h"
#include "RenderPass.h"
namespace Seele {
@@ -26,9 +27,11 @@ class VisibilityPass : public RenderPass {
Gfx::OPipelineStatisticsQuery query;
Gfx::PTimestampQuery timestamps;
constexpr static std::string VISIBILITY_NAME = "visibilityTexture";
// Holds culling information for every meshlet for each instance
Gfx::OShaderBuffer cullingBuffer;
glm::uvec3 threadGroupSize;
constexpr static std::string CULLINGBUFFER_NAME = "cullingBuffer";
UVector threadGroupSize;
};
DEFINE_REF(VisibilityPass)
} // namespace Seele
@@ -121,7 +121,7 @@ WaterRenderer::WaterRenderer(Gfx::PGraphics graphics, PScene scene, Gfx::PDescri
});
computeLayout = graphics->createDescriptorLayout("pParams");
computeLayout->addDescriptorBinding(Gfx::DescriptorBinding{
/*computeLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 0,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
.uniformLength = sizeof(MaterialParams),
@@ -153,7 +153,7 @@ WaterRenderer::WaterRenderer(Gfx::PGraphics graphics, PScene scene, Gfx::PDescri
computeLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 7,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLER,
});
});*/
computeLayout->create();
pipelineLayout = graphics->createPipelineLayout("WaterComputeLayout");
@@ -210,7 +210,7 @@ WaterRenderer::WaterRenderer(Gfx::PGraphics graphics, PScene scene, Gfx::PDescri
});
materialLayout = graphics->createDescriptorLayout("pWaterMaterial");
materialLayout->addDescriptorBinding(Gfx::DescriptorBinding{
/*materialLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 0,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
});
@@ -233,7 +233,7 @@ WaterRenderer::WaterRenderer(Gfx::PGraphics graphics, PScene scene, Gfx::PDescri
materialLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 5,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
});
});*/
materialLayout->create();
waterLayout = graphics->createPipelineLayout("WaterLayout");
waterLayout->addDescriptorLayout(viewParamsLayout);
@@ -530,14 +530,14 @@ void WaterRenderer::updateFFTDescriptor() {
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
computeSet = computeLayout->allocateDescriptorSet();
computeSet->updateBuffer(0, 0, paramsBuffer);
/*computeSet->updateBuffer(0, 0, paramsBuffer);
computeSet->updateTexture(1, 0, spectrumTextures);
computeSet->updateTexture(2, 0, initialSpectrumTextures);
computeSet->updateTexture(3, 0, displacementTextures);
computeSet->updateTexture(4, 0, slopeTextures);
computeSet->updateTexture(5, 0, boyancyData);
computeSet->updateBuffer(6, 0, spectrumBuffer);
computeSet->updateSampler(7, 0, linearRepeatSampler);
computeSet->updateSampler(7, 0, linearRepeatSampler);*/
computeSet->writeChanges();
}
@@ -547,11 +547,11 @@ void WaterRenderer::updateMaterialDescriptor() {
Gfx::SE_ACCESS_UNIFORM_READ_BIT,
Gfx::SE_PIPELINE_STAGE_MESH_SHADER_BIT_EXT | Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
materialSet = materialLayout->allocateDescriptorSet();
materialSet->updateBuffer(0, 0, materialUniforms);
/*materialSet->updateBuffer(0, 0, materialUniforms);
materialSet->updateTexture(1, 0, displacementTextures);
materialSet->updateTexture(2, 0, slopeTextures);
materialSet->updateTexture(3, 0, skyBox);
materialSet->updateSampler(4, 0, linearRepeatSampler);
materialSet->updateBuffer(5, 0, waterTiles);
materialSet->updateBuffer(5, 0, waterTiles);*/
materialSet->writeChanges();
}
+12 -12
View File
@@ -123,27 +123,27 @@ void StaticMeshVertexData::init(Gfx::PGraphics _graphics) {
VertexData::init(_graphics);
descriptorLayout = _graphics->createDescriptorLayout("pVertexData");
descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 0,
.name = POSITIONS_NAME,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
});
descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 1,
.name = NORMALS_NAME,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
});
descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 2,
.name = TANGENTS_NAME,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
});
descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 3,
.name = BITANGENTS_NAME,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
});
descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 4,
.name = COLORS_NAME,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
});
descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 5,
.name = TEXCOORDS_NAME,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
.descriptorCount = MAX_TEXCOORDS,
});
@@ -238,13 +238,13 @@ void StaticMeshVertexData::updateBuffers() {
}
descriptorLayout->reset();
descriptorSet = descriptorLayout->allocateDescriptorSet();
descriptorSet->updateBuffer(0, 0, positions);
descriptorSet->updateBuffer(1, 0, normals);
descriptorSet->updateBuffer(2, 0, tangents);
descriptorSet->updateBuffer(3, 0, biTangents);
descriptorSet->updateBuffer(4, 0, colors);
descriptorSet->updateBuffer(POSITIONS_NAME, 0, positions);
descriptorSet->updateBuffer(NORMALS_NAME, 0, normals);
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) {
descriptorSet->updateBuffer(5, i, texCoords[i]);
descriptorSet->updateBuffer(TEXCOORDS_NAME, i, texCoords[i]);
}
descriptorSet->writeChanges();
}
@@ -41,11 +41,17 @@ class StaticMeshVertexData : public VertexData {
Gfx::OShaderBuffer positions;
constexpr static std::string POSITIONS_NAME = "positions";
Gfx::OShaderBuffer texCoords[MAX_TEXCOORDS];
constexpr static std::string TEXCOORDS_NAME = "texCoords";
Gfx::OShaderBuffer normals;
constexpr static std::string NORMALS_NAME = "normals";
Gfx::OShaderBuffer tangents;
constexpr static std::string TANGENTS_NAME = "tangents";
Gfx::OShaderBuffer biTangents;
constexpr static std::string BITANGENTS_NAME = "biTangents";
Gfx::OShaderBuffer colors;
constexpr static std::string COLORS_NAME = "colors";
Array<PositionType> posData;
Array<TexCoordType> texData[MAX_TEXCOORDS];
Array<NormalType> norData;
+28 -18
View File
@@ -166,12 +166,12 @@ void VertexData::createDescriptors() {
instanceDataLayout->reset();
descriptorSet = instanceDataLayout->allocateDescriptorSet();
descriptorSet->updateBuffer(0, 0, instanceBuffer);
descriptorSet->updateBuffer(1, 0, instanceMeshDataBuffer);
descriptorSet->updateBuffer(2, 0, meshletBuffer);
descriptorSet->updateBuffer(3, 0, primitiveIndicesBuffer);
descriptorSet->updateBuffer(4, 0, vertexIndicesBuffer);
descriptorSet->updateBuffer(5, 0, cullingOffsetBuffer);
descriptorSet->updateBuffer(INSTANCES_NAME, 0, instanceBuffer);
descriptorSet->updateBuffer(MESHDATA_NAME, 0, instanceMeshDataBuffer);
descriptorSet->updateBuffer(MESHLET_NAME, 0, meshletBuffer);
descriptorSet->updateBuffer(PRIMITIVEINDICES_NAME, 0, primitiveIndicesBuffer);
descriptorSet->updateBuffer(VERTEXINDICES_NAME, 0, vertexIndicesBuffer);
descriptorSet->updateBuffer(CULLINGOFFSETS_NAME, 0, cullingOffsetBuffer);
Material::updateDescriptor();
}
@@ -319,29 +319,39 @@ void VertexData::init(Gfx::PGraphics _graphics) {
// instanceData
instanceDataLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 0,
.name = INSTANCES_NAME,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
});
// meshData
instanceDataLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 1,
.name = MESHDATA_NAME,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
});
// meshletData
instanceDataLayout->addDescriptorBinding(
Gfx::DescriptorBinding{.binding = 2, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER});
instanceDataLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.name = MESHLET_NAME,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
});
// primitiveIndices
instanceDataLayout->addDescriptorBinding(
Gfx::DescriptorBinding{.binding = 3, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER});
instanceDataLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.name = PRIMITIVEINDICES_NAME,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
});
// vertexIndices
instanceDataLayout->addDescriptorBinding(
Gfx::DescriptorBinding{.binding = 4, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER});
instanceDataLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.name = VERTEXINDICES_NAME,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
});
// cullingOffset
instanceDataLayout->addDescriptorBinding(
Gfx::DescriptorBinding{.binding = 5, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER});
instanceDataLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.name = CULLINGOFFSETS_NAME,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
});
// cullingInfos
instanceDataLayout->addDescriptorBinding(
Gfx::DescriptorBinding{.binding = 6, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER});
instanceDataLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.name = CULLINGDATA_NAME,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
});
instanceDataLayout->create();
+9
View File
@@ -128,18 +128,27 @@ class VertexData {
Gfx::ODescriptorLayout instanceDataLayout;
// for mesh shading
Gfx::OShaderBuffer meshletBuffer;
constexpr static std::string MESHLET_NAME = "meshlets";
Gfx::OShaderBuffer vertexIndicesBuffer;
constexpr static std::string VERTEXINDICES_NAME = "vertexIndices";
Gfx::OShaderBuffer primitiveIndicesBuffer;
constexpr static std::string PRIMITIVEINDICES_NAME = "primitiveIndices";
Gfx::OShaderBuffer cullingOffsetBuffer;
constexpr static std::string CULLINGOFFSETS_NAME = "cullingOffsets";
constexpr static std::string CULLINGDATA_NAME = "cullingData";
// for legacy pipeline
Gfx::OIndexBuffer indexBuffer;
constexpr static std::string INDEXBUFFER_NAME = "indexBuffer";
Array<Gfx::PBottomLevelAS> dataToBuild;
// Material data
Array<InstanceData> instanceData;
Gfx::OShaderBuffer instanceBuffer;
constexpr static std::string INSTANCES_NAME = "instances";
Array<MeshData> instanceMeshData;
Gfx::OShaderBuffer instanceMeshDataBuffer;
constexpr static std::string MESHDATA_NAME = "meshData";
Array<Gfx::PBottomLevelAS> rayTracingScene;
+69 -43
View File
@@ -3,8 +3,15 @@
#include "CRC.h"
#include "Command.h"
#include "Graphics.h"
#include "Graphics/Buffer.h"
#include "Graphics/Descriptor.h"
#include "Graphics/Enums.h"
#include "Graphics/Initializer.h"
#include "RayTracing.h"
#include "Texture.h"
#include "vulkan/vulkan_core.h"
#include <algorithm>
#include <ranges>
using namespace Seele;
using namespace Seele::Vulkan;
@@ -23,18 +30,39 @@ void DescriptorLayout::create() {
if (layoutHandle != VK_NULL_HANDLE) {
return;
}
bindings.resize(descriptorBindings.size());
Array<VkDescriptorBindingFlags> bindingFlags(descriptorBindings.size());
for (size_t i = 0; i < descriptorBindings.size(); ++i) {
const Gfx::DescriptorBinding& gfxBinding = descriptorBindings[i];
bindings[i] = {
.binding = gfxBinding.binding,
.descriptorType = cast(gfxBinding.descriptorType),
.descriptorCount = gfxBinding.descriptorCount,
.stageFlags = gfxBinding.shaderStages,
Array<VkDescriptorBindingFlags> bindingFlags;
if (std::ranges::contains(descriptorBindings, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &Gfx::DescriptorBinding::descriptorType)) {
bindings.add({
.binding = 0,
.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
.descriptorCount = 1,
.stageFlags = VK_SHADER_STAGE_ALL, // todo
.pImmutableSamplers = nullptr,
};
bindingFlags[i] = gfxBinding.bindingFlags;
});
bindingFlags.add(0);
}
for (const auto& gfxBinding : descriptorBindings) {
if (gfxBinding.descriptorType == Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER) {
mappings[gfxBinding.name] = {
.binding = 0,
.constantOffset = constantsSize,
.constantSize = gfxBinding.uniformLength,
};
constantsSize += gfxBinding.uniformLength;
constantsStages |= gfxBinding.shaderStages;
} else {
mappings[gfxBinding.name] = {
.binding = (uint32)bindings.size(),
};
bindings.add({
.binding = (uint32)bindings.size(),
.descriptorType = cast(gfxBinding.descriptorType),
.descriptorCount = gfxBinding.descriptorCount,
.stageFlags = gfxBinding.shaderStages,
.pImmutableSamplers = nullptr,
});
bindingFlags.add(gfxBinding.bindingFlags);
}
}
VkDescriptorSetLayoutBindingFlagsCreateInfo bindingFlagsInfo = {
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_BINDING_FLAGS_CREATE_INFO,
@@ -165,38 +193,19 @@ DescriptorSet::DescriptorSet(PGraphics graphics, PDescriptorPool owner)
for (uint32 i = 0; i < boundResources.size(); ++i) {
boundResources[i].resize(owner->getLayout()->getBindings()[i].descriptorCount);
}
constantData.resize(owner->getLayout()->constantsSize);
}
DescriptorSet::~DescriptorSet() {}
void DescriptorSet::updateBuffer(uint32_t binding, uint32 index, Gfx::PUniformBuffer uniformBuffer) {
PUniformBuffer vulkanBuffer = uniformBuffer.cast<UniformBuffer>();
if (boundResources[binding][index] == vulkanBuffer->getAlloc() || vulkanBuffer->getAlloc() == nullptr) {
return;
}
bufferInfos.add(VkDescriptorBufferInfo{
.buffer = vulkanBuffer->getHandle(),
.offset = 0,
.range = vulkanBuffer->getSize(),
});
writeDescriptors.add(VkWriteDescriptorSet{
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
.pNext = nullptr,
.dstSet = setHandle,
.dstBinding = binding,
.dstArrayElement = index,
.descriptorCount = 1,
.descriptorType = cast(layout->getBindings()[binding].descriptorType),
.pBufferInfo = &bufferInfos.back(),
});
boundResources[binding][index] = vulkanBuffer->getAlloc();
void DescriptorSet::updateConstants(const std::string& name, uint32 offset, void* data) {
std::memcpy(constantData.data() + owner->getLayout()->mappings[name].constantOffset, (char*)data + offset,
owner->getLayout()->mappings[name].constantSize);
}
void DescriptorSet::updateBuffer(uint32_t binding, uint32 index, Gfx::PShaderBuffer shaderBuffer) {
void DescriptorSet::updateBuffer(const std::string& name, uint32 index, Gfx::PShaderBuffer shaderBuffer) {
PShaderBuffer vulkanBuffer = shaderBuffer.cast<ShaderBuffer>();
uint32 binding = owner->getLayout()->mappings[name].binding;
if (boundResources[binding][index] == vulkanBuffer->getAlloc() || vulkanBuffer->getAlloc() == nullptr) {
return;
}
@@ -220,8 +229,9 @@ void DescriptorSet::updateBuffer(uint32_t binding, uint32 index, Gfx::PShaderBuf
boundResources[binding][index] = vulkanBuffer->getAlloc();
}
void DescriptorSet::updateBuffer(uint32_t binding, uint32 index, Gfx::PVertexBuffer indexBuffer) {
void DescriptorSet::updateBuffer(const std::string& name, uint32 index, Gfx::PVertexBuffer indexBuffer) {
PVertexBuffer vulkanBuffer = indexBuffer.cast<VertexBuffer>();
uint32 binding = owner->getLayout()->mappings[name].binding;
if (boundResources[binding][index] == vulkanBuffer->getAlloc() || vulkanBuffer->getAlloc() == nullptr) {
return;
}
@@ -245,8 +255,9 @@ void DescriptorSet::updateBuffer(uint32_t binding, uint32 index, Gfx::PVertexBuf
boundResources[binding][index] = vulkanBuffer->getAlloc();
}
void DescriptorSet::updateBuffer(uint32_t binding, uint32 index, Gfx::PIndexBuffer indexBuffer) {
void DescriptorSet::updateBuffer(const std::string& name, uint32 index, Gfx::PIndexBuffer indexBuffer) {
PIndexBuffer vulkanBuffer = indexBuffer.cast<IndexBuffer>();
uint32 binding = owner->getLayout()->mappings[name].binding;
if (boundResources[binding][index] == vulkanBuffer->getAlloc() || vulkanBuffer->getAlloc() == nullptr) {
return;
}
@@ -270,8 +281,9 @@ void DescriptorSet::updateBuffer(uint32_t binding, uint32 index, Gfx::PIndexBuff
boundResources[binding][index] = vulkanBuffer->getAlloc();
}
void DescriptorSet::updateSampler(uint32_t binding, uint32 index, Gfx::PSampler samplerState) {
void DescriptorSet::updateSampler(const std::string& name, uint32 index, Gfx::PSampler samplerState) {
PSampler vulkanSampler = samplerState.cast<Sampler>();
uint32 binding = owner->getLayout()->mappings[name].binding;
if (boundResources[binding][index] == vulkanSampler->getHandle()) {
return;
}
@@ -296,8 +308,9 @@ void DescriptorSet::updateSampler(uint32_t binding, uint32 index, Gfx::PSampler
boundResources[binding][index] = vulkanSampler->getHandle();
}
void DescriptorSet::updateTexture(uint32_t binding, uint32 index, Gfx::PTexture2D texture) {
void DescriptorSet::updateTexture(const std::string& name, uint32 index, Gfx::PTexture2D texture) {
TextureBase* vulkanTexture = texture.cast<TextureBase>().getHandle();
uint32 binding = owner->getLayout()->mappings[name].binding;
if (boundResources[binding][index] == vulkanTexture->getHandle()) {
return;
}
@@ -322,8 +335,9 @@ void DescriptorSet::updateTexture(uint32_t binding, uint32 index, Gfx::PTexture2
boundResources[binding][index] = vulkanTexture->getHandle();
}
void DescriptorSet::updateTexture(uint32_t binding, uint32 index, Gfx::PTexture3D texture) {
void DescriptorSet::updateTexture(const std::string& name, uint32 index, Gfx::PTexture3D texture) {
TextureBase* vulkanTexture = texture.cast<TextureBase>().getHandle();
uint32 binding = owner->getLayout()->mappings[name].binding;
if (boundResources[binding][index] == vulkanTexture->getHandle()) {
return;
}
@@ -348,8 +362,9 @@ void DescriptorSet::updateTexture(uint32_t binding, uint32 index, Gfx::PTexture3
boundResources[binding][index] = vulkanTexture->getHandle();
}
void DescriptorSet::updateTexture(uint32_t binding, uint32 index, Gfx::PTextureCube texture) {
void DescriptorSet::updateTexture(const std::string& name, uint32 index, Gfx::PTextureCube texture) {
TextureBase* vulkanTexture = texture.cast<TextureBase>().getHandle();
uint32 binding = owner->getLayout()->mappings[name].binding;
if (boundResources[binding][index] == vulkanTexture->getHandle()) {
return;
}
@@ -374,8 +389,9 @@ void DescriptorSet::updateTexture(uint32_t binding, uint32 index, Gfx::PTextureC
boundResources[binding][index] = vulkanTexture->getHandle();
}
void DescriptorSet::updateAccelerationStructure(uint32 binding, uint32 index, Gfx::PTopLevelAS as) {
void DescriptorSet::updateAccelerationStructure(const std::string& name, uint32 index, Gfx::PTopLevelAS as) {
auto tlas = as.cast<TopLevelAS>();
uint32 binding = owner->getLayout()->mappings[name].binding;
accelerationInfos.add(VkWriteDescriptorSetAccelerationStructureKHR{
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET_ACCELERATION_STRUCTURE_KHR,
.pNext = nullptr,
@@ -404,6 +420,16 @@ void DescriptorSet::writeChanges() {
imageInfos.clear();
bufferInfos.clear();
}
constantsBuffer = graphics->createUniformBuffer(UniformBufferCreateInfo{
.sourceData =
{
.size = constantData.size(),
.data = constantData.data(),
},
.name = owner->getLayout()->getName(),
});
constantsBuffer->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT,
Gfx::SE_ACCESS_UNIFORM_READ_BIT, Gfx::SE_PIPELINE_STAGE_ALL_COMMANDS_BIT);
}
PipelineLayout::PipelineLayout(PGraphics graphics, const std::string& name, Gfx::PPipelineLayout baseLayout)
+23 -9
View File
@@ -2,11 +2,18 @@
#include "Containers/List.h"
#include "Enums.h"
#include "Graphics/Descriptor.h"
#include "Graphics/Vulkan/Buffer.h"
#include "Resources.h"
namespace Seele {
namespace Vulkan {
DECLARE_REF(Graphics)
struct DescriptorMapping
{
uint32 binding;
uint32 constantOffset;
uint32 constantSize;
};
class DescriptorLayout : public Gfx::DescriptorLayout {
public:
DescriptorLayout(PGraphics graphics, const std::string& name);
@@ -16,9 +23,13 @@ class DescriptorLayout : public Gfx::DescriptorLayout {
private:
PGraphics graphics;
uint32 constantsSize;
VkShaderStageFlags constantsStages;
Array<VkDescriptorSetLayoutBinding> bindings;
Map<std::string, DescriptorMapping> mappings;
VkDescriptorSetLayout layoutHandle;
friend class DescriptorPool;
friend class DescriptorSet;
};
DEFINE_REF(DescriptorLayout)
@@ -48,19 +59,22 @@ class DescriptorSet : public Gfx::DescriptorSet, public CommandBoundResource {
DescriptorSet(PGraphics graphics, PDescriptorPool owner);
virtual ~DescriptorSet();
virtual void writeChanges() override;
virtual void updateBuffer(uint32 binding, uint32 index, Gfx::PUniformBuffer uniformBuffer) override;
virtual void updateBuffer(uint32 binding, uint32 index, Gfx::PShaderBuffer shaderBuffer) override;
virtual void updateBuffer(uint32 binding, uint32 index, Gfx::PVertexBuffer indexBuffer) override;
virtual void updateBuffer(uint32 binding, uint32 index, Gfx::PIndexBuffer indexBuffer) override;
virtual void updateSampler(uint32 binding, uint32 index, Gfx::PSampler samplerState) override;
virtual void updateTexture(uint32 binding, uint32 index, Gfx::PTexture2D texture) override;
virtual void updateTexture(uint32 binding, uint32 index, Gfx::PTexture3D texture) override;
virtual void updateTexture(uint32 binding, uint32 index, Gfx::PTextureCube texture) override;
virtual void updateAccelerationStructure(uint32 binding, uint32 index, Gfx::PTopLevelAS as) override;
virtual void updateConstants(const std::string& name, uint32 offset, void* data) override;
virtual void updateBuffer(const std::string& name, uint32 index, Gfx::PShaderBuffer shaderBuffer) override;
virtual void updateBuffer(const std::string& name, uint32 index, Gfx::PVertexBuffer indexBuffer) override;
virtual void updateBuffer(const std::string& name, uint32 index, Gfx::PIndexBuffer indexBuffer) override;
virtual void updateSampler(const std::string& name, uint32 index, Gfx::PSampler samplerState) override;
virtual void updateTexture(const std::string& name, uint32 index, Gfx::PTexture2D texture) override;
virtual void updateTexture(const std::string& name, uint32 index, Gfx::PTexture3D texture) override;
virtual void updateTexture(const std::string& name, uint32 index, Gfx::PTextureCube texture) override;
virtual void updateAccelerationStructure(const std::string& name, uint32 index, Gfx::PTopLevelAS as) override;
constexpr VkDescriptorSet getHandle() const { return setHandle; }
private:
std::vector<uint8> constantData;
Gfx::OUniformBuffer constantsBuffer;
VkShaderStageFlags constantsStageFlags;
List<VkDescriptorImageInfo> imageInfos;
List<VkDescriptorBufferInfo> bufferInfos;
List<VkWriteDescriptorSetAccelerationStructureKHR> accelerationInfos;
+2 -1
View File
@@ -9,6 +9,7 @@ class Window {
public:
Window();
virtual ~Window();
virtual void show() = 0;
virtual void pollInput() = 0;
virtual void beginFrame() = 0;
virtual void endFrame() = 0;
@@ -66,4 +67,4 @@ class Viewport {
DEFINE_REF(Viewport)
} // namespace Gfx
} // namespace Seele
} // namespace Seele
+8 -8
View File
@@ -34,14 +34,14 @@ void Seele::beginCompilation(const ShaderCompilationInfo& info, SlangCompileTarg
slang::SessionDesc sessionDesc;
sessionDesc.flags = 0;
Array<slang::CompilerOptionEntry> option = {
//{
// .name = slang::CompilerOptionName::Capability,
// .value =
// {
// .kind = slang::CompilerOptionValueKind::Int,
// .intValue0 = globalSession->findCapability("GLSL_450"),
// },
//},
{
.name = slang::CompilerOptionName::LineDirectiveMode,
.value =
{
.kind = slang::CompilerOptionValueKind::Int,
.intValue0 = SLANG_LINE_DIRECTIVE_MODE_NONE,
},
},
{
.name = slang::CompilerOptionName::EmitSpirvViaGLSL,
.value =
+7 -6
View File
@@ -36,21 +36,22 @@ Material::~Material() {}
void Material::init(Gfx::PGraphics graphics) {
layout = graphics->createDescriptorLayout("pResources");
layout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 0,
.name = "textures",
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
.descriptorCount = 512,
.bindingFlags = Gfx::SE_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT,
.shaderStages = Gfx::SE_SHADER_STAGE_FRAGMENT_BIT | Gfx::SE_SHADER_STAGE_CLOSEST_HIT_BIT_KHR,
.access = Gfx::SE_DESCRIPTOR_ACCESS_SAMPLE_BIT,
});
layout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 1,
.name = "samplers",
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLER,
.descriptorCount = 512,
.bindingFlags = Gfx::SE_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT,
.shaderStages = Gfx::SE_SHADER_STAGE_FRAGMENT_BIT | Gfx::SE_SHADER_STAGE_CLOSEST_HIT_BIT_KHR,
});
layout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 2,
.name = "floats",
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
.descriptorCount = 1,
.bindingFlags = Gfx::SE_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT,
@@ -77,15 +78,15 @@ void Material::updateDescriptor() {
set = layout->allocateDescriptorSet();
for (uint32 i = 0; i < textures.size(); ++i) {
if (textures[i] != nullptr) {
set->updateTexture(0, i, textures[i]);
set->updateTexture("textures", i, textures[i]);
}
}
for (uint32 i = 0; i < samplers.size(); ++i) {
if (samplers[i] != nullptr) {
set->updateSampler(1, i, samplers[i]);
set->updateSampler("samplers", i, samplers[i]);
}
}
set->updateBuffer(2, 0, floatBuffer);
set->updateBuffer("floats", 0, floatBuffer);
set->writeChanges();
}
+17 -20
View File
@@ -6,22 +6,23 @@ using namespace Seele;
LightEnvironment::LightEnvironment(Gfx::PGraphics graphics) : graphics(graphics) {
layout = graphics->createDescriptorLayout("pLightEnv");
layout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 0,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
.uniformLength = 24,//sizeof(LightEnv)
});
layout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 1,
.name = "directionalLights",
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
});
layout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 2,
.name = "numDirectionalLights",
.uniformLength = sizeof(uint)
});
layout->addDescriptorBinding(Gfx::DescriptorBinding{
.name = "pointLights",
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
});
layout->addDescriptorBinding(Gfx::DescriptorBinding{
.name = "numPointLights",
.uniformLength = sizeof(uint)
});
layout->create();
lightEnvBuffer = graphics->createUniformBuffer(UniformBufferCreateInfo{
.name = "LightEnv",
});
directionalLights = graphics->createShaderBuffer(ShaderBufferCreateInfo{
.name = "DirectionalLights",
});
@@ -44,13 +45,6 @@ void LightEnvironment::addDirectionalLight(Component::DirectionalLight dirLight)
void LightEnvironment::addPointLight(Component::PointLight pointLight) { points.add(pointLight); }
void LightEnvironment::commit() {
lightEnv.numDirectionalLights = dirs.size();
lightEnv.numPointLights = points.size();
lightEnvBuffer->updateContents(0, sizeof(LightEnv), &lightEnv);
lightEnvBuffer->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT,
Gfx::SE_ACCESS_UNIFORM_READ_BIT | Gfx::SE_ACCESS_TRANSFER_WRITE_BIT,
Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT | Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT |
Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT);
directionalLights->rotateBuffer(sizeof(Component::DirectionalLight) * dirs.size());
directionalLights->updateContents(0, sizeof(Component::DirectionalLight) * dirs.size(), dirs.data());
directionalLights->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT,
@@ -63,9 +57,12 @@ void LightEnvironment::commit() {
Gfx::SE_ACCESS_SHADER_READ_BIT | Gfx::SE_ACCESS_TRANSFER_WRITE_BIT,
Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT | Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT |
Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT);
set->updateBuffer(0, 0, lightEnvBuffer);
set->updateBuffer(1, 0, directionalLights);
set->updateBuffer(2, 0, pointLights);
uint32 numPointLights = points.size();
uint32 numDirectionalLights = dirs.size();
set->updateConstants("numPointLights", 0, &numPointLights);
set->updateBuffer("pointLights", 0, pointLights);
set->updateConstants("numDirectionalLights", 0, &numDirectionalLights);
set->updateBuffer("directionalLights", 0, directionalLights);
set->writeChanges();
}
-5
View File
@@ -18,12 +18,7 @@ class LightEnvironment {
Gfx::PDescriptorSet getDescriptorSet();
private:
struct LightEnv {
uint32 numDirectionalLights;
uint32 numPointLights;
} lightEnv;
Gfx::OShaderBuffer directionalLights;
Gfx::OUniformBuffer lightEnvBuffer;
Gfx::OShaderBuffer pointLights;
Array<Component::DirectionalLight> dirs;
Array<Component::PointLight> points;
+2 -1
View File
@@ -9,6 +9,7 @@ class Window {
public:
Window(PWindowManager owner, Gfx::OWindow handle);
~Window();
void show() { gfxHandle->show(); }
void addView(PView view);
void pollInputs();
void render();
@@ -23,4 +24,4 @@ class Window {
Gfx::OWindow gfxHandle;
};
DEFINE_REF(Window)
} // namespace Seele
} // namespace Seele