ANV_FROM_HANDLE(anv_buffer, buffer, pCreateInfo->buffer);
struct anv_buffer_view *view;
- /* TODO: Storage texel buffers */
-
view = anv_alloc2(&device->alloc, pAllocator, sizeof(*view), 8,
VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if (!view)
return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
+ const struct anv_format *format =
+ anv_format_for_vk_format(pCreateInfo->format);
+
+ view->format = format->surface_format;
view->bo = buffer->bo;
view->offset = buffer->offset + pCreateInfo->offset;
+ view->range = pCreateInfo->range;
- view->surface_state =
- anv_state_pool_alloc(&device->surface_state_pool, 64, 64);
+ if (buffer->usage & VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT) {
+ view->surface_state =
+ anv_state_pool_alloc(&device->surface_state_pool, 64, 64);
- const struct anv_format *format =
- anv_format_for_vk_format(pCreateInfo->format);
+ anv_fill_buffer_surface_state(device, view->surface_state.map,
+ view->format,
+ view->offset, pCreateInfo->range,
+ format->isl_layout->bpb / 8);
+ } else {
+ view->surface_state = (struct anv_state){ 0 };
+ }
+
+ if (buffer->usage & VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT) {
+ view->storage_surface_state =
+ anv_state_pool_alloc(&device->surface_state_pool, 64, 64);
- anv_fill_buffer_surface_state(device, view->surface_state.map,
- format->surface_format,
- view->offset, pCreateInfo->range,
- format->isl_layout->bpb / 8);
+ enum isl_format storage_format =
+ isl_lower_storage_image_format(&device->isl_dev, view->format);
+
+ anv_fill_buffer_surface_state(device, view->storage_surface_state.map,
+ storage_format,
+ view->offset, pCreateInfo->range,
+ format->isl_layout->bpb / 8);
+ } else {
+ view->storage_surface_state = (struct anv_state){ 0 };
+ }
*pView = anv_buffer_view_to_handle(view);
ANV_FROM_HANDLE(anv_device, device, _device);
ANV_FROM_HANDLE(anv_buffer_view, view, bufferView);
- anv_state_pool_free(&device->surface_state_pool, view->surface_state);
+ if (view->surface_state.alloc_size > 0)
+ anv_state_pool_free(&device->surface_state_pool,
+ view->surface_state);
+
+ if (view->storage_surface_state.alloc_size > 0)
+ anv_state_pool_free(&device->surface_state_pool,
+ view->storage_surface_state);
+
anv_free2(&device->alloc, pAllocator, view);
}
memset(param, 0, sizeof *param);
anv_finishme("Actually fill out brw_image_param");
}
+
+void
+anv_buffer_view_fill_image_param(struct anv_device *device,
+ struct anv_buffer_view *view,
+ struct brw_image_param *param)
+{
+ /* Set the swizzling shifts to all-ones to effectively disable swizzling --
+ * See emit_address_calculation() in brw_fs_surface_builder.cpp for a more
+ * detailed explanation of these parameters.
+ */
+ param->swizzling[0] = 0xff;
+ param->swizzling[1] = 0xff;
+
+ param->stride[0] = isl_format_layouts[view->format].bpb / 8;
+ param->size[0] = view->range / param->stride[0];
+}
struct anv_device * device;
VkDeviceSize size;
+ VkBufferUsageFlags usage;
+
/* Set when bound */
struct anv_bo * bo;
VkDeviceSize offset;
struct anv_cmd_buffer *cmd_buffer);
struct anv_buffer_view {
+ enum isl_format format; /**< VkBufferViewCreateInfo::format */
struct anv_bo *bo;
uint32_t offset; /**< Offset into bo. */
+ uint64_t range; /**< VkBufferViewCreateInfo::range */
struct anv_state surface_state;
+ struct anv_state storage_surface_state;
};
void anv_fill_buffer_surface_state(struct anv_device *device, void *state,
void anv_image_view_fill_image_param(struct anv_device *device,
struct anv_image_view *view,
struct brw_image_param *param);
+void anv_buffer_view_fill_image_param(struct anv_device *device,
+ struct anv_buffer_view *view,
+ struct brw_image_param *param);
struct anv_sampler {
uint32_t state[4];