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