1/*
2 * Copyright © 2022 Imagination Technologies Ltd.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * 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 THE
21 * SOFTWARE.
22 */
23
24#ifndef ROGUE_SHADER_H
25#define ROGUE_SHADER_H
26
27#include <stdbool.h>
28#include <stddef.h>
29
30#include "compiler/shader_enums.h"
31#include "rogue_instr.h"
32#include "rogue_operand.h"
33#include "rogue_util.h"
34#include "util/list.h"
35#include "util/macros.h"
36
37struct rogue_build_ctx;
38struct rogue_ra;
39
40/**
41 * \brief Shader description.
42 */
43struct rogue_shader {
44   gl_shader_stage stage; /** Shader stage. */
45
46   struct list_head instr_list; /** Instructions linked list. */
47
48   struct rogue_build_ctx *ctx;
49   struct rogue_ra *ra;
50
51   bool drc_used[ROGUE_NUM_DRCS];
52};
53
54/* Shader instruction list iterators and helpers. */
55#define foreach_instr(__instr, __list) \
56   list_for_each_entry (struct rogue_instr, __instr, __list, node)
57#define foreach_instr_rev(__instr, __list) \
58   list_for_each_entry_rev (struct rogue_instr, __instr, __list, node)
59#define foreach_instr_safe(__instr, __list) \
60   list_for_each_entry_safe (struct rogue_instr, __instr, __list, node)
61
62#define instr_first_entry(__list) \
63   list_first_entry(__list, struct rogue_instr, node)
64#define instr_last_entry(__list) \
65   list_last_entry(__list, struct rogue_instr, node)
66
67size_t rogue_shader_instr_count_type(const struct rogue_shader *shader,
68                                     enum rogue_opcode opcode);
69
70PUBLIC
71struct rogue_shader *rogue_shader_create(struct rogue_build_ctx *ctx,
72                                         gl_shader_stage stage);
73
74PUBLIC
75struct rogue_instr *rogue_shader_insert(struct rogue_shader *shader,
76                                        enum rogue_opcode opcode);
77
78size_t rogue_acquire_drc(struct rogue_shader *shader);
79void rogue_release_drc(struct rogue_shader *shader, size_t drc);
80
81#endif /* ROGUE_SHADER_H */
82