crocus: introduce main resource configuration helper.
Along the lines of what iris does. Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11352>
This commit is contained in:
@@ -142,6 +142,106 @@ crocus_target_to_isl_surf_dim(enum pipe_texture_target target)
|
||||
unreachable("invalid texture type");
|
||||
}
|
||||
|
||||
static isl_surf_usage_flags_t
|
||||
pipe_bind_to_isl_usage(unsigned bindings)
|
||||
{
|
||||
isl_surf_usage_flags_t usage = 0;
|
||||
|
||||
if (bindings & PIPE_BIND_RENDER_TARGET)
|
||||
usage |= ISL_SURF_USAGE_RENDER_TARGET_BIT;
|
||||
|
||||
if (bindings & PIPE_BIND_SAMPLER_VIEW)
|
||||
usage |= ISL_SURF_USAGE_TEXTURE_BIT;
|
||||
|
||||
if (bindings & (PIPE_BIND_SHADER_IMAGE | PIPE_BIND_SHADER_BUFFER))
|
||||
usage |= ISL_SURF_USAGE_STORAGE_BIT;
|
||||
|
||||
if (bindings & PIPE_BIND_DISPLAY_TARGET)
|
||||
usage |= ISL_SURF_USAGE_DISPLAY_BIT;
|
||||
return usage;
|
||||
}
|
||||
|
||||
static bool
|
||||
crocus_resource_configure_main(const struct crocus_screen *screen,
|
||||
struct crocus_resource *res,
|
||||
const struct pipe_resource *templ,
|
||||
uint64_t modifier, uint32_t row_pitch_B)
|
||||
{
|
||||
const struct intel_device_info *devinfo = &screen->devinfo;
|
||||
const struct util_format_description *format_desc =
|
||||
util_format_description(templ->format);
|
||||
const bool has_depth = util_format_has_depth(format_desc);
|
||||
isl_surf_usage_flags_t usage = pipe_bind_to_isl_usage(templ->bind);
|
||||
isl_tiling_flags_t tiling_flags = ISL_TILING_ANY_MASK;
|
||||
|
||||
/* TODO: This used to be because there wasn't BLORP to handle Y-tiling. */
|
||||
if (devinfo->ver < 6 && !util_format_is_depth_or_stencil(templ->format))
|
||||
tiling_flags &= ~ISL_TILING_Y0_BIT;
|
||||
|
||||
if (modifier != DRM_FORMAT_MOD_INVALID) {
|
||||
res->mod_info = isl_drm_modifier_get_info(modifier);
|
||||
|
||||
tiling_flags = 1 << res->mod_info->tiling;
|
||||
} else {
|
||||
if (templ->bind & PIPE_BIND_RENDER_TARGET && devinfo->ver < 6) {
|
||||
modifier = I915_FORMAT_MOD_X_TILED;
|
||||
res->mod_info = isl_drm_modifier_get_info(modifier);
|
||||
tiling_flags = 1 << res->mod_info->tiling;
|
||||
}
|
||||
/* Use linear for staging buffers */
|
||||
if (templ->usage == PIPE_USAGE_STAGING ||
|
||||
templ->bind & (PIPE_BIND_LINEAR | PIPE_BIND_CURSOR) )
|
||||
tiling_flags = ISL_TILING_LINEAR_BIT;
|
||||
}
|
||||
|
||||
if (templ->target == PIPE_TEXTURE_CUBE ||
|
||||
templ->target == PIPE_TEXTURE_CUBE_ARRAY)
|
||||
usage |= ISL_SURF_USAGE_CUBE_BIT;
|
||||
|
||||
if (templ->usage != PIPE_USAGE_STAGING) {
|
||||
if (templ->format == PIPE_FORMAT_S8_UINT)
|
||||
usage |= ISL_SURF_USAGE_STENCIL_BIT;
|
||||
else if (has_depth) {
|
||||
/* combined DS only on gen4/5 */
|
||||
if (devinfo->ver < 6) {
|
||||
if (templ->format == PIPE_FORMAT_Z24X8_UNORM ||
|
||||
templ->format == PIPE_FORMAT_Z24_UNORM_S8_UINT ||
|
||||
templ->format == PIPE_FORMAT_Z32_FLOAT_S8X24_UINT)
|
||||
usage |= ISL_SURF_USAGE_STENCIL_BIT;
|
||||
}
|
||||
usage |= ISL_SURF_USAGE_DEPTH_BIT;
|
||||
}
|
||||
|
||||
if (templ->format == PIPE_FORMAT_S8_UINT)
|
||||
tiling_flags = ISL_TILING_W_BIT;
|
||||
}
|
||||
|
||||
const enum isl_format format =
|
||||
crocus_format_for_usage(&screen->devinfo, templ->format, usage).fmt;
|
||||
|
||||
const struct isl_surf_init_info init_info = {
|
||||
.dim = crocus_target_to_isl_surf_dim(templ->target),
|
||||
.format = format,
|
||||
.width = templ->width0,
|
||||
.height = templ->height0,
|
||||
.depth = templ->depth0,
|
||||
.levels = templ->last_level + 1,
|
||||
.array_len = templ->array_size,
|
||||
.samples = MAX2(templ->nr_samples, 1),
|
||||
.min_alignment_B = 0,
|
||||
.row_pitch_B = row_pitch_B,
|
||||
.usage = usage,
|
||||
.tiling_flags = tiling_flags
|
||||
};
|
||||
|
||||
if (!isl_surf_init_s(&screen->isl_dev, &res->surf, &init_info))
|
||||
return false;
|
||||
|
||||
res->internal_format = templ->format;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void
|
||||
crocus_query_dmabuf_modifiers(struct pipe_screen *pscreen,
|
||||
enum pipe_format pfmt,
|
||||
@@ -180,26 +280,6 @@ crocus_query_dmabuf_modifiers(struct pipe_screen *pscreen,
|
||||
*count = supported_mods;
|
||||
}
|
||||
|
||||
static isl_surf_usage_flags_t
|
||||
pipe_bind_to_isl_usage(unsigned bindings)
|
||||
{
|
||||
isl_surf_usage_flags_t usage = 0;
|
||||
|
||||
if (bindings & PIPE_BIND_RENDER_TARGET)
|
||||
usage |= ISL_SURF_USAGE_RENDER_TARGET_BIT;
|
||||
|
||||
if (bindings & PIPE_BIND_SAMPLER_VIEW)
|
||||
usage |= ISL_SURF_USAGE_TEXTURE_BIT;
|
||||
|
||||
if (bindings & (PIPE_BIND_SHADER_IMAGE | PIPE_BIND_SHADER_BUFFER))
|
||||
usage |= ISL_SURF_USAGE_STORAGE_BIT;
|
||||
|
||||
if (bindings & PIPE_BIND_DISPLAY_TARGET)
|
||||
usage |= ISL_SURF_USAGE_DISPLAY_BIT;
|
||||
|
||||
return usage;
|
||||
}
|
||||
|
||||
struct pipe_resource *
|
||||
crocus_resource_get_separate_stencil(struct pipe_resource *p_res)
|
||||
{
|
||||
@@ -644,61 +724,12 @@ crocus_resource_create_with_modifiers(struct pipe_screen *pscreen,
|
||||
if (!res)
|
||||
return NULL;
|
||||
|
||||
const struct util_format_description *format_desc =
|
||||
util_format_description(templ->format);
|
||||
const bool has_depth = util_format_has_depth(format_desc);
|
||||
uint64_t modifier =
|
||||
select_best_modifier(devinfo, templ->format, modifiers, modifiers_count);
|
||||
|
||||
isl_tiling_flags_t tiling_flags = ISL_TILING_ANY_MASK;
|
||||
|
||||
/* TODO: This used to be because there wasn't BLORP to handle Y-tiling. */
|
||||
if (devinfo->ver < 6 && !util_format_is_depth_or_stencil(templ->format))
|
||||
tiling_flags &= ~ISL_TILING_Y0_BIT;
|
||||
|
||||
if (modifier != DRM_FORMAT_MOD_INVALID) {
|
||||
res->mod_info = isl_drm_modifier_get_info(modifier);
|
||||
|
||||
tiling_flags = 1 << res->mod_info->tiling;
|
||||
} else {
|
||||
if (modifiers_count > 0) {
|
||||
fprintf(stderr, "Unsupported modifier, resource creation failed.\n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (templ->bind & PIPE_BIND_RENDER_TARGET && devinfo->ver < 6) {
|
||||
modifier = I915_FORMAT_MOD_X_TILED;
|
||||
res->mod_info = isl_drm_modifier_get_info(modifier);
|
||||
tiling_flags = 1 << res->mod_info->tiling;
|
||||
}
|
||||
/* Use linear for staging buffers */
|
||||
if (templ->usage == PIPE_USAGE_STAGING ||
|
||||
templ->bind & (PIPE_BIND_LINEAR | PIPE_BIND_CURSOR) )
|
||||
tiling_flags = ISL_TILING_LINEAR_BIT;
|
||||
}
|
||||
|
||||
isl_surf_usage_flags_t usage = pipe_bind_to_isl_usage(templ->bind);
|
||||
|
||||
if (templ->target == PIPE_TEXTURE_CUBE ||
|
||||
templ->target == PIPE_TEXTURE_CUBE_ARRAY)
|
||||
usage |= ISL_SURF_USAGE_CUBE_BIT;
|
||||
|
||||
if (templ->usage != PIPE_USAGE_STAGING) {
|
||||
if (templ->format == PIPE_FORMAT_S8_UINT)
|
||||
usage |= ISL_SURF_USAGE_STENCIL_BIT;
|
||||
else if (has_depth) {
|
||||
/* combined DS only on gen4/5 */
|
||||
if (devinfo->ver < 6) {
|
||||
if (templ->format == PIPE_FORMAT_Z24X8_UNORM ||
|
||||
templ->format == PIPE_FORMAT_Z24_UNORM_S8_UINT ||
|
||||
templ->format == PIPE_FORMAT_Z32_FLOAT_S8X24_UINT)
|
||||
usage |= ISL_SURF_USAGE_STENCIL_BIT;
|
||||
}
|
||||
usage |= ISL_SURF_USAGE_DEPTH_BIT;
|
||||
}
|
||||
|
||||
if (templ->format == PIPE_FORMAT_S8_UINT)
|
||||
tiling_flags = ISL_TILING_W_BIT;
|
||||
if (modifier == DRM_FORMAT_MOD_INVALID && modifiers_count > 0) {
|
||||
fprintf(stderr, "Unsupported modifier, resource creation failed.\n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (templ->usage == PIPE_USAGE_STAGING &&
|
||||
@@ -706,30 +737,8 @@ crocus_resource_create_with_modifiers(struct pipe_screen *pscreen,
|
||||
devinfo->ver < 6)
|
||||
return NULL;
|
||||
|
||||
enum pipe_format pfmt = templ->format;
|
||||
res->internal_format = pfmt;
|
||||
|
||||
/* Should be handled by u_transfer_helper */
|
||||
// assert(!util_format_is_depth_and_stencil(pfmt));
|
||||
|
||||
struct crocus_format_info fmt = crocus_format_for_usage(devinfo, pfmt, usage);
|
||||
assert(fmt.fmt != ISL_FORMAT_UNSUPPORTED);
|
||||
enum isl_surf_dim dim = crocus_target_to_isl_surf_dim(templ->target);
|
||||
|
||||
UNUSED const bool isl_surf_created_successfully =
|
||||
isl_surf_init(&screen->isl_dev, &res->surf,
|
||||
.dim = dim,
|
||||
.format = fmt.fmt,
|
||||
.width = templ->width0,
|
||||
.height = templ->height0,
|
||||
.depth = templ->depth0,
|
||||
.levels = templ->last_level + 1,
|
||||
.array_len = templ->array_size,
|
||||
.samples = MAX2(templ->nr_samples, 1),
|
||||
.min_alignment_B = 0,
|
||||
.row_pitch_B = 0,
|
||||
.usage = usage,
|
||||
.tiling_flags = tiling_flags);
|
||||
crocus_resource_configure_main(screen, res, templ, modifier, 0);
|
||||
assert(isl_surf_created_successfully);
|
||||
|
||||
const char *name = "miptree";
|
||||
@@ -851,11 +860,8 @@ crocus_resource_from_handle(struct pipe_screen *pscreen,
|
||||
unsigned usage)
|
||||
{
|
||||
struct crocus_screen *screen = (struct crocus_screen *)pscreen;
|
||||
struct intel_device_info *devinfo = &screen->devinfo;
|
||||
struct crocus_bufmgr *bufmgr = screen->bufmgr;
|
||||
struct crocus_resource *res = crocus_alloc_resource(pscreen, templ);
|
||||
const struct isl_drm_modifier_info *mod_inf =
|
||||
isl_drm_modifier_get_info(whandle->modifier);
|
||||
|
||||
if (!res)
|
||||
return NULL;
|
||||
@@ -876,40 +882,19 @@ crocus_resource_from_handle(struct pipe_screen *pscreen,
|
||||
return NULL;
|
||||
|
||||
res->offset = whandle->offset;
|
||||
|
||||
if (mod_inf == NULL) {
|
||||
mod_inf =
|
||||
isl_drm_modifier_get_info(tiling_to_modifier(res->bo->tiling_mode));
|
||||
}
|
||||
assert(mod_inf);
|
||||
|
||||
res->external_format = whandle->format;
|
||||
res->mod_info = mod_inf;
|
||||
|
||||
isl_surf_usage_flags_t isl_usage = pipe_bind_to_isl_usage(templ->bind);
|
||||
|
||||
const struct crocus_format_info fmt =
|
||||
crocus_format_for_usage(devinfo, templ->format, isl_usage);
|
||||
res->internal_format = templ->format;
|
||||
|
||||
if (templ->target == PIPE_BUFFER) {
|
||||
res->surf.tiling = ISL_TILING_LINEAR;
|
||||
} else {
|
||||
if (whandle->plane < util_format_get_num_planes(whandle->format)) {
|
||||
const uint64_t modifier =
|
||||
whandle->modifier != DRM_FORMAT_MOD_INVALID ?
|
||||
whandle->modifier : tiling_to_modifier(res->bo->tiling_mode);
|
||||
|
||||
UNUSED const bool isl_surf_created_successfully =
|
||||
isl_surf_init(&screen->isl_dev, &res->surf,
|
||||
.dim = crocus_target_to_isl_surf_dim(templ->target),
|
||||
.format = fmt.fmt,
|
||||
.width = templ->width0,
|
||||
.height = templ->height0,
|
||||
.depth = templ->depth0,
|
||||
.levels = templ->last_level + 1,
|
||||
.array_len = templ->array_size,
|
||||
.samples = MAX2(templ->nr_samples, 1),
|
||||
.min_alignment_B = 0,
|
||||
.row_pitch_B = whandle->stride,
|
||||
.usage = isl_usage,
|
||||
.tiling_flags = 1 << res->mod_info->tiling);
|
||||
crocus_resource_configure_main(screen, res, templ, modifier,
|
||||
whandle->stride);
|
||||
assert(isl_surf_created_successfully);
|
||||
assert(res->bo->tiling_mode ==
|
||||
isl_tiling_to_i915_tiling(res->surf.tiling));
|
||||
|
Reference in New Issue
Block a user