swr: [rasterizer jitter] implement InstanceID/VertexID in fetch jit
[mesa.git] / src / gallium / drivers / swr / rasterizer / jitter / fetch_jit.h
1 /****************************************************************************
2 * Copyright (C) 2014-2015 Intel Corporation. All Rights Reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is 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
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 * @file fetch_jit.h
24 *
25 * @brief Definition of the fetch jitter
26 *
27 * Notes:
28 *
29 ******************************************************************************/
30 #pragma once
31
32 #include "common/formats.h"
33 #include "core/state.h"
34
35 //////////////////////////////////////////////////////////////////////////
36 /// INPUT_ELEMENT_DESC
37 //////////////////////////////////////////////////////////////////////////
38 struct INPUT_ELEMENT_DESC
39 {
40 union
41 {
42 struct
43 {
44 uint32_t AlignedByteOffset : 12;
45 uint32_t Format : 10;
46 uint32_t StreamIndex : 6;
47 uint32_t InstanceEnable : 1;
48 uint32_t ComponentControl0 : 3;
49 uint32_t ComponentControl1 : 3;
50 uint32_t ComponentControl2 : 3;
51 uint32_t ComponentControl3 : 3;
52 uint32_t ComponentPacking : 4;
53 uint32_t _reserved : 19;
54 };
55 uint64_t bits;
56 };
57 uint32_t InstanceDataStepRate;
58 };
59
60 // used to set ComponentPacking
61 enum ComponentEnable
62 {
63 NONE = 0x0,
64 X = 0x1,
65 Y = 0x2,
66 XY = 0x3,
67 Z = 0x4,
68 XZ = 0x5,
69 YZ = 0x6,
70 XYZ = 0x7,
71 W = 0x8,
72 XW = 0x9,
73 YW = 0xA,
74 XYW = 0xB,
75 ZW = 0xC,
76 XZW = 0xD,
77 YZW = 0xE,
78 XYZW = 0xF,
79 };
80
81 enum ComponentControl
82 {
83 NoStore = 0,
84 StoreSrc = 1,
85 Store0 = 2,
86 Store1Fp = 3,
87 Store1Int = 4,
88 };
89
90 //////////////////////////////////////////////////////////////////////////
91 /// State required for fetch shader jit compile.
92 //////////////////////////////////////////////////////////////////////////
93 struct FETCH_COMPILE_STATE
94 {
95 uint32_t numAttribs;
96 INPUT_ELEMENT_DESC layout[KNOB_NUM_ATTRIBUTES];
97 SWR_FORMAT indexType;
98 uint32_t cutIndex{ 0xffffffff };
99
100 bool InstanceIdEnable;
101 uint32_t InstanceIdElementOffset;
102 uint32_t InstanceIdComponentNumber;
103 bool VertexIdEnable;
104 uint32_t VertexIdElementOffset;
105 uint32_t VertexIdComponentNumber;
106
107 // Options that effect the JIT'd code
108 bool bDisableVGATHER; // if enabled, FetchJit will generate loads/shuffles instead of VGATHERs
109 bool bDisableIndexOOBCheck; // if enabled, FetchJit will exclude index OOB check
110 bool bEnableCutIndex{ false }; // compares indices with the cut index and returns a cut mask
111
112 FETCH_COMPILE_STATE(bool disableVGATHER = false, bool diableIndexOOBCheck = false):
113 bDisableVGATHER(disableVGATHER), bDisableIndexOOBCheck(diableIndexOOBCheck){ };
114
115 bool operator==(const FETCH_COMPILE_STATE &other) const
116 {
117 if (numAttribs != other.numAttribs) return false;
118 if (indexType != other.indexType) return false;
119 if (bDisableVGATHER != other.bDisableVGATHER) return false;
120 if (bDisableIndexOOBCheck != other.bDisableIndexOOBCheck) return false;
121 if (bEnableCutIndex != other.bEnableCutIndex) return false;
122 if (cutIndex != other.cutIndex) return false;
123
124 if (InstanceIdEnable != other.InstanceIdEnable) return false;
125 if (InstanceIdEnable)
126 {
127 if (InstanceIdComponentNumber != other.InstanceIdComponentNumber) return false;
128 if (InstanceIdElementOffset != other.InstanceIdElementOffset) return false;
129 }
130 if (VertexIdEnable != other.VertexIdEnable) return false;
131 if (VertexIdEnable)
132 {
133 if (VertexIdComponentNumber != other.VertexIdComponentNumber) return false;
134 if (VertexIdElementOffset != other.VertexIdElementOffset) return false;
135 }
136
137 for(uint32_t i = 0; i < numAttribs; ++i)
138 {
139 if((layout[i].bits != other.layout[i].bits) ||
140 ((layout[i].InstanceEnable == 1) &&
141 (layout[i].InstanceDataStepRate != other.layout[i].InstanceDataStepRate))){
142 return false;
143 }
144 }
145
146 return true;
147 }
148 };