Commit 17443727 authored by Joshua Ashton's avatar Joshua Ashton 🐸 Committed by Dave Airlie
Browse files

lavapipe: Use common Vulkan format helpers

Drops the vk_format_to_pipe (and it's outdated table) for vk_format_to_pipe_format, aswell as the duplicated vk_format_aspects function.

The old format table was missing USCALED and other values, causing incorrect rendering in many games.

Fixes rendering in Portal 1, Hat in Time, Half-Life 2 and pretty much every other D3D9 title with DXVK.

Fixes: b38879f8

 ("vallium: initial import of the vulkan frontend")
Signed-off-by: Joshua Ashton's avatarJoshua Ashton <joshua@froggi.es>
Reviewed-By: Mike Blumenkrantz's avatarMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Reviewed-by: default avatarDave Airlie <airlied@redhat.com>
Part-of: <mesa/mesa!11863>
parent 376fb4f5
......@@ -690,7 +690,7 @@ static void handle_graphics_pipeline(struct lvp_cmd_buffer_entry *cmd,
unsigned location = vi->pVertexAttributeDescriptions[i].location;
state->velem.velems[location].src_offset = vi->pVertexAttributeDescriptions[i].offset;
state->velem.velems[location].vertex_buffer_index = vi->pVertexAttributeDescriptions[i].binding;
state->velem.velems[location].src_format = vk_format_to_pipe(vi->pVertexAttributeDescriptions[i].format);
state->velem.velems[location].src_format = lvp_vk_format_to_pipe_format(vi->pVertexAttributeDescriptions[i].format);
switch (vi->pVertexBindingDescriptions[vi->pVertexAttributeDescriptions[i].binding].inputRate) {
case VK_VERTEX_INPUT_RATE_VERTEX:
......@@ -894,11 +894,11 @@ static void fill_sampler_view_stage(struct rendering_state *state,
enum pipe_format pformat;
if (iv->subresourceRange.aspectMask == VK_IMAGE_ASPECT_DEPTH_BIT)
pformat = vk_format_to_pipe(iv->format);
pformat = lvp_vk_format_to_pipe_format(iv->format);
else if (iv->subresourceRange.aspectMask == VK_IMAGE_ASPECT_STENCIL_BIT)
pformat = util_format_stencil_only(vk_format_to_pipe(iv->format));
pformat = util_format_stencil_only(lvp_vk_format_to_pipe_format(iv->format));
else
pformat = vk_format_to_pipe(iv->format);
pformat = lvp_vk_format_to_pipe_format(iv->format);
u_sampler_view_default_template(&templ,
iv->image->bo,
pformat);
......@@ -998,11 +998,11 @@ static void fill_image_view_stage(struct rendering_state *state,
idx += dyn_info->stage[stage].image_count;
state->iv[p_stage][idx].resource = iv->image->bo;
if (iv->subresourceRange.aspectMask == VK_IMAGE_ASPECT_DEPTH_BIT)
state->iv[p_stage][idx].format = vk_format_to_pipe(iv->format);
state->iv[p_stage][idx].format = lvp_vk_format_to_pipe_format(iv->format);
else if (iv->subresourceRange.aspectMask == VK_IMAGE_ASPECT_STENCIL_BIT)
state->iv[p_stage][idx].format = util_format_stencil_only(vk_format_to_pipe(iv->format));
state->iv[p_stage][idx].format = util_format_stencil_only(lvp_vk_format_to_pipe_format(iv->format));
else
state->iv[p_stage][idx].format = vk_format_to_pipe(iv->format);
state->iv[p_stage][idx].format = lvp_vk_format_to_pipe_format(iv->format);
if (iv->view_type == VK_IMAGE_VIEW_TYPE_3D) {
state->iv[p_stage][idx].u.tex.first_layer = 0;
......@@ -1255,7 +1255,7 @@ static struct pipe_surface *create_img_surface(struct rendering_state *state,
int base_layer, int layer_count)
{
return create_img_surface_bo(state, &imgv->subresourceRange, imgv->image->bo,
vk_format_to_pipe(format), width, height, base_layer, layer_count, 0);
lvp_vk_format_to_pipe_format(format), width, height, base_layer, layer_count, 0);
}
static void add_img_view_surface(struct rendering_state *state,
......@@ -2919,7 +2919,7 @@ static void handle_set_vertex_input(struct lvp_cmd_buffer_entry *cmd,
unsigned location = attrs[i].location;
state->velem.velems[location].src_offset = attrs[i].offset;
state->velem.velems[location].vertex_buffer_index = attrs[i].binding;
state->velem.velems[location].src_format = vk_format_to_pipe(attrs[i].format);
state->velem.velems[location].src_format = lvp_vk_format_to_pipe_format(attrs[i].format);
state->vb[attrs[i].binding].stride = binding->stride;
switch (binding->inputRate) {
......
......@@ -26,150 +26,6 @@
#include "util/u_math.h"
#include "vk_util.h"
#define COMMON_NAME(x) [VK_FORMAT_##x] = PIPE_FORMAT_##x
#define FLOAT_NAME(x) [VK_FORMAT_##x##_SFLOAT] = PIPE_FORMAT_##x##_FLOAT
static enum pipe_format format_to_vk_table[VK_FORMAT_ASTC_12x12_SRGB_BLOCK + 1] = {
COMMON_NAME(R8_UNORM),
COMMON_NAME(R8G8_UNORM),
COMMON_NAME(R8G8B8_UNORM),
COMMON_NAME(R8G8B8A8_UNORM),
COMMON_NAME(R8_SNORM),
COMMON_NAME(R8G8_SNORM),
COMMON_NAME(R8G8B8_SNORM),
COMMON_NAME(R8G8B8A8_SNORM),
// COMMON_NAME(R8_SRGB),
COMMON_NAME(R8G8B8_SRGB),
COMMON_NAME(R8G8B8A8_SRGB),
COMMON_NAME(B8G8R8A8_UNORM),
COMMON_NAME(B8G8R8A8_SRGB),
COMMON_NAME(R8_UINT),
COMMON_NAME(R8G8_UINT),
COMMON_NAME(R8G8B8_UINT),
COMMON_NAME(R8G8B8A8_UINT),
COMMON_NAME(R16_UINT),
COMMON_NAME(R16G16_UINT),
COMMON_NAME(R16G16B16_UINT),
COMMON_NAME(R16G16B16A16_UINT),
COMMON_NAME(R32_UINT),
COMMON_NAME(R32G32_UINT),
COMMON_NAME(R32G32B32_UINT),
COMMON_NAME(R32G32B32A32_UINT),
COMMON_NAME(R8_SINT),
COMMON_NAME(R8G8_SINT),
COMMON_NAME(R8G8B8_SINT),
COMMON_NAME(R8G8B8A8_SINT),
COMMON_NAME(R16_SINT),
COMMON_NAME(R16G16_SINT),
COMMON_NAME(R16G16B16_SINT),
COMMON_NAME(R16G16B16A16_SINT),
COMMON_NAME(R32_SINT),
COMMON_NAME(R32G32_SINT),
COMMON_NAME(R32G32B32_SINT),
COMMON_NAME(R32G32B32A32_SINT),
COMMON_NAME(R16_UNORM),
COMMON_NAME(R16G16_UNORM),
COMMON_NAME(R16G16B16_UNORM),
COMMON_NAME(R16G16B16A16_UNORM),
COMMON_NAME(R16_USCALED),
COMMON_NAME(R16G16_USCALED),
COMMON_NAME(R16G16B16_USCALED),
COMMON_NAME(R16G16B16A16_USCALED),
COMMON_NAME(R16_SNORM),
COMMON_NAME(R16G16_SNORM),
COMMON_NAME(R16G16B16_SNORM),
COMMON_NAME(R16G16B16A16_SNORM),
COMMON_NAME(R16_SSCALED),
COMMON_NAME(R16G16_SSCALED),
COMMON_NAME(R16G16B16_SSCALED),
COMMON_NAME(R16G16B16A16_SSCALED),
FLOAT_NAME(R16),
FLOAT_NAME(R16G16),
FLOAT_NAME(R16G16B16),
FLOAT_NAME(R16G16B16A16),
FLOAT_NAME(R32),
FLOAT_NAME(R32G32),
FLOAT_NAME(R32G32B32),
FLOAT_NAME(R32G32B32A32),
COMMON_NAME(S8_UINT),
[VK_FORMAT_UNDEFINED] = PIPE_FORMAT_NONE,
[VK_FORMAT_R5G6B5_UNORM_PACK16] = PIPE_FORMAT_B5G6R5_UNORM,
[VK_FORMAT_A1R5G5B5_UNORM_PACK16] = PIPE_FORMAT_B5G5R5A1_UNORM,
[VK_FORMAT_B4G4R4A4_UNORM_PACK16] = PIPE_FORMAT_A4R4G4B4_UNORM,
[VK_FORMAT_D16_UNORM] = PIPE_FORMAT_Z16_UNORM,
[VK_FORMAT_A8B8G8R8_UNORM_PACK32] = PIPE_FORMAT_R8G8B8A8_UNORM,
[VK_FORMAT_A8B8G8R8_SNORM_PACK32] = PIPE_FORMAT_R8G8B8A8_SNORM,
[VK_FORMAT_A8B8G8R8_UINT_PACK32] = PIPE_FORMAT_R8G8B8A8_UINT,
[VK_FORMAT_A8B8G8R8_SINT_PACK32] = PIPE_FORMAT_R8G8B8A8_SINT,
[VK_FORMAT_A8B8G8R8_SRGB_PACK32] = PIPE_FORMAT_R8G8B8A8_SRGB,
[VK_FORMAT_A2B10G10R10_UNORM_PACK32] = PIPE_FORMAT_R10G10B10A2_UNORM,
[VK_FORMAT_A2B10G10R10_SNORM_PACK32] = PIPE_FORMAT_R10G10B10A2_SNORM,
[VK_FORMAT_A2R10G10B10_UNORM_PACK32] = PIPE_FORMAT_B10G10R10A2_UNORM,
[VK_FORMAT_A2R10G10B10_SNORM_PACK32] = PIPE_FORMAT_B10G10R10A2_SNORM,
[VK_FORMAT_A2B10G10R10_UINT_PACK32] = PIPE_FORMAT_R10G10B10A2_UINT,
[VK_FORMAT_A2R10G10B10_UINT_PACK32] = PIPE_FORMAT_B10G10R10A2_UINT,
[VK_FORMAT_A2B10G10R10_USCALED_PACK32] = PIPE_FORMAT_R10G10B10A2_USCALED,
[VK_FORMAT_A2B10G10R10_SSCALED_PACK32] = PIPE_FORMAT_R10G10B10A2_SSCALED,
[VK_FORMAT_A2R10G10B10_USCALED_PACK32] = PIPE_FORMAT_B10G10R10A2_USCALED,
[VK_FORMAT_A2R10G10B10_SSCALED_PACK32] = PIPE_FORMAT_B10G10R10A2_SSCALED,
[VK_FORMAT_B10G11R11_UFLOAT_PACK32] = PIPE_FORMAT_R11G11B10_FLOAT,
[VK_FORMAT_E5B9G9R9_UFLOAT_PACK32] = PIPE_FORMAT_R9G9B9E5_FLOAT,
[VK_FORMAT_X8_D24_UNORM_PACK32] = PIPE_FORMAT_Z24X8_UNORM,
[VK_FORMAT_D32_SFLOAT] = PIPE_FORMAT_Z32_FLOAT,
[VK_FORMAT_D24_UNORM_S8_UINT] = PIPE_FORMAT_Z24_UNORM_S8_UINT,
[VK_FORMAT_D32_SFLOAT_S8_UINT] = PIPE_FORMAT_Z32_FLOAT_S8X24_UINT,
[VK_FORMAT_BC1_RGB_UNORM_BLOCK] = PIPE_FORMAT_DXT1_RGB,
[VK_FORMAT_BC1_RGBA_UNORM_BLOCK] = PIPE_FORMAT_DXT1_RGBA,
[VK_FORMAT_BC2_UNORM_BLOCK] = PIPE_FORMAT_DXT3_RGBA,
[VK_FORMAT_BC3_UNORM_BLOCK] = PIPE_FORMAT_DXT5_RGBA,
[VK_FORMAT_BC4_UNORM_BLOCK] = PIPE_FORMAT_RGTC1_UNORM,
[VK_FORMAT_BC5_UNORM_BLOCK] = PIPE_FORMAT_RGTC2_UNORM,
[VK_FORMAT_BC1_RGB_SRGB_BLOCK] = PIPE_FORMAT_DXT1_SRGB,
[VK_FORMAT_BC1_RGBA_SRGB_BLOCK] = PIPE_FORMAT_DXT1_SRGBA,
[VK_FORMAT_BC2_SRGB_BLOCK] = PIPE_FORMAT_DXT3_SRGBA,
[VK_FORMAT_BC3_SRGB_BLOCK] = PIPE_FORMAT_DXT5_SRGBA,
[VK_FORMAT_BC4_SNORM_BLOCK] = PIPE_FORMAT_RGTC1_SNORM,
[VK_FORMAT_BC5_SNORM_BLOCK] = PIPE_FORMAT_RGTC2_SNORM,
[VK_FORMAT_BC6H_UFLOAT_BLOCK] = PIPE_FORMAT_BPTC_RGB_UFLOAT,
[VK_FORMAT_BC6H_SFLOAT_BLOCK] = PIPE_FORMAT_BPTC_RGB_FLOAT,
[VK_FORMAT_BC7_UNORM_BLOCK] = PIPE_FORMAT_BPTC_RGBA_UNORM,
[VK_FORMAT_BC7_SRGB_BLOCK] = PIPE_FORMAT_BPTC_SRGBA,
};
enum pipe_format vk_format_to_pipe(VkFormat format)
{
if (format > VK_FORMAT_ASTC_12x12_SRGB_BLOCK)
return PIPE_FORMAT_NONE;
return format_to_vk_table[format];
}
static bool lvp_is_filter_minmax_format_supported(VkFormat format)
{
/* From the Vulkan spec 1.1.71:
......@@ -204,7 +60,7 @@ lvp_physical_device_get_format_properties(struct lvp_physical_device *physical_d
VkFormat format,
VkFormatProperties *out_properties)
{
enum pipe_format pformat = vk_format_to_pipe(format);
enum pipe_format pformat = lvp_vk_format_to_pipe_format(format);
unsigned features = 0, buffer_features = 0;
if (pformat == PIPE_FORMAT_NONE) {
out_properties->linearTilingFeatures = 0;
......@@ -322,7 +178,7 @@ static VkResult lvp_get_image_format_properties(struct lvp_physical_device *phys
uint32_t maxMipLevels;
uint32_t maxArraySize;
VkSampleCountFlags sampleCounts = VK_SAMPLE_COUNT_1_BIT;
enum pipe_format pformat = vk_format_to_pipe(info->format);
enum pipe_format pformat = lvp_vk_format_to_pipe_format(info->format);
lvp_physical_device_get_format_properties(physical_device, info->format,
&format_props);
if (info->tiling == VK_IMAGE_TILING_LINEAR) {
......
......@@ -77,7 +77,7 @@ lvp_image_create(VkDevice _device,
if (pCreateInfo->usage & VK_IMAGE_USAGE_STORAGE_BIT)
template.bind |= PIPE_BIND_SHADER_IMAGE;
template.format = vk_format_to_pipe(pCreateInfo->format);
template.format = lvp_vk_format_to_pipe_format(pCreateInfo->format);
template.width0 = pCreateInfo->extent.width;
template.height0 = pCreateInfo->extent.height;
template.depth0 = pCreateInfo->extent.depth;
......@@ -199,7 +199,7 @@ lvp_CreateImageView(VkDevice _device,
VK_OBJECT_TYPE_IMAGE_VIEW);
view->view_type = pCreateInfo->viewType;
view->format = pCreateInfo->format;
view->pformat = vk_format_to_pipe(pCreateInfo->format);
view->pformat = lvp_vk_format_to_pipe_format(pCreateInfo->format);
view->components = pCreateInfo->components;
view->subresourceRange = pCreateInfo->subresourceRange;
view->image = image;
......@@ -402,7 +402,7 @@ lvp_CreateBufferView(VkDevice _device,
VK_OBJECT_TYPE_BUFFER_VIEW);
view->buffer = buffer;
view->format = pCreateInfo->format;
view->pformat = vk_format_to_pipe(pCreateInfo->format);
view->pformat = lvp_vk_format_to_pipe_format(pCreateInfo->format);
view->offset = pCreateInfo->offset;
view->range = pCreateInfo->range;
*pView = lvp_buffer_view_to_handle(view);
......
......@@ -186,7 +186,7 @@ VKAPI_ATTR VkResult VKAPI_CALL lvp_CreateRenderPass2(
att->final_layout = pCreateInfo->pAttachments[i].finalLayout;
att->first_subpass_idx = UINT32_MAX;
bool is_zs = util_format_is_depth_or_stencil(vk_format_to_pipe(att->format));
bool is_zs = util_format_is_depth_or_stencil(lvp_vk_format_to_pipe_format(att->format));
pass->has_zs_attachment |= is_zs;
pass->has_color_attachment |= !is_zs;
}
......
......@@ -55,6 +55,7 @@ typedef uint32_t xcb_window_t;
#include "vk_physical_device.h"
#include "vk_shader_module.h"
#include "vk_util.h"
#include "vk_format.h"
#include "wsi_common.h"
......@@ -1167,31 +1168,39 @@ VkResult lvp_execute_cmds(struct lvp_device *device,
struct lvp_image *lvp_swapchain_get_image(VkSwapchainKHR swapchain,
uint32_t index);
enum pipe_format vk_format_to_pipe(VkFormat format);
static inline VkImageAspectFlags
vk_format_aspects(VkFormat format)
static inline enum pipe_format
lvp_vk_format_to_pipe_format(VkFormat format)
{
switch (format) {
case VK_FORMAT_UNDEFINED:
return 0;
case VK_FORMAT_S8_UINT:
return VK_IMAGE_ASPECT_STENCIL_BIT;
case VK_FORMAT_D16_UNORM_S8_UINT:
case VK_FORMAT_D24_UNORM_S8_UINT:
case VK_FORMAT_D32_SFLOAT_S8_UINT:
return VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
case VK_FORMAT_D16_UNORM:
case VK_FORMAT_X8_D24_UNORM_PACK32:
case VK_FORMAT_D32_SFLOAT:
return VK_IMAGE_ASPECT_DEPTH_BIT;
default:
return VK_IMAGE_ASPECT_COLOR_BIT;
}
/* Some formats cause problems with CTS right now.*/
if (format == VK_FORMAT_R4G4B4A4_UNORM_PACK16 ||
format == VK_FORMAT_A4R4G4B4_UNORM_PACK16_EXT || /* VK_EXT_4444_formats */
format == VK_FORMAT_A4B4G4R4_UNORM_PACK16_EXT || /* VK_EXT_4444_formats */
format == VK_FORMAT_R5G5B5A1_UNORM_PACK16 ||
format == VK_FORMAT_R8_SRGB ||
format == VK_FORMAT_R8G8_SRGB ||
format == VK_FORMAT_R64G64B64A64_SFLOAT ||
format == VK_FORMAT_R64_SFLOAT ||
format == VK_FORMAT_R64G64_SFLOAT ||
format == VK_FORMAT_R64G64B64_SFLOAT ||
format == VK_FORMAT_A2R10G10B10_SINT_PACK32 ||
format == VK_FORMAT_A2B10G10R10_SINT_PACK32 ||
format == VK_FORMAT_G8B8G8R8_422_UNORM ||
format == VK_FORMAT_B8G8R8G8_422_UNORM ||
format == VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM ||
format == VK_FORMAT_G8_B8R8_2PLANE_420_UNORM ||
format == VK_FORMAT_G8_B8_R8_3PLANE_422_UNORM ||
format == VK_FORMAT_G8_B8R8_2PLANE_422_UNORM ||
format == VK_FORMAT_G8_B8_R8_3PLANE_444_UNORM ||
format == VK_FORMAT_G16_B16_R16_3PLANE_420_UNORM ||
format == VK_FORMAT_G16_B16R16_2PLANE_420_UNORM ||
format == VK_FORMAT_G16_B16_R16_3PLANE_422_UNORM ||
format == VK_FORMAT_G16_B16R16_2PLANE_422_UNORM ||
format == VK_FORMAT_G16_B16_R16_3PLANE_444_UNORM ||
format == VK_FORMAT_D16_UNORM_S8_UINT)
return PIPE_FORMAT_NONE;
return vk_format_to_pipe_format(format);
}
#ifdef __cplusplus
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment