Path: blob/21.2-virgl/src/panfrost/vulkan/panvk_varyings.h
4560 views
/*1* Copyright (C) 2021 Collabora Ltd.2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER20* DEALINGS IN THE SOFTWARE.21*/2223#ifndef PANVK_VARYINGS_H24#define PANVK_VARYINGS_H2526#include "util/bitset.h"27#include "util/format/u_format.h"2829#include "compiler/shader_enums.h"30#include "midgard_pack.h"31#include "panfrost-job.h"3233struct pan_pool;34struct panvk_device;3536enum panvk_varying_buf_id {37PANVK_VARY_BUF_GENERAL,38PANVK_VARY_BUF_POSITION,39PANVK_VARY_BUF_PSIZ,40PANVK_VARY_BUF_PNTCOORD,41PANVK_VARY_BUF_FRAGCOORD,4243/* Keep last */44PANVK_VARY_BUF_MAX,45};4647struct panvk_varying {48unsigned buf;49unsigned offset;50enum pipe_format format;51};5253struct panvk_varying_buf {54mali_ptr address;55void *cpu;56unsigned stride;57unsigned size;58};5960struct panvk_varyings_info {61struct panvk_varying varying[VARYING_SLOT_MAX];62BITSET_DECLARE(active, VARYING_SLOT_MAX);63struct panvk_varying_buf buf[VARYING_SLOT_MAX];64struct {65unsigned count;66gl_varying_slot loc[VARYING_SLOT_MAX];67} stage[MESA_SHADER_STAGES];68unsigned buf_mask;69};7071void72panvk_varyings_alloc(struct panvk_varyings_info *varyings,73struct pan_pool *varying_mem_pool,74unsigned vertex_count);7576unsigned77panvk_varyings_buf_count(const struct panvk_device *dev,78struct panvk_varyings_info *varyings);7980static inline unsigned81panvk_varying_buf_index(const struct panvk_varyings_info *varyings,82enum panvk_varying_buf_id b)83{84return util_bitcount(varyings->buf_mask & BITFIELD_MASK(b));85}8687static inline enum panvk_varying_buf_id88panvk_varying_buf_id(bool fs, gl_varying_slot loc)89{90switch (loc) {91case VARYING_SLOT_POS:92return fs ? PANVK_VARY_BUF_FRAGCOORD : PANVK_VARY_BUF_POSITION;93case VARYING_SLOT_PSIZ:94return PANVK_VARY_BUF_PSIZ;95case VARYING_SLOT_PNTC:96return PANVK_VARY_BUF_PNTCOORD;97default:98return PANVK_VARY_BUF_GENERAL;99}100}101102static inline bool103panvk_varying_is_builtin(gl_shader_stage stage, gl_varying_slot loc)104{105bool fs = stage == MESA_SHADER_FRAGMENT;106107switch (loc) {108case VARYING_SLOT_POS:109case VARYING_SLOT_PNTC:110return fs;111default:112return false;113}114}115116static inline enum mali_attribute_special117panvk_varying_special_buf_id(enum panvk_varying_buf_id buf_id)118{119switch (buf_id) {120case PANVK_VARY_BUF_PNTCOORD:121return MALI_ATTRIBUTE_SPECIAL_POINT_COORD;122case PANVK_VARY_BUF_FRAGCOORD:123return MALI_ATTRIBUTE_SPECIAL_FRAG_COORD;124default:125return 0;126}127}128129static inline unsigned130panvk_varying_size(const struct panvk_varyings_info *varyings,131gl_varying_slot loc)132{133switch (loc) {134case VARYING_SLOT_POS:135return sizeof(float) * 4;136case VARYING_SLOT_PSIZ:137return sizeof(uint16_t);138default:139return util_format_get_blocksize(varyings->varying[loc].format);140}141}142143#endif144145146