Quesion about best {or decent} pratice around discrptors. paticulary WriteDescriptors

Hello, so, i’m working on a small project to teach myself vulkan, by porting part of my opengl program into vulkan app and i’ve been reading the specification and a bunch of tutorials. But when it comes to descriptors most examples have maybe one UBO, one or two textures samplers etc. my question is how is it best to organized it, currently i have 3

VkDescriptorSetLayoutCreateInfo

Which I organized along, the compute, frag and vertex shader (in the future I was planning on just adding more to those…

My 1st question:: is it better to organize them just across types of pipelines aka have one for the computer and done for the v-f pair?

I liked the idea of just having the sets 0, 1, 2 for each stage… however i could see how this would not scale well.

I have my 3 discriptorpools uniform, com-im-samp, and storage textel.

Note increase the size by my swapchain images vector size.

My vkAllocateDescriptorSets seems to work fine… With my multiply my descriprosetlayouts by 3 in a loop. And uses a loop offset for the VkDescriptorBufferInfo.

My issues arrsies now with VkWriteDescriptorSet

As it appears you set a binding at zero or a numbe rand it goes up.

So do I need to have a VkWriteDescriptorSet for each of my say uniform descriptors that are not in +1 binding order? Should the pBufferInfo

Be an array if i have more then one descriptor?

Basically what the best way to orginzes VkWriteDescriptorSet?

I have included what my needs are…

App layout

struct uniform_buffer_objz

{

alignas(16)glm::mat4 mvp[3];

alignas(16)glm::vec4 orgin;

alignas(16)glm::vec4 partc_attractor[MAX_ATTRACTORS];

alignas(16)bool has_channelz;

alignas(16)bool has_colour_map;

alignas(16)glm::vec4 colour_channelz[MAX_PARTICAL_COLOUR_CHANNELZ];

} uboz;

VkDescriptorSetLayoutBinding

  1. A uniform buffer array{vec4}
  2. A storage textel buffer
  3. A storage textel buffer
  4. A storage textel buffer

—(i may combine them to an array but for the moment their separate)

Fragment shader:

  1. Uniform buffer array{bool*2}
  2. Uniform buffer array{vec4*4}
  3. Combined image sampler
  4. Combined image sampler.

Vertex shader:

  1. Uniform buffer array{mat4*3}

not sure i endup with the best solution however, i did go back an reorganize my descriptorsets and its much cleaner, and simpler to expand. and seems to be more logical in how things are expected to be.

const VkDescriptorSetLayoutBinding active_disc_set_bindingsv2[] = 
{
	//graphicz set 0 startt at [0]
	{
		0,
		VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
		3,
		VK_SHADER_STAGE_VERTEX_BIT,
		NULL
	},

//frag set 0.//startt at [1]
//

	{
	1,
	VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
	1,
	VK_SHADER_STAGE_FRAGMENT_BIT,
	NULL	
	},

	{
	 2,
	 VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
	 MAX_PARTICAL_COLOUR_CHANNELZ,
	 VK_SHADER_STAGE_FRAGMENT_BIT,
	 NULL
	},

	{
	 3,
	 VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
	 1,
	 VK_SHADER_STAGE_FRAGMENT_BIT,
	 NULL
	},

	{
	 4,
	 VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
	 1,
	 VK_SHADER_STAGE_FRAGMENT_BIT,
     NULL
	},

	//compute set 1 //startt at [5]
	{
	 0,
	 VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
	 1,
	 VK_SHADER_STAGE_COMPUTE_BIT,
	 NULL
	},
	{
	 1,
	 VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
	 MAX_ATTRACTORS,
	 VK_SHADER_STAGE_COMPUTE_BIT,
	 NULL
	},

	{
	2,
	VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER,
	1,
	VK_SHADER_STAGE_COMPUTE_BIT,
	NULL
	},
	{
	3,
	VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER,
	1,
	VK_SHADER_STAGE_COMPUTE_BIT,
	NULL
	},
	{
	4,
	VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER,
	1,
	VK_SHADER_STAGE_COMPUTE_BIT,
	NULL
	}
};


const VkDescriptorSetLayoutCreateInfo desc_set_layouts_INFOv2[]=
{
{
     VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
	 NULL,
	 0,
	 5,
	&active_disc_set_bindingsv2[0]
},

{
     VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
	 NULL,
	 0,
	 5,
	 &active_disc_set_bindingsv2[5]
}};

and i curretly have two UBO write descriptors one my one graphics pipe, and one for my compute pipe. my plan would be for each new pipeline or shaderchain have a diffrent one (plus add my other stroage, and textel ones etc

        descriptorWrites[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
        descriptorWrites[0].dstSet = vk_occurance.descriptorSets[0];
        descriptorWrites[0].dstBinding = 0;
        descriptorWrites[0].dstArrayElement = 0;
        descriptorWrites[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
        descriptorWrites[0].descriptorCount = 3;
        descriptorWrites[0].pBufferInfo = &bufferinfoz_graph01[0];
        descriptorWrites[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
        descriptorWrites[1].dstSet = vk_occurance.descriptorSets[1];
        descriptorWrites[1].dstBinding = 0;
        descriptorWrites[1].dstArrayElement = 0;
        descriptorWrites[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
        descriptorWrites[1].descriptorCount = 2;
        descriptorWrites[1].pBufferInfo = &bufferinfoz_graph01[1];

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.