anv: Implement VK_REMAINING_{MIP_LEVELS,ARRAY_LAYERS}
authorNanley Chery <nanley.g.chery@intel.com>
Sat, 5 Mar 2016 04:41:05 +0000 (20:41 -0800)
committerNanley Chery <nanley.g.chery@intel.com>
Sat, 5 Mar 2016 05:25:23 +0000 (21:25 -0800)
v2: Subtract the baseMipLevel and baseArrayLayer (Jason)

Signed-off-by: Nanley Chery <nanley.g.chery@intel.com>
Reviewed-by: Jason Ekstrand <jason.ekstrand@intel.com>
src/intel/vulkan/anv_image.c
src/intel/vulkan/anv_meta_clear.c
src/intel/vulkan/anv_private.h

index c76a5f6dba9f7528c4e595b6957f5c3c78131ff3..143a08413f720d3405b802c8b98cd24f0563177e 100644 (file)
@@ -388,9 +388,9 @@ anv_validate_CreateImageView(VkDevice _device,
    assert(subresource->levelCount > 0);
    assert(subresource->layerCount > 0);
    assert(subresource->baseMipLevel < image->levels);
-   assert(subresource->baseMipLevel + subresource->levelCount <= image->levels);
+   assert(subresource->baseMipLevel + anv_get_levelCount(image, subresource) <= image->levels);
    assert(subresource->baseArrayLayer < image->array_size);
-   assert(subresource->baseArrayLayer + subresource->layerCount <= image->array_size);
+   assert(subresource->baseArrayLayer + anv_get_layerCount(image, subresource) <= image->array_size);
    assert(pView);
 
    const VkImageAspectFlags ds_flags = VK_IMAGE_ASPECT_DEPTH_BIT
@@ -496,10 +496,10 @@ anv_image_view_init(struct anv_image_view *iview,
       unreachable("bad VkImageType");
    case VK_IMAGE_TYPE_1D:
    case VK_IMAGE_TYPE_2D:
-      assert(range->baseArrayLayer + range->layerCount - 1 <= image->array_size);
+      assert(range->baseArrayLayer + anv_get_layerCount(image, range) - 1 <= image->array_size);
       break;
    case VK_IMAGE_TYPE_3D:
-      assert(range->baseArrayLayer + range->layerCount - 1
+      assert(range->baseArrayLayer + anv_get_layerCount(image, range) - 1
              <= anv_minify(image->extent.depth, range->baseMipLevel));
       break;
    }
@@ -525,9 +525,9 @@ anv_image_view_init(struct anv_image_view *iview,
    struct isl_view isl_view = {
       .format = format,
       .base_level = range->baseMipLevel,
-      .levels = range->levelCount,
+      .levels = anv_get_levelCount(image, range),
       .base_array_layer = range->baseArrayLayer,
-      .array_len = range->layerCount,
+      .array_len = anv_get_layerCount(image, range),
       .channel_select = {
          remap_swizzle(pCreateInfo->components.r,
                        VK_COMPONENT_SWIZZLE_R, swizzle),
index 8f92a9d755c9920a7e364fe685d83943db8b7f1c..bce9446084457a1fec74393362a6bc86f0bfdd54 100644 (file)
@@ -795,8 +795,8 @@ anv_cmd_clear_image(struct anv_cmd_buffer *cmd_buffer,
    for (uint32_t r = 0; r < range_count; r++) {
       const VkImageSubresourceRange *range = &ranges[r];
 
-      for (uint32_t l = 0; l < range->levelCount; ++l) {
-         for (uint32_t s = 0; s < range->layerCount; ++s) {
+      for (uint32_t l = 0; l < anv_get_levelCount(image, range); ++l) {
+         for (uint32_t s = 0; s < anv_get_layerCount(image, range); ++s) {
             struct anv_image_view iview;
             anv_image_view_init(&iview, cmd_buffer->device,
                &(VkImageViewCreateInfo) {
index cb4f9736fdf0f62f04ae8ea41dae036cc2c3edea..f87270466ae6be156188b18d60265667ba659015 100644 (file)
@@ -1641,6 +1641,23 @@ struct anv_image {
    };
 };
 
+static inline uint32_t
+anv_get_layerCount(const struct anv_image *image,
+                   const VkImageSubresourceRange *range)
+{
+   return range->layerCount == VK_REMAINING_ARRAY_LAYERS ?
+          image->array_size - range->baseArrayLayer : range->layerCount;
+}
+
+static inline uint32_t
+anv_get_levelCount(const struct anv_image *image,
+                   const VkImageSubresourceRange *range)
+{
+   return range->levelCount == VK_REMAINING_MIP_LEVELS ?
+          image->levels - range->baseMipLevel : range->levelCount;
+}
+
+
 struct anv_image_view {
    const struct anv_image *image; /**< VkImageViewCreateInfo::image */
    struct anv_bo *bo;