1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Copyright © 2014 Connor Abbott
3bf215546Sopenharmony_ci *
4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation
7bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
9bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
10bf215546Sopenharmony_ci *
11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next
12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the
13bf215546Sopenharmony_ci * Software.
14bf215546Sopenharmony_ci *
15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20bf215546Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21bf215546Sopenharmony_ci * IN THE SOFTWARE.
22bf215546Sopenharmony_ci */
23bf215546Sopenharmony_ci
24bf215546Sopenharmony_ci#ifndef NIR_SCHEDULE_H
25bf215546Sopenharmony_ci#define NIR_SCHEDULE_H
26bf215546Sopenharmony_ci
27bf215546Sopenharmony_ci#include "nir.h"
28bf215546Sopenharmony_ci
29bf215546Sopenharmony_ci#ifdef __cplusplus
30bf215546Sopenharmony_ciextern "C" {
31bf215546Sopenharmony_ci#endif
32bf215546Sopenharmony_ci
33bf215546Sopenharmony_ci/**
34bf215546Sopenharmony_ci * Struct filled in by the intrinsic_cb callback of nir_schedule_options to
35bf215546Sopenharmony_ci * specify a backend-specific dependency on an intrinsic.
36bf215546Sopenharmony_ci */
37bf215546Sopenharmony_citypedef struct nir_schedule_dependency {
38bf215546Sopenharmony_ci   /* Which class of dependency this is. The meanings of the classes are
39bf215546Sopenharmony_ci    * specific to the backend. This must be less than
40bf215546Sopenharmony_ci    * NIR_SCHEDULE_N_DEPENDENCY_CLASSES.
41bf215546Sopenharmony_ci    */
42bf215546Sopenharmony_ci   int klass;
43bf215546Sopenharmony_ci   /* The type of dependency */
44bf215546Sopenharmony_ci   enum {
45bf215546Sopenharmony_ci      NIR_SCHEDULE_READ_DEPENDENCY,
46bf215546Sopenharmony_ci      NIR_SCHEDULE_WRITE_DEPENDENCY,
47bf215546Sopenharmony_ci   } type;
48bf215546Sopenharmony_ci} nir_schedule_dependency;
49bf215546Sopenharmony_ci
50bf215546Sopenharmony_citypedef struct nir_schedule_options {
51bf215546Sopenharmony_ci   /* On some hardware with some stages the inputs and outputs to the shader
52bf215546Sopenharmony_ci    * share the same memory. In that case the scheduler needs to ensure that
53bf215546Sopenharmony_ci    * all output writes are scheduled after all of the input writes to avoid
54bf215546Sopenharmony_ci    * overwriting them. This is a bitmask of stages that need that.
55bf215546Sopenharmony_ci    */
56bf215546Sopenharmony_ci   unsigned stages_with_shared_io_memory;
57bf215546Sopenharmony_ci   /* The approximate amount of register pressure at which point the scheduler
58bf215546Sopenharmony_ci    * will try to reduce register usage.
59bf215546Sopenharmony_ci    */
60bf215546Sopenharmony_ci   int threshold;
61bf215546Sopenharmony_ci   /* If set, instead of trying to optimise parallelism, the scheduler will try
62bf215546Sopenharmony_ci    * to always minimise register pressure. This can be used as a fallback when
63bf215546Sopenharmony_ci    * register allocation fails so that it can at least try to generate a
64bf215546Sopenharmony_ci    * working shader even if it’s inefficient.
65bf215546Sopenharmony_ci    */
66bf215546Sopenharmony_ci   bool fallback;
67bf215546Sopenharmony_ci   /* Callback used to add custom dependencies on intrinsics. If it returns
68bf215546Sopenharmony_ci    * true then a dependency should be added and dep is filled in to describe
69bf215546Sopenharmony_ci    * it.
70bf215546Sopenharmony_ci    */
71bf215546Sopenharmony_ci   bool (* intrinsic_cb)(nir_intrinsic_instr *intr,
72bf215546Sopenharmony_ci                         nir_schedule_dependency *dep,
73bf215546Sopenharmony_ci                         void *user_data);
74bf215546Sopenharmony_ci
75bf215546Sopenharmony_ci   /* Data to pass to the intrinsic callback */
76bf215546Sopenharmony_ci   void *intrinsic_cb_data;
77bf215546Sopenharmony_ci
78bf215546Sopenharmony_ci   /* Callback used to specify instruction delays */
79bf215546Sopenharmony_ci   unsigned (* instr_delay_cb)(nir_instr *instr, void *user_data);
80bf215546Sopenharmony_ci
81bf215546Sopenharmony_ci   /* Data to pass to the instruction delay callback */
82bf215546Sopenharmony_ci   void *instr_delay_cb_data;
83bf215546Sopenharmony_ci
84bf215546Sopenharmony_ci} nir_schedule_options;
85bf215546Sopenharmony_ci
86bf215546Sopenharmony_civoid nir_schedule(nir_shader *shader, const nir_schedule_options *options);
87bf215546Sopenharmony_ci
88bf215546Sopenharmony_ci#ifdef __cplusplus
89bf215546Sopenharmony_ci} /* extern "C" */
90bf215546Sopenharmony_ci#endif
91bf215546Sopenharmony_ci
92bf215546Sopenharmony_ci#endif /* NIR_SCHEDULE_H */
93