turnip: move enum translation functions to a common header
Instead of having these functions sprinkled around the driver (and ending with a duplicated tu6_compare_func for example), move everything to a common header (using the previously unused tu_util.h). Also applied some simplifications: using a cast when the HW enum matches the VK enum, and using a lookup table when it makes sense (which is IMO nicer than the switch case way). Signed-off-by: Jonathan Marek <jonathan@marek.ca> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5538>
This commit is contained in:
parent
f7cc7079b0
commit
f8110226ba
|
@ -284,38 +284,6 @@ tu_tiling_config_get_tile(const struct tu_tiling_config *tiling,
|
|||
: tile->begin.y + tiling->tile0.extent.height;
|
||||
}
|
||||
|
||||
enum a3xx_msaa_samples
|
||||
tu_msaa_samples(uint32_t samples)
|
||||
{
|
||||
switch (samples) {
|
||||
case 1:
|
||||
return MSAA_ONE;
|
||||
case 2:
|
||||
return MSAA_TWO;
|
||||
case 4:
|
||||
return MSAA_FOUR;
|
||||
case 8:
|
||||
return MSAA_EIGHT;
|
||||
default:
|
||||
assert(!"invalid sample count");
|
||||
return MSAA_ONE;
|
||||
}
|
||||
}
|
||||
|
||||
static enum a4xx_index_size
|
||||
tu6_index_size(VkIndexType type)
|
||||
{
|
||||
switch (type) {
|
||||
case VK_INDEX_TYPE_UINT16:
|
||||
return INDEX4_SIZE_16_BIT;
|
||||
case VK_INDEX_TYPE_UINT32:
|
||||
return INDEX4_SIZE_32_BIT;
|
||||
default:
|
||||
unreachable("invalid VkIndexType");
|
||||
return INDEX4_SIZE_8_BIT;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
tu6_emit_event_write(struct tu_cmd_buffer *cmd,
|
||||
struct tu_cs *cs,
|
||||
|
|
|
@ -2122,57 +2122,6 @@ tu_DestroyFramebuffer(VkDevice _device,
|
|||
vk_free2(&device->alloc, pAllocator, fb);
|
||||
}
|
||||
|
||||
static enum a6xx_tex_clamp
|
||||
tu6_tex_wrap(VkSamplerAddressMode address_mode)
|
||||
{
|
||||
switch (address_mode) {
|
||||
case VK_SAMPLER_ADDRESS_MODE_REPEAT:
|
||||
return A6XX_TEX_REPEAT;
|
||||
case VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT:
|
||||
return A6XX_TEX_MIRROR_REPEAT;
|
||||
case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE:
|
||||
return A6XX_TEX_CLAMP_TO_EDGE;
|
||||
case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER:
|
||||
return A6XX_TEX_CLAMP_TO_BORDER;
|
||||
case VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE:
|
||||
/* only works for PoT.. need to emulate otherwise! */
|
||||
return A6XX_TEX_MIRROR_CLAMP;
|
||||
default:
|
||||
unreachable("illegal tex wrap mode");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
enum a6xx_tex_filter
|
||||
tu6_tex_filter(VkFilter filter, unsigned aniso)
|
||||
{
|
||||
switch (filter) {
|
||||
case VK_FILTER_NEAREST:
|
||||
return A6XX_TEX_NEAREST;
|
||||
case VK_FILTER_LINEAR:
|
||||
return aniso ? A6XX_TEX_ANISO : A6XX_TEX_LINEAR;
|
||||
case VK_FILTER_CUBIC_EXT:
|
||||
return A6XX_TEX_CUBIC;
|
||||
default:
|
||||
unreachable("illegal texture filter");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static inline enum adreno_compare_func
|
||||
tu6_compare_func(VkCompareOp op)
|
||||
{
|
||||
return (enum adreno_compare_func) op;
|
||||
}
|
||||
|
||||
static inline enum a6xx_reduction_mode
|
||||
tu6_reduction_mode(VkSamplerReductionMode reduction_mode)
|
||||
{
|
||||
/* note: vulkan enum matches hw */
|
||||
|
||||
return (enum a6xx_reduction_mode) reduction_mode;
|
||||
}
|
||||
|
||||
static void
|
||||
tu_init_sampler(struct tu_device *device,
|
||||
struct tu_sampler *sampler,
|
||||
|
|
|
@ -358,23 +358,6 @@ tu6_format_texture(VkFormat format, enum a6xx_tile_mode tile_mode)
|
|||
return fmt;
|
||||
}
|
||||
|
||||
enum a6xx_depth_format
|
||||
tu6_pipe2depth(VkFormat format)
|
||||
{
|
||||
switch (format) {
|
||||
case VK_FORMAT_D16_UNORM:
|
||||
return DEPTH6_16;
|
||||
case VK_FORMAT_X8_D24_UNORM_PACK32:
|
||||
case VK_FORMAT_D24_UNORM_S8_UINT:
|
||||
return DEPTH6_24_8;
|
||||
case VK_FORMAT_D32_SFLOAT:
|
||||
case VK_FORMAT_S8_UINT:
|
||||
return DEPTH6_32;
|
||||
default:
|
||||
return ~0;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
tu_physical_device_get_format_properties(
|
||||
struct tu_physical_device *physical_device,
|
||||
|
|
|
@ -256,25 +256,6 @@ tu6_texswiz(const VkComponentMapping *comps,
|
|||
A6XX_TEX_CONST_0_SWIZ_W(swiz[3]);
|
||||
}
|
||||
|
||||
static enum a6xx_tex_type
|
||||
tu6_tex_type(VkImageViewType type, bool storage)
|
||||
{
|
||||
switch (type) {
|
||||
default:
|
||||
case VK_IMAGE_VIEW_TYPE_1D:
|
||||
case VK_IMAGE_VIEW_TYPE_1D_ARRAY:
|
||||
return A6XX_TEX_1D;
|
||||
case VK_IMAGE_VIEW_TYPE_2D:
|
||||
case VK_IMAGE_VIEW_TYPE_2D_ARRAY:
|
||||
return A6XX_TEX_2D;
|
||||
case VK_IMAGE_VIEW_TYPE_3D:
|
||||
return A6XX_TEX_3D;
|
||||
case VK_IMAGE_VIEW_TYPE_CUBE:
|
||||
case VK_IMAGE_VIEW_TYPE_CUBE_ARRAY:
|
||||
return storage ? A6XX_TEX_2D : A6XX_TEX_CUBE;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
tu_cs_image_ref(struct tu_cs *cs, const struct tu_image_view *iview, uint32_t layer)
|
||||
{
|
||||
|
|
|
@ -40,26 +40,6 @@
|
|||
|
||||
#include "tu_cs.h"
|
||||
|
||||
uint32_t
|
||||
tu6_stage2opcode(gl_shader_stage stage)
|
||||
{
|
||||
if (stage == MESA_SHADER_FRAGMENT || stage == MESA_SHADER_COMPUTE)
|
||||
return CP_LOAD_STATE6_FRAG;
|
||||
return CP_LOAD_STATE6_GEOM;
|
||||
}
|
||||
|
||||
static enum a6xx_state_block
|
||||
tu6_stage2texsb(gl_shader_stage stage)
|
||||
{
|
||||
return SB6_VS_TEX + stage;
|
||||
}
|
||||
|
||||
enum a6xx_state_block
|
||||
tu6_stage2shadersb(gl_shader_stage stage)
|
||||
{
|
||||
return SB6_VS_SHADER + stage;
|
||||
}
|
||||
|
||||
/* Emit IB that preloads the descriptors that the shader uses */
|
||||
|
||||
static void
|
||||
|
@ -337,199 +317,6 @@ tu_blend_state_is_dual_src(const VkPipelineColorBlendStateCreateInfo *info)
|
|||
return false;
|
||||
}
|
||||
|
||||
static enum pc_di_primtype
|
||||
tu6_primtype(VkPrimitiveTopology topology)
|
||||
{
|
||||
switch (topology) {
|
||||
case VK_PRIMITIVE_TOPOLOGY_POINT_LIST:
|
||||
return DI_PT_POINTLIST;
|
||||
case VK_PRIMITIVE_TOPOLOGY_LINE_LIST:
|
||||
return DI_PT_LINELIST;
|
||||
case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP:
|
||||
return DI_PT_LINESTRIP;
|
||||
case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST:
|
||||
return DI_PT_TRILIST;
|
||||
case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP:
|
||||
return DI_PT_TRISTRIP;
|
||||
case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN:
|
||||
return DI_PT_TRIFAN;
|
||||
case VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY:
|
||||
return DI_PT_LINE_ADJ;
|
||||
case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY:
|
||||
return DI_PT_LINESTRIP_ADJ;
|
||||
case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY:
|
||||
return DI_PT_TRI_ADJ;
|
||||
case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY:
|
||||
return DI_PT_TRISTRIP_ADJ;
|
||||
case VK_PRIMITIVE_TOPOLOGY_PATCH_LIST:
|
||||
default:
|
||||
unreachable("invalid primitive topology");
|
||||
return DI_PT_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
static enum adreno_compare_func
|
||||
tu6_compare_func(VkCompareOp op)
|
||||
{
|
||||
switch (op) {
|
||||
case VK_COMPARE_OP_NEVER:
|
||||
return FUNC_NEVER;
|
||||
case VK_COMPARE_OP_LESS:
|
||||
return FUNC_LESS;
|
||||
case VK_COMPARE_OP_EQUAL:
|
||||
return FUNC_EQUAL;
|
||||
case VK_COMPARE_OP_LESS_OR_EQUAL:
|
||||
return FUNC_LEQUAL;
|
||||
case VK_COMPARE_OP_GREATER:
|
||||
return FUNC_GREATER;
|
||||
case VK_COMPARE_OP_NOT_EQUAL:
|
||||
return FUNC_NOTEQUAL;
|
||||
case VK_COMPARE_OP_GREATER_OR_EQUAL:
|
||||
return FUNC_GEQUAL;
|
||||
case VK_COMPARE_OP_ALWAYS:
|
||||
return FUNC_ALWAYS;
|
||||
default:
|
||||
unreachable("invalid VkCompareOp");
|
||||
return FUNC_NEVER;
|
||||
}
|
||||
}
|
||||
|
||||
static enum adreno_stencil_op
|
||||
tu6_stencil_op(VkStencilOp op)
|
||||
{
|
||||
switch (op) {
|
||||
case VK_STENCIL_OP_KEEP:
|
||||
return STENCIL_KEEP;
|
||||
case VK_STENCIL_OP_ZERO:
|
||||
return STENCIL_ZERO;
|
||||
case VK_STENCIL_OP_REPLACE:
|
||||
return STENCIL_REPLACE;
|
||||
case VK_STENCIL_OP_INCREMENT_AND_CLAMP:
|
||||
return STENCIL_INCR_CLAMP;
|
||||
case VK_STENCIL_OP_DECREMENT_AND_CLAMP:
|
||||
return STENCIL_DECR_CLAMP;
|
||||
case VK_STENCIL_OP_INVERT:
|
||||
return STENCIL_INVERT;
|
||||
case VK_STENCIL_OP_INCREMENT_AND_WRAP:
|
||||
return STENCIL_INCR_WRAP;
|
||||
case VK_STENCIL_OP_DECREMENT_AND_WRAP:
|
||||
return STENCIL_DECR_WRAP;
|
||||
default:
|
||||
unreachable("invalid VkStencilOp");
|
||||
return STENCIL_KEEP;
|
||||
}
|
||||
}
|
||||
|
||||
static enum a3xx_rop_code
|
||||
tu6_rop(VkLogicOp op)
|
||||
{
|
||||
switch (op) {
|
||||
case VK_LOGIC_OP_CLEAR:
|
||||
return ROP_CLEAR;
|
||||
case VK_LOGIC_OP_AND:
|
||||
return ROP_AND;
|
||||
case VK_LOGIC_OP_AND_REVERSE:
|
||||
return ROP_AND_REVERSE;
|
||||
case VK_LOGIC_OP_COPY:
|
||||
return ROP_COPY;
|
||||
case VK_LOGIC_OP_AND_INVERTED:
|
||||
return ROP_AND_INVERTED;
|
||||
case VK_LOGIC_OP_NO_OP:
|
||||
return ROP_NOOP;
|
||||
case VK_LOGIC_OP_XOR:
|
||||
return ROP_XOR;
|
||||
case VK_LOGIC_OP_OR:
|
||||
return ROP_OR;
|
||||
case VK_LOGIC_OP_NOR:
|
||||
return ROP_NOR;
|
||||
case VK_LOGIC_OP_EQUIVALENT:
|
||||
return ROP_EQUIV;
|
||||
case VK_LOGIC_OP_INVERT:
|
||||
return ROP_INVERT;
|
||||
case VK_LOGIC_OP_OR_REVERSE:
|
||||
return ROP_OR_REVERSE;
|
||||
case VK_LOGIC_OP_COPY_INVERTED:
|
||||
return ROP_COPY_INVERTED;
|
||||
case VK_LOGIC_OP_OR_INVERTED:
|
||||
return ROP_OR_INVERTED;
|
||||
case VK_LOGIC_OP_NAND:
|
||||
return ROP_NAND;
|
||||
case VK_LOGIC_OP_SET:
|
||||
return ROP_SET;
|
||||
default:
|
||||
unreachable("invalid VkLogicOp");
|
||||
return ROP_NOOP;
|
||||
}
|
||||
}
|
||||
|
||||
static enum adreno_rb_blend_factor
|
||||
tu6_blend_factor(VkBlendFactor factor)
|
||||
{
|
||||
switch (factor) {
|
||||
case VK_BLEND_FACTOR_ZERO:
|
||||
return FACTOR_ZERO;
|
||||
case VK_BLEND_FACTOR_ONE:
|
||||
return FACTOR_ONE;
|
||||
case VK_BLEND_FACTOR_SRC_COLOR:
|
||||
return FACTOR_SRC_COLOR;
|
||||
case VK_BLEND_FACTOR_ONE_MINUS_SRC_COLOR:
|
||||
return FACTOR_ONE_MINUS_SRC_COLOR;
|
||||
case VK_BLEND_FACTOR_DST_COLOR:
|
||||
return FACTOR_DST_COLOR;
|
||||
case VK_BLEND_FACTOR_ONE_MINUS_DST_COLOR:
|
||||
return FACTOR_ONE_MINUS_DST_COLOR;
|
||||
case VK_BLEND_FACTOR_SRC_ALPHA:
|
||||
return FACTOR_SRC_ALPHA;
|
||||
case VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA:
|
||||
return FACTOR_ONE_MINUS_SRC_ALPHA;
|
||||
case VK_BLEND_FACTOR_DST_ALPHA:
|
||||
return FACTOR_DST_ALPHA;
|
||||
case VK_BLEND_FACTOR_ONE_MINUS_DST_ALPHA:
|
||||
return FACTOR_ONE_MINUS_DST_ALPHA;
|
||||
case VK_BLEND_FACTOR_CONSTANT_COLOR:
|
||||
return FACTOR_CONSTANT_COLOR;
|
||||
case VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR:
|
||||
return FACTOR_ONE_MINUS_CONSTANT_COLOR;
|
||||
case VK_BLEND_FACTOR_CONSTANT_ALPHA:
|
||||
return FACTOR_CONSTANT_ALPHA;
|
||||
case VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA:
|
||||
return FACTOR_ONE_MINUS_CONSTANT_ALPHA;
|
||||
case VK_BLEND_FACTOR_SRC_ALPHA_SATURATE:
|
||||
return FACTOR_SRC_ALPHA_SATURATE;
|
||||
case VK_BLEND_FACTOR_SRC1_COLOR:
|
||||
return FACTOR_SRC1_COLOR;
|
||||
case VK_BLEND_FACTOR_ONE_MINUS_SRC1_COLOR:
|
||||
return FACTOR_ONE_MINUS_SRC1_COLOR;
|
||||
case VK_BLEND_FACTOR_SRC1_ALPHA:
|
||||
return FACTOR_SRC1_ALPHA;
|
||||
case VK_BLEND_FACTOR_ONE_MINUS_SRC1_ALPHA:
|
||||
return FACTOR_ONE_MINUS_SRC1_ALPHA;
|
||||
default:
|
||||
unreachable("invalid VkBlendFactor");
|
||||
return FACTOR_ZERO;
|
||||
}
|
||||
}
|
||||
|
||||
static enum a3xx_rb_blend_opcode
|
||||
tu6_blend_op(VkBlendOp op)
|
||||
{
|
||||
switch (op) {
|
||||
case VK_BLEND_OP_ADD:
|
||||
return BLEND_DST_PLUS_SRC;
|
||||
case VK_BLEND_OP_SUBTRACT:
|
||||
return BLEND_SRC_MINUS_DST;
|
||||
case VK_BLEND_OP_REVERSE_SUBTRACT:
|
||||
return BLEND_DST_MINUS_SRC;
|
||||
case VK_BLEND_OP_MIN:
|
||||
return BLEND_MIN_DST_SRC;
|
||||
case VK_BLEND_OP_MAX:
|
||||
return BLEND_MAX_DST_SRC;
|
||||
default:
|
||||
unreachable("invalid VkBlendOp");
|
||||
return BLEND_DST_PLUS_SRC;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
tu6_emit_xs_config(struct tu_cs *cs,
|
||||
gl_shader_stage stage, /* xs->type, but xs may be NULL */
|
||||
|
|
|
@ -62,6 +62,7 @@
|
|||
|
||||
#include "tu_descriptor_set.h"
|
||||
#include "tu_extensions.h"
|
||||
#include "tu_util.h"
|
||||
|
||||
/* Pre-declarations needed for WSI entrypoints */
|
||||
struct wl_surface;
|
||||
|
@ -1008,31 +1009,6 @@ struct tu_event
|
|||
struct tu_bo bo;
|
||||
};
|
||||
|
||||
static inline gl_shader_stage
|
||||
vk_to_mesa_shader_stage(VkShaderStageFlagBits vk_stage)
|
||||
{
|
||||
assert(__builtin_popcount(vk_stage) == 1);
|
||||
return ffs(vk_stage) - 1;
|
||||
}
|
||||
|
||||
static inline VkShaderStageFlagBits
|
||||
mesa_to_vk_shader_stage(gl_shader_stage mesa_stage)
|
||||
{
|
||||
return (1 << mesa_stage);
|
||||
}
|
||||
|
||||
#define TU_STAGE_MASK ((1 << MESA_SHADER_STAGES) - 1)
|
||||
|
||||
#define tu_foreach_stage(stage, stage_bits) \
|
||||
for (gl_shader_stage stage, \
|
||||
__tmp = (gl_shader_stage)((stage_bits) &TU_STAGE_MASK); \
|
||||
stage = __builtin_ffs(__tmp) - 1, __tmp; __tmp &= ~(1 << (stage)))
|
||||
|
||||
uint32_t
|
||||
tu6_stage2opcode(gl_shader_stage type);
|
||||
enum a6xx_state_block
|
||||
tu6_stage2shadersb(gl_shader_stage type);
|
||||
|
||||
struct tu_shader_module
|
||||
{
|
||||
unsigned char sha1[20];
|
||||
|
@ -1247,8 +1223,6 @@ tu6_base_format(VkFormat format)
|
|||
return tu6_format_color(format, TILE6_LINEAR).fmt;
|
||||
}
|
||||
|
||||
enum a6xx_depth_format tu6_pipe2depth(VkFormat format);
|
||||
|
||||
struct tu_image
|
||||
{
|
||||
VkImageType type;
|
||||
|
@ -1297,9 +1271,6 @@ tu_get_levelCount(const struct tu_image *image,
|
|||
: range->levelCount;
|
||||
}
|
||||
|
||||
enum a3xx_msaa_samples
|
||||
tu_msaa_samples(uint32_t samples);
|
||||
|
||||
struct tu_image_view
|
||||
{
|
||||
struct tu_image *image; /**< VkImageViewCreateInfo::image */
|
||||
|
@ -1360,9 +1331,6 @@ tu_cs_image_ref_2d(struct tu_cs *cs, const struct tu_image_view *iview, uint32_t
|
|||
void
|
||||
tu_cs_image_flag_ref(struct tu_cs *cs, const struct tu_image_view *iview, uint32_t layer);
|
||||
|
||||
enum a6xx_tex_filter
|
||||
tu6_tex_filter(VkFilter filter, unsigned aniso);
|
||||
|
||||
VkResult
|
||||
tu_image_create(VkDevice _device,
|
||||
const VkImageCreateInfo *pCreateInfo,
|
||||
|
|
|
@ -1,11 +1,251 @@
|
|||
/*
|
||||
* Copyright 2020 Valve Corporation
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Authors:
|
||||
* Jonathan Marek <jonathan@marek.ca>
|
||||
*/
|
||||
|
||||
#ifndef TU_UTIL_H
|
||||
#define TU_UTIL_H
|
||||
|
||||
#ifdef HAVE___BUILTIN_POPCOUNT
|
||||
#define util_bitcount(i) __builtin_popcount(i)
|
||||
#else
|
||||
extern unsigned int
|
||||
util_bitcount(unsigned int n);
|
||||
#endif
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "util/macros.h"
|
||||
#include "util/u_math.h"
|
||||
#include "compiler/shader_enums.h"
|
||||
|
||||
#include "adreno_common.xml.h"
|
||||
#include "adreno_pm4.xml.h"
|
||||
#include "a6xx.xml.h"
|
||||
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
static inline gl_shader_stage
|
||||
vk_to_mesa_shader_stage(VkShaderStageFlagBits vk_stage)
|
||||
{
|
||||
assert(__builtin_popcount(vk_stage) == 1);
|
||||
return util_logbase2(vk_stage);
|
||||
}
|
||||
|
||||
static inline VkShaderStageFlagBits
|
||||
mesa_to_vk_shader_stage(gl_shader_stage mesa_stage)
|
||||
{
|
||||
return 1 << mesa_stage;
|
||||
}
|
||||
|
||||
#define TU_STAGE_MASK ((1 << MESA_SHADER_STAGES) - 1)
|
||||
|
||||
#define tu_foreach_stage(stage, stage_bits) \
|
||||
for (gl_shader_stage stage, \
|
||||
__tmp = (gl_shader_stage)((stage_bits) &TU_STAGE_MASK); \
|
||||
stage = __builtin_ffs(__tmp) - 1, __tmp; __tmp &= ~(1 << (stage)))
|
||||
|
||||
static inline enum a3xx_msaa_samples
|
||||
tu_msaa_samples(VkSampleCountFlagBits samples)
|
||||
{
|
||||
assert(__builtin_popcount(samples) == 1);
|
||||
return util_logbase2(samples);
|
||||
}
|
||||
|
||||
static inline enum a4xx_index_size
|
||||
tu6_index_size(VkIndexType type)
|
||||
{
|
||||
switch (type) {
|
||||
case VK_INDEX_TYPE_UINT16:
|
||||
return INDEX4_SIZE_16_BIT;
|
||||
case VK_INDEX_TYPE_UINT32:
|
||||
return INDEX4_SIZE_32_BIT;
|
||||
case VK_INDEX_TYPE_UINT8_EXT:
|
||||
return INDEX4_SIZE_8_BIT;
|
||||
default:
|
||||
unreachable("invalid VkIndexType");
|
||||
}
|
||||
}
|
||||
|
||||
static inline uint32_t
|
||||
tu6_stage2opcode(gl_shader_stage stage)
|
||||
{
|
||||
if (stage == MESA_SHADER_FRAGMENT || stage == MESA_SHADER_COMPUTE)
|
||||
return CP_LOAD_STATE6_FRAG;
|
||||
return CP_LOAD_STATE6_GEOM;
|
||||
}
|
||||
|
||||
static inline enum a6xx_state_block
|
||||
tu6_stage2texsb(gl_shader_stage stage)
|
||||
{
|
||||
return SB6_VS_TEX + stage;
|
||||
}
|
||||
|
||||
static inline enum a6xx_state_block
|
||||
tu6_stage2shadersb(gl_shader_stage stage)
|
||||
{
|
||||
return SB6_VS_SHADER + stage;
|
||||
}
|
||||
|
||||
static inline enum a3xx_rop_code
|
||||
tu6_rop(VkLogicOp op)
|
||||
{
|
||||
/* note: hw enum matches the VK enum, but with the 4 bits reversed */
|
||||
static const uint8_t lookup[] = {
|
||||
[VK_LOGIC_OP_CLEAR] = ROP_CLEAR,
|
||||
[VK_LOGIC_OP_AND] = ROP_AND,
|
||||
[VK_LOGIC_OP_AND_REVERSE] = ROP_AND_REVERSE,
|
||||
[VK_LOGIC_OP_COPY] = ROP_COPY,
|
||||
[VK_LOGIC_OP_AND_INVERTED] = ROP_AND_INVERTED,
|
||||
[VK_LOGIC_OP_NO_OP] = ROP_NOOP,
|
||||
[VK_LOGIC_OP_XOR] = ROP_XOR,
|
||||
[VK_LOGIC_OP_OR] = ROP_OR,
|
||||
[VK_LOGIC_OP_NOR] = ROP_NOR,
|
||||
[VK_LOGIC_OP_EQUIVALENT] = ROP_EQUIV,
|
||||
[VK_LOGIC_OP_INVERT] = ROP_INVERT,
|
||||
[VK_LOGIC_OP_OR_REVERSE] = ROP_OR_REVERSE,
|
||||
[VK_LOGIC_OP_COPY_INVERTED] = ROP_COPY_INVERTED,
|
||||
[VK_LOGIC_OP_OR_INVERTED] = ROP_OR_INVERTED,
|
||||
[VK_LOGIC_OP_NAND] = ROP_NAND,
|
||||
[VK_LOGIC_OP_SET] = ROP_SET,
|
||||
};
|
||||
assert(op < ARRAY_SIZE(lookup));
|
||||
return lookup[op];
|
||||
}
|
||||
|
||||
static inline enum pc_di_primtype
|
||||
tu6_primtype(VkPrimitiveTopology topology)
|
||||
{
|
||||
static const uint8_t lookup[] = {
|
||||
[VK_PRIMITIVE_TOPOLOGY_POINT_LIST] = DI_PT_POINTLIST,
|
||||
[VK_PRIMITIVE_TOPOLOGY_LINE_LIST] = DI_PT_LINELIST,
|
||||
[VK_PRIMITIVE_TOPOLOGY_LINE_STRIP] = DI_PT_LINESTRIP,
|
||||
[VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST] = DI_PT_TRILIST,
|
||||
[VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP] = DI_PT_TRISTRIP,
|
||||
[VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN] = DI_PT_TRIFAN,
|
||||
[VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY] = DI_PT_LINE_ADJ,
|
||||
[VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY] = DI_PT_LINESTRIP_ADJ,
|
||||
[VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY] = DI_PT_TRI_ADJ,
|
||||
[VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY] = DI_PT_TRISTRIP_ADJ,
|
||||
[VK_PRIMITIVE_TOPOLOGY_PATCH_LIST] = 0,
|
||||
};
|
||||
assert(topology < ARRAY_SIZE(lookup));
|
||||
return lookup[topology];
|
||||
}
|
||||
|
||||
static inline enum adreno_compare_func
|
||||
tu6_compare_func(VkCompareOp op)
|
||||
{
|
||||
return (enum adreno_compare_func) op;
|
||||
}
|
||||
|
||||
static inline enum adreno_stencil_op
|
||||
tu6_stencil_op(VkStencilOp op)
|
||||
{
|
||||
return (enum adreno_stencil_op) op;
|
||||
}
|
||||
|
||||
static inline enum adreno_rb_blend_factor
|
||||
tu6_blend_factor(VkBlendFactor factor)
|
||||
{
|
||||
static const uint8_t lookup[] = {
|
||||
[VK_BLEND_FACTOR_ZERO] = FACTOR_ZERO,
|
||||
[VK_BLEND_FACTOR_ONE] = FACTOR_ONE,
|
||||
[VK_BLEND_FACTOR_SRC_COLOR] = FACTOR_SRC_COLOR,
|
||||
[VK_BLEND_FACTOR_ONE_MINUS_SRC_COLOR] = FACTOR_ONE_MINUS_SRC_COLOR,
|
||||
[VK_BLEND_FACTOR_DST_COLOR] = FACTOR_DST_COLOR,
|
||||
[VK_BLEND_FACTOR_ONE_MINUS_DST_COLOR] = FACTOR_ONE_MINUS_DST_COLOR,
|
||||
[VK_BLEND_FACTOR_SRC_ALPHA] = FACTOR_SRC_ALPHA,
|
||||
[VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA] = FACTOR_ONE_MINUS_SRC_ALPHA,
|
||||
[VK_BLEND_FACTOR_DST_ALPHA] = FACTOR_DST_ALPHA,
|
||||
[VK_BLEND_FACTOR_ONE_MINUS_DST_ALPHA] = FACTOR_ONE_MINUS_DST_ALPHA,
|
||||
[VK_BLEND_FACTOR_CONSTANT_COLOR] = FACTOR_CONSTANT_COLOR,
|
||||
[VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR]= FACTOR_ONE_MINUS_CONSTANT_COLOR,
|
||||
[VK_BLEND_FACTOR_CONSTANT_ALPHA] = FACTOR_CONSTANT_ALPHA,
|
||||
[VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA]= FACTOR_ONE_MINUS_CONSTANT_ALPHA,
|
||||
[VK_BLEND_FACTOR_SRC_ALPHA_SATURATE] = FACTOR_SRC_ALPHA_SATURATE,
|
||||
[VK_BLEND_FACTOR_SRC1_COLOR] = FACTOR_SRC1_COLOR,
|
||||
[VK_BLEND_FACTOR_ONE_MINUS_SRC1_COLOR] = FACTOR_ONE_MINUS_SRC1_COLOR,
|
||||
[VK_BLEND_FACTOR_SRC1_ALPHA] = FACTOR_SRC1_ALPHA,
|
||||
[VK_BLEND_FACTOR_ONE_MINUS_SRC1_ALPHA] = FACTOR_ONE_MINUS_SRC1_ALPHA,
|
||||
};
|
||||
assert(factor < ARRAY_SIZE(lookup));
|
||||
return lookup[factor];
|
||||
}
|
||||
|
||||
static inline enum a3xx_rb_blend_opcode
|
||||
tu6_blend_op(VkBlendOp op)
|
||||
{
|
||||
return (enum a3xx_rb_blend_opcode) op;
|
||||
}
|
||||
|
||||
static inline enum a6xx_tex_type
|
||||
tu6_tex_type(VkImageViewType type, bool storage)
|
||||
{
|
||||
switch (type) {
|
||||
default:
|
||||
case VK_IMAGE_VIEW_TYPE_1D:
|
||||
case VK_IMAGE_VIEW_TYPE_1D_ARRAY:
|
||||
return A6XX_TEX_1D;
|
||||
case VK_IMAGE_VIEW_TYPE_2D:
|
||||
case VK_IMAGE_VIEW_TYPE_2D_ARRAY:
|
||||
return A6XX_TEX_2D;
|
||||
case VK_IMAGE_VIEW_TYPE_3D:
|
||||
return A6XX_TEX_3D;
|
||||
case VK_IMAGE_VIEW_TYPE_CUBE:
|
||||
case VK_IMAGE_VIEW_TYPE_CUBE_ARRAY:
|
||||
return storage ? A6XX_TEX_2D : A6XX_TEX_CUBE;
|
||||
}
|
||||
}
|
||||
|
||||
static inline enum a6xx_tex_clamp
|
||||
tu6_tex_wrap(VkSamplerAddressMode address_mode)
|
||||
{
|
||||
uint8_t lookup[] = {
|
||||
[VK_SAMPLER_ADDRESS_MODE_REPEAT] = A6XX_TEX_REPEAT,
|
||||
[VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT] = A6XX_TEX_MIRROR_REPEAT,
|
||||
[VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE] = A6XX_TEX_CLAMP_TO_EDGE,
|
||||
[VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER] = A6XX_TEX_CLAMP_TO_BORDER,
|
||||
[VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE] = A6XX_TEX_MIRROR_CLAMP,
|
||||
};
|
||||
assert(address_mode < ARRAY_SIZE(lookup));
|
||||
return lookup[address_mode];
|
||||
}
|
||||
|
||||
static inline enum a6xx_tex_filter
|
||||
tu6_tex_filter(VkFilter filter, unsigned aniso)
|
||||
{
|
||||
switch (filter) {
|
||||
case VK_FILTER_NEAREST:
|
||||
return A6XX_TEX_NEAREST;
|
||||
case VK_FILTER_LINEAR:
|
||||
return aniso ? A6XX_TEX_ANISO : A6XX_TEX_LINEAR;
|
||||
case VK_FILTER_CUBIC_EXT:
|
||||
return A6XX_TEX_CUBIC;
|
||||
default:
|
||||
unreachable("illegal texture filter");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static inline enum a6xx_reduction_mode
|
||||
tu6_reduction_mode(VkSamplerReductionMode reduction_mode)
|
||||
{
|
||||
return (enum a6xx_reduction_mode) reduction_mode;
|
||||
}
|
||||
|
||||
static inline enum a6xx_depth_format
|
||||
tu6_pipe2depth(VkFormat format)
|
||||
{
|
||||
switch (format) {
|
||||
case VK_FORMAT_D16_UNORM:
|
||||
return DEPTH6_16;
|
||||
case VK_FORMAT_X8_D24_UNORM_PACK32:
|
||||
case VK_FORMAT_D24_UNORM_S8_UINT:
|
||||
return DEPTH6_24_8;
|
||||
case VK_FORMAT_D32_SFLOAT:
|
||||
case VK_FORMAT_S8_UINT:
|
||||
return DEPTH6_32;
|
||||
default:
|
||||
return ~0;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* TU_UTIL_H */
|
||||
|
|
Loading…
Reference in New Issue