vk: Consolidate image, buffer and color attachment views

These are all just surface state, offset and a bo.
This commit is contained in:
Kristian Høgsberg
2015-05-13 15:31:26 -07:00
parent 41db8db0f2
commit f5b0f1351f
5 changed files with 50 additions and 77 deletions

View File

@@ -1252,7 +1252,8 @@ VkResult VKAPI vkCreateBufferView(
VkBufferView* pView) VkBufferView* pView)
{ {
struct anv_device *device = (struct anv_device *) _device; struct anv_device *device = (struct anv_device *) _device;
struct anv_buffer_view *view; struct anv_buffer *buffer = (struct anv_buffer *) pCreateInfo->buffer;
struct anv_surface_view *view;
const struct anv_format *format; const struct anv_format *format;
assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO); assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO);
@@ -1262,10 +1263,11 @@ VkResult VKAPI vkCreateBufferView(
if (view == NULL) if (view == NULL)
return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
view->buffer = (struct anv_buffer *) pCreateInfo->buffer; view->bo = buffer->bo;
view->offset = pCreateInfo->offset; view->offset = buffer->offset + pCreateInfo->offset;
view->surface_state = view->surface_state =
anv_state_pool_alloc(&device->surface_state_pool, 64, 64); anv_state_pool_alloc(&device->surface_state_pool, 64, 64);
view->format = pCreateInfo->format;
format = anv_format_for_vk_format(pCreateInfo->format); format = anv_format_for_vk_format(pCreateInfo->format);
/* This assumes RGBA float format. */ /* This assumes RGBA float format. */
@@ -1306,7 +1308,7 @@ VkResult VKAPI vkCreateBufferView(
.ShaderChannelSelectAlpha = SCS_ALPHA, .ShaderChannelSelectAlpha = SCS_ALPHA,
.ResourceMinLOD = 0, .ResourceMinLOD = 0,
/* FIXME: We assume that the image must be bound at this time. */ /* FIXME: We assume that the image must be bound at this time. */
.SurfaceBaseAddress = { NULL, view->buffer->offset + view->offset }, .SurfaceBaseAddress = { NULL, view->offset },
}; };
GEN8_RENDER_SURFACE_STATE_pack(NULL, view->surface_state.map, &surface_state); GEN8_RENDER_SURFACE_STATE_pack(NULL, view->surface_state.map, &surface_state);
@@ -1581,8 +1583,8 @@ void VKAPI vkUpdateDescriptors(
update_sampler_textures = (VkUpdateSamplerTextures *) common; update_sampler_textures = (VkUpdateSamplerTextures *) common;
for (uint32_t j = 0; j < update_sampler_textures->count; j++) { for (uint32_t j = 0; j < update_sampler_textures->count; j++) {
set->descriptors[update_sampler_textures->binding + j].image_view = set->descriptors[update_sampler_textures->binding + j].view =
(struct anv_image_view *) (struct anv_surface_view *)
update_sampler_textures->pSamplerImageViews[j].pImageView->view; update_sampler_textures->pSamplerImageViews[j].pImageView->view;
set->descriptors[update_sampler_textures->binding + j].sampler = set->descriptors[update_sampler_textures->binding + j].sampler =
(struct anv_sampler *) (struct anv_sampler *)
@@ -1594,8 +1596,8 @@ void VKAPI vkUpdateDescriptors(
update_images = (VkUpdateImages *) common; update_images = (VkUpdateImages *) common;
for (uint32_t j = 0; j < update_images->count; j++) { for (uint32_t j = 0; j < update_images->count; j++) {
set->descriptors[update_images->binding + j].image_view = set->descriptors[update_images->binding + j].view =
(struct anv_image_view *) update_images->pImageViews[j].view; (struct anv_surface_view *) update_images->pImageViews[j].view;
} }
break; break;
@@ -1603,8 +1605,8 @@ void VKAPI vkUpdateDescriptors(
update_buffers = (VkUpdateBuffers *) common; update_buffers = (VkUpdateBuffers *) common;
for (uint32_t j = 0; j < update_buffers->count; j++) { for (uint32_t j = 0; j < update_buffers->count; j++) {
set->descriptors[update_buffers->binding + j].buffer_view = set->descriptors[update_buffers->binding + j].view =
(struct anv_buffer_view *) update_buffers->pBufferViews[j].view; (struct anv_surface_view *) update_buffers->pBufferViews[j].view;
} }
/* FIXME: descriptor arrays? */ /* FIXME: descriptor arrays? */
break; break;
@@ -2185,24 +2187,21 @@ flush_descriptor_sets(struct anv_cmd_buffer *cmd_buffer)
if (s == VK_SHADER_STAGE_FRAGMENT) { if (s == VK_SHADER_STAGE_FRAGMENT) {
for (uint32_t i = 0; i < framebuffer->color_attachment_count; i++) { for (uint32_t i = 0; i < framebuffer->color_attachment_count; i++) {
struct anv_color_attachment_view *view = framebuffer->color_attachments[i]; struct anv_surface_view *view = framebuffer->color_attachments[i];
table[i] = view->surface_state.offset; table[i] = view->surface_state.offset;
/* Don't write the reloc back to the surface state. We do that at /* Don't write the reloc back to the surface state. We do that at
* submit time. Surface address is dwords 8-9. */ * submit time. Surface address is dwords 8-9. */
anv_reloc_list_add(&cmd_buffer->batch.surf_relocs, anv_reloc_list_add(&cmd_buffer->batch.surf_relocs,
view->surface_state.offset + 8 * sizeof(int32_t), view->surface_state.offset + 8 * sizeof(int32_t),
view->image->bo, view->image->offset); view->bo, view->offset);
} }
} }
if (layout) { if (layout) {
for (uint32_t i = 0; i < layout->stage[s].surface_count; i++) { for (uint32_t i = 0; i < layout->stage[s].surface_count; i++) {
struct anv_pipeline_layout_entry *e = &layout->stage[s].surface_entries[i]; struct anv_pipeline_layout_entry *e = &layout->stage[s].surface_entries[i];
struct anv_descriptor *d = struct anv_surface_view *view;
&cmd_buffer->descriptor_sets[e->set]->descriptors[e->index];
struct anv_image_view *image_view;
struct anv_buffer_view *buffer_view;
switch (e->type) { switch (e->type) {
case VK_DESCRIPTOR_TYPE_SAMPLER: case VK_DESCRIPTOR_TYPE_SAMPLER:
@@ -2211,26 +2210,15 @@ flush_descriptor_sets(struct anv_cmd_buffer *cmd_buffer)
case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE: case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE: case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
image_view = d->image_view;
table[bias + i] = image_view->surface_state.offset;
anv_reloc_list_add(&cmd_buffer->batch.surf_relocs,
image_view->surface_state.offset + 8 * sizeof(int32_t),
image_view->image->bo,
image_view->image->offset);
break;
case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER: case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER: case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
/* FIXME: What are these? TBOs? */
break;
case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER: case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER: case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
buffer_view = d->buffer_view; view = cmd_buffer->descriptor_sets[e->set]->descriptors[e->index].view;
table[bias + i] = buffer_view->surface_state.offset; table[bias + i] = view->surface_state.offset;
anv_reloc_list_add(&cmd_buffer->batch.surf_relocs, anv_reloc_list_add(&cmd_buffer->batch.surf_relocs,
buffer_view->surface_state.offset + 8 * sizeof(int32_t), view->surface_state.offset + 8 * sizeof(int32_t),
buffer_view->buffer->bo, view->bo, view->offset);
buffer_view->buffer->offset + buffer_view->offset);
break; break;
case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC: case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
@@ -2673,7 +2661,7 @@ VkResult VKAPI vkCreateFramebuffer(
framebuffer->color_attachment_count = pCreateInfo->colorAttachmentCount; framebuffer->color_attachment_count = pCreateInfo->colorAttachmentCount;
for (uint32_t i = 0; i < pCreateInfo->colorAttachmentCount; i++) { for (uint32_t i = 0; i < pCreateInfo->colorAttachmentCount; i++) {
framebuffer->color_attachments[i] = framebuffer->color_attachments[i] =
(struct anv_color_attachment_view *) pCreateInfo->pColorAttachments[i].view; (struct anv_surface_view *) pCreateInfo->pColorAttachments[i].view;
} }
if (pCreateInfo->pDepthStencilAttachment) { if (pCreateInfo->pDepthStencilAttachment) {

View File

@@ -348,7 +348,8 @@ VkResult VKAPI vkCreateImageView(
VkImageView* pView) VkImageView* pView)
{ {
struct anv_device *device = (struct anv_device *) _device; struct anv_device *device = (struct anv_device *) _device;
struct anv_image_view *view; struct anv_surface_view *view;
struct anv_image *image = (struct anv_image *) pCreateInfo->image;
const struct anv_format *format = const struct anv_format *format =
anv_format_for_vk_format(pCreateInfo->format); anv_format_for_vk_format(pCreateInfo->format);
@@ -359,12 +360,13 @@ VkResult VKAPI vkCreateImageView(
if (view == NULL) if (view == NULL)
return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
view->image = (struct anv_image *) pCreateInfo->image; view->bo = image->bo;
view->offset = image->offset;
view->surface_state = create_surface_state(device, view->image, format); view->surface_state = create_surface_state(device, image, format);
view->format = pCreateInfo->format;
/* TODO: Miplevels */ /* TODO: Miplevels */
view->extent = view->image->extent; view->extent = image->extent;
*pView = (VkImageView) view; *pView = (VkImageView) view;
@@ -377,7 +379,8 @@ VkResult VKAPI vkCreateColorAttachmentView(
VkColorAttachmentView* pView) VkColorAttachmentView* pView)
{ {
struct anv_device *device = (struct anv_device *) _device; struct anv_device *device = (struct anv_device *) _device;
struct anv_color_attachment_view *view; struct anv_surface_view *view;
struct anv_image *image = (struct anv_image *) pCreateInfo->image;
const struct anv_format *format = const struct anv_format *format =
anv_format_for_vk_format(pCreateInfo->format); anv_format_for_vk_format(pCreateInfo->format);
@@ -388,12 +391,11 @@ VkResult VKAPI vkCreateColorAttachmentView(
if (view == NULL) if (view == NULL)
return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
view->image = (struct anv_image *) pCreateInfo->image; view->bo = image->bo;
view->offset = image->offset;
view->surface_state = create_surface_state(device, view->image, format); view->surface_state = create_surface_state(device, image, format);
view->extent = image->extent;
/* TODO: Miplevels */ view->format = pCreateInfo->format;
view->extent = view->image->extent;
*pView = (VkColorAttachmentView) view; *pView = (VkColorAttachmentView) view;

View File

@@ -468,10 +468,10 @@ struct blit_region {
static void static void
meta_emit_blit(struct anv_cmd_buffer *cmd_buffer, meta_emit_blit(struct anv_cmd_buffer *cmd_buffer,
struct anv_image_view *src, struct anv_surface_view *src,
VkOffset3D src_offset, VkOffset3D src_offset,
VkExtent3D src_extent, VkExtent3D src_extent,
struct anv_color_attachment_view *dest, struct anv_surface_view *dest,
VkOffset3D dest_offset, VkOffset3D dest_offset,
VkExtent3D dest_extent) VkExtent3D dest_extent)
{ {
@@ -587,7 +587,7 @@ meta_emit_blit(struct anv_cmd_buffer *cmd_buffer,
.extent = { }, .extent = { },
.sampleCount = 1, .sampleCount = 1,
.layers = 1, .layers = 1,
.pColorFormats = (VkFormat[]) { dest->image->format }, .pColorFormats = (VkFormat[]) { dest->format },
.pColorLayouts = (VkImageLayout[]) { VK_IMAGE_LAYOUT_GENERAL }, .pColorLayouts = (VkImageLayout[]) { VK_IMAGE_LAYOUT_GENERAL },
.pColorLoadOps = (VkAttachmentLoadOp[]) { VK_ATTACHMENT_LOAD_OP_LOAD }, .pColorLoadOps = (VkAttachmentLoadOp[]) { VK_ATTACHMENT_LOAD_OP_LOAD },
.pColorStoreOps = (VkAttachmentStoreOp[]) { VK_ATTACHMENT_STORE_OP_STORE }, .pColorStoreOps = (VkAttachmentStoreOp[]) { VK_ATTACHMENT_STORE_OP_STORE },
@@ -750,10 +750,10 @@ void VKAPI vkCmdCopyImageToBuffer(
vkCreateColorAttachmentView(vk_device, &dest_view_info, &dest_view); vkCreateColorAttachmentView(vk_device, &dest_view_info, &dest_view);
meta_emit_blit(cmd_buffer, meta_emit_blit(cmd_buffer,
(struct anv_image_view *)src_view, (struct anv_surface_view *)src_view,
pRegions[r].imageOffset, pRegions[r].imageOffset,
pRegions[r].imageExtent, pRegions[r].imageExtent,
(struct anv_color_attachment_view *)dest_view, (struct anv_surface_view *)dest_view,
(VkOffset3D) { 0, 0, 0 }, (VkOffset3D) { 0, 0, 0 },
pRegions[r].imageExtent); pRegions[r].imageExtent);
} }

View File

@@ -463,13 +463,8 @@ struct anv_descriptor_set_layout {
}; };
struct anv_descriptor { struct anv_descriptor {
union { struct anv_sampler *sampler;
struct { struct anv_surface_view *view;
struct anv_sampler *sampler;
struct anv_image_view *image_view;
};
struct anv_buffer_view *buffer_view;
};
}; };
struct anv_descriptor_set { struct anv_descriptor_set {
@@ -630,24 +625,12 @@ struct anv_image {
VkDeviceSize offset; VkDeviceSize offset;
}; };
struct anv_buffer_view { struct anv_surface_view {
struct anv_buffer * buffer;
struct anv_state surface_state; struct anv_state surface_state;
struct anv_bo * bo;
uint32_t offset; uint32_t offset;
};
struct anv_color_attachment_view {
struct anv_image * image;
struct anv_state surface_state;
VkExtent3D extent;
};
struct anv_image_view {
struct anv_image * image;
struct anv_state surface_state;
VkExtent3D extent; VkExtent3D extent;
VkFormat format;
}; };
struct anv_sampler { struct anv_sampler {
@@ -659,7 +642,7 @@ struct anv_depth_stencil_view {
struct anv_framebuffer { struct anv_framebuffer {
uint32_t color_attachment_count; uint32_t color_attachment_count;
struct anv_color_attachment_view * color_attachments[MAX_RTS]; struct anv_surface_view * color_attachments[MAX_RTS];
struct anv_depth_stencil_view * depth_stencil; struct anv_depth_stencil_view * depth_stencil;
uint32_t sample_count; uint32_t sample_count;

View File

@@ -562,6 +562,11 @@ int main(int argc, char *argv[])
}, },
&texture); &texture);
vkQueueBindObjectMemory(queue, VK_OBJECT_TYPE_IMAGE,
texture,
0, /* allocation index; for objects which need to bind to multiple mems */
mem, 2048 + 256 * 256 * 4);
VkImageView image_view; VkImageView image_view;
vkCreateImageView(device, vkCreateImageView(device,
&(VkImageViewCreateInfo) { &(VkImageViewCreateInfo) {
@@ -586,11 +591,6 @@ int main(int argc, char *argv[])
}, },
&image_view); &image_view);
vkQueueBindObjectMemory(queue, VK_OBJECT_TYPE_IMAGE,
texture,
0, /* allocation index; for objects which need to bind to multiple mems */
mem, 2048 + 256 * 256 * 4);
VkSampler sampler; VkSampler sampler;
vkCreateSampler(device, vkCreateSampler(device,
&(VkSamplerCreateInfo) { &(VkSamplerCreateInfo) {