Path: blob/21.2-virgl/src/gallium/drivers/etnaviv/etnaviv_emit.h
4570 views
/*1* Copyright (c) 2012-2015 Etnaviv Project2*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, sub license,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 the11* next paragraph) shall be included in all copies or substantial portions12* of the 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 NON-INFRINGEMENT. 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*22* Authors:23* Wladimir J. van der Laan <[email protected]>24*/2526#ifndef H_ETNA_EMIT27#define H_ETNA_EMIT2829#include "etnaviv_screen.h"30#include "etnaviv_util.h"31#include "hw/cmdstream.xml.h"3233struct etna_context;3435struct etna_coalesce {36uint32_t start;37uint32_t last_reg;38uint32_t last_fixp;39};4041static inline void42etna_emit_load_state(struct etna_cmd_stream *stream, const uint16_t offset,43const uint16_t count, const int fixp)44{45uint32_t v;4647v = VIV_FE_LOAD_STATE_HEADER_OP_LOAD_STATE |48COND(fixp, VIV_FE_LOAD_STATE_HEADER_FIXP) |49VIV_FE_LOAD_STATE_HEADER_OFFSET(offset) |50(VIV_FE_LOAD_STATE_HEADER_COUNT(count) &51VIV_FE_LOAD_STATE_HEADER_COUNT__MASK);5253etna_cmd_stream_emit(stream, v);54}5556static inline void57etna_set_state(struct etna_cmd_stream *stream, uint32_t address, uint32_t value)58{59etna_cmd_stream_reserve(stream, 2);60etna_emit_load_state(stream, address >> 2, 1, 0);61etna_cmd_stream_emit(stream, value);62}6364static inline void65etna_set_state_reloc(struct etna_cmd_stream *stream, uint32_t address,66const struct etna_reloc *reloc)67{68etna_cmd_stream_reserve(stream, 2);69etna_emit_load_state(stream, address >> 2, 1, 0);70etna_cmd_stream_reloc(stream, reloc);71}7273static inline void74etna_set_state_multi(struct etna_cmd_stream *stream, uint32_t base,75uint32_t num, const uint32_t *values)76{77if (num == 0)78return;7980etna_cmd_stream_reserve(stream, 1 + num + 1); /* 1 extra for potential alignment */81etna_emit_load_state(stream, base >> 2, num, 0);8283for (uint32_t i = 0; i < num; i++)84etna_cmd_stream_emit(stream, values[i]);8586/* add potential padding */87if ((num % 2) == 0)88etna_cmd_stream_emit(stream, 0);89}9091void92etna_stall(struct etna_cmd_stream *stream, uint32_t from, uint32_t to);9394static inline void95etna_draw_primitives(struct etna_cmd_stream *stream, uint32_t primitive_type,96uint32_t start, uint32_t count)97{98etna_cmd_stream_reserve(stream, 4);99100etna_cmd_stream_emit(stream, VIV_FE_DRAW_PRIMITIVES_HEADER_OP_DRAW_PRIMITIVES);101etna_cmd_stream_emit(stream, primitive_type);102etna_cmd_stream_emit(stream, start);103etna_cmd_stream_emit(stream, count);104}105106static inline void107etna_draw_indexed_primitives(struct etna_cmd_stream *stream,108uint32_t primitive_type, uint32_t start,109uint32_t count, uint32_t offset)110{111etna_cmd_stream_reserve(stream, 5 + 1);112113etna_cmd_stream_emit(stream, VIV_FE_DRAW_INDEXED_PRIMITIVES_HEADER_OP_DRAW_INDEXED_PRIMITIVES);114etna_cmd_stream_emit(stream, primitive_type);115etna_cmd_stream_emit(stream, start);116etna_cmd_stream_emit(stream, count);117etna_cmd_stream_emit(stream, offset);118etna_cmd_stream_emit(stream, 0);119}120121/* important: this takes a vertex count, not a primitive count */122static inline void123etna_draw_instanced(struct etna_cmd_stream *stream,124uint32_t indexed, uint32_t primitive_type,125uint32_t instance_count,126uint32_t vertex_count, uint32_t offset)127{128etna_cmd_stream_reserve(stream, 3 + 1);129etna_cmd_stream_emit(stream,130VIV_FE_DRAW_INSTANCED_HEADER_OP_DRAW_INSTANCED |131COND(indexed, VIV_FE_DRAW_INSTANCED_HEADER_INDEXED) |132VIV_FE_DRAW_INSTANCED_HEADER_TYPE(primitive_type) |133VIV_FE_DRAW_INSTANCED_HEADER_INSTANCE_COUNT_LO(instance_count & 0xffff));134etna_cmd_stream_emit(stream,135VIV_FE_DRAW_INSTANCED_COUNT_INSTANCE_COUNT_HI(instance_count >> 16) |136VIV_FE_DRAW_INSTANCED_COUNT_VERTEX_COUNT(vertex_count));137etna_cmd_stream_emit(stream,138VIV_FE_DRAW_INSTANCED_START_INDEX(offset));139etna_cmd_stream_emit(stream, 0);140}141142static inline void143etna_coalesce_start(struct etna_cmd_stream *stream,144struct etna_coalesce *coalesce)145{146coalesce->start = etna_cmd_stream_offset(stream);147coalesce->last_reg = 0;148coalesce->last_fixp = 0;149}150151static inline void152etna_coalesce_end(struct etna_cmd_stream *stream,153struct etna_coalesce *coalesce)154{155uint32_t end = etna_cmd_stream_offset(stream);156uint32_t size = end - coalesce->start;157158if (size) {159uint32_t offset = coalesce->start - 1;160uint32_t value = etna_cmd_stream_get(stream, offset);161162value |= VIV_FE_LOAD_STATE_HEADER_COUNT(size);163etna_cmd_stream_set(stream, offset, value);164}165166/* append needed padding */167if (end % 2 == 1)168etna_cmd_stream_emit(stream, 0xdeadbeef);169}170171static inline void172check_coalsence(struct etna_cmd_stream *stream, struct etna_coalesce *coalesce,173uint32_t reg, uint32_t fixp)174{175if (coalesce->last_reg != 0) {176if (((coalesce->last_reg + 4) != reg) || (coalesce->last_fixp != fixp)) {177etna_coalesce_end(stream, coalesce);178etna_emit_load_state(stream, reg >> 2, 0, fixp);179coalesce->start = etna_cmd_stream_offset(stream);180}181} else {182etna_emit_load_state(stream, reg >> 2, 0, fixp);183coalesce->start = etna_cmd_stream_offset(stream);184}185186coalesce->last_reg = reg;187coalesce->last_fixp = fixp;188}189190static inline void191etna_coalsence_emit(struct etna_cmd_stream *stream,192struct etna_coalesce *coalesce, uint32_t reg,193uint32_t value)194{195check_coalsence(stream, coalesce, reg, 0);196etna_cmd_stream_emit(stream, value);197}198199static inline void200etna_coalsence_emit_fixp(struct etna_cmd_stream *stream,201struct etna_coalesce *coalesce, uint32_t reg,202uint32_t value)203{204check_coalsence(stream, coalesce, reg, 1);205etna_cmd_stream_emit(stream, value);206}207208static inline void209etna_coalsence_emit_reloc(struct etna_cmd_stream *stream,210struct etna_coalesce *coalesce, uint32_t reg,211const struct etna_reloc *r)212{213if (r->bo) {214check_coalsence(stream, coalesce, reg, 0);215etna_cmd_stream_reloc(stream, r);216}217}218219void220etna_emit_state(struct etna_context *ctx);221222#endif223224225