summaryrefslogtreecommitdiffstats
path: root/src/intel
diff options
context:
space:
mode:
authorJason Ekstrand <[email protected]>2016-05-15 21:46:05 -0700
committerJason Ekstrand <[email protected]>2016-05-17 12:17:22 -0700
commitce375fba413a803f264335c7dd6e72b0003021f9 (patch)
tree5df199342d72bfcc2b41e42c25b8f9e1575374fe /src/intel
parent34198d798c003d45fd52ce88e56dbfac450afd91 (diff)
anv/formats: Refactor anv_get_format
The new code removes the switch statement and instead handles depth/stencil as up-front special cases. This allows for potentially more complicated color format handling in the future.
Diffstat (limited to 'src/intel')
-rw-r--r--src/intel/vulkan/anv_formats.c57
1 files changed, 27 insertions, 30 deletions
diff --git a/src/intel/vulkan/anv_formats.c b/src/intel/vulkan/anv_formats.c
index 6d677d54546..228f4672073 100644
--- a/src/intel/vulkan/anv_formats.c
+++ b/src/intel/vulkan/anv_formats.c
@@ -250,44 +250,41 @@ anv_get_format(VkFormat vk_format, VkImageAspectFlags aspect,
{
struct anv_format format = anv_formats[vk_format];
- const struct isl_format_layout *isl_layout =
- isl_format_get_layout(format.isl_format);
-
- switch (aspect) {
- case VK_IMAGE_ASPECT_COLOR_BIT:
- 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
- * them with the render pipeline. For 3-channel formats, we fix
- * this by switching them over to RGBX or RGBA formats under the
- * hood.
- */
- enum isl_format rgbx = isl_format_rgb_to_rgbx(format.isl_format);
- if (rgbx != ISL_FORMAT_UNSUPPORTED)
- format.isl_format = rgbx;
- else
- format.isl_format = isl_format_rgb_to_rgba(format.isl_format);
- return format;
- } else {
- 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);
+ if (format.isl_format == ISL_FORMAT_UNSUPPORTED)
return format;
- case VK_IMAGE_ASPECT_STENCIL_BIT:
+ if (aspect == VK_IMAGE_ASPECT_STENCIL_BIT) {
assert(vk_format_aspects(vk_format) & VK_IMAGE_ASPECT_STENCIL_BIT);
format.isl_format = ISL_FORMAT_R8_UINT;
return format;
+ }
- default:
- unreachable("bad VkImageAspect");
+ if (aspect & VK_IMAGE_ASPECT_DEPTH_BIT) {
+ assert(vk_format_aspects(vk_format) & VK_IMAGE_ASPECT_DEPTH_BIT);
return format;
}
+
+ assert(aspect == VK_IMAGE_ASPECT_COLOR_BIT);
+ assert(vk_format_aspects(vk_format) == VK_IMAGE_ASPECT_COLOR_BIT);
+
+ const struct isl_format_layout *isl_layout =
+ isl_format_get_layout(format.isl_format);
+
+ 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
+ * them with the render pipeline. For 3-channel formats, we fix
+ * this by switching them over to RGBX or RGBA formats under the
+ * hood.
+ */
+ enum isl_format rgbx = isl_format_rgb_to_rgbx(format.isl_format);
+ if (rgbx != ISL_FORMAT_UNSUPPORTED)
+ format.isl_format = rgbx;
+ else
+ format.isl_format = isl_format_rgb_to_rgba(format.isl_format);
+ }
+
+ return format;
}
// Format capabilities