summaryrefslogtreecommitdiffstats
path: root/src/vulkan/image.c
diff options
context:
space:
mode:
authorKristian Høgsberg <[email protected]>2015-05-25 22:12:24 -0700
committerKristian Høgsberg <[email protected]>2015-05-26 11:27:29 -0700
commit0dbed616aff26edf007e8b55f6a5d85aea0ef0d1 (patch)
tree602b0b28524984a2c688dd26e15af1bfce3ec160 /src/vulkan/image.c
parentcbe7ed416ec0ae7d6527916ef5dc50e483bc2685 (diff)
vk: Add support for texture component swizzle
This also drops the share create_surface_state helper and moves filling out SURFACE_STATE directly into anv_image_view_init() and anv_color_attachment_view_init().
Diffstat (limited to 'src/vulkan/image.c')
-rw-r--r--src/vulkan/image.c152
1 files changed, 97 insertions, 55 deletions
diff --git a/src/vulkan/image.c b/src/vulkan/image.c
index 99542f1b538..5404dd29ea7 100644
--- a/src/vulkan/image.c
+++ b/src/vulkan/image.c
@@ -145,17 +145,47 @@ VkResult anv_GetImageSubresourceInfo(
stub_return(VK_UNSUPPORTED);
}
-static struct anv_state
-create_surface_state(struct anv_device *device,
- struct anv_image *image, uint32_t format, uint32_t tile_mode,
- uint32_t offset, struct anv_cmd_buffer *cmd_buffer)
+void
+anv_image_view_init(struct anv_surface_view *view,
+ struct anv_device *device,
+ const VkImageViewCreateInfo* pCreateInfo,
+ struct anv_cmd_buffer *cmd_buffer)
{
- struct anv_state state;
+ struct anv_image *image = (struct anv_image *) pCreateInfo->image;
+ const struct anv_format *info =
+ anv_format_for_vk_format(pCreateInfo->format);
+ uint32_t tile_mode, format;
- if (cmd_buffer)
- state = anv_state_stream_alloc(&cmd_buffer->surface_state_stream, 64, 64);
- else
- state = anv_state_pool_alloc(&device->surface_state_pool, 64, 64);
+ view->bo = image->bo;
+ switch (pCreateInfo->subresourceRange.aspect) {
+ case VK_IMAGE_ASPECT_STENCIL:
+ /* FIXME: How is stencil texturing formed? */
+ view->offset = image->offset + image->stencil_offset;
+ tile_mode = WMAJOR;
+ format = R8_UINT;
+ break;
+ case VK_IMAGE_ASPECT_DEPTH:
+ case VK_IMAGE_ASPECT_COLOR:
+ view->offset = image->offset;
+ tile_mode = image->tile_mode;
+ format = info->format;
+ break;
+ default:
+ assert(0);
+ break;
+ }
+
+ /* TODO: Miplevels */
+ view->extent = image->extent;
+
+ 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 = SURFTYPE_2D,
@@ -186,53 +216,22 @@ create_surface_state(struct anv_device *device,
.GreenClearColor = 0,
.BlueClearColor = 0,
.AlphaClearColor = 0,
- .ShaderChannelSelectRed = SCS_RED,
- .ShaderChannelSelectGreen = SCS_GREEN,
- .ShaderChannelSelectBlue = SCS_BLUE,
- .ShaderChannelSelectAlpha = SCS_ALPHA,
+ .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,
- .SurfaceBaseAddress = { NULL, offset },
+ .SurfaceBaseAddress = { NULL, view->offset },
};
- GEN8_RENDER_SURFACE_STATE_pack(NULL, state.map, &surface_state);
-
- return state;
-}
-
-void
-anv_image_view_init(struct anv_surface_view *view,
- struct anv_device *device,
- const VkImageViewCreateInfo* pCreateInfo,
- struct anv_cmd_buffer *cmd_buffer)
-{
- struct anv_image *image = (struct anv_image *) pCreateInfo->image;
- const struct anv_format *info =
- anv_format_for_vk_format(pCreateInfo->format);
- uint32_t tile_mode, format;
-
- view->bo = image->bo;
- switch (pCreateInfo->subresourceRange.aspect) {
- case VK_IMAGE_ASPECT_STENCIL:
- /* FIXME: How is stencil texturing formed? */
- view->offset = image->offset + image->stencil_offset;
- tile_mode = WMAJOR;
- format = R8_UINT;
- break;
- case VK_IMAGE_ASPECT_DEPTH:
- case VK_IMAGE_ASPECT_COLOR:
- view->offset = image->offset;
- tile_mode = image->tile_mode;
- format = info->format;
- break;
- default:
- assert(0);
- break;
- }
+ 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);
- /* TODO: Miplevels */
- view->extent = image->extent;
- view->surface_state =
- create_surface_state(device, image, format, tile_mode, view->offset, cmd_buffer);
+ GEN8_RENDER_SURFACE_STATE_pack(NULL, view->surface_state.map, &surface_state);
}
VkResult anv_CreateImageView(
@@ -271,9 +270,52 @@ anv_color_attachment_view_init(struct anv_surface_view *view,
view->offset = image->offset;
view->extent = image->extent;
view->format = pCreateInfo->format;
- view->surface_state =
- create_surface_state(device, image,
- format->format, image->tile_mode, view->offset, cmd_buffer);
+
+ 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);
+
+ struct GEN8_RENDER_SURFACE_STATE surface_state = {
+ .SurfaceType = SURFTYPE_2D,
+ .SurfaceArray = false,
+ .SurfaceFormat = format->format,
+ .SurfaceVerticalAlignment = VALIGN4,
+ .SurfaceHorizontalAlignment = HALIGN4,
+ .TileMode = image->tile_mode,
+ .VerticalLineStride = 0,
+ .VerticalLineStrideOffset = 0,
+ .SamplerL2BypassModeDisable = true,
+ .RenderCacheReadWriteMode = WriteOnlyCache,
+ .MemoryObjectControlState = GEN8_MOCS,
+ .BaseMipLevel = 0,
+ .SurfaceQPitch = 0,
+ .Height = image->extent.height - 1,
+ .Width = image->extent.width - 1,
+ .Depth = image->extent.depth - 1,
+ .SurfacePitch = image->stride - 1,
+ .MinimumArrayElement = 0,
+ .NumberofMultisamples = MULTISAMPLECOUNT_1,
+ .XOffset = 0,
+ .YOffset = 0,
+ .SurfaceMinLOD = 0,
+ .MIPCountLOD = 0,
+ .AuxiliarySurfaceMode = AUX_NONE,
+ .RedClearColor = 0,
+ .GreenClearColor = 0,
+ .BlueClearColor = 0,
+ .AlphaClearColor = 0,
+ .ShaderChannelSelectRed = SCS_RED,
+ .ShaderChannelSelectGreen = SCS_GREEN,
+ .ShaderChannelSelectBlue = SCS_BLUE,
+ .ShaderChannelSelectAlpha = SCS_ALPHA,
+ .ResourceMinLOD = 0,
+ .SurfaceBaseAddress = { NULL, view->offset },
+ };
+
+ GEN8_RENDER_SURFACE_STATE_pack(NULL, view->surface_state.map, &surface_state);
}
VkResult anv_CreateColorAttachmentView(