Path: blob/21.2-virgl/src/gallium/drivers/freedreno/a6xx/fd6_texture.h
4574 views
/*1* Copyright (C) 2016 Rob Clark <[email protected]>2* Copyright © 2018 Google, Inc.3*4* Permission is hereby granted, free of charge, to any person obtaining a5* copy of this software and associated documentation files (the "Software"),6* to deal in the Software without restriction, including without limitation7* the rights to use, copy, modify, merge, publish, distribute, sublicense,8* and/or sell copies of the Software, and to permit persons to whom the9* Software is furnished to do so, subject to the following conditions:10*11* The above copyright notice and this permission notice (including the next12* paragraph) shall be included in all copies or substantial portions of the13* Software.14*15* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR16* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,17* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL18* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER19* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,20* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE21* SOFTWARE.22*23* Authors:24* Rob Clark <[email protected]>25*/2627#ifndef FD6_TEXTURE_H_28#define FD6_TEXTURE_H_2930#include "pipe/p_context.h"3132#include "freedreno_resource.h"33#include "freedreno_texture.h"3435#include "fd6_context.h"36#include "fd6_format.h"3738struct fd6_sampler_stateobj {39struct pipe_sampler_state base;40uint32_t texsamp0, texsamp1, texsamp2, texsamp3;41bool needs_border;42uint16_t seqno;43};4445static inline struct fd6_sampler_stateobj *46fd6_sampler_stateobj(struct pipe_sampler_state *samp)47{48return (struct fd6_sampler_stateobj *)samp;49}5051struct fd6_pipe_sampler_view {52struct pipe_sampler_view base;53uint32_t texconst0, texconst1, texconst2, texconst3, texconst5;54uint32_t texconst6, texconst7, texconst8, texconst9, texconst10, texconst11;55uint32_t offset1, offset2;56struct fd_resource *ptr1, *ptr2;57uint16_t seqno;5859/* For detecting when a resource has transitioned from UBWC compressed60* to uncompressed, which means the sampler state needs to be updated61*/62uint16_t rsc_seqno;6364bool needs_validate;65};6667static inline struct fd6_pipe_sampler_view *68fd6_pipe_sampler_view(struct pipe_sampler_view *pview)69{70return (struct fd6_pipe_sampler_view *)pview;71}7273void fd6_sampler_view_update(struct fd_context *ctx,74struct fd6_pipe_sampler_view *so) assert_dt;7576void fd6_texture_init(struct pipe_context *pctx);77void fd6_texture_fini(struct pipe_context *pctx);7879static inline enum a6xx_tex_type80fd6_tex_type(unsigned target)81{82switch (target) {83default:84assert(0);85case PIPE_BUFFER:86case PIPE_TEXTURE_1D:87case PIPE_TEXTURE_1D_ARRAY:88return A6XX_TEX_1D;89case PIPE_TEXTURE_RECT:90case PIPE_TEXTURE_2D:91case PIPE_TEXTURE_2D_ARRAY:92return A6XX_TEX_2D;93case PIPE_TEXTURE_3D:94return A6XX_TEX_3D;95case PIPE_TEXTURE_CUBE:96case PIPE_TEXTURE_CUBE_ARRAY:97return A6XX_TEX_CUBE;98}99}100101static inline unsigned102fd6_border_color_offset(struct fd_context *ctx, enum pipe_shader_type type,103struct fd_texture_stateobj *tex) assert_dt104{105/* Currently we put the FS border-color state after VS. Possibly106* we could swap the order.107*108* This will need update for HS/DS/GS109*/110if (type != PIPE_SHADER_FRAGMENT)111return 0;112113unsigned needs_border = false;114115for (unsigned i = 0; i < tex->num_samplers; i++) {116if (!tex->samplers[i])117continue;118119struct fd6_sampler_stateobj *sampler =120fd6_sampler_stateobj(tex->samplers[i]);121122needs_border |= sampler->needs_border;123}124125if (!needs_border)126return 0;127128return ctx->tex[PIPE_SHADER_VERTEX].num_samplers;129}130131/*132* Texture stateobj:133*134* The sampler and sampler-view state is mapped to a single hardware135* stateobj which can be emit'd as a pointer in a CP_SET_DRAW_STATE136* packet, to avoid the overhead of re-generating the entire cmdstream137* when application toggles thru multiple different texture states.138*/139140struct fd6_texture_key {141struct {142/* We need to track the seqno of the rsc as well as of the143* sampler view, because resource shadowing/etc can result144* that the underlying bo changes (which means the previous145* state was no longer valid.146*/147uint16_t rsc_seqno;148uint16_t seqno;149} view[16];150struct {151uint16_t seqno;152} samp[16];153uint8_t type;154uint8_t bcolor_offset;155};156157struct fd6_texture_state {158struct pipe_reference reference;159struct fd6_texture_key key;160struct fd_ringbuffer *stateobj;161bool needs_border;162};163164struct fd6_texture_state *165fd6_texture_state(struct fd_context *ctx, enum pipe_shader_type type,166struct fd_texture_stateobj *tex) assert_dt;167168/* not called directly: */169void __fd6_texture_state_describe(char *buf,170const struct fd6_texture_state *tex);171void __fd6_texture_state_destroy(struct fd6_texture_state *tex);172173static inline void174fd6_texture_state_reference(struct fd6_texture_state **ptr,175struct fd6_texture_state *tex)176{177struct fd6_texture_state *old_tex = *ptr;178179if (pipe_reference_described(180&(*ptr)->reference, &tex->reference,181(debug_reference_descriptor)__fd6_texture_state_describe))182__fd6_texture_state_destroy(old_tex);183184*ptr = tex;185}186187#endif /* FD6_TEXTURE_H_ */188189190