zink: break out image/buffer create info structs into helper funcs

Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9788>
This commit is contained in:
Mike Blumenkrantz 2020-12-12 00:40:19 -05:00
parent cde60ab179
commit d922850e36

View file

@ -179,19 +179,9 @@ aspect_from_format(enum pipe_format fmt)
return VK_IMAGE_ASPECT_COLOR_BIT;
}
static struct zink_resource_object *
resource_object_create(struct zink_screen *screen, const struct pipe_resource *templ, struct winsys_handle *whandle, bool *optimal_tiling)
static VkBufferCreateInfo
create_bci(struct zink_screen *screen, const struct pipe_resource *templ, unsigned bind)
{
struct zink_resource_object *obj = CALLOC_STRUCT(zink_resource_object);
if (!obj)
return NULL;
VkMemoryRequirements reqs = {};
VkMemoryPropertyFlags flags;
pipe_reference_init(&obj->reference, 1);
util_dynarray_init(&obj->desc_set_refs.refs, NULL);
if (templ->target == PIPE_BUFFER) {
VkBufferCreateInfo bci = {};
bci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
bci.size = templ->width0;
@ -204,7 +194,7 @@ resource_object_create(struct zink_screen *screen, const struct pipe_resource *t
bci.usage |= VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
/* apparently gallium thinks these are the jack-of-all-trades bind types */
if (templ->bind & (PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_QUERY_BUFFER)) {
if (bind & (PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_QUERY_BUFFER)) {
bci.usage |= VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT |
VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT |
VK_BUFFER_USAGE_INDIRECT_BUFFER_BIT |
@ -216,45 +206,40 @@ resource_object_create(struct zink_screen *screen, const struct pipe_resource *t
bci.usage |= VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
}
if (templ->bind & PIPE_BIND_VERTEX_BUFFER)
if (bind & PIPE_BIND_VERTEX_BUFFER)
bci.usage |= VK_BUFFER_USAGE_VERTEX_BUFFER_BIT |
VK_BUFFER_USAGE_INDEX_BUFFER_BIT |
VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT |
VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT |
VK_BUFFER_USAGE_TRANSFORM_FEEDBACK_BUFFER_BIT_EXT;
if (templ->bind & PIPE_BIND_INDEX_BUFFER)
if (bind & PIPE_BIND_INDEX_BUFFER)
bci.usage |= VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
if (templ->bind & PIPE_BIND_CONSTANT_BUFFER)
if (bind & PIPE_BIND_CONSTANT_BUFFER)
bci.usage |= VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
if (templ->bind & PIPE_BIND_SHADER_BUFFER)
if (bind & PIPE_BIND_SHADER_BUFFER)
bci.usage |= VK_BUFFER_USAGE_STORAGE_BUFFER_BIT;
if (templ->bind & PIPE_BIND_COMMAND_ARGS_BUFFER)
if (bind & PIPE_BIND_COMMAND_ARGS_BUFFER)
bci.usage |= VK_BUFFER_USAGE_INDIRECT_BUFFER_BIT;
if (templ->bind == (PIPE_BIND_STREAM_OUTPUT | PIPE_BIND_CUSTOM)) {
if (bind == (PIPE_BIND_STREAM_OUTPUT | PIPE_BIND_CUSTOM)) {
bci.usage |= VK_BUFFER_USAGE_TRANSFORM_FEEDBACK_COUNTER_BUFFER_BIT_EXT;
} else if (templ->bind & PIPE_BIND_STREAM_OUTPUT) {
} else if (bind & PIPE_BIND_STREAM_OUTPUT) {
bci.usage |= VK_BUFFER_USAGE_VERTEX_BUFFER_BIT |
VK_BUFFER_USAGE_INDEX_BUFFER_BIT |
VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT |
VK_BUFFER_USAGE_TRANSFORM_FEEDBACK_BUFFER_BIT_EXT;
}
return bci;
}
if (vkCreateBuffer(screen->dev, &bci, NULL, &obj->buffer) != VK_SUCCESS) {
debug_printf("vkCreateBuffer failed\n");
goto fail1;
}
vkGetBufferMemoryRequirements(screen->dev, obj->buffer, &reqs);
flags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
obj->is_buffer = true;
} else {
static VkImageCreateInfo
create_ici(struct zink_screen *screen, const struct pipe_resource *templ, unsigned bind)
{
VkImageCreateInfo ici = {};
VkExternalMemoryImageCreateInfo emici = {};
ici.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
ici.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
@ -276,7 +261,7 @@ resource_object_create(struct zink_screen *screen, const struct pipe_resource *t
case PIPE_TEXTURE_3D:
ici.imageType = VK_IMAGE_TYPE_3D;
if (templ->bind & PIPE_BIND_RENDER_TARGET)
if (bind & PIPE_BIND_RENDER_TARGET)
ici.flags |= VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT;
break;
@ -294,21 +279,12 @@ resource_object_create(struct zink_screen *screen, const struct pipe_resource *t
ici.mipLevels = templ->last_level + 1;
ici.arrayLayers = MAX2(templ->array_size, 1);
ici.samples = templ->nr_samples ? templ->nr_samples : VK_SAMPLE_COUNT_1_BIT;
ici.tiling = templ->bind & PIPE_BIND_LINEAR ? VK_IMAGE_TILING_LINEAR : VK_IMAGE_TILING_OPTIMAL;
ici.tiling = bind & PIPE_BIND_LINEAR ? VK_IMAGE_TILING_LINEAR : VK_IMAGE_TILING_OPTIMAL;
if (templ->target == PIPE_TEXTURE_CUBE ||
templ->target == PIPE_TEXTURE_CUBE_ARRAY)
ici.arrayLayers *= 6;
if (templ->bind & PIPE_BIND_SHARED) {
emici.sType = VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_IMAGE_CREATE_INFO;
emici.handleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT;
ici.pNext = &emici;
/* TODO: deal with DRM modifiers here */
ici.tiling = VK_IMAGE_TILING_LINEAR;
}
if (templ->usage == PIPE_USAGE_STAGING)
ici.tiling = VK_IMAGE_TILING_LINEAR;
@ -318,8 +294,8 @@ resource_object_create(struct zink_screen *screen, const struct pipe_resource *t
VK_IMAGE_USAGE_SAMPLED_BIT;
if ((templ->nr_samples <= 1 || screen->info.feats.features.shaderStorageImageMultisample) &&
(templ->bind & PIPE_BIND_SHADER_IMAGE ||
(templ->bind & PIPE_BIND_SAMPLER_VIEW && templ->flags & PIPE_RESOURCE_FLAG_TEXTURING_MORE_LIKELY))) {
(bind & PIPE_BIND_SHADER_IMAGE ||
(bind & PIPE_BIND_SAMPLER_VIEW && templ->flags & PIPE_RESOURCE_FLAG_TEXTURING_MORE_LIKELY))) {
VkFormatProperties props = screen->format_props[templ->format];
/* gallium doesn't provide any way to actually know whether this will be used as a shader image,
* so we have to just assume and set the bit if it's available
@ -328,23 +304,62 @@ resource_object_create(struct zink_screen *screen, const struct pipe_resource *t
(ici.tiling == VK_IMAGE_TILING_OPTIMAL && props.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT))
ici.usage |= VK_IMAGE_USAGE_STORAGE_BIT;
}
if (optimal_tiling)
*optimal_tiling = ici.tiling != VK_IMAGE_TILING_LINEAR;
if (templ->bind & PIPE_BIND_RENDER_TARGET)
if (bind & PIPE_BIND_RENDER_TARGET)
ici.usage |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
if (templ->bind & PIPE_BIND_DEPTH_STENCIL)
if (bind & PIPE_BIND_DEPTH_STENCIL)
ici.usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
if (templ->flags & PIPE_RESOURCE_FLAG_SPARSE)
ici.usage |= VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT;
if (templ->bind & PIPE_BIND_STREAM_OUTPUT)
if (bind & PIPE_BIND_STREAM_OUTPUT)
ici.usage |= VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT;
ici.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
ici.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
return ici;
}
static struct zink_resource_object *
resource_object_create(struct zink_screen *screen, const struct pipe_resource *templ, struct winsys_handle *whandle, bool *optimal_tiling)
{
struct zink_resource_object *obj = CALLOC_STRUCT(zink_resource_object);
if (!obj)
return NULL;
VkMemoryRequirements reqs = {};
VkMemoryPropertyFlags flags;
pipe_reference_init(&obj->reference, 1);
util_dynarray_init(&obj->desc_set_refs.refs, NULL);
if (templ->target == PIPE_BUFFER) {
VkBufferCreateInfo bci = create_bci(screen, templ, templ->bind);
if (vkCreateBuffer(screen->dev, &bci, NULL, &obj->buffer) != VK_SUCCESS) {
debug_printf("vkCreateBuffer failed\n");
goto fail1;
}
vkGetBufferMemoryRequirements(screen->dev, obj->buffer, &reqs);
flags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
obj->is_buffer = true;
} else {
VkImageCreateInfo ici = create_ici(screen, templ, templ->bind);
VkExternalMemoryImageCreateInfo emici = {};
if (templ->bind & PIPE_BIND_SHARED) {
emici.sType = VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_IMAGE_CREATE_INFO;
emici.handleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT;
ici.pNext = &emici;
/* TODO: deal with DRM modifiers here */
ici.tiling = VK_IMAGE_TILING_LINEAR;
}
if (optimal_tiling)
*optimal_tiling = ici.tiling != VK_IMAGE_TILING_LINEAR;
struct wsi_image_create_info image_wsi_info = {
VK_STRUCTURE_TYPE_WSI_IMAGE_CREATE_INFO_MESA,