[vulkan] Switch over to pushed descriptors

I don't really know why (I need to do some research), but this fixes the
lockups when accessing the matrices UBO. It has made a mess of my
carefully designed uniform binding layout, so I hope I can get bound
descriptor sets working the way I want, but I really need to progress on
the rest of the project.
This commit is contained in:
Bill Currie 2021-01-28 10:49:23 +09:00
parent caa7623a35
commit 64904e2b27
3 changed files with 66 additions and 17 deletions

View file

@ -1,5 +1,5 @@
#version 450
/*
layout (set = 2, binding = 0) uniform sampler2D Texture;
layout (set = 2, binding = 1) uniform sampler2D GlowMap;
layout (set = 2, binding = 2) uniform sampler2D ColorA;
@ -19,7 +19,7 @@ layout (set = 1, binding = 0) uniform Lights {
int light_count;
LightData lights[MaxLights];
};
*/
layout (push_constant) uniform PushConstants {
layout (offset = 80)
vec4 fog;
@ -38,7 +38,7 @@ main (void)
vec4 c;
int i;
vec3 light = vec3 (0);
/*
c = texture (Texture, st);
c += texture (ColorA, st);
c += texture (ColorB, st);
@ -52,4 +52,6 @@ main (void)
}
}
frag_color = c * vec4(light, 1);//fogBlend (c);
*/
frag_color = vec4((normal + 1)/2, 1);
}

View file

@ -110,7 +110,7 @@
},
);
};
quakebsp.textures = {
quakebsp.set = {
flags = push_descriptor;
bindings = (
{
@ -151,6 +151,47 @@
},
);
};
alias.set = {
flags = push_descriptor;
bindings = (
{
binding = 0;
descriptorType = uniform_buffer;
descriptorCount = 1;
stageFlags = vertex;
},
{
binding = 1;
descriptorType = uniform_buffer;
descriptorCount = 1;
stageFlags = fragment;
},
{
binding = 2;
descriptorType = combined_image_sampler;
descriptorCount = 1;
stageFlags = fragment;
},
{
binding = 3;
descriptorType = combined_image_sampler;
descriptorCount = 1;
stageFlags = fragment;
},
{
binding = 4;
descriptorType = combined_image_sampler;
descriptorCount = 1;
stageFlags = fragment;
},
{
binding = 5;
descriptorType = combined_image_sampler;
descriptorCount = 1;
stageFlags = fragment;
},
);
};
alias.matrices = {
bindings = (
{
@ -223,7 +264,7 @@
setLayouts = (twod.set);
};
quakebsp.layout = {
setLayouts = (quakebsp.textures);
setLayouts = (quakebsp.set);
pushConstantRanges = (
{
stageFlags = vertex;
@ -238,7 +279,8 @@
);
};
alias.layout = {
setLayouts = (alias.matrices, alias.lights, alias.textures);
//setLayouts = (alias.matrices, alias.lights, alias.textures);
setLayouts = (alias.set);
pushConstantRanges = (
{
stageFlags = vertex;

View file

@ -123,6 +123,7 @@ Vulkan_DrawAlias (struct entity_s *ent, struct vulkan_ctx_s *ctx)
dfunc->vkCmdPushConstants (aframe->cmd, actx->layout,
VK_SHADER_STAGE_VERTEX_BIT,
64, sizeof (float), &blend);
if (0) {
aframe->imageInfo[0].imageView = get_view (skin->tex, ctx->default_white);
aframe->imageInfo[1].imageView = get_view (skin->glow, ctx->default_black);
aframe->imageInfo[2].imageView = get_view (skin->colora,
@ -135,6 +136,7 @@ Vulkan_DrawAlias (struct entity_s *ent, struct vulkan_ctx_s *ctx)
ALIAS_BUFFER_INFOS, ALIAS_IMAGE_INFOS,
aframe->descriptors
+ ALIAS_BUFFER_INFOS);
}
dfunc->vkCmdDrawIndexed (aframe->cmd, 3 * hdr->mdl.numtris, 1, 0, 0, 0);
}
@ -185,18 +187,21 @@ Vulkan_AliasBegin (vulkan_ctx_t *ctx)
dfunc->vkCmdBindPipeline (cmd, VK_PIPELINE_BIND_POINT_GRAPHICS,
actx->pipeline);
VkDescriptorSet sets[] = {
aframe->descriptors[0].dstSet,
aframe->descriptors[1].dstSet,
};
dfunc->vkCmdBindDescriptorSets (cmd, VK_PIPELINE_BIND_POINT_GRAPHICS,
actx->layout, 0, 2, sets, 0, 0);
//VkDescriptorSet sets[] = {
// aframe->descriptors[0].dstSet,
// aframe->descriptors[1].dstSet,
//};
//dfunc->vkCmdBindDescriptorSets (cmd, VK_PIPELINE_BIND_POINT_GRAPHICS,
// actx->layout, 0, 2, sets, 0, 0);
dfunc->vkCmdPushDescriptorSetKHR (cmd, VK_PIPELINE_BIND_POINT_GRAPHICS,
actx->layout,
0, 1, aframe->descriptors + 0);
VkViewport viewport = {0, 0, vid.width, vid.height, 0, 1};
VkRect2D scissor = { {0, 0}, {vid.width, vid.height} };
dfunc->vkCmdSetViewport (cmd, 0, 1, &viewport);
dfunc->vkCmdSetScissor (cmd, 0, 1, &scissor);
dfunc->vkUpdateDescriptorSets (device->dev, 2, aframe->descriptors, 0, 0);
//dfunc->vkUpdateDescriptorSets (device->dev, 2, aframe->descriptors, 0, 0);
//XXX glsl_Fog_GetColor (fog);
//XXX fog[3] = glsl_Fog_GetDensity () / 64.0;
@ -257,7 +262,7 @@ Vulkan_Alias_Init (vulkan_ctx_t *ctx)
layouts->a[2 * i + 0] = mats;
layouts->a[2 * i + 1] = lights;
}
__auto_type pool = QFV_GetDescriptorPool (ctx, "alias.pool");
//__auto_type pool = QFV_GetDescriptorPool (ctx, "alias.pool");
__auto_type cmdBuffers = QFV_AllocCommandBufferSet (frames, alloca);
QFV_AllocateCommandBuffers (device, ctx->cmdpool, 1, cmdBuffers);
@ -277,7 +282,7 @@ Vulkan_Alias_Init (vulkan_ctx_t *ctx)
dfunc->vkMapMemory (device->dev, actx->light_memory, 0,
frames * requirements.size, 0, (void **) &light_data);
__auto_type sets = QFV_AllocateDescriptorSet (device, pool, layouts);
//__auto_type sets = QFV_AllocateDescriptorSet (device, pool, layouts);
for (size_t i = 0; i < frames; i++) {
__auto_type aframe = &actx->frames.a[i];
aframe->cmd = cmdBuffers->a[i];
@ -289,7 +294,7 @@ Vulkan_Alias_Init (vulkan_ctx_t *ctx)
for (int j = 0; j < ALIAS_BUFFER_INFOS; j++) {
aframe->bufferInfo[j] = base_buffer_info;
aframe->descriptors[j] = base_buffer_write;
aframe->descriptors[j].dstSet = sets->a[ALIAS_BUFFER_INFOS*i + j];
//aframe->descriptors[j].dstSet = sets->a[ALIAS_BUFFER_INFOS*i + j];
aframe->descriptors[j].dstBinding = 0;
aframe->descriptors[j].pBufferInfo = &aframe->bufferInfo[j];
}
@ -302,7 +307,7 @@ Vulkan_Alias_Init (vulkan_ctx_t *ctx)
aframe->descriptors[k].pImageInfo = &aframe->imageInfo[j];
}
}
free (sets);
//free (sets);
}
void