[anv][gbm] Support for magma images with CCS
Change-Id: I98023282fd9228a184c0fa7764a3d1b8c3cc1886
Reviewed-on: https://fuchsia-review.googlesource.com/c/third_party/mesa/+/652284
Reviewed-by: David Reveman <reveman@google.com>
diff --git a/src/gbm/backends/magma/gbm_magma.c b/src/gbm/backends/magma/gbm_magma.c
index 8ac9618..b163b0e 100644
--- a/src/gbm/backends/magma/gbm_magma.c
+++ b/src/gbm/backends/magma/gbm_magma.c
@@ -26,8 +26,8 @@
#include <assert.h>
#include <errno.h>
#include <magma.h>
-#include <stdio.h>
#include <stdbool.h>
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
@@ -47,8 +47,7 @@
struct gbm_magma_bo {
struct gbm_bo base;
magma_buffer_t image;
- uint64_t modifier;
- uint32_t coherency_domain;
+ magma_image_info_t info;
};
static struct gbm_magma_device* magma_device(struct gbm_device* device)
@@ -82,7 +81,13 @@
static int magma_get_format_modifier_plane_count(struct gbm_device* device, uint32_t format,
uint64_t modifier)
{
- return 1;
+ switch (modifier) {
+ case I915_FORMAT_MOD_Y_TILED_CCS:
+ case I915_FORMAT_MOD_Yf_TILED_CCS:
+ return 2;
+ default:
+ return 1;
+ }
}
static struct gbm_bo* magma_bo_create(struct gbm_device* device, uint32_t width, uint32_t height,
@@ -135,8 +140,7 @@
struct gbm_magma_bo* bo = malloc(sizeof(struct gbm_magma_bo));
bo->image = image;
- bo->modifier = info.drm_format_modifier;
- bo->coherency_domain = info.coherency_domain;
+ bo->info = info;
bo->base.gbm = device;
bo->base.width = width;
@@ -209,17 +213,15 @@
struct gbm_magma_bo* bo = malloc(sizeof(struct gbm_magma_bo));
bo->image = image;
- // if no modifier is provided, provide the actual modifier
- bo->modifier = import_data.modifier != DRM_FORMAT_MOD_INVALID ? import_data.modifier
- : info.drm_format_modifier;
- bo->coherency_domain = info.coherency_domain;
+ // don't use the client given modifier
+ bo->info = info;
bo->base.gbm = device;
bo->base.width = import_data.width;
bo->base.height = import_data.height;
bo->base.format = import_data.format;
- // if no stride is provided, provide the actual stride
- bo->base.stride = import_data.strides[0] ? import_data.strides[0] : info.plane_strides[0];
+ // don't use the given stride
+ bo->base.stride = info.plane_strides[0];
bo->base.handle.u64 = image;
bo->base.user_data = NULL;
bo->base.destroy_user_data = NULL;
@@ -227,35 +229,69 @@
return &bo->base;
}
-static int magma_bo_get_planes(struct gbm_bo* bo) { return 1; }
+static int magma_bo_get_planes(struct gbm_bo* bo)
+{
+ return magma_get_format_modifier_plane_count(bo->gbm, magma_bo(bo)->base.format,
+ magma_bo(bo)->info.drm_format_modifier);
+}
static union gbm_bo_handle magma_bo_get_handle_for_plane(struct gbm_bo* bo, int plane)
{
+ // We don't support more than one memory plane
if (plane != 0) {
- LOG_VERBOSE("Unhandled plane: %d\n", plane);
- union gbm_bo_handle handle = {0};
+ LOG_VERBOSE("Only one memory plane supported");
+ union gbm_bo_handle handle;
+ handle.s32 = -1;
return handle;
}
+
return magma_bo(bo)->base.handle;
}
-static uint64_t magma_bo_get_modifier(struct gbm_bo* bo) { return magma_bo(bo)->modifier; }
-
-static uint32_t magma_bo_get_offset(struct gbm_bo* bo, int plane) { return 0; }
-
-static uint32_t magma_bo_get_stride(struct gbm_bo* bo, int plane)
+static uint64_t magma_bo_get_modifier(struct gbm_bo* bo)
{
- if (plane != 0) {
+ return magma_bo(bo)->info.drm_format_modifier;
+}
+
+static int find_plane(struct gbm_bo* bo, int plane)
+{
+ int found_plane = -1;
+
+ for (int i = 0; i < MAGMA_MAX_IMAGE_PLANES; i++) {
+ if (i == 0 || magma_bo(bo)->info.plane_offsets[i]) {
+ if (++found_plane == plane)
+ return i;
+ }
+ }
+
+ return -1;
+}
+
+static uint32_t magma_bo_get_offset(struct gbm_bo* bo, int plane)
+{
+ int plane_index = find_plane(bo, plane);
+ if (plane_index < 0) {
LOG_VERBOSE("Unhandled plane: %d\n", plane);
return 0;
}
- return magma_bo(bo)->base.stride;
+ return magma_bo(bo)->info.plane_offsets[plane_index];
+}
+
+static uint32_t magma_bo_get_stride(struct gbm_bo* bo, int plane)
+{
+ int plane_index = find_plane(bo, plane);
+ if (plane_index < 0) {
+ LOG_VERBOSE("Unhandled plane: %d\n", plane);
+ return 0;
+ }
+ return magma_bo(bo)->info.plane_strides[plane_index];
}
static int magma_bo_get_plane_fd(struct gbm_bo* bo, int plane)
{
+ // We don't support more than one memory plane
if (plane != 0) {
- LOG_VERBOSE("Unhandled plane: %d\n", plane);
+ LOG_VERBOSE("Only one memory plane supported");
return -1;
}
@@ -323,7 +359,7 @@
vma->flags = flags;
if ((flags & GBM_BO_TRANSFER_READ) &&
- magma_bo(bo)->coherency_domain == MAGMA_COHERENCY_DOMAIN_RAM) {
+ magma_bo(bo)->info.coherency_domain == MAGMA_COHERENCY_DOMAIN_RAM) {
magma_status_t status = magma_clean_cache(magma_bo(bo)->image, vma->offset, vma->length,
MAGMA_CACHE_OPERATION_CLEAN_INVALIDATE);
if (status != MAGMA_STATUS_OK) {
@@ -342,7 +378,7 @@
struct Vma* vma = map_data;
if ((vma->flags & GBM_BO_TRANSFER_WRITE) &&
- magma_bo(bo)->coherency_domain == MAGMA_COHERENCY_DOMAIN_RAM) {
+ magma_bo(bo)->info.coherency_domain == MAGMA_COHERENCY_DOMAIN_RAM) {
magma_status_t status = magma_clean_cache(magma_bo(bo)->image, vma->offset, vma->length,
MAGMA_CACHE_OPERATION_CLEAN);
if (status != MAGMA_STATUS_OK) {
diff --git a/src/intel/vulkan/anv_image.c b/src/intel/vulkan/anv_image.c
index 893d0aa..800e455 100644
--- a/src/intel/vulkan/anv_image.c
+++ b/src/intel/vulkan/anv_image.c
@@ -1607,9 +1607,6 @@
}
assert(drm_format_modifier != DRM_FORMAT_MOD_INVALID);
- /* TODO(fxbug.dev/73404) - CCS disabled bc sysmem doesn't support it. */
- const uint32_t kExtraUsageFlags = ISL_SURF_USAGE_DISABLE_AUX_BIT;
-
/* If there is no explicit info, create a list-of-one to convey the modifier.
* Insert at the beginning of the chain to hide any existing list.
*/
@@ -1628,7 +1625,7 @@
VkResult result = anv_image_create(device,
&(struct anv_image_create_info){
.vk_info = &local_create_info,
- .isl_extra_usage_flags = kExtraUsageFlags,
+ .isl_extra_usage_flags = 0,
},
pAllocator, pImage);
if (result != VK_SUCCESS) {