radv/meta: create itoi layouts on-demand

Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30640>
This commit is contained in:
Samuel Pitoiset 2024-08-13 10:23:09 +02:00 committed by Marge Bot
parent bd00446bb0
commit 1dfb6e19d5

View File

@ -511,13 +511,57 @@ build_nir_itoi_compute_shader(struct radv_device *dev, bool src_3d, bool dst_3d,
return b.shader;
}
static VkResult
create_itoi_layout(struct radv_device *device)
{
VkResult result = VK_SUCCESS;
if (!device->meta_state.itoi.img_ds_layout) {
const VkDescriptorSetLayoutBinding bindings[] = {
{
.binding = 0,
.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
.descriptorCount = 1,
.stageFlags = VK_SHADER_STAGE_COMPUTE_BIT,
},
{
.binding = 1,
.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
.descriptorCount = 1,
.stageFlags = VK_SHADER_STAGE_COMPUTE_BIT,
},
};
result = radv_meta_create_descriptor_set_layout(device, 2, bindings, &device->meta_state.itoi.img_ds_layout);
if (result != VK_SUCCESS)
return result;
}
if (!device->meta_state.itoi.img_p_layout) {
const VkPushConstantRange pc_range = {
.stageFlags = VK_SHADER_STAGE_COMPUTE_BIT,
.size = 24,
};
result = radv_meta_create_pipeline_layout(device, &device->meta_state.itoi.img_ds_layout, 1, &pc_range,
&device->meta_state.itoi.img_p_layout);
}
return result;
}
static VkResult
create_itoi_pipeline(struct radv_device *device, bool src_3d, bool dst_3d, int samples, VkPipeline *pipeline)
{
struct radv_meta_state *state = &device->meta_state;
nir_shader *cs = build_nir_itoi_compute_shader(device, src_3d, dst_3d, samples);
VkResult result;
result = create_itoi_layout(device);
if (result != VK_SUCCESS)
return result;
nir_shader *cs = build_nir_itoi_compute_shader(device, src_3d, dst_3d, samples);
result = radv_meta_create_compute_pipeline(device, cs, state->itoi.img_p_layout, pipeline);
ralloc_free(cs);
return result;
@ -564,35 +608,6 @@ radv_device_init_meta_itoi_state(struct radv_device *device, bool on_demand)
{
VkResult result;
const VkDescriptorSetLayoutBinding bindings[] = {
{
.binding = 0,
.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
.descriptorCount = 1,
.stageFlags = VK_SHADER_STAGE_COMPUTE_BIT,
},
{
.binding = 1,
.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
.descriptorCount = 1,
.stageFlags = VK_SHADER_STAGE_COMPUTE_BIT,
},
};
result = radv_meta_create_descriptor_set_layout(device, 2, bindings, &device->meta_state.itoi.img_ds_layout);
if (result != VK_SUCCESS)
return result;
const VkPushConstantRange pc_range = {
.stageFlags = VK_SHADER_STAGE_COMPUTE_BIT,
.size = 24,
};
result = radv_meta_create_pipeline_layout(device, &device->meta_state.itoi.img_ds_layout, 1, &pc_range,
&device->meta_state.itoi.img_p_layout);
if (result != VK_SUCCESS)
return result;
if (on_demand)
return VK_SUCCESS;
@ -693,10 +708,55 @@ build_nir_itoi_r32g32b32_compute_shader(struct radv_device *dev)
}
/* Image to image - special path for R32G32B32 */
static VkResult
create_itoi_r32g32b32_layout(struct radv_device *device)
{
VkResult result = VK_SUCCESS;
if (!device->meta_state.itoi_r32g32b32.img_ds_layout) {
const VkDescriptorSetLayoutBinding bindings[] = {
{
.binding = 0,
.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER,
.descriptorCount = 1,
.stageFlags = VK_SHADER_STAGE_COMPUTE_BIT,
},
{
.binding = 1,
.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER,
.descriptorCount = 1,
.stageFlags = VK_SHADER_STAGE_COMPUTE_BIT,
},
};
result =
radv_meta_create_descriptor_set_layout(device, 2, bindings, &device->meta_state.itoi_r32g32b32.img_ds_layout);
if (result != VK_SUCCESS)
return result;
}
if (!device->meta_state.itoi_r32g32b32.img_p_layout) {
const VkPushConstantRange pc_range = {
.stageFlags = VK_SHADER_STAGE_COMPUTE_BIT,
.size = 24,
};
result = radv_meta_create_pipeline_layout(device, &device->meta_state.itoi_r32g32b32.img_ds_layout, 1, &pc_range,
&device->meta_state.itoi_r32g32b32.img_p_layout);
}
return result;
}
static VkResult
create_itoi_r32g32b32_pipeline(struct radv_device *device, VkPipeline *pipeline)
{
VkResult result;
result = create_itoi_r32g32b32_layout(device);
if (result != VK_SUCCESS)
return result;
nir_shader *cs = build_nir_itoi_r32g32b32_compute_shader(device);
result = radv_meta_create_compute_pipeline(device, cs, device->meta_state.itoi_r32g32b32.img_p_layout, pipeline);
@ -728,38 +788,6 @@ fail:
static VkResult
radv_device_init_meta_itoi_r32g32b32_state(struct radv_device *device, bool on_demand)
{
VkResult result;
const VkDescriptorSetLayoutBinding bindings[] = {
{
.binding = 0,
.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER,
.descriptorCount = 1,
.stageFlags = VK_SHADER_STAGE_COMPUTE_BIT,
},
{
.binding = 1,
.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER,
.descriptorCount = 1,
.stageFlags = VK_SHADER_STAGE_COMPUTE_BIT,
},
};
result =
radv_meta_create_descriptor_set_layout(device, 2, bindings, &device->meta_state.itoi_r32g32b32.img_ds_layout);
if (result != VK_SUCCESS)
return result;
const VkPushConstantRange pc_range = {
.stageFlags = VK_SHADER_STAGE_COMPUTE_BIT,
.size = 24,
};
result = radv_meta_create_pipeline_layout(device, &device->meta_state.itoi_r32g32b32.img_ds_layout, 1, &pc_range,
&device->meta_state.itoi_r32g32b32.img_p_layout);
if (result != VK_SUCCESS)
return result;
if (on_demand)
return VK_SUCCESS;