From 16f4b93cac9ee2e49251b85965e838e803847743 Mon Sep 17 00:00:00 2001 From: Konstantin Seurer Date: Fri, 6 Sep 2024 10:56:36 +0200 Subject: [PATCH] lavapipe: Implement VK_KHR_compute_shader_derivatives Reviewed-by: Dave Airlie Part-of: --- src/gallium/drivers/llvmpipe/lp_state_cs.c | 22 ++++++++++++++++++--- src/gallium/frontends/lavapipe/lvp_device.c | 8 ++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/gallium/drivers/llvmpipe/lp_state_cs.c b/src/gallium/drivers/llvmpipe/lp_state_cs.c index 15ed604216d..5b21443be9f 100644 --- a/src/gallium/drivers/llvmpipe/lp_state_cs.c +++ b/src/gallium/drivers/llvmpipe/lp_state_cs.c @@ -741,9 +741,25 @@ generate_compute(struct llvmpipe_context *lp, LLVMValueRef block_x_size_vec = lp_build_broadcast_scalar(&bld, block_x_size_arg); LLVMValueRef block_y_size_vec = lp_build_broadcast_scalar(&bld, block_y_size_arg); - system_values.thread_id[0] = LLVMBuildURem(gallivm->builder, invocation_index, block_x_size_vec, ""); - system_values.thread_id[1] = LLVMBuildUDiv(gallivm->builder, invocation_index, block_x_size_vec, ""); - system_values.thread_id[1] = LLVMBuildURem(gallivm->builder, system_values.thread_id[1], block_y_size_vec, ""); + if (nir->info.derivative_group == DERIVATIVE_GROUP_QUADS) { + /* x = (invocation_index / 4 * 2 + invocation_index % 2) % block_width */ + LLVMValueRef quad_x = LLVMBuildAnd(builder, invocation_index, lp_build_const_int_vec(gallivm, bld.type, ~3u), ""); + quad_x = LLVMBuildUDiv(builder, quad_x, lp_build_const_int_vec(gallivm, bld.type, 2), ""); + LLVMValueRef quad_sub_x = LLVMBuildURem(builder, invocation_index, lp_build_const_int_vec(gallivm, bld.type, 2), ""); + system_values.thread_id[0] = LLVMBuildAdd(builder, quad_x, quad_sub_x, ""); + system_values.thread_id[0] = LLVMBuildURem(builder, system_values.thread_id[0], block_x_size_vec, ""); + /* y = (invocation_index / block_width / 2 * 2 + (invocation_index / 2) % 2) % block_height */ + LLVMValueRef quad_y = LLVMBuildUDiv(builder, invocation_index, block_x_size_vec, ""); + quad_y = LLVMBuildAnd(builder, quad_y, lp_build_const_int_vec(gallivm, bld.type, ~1u), ""); + LLVMValueRef quad_sub_y = LLVMBuildUDiv(builder, invocation_index, lp_build_const_int_vec(gallivm, bld.type, 2), ""); + quad_sub_y = LLVMBuildURem(builder, quad_sub_y, lp_build_const_int_vec(gallivm, bld.type, 2), ""); + system_values.thread_id[1] = LLVMBuildAdd(builder, quad_y, quad_sub_y, ""); + system_values.thread_id[1] = LLVMBuildURem(builder, system_values.thread_id[1], block_y_size_vec, ""); + } else { + system_values.thread_id[0] = LLVMBuildURem(gallivm->builder, invocation_index, block_x_size_vec, ""); + system_values.thread_id[1] = LLVMBuildUDiv(gallivm->builder, invocation_index, block_x_size_vec, ""); + system_values.thread_id[1] = LLVMBuildURem(gallivm->builder, system_values.thread_id[1], block_y_size_vec, ""); + } system_values.thread_id[2] = LLVMBuildUDiv(gallivm->builder, invocation_index, block_x_size_vec, ""); system_values.thread_id[2] = LLVMBuildUDiv(gallivm->builder, system_values.thread_id[2], block_y_size_vec, ""); diff --git a/src/gallium/frontends/lavapipe/lvp_device.c b/src/gallium/frontends/lavapipe/lvp_device.c index 141561dd658..56f76a555c7 100644 --- a/src/gallium/frontends/lavapipe/lvp_device.c +++ b/src/gallium/frontends/lavapipe/lvp_device.c @@ -111,6 +111,7 @@ static const struct vk_device_extension_table lvp_device_extensions_supported = .KHR_bind_memory2 = true, .KHR_buffer_device_address = true, .KHR_create_renderpass2 = true, + .KHR_compute_shader_derivatives = true, .KHR_copy_commands2 = true, .KHR_dedicated_allocation = true, .KHR_deferred_host_operations = true, @@ -750,6 +751,10 @@ lvp_get_features(const struct lvp_physical_device *pdevice, /* KHR_shader_float_controls2 */ .shaderFloatControls2 = true, + + /* VK_KHR_compute_shader_derivatives */ + .computeDerivativeGroupQuads = true, + .computeDerivativeGroupLinear = true, }; } @@ -1217,6 +1222,9 @@ lvp_get_properties(const struct lvp_physical_device *device, struct vk_propertie .maxRayDispatchInvocationCount = 1024 * 1024 * 64, .shaderGroupHandleAlignment = 16, .maxRayHitAttributeSize = LVP_RAY_HIT_ATTRIBS_SIZE, + + /* VK_KHR_compute_shader_derivatives */ + .meshAndTaskShaderDerivatives = true, }; /* Vulkan 1.0 */