diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c index a611512b3c5..7992c5e007c 100644 --- a/src/intel/vulkan/anv_device.c +++ b/src/intel/vulkan/anv_device.c @@ -2893,6 +2893,11 @@ anv_device_init_border_colors(struct anv_device *device) device->border_colors = anv_state_pool_emit_data(&device->dynamic_state_pool, sizeof(border_colors), 64, border_colors); + if (device->vk.enabled_extensions.EXT_descriptor_buffer) { + device->border_colors_db = + anv_state_pool_emit_data(&device->dynamic_state_db_pool, + sizeof(border_colors), 64, border_colors); + } } static VkResult @@ -3412,6 +3417,12 @@ VkResult anv_CreateDevice( &device->dynamic_state_pool, MAX_CUSTOM_BORDER_COLORS, sizeof(struct gfx8_border_color), 64); + if (device->vk.enabled_extensions.EXT_descriptor_buffer) { + anv_state_reserved_pool_init(&device->custom_border_colors_db, + &device->dynamic_state_db_pool, + MAX_CUSTOM_BORDER_COLORS, + sizeof(struct gfx8_border_color), 64); + } result = anv_state_pool_init(&device->instruction_state_pool, device, &(struct anv_state_pool_params) { @@ -3825,8 +3836,10 @@ VkResult anv_CreateDevice( anv_state_pool_finish(&device->instruction_state_pool); fail_dynamic_state_db_pool: anv_state_reserved_pool_finish(&device->custom_border_colors); - if (device->vk.enabled_extensions.EXT_descriptor_buffer) + if (device->vk.enabled_extensions.EXT_descriptor_buffer) { + anv_state_reserved_pool_finish(&device->custom_border_colors_db); anv_state_pool_finish(&device->dynamic_state_db_pool); + } fail_dynamic_state_pool: anv_state_pool_finish(&device->dynamic_state_pool); fail_general_state_pool: @@ -3915,11 +3928,15 @@ void anv_DestroyDevice( */ anv_state_reserved_pool_finish(&device->custom_border_colors); anv_state_pool_free(&device->dynamic_state_pool, device->border_colors); + anv_state_pool_free(&device->dynamic_state_pool, device->border_colors_db); anv_state_pool_free(&device->dynamic_state_pool, device->slice_hash); anv_state_pool_free(&device->dynamic_state_pool, device->cps_states); anv_state_pool_free(&device->dynamic_state_pool, device->breakpoint); - if (device->vk.enabled_extensions.EXT_descriptor_buffer) + if (device->vk.enabled_extensions.EXT_descriptor_buffer) { anv_state_pool_free(&device->dynamic_state_db_pool, device->slice_hash_db); + anv_state_pool_free(&device->dynamic_state_db_pool, device->border_colors_db); + anv_state_reserved_pool_finish(&device->custom_border_colors_db); + } #endif for (unsigned i = 0; i < ARRAY_SIZE(device->rt_scratch_bos); i++) { @@ -5055,10 +5072,19 @@ void anv_DestroySampler( sampler->bindless_state); } + if (sampler->bindless_state_db.map) { + anv_state_pool_free(&device->dynamic_state_db_pool, + sampler->bindless_state_db); + } + if (sampler->custom_border_color.map) { anv_state_reserved_pool_free(&device->custom_border_colors, sampler->custom_border_color); } + if (sampler->custom_border_color_db.map) { + anv_state_reserved_pool_free(&device->custom_border_colors_db, + sampler->custom_border_color_db); + } vk_sampler_destroy(&device->vk, pAllocator, &sampler->vk); } diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h index 9663475f496..6b6cffcc305 100644 --- a/src/intel/vulkan/anv_private.h +++ b/src/intel/vulkan/anv_private.h @@ -1740,6 +1740,7 @@ struct anv_device { struct anv_state_pool push_descriptor_buffer_pool; struct anv_state_reserved_pool custom_border_colors; + struct anv_state_reserved_pool custom_border_colors_db; /** BO used for various workarounds * @@ -1774,6 +1775,7 @@ struct anv_device { struct blorp_context blorp; struct anv_state border_colors; + struct anv_state border_colors_db; struct anv_state slice_hash; struct anv_state slice_hash_db; @@ -5620,14 +5622,17 @@ struct anv_sampler { struct vk_sampler vk; uint32_t state[3][4]; + uint32_t db_state[3][4]; uint32_t n_planes; /* Blob of sampler state data which is guaranteed to be 32-byte aligned * and with a 32-byte stride for use as bindless samplers. */ struct anv_state bindless_state; + struct anv_state bindless_state_db; struct anv_state custom_border_color; + struct anv_state custom_border_color_db; }; #define ANV_PIPELINE_STATISTICS_MASK 0x000007ff diff --git a/src/intel/vulkan/genX_init_state.c b/src/intel/vulkan/genX_init_state.c index 8b0effb377e..47f80e1e74d 100644 --- a/src/intel/vulkan/genX_init_state.c +++ b/src/intel/vulkan/genX_init_state.c @@ -1111,16 +1111,23 @@ VkResult genX(CreateSampler)( sampler->n_planes = ycbcr_info ? ycbcr_info->n_planes : 1; uint32_t border_color_stride = 64; - uint32_t border_color_offset; + uint32_t border_color_offset, border_color_db_offset = 0; + void *border_color_ptr; if (sampler->vk.border_color <= VK_BORDER_COLOR_INT_OPAQUE_WHITE) { border_color_offset = device->border_colors.offset + pCreateInfo->borderColor * border_color_stride; + border_color_db_offset = device->border_colors_db.offset + + pCreateInfo->borderColor * + border_color_stride; + border_color_ptr = device->border_colors.map + + pCreateInfo->borderColor * border_color_stride; } else { assert(vk_border_color_is_custom(sampler->vk.border_color)); sampler->custom_border_color = anv_state_reserved_pool_alloc(&device->custom_border_colors); border_color_offset = sampler->custom_border_color.offset; + border_color_ptr = sampler->custom_border_color.map; union isl_color_value color = { .u32 = { sampler->vk.border_color_value.uint32[0], @@ -1141,17 +1148,15 @@ VkResult genX(CreateSampler)( color = isl_color_value_swizzle(color, fmt_plane->swizzle, true); } - memcpy(sampler->custom_border_color.map, color.u32, sizeof(color)); - } + memcpy(border_color_ptr, color.u32, sizeof(color)); - /* If we have bindless, allocate enough samplers. We allocate 32 bytes - * for each sampler instead of 16 bytes because we want all bindless - * samplers to be 32-byte aligned so we don't have to use indirect - * sampler messages on them. - */ - sampler->bindless_state = - anv_state_pool_alloc(&device->dynamic_state_pool, - sampler->n_planes * 32, 32); + if (device->vk.enabled_extensions.EXT_descriptor_buffer) { + sampler->custom_border_color_db = + anv_state_reserved_pool_alloc(&device->custom_border_colors_db); + border_color_db_offset = sampler->custom_border_color_db.offset; + memcpy(sampler->custom_border_color_db.map, color.u32, sizeof(color)); + } + } const bool seamless_cube = !(pCreateInfo->flags & VK_SAMPLER_CREATE_NON_SEAMLESS_CUBE_MAP_BIT_EXT); @@ -1235,11 +1240,38 @@ VkResult genX(CreateSampler)( sampler->vk.reduction_mode != VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE, }; + /* Put border color after the hashing, we don't want the allocation + * order of border colors to influence the hash. We just need th + * parameters to be hashed. + */ + sampler_state.BorderColorPointer = border_color_offset; GENX(SAMPLER_STATE_pack)(NULL, sampler->state[p], &sampler_state); - if (sampler->bindless_state.map) { - memcpy(sampler->bindless_state.map + p * 32, - sampler->state[p], GENX(SAMPLER_STATE_length) * 4); + if (device->vk.enabled_extensions.EXT_descriptor_buffer) { + sampler_state.BorderColorPointer = border_color_db_offset; + GENX(SAMPLER_STATE_pack)(NULL, sampler->db_state[p], &sampler_state); + } + } + + /* If we have bindless, allocate enough samplers. We allocate 32 bytes + * for each sampler instead of 16 bytes because we want all bindless + * samplers to be 32-byte aligned so we don't have to use indirect + * sampler messages on them. + */ + sampler->bindless_state = + anv_state_pool_alloc(&device->dynamic_state_pool, + sampler->n_planes * 32, 32); + if (sampler->bindless_state.map) { + memcpy(sampler->bindless_state.map, sampler->state, + sampler->n_planes * GENX(SAMPLER_STATE_length) * 4); + } + if (device->vk.enabled_extensions.EXT_descriptor_buffer) { + sampler->bindless_state_db = + anv_state_pool_alloc(&device->dynamic_state_db_pool, + sampler->n_planes * 32, 32); + if (sampler->bindless_state_db.map) { + memcpy(sampler->bindless_state_db.map, sampler->db_state, + sampler->n_planes * GENX(SAMPLER_STATE_length) * 4); } }