summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKristian Høgsberg Kristensen <[email protected]>2015-08-19 21:36:57 -0700
committerKristian Høgsberg Kristensen <[email protected]>2015-08-24 13:45:40 -0700
commit988341a73c8d6d4f839802b129e3c6df14ddcc3c (patch)
tree3b61f43df417b358b769bd18983fd5892d12dc94
parentbc568ee992ff272372dc8e57524ab12ec0b7d8a8 (diff)
vk: Move anv_CreateImageView to gen8_state.c
We'll probably want to move some code back into a shared init function, but this gets one GEN8 surface state initialization out of anv_image.c. Signed-off-by: Kristian Høgsberg Kristensen <[email protected]>
-rw-r--r--src/vulkan/anv_image.c163
-rw-r--r--src/vulkan/anv_private.h15
-rw-r--r--src/vulkan/gen8_state.c154
3 files changed, 197 insertions, 135 deletions
diff --git a/src/vulkan/anv_image.c b/src/vulkan/anv_image.c
index f24acdb0fac..04fab514582 100644
--- a/src/vulkan/anv_image.c
+++ b/src/vulkan/anv_image.c
@@ -29,12 +29,6 @@
#include "anv_private.h"
-struct anv_image_view_info {
- uint8_t surface_type; /**< RENDER_SURFACE_STATE.SurfaceType */
- bool is_array:1; /**< RENDER_SURFACE_STATE.SurfaceArray */
- bool is_cube:1; /**< RENDER_SURFACE_STATE.CubeFaceEnable* */
-};
-
static const uint8_t anv_halign[] = {
[4] = HALIGN4,
[8] = HALIGN8,
@@ -67,6 +61,12 @@ anv_image_view_info_table[] = {
#undef INFO
};
+const struct anv_image_view_info *
+anv_image_view_info_for_vk_image_view_type(VkImageViewType type)
+{
+ return &anv_image_view_info_table[type];
+}
+
static const struct anv_surf_type_limits {
int32_t width;
int32_t height;
@@ -329,124 +329,6 @@ anv_surface_view_fini(struct anv_device *device,
anv_state_pool_free(&device->surface_state_pool, view->surface_state);
}
-void
-anv_image_view_init(struct anv_image_view *iview,
- struct anv_device *device,
- const VkImageViewCreateInfo* pCreateInfo,
- struct anv_cmd_buffer *cmd_buffer)
-{
- ANV_FROM_HANDLE(anv_image, image, pCreateInfo->image);
-
- const VkImageSubresourceRange *range = &pCreateInfo->subresourceRange;
- struct anv_surface_view *view = &iview->view;
- struct anv_surface *surface;
-
- const struct anv_image_view_info *view_type_info
- = &anv_image_view_info_table[pCreateInfo->viewType];
-
- if (pCreateInfo->viewType != VK_IMAGE_VIEW_TYPE_2D)
- anv_finishme("non-2D image views");
-
- switch (pCreateInfo->subresourceRange.aspect) {
- case VK_IMAGE_ASPECT_STENCIL:
- anv_finishme("stencil image views");
- abort();
- break;
- case VK_IMAGE_ASPECT_DEPTH:
- case VK_IMAGE_ASPECT_COLOR:
- surface = &image->primary_surface;
- break;
- default:
- unreachable("");
- break;
- }
-
- view->bo = image->bo;
- view->offset = image->offset + surface->offset;
- view->format = anv_format_for_vk_format(pCreateInfo->format);
-
- iview->extent = (VkExtent3D) {
- .width = anv_minify(image->extent.width, range->baseMipLevel),
- .height = anv_minify(image->extent.height, range->baseMipLevel),
- .depth = anv_minify(image->extent.depth, range->baseMipLevel),
- };
-
- uint32_t depth = 1;
- if (range->arraySize > 1) {
- depth = range->arraySize;
- } else if (image->extent.depth > 1) {
- depth = image->extent.depth;
- }
-
- static const uint32_t vk_to_gen_swizzle[] = {
- [VK_CHANNEL_SWIZZLE_ZERO] = SCS_ZERO,
- [VK_CHANNEL_SWIZZLE_ONE] = SCS_ONE,
- [VK_CHANNEL_SWIZZLE_R] = SCS_RED,
- [VK_CHANNEL_SWIZZLE_G] = SCS_GREEN,
- [VK_CHANNEL_SWIZZLE_B] = SCS_BLUE,
- [VK_CHANNEL_SWIZZLE_A] = SCS_ALPHA
- };
-
- struct GEN8_RENDER_SURFACE_STATE surface_state = {
- .SurfaceType = view_type_info->surface_type,
- .SurfaceArray = image->array_size > 1,
- .SurfaceFormat = view->format->surface_format,
- .SurfaceVerticalAlignment = anv_valign[surface->v_align],
- .SurfaceHorizontalAlignment = anv_halign[surface->h_align],
- .TileMode = surface->tile_mode,
- .VerticalLineStride = 0,
- .VerticalLineStrideOffset = 0,
- .SamplerL2BypassModeDisable = true,
- .RenderCacheReadWriteMode = WriteOnlyCache,
- .MemoryObjectControlState = GEN8_MOCS,
-
- /* The driver sets BaseMipLevel in SAMPLER_STATE, not here in
- * RENDER_SURFACE_STATE. The Broadwell PRM says "it is illegal to have
- * both Base Mip Level fields nonzero".
- */
- .BaseMipLevel = 0.0,
-
- .SurfaceQPitch = surface->qpitch >> 2,
- .Height = image->extent.height - 1,
- .Width = image->extent.width - 1,
- .Depth = depth - 1,
- .SurfacePitch = surface->stride - 1,
- .MinimumArrayElement = range->baseArraySlice,
- .NumberofMultisamples = MULTISAMPLECOUNT_1,
- .XOffset = 0,
- .YOffset = 0,
-
- /* For sampler surfaces, the hardware interprets field MIPCount/LOD as
- * MIPCount. The range of levels accessible by the sampler engine is
- * [SurfaceMinLOD, SurfaceMinLOD + MIPCountLOD].
- */
- .MIPCountLOD = range->mipLevels - 1,
- .SurfaceMinLOD = range->baseMipLevel,
-
- .AuxiliarySurfaceMode = AUX_NONE,
- .RedClearColor = 0,
- .GreenClearColor = 0,
- .BlueClearColor = 0,
- .AlphaClearColor = 0,
- .ShaderChannelSelectRed = vk_to_gen_swizzle[pCreateInfo->channels.r],
- .ShaderChannelSelectGreen = vk_to_gen_swizzle[pCreateInfo->channels.g],
- .ShaderChannelSelectBlue = vk_to_gen_swizzle[pCreateInfo->channels.b],
- .ShaderChannelSelectAlpha = vk_to_gen_swizzle[pCreateInfo->channels.a],
- .ResourceMinLOD = 0.0,
- .SurfaceBaseAddress = { NULL, view->offset },
- };
-
- if (cmd_buffer) {
- view->surface_state =
- anv_state_stream_alloc(&cmd_buffer->surface_state_stream, 64, 64);
- } else {
- view->surface_state =
- anv_state_pool_alloc(&device->surface_state_pool, 64, 64);
- }
-
- GEN8_RENDER_SURFACE_STATE_pack(NULL, view->surface_state.map, &surface_state);
-}
-
VkResult
anv_validate_CreateImageView(VkDevice _device,
const VkImageViewCreateInfo *pCreateInfo,
@@ -525,26 +407,37 @@ anv_validate_CreateImageView(VkDevice _device,
return anv_CreateImageView(_device, pCreateInfo, pView);
}
+void
+anv_image_view_init(struct anv_image_view *iview,
+ struct anv_device *device,
+ const VkImageViewCreateInfo* pCreateInfo,
+ struct anv_cmd_buffer *cmd_buffer)
+{
+ switch (device->info.gen) {
+ case 8:
+ gen8_image_view_init(iview, device, pCreateInfo, cmd_buffer);
+ break;
+ default:
+ unreachable("unsupported gen\n");
+ }
+}
+
VkResult
anv_CreateImageView(VkDevice _device,
const VkImageViewCreateInfo *pCreateInfo,
VkImageView *pView)
{
ANV_FROM_HANDLE(anv_device, device, _device);
- struct anv_image_view *view;
-
- view = anv_device_alloc(device, sizeof(*view), 8,
- VK_SYSTEM_ALLOC_TYPE_API_OBJECT);
- if (view == NULL)
- return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
- anv_image_view_init(view, device, pCreateInfo, NULL);
-
- *pView = anv_image_view_to_handle(view);
-
- return VK_SUCCESS;
+ switch (device->info.gen) {
+ case 8:
+ return gen8_CreateImageView(_device, pCreateInfo, pView);
+ default:
+ unreachable("unsupported gen\n");
+ }
}
+
VkResult
anv_DestroyImageView(VkDevice _device, VkImageView _iview)
{
diff --git a/src/vulkan/anv_private.h b/src/vulkan/anv_private.h
index 2f741aca101..234cb6ebdc3 100644
--- a/src/vulkan/anv_private.h
+++ b/src/vulkan/anv_private.h
@@ -931,6 +931,15 @@ anv_format_is_depth_or_stencil(const struct anv_format *format)
return format->depth_format || format->has_stencil;
}
+struct anv_image_view_info {
+ uint8_t surface_type; /**< RENDER_SURFACE_STATE.SurfaceType */
+ bool is_array:1; /**< RENDER_SURFACE_STATE.SurfaceArray */
+ bool is_cube:1; /**< RENDER_SURFACE_STATE.CubeFaceEnable* */
+};
+
+const struct anv_image_view_info *
+anv_image_view_info_for_vk_image_view_type(VkImageViewType type);
+
/**
* A proxy for the color surfaces, depth surfaces, and stencil surfaces.
*/
@@ -1047,6 +1056,12 @@ void anv_image_view_init(struct anv_image_view *view,
const VkImageViewCreateInfo* pCreateInfo,
struct anv_cmd_buffer *cmd_buffer);
+void
+gen8_image_view_init(struct anv_image_view *iview,
+ struct anv_device *device,
+ const VkImageViewCreateInfo* pCreateInfo,
+ struct anv_cmd_buffer *cmd_buffer);
+
void anv_color_attachment_view_init(struct anv_color_attachment_view *view,
struct anv_device *device,
const VkAttachmentViewCreateInfo* pCreateInfo,
diff --git a/src/vulkan/gen8_state.c b/src/vulkan/gen8_state.c
index d7078a21696..fb013cbf3a4 100644
--- a/src/vulkan/gen8_state.c
+++ b/src/vulkan/gen8_state.c
@@ -142,6 +142,160 @@ VkResult gen8_CreateBufferView(
return VK_SUCCESS;
}
+static const uint8_t anv_halign[] = {
+ [4] = HALIGN4,
+ [8] = HALIGN8,
+ [16] = HALIGN16,
+};
+
+static const uint8_t anv_valign[] = {
+ [4] = VALIGN4,
+ [8] = VALIGN8,
+ [16] = VALIGN16,
+};
+
+void
+gen8_image_view_init(struct anv_image_view *iview,
+ struct anv_device *device,
+ const VkImageViewCreateInfo* pCreateInfo,
+ struct anv_cmd_buffer *cmd_buffer)
+{
+ ANV_FROM_HANDLE(anv_image, image, pCreateInfo->image);
+
+ const VkImageSubresourceRange *range = &pCreateInfo->subresourceRange;
+ struct anv_surface_view *view = &iview->view;
+ struct anv_surface *surface;
+
+ const struct anv_format *format_info =
+ anv_format_for_vk_format(pCreateInfo->format);
+
+ const struct anv_image_view_info *view_type_info =
+ anv_image_view_info_for_vk_image_view_type(pCreateInfo->viewType);
+
+ if (pCreateInfo->viewType != VK_IMAGE_VIEW_TYPE_2D)
+ anv_finishme("non-2D image views");
+
+ switch (pCreateInfo->subresourceRange.aspect) {
+ case VK_IMAGE_ASPECT_STENCIL:
+ anv_finishme("stencil image views");
+ abort();
+ break;
+ case VK_IMAGE_ASPECT_DEPTH:
+ case VK_IMAGE_ASPECT_COLOR:
+ view->offset = image->offset;
+ surface = &image->primary_surface;
+ break;
+ default:
+ unreachable("");
+ break;
+ }
+
+ view->bo = image->bo;
+ view->offset = image->offset + surface->offset;
+ view->format = format_info;
+
+ iview->extent = (VkExtent3D) {
+ .width = anv_minify(image->extent.width, range->baseMipLevel),
+ .height = anv_minify(image->extent.height, range->baseMipLevel),
+ .depth = anv_minify(image->extent.depth, range->baseMipLevel),
+ };
+
+ uint32_t depth = 1;
+ if (range->arraySize > 1) {
+ depth = range->arraySize;
+ } else if (image->extent.depth > 1) {
+ depth = image->extent.depth;
+ }
+
+ static const uint32_t vk_to_gen_swizzle[] = {
+ [VK_CHANNEL_SWIZZLE_ZERO] = SCS_ZERO,
+ [VK_CHANNEL_SWIZZLE_ONE] = SCS_ONE,
+ [VK_CHANNEL_SWIZZLE_R] = SCS_RED,
+ [VK_CHANNEL_SWIZZLE_G] = SCS_GREEN,
+ [VK_CHANNEL_SWIZZLE_B] = SCS_BLUE,
+ [VK_CHANNEL_SWIZZLE_A] = SCS_ALPHA
+ };
+
+ struct GEN8_RENDER_SURFACE_STATE surface_state = {
+ .SurfaceType = view_type_info->surface_type,
+ .SurfaceArray = image->array_size > 1,
+ .SurfaceFormat = format_info->surface_format,
+ .SurfaceVerticalAlignment = anv_valign[surface->v_align],
+ .SurfaceHorizontalAlignment = anv_halign[surface->h_align],
+ .TileMode = surface->tile_mode,
+ .VerticalLineStride = 0,
+ .VerticalLineStrideOffset = 0,
+ .SamplerL2BypassModeDisable = true,
+ .RenderCacheReadWriteMode = WriteOnlyCache,
+ .MemoryObjectControlState = GEN8_MOCS,
+
+ /* The driver sets BaseMipLevel in SAMPLER_STATE, not here in
+ * RENDER_SURFACE_STATE. The Broadwell PRM says "it is illegal to have
+ * both Base Mip Level fields nonzero".
+ */
+ .BaseMipLevel = 0.0,
+
+ .SurfaceQPitch = surface->qpitch >> 2,
+ .Height = image->extent.height - 1,
+ .Width = image->extent.width - 1,
+ .Depth = depth - 1,
+ .SurfacePitch = surface->stride - 1,
+ .MinimumArrayElement = range->baseArraySlice,
+ .NumberofMultisamples = MULTISAMPLECOUNT_1,
+ .XOffset = 0,
+ .YOffset = 0,
+
+ /* For sampler surfaces, the hardware interprets field MIPCount/LOD as
+ * MIPCount. The range of levels accessible by the sampler engine is
+ * [SurfaceMinLOD, SurfaceMinLOD + MIPCountLOD].
+ */
+ .MIPCountLOD = range->mipLevels - 1,
+ .SurfaceMinLOD = range->baseMipLevel,
+
+ .AuxiliarySurfaceMode = AUX_NONE,
+ .RedClearColor = 0,
+ .GreenClearColor = 0,
+ .BlueClearColor = 0,
+ .AlphaClearColor = 0,
+ .ShaderChannelSelectRed = vk_to_gen_swizzle[pCreateInfo->channels.r],
+ .ShaderChannelSelectGreen = vk_to_gen_swizzle[pCreateInfo->channels.g],
+ .ShaderChannelSelectBlue = vk_to_gen_swizzle[pCreateInfo->channels.b],
+ .ShaderChannelSelectAlpha = vk_to_gen_swizzle[pCreateInfo->channels.a],
+ .ResourceMinLOD = 0.0,
+ .SurfaceBaseAddress = { NULL, view->offset },
+ };
+
+ if (cmd_buffer) {
+ view->surface_state =
+ anv_state_stream_alloc(&cmd_buffer->surface_state_stream, 64, 64);
+ } else {
+ view->surface_state =
+ anv_state_pool_alloc(&device->surface_state_pool, 64, 64);
+ }
+
+ GEN8_RENDER_SURFACE_STATE_pack(NULL, view->surface_state.map, &surface_state);
+}
+
+VkResult
+gen8_CreateImageView(VkDevice _device,
+ const VkImageViewCreateInfo *pCreateInfo,
+ VkImageView *pView)
+{
+ ANV_FROM_HANDLE(anv_device, device, _device);
+ struct anv_image_view *view;
+
+ view = anv_device_alloc(device, sizeof(*view), 8,
+ VK_SYSTEM_ALLOC_TYPE_API_OBJECT);
+ if (view == NULL)
+ return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
+
+ anv_image_view_init(view, device, pCreateInfo, NULL);
+
+ *pView = anv_image_view_to_handle(view);
+
+ return VK_SUCCESS;
+}
+
VkResult gen8_CreateSampler(
VkDevice _device,
const VkSamplerCreateInfo* pCreateInfo,