xref: /aosp_15_r20/external/angle/src/libANGLE/renderer/d3d/ShaderD3D.cpp (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1*8975f5c5SAndroid Build Coastguard Worker //
2*8975f5c5SAndroid Build Coastguard Worker // Copyright 2014 The ANGLE Project Authors. All rights reserved.
3*8975f5c5SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
4*8975f5c5SAndroid Build Coastguard Worker // found in the LICENSE file.
5*8975f5c5SAndroid Build Coastguard Worker //
6*8975f5c5SAndroid Build Coastguard Worker 
7*8975f5c5SAndroid Build Coastguard Worker // ShaderD3D.cpp: Defines the rx::ShaderD3D class which implements rx::ShaderImpl.
8*8975f5c5SAndroid Build Coastguard Worker 
9*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/renderer/d3d/ShaderD3D.h"
10*8975f5c5SAndroid Build Coastguard Worker 
11*8975f5c5SAndroid Build Coastguard Worker #include "common/system_utils.h"
12*8975f5c5SAndroid Build Coastguard Worker #include "common/utilities.h"
13*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/Caps.h"
14*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/Compiler.h"
15*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/Context.h"
16*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/Shader.h"
17*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/features.h"
18*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/renderer/ContextImpl.h"
19*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/renderer/d3d/ProgramD3D.h"
20*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/renderer/d3d/RendererD3D.h"
21*8975f5c5SAndroid Build Coastguard Worker #include "libANGLE/trace.h"
22*8975f5c5SAndroid Build Coastguard Worker 
23*8975f5c5SAndroid Build Coastguard Worker namespace rx
24*8975f5c5SAndroid Build Coastguard Worker {
25*8975f5c5SAndroid Build Coastguard Worker namespace
26*8975f5c5SAndroid Build Coastguard Worker {
GetUniformRegisterMap(const std::map<std::string,unsigned int> * uniformRegisterMap)27*8975f5c5SAndroid Build Coastguard Worker const std::map<std::string, unsigned int> &GetUniformRegisterMap(
28*8975f5c5SAndroid Build Coastguard Worker     const std::map<std::string, unsigned int> *uniformRegisterMap)
29*8975f5c5SAndroid Build Coastguard Worker {
30*8975f5c5SAndroid Build Coastguard Worker     ASSERT(uniformRegisterMap);
31*8975f5c5SAndroid Build Coastguard Worker     return *uniformRegisterMap;
32*8975f5c5SAndroid Build Coastguard Worker }
33*8975f5c5SAndroid Build Coastguard Worker 
GetSlowCompilingUniformBlockSet(const std::set<std::string> * slowCompilingUniformBlockSet)34*8975f5c5SAndroid Build Coastguard Worker const std::set<std::string> &GetSlowCompilingUniformBlockSet(
35*8975f5c5SAndroid Build Coastguard Worker     const std::set<std::string> *slowCompilingUniformBlockSet)
36*8975f5c5SAndroid Build Coastguard Worker {
37*8975f5c5SAndroid Build Coastguard Worker     ASSERT(slowCompilingUniformBlockSet);
38*8975f5c5SAndroid Build Coastguard Worker     return *slowCompilingUniformBlockSet;
39*8975f5c5SAndroid Build Coastguard Worker }
40*8975f5c5SAndroid Build Coastguard Worker 
GetUsedImage2DFunctionNames(const std::set<std::string> * usedImage2DFunctionNames)41*8975f5c5SAndroid Build Coastguard Worker const std::set<std::string> &GetUsedImage2DFunctionNames(
42*8975f5c5SAndroid Build Coastguard Worker     const std::set<std::string> *usedImage2DFunctionNames)
43*8975f5c5SAndroid Build Coastguard Worker {
44*8975f5c5SAndroid Build Coastguard Worker     ASSERT(usedImage2DFunctionNames);
45*8975f5c5SAndroid Build Coastguard Worker     return *usedImage2DFunctionNames;
46*8975f5c5SAndroid Build Coastguard Worker }
47*8975f5c5SAndroid Build Coastguard Worker 
48*8975f5c5SAndroid Build Coastguard Worker class ShaderTranslateTaskD3D final : public ShaderTranslateTask
49*8975f5c5SAndroid Build Coastguard Worker {
50*8975f5c5SAndroid Build Coastguard Worker   public:
ShaderTranslateTaskD3D(const SharedCompiledShaderStateD3D & shader,std::string && sourcePath)51*8975f5c5SAndroid Build Coastguard Worker     ShaderTranslateTaskD3D(const SharedCompiledShaderStateD3D &shader, std::string &&sourcePath)
52*8975f5c5SAndroid Build Coastguard Worker         : mSourcePath(std::move(sourcePath)), mShader(shader)
53*8975f5c5SAndroid Build Coastguard Worker     {}
54*8975f5c5SAndroid Build Coastguard Worker     ~ShaderTranslateTaskD3D() override = default;
55*8975f5c5SAndroid Build Coastguard Worker 
translate(ShHandle compiler,const ShCompileOptions & options,const std::string & source)56*8975f5c5SAndroid Build Coastguard Worker     bool translate(ShHandle compiler,
57*8975f5c5SAndroid Build Coastguard Worker                    const ShCompileOptions &options,
58*8975f5c5SAndroid Build Coastguard Worker                    const std::string &source) override
59*8975f5c5SAndroid Build Coastguard Worker     {
60*8975f5c5SAndroid Build Coastguard Worker         ANGLE_TRACE_EVENT1("gpu.angle", "ShaderTranslateTaskD3D::run", "source", source);
61*8975f5c5SAndroid Build Coastguard Worker         angle::FixedVector<const char *, 2> srcStrings;
62*8975f5c5SAndroid Build Coastguard Worker         if (!mSourcePath.empty())
63*8975f5c5SAndroid Build Coastguard Worker         {
64*8975f5c5SAndroid Build Coastguard Worker             srcStrings.push_back(mSourcePath.c_str());
65*8975f5c5SAndroid Build Coastguard Worker         }
66*8975f5c5SAndroid Build Coastguard Worker         srcStrings.push_back(source.c_str());
67*8975f5c5SAndroid Build Coastguard Worker 
68*8975f5c5SAndroid Build Coastguard Worker         return sh::Compile(compiler, srcStrings.data(), srcStrings.size(), options);
69*8975f5c5SAndroid Build Coastguard Worker     }
70*8975f5c5SAndroid Build Coastguard Worker 
postTranslate(ShHandle compiler,const gl::CompiledShaderState & compiledState)71*8975f5c5SAndroid Build Coastguard Worker     void postTranslate(ShHandle compiler, const gl::CompiledShaderState &compiledState) override
72*8975f5c5SAndroid Build Coastguard Worker     {
73*8975f5c5SAndroid Build Coastguard Worker         const std::string &translatedSource = compiledState.translatedSource;
74*8975f5c5SAndroid Build Coastguard Worker         CompiledShaderStateD3D *state       = mShader.get();
75*8975f5c5SAndroid Build Coastguard Worker 
76*8975f5c5SAndroid Build Coastguard Worker         // Note: We shouldn't need to cache this.
77*8975f5c5SAndroid Build Coastguard Worker         state->compilerOutputType = sh::GetShaderOutputType(compiler);
78*8975f5c5SAndroid Build Coastguard Worker 
79*8975f5c5SAndroid Build Coastguard Worker         state->usesMultipleRenderTargets =
80*8975f5c5SAndroid Build Coastguard Worker             translatedSource.find("GL_USES_MRT") != std::string::npos;
81*8975f5c5SAndroid Build Coastguard Worker         state->usesFragColor = translatedSource.find("GL_USES_FRAG_COLOR") != std::string::npos;
82*8975f5c5SAndroid Build Coastguard Worker         state->usesFragData  = translatedSource.find("GL_USES_FRAG_DATA") != std::string::npos;
83*8975f5c5SAndroid Build Coastguard Worker         state->usesSecondaryColor =
84*8975f5c5SAndroid Build Coastguard Worker             translatedSource.find("GL_USES_SECONDARY_COLOR") != std::string::npos;
85*8975f5c5SAndroid Build Coastguard Worker         state->usesFragCoord   = translatedSource.find("GL_USES_FRAG_COORD") != std::string::npos;
86*8975f5c5SAndroid Build Coastguard Worker         state->usesFrontFacing = translatedSource.find("GL_USES_FRONT_FACING") != std::string::npos;
87*8975f5c5SAndroid Build Coastguard Worker         state->usesSampleID    = translatedSource.find("GL_USES_SAMPLE_ID") != std::string::npos;
88*8975f5c5SAndroid Build Coastguard Worker         state->usesSamplePosition =
89*8975f5c5SAndroid Build Coastguard Worker             translatedSource.find("GL_USES_SAMPLE_POSITION") != std::string::npos;
90*8975f5c5SAndroid Build Coastguard Worker         state->usesSampleMaskIn =
91*8975f5c5SAndroid Build Coastguard Worker             translatedSource.find("GL_USES_SAMPLE_MASK_IN") != std::string::npos;
92*8975f5c5SAndroid Build Coastguard Worker         state->usesSampleMask =
93*8975f5c5SAndroid Build Coastguard Worker             translatedSource.find("GL_USES_SAMPLE_MASK_OUT") != std::string::npos;
94*8975f5c5SAndroid Build Coastguard Worker         state->usesHelperInvocation =
95*8975f5c5SAndroid Build Coastguard Worker             translatedSource.find("GL_USES_HELPER_INVOCATION") != std::string::npos;
96*8975f5c5SAndroid Build Coastguard Worker         state->usesPointSize  = translatedSource.find("GL_USES_POINT_SIZE") != std::string::npos;
97*8975f5c5SAndroid Build Coastguard Worker         state->usesPointCoord = translatedSource.find("GL_USES_POINT_COORD") != std::string::npos;
98*8975f5c5SAndroid Build Coastguard Worker         state->usesDepthRange = translatedSource.find("GL_USES_DEPTH_RANGE") != std::string::npos;
99*8975f5c5SAndroid Build Coastguard Worker         state->hasMultiviewEnabled =
100*8975f5c5SAndroid Build Coastguard Worker             translatedSource.find("GL_MULTIVIEW_ENABLED") != std::string::npos;
101*8975f5c5SAndroid Build Coastguard Worker         state->usesVertexID = translatedSource.find("GL_USES_VERTEX_ID") != std::string::npos;
102*8975f5c5SAndroid Build Coastguard Worker         state->usesViewID   = translatedSource.find("GL_USES_VIEW_ID") != std::string::npos;
103*8975f5c5SAndroid Build Coastguard Worker         state->usesDiscardRewriting =
104*8975f5c5SAndroid Build Coastguard Worker             translatedSource.find("ANGLE_USES_DISCARD_REWRITING") != std::string::npos;
105*8975f5c5SAndroid Build Coastguard Worker         state->usesNestedBreak =
106*8975f5c5SAndroid Build Coastguard Worker             translatedSource.find("ANGLE_USES_NESTED_BREAK") != std::string::npos;
107*8975f5c5SAndroid Build Coastguard Worker         state->requiresIEEEStrictCompiling =
108*8975f5c5SAndroid Build Coastguard Worker             translatedSource.find("ANGLE_REQUIRES_IEEE_STRICT_COMPILING") != std::string::npos;
109*8975f5c5SAndroid Build Coastguard Worker 
110*8975f5c5SAndroid Build Coastguard Worker         if (translatedSource.find("GL_USES_FRAG_DEPTH_GREATER") != std::string::npos)
111*8975f5c5SAndroid Build Coastguard Worker         {
112*8975f5c5SAndroid Build Coastguard Worker             state->fragDepthUsage = FragDepthUsage::Greater;
113*8975f5c5SAndroid Build Coastguard Worker         }
114*8975f5c5SAndroid Build Coastguard Worker         else if (translatedSource.find("GL_USES_FRAG_DEPTH_LESS") != std::string::npos)
115*8975f5c5SAndroid Build Coastguard Worker         {
116*8975f5c5SAndroid Build Coastguard Worker             state->fragDepthUsage = FragDepthUsage::Less;
117*8975f5c5SAndroid Build Coastguard Worker         }
118*8975f5c5SAndroid Build Coastguard Worker         else if (translatedSource.find("GL_USES_FRAG_DEPTH") != std::string::npos)
119*8975f5c5SAndroid Build Coastguard Worker         {
120*8975f5c5SAndroid Build Coastguard Worker             state->fragDepthUsage = FragDepthUsage::Any;
121*8975f5c5SAndroid Build Coastguard Worker         }
122*8975f5c5SAndroid Build Coastguard Worker         state->clipDistanceSize   = sh::GetClipDistanceArraySize(compiler);
123*8975f5c5SAndroid Build Coastguard Worker         state->cullDistanceSize   = sh::GetCullDistanceArraySize(compiler);
124*8975f5c5SAndroid Build Coastguard Worker         state->uniformRegisterMap = GetUniformRegisterMap(sh::GetUniformRegisterMap(compiler));
125*8975f5c5SAndroid Build Coastguard Worker         state->readonlyImage2DRegisterIndex = sh::GetReadonlyImage2DRegisterIndex(compiler);
126*8975f5c5SAndroid Build Coastguard Worker         state->image2DRegisterIndex         = sh::GetImage2DRegisterIndex(compiler);
127*8975f5c5SAndroid Build Coastguard Worker         state->usedImage2DFunctionNames =
128*8975f5c5SAndroid Build Coastguard Worker             GetUsedImage2DFunctionNames(sh::GetUsedImage2DFunctionNames(compiler));
129*8975f5c5SAndroid Build Coastguard Worker 
130*8975f5c5SAndroid Build Coastguard Worker         for (const sh::InterfaceBlock &interfaceBlock : compiledState.uniformBlocks)
131*8975f5c5SAndroid Build Coastguard Worker         {
132*8975f5c5SAndroid Build Coastguard Worker             if (interfaceBlock.active)
133*8975f5c5SAndroid Build Coastguard Worker             {
134*8975f5c5SAndroid Build Coastguard Worker                 unsigned int index = static_cast<unsigned int>(-1);
135*8975f5c5SAndroid Build Coastguard Worker                 bool blockRegisterResult =
136*8975f5c5SAndroid Build Coastguard Worker                     sh::GetUniformBlockRegister(compiler, interfaceBlock.name, &index);
137*8975f5c5SAndroid Build Coastguard Worker                 ASSERT(blockRegisterResult);
138*8975f5c5SAndroid Build Coastguard Worker                 bool useStructuredBuffer =
139*8975f5c5SAndroid Build Coastguard Worker                     sh::ShouldUniformBlockUseStructuredBuffer(compiler, interfaceBlock.name);
140*8975f5c5SAndroid Build Coastguard Worker 
141*8975f5c5SAndroid Build Coastguard Worker                 state->uniformBlockRegisterMap[interfaceBlock.name] = index;
142*8975f5c5SAndroid Build Coastguard Worker                 state->uniformBlockUseStructuredBufferMap[interfaceBlock.name] =
143*8975f5c5SAndroid Build Coastguard Worker                     useStructuredBuffer;
144*8975f5c5SAndroid Build Coastguard Worker             }
145*8975f5c5SAndroid Build Coastguard Worker         }
146*8975f5c5SAndroid Build Coastguard Worker 
147*8975f5c5SAndroid Build Coastguard Worker         state->slowCompilingUniformBlockSet =
148*8975f5c5SAndroid Build Coastguard Worker             GetSlowCompilingUniformBlockSet(sh::GetSlowCompilingUniformBlockSet(compiler));
149*8975f5c5SAndroid Build Coastguard Worker 
150*8975f5c5SAndroid Build Coastguard Worker         for (const sh::InterfaceBlock &interfaceBlock : compiledState.shaderStorageBlocks)
151*8975f5c5SAndroid Build Coastguard Worker         {
152*8975f5c5SAndroid Build Coastguard Worker             if (interfaceBlock.active)
153*8975f5c5SAndroid Build Coastguard Worker             {
154*8975f5c5SAndroid Build Coastguard Worker                 unsigned int index = static_cast<unsigned int>(-1);
155*8975f5c5SAndroid Build Coastguard Worker                 bool blockRegisterResult =
156*8975f5c5SAndroid Build Coastguard Worker                     sh::GetShaderStorageBlockRegister(compiler, interfaceBlock.name, &index);
157*8975f5c5SAndroid Build Coastguard Worker                 ASSERT(blockRegisterResult);
158*8975f5c5SAndroid Build Coastguard Worker 
159*8975f5c5SAndroid Build Coastguard Worker                 state->shaderStorageBlockRegisterMap[interfaceBlock.name] = index;
160*8975f5c5SAndroid Build Coastguard Worker             }
161*8975f5c5SAndroid Build Coastguard Worker         }
162*8975f5c5SAndroid Build Coastguard Worker 
163*8975f5c5SAndroid Build Coastguard Worker         state->debugInfo +=
164*8975f5c5SAndroid Build Coastguard Worker             "// INITIAL HLSL BEGIN\n\n" + translatedSource + "\n// INITIAL HLSL END\n\n\n";
165*8975f5c5SAndroid Build Coastguard Worker     }
166*8975f5c5SAndroid Build Coastguard Worker 
167*8975f5c5SAndroid Build Coastguard Worker   private:
168*8975f5c5SAndroid Build Coastguard Worker     std::string mSourcePath;
169*8975f5c5SAndroid Build Coastguard Worker     SharedCompiledShaderStateD3D mShader;
170*8975f5c5SAndroid Build Coastguard Worker };
171*8975f5c5SAndroid Build Coastguard Worker }  // anonymous namespace
172*8975f5c5SAndroid Build Coastguard Worker 
CompiledShaderStateD3D()173*8975f5c5SAndroid Build Coastguard Worker CompiledShaderStateD3D::CompiledShaderStateD3D()
174*8975f5c5SAndroid Build Coastguard Worker     : compilerOutputType(SH_ESSL_OUTPUT),
175*8975f5c5SAndroid Build Coastguard Worker       usesMultipleRenderTargets(false),
176*8975f5c5SAndroid Build Coastguard Worker       usesFragColor(false),
177*8975f5c5SAndroid Build Coastguard Worker       usesFragData(false),
178*8975f5c5SAndroid Build Coastguard Worker       usesSecondaryColor(false),
179*8975f5c5SAndroid Build Coastguard Worker       usesFragCoord(false),
180*8975f5c5SAndroid Build Coastguard Worker       usesFrontFacing(false),
181*8975f5c5SAndroid Build Coastguard Worker       usesHelperInvocation(false),
182*8975f5c5SAndroid Build Coastguard Worker       usesPointSize(false),
183*8975f5c5SAndroid Build Coastguard Worker       usesPointCoord(false),
184*8975f5c5SAndroid Build Coastguard Worker       usesDepthRange(false),
185*8975f5c5SAndroid Build Coastguard Worker       usesSampleID(false),
186*8975f5c5SAndroid Build Coastguard Worker       usesSamplePosition(false),
187*8975f5c5SAndroid Build Coastguard Worker       usesSampleMaskIn(false),
188*8975f5c5SAndroid Build Coastguard Worker       usesSampleMask(false),
189*8975f5c5SAndroid Build Coastguard Worker       hasMultiviewEnabled(false),
190*8975f5c5SAndroid Build Coastguard Worker       usesVertexID(false),
191*8975f5c5SAndroid Build Coastguard Worker       usesViewID(false),
192*8975f5c5SAndroid Build Coastguard Worker       usesDiscardRewriting(false),
193*8975f5c5SAndroid Build Coastguard Worker       usesNestedBreak(false),
194*8975f5c5SAndroid Build Coastguard Worker       requiresIEEEStrictCompiling(false),
195*8975f5c5SAndroid Build Coastguard Worker       fragDepthUsage(FragDepthUsage::Unused),
196*8975f5c5SAndroid Build Coastguard Worker       clipDistanceSize(0),
197*8975f5c5SAndroid Build Coastguard Worker       cullDistanceSize(0),
198*8975f5c5SAndroid Build Coastguard Worker       readonlyImage2DRegisterIndex(0),
199*8975f5c5SAndroid Build Coastguard Worker       image2DRegisterIndex(0)
200*8975f5c5SAndroid Build Coastguard Worker {}
201*8975f5c5SAndroid Build Coastguard Worker 
202*8975f5c5SAndroid Build Coastguard Worker CompiledShaderStateD3D::~CompiledShaderStateD3D() = default;
203*8975f5c5SAndroid Build Coastguard Worker 
ShaderD3D(const gl::ShaderState & state,RendererD3D * renderer)204*8975f5c5SAndroid Build Coastguard Worker ShaderD3D::ShaderD3D(const gl::ShaderState &state, RendererD3D *renderer)
205*8975f5c5SAndroid Build Coastguard Worker     : ShaderImpl(state), mRenderer(renderer)
206*8975f5c5SAndroid Build Coastguard Worker {}
207*8975f5c5SAndroid Build Coastguard Worker 
~ShaderD3D()208*8975f5c5SAndroid Build Coastguard Worker ShaderD3D::~ShaderD3D() {}
209*8975f5c5SAndroid Build Coastguard Worker 
getDebugInfo() const210*8975f5c5SAndroid Build Coastguard Worker std::string ShaderD3D::getDebugInfo() const
211*8975f5c5SAndroid Build Coastguard Worker {
212*8975f5c5SAndroid Build Coastguard Worker     if (!mCompiledState || mCompiledState->debugInfo.empty())
213*8975f5c5SAndroid Build Coastguard Worker     {
214*8975f5c5SAndroid Build Coastguard Worker         return "";
215*8975f5c5SAndroid Build Coastguard Worker     }
216*8975f5c5SAndroid Build Coastguard Worker 
217*8975f5c5SAndroid Build Coastguard Worker     return mCompiledState->debugInfo + std::string("\n// ") +
218*8975f5c5SAndroid Build Coastguard Worker            gl::GetShaderTypeString(mState.getShaderType()) + " SHADER END\n";
219*8975f5c5SAndroid Build Coastguard Worker }
220*8975f5c5SAndroid Build Coastguard Worker 
generateWorkarounds(CompilerWorkaroundsD3D * workarounds) const221*8975f5c5SAndroid Build Coastguard Worker void CompiledShaderStateD3D::generateWorkarounds(CompilerWorkaroundsD3D *workarounds) const
222*8975f5c5SAndroid Build Coastguard Worker {
223*8975f5c5SAndroid Build Coastguard Worker     if (usesDiscardRewriting)
224*8975f5c5SAndroid Build Coastguard Worker     {
225*8975f5c5SAndroid Build Coastguard Worker         // ANGLE issue 486:
226*8975f5c5SAndroid Build Coastguard Worker         // Work-around a D3D9 compiler bug that presents itself when using conditional discard, by
227*8975f5c5SAndroid Build Coastguard Worker         // disabling optimization
228*8975f5c5SAndroid Build Coastguard Worker         workarounds->skipOptimization = true;
229*8975f5c5SAndroid Build Coastguard Worker     }
230*8975f5c5SAndroid Build Coastguard Worker     else if (usesNestedBreak)
231*8975f5c5SAndroid Build Coastguard Worker     {
232*8975f5c5SAndroid Build Coastguard Worker         // ANGLE issue 603:
233*8975f5c5SAndroid Build Coastguard Worker         // Work-around a D3D9 compiler bug that presents itself when using break in a nested loop,
234*8975f5c5SAndroid Build Coastguard Worker         // by maximizing optimization We want to keep the use of
235*8975f5c5SAndroid Build Coastguard Worker         // ANGLE_D3D_WORKAROUND_MAX_OPTIMIZATION minimal to prevent hangs, so usesDiscard takes
236*8975f5c5SAndroid Build Coastguard Worker         // precedence
237*8975f5c5SAndroid Build Coastguard Worker         workarounds->useMaxOptimization = true;
238*8975f5c5SAndroid Build Coastguard Worker     }
239*8975f5c5SAndroid Build Coastguard Worker 
240*8975f5c5SAndroid Build Coastguard Worker     if (requiresIEEEStrictCompiling)
241*8975f5c5SAndroid Build Coastguard Worker     {
242*8975f5c5SAndroid Build Coastguard Worker         // IEEE Strictness for D3D compiler needs to be enabled for NaNs to work.
243*8975f5c5SAndroid Build Coastguard Worker         workarounds->enableIEEEStrictness = true;
244*8975f5c5SAndroid Build Coastguard Worker     }
245*8975f5c5SAndroid Build Coastguard Worker }
246*8975f5c5SAndroid Build Coastguard Worker 
getUniformRegister(const std::string & uniformName) const247*8975f5c5SAndroid Build Coastguard Worker unsigned int CompiledShaderStateD3D::getUniformRegister(const std::string &uniformName) const
248*8975f5c5SAndroid Build Coastguard Worker {
249*8975f5c5SAndroid Build Coastguard Worker     ASSERT(uniformRegisterMap.count(uniformName) > 0);
250*8975f5c5SAndroid Build Coastguard Worker     return uniformRegisterMap.find(uniformName)->second;
251*8975f5c5SAndroid Build Coastguard Worker }
252*8975f5c5SAndroid Build Coastguard Worker 
getUniformBlockRegister(const std::string & blockName) const253*8975f5c5SAndroid Build Coastguard Worker unsigned int CompiledShaderStateD3D::getUniformBlockRegister(const std::string &blockName) const
254*8975f5c5SAndroid Build Coastguard Worker {
255*8975f5c5SAndroid Build Coastguard Worker     ASSERT(uniformBlockRegisterMap.count(blockName) > 0);
256*8975f5c5SAndroid Build Coastguard Worker     return uniformBlockRegisterMap.find(blockName)->second;
257*8975f5c5SAndroid Build Coastguard Worker }
258*8975f5c5SAndroid Build Coastguard Worker 
shouldUniformBlockUseStructuredBuffer(const std::string & blockName) const259*8975f5c5SAndroid Build Coastguard Worker bool CompiledShaderStateD3D::shouldUniformBlockUseStructuredBuffer(
260*8975f5c5SAndroid Build Coastguard Worker     const std::string &blockName) const
261*8975f5c5SAndroid Build Coastguard Worker {
262*8975f5c5SAndroid Build Coastguard Worker     ASSERT(uniformBlockUseStructuredBufferMap.count(blockName) > 0);
263*8975f5c5SAndroid Build Coastguard Worker     return uniformBlockUseStructuredBufferMap.find(blockName)->second;
264*8975f5c5SAndroid Build Coastguard Worker }
265*8975f5c5SAndroid Build Coastguard Worker 
getShaderStorageBlockRegister(const std::string & blockName) const266*8975f5c5SAndroid Build Coastguard Worker unsigned int CompiledShaderStateD3D::getShaderStorageBlockRegister(
267*8975f5c5SAndroid Build Coastguard Worker     const std::string &blockName) const
268*8975f5c5SAndroid Build Coastguard Worker {
269*8975f5c5SAndroid Build Coastguard Worker     ASSERT(shaderStorageBlockRegisterMap.count(blockName) > 0);
270*8975f5c5SAndroid Build Coastguard Worker     return shaderStorageBlockRegisterMap.find(blockName)->second;
271*8975f5c5SAndroid Build Coastguard Worker }
272*8975f5c5SAndroid Build Coastguard Worker 
useImage2DFunction(const std::string & functionName) const273*8975f5c5SAndroid Build Coastguard Worker bool CompiledShaderStateD3D::useImage2DFunction(const std::string &functionName) const
274*8975f5c5SAndroid Build Coastguard Worker {
275*8975f5c5SAndroid Build Coastguard Worker     if (usedImage2DFunctionNames.empty())
276*8975f5c5SAndroid Build Coastguard Worker     {
277*8975f5c5SAndroid Build Coastguard Worker         return false;
278*8975f5c5SAndroid Build Coastguard Worker     }
279*8975f5c5SAndroid Build Coastguard Worker 
280*8975f5c5SAndroid Build Coastguard Worker     return usedImage2DFunctionNames.find(functionName) != usedImage2DFunctionNames.end();
281*8975f5c5SAndroid Build Coastguard Worker }
282*8975f5c5SAndroid Build Coastguard Worker 
getSlowCompilingUniformBlockSet() const283*8975f5c5SAndroid Build Coastguard Worker const std::set<std::string> &CompiledShaderStateD3D::getSlowCompilingUniformBlockSet() const
284*8975f5c5SAndroid Build Coastguard Worker {
285*8975f5c5SAndroid Build Coastguard Worker     return slowCompilingUniformBlockSet;
286*8975f5c5SAndroid Build Coastguard Worker }
287*8975f5c5SAndroid Build Coastguard Worker 
compile(const gl::Context * context,ShCompileOptions * options)288*8975f5c5SAndroid Build Coastguard Worker std::shared_ptr<ShaderTranslateTask> ShaderD3D::compile(const gl::Context *context,
289*8975f5c5SAndroid Build Coastguard Worker                                                         ShCompileOptions *options)
290*8975f5c5SAndroid Build Coastguard Worker {
291*8975f5c5SAndroid Build Coastguard Worker     // Create a new compiled shader state.  Currently running program link jobs will use the
292*8975f5c5SAndroid Build Coastguard Worker     // previous state.
293*8975f5c5SAndroid Build Coastguard Worker     mCompiledState = std::make_shared<CompiledShaderStateD3D>();
294*8975f5c5SAndroid Build Coastguard Worker 
295*8975f5c5SAndroid Build Coastguard Worker     std::string sourcePath;
296*8975f5c5SAndroid Build Coastguard Worker 
297*8975f5c5SAndroid Build Coastguard Worker     const angle::FeaturesD3D &features = mRenderer->getFeatures();
298*8975f5c5SAndroid Build Coastguard Worker     const gl::Extensions &extensions   = mRenderer->getNativeExtensions();
299*8975f5c5SAndroid Build Coastguard Worker 
300*8975f5c5SAndroid Build Coastguard Worker     const std::string &source = mState.getSource();
301*8975f5c5SAndroid Build Coastguard Worker 
302*8975f5c5SAndroid Build Coastguard Worker #if !defined(ANGLE_ENABLE_WINDOWS_UWP)
303*8975f5c5SAndroid Build Coastguard Worker     if (gl::DebugAnnotationsActive(context))
304*8975f5c5SAndroid Build Coastguard Worker     {
305*8975f5c5SAndroid Build Coastguard Worker         sourcePath = angle::CreateTemporaryFile().value();
306*8975f5c5SAndroid Build Coastguard Worker         writeFile(sourcePath.c_str(), source.c_str(), source.length());
307*8975f5c5SAndroid Build Coastguard Worker         options->lineDirectives = true;
308*8975f5c5SAndroid Build Coastguard Worker         options->sourcePath     = true;
309*8975f5c5SAndroid Build Coastguard Worker     }
310*8975f5c5SAndroid Build Coastguard Worker #endif
311*8975f5c5SAndroid Build Coastguard Worker 
312*8975f5c5SAndroid Build Coastguard Worker     if (features.expandIntegerPowExpressions.enabled)
313*8975f5c5SAndroid Build Coastguard Worker     {
314*8975f5c5SAndroid Build Coastguard Worker         options->expandSelectHLSLIntegerPowExpressions = true;
315*8975f5c5SAndroid Build Coastguard Worker     }
316*8975f5c5SAndroid Build Coastguard Worker 
317*8975f5c5SAndroid Build Coastguard Worker     if (features.getDimensionsIgnoresBaseLevel.enabled)
318*8975f5c5SAndroid Build Coastguard Worker     {
319*8975f5c5SAndroid Build Coastguard Worker         options->HLSLGetDimensionsIgnoresBaseLevel = true;
320*8975f5c5SAndroid Build Coastguard Worker     }
321*8975f5c5SAndroid Build Coastguard Worker 
322*8975f5c5SAndroid Build Coastguard Worker     if (features.preAddTexelFetchOffsets.enabled)
323*8975f5c5SAndroid Build Coastguard Worker     {
324*8975f5c5SAndroid Build Coastguard Worker         options->rewriteTexelFetchOffsetToTexelFetch = true;
325*8975f5c5SAndroid Build Coastguard Worker     }
326*8975f5c5SAndroid Build Coastguard Worker     if (features.rewriteUnaryMinusOperator.enabled)
327*8975f5c5SAndroid Build Coastguard Worker     {
328*8975f5c5SAndroid Build Coastguard Worker         options->rewriteIntegerUnaryMinusOperator = true;
329*8975f5c5SAndroid Build Coastguard Worker     }
330*8975f5c5SAndroid Build Coastguard Worker     if (features.emulateIsnanFloat.enabled)
331*8975f5c5SAndroid Build Coastguard Worker     {
332*8975f5c5SAndroid Build Coastguard Worker         options->emulateIsnanFloatFunction = true;
333*8975f5c5SAndroid Build Coastguard Worker     }
334*8975f5c5SAndroid Build Coastguard Worker     if (features.skipVSConstantRegisterZero.enabled &&
335*8975f5c5SAndroid Build Coastguard Worker         mState.getShaderType() == gl::ShaderType::Vertex)
336*8975f5c5SAndroid Build Coastguard Worker     {
337*8975f5c5SAndroid Build Coastguard Worker         options->skipD3DConstantRegisterZero = true;
338*8975f5c5SAndroid Build Coastguard Worker     }
339*8975f5c5SAndroid Build Coastguard Worker     if (features.forceAtomicValueResolution.enabled)
340*8975f5c5SAndroid Build Coastguard Worker     {
341*8975f5c5SAndroid Build Coastguard Worker         options->forceAtomicValueResolution = true;
342*8975f5c5SAndroid Build Coastguard Worker     }
343*8975f5c5SAndroid Build Coastguard Worker     if (features.allowTranslateUniformBlockToStructuredBuffer.enabled)
344*8975f5c5SAndroid Build Coastguard Worker     {
345*8975f5c5SAndroid Build Coastguard Worker         options->allowTranslateUniformBlockToStructuredBuffer = true;
346*8975f5c5SAndroid Build Coastguard Worker     }
347*8975f5c5SAndroid Build Coastguard Worker     if (extensions.multiviewOVR || extensions.multiview2OVR)
348*8975f5c5SAndroid Build Coastguard Worker     {
349*8975f5c5SAndroid Build Coastguard Worker         options->initializeBuiltinsForInstancedMultiview = true;
350*8975f5c5SAndroid Build Coastguard Worker     }
351*8975f5c5SAndroid Build Coastguard Worker     if (extensions.shaderPixelLocalStorageANGLE)
352*8975f5c5SAndroid Build Coastguard Worker     {
353*8975f5c5SAndroid Build Coastguard Worker         options->pls = mRenderer->getNativePixelLocalStorageOptions();
354*8975f5c5SAndroid Build Coastguard Worker     }
355*8975f5c5SAndroid Build Coastguard Worker 
356*8975f5c5SAndroid Build Coastguard Worker     // D3D11 Feature Level 9_3 and below do not support non-constant loop indexes in fragment
357*8975f5c5SAndroid Build Coastguard Worker     // shaders.  Shader compilation will fail.  To provide a better error message we can instruct
358*8975f5c5SAndroid Build Coastguard Worker     // the compiler to pre-validate.
359*8975f5c5SAndroid Build Coastguard Worker     if (!features.supportsNonConstantLoopIndexing.enabled)
360*8975f5c5SAndroid Build Coastguard Worker     {
361*8975f5c5SAndroid Build Coastguard Worker         options->validateLoopIndexing = true;
362*8975f5c5SAndroid Build Coastguard Worker     }
363*8975f5c5SAndroid Build Coastguard Worker 
364*8975f5c5SAndroid Build Coastguard Worker     // The D3D translations are not currently validation-error-free
365*8975f5c5SAndroid Build Coastguard Worker     options->validateAST = false;
366*8975f5c5SAndroid Build Coastguard Worker 
367*8975f5c5SAndroid Build Coastguard Worker     return std::shared_ptr<ShaderTranslateTask>(
368*8975f5c5SAndroid Build Coastguard Worker         new ShaderTranslateTaskD3D(mCompiledState, std::move(sourcePath)));
369*8975f5c5SAndroid Build Coastguard Worker }
370*8975f5c5SAndroid Build Coastguard Worker 
load(const gl::Context * context,gl::BinaryInputStream * stream)371*8975f5c5SAndroid Build Coastguard Worker std::shared_ptr<ShaderTranslateTask> ShaderD3D::load(const gl::Context *context,
372*8975f5c5SAndroid Build Coastguard Worker                                                      gl::BinaryInputStream *stream)
373*8975f5c5SAndroid Build Coastguard Worker {
374*8975f5c5SAndroid Build Coastguard Worker     UNREACHABLE();
375*8975f5c5SAndroid Build Coastguard Worker     return std::shared_ptr<ShaderTranslateTask>(new ShaderTranslateTask);
376*8975f5c5SAndroid Build Coastguard Worker }
377*8975f5c5SAndroid Build Coastguard Worker 
hasUniform(const std::string & name) const378*8975f5c5SAndroid Build Coastguard Worker bool CompiledShaderStateD3D::hasUniform(const std::string &name) const
379*8975f5c5SAndroid Build Coastguard Worker {
380*8975f5c5SAndroid Build Coastguard Worker     return uniformRegisterMap.find(name) != uniformRegisterMap.end();
381*8975f5c5SAndroid Build Coastguard Worker }
382*8975f5c5SAndroid Build Coastguard Worker 
383*8975f5c5SAndroid Build Coastguard Worker }  // namespace rx
384