Changing descriptor update signature

This commit is contained in:
Dynamitos
2024-09-27 15:57:37 +02:00
parent 1c7a3db939
commit 242acdab58
28 changed files with 240 additions and 225 deletions
+70 -75
View File
@@ -163,15 +163,15 @@ DescriptorSet::DescriptorSet(PGraphics graphics, PDescriptorPool owner)
graphics(graphics), owner(owner) {
boundResources.resize(owner->getLayout()->getBindings().size());
for (uint32 i = 0; i < boundResources.size(); ++i) {
if(owner->getLayout()->getBindings()[i].descriptorCount > 1) std::abort();
boundResources[i].resize(owner->getLayout()->getBindings()[i].descriptorCount);
}
}
DescriptorSet::~DescriptorSet() {}
void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PUniformBuffer uniformBuffer) {
void DescriptorSet::updateBuffer(uint32_t binding, uint32 index, Gfx::PUniformBuffer uniformBuffer) {
PUniformBuffer vulkanBuffer = uniformBuffer.cast<UniformBuffer>();
if (boundResources[binding] == vulkanBuffer->getAlloc()) {
if (boundResources[binding][index] == vulkanBuffer->getAlloc()) {
return;
}
@@ -186,18 +186,18 @@ void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PUniformBuffer uniformBu
.pNext = nullptr,
.dstSet = setHandle,
.dstBinding = binding,
.dstArrayElement = 0,
.dstArrayElement = index,
.descriptorCount = 1,
.descriptorType = cast(layout->getBindings()[binding].descriptorType),
.pBufferInfo = &bufferInfos.back(),
});
boundResources[binding] = vulkanBuffer->getAlloc();
boundResources[binding][index] = vulkanBuffer->getAlloc();
}
void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PShaderBuffer shaderBuffer) {
void DescriptorSet::updateBuffer(uint32_t binding, uint32 index, Gfx::PShaderBuffer shaderBuffer) {
PShaderBuffer vulkanBuffer = shaderBuffer.cast<ShaderBuffer>();
if (boundResources[binding] == vulkanBuffer->getAlloc()) {
if (boundResources[binding][index] == vulkanBuffer->getAlloc()) {
return;
}
@@ -211,18 +211,18 @@ void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PShaderBuffer shaderBuff
.pNext = nullptr,
.dstSet = setHandle,
.dstBinding = binding,
.dstArrayElement = 0,
.dstArrayElement = index,
.descriptorCount = 1,
.descriptorType = cast(layout->getBindings()[binding].descriptorType),
.pBufferInfo = &bufferInfos.back(),
});
boundResources[binding] = vulkanBuffer->getAlloc();
boundResources[binding][index] = vulkanBuffer->getAlloc();
}
void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PIndexBuffer indexBuffer) {
void DescriptorSet::updateBuffer(uint32_t binding, uint32 index, Gfx::PIndexBuffer indexBuffer) {
PIndexBuffer vulkanBuffer = indexBuffer.cast<IndexBuffer>();
if (boundResources[binding] == vulkanBuffer->getAlloc()) {
if (boundResources[binding][index] == vulkanBuffer->getAlloc()) {
return;
}
@@ -236,18 +236,18 @@ void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PIndexBuffer indexBuffer
.pNext = nullptr,
.dstSet = setHandle,
.dstBinding = binding,
.dstArrayElement = 0,
.dstArrayElement = index,
.descriptorCount = 1,
.descriptorType = cast(layout->getBindings()[binding].descriptorType),
.pBufferInfo = &bufferInfos.back(),
});
boundResources[binding] = vulkanBuffer->getAlloc();
boundResources[binding][index] = vulkanBuffer->getAlloc();
}
void DescriptorSet::updateSampler(uint32_t binding, Gfx::PSampler samplerState) {
void DescriptorSet::updateSampler(uint32_t binding, uint32 index, Gfx::PSampler samplerState) {
PSampler vulkanSampler = samplerState.cast<Sampler>();
if (boundResources[binding] == vulkanSampler->getHandle()) {
if (boundResources[binding][index] == vulkanSampler->getHandle()) {
return;
}
@@ -262,24 +262,24 @@ void DescriptorSet::updateSampler(uint32_t binding, Gfx::PSampler samplerState)
.pNext = nullptr,
.dstSet = setHandle,
.dstBinding = binding,
.dstArrayElement = 0,
.dstArrayElement = index,
.descriptorCount = 1,
.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER,
.pImageInfo = &imageInfos.back(),
});
boundResources[binding] = vulkanSampler->getHandle();
boundResources[binding][index] = vulkanSampler->getHandle();
}
void DescriptorSet::updateTexture(uint32_t binding, Gfx::PTexture texture, Gfx::PSampler samplerState) {
void DescriptorSet::updateTexture(uint32_t binding, uint32 index, Gfx::PTexture2D texture) {
TextureBase* vulkanTexture = texture.cast<TextureBase>().getHandle();
if (boundResources[binding] == vulkanTexture->getHandle()) {
if (boundResources[binding][index] == vulkanTexture->getHandle()) {
return;
}
// It is assumed that the image is in the correct layout
imageInfos.add(VkDescriptorImageInfo{
.sampler = samplerState != nullptr ? samplerState.cast<Sampler>()->getSampler() : VK_NULL_HANDLE,
.sampler = VK_NULL_HANDLE,
.imageView = vulkanTexture->getView(),
.imageLayout = cast(vulkanTexture->getLayout()),
});
@@ -288,73 +288,68 @@ void DescriptorSet::updateTexture(uint32_t binding, Gfx::PTexture texture, Gfx::
.pNext = nullptr,
.dstSet = setHandle,
.dstBinding = binding,
.dstArrayElement = 0,
.dstArrayElement = index,
.descriptorCount = 1,
.descriptorType = cast(layout->getBindings()[binding].descriptorType),
.pImageInfo = &imageInfos.back(),
});
boundResources[binding] = vulkanTexture->getHandle();
boundResources[binding][index] = vulkanTexture->getHandle();
}
void DescriptorSet::updateTextureArray(uint32_t binding, Array<Gfx::PTexture2D> textures) {
// maybe make this a parameter?
uint32 arrayElement = 0;
for (auto& gfxTexture : textures) {
TextureBase* vulkanTexture = gfxTexture.cast<TextureBase>().getHandle();
if (boundResources[binding+arrayElement] == vulkanTexture->getHandle()) {
continue;
}
imageInfos.add(VkDescriptorImageInfo{
.sampler = VK_NULL_HANDLE,
.imageView = vulkanTexture->getView(),
.imageLayout = cast(vulkanTexture->getLayout()),
});
boundResources[binding+arrayElement] = vulkanTexture->getHandle();
writeDescriptors.add(VkWriteDescriptorSet{
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
.pNext = nullptr,
.dstSet = setHandle,
.dstBinding = binding,
.dstArrayElement = arrayElement++,
.descriptorCount = 1,
.descriptorType = cast(layout->getBindings()[binding].descriptorType),
.pImageInfo = &imageInfos.back(),
});
void DescriptorSet::updateTexture(uint32_t binding, uint32 index, Gfx::PTexture3D texture) {
TextureBase* vulkanTexture = texture.cast<TextureBase>().getHandle();
if (boundResources[binding][index] == vulkanTexture->getHandle()) {
return;
}
// It is assumed that the image is in the correct layout
imageInfos.add(VkDescriptorImageInfo{
.sampler = VK_NULL_HANDLE,
.imageView = vulkanTexture->getView(),
.imageLayout = cast(vulkanTexture->getLayout()),
});
writeDescriptors.add(VkWriteDescriptorSet{
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
.pNext = nullptr,
.dstSet = setHandle,
.dstBinding = binding,
.dstArrayElement = index,
.descriptorCount = 1,
.descriptorType = cast(layout->getBindings()[binding].descriptorType),
.pImageInfo = &imageInfos.back(),
});
boundResources[binding][index] = vulkanTexture->getHandle();
}
void DescriptorSet::updateSamplerArray(uint32_t binding, Array<Gfx::PSampler> samplers) {
// maybe make this a parameter?
uint32 arrayElement = 0;
for (auto& gfxSampler : samplers) {
PSampler vulkanSampler = gfxSampler.cast<Sampler>();
if (boundResources[binding+arrayElement] == vulkanSampler->getHandle()) {
continue;
}
imageInfos.add(VkDescriptorImageInfo{
.sampler = vulkanSampler->getHandle()->sampler,
.imageView = VK_NULL_HANDLE,
.imageLayout = VK_IMAGE_LAYOUT_UNDEFINED,
});
VkDescriptorType descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
boundResources[binding] = vulkanSampler->getHandle();
writeDescriptors.add(VkWriteDescriptorSet{
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
.pNext = nullptr,
.dstSet = setHandle,
.dstBinding = binding,
.dstArrayElement = arrayElement++,
.descriptorCount = 1,
.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER,
.pImageInfo = &imageInfos.back(),
});
void DescriptorSet::updateTexture(uint32_t binding, uint32 index, Gfx::PTextureCube texture) {
TextureBase* vulkanTexture = texture.cast<TextureBase>().getHandle();
if (boundResources[binding][index] == vulkanTexture->getHandle()) {
return;
}
// It is assumed that the image is in the correct layout
imageInfos.add(VkDescriptorImageInfo{
.sampler = VK_NULL_HANDLE,
.imageView = vulkanTexture->getView(),
.imageLayout = cast(vulkanTexture->getLayout()),
});
writeDescriptors.add(VkWriteDescriptorSet{
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
.pNext = nullptr,
.dstSet = setHandle,
.dstBinding = binding,
.dstArrayElement = index,
.descriptorCount = 1,
.descriptorType = cast(layout->getBindings()[binding].descriptorType),
.pImageInfo = &imageInfos.back(),
});
boundResources[binding][index] = vulkanTexture->getHandle();
}
void DescriptorSet::updateAccelerationStructure(uint32 binding, Gfx::PTopLevelAS as) {
void DescriptorSet::updateAccelerationStructure(uint32 binding, uint32 index, Gfx::PTopLevelAS as) {
auto tlas = as.cast<TopLevelAS>();
accelerationInfos.add(VkWriteDescriptorSetAccelerationStructureKHR{
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET_ACCELERATION_STRUCTURE_KHR,
@@ -367,7 +362,7 @@ void DescriptorSet::updateAccelerationStructure(uint32 binding, Gfx::PTopLevelAS
.pNext = &accelerationInfos.back(),
.dstSet = setHandle,
.dstBinding = binding,
.dstArrayElement = 0,
.dstArrayElement = index,
.descriptorCount = 1,
.descriptorType = VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR,
});