zink: make zink_format all about raw format-translation

This moves the parts of zink_format.c that also operates on zink_screen
into zink_screen.c. This has the benefit that we can start testing the
enum-translation code separately from the state.

This will make the next commit a bit cleaner.

Reviewed-By: Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7982>
This commit is contained in:
Erik Faye-Lund 2020-12-07 19:50:04 +01:00 committed by Marge Bot
parent d66df61bf7
commit 123f3d0d64
3 changed files with 84 additions and 43 deletions

View file

@ -1,4 +1,4 @@
#include "zink_screen.h"
#include "zink_format.h"
static const VkFormat formats[PIPE_FORMAT_COUNT] = {
#define MAP_FORMAT_NORM(FMT) \
@ -129,48 +129,8 @@ static const VkFormat formats[PIPE_FORMAT_COUNT] = {
[PIPE_FORMAT_BPTC_RGB_UFLOAT] = VK_FORMAT_BC6H_UFLOAT_BLOCK,
};
bool
zink_is_depth_format_supported(struct zink_screen *screen, VkFormat format)
{
VkFormatProperties props;
vkGetPhysicalDeviceFormatProperties(screen->pdev, format, &props);
return (props.linearTilingFeatures | props.optimalTilingFeatures) &
VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT;
}
static enum pipe_format
emulate_x8(enum pipe_format format)
{
/* convert missing X8 variants to A8 */
switch (format) {
case PIPE_FORMAT_B8G8R8X8_UNORM:
return PIPE_FORMAT_B8G8R8A8_UNORM;
case PIPE_FORMAT_B8G8R8X8_SRGB:
return PIPE_FORMAT_B8G8R8A8_SRGB;
default:
return format;
}
}
VkFormat
zink_get_format(struct zink_screen *screen, enum pipe_format format)
zink_pipe_format_to_vk_format(enum pipe_format format)
{
VkFormat ret = formats[emulate_x8(format)];
if (ret == VK_FORMAT_X8_D24_UNORM_PACK32 &&
!screen->have_X8_D24_UNORM_PACK32) {
assert(zink_is_depth_format_supported(screen, VK_FORMAT_D32_SFLOAT));
return VK_FORMAT_D32_SFLOAT;
}
if (ret == VK_FORMAT_D24_UNORM_S8_UINT &&
!screen->have_D24_UNORM_S8_UINT) {
assert(zink_is_depth_format_supported(screen,
VK_FORMAT_D32_SFLOAT_S8_UINT));
return VK_FORMAT_D32_SFLOAT_S8_UINT;
}
return ret;
return formats[format];
}

View file

@ -0,0 +1,34 @@
/*
* Copyright 2020 Collabora Ltd.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* on the rights to use, copy, modify, merge, publish, distribute, sub
* license, and/or sell copies of the Software, and to permit persons to whom
* the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
* THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
* USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef ZINK_FORMAT_H
#define ZINK_FORMAT_H
#include "pipe/p_format.h"
#include <vulkan/vulkan.h>
VkFormat
zink_pipe_format_to_vk_format(enum pipe_format format);
#endif

View file

@ -27,6 +27,7 @@
#include "zink_context.h"
#include "zink_device_info.h"
#include "zink_fence.h"
#include "zink_format.h"
#include "zink_instance.h"
#include "zink_public.h"
#include "zink_resource.h"
@ -735,6 +736,52 @@ zink_flush_frontbuffer(struct pipe_screen *pscreen,
winsys->displaytarget_display(winsys, res->dt, winsys_drawable_handle, sub_box);
}
bool
zink_is_depth_format_supported(struct zink_screen *screen, VkFormat format)
{
VkFormatProperties props;
vkGetPhysicalDeviceFormatProperties(screen->pdev, format, &props);
return (props.linearTilingFeatures | props.optimalTilingFeatures) &
VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT;
}
static enum pipe_format
emulate_x8(enum pipe_format format)
{
/* convert missing X8 variants to A8 */
switch (format) {
case PIPE_FORMAT_B8G8R8X8_UNORM:
return PIPE_FORMAT_B8G8R8A8_UNORM;
case PIPE_FORMAT_B8G8R8X8_SRGB:
return PIPE_FORMAT_B8G8R8A8_SRGB;
default:
return format;
}
}
VkFormat
zink_get_format(struct zink_screen *screen, enum pipe_format format)
{
VkFormat ret = zink_pipe_format_to_vk_format(emulate_x8(format));
if (ret == VK_FORMAT_X8_D24_UNORM_PACK32 &&
!screen->have_X8_D24_UNORM_PACK32) {
assert(zink_is_depth_format_supported(screen, VK_FORMAT_D32_SFLOAT));
return VK_FORMAT_D32_SFLOAT;
}
if (ret == VK_FORMAT_D24_UNORM_S8_UINT &&
!screen->have_D24_UNORM_S8_UINT) {
assert(zink_is_depth_format_supported(screen,
VK_FORMAT_D32_SFLOAT_S8_UINT));
return VK_FORMAT_D32_SFLOAT_S8_UINT;
}
return ret;
}
static bool
load_instance_extensions(struct zink_screen *screen)
{