2 * Copyright © 2015 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
26 struct anv_render_pass anv_meta_dummy_renderpass = {0};
29 anv_meta_save(struct anv_meta_saved_state *state,
30 const struct anv_cmd_buffer *cmd_buffer,
31 uint32_t dynamic_mask)
33 state->old_pipeline = cmd_buffer->state.pipeline;
34 state->old_descriptor_set0 = cmd_buffer->state.descriptors[0];
35 memcpy(state->old_vertex_bindings, cmd_buffer->state.vertex_bindings,
36 sizeof(state->old_vertex_bindings));
38 state->dynamic_mask = dynamic_mask;
39 anv_dynamic_state_copy(&state->dynamic, &cmd_buffer->state.dynamic,
44 anv_meta_restore(const struct anv_meta_saved_state *state,
45 struct anv_cmd_buffer *cmd_buffer)
47 cmd_buffer->state.pipeline = state->old_pipeline;
48 cmd_buffer->state.descriptors[0] = state->old_descriptor_set0;
49 memcpy(cmd_buffer->state.vertex_bindings, state->old_vertex_bindings,
50 sizeof(state->old_vertex_bindings));
52 cmd_buffer->state.vb_dirty |= (1 << ANV_META_VERTEX_BINDING_COUNT) - 1;
53 cmd_buffer->state.dirty |= ANV_CMD_DIRTY_PIPELINE;
54 cmd_buffer->state.descriptors_dirty |= VK_SHADER_STAGE_FRAGMENT_BIT;
56 anv_dynamic_state_copy(&cmd_buffer->state.dynamic, &state->dynamic,
58 cmd_buffer->state.dirty |= state->dynamic_mask;
60 /* Since we've used the pipeline with the VS disabled, set
61 * need_query_wa. See CmdBeginQuery.
63 cmd_buffer->state.need_query_wa = true;
67 anv_meta_get_view_type(const struct anv_image *image)
69 switch (image->type) {
70 case VK_IMAGE_TYPE_1D: return VK_IMAGE_VIEW_TYPE_1D;
71 case VK_IMAGE_TYPE_2D: return VK_IMAGE_VIEW_TYPE_2D;
72 case VK_IMAGE_TYPE_3D: return VK_IMAGE_VIEW_TYPE_3D;
74 unreachable("bad VkImageViewType");
79 * When creating a destination VkImageView, this function provides the needed
80 * VkImageViewCreateInfo::subresourceRange::baseArrayLayer.
83 anv_meta_get_iview_layer(const struct anv_image *dest_image,
84 const VkImageSubresourceLayers *dest_subresource,
85 const VkOffset3D *dest_offset)
87 switch (dest_image->type) {
88 case VK_IMAGE_TYPE_1D:
89 case VK_IMAGE_TYPE_2D:
90 return dest_subresource->baseArrayLayer;
91 case VK_IMAGE_TYPE_3D:
92 /* HACK: Vulkan does not allow attaching a 3D image to a framebuffer,
93 * but meta does it anyway. When doing so, we translate the
94 * destination's z offset into an array offset.
96 return dest_offset->z;
98 assert(!"bad VkImageType");
104 meta_alloc(void* _device, size_t size, size_t alignment,
105 VkSystemAllocationScope allocationScope)
107 struct anv_device *device = _device;
108 return device->alloc.pfnAllocation(device->alloc.pUserData, size, alignment,
109 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE);
113 meta_realloc(void* _device, void *original, size_t size, size_t alignment,
114 VkSystemAllocationScope allocationScope)
116 struct anv_device *device = _device;
117 return device->alloc.pfnReallocation(device->alloc.pUserData, original,
119 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE);
123 meta_free(void* _device, void *data)
125 struct anv_device *device = _device;
126 return device->alloc.pfnFree(device->alloc.pUserData, data);
130 anv_device_init_meta(struct anv_device *device)
134 device->meta_state.alloc = (VkAllocationCallbacks) {
136 .pfnAllocation = meta_alloc,
137 .pfnReallocation = meta_realloc,
138 .pfnFree = meta_free,
141 result = anv_device_init_meta_clear_state(device);
142 if (result != VK_SUCCESS)
145 result = anv_device_init_meta_resolve_state(device);
146 if (result != VK_SUCCESS)
149 result = anv_device_init_meta_blit_state(device);
150 if (result != VK_SUCCESS)
153 result = anv_device_init_meta_blit2d_state(device);
154 if (result != VK_SUCCESS)
160 anv_device_finish_meta_blit_state(device);
162 anv_device_finish_meta_resolve_state(device);
164 anv_device_finish_meta_clear_state(device);
170 anv_device_finish_meta(struct anv_device *device)
172 anv_device_finish_meta_resolve_state(device);
173 anv_device_finish_meta_clear_state(device);
174 anv_device_finish_meta_blit_state(device);
175 anv_device_finish_meta_blit2d_state(device);