Path: blob/21.2-virgl/src/gallium/drivers/radeonsi/si_pm4.c
4570 views
/*1* Copyright 2012 Advanced Micro Devices, Inc.2* All Rights Reserved.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* on the rights to use, copy, modify, merge, publish, distribute, sub8* license, and/or sell copies of the Software, and to permit persons to whom9* the 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 NON-INFRINGEMENT. IN NO EVENT SHALL18* THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,19* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR20* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE21* USE OR OTHER DEALINGS IN THE SOFTWARE.22*/2324#include "si_pipe.h"25#include "si_build_pm4.h"26#include "sid.h"27#include "util/u_memory.h"2829static void si_pm4_cmd_begin(struct si_pm4_state *state, unsigned opcode)30{31assert(state->ndw < SI_PM4_MAX_DW);32state->last_opcode = opcode;33state->last_pm4 = state->ndw++;34}3536void si_pm4_cmd_add(struct si_pm4_state *state, uint32_t dw)37{38assert(state->ndw < SI_PM4_MAX_DW);39state->pm4[state->ndw++] = dw;40state->last_opcode = -1;41}4243static void si_pm4_cmd_end(struct si_pm4_state *state, bool predicate)44{45unsigned count;46count = state->ndw - state->last_pm4 - 2;47state->pm4[state->last_pm4] = PKT3(state->last_opcode, count, predicate);48}4950void si_pm4_set_reg(struct si_pm4_state *state, unsigned reg, uint32_t val)51{52unsigned opcode;5354SI_CHECK_SHADOWED_REGS(reg, 1);5556if (reg >= SI_CONFIG_REG_OFFSET && reg < SI_CONFIG_REG_END) {57opcode = PKT3_SET_CONFIG_REG;58reg -= SI_CONFIG_REG_OFFSET;5960} else if (reg >= SI_SH_REG_OFFSET && reg < SI_SH_REG_END) {61opcode = PKT3_SET_SH_REG;62reg -= SI_SH_REG_OFFSET;6364} else if (reg >= SI_CONTEXT_REG_OFFSET && reg < SI_CONTEXT_REG_END) {65opcode = PKT3_SET_CONTEXT_REG;66reg -= SI_CONTEXT_REG_OFFSET;6768} else if (reg >= CIK_UCONFIG_REG_OFFSET && reg < CIK_UCONFIG_REG_END) {69opcode = PKT3_SET_UCONFIG_REG;70reg -= CIK_UCONFIG_REG_OFFSET;7172} else {73PRINT_ERR("Invalid register offset %08x!\n", reg);74return;75}7677reg >>= 2;7879assert(state->ndw + 2 <= SI_PM4_MAX_DW);8081if (opcode != state->last_opcode || reg != (state->last_reg + 1)) {82si_pm4_cmd_begin(state, opcode);83state->pm4[state->ndw++] = reg;84}8586state->last_reg = reg;87state->pm4[state->ndw++] = val;88si_pm4_cmd_end(state, false);89}9091void si_pm4_clear_state(struct si_pm4_state *state)92{93state->ndw = 0;94}9596void si_pm4_free_state(struct si_context *sctx, struct si_pm4_state *state, unsigned idx)97{98if (!state)99return;100101if (idx != ~0) {102if (sctx->emitted.array[idx] == state)103sctx->emitted.array[idx] = NULL;104105if (sctx->queued.array[idx] == state) {106sctx->queued.array[idx] = NULL;107sctx->dirty_states &= ~BITFIELD_BIT(idx);108}109}110111si_pm4_clear_state(state);112FREE(state);113}114115void si_pm4_emit(struct si_context *sctx, struct si_pm4_state *state)116{117struct radeon_cmdbuf *cs = &sctx->gfx_cs;118119if (state->shader) {120radeon_add_to_buffer_list(sctx, &sctx->gfx_cs, state->shader->bo,121RADEON_USAGE_READ, RADEON_PRIO_SHADER_BINARY);122}123124radeon_begin(cs);125radeon_emit_array(cs, state->pm4, state->ndw);126radeon_end();127128if (state->atom.emit)129state->atom.emit(sctx);130}131132void si_pm4_reset_emitted(struct si_context *sctx, bool first_cs)133{134if (!first_cs && sctx->shadowed_regs) {135/* Only dirty states that contain buffers, so that they are136* added to the buffer list on the next draw call.137*/138for (unsigned i = 0; i < SI_NUM_STATES; i++) {139struct si_pm4_state *state = sctx->emitted.array[i];140141if (state && state->shader) {142sctx->emitted.array[i] = NULL;143sctx->dirty_states |= 1 << i;144}145}146return;147}148149memset(&sctx->emitted, 0, sizeof(sctx->emitted));150151for (unsigned i = 0; i < SI_NUM_STATES; i++) {152if (sctx->queued.array[i])153sctx->dirty_states |= BITFIELD_BIT(i);154}155}156157158