[vulkan] Render object id to a buffer

Currently the instance id is written (with the idea that it can be
mapped back to entity in C). The plan is to use it for mouse picking.
This commit is contained in:
Bill Currie 2023-06-30 03:34:16 +09:00
parent d45b76313c
commit e2b6e0728e
4 changed files with 49 additions and 3 deletions

View file

@ -155,6 +155,7 @@ QFV_CreateDevice (vulkan_ctx_t *ctx, const char **extensions)
.multiviewGeometryShader = 1,
};
VkPhysicalDeviceFeatures features = {
.independentBlend = 1,
.geometryShader = 1,
.multiViewport = 1,
.fragmentStoresAndAtomics = 1,

View file

@ -1012,6 +1012,11 @@ images = {
usage = color_attachment|input_attachment|sampled;
format = $render_output.format;
};
entid = {
@inherit = $image_base;
format = r32_uint;
}
};
imageviews = {
depth = {
@ -1091,6 +1096,11 @@ imageviews = {
image = cube_output;
format = $render_output.format;
};
entid = {
@inherit = $view_base;
image = entid;
};
};
output = {
view = $output;
@ -1499,7 +1509,7 @@ renderpasses = {
);
layout = $compose.layout;
};
/* debug = {
/*debug = {
@inherit = $compose_base;
color = $color.lights;
@ -1594,6 +1604,16 @@ renderpasses = {
layers = 1;
attachments = {
output = $swapchain;
entid = {
@inherit = $attachment_base;
format = $images.entid.format;
loadOp = clear;
storeOp = store;
clearValue = {
color = { int32 = (-1, -1, -1, -1); };
};
view = entid;
};
};
};
subpasses = {
@ -1652,6 +1672,26 @@ renderpasses = {
);
layout = $fisheye.layout;
};
};
};
slice = {
color = $color.slice;
dependencies = {
compose = $color_dependency;
};
attachments = {
color = {
output = {
layout = color_attachment_optimal;
blend = $alpha_blend;
};
entid = {
layout = color_attachment_optimal;
blend = $blend_disable;
};
};
};
pipelines = {
slice = {
@inherit = $compose_base;
@ -1668,7 +1708,7 @@ renderpasses = {
inputAssembly = $slice.inputAssembly;
layout = $slice.layout;
};
lines = {
/*lines = {
@inherit = $compose_base;
color = $color.lines;
@ -1683,7 +1723,7 @@ renderpasses = {
vertexInput = $lines.vertexInput;
inputAssembly = $lines.inputAssembly;
layout = $lines.layout;
};
};*/
};
};
};

View file

@ -17,6 +17,7 @@ layout (location = 3) in vec2 glyph_offset; // for 9-slice
layout (location = 0) out vec2 uv;
layout (location = 1) out vec4 color;
layout (location = 2) out uint id;
void
main (void)
@ -29,4 +30,5 @@ main (void)
// texture uv stored in glyph components 2 and 3
uv = glyph.pq;
color = glyph_color;
id = gl_InstanceIndex;
}

View file

@ -4,8 +4,10 @@ layout (set = 1, binding = 0) uniform sampler2D Texture;
layout (location = 0) in vec2 st;
layout (location = 1) in vec4 color;
layout (location = 2) in flat uint id;
layout (location = 0) out vec4 frag_color;
layout (location = 1) out uint entid;
void
main (void)
@ -14,4 +16,5 @@ main (void)
pix = texture (Texture, st);
frag_color = pix * color;
entid = id;
}