Now able to import stuff properly

This commit is contained in:
Dynamitos
2024-05-06 18:36:16 +02:00
parent 05bb1d0cee
commit af7d624d06
21 changed files with 189 additions and 79 deletions
+1
View File
@@ -61,6 +61,7 @@ public:
virtual void writeChanges() = 0;
virtual void updateBuffer(uint32 binding, PUniformBuffer uniformBuffer) = 0;
virtual void updateBuffer(uint32 binding, PShaderBuffer ShaderBuffer) = 0;
virtual void updateBuffer(uint32_t binding, uint32 index, Gfx::PShaderBuffer uniformBuffer) = 0;
virtual void updateSampler(uint32 binding, PSampler sampler) = 0;
virtual void updateTexture(uint32 binding, PTexture texture, PSampler samplerState = nullptr) = 0;
virtual void updateTextureArray(uint32_t binding, Array<PTexture> texture) = 0;
+2 -2
View File
@@ -99,7 +99,7 @@ void BasePass::render()
pipelineInfo.fragmentShader = collection->fragmentShader;
pipelineInfo.pipelineLayout = collection->pipelineLayout;
pipelineInfo.renderPass = renderPass;
pipelineInfo.depthStencilState.depthCompareOp = Gfx::SE_COMPARE_OP_LESS_OR_EQUAL;
pipelineInfo.depthStencilState.depthCompareOp = Gfx::SE_COMPARE_OP_GREATER_OR_EQUAL;
pipelineInfo.multisampleState.samples = viewport->getSamples();
pipelineInfo.colorBlend.attachmentCount = 1;
Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo));
@@ -112,7 +112,7 @@ void BasePass::render()
pipelineInfo.fragmentShader = collection->fragmentShader;
pipelineInfo.pipelineLayout = collection->pipelineLayout;
pipelineInfo.renderPass = renderPass;
pipelineInfo.depthStencilState.depthCompareOp = Gfx::SE_COMPARE_OP_LESS_OR_EQUAL;
pipelineInfo.depthStencilState.depthCompareOp = Gfx::SE_COMPARE_OP_GREATER_OR_EQUAL;
pipelineInfo.multisampleState.samples = viewport->getSamples();
pipelineInfo.colorBlend.attachmentCount = 1;
Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo));
@@ -79,7 +79,7 @@ void DepthPrepass::render()
pipelineInfo.fragmentShader = collection->fragmentShader;
pipelineInfo.pipelineLayout = collection->pipelineLayout;
pipelineInfo.renderPass = renderPass;
pipelineInfo.depthStencilState.depthCompareOp = Gfx::SE_COMPARE_OP_LESS;
pipelineInfo.depthStencilState.depthCompareOp = Gfx::SE_COMPARE_OP_GREATER;
pipelineInfo.multisampleState.samples = viewport->getSamples();
Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo));
command->bindPipeline(pipeline);
@@ -92,7 +92,7 @@ void DepthPrepass::render()
pipelineInfo.pipelineLayout = collection->pipelineLayout;
pipelineInfo.renderPass = renderPass;
//pipelineInfo.depthStencilState.depthWriteEnable = false;
pipelineInfo.depthStencilState.depthCompareOp = Gfx::SE_COMPARE_OP_LESS_OR_EQUAL;
pipelineInfo.depthStencilState.depthCompareOp = Gfx::SE_COMPARE_OP_GREATER;
pipelineInfo.multisampleState.samples = viewport->getSamples();
Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo));
command->bindPipeline(pipeline);
@@ -147,7 +147,6 @@ void DepthPrepass::publishOutputs()
Gfx::RenderTargetAttachment(depthBuffer,
Gfx::SE_IMAGE_LAYOUT_UNDEFINED, Gfx::SE_IMAGE_LAYOUT_GENERAL,
Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_STORE);
depthAttachment.clear.depthStencil.depth = 1.0f;
resources->registerRenderPassOutput("DEPTHPREPASS_DEPTH", depthAttachment);
}
@@ -76,7 +76,6 @@ void UIPass::publishOutputs()
Gfx::RenderTargetAttachment(depthBuffer,
Gfx::SE_IMAGE_LAYOUT_UNDEFINED, Gfx::SE_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_STORE);
depthAttachment.clear.depthStencil.depth = 1.0f;
resources->registerRenderPassOutput("UIPASS_DEPTH", depthAttachment);
TextureCreateInfo colorBufferInfo = {
+39 -21
View File
@@ -32,7 +32,7 @@ void StaticMeshVertexData::loadPositions(MeshId id, const Array<Vector>& data)
dirty = true;
}
void StaticMeshVertexData::loadTexCoords(MeshId id, const Array<Vector2>& data)
void StaticMeshVertexData::loadTexCoords(MeshId id, uint64 index, const Array<Vector2>& data)
{
uint64 offset;
{
@@ -40,7 +40,7 @@ void StaticMeshVertexData::loadTexCoords(MeshId id, const Array<Vector2>& data)
offset = meshOffsets[id];
}
assert(offset + data.size() <= head);
std::memcpy(texCoordsData.data() + offset, data.data(), data.size() * sizeof(Vector2));
std::memcpy(texCoordsData[index].data() + offset, data.data(), data.size() * sizeof(Vector2));
dirty = true;
}
@@ -100,19 +100,23 @@ void StaticMeshVertexData::serializeMesh(MeshId id, uint64 numVertices, ArchiveB
offset = meshOffsets[id];
}
Array<Vector> pos(numVertices);
Array<Vector2> tex(numVertices);
Array<Vector2> tex[MAX_TEXCOORDS];
for (size_t i = 0; i < MAX_TEXCOORDS; ++i)
{
tex[i].resize(numVertices);
std::memcpy(tex[i].data(), texCoordsData[i].data() + offset, numVertices * sizeof(Vector2));
Serialization::save(buffer, tex[i]);
}
Array<Vector> nor(numVertices);
Array<Vector> tan(numVertices);
Array<Vector> bit(numVertices);
Array<Vector> col(numVertices);
std::memcpy(pos.data(), positionData.data() + offset, numVertices * sizeof(Vector));
std::memcpy(tex.data(), texCoordsData.data() + offset, numVertices * sizeof(Vector2));
std::memcpy(nor.data(), normalData.data() + offset, numVertices * sizeof(Vector));
std::memcpy(tan.data(), tangentData.data() + offset, numVertices * sizeof(Vector));
std::memcpy(bit.data(), biTangentData.data() + offset, numVertices * sizeof(Vector));
std::memcpy(col.data(), colorData.data() + offset, numVertices * sizeof(Vector));
Serialization::save(buffer, pos);
Serialization::save(buffer, tex);
Serialization::save(buffer, nor);
Serialization::save(buffer, tan);
Serialization::save(buffer, bit);
@@ -122,19 +126,22 @@ void StaticMeshVertexData::serializeMesh(MeshId id, uint64 numVertices, ArchiveB
void StaticMeshVertexData::deserializeMesh(MeshId id, ArchiveBuffer& buffer)
{
Array<Vector> pos;
Array<Vector2> tex;
Array<Vector2> tex[MAX_TEXCOORDS];
for (size_t i = 0; i < MAX_TEXCOORDS; ++i)
{
Serialization::load(buffer, tex[i]);
loadTexCoords(id, i, tex[i]);
}
Array<Vector> nor;
Array<Vector> tan;
Array<Vector> bit;
Array<Vector> col;
Serialization::load(buffer, pos);
Serialization::load(buffer, tex);
Serialization::load(buffer, nor);
Serialization::load(buffer, tan);
Serialization::load(buffer, bit);
Serialization::load(buffer, col);
loadPositions(id, pos);
loadTexCoords(id, tex);
loadNormals(id, nor);
loadTangents(id, tan);
loadBiTangents(id, bit);
@@ -150,7 +157,7 @@ void StaticMeshVertexData::init(Gfx::PGraphics _graphics)
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});
descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 5, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER, .descriptorCount = MAX_TEXCOORDS });
descriptorLayout->create();
descriptorSet = descriptorLayout->allocateDescriptorSet();
}
@@ -159,7 +166,10 @@ void StaticMeshVertexData::destroy()
{
VertexData::destroy();
positions = nullptr;
texCoords = nullptr;
for (size_t i = 0; i < MAX_TEXCOORDS; ++i)
{
texCoords[i] = nullptr;
}
normals = nullptr;
tangents = nullptr;
biTangents = nullptr;
@@ -204,10 +214,13 @@ void StaticMeshVertexData::resizeBuffers()
createInfo.sourceData.size = verticesAllocated * sizeof(Vector2);
createInfo.name = "TexCoords";
createInfo.numElements = verticesAllocated * 2;
texCoords = graphics->createShaderBuffer(createInfo);
for (size_t i = 0; i < MAX_TEXCOORDS; ++i)
{
texCoords[i] = graphics->createShaderBuffer(createInfo);
texCoordsData[i].resize(verticesAllocated);
}
positionData.resize(verticesAllocated);
texCoordsData.resize(verticesAllocated);
normalData.resize(verticesAllocated);
tangentData.resize(verticesAllocated);
biTangentData.resize(verticesAllocated);
@@ -220,10 +233,13 @@ void StaticMeshVertexData::updateBuffers()
.size = positionData.size() * sizeof(Vector),
.data = (uint8*)positionData.data(),
});
texCoords->updateContents(DataSource{
.size = texCoordsData.size() * sizeof(Vector2),
.data = (uint8*)texCoordsData.data(),
});
for (size_t i = 0; i < MAX_TEXCOORDS; ++i)
{
texCoords[i]->updateContents(DataSource{
.size = texCoordsData[i].size() * sizeof(Vector2),
.data = (uint8*)texCoordsData[i].data(),
});
}
normals->updateContents(DataSource{
.size = normalData.size() * sizeof(Vector),
.data = (uint8*)normalData.data(),
@@ -243,10 +259,12 @@ void StaticMeshVertexData::updateBuffers()
descriptorLayout->reset();
descriptorSet = descriptorLayout->allocateDescriptorSet();
descriptorSet->updateBuffer(0, positions);
descriptorSet->updateBuffer(1, texCoords);
descriptorSet->updateBuffer(2, normals);
descriptorSet->updateBuffer(3, tangents);
descriptorSet->updateBuffer(4, biTangents);
descriptorSet->updateBuffer(5, colors);
descriptorSet->updateBuffer(1, normals);
descriptorSet->updateBuffer(2, tangents);
descriptorSet->updateBuffer(3, biTangents);
descriptorSet->updateBuffer(4, colors);
for (size_t i = 0; i < MAX_TEXCOORDS; ++i) {
descriptorSet->updateBuffer(5, i, texCoords[i]);
}
descriptorSet->writeChanges();
}
+3 -3
View File
@@ -13,7 +13,7 @@ public:
virtual ~StaticMeshVertexData();
static StaticMeshVertexData* getInstance();
void loadPositions(MeshId id, const Array<Vector>& data);
void loadTexCoords(MeshId id, const Array<Vector2>& data);
void loadTexCoords(MeshId id, uint64 index, const Array<Vector2>& data);
void loadNormals(MeshId id, const Array<Vector>& data);
void loadTangents(MeshId id, const Array<Vector>& data);
void loadBiTangents(MeshId id, const Array<Vector>& data);
@@ -32,8 +32,8 @@ private:
std::mutex mutex;
Gfx::OShaderBuffer positions;
Array<Vector> positionData;
Gfx::OShaderBuffer texCoords;
Array<Vector2> texCoordsData;
Gfx::OShaderBuffer texCoords[MAX_TEXCOORDS];
Array<Vector2> texCoordsData[MAX_TEXCOORDS];
Gfx::OShaderBuffer normals;
Array<Vector> normalData;
Gfx::OShaderBuffer tangents;
+2
View File
@@ -8,6 +8,8 @@
#include "Graphics/Buffer.h"
#include "Meshlet.h"
constexpr uint64 MAX_TEXCOORDS = 8;
namespace Seele
{
DECLARE_REF(Mesh)
+27
View File
@@ -218,6 +218,33 @@ void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PShaderBuffer shaderBuff
cachedData[binding] = vulkanBuffer.getHandle();
}
void DescriptorSet::updateBuffer(uint32_t binding, uint32 index, Gfx::PShaderBuffer shaderBuffer) {
PShaderBuffer vulkanBuffer = shaderBuffer.cast<ShaderBuffer>();
ShaderBuffer* cachedBuffer = reinterpret_cast<ShaderBuffer*>(cachedData[binding]);
if (vulkanBuffer.getHandle() == cachedBuffer) {
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 = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
.pBufferInfo = &bufferInfos.back(),
});
cachedData[binding] = vulkanBuffer.getHandle();
}
void DescriptorSet::updateSampler(uint32_t binding, Gfx::PSampler samplerState) {
PSampler vulkanSampler = samplerState.cast<Sampler>();
Sampler* cachedSampler = reinterpret_cast<Sampler*>(cachedData[binding]);
+1
View File
@@ -50,6 +50,7 @@ public:
virtual void writeChanges() override;
virtual void updateBuffer(uint32_t binding, Gfx::PUniformBuffer uniformBuffer) override;
virtual void updateBuffer(uint32_t binding, Gfx::PShaderBuffer uniformBuffer) override;
virtual void updateBuffer(uint32_t binding, uint32 index, Gfx::PShaderBuffer uniformBuffer) override;
virtual void updateSampler(uint32_t binding, Gfx::PSampler samplerState) override;
virtual void updateTexture(uint32_t binding, Gfx::PTexture texture, Gfx::PSampler sampler = nullptr) override;
virtual void updateTextureArray(uint32_t binding, Array<Gfx::PTexture> texture) override;
+2 -2
View File
@@ -361,8 +361,8 @@ Viewport::Viewport(PWindow owner, const ViewportCreateInfo &viewportInfo)
handle.x = static_cast<float>(offsetX);
handle.y = static_cast<float>(offsetY) + handle.height;
handle.height = -handle.height;
handle.minDepth = 0.f;
handle.maxDepth = 1.f;
handle.minDepth = 1.f;
handle.maxDepth = 0.f;
}
Viewport::~Viewport()
+12
View File
@@ -31,6 +31,18 @@ Matrix4 Viewport::getProjectionMatrix() const
{
if (fieldOfView > 0.0f)
{
//float h = 1.0 / tan(fieldOfView * 0.5);
//float w = h / (sizeX / static_cast<float>(sizeY));
//float zFar = 1000.0f;
//float zNear = 0.1f;
//float a = -zNear / (zFar - zNear);
//float b = (zNear * zFar) / (zFar - zNear);
//return Matrix4(
// w, 0, 0, 0,
// 0, -h, 0, 0,
// 0, 0, a, b,
// 0, 0, 1, 0
//);
return glm::perspective(fieldOfView, sizeX / static_cast<float>(sizeY), 0.1f, 10000.0f);
}
else