Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed ViewDependentState lightData and viewportData to use storage buffer rather than uniform buffer to allow variable sized arrays to be used. #1143

Merged
merged 1 commit into from
Mar 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion include/vsg/state/ViewDependentState.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,17 +135,18 @@ namespace vsg

ref_ptr<vec4Array> lightData;
ref_ptr<BufferInfo> lightDataBufferInfo;
ref_ptr<DescriptorBuffer> lightDataDescriptor;

ref_ptr<vec4Array> viewportData;
ref_ptr<BufferInfo> viewportDataBufferInfo;
ref_ptr<DescriptorBuffer> viewportDescriptor;

ref_ptr<Image> shadowDepthImage;
ref_ptr<DescriptorImage> shadowMapImages;
ref_ptr<DescriptorImage> shadowMapDirectSamplerDescriptor;
ref_ptr<DescriptorImage> shadowMapShadowSamplerDescriptor;

ref_ptr<DescriptorSetLayout> descriptorSetLayout;
ref_ptr<DescriptorBuffer> descriptor;
ref_ptr<DescriptorSet> descriptorSet;

// shadow map hints
Expand Down
10 changes: 6 additions & 4 deletions src/vsg/state/ViewDependentState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,13 @@ void ViewDependentState::init(ResourceRequirements& requirements)
lightData->properties.dataVariance = DYNAMIC_DATA_TRANSFER_AFTER_RECORD;
lightDataBufferInfo = BufferInfo::create(lightData.get());

lightDataDescriptor = DescriptorBuffer::create(BufferInfoList{lightDataBufferInfo}, 0, 0, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER); // hardwired position for now

viewportData = vec4Array::create(maxViewports);
viewportData->properties.dataVariance = DYNAMIC_DATA_TRANSFER_AFTER_RECORD;
viewportDataBufferInfo = BufferInfo::create(viewportData.get());

descriptor = DescriptorBuffer::create(BufferInfoList{lightDataBufferInfo, viewportDataBufferInfo}, 0); // hardwired position for now
viewportDescriptor = DescriptorBuffer::create(BufferInfoList{viewportDataBufferInfo}, 1, 0, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER); // hardwired position for now

// set up ShadowMaps
auto shadowMapDirectSampler = Sampler::create();
Expand Down Expand Up @@ -329,15 +331,15 @@ void ViewDependentState::init(ResourceRequirements& requirements)
}

DescriptorSetLayoutBindings descriptorBindings{
VkDescriptorSetLayoutBinding{0, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1, VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, nullptr}, // lightData
VkDescriptorSetLayoutBinding{1, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1, VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, nullptr}, // viewportData
VkDescriptorSetLayoutBinding{0, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, nullptr}, // lightData
VkDescriptorSetLayoutBinding{1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, nullptr}, // viewportData
VkDescriptorSetLayoutBinding{2, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr}, // shadow map 2D texture array
VkDescriptorSetLayoutBinding{3, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr}, // shadow map direct sampler
VkDescriptorSetLayoutBinding{4, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr}, // shadow map shadow sampler
};

descriptorSetLayout = DescriptorSetLayout::create(descriptorBindings);
descriptorSet = DescriptorSet::create(descriptorSetLayout, Descriptors{descriptor, shadowMapImages, shadowMapDirectSamplerDescriptor, shadowMapShadowSamplerDescriptor});
descriptorSet = DescriptorSet::create(descriptorSetLayout, Descriptors{lightDataDescriptor, viewportDescriptor, shadowMapImages, shadowMapDirectSamplerDescriptor, shadowMapShadowSamplerDescriptor});

// if not active then don't enable shadow maps
if (maxShadowMaps == 0) return;
Expand Down
Loading
Loading