#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.
*/
-enum isl_format
-anv_get_isl_format(VkFormat vk_format, VkImageAspectFlags aspect,
- VkImageTiling tiling, struct anv_format_swizzle *swizzle)
+struct anv_format
+anv_get_format(VkFormat vk_format, VkImageAspectFlags aspect,
+ VkImageTiling tiling)
{
- const enum isl_format isl_format = anv_formats[vk_format].isl_format;
-
- if (swizzle)
- *swizzle = anv_formats[vk_format].swizzle;
+ struct anv_format format = anv_formats[vk_format];
const struct isl_format_layout *isl_layout =
- isl_format_get_layout(isl_format);
+ isl_format_get_layout(format.isl_format);
switch (aspect) {
case VK_IMAGE_ASPECT_COLOR_BIT:
- if (isl_format == ISL_FORMAT_UNSUPPORTED) {
- return ISL_FORMAT_UNSUPPORTED;
+ if (format.isl_format == ISL_FORMAT_UNSUPPORTED) {
+ return format;
} else if (tiling == VK_IMAGE_TILING_OPTIMAL &&
!util_is_power_of_two(isl_layout->bs)) {
/* Tiled formats *must* be power-of-two because we need up upload
* this by switching them over to RGBX or RGBA formats under the
* 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)
- return rgbx;
+ format.isl_format = rgbx;
else
- return isl_format_rgb_to_rgba(isl_format);
+ format.isl_format = isl_format_rgb_to_rgba(format.isl_format);
+ return format;
} else {
- return isl_format;
+ return format;
}
case VK_IMAGE_ASPECT_DEPTH_BIT:
case (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT):
assert(vk_format_aspects(vk_format) & VK_IMAGE_ASPECT_DEPTH_BIT);
- return isl_format;
+ return format;
case 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:
unreachable("bad VkImageAspect");
- return ISL_FORMAT_UNSUPPORTED;
+ return format;
}
}
static VkFormatFeatureFlags
get_image_format_properties(int gen, enum isl_format base,
- enum isl_format actual,
- struct anv_format_swizzle swizzle)
+ struct anv_format format)
{
- 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;
VkFormatFeatureFlags flags = 0;
* moved, then blending won't work correctly. The PRM tells us
* 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 |
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;
/* Load/store is determined based on base format. This prevents RGB
tiled |= VK_FORMAT_FEATURE_BLIT_SRC_BIT |
VK_FORMAT_FEATURE_BLIT_DST_BIT;
} else {
- enum isl_format linear_fmt, tiled_fmt;
- struct anv_format_swizzle linear_swizzle, tiled_swizzle;
- linear_fmt = anv_get_isl_format(format, VK_IMAGE_ASPECT_COLOR_BIT,
- VK_IMAGE_TILING_LINEAR, &linear_swizzle);
- tiled_fmt = anv_get_isl_format(format, VK_IMAGE_ASPECT_COLOR_BIT,
- VK_IMAGE_TILING_OPTIMAL, &tiled_swizzle);
-
- linear = get_image_format_properties(gen, linear_fmt, linear_fmt,
- linear_swizzle);
- tiled = get_image_format_properties(gen, linear_fmt, tiled_fmt,
- tiled_swizzle);
- buffer = get_buffer_format_properties(gen, linear_fmt);
+ struct anv_format linear_fmt, tiled_fmt;
+ linear_fmt = anv_get_format(format, VK_IMAGE_ASPECT_COLOR_BIT,
+ VK_IMAGE_TILING_LINEAR);
+ tiled_fmt = anv_get_format(format, VK_IMAGE_ASPECT_COLOR_BIT,
+ VK_IMAGE_TILING_OPTIMAL);
+
+ linear = get_image_format_properties(gen, linear_fmt.isl_format,
+ linear_fmt);
+ tiled = get_image_format_properties(gen, linear_fmt.isl_format,
+ tiled_fmt);
+ buffer = get_buffer_format_properties(gen, linear_fmt.isl_format);
/* XXX: We handle 3-channel formats by switching them out for RGBX or
* RGBA formats behind-the-scenes. This works fine for textures
* substantially more work and we have enough RGBX formats to handle
* what most clients will want.
*/
- if (linear_fmt != ISL_FORMAT_UNSUPPORTED &&
- !util_is_power_of_two(isl_format_layouts[linear_fmt].bs) &&
- isl_format_rgb_to_rgbx(linear_fmt) == ISL_FORMAT_UNSUPPORTED) {
+ if (linear_fmt.isl_format != ISL_FORMAT_UNSUPPORTED &&
+ !util_is_power_of_two(isl_format_layouts[linear_fmt.isl_format].bs) &&
+ isl_format_rgb_to_rgbx(linear_fmt.isl_format) == ISL_FORMAT_UNSUPPORTED) {
tiled &= ~VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT &
~VK_FORMAT_FEATURE_BLIT_DST_BIT;
}
ok = isl_surf_init(&dev->isl_dev, &anv_surf->isl,
.dim = vk_to_isl_surf_dim[vk_info->imageType],
- .format = anv_get_isl_format(vk_info->format, aspect,
- vk_info->tiling, NULL),
+ .format = anv_get_isl_format(vk_info->format, aspect, vk_info->tiling),
.width = image->extent.width,
.height = image->extent.height,
.depth = image->extent.depth,
iview->aspect_mask = pCreateInfo->subresourceRange.aspectMask;
iview->vk_format = pCreateInfo->format;
- struct anv_format_swizzle swizzle;
- enum isl_format format = anv_get_isl_format(pCreateInfo->format,
- range->aspectMask,
- image->tiling, &swizzle);
+ struct anv_format format =
+ anv_get_format(pCreateInfo->format, range->aspectMask, image->tiling);
iview->base_layer = range->baseArrayLayer;
iview->base_mip = range->baseMipLevel;
struct isl_view isl_view = {
- .format = format,
+ .format = format.isl_format,
.base_level = range->baseMipLevel,
.levels = anv_get_levelCount(image, range),
.base_array_layer = range->baseArrayLayer,
.array_len = anv_get_layerCount(image, range),
.channel_select = {
remap_swizzle(pCreateInfo->components.r,
- VK_COMPONENT_SWIZZLE_R, swizzle),
+ VK_COMPONENT_SWIZZLE_R, format.swizzle),
remap_swizzle(pCreateInfo->components.g,
- VK_COMPONENT_SWIZZLE_G, swizzle),
+ VK_COMPONENT_SWIZZLE_G, format.swizzle),
remap_swizzle(pCreateInfo->components.b,
- VK_COMPONENT_SWIZZLE_B, swizzle),
+ VK_COMPONENT_SWIZZLE_B, format.swizzle),
remap_swizzle(pCreateInfo->components.a,
- VK_COMPONENT_SWIZZLE_A, swizzle),
+ VK_COMPONENT_SWIZZLE_A, format.swizzle),
},
};
if (image->usage & usage_mask & VK_IMAGE_USAGE_STORAGE_BIT) {
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_surf_fill_state(&device->isl_dev,
iview->storage_surface_state.map,
view->format = anv_get_isl_format(pCreateInfo->format,
VK_IMAGE_ASPECT_COLOR_BIT,
- VK_IMAGE_TILING_LINEAR, NULL);
+ VK_IMAGE_TILING_LINEAR);
view->bo = buffer->bo;
view->offset = buffer->offset + pCreateInfo->offset;
view->range = pCreateInfo->range == VK_WHOLE_SIZE ?