17ec681f3Smrg/**************************************************************************
27ec681f3Smrg *
37ec681f3Smrg * Copyright 2012-2021 VMware, Inc.
47ec681f3Smrg * All Rights Reserved.
57ec681f3Smrg *
67ec681f3Smrg * Permission is hereby granted, free of charge, to any person obtaining a
77ec681f3Smrg * copy of this software and associated documentation files (the
87ec681f3Smrg * "Software"), to deal in the Software without restriction, including
97ec681f3Smrg * without limitation the rights to use, copy, modify, merge, publish,
107ec681f3Smrg * distribute, sub license, and/or sell copies of the Software, and to
117ec681f3Smrg * permit persons to whom the Software is furnished to do so, subject to
127ec681f3Smrg * the following conditions:
137ec681f3Smrg *
147ec681f3Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
157ec681f3Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
167ec681f3Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
177ec681f3Smrg * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
187ec681f3Smrg * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
197ec681f3Smrg * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
207ec681f3Smrg * USE OR OTHER DEALINGS IN THE SOFTWARE.
217ec681f3Smrg *
227ec681f3Smrg * The above copyright notice and this permission notice (including the
237ec681f3Smrg * next paragraph) shall be included in all copies or substantial portions
247ec681f3Smrg * of the Software.
257ec681f3Smrg *
267ec681f3Smrg **************************************************************************/
277ec681f3Smrg
287ec681f3Smrg/*
297ec681f3Smrg * ShaderParse.h --
307ec681f3Smrg *    Functions for parsing shader tokens.
317ec681f3Smrg */
327ec681f3Smrg
337ec681f3Smrg#ifndef SHADER_PARSE_H
347ec681f3Smrg#define SHADER_PARSE_H
357ec681f3Smrg
367ec681f3Smrg#include "DriverIncludes.h"
377ec681f3Smrg
387ec681f3Smrg//#include "winddk/winddk_compat.h"
397ec681f3Smrg#include "winddk/d3d10tokenizedprogramformat.hpp"
407ec681f3Smrg
417ec681f3Smrg#ifdef __cplusplus
427ec681f3Smrgextern "C" {
437ec681f3Smrg#endif
447ec681f3Smrg
457ec681f3Smrgstruct Shader_header {
467ec681f3Smrg   D3D10_SB_TOKENIZED_PROGRAM_TYPE type;
477ec681f3Smrg   unsigned major_version;
487ec681f3Smrg   unsigned minor_version;
497ec681f3Smrg   unsigned size;
507ec681f3Smrg};
517ec681f3Smrg
527ec681f3Smrgstruct dx10_imm_const_buf {
537ec681f3Smrg   unsigned count;
547ec681f3Smrg   unsigned *data;
557ec681f3Smrg};
567ec681f3Smrg
577ec681f3Smrgstruct dx10_customdata {
587ec681f3Smrg   D3D10_SB_CUSTOMDATA_CLASS _class;
597ec681f3Smrg   union {
607ec681f3Smrg      struct dx10_imm_const_buf constbuf;
617ec681f3Smrg   } u;
627ec681f3Smrg};
637ec681f3Smrg
647ec681f3Smrgstruct dx10_indexable_temp {
657ec681f3Smrg   unsigned index;
667ec681f3Smrg   unsigned count;
677ec681f3Smrg   unsigned components;
687ec681f3Smrg};
697ec681f3Smrg
707ec681f3Smrgstruct dx10_global_flags {
717ec681f3Smrg   unsigned refactoring_allowed:1;
727ec681f3Smrg};
737ec681f3Smrg
747ec681f3Smrgstruct Shader_relative_index {
757ec681f3Smrg   unsigned imm;
767ec681f3Smrg};
777ec681f3Smrg
787ec681f3Smrgstruct Shader_relative_operand {
797ec681f3Smrg   D3D10_SB_OPERAND_TYPE type;
807ec681f3Smrg   struct Shader_relative_index index[2];
817ec681f3Smrg   D3D10_SB_4_COMPONENT_NAME comp;
827ec681f3Smrg};
837ec681f3Smrg
847ec681f3Smrgstruct Shader_index {
857ec681f3Smrg   unsigned imm;
867ec681f3Smrg   struct Shader_relative_operand rel;
877ec681f3Smrg   D3D10_SB_OPERAND_INDEX_REPRESENTATION index_rep;
887ec681f3Smrg};
897ec681f3Smrg
907ec681f3Smrgstruct Shader_operand {
917ec681f3Smrg   D3D10_SB_OPERAND_TYPE type;
927ec681f3Smrg   struct Shader_index index[2];
937ec681f3Smrg   unsigned index_dim;
947ec681f3Smrg};
957ec681f3Smrg
967ec681f3Smrgstruct Shader_dst_operand {
977ec681f3Smrg   struct Shader_operand base;
987ec681f3Smrg   unsigned mask;
997ec681f3Smrg};
1007ec681f3Smrg
1017ec681f3Smrgunion Shader_immediate {
1027ec681f3Smrg   float f32;
1037ec681f3Smrg   int i32;
1047ec681f3Smrg   unsigned u32;
1057ec681f3Smrg};
1067ec681f3Smrg
1077ec681f3Smrgstruct Shader_src_operand {
1087ec681f3Smrg   struct Shader_operand base;
1097ec681f3Smrg   union Shader_immediate imm[4];
1107ec681f3Smrg   D3D10_SB_4_COMPONENT_NAME swizzle[4];
1117ec681f3Smrg   D3D10_SB_OPERAND_MODIFIER modifier;
1127ec681f3Smrg};
1137ec681f3Smrg
1147ec681f3Smrg#define SHADER_MAX_DST_OPERANDS 2
1157ec681f3Smrg#define SHADER_MAX_SRC_OPERANDS 5
1167ec681f3Smrg
1177ec681f3Smrgstruct Shader_opcode {
1187ec681f3Smrg   D3D10_SB_OPCODE_TYPE type;
1197ec681f3Smrg   unsigned num_dst;
1207ec681f3Smrg   unsigned num_src;
1217ec681f3Smrg   struct Shader_dst_operand dst[SHADER_MAX_DST_OPERANDS];
1227ec681f3Smrg   struct Shader_src_operand src[SHADER_MAX_SRC_OPERANDS];
1237ec681f3Smrg
1247ec681f3Smrg   /* Opcode specific data.
1257ec681f3Smrg    */
1267ec681f3Smrg   union {
1277ec681f3Smrg      D3D10_SB_RESOURCE_DIMENSION dcl_resource_dimension;
1287ec681f3Smrg      D3D10_SB_SAMPLER_MODE dcl_sampler_mode;
1297ec681f3Smrg      D3D10_SB_CONSTANT_BUFFER_ACCESS_PATTERN dcl_cb_access_pattern;
1307ec681f3Smrg      D3D10_SB_INTERPOLATION_MODE dcl_in_ps_interp;
1317ec681f3Smrg      D3D10_SB_PRIMITIVE_TOPOLOGY dcl_gs_output_primitive_topology;
1327ec681f3Smrg      D3D10_SB_PRIMITIVE dcl_gs_input_primitive;
1337ec681f3Smrg      D3D10_SB_INSTRUCTION_TEST_BOOLEAN test_boolean;
1347ec681f3Smrg      D3D10_SB_RESINFO_INSTRUCTION_RETURN_TYPE resinfo_ret_type;
1357ec681f3Smrg      unsigned dcl_max_output_vertex_count;
1367ec681f3Smrg      unsigned dcl_num_temps;
1377ec681f3Smrg      struct dx10_indexable_temp dcl_indexable_temp;
1387ec681f3Smrg      unsigned index_range_count;
1397ec681f3Smrg      struct dx10_global_flags global_flags;
1407ec681f3Smrg   } specific;
1417ec681f3Smrg   D3D10_SB_NAME dcl_siv_name;
1427ec681f3Smrg   D3D10_SB_RESOURCE_RETURN_TYPE dcl_resource_ret_type[4];
1437ec681f3Smrg
1447ec681f3Smrg   boolean saturate;
1457ec681f3Smrg
1467ec681f3Smrg   struct {
1477ec681f3Smrg      int u:4;
1487ec681f3Smrg      int v:4;
1497ec681f3Smrg      int w:4;
1507ec681f3Smrg   } imm_texel_offset;
1517ec681f3Smrg
1527ec681f3Smrg   struct dx10_customdata customdata;
1537ec681f3Smrg};
1547ec681f3Smrg
1557ec681f3Smrgstruct Shader_parser {
1567ec681f3Smrg   const unsigned *code;
1577ec681f3Smrg   const unsigned *curr;
1587ec681f3Smrg
1597ec681f3Smrg   struct Shader_header header;
1607ec681f3Smrg};
1617ec681f3Smrg
1627ec681f3Smrgvoid
1637ec681f3SmrgShader_parse_init(struct Shader_parser *parser,
1647ec681f3Smrg                       const unsigned *code);
1657ec681f3Smrg
1667ec681f3Smrgboolean
1677ec681f3SmrgShader_parse_opcode(struct Shader_parser *parser,
1687ec681f3Smrg                         struct Shader_opcode *opcode);
1697ec681f3Smrg
1707ec681f3Smrgvoid
1717ec681f3SmrgShader_opcode_free(struct Shader_opcode *opcode);
1727ec681f3Smrg
1737ec681f3Smrg
1747ec681f3Smrgconst struct tgsi_token *
1757ec681f3SmrgShader_tgsi_translate(const unsigned *code,
1767ec681f3Smrg                      unsigned *output_mapping);
1777ec681f3Smrg
1787ec681f3Smrg
1797ec681f3Smrg#ifdef __cplusplus
1807ec681f3Smrg}
1817ec681f3Smrg#endif
1827ec681f3Smrg
1837ec681f3Smrg#endif /* SHADER_PARSE_H */
184