Mesa (main): radv: Add more BVH vertex formats.
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Fri Apr 1 21:17:59 UTC 2022
Module: Mesa
Branch: main
Commit: 51757d2249d1a6bbc0ac2a97420375056973ebb9
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=51757d2249d1a6bbc0ac2a97420375056973ebb9
Author: Bas Nieuwenhuizen <bas at basnieuwenhuizen.nl>
Date: Sat Mar 19 21:07:49 2022 +0100
radv: Add more BVH vertex formats.
AFAIU this is needed for DXR 1.1 with vkd3d-proton.
Reviewed-by: Samuel Pitoiset<samuel.pitoiset at gmail.com>
Reviewed-by: Konstantin Seurer <konstantin.seurer at gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15475>
---
src/amd/vulkan/radv_acceleration_structure.c | 81 ++++++++++++++++++++++++----
src/amd/vulkan/radv_formats.c | 6 +++
2 files changed, 78 insertions(+), 9 deletions(-)
diff --git a/src/amd/vulkan/radv_acceleration_structure.c b/src/amd/vulkan/radv_acceleration_structure.c
index c7e89c88f78..c91bdfecdf8 100644
--- a/src/amd/vulkan/radv_acceleration_structure.c
+++ b/src/amd/vulkan/radv_acceleration_structure.c
@@ -263,6 +263,12 @@ build_triangles(struct radv_bvh_build_ctx *ctx, const VkAccelerationStructureGeo
coords[2] = 0.0f;
coords[3] = 1.0f;
break;
+ case VK_FORMAT_R16G16_UNORM:
+ coords[0] = _mesa_unorm_to_float(*(const uint16_t *)(v_data + 0), 16);
+ coords[1] = _mesa_unorm_to_float(*(const uint16_t *)(v_data + 2), 16);
+ coords[2] = 0.0f;
+ coords[3] = 1.0f;
+ break;
case VK_FORMAT_R16G16B16A16_SNORM:
coords[0] = _mesa_snorm_to_float(*(const int16_t *)(v_data + 0), 16);
coords[1] = _mesa_snorm_to_float(*(const int16_t *)(v_data + 2), 16);
@@ -275,6 +281,37 @@ build_triangles(struct radv_bvh_build_ctx *ctx, const VkAccelerationStructureGeo
coords[2] = _mesa_unorm_to_float(*(const uint16_t *)(v_data + 4), 16);
coords[3] = _mesa_unorm_to_float(*(const uint16_t *)(v_data + 6), 16);
break;
+ case VK_FORMAT_R8G8_SNORM:
+ coords[0] = _mesa_snorm_to_float(*(const int8_t *)(v_data + 0), 8);
+ coords[1] = _mesa_snorm_to_float(*(const int8_t *)(v_data + 1), 8);
+ coords[2] = 0.0f;
+ coords[3] = 1.0f;
+ break;
+ case VK_FORMAT_R8G8_UNORM:
+ coords[0] = _mesa_unorm_to_float(*(const uint8_t *)(v_data + 0), 8);
+ coords[1] = _mesa_unorm_to_float(*(const uint8_t *)(v_data + 1), 8);
+ coords[2] = 0.0f;
+ coords[3] = 1.0f;
+ break;
+ case VK_FORMAT_R8G8B8A8_SNORM:
+ coords[0] = _mesa_snorm_to_float(*(const int8_t *)(v_data + 0), 8);
+ coords[1] = _mesa_snorm_to_float(*(const int8_t *)(v_data + 1), 8);
+ coords[2] = _mesa_snorm_to_float(*(const int8_t *)(v_data + 2), 8);
+ coords[3] = _mesa_snorm_to_float(*(const int8_t *)(v_data + 3), 8);
+ break;
+ case VK_FORMAT_R8G8B8A8_UNORM:
+ coords[0] = _mesa_unorm_to_float(*(const uint8_t *)(v_data + 0), 8);
+ coords[1] = _mesa_unorm_to_float(*(const uint8_t *)(v_data + 1), 8);
+ coords[2] = _mesa_unorm_to_float(*(const uint8_t *)(v_data + 2), 8);
+ coords[3] = _mesa_unorm_to_float(*(const uint8_t *)(v_data + 3), 8);
+ break;
+ case VK_FORMAT_A2B10G10R10_UNORM_PACK32: {
+ uint32_t val = *(const uint32_t *)v_data;
+ coords[0] = _mesa_unorm_to_float((val >> 0) & 0x3FF, 10);
+ coords[1] = _mesa_unorm_to_float((val >> 10) & 0x3FF, 10);
+ coords[2] = _mesa_unorm_to_float((val >> 20) & 0x3FF, 10);
+ coords[3] = _mesa_unorm_to_float((val >> 30) & 0x3, 2);
+ } break;
default:
unreachable("Unhandled vertex format in BVH build");
}
@@ -771,9 +808,21 @@ get_vertices(nir_builder *b, nir_ssa_def *addresses, nir_ssa_def *format, nir_ss
nir_variable_create(b->shader, nir_var_shader_temp, vec3_type, "vertex2")};
VkFormat formats[] = {
- VK_FORMAT_R32G32B32_SFLOAT, VK_FORMAT_R32G32B32A32_SFLOAT, VK_FORMAT_R16G16B16_SFLOAT,
- VK_FORMAT_R16G16B16A16_SFLOAT, VK_FORMAT_R16G16_SFLOAT, VK_FORMAT_R32G32_SFLOAT,
- VK_FORMAT_R16G16_SNORM, VK_FORMAT_R16G16B16A16_SNORM, VK_FORMAT_R16G16B16A16_UNORM,
+ VK_FORMAT_R32G32B32_SFLOAT,
+ VK_FORMAT_R32G32B32A32_SFLOAT,
+ VK_FORMAT_R16G16B16_SFLOAT,
+ VK_FORMAT_R16G16B16A16_SFLOAT,
+ VK_FORMAT_R16G16_SFLOAT,
+ VK_FORMAT_R32G32_SFLOAT,
+ VK_FORMAT_R16G16_SNORM,
+ VK_FORMAT_R16G16_UNORM,
+ VK_FORMAT_R16G16B16A16_SNORM,
+ VK_FORMAT_R16G16B16A16_UNORM,
+ VK_FORMAT_R8G8_SNORM,
+ VK_FORMAT_R8G8_UNORM,
+ VK_FORMAT_R8G8B8A8_SNORM,
+ VK_FORMAT_R8G8B8A8_UNORM,
+ VK_FORMAT_A2B10G10R10_UNORM_PACK32,
};
for (unsigned f = 0; f < ARRAY_SIZE(formats); ++f) {
@@ -792,20 +841,34 @@ get_vertices(nir_builder *b, nir_ssa_def *addresses, nir_ssa_def *format, nir_ss
case VK_FORMAT_R16G16B16_SFLOAT:
case VK_FORMAT_R16G16B16A16_SFLOAT:
case VK_FORMAT_R16G16_SNORM:
+ case VK_FORMAT_R16G16_UNORM:
case VK_FORMAT_R16G16B16A16_SNORM:
- case VK_FORMAT_R16G16B16A16_UNORM: {
+ case VK_FORMAT_R16G16B16A16_UNORM:
+ case VK_FORMAT_R8G8_SNORM:
+ case VK_FORMAT_R8G8_UNORM:
+ case VK_FORMAT_R8G8B8A8_SNORM:
+ case VK_FORMAT_R8G8B8A8_UNORM:
+ case VK_FORMAT_A2B10G10R10_UNORM_PACK32: {
unsigned components = MIN2(3, vk_format_get_nr_components(formats[f]));
unsigned comp_bits =
vk_format_get_blocksizebits(formats[f]) / vk_format_get_nr_components(formats[f]);
unsigned comp_bytes = comp_bits / 8;
nir_ssa_def *values[3];
nir_ssa_def *addr = nir_channel(b, addresses, i);
- for (unsigned j = 0; j < components; ++j)
- values[j] = nir_build_load_global(
- b, 1, comp_bits, nir_iadd(b, addr, nir_imm_int64(b, j * comp_bytes)));
- for (unsigned j = components; j < 3; ++j)
- values[j] = nir_imm_intN_t(b, 0, comp_bits);
+ if (formats[f] == VK_FORMAT_A2B10G10R10_UNORM_PACK32) {
+ comp_bits = 10;
+ nir_ssa_def *val = nir_build_load_global(b, 1, 32, addr);
+ for (unsigned j = 0; j < 3; ++j)
+ values[j] = nir_ubfe(b, val, nir_imm_int(b, j * 10), nir_imm_int(b, 10));
+ } else {
+ for (unsigned j = 0; j < components; ++j)
+ values[j] = nir_build_load_global(
+ b, 1, comp_bits, nir_iadd(b, addr, nir_imm_int64(b, j * comp_bytes)));
+
+ for (unsigned j = components; j < 3; ++j)
+ values[j] = nir_imm_intN_t(b, 0, comp_bits);
+ }
nir_ssa_def *vec;
if (util_format_is_snorm(vk_format_to_pipe_format(formats[f]))) {
diff --git a/src/amd/vulkan/radv_formats.c b/src/amd/vulkan/radv_formats.c
index 68418f6f16a..154beb8ea4c 100644
--- a/src/amd/vulkan/radv_formats.c
+++ b/src/amd/vulkan/radv_formats.c
@@ -847,8 +847,14 @@ radv_physical_device_get_format_properties(struct radv_physical_device *physical
case VK_FORMAT_R16G16B16_SFLOAT:
case VK_FORMAT_R16G16B16A16_SFLOAT:
case VK_FORMAT_R16G16_SNORM:
+ case VK_FORMAT_R16G16_UNORM:
case VK_FORMAT_R16G16B16A16_SNORM:
case VK_FORMAT_R16G16B16A16_UNORM:
+ case VK_FORMAT_R8G8_SNORM:
+ case VK_FORMAT_R8G8_UNORM:
+ case VK_FORMAT_R8G8B8A8_SNORM:
+ case VK_FORMAT_R8G8B8A8_UNORM:
+ case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
buffer |= VK_FORMAT_FEATURE_2_ACCELERATION_STRUCTURE_VERTEX_BUFFER_BIT_KHR;
break;
default:
More information about the mesa-commit
mailing list