17ec681f3Smrg/* 27ec681f3Smrg * Copyright © 2019 Red Hat. 37ec681f3Smrg * 47ec681f3Smrg * Permission is hereby granted, free of charge, to any person obtaining a 57ec681f3Smrg * copy of this software and associated documentation files (the "Software"), 67ec681f3Smrg * to deal in the Software without restriction, including without limitation 77ec681f3Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 87ec681f3Smrg * and/or sell copies of the Software, and to permit persons to whom the 97ec681f3Smrg * Software is furnished to do so, subject to the following conditions: 107ec681f3Smrg * 117ec681f3Smrg * The above copyright notice and this permission notice (including the next 127ec681f3Smrg * paragraph) shall be included in all copies or substantial portions of the 137ec681f3Smrg * Software. 147ec681f3Smrg * 157ec681f3Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 167ec681f3Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 177ec681f3Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 187ec681f3Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 197ec681f3Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 207ec681f3Smrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 217ec681f3Smrg * IN THE SOFTWARE. 227ec681f3Smrg */ 237ec681f3Smrg 247ec681f3Smrg#pragma once 257ec681f3Smrg 267ec681f3Smrgstatic inline unsigned vk_cull_to_pipe(uint32_t vk_cull) 277ec681f3Smrg{ 287ec681f3Smrg /* these correspond */ 297ec681f3Smrg return vk_cull; 307ec681f3Smrg} 317ec681f3Smrg 327ec681f3Smrgstatic inline unsigned vk_polygon_mode_to_pipe(uint32_t vk_poly_mode) 337ec681f3Smrg{ 347ec681f3Smrg /* these correspond */ 357ec681f3Smrg return vk_poly_mode; 367ec681f3Smrg} 377ec681f3Smrg 387ec681f3Smrgstatic inline unsigned vk_conv_stencil_op(uint32_t vk_stencil_op) 397ec681f3Smrg{ 407ec681f3Smrg switch (vk_stencil_op) { 417ec681f3Smrg case VK_STENCIL_OP_KEEP: 427ec681f3Smrg return PIPE_STENCIL_OP_KEEP; 437ec681f3Smrg case VK_STENCIL_OP_ZERO: 447ec681f3Smrg return PIPE_STENCIL_OP_ZERO; 457ec681f3Smrg case VK_STENCIL_OP_REPLACE: 467ec681f3Smrg return PIPE_STENCIL_OP_REPLACE; 477ec681f3Smrg case VK_STENCIL_OP_INCREMENT_AND_CLAMP: 487ec681f3Smrg return PIPE_STENCIL_OP_INCR; 497ec681f3Smrg case VK_STENCIL_OP_DECREMENT_AND_CLAMP: 507ec681f3Smrg return PIPE_STENCIL_OP_DECR; 517ec681f3Smrg case VK_STENCIL_OP_INVERT: 527ec681f3Smrg return PIPE_STENCIL_OP_INVERT; 537ec681f3Smrg case VK_STENCIL_OP_INCREMENT_AND_WRAP: 547ec681f3Smrg return PIPE_STENCIL_OP_INCR_WRAP; 557ec681f3Smrg case VK_STENCIL_OP_DECREMENT_AND_WRAP: 567ec681f3Smrg return PIPE_STENCIL_OP_DECR_WRAP; 577ec681f3Smrg default: 587ec681f3Smrg assert(0); 597ec681f3Smrg return 0; 607ec681f3Smrg } 617ec681f3Smrg} 627ec681f3Smrg 637ec681f3Smrgstatic inline unsigned vk_conv_topology(VkPrimitiveTopology topology) 647ec681f3Smrg{ 657ec681f3Smrg switch (topology) { 667ec681f3Smrg case VK_PRIMITIVE_TOPOLOGY_POINT_LIST: 677ec681f3Smrg return PIPE_PRIM_POINTS; 687ec681f3Smrg case VK_PRIMITIVE_TOPOLOGY_LINE_LIST: 697ec681f3Smrg return PIPE_PRIM_LINES; 707ec681f3Smrg case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP: 717ec681f3Smrg return PIPE_PRIM_LINE_STRIP; 727ec681f3Smrg case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST: 737ec681f3Smrg return PIPE_PRIM_TRIANGLES; 747ec681f3Smrg case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP: 757ec681f3Smrg return PIPE_PRIM_TRIANGLE_STRIP; 767ec681f3Smrg case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN: 777ec681f3Smrg return PIPE_PRIM_TRIANGLE_FAN; 787ec681f3Smrg case VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY: 797ec681f3Smrg return PIPE_PRIM_LINES_ADJACENCY; 807ec681f3Smrg case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY: 817ec681f3Smrg return PIPE_PRIM_LINE_STRIP_ADJACENCY; 827ec681f3Smrg case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY: 837ec681f3Smrg return PIPE_PRIM_TRIANGLES_ADJACENCY; 847ec681f3Smrg case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY: 857ec681f3Smrg return PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY; 867ec681f3Smrg case VK_PRIMITIVE_TOPOLOGY_PATCH_LIST: 877ec681f3Smrg return PIPE_PRIM_PATCHES; 887ec681f3Smrg default: 897ec681f3Smrg assert(0); 907ec681f3Smrg return 0; 917ec681f3Smrg } 927ec681f3Smrg} 937ec681f3Smrg 947ec681f3Smrgstatic inline unsigned vk_conv_wrap_mode(enum VkSamplerAddressMode addr_mode) 957ec681f3Smrg{ 967ec681f3Smrg switch (addr_mode) { 977ec681f3Smrg case VK_SAMPLER_ADDRESS_MODE_REPEAT: 987ec681f3Smrg return PIPE_TEX_WRAP_REPEAT; 997ec681f3Smrg case VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT: 1007ec681f3Smrg return PIPE_TEX_WRAP_MIRROR_REPEAT; 1017ec681f3Smrg case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE: 1027ec681f3Smrg return PIPE_TEX_WRAP_CLAMP_TO_EDGE; 1037ec681f3Smrg case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER: 1047ec681f3Smrg return PIPE_TEX_WRAP_CLAMP_TO_BORDER; 1057ec681f3Smrg case VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE: 1067ec681f3Smrg return PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE; 1077ec681f3Smrg default: 1087ec681f3Smrg assert(0); 1097ec681f3Smrg return 0; 1107ec681f3Smrg } 1117ec681f3Smrg} 1127ec681f3Smrg 1137ec681f3Smrgstatic inline unsigned vk_conv_blend_factor(enum VkBlendFactor vk_factor) 1147ec681f3Smrg{ 1157ec681f3Smrg switch (vk_factor) { 1167ec681f3Smrg case VK_BLEND_FACTOR_ZERO: 1177ec681f3Smrg return PIPE_BLENDFACTOR_ZERO; 1187ec681f3Smrg case VK_BLEND_FACTOR_ONE: 1197ec681f3Smrg return PIPE_BLENDFACTOR_ONE; 1207ec681f3Smrg case VK_BLEND_FACTOR_SRC_COLOR: 1217ec681f3Smrg return PIPE_BLENDFACTOR_SRC_COLOR; 1227ec681f3Smrg case VK_BLEND_FACTOR_ONE_MINUS_SRC_COLOR: 1237ec681f3Smrg return PIPE_BLENDFACTOR_INV_SRC_COLOR; 1247ec681f3Smrg case VK_BLEND_FACTOR_DST_COLOR: 1257ec681f3Smrg return PIPE_BLENDFACTOR_DST_COLOR; 1267ec681f3Smrg case VK_BLEND_FACTOR_ONE_MINUS_DST_COLOR: 1277ec681f3Smrg return PIPE_BLENDFACTOR_INV_DST_COLOR; 1287ec681f3Smrg case VK_BLEND_FACTOR_SRC_ALPHA: 1297ec681f3Smrg return PIPE_BLENDFACTOR_SRC_ALPHA; 1307ec681f3Smrg case VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA: 1317ec681f3Smrg return PIPE_BLENDFACTOR_INV_SRC_ALPHA; 1327ec681f3Smrg case VK_BLEND_FACTOR_DST_ALPHA: 1337ec681f3Smrg return PIPE_BLENDFACTOR_DST_ALPHA; 1347ec681f3Smrg case VK_BLEND_FACTOR_ONE_MINUS_DST_ALPHA: 1357ec681f3Smrg return PIPE_BLENDFACTOR_INV_DST_ALPHA; 1367ec681f3Smrg case VK_BLEND_FACTOR_CONSTANT_COLOR: 1377ec681f3Smrg return PIPE_BLENDFACTOR_CONST_COLOR; 1387ec681f3Smrg case VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR: 1397ec681f3Smrg return PIPE_BLENDFACTOR_INV_CONST_COLOR; 1407ec681f3Smrg case VK_BLEND_FACTOR_CONSTANT_ALPHA: 1417ec681f3Smrg return PIPE_BLENDFACTOR_CONST_ALPHA; 1427ec681f3Smrg case VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA: 1437ec681f3Smrg return PIPE_BLENDFACTOR_INV_CONST_ALPHA; 1447ec681f3Smrg case VK_BLEND_FACTOR_SRC1_COLOR: 1457ec681f3Smrg return PIPE_BLENDFACTOR_SRC1_COLOR; 1467ec681f3Smrg case VK_BLEND_FACTOR_ONE_MINUS_SRC1_COLOR: 1477ec681f3Smrg return PIPE_BLENDFACTOR_INV_SRC1_COLOR; 1487ec681f3Smrg case VK_BLEND_FACTOR_SRC1_ALPHA: 1497ec681f3Smrg return PIPE_BLENDFACTOR_SRC1_ALPHA; 1507ec681f3Smrg case VK_BLEND_FACTOR_ONE_MINUS_SRC1_ALPHA: 1517ec681f3Smrg return PIPE_BLENDFACTOR_INV_SRC1_ALPHA; 1527ec681f3Smrg case VK_BLEND_FACTOR_SRC_ALPHA_SATURATE: 1537ec681f3Smrg return PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE; 1547ec681f3Smrg default: 1557ec681f3Smrg assert(0); 1567ec681f3Smrg return 0; 1577ec681f3Smrg } 1587ec681f3Smrg} 1597ec681f3Smrg 1607ec681f3Smrgstatic inline unsigned vk_conv_blend_func(enum VkBlendOp op) 1617ec681f3Smrg{ 1627ec681f3Smrg switch (op) { 1637ec681f3Smrg case VK_BLEND_OP_ADD: 1647ec681f3Smrg return PIPE_BLEND_ADD; 1657ec681f3Smrg case VK_BLEND_OP_SUBTRACT: 1667ec681f3Smrg return PIPE_BLEND_SUBTRACT; 1677ec681f3Smrg case VK_BLEND_OP_REVERSE_SUBTRACT: 1687ec681f3Smrg return PIPE_BLEND_REVERSE_SUBTRACT; 1697ec681f3Smrg case VK_BLEND_OP_MIN: 1707ec681f3Smrg return PIPE_BLEND_MIN; 1717ec681f3Smrg case VK_BLEND_OP_MAX: 1727ec681f3Smrg return PIPE_BLEND_MAX; 1737ec681f3Smrg default: 1747ec681f3Smrg assert(0); 1757ec681f3Smrg return 0; 1767ec681f3Smrg } 1777ec681f3Smrg} 1787ec681f3Smrg 1797ec681f3Smrgstatic inline unsigned vk_conv_logic_op(enum VkLogicOp op) 1807ec681f3Smrg{ 1817ec681f3Smrg switch (op) { 1827ec681f3Smrg case VK_LOGIC_OP_CLEAR: 1837ec681f3Smrg return PIPE_LOGICOP_CLEAR; 1847ec681f3Smrg case VK_LOGIC_OP_NOR: 1857ec681f3Smrg return PIPE_LOGICOP_NOR; 1867ec681f3Smrg case VK_LOGIC_OP_AND_INVERTED: 1877ec681f3Smrg return PIPE_LOGICOP_AND_INVERTED; 1887ec681f3Smrg case VK_LOGIC_OP_COPY_INVERTED: 1897ec681f3Smrg return PIPE_LOGICOP_COPY_INVERTED; 1907ec681f3Smrg case VK_LOGIC_OP_AND_REVERSE: 1917ec681f3Smrg return PIPE_LOGICOP_AND_REVERSE; 1927ec681f3Smrg case VK_LOGIC_OP_INVERT: 1937ec681f3Smrg return PIPE_LOGICOP_INVERT; 1947ec681f3Smrg case VK_LOGIC_OP_XOR: 1957ec681f3Smrg return PIPE_LOGICOP_XOR; 1967ec681f3Smrg case VK_LOGIC_OP_NAND: 1977ec681f3Smrg return PIPE_LOGICOP_NAND; 1987ec681f3Smrg case VK_LOGIC_OP_AND: 1997ec681f3Smrg return PIPE_LOGICOP_AND; 2007ec681f3Smrg case VK_LOGIC_OP_EQUIVALENT: 2017ec681f3Smrg return PIPE_LOGICOP_EQUIV; 2027ec681f3Smrg case VK_LOGIC_OP_NO_OP: 2037ec681f3Smrg return PIPE_LOGICOP_NOOP; 2047ec681f3Smrg case VK_LOGIC_OP_OR_INVERTED: 2057ec681f3Smrg return PIPE_LOGICOP_OR_INVERTED; 2067ec681f3Smrg case VK_LOGIC_OP_COPY: 2077ec681f3Smrg return PIPE_LOGICOP_COPY; 2087ec681f3Smrg case VK_LOGIC_OP_OR_REVERSE: 2097ec681f3Smrg return PIPE_LOGICOP_OR_REVERSE; 2107ec681f3Smrg case VK_LOGIC_OP_OR: 2117ec681f3Smrg return PIPE_LOGICOP_OR; 2127ec681f3Smrg case VK_LOGIC_OP_SET: 2137ec681f3Smrg return PIPE_LOGICOP_SET; 2147ec681f3Smrg default: 2157ec681f3Smrg assert(0); 2167ec681f3Smrg return 0; 2177ec681f3Smrg } 2187ec681f3Smrg} 2197ec681f3Smrg 2207ec681f3Smrgstatic inline enum pipe_swizzle vk_conv_swizzle(VkComponentSwizzle swiz) 2217ec681f3Smrg{ 2227ec681f3Smrg switch (swiz) { 2237ec681f3Smrg case VK_COMPONENT_SWIZZLE_ZERO: 2247ec681f3Smrg return PIPE_SWIZZLE_0; 2257ec681f3Smrg case VK_COMPONENT_SWIZZLE_ONE: 2267ec681f3Smrg return PIPE_SWIZZLE_1; 2277ec681f3Smrg case VK_COMPONENT_SWIZZLE_R: 2287ec681f3Smrg return PIPE_SWIZZLE_X; 2297ec681f3Smrg case VK_COMPONENT_SWIZZLE_G: 2307ec681f3Smrg return PIPE_SWIZZLE_Y; 2317ec681f3Smrg case VK_COMPONENT_SWIZZLE_B: 2327ec681f3Smrg return PIPE_SWIZZLE_Z; 2337ec681f3Smrg case VK_COMPONENT_SWIZZLE_A: 2347ec681f3Smrg return PIPE_SWIZZLE_W; 2357ec681f3Smrg case VK_COMPONENT_SWIZZLE_IDENTITY: 2367ec681f3Smrg default: 2377ec681f3Smrg return PIPE_SWIZZLE_NONE; 2387ec681f3Smrg } 2397ec681f3Smrg} 240