Progress i guess
This commit is contained in:
@@ -19,6 +19,7 @@ DepthPrepass::DepthPrepass(Gfx::PGraphics graphics, PScene scene)
|
||||
|
||||
depthPrepassLayout = graphics->createPipelineLayout();
|
||||
depthPrepassLayout->addDescriptorLayout(INDEX_VIEW_PARAMS, viewParamsLayout);
|
||||
graphics->getShaderCompiler()->registerRenderPass("DepthPass", "LegacyBasePass");
|
||||
}
|
||||
|
||||
DepthPrepass::~DepthPrepass()
|
||||
@@ -43,18 +44,18 @@ void DepthPrepass::render()
|
||||
{
|
||||
permutation.useMeshShading = true;
|
||||
permutation.hasTaskShader = true;
|
||||
std::memcpy(permutation.taskFile, "MeshletBasePass", sizeof("MeshletBasePass"));
|
||||
std::memcpy(permutation.vertexMeshFile, "MeshletBasePass", sizeof("MeshletBasePass"));
|
||||
std::strncpy(permutation.taskFile, "MeshletBasePass", sizeof("MeshletBasePass"));
|
||||
std::strncpy(permutation.vertexMeshFile, "MeshletBasePass", sizeof("MeshletBasePass"));
|
||||
}
|
||||
else
|
||||
{
|
||||
permutation.useMeshShading = false;
|
||||
std::memcpy(permutation.vertexMeshFile, "LegacyBasePass", sizeof("LegacyBasePass"));
|
||||
std::strncpy(permutation.vertexMeshFile, "LegacyBasePass", sizeof("LegacyBasePass"));
|
||||
}
|
||||
graphics->beginRenderPass(renderPass);
|
||||
for (VertexData* vertexData : VertexData::getList())
|
||||
{
|
||||
std::memcpy(permutation.vertexDataName, vertexData->getTypeName().c_str(), std::strlen(vertexData->getTypeName().c_str()));
|
||||
std::strncpy(permutation.vertexDataName, vertexData->getTypeName().c_str(), sizeof(permutation.vertexDataName));
|
||||
const auto& materials = vertexData->getMaterialData();
|
||||
for (const auto& [_, materialData] : materials)
|
||||
{
|
||||
@@ -64,7 +65,7 @@ void DepthPrepass::render()
|
||||
// Material => per material
|
||||
// VertexData => per meshtype
|
||||
// SceneData => per material instance
|
||||
std::memcpy(permutation.materialName, materialData.material->getName().c_str(), std::strlen(materialData.material->getName().c_str()));
|
||||
std::strncpy(permutation.materialName, materialData.material->getName().c_str(), sizeof(permutation.materialName));
|
||||
Gfx::PermutationId id(permutation);
|
||||
|
||||
Gfx::PRenderCommand command = graphics->createRenderCommand("DepthRender");
|
||||
|
||||
@@ -18,8 +18,8 @@ public:
|
||||
virtual void createRenderPass() override;
|
||||
static void modifyRenderPassMacros(Map<const char*, const char*>& defines);
|
||||
private:
|
||||
Gfx::PRenderTargetAttachment depthAttachment;
|
||||
Gfx::PTexture2D depthBuffer;
|
||||
Gfx::ORenderTargetAttachment depthAttachment;
|
||||
Gfx::OTexture2D depthBuffer;
|
||||
|
||||
Array<Gfx::PDescriptorSet> descriptorSets;
|
||||
|
||||
|
||||
@@ -200,7 +200,7 @@ void LightCullingPass::setupFrustums()
|
||||
dispatchParams.numThreads = numThreads;
|
||||
dispatchParams.numThreadGroups = numThreadGroups;
|
||||
|
||||
Gfx::ODescriptorLayout frustumDescriptorLayout = graphics->createDescriptorLayout("FrustumLayout");
|
||||
frustumDescriptorLayout = graphics->createDescriptorLayout("FrustumLayout");
|
||||
frustumDescriptorLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
|
||||
frustumDescriptorLayout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
||||
frustumLayout = graphics->createPipelineLayout();
|
||||
|
||||
@@ -45,6 +45,7 @@ private:
|
||||
Gfx::OShaderBuffer frustumBuffer;
|
||||
Gfx::OUniformBuffer dispatchParamsBuffer;
|
||||
Gfx::OUniformBuffer viewParamsBuffer;
|
||||
Gfx::ODescriptorLayout frustumDescriptorLayout;
|
||||
Gfx::PDescriptorSet frustumDescriptorSet;
|
||||
Gfx::OComputeShader frustumShader;
|
||||
Gfx::OPipelineLayout frustumLayout;
|
||||
|
||||
@@ -38,7 +38,7 @@ protected:
|
||||
PRenderGraphResources resources;
|
||||
static constexpr uint32 INDEX_VIEW_PARAMS = 0;
|
||||
Gfx::ODescriptorLayout viewParamsLayout;
|
||||
Gfx::OShaderBuffer viewParamsBuffer;
|
||||
Gfx::OUniformBuffer viewParamsBuffer;
|
||||
Gfx::PDescriptorSet viewParamsSet;
|
||||
Gfx::ORenderPass renderPass;
|
||||
Gfx::PGraphics graphics;
|
||||
|
||||
@@ -169,14 +169,13 @@ void SkyboxRenderPass::createRenderPass()
|
||||
createInfo.name = "SkyboxVertex";
|
||||
createInfo.mainModule = "Skybox";
|
||||
createInfo.entryPoint = "vertexMain";
|
||||
createInfo.defines["INDEX_VIEW_PARAMS"] = "0";
|
||||
Gfx::PVertexShader vertexShader = graphics->createVertexShader(createInfo);
|
||||
vertexShader = graphics->createVertexShader(createInfo);
|
||||
|
||||
createInfo.name = "SkyboxFragment";
|
||||
createInfo.entryPoint = "fragmentMain";
|
||||
Gfx::PFragmentShader fragmentShader = graphics->createFragmentShader(createInfo);
|
||||
fragmentShader = graphics->createFragmentShader(createInfo);
|
||||
|
||||
Gfx::PVertexDeclaration vertexDecl = graphics->createVertexDeclaration({
|
||||
declaration = graphics->createVertexDeclaration({
|
||||
Gfx::VertexElement {
|
||||
.binding = 0,
|
||||
.offset = 0,
|
||||
@@ -187,7 +186,7 @@ void SkyboxRenderPass::createRenderPass()
|
||||
});
|
||||
|
||||
Gfx::LegacyPipelineCreateInfo gfxInfo;
|
||||
gfxInfo.vertexDeclaration = vertexDecl;
|
||||
gfxInfo.vertexDeclaration = declaration;
|
||||
gfxInfo.vertexShader = vertexShader;
|
||||
gfxInfo.fragmentShader = fragmentShader;
|
||||
gfxInfo.rasterizationState.polygonMode = Gfx::SE_POLYGON_MODE_FILL;
|
||||
|
||||
@@ -26,6 +26,9 @@ private:
|
||||
Gfx::ODescriptorLayout descriptorLayout;
|
||||
Gfx::PDescriptorSet descriptorSet;
|
||||
Gfx::OPipelineLayout pipelineLayout;
|
||||
Gfx::OVertexDeclaration declaration;
|
||||
Gfx::OVertexShader vertexShader;
|
||||
Gfx::OFragmentShader fragmentShader;
|
||||
Gfx::OGraphicsPipeline pipeline;
|
||||
Gfx::OSamplerState skyboxSampler;
|
||||
Component::Skybox skybox;
|
||||
|
||||
@@ -155,8 +155,8 @@ void UIPass::createRenderPass()
|
||||
},
|
||||
.dynamic = false,
|
||||
};
|
||||
Gfx::PUniformBuffer uniformBuffer = graphics->createUniformBuffer(info);
|
||||
Gfx::PSamplerState backgroundSampler = graphics->createSamplerState({});
|
||||
Gfx::OUniformBuffer uniformBuffer = graphics->createUniformBuffer(info);
|
||||
Gfx::OSamplerState backgroundSampler = graphics->createSamplerState({});
|
||||
|
||||
info = {
|
||||
.sourceData = {
|
||||
|
||||
@@ -53,27 +53,26 @@ void ShaderCompiler::compile()
|
||||
ShaderPermutation permutation;
|
||||
for (const auto& [name, pass] : passes)
|
||||
{
|
||||
std::memset(&permutation, 0, sizeof(ShaderPermutation));
|
||||
permutation.hasFragment = pass.hasFragmentShader;
|
||||
permutation.useMeshShading = pass.useMeshShading;
|
||||
permutation.hasTaskShader = pass.hasTaskShader;
|
||||
std::memcpy(permutation.vertexMeshFile, pass.mainFile.c_str(), sizeof(permutation.vertexMeshFile));
|
||||
std::strncpy(permutation.vertexMeshFile, pass.mainFile.c_str(), sizeof(permutation.vertexMeshFile));
|
||||
if (pass.hasFragmentShader)
|
||||
{
|
||||
std::memcpy(permutation.fragmentFile, pass.fragmentFile.c_str(), sizeof(permutation.fragmentFile));
|
||||
std::strncpy(permutation.fragmentFile, pass.fragmentFile.c_str(), sizeof(permutation.fragmentFile));
|
||||
}
|
||||
if (pass.hasTaskShader)
|
||||
{
|
||||
std::memcpy(permutation.taskFile, pass.taskFile.c_str(), sizeof(permutation.taskFile));
|
||||
std::strncpy(permutation.taskFile, pass.taskFile.c_str(), sizeof(permutation.taskFile));
|
||||
}
|
||||
for (const auto& [vdName, vd] : vertexData)
|
||||
{
|
||||
std::memcpy(permutation.vertexDataName, vd->getTypeName().c_str(), sizeof(permutation.vertexDataName));
|
||||
std::strncpy(permutation.vertexDataName, vd->getTypeName().c_str(), sizeof(permutation.vertexDataName));
|
||||
if (pass.useMaterial)
|
||||
{
|
||||
for (const auto& [matName, mat] : materials)
|
||||
{
|
||||
std::memcpy(permutation.materialName, matName.c_str(), sizeof(permutation.materialName));
|
||||
std::strncpy(permutation.materialName, matName.c_str(), sizeof(permutation.materialName));
|
||||
createShaders(permutation);
|
||||
}
|
||||
}
|
||||
@@ -92,10 +91,23 @@ ShaderCollection& ShaderCompiler::createShaders(ShaderPermutation permutation)
|
||||
ShaderCollection collection;
|
||||
|
||||
ShaderCreateInfo createInfo;
|
||||
createInfo.typeParameter = { permutation.materialName, permutation.vertexDataName };
|
||||
createInfo.typeParameter = { permutation.vertexDataName };
|
||||
createInfo.name = std::format("Material {0}", permutation.materialName);
|
||||
createInfo.additionalModules.add(permutation.materialName);
|
||||
if (std::strlen(permutation.materialName) > 0)
|
||||
{
|
||||
createInfo.additionalModules.add(permutation.materialName);
|
||||
createInfo.typeParameter.add(permutation.materialName);
|
||||
}
|
||||
createInfo.additionalModules.add(permutation.vertexDataName);
|
||||
createInfo.additionalModules.add(permutation.vertexMeshFile);
|
||||
if (permutation.hasFragment)
|
||||
{
|
||||
createInfo.additionalModules.add(permutation.fragmentFile);
|
||||
}
|
||||
if (permutation.hasTaskShader)
|
||||
{
|
||||
createInfo.additionalModules.add(permutation.taskFile);
|
||||
}
|
||||
|
||||
if (permutation.useMeshShading)
|
||||
{
|
||||
|
||||
@@ -62,6 +62,10 @@ struct ShaderPermutation
|
||||
uint8 useMeshShading : 1;
|
||||
uint8 hasTaskShader : 1;
|
||||
//TODO: lightmapping etc
|
||||
ShaderPermutation()
|
||||
{
|
||||
std::memset(this, 0, sizeof(ShaderPermutation));
|
||||
}
|
||||
};
|
||||
//Hashed ShaderPermutation for fast lookup
|
||||
struct PermutationId
|
||||
|
||||
@@ -16,6 +16,7 @@ void VertexData::resetMeshData()
|
||||
if (dirty)
|
||||
{
|
||||
updateBuffers();
|
||||
dirty = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +24,7 @@ void VertexData::updateMesh(const Component::Transform& transform, PMesh mesh)
|
||||
{
|
||||
PMaterial mat = mesh->referencedMaterial->getHandle()->getBaseMaterial();
|
||||
MaterialData& matData = materialData[mat->getName()];
|
||||
matData.material = mat;
|
||||
MaterialInstanceData& matInstanceData = matData.instances[mesh->referencedMaterial->getHandle()->getId()];
|
||||
matInstanceData.meshes.add(MeshInstanceData{
|
||||
.id = mesh->id,
|
||||
@@ -89,7 +91,6 @@ void VertexData::loadMesh(MeshId id, Array<Meshlet> loadedMeshlets)
|
||||
.stride = sizeof(uint8),
|
||||
.dynamic = true,
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
void VertexData::createDescriptors()
|
||||
@@ -108,7 +109,7 @@ void VertexData::createDescriptors()
|
||||
meshes.add(mesh);
|
||||
}
|
||||
}
|
||||
Gfx::PShaderBuffer instanceBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
|
||||
matInst.instanceBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
|
||||
.sourceData = {
|
||||
.size = sizeof(InstanceData) * instanceData.size(),
|
||||
.data = (uint8*)instanceData.data(),
|
||||
@@ -117,17 +118,17 @@ void VertexData::createDescriptors()
|
||||
});
|
||||
instanceDataLayout->reset();
|
||||
matInst.descriptorSet = instanceDataLayout->allocateDescriptorSet();
|
||||
matInst.descriptorSet->updateBuffer(0, instanceBuffer);
|
||||
matInst.descriptorSet->updateBuffer(0, matInst.instanceBuffer);
|
||||
if (graphics->supportMeshShading())
|
||||
{
|
||||
Gfx::PShaderBuffer meshDataBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
|
||||
matInst.meshDataBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
|
||||
.sourceData = {
|
||||
.size = sizeof(MeshData) * meshes.size(),
|
||||
.data = (uint8*)meshes.data(),
|
||||
},
|
||||
.stride = sizeof(MeshData)
|
||||
});
|
||||
matInst.descriptorSet->updateBuffer(1, meshDataBuffer);
|
||||
matInst.descriptorSet->updateBuffer(1, matInst.meshDataBuffer);
|
||||
matInst.descriptorSet->updateBuffer(2, meshletBuffer);
|
||||
matInst.descriptorSet->updateBuffer(3, primitiveIndicesBuffer);
|
||||
matInst.descriptorSet->updateBuffer(4, vertexIndicesBuffer);
|
||||
|
||||
@@ -43,6 +43,8 @@ public:
|
||||
struct MaterialInstanceData
|
||||
{
|
||||
PMaterialInstance materialInstance;
|
||||
Gfx::OShaderBuffer instanceBuffer;
|
||||
Gfx::OShaderBuffer meshDataBuffer;
|
||||
Gfx::PDescriptorSet descriptorSet;
|
||||
uint32 numMeshes; // not necessarily equal to meshes.size() if a MeshId has multiple meshes
|
||||
Array<MeshInstanceData> meshes;
|
||||
|
||||
@@ -4,12 +4,12 @@
|
||||
|
||||
using namespace Seele::Vulkan;
|
||||
|
||||
SubAllocation::SubAllocation(PAllocation owner, VkDeviceSize allocatedOffset, VkDeviceSize size, VkDeviceSize alignedOffset, VkDeviceSize allocatedSize)
|
||||
SubAllocation::SubAllocation(PAllocation owner, VkDeviceSize requestedSize, VkDeviceSize allocatedOffset, VkDeviceSize allocatedSize, VkDeviceSize alignedOffset)
|
||||
: owner(owner)
|
||||
, size(size)
|
||||
, requestedSize(requestedSize)
|
||||
, allocatedOffset(allocatedOffset)
|
||||
, alignedOffset(alignedOffset)
|
||||
, allocatedSize(allocatedSize)
|
||||
, alignedOffset(alignedOffset)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ Allocation::Allocation(PGraphics graphics, PAllocator allocator, VkDeviceSize si
|
||||
allocInfo.pNext = dedicatedInfo;
|
||||
VK_CHECK(vkAllocateMemory(device, &allocInfo, nullptr, &allocatedMemory));
|
||||
bytesAllocated = size;
|
||||
freeRanges[0] = new SubAllocation(this, 0, size, 0, size);
|
||||
freeRanges[0] = size;
|
||||
|
||||
canMap = (properties & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) == VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
|
||||
isMapped = false;
|
||||
@@ -69,16 +69,16 @@ Allocation::Allocation(PGraphics graphics, PAllocator allocator, VkDeviceSize si
|
||||
|
||||
Allocation::~Allocation()
|
||||
{
|
||||
assert(bytesUsed == 0);
|
||||
}
|
||||
|
||||
OSubAllocation Allocation::getSuballocation(VkDeviceSize requestedSize, VkDeviceSize alignment)
|
||||
{
|
||||
std::scoped_lock lck(lock);
|
||||
if (isDedicated)
|
||||
{
|
||||
if (activeAllocations.empty() && requestedSize == bytesAllocated)
|
||||
{
|
||||
OSubAllocation suballoc = std::move(freeRanges[0]);
|
||||
OSubAllocation suballoc = new SubAllocation(this, requestedSize, 0, requestedSize, 0);
|
||||
activeAllocations.add(suballoc);
|
||||
freeRanges.clear();
|
||||
bytesUsed += requestedSize;
|
||||
@@ -89,32 +89,30 @@ OSubAllocation Allocation::getSuballocation(VkDeviceSize requestedSize, VkDevice
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
for (auto& [allocatedOffset, freeAllocation] : freeRanges)
|
||||
for (const auto& [lower, size] : freeRanges)
|
||||
{
|
||||
assert(allocatedOffset == freeAllocation->allocatedOffset);
|
||||
VkDeviceSize alignedOffset = allocatedOffset + alignment - 1;
|
||||
VkDeviceSize alignedOffset = lower + alignment - 1;
|
||||
alignedOffset /= alignment;
|
||||
alignedOffset *= alignment;
|
||||
VkDeviceSize allocatedSize = requestedSize + (alignedOffset - allocatedOffset);
|
||||
if (freeAllocation->size == allocatedSize)
|
||||
VkDeviceSize allocatedSize = requestedSize + (alignedOffset - lower);
|
||||
if (size == allocatedSize)
|
||||
{
|
||||
activeAllocations.add(freeAllocation);
|
||||
freeRanges.erase(allocatedOffset);
|
||||
OSubAllocation alloc = new SubAllocation(this, requestedSize, lower, allocatedSize, alignedOffset);
|
||||
activeAllocations.add(alloc);
|
||||
freeRanges.erase(lower);
|
||||
bytesUsed += allocatedSize;
|
||||
return std::move(freeAllocation);
|
||||
return std::move(alloc);
|
||||
}
|
||||
else if (allocatedSize < freeAllocation->allocatedSize)
|
||||
else if (allocatedSize < size)
|
||||
{
|
||||
freeAllocation->size -= allocatedSize;
|
||||
freeAllocation->allocatedSize -= allocatedSize;
|
||||
freeAllocation->allocatedOffset += allocatedSize;
|
||||
freeAllocation->alignedOffset += allocatedSize;
|
||||
OSubAllocation subAlloc = new SubAllocation(this, allocatedOffset, allocatedSize, alignedOffset, allocatedSize);
|
||||
VkDeviceSize newSize = size - allocatedSize;
|
||||
VkDeviceSize newLower = lower + allocatedSize;
|
||||
OSubAllocation subAlloc = new SubAllocation(this, requestedSize, lower, allocatedSize, alignedOffset);
|
||||
activeAllocations.add(subAlloc);
|
||||
freeRanges[freeAllocation->allocatedOffset] = std::move(freeAllocation);
|
||||
freeRanges.erase(allocatedOffset);
|
||||
freeRanges.erase(lower);
|
||||
freeRanges[newLower] = newSize;
|
||||
bytesUsed += allocatedSize;
|
||||
return subAlloc;
|
||||
return std::move(subAlloc);
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
@@ -122,70 +120,28 @@ OSubAllocation Allocation::getSuballocation(VkDeviceSize requestedSize, VkDevice
|
||||
|
||||
void Allocation::markFree(PSubAllocation allocation)
|
||||
{
|
||||
// Dont free if it is already a free allocation, since they also mark themselves on deletion
|
||||
if (freeRanges.find(allocation->allocatedOffset) != freeRanges.end())
|
||||
{
|
||||
return;
|
||||
}
|
||||
assert(activeAllocations.find(allocation) != activeAllocations.end());
|
||||
VkDeviceSize lowerBound = allocation->allocatedOffset;
|
||||
VkDeviceSize upperBound = allocation->allocatedOffset + allocation->allocatedSize;
|
||||
PSubAllocation allocHandle;
|
||||
PSubAllocation freeRangeToDelete;
|
||||
|
||||
freeRanges[lowerBound] = allocation->allocatedSize;
|
||||
for (const auto& [lower, size] : freeRanges)
|
||||
{
|
||||
std::scoped_lock lck(lock);
|
||||
//Join lower bound
|
||||
for (auto& [allocatedOffset, freeAlloc] : freeRanges)
|
||||
if (lower + size == lowerBound)
|
||||
{
|
||||
if (freeAlloc->allocatedOffset <= lowerBound
|
||||
&& freeAlloc->allocatedOffset + freeAlloc->allocatedSize >= upperBound)
|
||||
{
|
||||
// allocation is already in a free region
|
||||
assert(false);
|
||||
}
|
||||
if (freeAlloc->allocatedOffset + freeAlloc->allocatedSize == lowerBound)
|
||||
{
|
||||
//extend freeAlloc by the allocatedSize
|
||||
freeAlloc->allocatedSize += allocation->allocatedSize;
|
||||
allocHandle = freeAlloc;
|
||||
break;
|
||||
}
|
||||
freeRanges[lower] = upperBound;
|
||||
freeRanges.erase(lowerBound);
|
||||
lowerBound = lower;
|
||||
break;
|
||||
}
|
||||
//Join upper bound
|
||||
auto foundAlloc = freeRanges.find(upperBound);
|
||||
if (foundAlloc != freeRanges.end())
|
||||
{
|
||||
// There is a free allocation ending where the new free one ends
|
||||
freeRangeToDelete = foundAlloc->value;
|
||||
if (allocHandle != nullptr)
|
||||
{
|
||||
// extend allocHandle by another foundAlloc->allocatedSize bytes
|
||||
allocHandle->allocatedSize += foundAlloc->value->allocatedSize;
|
||||
freeRanges.erase(foundAlloc->key);
|
||||
}
|
||||
else
|
||||
{
|
||||
// set foundAlloc back by size amount
|
||||
allocHandle = foundAlloc->value;
|
||||
allocHandle->allocatedOffset -= allocation->allocatedSize;
|
||||
allocHandle->alignedOffset -= allocation->allocatedSize;
|
||||
allocHandle->size += allocation->allocatedSize;
|
||||
allocHandle->allocatedSize += allocation->allocatedSize;
|
||||
// place back at correct offset, move original owning pointer
|
||||
freeRanges[allocHandle->allocatedOffset] = std::move(foundAlloc->value);
|
||||
// remove from offset map since key changes
|
||||
freeRanges.erase(foundAlloc->key);
|
||||
}
|
||||
}
|
||||
|
||||
if (allocHandle == nullptr)
|
||||
{
|
||||
freeRanges[allocation->allocatedOffset] = new SubAllocation(this, allocation->allocatedOffset, allocation->size, allocation->alignedOffset, allocation->allocatedSize);
|
||||
}
|
||||
activeAllocations.remove_if([&](const PSubAllocation& a) {return a.getHandle() == allocation.getHandle(); });
|
||||
}
|
||||
if (freeRanges.find(upperBound) != freeRanges.end())
|
||||
{
|
||||
freeRanges[lowerBound] += freeRanges[upperBound];
|
||||
freeRanges.erase(upperBound);
|
||||
}
|
||||
activeAllocations.remove(allocation, false);
|
||||
bytesUsed -= allocation->allocatedSize;
|
||||
if(bytesUsed == 0)
|
||||
if (bytesUsed == 0)
|
||||
{
|
||||
allocator->free(this);
|
||||
}
|
||||
@@ -231,7 +187,6 @@ Allocator::Allocator(PGraphics graphics)
|
||||
|
||||
Allocator::~Allocator()
|
||||
{
|
||||
std::scoped_lock lck(lock);
|
||||
for (auto& heap : heaps)
|
||||
{
|
||||
for (auto& alloc : heap.allocations)
|
||||
@@ -246,7 +201,6 @@ Allocator::~Allocator()
|
||||
|
||||
OSubAllocation Allocator::allocate(const VkMemoryRequirements2 &memRequirements2, VkMemoryPropertyFlags properties, VkMemoryDedicatedAllocateInfo *dedicatedInfo)
|
||||
{
|
||||
std::scoped_lock lck(lock);
|
||||
const VkMemoryRequirements &requirements = memRequirements2.memoryRequirements;
|
||||
uint32 memoryTypeIndex = findMemoryType(requirements.memoryTypeBits, properties);
|
||||
uint32 heapIndex = memProperties.memoryTypes[memoryTypeIndex].heapIndex;
|
||||
@@ -270,7 +224,7 @@ OSubAllocation Allocator::allocate(const VkMemoryRequirements2 &memRequirements2
|
||||
OSubAllocation suballoc = alloc->getSuballocation(requirements.size, requirements.alignment);
|
||||
if (suballoc != nullptr)
|
||||
{
|
||||
return suballoc;
|
||||
return std::move(suballoc);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -284,7 +238,6 @@ OSubAllocation Allocator::allocate(const VkMemoryRequirements2 &memRequirements2
|
||||
|
||||
void Allocator::free(PAllocation allocation)
|
||||
{
|
||||
std::scoped_lock lck(lock);
|
||||
for (uint32 heapIndex = 0; heapIndex < heaps.size(); ++heapIndex)
|
||||
{
|
||||
for (uint32 alloc = 0; alloc < heaps[heapIndex].allocations.size(); ++alloc)
|
||||
@@ -293,7 +246,7 @@ void Allocator::free(PAllocation allocation)
|
||||
{
|
||||
heaps[heapIndex].inUse -= allocation->bytesAllocated;
|
||||
std::cout << "Heap " << heapIndex << " -" <<allocation->bytesAllocated << ": " << (float)heaps[heapIndex].inUse / heaps[heapIndex].maxSize << "%" << std::endl;
|
||||
heaps[heapIndex].allocations.removeAt(heapIndex, false);
|
||||
heaps[heapIndex].allocations.removeAt(alloc, false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -371,7 +324,6 @@ void StagingManager::clearPending()
|
||||
|
||||
OStagingBuffer StagingManager::allocateStagingBuffer(uint64 size, VkBufferUsageFlags usage, bool readable)
|
||||
{
|
||||
std::scoped_lock l(lock);
|
||||
for (auto it = freeBuffers.begin(); it != freeBuffers.end(); ++it)
|
||||
{
|
||||
auto& freeBuffer = *it;
|
||||
@@ -381,7 +333,7 @@ OStagingBuffer StagingManager::allocateStagingBuffer(uint64 size, VkBufferUsageF
|
||||
activeBuffers.add(freeBuffer);
|
||||
OStagingBuffer owner = std::move(freeBuffer);
|
||||
freeBuffers.remove(it, false);
|
||||
return owner;
|
||||
return std::move(owner);
|
||||
}
|
||||
}
|
||||
//std::cout << "Creating new stagingbuffer" << std::endl;
|
||||
@@ -421,11 +373,9 @@ OStagingBuffer StagingManager::allocateStagingBuffer(uint64 size, VkBufferUsageF
|
||||
);
|
||||
vkBindBufferMemory(graphics->getDevice(), buffer, stagingBuffer->getMemoryHandle(), stagingBuffer->getOffset());
|
||||
|
||||
std::cout << "Creating new stagingbuffer size " << stagingBuffer->getSize() << std::endl;
|
||||
|
||||
activeBuffers.add(stagingBuffer);
|
||||
|
||||
return stagingBuffer;
|
||||
return std::move(stagingBuffer);
|
||||
}
|
||||
|
||||
void StagingManager::releaseStagingBuffer(OStagingBuffer buffer)
|
||||
@@ -434,8 +384,6 @@ void StagingManager::releaseStagingBuffer(OStagingBuffer buffer)
|
||||
{
|
||||
return;
|
||||
}
|
||||
std::scoped_lock l(lock);
|
||||
activeBuffers.remove(buffer);
|
||||
std::cout << "Releasing stagingbuffer size " << buffer->getSize() << std::endl;
|
||||
freeBuffers.add(std::move(buffer));
|
||||
}
|
||||
@@ -15,13 +15,13 @@ DECLARE_REF(Allocation)
|
||||
class SubAllocation
|
||||
{
|
||||
public:
|
||||
SubAllocation(PAllocation owner, VkDeviceSize allocatedOffset, VkDeviceSize size, VkDeviceSize alignedOffset, VkDeviceSize allocatedSize);
|
||||
SubAllocation(PAllocation owner, VkDeviceSize requestedSize, VkDeviceSize allocatedOffset, VkDeviceSize allocatedSize, VkDeviceSize alignedOffset);
|
||||
~SubAllocation();
|
||||
VkDeviceMemory getHandle() const;
|
||||
|
||||
constexpr VkDeviceSize getSize() const
|
||||
{
|
||||
return size;
|
||||
return requestedSize;
|
||||
}
|
||||
|
||||
constexpr VkDeviceSize getOffset() const
|
||||
@@ -37,7 +37,7 @@ public:
|
||||
|
||||
private:
|
||||
PAllocation owner;
|
||||
VkDeviceSize size;
|
||||
VkDeviceSize requestedSize;
|
||||
VkDeviceSize allocatedOffset;
|
||||
VkDeviceSize alignedOffset;
|
||||
VkDeviceSize allocatedSize;
|
||||
@@ -87,8 +87,7 @@ private:
|
||||
VkDeviceSize bytesUsed;
|
||||
VkDeviceMemory allocatedMemory;
|
||||
Array<PSubAllocation> activeAllocations;
|
||||
Map<VkDeviceSize, OSubAllocation> freeRanges;
|
||||
std::mutex lock;
|
||||
Map<VkDeviceSize, VkDeviceSize> freeRanges;
|
||||
void *mappedPointer;
|
||||
uint8 isDedicated : 1;
|
||||
uint8 canMap : 1;
|
||||
@@ -147,7 +146,6 @@ private:
|
||||
};
|
||||
Array<HeapInfo> heaps;
|
||||
uint32 findMemoryType(uint32 typeBits, VkMemoryPropertyFlags properties);
|
||||
std::mutex lock;
|
||||
PGraphics graphics;
|
||||
VkPhysicalDeviceMemoryProperties memProperties;
|
||||
};
|
||||
@@ -200,7 +198,6 @@ private:
|
||||
PAllocator allocator;
|
||||
Array<OStagingBuffer> freeBuffers;
|
||||
Array<PStagingBuffer> activeBuffers;
|
||||
std::mutex lock;
|
||||
};
|
||||
DEFINE_REF(StagingManager)
|
||||
} // namespace Vulkan
|
||||
|
||||
@@ -76,31 +76,31 @@ public:
|
||||
virtual void updateTextureArray(uint32_t binding, Array<Gfx::PTexture> texture);
|
||||
virtual bool operator<(Gfx::PDescriptorSet other);
|
||||
|
||||
inline bool isCurrentlyBound() const
|
||||
constexpr bool isCurrentlyBound() const
|
||||
{
|
||||
return currentlyBound;
|
||||
}
|
||||
inline bool isCurrentlyInUse() const
|
||||
constexpr bool isCurrentlyInUse() const
|
||||
{
|
||||
return currentlyInUse;
|
||||
}
|
||||
void bind()
|
||||
constexpr void bind()
|
||||
{
|
||||
currentlyBound = true;
|
||||
}
|
||||
void unbind()
|
||||
constexpr void unbind()
|
||||
{
|
||||
currentlyBound = false;
|
||||
}
|
||||
void allocate()
|
||||
constexpr void allocate()
|
||||
{
|
||||
currentlyInUse = true;
|
||||
}
|
||||
void free()
|
||||
constexpr void free()
|
||||
{
|
||||
currentlyInUse = false;
|
||||
}
|
||||
inline VkDescriptorSet getHandle() const
|
||||
constexpr VkDescriptorSet getHandle() const
|
||||
{
|
||||
return setHandle;
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ protected:
|
||||
std::mutex viewportLock;
|
||||
Array<PViewport> viewports;
|
||||
std::mutex allocatedFrameBufferLock;
|
||||
Map<uint32, PFramebuffer> allocatedFramebuffers;
|
||||
Map<uint32, OFramebuffer> allocatedFramebuffers;
|
||||
OAllocator allocator;
|
||||
OStagingManager stagingManager;
|
||||
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
using namespace Seele;
|
||||
using namespace Seele::Vulkan;
|
||||
|
||||
RenderPass::RenderPass(PGraphics graphics, Gfx::ORenderTargetLayout layout, Gfx::PViewport viewport)
|
||||
: Gfx::RenderPass(std::move(layout))
|
||||
RenderPass::RenderPass(PGraphics graphics, Gfx::ORenderTargetLayout _layout, Gfx::PViewport viewport)
|
||||
: Gfx::RenderPass(std::move(_layout))
|
||||
, graphics(graphics)
|
||||
{
|
||||
renderArea.extent.width = viewport->getSizeX();
|
||||
@@ -22,7 +22,7 @@ RenderPass::RenderPass(PGraphics graphics, Gfx::ORenderTargetLayout layout, Gfx:
|
||||
Array<VkAttachmentReference> colorRefs;
|
||||
VkAttachmentReference depthRef;
|
||||
uint32 attachmentCounter = 0;
|
||||
for (auto& inputAttachment : this->layout->inputAttachments)
|
||||
for (auto& inputAttachment : layout->inputAttachments)
|
||||
{
|
||||
PTexture2D image = inputAttachment->getTexture().cast<Texture2D>();
|
||||
VkAttachmentDescription& desc = attachments.add();
|
||||
@@ -40,7 +40,7 @@ RenderPass::RenderPass(PGraphics graphics, Gfx::ORenderTargetLayout layout, Gfx:
|
||||
ref.attachment = attachmentCounter;
|
||||
attachmentCounter++;
|
||||
}
|
||||
for (auto& colorAttachment : this->layout->colorAttachments)
|
||||
for (auto& colorAttachment : layout->colorAttachments)
|
||||
{
|
||||
VkAttachmentDescription& desc = attachments.add();
|
||||
desc.flags = 0;
|
||||
|
||||
@@ -223,16 +223,16 @@ void Window::present()
|
||||
backBufferImages[currentImageIndex]->changeLayout(Gfx::SE_IMAGE_LAYOUT_PRESENT_SRC_KHR);
|
||||
graphics->getGraphicsCommands()->submitCommands(renderFinished[currentImageIndex]);
|
||||
VkSemaphore renderFinishedHandle = renderFinished[currentImageIndex]->getHandle();
|
||||
VkPresentInfoKHR info;
|
||||
info.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
|
||||
info.pNext = nullptr;
|
||||
info.swapchainCount = 1;
|
||||
info.pSwapchains = &swapchain;
|
||||
info.pImageIndices = (uint32 *)¤tImageIndex;
|
||||
info.pResults = 0;
|
||||
info.waitSemaphoreCount = 1;
|
||||
info.pWaitSemaphores = &renderFinishedHandle;
|
||||
|
||||
VkPresentInfoKHR info = {
|
||||
.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR,
|
||||
.pNext = nullptr,
|
||||
.waitSemaphoreCount = 1,
|
||||
.pWaitSemaphores = &renderFinishedHandle,
|
||||
.swapchainCount = 1,
|
||||
.pSwapchains = &swapchain,
|
||||
.pImageIndices = (uint32*)¤tImageIndex,
|
||||
.pResults = 0,
|
||||
};
|
||||
VkResult presentResult = VK_ERROR_OUT_OF_DATE_KHR;
|
||||
// Trial and error
|
||||
while (presentResult != VK_SUCCESS)
|
||||
|
||||
@@ -39,11 +39,11 @@ void Shader::create(const ShaderCreateInfo& createInfo)
|
||||
sessionDesc.flags = 0;
|
||||
sessionDesc.defaultMatrixLayoutMode = SLANG_MATRIX_LAYOUT_COLUMN_MAJOR;
|
||||
Array<slang::PreprocessorMacroDesc> macros;
|
||||
for(auto define : createInfo.defines)
|
||||
for(const auto& [key, val] : createInfo.defines)
|
||||
{
|
||||
macros.add(slang::PreprocessorMacroDesc{
|
||||
.name = define.key,
|
||||
.value = define.value
|
||||
.name = key,
|
||||
.value = val,
|
||||
});
|
||||
}
|
||||
sessionDesc.preprocessorMacroCount = macros.size();
|
||||
@@ -91,10 +91,11 @@ void Shader::create(const ShaderCreateInfo& createInfo)
|
||||
std::cout << (const char*)diagnostics->getBufferPointer() << std::endl;
|
||||
}
|
||||
|
||||
/*for(auto typeParam : createInfo.typeParameter)
|
||||
/*slang::ProgramLayout* layout = moduleComposition->getLayout();
|
||||
for(auto typeParam : createInfo.typeParameter)
|
||||
{
|
||||
Slang::ComPtr<slang::ITypeConformance> typeConformance;
|
||||
session->createTypeConformanceComponentType(moduleComposition->getLayout()->findTypeByName(typeParam), moduleComposition->getLayout()->findTypeByName("IMaterial"), typeConformance.writeRef(), -1, diagnostics.writeRef());
|
||||
session->createTypeConformanceComponentType(layout->findTypeByName(typeParam), layout->findTypeByName("IMaterial"), typeConformance.writeRef(), -1, diagnostics.writeRef());
|
||||
modules.add(typeConformance);
|
||||
if(diagnostics)
|
||||
{
|
||||
@@ -104,7 +105,7 @@ void Shader::create(const ShaderCreateInfo& createInfo)
|
||||
|
||||
Slang::ComPtr<slang::IComponentType> conformingModule;
|
||||
session->createCompositeComponentType(modules.data(), modules.size(), conformingModule.writeRef(), diagnostics.writeRef());
|
||||
*/
|
||||
*/
|
||||
Slang::ComPtr<slang::IComponentType> linkedProgram;
|
||||
moduleComposition->link(linkedProgram.writeRef(), diagnostics.writeRef());
|
||||
if(diagnostics)
|
||||
|
||||
Reference in New Issue
Block a user