-
I have attempted two approaches to pass a uniform struct to a shader, and the first one failed while the second one succeeded. My goal is to dynamically change the values in this uniform struct during the rendering loop. I believe the first approach is more in line with the VSG (VulkanSceneGraph) specification, but I'm unsure how to modify it. I would appreciate any suggestions or advice from experts.
PlaneInfo planeInfo; auto descriptorBuffer = vsg::DescriptorBuffer::create(DataList{ planeInfo.m_indeices, planeInfo.m_color}, 0); auto descriptorSet = vsg::DescriptorSet::create(descriptorSetLayout, vsg::Descriptors{ descriptorBuffer });
auto bufferSize = sizeof(PlaneInfo); auto uniformBufferInfo = vsg::BufferInfo::create(); PlaneInfo planeInfo; void* data; auto descriptorBuffer = vsg::DescriptorBuffer::create(BufferInfoList{ uniformBufferInfo }, 0, 0, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER); auto descriptorSet = vsg::DescriptorSet::create(descriptorSetLayout, vsg::Descriptors{ descriptorBuffer }); |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 5 replies
-
I don't know why you have the PlaneInfo defined in case 1, it should be irrelevant to the operation. However, in general just assigning the Data to DescrptoriBuffer as you have done should be OK, and they only bit missing will be calling data->dirty(). You don't say whether you've done this or not, or in what way it doesn't work. The second doesn't included PlateInfo, is it the same definition as case 1? If so I can't see how passing pointers to objects in main memory will ever work when passing data to the GPU. Could it be that case 1 actually worked and case 2 failed and just typed things up wrong? My recommendation is to have a look at the vsgclip example, this illustrates passing dynamically updated uniform data. It is possible to allocate a buffer and then map it and copy to it, but you'll need to think about buffering of the copy region to avoid updating data while it's still being rendered by a previous frame, and the map/unmap is expensive. The vsg::TransferData class does this buffering for you and avoids the map/unmap. as well as being automatically set up for you, so it's more robust, faster and simpler than manually managing and mapping the buffer. When copying packed data you can use your own struct {} and then attach this to the DescriptorBuffer as data via vsg::Value template. This is how material structs are passed to the GPU. See include/vsg/state/material.h to see how this is done. |
Beta Was this translation helpful? Give feedback.
-
I loaded the vsgt model in the vsgclip, passing uniform to the gpu was fine. But loading gltf model can not pass uniform to gpu, May I ask have encountered such a problem |
Beta Was this translation helpful? Give feedback.
-
I want to add some functionality to vsg's default shader, or write a shader to replace vsg's default shader |
Beta Was this translation helpful? Give feedback.
-
Great. Thank you so much. I'm looking forward to it. |
Beta Was this translation helpful? Give feedback.
-
Robert Sfield, you are amazing |
Beta Was this translation helpful? Give feedback.
I don't know why you have the PlaneInfo defined in case 1, it should be irrelevant to the operation. However, in general just assigning the Data to DescrptoriBuffer as you have done should be OK, and they only bit missing will be calling data->dirty(). You don't say whether you've done this or not, or in what way it doesn't work.
The second doesn't included PlateInfo, is it the same definition as case 1? If so I can't see how passing pointers to objects in main memory will ever work when passing data to the GPU.
Could it be that case 1 actually worked and case 2 failed and just typed things up wrong?
My recommendation is to have a look at the vsgclip example, this illustrates passing dyna…