17ec681f3Smrg/*
27ec681f3Smrg * Copyright © 2014 Connor Abbott
37ec681f3Smrg *
47ec681f3Smrg * Permission is hereby granted, free of charge, to any person obtaining a
57ec681f3Smrg * copy of this software and associated documentation files (the "Software"),
67ec681f3Smrg * to deal in the Software without restriction, including without limitation
77ec681f3Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
87ec681f3Smrg * and/or sell copies of the Software, and to permit persons to whom the
97ec681f3Smrg * Software is furnished to do so, subject to the following conditions:
107ec681f3Smrg *
117ec681f3Smrg * The above copyright notice and this permission notice (including the next
127ec681f3Smrg * paragraph) shall be included in all copies or substantial portions of the
137ec681f3Smrg * Software.
147ec681f3Smrg *
157ec681f3Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
167ec681f3Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
177ec681f3Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
187ec681f3Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
197ec681f3Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
207ec681f3Smrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
217ec681f3Smrg * IN THE SOFTWARE.
227ec681f3Smrg */
237ec681f3Smrg
247ec681f3Smrg#ifndef NIR_SCHEDULE_H
257ec681f3Smrg#define NIR_SCHEDULE_H
267ec681f3Smrg
277ec681f3Smrg#include "nir.h"
287ec681f3Smrg
297ec681f3Smrg#ifdef __cplusplus
307ec681f3Smrgextern "C" {
317ec681f3Smrg#endif
327ec681f3Smrg
337ec681f3Smrg/**
347ec681f3Smrg * Struct filled in by the intrinsic_cb callback of nir_schedule_options to
357ec681f3Smrg * specify a backend-specific dependency on an intrinsic.
367ec681f3Smrg */
377ec681f3Smrgtypedef struct nir_schedule_dependency {
387ec681f3Smrg   /* Which class of dependency this is. The meanings of the classes are
397ec681f3Smrg    * specific to the backend. This must be less than
407ec681f3Smrg    * NIR_SCHEDULE_N_DEPENDENCY_CLASSES.
417ec681f3Smrg    */
427ec681f3Smrg   int klass;
437ec681f3Smrg   /* The type of dependency */
447ec681f3Smrg   enum {
457ec681f3Smrg      NIR_SCHEDULE_READ_DEPENDENCY,
467ec681f3Smrg      NIR_SCHEDULE_WRITE_DEPENDENCY,
477ec681f3Smrg   } type;
487ec681f3Smrg} nir_schedule_dependency;
497ec681f3Smrg
507ec681f3Smrgtypedef struct nir_schedule_options {
517ec681f3Smrg   /* On some hardware with some stages the inputs and outputs to the shader
527ec681f3Smrg    * share the same memory. In that case the scheduler needs to ensure that
537ec681f3Smrg    * all output writes are scheduled after all of the input writes to avoid
547ec681f3Smrg    * overwriting them. This is a bitmask of stages that need that.
557ec681f3Smrg    */
567ec681f3Smrg   unsigned stages_with_shared_io_memory;
577ec681f3Smrg   /* The approximate amount of register pressure at which point the scheduler
587ec681f3Smrg    * will try to reduce register usage.
597ec681f3Smrg    */
607ec681f3Smrg   int threshold;
617ec681f3Smrg   /* If set, instead of trying to optimise parallelism, the scheduler will try
627ec681f3Smrg    * to always minimise register pressure. This can be used as a fallback when
637ec681f3Smrg    * register allocation fails so that it can at least try to generate a
647ec681f3Smrg    * working shader even if it’s inefficient.
657ec681f3Smrg    */
667ec681f3Smrg   bool fallback;
677ec681f3Smrg   /* Callback used to add custom dependencies on intrinsics. If it returns
687ec681f3Smrg    * true then a dependency should be added and dep is filled in to describe
697ec681f3Smrg    * it.
707ec681f3Smrg    */
717ec681f3Smrg   bool (* intrinsic_cb)(nir_intrinsic_instr *intr,
727ec681f3Smrg                         nir_schedule_dependency *dep,
737ec681f3Smrg                         void *user_data);
747ec681f3Smrg   /* Data to pass to the callback */
757ec681f3Smrg   void *intrinsic_cb_data;
767ec681f3Smrg} nir_schedule_options;
777ec681f3Smrg
787ec681f3Smrgvoid nir_schedule(nir_shader *shader, const nir_schedule_options *options);
797ec681f3Smrg
807ec681f3Smrg#ifdef __cplusplus
817ec681f3Smrg} /* extern "C" */
827ec681f3Smrg#endif
837ec681f3Smrg
847ec681f3Smrg#endif /* NIR_SCHEDULE_H */
85