anv/formats: Add an anv_get_format helper
This commit removes anv_format_for_vk_format and adds an anv_get_format helper. The anv_get_format helper returns the anv_format by-value. Unlike anv_format_for_vk_format the format returned by anv_get_format is 100% accurate and includes any tweaks needed for tiled vs. linear. anv_get_isl_format is now just a wrapper around anv_get_format that picks off just the isl_format.
This commit is contained in:
@@ -234,31 +234,22 @@ static const struct anv_format anv_formats[] = {
|
|||||||
|
|
||||||
#undef fmt
|
#undef fmt
|
||||||
|
|
||||||
const struct anv_format *
|
|
||||||
anv_format_for_vk_format(VkFormat format)
|
|
||||||
{
|
|
||||||
return &anv_formats[format];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exactly one bit must be set in \a aspect.
|
* Exactly one bit must be set in \a aspect.
|
||||||
*/
|
*/
|
||||||
enum isl_format
|
struct anv_format
|
||||||
anv_get_isl_format(VkFormat vk_format, VkImageAspectFlags aspect,
|
anv_get_format(VkFormat vk_format, VkImageAspectFlags aspect,
|
||||||
VkImageTiling tiling, struct anv_format_swizzle *swizzle)
|
VkImageTiling tiling)
|
||||||
{
|
{
|
||||||
const enum isl_format isl_format = anv_formats[vk_format].isl_format;
|
struct anv_format format = anv_formats[vk_format];
|
||||||
|
|
||||||
if (swizzle)
|
|
||||||
*swizzle = anv_formats[vk_format].swizzle;
|
|
||||||
|
|
||||||
const struct isl_format_layout *isl_layout =
|
const struct isl_format_layout *isl_layout =
|
||||||
isl_format_get_layout(isl_format);
|
isl_format_get_layout(format.isl_format);
|
||||||
|
|
||||||
switch (aspect) {
|
switch (aspect) {
|
||||||
case VK_IMAGE_ASPECT_COLOR_BIT:
|
case VK_IMAGE_ASPECT_COLOR_BIT:
|
||||||
if (isl_format == ISL_FORMAT_UNSUPPORTED) {
|
if (format.isl_format == ISL_FORMAT_UNSUPPORTED) {
|
||||||
return ISL_FORMAT_UNSUPPORTED;
|
return format;
|
||||||
} else if (tiling == VK_IMAGE_TILING_OPTIMAL &&
|
} else if (tiling == VK_IMAGE_TILING_OPTIMAL &&
|
||||||
!util_is_power_of_two(isl_layout->bs)) {
|
!util_is_power_of_two(isl_layout->bs)) {
|
||||||
/* Tiled formats *must* be power-of-two because we need up upload
|
/* Tiled formats *must* be power-of-two because we need up upload
|
||||||
@@ -266,27 +257,29 @@ anv_get_isl_format(VkFormat vk_format, VkImageAspectFlags aspect,
|
|||||||
* this by switching them over to RGBX or RGBA formats under the
|
* this by switching them over to RGBX or RGBA formats under the
|
||||||
* hood.
|
* hood.
|
||||||
*/
|
*/
|
||||||
enum isl_format rgbx = isl_format_rgb_to_rgbx(isl_format);
|
enum isl_format rgbx = isl_format_rgb_to_rgbx(format.isl_format);
|
||||||
if (rgbx != ISL_FORMAT_UNSUPPORTED)
|
if (rgbx != ISL_FORMAT_UNSUPPORTED)
|
||||||
return rgbx;
|
format.isl_format = rgbx;
|
||||||
else
|
else
|
||||||
return isl_format_rgb_to_rgba(isl_format);
|
format.isl_format = isl_format_rgb_to_rgba(format.isl_format);
|
||||||
|
return format;
|
||||||
} else {
|
} else {
|
||||||
return isl_format;
|
return format;
|
||||||
}
|
}
|
||||||
|
|
||||||
case VK_IMAGE_ASPECT_DEPTH_BIT:
|
case VK_IMAGE_ASPECT_DEPTH_BIT:
|
||||||
case (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT):
|
case (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT):
|
||||||
assert(vk_format_aspects(vk_format) & VK_IMAGE_ASPECT_DEPTH_BIT);
|
assert(vk_format_aspects(vk_format) & VK_IMAGE_ASPECT_DEPTH_BIT);
|
||||||
return isl_format;
|
return format;
|
||||||
|
|
||||||
case VK_IMAGE_ASPECT_STENCIL_BIT:
|
case VK_IMAGE_ASPECT_STENCIL_BIT:
|
||||||
assert(vk_format_aspects(vk_format) & VK_IMAGE_ASPECT_STENCIL_BIT);
|
assert(vk_format_aspects(vk_format) & VK_IMAGE_ASPECT_STENCIL_BIT);
|
||||||
return ISL_FORMAT_R8_UINT;
|
format.isl_format = ISL_FORMAT_R8_UINT;
|
||||||
|
return format;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
unreachable("bad VkImageAspect");
|
unreachable("bad VkImageAspect");
|
||||||
return ISL_FORMAT_UNSUPPORTED;
|
return format;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -294,12 +287,12 @@ anv_get_isl_format(VkFormat vk_format, VkImageAspectFlags aspect,
|
|||||||
|
|
||||||
static VkFormatFeatureFlags
|
static VkFormatFeatureFlags
|
||||||
get_image_format_properties(int gen, enum isl_format base,
|
get_image_format_properties(int gen, enum isl_format base,
|
||||||
enum isl_format actual,
|
struct anv_format format)
|
||||||
struct anv_format_swizzle swizzle)
|
|
||||||
{
|
{
|
||||||
const struct brw_surface_format_info *info = &surface_formats[actual];
|
const struct brw_surface_format_info *info =
|
||||||
|
&surface_formats[format.isl_format];
|
||||||
|
|
||||||
if (actual == ISL_FORMAT_UNSUPPORTED || !info->exists)
|
if (format.isl_format == ISL_FORMAT_UNSUPPORTED || !info->exists)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
VkFormatFeatureFlags flags = 0;
|
VkFormatFeatureFlags flags = 0;
|
||||||
@@ -315,12 +308,12 @@ get_image_format_properties(int gen, enum isl_format base,
|
|||||||
* moved, then blending won't work correctly. The PRM tells us
|
* moved, then blending won't work correctly. The PRM tells us
|
||||||
* straight-up not to render to such a surface.
|
* straight-up not to render to such a surface.
|
||||||
*/
|
*/
|
||||||
if (info->render_target <= gen && swizzle.a == 3) {
|
if (info->render_target <= gen && format.swizzle.a == 3) {
|
||||||
flags |= VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT |
|
flags |= VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT |
|
||||||
VK_FORMAT_FEATURE_BLIT_DST_BIT;
|
VK_FORMAT_FEATURE_BLIT_DST_BIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info->alpha_blend <= gen && swizzle.a == 3)
|
if (info->alpha_blend <= gen && format.swizzle.a == 3)
|
||||||
flags |= VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT;
|
flags |= VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT;
|
||||||
|
|
||||||
/* Load/store is determined based on base format. This prevents RGB
|
/* Load/store is determined based on base format. This prevents RGB
|
||||||
@@ -378,18 +371,17 @@ anv_physical_device_get_format_properties(struct anv_physical_device *physical_d
|
|||||||
tiled |= VK_FORMAT_FEATURE_BLIT_SRC_BIT |
|
tiled |= VK_FORMAT_FEATURE_BLIT_SRC_BIT |
|
||||||
VK_FORMAT_FEATURE_BLIT_DST_BIT;
|
VK_FORMAT_FEATURE_BLIT_DST_BIT;
|
||||||
} else {
|
} else {
|
||||||
enum isl_format linear_fmt, tiled_fmt;
|
struct anv_format linear_fmt, tiled_fmt;
|
||||||
struct anv_format_swizzle linear_swizzle, tiled_swizzle;
|
linear_fmt = anv_get_format(format, VK_IMAGE_ASPECT_COLOR_BIT,
|
||||||
linear_fmt = anv_get_isl_format(format, VK_IMAGE_ASPECT_COLOR_BIT,
|
VK_IMAGE_TILING_LINEAR);
|
||||||
VK_IMAGE_TILING_LINEAR, &linear_swizzle);
|
tiled_fmt = anv_get_format(format, VK_IMAGE_ASPECT_COLOR_BIT,
|
||||||
tiled_fmt = anv_get_isl_format(format, VK_IMAGE_ASPECT_COLOR_BIT,
|
VK_IMAGE_TILING_OPTIMAL);
|
||||||
VK_IMAGE_TILING_OPTIMAL, &tiled_swizzle);
|
|
||||||
|
|
||||||
linear = get_image_format_properties(gen, linear_fmt, linear_fmt,
|
linear = get_image_format_properties(gen, linear_fmt.isl_format,
|
||||||
linear_swizzle);
|
linear_fmt);
|
||||||
tiled = get_image_format_properties(gen, linear_fmt, tiled_fmt,
|
tiled = get_image_format_properties(gen, linear_fmt.isl_format,
|
||||||
tiled_swizzle);
|
tiled_fmt);
|
||||||
buffer = get_buffer_format_properties(gen, linear_fmt);
|
buffer = get_buffer_format_properties(gen, linear_fmt.isl_format);
|
||||||
|
|
||||||
/* XXX: We handle 3-channel formats by switching them out for RGBX or
|
/* XXX: We handle 3-channel formats by switching them out for RGBX or
|
||||||
* RGBA formats behind-the-scenes. This works fine for textures
|
* RGBA formats behind-the-scenes. This works fine for textures
|
||||||
@@ -398,9 +390,9 @@ anv_physical_device_get_format_properties(struct anv_physical_device *physical_d
|
|||||||
* substantially more work and we have enough RGBX formats to handle
|
* substantially more work and we have enough RGBX formats to handle
|
||||||
* what most clients will want.
|
* what most clients will want.
|
||||||
*/
|
*/
|
||||||
if (linear_fmt != ISL_FORMAT_UNSUPPORTED &&
|
if (linear_fmt.isl_format != ISL_FORMAT_UNSUPPORTED &&
|
||||||
!util_is_power_of_two(isl_format_layouts[linear_fmt].bs) &&
|
!util_is_power_of_two(isl_format_layouts[linear_fmt.isl_format].bs) &&
|
||||||
isl_format_rgb_to_rgbx(linear_fmt) == ISL_FORMAT_UNSUPPORTED) {
|
isl_format_rgb_to_rgbx(linear_fmt.isl_format) == ISL_FORMAT_UNSUPPORTED) {
|
||||||
tiled &= ~VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT &
|
tiled &= ~VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT &
|
||||||
~VK_FORMAT_FEATURE_BLIT_DST_BIT;
|
~VK_FORMAT_FEATURE_BLIT_DST_BIT;
|
||||||
}
|
}
|
||||||
|
@@ -131,8 +131,7 @@ make_surface(const struct anv_device *dev,
|
|||||||
|
|
||||||
ok = isl_surf_init(&dev->isl_dev, &anv_surf->isl,
|
ok = isl_surf_init(&dev->isl_dev, &anv_surf->isl,
|
||||||
.dim = vk_to_isl_surf_dim[vk_info->imageType],
|
.dim = vk_to_isl_surf_dim[vk_info->imageType],
|
||||||
.format = anv_get_isl_format(vk_info->format, aspect,
|
.format = anv_get_isl_format(vk_info->format, aspect, vk_info->tiling),
|
||||||
vk_info->tiling, NULL),
|
|
||||||
.width = image->extent.width,
|
.width = image->extent.width,
|
||||||
.height = image->extent.height,
|
.height = image->extent.height,
|
||||||
.depth = image->extent.depth,
|
.depth = image->extent.depth,
|
||||||
@@ -473,29 +472,27 @@ anv_image_view_init(struct anv_image_view *iview,
|
|||||||
iview->aspect_mask = pCreateInfo->subresourceRange.aspectMask;
|
iview->aspect_mask = pCreateInfo->subresourceRange.aspectMask;
|
||||||
iview->vk_format = pCreateInfo->format;
|
iview->vk_format = pCreateInfo->format;
|
||||||
|
|
||||||
struct anv_format_swizzle swizzle;
|
struct anv_format format =
|
||||||
enum isl_format format = anv_get_isl_format(pCreateInfo->format,
|
anv_get_format(pCreateInfo->format, range->aspectMask, image->tiling);
|
||||||
range->aspectMask,
|
|
||||||
image->tiling, &swizzle);
|
|
||||||
|
|
||||||
iview->base_layer = range->baseArrayLayer;
|
iview->base_layer = range->baseArrayLayer;
|
||||||
iview->base_mip = range->baseMipLevel;
|
iview->base_mip = range->baseMipLevel;
|
||||||
|
|
||||||
struct isl_view isl_view = {
|
struct isl_view isl_view = {
|
||||||
.format = format,
|
.format = format.isl_format,
|
||||||
.base_level = range->baseMipLevel,
|
.base_level = range->baseMipLevel,
|
||||||
.levels = anv_get_levelCount(image, range),
|
.levels = anv_get_levelCount(image, range),
|
||||||
.base_array_layer = range->baseArrayLayer,
|
.base_array_layer = range->baseArrayLayer,
|
||||||
.array_len = anv_get_layerCount(image, range),
|
.array_len = anv_get_layerCount(image, range),
|
||||||
.channel_select = {
|
.channel_select = {
|
||||||
remap_swizzle(pCreateInfo->components.r,
|
remap_swizzle(pCreateInfo->components.r,
|
||||||
VK_COMPONENT_SWIZZLE_R, swizzle),
|
VK_COMPONENT_SWIZZLE_R, format.swizzle),
|
||||||
remap_swizzle(pCreateInfo->components.g,
|
remap_swizzle(pCreateInfo->components.g,
|
||||||
VK_COMPONENT_SWIZZLE_G, swizzle),
|
VK_COMPONENT_SWIZZLE_G, format.swizzle),
|
||||||
remap_swizzle(pCreateInfo->components.b,
|
remap_swizzle(pCreateInfo->components.b,
|
||||||
VK_COMPONENT_SWIZZLE_B, swizzle),
|
VK_COMPONENT_SWIZZLE_B, format.swizzle),
|
||||||
remap_swizzle(pCreateInfo->components.a,
|
remap_swizzle(pCreateInfo->components.a,
|
||||||
VK_COMPONENT_SWIZZLE_A, swizzle),
|
VK_COMPONENT_SWIZZLE_A, format.swizzle),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -548,7 +545,8 @@ anv_image_view_init(struct anv_image_view *iview,
|
|||||||
if (image->usage & usage_mask & VK_IMAGE_USAGE_STORAGE_BIT) {
|
if (image->usage & usage_mask & VK_IMAGE_USAGE_STORAGE_BIT) {
|
||||||
iview->storage_surface_state = alloc_surface_state(device, cmd_buffer);
|
iview->storage_surface_state = alloc_surface_state(device, cmd_buffer);
|
||||||
|
|
||||||
if (isl_has_matching_typed_storage_image_format(&device->info, format)) {
|
if (isl_has_matching_typed_storage_image_format(&device->info,
|
||||||
|
format.isl_format)) {
|
||||||
isl_view.usage = cube_usage | ISL_SURF_USAGE_STORAGE_BIT;
|
isl_view.usage = cube_usage | ISL_SURF_USAGE_STORAGE_BIT;
|
||||||
isl_surf_fill_state(&device->isl_dev,
|
isl_surf_fill_state(&device->isl_dev,
|
||||||
iview->storage_surface_state.map,
|
iview->storage_surface_state.map,
|
||||||
@@ -631,7 +629,7 @@ void anv_buffer_view_init(struct anv_buffer_view *view,
|
|||||||
|
|
||||||
view->format = anv_get_isl_format(pCreateInfo->format,
|
view->format = anv_get_isl_format(pCreateInfo->format,
|
||||||
VK_IMAGE_ASPECT_COLOR_BIT,
|
VK_IMAGE_ASPECT_COLOR_BIT,
|
||||||
VK_IMAGE_TILING_LINEAR, NULL);
|
VK_IMAGE_TILING_LINEAR);
|
||||||
view->bo = buffer->bo;
|
view->bo = buffer->bo;
|
||||||
view->offset = buffer->offset + pCreateInfo->offset;
|
view->offset = buffer->offset + pCreateInfo->offset;
|
||||||
view->range = pCreateInfo->range == VK_WHOLE_SIZE ?
|
view->range = pCreateInfo->range == VK_WHOLE_SIZE ?
|
||||||
|
@@ -162,8 +162,7 @@ meta_copy_buffer_to_image(struct anv_cmd_buffer *cmd_buffer,
|
|||||||
struct anv_meta_blit2d_surf img_bsurf =
|
struct anv_meta_blit2d_surf img_bsurf =
|
||||||
blit_surf_for_image(image, img_isl_surf);
|
blit_surf_for_image(image, img_isl_surf);
|
||||||
enum isl_format buf_format = anv_get_isl_format(image->vk_format, aspect,
|
enum isl_format buf_format = anv_get_isl_format(image->vk_format, aspect,
|
||||||
VK_IMAGE_TILING_LINEAR,
|
VK_IMAGE_TILING_LINEAR);
|
||||||
NULL);
|
|
||||||
struct anv_meta_blit2d_surf buf_bsurf = {
|
struct anv_meta_blit2d_surf buf_bsurf = {
|
||||||
.bo = buffer->bo,
|
.bo = buffer->bo,
|
||||||
.tiling = ISL_TILING_LINEAR,
|
.tiling = ISL_TILING_LINEAR,
|
||||||
|
@@ -1518,12 +1518,16 @@ struct anv_format {
|
|||||||
struct anv_format_swizzle swizzle;
|
struct anv_format_swizzle swizzle;
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct anv_format *
|
struct anv_format
|
||||||
anv_format_for_vk_format(VkFormat format);
|
anv_get_format(VkFormat format, VkImageAspectFlags aspect,
|
||||||
|
VkImageTiling tiling);
|
||||||
|
|
||||||
enum isl_format
|
static inline enum isl_format
|
||||||
anv_get_isl_format(VkFormat format, VkImageAspectFlags aspect,
|
anv_get_isl_format(VkFormat vk_format, VkImageAspectFlags aspect,
|
||||||
VkImageTiling tiling, struct anv_format_swizzle *swizzle);
|
VkImageTiling tiling)
|
||||||
|
{
|
||||||
|
return anv_get_format(vk_format, aspect, tiling).isl_format;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Subsurface of an anv_image.
|
* Subsurface of an anv_image.
|
||||||
|
@@ -102,8 +102,7 @@ emit_vertex_input(struct anv_pipeline *pipeline,
|
|||||||
&info->pVertexAttributeDescriptions[i];
|
&info->pVertexAttributeDescriptions[i];
|
||||||
enum isl_format format = anv_get_isl_format(desc->format,
|
enum isl_format format = anv_get_isl_format(desc->format,
|
||||||
VK_IMAGE_ASPECT_COLOR_BIT,
|
VK_IMAGE_ASPECT_COLOR_BIT,
|
||||||
VK_IMAGE_TILING_LINEAR,
|
VK_IMAGE_TILING_LINEAR);
|
||||||
NULL);
|
|
||||||
|
|
||||||
assert(desc->binding < 32);
|
assert(desc->binding < 32);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user