swr/rast: Use metadata to communicate between passes
[mesa.git] / src / gallium / drivers / swr / rasterizer / jitter / builder.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 builder.h
24 *
25 * @brief Includes all the builder related functionality
26 *
27 * Notes:
28 *
29 ******************************************************************************/
30 #pragma once
31
32 #include "JitManager.h"
33 #include "common/formats.h"
34
35 namespace SwrJit
36 {
37 ///@todo Move this to better place
38 enum SHADER_STATS_COUNTER_TYPE
39 {
40 STATS_INST_EXECUTED = 0,
41 STATS_SAMPLE_EXECUTED = 1,
42 STATS_SAMPLE_L_EXECUTED = 2,
43 STATS_SAMPLE_B_EXECUTED = 3,
44 STATS_SAMPLE_C_EXECUTED = 4,
45 STATS_SAMPLE_C_LZ_EXECUTED = 5,
46 STATS_SAMPLE_C_D_EXECUTED = 6,
47 STATS_LOD_EXECUTED = 7,
48 STATS_GATHER4_EXECUTED = 8,
49 STATS_GATHER4_C_EXECUTED = 9,
50 STATS_GATHER4_C_PO_EXECUTED = 10,
51 STATS_GATHER4_C_PO_C_EXECUTED = 11,
52 STATS_LOAD_RAW_UAV = 12,
53 STATS_LOAD_RAW_RESOURCE = 13,
54 STATS_STORE_RAW_UAV = 14,
55 STATS_STORE_TGSM = 15,
56 STATS_DISCARD = 16,
57 STATS_BARRIER = 17,
58 };
59
60 using namespace llvm;
61 struct Builder
62 {
63 Builder(JitManager *pJitMgr);
64 virtual ~Builder() {}
65
66 IRBuilder<> *IRB() { return mpIRBuilder; };
67 JitManager *JM() { return mpJitMgr; }
68
69 JitManager *mpJitMgr;
70 IRBuilder<> *mpIRBuilder;
71
72 uint32_t mVWidth; // vector width target simd
73 uint32_t mVWidth16; // vector width simd16
74
75 // Built in types: scalar
76
77 Type* mVoidTy;
78 Type* mInt1Ty;
79 Type* mInt8Ty;
80 Type* mInt16Ty;
81 Type* mInt32Ty;
82 Type* mInt64Ty;
83 Type* mIntPtrTy;
84 Type* mFP16Ty;
85 Type* mFP32Ty;
86 Type* mFP32PtrTy;
87 Type* mDoubleTy;
88 Type* mInt8PtrTy;
89 Type* mInt16PtrTy;
90 Type* mInt32PtrTy;
91
92 Type* mSimd4FP64Ty;
93
94 // Built in types: target SIMD
95
96 Type* mSimdFP16Ty;
97 Type* mSimdFP32Ty;
98 Type* mSimdInt1Ty;
99 Type* mSimdInt16Ty;
100 Type* mSimdInt32Ty;
101 Type* mSimdInt64Ty;
102 Type* mSimdIntPtrTy;
103 Type* mSimdVectorTy;
104 Type* mSimdVectorTRTy;
105 Type* mSimdVectorIntTy;
106
107 // Built in types: simd16
108
109 Type* mSimd16FP16Ty;
110 Type* mSimd16FP32Ty;
111 Type* mSimd16Int1Ty;
112 Type* mSimd16Int16Ty;
113 Type* mSimd16Int32Ty;
114 Type* mSimd16Int64Ty;
115 Type* mSimd16IntPtrTy;
116 Type* mSimd16VectorTy;
117 Type* mSimd16VectorTRTy;
118
119 Type* mSimd32Int8Ty;
120
121 void SetTargetWidth(uint32_t width);
122 void SetTempAlloca(Value* inst);
123 bool IsTempAlloca(Value* inst);
124 bool SetTexelMaskEvaluate(Instruction* inst);
125 bool IsTexelMaskEvaluate(Instruction* inst);
126 Type* GetVectorType(Type* pType);
127 void SetMetadata(StringRef s, uint32_t val)
128 {
129 llvm::NamedMDNode *metaData = mpJitMgr->mpCurrentModule->getOrInsertNamedMetadata(s);
130 Constant* cval = mpIRBuilder->getInt32(val);
131 llvm::MDNode *mdNode = llvm::MDNode::get(mpJitMgr->mpCurrentModule->getContext(), llvm::ConstantAsMetadata::get(cval));
132 if (metaData->getNumOperands())
133 {
134 metaData->setOperand(0, mdNode);
135 }
136 else
137 {
138 metaData->addOperand(mdNode);
139 }
140 }
141 uint32_t GetMetadata(StringRef s)
142 {
143 NamedMDNode* metaData = mpJitMgr->mpCurrentModule->getNamedMetadata(s);
144 if (metaData)
145 {
146 MDNode* mdNode = metaData->getOperand(0);
147 Metadata* val = mdNode->getOperand(0);
148 return mdconst::dyn_extract<ConstantInt>(val)->getZExtValue();
149 }
150 else
151 {
152 return 0;
153 }
154 }
155
156 #include "gen_builder.hpp"
157 #include "gen_builder_meta.hpp"
158 #include "gen_builder_intrin.hpp"
159 #include "builder_misc.h"
160 #include "builder_math.h"
161 #include "builder_mem.h"
162
163 protected:
164
165 void SetPrivateContext(Value* pPrivateContext)
166 {
167 mpPrivateContext = pPrivateContext;
168 NotifyPrivateContextSet();
169 }
170 virtual void NotifyPrivateContextSet() {}
171 inline Value* GetPrivateContext() { return mpPrivateContext; }
172
173 private:
174 Value* mpPrivateContext;
175
176 };
177 }