From 84612f4014089b089c9a04a6592b5a1ea7423c70 Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Fri, 22 Jan 2016 11:40:56 -0800 Subject: [PATCH] anv/state: Refactor surface state setup into a "fill" function --- src/vulkan/gen7_state.c | 49 +++++++++++++++-------------------------- src/vulkan/gen8_state.c | 48 +++++++++++++++------------------------- 2 files changed, 36 insertions(+), 61 deletions(-) diff --git a/src/vulkan/gen7_state.c b/src/vulkan/gen7_state.c index aecdfe2fe4d..2d16bf3861b 100644 --- a/src/vulkan/gen7_state.c +++ b/src/vulkan/gen7_state.c @@ -148,11 +148,11 @@ static const uint8_t anv_valign[] = { [4] = VALIGN_4, }; -static struct GENX(RENDER_SURFACE_STATE) -surface_state_for_image_view(struct anv_image_view *iview, - struct anv_device *device, - const VkImageViewCreateInfo *pCreateInfo, - VkImageUsageFlagBits usage) +static void +genX(fill_image_surface_state)(struct anv_device *device, void *state_map, + struct anv_image_view *iview, + const VkImageViewCreateInfo *pCreateInfo, + VkImageUsageFlagBits usage) { assert(usage & (VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT | @@ -248,7 +248,10 @@ surface_state_for_image_view(struct anv_image_view *iview, template.MIPCountLOD = MAX2(range->levelCount, 1) - 1; } - return template; + GENX(RENDER_SURFACE_STATE_pack)(NULL, state_map, &template); + + if (!device->info.has_llc) + anv_state_clflush(iview->nonrt_surface_state); } GENX_FUNC(GEN7, GEN75) void @@ -263,47 +266,31 @@ genX(image_view_init)(struct anv_image_view *iview, anv_finishme("non-2D image views"); if (image->needs_nonrt_surface_state) { - struct GENX(RENDER_SURFACE_STATE) surface_state = - surface_state_for_image_view(iview, device, pCreateInfo, - VK_IMAGE_USAGE_SAMPLED_BIT); - iview->nonrt_surface_state = alloc_surface_state(device, cmd_buffer); - GENX(RENDER_SURFACE_STATE_pack)(NULL, iview->nonrt_surface_state.map, - &surface_state); - - if (!device->info.has_llc) - anv_state_clflush(iview->nonrt_surface_state); + genX(fill_image_surface_state)(device, iview->nonrt_surface_state.map, + iview, pCreateInfo, + VK_IMAGE_USAGE_SAMPLED_BIT); } else { iview->nonrt_surface_state.alloc_size = 0; } if (image->needs_color_rt_surface_state) { - struct GENX(RENDER_SURFACE_STATE) surface_state = - surface_state_for_image_view(iview, device, pCreateInfo, - VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT); - iview->color_rt_surface_state = alloc_surface_state(device, cmd_buffer); - GENX(RENDER_SURFACE_STATE_pack)(NULL, iview->color_rt_surface_state.map, - &surface_state); - if (!device->info.has_llc) - anv_state_clflush(iview->color_rt_surface_state); + genX(fill_image_surface_state)(device, iview->color_rt_surface_state.map, + iview, pCreateInfo, + VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT); } else { iview->color_rt_surface_state.alloc_size = 0; } if (image->needs_storage_surface_state) { - struct GENX(RENDER_SURFACE_STATE) surface_state = - surface_state_for_image_view(iview, device, pCreateInfo, - VK_IMAGE_USAGE_STORAGE_BIT); - iview->storage_surface_state = alloc_surface_state(device, cmd_buffer); - GENX(RENDER_SURFACE_STATE_pack)(NULL, iview->storage_surface_state.map, - &surface_state); - if (!device->info.has_llc) - anv_state_clflush(iview->storage_surface_state); + genX(fill_image_surface_state)(device, iview->storage_surface_state.map, + iview, pCreateInfo, + VK_IMAGE_USAGE_STORAGE_BIT); } else { iview->storage_surface_state.alloc_size = 0; } diff --git a/src/vulkan/gen8_state.c b/src/vulkan/gen8_state.c index 9fad7961b3f..15bf0ffe4ac 100644 --- a/src/vulkan/gen8_state.c +++ b/src/vulkan/gen8_state.c @@ -162,11 +162,11 @@ get_qpitch(const struct isl_surf *surf) } } -static struct GENX(RENDER_SURFACE_STATE) -surface_state_for_image_view(struct anv_image_view *iview, - struct anv_device *device, - const VkImageViewCreateInfo *pCreateInfo, - VkImageUsageFlagBits usage) +static void +genX(fill_image_surface_state)(struct anv_device *device, void *state_map, + struct anv_image_view *iview, + const VkImageViewCreateInfo *pCreateInfo, + VkImageUsageFlagBits usage) { assert(usage & (VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT | @@ -319,7 +319,10 @@ surface_state_for_image_view(struct anv_image_view *iview, template.MIPCountLOD = MAX2(range->levelCount, 1) - 1; } - return template; + GENX(RENDER_SURFACE_STATE_pack)(NULL, state_map, &template); + + if (!device->info.has_llc) + anv_state_clflush(iview->nonrt_surface_state); } void @@ -331,49 +334,34 @@ genX(image_view_init)(struct anv_image_view *iview, ANV_FROM_HANDLE(anv_image, image, pCreateInfo->image); if (image->needs_nonrt_surface_state) { - const struct GENX(RENDER_SURFACE_STATE) surface_state = - surface_state_for_image_view(iview, device, pCreateInfo, - VK_IMAGE_USAGE_SAMPLED_BIT); - iview->nonrt_surface_state = alloc_surface_state(device, cmd_buffer); - GENX(RENDER_SURFACE_STATE_pack)(NULL, iview->nonrt_surface_state.map, - &surface_state); - if (!device->info.has_llc) - anv_state_clflush(iview->nonrt_surface_state); + genX(fill_image_surface_state)(device, iview->nonrt_surface_state.map, + iview, pCreateInfo, + VK_IMAGE_USAGE_SAMPLED_BIT); } else { iview->nonrt_surface_state.alloc_size = 0; } if (image->needs_color_rt_surface_state) { - const struct GENX(RENDER_SURFACE_STATE) surface_state = - surface_state_for_image_view(iview, device, pCreateInfo, - VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT); - iview->color_rt_surface_state = alloc_surface_state(device, cmd_buffer); - GENX(RENDER_SURFACE_STATE_pack)(NULL, iview->color_rt_surface_state.map, - &surface_state); - if (!device->info.has_llc) - anv_state_clflush(iview->color_rt_surface_state); + genX(fill_image_surface_state)(device, iview->color_rt_surface_state.map, + iview, pCreateInfo, + VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT); } else { iview->color_rt_surface_state.alloc_size = 0; } if (image->needs_storage_surface_state) { - struct GENX(RENDER_SURFACE_STATE) surface_state = - surface_state_for_image_view(iview, device, pCreateInfo, - VK_IMAGE_USAGE_STORAGE_BIT); - iview->storage_surface_state = alloc_surface_state(device, cmd_buffer); - GENX(RENDER_SURFACE_STATE_pack)(NULL, iview->storage_surface_state.map, - &surface_state); - if (!device->info.has_llc) - anv_state_clflush(iview->storage_surface_state); + genX(fill_image_surface_state)(device, iview->storage_surface_state.map, + iview, pCreateInfo, + VK_IMAGE_USAGE_STORAGE_BIT); } else { iview->storage_surface_state.alloc_size = 0; } -- 2.30.2