zink: add function for decomposing vertex format to single component
Reviewed-by: Dave Airlie <airlied@redhat.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12771>
This commit is contained in:
parent
9df5ebe5bf
commit
c106c45a99
|
@ -148,6 +148,53 @@ static const VkFormat formats[PIPE_FORMAT_COUNT] = {
|
||||||
[PIPE_FORMAT_BPTC_RGB_UFLOAT] = VK_FORMAT_BC6H_UFLOAT_BLOCK,
|
[PIPE_FORMAT_BPTC_RGB_UFLOAT] = VK_FORMAT_BC6H_UFLOAT_BLOCK,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum pipe_format
|
||||||
|
zink_decompose_vertex_format(enum pipe_format format)
|
||||||
|
{
|
||||||
|
const struct util_format_description *desc = util_format_description(format);
|
||||||
|
unsigned first_non_void = util_format_get_first_non_void_channel(format);
|
||||||
|
enum pipe_format new_format;
|
||||||
|
assert(first_non_void == 0);
|
||||||
|
if (!desc->is_array)
|
||||||
|
return PIPE_FORMAT_NONE;
|
||||||
|
if (desc->is_unorm) {
|
||||||
|
enum pipe_format unorm_formats[] = {
|
||||||
|
PIPE_FORMAT_R8_UNORM,
|
||||||
|
PIPE_FORMAT_R16_UNORM,
|
||||||
|
PIPE_FORMAT_R32_UNORM
|
||||||
|
};
|
||||||
|
return unorm_formats[desc->channel[first_non_void].size >> 4];
|
||||||
|
} else if (desc->is_snorm) {
|
||||||
|
enum pipe_format snorm_formats[] = {
|
||||||
|
PIPE_FORMAT_R8_SNORM,
|
||||||
|
PIPE_FORMAT_R16_SNORM,
|
||||||
|
PIPE_FORMAT_R32_SNORM
|
||||||
|
};
|
||||||
|
return snorm_formats[desc->channel[first_non_void].size >> 4];
|
||||||
|
} else {
|
||||||
|
enum pipe_format uint_formats[][3] = {
|
||||||
|
{PIPE_FORMAT_R8_USCALED, PIPE_FORMAT_R16_USCALED, PIPE_FORMAT_R32_USCALED},
|
||||||
|
{PIPE_FORMAT_R8_UINT, PIPE_FORMAT_R16_UINT, PIPE_FORMAT_R32_UINT},
|
||||||
|
};
|
||||||
|
enum pipe_format sint_formats[][3] = {
|
||||||
|
{PIPE_FORMAT_R8_SSCALED, PIPE_FORMAT_R16_SSCALED, PIPE_FORMAT_R32_SSCALED},
|
||||||
|
{PIPE_FORMAT_R8_SINT, PIPE_FORMAT_R16_SINT, PIPE_FORMAT_R32_SINT},
|
||||||
|
};
|
||||||
|
switch (desc->channel[first_non_void].type) {
|
||||||
|
case UTIL_FORMAT_TYPE_UNSIGNED:
|
||||||
|
return uint_formats[desc->channel[first_non_void].pure_integer][desc->channel[first_non_void].size >> 4];
|
||||||
|
case UTIL_FORMAT_TYPE_SIGNED:
|
||||||
|
return sint_formats[desc->channel[first_non_void].pure_integer][desc->channel[first_non_void].size >> 4];
|
||||||
|
case UTIL_FORMAT_TYPE_FLOAT:
|
||||||
|
return desc->channel[first_non_void].size == 16 ? PIPE_FORMAT_R16_FLOAT : PIPE_FORMAT_R32_FLOAT;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return PIPE_FORMAT_NONE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new_format;
|
||||||
|
}
|
||||||
|
|
||||||
VkFormat
|
VkFormat
|
||||||
zink_pipe_format_to_vk_format(enum pipe_format format)
|
zink_pipe_format_to_vk_format(enum pipe_format format)
|
||||||
{
|
{
|
||||||
|
|
|
@ -29,6 +29,9 @@
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <vulkan/vulkan.h>
|
#include <vulkan/vulkan.h>
|
||||||
|
|
||||||
|
enum pipe_format
|
||||||
|
zink_decompose_vertex_format(enum pipe_format format);
|
||||||
|
|
||||||
VkFormat
|
VkFormat
|
||||||
zink_pipe_format_to_vk_format(enum pipe_format format);
|
zink_pipe_format_to_vk_format(enum pipe_format format);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue