zink: implement Vk_EXT_index_type_uint8

this is a simple extension that enables using uint8-sized index buffers,
which lets us avoid having those go through primconvert

Reviewed-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5712>
This commit is contained in:
Mike Blumenkrantz 2020-07-01 09:13:35 -04:00 committed by Marge Bot
parent 53372175c9
commit f2f57ef9f7
3 changed files with 33 additions and 5 deletions

View file

@ -210,7 +210,7 @@ zink_draw_vbo(struct pipe_context *pctx,
if (dinfo->mode >= PIPE_PRIM_QUADS ||
dinfo->mode == PIPE_PRIM_LINE_LOOP ||
dinfo->index_size == 1) {
(dinfo->index_size == 1 && !screen->have_EXT_index_type_uint8)) {
if (!u_trim_pipe_prim(dinfo->mode, (unsigned *)&dinfo->count))
return;
@ -424,8 +424,21 @@ zink_draw_vbo(struct pipe_context *pctx,
}
if (dinfo->index_size > 0) {
assert(dinfo->index_size != 1);
VkIndexType index_type = dinfo->index_size == 2 ? VK_INDEX_TYPE_UINT16 : VK_INDEX_TYPE_UINT32;
VkIndexType index_type;
switch (dinfo->index_size) {
case 1:
assert(screen->have_EXT_index_type_uint8);
index_type = VK_INDEX_TYPE_UINT8_EXT;
break;
case 2:
index_type = VK_INDEX_TYPE_UINT16;
break;
case 4:
index_type = VK_INDEX_TYPE_UINT32;
break;
default:
unreachable("unknown index size!");
}
struct zink_resource *res = zink_resource(index_buffer);
vkCmdBindIndexBuffer(batch->cmdbuf, res->buffer, index_offset, index_type);
zink_batch_reference_resoure(batch, res);

View file

@ -759,7 +759,7 @@ static struct pipe_screen *
zink_internal_create_screen(struct sw_winsys *winsys, int fd)
{
struct zink_screen *screen = CALLOC_STRUCT(zink_screen);
bool have_tf_ext = false, have_cond_render_ext = false;
bool have_tf_ext = false, have_cond_render_ext = false, have_EXT_index_type_uint8 = false;
if (!screen)
return NULL;
@ -798,6 +798,9 @@ zink_internal_create_screen(struct sw_winsys *winsys, int fd)
if (!strcmp(extensions[i].extensionName,
VK_EXT_TRANSFORM_FEEDBACK_EXTENSION_NAME))
have_tf_ext = true;
if (!strcmp(extensions[i].extensionName,
VK_EXT_INDEX_TYPE_UINT8_EXTENSION_NAME))
have_EXT_index_type_uint8 = true;
}
FREE(extensions);
@ -806,6 +809,7 @@ zink_internal_create_screen(struct sw_winsys *winsys, int fd)
VkPhysicalDeviceFeatures2 feats = {};
VkPhysicalDeviceTransformFeedbackFeaturesEXT tf_feats = {};
VkPhysicalDeviceConditionalRenderingFeaturesEXT cond_render_feats = {};
VkPhysicalDeviceIndexTypeUint8FeaturesEXT index_uint8_feats = {};
feats.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
if (have_tf_ext) {
@ -818,12 +822,19 @@ zink_internal_create_screen(struct sw_winsys *winsys, int fd)
cond_render_feats.pNext = feats.pNext;
feats.pNext = &cond_render_feats;
}
if (have_EXT_index_type_uint8) {
index_uint8_feats.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INDEX_TYPE_UINT8_FEATURES_EXT;
index_uint8_feats.pNext = feats.pNext;
feats.pNext = &index_uint8_feats;
}
vkGetPhysicalDeviceFeatures2(screen->pdev, &feats);
memcpy(&screen->feats, &feats.features, sizeof(screen->feats));
if (have_tf_ext && tf_feats.transformFeedback)
screen->have_EXT_transform_feedback = true;
if (have_cond_render_ext && cond_render_feats.conditionalRendering)
screen->have_EXT_conditional_rendering = true;
if (have_EXT_index_type_uint8 && index_uint8_feats.indexTypeUint8)
screen->have_EXT_index_type_uint8 = true;
VkPhysicalDeviceProperties2 props = {};
props.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2;
@ -855,7 +866,7 @@ zink_internal_create_screen(struct sw_winsys *winsys, int fd)
* this requires us to pass the whole VkPhysicalDeviceFeatures2 struct
*/
dci.pNext = &feats;
const char *extensions[5] = {
const char *extensions[6] = {
VK_KHR_MAINTENANCE1_EXTENSION_NAME,
};
num_extensions = 1;
@ -873,6 +884,9 @@ zink_internal_create_screen(struct sw_winsys *winsys, int fd)
if (screen->have_EXT_conditional_rendering)
extensions[num_extensions++] = VK_EXT_CONDITIONAL_RENDERING_EXTENSION_NAME;
if (screen->have_EXT_index_type_uint8)
extensions[num_extensions++] = VK_EXT_INDEX_TYPE_UINT8_EXTENSION_NAME;
if (screen->have_EXT_transform_feedback)
extensions[num_extensions++] = VK_EXT_TRANSFORM_FEEDBACK_EXTENSION_NAME;
assert(num_extensions <= ARRAY_SIZE(extensions));

View file

@ -54,6 +54,7 @@ struct zink_screen {
bool have_KHR_external_memory_fd;
bool have_EXT_conditional_rendering;
bool have_EXT_transform_feedback;
bool have_EXT_index_type_uint8;
bool have_X8_D24_UNORM_PACK32;
bool have_D24_UNORM_S8_UINT;