Path: blob/21.2-virgl/src/panfrost/bifrost/bi_scoreboard.c
4564 views
/*1* Copyright (C) 2020 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, ARISING FROM,19* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE20* SOFTWARE.21*22* Authors (Collabora):23* Alyssa Rosenzweig <[email protected]>24*/2526#include "compiler.h"2728/* Assign dependency slots to each clause and calculate dependencies, This pass29* must be run after scheduling.30*31* 1. A clause that does not produce a message must use the sentinel slot #032* 2a. A clause that depends on the results of a previous message-passing33* instruction must depend on that instruction's dependency slot, unless all34* reaching code paths already depended on it.35* 2b. More generally, any dependencies must be encoded. This includes36* Write-After-Write and Write-After-Read hazards with LOAD/STORE to memory.37* 3. The shader must wait on slot #6 before running BLEND, ATEST38* 4. The shader must wait on slot #7 before running BLEND, ST_TILE39* 5. ATEST, ZS_EMIT must be issued with slot #040* 6. BARRIER must be issued with slot #741* 7. Only slots #0 through #5 may be used for clauses not otherwise specified.42* 8. If a clause writes to a read staging register of an unresolved43* dependency, it must set a staging barrier.44*45* Note it _is_ legal to reuse slots for multiple message passing instructions46* with overlapping liveness, albeit with a slight performance penalty. As such47* the problem is significantly easier than register allocation, rather than48* spilling we may simply reuse slots. (TODO: does this have an optimal49* linear-time solution).50*51* Within these constraints we are free to assign slots as we like. This pass52* attempts to minimize stalls (TODO).53*/5455#define BI_NUM_GENERAL_SLOTS 65657/* A model for the state of the scoreboard */5859struct bi_scoreboard_state {60/* TODO: what do we track here for a heuristic? */61};6263/* Given a scoreboard model, choose a slot for a clause wrapping a given64* message passing instruction. No side effects. */6566static unsigned67bi_choose_scoreboard_slot(struct bi_scoreboard_state *st, bi_instr *message)68{69/* A clause that does not produce a message must use slot #0 */70if (!message)71return 0;7273switch (message->op) {74/* ATEST, ZS_EMIT must be issued with slot #0 */75case BI_OPCODE_ATEST:76case BI_OPCODE_ZS_EMIT:77return 0;7879/* BARRIER must be issued with slot #7 */80case BI_OPCODE_BARRIER:81return 7;8283default:84break;85}8687/* TODO: Use a heuristic */88return 0;89}9091void92bi_assign_scoreboard(bi_context *ctx)93{94struct bi_scoreboard_state st = {};9596/* Assign slots */97bi_foreach_block(ctx, _block) {98bi_block *block = (bi_block *) _block;99100bi_foreach_clause_in_block(block, clause) {101unsigned slot = bi_choose_scoreboard_slot(&st, clause->message);102clause->scoreboard_id = slot;103104bi_clause *next = bi_next_clause(ctx, _block, clause);105if (next)106next->dependencies |= (1 << slot);107}108}109}110111112