Fixing more macos things
This commit is contained in:
@@ -30,10 +30,11 @@ void VertexData::resetMeshData()
|
|||||||
void VertexData::updateMesh(PMesh mesh, Component::Transform& transform)
|
void VertexData::updateMesh(PMesh mesh, Component::Transform& transform)
|
||||||
{
|
{
|
||||||
std::unique_lock l(materialDataLock);
|
std::unique_lock l(materialDataLock);
|
||||||
PMaterial mat = mesh->referencedMaterial->getHandle()->getBaseMaterial();
|
PMaterialInstance referencedInstance = mesh->referencedMaterial->getHandle();
|
||||||
|
PMaterial mat = referencedInstance->getBaseMaterial();
|
||||||
MaterialData& matData = materialData[mat->getName()];
|
MaterialData& matData = materialData[mat->getName()];
|
||||||
matData.material = mat;
|
matData.material = mat;
|
||||||
MaterialInstanceData& matInstanceData = matData.instances[mesh->referencedMaterial->getHandle()->getId()];
|
MaterialInstanceData& matInstanceData = matData.instances[referencedInstance->getId()];
|
||||||
for (const auto& data : meshData[mesh->id])
|
for (const auto& data : meshData[mesh->id])
|
||||||
{
|
{
|
||||||
matInstanceData.meshes.add(MeshInstanceData{
|
matInstanceData.meshes.add(MeshInstanceData{
|
||||||
@@ -43,7 +44,8 @@ void VertexData::updateMesh(PMesh mesh, Component::Transform& transform)
|
|||||||
.data = data,
|
.data = data,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
matInstanceData.materialInstance = mesh->referencedMaterial->getHandle();
|
matInstanceData.materialInstance = referencedInstance;
|
||||||
|
referencedInstance->updateDescriptor();
|
||||||
}
|
}
|
||||||
|
|
||||||
void VertexData::createDescriptors()
|
void VertexData::createDescriptors()
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ struct PendingBuffer
|
|||||||
uint64 size;
|
uint64 size;
|
||||||
VkBuffer stagingBuffer;
|
VkBuffer stagingBuffer;
|
||||||
VmaAllocation allocation;
|
VmaAllocation allocation;
|
||||||
void *mappedMemory;
|
|
||||||
Gfx::QueueType prevQueue;
|
Gfx::QueueType prevQueue;
|
||||||
bool writeOnly;
|
bool writeOnly;
|
||||||
};
|
};
|
||||||
@@ -163,7 +162,7 @@ void *Buffer::mapRegion(uint64 regionOffset, uint64 regionSize, bool writeOnly)
|
|||||||
{
|
{
|
||||||
if (buffers[currentBuffer].properties & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT)
|
if (buffers[currentBuffer].properties & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT)
|
||||||
{
|
{
|
||||||
VK_CHECK(vmaMapMemory(graphics->getAllocator(), buffers[currentBuffer].allocation, &pending.mappedMemory));
|
VK_CHECK(vmaMapMemory(graphics->getAllocator(), buffers[currentBuffer].allocation, &data));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -177,9 +176,10 @@ void *Buffer::mapRegion(uint64 regionOffset, uint64 regionSize, bool writeOnly)
|
|||||||
};
|
};
|
||||||
VmaAllocationCreateInfo allocInfo = {
|
VmaAllocationCreateInfo allocInfo = {
|
||||||
.usage = VMA_MEMORY_USAGE_AUTO,
|
.usage = VMA_MEMORY_USAGE_AUTO,
|
||||||
|
.requiredFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
|
||||||
};
|
};
|
||||||
VK_CHECK(vmaCreateBuffer(graphics->getAllocator(), &stagingInfo, &allocInfo, &pending.stagingBuffer, &pending.allocation, nullptr));
|
VK_CHECK(vmaCreateBuffer(graphics->getAllocator(), &stagingInfo, &allocInfo, &pending.stagingBuffer, &pending.allocation, nullptr));
|
||||||
vmaMapMemory(graphics->getAllocator(), pending.allocation, &pending.mappedMemory);
|
vmaMapMemory(graphics->getAllocator(), pending.allocation, &data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -247,7 +247,7 @@ void TextureBase::download(uint32 mipLevel, uint32 arrayLayer, uint32 face, Arra
|
|||||||
void* data;
|
void* data;
|
||||||
VkBuffer stagingBuffer = VK_NULL_HANDLE;
|
VkBuffer stagingBuffer = VK_NULL_HANDLE;
|
||||||
VmaAllocation stagingAlloc;
|
VmaAllocation stagingAlloc;
|
||||||
|
// always create a staging buffer since we do buffer -> image copy and the image may be in any tiling format
|
||||||
VkBufferCreateInfo stagingInfo = {
|
VkBufferCreateInfo stagingInfo = {
|
||||||
.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
|
.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
|
||||||
.pNext = nullptr,
|
.pNext = nullptr,
|
||||||
@@ -258,6 +258,7 @@ void TextureBase::download(uint32 mipLevel, uint32 arrayLayer, uint32 face, Arra
|
|||||||
};
|
};
|
||||||
VmaAllocationCreateInfo alloc = {
|
VmaAllocationCreateInfo alloc = {
|
||||||
.usage = VMA_MEMORY_USAGE_AUTO,
|
.usage = VMA_MEMORY_USAGE_AUTO,
|
||||||
|
.flags = VMA_ALLOCATION_CREATE_MAPPED_BIT | VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT,
|
||||||
};
|
};
|
||||||
VK_CHECK(vmaCreateBuffer(graphics->getAllocator(), &stagingInfo, &alloc, &stagingBuffer, &stagingAlloc, nullptr));
|
VK_CHECK(vmaCreateBuffer(graphics->getAllocator(), &stagingInfo, &alloc, &stagingBuffer, &stagingAlloc, nullptr));
|
||||||
|
|
||||||
@@ -286,10 +287,11 @@ void TextureBase::download(uint32 mipLevel, uint32 arrayLayer, uint32 face, Arra
|
|||||||
};
|
};
|
||||||
vkCmdCopyImageToBuffer(cmdBuffer->getHandle(), image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, stagingBuffer, 1, ®ion);
|
vkCmdCopyImageToBuffer(cmdBuffer->getHandle(), image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, stagingBuffer, 1, ®ion);
|
||||||
changeLayout(prevLayout);
|
changeLayout(prevLayout);
|
||||||
|
VK_CHECK(vmaMapMemory(graphics->getAllocator(), stagingAlloc, &data));
|
||||||
buffer.resize(imageSize);
|
buffer.resize(imageSize);
|
||||||
std::memcpy(buffer.data(), data, buffer.size());
|
std::memcpy(buffer.data(), data, buffer.size());
|
||||||
vmaUnmapMemory(graphics->getAllocator(), stagingAlloc);
|
vmaUnmapMemory(graphics->getAllocator(), stagingAlloc);
|
||||||
vmaDestroyBuffer(graphics->getAllocator(), stagingBuffer, stagingAlloc);
|
graphics->getDestructionManager()->queueBuffer(cmdBuffer, stagingBuffer, stagingAlloc);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextureBase::executeOwnershipBarrier(Gfx::QueueType newOwner)
|
void TextureBase::executeOwnershipBarrier(Gfx::QueueType newOwner)
|
||||||
|
|||||||
@@ -50,6 +50,8 @@ MaterialInstance::~MaterialInstance()
|
|||||||
|
|
||||||
void MaterialInstance::updateDescriptor()
|
void MaterialInstance::updateDescriptor()
|
||||||
{
|
{
|
||||||
|
if(!dirty)
|
||||||
|
return;
|
||||||
Gfx::PDescriptorLayout layout = baseMaterial->getMaterial()->getDescriptorLayout();
|
Gfx::PDescriptorLayout layout = baseMaterial->getMaterial()->getDescriptorLayout();
|
||||||
descriptor = layout->allocateDescriptorSet();
|
descriptor = layout->allocateDescriptorSet();
|
||||||
for (auto& param : parameters)
|
for (auto& param : parameters)
|
||||||
@@ -85,7 +87,6 @@ void MaterialInstance::setBaseMaterial(PMaterialAsset asset)
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
baseMaterial = asset;
|
baseMaterial = asset;
|
||||||
updateDescriptor();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MaterialInstance::save(ArchiveBuffer& buffer) const
|
void MaterialInstance::save(ArchiveBuffer& buffer) const
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ private:
|
|||||||
Gfx::PDescriptorSet descriptor;
|
Gfx::PDescriptorSet descriptor;
|
||||||
PMaterialAsset baseMaterial;
|
PMaterialAsset baseMaterial;
|
||||||
uint64 id;
|
uint64 id;
|
||||||
|
bool dirty = true;
|
||||||
};
|
};
|
||||||
DEFINE_REF(MaterialInstance)
|
DEFINE_REF(MaterialInstance)
|
||||||
} // namespace Seele
|
} // namespace Seele
|
||||||
Reference in New Issue
Block a user