19f464c52Smaya/*
29f464c52Smaya * Copyright (C) 2018 Jonathan Marek <jonathan@marek.ca>
39f464c52Smaya *
49f464c52Smaya * Permission is hereby granted, free of charge, to any person obtaining a
59f464c52Smaya * copy of this software and associated documentation files (the "Software"),
69f464c52Smaya * to deal in the Software without restriction, including without limitation
79f464c52Smaya * the rights to use, copy, modify, merge, publish, distribute, sublicense,
89f464c52Smaya * and/or sell copies of the Software, and to permit persons to whom the
99f464c52Smaya * Software is furnished to do so, subject to the following conditions:
109f464c52Smaya *
119f464c52Smaya * The above copyright notice and this permission notice (including the next
129f464c52Smaya * paragraph) shall be included in all copies or substantial portions of the
139f464c52Smaya * Software.
149f464c52Smaya *
159f464c52Smaya * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
169f464c52Smaya * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
179f464c52Smaya * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
189f464c52Smaya * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
199f464c52Smaya * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
209f464c52Smaya * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
219f464c52Smaya * SOFTWARE.
229f464c52Smaya *
239f464c52Smaya * Authors:
249f464c52Smaya *    Jonathan Marek <jonathan@marek.ca>
259f464c52Smaya */
269f464c52Smaya
279f464c52Smaya#ifndef IR2_H_
289f464c52Smaya#define IR2_H_
299f464c52Smaya
309f464c52Smaya#include "compiler/nir/nir.h"
319f464c52Smaya#include "pipe/p_context.h"
329f464c52Smaya
339f464c52Smayastruct ir2_fetch_info {
347ec681f3Smrg   /* dword offset of the fetch instruction */
357ec681f3Smrg   uint16_t offset;
367ec681f3Smrg   union {
377ec681f3Smrg      /* swizzle to merge with tgsi swizzle */
387ec681f3Smrg      struct {
397ec681f3Smrg         uint16_t dst_swiz;
407ec681f3Smrg      } vtx;
417ec681f3Smrg      /* sampler id to patch const_idx */
427ec681f3Smrg      struct {
437ec681f3Smrg         uint16_t samp_id;
447ec681f3Smrg         uint8_t src_swiz;
457ec681f3Smrg      } tex;
467ec681f3Smrg   };
479f464c52Smaya};
489f464c52Smaya
499f464c52Smayastruct ir2_shader_info {
507ec681f3Smrg   /* compiler shader */
517ec681f3Smrg   uint32_t *dwords;
529f464c52Smaya
537ec681f3Smrg   /* size of the compiled shader in dwords */
547ec681f3Smrg   uint16_t sizedwords;
559f464c52Smaya
567ec681f3Smrg   /* highest GPR # used by shader */
577ec681f3Smrg   int8_t max_reg;
589f464c52Smaya
597ec681f3Smrg   /* offset in dwords of first MEMORY export CF (for a20x hw binning) */
607ec681f3Smrg   int16_t mem_export_ptr;
619f464c52Smaya
627ec681f3Smrg   /* fetch instruction info for patching */
637ec681f3Smrg   uint16_t num_fetch_instrs;
647ec681f3Smrg   struct ir2_fetch_info fetch_info[64];
659f464c52Smaya};
669f464c52Smaya
679f464c52Smayastruct ir2_frag_linkage {
687ec681f3Smrg   unsigned inputs_count;
697ec681f3Smrg   struct {
707ec681f3Smrg      uint8_t slot;
717ec681f3Smrg      uint8_t ncomp;
727ec681f3Smrg   } inputs[16];
737ec681f3Smrg
747ec681f3Smrg   /* driver_location of fragcoord.zw, -1 if not used */
757ec681f3Smrg   int fragcoord;
769f464c52Smaya};
779f464c52Smaya
789f464c52Smayastruct ir2_shader_variant {
797ec681f3Smrg   struct ir2_shader_info info;
807ec681f3Smrg   struct ir2_frag_linkage f;
819f464c52Smaya};
829f464c52Smaya
839f464c52Smayastruct fd2_shader_stateobj;
849f464c52Smayastruct tgsi_token;
859f464c52Smaya
869f464c52Smayavoid ir2_compile(struct fd2_shader_stateobj *so, unsigned variant,
877ec681f3Smrg                 struct fd2_shader_stateobj *fp);
889f464c52Smaya
899f464c52Smayastruct nir_shader *ir2_tgsi_to_nir(const struct tgsi_token *tokens,
907ec681f3Smrg                                   struct pipe_screen *screen);
919f464c52Smaya
929f464c52Smayaconst nir_shader_compiler_options *ir2_get_compiler_options(void);
939f464c52Smaya
949f464c52Smayaint ir2_optimize_nir(nir_shader *s, bool lower);
959f464c52Smaya
967ec681f3Smrg#endif /* IR2_H_ */
97