Trying to fix memory usage, made it worse and nothing works

This commit is contained in:
Dynamitos
2024-08-08 22:14:25 +02:00
parent 3f8ce3a25e
commit ac72377210
13 changed files with 172 additions and 284 deletions
+6 -4
View File
@@ -24,7 +24,7 @@ class VertexBuffer : public Buffer {
// Size of one vertex in bytes // Size of one vertex in bytes
constexpr uint32 getVertexSize() const { return vertexSize; } constexpr uint32 getVertexSize() const { return vertexSize; }
virtual void updateRegion(DataSource update) = 0; virtual void updateRegion(uint64 offset, uint64 size, void* data) = 0;
virtual void download(Array<uint8>& buffer) = 0; virtual void download(Array<uint8>& buffer) = 0;
protected: protected:
@@ -63,7 +63,7 @@ class UniformBuffer : public Buffer {
virtual ~UniformBuffer(); virtual ~UniformBuffer();
virtual void rotateBuffer(uint64 size) = 0; virtual void rotateBuffer(uint64 size) = 0;
virtual void updateContents(const DataSource& sourceData) = 0; virtual void updateContents(uint64 offset, uint64 size, void* data) = 0;
protected: protected:
// Inherited via QueueOwnedResource // Inherited via QueueOwnedResource
@@ -76,9 +76,11 @@ class ShaderBuffer : public Buffer {
public: public:
ShaderBuffer(QueueFamilyMapping mapping, const ShaderBufferCreateInfo& createInfo); ShaderBuffer(QueueFamilyMapping mapping, const ShaderBufferCreateInfo& createInfo);
virtual ~ShaderBuffer(); virtual ~ShaderBuffer();
virtual void readContents(Array<uint8>& data) = 0; virtual void readContents(uint64 offset, uint64 size, void* data) = 0;
virtual void rotateBuffer(uint64 size, bool preserveContents = false) = 0; virtual void rotateBuffer(uint64 size, bool preserveContents = false) = 0;
virtual void updateContents(const ShaderBufferCreateInfo& sourceData) = 0; virtual void updateContents(uint64 offset, uint64 size, void* data) = 0;
virtual void* map() = 0;
virtual void unmap() = 0;
constexpr uint32 getNumElements() const { return numElements; } constexpr uint32 getNumElements() const { return numElements; }
virtual void clear() = 0; virtual void clear() = 0;
+1 -4
View File
@@ -116,10 +116,7 @@ void BasePass::beginFrame(const Component::Camera& cam) {
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->rotateBuffer(sizeof(SkyboxData));
skyboxBuffer->updateContents(DataSource{ skyboxBuffer->updateContents(0, sizeof(SkyboxData), &skyboxData);
.size = sizeof(SkyboxData),
.data = (uint8*)&skyboxData,
});
skyboxBuffer->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT, Gfx::SE_ACCESS_UNIFORM_READ_BIT, 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); Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
skyboxDataSet = skyboxDataLayout->allocateDescriptorSet(); skyboxDataSet = skyboxDataLayout->allocateDescriptorSet();
@@ -22,18 +22,10 @@ void LightCullingPass::beginFrame(const Component::Camera& cam) {
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, Gfx::SE_ACCESS_MEMORY_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, Gfx::SE_ACCESS_MEMORY_WRITE_BIT,
Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT); Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT);
uint32 reset = 0; uint32 reset = 0;
ShaderBufferCreateInfo counterReset = {
.sourceData =
{
.size = sizeof(uint32),
.data = (uint8*)&reset,
.owner = Gfx::QueueType::COMPUTE,
},
};
oLightIndexCounter->rotateBuffer(sizeof(uint32)); oLightIndexCounter->rotateBuffer(sizeof(uint32));
oLightIndexCounter->updateContents(counterReset); oLightIndexCounter->updateContents(0, sizeof(uint32), &reset);
tLightIndexCounter->rotateBuffer(sizeof(uint32)); tLightIndexCounter->rotateBuffer(sizeof(uint32));
tLightIndexCounter->updateContents(counterReset); tLightIndexCounter->updateContents(0, sizeof(uint32), &reset);
oLightIndexCounter->pipelineBarrier(Gfx::SE_ACCESS_MEMORY_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT, oLightIndexCounter->pipelineBarrier(Gfx::SE_ACCESS_MEMORY_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT,
Gfx::SE_ACCESS_MEMORY_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); Gfx::SE_ACCESS_MEMORY_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
tLightIndexCounter->pipelineBarrier(Gfx::SE_ACCESS_MEMORY_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT, tLightIndexCounter->pipelineBarrier(Gfx::SE_ACCESS_MEMORY_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT,
@@ -32,12 +32,8 @@ void RenderPass::beginFrame(const Component::Camera& cam) {
.cameraPosition = Vector4(cam.getCameraPosition(), 1), .cameraPosition = Vector4(cam.getCameraPosition(), 1),
.screenDimensions = Vector2(static_cast<float>(viewport->getWidth()), static_cast<float>(viewport->getHeight())), .screenDimensions = Vector2(static_cast<float>(viewport->getWidth()), static_cast<float>(viewport->getHeight())),
}; };
DataSource uniformUpdate = {
.size = sizeof(ViewParameter),
.data = (uint8*)&viewParams,
};
viewParamsBuffer->rotateBuffer(sizeof(ViewParameter)); viewParamsBuffer->rotateBuffer(sizeof(ViewParameter));
viewParamsBuffer->updateContents(uniformUpdate); viewParamsBuffer->updateContents(0, sizeof(ViewParameter), &viewParams);
viewParamsBuffer->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT, 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_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_TASK_SHADER_BIT_EXT | Gfx::SE_PIPELINE_STAGE_MESH_SHADER_BIT_EXT |
+1 -5
View File
@@ -53,11 +53,7 @@ void TextPass::beginFrame(const Component::Camera& cam) {
}; };
} }
auto proj = viewport->getProjectionMatrix(); auto proj = viewport->getProjectionMatrix();
DataSource projectionUpdate = { projectionBuffer->updateContents(0, sizeof(Matrix4), &proj);
.size = sizeof(Matrix4),
.data = (uint8*)&proj,
};
projectionBuffer->updateContents(projectionUpdate);
generalSet->updateBuffer(1, projectionBuffer); generalSet->updateBuffer(1, projectionBuffer);
generalSet->writeChanges(); generalSet->writeChanges();
// co_return; // co_return;
+1 -4
View File
@@ -20,10 +20,7 @@ void UIPass::beginFrame(const Component::Camera& cam) {
}; };
elementBuffer = graphics->createVertexBuffer(info); elementBuffer = graphics->createVertexBuffer(info);
uint32 numTextures = static_cast<uint32>(usedTextures.size()); uint32 numTextures = static_cast<uint32>(usedTextures.size());
numTexturesBuffer->updateContents({ numTexturesBuffer->updateContents(0, sizeof(uint32), &numTextures);
.size = sizeof(uint32),
.data = (uint8*)&numTextures,
});
descriptorSet->updateBuffer(2, numTexturesBuffer); descriptorSet->updateBuffer(2, numTexturesBuffer);
descriptorSet->updateTextureArray(3, usedTextures); descriptorSet->updateTextureArray(3, usedTextures);
descriptorSet->writeChanges(); descriptorSet->writeChanges();
+72 -162
View File
@@ -18,56 +18,44 @@ StaticMeshVertexData* StaticMeshVertexData::getInstance() {
} }
void StaticMeshVertexData::loadPositions(uint64 offset, const Array<Vector4>& data) { void StaticMeshVertexData::loadPositions(uint64 offset, const Array<Vector4>& data) {
if (swappedOut) {
swapIn();
}
assert(offset + data.size() <= head); assert(offset + data.size() <= head);
std::memcpy(positionData.data() + offset, data.data(), data.size() * sizeof(Vector4)); std::memcpy((Vector4*)positions->map() + offset, data.data(), data.size() * sizeof(Vector4));
//positions->updateContents(offset * sizeof(Vector4), data.size() * sizeof(Vector4), data.data());
dirty = true; dirty = true;
} }
void StaticMeshVertexData::loadTexCoords(uint64 offset, uint64 index, const Array<Vector2>& data) { void StaticMeshVertexData::loadTexCoords(uint64 offset, uint64 index, const Array<Vector2>& data) {
if (swappedOut) {
swapIn();
}
assert(offset + data.size() <= head); assert(offset + data.size() <= head);
std::memcpy(texCoordsData[index].data() + offset, data.data(), data.size() * sizeof(Vector2)); std::memcpy((Vector2*)texCoords[index]->map() + offset, data.data(), data.size() * sizeof(Vector2));
//texCoords[index]->updateContents(offset * sizeof(Vector2), data.size() * sizeof(Vector2), data.data());
dirty = true; dirty = true;
} }
void StaticMeshVertexData::loadNormals(uint64 offset, const Array<Vector4>& data) { void StaticMeshVertexData::loadNormals(uint64 offset, const Array<Vector4>& data) {
if (swappedOut) {
swapIn();
}
assert(offset + data.size() <= head); assert(offset + data.size() <= head);
std::memcpy(normalData.data() + offset, data.data(), data.size() * sizeof(Vector4)); std::memcpy((Vector4*)normals->map() + offset, data.data(), data.size() * sizeof(Vector4));
// normals->updateContents(offset * sizeof(Vector4), data.size() * sizeof(Vector4), data.data());
dirty = true; dirty = true;
} }
void StaticMeshVertexData::loadTangents(uint64 offset, const Array<Vector4>& data) { void StaticMeshVertexData::loadTangents(uint64 offset, const Array<Vector4>& data) {
if (swappedOut) {
swapIn();
}
assert(offset + data.size() <= head); assert(offset + data.size() <= head);
std::memcpy(tangentData.data() + offset, data.data(), data.size() * sizeof(Vector4)); std::memcpy((Vector4*)tangents->map() + offset, data.data(), data.size() * sizeof(Vector4));
//tangents->updateContents(offset * sizeof(Vector4), data.size() * sizeof(Vector4), data.data());
dirty = true; dirty = true;
} }
void StaticMeshVertexData::loadBiTangents(uint64 offset, const Array<Vector4>& data) { void StaticMeshVertexData::loadBiTangents(uint64 offset, const Array<Vector4>& data) {
if (swappedOut) {
swapIn();
}
assert(offset + data.size() <= head); assert(offset + data.size() <= head);
std::memcpy(biTangentData.data() + offset, data.data(), data.size() * sizeof(Vector4)); std::memcpy((Vector4*)biTangents->map() + offset, data.data(), data.size() * sizeof(Vector4));
// biTangents->updateContents(offset * sizeof(Vector4), data.size() * sizeof(Vector4), data.data());
dirty = true; dirty = true;
} }
void Seele::StaticMeshVertexData::loadColors(uint64 offset, const Array<Vector4>& data) { void StaticMeshVertexData::loadColors(uint64 offset, const Array<Vector4>& data) {
if (swappedOut) {
swapIn();
}
assert(offset + data.size() <= head); assert(offset + data.size() <= head);
std::memcpy(colorData.data() + offset, data.data(), data.size() * sizeof(Vector4)); std::memcpy((Vector4*)colors->map() + offset, data.data(), data.size() * sizeof(Vector4));
//colors->updateContents(offset * sizeof(Vector4), data.size() * sizeof(Vector4), data.data());
dirty = true; dirty = true;
} }
@@ -82,18 +70,18 @@ void StaticMeshVertexData::serializeMesh(MeshId id, uint64 numVertices, ArchiveB
Array<Vector2> tex[MAX_TEXCOORDS]; Array<Vector2> tex[MAX_TEXCOORDS];
for (size_t i = 0; i < MAX_TEXCOORDS; ++i) { for (size_t i = 0; i < MAX_TEXCOORDS; ++i) {
tex[i].resize(numVertices); tex[i].resize(numVertices);
std::memcpy(tex[i].data(), texCoordsData[i].data() + offset, numVertices * sizeof(Vector2)); texCoords[i]->readContents(offset * sizeof(Vector2), numVertices * sizeof(Vector2), tex[i].data());
Serialization::save(buffer, tex[i]); Serialization::save(buffer, tex[i]);
} }
Array<Vector4> nor(numVertices); Array<Vector4> nor(numVertices);
Array<Vector4> tan(numVertices); Array<Vector4> tan(numVertices);
Array<Vector4> bit(numVertices); Array<Vector4> bit(numVertices);
Array<Vector4> col(numVertices); Array<Vector4> col(numVertices);
std::memcpy(pos.data(), positionData.data() + offset, numVertices * sizeof(Vector4)); positions->readContents(offset * sizeof(Vector4), numVertices * sizeof(Vector4), pos.data());
std::memcpy(nor.data(), normalData.data() + offset, numVertices * sizeof(Vector4)); normals->readContents(offset * sizeof(Vector4), numVertices * sizeof(Vector4), nor.data());
std::memcpy(tan.data(), tangentData.data() + offset, numVertices * sizeof(Vector4)); tangents->readContents(offset * sizeof(Vector4), numVertices * sizeof(Vector4), tan.data());
std::memcpy(bit.data(), biTangentData.data() + offset, numVertices * sizeof(Vector4)); biTangents->readContents(offset * sizeof(Vector4), numVertices * sizeof(Vector4), bit.data());
std::memcpy(col.data(), colorData.data() + offset, numVertices * sizeof(Vector4)); colors->readContents(offset * sizeof(Vector4), numVertices * sizeof(Vector4), col.data());
Serialization::save(buffer, pos); Serialization::save(buffer, pos);
Serialization::save(buffer, nor); Serialization::save(buffer, nor);
Serialization::save(buffer, tan); Serialization::save(buffer, tan);
@@ -108,13 +96,13 @@ uint64 StaticMeshVertexData::deserializeMesh(MeshId id, ArchiveBuffer& buffer) {
std::unique_lock l(vertexDataLock); std::unique_lock l(vertexDataLock);
offset = meshOffsets[id]; offset = meshOffsets[id];
} }
Array<Vector4> pos;
Array<Vector2> tex[MAX_TEXCOORDS]; Array<Vector2> tex[MAX_TEXCOORDS];
for (size_t i = 0; i < MAX_TEXCOORDS; ++i) { for (size_t i = 0; i < MAX_TEXCOORDS; ++i) {
Serialization::load(buffer, tex[i]); Serialization::load(buffer, tex[i]);
loadTexCoords(offset, i, tex[i]); loadTexCoords(offset, i, tex[i]);
result += tex[i].size() * sizeof(Vector2); result += tex[i].size() * sizeof(Vector2);
} }
Array<Vector4> pos;
Array<Vector4> nor; Array<Vector4> nor;
Array<Vector4> tan; Array<Vector4> tan;
Array<Vector4> bit; Array<Vector4> bit;
@@ -139,51 +127,13 @@ uint64 StaticMeshVertexData::deserializeMesh(MeshId id, ArchiveBuffer& buffer) {
void StaticMeshVertexData::init(Gfx::PGraphics _graphics) { void StaticMeshVertexData::init(Gfx::PGraphics _graphics) {
VertexData::init(_graphics); VertexData::init(_graphics);
descriptorLayout = _graphics->createDescriptorLayout("pVertexData");
descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 0, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER});
descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 1, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER});
descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 2, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER});
descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 3, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER});
descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 4, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER});
descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 5,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
.descriptorCount = MAX_TEXCOORDS,
});
descriptorLayout->create();
descriptorSet = descriptorLayout->allocateDescriptorSet();
}
void StaticMeshVertexData::destroy() {
VertexData::destroy();
positions = nullptr;
for (size_t i = 0; i < MAX_TEXCOORDS; ++i) {
texCoords[i] = nullptr;
}
normals = nullptr;
tangents = nullptr;
biTangents = nullptr;
colors = nullptr;
descriptorSet = nullptr;
descriptorLayout = nullptr;
}
void StaticMeshVertexData::bindBuffers(Gfx::PRenderCommand) {
// TODO: for legacy vertex buffer binding
}
Gfx::PDescriptorLayout StaticMeshVertexData::getVertexDataLayout() { return descriptorLayout; }
Gfx::PDescriptorSet StaticMeshVertexData::getVertexDataSet() { return descriptorSet; }
void StaticMeshVertexData::resizeBuffers() {
ShaderBufferCreateInfo createInfo = { ShaderBufferCreateInfo createInfo = {
.sourceData = .sourceData =
{ {
.size = verticesAllocated * sizeof(Vector4), .size = verticesAllocated * sizeof(Vector4),
}, },
.numElements = verticesAllocated, .numElements = verticesAllocated,
.dynamic = false, .dynamic = true,
.vertexBuffer = true, .vertexBuffer = true,
.name = "Positions", .name = "Positions",
}; };
@@ -201,68 +151,64 @@ void StaticMeshVertexData::resizeBuffers() {
createInfo.name = "TexCoords"; createInfo.name = "TexCoords";
for (size_t i = 0; i < MAX_TEXCOORDS; ++i) { for (size_t i = 0; i < MAX_TEXCOORDS; ++i) {
texCoords[i] = graphics->createShaderBuffer(createInfo); texCoords[i] = graphics->createShaderBuffer(createInfo);
texCoordsData[i].resize(verticesAllocated);
} }
descriptorLayout = _graphics->createDescriptorLayout("pVertexData");
descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 0, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER});
descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 1, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER});
descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 2, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER});
descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 3, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER});
descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 4, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER});
descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 5,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
.descriptorCount = MAX_TEXCOORDS,
});
descriptorLayout->create();
descriptorSet = descriptorLayout->allocateDescriptorSet();
}
positionData.resize(verticesAllocated); void StaticMeshVertexData::destroy() {
normalData.resize(verticesAllocated); VertexData::destroy();
tangentData.resize(verticesAllocated); for (size_t i = 0; i < MAX_TEXCOORDS; ++i) {
biTangentData.resize(verticesAllocated); texCoords[i] = nullptr;
colorData.resize(verticesAllocated); }
positions = nullptr;
normals = nullptr;
tangents = nullptr;
biTangents = nullptr;
colors = nullptr;
descriptorSet = nullptr;
descriptorLayout = nullptr;
}
void StaticMeshVertexData::bindBuffers(Gfx::PRenderCommand) {
// TODO: for legacy vertex buffer binding
}
Gfx::PDescriptorLayout StaticMeshVertexData::getVertexDataLayout() { return descriptorLayout; }
Gfx::PDescriptorSet StaticMeshVertexData::getVertexDataSet() { return descriptorSet; }
void StaticMeshVertexData::resizeBuffers() {
positions->rotateBuffer(verticesAllocated * sizeof(Vector4), true);
normals->rotateBuffer(verticesAllocated * sizeof(Vector4), true);
tangents->rotateBuffer(verticesAllocated * sizeof(Vector4), true);
biTangents->rotateBuffer(verticesAllocated * sizeof(Vector4), true);
colors->rotateBuffer(verticesAllocated * sizeof(Vector4), true);
for (size_t i = 0; i < MAX_TEXCOORDS; ++i) {
texCoords[i]->rotateBuffer(verticesAllocated * sizeof(Vector2), true);
}
} }
void StaticMeshVertexData::updateBuffers() { void StaticMeshVertexData::updateBuffers() {
positions->updateContents(ShaderBufferCreateInfo{ positions->unmap();
.sourceData{ normals->unmap();
.size = positionData.size() * sizeof(Vector4), tangents->unmap();
.data = (uint8*)positionData.data(), biTangents->unmap();
}, colors->unmap();
.numElements = positionData.size(),
});
for (size_t i = 0; i < MAX_TEXCOORDS; ++i) { for (size_t i = 0; i < MAX_TEXCOORDS; ++i) {
texCoords[i]->updateContents(ShaderBufferCreateInfo{ texCoords[i]->unmap();
.sourceData =
{
.size = texCoordsData[i].size() * sizeof(Vector2),
.data = (uint8*)texCoordsData[i].data(),
},
.numElements = texCoordsData[i].size(),
});
} }
normals->updateContents(ShaderBufferCreateInfo{
.sourceData =
{
.size = normalData.size() * sizeof(Vector4),
.data = (uint8*)normalData.data(),
},
.numElements = normalData.size(),
});
tangents->updateContents(ShaderBufferCreateInfo{
.sourceData =
{
.size = tangentData.size() * sizeof(Vector4),
.data = (uint8*)tangentData.data(),
},
.numElements = tangentData.size(),
});
biTangents->updateContents(ShaderBufferCreateInfo{
.sourceData =
{
.size = biTangentData.size() * sizeof(Vector4),
.data = (uint8*)biTangentData.data(),
},
.numElements = biTangentData.size(),
});
colors->updateContents(ShaderBufferCreateInfo{
.sourceData =
{
.size = colorData.size() * sizeof(Vector4),
.data = (uint8*)colorData.data(),
},
.numElements = colorData.size(),
});
// we just updated the GPU buffers, might not change that for a while
swapOut();
descriptorLayout->reset(); descriptorLayout->reset();
descriptorSet = descriptorLayout->allocateDescriptorSet(); descriptorSet = descriptorLayout->allocateDescriptorSet();
descriptorSet->updateBuffer(0, positions); descriptorSet->updateBuffer(0, positions);
@@ -275,39 +221,3 @@ void StaticMeshVertexData::updateBuffers() {
} }
descriptorSet->writeChanges(); descriptorSet->writeChanges();
} }
void StaticMeshVertexData::swapOut() {
ArchiveBuffer buf;
Serialization::save(buf, positionData);
positionData.clear();
Serialization::save(buf, normalData);
normalData.clear();
Serialization::save(buf, tangentData);
tangentData.clear();
Serialization::save(buf, biTangentData);
biTangentData.clear();
Serialization::save(buf, colorData);
colorData.clear();
for (size_t i = 0; i < MAX_TEXCOORDS; ++i) {
Serialization::save(buf, texCoordsData[i]);
texCoordsData[i].clear();
}
std::ofstream str("vertex", std::ios::binary);
buf.writeToStream(str);
swappedOut = true;
}
void StaticMeshVertexData::swapIn() {
ArchiveBuffer buf;
std::ifstream str("vertex", std::ios::binary);
buf.readFromStream(str);
Serialization::load(buf, positionData);
Serialization::load(buf, normalData);
Serialization::load(buf, tangentData);
Serialization::load(buf, biTangentData);
Serialization::load(buf, colorData);
for (size_t i = 0; i < MAX_TEXCOORDS; ++i) {
Serialization::load(buf, texCoordsData[i]);
}
swappedOut = false;
}
@@ -32,22 +32,12 @@ class StaticMeshVertexData : public VertexData {
virtual void resizeBuffers() override; virtual void resizeBuffers() override;
virtual void updateBuffers() override; virtual void updateBuffers() override;
void swapOut();
void swapIn();
Gfx::OShaderBuffer positions; Gfx::OShaderBuffer positions;
Array<Vector4> positionData;
Gfx::OShaderBuffer texCoords[MAX_TEXCOORDS]; Gfx::OShaderBuffer texCoords[MAX_TEXCOORDS];
Array<Vector2> texCoordsData[MAX_TEXCOORDS];
Gfx::OShaderBuffer normals; Gfx::OShaderBuffer normals;
Array<Vector4> normalData;
Gfx::OShaderBuffer tangents; Gfx::OShaderBuffer tangents;
Array<Vector4> tangentData;
Gfx::OShaderBuffer biTangents; Gfx::OShaderBuffer biTangents;
Array<Vector4> biTangentData;
Gfx::OShaderBuffer colors; Gfx::OShaderBuffer colors;
Array<Vector4> colorData;
bool swappedOut = false;
Gfx::ODescriptorLayout descriptorLayout; Gfx::ODescriptorLayout descriptorLayout;
Gfx::PDescriptorSet descriptorSet; Gfx::PDescriptorSet descriptorSet;
}; };
+7 -27
View File
@@ -7,10 +7,11 @@
#include "Graphics/Shader.h" #include "Graphics/Shader.h"
#include "Material/Material.h" #include "Material/Material.h"
#include "Material/MaterialInstance.h" #include "Material/MaterialInstance.h"
#include <iostream>
using namespace Seele; using namespace Seele;
constexpr static uint64 NUM_DEFAULT_ELEMENTS = 1024 * 1024; constexpr static uint64 NUM_DEFAULT_ELEMENTS = 1024 * 1024;// 17962284
Map<VertexData::MeshMapping, VertexData::CullingMapping> VertexData::instanceIdMap; Map<VertexData::MeshMapping, VertexData::CullingMapping> VertexData::instanceIdMap;
uint64 VertexData::instanceCount = 0; uint64 VertexData::instanceCount = 0;
uint64 VertexData::meshletCount = 0; uint64 VertexData::meshletCount = 0;
@@ -152,38 +153,17 @@ void VertexData::createDescriptors() {
rayTracingScene.add(transparentData[i].rayTracingScene); rayTracingScene.add(transparentData[i].rayTracingScene);
} }
cullingOffsetBuffer->rotateBuffer(cullingOffsets.size() * sizeof(uint32)); cullingOffsetBuffer->rotateBuffer(cullingOffsets.size() * sizeof(uint32));
cullingOffsetBuffer->updateContents(ShaderBufferCreateInfo{ cullingOffsetBuffer->updateContents(0, cullingOffsets.size() * sizeof(uint32), cullingOffsets.data());
.sourceData =
{
.size = cullingOffsets.size() * sizeof(uint32),
.data = (uint8*)cullingOffsets.data(),
},
.numElements = cullingOffsets.size(),
});
cullingOffsetBuffer->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT, cullingOffsetBuffer->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT,
Gfx::SE_ACCESS_MEMORY_READ_BIT, Gfx::SE_PIPELINE_STAGE_TOP_OF_PIPE_BIT); Gfx::SE_ACCESS_MEMORY_READ_BIT, Gfx::SE_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
instanceBuffer->rotateBuffer(instanceData.size() * sizeof(InstanceData)); instanceBuffer->rotateBuffer(instanceData.size() * sizeof(InstanceData));
instanceBuffer->updateContents(ShaderBufferCreateInfo{ instanceBuffer->updateContents(0, instanceData.size() * sizeof(InstanceData), instanceData.data());
.sourceData =
{
.size = instanceData.size() * sizeof(InstanceData),
.data = (uint8*)instanceData.data(),
},
.numElements = instanceData.size(),
});
instanceBuffer->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT, Gfx::SE_ACCESS_MEMORY_READ_BIT, instanceBuffer->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT, Gfx::SE_ACCESS_MEMORY_READ_BIT,
Gfx::SE_PIPELINE_STAGE_TOP_OF_PIPE_BIT); Gfx::SE_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
instanceMeshDataBuffer->rotateBuffer(sizeof(MeshData) * instanceMeshData.size()); instanceMeshDataBuffer->rotateBuffer(sizeof(MeshData) * instanceMeshData.size());
instanceMeshDataBuffer->updateContents(ShaderBufferCreateInfo{ instanceMeshDataBuffer->updateContents(0, sizeof(MeshData) * instanceMeshData.size(), instanceMeshData.data());
.sourceData =
{
.size = sizeof(MeshData) * instanceMeshData.size(),
.data = (uint8*)instanceMeshData.data(),
},
.numElements = instanceMeshData.size(),
});
instanceMeshDataBuffer->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT, instanceMeshDataBuffer->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT,
Gfx::SE_ACCESS_MEMORY_READ_BIT, Gfx::SE_PIPELINE_STAGE_TOP_OF_PIPE_BIT); Gfx::SE_ACCESS_MEMORY_READ_BIT, Gfx::SE_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
@@ -287,7 +267,8 @@ MeshId VertexData::allocateVertexData(uint64 numVertices) {
meshData.add({}); meshData.add({});
head += numVertices; head += numVertices;
if (head > verticesAllocated) { if (head > verticesAllocated) {
verticesAllocated = std::max(head, verticesAllocated + NUM_DEFAULT_ELEMENTS); verticesAllocated = 2 * head; // double capacity
std::cout << "Resizing buffers to " << verticesAllocated << std::endl;
resizeBuffers(); resizeBuffers();
} }
return res; return res;
@@ -383,7 +364,6 @@ void VertexData::init(Gfx::PGraphics _graphics) {
.dynamic = true, .dynamic = true,
.name = "MeshDataBuffer", .name = "MeshDataBuffer",
}); });
resizeBuffers();
graphics->getShaderCompiler()->registerVertexData(this); graphics->getShaderCompiler()->registerVertexData(this);
} }
+67 -22
View File
@@ -2,13 +2,12 @@
#include "Command.h" #include "Command.h"
#include "Enums.h" #include "Enums.h"
#include "Graphics/Enums.h" #include "Graphics/Enums.h"
#include <fmt/format.h>
#include <vma/vk_mem_alloc.h> #include <vma/vk_mem_alloc.h>
#include <vulkan/vulkan_core.h>
uint64 bufferSize = 0; uint64 bufferSize = 0;
uint64 getBufferSize() uint64 getBufferSize() { return bufferSize; }
{ return bufferSize; }
using namespace Seele; using namespace Seele;
using namespace Seele::Vulkan; using namespace Seele::Vulkan;
@@ -186,12 +185,16 @@ void BufferAllocation::readContents(uint64 regionOffset, uint64 regionSize, void
} }
void* BufferAllocation::map() { void* BufferAllocation::map() {
void* data; if (mappedPointer == nullptr) {
vmaMapMemory(graphics->getAllocator(), allocation, &data); vmaMapMemory(graphics->getAllocator(), allocation, &mappedPointer);
return data; }
return mappedPointer;
} }
void BufferAllocation::unmap() { vmaUnmapMemory(graphics->getAllocator(), allocation); } void BufferAllocation::unmap() {
vmaUnmapMemory(graphics->getAllocator(), allocation);
mappedPointer = nullptr;
}
Buffer::Buffer(PGraphics graphics, uint64 size, VkBufferUsageFlags usage, Gfx::QueueType queueType, bool dynamic, std::string name, Buffer::Buffer(PGraphics graphics, uint64 size, VkBufferUsageFlags usage, Gfx::QueueType queueType, bool dynamic, std::string name,
bool createCleared, uint32 clearValue) bool createCleared, uint32 clearValue)
@@ -222,10 +225,52 @@ void Buffer::readContents(uint64 regionOffset, uint64 regionSize, void* buffer)
getAlloc()->readContents(regionOffset, regionSize, buffer); getAlloc()->readContents(regionOffset, regionSize, buffer);
} }
void* Buffer::map() {
if (stagingBuffer == nullptr) {
stagingBuffer = new BufferAllocation(graphics, fmt::format("{}Staging", name),
VkBufferCreateInfo{
.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
.pNext = nullptr,
.flags = 0,
.size = getSize(),
.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
},
VmaAllocationCreateInfo{
.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT,
.usage = VMA_MEMORY_USAGE_AUTO,
},
Gfx::QueueType::GRAPHICS);
}
return stagingBuffer->map();
}
void Buffer::unmap() {
if (stagingBuffer == nullptr)
return;
stagingBuffer->unmap();
PCommand cmd = graphics->getQueueCommands(Gfx::QueueType::GRAPHICS)->getCommands();
VkBufferCopy copy = {
.srcOffset = 0,
.dstOffset = 0,
.size = getSize(),
};
cmd->bindResource(getAlloc());
cmd->bindResource(PBufferAllocation(stagingBuffer));
vkCmdCopyBuffer(cmd->getHandle(), stagingBuffer->buffer, getAlloc()->buffer, 1, &copy);
pipelineBarrier(VK_ACCESS_TRANSFER_WRITE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_TRANSFER_WRITE_BIT,
VK_PIPELINE_STAGE_TRANSFER_BIT);
// transferOwnership(prevOwner);
graphics->getDestructionManager()->queueResourceForDestruction(std::move(stagingBuffer));
stagingBuffer = nullptr;
}
void Buffer::rotateBuffer(uint64 size, bool preserveContents) { void Buffer::rotateBuffer(uint64 size, bool preserveContents) {
if (size == 0) if (size == 0)
return; return;
assert(dynamic); assert(dynamic);
unmap();
for (uint32 i = 0; i < buffers.size(); ++i) { for (uint32 i = 0; i < buffers.size(); ++i) {
if (buffers[i]->isCurrentlyBound()) { if (buffers[i]->isCurrentlyBound()) {
continue; continue;
@@ -353,10 +398,10 @@ UniformBuffer::UniformBuffer(PGraphics graphics, const UniformBufferCreateInfo&
UniformBuffer::~UniformBuffer() {} UniformBuffer::~UniformBuffer() {}
void UniformBuffer::updateContents(const DataSource& sourceData) { void UniformBuffer::updateContents(uint64 offset, uint64 size, void* data) {
if (sourceData.size > 0 && sourceData.data != nullptr) { if (size > 0 && data != nullptr) {
rotateBuffer(sourceData.size); rotateBuffer(size);
getAlloc()->updateContents(sourceData.offset, sourceData.size, sourceData.data); getAlloc()->updateContents(offset, size, data);
} }
} }
@@ -384,18 +429,15 @@ ShaderBuffer::ShaderBuffer(PGraphics graphics, const ShaderBufferCreateInfo& cre
ShaderBuffer::~ShaderBuffer() {} ShaderBuffer::~ShaderBuffer() {}
void ShaderBuffer::readContents(Array<uint8>& data) { void ShaderBuffer::readContents(uint64 offset, uint64 size, void* data) { getAlloc()->readContents(offset, size, data); }
data.resize(getSize());
getAlloc()->readContents(0, data.size(), data.data());
}
void ShaderBuffer::updateContents(const ShaderBufferCreateInfo& createInfo) { void ShaderBuffer::updateContents(uint64 offset, uint64 size, void* data) {
if (createInfo.sourceData.data == nullptr) { if (data == nullptr) {
return; return;
} }
// We always want to update, as the contents could be different on the GPU // We always want to update, as the contents could be different on the GPU
if (createInfo.sourceData.size > 0 && createInfo.sourceData.data != nullptr) { if (size > 0 && data != nullptr) {
getAlloc()->updateContents(createInfo.sourceData.offset, createInfo.sourceData.size, createInfo.sourceData.data); getAlloc()->updateContents(offset, size, data);
} }
} }
@@ -404,11 +446,14 @@ void ShaderBuffer::rotateBuffer(uint64 size, bool preserveContents) {
Vulkan::Buffer::rotateBuffer(size, preserveContents); Vulkan::Buffer::rotateBuffer(size, preserveContents);
} }
void* ShaderBuffer::map() { return Vulkan::Buffer::map(); }
void ShaderBuffer::unmap() { Vulkan::Buffer::unmap(); }
void ShaderBuffer::clear() { void ShaderBuffer::clear() {
PCommand command = graphics->getQueueCommands(getAlloc()->owner)->getCommands(); PCommand command = graphics->getQueueCommands(getAlloc()->owner)->getCommands();
command->bindResource(PBufferAllocation(getAlloc())); command->bindResource(PBufferAllocation(getAlloc()));
vkCmdFillBuffer(command->getHandle(), Vulkan::Buffer::getHandle(), 0, vkCmdFillBuffer(command->getHandle(), Vulkan::Buffer::getHandle(), 0, VK_WHOLE_SIZE, 0);
VK_WHOLE_SIZE, 0);
} }
void ShaderBuffer::executeOwnershipBarrier(Gfx::QueueType newOwner) { Vulkan::Buffer::transferOwnership(newOwner); } void ShaderBuffer::executeOwnershipBarrier(Gfx::QueueType newOwner) { Vulkan::Buffer::transferOwnership(newOwner); }
@@ -429,7 +474,7 @@ VertexBuffer::VertexBuffer(PGraphics graphics, const VertexBufferCreateInfo& cre
VertexBuffer::~VertexBuffer() {} VertexBuffer::~VertexBuffer() {}
void VertexBuffer::updateRegion(DataSource sourceData) { getAlloc()->updateContents(sourceData.offset, sourceData.size, sourceData.data); } void VertexBuffer::updateRegion(uint64 offset, uint64 size, void* data) { getAlloc()->updateContents(offset, size, data); }
void VertexBuffer::download(Array<uint8>& buffer) { void VertexBuffer::download(Array<uint8>& buffer) {
buffer.resize(getSize()); buffer.resize(getSize());
+10 -4
View File
@@ -26,6 +26,7 @@ class BufferAllocation : public CommandBoundResource {
VmaAllocation allocation = VmaAllocation(); VmaAllocation allocation = VmaAllocation();
VmaAllocationInfo info = VmaAllocationInfo(); VmaAllocationInfo info = VmaAllocationInfo();
VkMemoryPropertyFlags properties = 0; VkMemoryPropertyFlags properties = 0;
void* mappedPointer = nullptr;
uint64 size = 0; uint64 size = 0;
VkDeviceAddress deviceAddress; VkDeviceAddress deviceAddress;
Gfx::QueueType owner; Gfx::QueueType owner;
@@ -42,12 +43,15 @@ class Buffer {
uint64 getSize() const { return buffers[currentBuffer]->size; } uint64 getSize() const { return buffers[currentBuffer]->size; }
void updateContents(uint64 regionOffset, uint64 regionSize, void* ptr); void updateContents(uint64 regionOffset, uint64 regionSize, void* ptr);
void readContents(uint64 regionOffset, uint64 regionSize, void* ptr); void readContents(uint64 regionOffset, uint64 regionSize, void* ptr);
void* map();
void unmap();
protected: protected:
PGraphics graphics; PGraphics graphics;
uint32 currentBuffer; uint32 currentBuffer;
Gfx::QueueType initialOwner; Gfx::QueueType initialOwner;
Array<OBufferAllocation> buffers; Array<OBufferAllocation> buffers;
OBufferAllocation stagingBuffer = nullptr;
VkBufferUsageFlags usage; VkBufferUsageFlags usage;
bool dynamic; bool dynamic;
bool createCleared; bool createCleared;
@@ -67,7 +71,7 @@ class VertexBuffer : public Gfx::VertexBuffer, public Buffer {
VertexBuffer(PGraphics graphics, const VertexBufferCreateInfo& sourceData); VertexBuffer(PGraphics graphics, const VertexBufferCreateInfo& sourceData);
virtual ~VertexBuffer(); virtual ~VertexBuffer();
virtual void updateRegion(DataSource update) override; virtual void updateRegion(uint64 offset, uint64 size, void* data) override;
virtual void download(Array<uint8>& buffer) override; virtual void download(Array<uint8>& buffer) override;
protected: protected:
@@ -96,7 +100,7 @@ class UniformBuffer : public Gfx::UniformBuffer, public Buffer {
public: public:
UniformBuffer(PGraphics graphics, const UniformBufferCreateInfo& sourceData); UniformBuffer(PGraphics graphics, const UniformBufferCreateInfo& sourceData);
virtual ~UniformBuffer(); virtual ~UniformBuffer();
virtual void updateContents(const DataSource& sourceData) override; virtual void updateContents(uint64 offset, uint64 size, void* data) override;
virtual void rotateBuffer(uint64 size) override; virtual void rotateBuffer(uint64 size) override;
protected: protected:
@@ -113,9 +117,11 @@ class ShaderBuffer : public Gfx::ShaderBuffer, public Buffer {
public: public:
ShaderBuffer(PGraphics graphics, const ShaderBufferCreateInfo& sourceData); ShaderBuffer(PGraphics graphics, const ShaderBufferCreateInfo& sourceData);
virtual ~ShaderBuffer(); virtual ~ShaderBuffer();
virtual void readContents(Array<uint8>& data) override; virtual void readContents(uint64 offset, uint64 size, void* data) override;
virtual void updateContents(const ShaderBufferCreateInfo& createInfo) override; virtual void updateContents(uint64 offset, uint64 size, void* data) override;
virtual void rotateBuffer(uint64 size, bool preserveContents = false) override; virtual void rotateBuffer(uint64 size, bool preserveContents = false) override;
virtual void* map() override;
virtual void unmap() override;
virtual void clear() override; virtual void clear() override;
+1 -7
View File
@@ -71,13 +71,7 @@ void Material::destroy() {
void Material::updateDescriptor() { void Material::updateDescriptor() {
floatBuffer->rotateBuffer(floatData.size() * sizeof(float)); floatBuffer->rotateBuffer(floatData.size() * sizeof(float));
floatBuffer->updateContents(ShaderBufferCreateInfo{ floatBuffer->updateContents(0, floatData.size() * sizeof(float), floatData.data());
.sourceData =
{
.size = floatData.size() * sizeof(float),
.data = (uint8*)floatData.data(),
},
});
floatBuffer->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT, Gfx::SE_ACCESS_SHADER_READ_BIT, floatBuffer->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT, Gfx::SE_ACCESS_SHADER_READ_BIT,
Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT); Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
layout->reset(); layout->reset();
+3 -20
View File
@@ -45,36 +45,19 @@ void LightEnvironment::addPointLight(Component::PointLight pointLight) { points.
void LightEnvironment::commit() { void LightEnvironment::commit() {
lightEnv.numDirectionalLights = dirs.size(); lightEnv.numDirectionalLights = dirs.size();
lightEnv.numPointLights = points.size(); lightEnv.numPointLights = points.size();
lightEnvBuffer->updateContents(DataSource{ lightEnvBuffer->updateContents(0, sizeof(LightEnv), &lightEnv);
.size = sizeof(LightEnv),
.data = (uint8*)&lightEnv,
});
lightEnvBuffer->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT, 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_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_FRAGMENT_SHADER_BIT | Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT |
Gfx::SE_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_KHR | Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT); Gfx::SE_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_KHR | Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT);
directionalLights->rotateBuffer(sizeof(Component::DirectionalLight) * dirs.size()); directionalLights->rotateBuffer(sizeof(Component::DirectionalLight) * dirs.size());
directionalLights->updateContents({ directionalLights->updateContents(0, sizeof(Component::DirectionalLight) * dirs.size(), dirs.data());
.sourceData =
{
.size = sizeof(Component::DirectionalLight) * dirs.size(),
.data = (uint8*)dirs.data(),
},
.numElements = dirs.size(),
});
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,
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_RAY_TRACING_SHADER_BIT_KHR | Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT); Gfx::SE_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_KHR | Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT);
pointLights->rotateBuffer(sizeof(Component::PointLight) * points.size()); pointLights->rotateBuffer(sizeof(Component::PointLight) * points.size());
pointLights->updateContents({ pointLights->updateContents(0, sizeof(Component::PointLight) * points.size(), points.data());
.sourceData =
{
.size = sizeof(Component::PointLight) * points.size(),
.data = (uint8*)points.data(),
},
.numElements = points.size(),
});
pointLights->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT, pointLights->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT,
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 |