|
Lines 10-15
index 6d9040a..c8c9b6c 100644
a/Source/ThirdParty/ANGLE/changes.diff_sec1
|
| 10 |
/tools/clang |
10 |
/tools/clang |
| 11 |
/tools/flex-bison/linux/bison |
11 |
/tools/flex-bison/linux/bison |
| 12 |
/tools/flex-bison/linux/flex |
12 |
/tools/flex-bison/linux/flex |
|
|
13 |
diff --git a/include/GLSLANG/ShaderLang.h b/include/GLSLANG/ShaderLang.h |
| 14 |
index e10d112..6f6a72b 100644 |
| 15 |
--- a/include/GLSLANG/ShaderLang.h |
| 16 |
+++ b/include/GLSLANG/ShaderLang.h |
| 17 |
@@ -73,6 +73,9 @@ enum ShShaderOutput |
| 18 |
// Output specialized GLSL to be fed to glslang for Vulkan SPIR to be cross compiled to Metal |
| 19 |
// later. |
| 20 |
SH_GLSL_METAL_OUTPUT = 0x8B4C, |
| 21 |
+ |
| 22 |
+ // Output for MSL |
| 23 |
+ SH_MSL_METAL_OUTPUT = 0x8B4D, |
| 24 |
}; |
| 25 |
|
| 26 |
// Compile options. |
| 27 |
diff --git a/include/platform/FeaturesMtl.h b/include/platform/FeaturesMtl.h |
| 28 |
index fe5e8ab..9a0bee0 100644 |
| 29 |
--- a/include/platform/FeaturesMtl.h |
| 30 |
+++ b/include/platform/FeaturesMtl.h |
| 31 |
@@ -27,7 +27,7 @@ struct FeaturesMtl : FeatureSetBase |
| 32 |
"The renderer supports depth texture's filtering other than nearest", &members}; |
| 33 |
|
| 34 |
// Support explicit memory barrier |
| 35 |
- Feature hasExplicitMemBarrier = {"has_explicit_mem_barrier_mtl", FeatureCategory::MetalFeatures, |
| 36 |
+ Feature hasExplicitMemBarrier = {"has_explicit_mem_barrier", FeatureCategory::MetalFeatures, |
| 37 |
"The renderer supports explicit memory barrier", &members}; |
| 38 |
|
| 39 |
// Some renderer can break render pass cheaply, i.e. desktop class GPUs. |
| 40 |
@@ -40,7 +40,7 @@ struct FeaturesMtl : FeatureSetBase |
| 41 |
"The renderer supports non uniform compute shader dispatch's group size", &members}; |
| 42 |
|
| 43 |
// fragment stencil output support |
| 44 |
- Feature hasStencilOutput = {"has_shader_stencil_output", FeatureCategory::MetalFeatures, |
| 45 |
+ Feature hasStencilOutput = {"has_stencil_output", FeatureCategory::MetalFeatures, |
| 46 |
"The renderer supports stencil output from fragment shader", |
| 47 |
&members}; |
| 48 |
|
| 49 |
@@ -59,6 +59,10 @@ struct FeaturesMtl : FeatureSetBase |
| 50 |
Feature hasEvents = {"has_mtl_events", FeatureCategory::MetalFeatures, |
| 51 |
"The renderer supports MTL(Shared)Event", &members}; |
| 52 |
|
| 53 |
+ Feature allowInlineConstVertexData = { |
| 54 |
+ "allow_inline_const_vertex_data", FeatureCategory::MetalFeatures, |
| 55 |
+ "The renderer supports using inline constant data for small client vertex data", &members}; |
| 56 |
+ |
| 57 |
// On macos, separate depth & stencil buffers are not supproted. However, on iOS devices, |
| 58 |
// they are supproted: |
| 59 |
Feature allowSeparatedDepthStencilBuffers = { |
| 60 |
@@ -67,6 +71,21 @@ struct FeaturesMtl : FeatureSetBase |
| 61 |
"whereas others such as macOS don't", |
| 62 |
&members}; |
| 63 |
|
| 64 |
+ Feature allowRuntimeSamplerCompareMode = { |
| 65 |
+ "allow_runtime_sampler_compare_mode", FeatureCategory::MetalFeatures, |
| 66 |
+ "The renderer supports changing sampler's compare mode outside shaders", &members}; |
| 67 |
+ |
| 68 |
+ Feature allowSamplerCompareGradient = { |
| 69 |
+ "allow_sampler_compare_gradient", FeatureCategory::MetalFeatures, |
| 70 |
+ "The renderer supports sample_compare with gradients", &members}; |
| 71 |
+ |
| 72 |
+ Feature allowSamplerCompareLod = {"allow_sampler_compare_lod", FeatureCategory::MetalFeatures, |
| 73 |
+ "The renderer supports sample_compare with lod", &members}; |
| 74 |
+ |
| 75 |
+ Feature allowBufferReadWrite = {"allow_buffer_read_write", FeatureCategory::MetalFeatures, |
| 76 |
+ "The renderer supports buffer read & write in the same shader", |
| 77 |
+ &members}; |
| 78 |
+ |
| 79 |
Feature allowMultisampleStoreAndResolve = { |
| 80 |
"allow_msaa_store_and_resolve", FeatureCategory::MetalFeatures, |
| 81 |
"The renderer supports MSAA store and resolve in the same pass", &members}; |
| 82 |
@@ -75,14 +94,27 @@ struct FeaturesMtl : FeatureSetBase |
| 83 |
"gen_multiple_mips_per_pass", FeatureCategory::MetalFeatures, |
| 84 |
"The renderer supports generating multiple mipmaps per pass", &members}; |
| 85 |
|
| 86 |
+ Feature forceD24S8AsUnsupported = {"force_d24s8_as_unsupported", FeatureCategory::MetalFeatures, |
| 87 |
+ "Force Depth24Stencil8 format as unsupported.", &members}; |
| 88 |
+ |
| 89 |
+ Feature breakRenderPassIsCheap = {"break_render_pass_is_cheap", FeatureCategory::MetalFeatures, |
| 90 |
+ "Breaking render pass is a cheap operation", &members}; |
| 91 |
+ |
| 92 |
Feature forceBufferGPUStorage = { |
| 93 |
- "force_buffer_gpu_storage_mtl", FeatureCategory::MetalFeatures, |
| 94 |
- "On systems that support both buffer's memory allocation on GPU and shared memory (such as " |
| 95 |
- "macOS), force using GPU memory allocation for buffers.", |
| 96 |
+ "force_buffer_gpu_storage", FeatureCategory::MetalFeatures, |
| 97 |
+ "On systems that support both buffer' memory allocation on GPU and shared memory (such as " |
| 98 |
+ "macOS), force using GPU memory allocation for buffers everytime or not.", |
| 99 |
&members}; |
| 100 |
|
| 101 |
- Feature forceD24S8AsUnsupported = {"force_d24s8_as_unsupported", FeatureCategory::MetalFeatures, |
| 102 |
- "Force Depth24Stencil8 format as unsupported.", &members}; |
| 103 |
+ Feature forceNonCSBaseMipmapGeneration = { |
| 104 |
+ "force_non_cs_mipmap_gen", FeatureCategory::MetalFeatures, |
| 105 |
+ "Turn this feature on to disallow Compute Shader based mipmap generation. Compute Shader " |
| 106 |
+ "based mipmap generation might cause GPU hang on some older iOS devices.", |
| 107 |
+ &members}; |
| 108 |
+ |
| 109 |
+ Feature emulateTransformFeedback = { |
| 110 |
+ "emulate_transform_feedback", FeatureCategory::MetalFeatures, |
| 111 |
+ "Turn this on to allow transform feedback in Metal using a 2-pass VS for GLES3.", &members}; |
| 112 |
}; |
| 113 |
|
| 114 |
} // namespace angle |
| 115 |
diff --git a/src/common/PoolAlloc.cpp b/src/common/PoolAlloc.cpp |
| 116 |
index 27dd930..3bdcc30 100644 |
| 117 |
--- a/src/common/PoolAlloc.cpp |
| 118 |
+++ b/src/common/PoolAlloc.cpp |
| 119 |
@@ -335,7 +335,7 @@ void PoolAllocator::unlock() |
| 120 |
void Allocation::checkAllocList() const |
| 121 |
{ |
| 122 |
for (const Allocation *alloc = this; alloc != 0; alloc = alloc->mPrevAlloc) |
| 123 |
- alloc->check(); |
| 124 |
+ alloc->checkAlloc(); |
| 125 |
} |
| 126 |
|
| 127 |
} // namespace angle |
| 128 |
diff --git a/src/common/PoolAlloc.h b/src/common/PoolAlloc.h |
| 129 |
index 692992c..cd266a0 100644 |
| 130 |
--- a/src/common/PoolAlloc.h |
| 131 |
+++ b/src/common/PoolAlloc.h |
| 132 |
@@ -65,7 +65,7 @@ class Allocation |
| 133 |
#endif |
| 134 |
} |
| 135 |
|
| 136 |
- void check() const |
| 137 |
+ void checkAlloc() const |
| 138 |
{ |
| 139 |
checkGuardBlock(preGuard(), kGuardBlockBeginVal, "before"); |
| 140 |
checkGuardBlock(postGuard(), kGuardBlockEndVal, "after"); |
| 141 |
diff --git a/src/common/apple_platform_utils.h b/src/common/apple_platform_utils.h |
| 142 |
index 55ebb7a..83ab532 100644 |
| 143 |
--- a/src/common/apple_platform_utils.h |
| 144 |
+++ b/src/common/apple_platform_utils.h |
| 145 |
@@ -15,24 +15,32 @@ |
| 146 |
|
| 147 |
// TARGET_OS_MACCATALYST only available in MacSDK 10.15 |
| 148 |
|
| 149 |
+#if TARGET_OS_MACCATALYST |
| 150 |
// ANGLE_APPLE_AVAILABLE_XCI: check if either of the 3 platforms (OSX/Catalyst/iOS) min verions is |
| 151 |
// available: |
| 152 |
-#if TARGET_OS_MACCATALYST |
| 153 |
# define ANGLE_APPLE_AVAILABLE_XCI(macVer, macCatalystVer, iOSVer) \ |
| 154 |
@available(macOS macVer, macCatalyst macCatalystVer, iOS iOSVer, *) |
| 155 |
// ANGLE_APPLE_AVAILABLE_XC: check if either of the 2 platforms (OSX/Catalyst) min verions is |
| 156 |
// available: |
| 157 |
# define ANGLE_APPLE_AVAILABLE_XC(macVer, macCatalystVer) \ |
| 158 |
@available(macOS macVer, macCatalyst macCatalystVer, *) |
| 159 |
+// ANGLE_APPLE_AVAILABLE_CI: check if either of the 2 platforms (Catalyst/iOS) min verions is |
| 160 |
+// available: |
| 161 |
+# define ANGLE_APPLE_AVAILABLE_CI(macCatalystVer, iOSVer) \ |
| 162 |
+ @available(macCatalyst macCatalystVer, iOS iOSVer, *) |
| 163 |
#else |
| 164 |
# define ANGLE_APPLE_AVAILABLE_XCI(macVer, macCatalystVer, iOSVer) \ |
| 165 |
ANGLE_APPLE_AVAILABLE_XI(macVer, iOSVer) |
| 166 |
-// ANGLE_APPLE_AVAILABLE_XC: check if either of the 2 platforms (OSX/Catalyst) min verions is |
| 167 |
-// available: |
| 168 |
+ |
| 169 |
# define ANGLE_APPLE_AVAILABLE_XC(macVer, macCatalystVer) @available(macOS macVer, *) |
| 170 |
+# define ANGLE_APPLE_AVAILABLE_CI(macCatalystVer, iOSVer) @available(iOS iOSVer, tvOS iOSVer, *) |
| 171 |
#endif |
| 172 |
|
| 173 |
// ANGLE_APPLE_AVAILABLE_XI: check if either of the 2 platforms (OSX/iOS) min verions is available: |
| 174 |
-#define ANGLE_APPLE_AVAILABLE_XI(macVer, iOSVer) @available(macOS macVer, iOS iOSVer, *) |
| 175 |
+#define ANGLE_APPLE_AVAILABLE_XI(macVer, iOSVer) \ |
| 176 |
+ @available(macOS macVer, iOS iOSVer, tvOS iOSVer, *) |
| 177 |
+ |
| 178 |
+// ANGLE_APPLE_AVAILABLE_I: check if a particular iOS version is available |
| 179 |
+#define ANGLE_APPLE_AVAILABLE_I(iOSVer) @available(iOS iOSVer, tvOS iOSVer, *) |
| 180 |
|
| 181 |
#endif |
| 182 |
diff --git a/src/common/debug.h b/src/common/debug.h |
| 183 |
index e0037a4..28170a5 100644 |
| 184 |
--- a/src/common/debug.h |
| 185 |
+++ b/src/common/debug.h |
| 186 |
@@ -314,9 +314,15 @@ std::ostream &FmtHex(std::ostream &os, T value) |
| 187 |
// A macro asserting a condition and outputting failures to the debug log |
| 188 |
#if defined(ANGLE_ENABLE_ASSERTS) |
| 189 |
# define ASSERT(expression) \ |
| 190 |
- (expression ? static_cast<void>(0) \ |
| 191 |
- : (FATAL() << "\t! Assert failed in " << __FUNCTION__ << " (" << __FILE__ \ |
| 192 |
- << ":" << __LINE__ << "): " << #expression)) |
| 193 |
+ do \ |
| 194 |
+ { \ |
| 195 |
+ if (!(expression)) \ |
| 196 |
+ { \ |
| 197 |
+ __builtin_debugtrap(); \ |
| 198 |
+ } \ |
| 199 |
+ int x = 0; /* This forces sane breakpoint location at call site. */ \ |
| 200 |
+ (void)x; \ |
| 201 |
+ } while (false) |
| 202 |
#else |
| 203 |
# define ASSERT(condition) ANGLE_EAT_STREAM_PARAMETERS << !(condition) |
| 204 |
#endif // defined(ANGLE_ENABLE_ASSERTS) |
| 13 |
diff --git a/src/common/gl/cgl/FunctionsCGL.cpp b/src/common/gl/cgl/FunctionsCGL.cpp |
205 |
diff --git a/src/common/gl/cgl/FunctionsCGL.cpp b/src/common/gl/cgl/FunctionsCGL.cpp |
| 14 |
index b57f42b..3e5a37a 100644 |
206 |
index b57f42b..3e5a37a 100644 |
| 15 |
--- a/src/common/gl/cgl/FunctionsCGL.cpp |
207 |
--- a/src/common/gl/cgl/FunctionsCGL.cpp |
|
Lines 34-55
index 9112659..39df6fe 100644
a/Source/ThirdParty/ANGLE/changes.diff_sec2
|
| 34 |
SOFT_LINK_FUNCTION_HEADER(OpenGL, CGLSetCurrentContext, CGLError, (CGLContextObj ctx), (ctx)) |
226 |
SOFT_LINK_FUNCTION_HEADER(OpenGL, CGLSetCurrentContext, CGLError, (CGLContextObj ctx), (ctx)) |
| 35 |
SOFT_LINK_FUNCTION_HEADER(OpenGL, |
227 |
SOFT_LINK_FUNCTION_HEADER(OpenGL, |
| 36 |
CGLSetVirtualScreen, |
228 |
CGLSetVirtualScreen, |
|
|
229 |
diff --git a/src/common/system_utils_ios.mm b/src/common/system_utils_ios.mm |
| 230 |
new file mode 100644 |
| 231 |
index 0000000..a36bea4 |
| 232 |
--- /dev/null |
| 233 |
+++ b/src/common/system_utils_ios.mm |
| 234 |
@@ -0,0 +1,53 @@ |
| 235 |
+// |
| 236 |
+// Copyright 2015 The ANGLE Project Authors. All rights reserved. |
| 237 |
+// Use of this source code is governed by a BSD-style license that can be |
| 238 |
+// found in the LICENSE file. |
| 239 |
+// |
| 240 |
+ |
| 241 |
+// system_utils_ios.mm: Implementation of iOS-specific functions for OSX |
| 242 |
+ |
| 243 |
+#include "system_utils.h" |
| 244 |
+ |
| 245 |
+#include <unistd.h> |
| 246 |
+ |
| 247 |
+#include <CoreServices/CoreServices.h> |
| 248 |
+#include <mach-o/dyld.h> |
| 249 |
+#include <mach/mach.h> |
| 250 |
+#include <mach/mach_time.h> |
| 251 |
+#include <array> |
| 252 |
+#include <cstdlib> |
| 253 |
+#include <vector> |
| 254 |
+ |
| 255 |
+#import <Foundation/Foundation.h> |
| 256 |
+ |
| 257 |
+namespace angle |
| 258 |
+{ |
| 259 |
+std::string GetExecutablePath() |
| 260 |
+{ |
| 261 |
+ |
| 262 |
+ NSString *executableString = [[NSBundle mainBundle] executablePath]; |
| 263 |
+ std::string result([executableString UTF8String]); |
| 264 |
+ return result; |
| 265 |
+} |
| 266 |
+ |
| 267 |
+std::string GetExecutableDirectory() |
| 268 |
+{ |
| 269 |
+ std::string executablePath = GetExecutablePath(); |
| 270 |
+ size_t lastPathSepLoc = executablePath.find_last_of("/"); |
| 271 |
+ return (lastPathSepLoc != std::string::npos) ? executablePath.substr(0, lastPathSepLoc) : ""; |
| 272 |
+} |
| 273 |
+ |
| 274 |
+const char *GetSharedLibraryExtension() |
| 275 |
+{ |
| 276 |
+ return "dylib"; |
| 277 |
+} |
| 278 |
+ |
| 279 |
+double GetCurrentTime() |
| 280 |
+{ |
| 281 |
+ mach_timebase_info_data_t timebaseInfo; |
| 282 |
+ mach_timebase_info(&timebaseInfo); |
| 283 |
+ |
| 284 |
+ double secondCoeff = timebaseInfo.numer * 1e-9 / timebaseInfo.denom; |
| 285 |
+ return secondCoeff * mach_absolute_time(); |
| 286 |
+} |
| 287 |
+} // namespace angle |
| 37 |
diff --git a/src/common/utilities.cpp b/src/common/utilities.cpp |
288 |
diff --git a/src/common/utilities.cpp b/src/common/utilities.cpp |
| 38 |
index c953ff9..63b3a59 100644 |
289 |
index c953ff9..d09e270 100644 |
| 39 |
--- a/src/common/utilities.cpp |
290 |
--- a/src/common/utilities.cpp |
| 40 |
+++ b/src/common/utilities.cpp |
291 |
+++ b/src/common/utilities.cpp |
| 41 |
@@ -6,6 +6,11 @@ |
292 |
@@ -471,6 +471,50 @@ int VariableColumnCount(GLenum type) |
| 42 |
|
|
|
| 43 |
// utilities.cpp: Conversion functions and other utility routines. |
| 44 |
|
293 |
|
| 45 |
+// Older clang versions have a false positive on this warning here. |
294 |
return 0; |
| 46 |
+#if defined(__clang__) |
295 |
} |
| 47 |
+#pragma clang diagnostic ignored "-Wglobal-constructors" |
296 |
+/** |
| 48 |
+#endif |
297 |
+Determine the number of attribute slots used by a variable type |
|
|
298 |
+*/ |
| 299 |
+int VariableAttributeCount(GLenum type) |
| 300 |
+{ |
| 301 |
+ switch (type) |
| 302 |
+ { |
| 303 |
+ case GL_NONE: |
| 304 |
+ return 0; |
| 305 |
+ case GL_BOOL: |
| 306 |
+ case GL_FLOAT: |
| 307 |
+ case GL_INT: |
| 308 |
+ case GL_UNSIGNED_INT: |
| 309 |
+ case GL_BOOL_VEC2: |
| 310 |
+ case GL_FLOAT_VEC2: |
| 311 |
+ case GL_INT_VEC2: |
| 312 |
+ case GL_UNSIGNED_INT_VEC2: |
| 313 |
+ case GL_BOOL_VEC3: |
| 314 |
+ case GL_FLOAT_VEC3: |
| 315 |
+ case GL_INT_VEC3: |
| 316 |
+ case GL_UNSIGNED_INT_VEC3: |
| 317 |
+ case GL_BOOL_VEC4: |
| 318 |
+ case GL_FLOAT_VEC4: |
| 319 |
+ case GL_INT_VEC4: |
| 320 |
+ case GL_UNSIGNED_INT_VEC4: |
| 321 |
+ return 1; |
| 322 |
+ case GL_FLOAT_MAT2: |
| 323 |
+ case GL_FLOAT_MAT2x3: |
| 324 |
+ case GL_FLOAT_MAT2x4: |
| 325 |
+ return 2; |
| 326 |
+ case GL_FLOAT_MAT3: |
| 327 |
+ case GL_FLOAT_MAT3x2: |
| 328 |
+ case GL_FLOAT_MAT3x4: |
| 329 |
+ return 3; |
| 330 |
+ case GL_FLOAT_MAT4: |
| 331 |
+ case GL_FLOAT_MAT4x2: |
| 332 |
+ case GL_FLOAT_MAT4x3: |
| 333 |
+ return 4; |
| 334 |
+ default: |
| 335 |
+ UNREACHABLE(); |
| 336 |
+ } |
| 49 |
+ |
337 |
+ |
| 50 |
#include "common/utilities.h" |
338 |
+ return 0; |
| 51 |
#include "GLES3/gl3.h" |
339 |
+} |
| 52 |
#include "common/mathutil.h" |
340 |
|
|
|
341 |
bool IsSamplerType(GLenum type) |
| 342 |
{ |
| 343 |
diff --git a/src/common/utilities.h b/src/common/utilities.h |
| 344 |
index 0c7d811..ba693a2 100644 |
| 345 |
--- a/src/common/utilities.h |
| 346 |
+++ b/src/common/utilities.h |
| 347 |
@@ -37,6 +37,7 @@ size_t VariableInternalSize(GLenum type); |
| 348 |
size_t VariableExternalSize(GLenum type); |
| 349 |
int VariableRowCount(GLenum type); |
| 350 |
int VariableColumnCount(GLenum type); |
| 351 |
+int VariableAttributeCount(GLenum type); |
| 352 |
bool IsSamplerType(GLenum type); |
| 353 |
bool IsSamplerCubeType(GLenum type); |
| 354 |
bool IsImageType(GLenum type); |
| 53 |
diff --git a/src/compiler/preprocessor/preprocessor_tab_autogen.cpp b/src/compiler/preprocessor/preprocessor_tab_autogen.cpp |
355 |
diff --git a/src/compiler/preprocessor/preprocessor_tab_autogen.cpp b/src/compiler/preprocessor/preprocessor_tab_autogen.cpp |
| 54 |
index 4711774..cf25e48 100644 |
356 |
index 4711774..cf25e48 100644 |
| 55 |
--- a/src/compiler/preprocessor/preprocessor_tab_autogen.cpp |
357 |
--- a/src/compiler/preprocessor/preprocessor_tab_autogen.cpp |
|
Lines 62-299
index 4711774..cf25e48 100644
a/Source/ThirdParty/ANGLE/changes.diff_sec3
|
| 62 |
/* Bison implementation for Yacc-like parsers in C |
364 |
/* Bison implementation for Yacc-like parsers in C |
| 63 |
|
365 |
|
| 64 |
Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2019 Free Software Foundation, |
366 |
Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2019 Free Software Foundation, |
| 65 |
diff --git a/src/compiler/translator/glslang_tab_autogen.cpp b/src/compiler/translator/glslang_tab_autogen.cpp |
367 |
diff --git a/src/compiler/translator/CodeGen.cpp b/src/compiler/translator/CodeGen.cpp |
| 66 |
index 130b98a..33b83db 100644 |
368 |
index a444499..cac9f49 100644 |
| 67 |
--- a/src/compiler/translator/glslang_tab_autogen.cpp |
369 |
--- a/src/compiler/translator/CodeGen.cpp |
| 68 |
+++ b/src/compiler/translator/glslang_tab_autogen.cpp |
370 |
+++ b/src/compiler/translator/CodeGen.cpp |
| 69 |
@@ -1,5 +1,7 @@ |
371 |
@@ -21,8 +21,11 @@ |
| 70 |
/* A Bison parser, made by GNU Bison 3.3.2. */ |
372 |
#endif // ANGLE_ENABLE_VULKAN |
| 71 |
|
373 |
|
| 72 |
+/* Apple Note: For the avoidance of doubt, Apple elects to distribute this file under the terms of the BSD license. */ |
374 |
#ifdef ANGLE_ENABLE_METAL |
|
|
375 |
-# include "compiler/translator/TranslatorMetal.h" |
| 376 |
+# include "compiler/translator/TranslatorMetalDirect.h" |
| 377 |
#endif // ANGLE_ENABLE_METAL |
| 378 |
+#ifdef ANGLE_ENABLE_METAL_SPIRV |
| 379 |
+# include "compiler/translator/TranslatorMetal.h" |
| 380 |
+#endif // ANGLE_ENABLE_METAL_SPIRV |
| 381 |
|
| 382 |
#include "compiler/translator/util.h" |
| 383 |
|
| 384 |
@@ -64,11 +67,17 @@ TCompiler *ConstructCompiler(sh::GLenum type, ShShaderSpec spec, ShShaderOutput |
| 385 |
} |
| 386 |
#endif // ANGLE_ENABLE_VULKAN |
| 387 |
|
| 388 |
-#ifdef ANGLE_ENABLE_METAL |
| 389 |
+#ifdef ANGLE_ENABLE_METAL_SPIRV |
| 390 |
if (IsOutputMetal(output)) |
| 391 |
{ |
| 392 |
return new TranslatorMetal(type, spec); |
| 393 |
} |
| 394 |
+#endif |
| 395 |
+#ifdef ANGLE_ENABLE_METAL |
| 396 |
+ if (IsOutputMetalDirect(output)) |
| 397 |
+ { |
| 398 |
+ return new TranslatorMetalDirect(type, spec, output); |
| 399 |
+ } |
| 400 |
#endif // ANGLE_ENABLE_METAL |
| 401 |
|
| 402 |
// Unsupported compiler or unknown format. Return nullptr per the sh::ConstructCompiler API. |
| 403 |
diff --git a/src/compiler/translator/Common.h b/src/compiler/translator/Common.h |
| 404 |
index 835c90a..1c09cda 100644 |
| 405 |
--- a/src/compiler/translator/Common.h |
| 406 |
+++ b/src/compiler/translator/Common.h |
| 407 |
@@ -31,6 +31,8 @@ struct TSourceLoc |
| 408 |
int last_line; |
| 409 |
}; |
| 410 |
|
| 411 |
+constexpr TSourceLoc kNoSourceLoc{-1, -1, -1, -1}; |
| 73 |
+ |
412 |
+ |
| 74 |
/* Bison implementation for Yacc-like parsers in C |
413 |
// |
|
|
414 |
// Put POOL_ALLOCATOR_NEW_DELETE in base classes to make them use this scheme. |
| 415 |
// |
| 416 |
diff --git a/src/compiler/translator/Compiler.cpp b/src/compiler/translator/Compiler.cpp |
| 417 |
index 34d8e12..9316e2e 100644 |
| 418 |
--- a/src/compiler/translator/Compiler.cpp |
| 419 |
+++ b/src/compiler/translator/Compiler.cpp |
| 420 |
@@ -722,7 +722,7 @@ bool TCompiler::checkAndSimplifyAST(TIntermBlock *root, |
| 421 |
} |
| 422 |
} |
| 75 |
|
423 |
|
| 76 |
Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2019 Free Software Foundation, |
424 |
- int simplifyScalarized = (compileOptions & SH_SCALARIZE_VEC_AND_MAT_CONSTRUCTOR_ARGS) |
| 77 |
diff --git a/src/compiler/translator/glslang_tab_autogen.h b/src/compiler/translator/glslang_tab_autogen.h |
425 |
+ unsigned int simplifyScalarized = (compileOptions & SH_SCALARIZE_VEC_AND_MAT_CONSTRUCTOR_ARGS) |
| 78 |
index 5306032..0250300 100644 |
426 |
? IntermNodePatternMatcher::kScalarizedVecOrMatConstructor |
| 79 |
--- a/src/compiler/translator/glslang_tab_autogen.h |
427 |
: 0; |
| 80 |
+++ b/src/compiler/translator/glslang_tab_autogen.h |
|
|
| 81 |
@@ -1,5 +1,7 @@ |
| 82 |
/* A Bison parser, made by GNU Bison 3.3.2. */ |
| 83 |
|
428 |
|
| 84 |
+/* Apple Note: For the avoidance of doubt, Apple elects to distribute this file under the terms of the BSD license. */ |
429 |
diff --git a/src/compiler/translator/Compiler.h b/src/compiler/translator/Compiler.h |
|
|
430 |
index d0b24ba..043ddd5 100644 |
| 431 |
--- a/src/compiler/translator/Compiler.h |
| 432 |
+++ b/src/compiler/translator/Compiler.h |
| 433 |
@@ -35,6 +35,9 @@ class TParseContext; |
| 434 |
#ifdef ANGLE_ENABLE_HLSL |
| 435 |
class TranslatorHLSL; |
| 436 |
#endif // ANGLE_ENABLE_HLSL |
| 437 |
+#ifdef ANGLE_ENABLE_METAL |
| 438 |
+class TranslatorMetalDirect; |
| 439 |
+#endif // ANGLE_ENABLE_METAL |
| 440 |
|
| 441 |
// |
| 442 |
// Helper function to check if the shader type is GLSL. |
| 443 |
@@ -63,6 +66,9 @@ class TShHandleBase |
| 444 |
#ifdef ANGLE_ENABLE_HLSL |
| 445 |
virtual TranslatorHLSL *getAsTranslatorHLSL() { return 0; } |
| 446 |
#endif // ANGLE_ENABLE_HLSL |
| 447 |
+#ifdef ANGLE_ENABLE_METAL |
| 448 |
+ virtual TranslatorMetalDirect *getAsTranslatorMetalDirect() { return nullptr; } |
| 449 |
+#endif // ANGLE_ENABLE_METAL |
| 450 |
|
| 451 |
protected: |
| 452 |
// Memory allocator. Allocates and tracks memory required by the compiler. |
| 453 |
diff --git a/src/compiler/translator/ConstantUnion.cpp b/src/compiler/translator/ConstantUnion.cpp |
| 454 |
index 0335171..104affb 100644 |
| 455 |
--- a/src/compiler/translator/ConstantUnion.cpp |
| 456 |
+++ b/src/compiler/translator/ConstantUnion.cpp |
| 457 |
@@ -67,11 +67,15 @@ bool IsValidShiftOffset(const TConstantUnion &rhs) |
| 458 |
|
| 459 |
} // anonymous namespace |
| 460 |
|
| 461 |
-TConstantUnion::TConstantUnion() |
| 462 |
-{ |
| 463 |
- iConst = 0; |
| 464 |
- type = EbtVoid; |
| 465 |
-} |
| 466 |
+TConstantUnion::TConstantUnion() : iConst(0), type(EbtVoid) {} |
| 85 |
+ |
467 |
+ |
| 86 |
/* Bison interface for Yacc-like parsers in C |
468 |
+TConstantUnion::TConstantUnion(int i) : iConst(i), type(EbtInt) {} |
|
|
469 |
+ |
| 470 |
+TConstantUnion::TConstantUnion(unsigned int u) : uConst(u), type(EbtUInt) {} |
| 471 |
+ |
| 472 |
+TConstantUnion::TConstantUnion(float f) : fConst(f), type(EbtFloat) {} |
| 473 |
+ |
| 474 |
+TConstantUnion::TConstantUnion(bool b) : bConst(b), type(EbtBool) {} |
| 87 |
|
475 |
|
| 88 |
Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2019 Free Software Foundation, |
476 |
int TConstantUnion::getIConst() const |
| 89 |
diff --git a/src/gpu_info_util/SystemInfo.cpp b/src/gpu_info_util/SystemInfo.cpp |
477 |
{ |
| 90 |
index f748949..54c3db5 100644 |
478 |
diff --git a/src/compiler/translator/ConstantUnion.h b/src/compiler/translator/ConstantUnion.h |
| 91 |
--- a/src/gpu_info_util/SystemInfo.cpp |
479 |
index a623d65..df53857 100644 |
| 92 |
+++ b/src/gpu_info_util/SystemInfo.cpp |
480 |
--- a/src/compiler/translator/ConstantUnion.h |
| 93 |
@@ -47,6 +47,8 @@ std::string VendorName(VendorID vendor) |
481 |
+++ b/src/compiler/translator/ConstantUnion.h |
| 94 |
return "Vivante"; |
482 |
@@ -20,6 +20,10 @@ class TConstantUnion |
| 95 |
case kVendorID_VMWare: |
483 |
public: |
| 96 |
return "VMWare"; |
484 |
POOL_ALLOCATOR_NEW_DELETE |
| 97 |
+ case kVendorID_Apple: |
485 |
TConstantUnion(); |
| 98 |
+ return "Apple"; |
486 |
+ TConstantUnion(int i); |
| 99 |
default: |
487 |
+ TConstantUnion(unsigned int u); |
| 100 |
return "Unknown (" + std::to_string(vendor) + ")"; |
488 |
+ TConstantUnion(float f); |
|
|
489 |
+ TConstantUnion(bool b); |
| 490 |
|
| 491 |
bool cast(TBasicType newType, const TConstantUnion &constant); |
| 492 |
|
| 493 |
diff --git a/src/compiler/translator/IntermNode.cpp b/src/compiler/translator/IntermNode.cpp |
| 494 |
index bbdf866..5136d20 100644 |
| 495 |
--- a/src/compiler/translator/IntermNode.cpp |
| 496 |
+++ b/src/compiler/translator/IntermNode.cpp |
| 497 |
@@ -41,7 +41,7 @@ TPrecision GetHigherPrecision(TPrecision left, TPrecision right) |
| 498 |
TConstantUnion *Vectorize(const TConstantUnion &constant, size_t size) |
| 499 |
{ |
| 500 |
TConstantUnion *constUnion = new TConstantUnion[size]; |
| 501 |
- for (unsigned int i = 0; i < size; ++i) |
| 502 |
+ for (size_t i = 0; i < size; ++i) |
| 503 |
constUnion[i] = constant; |
| 504 |
|
| 505 |
return constUnion; |
| 506 |
@@ -415,6 +415,14 @@ TIntermBlock::TIntermBlock(const TIntermBlock &node) |
| 101 |
} |
507 |
} |
| 102 |
@@ -160,6 +162,11 @@ bool IsVivante(VendorID vendorId) |
|
|
| 103 |
return vendorId == kVendorID_Vivante; |
| 104 |
} |
508 |
} |
| 105 |
|
509 |
|
| 106 |
+bool IsApple(VendorID vendorId) |
510 |
+TIntermBlock::TIntermBlock(std::initializer_list<TIntermNode *> stmts) |
| 107 |
+{ |
511 |
+{ |
| 108 |
+ return vendorId == kVendorID_Apple; |
512 |
+ for (TIntermNode *stmt : stmts) |
|
|
513 |
+ { |
| 514 |
+ appendStatement(stmt); |
| 515 |
+ } |
| 109 |
+} |
516 |
+} |
| 110 |
+ |
517 |
+ |
| 111 |
bool ParseAMDBrahmaDriverVersion(const std::string &content, std::string *version) |
518 |
size_t TIntermBlock::getChildCount() const |
| 112 |
{ |
519 |
{ |
| 113 |
const size_t begin = content.find_first_of("0123456789"); |
520 |
return mStatements.size(); |
| 114 |
diff --git a/src/gpu_info_util/SystemInfo.h b/src/gpu_info_util/SystemInfo.h |
521 |
@@ -446,6 +454,37 @@ bool TIntermFunctionPrototype::replaceChildNode(TIntermNode *original, TIntermNo |
| 115 |
index ad17698..509a1e9 100644 |
522 |
return false; |
| 116 |
--- a/src/gpu_info_util/SystemInfo.h |
523 |
} |
| 117 |
+++ b/src/gpu_info_util/SystemInfo.h |
|
|
| 118 |
@@ -67,9 +67,8 @@ struct SystemInfo |
| 119 |
bool isAMDSwitchable = false; |
| 120 |
// Only true on dual-GPU Mac laptops. |
| 121 |
bool isMacSwitchable = false; |
| 122 |
- // Only true on Apple Silicon Macs when running iOS binaries. |
| 123 |
- // See https://developer.apple.com/documentation/foundation/nsprocessinfo/3608556-iosapponmac |
| 124 |
- bool isiOSAppOnMac = false; |
| 125 |
+ // Only true on Apple Silicon Macs when running in macCatalyst. |
| 126 |
+ bool needsEAGLOnMac = false; |
| 127 |
|
| 128 |
// Only available on Android |
| 129 |
std::string machineManufacturer; |
| 130 |
@@ -99,6 +98,7 @@ constexpr VendorID kVendorID_Intel = 0x8086; |
| 131 |
constexpr VendorID kVendorID_NVIDIA = 0x10DE; |
| 132 |
constexpr VendorID kVendorID_Qualcomm = 0x5143; |
| 133 |
constexpr VendorID kVendorID_VMWare = 0x15ad; |
| 134 |
+constexpr VendorID kVendorID_Apple = 0x106B; |
| 135 |
|
| 136 |
// Known non-PCI (i.e. Khronos-registered) vendor IDs |
| 137 |
constexpr VendorID kVendorID_Vivante = 0x10001; |
| 138 |
@@ -124,6 +124,7 @@ bool IsSwiftshader(VendorID vendorId); |
| 139 |
bool IsVeriSilicon(VendorID vendorId); |
| 140 |
bool IsVMWare(VendorID vendorId); |
| 141 |
bool IsVivante(VendorID vendorId); |
| 142 |
+bool IsApple(VendorID vendorId); |
| 143 |
|
524 |
|
| 144 |
// Use a heuristic to attempt to find the GPU used for 3D graphics. Sets activeGPUIndex, |
525 |
+TIntermDeclaration::TIntermDeclaration(const TVariable *var, TIntermTyped *initExpr) |
| 145 |
// isOptimus, and isAMDSwitchable. |
526 |
+{ |
| 146 |
diff --git a/src/gpu_info_util/SystemInfo_apple.mm b/src/gpu_info_util/SystemInfo_apple.mm |
527 |
+ if (initExpr) |
| 147 |
index c7756f6..a49dc52 100644 |
528 |
+ { |
| 148 |
--- a/src/gpu_info_util/SystemInfo_apple.mm |
529 |
+ appendDeclarator( |
| 149 |
+++ b/src/gpu_info_util/SystemInfo_apple.mm |
530 |
+ new TIntermBinary(TOperator::EOpInitialize, new TIntermSymbol(var), initExpr)); |
| 150 |
@@ -19,25 +19,7 @@ namespace angle |
531 |
+ } |
|
|
532 |
+ else |
| 533 |
+ { |
| 534 |
+ appendDeclarator(new TIntermSymbol(var)); |
| 535 |
+ } |
| 536 |
+} |
| 537 |
+ |
| 538 |
+TIntermDeclaration::TIntermDeclaration(std::initializer_list<const TVariable *> declarators) |
| 539 |
+ : TIntermDeclaration() |
| 540 |
+{ |
| 541 |
+ for (auto *d : declarators) |
| 542 |
+ { |
| 543 |
+ appendDeclarator(new TIntermSymbol(d)); |
| 544 |
+ } |
| 545 |
+} |
| 546 |
+ |
| 547 |
+TIntermDeclaration::TIntermDeclaration(std::initializer_list<TIntermTyped *> declarators) |
| 548 |
+ : TIntermDeclaration() |
| 549 |
+{ |
| 550 |
+ for (auto *d : declarators) |
| 551 |
+ { |
| 552 |
+ appendDeclarator(d); |
| 553 |
+ } |
| 554 |
+} |
| 555 |
+ |
| 556 |
size_t TIntermDeclaration::getChildCount() const |
| 557 |
{ |
| 558 |
return mDeclarators.size(); |
| 559 |
@@ -463,9 +502,10 @@ bool TIntermDeclaration::replaceChildNode(TIntermNode *original, TIntermNode *re |
| 151 |
|
560 |
|
| 152 |
bool GetSystemInfo(SystemInfo *info) |
561 |
bool TIntermAggregateBase::replaceChildNodeInternal(TIntermNode *original, TIntermNode *replacement) |
| 153 |
{ |
562 |
{ |
| 154 |
-# if defined(ANGLE_PLATFORM_MACCATALYST) && defined(ANGLE_CPU_ARM64) |
563 |
- for (size_t ii = 0; ii < getSequence()->size(); ++ii) |
| 155 |
- static bool isiOSAppOnMac = false; |
564 |
+ auto &seq = *getSequence(); |
| 156 |
- static dispatch_once_t once; |
565 |
+ for (auto *&node : seq) |
| 157 |
- dispatch_once(&once, ^{ |
566 |
{ |
| 158 |
- isiOSAppOnMac = [[NSProcessInfo processInfo] isiOSAppOnMac]; |
567 |
- REPLACE_IF_IS((*getSequence())[ii], TIntermNode, original, replacement); |
| 159 |
- }); |
568 |
+ REPLACE_IF_IS(node, TIntermNode, original, replacement); |
| 160 |
- |
569 |
} |
| 161 |
- if (isiOSAppOnMac) |
570 |
return false; |
| 162 |
- { |
571 |
} |
| 163 |
- GetSystemInfo_ios(info); |
572 |
@@ -473,12 +513,13 @@ bool TIntermAggregateBase::replaceChildNodeInternal(TIntermNode *original, TInte |
| 164 |
- if (info) |
573 |
bool TIntermAggregateBase::replaceChildNodeWithMultiple(TIntermNode *original, |
| 165 |
- { |
574 |
const TIntermSequence &replacements) |
| 166 |
- info->isiOSAppOnMac = true; |
|
|
| 167 |
- } |
| 168 |
- return info; |
| 169 |
- } |
| 170 |
- |
| 171 |
- return GetSystemInfo_mac(info); |
| 172 |
-# elif defined(ANGLE_PLATFORM_MACOS) || defined(ANGLE_PLATFORM_MACCATALYST) |
| 173 |
+#if defined(ANGLE_PLATFORM_MACOS) || defined(ANGLE_PLATFORM_MACCATALYST) |
| 174 |
return GetSystemInfo_mac(info); |
| 175 |
# else |
| 176 |
return GetSystemInfo_ios(info); |
| 177 |
diff --git a/src/gpu_info_util/SystemInfo_ios.cpp b/src/gpu_info_util/SystemInfo_ios.cpp |
| 178 |
index 323af2c..e52ecb3 100644 |
| 179 |
--- a/src/gpu_info_util/SystemInfo_ios.cpp |
| 180 |
+++ b/src/gpu_info_util/SystemInfo_ios.cpp |
| 181 |
@@ -18,8 +18,9 @@ namespace angle |
| 182 |
bool GetSystemInfo_ios(SystemInfo *info) |
| 183 |
{ |
575 |
{ |
|
|
576 |
- for (auto it = getSequence()->begin(); it < getSequence()->end(); ++it) |
| 577 |
+ auto &seq = *getSequence(); |
| 578 |
+ for (auto it = seq.begin(); it < seq.end(); ++it) |
| 184 |
{ |
579 |
{ |
| 185 |
- // TODO(anglebug.com/4275): Get the actual system version. |
580 |
if (*it == original) |
| 186 |
+ // TODO(anglebug.com/4275): Get the actual system version and GPU info. |
581 |
{ |
| 187 |
info->machineModelVersion = "0.0"; |
582 |
- it = getSequence()->erase(it); |
| 188 |
+ info->gpus.emplace_back().vendorId = kVendorID_Apple; |
583 |
- getSequence()->insert(it, replacements.begin(), replacements.end()); |
|
|
584 |
+ it = seq.erase(it); |
| 585 |
+ seq.insert(it, replacements.begin(), replacements.end()); |
| 586 |
return true; |
| 587 |
} |
| 189 |
} |
588 |
} |
| 190 |
|
589 |
@@ -488,12 +529,13 @@ bool TIntermAggregateBase::replaceChildNodeWithMultiple(TIntermNode *original, |
| 191 |
return true; |
590 |
bool TIntermAggregateBase::insertChildNodes(TIntermSequence::size_type position, |
| 192 |
diff --git a/src/gpu_info_util/SystemInfo_macos.mm b/src/gpu_info_util/SystemInfo_macos.mm |
591 |
const TIntermSequence &insertions) |
| 193 |
index b1cd055..c5e039e 100644 |
592 |
{ |
| 194 |
--- a/src/gpu_info_util/SystemInfo_macos.mm |
593 |
- if (position > getSequence()->size()) |
| 195 |
+++ b/src/gpu_info_util/SystemInfo_macos.mm |
594 |
+ auto &seq = *getSequence(); |
| 196 |
@@ -322,6 +322,10 @@ bool GetSystemInfo_mac(SystemInfo *info) |
595 |
+ if (position > seq.size()) |
| 197 |
info->isMacSwitchable = true; |
596 |
{ |
|
|
597 |
return false; |
| 198 |
} |
598 |
} |
| 199 |
|
599 |
- auto it = getSequence()->begin() + position; |
| 200 |
+#if defined(ANGLE_PLATFORM_MACCATALYST) && defined(ANGLE_CPU_ARM64) |
600 |
- getSequence()->insert(it, insertions.begin(), insertions.end()); |
| 201 |
+ info->needsEAGLOnMac = true; |
601 |
+ auto it = seq.begin() + position; |
| 202 |
+#endif |
602 |
+ seq.insert(it, insertions.begin(), insertions.end()); |
| 203 |
+ |
|
|
| 204 |
return true; |
603 |
return true; |
| 205 |
} |
604 |
} |
| 206 |
|
605 |
|
| 207 |
diff --git a/src/libANGLE/Caps.cpp b/src/libANGLE/Caps.cpp |
606 |
@@ -1040,8 +1082,8 @@ TIntermAggregate::TIntermAggregate(const TIntermAggregate &node) |
| 208 |
index f906783..1dddd4d 100644 |
|
|
| 209 |
--- a/src/libANGLE/Caps.cpp |
| 210 |
+++ b/src/libANGLE/Caps.cpp |
| 211 |
@@ -630,7 +630,12 @@ static bool DetermineDepthTextureANGLESupport(const TextureCapsMap &textureCaps) |
| 212 |
{ |
| 213 |
constexpr GLenum requiredFormats[] = { |
| 214 |
GL_DEPTH_COMPONENT16, |
| 215 |
+#if !defined(ANGLE_PLATFORM_IOS) && (!defined(ANGLE_PLATFORM_MACCATALYST) || !defined(ANGLE_CPU_ARM64)) |
| 216 |
+ // TODO(dino): Temporarily Removing the need for GL_DEPTH_COMPONENT32_OES |
| 217 |
+ // because it is not supported on iOS. |
| 218 |
+ // TODO(dino): I think this needs to be a runtime check when running an iOS app on Mac. |
| 219 |
GL_DEPTH_COMPONENT32_OES, |
| 220 |
+#endif |
| 221 |
GL_DEPTH24_STENCIL8_OES, |
| 222 |
}; |
| 223 |
|
607 |
|
| 224 |
@@ -642,7 +647,12 @@ static bool DetermineDepthTextureOESSupport(const TextureCapsMap &textureCaps) |
608 |
TIntermAggregate *TIntermAggregate::shallowCopy() const |
| 225 |
{ |
609 |
{ |
| 226 |
constexpr GLenum requiredFormats[] = { |
610 |
- TIntermSequence *copySeq = new TIntermSequence(); |
| 227 |
GL_DEPTH_COMPONENT16, |
611 |
- copySeq->insert(copySeq->begin(), getSequence()->begin(), getSequence()->end()); |
| 228 |
+#if !defined(ANGLE_PLATFORM_IOS) && (!defined(ANGLE_PLATFORM_MACCATALYST) || !defined(ANGLE_CPU_ARM64)) |
612 |
+ auto &seq = *getSequence(); |
| 229 |
+ // TODO(dino): Temporarily Removing the need for GL_DEPTH_COMPONENT32_OES |
613 |
+ TIntermSequence *copySeq = new TIntermSequence(seq.begin(), seq.end()); |
| 230 |
+ // because it is not supported on iOS. |
614 |
TIntermAggregate *copyNode = new TIntermAggregate(mFunction, mType, mOp, copySeq); |
| 231 |
+ // TODO(dino): I think this needs to be a runtime check when running an iOS app on Mac. |
615 |
copyNode->setLine(mLine); |
| 232 |
GL_DEPTH_COMPONENT32_OES, |
616 |
return copyNode; |
| 233 |
+#endif |
617 |
diff --git a/src/compiler/translator/IntermNode.h b/src/compiler/translator/IntermNode.h |
| 234 |
}; |
618 |
index 3643847..3b6f872 100644 |
|
|
619 |
--- a/src/compiler/translator/IntermNode.h |
| 620 |
+++ b/src/compiler/translator/IntermNode.h |
| 621 |
@@ -674,6 +674,7 @@ class TIntermBlock : public TIntermNode, public TIntermAggregateBase |
| 622 |
{ |
| 623 |
public: |
| 624 |
TIntermBlock() : TIntermNode() {} |
| 625 |
+ TIntermBlock(std::initializer_list<TIntermNode *> stmts); |
| 626 |
~TIntermBlock() override {} |
| 235 |
|
627 |
|
| 236 |
return GetFormatSupport(textureCaps, requiredFormats, true, true, true, true, false); |
628 |
TIntermBlock *getAsBlock() override { return this; } |
| 237 |
diff --git a/src/libANGLE/State.cpp b/src/libANGLE/State.cpp |
629 |
@@ -776,6 +777,9 @@ class TIntermDeclaration : public TIntermNode, public TIntermAggregateBase |
| 238 |
index 7b08d8d..a804486 100644 |
630 |
{ |
| 239 |
--- a/src/libANGLE/State.cpp |
631 |
public: |
| 240 |
+++ b/src/libANGLE/State.cpp |
632 |
TIntermDeclaration() : TIntermNode() {} |
| 241 |
@@ -6,6 +6,9 @@ |
633 |
+ TIntermDeclaration(const TVariable *var, TIntermTyped *initExpr); |
|
|
634 |
+ TIntermDeclaration(std::initializer_list<const TVariable *> declarators); |
| 635 |
+ TIntermDeclaration(std::initializer_list<TIntermTyped *> declarators); |
| 636 |
~TIntermDeclaration() override {} |
| 242 |
|
637 |
|
| 243 |
// State.cpp: Implements the State class, encapsulating raw GL state. |
638 |
TIntermDeclaration *getAsDeclarationNode() override { return this; } |
|
|
639 |
diff --git a/src/compiler/translator/Symbol.cpp b/src/compiler/translator/Symbol.cpp |
| 640 |
index d0389af..fe2e19b 100644 |
| 641 |
--- a/src/compiler/translator/Symbol.cpp |
| 642 |
+++ b/src/compiler/translator/Symbol.cpp |
| 643 |
@@ -196,7 +196,8 @@ void TFunction::shareParameters(const TFunction ¶metersSource) |
| 244 |
|
644 |
|
| 245 |
+// Older clang versions have a false positive on this warning here. |
645 |
ImmutableString TFunction::buildMangledName() const |
| 246 |
+#pragma clang diagnostic ignored "-Wglobal-constructors" |
646 |
{ |
| 247 |
+ |
647 |
- std::string newName(name().data(), name().length()); |
| 248 |
#include "libANGLE/State.h" |
648 |
+ ImmutableString name = this->name(); |
|
|
649 |
+ std::string newName(name.data(), name.length()); |
| 650 |
newName += kFunctionMangledNameSeparator; |
| 249 |
|
651 |
|
| 250 |
#include <string.h> |
652 |
for (size_t i = 0u; i < mParamCount; ++i) |
| 251 |
diff --git a/src/libANGLE/formatutils.cpp b/src/libANGLE/formatutils.cpp |
653 |
diff --git a/src/compiler/translator/Symbol.h b/src/compiler/translator/Symbol.h |
| 252 |
index 3f9f37d..5e628f2 100644 |
654 |
index b9cf908..0abb1d4 100644 |
| 253 |
--- a/src/libANGLE/formatutils.cpp |
655 |
--- a/src/compiler/translator/Symbol.h |
| 254 |
+++ b/src/libANGLE/formatutils.cpp |
656 |
+++ b/src/compiler/translator/Symbol.h |
| 255 |
@@ -1034,7 +1034,7 @@ static InternalFormatInfoMap BuildInternalFormatInfoMap() |
657 |
@@ -222,7 +222,7 @@ class TFunction : public TSymbol |
| 256 |
angle::SystemInfo info; |
658 |
TOperator getBuiltInOp() const { return mOp; } |
| 257 |
if (angle::GetSystemInfo(&info)) |
|
|
| 258 |
{ |
| 259 |
- if (info.isiOSAppOnMac) |
| 260 |
+ if (info.needsEAGLOnMac) |
| 261 |
{ |
| 262 |
// Using OpenGLES.framework. |
| 263 |
AddRGBAFormat(&map, GL_BGRA_EXT, false, 8, 8, 8, 8, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireES<2, 0>, AlwaysSupported, RequireES<2, 0>, NeverSupported, NeverSupported); |
| 264 |
diff --git a/src/libANGLE/renderer/gl/apple/DisplayApple_api.cpp b/src/libANGLE/renderer/gl/apple/DisplayApple_api.cpp |
| 265 |
index de216fb..e63a8b6 100644 |
| 266 |
--- a/src/libANGLE/renderer/gl/apple/DisplayApple_api.cpp |
| 267 |
+++ b/src/libANGLE/renderer/gl/apple/DisplayApple_api.cpp |
| 268 |
@@ -37,7 +37,7 @@ DisplayImpl *CreateDisplayCGLOrEAGL(const egl::DisplayState &state) |
| 269 |
break; |
| 270 |
} |
| 271 |
|
659 |
|
| 272 |
- if (info.isiOSAppOnMac) |
660 |
void setDefined() { defined = true; } |
| 273 |
+ if (info.needsEAGLOnMac) |
661 |
- bool isDefined() { return defined; } |
| 274 |
{ |
662 |
+ bool isDefined() const { return defined; } |
| 275 |
return new rx::DisplayEAGL(state); |
663 |
void setHasPrototypeDeclaration() { mHasPrototypeDeclaration = true; } |
| 276 |
} |
664 |
bool hasPrototypeDeclaration() const { return mHasPrototypeDeclaration; } |
| 277 |
diff --git a/src/libANGLE/renderer/gl/cgl/ContextCGL.cpp b/src/libANGLE/renderer/gl/cgl/ContextCGL.cpp |
|
|
| 278 |
index bdf5597..be99b85 100644 |
| 279 |
--- a/src/libANGLE/renderer/gl/cgl/ContextCGL.cpp |
| 280 |
+++ b/src/libANGLE/renderer/gl/cgl/ContextCGL.cpp |
| 281 |
@@ -13,6 +13,8 @@ |
| 282 |
#include "libANGLE/Display.h" |
| 283 |
#include "libANGLE/renderer/gl/cgl/DisplayCGL.h" |
| 284 |
|
665 |
|
| 285 |
+#if defined(ANGLE_PLATFORM_MACOS) || defined(ANGLE_PLATFORM_MACCATALYST) |
666 |
diff --git a/src/compiler/translator/TranslatorMetal.cpp b/src/compiler/translator/TranslatorMetal.cpp |
| 286 |
+ |
667 |
index a1fcf8c..ea566b1 100644 |
| 287 |
namespace rx |
668 |
--- a/src/compiler/translator/TranslatorMetal.cpp |
|
|
669 |
+++ b/src/compiler/translator/TranslatorMetal.cpp |
| 670 |
@@ -41,8 +41,14 @@ const char kRasterizerDiscardEnabledConstName[] = "ANGLERasterizerDisabled"; |
| 671 |
namespace |
| 288 |
{ |
672 |
{ |
| 289 |
|
673 |
|
| 290 |
@@ -63,3 +65,5 @@ void ContextCGL::onDestroy(const gl::Context *context) |
674 |
+constexpr ImmutableString kRasterizationDiscardEnabledConstName = |
|
|
675 |
+ ImmutableString("ANGLERasterizationDisabled"); |
| 676 |
+constexpr ImmutableString kCoverageMaskEnabledConstName = |
| 677 |
+ ImmutableString("ANGLECoverageMaskEnabled"); |
| 678 |
constexpr ImmutableString kCoverageMaskField = ImmutableString("coverageMask"); |
| 679 |
+constexpr ImmutableString kEmuInstanceIDField = ImmutableString("emulatedInstanceID"); |
| 680 |
constexpr ImmutableString kSampleMaskWriteFuncName = ImmutableString("ANGLEWriteSampleMask"); |
| 681 |
+constexpr ImmutableString kDiscardWrapperFuncName = ImmutableString("ANGLEDiscardWrapper"); |
| 682 |
|
| 683 |
TIntermBinary *CreateDriverUniformRef(const TVariable *driverUniforms, const char *fieldName) |
| 684 |
{ |
| 685 |
@@ -86,6 +92,21 @@ ANGLE_NO_DISCARD bool AppendVertexShaderPositionYCorrectionToMain(TCompiler *com |
| 686 |
return RunAtTheEndOfShader(compiler, root, assignment, symbolTable); |
| 291 |
} |
687 |
} |
| 292 |
|
688 |
|
| 293 |
} // namespace rx |
689 |
+ANGLE_NO_DISCARD bool EmulateInstanceID(TCompiler *compiler, |
|
|
690 |
+ TIntermBlock *root, |
| 691 |
+ TSymbolTable *symbolTable, |
| 692 |
+ const TVariable *driverUniforms) |
| 693 |
+{ |
| 694 |
+ // emuInstanceID |
| 695 |
+ TIntermBinary *emuInstanceID = |
| 696 |
+ CreateDriverUniformRef(driverUniforms, kEmuInstanceIDField.data()); |
| 294 |
+ |
697 |
+ |
| 295 |
+#endif // defined(ANGLE_PLATFORM_MACOS) || defined(ANGLE_PLATFORM_MACCATALYST) |
698 |
+ // Create a symbol reference to "gl_InstanceIndex" |
| 296 |
\ No newline at end of file |
699 |
+ const TVariable *instanceID = BuiltInVariable::gl_InstanceIndex(); |
|
|
700 |
+ |
| 701 |
+ return ReplaceVariableWithTyped(compiler, root, instanceID, emuInstanceID); |
| 702 |
+} |
| 703 |
+ |
| 704 |
// Initialize unused varying outputs. |
| 705 |
ANGLE_NO_DISCARD bool InitializeUnusedOutputs(TIntermBlock *root, |
| 706 |
TSymbolTable *symbolTable, |
| 707 |
@@ -123,6 +144,18 @@ ANGLE_NO_DISCARD bool InitializeUnusedOutputs(TIntermBlock *root, |
| 708 |
|
| 709 |
} // anonymous namespace |
| 710 |
|
| 711 |
+/** static */ |
| 712 |
+const char *TranslatorMetal::GetCoverageMaskEnabledConstName() |
| 713 |
+{ |
| 714 |
+ return kCoverageMaskEnabledConstName.data(); |
| 715 |
+} |
| 716 |
+ |
| 717 |
+/** static */ |
| 718 |
+const char *TranslatorMetal::GetRasterizationDiscardEnabledConstName() |
| 719 |
+{ |
| 720 |
+ return kRasterizationDiscardEnabledConstName.data(); |
| 721 |
+} |
| 722 |
+ |
| 723 |
TranslatorMetal::TranslatorMetal(sh::GLenum type, ShShaderSpec spec) : TranslatorVulkan(type, spec) |
| 724 |
{} |
| 725 |
|
| 726 |
@@ -153,20 +186,58 @@ bool TranslatorMetal::translate(TIntermBlock *root, |
| 727 |
{ |
| 728 |
auto negFlipY = getDriverUniformNegFlipYRef(driverUniforms); |
| 729 |
|
| 730 |
+ if (mEmulatedInstanceID) |
| 731 |
+ { |
| 732 |
+ // Emulate gl_InstanceID |
| 733 |
+ if (!EmulateInstanceID(this, root, &getSymbolTable(), driverUniforms)) |
| 734 |
+ { |
| 735 |
+ return false; |
| 736 |
+ } |
| 737 |
+ } |
| 738 |
+ |
| 739 |
// Append gl_Position.y correction to main |
| 740 |
if (!AppendVertexShaderPositionYCorrectionToMain(this, root, &getSymbolTable(), negFlipY)) |
| 741 |
{ |
| 742 |
return false; |
| 743 |
} |
| 744 |
|
| 745 |
- // Insert rasterizer discard logic |
| 746 |
- if (!insertRasterizerDiscardLogic(root)) |
| 747 |
+ // Insert rasterization discard logic |
| 748 |
+ if (!insertRasterizationDiscardLogic(root)) |
| 749 |
+ { |
| 750 |
+ return false; |
| 751 |
+ } |
| 752 |
+ } |
| 753 |
+ |
| 754 |
+ // Initialize unused varying outputs to avoid spirv-cross dead-code removing them in later |
| 755 |
+ // stage. Only do this if SH_INIT_OUTPUT_VARIABLES is not specified. |
| 756 |
+ if ((getShaderType() == GL_VERTEX_SHADER || getShaderType() == GL_GEOMETRY_SHADER_EXT) && |
| 757 |
+ !(compileOptions & SH_INIT_OUTPUT_VARIABLES)) |
| 758 |
+ { |
| 759 |
+ InitVariableList list; |
| 760 |
+ for (const sh::ShaderVariable &var : mOutputVaryings) |
| 761 |
+ { |
| 762 |
+ if (!var.active) |
| 763 |
+ { |
| 764 |
+ list.push_back(var); |
| 765 |
+ } |
| 766 |
+ } |
| 767 |
+ |
| 768 |
+ if (!InitializeUnusedOutputs(root, &getSymbolTable(), list)) |
| 769 |
{ |
| 770 |
return false; |
| 771 |
} |
| 772 |
} |
| 773 |
else if (getShaderType() == GL_FRAGMENT_SHADER) |
| 774 |
{ |
| 775 |
+ // For non void MSL fragment functions replace discard |
| 776 |
+ // with ANGLEDiscardWrapper() |
| 777 |
+ if (mOutputVariables.size() > 0) |
| 778 |
+ { |
| 779 |
+ if (!replaceAllMainDiscardUses(root)) |
| 780 |
+ { |
| 781 |
+ return false; |
| 782 |
+ } |
| 783 |
+ } |
| 784 |
if (!insertSampleMaskWritingLogic(root, driverUniforms)) |
| 785 |
{ |
| 786 |
return false; |
| 787 |
@@ -235,6 +306,13 @@ void TranslatorMetal::createAdditionalGraphicsDriverUniformFields(std::vector<TF |
| 788 |
TField *coverageMaskField = |
| 789 |
new TField(new TType(EbtUInt), kCoverageMaskField, TSourceLoc(), SymbolType::AngleInternal); |
| 790 |
fieldsOut->push_back(coverageMaskField); |
| 791 |
+ |
| 792 |
+ if (mEmulatedInstanceID) |
| 793 |
+ { |
| 794 |
+ TField *emuInstanceIDField = new TField(new TType(EbtInt), kEmuInstanceIDField, |
| 795 |
+ TSourceLoc(), SymbolType::AngleInternal); |
| 796 |
+ fieldsOut->push_back(emuInstanceIDField); |
| 797 |
+ } |
| 798 |
} |
| 799 |
|
| 800 |
// Add sample_mask writing to main, guarded by the specialization constant |
| 801 |
@@ -293,24 +371,24 @@ ANGLE_NO_DISCARD bool TranslatorMetal::insertSampleMaskWritingLogic(TIntermBlock |
| 802 |
return RunAtTheEndOfShader(this, root, ifCall, symbolTable); |
| 803 |
} |
| 804 |
|
| 805 |
-ANGLE_NO_DISCARD bool TranslatorMetal::insertRasterizerDiscardLogic(TIntermBlock *root) |
| 806 |
+ANGLE_NO_DISCARD bool TranslatorMetal::insertRasterizationDiscardLogic(TIntermBlock *root) |
| 807 |
{ |
| 808 |
TInfoSinkBase &sink = getInfoSink().obj; |
| 809 |
TSymbolTable *symbolTable = &getSymbolTable(); |
| 810 |
|
| 811 |
// Insert rasterizationDisabled specialization constant. |
| 812 |
- sink << "layout (constant_id=0) const bool " << mtl::kRasterizerDiscardEnabledConstName; |
| 813 |
+ sink << "layout (constant_id=0) const bool " << kRasterizationDiscardEnabledConstName; |
| 814 |
sink << " = false;\n"; |
| 815 |
|
| 816 |
- // Create kRasterizerDiscardEnabledConstName variable reference. |
| 817 |
+ // Create kRasterizationDiscardEnabledConstName and kRasterizationDiscardFuncName variable |
| 818 |
+ // references. |
| 819 |
TType *boolType = new TType(EbtBool); |
| 820 |
boolType->setQualifier(EvqConst); |
| 821 |
- TVariable *discardEnabledVar = |
| 822 |
- new TVariable(symbolTable, ImmutableString(mtl::kRasterizerDiscardEnabledConstName), |
| 823 |
+ TVariable *discardEnabledVar = new TVariable(symbolTable, kRasterizationDiscardEnabledConstName, |
| 824 |
boolType, SymbolType::AngleInternal); |
| 825 |
|
| 826 |
// Insert this code to the end of main() |
| 827 |
- // if (ANGLERasterizerDisabled) |
| 828 |
+ // if (ANGLERasterizationDisabled) |
| 829 |
// { |
| 830 |
// gl_Position = vec4(-3.0, -3.0, -3.0, 1.0); |
| 831 |
// } |
| 832 |
@@ -341,4 +419,79 @@ ANGLE_NO_DISCARD bool TranslatorMetal::insertRasterizerDiscardLogic(TIntermBlock |
| 833 |
return RunAtTheEndOfShader(this, root, ifCall, symbolTable); |
| 834 |
} |
| 835 |
|
| 836 |
+// If the MSL fragment shader is non-void, we need to ensure |
| 837 |
+// that there is a return at the end. The MSL compiler |
| 838 |
+// will error out if there's no return at the end, even if all |
| 839 |
+// paths lead to discard_fragment(). So wrap discard in a wrapper function. |
| 840 |
+// Fixes dEQP-GLES3.functional.shaders.discard.basic_always |
| 841 |
+ANGLE_NO_DISCARD bool TranslatorMetal::replaceAllMainDiscardUses(TIntermBlock *root) |
| 842 |
+{ |
| 843 |
+ // before |
| 844 |
+ // void main (void) |
| 845 |
+ // { |
| 846 |
+ // o_color = v_color; |
| 847 |
+ // discard; |
| 848 |
+ // } |
| 849 |
+ |
| 850 |
+ // after |
| 851 |
+ // void ANGLEDiscardWrapper() |
| 852 |
+ // { |
| 853 |
+ // discard; |
| 854 |
+ // } |
| 855 |
+ // void main (void) |
| 856 |
+ // { |
| 857 |
+ // o_color = v_color; |
| 858 |
+ // ANGLEDiscardWrapper(); |
| 859 |
+ // } |
| 860 |
+ |
| 861 |
+ TIntermFunctionDefinition *main = FindMain(root); |
| 862 |
+ TIntermBlock *mainBody = main->getBody(); |
| 863 |
+ TIntermSequence *functionSequence = mainBody->getSequence(); |
| 864 |
+ TIntermAggregate *discardFunc = nullptr; |
| 865 |
+ // Iterate over all branches in main function, and replace all uses |
| 866 |
+ // of discard with ANGLEDiscardWrapper(). |
| 867 |
+ for (size_t index = 0; index < functionSequence->size(); ++index) |
| 868 |
+ { |
| 869 |
+ TIntermNode *functionNode = (*functionSequence)[index]; |
| 870 |
+ TIntermBranch *branchNode = functionNode->getAsBranchNode(); |
| 871 |
+ if (branchNode != nullptr) |
| 872 |
+ { |
| 873 |
+ if (branchNode->getFlowOp() == EOpKill) |
| 874 |
+ { |
| 875 |
+ if (discardFunc == nullptr) |
| 876 |
+ { |
| 877 |
+ discardFunc = createDiscardWrapperFunc(root); |
| 878 |
+ } |
| 879 |
+ bool replaced = mainBody->replaceChildNode(branchNode, discardFunc); |
| 880 |
+ if (!replaced) |
| 881 |
+ { |
| 882 |
+ return false; |
| 883 |
+ } |
| 884 |
+ } |
| 885 |
+ } |
| 886 |
+ } |
| 887 |
+ return validateAST(root); |
| 888 |
+} |
| 889 |
+ |
| 890 |
+// Create discard_wrapper function to ensure that SPIRV-Cross will always have a return at the end |
| 891 |
+// of fragment shaders |
| 892 |
+ANGLE_NO_DISCARD TIntermAggregate *TranslatorMetal::createDiscardWrapperFunc(TIntermBlock *root) |
| 893 |
+{ |
| 894 |
+ TInfoSinkBase &sink = getInfoSink().obj; |
| 895 |
+ TSymbolTable *symbolTable = &getSymbolTable(); |
| 896 |
+ |
| 897 |
+ sink << "void " << kDiscardWrapperFuncName << "()\n"; |
| 898 |
+ sink << "{\n"; |
| 899 |
+ sink << " discard;\n"; |
| 900 |
+ sink << "}\n"; |
| 901 |
+ |
| 902 |
+ TFunction *discardWrapperFunc = |
| 903 |
+ new TFunction(symbolTable, kDiscardWrapperFuncName, SymbolType::AngleInternal, |
| 904 |
+ StaticType::GetBasic<EbtVoid>(), true); |
| 905 |
+ |
| 906 |
+ TIntermAggregate *callDiscardWrapperFunc = |
| 907 |
+ TIntermAggregate::CreateFunctionCall(*discardWrapperFunc, new TIntermSequence()); |
| 908 |
+ return callDiscardWrapperFunc; |
| 909 |
+} |
| 910 |
+ |
| 911 |
} // namespace sh |
| 912 |
diff --git a/src/compiler/translator/TranslatorMetal.h b/src/compiler/translator/TranslatorMetal.h |
| 913 |
index 0f4f1cc..bcc3187 100644 |
| 914 |
--- a/src/compiler/translator/TranslatorMetal.h |
| 915 |
+++ b/src/compiler/translator/TranslatorMetal.h |
| 916 |
@@ -25,6 +25,11 @@ class TranslatorMetal : public TranslatorVulkan |
| 917 |
public: |
| 918 |
TranslatorMetal(sh::GLenum type, ShShaderSpec spec); |
| 919 |
|
| 920 |
+ static const char *GetCoverageMaskEnabledConstName(); |
| 921 |
+ static const char *GetRasterizationDiscardEnabledConstName(); |
| 922 |
+ |
| 923 |
+ void enableEmulatedInstanceID(bool e) { mEmulatedInstanceID = e; } |
| 924 |
+ |
| 925 |
protected: |
| 926 |
ANGLE_NO_DISCARD bool translate(TIntermBlock *root, |
| 927 |
ShCompileOptions compileOptions, |
| 928 |
@@ -37,7 +42,13 @@ class TranslatorMetal : public TranslatorVulkan |
| 929 |
|
| 930 |
ANGLE_NO_DISCARD bool insertSampleMaskWritingLogic(TIntermBlock *root, |
| 931 |
const TVariable *driverUniforms); |
| 932 |
- ANGLE_NO_DISCARD bool insertRasterizerDiscardLogic(TIntermBlock *root); |
| 933 |
+ ANGLE_NO_DISCARD bool insertRasterizationDiscardLogic(TIntermBlock *root); |
| 934 |
+ |
| 935 |
+ ANGLE_NO_DISCARD bool replaceAllMainDiscardUses(TIntermBlock *root); |
| 936 |
+ |
| 937 |
+ ANGLE_NO_DISCARD TIntermAggregate *createDiscardWrapperFunc(TIntermBlock *root); |
| 938 |
+ |
| 939 |
+ bool mEmulatedInstanceID = false; |
| 940 |
}; |
| 941 |
|
| 942 |
} // namespace sh |
| 943 |
diff --git a/src/compiler/translator/TranslatorMetalDirect.cpp b/src/compiler/translator/TranslatorMetalDirect.cpp |
| 944 |
new file mode 100644 |
| 945 |
index 0000000..4e10228 |
| 946 |
--- /dev/null |
| 947 |
+++ b/src/compiler/translator/TranslatorMetalDirect.cpp |
| 948 |
@@ -0,0 +1,1439 @@ |
| 949 |
+// |
| 950 |
+// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 951 |
+// Use of this source code is governed by a BSD-style license that can be |
| 952 |
+// found in the LICENSE file. |
| 953 |
+// |
| 954 |
+ |
| 955 |
+#include "compiler/translator/TranslatorMetalDirect.h" |
| 956 |
+ |
| 957 |
+#include "angle_gl.h" |
| 958 |
+#include "common/utilities.h" |
| 959 |
+#include "compiler/translator/BuiltinsWorkaroundGLSL.h" |
| 960 |
+#include "compiler/translator/ImmutableStringBuilder.h" |
| 961 |
+#include "compiler/translator/OutputVulkanGLSL.h" |
| 962 |
+#include "compiler/translator/StaticType.h" |
| 963 |
+#include "compiler/translator/TranslatorMetalDirect/AddExplicitTypeCasts.h" |
| 964 |
+#include "compiler/translator/TranslatorMetalDirect/AstHelpers.h" |
| 965 |
+#include "compiler/translator/TranslatorMetalDirect/ConstantNames.h" |
| 966 |
+#include "compiler/translator/TranslatorMetalDirect/EmitMetal.h" |
| 967 |
+#include "compiler/translator/TranslatorMetalDirect/HoistConstants.h" |
| 968 |
+#include "compiler/translator/TranslatorMetalDirect/Name.h" |
| 969 |
+#include "compiler/translator/TranslatorMetalDirect/ReduceInterfaceBlocks.h" |
| 970 |
+#include "compiler/translator/TranslatorMetalDirect/RewriteCaseDeclarations.h" |
| 971 |
+#include "compiler/translator/TranslatorMetalDirect/RewriteGlobalQualifierDecls.h" |
| 972 |
+#include "compiler/translator/TranslatorMetalDirect/RewriteKeywords.h" |
| 973 |
+#include "compiler/translator/TranslatorMetalDirect/RewriteOutArgs.h" |
| 974 |
+#include "compiler/translator/TranslatorMetalDirect/RewritePipelines.h" |
| 975 |
+#include "compiler/translator/TranslatorMetalDirect/RewriteUnaddressableReferences.h" |
| 976 |
+#include "compiler/translator/TranslatorMetalDirect/SeparateCompoundExpressions.h" |
| 977 |
+#include "compiler/translator/TranslatorMetalDirect/SeparateCompoundStructDeclarations.h" |
| 978 |
+#include "compiler/translator/TranslatorMetalDirect/SymbolEnv.h" |
| 979 |
+#include "compiler/translator/TranslatorMetalDirect/ToposortStructs.h" |
| 980 |
+#include "compiler/translator/TranslatorMetalDirect/WrapMain.h" |
| 981 |
+#include "compiler/translator/TranslatorMetalUtils.h" |
| 982 |
+#include "compiler/translator/tree_ops/InitializeVariables.h" |
| 983 |
+#include "compiler/translator/tree_ops/NameEmbeddedUniformStructs.h" |
| 984 |
+#include "compiler/translator/tree_ops/RemoveAtomicCounterBuiltins.h" |
| 985 |
+#include "compiler/translator/tree_ops/RemoveInactiveInterfaceVariables.h" |
| 986 |
+#include "compiler/translator/tree_ops/RewriteAtomicCounters.h" |
| 987 |
+#include "compiler/translator/tree_ops/RewriteCubeMapSamplersAs2DArray.h" |
| 988 |
+#include "compiler/translator/tree_ops/RewriteDfdy.h" |
| 989 |
+#include "compiler/translator/tree_ops/RewriteStructSamplers.h" |
| 990 |
+#include "compiler/translator/tree_util/BuiltIn.h" |
| 991 |
+#include "compiler/translator/tree_util/FindFunction.h" |
| 992 |
+#include "compiler/translator/tree_util/FindMain.h" |
| 993 |
+#include "compiler/translator/tree_util/FindSymbolNode.h" |
| 994 |
+#include "compiler/translator/tree_util/IntermNode_util.h" |
| 995 |
+#include "compiler/translator/tree_util/ReplaceClipDistanceVariable.h" |
| 996 |
+#include "compiler/translator/tree_util/ReplaceVariable.h" |
| 997 |
+#include "compiler/translator/tree_util/RunAtTheEndOfShader.h" |
| 998 |
+#include "compiler/translator/util.h" |
| 999 |
+ |
| 1000 |
+namespace sh |
| 1001 |
+{ |
| 1002 |
+ |
| 1003 |
+namespace |
| 1004 |
+{ |
| 1005 |
+ |
| 1006 |
+constexpr Name kCoverageMaskField("coverageMask", SymbolType::UserDefined); |
| 1007 |
+constexpr Name kEmuInstanceIDField("emulatedInstanceID", SymbolType::UserDefined); |
| 1008 |
+#if 0 |
| 1009 |
+constexpr Name kSampleMaskWriteFuncName("WriteSampleMask"); |
| 1010 |
+constexpr Name kDiscardWrapperFuncName("DiscardWrapper"); |
| 1011 |
+#endif |
| 1012 |
+constexpr Name kEmulatedDepthRangeParams("DepthRangeParams"); |
| 1013 |
+constexpr Name kUniformsBlockName("AngleUniforms"); |
| 1014 |
+constexpr Name kUniformsVarName("angleUniforms"); |
| 1015 |
+constexpr Name kFlippedPointCoordName("flippedPointCoord", SymbolType::UserDefined); |
| 1016 |
+constexpr Name kFlippedFragCoordName("flippedFragCoord", SymbolType::UserDefined); |
| 1017 |
+ |
| 1018 |
+constexpr const char kViewport[] = "viewport"; |
| 1019 |
+constexpr const char kHalfRenderArea[] = "halfRenderArea"; |
| 1020 |
+constexpr const char kFlipXY[] = "flipXY"; |
| 1021 |
+constexpr const char kNegFlipXY[] = "negFlipXY"; |
| 1022 |
+constexpr const char kClipDistancesEnabled[] = "clipDistancesEnabled"; |
| 1023 |
+constexpr const char kXfbActiveUnpaused[] = "xfbActiveUnpaused"; |
| 1024 |
+constexpr const char kXfbVerticesPerDraw[] = "xfbVerticesPerDraw"; |
| 1025 |
+constexpr const char kXfbBufferOffsets[] = "xfbBufferOffsets"; |
| 1026 |
+constexpr const char kAcbBufferOffsets[] = "acbBufferOffsets"; |
| 1027 |
+constexpr const char kDepthRange[] = "depthRange"; |
| 1028 |
+constexpr const char kPreRotation[] = "preRotation"; |
| 1029 |
+constexpr const char kFragRotation[] = "fragRotation"; |
| 1030 |
+ |
| 1031 |
+constexpr const TVariable kgl_VertexIndexMetal( |
| 1032 |
+ BuiltInId::gl_VertexIndex, |
| 1033 |
+ ImmutableString("gl_VertexIndex"), |
| 1034 |
+ SymbolType::BuiltIn, |
| 1035 |
+ TExtension::UNDEFINED, |
| 1036 |
+ StaticType::Get<EbtUInt, EbpHigh, EvqVertexID, 1, 1>()); |
| 1037 |
+ |
| 1038 |
+constexpr size_t kNumGraphicsDriverUniforms = 12; |
| 1039 |
+constexpr std::array<const char *, kNumGraphicsDriverUniforms> kGraphicsDriverUniformNames = { |
| 1040 |
+ {kViewport, kHalfRenderArea, kFlipXY, kNegFlipXY, kClipDistancesEnabled, kXfbActiveUnpaused, |
| 1041 |
+ kXfbVerticesPerDraw, kXfbBufferOffsets, kAcbBufferOffsets, kDepthRange, kPreRotation, |
| 1042 |
+ kFragRotation}}; |
| 1043 |
+ |
| 1044 |
+constexpr size_t kNumComputeDriverUniforms = 1; |
| 1045 |
+constexpr std::array<const char *, kNumComputeDriverUniforms> kComputeDriverUniformNames = { |
| 1046 |
+ {kAcbBufferOffsets}}; |
| 1047 |
+ |
| 1048 |
+class DeclareStructTypesTraverser : public TIntermTraverser |
| 1049 |
+{ |
| 1050 |
+ public: |
| 1051 |
+ explicit DeclareStructTypesTraverser(TOutputMSL *outputMSL) |
| 1052 |
+ : TIntermTraverser(true, false, false), mOutputMSL(outputMSL) |
| 1053 |
+ {} |
| 1054 |
+ |
| 1055 |
+ bool visitDeclaration(Visit visit, TIntermDeclaration *node) override |
| 1056 |
+ { |
| 1057 |
+ ASSERT(visit == PreVisit); |
| 1058 |
+ if (!mInGlobalScope) |
| 1059 |
+ { |
| 1060 |
+ return false; |
| 1061 |
+ } |
| 1062 |
+ |
| 1063 |
+ const TIntermSequence &sequence = *(node->getSequence()); |
| 1064 |
+ TIntermTyped *declarator = sequence.front()->getAsTyped(); |
| 1065 |
+ const TType &type = declarator->getType(); |
| 1066 |
+ |
| 1067 |
+ if (type.isStructSpecifier()) |
| 1068 |
+ { |
| 1069 |
+ const TStructure *structure = type.getStruct(); |
| 1070 |
+ |
| 1071 |
+ // Embedded structs should be parsed away by now. |
| 1072 |
+ ASSERT(structure->symbolType() != SymbolType::Empty); |
| 1073 |
+ // outputMSL->writeStructType(structure); |
| 1074 |
+ |
| 1075 |
+ TIntermSymbol *symbolNode = declarator->getAsSymbolNode(); |
| 1076 |
+ if (symbolNode && symbolNode->variable().symbolType() == SymbolType::Empty) |
| 1077 |
+ { |
| 1078 |
+ // Remove the struct specifier declaration from the tree so it isn't parsed again. |
| 1079 |
+ TIntermSequence emptyReplacement; |
| 1080 |
+ mMultiReplacements.emplace_back(getParentNode()->getAsBlock(), node, |
| 1081 |
+ emptyReplacement); |
| 1082 |
+ } |
| 1083 |
+ } |
| 1084 |
+ // TODO: REMOVE, used to remove 'unsued' warning |
| 1085 |
+ mOutputMSL = nullptr; |
| 1086 |
+ |
| 1087 |
+ return false; |
| 1088 |
+ } |
| 1089 |
+ |
| 1090 |
+ private: |
| 1091 |
+ TOutputMSL *mOutputMSL; |
| 1092 |
+}; |
| 1093 |
+ |
| 1094 |
+class DeclareDefaultUniformsTraverser : public TIntermTraverser |
| 1095 |
+{ |
| 1096 |
+ public: |
| 1097 |
+ DeclareDefaultUniformsTraverser(TInfoSinkBase *sink, |
| 1098 |
+ ShHashFunction64 hashFunction, |
| 1099 |
+ NameMap *nameMap) |
| 1100 |
+ : TIntermTraverser(true, true, true), |
| 1101 |
+ mSink(sink), |
| 1102 |
+ mHashFunction(hashFunction), |
| 1103 |
+ mNameMap(nameMap), |
| 1104 |
+ mInDefaultUniform(false) |
| 1105 |
+ {} |
| 1106 |
+ |
| 1107 |
+ bool visitDeclaration(Visit visit, TIntermDeclaration *node) override |
| 1108 |
+ { |
| 1109 |
+ const TIntermSequence &sequence = *(node->getSequence()); |
| 1110 |
+ |
| 1111 |
+ // TODO(jmadill): Compound declarations. |
| 1112 |
+ ASSERT(sequence.size() == 1); |
| 1113 |
+ |
| 1114 |
+ TIntermTyped *variable = sequence.front()->getAsTyped(); |
| 1115 |
+ const TType &type = variable->getType(); |
| 1116 |
+ bool isUniform = type.getQualifier() == EvqUniform && !type.isInterfaceBlock() && |
| 1117 |
+ !IsOpaqueType(type.getBasicType()); |
| 1118 |
+ |
| 1119 |
+ if (visit == PreVisit) |
| 1120 |
+ { |
| 1121 |
+ if (isUniform) |
| 1122 |
+ { |
| 1123 |
+ (*mSink) << " " << GetTypeName(type, mHashFunction, mNameMap) << " "; |
| 1124 |
+ mInDefaultUniform = true; |
| 1125 |
+ } |
| 1126 |
+ } |
| 1127 |
+ else if (visit == InVisit) |
| 1128 |
+ { |
| 1129 |
+ mInDefaultUniform = isUniform; |
| 1130 |
+ } |
| 1131 |
+ else if (visit == PostVisit) |
| 1132 |
+ { |
| 1133 |
+ if (isUniform) |
| 1134 |
+ { |
| 1135 |
+ (*mSink) << ";\n"; |
| 1136 |
+ |
| 1137 |
+ // Remove the uniform declaration from the tree so it isn't parsed again. |
| 1138 |
+ TIntermSequence emptyReplacement; |
| 1139 |
+ mMultiReplacements.emplace_back(getParentNode()->getAsBlock(), node, |
| 1140 |
+ emptyReplacement); |
| 1141 |
+ } |
| 1142 |
+ |
| 1143 |
+ mInDefaultUniform = false; |
| 1144 |
+ } |
| 1145 |
+ return true; |
| 1146 |
+ } |
| 1147 |
+ |
| 1148 |
+ void visitSymbol(TIntermSymbol *symbol) override |
| 1149 |
+ { |
| 1150 |
+ if (mInDefaultUniform) |
| 1151 |
+ { |
| 1152 |
+ const ImmutableString &name = symbol->variable().name(); |
| 1153 |
+ ASSERT(!name.beginsWith("gl_")); |
| 1154 |
+ (*mSink) << HashName(&symbol->variable(), mHashFunction, mNameMap) |
| 1155 |
+ << ArrayString(symbol->getType()); |
| 1156 |
+ } |
| 1157 |
+ } |
| 1158 |
+ |
| 1159 |
+ private: |
| 1160 |
+ TInfoSinkBase *mSink; |
| 1161 |
+ ShHashFunction64 mHashFunction; |
| 1162 |
+ NameMap *mNameMap; |
| 1163 |
+ bool mInDefaultUniform; |
| 1164 |
+}; |
| 1165 |
+ |
| 1166 |
+TIntermBinary *CreateDriverUniformRef(const TVariable &driverUniforms, const char *fieldName) |
| 1167 |
+{ |
| 1168 |
+ size_t fieldIndex = FindFieldIndex(driverUniforms.getType().getStruct()->fields(), fieldName); |
| 1169 |
+ |
| 1170 |
+ TIntermSymbol *angleUniformsRef = new TIntermSymbol(&driverUniforms); |
| 1171 |
+ TConstantUnion *uniformIndex = new TConstantUnion; |
| 1172 |
+ uniformIndex->setIConst(static_cast<int>(fieldIndex)); |
| 1173 |
+ TIntermConstantUnion *indexRef = |
| 1174 |
+ new TIntermConstantUnion(uniformIndex, *StaticType::GetBasic<EbtInt>()); |
| 1175 |
+ return new TIntermBinary(EOpIndexDirectStruct, angleUniformsRef, indexRef); |
| 1176 |
+} |
| 1177 |
+ |
| 1178 |
+#if 0 |
| 1179 |
+// Unlike Vulkan having auto viewport flipping extension, in Metal we have to flip gl_Position.y |
| 1180 |
+// manually. |
| 1181 |
+// This operation performs flipping the gl_Position.y using this expression: |
| 1182 |
+// gl_Position.y = gl_Position.y * negViewportScaleY |
| 1183 |
+ANGLE_NO_DISCARD bool AppendVertexShaderPositionYCorrectionToMain(TCompiler &compiler, |
| 1184 |
+ TIntermBlock &root, |
| 1185 |
+ TIntermSwizzle &negFlipY) |
| 1186 |
+{ |
| 1187 |
+ TSymbolTable &symbolTable = compiler.getSymbolTable(); |
| 1188 |
+ |
| 1189 |
+ // Create a symbol reference to "gl_Position" |
| 1190 |
+ const TVariable *position = BuiltInVariable::gl_Position(); |
| 1191 |
+ TIntermSymbol *positionRef = new TIntermSymbol(position); |
| 1192 |
+ |
| 1193 |
+ // Create a swizzle to "gl_Position.y" |
| 1194 |
+ TVector<int> swizzleOffsetY; |
| 1195 |
+ swizzleOffsetY.push_back(1); |
| 1196 |
+ TIntermSwizzle *positionY = new TIntermSwizzle(positionRef, swizzleOffsetY); |
| 1197 |
+ |
| 1198 |
+ // Create the expression "gl_Position.y * negFlipY" |
| 1199 |
+ TIntermBinary *inverseY = new TIntermBinary(EOpMul, positionY->deepCopy(), &negFlipY); |
| 1200 |
+ |
| 1201 |
+ // Create the assignment "gl_Position.y = gl_Position.y * negViewportScaleY |
| 1202 |
+ TIntermTyped *positionYLHS = positionY->deepCopy(); |
| 1203 |
+ TIntermBinary *assignment = new TIntermBinary(TOperator::EOpAssign, positionYLHS, inverseY); |
| 1204 |
+ |
| 1205 |
+ // Append the assignment as a statement at the end of the shader. |
| 1206 |
+ return RunAtTheEndOfShader(&compiler, &root, assignment, &symbolTable); |
| 1207 |
+} |
| 1208 |
+#endif |
| 1209 |
+ |
| 1210 |
+#if 0 |
| 1211 |
+// Initialize unused varying outputs. |
| 1212 |
+ANGLE_NO_DISCARD bool InitializeUnusedOutputs(TIntermBlock &root, |
| 1213 |
+ TSymbolTable &symbolTable, |
| 1214 |
+ const InitVariableList &unusedVars) |
| 1215 |
+{ |
| 1216 |
+ if (unusedVars.empty()) |
| 1217 |
+ { |
| 1218 |
+ return true; |
| 1219 |
+ } |
| 1220 |
+ |
| 1221 |
+ TIntermSequence *insertSequence = new TIntermSequence; |
| 1222 |
+ |
| 1223 |
+ for (const sh::ShaderVariable &var : unusedVars) |
| 1224 |
+ { |
| 1225 |
+ ASSERT(!var.active); |
| 1226 |
+ const TIntermSymbol *symbol = FindSymbolNode(&root, var.name); |
| 1227 |
+ ASSERT(symbol); |
| 1228 |
+ |
| 1229 |
+ TIntermSequence *initCode = CreateInitCode(symbol, false, false, &symbolTable); |
| 1230 |
+ |
| 1231 |
+ insertSequence->insert(insertSequence->end(), initCode->begin(), initCode->end()); |
| 1232 |
+ } |
| 1233 |
+ |
| 1234 |
+ if (insertSequence) |
| 1235 |
+ { |
| 1236 |
+ TIntermFunctionDefinition *main = FindMain(&root); |
| 1237 |
+ TIntermSequence *mainSequence = main->getBody()->getSequence(); |
| 1238 |
+ |
| 1239 |
+ // Insert init code at the start of main() |
| 1240 |
+ mainSequence->insert(mainSequence->begin(), insertSequence->begin(), insertSequence->end()); |
| 1241 |
+ } |
| 1242 |
+ |
| 1243 |
+ return true; |
| 1244 |
+} |
| 1245 |
+#endif |
| 1246 |
+ |
| 1247 |
+const TVariable *AddComputeDriverUniformsToShader(TIntermBlock &root, TSymbolTable &symbolTable) |
| 1248 |
+{ |
| 1249 |
+ // This field list mirrors the structure of ComputeDriverUniforms in ContextVk.cpp. |
| 1250 |
+ TFieldList *driverFieldList = new TFieldList; |
| 1251 |
+ |
| 1252 |
+ const std::array<TType *, kNumComputeDriverUniforms> kDriverUniformTypes = {{ |
| 1253 |
+ new TType(EbtUInt, 4), |
| 1254 |
+ }}; |
| 1255 |
+ |
| 1256 |
+ for (size_t uniformIndex = 0; uniformIndex < kNumComputeDriverUniforms; ++uniformIndex) |
| 1257 |
+ { |
| 1258 |
+ TField *driverUniformField = |
| 1259 |
+ new TField(kDriverUniformTypes[uniformIndex], |
| 1260 |
+ ImmutableString(kComputeDriverUniformNames[uniformIndex]), kNoSourceLoc, |
| 1261 |
+ SymbolType::AngleInternal); |
| 1262 |
+ driverFieldList->push_back(driverUniformField); |
| 1263 |
+ } |
| 1264 |
+ |
| 1265 |
+ return DeclareStructure(&root, &symbolTable, driverFieldList, EvqUniform, |
| 1266 |
+ TMemoryQualifier::Create(), 0, kUniformsBlockName.rawName(), |
| 1267 |
+ &kUniformsVarName.rawName()) |
| 1268 |
+ .second; |
| 1269 |
+} |
| 1270 |
+ |
| 1271 |
+// The Add*DriverUniformsToShader operation adds an internal uniform block to a shader. The driver |
| 1272 |
+// block is used to implement Vulkan-specific features and workarounds. Returns the driver uniforms |
| 1273 |
+// variable. |
| 1274 |
+// |
| 1275 |
+// There are Graphics and Compute variations as they require different uniforms. |
| 1276 |
+const TVariable *AddGraphicsDriverUniformsToShader(TIntermBlock &root, |
| 1277 |
+ TSymbolTable &symbolTable, |
| 1278 |
+ const std::vector<TField *> &additionalFields) |
| 1279 |
+{ |
| 1280 |
+ // Init the depth range type. |
| 1281 |
+ TFieldList *depthRangeParamsFields = new TFieldList(); |
| 1282 |
+ depthRangeParamsFields->push_back(new TField(new TType(EbtFloat, EbpHigh, EvqGlobal, 1, 1), |
| 1283 |
+ ImmutableString("near"), kNoSourceLoc, |
| 1284 |
+ SymbolType::AngleInternal)); |
| 1285 |
+ depthRangeParamsFields->push_back(new TField(new TType(EbtFloat, EbpHigh, EvqGlobal, 1, 1), |
| 1286 |
+ ImmutableString("far"), kNoSourceLoc, |
| 1287 |
+ SymbolType::AngleInternal)); |
| 1288 |
+ depthRangeParamsFields->push_back(new TField(new TType(EbtFloat, EbpHigh, EvqGlobal, 1, 1), |
| 1289 |
+ ImmutableString("diff"), kNoSourceLoc, |
| 1290 |
+ SymbolType::AngleInternal)); |
| 1291 |
+ // This additional field might be used by subclass such as TranslatorMetal. |
| 1292 |
+ depthRangeParamsFields->push_back(new TField(new TType(EbtFloat, EbpHigh, EvqGlobal, 1, 1), |
| 1293 |
+ ImmutableString("reserved"), kNoSourceLoc, |
| 1294 |
+ SymbolType::AngleInternal)); |
| 1295 |
+ |
| 1296 |
+ const TStructure *emulatedDepthRangeParams = |
| 1297 |
+ DeclareStructure(&root, &symbolTable, depthRangeParamsFields, EvqGlobal, |
| 1298 |
+ TMemoryQualifier::Create(), 0, kEmulatedDepthRangeParams.rawName(), |
| 1299 |
+ nullptr) |
| 1300 |
+ .first->getType() |
| 1301 |
+ .getStruct(); |
| 1302 |
+ |
| 1303 |
+ // This field list mirrors the structure of GraphicsDriverUniforms in ContextVk.cpp. |
| 1304 |
+ TFieldList *driverFieldList = new TFieldList; |
| 1305 |
+ |
| 1306 |
+ const std::array<TType *, kNumGraphicsDriverUniforms> kDriverUniformTypes = {{ |
| 1307 |
+ new TType(EbtFloat, 4), |
| 1308 |
+ new TType(EbtFloat, 2), |
| 1309 |
+ new TType(EbtFloat, 2), |
| 1310 |
+ new TType(EbtFloat, 2), |
| 1311 |
+ new TType(EbtUInt), // uint clipDistancesEnabled; // 32 bits for 32 clip distances max |
| 1312 |
+ new TType(EbtUInt), |
| 1313 |
+ new TType(EbtUInt), |
| 1314 |
+ // NOTE: There's a vec3 gap here that can be used in the future |
| 1315 |
+ new TType(EbtInt, 4), |
| 1316 |
+ new TType(EbtUInt, 4), |
| 1317 |
+ new TType(emulatedDepthRangeParams, false), |
| 1318 |
+ new TType(EbtFloat, 2, 4), |
| 1319 |
+ new TType(EbtFloat, 2, 4), |
| 1320 |
+ }}; |
| 1321 |
+ |
| 1322 |
+ for (size_t uniformIndex = 0; uniformIndex < kNumGraphicsDriverUniforms; ++uniformIndex) |
| 1323 |
+ { |
| 1324 |
+ TField *driverUniformField = |
| 1325 |
+ new TField(kDriverUniformTypes[uniformIndex], |
| 1326 |
+ ImmutableString(kGraphicsDriverUniformNames[uniformIndex]), kNoSourceLoc, |
| 1327 |
+ SymbolType::AngleInternal); |
| 1328 |
+ driverFieldList->push_back(driverUniformField); |
| 1329 |
+ } |
| 1330 |
+ |
| 1331 |
+ // Back-end specific fields |
| 1332 |
+ driverFieldList->insert(driverFieldList->end(), additionalFields.begin(), |
| 1333 |
+ additionalFields.end()); |
| 1334 |
+ |
| 1335 |
+ // Define a driver uniform block "ANGLEUniformBlock" with instance name "ANGLEUniforms". |
| 1336 |
+ return DeclareStructure(&root, &symbolTable, driverFieldList, EvqUniform, |
| 1337 |
+ TMemoryQualifier::Create(), 0, kUniformsBlockName.rawName(), |
| 1338 |
+ &kUniformsVarName.rawName()) |
| 1339 |
+ .second; |
| 1340 |
+} |
| 1341 |
+ |
| 1342 |
+// Declares a new variable to replace gl_DepthRange, its values are fed from a driver uniform. |
| 1343 |
+ANGLE_NO_DISCARD bool ReplaceGLDepthRangeWithDriverUniform(TCompiler &compiler, |
| 1344 |
+ TIntermBlock &root, |
| 1345 |
+ const TVariable &driverUniforms) |
| 1346 |
+{ |
| 1347 |
+ TSymbolTable &symbolTable = compiler.getSymbolTable(); |
| 1348 |
+ |
| 1349 |
+ // Create a symbol reference to "gl_DepthRange" |
| 1350 |
+ const TVariable *depthRangeVar = static_cast<const TVariable *>( |
| 1351 |
+ symbolTable.findBuiltIn(ImmutableString("gl_DepthRange"), 0)); |
| 1352 |
+ |
| 1353 |
+ // ANGLEUniforms.depthRange |
| 1354 |
+ TIntermBinary *angleEmulatedDepthRangeRef = CreateDriverUniformRef(driverUniforms, kDepthRange); |
| 1355 |
+ |
| 1356 |
+ // Use this variable instead of gl_DepthRange everywhere. |
| 1357 |
+ return ReplaceVariableWithTyped(&compiler, &root, depthRangeVar, angleEmulatedDepthRangeRef); |
| 1358 |
+} |
| 1359 |
+ |
| 1360 |
+TIntermSequence *GetMainSequence(TIntermBlock &root) |
| 1361 |
+{ |
| 1362 |
+ TIntermFunctionDefinition *main = FindMain(&root); |
| 1363 |
+ return main->getBody()->getSequence(); |
| 1364 |
+} |
| 1365 |
+ |
| 1366 |
+ANGLE_NO_DISCARD bool AppendVertexShaderTransformFeedbackOutputToMain(TCompiler &compiler, |
| 1367 |
+ TIntermBlock &root) |
| 1368 |
+{ |
| 1369 |
+ TSymbolTable &symbolTable = compiler.getSymbolTable(); |
| 1370 |
+ TVariable *xfbPlaceholder = new TVariable(&symbolTable, ImmutableString("@@ XFB-OUT @@"), |
| 1371 |
+ new TType(), SymbolType::AngleInternal); |
| 1372 |
+ |
| 1373 |
+ // Append the assignment as a statement at the end of the shader. |
| 1374 |
+ return RunAtTheEndOfShader(&compiler, &root, new TIntermSymbol(xfbPlaceholder), &symbolTable); |
| 1375 |
+} |
| 1376 |
+ |
| 1377 |
+// This operation performs the viewport depth translation needed by Vulkan. In GL the viewport |
| 1378 |
+// transformation is slightly different - see the GL 2.0 spec section "2.12.1 Controlling the |
| 1379 |
+// Viewport". In Vulkan the corresponding spec section is currently "23.4. Coordinate |
| 1380 |
+// Transformations". |
| 1381 |
+// The equations reduce to an expression: |
| 1382 |
+// |
| 1383 |
+// z_vk = 0.5 * (w_gl + z_gl) |
| 1384 |
+// |
| 1385 |
+// where z_vk is the depth output of a Vulkan vertex shader and z_gl is the same for GL. |
| 1386 |
+ANGLE_NO_DISCARD bool AppendVertexShaderDepthCorrectionToMain(TCompiler &compiler, |
| 1387 |
+ TIntermBlock &root) |
| 1388 |
+{ |
| 1389 |
+ TSymbolTable &symbolTable = compiler.getSymbolTable(); |
| 1390 |
+ |
| 1391 |
+ const TVariable *position = BuiltInVariable::gl_Position(); |
| 1392 |
+ TIntermSymbol *positionRef = new TIntermSymbol(position); |
| 1393 |
+ |
| 1394 |
+ TVector<int> swizzleOffsetZ = {2}; |
| 1395 |
+ TIntermSwizzle *positionZ = new TIntermSwizzle(positionRef, swizzleOffsetZ); |
| 1396 |
+ |
| 1397 |
+ TIntermConstantUnion *oneHalf = CreateFloatNode(0.5f); |
| 1398 |
+ |
| 1399 |
+ TVector<int> swizzleOffsetW = {3}; |
| 1400 |
+ TIntermSwizzle *positionW = new TIntermSwizzle(positionRef->deepCopy(), swizzleOffsetW); |
| 1401 |
+ |
| 1402 |
+ // Create the expression "(gl_Position.z + gl_Position.w) * 0.5". |
| 1403 |
+ TIntermBinary *zPlusW = new TIntermBinary(EOpAdd, positionZ->deepCopy(), positionW->deepCopy()); |
| 1404 |
+ TIntermBinary *halfZPlusW = new TIntermBinary(EOpMul, zPlusW, oneHalf->deepCopy()); |
| 1405 |
+ |
| 1406 |
+ // Create the assignment "gl_Position.z = (gl_Position.z + gl_Position.w) * 0.5" |
| 1407 |
+ TIntermTyped *positionZLHS = positionZ->deepCopy(); |
| 1408 |
+ TIntermBinary *assignment = new TIntermBinary(TOperator::EOpAssign, positionZLHS, halfZPlusW); |
| 1409 |
+ |
| 1410 |
+ // Append the assignment as a statement at the end of the shader. |
| 1411 |
+ return RunAtTheEndOfShader(&compiler, &root, assignment, &symbolTable); |
| 1412 |
+} |
| 1413 |
+ |
| 1414 |
+// This operation performs Android pre-rotation and y-flip. For Android (and potentially other |
| 1415 |
+// platforms), the device may rotate, such that the orientation of the application is rotated |
| 1416 |
+// relative to the native orientation of the device. This is corrected in part by multiplying |
| 1417 |
+// gl_Position by a mat2. |
| 1418 |
+// The equations reduce to an expression: |
| 1419 |
+// |
| 1420 |
+// gl_Position.xy = gl_Position.xy * preRotation |
| 1421 |
+ANGLE_NO_DISCARD bool AppendPreRotation(TCompiler &compiler, |
| 1422 |
+ TIntermBlock &root, |
| 1423 |
+ const TVariable &driverUniforms) |
| 1424 |
+{ |
| 1425 |
+ TSymbolTable &symbolTable = compiler.getSymbolTable(); |
| 1426 |
+ TIntermBinary *preRotationRef = CreateDriverUniformRef(driverUniforms, kPreRotation); |
| 1427 |
+ TIntermSymbol *glPos = new TIntermSymbol(BuiltInVariable::gl_Position()); |
| 1428 |
+ TVector<int> swizzleOffsetXY = {0, 1}; |
| 1429 |
+ TIntermSwizzle *glPosXY = new TIntermSwizzle(glPos, swizzleOffsetXY); |
| 1430 |
+ |
| 1431 |
+ // Create the expression "(gl_Position.xy * preRotation)" |
| 1432 |
+ TIntermBinary *zRotated = |
| 1433 |
+ new TIntermBinary(EOpMatrixTimesVector, preRotationRef->deepCopy(), glPosXY->deepCopy()); |
| 1434 |
+ |
| 1435 |
+ // Create the assignment "gl_Position.xy = (gl_Position.xy * preRotation)" |
| 1436 |
+ TIntermBinary *assignment = |
| 1437 |
+ new TIntermBinary(TOperator::EOpAssign, glPosXY->deepCopy(), zRotated); |
| 1438 |
+ |
| 1439 |
+ // Append the assignment as a statement at the end of the shader. |
| 1440 |
+ return RunAtTheEndOfShader(&compiler, &root, assignment, &symbolTable); |
| 1441 |
+} |
| 1442 |
+ |
| 1443 |
+ANGLE_NO_DISCARD bool RotateAndFlipBuiltinVariable(TCompiler &compiler, |
| 1444 |
+ TIntermBlock &root, |
| 1445 |
+ TIntermSequence &insertSequence, |
| 1446 |
+ TIntermTyped &flipXY, |
| 1447 |
+ const TVariable &builtin, |
| 1448 |
+ const Name &flippedVariableName, |
| 1449 |
+ TIntermTyped &pivot, |
| 1450 |
+ TIntermTyped *fragRotation) |
| 1451 |
+{ |
| 1452 |
+ TSymbolTable &symbolTable = compiler.getSymbolTable(); |
| 1453 |
+ |
| 1454 |
+ // Create a symbol reference to 'builtin'. |
| 1455 |
+ TIntermSymbol *builtinRef = new TIntermSymbol(&builtin); |
| 1456 |
+ |
| 1457 |
+ // Create a swizzle to "builtin.xy" |
| 1458 |
+ TVector<int> swizzleOffsetXY = {0, 1}; |
| 1459 |
+ TIntermSwizzle *builtinXY = new TIntermSwizzle(builtinRef, swizzleOffsetXY); |
| 1460 |
+ |
| 1461 |
+ // Create a symbol reference to our new variable that will hold the modified builtin. |
| 1462 |
+ const TType *type = StaticType::GetForVec<EbtFloat>( |
| 1463 |
+ EvqGlobal, static_cast<unsigned char>(builtin.getType().getNominalSize())); |
| 1464 |
+ TVariable *replacementVar = new TVariable(&symbolTable, flippedVariableName.rawName(), type, |
| 1465 |
+ flippedVariableName.symbolType()); |
| 1466 |
+ DeclareGlobalVariable(&root, replacementVar); |
| 1467 |
+ TIntermSymbol *flippedBuiltinRef = new TIntermSymbol(replacementVar); |
| 1468 |
+ |
| 1469 |
+ // Use this new variable instead of 'builtin' everywhere. |
| 1470 |
+ if (!ReplaceVariable(&compiler, &root, &builtin, replacementVar)) |
| 1471 |
+ { |
| 1472 |
+ return false; |
| 1473 |
+ } |
| 1474 |
+ |
| 1475 |
+ // Create the expression "(builtin.xy * fragRotation)" |
| 1476 |
+ TIntermTyped *rotatedXY; |
| 1477 |
+ if (fragRotation) |
| 1478 |
+ { |
| 1479 |
+ rotatedXY = new TIntermBinary(EOpMatrixTimesVector, fragRotation->deepCopy(), |
| 1480 |
+ builtinXY->deepCopy()); |
| 1481 |
+ } |
| 1482 |
+ else |
| 1483 |
+ { |
| 1484 |
+ // No rotation applied, use original variable. |
| 1485 |
+ rotatedXY = builtinXY->deepCopy(); |
| 1486 |
+ } |
| 1487 |
+ |
| 1488 |
+ // Create the expression "(builtin.xy - pivot) * flipXY + pivot |
| 1489 |
+ TIntermBinary *removePivot = new TIntermBinary(EOpSub, rotatedXY, &pivot); |
| 1490 |
+ TIntermBinary *inverseXY = new TIntermBinary(EOpMul, removePivot, &flipXY); |
| 1491 |
+ TIntermBinary *plusPivot = new TIntermBinary(EOpAdd, inverseXY, pivot.deepCopy()); |
| 1492 |
+ |
| 1493 |
+ // Create the corrected variable and copy the value of the original builtin. |
| 1494 |
+ TIntermSequence *sequence = new TIntermSequence(); |
| 1495 |
+ sequence->push_back(builtinRef->deepCopy()); |
| 1496 |
+ TIntermAggregate *aggregate = TIntermAggregate::CreateConstructor(builtin.getType(), sequence); |
| 1497 |
+ TIntermBinary *assignment = new TIntermBinary(EOpInitialize, flippedBuiltinRef, aggregate); |
| 1498 |
+ |
| 1499 |
+ // Create an assignment to the replaced variable's .xy. |
| 1500 |
+ TIntermSwizzle *correctedXY = |
| 1501 |
+ new TIntermSwizzle(flippedBuiltinRef->deepCopy(), swizzleOffsetXY); |
| 1502 |
+ TIntermBinary *assignToY = new TIntermBinary(EOpAssign, correctedXY, plusPivot); |
| 1503 |
+ |
| 1504 |
+ // Add this assigment at the beginning of the main function |
| 1505 |
+ { |
| 1506 |
+ TIntermBinary *nodes[] = {assignment, assignToY}; |
| 1507 |
+ insertSequence.insert(insertSequence.begin(), std::begin(nodes), std::end(nodes)); |
| 1508 |
+ } |
| 1509 |
+ |
| 1510 |
+ return compiler.validateAST(&root); |
| 1511 |
+} |
| 1512 |
+ |
| 1513 |
+ANGLE_NO_DISCARD bool InsertFragCoordCorrection(TCompiler &compiler, |
| 1514 |
+ ShCompileOptions compileOptions, |
| 1515 |
+ TIntermBlock &root, |
| 1516 |
+ TIntermSequence &insertSequence, |
| 1517 |
+ const TVariable &driverUniforms) |
| 1518 |
+{ |
| 1519 |
+ TIntermBinary &flipXY = *CreateDriverUniformRef(driverUniforms, kFlipXY); |
| 1520 |
+ TIntermBinary &pivot = *CreateDriverUniformRef(driverUniforms, kHalfRenderArea); |
| 1521 |
+ TIntermBinary *fragRotation = (compileOptions & SH_ADD_PRE_ROTATION) |
| 1522 |
+ ? CreateDriverUniformRef(driverUniforms, kFragRotation) |
| 1523 |
+ : nullptr; |
| 1524 |
+ return RotateAndFlipBuiltinVariable(compiler, root, insertSequence, flipXY, |
| 1525 |
+ *BuiltInVariable::gl_FragCoord(), kFlippedFragCoordName, |
| 1526 |
+ pivot, fragRotation); |
| 1527 |
+} |
| 1528 |
+ |
| 1529 |
+TIntermBinary *GetDriverUniformDepthRangeReservedFieldRef(const TVariable &driverUniforms) |
| 1530 |
+{ |
| 1531 |
+ TIntermBinary *depthRange = CreateDriverUniformRef(driverUniforms, kDepthRange); |
| 1532 |
+ |
| 1533 |
+ return new TIntermBinary(EOpIndexDirectStruct, depthRange, CreateIndexNode(3)); |
| 1534 |
+} |
| 1535 |
+ |
| 1536 |
+void DeclareRightBeforeMain(TIntermBlock &root, const TVariable &var) |
| 1537 |
+{ |
| 1538 |
+ root.insertChildNodes(FindMainIndex(&root), {new TIntermDeclaration{&var}}); |
| 1539 |
+} |
| 1540 |
+ |
| 1541 |
+void AddFragColorDeclaration(TIntermBlock &root, TSymbolTable &symbolTable) |
| 1542 |
+{ |
| 1543 |
+ root.insertChildNodes(FindMainIndex(&root), |
| 1544 |
+ TIntermSequence{new TIntermDeclaration{BuiltInVariable::gl_FragColor()}}); |
| 1545 |
+} |
| 1546 |
+ |
| 1547 |
+void AddFragDepthDeclaration(TIntermBlock &root, TSymbolTable &symbolTable) |
| 1548 |
+{ |
| 1549 |
+ root.insertChildNodes(FindMainIndex(&root), |
| 1550 |
+ TIntermSequence{new TIntermDeclaration{BuiltInVariable::gl_FragDepth()}}); |
| 1551 |
+} |
| 1552 |
+ |
| 1553 |
+ANGLE_NO_DISCARD bool AddFragDataDeclaration(TCompiler &compiler, TIntermBlock &root) |
| 1554 |
+{ |
| 1555 |
+ TSymbolTable &symbolTable = compiler.getSymbolTable(); |
| 1556 |
+ const int maxDrawBuffers = compiler.getResources().MaxDrawBuffers; |
| 1557 |
+ TType *gl_FragDataType = new TType(EbtFloat, EbpMedium, EvqFragData, 4, 1); |
| 1558 |
+ std::vector<const TVariable *> glFragDataSlots; |
| 1559 |
+ TIntermSequence declareGLFragdataSequence; |
| 1560 |
+ |
| 1561 |
+ // Create gl_FragData_0,1,2,3 |
| 1562 |
+ for (int i = 0; i < maxDrawBuffers; i++) |
| 1563 |
+ { |
| 1564 |
+ ImmutableStringBuilder builder(strlen("gl_FragData_") + 2); |
| 1565 |
+ builder << "gl_FragData_"; |
| 1566 |
+ builder.appendDecimal(i); |
| 1567 |
+ const TVariable *glFragData = |
| 1568 |
+ new TVariable(&symbolTable, builder, gl_FragDataType, SymbolType::AngleInternal, |
| 1569 |
+ TExtension::UNDEFINED); |
| 1570 |
+ glFragDataSlots.push_back(glFragData); |
| 1571 |
+ declareGLFragdataSequence.push_back(new TIntermDeclaration{glFragData}); |
| 1572 |
+ } |
| 1573 |
+ root.insertChildNodes(FindMainIndex(&root), declareGLFragdataSequence); |
| 1574 |
+ |
| 1575 |
+ // Create an internal gl_FragData array type, compatible with indexing syntax. |
| 1576 |
+ TType *gl_FragDataTypeArray = new TType(EbtFloat, EbpMedium, EvqGlobal, 4, 1); |
| 1577 |
+ gl_FragDataTypeArray->makeArray(maxDrawBuffers); |
| 1578 |
+ const TVariable *glFragDataGlobal = new TVariable(&symbolTable, ImmutableString("gl_FragData"), |
| 1579 |
+ gl_FragDataTypeArray, SymbolType::BuiltIn); |
| 1580 |
+ |
| 1581 |
+ DeclareGlobalVariable(&root, glFragDataGlobal); |
| 1582 |
+ const TIntermSymbol *originalGLFragData = FindSymbolNode(&root, ImmutableString("gl_FragData")); |
| 1583 |
+ ASSERT(originalGLFragData); |
| 1584 |
+ |
| 1585 |
+ // Replace gl_FragData() with our globally defined fragdata |
| 1586 |
+ if (!ReplaceVariable(&compiler, &root, &(originalGLFragData->variable()), glFragDataGlobal)) |
| 1587 |
+ { |
| 1588 |
+ return false; |
| 1589 |
+ } |
| 1590 |
+ |
| 1591 |
+ // Assign each array attribute to an output |
| 1592 |
+ TIntermBlock *insertSequence = new TIntermBlock(); |
| 1593 |
+ for (int i = 0; i < maxDrawBuffers; i++) |
| 1594 |
+ { |
| 1595 |
+ TIntermTyped *glFragDataSlot = new TIntermSymbol(glFragDataSlots[i]); |
| 1596 |
+ TIntermTyped *glFragDataGlobalSymbol = new TIntermSymbol(glFragDataGlobal); |
| 1597 |
+ auto &access = AccessIndex(*glFragDataGlobalSymbol, i); |
| 1598 |
+ TIntermBinary *assignment = |
| 1599 |
+ new TIntermBinary(TOperator::EOpAssign, glFragDataSlot, &access); |
| 1600 |
+ insertSequence->appendStatement(assignment); |
| 1601 |
+ } |
| 1602 |
+ return RunAtTheEndOfShader(&compiler, &root, insertSequence, &symbolTable); |
| 1603 |
+} |
| 1604 |
+ |
| 1605 |
+ANGLE_NO_DISCARD bool EmulateInstanceID(TCompiler &compiler, |
| 1606 |
+ TIntermBlock &root, |
| 1607 |
+ const TVariable &driverUniforms) |
| 1608 |
+{ |
| 1609 |
+ TIntermBinary *emuInstanceID = |
| 1610 |
+ CreateDriverUniformRef(driverUniforms, kEmuInstanceIDField.rawName().data()); |
| 1611 |
+ const TVariable *instanceID = BuiltInVariable::gl_InstanceIndex(); |
| 1612 |
+ return ReplaceVariableWithTyped(&compiler, &root, instanceID, emuInstanceID); |
| 1613 |
+} |
| 1614 |
+ |
| 1615 |
+// Unlike Vulkan having auto viewport flipping extension, in Metal we have to flip gl_Position.y |
| 1616 |
+// manually. |
| 1617 |
+// This operation performs flipping the gl_Position.y using this expression: |
| 1618 |
+// gl_Position.y = gl_Position.y * negViewportScaleY |
| 1619 |
+ANGLE_NO_DISCARD bool AppendVertexShaderPositionYCorrectionToMain(TCompiler &compiler, |
| 1620 |
+ TIntermBlock &root, |
| 1621 |
+ TIntermSwizzle &negFlipY) |
| 1622 |
+{ |
| 1623 |
+ TSymbolTable &symbolTable = compiler.getSymbolTable(); |
| 1624 |
+ |
| 1625 |
+ const TVariable *position = BuiltInVariable::gl_Position(); |
| 1626 |
+ TIntermSymbol *positionRef = new TIntermSymbol(position); |
| 1627 |
+ |
| 1628 |
+ TVector<int> swizzleOffsetY; |
| 1629 |
+ swizzleOffsetY.push_back(1); |
| 1630 |
+ TIntermSwizzle *positionY = new TIntermSwizzle(positionRef, swizzleOffsetY); |
| 1631 |
+ |
| 1632 |
+ // Create the expression "gl_Position.y * negFlipY" |
| 1633 |
+ TIntermBinary *inverseY = new TIntermBinary(EOpMul, positionY->deepCopy(), &negFlipY); |
| 1634 |
+ |
| 1635 |
+ // Create the assignment "gl_Position.y = gl_Position.y * negViewportScaleY |
| 1636 |
+ TIntermTyped *positionYLHS = positionY->deepCopy(); |
| 1637 |
+ TIntermBinary *assignment = new TIntermBinary(TOperator::EOpAssign, positionYLHS, inverseY); |
| 1638 |
+ |
| 1639 |
+ // Append the assignment as a statement at the end of the shader. |
| 1640 |
+ return RunAtTheEndOfShader(&compiler, &root, assignment, &symbolTable); |
| 1641 |
+} |
| 1642 |
+ |
| 1643 |
+} // namespace |
| 1644 |
+ |
| 1645 |
+TranslatorMetalDirect::TranslatorMetalDirect(sh::GLenum type, |
| 1646 |
+ ShShaderSpec spec, |
| 1647 |
+ ShShaderOutput output) |
| 1648 |
+ : TCompiler(type, spec, output) |
| 1649 |
+{} |
| 1650 |
+ |
| 1651 |
+// static |
| 1652 |
+const char *TranslatorMetalDirect::GetCoverageMaskEnabledConstName() |
| 1653 |
+{ |
| 1654 |
+ return constant_names::kCoverageMaskEnabled.rawName().data(); |
| 1655 |
+} |
| 1656 |
+ |
| 1657 |
+// static |
| 1658 |
+const char *TranslatorMetalDirect::GetRasterizationDiscardEnabledConstName() |
| 1659 |
+{ |
| 1660 |
+ return constant_names::kRasterizationDiscardEnabled.rawName().data(); |
| 1661 |
+} |
| 1662 |
+ |
| 1663 |
+ANGLE_NO_DISCARD bool TranslatorMetalDirect::insertRasterizationDiscardLogic(TIntermBlock &root) |
| 1664 |
+{ |
| 1665 |
+ TSymbolTable *symbolTable = &getSymbolTable(); |
| 1666 |
+ |
| 1667 |
+ TType *boolType = new TType(EbtBool); |
| 1668 |
+ boolType->setQualifier(EvqConst); |
| 1669 |
+ TVariable *discardEnabledVar = |
| 1670 |
+ new TVariable(symbolTable, constant_names::kRasterizationDiscardEnabled.rawName(), boolType, |
| 1671 |
+ constant_names::kRasterizationDiscardEnabled.symbolType()); |
| 1672 |
+ |
| 1673 |
+ const TVariable *position = BuiltInVariable::gl_Position(); |
| 1674 |
+ TIntermSymbol *positionRef = new TIntermSymbol(position); |
| 1675 |
+ |
| 1676 |
+ // Create vec4(-3, -3, -3, 1): |
| 1677 |
+ auto vec4Type = new TType(EbtFloat, 4); |
| 1678 |
+ TIntermSequence *vec4Args = new TIntermSequence(); |
| 1679 |
+ vec4Args->push_back(CreateFloatNode(-3.0f)); |
| 1680 |
+ vec4Args->push_back(CreateFloatNode(-3.0f)); |
| 1681 |
+ vec4Args->push_back(CreateFloatNode(-3.0f)); |
| 1682 |
+ vec4Args->push_back(CreateFloatNode(1.0f)); |
| 1683 |
+ TIntermAggregate *constVarConstructor = |
| 1684 |
+ TIntermAggregate::CreateConstructor(*vec4Type, vec4Args); |
| 1685 |
+ |
| 1686 |
+ // Create the assignment "gl_Position = vec4(-3, -3, -3, 1)" |
| 1687 |
+ TIntermBinary *assignment = |
| 1688 |
+ new TIntermBinary(TOperator::EOpAssign, positionRef->deepCopy(), constVarConstructor); |
| 1689 |
+ |
| 1690 |
+ TIntermBlock *discardBlock = new TIntermBlock; |
| 1691 |
+ discardBlock->appendStatement(assignment); |
| 1692 |
+ |
| 1693 |
+ TIntermSymbol *discardEnabled = new TIntermSymbol(discardEnabledVar); |
| 1694 |
+ TIntermIfElse *ifCall = new TIntermIfElse(discardEnabled, discardBlock, nullptr); |
| 1695 |
+ |
| 1696 |
+ return RunAtTheEndOfShader(this, &root, ifCall, symbolTable); |
| 1697 |
+} |
| 1698 |
+ |
| 1699 |
+// Metal needs to inverse the depth if depthRange is is reverse order, i.e. depth near > depth far |
| 1700 |
+// This is achieved by multiply the depth value with scale value stored in |
| 1701 |
+// driver uniform's depthRange.reserved |
| 1702 |
+bool TranslatorMetalDirect::transformDepthBeforeCorrection(TIntermBlock &root, |
| 1703 |
+ const TVariable &driverUniforms) |
| 1704 |
+{ |
| 1705 |
+ const TVariable *position = BuiltInVariable::gl_Position(); |
| 1706 |
+ TIntermSymbol *positionRef = new TIntermSymbol(position); |
| 1707 |
+ |
| 1708 |
+ TVector<int> swizzleOffsetZ = {2}; |
| 1709 |
+ TIntermSwizzle *positionZ = new TIntermSwizzle(positionRef, swizzleOffsetZ); |
| 1710 |
+ |
| 1711 |
+ TIntermBinary *viewportZScale = GetDriverUniformDepthRangeReservedFieldRef(driverUniforms); |
| 1712 |
+ |
| 1713 |
+ // Create the expression "gl_Position.z * depthRange.reserved". |
| 1714 |
+ TIntermBinary *zScale = new TIntermBinary(EOpMul, positionZ->deepCopy(), viewportZScale); |
| 1715 |
+ |
| 1716 |
+ // Create the assignment "gl_Position.z = gl_Position.z * depthRange.reserved" |
| 1717 |
+ TIntermTyped *positionZLHS = positionZ->deepCopy(); |
| 1718 |
+ TIntermBinary *assignment = new TIntermBinary(TOperator::EOpAssign, positionZLHS, zScale); |
| 1719 |
+ |
| 1720 |
+ return RunAtTheEndOfShader(this, &root, assignment, &getSymbolTable()); |
| 1721 |
+} |
| 1722 |
+ |
| 1723 |
+void TranslatorMetalDirect::createAdditionalGraphicsDriverUniformFields( |
| 1724 |
+ std::vector<TField *> &fieldsOut) |
| 1725 |
+{ |
| 1726 |
+ // Add coverage mask to driver uniform. Metal doesn't have built-in GL_SAMPLE_COVERAGE_VALUE |
| 1727 |
+ // equivalent functionality, needs to emulate it using fragment shader's [[sample_mask]] output |
| 1728 |
+ // value. |
| 1729 |
+ TField *coverageMaskField = new TField(new TType(EbtUInt), kCoverageMaskField.rawName(), |
| 1730 |
+ kNoSourceLoc, kCoverageMaskField.symbolType()); |
| 1731 |
+ fieldsOut.push_back(coverageMaskField); |
| 1732 |
+ |
| 1733 |
+ if (mEmulatedInstanceID) |
| 1734 |
+ { |
| 1735 |
+ TField *emuInstanceIDField = new TField(new TType(EbtInt), kEmuInstanceIDField.rawName(), |
| 1736 |
+ kNoSourceLoc, kEmuInstanceIDField.symbolType()); |
| 1737 |
+ fieldsOut.push_back(emuInstanceIDField); |
| 1738 |
+ } |
| 1739 |
+} |
| 1740 |
+ |
| 1741 |
+TIntermSwizzle *TranslatorMetalDirect::getDriverUniformNegFlipYRef( |
| 1742 |
+ const TVariable &driverUniforms) const |
| 1743 |
+{ |
| 1744 |
+ // Create a swizzle to "negFlipXY.y" |
| 1745 |
+ TIntermBinary *negFlipXY = CreateDriverUniformRef(driverUniforms, kNegFlipXY); |
| 1746 |
+ TVector<int> swizzleOffsetY = {1}; |
| 1747 |
+ TIntermSwizzle *negFlipY = new TIntermSwizzle(negFlipXY, swizzleOffsetY); |
| 1748 |
+ return negFlipY; |
| 1749 |
+} |
| 1750 |
+ |
| 1751 |
+static std::set<ImmutableString> GetMslKeywords() |
| 1752 |
+{ |
| 1753 |
+ std::set<ImmutableString> keywords; |
| 1754 |
+ |
| 1755 |
+ keywords.emplace("alignas"); |
| 1756 |
+ keywords.emplace("alignof"); |
| 1757 |
+ keywords.emplace("as_type"); |
| 1758 |
+ keywords.emplace("auto"); |
| 1759 |
+ keywords.emplace("catch"); |
| 1760 |
+ keywords.emplace("char"); |
| 1761 |
+ keywords.emplace("class"); |
| 1762 |
+ keywords.emplace("const_cast"); |
| 1763 |
+ keywords.emplace("constant"); |
| 1764 |
+ keywords.emplace("constexpr"); |
| 1765 |
+ keywords.emplace("decltype"); |
| 1766 |
+ keywords.emplace("delete"); |
| 1767 |
+ keywords.emplace("device"); |
| 1768 |
+ keywords.emplace("dynamic_cast"); |
| 1769 |
+ keywords.emplace("enum"); |
| 1770 |
+ keywords.emplace("explicit"); |
| 1771 |
+ keywords.emplace("export"); |
| 1772 |
+ keywords.emplace("extern"); |
| 1773 |
+ keywords.emplace("fragment"); |
| 1774 |
+ keywords.emplace("friend"); |
| 1775 |
+ keywords.emplace("goto"); |
| 1776 |
+ keywords.emplace("half"); |
| 1777 |
+ keywords.emplace("inline"); |
| 1778 |
+ keywords.emplace("int16_t"); |
| 1779 |
+ keywords.emplace("int32_t"); |
| 1780 |
+ keywords.emplace("int64_t"); |
| 1781 |
+ keywords.emplace("int8_t"); |
| 1782 |
+ keywords.emplace("kernel"); |
| 1783 |
+ keywords.emplace("long"); |
| 1784 |
+ keywords.emplace("main0"); |
| 1785 |
+ keywords.emplace("metal"); |
| 1786 |
+ keywords.emplace("mutable"); |
| 1787 |
+ keywords.emplace("namespace"); |
| 1788 |
+ keywords.emplace("new"); |
| 1789 |
+ keywords.emplace("noexcept"); |
| 1790 |
+ keywords.emplace("nullptr_t"); |
| 1791 |
+ keywords.emplace("nullptr"); |
| 1792 |
+ keywords.emplace("operator"); |
| 1793 |
+ keywords.emplace("override"); |
| 1794 |
+ keywords.emplace("private"); |
| 1795 |
+ keywords.emplace("protected"); |
| 1796 |
+ keywords.emplace("ptrdiff_t"); |
| 1797 |
+ keywords.emplace("public"); |
| 1798 |
+ keywords.emplace("ray_data"); |
| 1799 |
+ keywords.emplace("register"); |
| 1800 |
+ keywords.emplace("short"); |
| 1801 |
+ keywords.emplace("signed"); |
| 1802 |
+ keywords.emplace("size_t"); |
| 1803 |
+ keywords.emplace("sizeof"); |
| 1804 |
+ keywords.emplace("stage_in"); |
| 1805 |
+ keywords.emplace("static_assert"); |
| 1806 |
+ keywords.emplace("static_cast"); |
| 1807 |
+ keywords.emplace("static"); |
| 1808 |
+ keywords.emplace("template"); |
| 1809 |
+ keywords.emplace("this"); |
| 1810 |
+ keywords.emplace("thread_local"); |
| 1811 |
+ keywords.emplace("thread"); |
| 1812 |
+ keywords.emplace("threadgroup_imageblock"); |
| 1813 |
+ keywords.emplace("threadgroup"); |
| 1814 |
+ keywords.emplace("throw"); |
| 1815 |
+ keywords.emplace("try"); |
| 1816 |
+ keywords.emplace("typedef"); |
| 1817 |
+ keywords.emplace("typeid"); |
| 1818 |
+ keywords.emplace("typename"); |
| 1819 |
+ keywords.emplace("uchar"); |
| 1820 |
+ keywords.emplace("uint16_t"); |
| 1821 |
+ keywords.emplace("uint32_t"); |
| 1822 |
+ keywords.emplace("uint64_t"); |
| 1823 |
+ keywords.emplace("uint8_t"); |
| 1824 |
+ keywords.emplace("union"); |
| 1825 |
+ keywords.emplace("unsigned"); |
| 1826 |
+ keywords.emplace("ushort"); |
| 1827 |
+ keywords.emplace("using"); |
| 1828 |
+ keywords.emplace("vertex"); |
| 1829 |
+ keywords.emplace("virtual"); |
| 1830 |
+ keywords.emplace("volatile"); |
| 1831 |
+ keywords.emplace("wchar_t"); |
| 1832 |
+ |
| 1833 |
+ return keywords; |
| 1834 |
+} |
| 1835 |
+ |
| 1836 |
+bool TranslatorMetalDirect::translateImpl(TIntermBlock &root, ShCompileOptions compileOptions) |
| 1837 |
+{ |
| 1838 |
+ TSymbolTable &symbolTable = getSymbolTable(); |
| 1839 |
+ IdGen idGen; |
| 1840 |
+ ProgramPreludeConfig ppc; |
| 1841 |
+ |
| 1842 |
+ if (!WrapMain(*this, idGen, root)) |
| 1843 |
+ { |
| 1844 |
+ return false; |
| 1845 |
+ } |
| 1846 |
+ |
| 1847 |
+ TInfoSinkBase &sink = getInfoSink().obj; |
| 1848 |
+#if 0 |
| 1849 |
+ if (getShaderType() == GL_VERTEX_SHADER) |
| 1850 |
+ { |
| 1851 |
+ if (!ShaderBuiltinsWorkaround(this, &root, &symbolTable, compileOptions)) |
| 1852 |
+ { |
| 1853 |
+ return false; |
| 1854 |
+ } |
| 1855 |
+ } |
| 1856 |
+#endif |
| 1857 |
+ |
| 1858 |
+ // Strip any inactive variables from the program. |
| 1859 |
+ if (!RemoveInactiveInterfaceVariables(this, &root, getAttributes(), getInputVaryings(), |
| 1860 |
+ getOutputVariables(), getUniforms(), |
| 1861 |
+ getInterfaceBlocks())) |
| 1862 |
+ { |
| 1863 |
+ return false; |
| 1864 |
+ } |
| 1865 |
+ |
| 1866 |
+ // Write out default uniforms into a uniform block assigned to a specific set/binding. |
| 1867 |
+ int defaultUniformCount = 0; |
| 1868 |
+ int aggregateTypesUsedForUniforms = 0; |
| 1869 |
+ int atomicCounterCount = 0; |
| 1870 |
+ for (const auto &uniform : getUniforms()) |
| 1871 |
+ { |
| 1872 |
+ if (!uniform.isBuiltIn() && uniform.active && !gl::IsOpaqueType(uniform.type)) |
| 1873 |
+ { |
| 1874 |
+ ++defaultUniformCount; |
| 1875 |
+ } |
| 1876 |
+ |
| 1877 |
+ if (uniform.isStruct() || uniform.isArrayOfArrays()) |
| 1878 |
+ { |
| 1879 |
+ ++aggregateTypesUsedForUniforms; |
| 1880 |
+ } |
| 1881 |
+ |
| 1882 |
+ if (uniform.active && gl::IsAtomicCounterType(uniform.type)) |
| 1883 |
+ { |
| 1884 |
+ ++atomicCounterCount; |
| 1885 |
+ } |
| 1886 |
+ } |
| 1887 |
+ |
| 1888 |
+ if (aggregateTypesUsedForUniforms > 0) |
| 1889 |
+ { |
| 1890 |
+ if (!NameEmbeddedStructUniforms(this, &root, &symbolTable)) |
| 1891 |
+ { |
| 1892 |
+ return false; |
| 1893 |
+ } |
| 1894 |
+ |
| 1895 |
+ bool rewriteStructSamplersResult; |
| 1896 |
+ int removedUniformsCount; |
| 1897 |
+ |
| 1898 |
+ if (compileOptions & SH_USE_OLD_REWRITE_STRUCT_SAMPLERS) |
| 1899 |
+ { |
| 1900 |
+ rewriteStructSamplersResult = |
| 1901 |
+ RewriteStructSamplersOld(this, &root, &symbolTable, &removedUniformsCount); |
| 1902 |
+ } |
| 1903 |
+ else |
| 1904 |
+ { |
| 1905 |
+ rewriteStructSamplersResult = |
| 1906 |
+ RewriteStructSamplers(this, &root, &symbolTable, &removedUniformsCount); |
| 1907 |
+ } |
| 1908 |
+ |
| 1909 |
+ if (!rewriteStructSamplersResult) |
| 1910 |
+ { |
| 1911 |
+ return false; |
| 1912 |
+ } |
| 1913 |
+ defaultUniformCount -= removedUniformsCount; |
| 1914 |
+ |
| 1915 |
+#if 0 |
| 1916 |
+ // We must declare the struct types before using them. |
| 1917 |
+ DeclareStructTypesTraverser structTypesTraverser(outputMSL); |
| 1918 |
+ root->traverse(&structTypesTraverser); |
| 1919 |
+ if (!structTypesTraverser.updateTree(this, root)) |
| 1920 |
+ { |
| 1921 |
+ return false; |
| 1922 |
+ } |
| 1923 |
+#endif |
| 1924 |
+ } |
| 1925 |
+ |
| 1926 |
+ if (compileOptions & SH_EMULATE_SEAMFUL_CUBE_MAP_SAMPLING) |
| 1927 |
+ { |
| 1928 |
+ if (!RewriteCubeMapSamplersAs2DArray(this, &root, &symbolTable, |
| 1929 |
+ getShaderType() == GL_FRAGMENT_SHADER)) |
| 1930 |
+ { |
| 1931 |
+ return false; |
| 1932 |
+ } |
| 1933 |
+ } |
| 1934 |
+ |
| 1935 |
+#if 0 |
| 1936 |
+ // Write default uniform block |
| 1937 |
+ if (defaultUniformCount > 0) |
| 1938 |
+ { |
| 1939 |
+ gl::ShaderType shaderType = gl::FromGLenum<gl::ShaderType>(getShaderType()); |
| 1940 |
+ sink << "\nstruct " << kDefaultUniformNames[shaderType] << "\n{\n"; |
| 1941 |
+ DeclareDefaultUniformsTraverser defaultTraverser(&sink, getHashFunction(), &getNameMap()); |
| 1942 |
+ root->traverse(&defaultTraverser); |
| 1943 |
+ if (!defaultTraverser.updateTree(this, root)) |
| 1944 |
+ { |
| 1945 |
+ return false; |
| 1946 |
+ } |
| 1947 |
+ |
| 1948 |
+ sink << "};\n"; |
| 1949 |
+ } |
| 1950 |
+#endif |
| 1951 |
+ |
| 1952 |
+ const TVariable &driverUniforms = *[&]() { |
| 1953 |
+ if (getShaderType() == GL_COMPUTE_SHADER) |
| 1954 |
+ { |
| 1955 |
+ return AddComputeDriverUniformsToShader(root, symbolTable); |
| 1956 |
+ } |
| 1957 |
+ else |
| 1958 |
+ { |
| 1959 |
+ std::vector<TField *> additionalFields; |
| 1960 |
+ createAdditionalGraphicsDriverUniformFields(additionalFields); |
| 1961 |
+ return AddGraphicsDriverUniformsToShader(root, symbolTable, additionalFields); |
| 1962 |
+ } |
| 1963 |
+ }(); |
| 1964 |
+ |
| 1965 |
+ if (atomicCounterCount > 0) |
| 1966 |
+ { |
| 1967 |
+ // ANGLEUniforms.acbBufferOffsets |
| 1968 |
+ const TIntermBinary *acbBufferOffsets = |
| 1969 |
+ CreateDriverUniformRef(driverUniforms, kAcbBufferOffsets); |
| 1970 |
+ |
| 1971 |
+ if (!RewriteAtomicCounters(this, &root, &symbolTable, acbBufferOffsets)) |
| 1972 |
+ { |
| 1973 |
+ return false; |
| 1974 |
+ } |
| 1975 |
+ } |
| 1976 |
+ else if (getShaderVersion() >= 310) |
| 1977 |
+ { |
| 1978 |
+ // Vulkan doesn't support Atomic Storage as a Storage Class, but we've seen |
| 1979 |
+ // cases where builtins are using it even with no active atomic counters. |
| 1980 |
+ // This pass simply removes those builtins in that scenario. |
| 1981 |
+ if (!RemoveAtomicCounterBuiltins(this, &root)) |
| 1982 |
+ { |
| 1983 |
+ return false; |
| 1984 |
+ } |
| 1985 |
+ } |
| 1986 |
+ |
| 1987 |
+ if (getShaderType() != GL_COMPUTE_SHADER) |
| 1988 |
+ { |
| 1989 |
+ if (!ReplaceGLDepthRangeWithDriverUniform(*this, root, driverUniforms)) |
| 1990 |
+ { |
| 1991 |
+ return false; |
| 1992 |
+ } |
| 1993 |
+ |
| 1994 |
+#if 0 |
| 1995 |
+ // Add specialization constant declarations. The default value of the specialization |
| 1996 |
+ // constant is irrelevant, as it will be set when creating the pipeline. |
| 1997 |
+ if (compileOptions & SH_ADD_BRESENHAM_LINE_RASTER_EMULATION) |
| 1998 |
+ { |
| 1999 |
+ sink << "layout(constant_id=" |
| 2000 |
+ << static_cast<uint32_t>(vk::SpecializationConstantId::LineRasterEmulation) |
| 2001 |
+ << ") const bool " << kLineRasterEmulationSpecConstVarName << " = false;\n\n"; |
| 2002 |
+ } |
| 2003 |
+#endif |
| 2004 |
+ } |
| 2005 |
+ |
| 2006 |
+ { |
| 2007 |
+ bool usesInstanceId = false; |
| 2008 |
+ for (const ShaderVariable &var : mAttributes) |
| 2009 |
+ { |
| 2010 |
+ if (var.isBuiltIn()) |
| 2011 |
+ { |
| 2012 |
+ if (var.name == "gl_InstanceID") |
| 2013 |
+ { |
| 2014 |
+ usesInstanceId = true; |
| 2015 |
+ } |
| 2016 |
+ } |
| 2017 |
+ } |
| 2018 |
+ |
| 2019 |
+ if (usesInstanceId) |
| 2020 |
+ { |
| 2021 |
+ root.insertChildNodes( |
| 2022 |
+ FindMainIndex(&root), |
| 2023 |
+ TIntermSequence{new TIntermDeclaration{BuiltInVariable::gl_InstanceID()}}); |
| 2024 |
+ } |
| 2025 |
+ } |
| 2026 |
+ |
| 2027 |
+ // Declare gl_FragColor and glFragData as webgl_FragColor and webgl_FragData |
| 2028 |
+ // if it's core profile shaders and they are used. |
| 2029 |
+ if (getShaderType() == GL_FRAGMENT_SHADER) |
| 2030 |
+ { |
| 2031 |
+ bool usesPointCoord = false; |
| 2032 |
+ bool usesFragCoord = false; |
| 2033 |
+ bool usesFrontFacing = false; |
| 2034 |
+ for (const ShaderVariable &inputVarying : mInputVaryings) |
| 2035 |
+ { |
| 2036 |
+ if (inputVarying.isBuiltIn()) |
| 2037 |
+ { |
| 2038 |
+ if (inputVarying.name == "gl_PointCoord") |
| 2039 |
+ { |
| 2040 |
+ usesPointCoord = true; |
| 2041 |
+ } |
| 2042 |
+ else if (inputVarying.name == "gl_FragCoord") |
| 2043 |
+ { |
| 2044 |
+ usesFragCoord = true; |
| 2045 |
+ } |
| 2046 |
+ else if (inputVarying.name == "gl_FrontFacing") |
| 2047 |
+ { |
| 2048 |
+ usesFrontFacing = true; |
| 2049 |
+ } |
| 2050 |
+ } |
| 2051 |
+ } |
| 2052 |
+ |
| 2053 |
+ bool usesFragColor = false; |
| 2054 |
+ bool usesFragData = false; |
| 2055 |
+ bool usesFragDepth = false; |
| 2056 |
+ for (const ShaderVariable &outputVarying : mOutputVariables) |
| 2057 |
+ { |
| 2058 |
+ if (outputVarying.isBuiltIn()) |
| 2059 |
+ { |
| 2060 |
+ if (outputVarying.name == "gl_FragColor") |
| 2061 |
+ { |
| 2062 |
+ usesFragColor = true; |
| 2063 |
+ } |
| 2064 |
+ else if (outputVarying.name == "gl_FragData") |
| 2065 |
+ { |
| 2066 |
+ usesFragData = true; |
| 2067 |
+ } |
| 2068 |
+ else if (outputVarying.name == "gl_FragDepth") |
| 2069 |
+ { |
| 2070 |
+ usesFragDepth = true; |
| 2071 |
+ } |
| 2072 |
+ } |
| 2073 |
+ } |
| 2074 |
+ |
| 2075 |
+ if (usesFragColor && usesFragData) |
| 2076 |
+ { |
| 2077 |
+ return false; |
| 2078 |
+ } |
| 2079 |
+ |
| 2080 |
+ if (usesFragColor) |
| 2081 |
+ { |
| 2082 |
+ AddFragColorDeclaration(root, symbolTable); |
| 2083 |
+ } |
| 2084 |
+ |
| 2085 |
+ if (usesFragData) |
| 2086 |
+ { |
| 2087 |
+ if (!AddFragDataDeclaration(*this, root)) |
| 2088 |
+ { |
| 2089 |
+ return false; |
| 2090 |
+ } |
| 2091 |
+ } |
| 2092 |
+ |
| 2093 |
+ if (usesFragDepth) |
| 2094 |
+ { |
| 2095 |
+ AddFragDepthDeclaration(root, symbolTable); |
| 2096 |
+ } |
| 2097 |
+ |
| 2098 |
+#if 0 |
| 2099 |
+ if (compileOptions & SH_ADD_BRESENHAM_LINE_RASTER_EMULATION) |
| 2100 |
+ { |
| 2101 |
+ if (!AddBresenhamEmulationFS(this, compileOptions, sink, root, &symbolTable, |
| 2102 |
+ driverUniforms, usesFragCoord)) |
| 2103 |
+ { |
| 2104 |
+ return false; |
| 2105 |
+ } |
| 2106 |
+ } |
| 2107 |
+#endif |
| 2108 |
+ |
| 2109 |
+ bool usePreRotation = compileOptions & SH_ADD_PRE_ROTATION; |
| 2110 |
+ |
| 2111 |
+ if (usesPointCoord) |
| 2112 |
+ { |
| 2113 |
+ TIntermBinary &flipXY = *CreateDriverUniformRef(driverUniforms, kNegFlipXY); |
| 2114 |
+ TIntermConstantUnion &pivot = *CreateFloatNode(0.5f); |
| 2115 |
+ TIntermBinary *fragRotation = |
| 2116 |
+ usePreRotation ? CreateDriverUniformRef(driverUniforms, kFragRotation) : nullptr; |
| 2117 |
+ if (!RotateAndFlipBuiltinVariable(*this, root, *GetMainSequence(root), flipXY, |
| 2118 |
+ *BuiltInVariable::gl_PointCoord(), |
| 2119 |
+ kFlippedPointCoordName, pivot, fragRotation)) |
| 2120 |
+ { |
| 2121 |
+ return false; |
| 2122 |
+ } |
| 2123 |
+ DeclareRightBeforeMain(root, *BuiltInVariable::gl_PointCoord()); |
| 2124 |
+ } |
| 2125 |
+ |
| 2126 |
+ if (usesFragCoord) |
| 2127 |
+ { |
| 2128 |
+ if (!InsertFragCoordCorrection(*this, compileOptions, root, *GetMainSequence(root), |
| 2129 |
+ driverUniforms)) |
| 2130 |
+ { |
| 2131 |
+ return false; |
| 2132 |
+ } |
| 2133 |
+ DeclareRightBeforeMain(root, *BuiltInVariable::gl_FragCoord()); |
| 2134 |
+ } |
| 2135 |
+ |
| 2136 |
+ { |
| 2137 |
+ TIntermBinary *flipXY = CreateDriverUniformRef(driverUniforms, kFlipXY); |
| 2138 |
+ TIntermBinary *fragRotation = |
| 2139 |
+ usePreRotation ? CreateDriverUniformRef(driverUniforms, kFragRotation) : nullptr; |
| 2140 |
+ if (!RewriteDfdy(this, &root, symbolTable, getShaderVersion(), flipXY, fragRotation)) |
| 2141 |
+ { |
| 2142 |
+ return false; |
| 2143 |
+ } |
| 2144 |
+ } |
| 2145 |
+ |
| 2146 |
+ if (usesFrontFacing) |
| 2147 |
+ { |
| 2148 |
+ DeclareRightBeforeMain(root, *BuiltInVariable::gl_FrontFacing()); |
| 2149 |
+ } |
| 2150 |
+ |
| 2151 |
+ EmitEarlyFragmentTestsGLSL(*this, sink); |
| 2152 |
+ } |
| 2153 |
+ else if (getShaderType() == GL_VERTEX_SHADER) |
| 2154 |
+ { |
| 2155 |
+ DeclareRightBeforeMain(root, *BuiltInVariable::gl_Position()); |
| 2156 |
+ |
| 2157 |
+ if (FindSymbolNode(&root, BuiltInVariable::gl_PointSize()->name())) |
| 2158 |
+ { |
| 2159 |
+ DeclareRightBeforeMain(root, *BuiltInVariable::gl_PointSize()); |
| 2160 |
+ } |
| 2161 |
+ |
| 2162 |
+ if (FindSymbolNode(&root, BuiltInVariable::gl_VertexIndex()->name())) |
| 2163 |
+ { |
| 2164 |
+ if (!ReplaceVariable(this, &root, BuiltInVariable::gl_VertexIndex(), |
| 2165 |
+ &kgl_VertexIndexMetal)) |
| 2166 |
+ { |
| 2167 |
+ return false; |
| 2168 |
+ } |
| 2169 |
+ DeclareRightBeforeMain(root, kgl_VertexIndexMetal); |
| 2170 |
+ } |
| 2171 |
+ |
| 2172 |
+#if 0 |
| 2173 |
+ if (compileOptions & SH_ADD_BRESENHAM_LINE_RASTER_EMULATION) |
| 2174 |
+ { |
| 2175 |
+ if (!AddBresenhamEmulationVS(this, root, &symbolTable, driverUniforms)) |
| 2176 |
+ { |
| 2177 |
+ return false; |
| 2178 |
+ } |
| 2179 |
+ } |
| 2180 |
+ |
| 2181 |
+ // Add a macro to declare transform feedback buffers. |
| 2182 |
+ sink << "@@ XFB-DECL @@\n\n"; |
| 2183 |
+#endif |
| 2184 |
+ |
| 2185 |
+ // Append a macro for transform feedback substitution prior to modifying depth. |
| 2186 |
+ if (!AppendVertexShaderTransformFeedbackOutputToMain(*this, root)) |
| 2187 |
+ { |
| 2188 |
+ return false; |
| 2189 |
+ } |
| 2190 |
+ |
| 2191 |
+ // Search for the gl_ClipDistance usage, if its used, we need to do some replacements. |
| 2192 |
+ bool useClipDistance = false; |
| 2193 |
+ for (const ShaderVariable &outputVarying : mOutputVaryings) |
| 2194 |
+ { |
| 2195 |
+ if (outputVarying.name == "gl_ClipDistance") |
| 2196 |
+ { |
| 2197 |
+ useClipDistance = true; |
| 2198 |
+ break; |
| 2199 |
+ } |
| 2200 |
+ } |
| 2201 |
+ |
| 2202 |
+ if (useClipDistance && !ReplaceClipDistanceAssignments( |
| 2203 |
+ this, &root, &symbolTable, |
| 2204 |
+ CreateDriverUniformRef(driverUniforms, kClipDistancesEnabled))) |
| 2205 |
+ { |
| 2206 |
+ return false; |
| 2207 |
+ } |
| 2208 |
+ |
| 2209 |
+ if (!transformDepthBeforeCorrection(root, driverUniforms)) |
| 2210 |
+ { |
| 2211 |
+ return false; |
| 2212 |
+ } |
| 2213 |
+ |
| 2214 |
+ if (!AppendVertexShaderDepthCorrectionToMain(*this, root)) |
| 2215 |
+ { |
| 2216 |
+ return false; |
| 2217 |
+ } |
| 2218 |
+ |
| 2219 |
+ if ((compileOptions & SH_ADD_PRE_ROTATION) != 0 && |
| 2220 |
+ !AppendPreRotation(*this, root, driverUniforms)) |
| 2221 |
+ { |
| 2222 |
+ return false; |
| 2223 |
+ } |
| 2224 |
+ } |
| 2225 |
+ else if (getShaderType() == GL_GEOMETRY_SHADER) |
| 2226 |
+ { |
| 2227 |
+ WriteGeometryShaderLayoutQualifiers( |
| 2228 |
+ sink, getGeometryShaderInputPrimitiveType(), getGeometryShaderInvocations(), |
| 2229 |
+ getGeometryShaderOutputPrimitiveType(), getGeometryShaderMaxVertices()); |
| 2230 |
+ } |
| 2231 |
+ else |
| 2232 |
+ { |
| 2233 |
+ ASSERT(getShaderType() == GL_COMPUTE_SHADER); |
| 2234 |
+ EmitWorkGroupSizeGLSL(*this, sink); |
| 2235 |
+ } |
| 2236 |
+ |
| 2237 |
+ if (getShaderType() == GL_VERTEX_SHADER) |
| 2238 |
+ { |
| 2239 |
+ auto &negFlipY = *getDriverUniformNegFlipYRef(driverUniforms); |
| 2240 |
+ |
| 2241 |
+ if (mEmulatedInstanceID) |
| 2242 |
+ { |
| 2243 |
+ if (!EmulateInstanceID(*this, root, driverUniforms)) |
| 2244 |
+ { |
| 2245 |
+ return false; |
| 2246 |
+ } |
| 2247 |
+ } |
| 2248 |
+ |
| 2249 |
+ if (!AppendVertexShaderPositionYCorrectionToMain(*this, root, negFlipY)) |
| 2250 |
+ { |
| 2251 |
+ return false; |
| 2252 |
+ } |
| 2253 |
+ |
| 2254 |
+ if (!insertRasterizationDiscardLogic(root)) |
| 2255 |
+ { |
| 2256 |
+ return false; |
| 2257 |
+ } |
| 2258 |
+ } |
| 2259 |
+ |
| 2260 |
+ if (!validateAST(&root)) |
| 2261 |
+ { |
| 2262 |
+ return false; |
| 2263 |
+ } |
| 2264 |
+ |
| 2265 |
+ if (!RewriteKeywords(*this, root, idGen, GetMslKeywords())) |
| 2266 |
+ { |
| 2267 |
+ return false; |
| 2268 |
+ } |
| 2269 |
+ |
| 2270 |
+ if (!ReduceInterfaceBlocks(*this, root)) |
| 2271 |
+ { |
| 2272 |
+ return false; |
| 2273 |
+ } |
| 2274 |
+ |
| 2275 |
+ if (!SeparateCompoundStructDeclarations(*this, root)) |
| 2276 |
+ { |
| 2277 |
+ return false; |
| 2278 |
+ } |
| 2279 |
+ |
| 2280 |
+ // This is the largest size required to pass all the tests in |
| 2281 |
+ // (dEQP-GLES3.functional.shaders.large_constant_arrays) |
| 2282 |
+ // This value could in principle be smaller. |
| 2283 |
+ const size_t hoistThresholdSize = 256; |
| 2284 |
+ if (!HoistConstants(*this, root, idGen, hoistThresholdSize)) |
| 2285 |
+ { |
| 2286 |
+ return false; |
| 2287 |
+ } |
| 2288 |
+ |
| 2289 |
+ Invariants invariants; |
| 2290 |
+ if (!RewriteGlobalQualifierDecls(*this, root, invariants)) |
| 2291 |
+ { |
| 2292 |
+ return false; |
| 2293 |
+ } |
| 2294 |
+ |
| 2295 |
+ SymbolEnv symbolEnv(*this, root); |
| 2296 |
+ |
| 2297 |
+ if (!AddExplicitTypeCasts(*this, root, symbolEnv)) |
| 2298 |
+ { |
| 2299 |
+ return false; |
| 2300 |
+ } |
| 2301 |
+ |
| 2302 |
+ PipelineStructs pipelineStructs; |
| 2303 |
+ if (!RewritePipelines(*this, root, idGen, driverUniforms, symbolEnv, invariants, |
| 2304 |
+ pipelineStructs)) |
| 2305 |
+ { |
| 2306 |
+ return false; |
| 2307 |
+ } |
| 2308 |
+ |
| 2309 |
+ if (!SeparateCompoundExpressions(*this, symbolEnv, idGen, root)) |
| 2310 |
+ { |
| 2311 |
+ return false; |
| 2312 |
+ } |
| 2313 |
+ |
| 2314 |
+ if (!RewriteCaseDeclarations(*this, root)) |
| 2315 |
+ { |
| 2316 |
+ return false; |
| 2317 |
+ } |
| 2318 |
+ |
| 2319 |
+ if (!RewriteUnaddressableReferences(*this, root, symbolEnv)) |
| 2320 |
+ { |
| 2321 |
+ return false; |
| 2322 |
+ } |
| 2323 |
+ |
| 2324 |
+ if (!RewriteOutArgs(*this, root, symbolEnv)) |
| 2325 |
+ { |
| 2326 |
+ return false; |
| 2327 |
+ } |
| 2328 |
+ |
| 2329 |
+ if (!ToposortStructs(*this, symbolEnv, root, ppc)) |
| 2330 |
+ { |
| 2331 |
+ return false; |
| 2332 |
+ } |
| 2333 |
+ |
| 2334 |
+ if (!EmitMetal(*this, root, idGen, pipelineStructs, invariants, symbolEnv, ppc)) |
| 2335 |
+ { |
| 2336 |
+ return false; |
| 2337 |
+ } |
| 2338 |
+ |
| 2339 |
+ ASSERT(validateAST(&root)); |
| 2340 |
+ |
| 2341 |
+ return true; |
| 2342 |
+} |
| 2343 |
+ |
| 2344 |
+bool TranslatorMetalDirect::translate(TIntermBlock *root, |
| 2345 |
+ ShCompileOptions compileOptions, |
| 2346 |
+ PerformanceDiagnostics *perfDiagnostics) |
| 2347 |
+{ |
| 2348 |
+ if (!root) |
| 2349 |
+ { |
| 2350 |
+ return false; |
| 2351 |
+ } |
| 2352 |
+ |
| 2353 |
+ TInfoSinkBase &sink = getInfoSink().obj; |
| 2354 |
+ |
| 2355 |
+ bool precisionEmulation = false; |
| 2356 |
+ if (!emulatePrecisionIfNeeded(root, sink, &precisionEmulation, SH_GLSL_VULKAN_OUTPUT)) |
| 2357 |
+ { |
| 2358 |
+ return false; |
| 2359 |
+ } |
| 2360 |
+ |
| 2361 |
+#if 0 |
| 2362 |
+ bool enablePrecision = ((compileOptions & SH_IGNORE_PRECISION_QUALIFIERS) == 0); |
| 2363 |
+ |
| 2364 |
+ TOutputMSL outputMSL(sink, getArrayIndexClampingStrategy(), getHashFunction(), getNameMap(), |
| 2365 |
+ &getSymbolTable(), getShaderType(), getShaderVersion(), getOutputType(), |
| 2366 |
+ precisionEmulation, enablePrecision, compileOptions); |
| 2367 |
+#endif |
| 2368 |
+ |
| 2369 |
+ if (!translateImpl(*root, compileOptions)) |
| 2370 |
+ { |
| 2371 |
+ return false; |
| 2372 |
+ } |
| 2373 |
+ |
| 2374 |
+#if 0 |
| 2375 |
+ // Write translated shader. |
| 2376 |
+ root->traverse(outputMSL); |
| 2377 |
+#endif |
| 2378 |
+ |
| 2379 |
+ return true; |
| 2380 |
+} |
| 2381 |
+bool TranslatorMetalDirect::shouldFlattenPragmaStdglInvariantAll() |
| 2382 |
+{ |
| 2383 |
+ // Not neccesary for MSL transformation. |
| 2384 |
+ return false; |
| 2385 |
+} |
| 2386 |
+ |
| 2387 |
+} // namespace sh |
| 2388 |
diff --git a/src/compiler/translator/TranslatorMetalDirect.h b/src/compiler/translator/TranslatorMetalDirect.h |
| 2389 |
new file mode 100644 |
| 2390 |
index 0000000..efcb306 |
| 2391 |
--- /dev/null |
| 2392 |
+++ b/src/compiler/translator/TranslatorMetalDirect.h |
| 2393 |
@@ -0,0 +1,132 @@ |
| 2394 |
+// |
| 2395 |
+// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 2396 |
+// Use of this source code is governed by a BSD-style license that can be |
| 2397 |
+// found in the LICENSE file. |
| 2398 |
+// |
| 2399 |
+ |
| 2400 |
+#ifndef COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_H_ |
| 2401 |
+#define COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_H_ |
| 2402 |
+ |
| 2403 |
+#include "compiler/translator/Compiler.h" |
| 2404 |
+ |
| 2405 |
+namespace sh |
| 2406 |
+{ |
| 2407 |
+class TOutputMSL; |
| 2408 |
+ |
| 2409 |
+typedef std::unordered_map<size_t, std::string> originalNamesMap; |
| 2410 |
+typedef std::unordered_map<std::string, size_t> samplerBindingMap; |
| 2411 |
+typedef std::unordered_map<std::string, size_t> textureBindingMap; |
| 2412 |
+typedef std::unordered_map<std::string, size_t> uniformBufferBindingMap; |
| 2413 |
+ |
| 2414 |
+class TranslatorMetalReflection |
| 2415 |
+{ |
| 2416 |
+ public: |
| 2417 |
+ TranslatorMetalReflection() {} |
| 2418 |
+ ~TranslatorMetalReflection() {} |
| 2419 |
+ |
| 2420 |
+ void addOriginalName(const size_t id, const std::string &name) |
| 2421 |
+ { |
| 2422 |
+ originalNames.insert({id, name}); |
| 2423 |
+ } |
| 2424 |
+ void addSamplerBinding(const std::string &name, size_t samplerBinding) |
| 2425 |
+ { |
| 2426 |
+ samplerBindings.insert({name, samplerBinding}); |
| 2427 |
+ } |
| 2428 |
+ void addTextureBinding(const std::string &name, size_t textureBinding) |
| 2429 |
+ { |
| 2430 |
+ textureBindings.insert({name, textureBinding}); |
| 2431 |
+ } |
| 2432 |
+ void addUniformBufferBinding(const std::string &name, size_t uniformBufferBinding) |
| 2433 |
+ { |
| 2434 |
+ uniformBufferBindings.insert({name, uniformBufferBinding}); |
| 2435 |
+ } |
| 2436 |
+ std::string getOriginalName(const size_t id) { return originalNames.at(id); } |
| 2437 |
+ samplerBindingMap getSamplerBindings() const { return samplerBindings; } |
| 2438 |
+ textureBindingMap getTextureBindings() const { return textureBindings; } |
| 2439 |
+ uniformBufferBindingMap getUniformBufferBindings() const { return uniformBufferBindings; } |
| 2440 |
+ size_t getSamplerBinding(const std::string &name) const |
| 2441 |
+ { |
| 2442 |
+ auto it = samplerBindings.find(name); |
| 2443 |
+ if (it != samplerBindings.end()) |
| 2444 |
+ { |
| 2445 |
+ return it->second; |
| 2446 |
+ } |
| 2447 |
+ ASSERT(0); |
| 2448 |
+ return std::numeric_limits<size_t>::max(); |
| 2449 |
+ } |
| 2450 |
+ size_t getTextureBinding(const std::string &name) const |
| 2451 |
+ { |
| 2452 |
+ auto it = textureBindings.find(name); |
| 2453 |
+ if (it != textureBindings.end()) |
| 2454 |
+ { |
| 2455 |
+ return it->second; |
| 2456 |
+ } |
| 2457 |
+ ASSERT(0); |
| 2458 |
+ return std::numeric_limits<size_t>::max(); |
| 2459 |
+ } |
| 2460 |
+ size_t getUniformBufferBinding(const std::string &name) const |
| 2461 |
+ { |
| 2462 |
+ auto it = uniformBufferBindings.find(name); |
| 2463 |
+ if (it != uniformBufferBindings.end()) |
| 2464 |
+ { |
| 2465 |
+ return it->second; |
| 2466 |
+ } |
| 2467 |
+ ASSERT(0); |
| 2468 |
+ return std::numeric_limits<size_t>::max(); |
| 2469 |
+ } |
| 2470 |
+ void reset() |
| 2471 |
+ { |
| 2472 |
+ originalNames.clear(); |
| 2473 |
+ samplerBindings.clear(); |
| 2474 |
+ textureBindings.clear(); |
| 2475 |
+ uniformBufferBindings.clear(); |
| 2476 |
+ } |
| 2477 |
+ |
| 2478 |
+ private: |
| 2479 |
+ originalNamesMap originalNames; |
| 2480 |
+ samplerBindingMap samplerBindings; |
| 2481 |
+ textureBindingMap textureBindings; |
| 2482 |
+ uniformBufferBindingMap uniformBufferBindings; |
| 2483 |
+}; |
| 2484 |
+ |
| 2485 |
+class TranslatorMetalDirect : public TCompiler |
| 2486 |
+{ |
| 2487 |
+ public: |
| 2488 |
+ TranslatorMetalDirect(sh::GLenum type, ShShaderSpec spec, ShShaderOutput output); |
| 2489 |
+ |
| 2490 |
+#ifdef ANGLE_ENABLE_METAL |
| 2491 |
+ TranslatorMetalDirect *getAsTranslatorMetalDirect() override { return this; } |
| 2492 |
+#endif |
| 2493 |
+ |
| 2494 |
+ static const char *GetCoverageMaskEnabledConstName(); |
| 2495 |
+ static const char *GetRasterizationDiscardEnabledConstName(); |
| 2496 |
+ |
| 2497 |
+ void enableEmulatedInstanceID(bool e) { mEmulatedInstanceID = e; } |
| 2498 |
+ TranslatorMetalReflection *getTranslatorMetalReflection() { return &translatorMetalReflection; } |
| 2499 |
+ |
| 2500 |
+ protected: |
| 2501 |
+ bool translate(TIntermBlock *root, |
| 2502 |
+ ShCompileOptions compileOptions, |
| 2503 |
+ PerformanceDiagnostics *perfDiagnostics) override; |
| 2504 |
+ |
| 2505 |
+ ANGLE_NO_DISCARD bool translateImpl(TIntermBlock &root, ShCompileOptions compileOptions); |
| 2506 |
+ |
| 2507 |
+ ANGLE_NO_DISCARD bool shouldFlattenPragmaStdglInvariantAll() override; |
| 2508 |
+ |
| 2509 |
+ ANGLE_NO_DISCARD bool transformDepthBeforeCorrection(TIntermBlock &root, |
| 2510 |
+ const TVariable &driverUniforms); |
| 2511 |
+ ANGLE_NO_DISCARD bool insertRasterizationDiscardLogic(TIntermBlock &root); |
| 2512 |
+ |
| 2513 |
+ void createAdditionalGraphicsDriverUniformFields(std::vector<TField *> &fieldsOut); |
| 2514 |
+ |
| 2515 |
+ ANGLE_NO_DISCARD TIntermSwizzle *getDriverUniformNegFlipYRef( |
| 2516 |
+ const TVariable &driverUniforms) const; |
| 2517 |
+ |
| 2518 |
+ bool mEmulatedInstanceID = false; |
| 2519 |
+ |
| 2520 |
+ TranslatorMetalReflection translatorMetalReflection = {}; |
| 2521 |
+}; |
| 2522 |
+ |
| 2523 |
+} // namespace sh |
| 2524 |
+ |
| 2525 |
+#endif // COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_H_ |
| 2526 |
diff --git a/src/compiler/translator/TranslatorMetalDirect/AddExplicitTypeCasts.cpp b/src/compiler/translator/TranslatorMetalDirect/AddExplicitTypeCasts.cpp |
| 2527 |
new file mode 100644 |
| 2528 |
index 0000000..5341180 |
| 2529 |
--- /dev/null |
| 2530 |
+++ b/src/compiler/translator/TranslatorMetalDirect/AddExplicitTypeCasts.cpp |
| 2531 |
@@ -0,0 +1,95 @@ |
| 2532 |
+// |
| 2533 |
+// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 2534 |
+// Use of this source code is governed by a BSD-style license that can be |
| 2535 |
+// found in the LICENSE file. |
| 2536 |
+// |
| 2537 |
+ |
| 2538 |
+#include "compiler/translator/TranslatorMetalDirect/AddExplicitTypeCasts.h" |
| 2539 |
+#include "compiler/translator/TranslatorMetalDirect/AstHelpers.h" |
| 2540 |
+#include "compiler/translator/tree_util/IntermRebuild.h" |
| 2541 |
+ |
| 2542 |
+using namespace sh; |
| 2543 |
+ |
| 2544 |
+namespace |
| 2545 |
+{ |
| 2546 |
+ |
| 2547 |
+class Rewriter : public TIntermRebuild |
| 2548 |
+{ |
| 2549 |
+ SymbolEnv &mSymbolEnv; |
| 2550 |
+ |
| 2551 |
+ public: |
| 2552 |
+ Rewriter(TCompiler &compiler, SymbolEnv &symbolEnv) |
| 2553 |
+ : TIntermRebuild(compiler, false, true), mSymbolEnv(symbolEnv) |
| 2554 |
+ {} |
| 2555 |
+ |
| 2556 |
+ PostResult visitAggregatePost(TIntermAggregate &callNode) override |
| 2557 |
+ { |
| 2558 |
+ const size_t argCount = callNode.getChildCount(); |
| 2559 |
+ const TType &retType = callNode.getType(); |
| 2560 |
+ |
| 2561 |
+ if (callNode.isConstructor()) |
| 2562 |
+ { |
| 2563 |
+ if (IsScalarBasicType(retType)) |
| 2564 |
+ { |
| 2565 |
+ if (argCount == 1) |
| 2566 |
+ { |
| 2567 |
+ TIntermTyped &arg = GetArg(callNode, 0); |
| 2568 |
+ const TType argType = arg.getType(); |
| 2569 |
+ if (argType.isVector()) |
| 2570 |
+ { |
| 2571 |
+ return CoerceSimple(retType, SubVector(arg, 0, 1)); |
| 2572 |
+ } |
| 2573 |
+ } |
| 2574 |
+ } |
| 2575 |
+ else if (retType.isVector()) |
| 2576 |
+ { |
| 2577 |
+ if (argCount == 1) |
| 2578 |
+ { |
| 2579 |
+ TIntermTyped &arg = GetArg(callNode, 0); |
| 2580 |
+ const TType argType = arg.getType(); |
| 2581 |
+ if (argType.isVector()) |
| 2582 |
+ { |
| 2583 |
+ return CoerceSimple(retType, SubVector(arg, 0, retType.getNominalSize())); |
| 2584 |
+ } |
| 2585 |
+ } |
| 2586 |
+ for (size_t i = 0; i < argCount; ++i) |
| 2587 |
+ { |
| 2588 |
+ TIntermTyped &arg = GetArg(callNode, i); |
| 2589 |
+ SetArg(callNode, i, CoerceSimple(retType.getBasicType(), arg)); |
| 2590 |
+ } |
| 2591 |
+ } |
| 2592 |
+ else if (retType.isMatrix()) |
| 2593 |
+ { |
| 2594 |
+ if (argCount == 1) |
| 2595 |
+ { |
| 2596 |
+ TIntermTyped &arg = GetArg(callNode, 0); |
| 2597 |
+ const TType argType = arg.getType(); |
| 2598 |
+ if (argType.isMatrix()) |
| 2599 |
+ { |
| 2600 |
+ if (retType.getCols() != argType.getCols() || |
| 2601 |
+ retType.getRows() != argType.getRows()) |
| 2602 |
+ { |
| 2603 |
+ TemplateArg templateArgs[] = {retType.getCols(), retType.getRows()}; |
| 2604 |
+ return mSymbolEnv.callFunctionOverload( |
| 2605 |
+ Name("cast"), retType, *new TIntermSequence{&arg}, 2, templateArgs); |
| 2606 |
+ } |
| 2607 |
+ } |
| 2608 |
+ } |
| 2609 |
+ } |
| 2610 |
+ } |
| 2611 |
+ |
| 2612 |
+ return callNode; |
| 2613 |
+ } |
| 2614 |
+}; |
| 2615 |
+ |
| 2616 |
+} // anonymous namespace |
| 2617 |
+ |
| 2618 |
+bool sh::AddExplicitTypeCasts(TCompiler &compiler, TIntermBlock &root, SymbolEnv &symbolEnv) |
| 2619 |
+{ |
| 2620 |
+ Rewriter rewriter(compiler, symbolEnv); |
| 2621 |
+ if (!rewriter.rebuildRoot(root)) |
| 2622 |
+ { |
| 2623 |
+ return false; |
| 2624 |
+ } |
| 2625 |
+ return true; |
| 2626 |
+} |
| 2627 |
diff --git a/src/compiler/translator/TranslatorMetalDirect/AddExplicitTypeCasts.h b/src/compiler/translator/TranslatorMetalDirect/AddExplicitTypeCasts.h |
| 2628 |
new file mode 100644 |
| 2629 |
index 0000000..5034288 |
| 2630 |
--- /dev/null |
| 2631 |
+++ b/src/compiler/translator/TranslatorMetalDirect/AddExplicitTypeCasts.h |
| 2632 |
@@ -0,0 +1,24 @@ |
| 2633 |
+// |
| 2634 |
+// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 2635 |
+// Use of this source code is governed by a BSD-style license that can be |
| 2636 |
+// found in the LICENSE file. |
| 2637 |
+// |
| 2638 |
+ |
| 2639 |
+#ifndef COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_ADDEXPLICITTYPECASTS_H_ |
| 2640 |
+#define COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_ADDEXPLICITTYPECASTS_H_ |
| 2641 |
+ |
| 2642 |
+#include "compiler/translator/Compiler.h" |
| 2643 |
+#include "compiler/translator/TranslatorMetalDirect/ProgramPrelude.h" |
| 2644 |
+#include "compiler/translator/TranslatorMetalDirect/SymbolEnv.h" |
| 2645 |
+ |
| 2646 |
+namespace sh |
| 2647 |
+{ |
| 2648 |
+ |
| 2649 |
+// Adds explicit type casts into the AST where casting is done implicitly. |
| 2650 |
+ANGLE_NO_DISCARD bool AddExplicitTypeCasts(TCompiler &compiler, |
| 2651 |
+ TIntermBlock &root, |
| 2652 |
+ SymbolEnv &symbolEnv); |
| 2653 |
+ |
| 2654 |
+} // namespace sh |
| 2655 |
+ |
| 2656 |
+#endif // COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_ADDEXPLICITTYPECASTS_H_ |
| 2657 |
diff --git a/src/compiler/translator/TranslatorMetalDirect/AstHelpers.cpp b/src/compiler/translator/TranslatorMetalDirect/AstHelpers.cpp |
| 2658 |
new file mode 100644 |
| 2659 |
index 0000000..4ba4ec7 |
| 2660 |
--- /dev/null |
| 2661 |
+++ b/src/compiler/translator/TranslatorMetalDirect/AstHelpers.cpp |
| 2662 |
@@ -0,0 +1,474 @@ |
| 2663 |
+// |
| 2664 |
+// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 2665 |
+// Use of this source code is governed by a BSD-style license that can be |
| 2666 |
+// found in the LICENSE file. |
| 2667 |
+// |
| 2668 |
+ |
| 2669 |
+#include <cstring> |
| 2670 |
+#include <numeric> |
| 2671 |
+#include <unordered_map> |
| 2672 |
+#include <unordered_set> |
| 2673 |
+ |
| 2674 |
+#include "compiler/translator/TranslatorMetalDirect/AstHelpers.h" |
| 2675 |
+ |
| 2676 |
+using namespace sh; |
| 2677 |
+ |
| 2678 |
+//////////////////////////////////////////////////////////////////////////////// |
| 2679 |
+ |
| 2680 |
+Declaration sh::ViewDeclaration(TIntermDeclaration &declNode) |
| 2681 |
+{ |
| 2682 |
+ ASSERT(declNode.getChildCount() == 1); |
| 2683 |
+ TIntermNode *childNode = declNode.getChildNode(0); |
| 2684 |
+ ASSERT(childNode); |
| 2685 |
+ TIntermSymbol *symbolNode; |
| 2686 |
+ if ((symbolNode = childNode->getAsSymbolNode())) |
| 2687 |
+ { |
| 2688 |
+ return {*symbolNode, nullptr}; |
| 2689 |
+ } |
| 2690 |
+ else |
| 2691 |
+ { |
| 2692 |
+ TIntermBinary *initNode = childNode->getAsBinaryNode(); |
| 2693 |
+ ASSERT(initNode); |
| 2694 |
+ ASSERT(initNode->getOp() == TOperator::EOpInitialize); |
| 2695 |
+ symbolNode = initNode->getLeft()->getAsSymbolNode(); |
| 2696 |
+ ASSERT(symbolNode); |
| 2697 |
+ return {*symbolNode, initNode->getRight()}; |
| 2698 |
+ } |
| 2699 |
+} |
| 2700 |
+ |
| 2701 |
+const TVariable &sh::CreateStructTypeVariable(TSymbolTable &symbolTable, |
| 2702 |
+ const TStructure &structure) |
| 2703 |
+{ |
| 2704 |
+ auto *type = new TType(&structure, true); |
| 2705 |
+ auto *var = new TVariable(&symbolTable, ImmutableString(""), type, SymbolType::Empty); |
| 2706 |
+ return *var; |
| 2707 |
+} |
| 2708 |
+ |
| 2709 |
+const TVariable &sh::CreateInstanceVariable(TSymbolTable &symbolTable, |
| 2710 |
+ const TStructure &structure, |
| 2711 |
+ const Name &name, |
| 2712 |
+ TQualifier qualifier, |
| 2713 |
+ const TSpan<const unsigned int> *arraySizes) |
| 2714 |
+{ |
| 2715 |
+ auto *type = new TType(&structure, false); |
| 2716 |
+ type->setQualifier(qualifier); |
| 2717 |
+ if (arraySizes) |
| 2718 |
+ { |
| 2719 |
+ type->makeArrays(*arraySizes); |
| 2720 |
+ } |
| 2721 |
+ auto *var = new TVariable(&symbolTable, name.rawName(), type, name.symbolType()); |
| 2722 |
+ return *var; |
| 2723 |
+} |
| 2724 |
+ |
| 2725 |
+static void AcquireFunctionExtras(TFunction &dest, const TFunction &src) |
| 2726 |
+{ |
| 2727 |
+ if (src.isDefined()) |
| 2728 |
+ { |
| 2729 |
+ dest.setDefined(); |
| 2730 |
+ } |
| 2731 |
+ |
| 2732 |
+ if (src.hasPrototypeDeclaration()) |
| 2733 |
+ { |
| 2734 |
+ dest.setHasPrototypeDeclaration(); |
| 2735 |
+ } |
| 2736 |
+} |
| 2737 |
+ |
| 2738 |
+TIntermSequence &sh::CloneSequenceAndPrepend(const TIntermSequence &seq, TIntermNode &node) |
| 2739 |
+{ |
| 2740 |
+ auto *newSeq = new TIntermSequence(); |
| 2741 |
+ newSeq->push_back(&node); |
| 2742 |
+ |
| 2743 |
+ for (TIntermNode *oldNode : seq) |
| 2744 |
+ { |
| 2745 |
+ newSeq->push_back(oldNode); |
| 2746 |
+ } |
| 2747 |
+ |
| 2748 |
+ return *newSeq; |
| 2749 |
+} |
| 2750 |
+ |
| 2751 |
+void sh::AddParametersFrom(TFunction &dest, const TFunction &src) |
| 2752 |
+{ |
| 2753 |
+ const size_t paramCount = src.getParamCount(); |
| 2754 |
+ for (size_t i = 0; i < paramCount; ++i) |
| 2755 |
+ { |
| 2756 |
+ const TVariable *var = src.getParam(i); |
| 2757 |
+ dest.addParameter(var); |
| 2758 |
+ } |
| 2759 |
+} |
| 2760 |
+ |
| 2761 |
+const TFunction &sh::CloneFunction(TSymbolTable &symbolTable, |
| 2762 |
+ IdGen &idGen, |
| 2763 |
+ const TFunction &oldFunc) |
| 2764 |
+{ |
| 2765 |
+ ASSERT(oldFunc.symbolType() == SymbolType::UserDefined); |
| 2766 |
+ |
| 2767 |
+ Name newName = idGen.createNewName(Name(oldFunc)); |
| 2768 |
+ |
| 2769 |
+ auto &newFunc = *new TFunction(&symbolTable, newName.rawName(), newName.symbolType(), |
| 2770 |
+ &oldFunc.getReturnType(), oldFunc.isKnownToNotHaveSideEffects()); |
| 2771 |
+ |
| 2772 |
+ AcquireFunctionExtras(newFunc, oldFunc); |
| 2773 |
+ AddParametersFrom(newFunc, oldFunc); |
| 2774 |
+ |
| 2775 |
+ return newFunc; |
| 2776 |
+} |
| 2777 |
+ |
| 2778 |
+const TFunction &sh::CloneFunctionAndPrependParam(TSymbolTable &symbolTable, |
| 2779 |
+ IdGen *idGen, |
| 2780 |
+ const TFunction &oldFunc, |
| 2781 |
+ const TVariable &newParam) |
| 2782 |
+{ |
| 2783 |
+ ASSERT(oldFunc.symbolType() == SymbolType::UserDefined || |
| 2784 |
+ oldFunc.symbolType() == SymbolType::AngleInternal); |
| 2785 |
+ |
| 2786 |
+ Name newName = idGen ? idGen->createNewName(Name(oldFunc)) : Name(oldFunc); |
| 2787 |
+ |
| 2788 |
+ auto &newFunc = *new TFunction(&symbolTable, newName.rawName(), newName.symbolType(), |
| 2789 |
+ &oldFunc.getReturnType(), oldFunc.isKnownToNotHaveSideEffects()); |
| 2790 |
+ |
| 2791 |
+ AcquireFunctionExtras(newFunc, oldFunc); |
| 2792 |
+ newFunc.addParameter(&newParam); |
| 2793 |
+ AddParametersFrom(newFunc, oldFunc); |
| 2794 |
+ |
| 2795 |
+ return newFunc; |
| 2796 |
+} |
| 2797 |
+ |
| 2798 |
+const TFunction &sh::CloneFunctionAndAppendParams(TSymbolTable &symbolTable, |
| 2799 |
+ IdGen *idGen, |
| 2800 |
+ const TFunction &oldFunc, |
| 2801 |
+ const std::vector<const TVariable *> &newParams) |
| 2802 |
+{ |
| 2803 |
+ ASSERT(oldFunc.symbolType() == SymbolType::UserDefined || |
| 2804 |
+ oldFunc.symbolType() == SymbolType::AngleInternal); |
| 2805 |
+ |
| 2806 |
+ Name newName = idGen ? idGen->createNewName(Name(oldFunc)) : Name(oldFunc); |
| 2807 |
+ |
| 2808 |
+ auto &newFunc = *new TFunction(&symbolTable, newName.rawName(), newName.symbolType(), |
| 2809 |
+ &oldFunc.getReturnType(), oldFunc.isKnownToNotHaveSideEffects()); |
| 2810 |
+ |
| 2811 |
+ AcquireFunctionExtras(newFunc, oldFunc); |
| 2812 |
+ AddParametersFrom(newFunc, oldFunc); |
| 2813 |
+ for (auto *param : newParams) |
| 2814 |
+ { |
| 2815 |
+ newFunc.addParameter(param); |
| 2816 |
+ } |
| 2817 |
+ |
| 2818 |
+ return newFunc; |
| 2819 |
+} |
| 2820 |
+ |
| 2821 |
+const TFunction &sh::CloneFunctionAndChangeReturnType(TSymbolTable &symbolTable, |
| 2822 |
+ IdGen *idGen, |
| 2823 |
+ const TFunction &oldFunc, |
| 2824 |
+ const TStructure &newReturn) |
| 2825 |
+{ |
| 2826 |
+ ASSERT(oldFunc.symbolType() == SymbolType::UserDefined); |
| 2827 |
+ |
| 2828 |
+ Name newName = idGen ? idGen->createNewName(Name(oldFunc)) : Name(oldFunc); |
| 2829 |
+ |
| 2830 |
+ auto *newReturnType = new TType(&newReturn, true); |
| 2831 |
+ auto &newFunc = *new TFunction(&symbolTable, newName.rawName(), newName.symbolType(), |
| 2832 |
+ newReturnType, oldFunc.isKnownToNotHaveSideEffects()); |
| 2833 |
+ |
| 2834 |
+ AcquireFunctionExtras(newFunc, oldFunc); |
| 2835 |
+ AddParametersFrom(newFunc, oldFunc); |
| 2836 |
+ |
| 2837 |
+ return newFunc; |
| 2838 |
+} |
| 2839 |
+ |
| 2840 |
+TIntermTyped &sh::GetArg(const TIntermAggregate &call, size_t index) |
| 2841 |
+{ |
| 2842 |
+ ASSERT(index < call.getChildCount()); |
| 2843 |
+ auto *arg = call.getChildNode(index); |
| 2844 |
+ ASSERT(arg); |
| 2845 |
+ auto *targ = arg->getAsTyped(); |
| 2846 |
+ ASSERT(targ); |
| 2847 |
+ return *targ; |
| 2848 |
+} |
| 2849 |
+ |
| 2850 |
+void sh::SetArg(TIntermAggregate &call, size_t index, TIntermTyped &arg) |
| 2851 |
+{ |
| 2852 |
+ ASSERT(index < call.getChildCount()); |
| 2853 |
+ (*call.getSequence())[index] = &arg; |
| 2854 |
+} |
| 2855 |
+ |
| 2856 |
+int sh::GetFieldIndex(const TStructure &structure, const ImmutableString &fieldName) |
| 2857 |
+{ |
| 2858 |
+ const TFieldList &fieldList = structure.fields(); |
| 2859 |
+ |
| 2860 |
+ int i = 0; |
| 2861 |
+ for (TField *field : fieldList) |
| 2862 |
+ { |
| 2863 |
+ if (field->name() == fieldName) |
| 2864 |
+ { |
| 2865 |
+ return i; |
| 2866 |
+ } |
| 2867 |
+ ++i; |
| 2868 |
+ } |
| 2869 |
+ |
| 2870 |
+ return -1; |
| 2871 |
+} |
| 2872 |
+ |
| 2873 |
+TIntermBinary &sh::AccessField(const TVariable &structInstanceVar, const ImmutableString &fieldName) |
| 2874 |
+{ |
| 2875 |
+ return AccessField(*new TIntermSymbol(&structInstanceVar), fieldName); |
| 2876 |
+} |
| 2877 |
+ |
| 2878 |
+TIntermBinary &sh::AccessField(TIntermTyped &object, const ImmutableString &fieldName) |
| 2879 |
+{ |
| 2880 |
+ const TStructure *structure = object.getType().getStruct(); |
| 2881 |
+ ASSERT(structure); |
| 2882 |
+ |
| 2883 |
+ const int index = GetFieldIndex(*structure, fieldName); |
| 2884 |
+ ASSERT(index >= 0); |
| 2885 |
+ return AccessFieldByIndex(object, index); |
| 2886 |
+} |
| 2887 |
+ |
| 2888 |
+TIntermBinary &sh::AccessFieldByIndex(TIntermTyped &object, int index) |
| 2889 |
+{ |
| 2890 |
+#if defined(ANGLE_ENABLE_ASSERTS) |
| 2891 |
+ const TType &type = object.getType(); |
| 2892 |
+ ASSERT(!type.isArray()); |
| 2893 |
+ const TStructure *structure = type.getStruct(); |
| 2894 |
+ ASSERT(structure); |
| 2895 |
+ ASSERT(0 <= index); |
| 2896 |
+ ASSERT(static_cast<size_t>(index) < structure->fields().size()); |
| 2897 |
+#endif |
| 2898 |
+ |
| 2899 |
+ return *new TIntermBinary( |
| 2900 |
+ TOperator::EOpIndexDirectStruct, &object, |
| 2901 |
+ new TIntermConstantUnion(new TConstantUnion(index), *new TType(TBasicType::EbtInt))); |
| 2902 |
+} |
| 2903 |
+ |
| 2904 |
+TIntermBinary &sh::AccessIndex(TIntermTyped &indexableNode, int index) |
| 2905 |
+{ |
| 2906 |
+#if defined(ANGLE_ENABLE_ASSERTS) |
| 2907 |
+ const TType &type = indexableNode.getType(); |
| 2908 |
+ ASSERT(type.isArray() || type.isVector() || type.isMatrix()); |
| 2909 |
+#endif |
| 2910 |
+ |
| 2911 |
+ auto *accessNode = new TIntermBinary( |
| 2912 |
+ TOperator::EOpIndexDirect, &indexableNode, |
| 2913 |
+ new TIntermConstantUnion(new TConstantUnion(index), *new TType(TBasicType::EbtInt))); |
| 2914 |
+ return *accessNode; |
| 2915 |
+} |
| 2916 |
+ |
| 2917 |
+TIntermTyped &sh::AccessIndex(TIntermTyped &node, const int *index) |
| 2918 |
+{ |
| 2919 |
+ if (index) |
| 2920 |
+ { |
| 2921 |
+ return AccessIndex(node, *index); |
| 2922 |
+ } |
| 2923 |
+ return node; |
| 2924 |
+} |
| 2925 |
+ |
| 2926 |
+TIntermTyped &sh::SubVector(TIntermTyped &vectorNode, int begin, int end) |
| 2927 |
+{ |
| 2928 |
+ ASSERT(vectorNode.getType().isVector()); |
| 2929 |
+ ASSERT(0 <= begin); |
| 2930 |
+ ASSERT(end <= 4); |
| 2931 |
+ ASSERT(begin <= end); |
| 2932 |
+ if (begin == 0 && end == vectorNode.getType().getNominalSize()) |
| 2933 |
+ { |
| 2934 |
+ return vectorNode; |
| 2935 |
+ } |
| 2936 |
+ TVector<int> offsets(static_cast<size_t>(end - begin)); |
| 2937 |
+ std::iota(offsets.begin(), offsets.end(), begin); |
| 2938 |
+ auto *swizzle = new TIntermSwizzle(&vectorNode, offsets); |
| 2939 |
+ return *swizzle; |
| 2940 |
+} |
| 2941 |
+ |
| 2942 |
+bool sh::IsScalarBasicType(const TType &type) |
| 2943 |
+{ |
| 2944 |
+ if (!type.isScalar()) |
| 2945 |
+ { |
| 2946 |
+ return false; |
| 2947 |
+ } |
| 2948 |
+ return HasScalarBasicType(type); |
| 2949 |
+} |
| 2950 |
+ |
| 2951 |
+bool sh::IsVectorBasicType(const TType &type) |
| 2952 |
+{ |
| 2953 |
+ if (!type.isVector()) |
| 2954 |
+ { |
| 2955 |
+ return false; |
| 2956 |
+ } |
| 2957 |
+ return HasScalarBasicType(type); |
| 2958 |
+} |
| 2959 |
+ |
| 2960 |
+bool sh::HasScalarBasicType(TBasicType type) |
| 2961 |
+{ |
| 2962 |
+ switch (type) |
| 2963 |
+ { |
| 2964 |
+ case TBasicType::EbtFloat: |
| 2965 |
+ case TBasicType::EbtDouble: |
| 2966 |
+ case TBasicType::EbtInt: |
| 2967 |
+ case TBasicType::EbtUInt: |
| 2968 |
+ case TBasicType::EbtBool: |
| 2969 |
+ return true; |
| 2970 |
+ |
| 2971 |
+ default: |
| 2972 |
+ return false; |
| 2973 |
+ } |
| 2974 |
+} |
| 2975 |
+ |
| 2976 |
+bool sh::HasScalarBasicType(const TType &type) |
| 2977 |
+{ |
| 2978 |
+ return HasScalarBasicType(type.getBasicType()); |
| 2979 |
+} |
| 2980 |
+ |
| 2981 |
+static void InitType(TType &type) |
| 2982 |
+{ |
| 2983 |
+ if (type.isArray()) |
| 2984 |
+ { |
| 2985 |
+ auto sizes = type.getArraySizes(); |
| 2986 |
+ type.toArrayBaseType(); |
| 2987 |
+ type.makeArrays(sizes); |
| 2988 |
+ } |
| 2989 |
+} |
| 2990 |
+ |
| 2991 |
+TType &sh::CloneType(const TType &type) |
| 2992 |
+{ |
| 2993 |
+ auto &clone = *new TType(type); |
| 2994 |
+ InitType(clone); |
| 2995 |
+ return clone; |
| 2996 |
+} |
| 2997 |
+ |
| 2998 |
+TType &sh::InnermostType(const TType &type) |
| 2999 |
+{ |
| 3000 |
+ auto &inner = *new TType(type); |
| 3001 |
+ inner.toArrayBaseType(); |
| 3002 |
+ InitType(inner); |
| 3003 |
+ return inner; |
| 3004 |
+} |
| 3005 |
+ |
| 3006 |
+TType &sh::DropColumns(const TType &matrixType) |
| 3007 |
+{ |
| 3008 |
+ ASSERT(matrixType.isMatrix()); |
| 3009 |
+ ASSERT(HasScalarBasicType(matrixType)); |
| 3010 |
+ const char *mangledName = nullptr; |
| 3011 |
+ |
| 3012 |
+ auto &vectorType = |
| 3013 |
+ *new TType(matrixType.getBasicType(), matrixType.getPrecision(), matrixType.getQualifier(), |
| 3014 |
+ matrixType.getRows(), 1, matrixType.getArraySizes(), mangledName); |
| 3015 |
+ InitType(vectorType); |
| 3016 |
+ return vectorType; |
| 3017 |
+} |
| 3018 |
+ |
| 3019 |
+TType &sh::DropOuterDimension(const TType &arrayType) |
| 3020 |
+{ |
| 3021 |
+ ASSERT(arrayType.isArray()); |
| 3022 |
+ const char *mangledName = nullptr; |
| 3023 |
+ const auto &arraySizes = arrayType.getArraySizes(); |
| 3024 |
+ |
| 3025 |
+ auto &innerType = |
| 3026 |
+ *new TType(arrayType.getBasicType(), arrayType.getPrecision(), arrayType.getQualifier(), |
| 3027 |
+ arrayType.getNominalSize(), arrayType.getSecondarySize(), |
| 3028 |
+ arraySizes.subspan(0, arraySizes.size() - 1), mangledName); |
| 3029 |
+ InitType(innerType); |
| 3030 |
+ return innerType; |
| 3031 |
+} |
| 3032 |
+ |
| 3033 |
+static TType &SetTypeDimsImpl(const TType &type, int primary, int secondary) |
| 3034 |
+{ |
| 3035 |
+ ASSERT(1 < primary && primary <= 4); |
| 3036 |
+ ASSERT(1 <= secondary && secondary <= 4); |
| 3037 |
+ ASSERT(HasScalarBasicType(type)); |
| 3038 |
+ const char *mangledName = nullptr; |
| 3039 |
+ |
| 3040 |
+ auto &newType = *new TType(type.getBasicType(), type.getPrecision(), type.getQualifier(), |
| 3041 |
+ primary, secondary, type.getArraySizes(), mangledName); |
| 3042 |
+ InitType(newType); |
| 3043 |
+ return newType; |
| 3044 |
+} |
| 3045 |
+ |
| 3046 |
+TType &sh::SetVectorDim(const TType &type, int newDim) |
| 3047 |
+{ |
| 3048 |
+ ASSERT(type.isRank0() || type.isVector()); |
| 3049 |
+ return SetTypeDimsImpl(type, newDim, 1); |
| 3050 |
+} |
| 3051 |
+ |
| 3052 |
+TType &sh::SetMatrixRowDim(const TType &matrixType, int newDim) |
| 3053 |
+{ |
| 3054 |
+ ASSERT(matrixType.isMatrix()); |
| 3055 |
+ ASSERT(1 < newDim && newDim <= 4); |
| 3056 |
+ return SetTypeDimsImpl(matrixType, matrixType.getCols(), newDim); |
| 3057 |
+} |
| 3058 |
+ |
| 3059 |
+bool sh::HasMatrixField(const TStructure &structure) |
| 3060 |
+{ |
| 3061 |
+ for (const TField *field : structure.fields()) |
| 3062 |
+ { |
| 3063 |
+ const TType &type = *field->type(); |
| 3064 |
+ if (type.isMatrix()) |
| 3065 |
+ { |
| 3066 |
+ return true; |
| 3067 |
+ } |
| 3068 |
+ } |
| 3069 |
+ return false; |
| 3070 |
+} |
| 3071 |
+ |
| 3072 |
+bool sh::HasArrayField(const TStructure &structure) |
| 3073 |
+{ |
| 3074 |
+ for (const TField *field : structure.fields()) |
| 3075 |
+ { |
| 3076 |
+ const TType &type = *field->type(); |
| 3077 |
+ if (type.isArray()) |
| 3078 |
+ { |
| 3079 |
+ return true; |
| 3080 |
+ } |
| 3081 |
+ } |
| 3082 |
+ return false; |
| 3083 |
+} |
| 3084 |
+ |
| 3085 |
+TIntermTyped &sh::CoerceSimple(TBasicType toType, TIntermTyped &fromNode) |
| 3086 |
+{ |
| 3087 |
+ const TType &fromType = fromNode.getType(); |
| 3088 |
+ |
| 3089 |
+ ASSERT(HasScalarBasicType(toType)); |
| 3090 |
+ ASSERT(HasScalarBasicType(fromType)); |
| 3091 |
+ ASSERT(!fromType.isArray()); |
| 3092 |
+ |
| 3093 |
+ if (toType != fromType.getBasicType()) |
| 3094 |
+ { |
| 3095 |
+ return *TIntermAggregate::CreateConstructor( |
| 3096 |
+ *new TType(toType, fromType.getNominalSize(), fromType.getSecondarySize()), |
| 3097 |
+ new TIntermSequence{&fromNode}); |
| 3098 |
+ } |
| 3099 |
+ return fromNode; |
| 3100 |
+} |
| 3101 |
+ |
| 3102 |
+TIntermTyped &sh::CoerceSimple(const TType &toType, TIntermTyped &fromNode) |
| 3103 |
+{ |
| 3104 |
+ const TType &fromType = fromNode.getType(); |
| 3105 |
+ |
| 3106 |
+ ASSERT(HasScalarBasicType(toType)); |
| 3107 |
+ ASSERT(HasScalarBasicType(fromType)); |
| 3108 |
+ ASSERT(toType.getNominalSize() == fromType.getNominalSize()); |
| 3109 |
+ ASSERT(toType.getSecondarySize() == fromType.getSecondarySize()); |
| 3110 |
+ ASSERT(!toType.isArray()); |
| 3111 |
+ ASSERT(!fromType.isArray()); |
| 3112 |
+ |
| 3113 |
+ if (toType.getBasicType() != fromType.getBasicType()) |
| 3114 |
+ { |
| 3115 |
+ return *TIntermAggregate::CreateConstructor(toType, new TIntermSequence{&fromNode}); |
| 3116 |
+ } |
| 3117 |
+ return fromNode; |
| 3118 |
+} |
| 3119 |
+ |
| 3120 |
+TIntermTyped &sh::AsType(SymbolEnv &symbolEnv, const TType &toType, TIntermTyped &fromNode) |
| 3121 |
+{ |
| 3122 |
+ const TType &fromType = fromNode.getType(); |
| 3123 |
+ |
| 3124 |
+ ASSERT(HasScalarBasicType(toType)); |
| 3125 |
+ ASSERT(HasScalarBasicType(fromType)); |
| 3126 |
+ ASSERT(!toType.isArray()); |
| 3127 |
+ ASSERT(!fromType.isArray()); |
| 3128 |
+ |
| 3129 |
+ if (toType == fromType) |
| 3130 |
+ { |
| 3131 |
+ return fromNode; |
| 3132 |
+ } |
| 3133 |
+ TemplateArg targ(toType); |
| 3134 |
+ return symbolEnv.callFunctionOverload(Name("as_type", SymbolType::BuiltIn), toType, |
| 3135 |
+ *new TIntermSequence{&fromNode}, 1, &targ); |
| 3136 |
+} |
| 3137 |
diff --git a/src/compiler/translator/TranslatorMetalDirect/AstHelpers.h b/src/compiler/translator/TranslatorMetalDirect/AstHelpers.h |
| 3138 |
new file mode 100644 |
| 3139 |
index 0000000..d9e89fe |
| 3140 |
--- /dev/null |
| 3141 |
+++ b/src/compiler/translator/TranslatorMetalDirect/AstHelpers.h |
| 3142 |
@@ -0,0 +1,157 @@ |
| 3143 |
+// |
| 3144 |
+// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 3145 |
+// Use of this source code is governed by a BSD-style license that can be |
| 3146 |
+// found in the LICENSE file. |
| 3147 |
+// |
| 3148 |
+ |
| 3149 |
+#ifndef COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_ASTHELPERS_H_ |
| 3150 |
+#define COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_ASTHELPERS_H_ |
| 3151 |
+ |
| 3152 |
+#include <cstring> |
| 3153 |
+#include <unordered_map> |
| 3154 |
+#include <unordered_set> |
| 3155 |
+ |
| 3156 |
+#include "compiler/translator/TranslatorMetalDirect/IdGen.h" |
| 3157 |
+#include "compiler/translator/TranslatorMetalDirect/Name.h" |
| 3158 |
+#include "compiler/translator/TranslatorMetalDirect/SymbolEnv.h" |
| 3159 |
+ |
| 3160 |
+namespace sh |
| 3161 |
+{ |
| 3162 |
+ |
| 3163 |
+// A convenience view of a TIntermDeclaration node's children. |
| 3164 |
+struct Declaration |
| 3165 |
+{ |
| 3166 |
+ TIntermSymbol &symbol; |
| 3167 |
+ TIntermTyped *initExpr; // Non-null iff declaration is initialized. |
| 3168 |
+}; |
| 3169 |
+ |
| 3170 |
+// Returns a `Declaration` view of the given node. |
| 3171 |
+Declaration ViewDeclaration(TIntermDeclaration &declNode); |
| 3172 |
+ |
| 3173 |
+// Creates a variable for a struct type. |
| 3174 |
+const TVariable &CreateStructTypeVariable(TSymbolTable &symbolTable, const TStructure &structure); |
| 3175 |
+ |
| 3176 |
+// Creates a variable for a struct instance. |
| 3177 |
+const TVariable &CreateInstanceVariable(TSymbolTable &symbolTable, |
| 3178 |
+ const TStructure &structure, |
| 3179 |
+ const Name &name, |
| 3180 |
+ TQualifier qualifier = TQualifier::EvqTemporary, |
| 3181 |
+ const TSpan<const unsigned int> *arraySizes = nullptr); |
| 3182 |
+ |
| 3183 |
+// The input sequence should be discarded from AST after this is called. |
| 3184 |
+TIntermSequence &CloneSequenceAndPrepend(const TIntermSequence &seq, TIntermNode &node); |
| 3185 |
+ |
| 3186 |
+// Appends parameters from `src` function to `dest` function. |
| 3187 |
+void AddParametersFrom(TFunction &dest, const TFunction &src); |
| 3188 |
+ |
| 3189 |
+// Clones a function. |
| 3190 |
+const TFunction &CloneFunction(TSymbolTable &symbolTable, IdGen &idGen, const TFunction &oldFunc); |
| 3191 |
+ |
| 3192 |
+// Clones a function and prepends the provided extr parameter. |
| 3193 |
+// If `idGen` is null, the original function must be discarded from the AST. |
| 3194 |
+const TFunction &CloneFunctionAndPrependParam(TSymbolTable &symbolTable, |
| 3195 |
+ IdGen *idGen, |
| 3196 |
+ const TFunction &oldFunc, |
| 3197 |
+ const TVariable &newParam); |
| 3198 |
+ |
| 3199 |
+// Clones a function and appends the provided extra parameters. |
| 3200 |
+// If `idGen` is null, the original function must be discarded from the AST. |
| 3201 |
+const TFunction &CloneFunctionAndAppendParams(TSymbolTable &symbolTable, |
| 3202 |
+ IdGen *idGen, |
| 3203 |
+ const TFunction &oldFunc, |
| 3204 |
+ const std::vector<const TVariable *> &newParam); |
| 3205 |
+ |
| 3206 |
+// Clones a function and changes its return type. |
| 3207 |
+// If `idGen` is null, the original function must be discarded from the AST. |
| 3208 |
+const TFunction &CloneFunctionAndChangeReturnType(TSymbolTable &symbolTable, |
| 3209 |
+ IdGen *idGen, |
| 3210 |
+ const TFunction &oldFunc, |
| 3211 |
+ const TStructure &newReturn); |
| 3212 |
+ |
| 3213 |
+// Gets the argument of a function call at the given index. |
| 3214 |
+TIntermTyped &GetArg(const TIntermAggregate &call, size_t index); |
| 3215 |
+ |
| 3216 |
+// Sets the argument of a function call at the given index. |
| 3217 |
+void SetArg(TIntermAggregate &call, size_t index, TIntermTyped &arg); |
| 3218 |
+ |
| 3219 |
+// Returns the field index within the given struct for the given field name. |
| 3220 |
+// Returns -1 if the struct has no field with the given name. |
| 3221 |
+int GetFieldIndex(const TStructure &structure, const ImmutableString &fieldName); |
| 3222 |
+ |
| 3223 |
+// Accesses a field for the given variable with the given field name. |
| 3224 |
+// The variable must be a struct instance. |
| 3225 |
+TIntermBinary &AccessField(const TVariable &structInstanceVar, const ImmutableString &fieldName); |
| 3226 |
+ |
| 3227 |
+// Accesses a field for the given node with the given field name. |
| 3228 |
+// The node must be a struct instance. |
| 3229 |
+TIntermBinary &AccessField(TIntermTyped &object, const ImmutableString &fieldName); |
| 3230 |
+ |
| 3231 |
+// Accesses a field for the given node by its field index. |
| 3232 |
+// The node must be a struct instance. |
| 3233 |
+TIntermBinary &AccessFieldByIndex(TIntermTyped &object, int index); |
| 3234 |
+ |
| 3235 |
+// Accesses an element by index for the given node. |
| 3236 |
+// The node must be an array, vector, or matrix. |
| 3237 |
+TIntermBinary &AccessIndex(TIntermTyped &indexableNode, int index); |
| 3238 |
+ |
| 3239 |
+// Accesses an element by index for the given node if `index` is non-null. |
| 3240 |
+// Returns the original node if `index` is null. |
| 3241 |
+// The node must be an array, vector, or matrix if `index` is non-null. |
| 3242 |
+TIntermTyped &AccessIndex(TIntermTyped &node, const int *index); |
| 3243 |
+ |
| 3244 |
+// Returns a subvector based on the input slice range. |
| 3245 |
+// This returns the original node if the slice is an identity for the node. |
| 3246 |
+TIntermTyped &SubVector(TIntermTyped &vectorNode, int begin, int end); |
| 3247 |
+ |
| 3248 |
+// Matches scalar bool, int, uint, float, double. |
| 3249 |
+bool IsScalarBasicType(const TType &type); |
| 3250 |
+ |
| 3251 |
+// Matches vector bool, int, uint, float, double. |
| 3252 |
+bool IsVectorBasicType(const TType &type); |
| 3253 |
+ |
| 3254 |
+// Matches bool, int, uint, float, double. |
| 3255 |
+// Type does not need to be a scalar. |
| 3256 |
+bool HasScalarBasicType(const TType &type); |
| 3257 |
+ |
| 3258 |
+// Matches bool, int, uint, float, double. |
| 3259 |
+bool HasScalarBasicType(TBasicType type); |
| 3260 |
+ |
| 3261 |
+// Clones a type. |
| 3262 |
+TType &CloneType(const TType &type); |
| 3263 |
+ |
| 3264 |
+// Clones a type and drops all array dimensions. |
| 3265 |
+TType &InnermostType(const TType &type); |
| 3266 |
+ |
| 3267 |
+// Creates a vector type by dropping the columns off of a matrix type. |
| 3268 |
+TType &DropColumns(const TType &matrixType); |
| 3269 |
+ |
| 3270 |
+// Creates a type by dropping the outer dimension off of an array type. |
| 3271 |
+TType &DropOuterDimension(const TType &arrayType); |
| 3272 |
+ |
| 3273 |
+// Creates a scalar or vector type by changing the dimensions of a vector type. |
| 3274 |
+TType &SetVectorDim(const TType &type, int newDim); |
| 3275 |
+ |
| 3276 |
+// Creates a matrix type by changing the row dimensions of a matrix type. |
| 3277 |
+TType &SetMatrixRowDim(const TType &matrixType, int newDim); |
| 3278 |
+ |
| 3279 |
+// Returns true iff the structure directly contains a field with matrix type. |
| 3280 |
+bool HasMatrixField(const TStructure &structure); |
| 3281 |
+ |
| 3282 |
+// Returns true iff the structure directly contains a field with array type. |
| 3283 |
+bool HasArrayField(const TStructure &structure); |
| 3284 |
+ |
| 3285 |
+// Coerces `fromNode` to `toType` by a constructor call of `toType` if their types differ. |
| 3286 |
+// Vector and matrix dimensions are retained. |
| 3287 |
+// Array types are not allowed. |
| 3288 |
+TIntermTyped &CoerceSimple(TBasicType toType, TIntermTyped &fromNode); |
| 3289 |
+ |
| 3290 |
+// Coerces `fromNode` to `toType` by a constructor call of `toType` if their types differ. |
| 3291 |
+// Vector and matrix dimensions must coincide between to and from. |
| 3292 |
+// Array types are not allowed. |
| 3293 |
+TIntermTyped &CoerceSimple(const TType &toType, TIntermTyped &fromNode); |
| 3294 |
+ |
| 3295 |
+TIntermTyped &AsType(SymbolEnv &symbolEnv, const TType &toType, TIntermTyped &fromNode); |
| 3296 |
+ |
| 3297 |
+} // namespace sh |
| 3298 |
+ |
| 3299 |
+#endif // COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_ASTHELPERS_H_ |
| 3300 |
diff --git a/src/compiler/translator/TranslatorMetalDirect/ConstantNames.h b/src/compiler/translator/TranslatorMetalDirect/ConstantNames.h |
| 3301 |
new file mode 100644 |
| 3302 |
index 0000000..fddd865 |
| 3303 |
--- /dev/null |
| 3304 |
+++ b/src/compiler/translator/TranslatorMetalDirect/ConstantNames.h |
| 3305 |
@@ -0,0 +1,26 @@ |
| 3306 |
+// |
| 3307 |
+// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 3308 |
+// Use of this source code is governed by a BSD-style license that can be |
| 3309 |
+// found in the LICENSE file. |
| 3310 |
+// |
| 3311 |
+ |
| 3312 |
+#ifndef COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_CONSTANT_NAMES_H_ |
| 3313 |
+#define COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_CONSTANT_NAMES_H_ |
| 3314 |
+ |
| 3315 |
+#include "compiler/translator/TranslatorMetalDirect/Name.h" |
| 3316 |
+ |
| 3317 |
+namespace sh |
| 3318 |
+{ |
| 3319 |
+ |
| 3320 |
+namespace constant_names |
| 3321 |
+{ |
| 3322 |
+ |
| 3323 |
+constexpr Name kCoverageMaskEnabled("ANGLE_CoverageMaskEnabled", SymbolType::AngleInternal); |
| 3324 |
+constexpr Name kRasterizationDiscardEnabled("ANGLE_RasterizationDiscard", |
| 3325 |
+ SymbolType::AngleInternal); |
| 3326 |
+ |
| 3327 |
+} // namespace constant_names |
| 3328 |
+ |
| 3329 |
+} // namespace sh |
| 3330 |
+ |
| 3331 |
+#endif // COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_CONSTANT_NAMES_H_ |
| 3332 |
diff --git a/src/compiler/translator/TranslatorMetalDirect/Debug.h b/src/compiler/translator/TranslatorMetalDirect/Debug.h |
| 3333 |
new file mode 100644 |
| 3334 |
index 0000000..585e9a6 |
| 3335 |
--- /dev/null |
| 3336 |
+++ b/src/compiler/translator/TranslatorMetalDirect/Debug.h |
| 3337 |
@@ -0,0 +1,16 @@ |
| 3338 |
+// |
| 3339 |
+// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 3340 |
+// Use of this source code is governed by a BSD-style license that can be |
| 3341 |
+// found in the LICENSE file. |
| 3342 |
+// |
| 3343 |
+ |
| 3344 |
+#ifndef COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_DEBUG_H_ |
| 3345 |
+#define COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_DEBUG_H_ |
| 3346 |
+ |
| 3347 |
+#include "common/debug.h" |
| 3348 |
+ |
| 3349 |
+#define TODO() ASSERT(false) |
| 3350 |
+ |
| 3351 |
+#define LOGIC_ERROR() ASSERT(false) |
| 3352 |
+ |
| 3353 |
+#endif // COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_DEBUG_H_ |
| 3354 |
diff --git a/src/compiler/translator/TranslatorMetalDirect/DebugSink.h b/src/compiler/translator/TranslatorMetalDirect/DebugSink.h |
| 3355 |
new file mode 100644 |
| 3356 |
index 0000000..872add7 |
| 3357 |
--- /dev/null |
| 3358 |
+++ b/src/compiler/translator/TranslatorMetalDirect/DebugSink.h |
| 3359 |
@@ -0,0 +1,159 @@ |
| 3360 |
+// |
| 3361 |
+// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 3362 |
+// Use of this source code is governed by a BSD-style license that can be |
| 3363 |
+// found in the LICENSE file. |
| 3364 |
+// |
| 3365 |
+ |
| 3366 |
+#include <iostream> |
| 3367 |
+ |
| 3368 |
+#include "compiler/translator/InfoSink.h" |
| 3369 |
+ |
| 3370 |
+namespace sh |
| 3371 |
+{ |
| 3372 |
+ |
| 3373 |
+class StringObserver |
| 3374 |
+{ |
| 3375 |
+ public: |
| 3376 |
+ StringObserver(const std::string &needle) : needle(needle) { ASSERT(!needle.empty()); } |
| 3377 |
+ |
| 3378 |
+ bool observe(char c) |
| 3379 |
+ { |
| 3380 |
+ if (needle[currPos] == c) |
| 3381 |
+ { |
| 3382 |
+ ++currPos; |
| 3383 |
+ if (currPos == needle.size()) |
| 3384 |
+ { |
| 3385 |
+ reset(); |
| 3386 |
+ return true; |
| 3387 |
+ } |
| 3388 |
+ } |
| 3389 |
+ else |
| 3390 |
+ { |
| 3391 |
+ reset(); |
| 3392 |
+ } |
| 3393 |
+ return false; |
| 3394 |
+ } |
| 3395 |
+ |
| 3396 |
+ const std::string &getNeedle() const { return needle; } |
| 3397 |
+ |
| 3398 |
+ void reset() { currPos = 0; } |
| 3399 |
+ |
| 3400 |
+ private: |
| 3401 |
+ std::string needle; |
| 3402 |
+ size_t currPos = 0; |
| 3403 |
+}; |
| 3404 |
+ |
| 3405 |
+class DebugSink : angle::NonCopyable |
| 3406 |
+{ |
| 3407 |
+ public: |
| 3408 |
+ friend class EscapedSink; |
| 3409 |
+ class EscapedSink : angle::NonCopyable |
| 3410 |
+ { |
| 3411 |
+ friend class DebugSink; |
| 3412 |
+ |
| 3413 |
+ private: |
| 3414 |
+ EscapedSink(DebugSink &owner) : mOwner(owner), mBegin(owner.size()) {} |
| 3415 |
+ |
| 3416 |
+ public: |
| 3417 |
+ EscapedSink(EscapedSink &&other) : mOwner(other.mOwner), mBegin(other.mBegin) {} |
| 3418 |
+ |
| 3419 |
+ ~EscapedSink() |
| 3420 |
+ { |
| 3421 |
+ const char *p = mOwner.c_str(); |
| 3422 |
+ const int end = mOwner.size(); |
| 3423 |
+ mOwner.onWrite(p + mBegin, p + end); |
| 3424 |
+ } |
| 3425 |
+ |
| 3426 |
+ TInfoSinkBase &get() { return mOwner.mParent; } |
| 3427 |
+ |
| 3428 |
+ operator TInfoSinkBase &() { return get(); } |
| 3429 |
+ |
| 3430 |
+ private: |
| 3431 |
+ DebugSink &mOwner; |
| 3432 |
+ const int mBegin; |
| 3433 |
+ }; |
| 3434 |
+ |
| 3435 |
+ public: |
| 3436 |
+ DebugSink(TInfoSinkBase &parent, bool alsoLogToStdout) |
| 3437 |
+ : mParent(parent), mAlsoLogToStdout(alsoLogToStdout) |
| 3438 |
+ {} |
| 3439 |
+ |
| 3440 |
+ void watch(std::string const &needle) |
| 3441 |
+ { |
| 3442 |
+ if (!needle.empty()) |
| 3443 |
+ { |
| 3444 |
+ mObservers.emplace_back(needle); |
| 3445 |
+ } |
| 3446 |
+ } |
| 3447 |
+ |
| 3448 |
+ void erase() |
| 3449 |
+ { |
| 3450 |
+ mParent.erase(); |
| 3451 |
+ for (StringObserver &observer : mObservers) |
| 3452 |
+ { |
| 3453 |
+ observer.reset(); |
| 3454 |
+ } |
| 3455 |
+ } |
| 3456 |
+ |
| 3457 |
+ int size() { return mParent.size(); } |
| 3458 |
+ |
| 3459 |
+ const TPersistString &str() const { return mParent.str(); } |
| 3460 |
+ |
| 3461 |
+ const char *c_str() const { return mParent.c_str(); } |
| 3462 |
+ |
| 3463 |
+ EscapedSink escape() { return EscapedSink(*this); } |
| 3464 |
+ |
| 3465 |
+ template <typename T> |
| 3466 |
+ DebugSink &operator<<(const T &value) |
| 3467 |
+ { |
| 3468 |
+ const size_t begin = mParent.size(); |
| 3469 |
+ mParent << value; |
| 3470 |
+ const size_t end = mParent.size(); |
| 3471 |
+ |
| 3472 |
+ const char *p = mParent.c_str(); |
| 3473 |
+ onWrite(p + begin, p + end); |
| 3474 |
+ |
| 3475 |
+ return *this; |
| 3476 |
+ } |
| 3477 |
+ |
| 3478 |
+ private: |
| 3479 |
+ void onWrite(const char *begin, char const *end) |
| 3480 |
+ { |
| 3481 |
+ const char *p = begin; |
| 3482 |
+ while (p != end) |
| 3483 |
+ { |
| 3484 |
+ if (mAlsoLogToStdout) |
| 3485 |
+ { |
| 3486 |
+ std::cout << *p; |
| 3487 |
+ } |
| 3488 |
+ |
| 3489 |
+ for (StringObserver &observer : mObservers) |
| 3490 |
+ { |
| 3491 |
+ if (observer.observe(*p)) |
| 3492 |
+ { |
| 3493 |
+ if (mAlsoLogToStdout) |
| 3494 |
+ { |
| 3495 |
+ std::cout.flush(); |
| 3496 |
+ } |
| 3497 |
+ const std::string &needle = observer.getNeedle(); |
| 3498 |
+ (void)needle; |
| 3499 |
+ ASSERT(true); // place your breakpoint here |
| 3500 |
+ } |
| 3501 |
+ } |
| 3502 |
+ |
| 3503 |
+ ++p; |
| 3504 |
+ } |
| 3505 |
+ |
| 3506 |
+ if (mAlsoLogToStdout) |
| 3507 |
+ { |
| 3508 |
+ std::cout.flush(); |
| 3509 |
+ } |
| 3510 |
+ } |
| 3511 |
+ |
| 3512 |
+ private: |
| 3513 |
+ TInfoSinkBase &mParent; |
| 3514 |
+ std::vector<StringObserver> mObservers; |
| 3515 |
+ bool mAlsoLogToStdout; |
| 3516 |
+}; |
| 3517 |
+ |
| 3518 |
+} // namespace sh |
| 3519 |
diff --git a/src/compiler/translator/TranslatorMetalDirect/DiscoverDependentFunctions.cpp b/src/compiler/translator/TranslatorMetalDirect/DiscoverDependentFunctions.cpp |
| 3520 |
new file mode 100644 |
| 3521 |
index 0000000..42df430 |
| 3522 |
--- /dev/null |
| 3523 |
+++ b/src/compiler/translator/TranslatorMetalDirect/DiscoverDependentFunctions.cpp |
| 3524 |
@@ -0,0 +1,131 @@ |
| 3525 |
+// |
| 3526 |
+// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 3527 |
+// Use of this source code is governed by a BSD-style license that can be |
| 3528 |
+// found in the LICENSE file. |
| 3529 |
+// |
| 3530 |
+ |
| 3531 |
+#include <cstring> |
| 3532 |
+#include <unordered_map> |
| 3533 |
+#include <unordered_set> |
| 3534 |
+ |
| 3535 |
+#include "compiler/translator/TranslatorMetalDirect/DiscoverDependentFunctions.h" |
| 3536 |
+#include "compiler/translator/TranslatorMetalDirect/DiscoverEnclosingFunctionTraverser.h" |
| 3537 |
+#include "compiler/translator/TranslatorMetalDirect/MapFunctionsToDefinitions.h" |
| 3538 |
+ |
| 3539 |
+using namespace sh; |
| 3540 |
+ |
| 3541 |
+//////////////////////////////////////////////////////////////////////////////// |
| 3542 |
+ |
| 3543 |
+namespace |
| 3544 |
+{ |
| 3545 |
+ |
| 3546 |
+class Discoverer : public DiscoverEnclosingFunctionTraverser |
| 3547 |
+{ |
| 3548 |
+ private: |
| 3549 |
+ const std::function<bool(const TVariable &)> &mVars; |
| 3550 |
+ const FunctionToDefinition &mFuncToDef; |
| 3551 |
+ std::unordered_set<const TFunction *> mNonDepFunctions; |
| 3552 |
+ |
| 3553 |
+ public: |
| 3554 |
+ std::unordered_set<const TFunction *> mDepFunctions; |
| 3555 |
+ |
| 3556 |
+ public: |
| 3557 |
+ Discoverer(const std::function<bool(const TVariable &)> &vars, |
| 3558 |
+ const FunctionToDefinition &funcToDef) |
| 3559 |
+ : DiscoverEnclosingFunctionTraverser(true, false, true), mVars(vars), mFuncToDef(funcToDef) |
| 3560 |
+ {} |
| 3561 |
+ |
| 3562 |
+ void visitSymbol(TIntermSymbol *symbolNode) override |
| 3563 |
+ { |
| 3564 |
+ const TVariable &var = symbolNode->variable(); |
| 3565 |
+ if (!mVars(var)) |
| 3566 |
+ { |
| 3567 |
+ return; |
| 3568 |
+ } |
| 3569 |
+ const TFunction *owner = discoverEnclosingFunction(symbolNode); |
| 3570 |
+ ASSERT(owner); |
| 3571 |
+ mDepFunctions.insert(owner); |
| 3572 |
+ } |
| 3573 |
+ |
| 3574 |
+ bool visitAggregate(Visit visit, TIntermAggregate *aggregateNode) override |
| 3575 |
+ { |
| 3576 |
+ if (visit != Visit::PreVisit) |
| 3577 |
+ { |
| 3578 |
+ return true; |
| 3579 |
+ } |
| 3580 |
+ |
| 3581 |
+ if (!aggregateNode->isConstructor()) |
| 3582 |
+ { |
| 3583 |
+ const TFunction *func = aggregateNode->getFunction(); |
| 3584 |
+ |
| 3585 |
+ if (mNonDepFunctions.find(func) != mNonDepFunctions.end()) |
| 3586 |
+ { |
| 3587 |
+ return true; |
| 3588 |
+ } |
| 3589 |
+ |
| 3590 |
+ if (mDepFunctions.find(func) == mDepFunctions.end()) |
| 3591 |
+ { |
| 3592 |
+ auto it = mFuncToDef.find(func); |
| 3593 |
+ if (it == mFuncToDef.end()) |
| 3594 |
+ { |
| 3595 |
+ return true; |
| 3596 |
+ } |
| 3597 |
+ |
| 3598 |
+ // Recursion is banned in GLSL, so I believe AngleIR has this property too. |
| 3599 |
+ // This implementation assumes (direct and mutual) recursion is prohibited. |
| 3600 |
+ TIntermFunctionDefinition &funcDefNode = *it->second; |
| 3601 |
+ funcDefNode.traverse(this); |
| 3602 |
+ if (mNonDepFunctions.find(func) != mNonDepFunctions.end()) |
| 3603 |
+ { |
| 3604 |
+ return true; |
| 3605 |
+ } |
| 3606 |
+ ASSERT(mDepFunctions.find(func) != mDepFunctions.end()); |
| 3607 |
+ } |
| 3608 |
+ |
| 3609 |
+ const TFunction *owner = discoverEnclosingFunction(aggregateNode); |
| 3610 |
+ ASSERT(owner); |
| 3611 |
+ mDepFunctions.insert(owner); |
| 3612 |
+ } |
| 3613 |
+ |
| 3614 |
+ return true; |
| 3615 |
+ } |
| 3616 |
+ |
| 3617 |
+ bool visitFunctionDefinition(Visit visit, TIntermFunctionDefinition *funcDefNode) override |
| 3618 |
+ { |
| 3619 |
+ const TFunction *func = funcDefNode->getFunction(); |
| 3620 |
+ |
| 3621 |
+ if (visit != Visit::PostVisit) |
| 3622 |
+ { |
| 3623 |
+ if (mDepFunctions.find(func) != mDepFunctions.end()) |
| 3624 |
+ { |
| 3625 |
+ return false; |
| 3626 |
+ } |
| 3627 |
+ |
| 3628 |
+ if (mNonDepFunctions.find(func) != mNonDepFunctions.end()) |
| 3629 |
+ { |
| 3630 |
+ return false; |
| 3631 |
+ } |
| 3632 |
+ |
| 3633 |
+ return true; |
| 3634 |
+ } |
| 3635 |
+ |
| 3636 |
+ if (mDepFunctions.find(func) == mDepFunctions.end()) |
| 3637 |
+ { |
| 3638 |
+ mNonDepFunctions.insert(func); |
| 3639 |
+ } |
| 3640 |
+ |
| 3641 |
+ return true; |
| 3642 |
+ } |
| 3643 |
+}; |
| 3644 |
+ |
| 3645 |
+} // namespace |
| 3646 |
+ |
| 3647 |
+std::unordered_set<const TFunction *> sh::DiscoverDependentFunctions( |
| 3648 |
+ TIntermBlock &root, |
| 3649 |
+ const std::function<bool(const TVariable &)> &vars) |
| 3650 |
+{ |
| 3651 |
+ const FunctionToDefinition funcToDef = MapFunctionsToDefinitions(root); |
| 3652 |
+ Discoverer discoverer(vars, funcToDef); |
| 3653 |
+ root.traverse(&discoverer); |
| 3654 |
+ return std::move(discoverer.mDepFunctions); |
| 3655 |
+} |
| 3656 |
diff --git a/src/compiler/translator/TranslatorMetalDirect/DiscoverDependentFunctions.h b/src/compiler/translator/TranslatorMetalDirect/DiscoverDependentFunctions.h |
| 3657 |
new file mode 100644 |
| 3658 |
index 0000000..5d1bf27 |
| 3659 |
--- /dev/null |
| 3660 |
+++ b/src/compiler/translator/TranslatorMetalDirect/DiscoverDependentFunctions.h |
| 3661 |
@@ -0,0 +1,25 @@ |
| 3662 |
+// |
| 3663 |
+// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 3664 |
+// Use of this source code is governed by a BSD-style license that can be |
| 3665 |
+// found in the LICENSE file. |
| 3666 |
+// |
| 3667 |
+ |
| 3668 |
+#ifndef COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_DISCOVERDEPENDENTFUNCTIONS_H_ |
| 3669 |
+#define COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_DISCOVERDEPENDENTFUNCTIONS_H_ |
| 3670 |
+ |
| 3671 |
+#include <unordered_set> |
| 3672 |
+ |
| 3673 |
+#include "common/angleutils.h" |
| 3674 |
+#include "compiler/translator/Compiler.h" |
| 3675 |
+ |
| 3676 |
+namespace sh |
| 3677 |
+{ |
| 3678 |
+ |
| 3679 |
+// Finds and returns all functions that contain the provided variables. |
| 3680 |
+ANGLE_NO_DISCARD std::unordered_set<const TFunction *> DiscoverDependentFunctions( |
| 3681 |
+ TIntermBlock &root, |
| 3682 |
+ const std::function<bool(const TVariable &)> &vars); |
| 3683 |
+ |
| 3684 |
+} // namespace sh |
| 3685 |
+ |
| 3686 |
+#endif // COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_DISCOVERDEPENDENTFUNCTIONS_H_ |
| 3687 |
diff --git a/src/compiler/translator/TranslatorMetalDirect/DiscoverEnclosingFunctionTraverser.cpp b/src/compiler/translator/TranslatorMetalDirect/DiscoverEnclosingFunctionTraverser.cpp |
| 3688 |
new file mode 100644 |
| 3689 |
index 0000000..22d390e |
| 3690 |
--- /dev/null |
| 3691 |
+++ b/src/compiler/translator/TranslatorMetalDirect/DiscoverEnclosingFunctionTraverser.cpp |
| 3692 |
@@ -0,0 +1,33 @@ |
| 3693 |
+// |
| 3694 |
+// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 3695 |
+// Use of this source code is governed by a BSD-style license that can be |
| 3696 |
+// found in the LICENSE file. |
| 3697 |
+// |
| 3698 |
+ |
| 3699 |
+#include "compiler/translator/TranslatorMetalDirect/DiscoverEnclosingFunctionTraverser.h" |
| 3700 |
+ |
| 3701 |
+using namespace sh; |
| 3702 |
+ |
| 3703 |
+DiscoverEnclosingFunctionTraverser::DiscoverEnclosingFunctionTraverser(bool preVisit_, |
| 3704 |
+ bool inVisit_, |
| 3705 |
+ bool postVisit_, |
| 3706 |
+ TSymbolTable *symbolTable) |
| 3707 |
+ : TIntermTraverser(preVisit_, inVisit_, postVisit_, symbolTable) |
| 3708 |
+{} |
| 3709 |
+ |
| 3710 |
+const TFunction *DiscoverEnclosingFunctionTraverser::discoverEnclosingFunction(TIntermNode *node) |
| 3711 |
+{ |
| 3712 |
+ ASSERT(!node->getAsFunctionDefinition()); |
| 3713 |
+ |
| 3714 |
+ unsigned height = 0; |
| 3715 |
+ while (TIntermNode *ancestor = getAncestorNode(height)) |
| 3716 |
+ { |
| 3717 |
+ if (TIntermFunctionDefinition *funcDefNode = ancestor->getAsFunctionDefinition()) |
| 3718 |
+ { |
| 3719 |
+ return funcDefNode->getFunction(); |
| 3720 |
+ } |
| 3721 |
+ ++height; |
| 3722 |
+ } |
| 3723 |
+ |
| 3724 |
+ return nullptr; |
| 3725 |
+} |
| 3726 |
diff --git a/src/compiler/translator/TranslatorMetalDirect/DiscoverEnclosingFunctionTraverser.h b/src/compiler/translator/TranslatorMetalDirect/DiscoverEnclosingFunctionTraverser.h |
| 3727 |
new file mode 100644 |
| 3728 |
index 0000000..f9cb2aa |
| 3729 |
--- /dev/null |
| 3730 |
+++ b/src/compiler/translator/TranslatorMetalDirect/DiscoverEnclosingFunctionTraverser.h |
| 3731 |
@@ -0,0 +1,31 @@ |
| 3732 |
+// |
| 3733 |
+// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 3734 |
+// Use of this source code is governed by a BSD-style license that can be |
| 3735 |
+// found in the LICENSE file. |
| 3736 |
+// |
| 3737 |
+ |
| 3738 |
+#ifndef COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_DISCOVERENCLOSINGFUNCTIONTRAVERSER_H_ |
| 3739 |
+#define COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_DISCOVERENCLOSINGFUNCTIONTRAVERSER_H_ |
| 3740 |
+ |
| 3741 |
+#include "compiler/translator/tree_util/IntermTraverse.h" |
| 3742 |
+ |
| 3743 |
+namespace sh |
| 3744 |
+{ |
| 3745 |
+ |
| 3746 |
+// A TIntermTraverser that supports discovery of the function a node belongs to. |
| 3747 |
+class DiscoverEnclosingFunctionTraverser : public TIntermTraverser |
| 3748 |
+{ |
| 3749 |
+ public: |
| 3750 |
+ DiscoverEnclosingFunctionTraverser(bool preVisit, |
| 3751 |
+ bool inVisit, |
| 3752 |
+ bool postVisit, |
| 3753 |
+ TSymbolTable *symbolTable = nullptr); |
| 3754 |
+ |
| 3755 |
+ // Returns the function a node belongs inside. |
| 3756 |
+ // Returns null if the node does not belong inside a function. |
| 3757 |
+ const TFunction *discoverEnclosingFunction(TIntermNode *node); |
| 3758 |
+}; |
| 3759 |
+ |
| 3760 |
+} // namespace sh |
| 3761 |
+ |
| 3762 |
+#endif // COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_DISCOVERENCLOSINGFUNCTIONTRAVERSER_H_ |
| 3763 |
diff --git a/src/compiler/translator/TranslatorMetalDirect/EmitMetal.cpp b/src/compiler/translator/TranslatorMetalDirect/EmitMetal.cpp |
| 3764 |
new file mode 100644 |
| 3765 |
index 0000000..1bbdd3f |
| 3766 |
--- /dev/null |
| 3767 |
+++ b/src/compiler/translator/TranslatorMetalDirect/EmitMetal.cpp |
| 3768 |
@@ -0,0 +1,2455 @@ |
| 3769 |
+// |
| 3770 |
+// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 3771 |
+// Use of this source code is governed by a BSD-style license that can be |
| 3772 |
+// found in the LICENSE file. |
| 3773 |
+// |
| 3774 |
+ |
| 3775 |
+#include <cctype> |
| 3776 |
+#include <map> |
| 3777 |
+ |
| 3778 |
+#include "compiler/translator/ImmutableStringBuilder.h" |
| 3779 |
+#include "compiler/translator/SymbolTable.h" |
| 3780 |
+#include "compiler/translator/TranslatorMetalDirect.h" |
| 3781 |
+#include "compiler/translator/TranslatorMetalDirect/AstHelpers.h" |
| 3782 |
+#include "compiler/translator/TranslatorMetalDirect/Debug.h" |
| 3783 |
+#include "compiler/translator/TranslatorMetalDirect/DebugSink.h" |
| 3784 |
+#include "compiler/translator/TranslatorMetalDirect/EmitMetal.h" |
| 3785 |
+#include "compiler/translator/TranslatorMetalDirect/EnvironmentVariable.h" |
| 3786 |
+#include "compiler/translator/TranslatorMetalDirect/Layout.h" |
| 3787 |
+#include "compiler/translator/TranslatorMetalDirect/Name.h" |
| 3788 |
+#include "compiler/translator/TranslatorMetalDirect/ProgramPrelude.h" |
| 3789 |
+#include "compiler/translator/TranslatorMetalDirect/RewritePipelines.h" |
| 3790 |
+#include "compiler/translator/tree_util/IntermTraverse.h" |
| 3791 |
+#include "libANGLE/renderer/metal/mtl_constants.h" |
| 3792 |
+ |
| 3793 |
+using namespace sh; |
| 3794 |
+ |
| 3795 |
+//////////////////////////////////////////////////////////////////////////////// |
| 3796 |
+ |
| 3797 |
+#if defined(ANGLE_ENABLE_ASSERTS) |
| 3798 |
+using Sink = DebugSink; |
| 3799 |
+#else |
| 3800 |
+using Sink = TInfoSinkBase; |
| 3801 |
+#endif |
| 3802 |
+ |
| 3803 |
+//////////////////////////////////////////////////////////////////////////////// |
| 3804 |
+ |
| 3805 |
+namespace |
| 3806 |
+{ |
| 3807 |
+ |
| 3808 |
+struct VarDecl |
| 3809 |
+{ |
| 3810 |
+ explicit VarDecl(const TVariable &var) : mVariable(&var), mIsField(false) {} |
| 3811 |
+ explicit VarDecl(const TField &field) : mField(&field), mIsField(true) {} |
| 3812 |
+ |
| 3813 |
+ ANGLE_INLINE const TVariable &variable() const |
| 3814 |
+ { |
| 3815 |
+ ASSERT(isVariable()); |
| 3816 |
+ return *mVariable; |
| 3817 |
+ } |
| 3818 |
+ |
| 3819 |
+ ANGLE_INLINE const TField &field() const |
| 3820 |
+ { |
| 3821 |
+ ASSERT(isField()); |
| 3822 |
+ return *mField; |
| 3823 |
+ } |
| 3824 |
+ |
| 3825 |
+ ANGLE_INLINE bool isVariable() const { return !mIsField; } |
| 3826 |
+ |
| 3827 |
+ ANGLE_INLINE bool isField() const { return mIsField; } |
| 3828 |
+ |
| 3829 |
+ const TType &type() const { return isField() ? *field().type() : variable().getType(); } |
| 3830 |
+ |
| 3831 |
+ SymbolType symbolType() const |
| 3832 |
+ { |
| 3833 |
+ return isField() ? field().symbolType() : variable().symbolType(); |
| 3834 |
+ } |
| 3835 |
+ |
| 3836 |
+ private: |
| 3837 |
+ union |
| 3838 |
+ { |
| 3839 |
+ const TVariable *mVariable; |
| 3840 |
+ const TField *mField; |
| 3841 |
+ }; |
| 3842 |
+ bool mIsField; |
| 3843 |
+}; |
| 3844 |
+ |
| 3845 |
+class GenMetalTraverser : public TIntermTraverser |
| 3846 |
+{ |
| 3847 |
+ public: |
| 3848 |
+ ~GenMetalTraverser() override; |
| 3849 |
+ |
| 3850 |
+ GenMetalTraverser(const TCompiler &compiler, |
| 3851 |
+ Sink &out, |
| 3852 |
+ IdGen &idGen, |
| 3853 |
+ const PipelineStructs &pipelineStructs, |
| 3854 |
+ const Invariants &invariants, |
| 3855 |
+ SymbolEnv &symbolEnv); |
| 3856 |
+ |
| 3857 |
+ void visitSymbol(TIntermSymbol *) override; |
| 3858 |
+ void visitConstantUnion(TIntermConstantUnion *) override; |
| 3859 |
+ bool visitSwizzle(Visit, TIntermSwizzle *) override; |
| 3860 |
+ bool visitBinary(Visit, TIntermBinary *) override; |
| 3861 |
+ bool visitUnary(Visit, TIntermUnary *) override; |
| 3862 |
+ bool visitTernary(Visit, TIntermTernary *) override; |
| 3863 |
+ bool visitIfElse(Visit, TIntermIfElse *) override; |
| 3864 |
+ bool visitSwitch(Visit, TIntermSwitch *) override; |
| 3865 |
+ bool visitCase(Visit, TIntermCase *) override; |
| 3866 |
+ void visitFunctionPrototype(TIntermFunctionPrototype *) override; |
| 3867 |
+ bool visitFunctionDefinition(Visit, TIntermFunctionDefinition *) override; |
| 3868 |
+ bool visitAggregate(Visit, TIntermAggregate *) override; |
| 3869 |
+ bool visitBlock(Visit, TIntermBlock *) override; |
| 3870 |
+ bool visitGlobalQualifierDeclaration(Visit, TIntermGlobalQualifierDeclaration *) override; |
| 3871 |
+ bool visitDeclaration(Visit, TIntermDeclaration *) override; |
| 3872 |
+ bool visitLoop(Visit, TIntermLoop *) override; |
| 3873 |
+ bool visitForLoop(TIntermLoop *); |
| 3874 |
+ bool visitWhileLoop(TIntermLoop *); |
| 3875 |
+ bool visitDoWhileLoop(TIntermLoop *); |
| 3876 |
+ bool visitBranch(Visit, TIntermBranch *) override; |
| 3877 |
+ |
| 3878 |
+ private: |
| 3879 |
+ using FuncToName = std::map<ImmutableString, Name>; |
| 3880 |
+ static FuncToName BuildFuncToName(); |
| 3881 |
+ |
| 3882 |
+ struct EmitVariableDeclarationConfig |
| 3883 |
+ { |
| 3884 |
+ bool isParameter = false; |
| 3885 |
+ bool isMainParameter = false; |
| 3886 |
+ bool emitPostQualifier = false; |
| 3887 |
+ bool isPacked = false; |
| 3888 |
+ bool disableStructSpecifier = false; |
| 3889 |
+ const AddressSpace *isPointer = nullptr; |
| 3890 |
+ const AddressSpace *isReference = nullptr; |
| 3891 |
+ }; |
| 3892 |
+ |
| 3893 |
+ struct EmitTypeConfig |
| 3894 |
+ { |
| 3895 |
+ const EmitVariableDeclarationConfig *evdConfig = nullptr; |
| 3896 |
+ }; |
| 3897 |
+ |
| 3898 |
+ void emitIndentation(); |
| 3899 |
+ void emitFunctionSignature(const TFunction &func); |
| 3900 |
+ void emitFunctionReturn(const TFunction &func); |
| 3901 |
+ void emitFunctionParameter(const TFunction &func, const TVariable ¶m); |
| 3902 |
+ |
| 3903 |
+ void emitNameOf(const TField &object); |
| 3904 |
+ void emitNameOf(const TSymbol &object); |
| 3905 |
+ void emitNameOf(const VarDecl &object); |
| 3906 |
+ |
| 3907 |
+ void emitBareTypeName(const TType &type, const EmitTypeConfig &etConfig); |
| 3908 |
+ void emitType(const TType &type, const EmitTypeConfig &etConfig); |
| 3909 |
+ void emitPostQualifier(const EmitVariableDeclarationConfig &evdConfig, |
| 3910 |
+ const VarDecl &decl, |
| 3911 |
+ const TQualifier qualifier); |
| 3912 |
+ |
| 3913 |
+ struct FieldAnnotationIndices |
| 3914 |
+ { |
| 3915 |
+ size_t attribute = 0; |
| 3916 |
+ size_t color = 0; |
| 3917 |
+ }; |
| 3918 |
+ |
| 3919 |
+ void emitFieldDeclaration(const TField &field, |
| 3920 |
+ const TStructure &parent, |
| 3921 |
+ FieldAnnotationIndices &annotationIndices); |
| 3922 |
+ void emitAttributeDeclaration(const TField &field, FieldAnnotationIndices &annotationIndices); |
| 3923 |
+ void emitStructDeclaration(const TType &type); |
| 3924 |
+ void emitOrdinaryVariableDeclaration(const VarDecl &decl, |
| 3925 |
+ const EmitVariableDeclarationConfig &evdConfig); |
| 3926 |
+ void emitVariableDeclaration(const VarDecl &decl, |
| 3927 |
+ const EmitVariableDeclarationConfig &evdConfig); |
| 3928 |
+ |
| 3929 |
+ void emitOpenBrace(); |
| 3930 |
+ void emitCloseBrace(); |
| 3931 |
+ |
| 3932 |
+ void groupedTraverse(TIntermNode &node); |
| 3933 |
+ |
| 3934 |
+ const TField &getDirectField(const TFieldListCollection &fieldsNode, |
| 3935 |
+ const TConstantUnion &index); |
| 3936 |
+ const TField &getDirectField(const TIntermTyped &fieldsNode, TIntermTyped &indexNode); |
| 3937 |
+ |
| 3938 |
+ const TConstantUnion *emitConstantUnionArray(const TConstantUnion *const constUnion, |
| 3939 |
+ const size_t size); |
| 3940 |
+ |
| 3941 |
+ const TConstantUnion *emitConstantUnion(const TType &type, const TConstantUnion *constUnion); |
| 3942 |
+ |
| 3943 |
+ void emitSingleConstant(const TConstantUnion *const constUnion); |
| 3944 |
+ |
| 3945 |
+ private: |
| 3946 |
+ Sink &mOut; |
| 3947 |
+ const TCompiler &mCompiler; |
| 3948 |
+ const PipelineStructs &mPipelineStructs; |
| 3949 |
+ const Invariants &mInvariants; |
| 3950 |
+ SymbolEnv &mSymbolEnv; |
| 3951 |
+ IdGen &mIdGen; |
| 3952 |
+ int mIndentLevel = -1; |
| 3953 |
+ int mLastIndentationPos = -1; |
| 3954 |
+ bool mParentIsSwitch = false; |
| 3955 |
+ std::unordered_map<const TSymbol *, Name> mRenamedSymbols; |
| 3956 |
+ const FuncToName mFuncToName = BuildFuncToName(); |
| 3957 |
+ size_t mMainTextureIndex = 0; |
| 3958 |
+ size_t mMainSamplerIndex = 0; |
| 3959 |
+ size_t mMainUniformBufferIndex = rx::mtl::kDefaultUniformsBindingIndex; |
| 3960 |
+}; |
| 3961 |
+ |
| 3962 |
+} // anonymous namespace |
| 3963 |
+ |
| 3964 |
+GenMetalTraverser::~GenMetalTraverser() |
| 3965 |
+{ |
| 3966 |
+ ASSERT(mIndentLevel == -1); |
| 3967 |
+ ASSERT(!mParentIsSwitch); |
| 3968 |
+} |
| 3969 |
+ |
| 3970 |
+GenMetalTraverser::GenMetalTraverser(const TCompiler &compiler, |
| 3971 |
+ Sink &out, |
| 3972 |
+ IdGen &idGen, |
| 3973 |
+ const PipelineStructs &pipelineStructs, |
| 3974 |
+ const Invariants &invariants, |
| 3975 |
+ SymbolEnv &symbolEnv) |
| 3976 |
+ : TIntermTraverser(true, false, false), |
| 3977 |
+ mOut(out), |
| 3978 |
+ mCompiler(compiler), |
| 3979 |
+ mPipelineStructs(pipelineStructs), |
| 3980 |
+ mInvariants(invariants), |
| 3981 |
+ mSymbolEnv(symbolEnv), |
| 3982 |
+ mIdGen(idGen) |
| 3983 |
+{} |
| 3984 |
+ |
| 3985 |
+void GenMetalTraverser::emitIndentation() |
| 3986 |
+{ |
| 3987 |
+ ASSERT(mIndentLevel >= 0); |
| 3988 |
+ |
| 3989 |
+ if (mLastIndentationPos == mOut.size()) |
| 3990 |
+ { |
| 3991 |
+ return; // Line is already indented. |
| 3992 |
+ } |
| 3993 |
+ |
| 3994 |
+ for (int i = 0; i < mIndentLevel; ++i) |
| 3995 |
+ { |
| 3996 |
+ mOut << " "; |
| 3997 |
+ } |
| 3998 |
+ |
| 3999 |
+ mLastIndentationPos = mOut.size(); |
| 4000 |
+} |
| 4001 |
+ |
| 4002 |
+static const char *GetOperatorString(TOperator op, |
| 4003 |
+ const TType &resultType, |
| 4004 |
+ const TType *argType0, |
| 4005 |
+ const TType *argType1 = nullptr) |
| 4006 |
+{ |
| 4007 |
+ switch (op) |
| 4008 |
+ { |
| 4009 |
+ case TOperator::EOpComma: |
| 4010 |
+ return ","; |
| 4011 |
+ case TOperator::EOpAssign: |
| 4012 |
+ return "="; |
| 4013 |
+ case TOperator::EOpInitialize: |
| 4014 |
+ return "="; |
| 4015 |
+ case TOperator::EOpAddAssign: |
| 4016 |
+ return "+="; |
| 4017 |
+ case TOperator::EOpSubAssign: |
| 4018 |
+ return "-="; |
| 4019 |
+ case TOperator::EOpMulAssign: |
| 4020 |
+ return "*="; |
| 4021 |
+ case TOperator::EOpDivAssign: |
| 4022 |
+ return "/="; |
| 4023 |
+ case TOperator::EOpIModAssign: |
| 4024 |
+ return "%="; |
| 4025 |
+ case TOperator::EOpBitShiftLeftAssign: |
| 4026 |
+ return "<<="; // TODO: Check logical vs arithmetic shifting. |
| 4027 |
+ case TOperator::EOpBitShiftRightAssign: |
| 4028 |
+ return ">>="; // TODO: Check logical vs arithmetic shifting. |
| 4029 |
+ case TOperator::EOpBitwiseAndAssign: |
| 4030 |
+ return "&="; |
| 4031 |
+ case TOperator::EOpBitwiseXorAssign: |
| 4032 |
+ return "^="; |
| 4033 |
+ case TOperator::EOpBitwiseOrAssign: |
| 4034 |
+ return "|="; |
| 4035 |
+ case TOperator::EOpAdd: |
| 4036 |
+ return "+"; |
| 4037 |
+ case TOperator::EOpSub: |
| 4038 |
+ return "-"; |
| 4039 |
+ case TOperator::EOpMul: |
| 4040 |
+ return "*"; |
| 4041 |
+ case TOperator::EOpDiv: |
| 4042 |
+ return "/"; |
| 4043 |
+ case TOperator::EOpIMod: |
| 4044 |
+ return "%"; |
| 4045 |
+ case TOperator::EOpBitShiftLeft: |
| 4046 |
+ return "<<"; // TODO: Check logical vs arithmetic shifting. |
| 4047 |
+ case TOperator::EOpBitShiftRight: |
| 4048 |
+ return ">>"; // TODO: Check logical vs arithmetic shifting. |
| 4049 |
+ case TOperator::EOpBitwiseAnd: |
| 4050 |
+ return "&"; |
| 4051 |
+ case TOperator::EOpBitwiseXor: |
| 4052 |
+ return "^"; |
| 4053 |
+ case TOperator::EOpBitwiseOr: |
| 4054 |
+ return "|"; |
| 4055 |
+ case TOperator::EOpLessThan: |
| 4056 |
+ return "<"; |
| 4057 |
+ case TOperator::EOpGreaterThan: |
| 4058 |
+ return ">"; |
| 4059 |
+ case TOperator::EOpLessThanEqual: |
| 4060 |
+ return "<="; |
| 4061 |
+ case TOperator::EOpGreaterThanEqual: |
| 4062 |
+ return ">="; |
| 4063 |
+ case TOperator::EOpLessThanComponentWise: |
| 4064 |
+ return "<"; |
| 4065 |
+ case TOperator::EOpLessThanEqualComponentWise: |
| 4066 |
+ return "<="; |
| 4067 |
+ case TOperator::EOpGreaterThanEqualComponentWise: |
| 4068 |
+ return ">="; |
| 4069 |
+ case TOperator::EOpGreaterThanComponentWise: |
| 4070 |
+ return ">"; |
| 4071 |
+ case TOperator::EOpLogicalOr: |
| 4072 |
+ return "||"; |
| 4073 |
+ case TOperator::EOpLogicalXor: |
| 4074 |
+ return "!=/*xor*/"; // XXX: This might need to be handled differently for some obtuse |
| 4075 |
+ // use case. |
| 4076 |
+ case TOperator::EOpLogicalAnd: |
| 4077 |
+ return "&&"; |
| 4078 |
+ case TOperator::EOpNegative: |
| 4079 |
+ return "-"; |
| 4080 |
+ case TOperator::EOpPositive: |
| 4081 |
+ if (argType0->isMatrix()) |
| 4082 |
+ { |
| 4083 |
+ return ""; |
| 4084 |
+ } |
| 4085 |
+ return "+"; |
| 4086 |
+ case TOperator::EOpLogicalNot: |
| 4087 |
+ return "!"; |
| 4088 |
+ case TOperator::EOpLogicalNotComponentWise: |
| 4089 |
+ return "!"; |
| 4090 |
+ case TOperator::EOpBitwiseNot: |
| 4091 |
+ return "~"; |
| 4092 |
+ case TOperator::EOpPostIncrement: |
| 4093 |
+ return "++"; |
| 4094 |
+ case TOperator::EOpPostDecrement: |
| 4095 |
+ return "--"; |
| 4096 |
+ case TOperator::EOpPreIncrement: |
| 4097 |
+ return "++"; |
| 4098 |
+ case TOperator::EOpPreDecrement: |
| 4099 |
+ return "--"; |
| 4100 |
+ case TOperator::EOpVectorTimesScalarAssign: |
| 4101 |
+ return "*="; |
| 4102 |
+ case TOperator::EOpVectorTimesMatrixAssign: |
| 4103 |
+ return "*="; |
| 4104 |
+ case TOperator::EOpMatrixTimesScalarAssign: |
| 4105 |
+ return "*="; |
| 4106 |
+ case TOperator::EOpMatrixTimesMatrixAssign: |
| 4107 |
+ return "*="; |
| 4108 |
+ case TOperator::EOpVectorTimesScalar: |
| 4109 |
+ return "*"; |
| 4110 |
+ case TOperator::EOpVectorTimesMatrix: |
| 4111 |
+ return "*"; |
| 4112 |
+ case TOperator::EOpMatrixTimesVector: |
| 4113 |
+ return "*"; |
| 4114 |
+ case TOperator::EOpMatrixTimesScalar: |
| 4115 |
+ return "*"; |
| 4116 |
+ case TOperator::EOpMatrixTimesMatrix: |
| 4117 |
+ return "*"; |
| 4118 |
+ case TOperator::EOpEqualComponentWise: |
| 4119 |
+ return "=="; |
| 4120 |
+ case TOperator::EOpNotEqualComponentWise: |
| 4121 |
+ return "!="; |
| 4122 |
+ |
| 4123 |
+ case TOperator::EOpEqual: |
| 4124 |
+ if ((argType0->isVector() && argType1->isVector()) || |
| 4125 |
+ (argType0->getStruct() && argType1->getStruct()) || |
| 4126 |
+ (argType0->isArray() && argType1->isArray())) |
| 4127 |
+ |
| 4128 |
+ { |
| 4129 |
+ return "ANGLE_equal"; |
| 4130 |
+ } |
| 4131 |
+ |
| 4132 |
+ return "=="; |
| 4133 |
+ |
| 4134 |
+ case TOperator::EOpNotEqual: |
| 4135 |
+ if ((argType0->isVector() && argType1->isVector()) || |
| 4136 |
+ (argType0->isArray() && argType1->isArray())) |
| 4137 |
+ { |
| 4138 |
+ return "ANGLE_notEqual"; |
| 4139 |
+ } |
| 4140 |
+ else if (argType0->getStruct() && argType1->getStruct()) |
| 4141 |
+ { |
| 4142 |
+ return "ANGLE_notEqualStruct"; |
| 4143 |
+ } |
| 4144 |
+ return "!="; |
| 4145 |
+ |
| 4146 |
+ case TOperator::EOpKill: |
| 4147 |
+ TODO(); |
| 4148 |
+ return "kill"; |
| 4149 |
+ case TOperator::EOpReturn: |
| 4150 |
+ return "return"; |
| 4151 |
+ case TOperator::EOpBreak: |
| 4152 |
+ return "break"; |
| 4153 |
+ case TOperator::EOpContinue: |
| 4154 |
+ return "continue"; |
| 4155 |
+ |
| 4156 |
+ case TOperator::EOpRadians: |
| 4157 |
+ return "ANGLE_radians"; |
| 4158 |
+ case TOperator::EOpDegrees: |
| 4159 |
+ return "ANGLE_degrees"; |
| 4160 |
+ case TOperator::EOpAtan: |
| 4161 |
+ return "ANGLE_atan"; |
| 4162 |
+ case TOperator::EOpMod: |
| 4163 |
+ return "ANGLE_mod"; // differs from metal::mod |
| 4164 |
+ case TOperator::EOpRefract: |
| 4165 |
+ return "ANGLE_refract"; |
| 4166 |
+ case TOperator::EOpDistance: |
| 4167 |
+ return "ANGLE_distance"; |
| 4168 |
+ case TOperator::EOpLength: |
| 4169 |
+ return "ANGLE_length"; |
| 4170 |
+ case TOperator::EOpDot: |
| 4171 |
+ return "ANGLE_dot"; |
| 4172 |
+ case TOperator::EOpNormalize: |
| 4173 |
+ return "ANGLE_normalize"; |
| 4174 |
+ case TOperator::EOpFaceforward: |
| 4175 |
+ return "ANGLE_faceforward"; |
| 4176 |
+ case TOperator::EOpReflect: |
| 4177 |
+ return "ANGLE_reflect"; |
| 4178 |
+ case TOperator::EOpMulMatrixComponentWise: |
| 4179 |
+ return "ANGLE_componentWiseMultiply"; |
| 4180 |
+ case TOperator::EOpOuterProduct: |
| 4181 |
+ return "ANGLE_outerProduct"; |
| 4182 |
+ case TOperator::EOpSign: |
| 4183 |
+ return "ANGLE_sign"; |
| 4184 |
+ |
| 4185 |
+ case TOperator::EOpAbs: |
| 4186 |
+ return "metal::abs"; |
| 4187 |
+ case TOperator::EOpAll: |
| 4188 |
+ return "metal::all"; |
| 4189 |
+ case TOperator::EOpAny: |
| 4190 |
+ return "metal::any"; |
| 4191 |
+ case TOperator::EOpSin: |
| 4192 |
+ return "metal::sin"; |
| 4193 |
+ case TOperator::EOpCos: |
| 4194 |
+ return "metal::cos"; |
| 4195 |
+ case TOperator::EOpTan: |
| 4196 |
+ return "metal::tan"; |
| 4197 |
+ case TOperator::EOpAsin: |
| 4198 |
+ return "metal::asin"; |
| 4199 |
+ case TOperator::EOpAcos: |
| 4200 |
+ return "metal::acos"; |
| 4201 |
+ case TOperator::EOpSinh: |
| 4202 |
+ return "metal::sinh"; |
| 4203 |
+ case TOperator::EOpCosh: |
| 4204 |
+ return "metal::cosh"; |
| 4205 |
+ case TOperator::EOpTanh: |
| 4206 |
+ return "metal::tanh"; |
| 4207 |
+ case TOperator::EOpAsinh: |
| 4208 |
+ return "metal::asinh"; |
| 4209 |
+ case TOperator::EOpAcosh: |
| 4210 |
+ return "metal::acosh"; |
| 4211 |
+ case TOperator::EOpAtanh: |
| 4212 |
+ return "metal::atanh"; |
| 4213 |
+ case TOperator::EOpFma: |
| 4214 |
+ return "metal::fma"; |
| 4215 |
+ case TOperator::EOpPow: |
| 4216 |
+ return "metal::pow"; |
| 4217 |
+ case TOperator::EOpExp: |
| 4218 |
+ return "metal::exp"; |
| 4219 |
+ case TOperator::EOpExp2: |
| 4220 |
+ return "metal::exp2"; |
| 4221 |
+ case TOperator::EOpLog: |
| 4222 |
+ return "metal::log"; |
| 4223 |
+ case TOperator::EOpLog2: |
| 4224 |
+ return "metal::log2"; |
| 4225 |
+ case TOperator::EOpSqrt: |
| 4226 |
+ return "metal::sqrt"; |
| 4227 |
+ case TOperator::EOpFloor: |
| 4228 |
+ return "metal::floor"; |
| 4229 |
+ case TOperator::EOpTrunc: |
| 4230 |
+ return "metal::trunc"; |
| 4231 |
+ case TOperator::EOpCeil: |
| 4232 |
+ return "metal::ceil"; |
| 4233 |
+ case TOperator::EOpFract: |
| 4234 |
+ return "metal::fract"; |
| 4235 |
+ case TOperator::EOpMin: |
| 4236 |
+ return "metal::min"; |
| 4237 |
+ case TOperator::EOpMax: |
| 4238 |
+ return "metal::max"; |
| 4239 |
+ case TOperator::EOpRound: |
| 4240 |
+ return "metal::round"; |
| 4241 |
+ case TOperator::EOpRoundEven: |
| 4242 |
+ return "metal::rint"; |
| 4243 |
+ case TOperator::EOpClamp: |
| 4244 |
+ return "metal::clamp"; // TODO fast vs precise namespace |
| 4245 |
+ case TOperator::EOpMix: |
| 4246 |
+ return "metal::mix"; |
| 4247 |
+ case TOperator::EOpStep: |
| 4248 |
+ return "metal::step"; |
| 4249 |
+ case TOperator::EOpSmoothstep: |
| 4250 |
+ return "metal::smoothstep"; |
| 4251 |
+ case TOperator::EOpModf: |
| 4252 |
+ return "metal::modf"; |
| 4253 |
+ case TOperator::EOpIsnan: |
| 4254 |
+ return "metal::isnan"; |
| 4255 |
+ case TOperator::EOpIsinf: |
| 4256 |
+ return "metal::isinf"; |
| 4257 |
+ case TOperator::EOpLdexp: |
| 4258 |
+ return "metal::ldexp"; |
| 4259 |
+ case TOperator::EOpFrexp: |
| 4260 |
+ return "metal::frexp"; |
| 4261 |
+ case TOperator::EOpInversesqrt: |
| 4262 |
+ return "metal::rsqrt"; |
| 4263 |
+ case TOperator::EOpCross: |
| 4264 |
+ return "metal::cross"; |
| 4265 |
+ case TOperator::EOpDFdx: |
| 4266 |
+ return "metal::dfdx"; |
| 4267 |
+ case TOperator::EOpDFdy: |
| 4268 |
+ return "metal::dfdy"; |
| 4269 |
+ case TOperator::EOpFwidth: |
| 4270 |
+ return "metal::fwidth"; |
| 4271 |
+ case TOperator::EOpTranspose: |
| 4272 |
+ return "metal::transpose"; |
| 4273 |
+ case TOperator::EOpDeterminant: |
| 4274 |
+ return "metal::determinant"; |
| 4275 |
+ |
| 4276 |
+ case TOperator::EOpInverse: |
| 4277 |
+ return "ANGLE_inverse"; |
| 4278 |
+ |
| 4279 |
+ case TOperator::EOpFloatBitsToInt: |
| 4280 |
+ case TOperator::EOpFloatBitsToUint: |
| 4281 |
+ case TOperator::EOpIntBitsToFloat: |
| 4282 |
+ case TOperator::EOpUintBitsToFloat: |
| 4283 |
+ { |
| 4284 |
+#define RETURN_AS_TYPE(post) \ |
| 4285 |
+ do \ |
| 4286 |
+ switch (resultType.getBasicType()) \ |
| 4287 |
+ { \ |
| 4288 |
+ case TBasicType::EbtInt: \ |
| 4289 |
+ return "as_type<int" post ">"; \ |
| 4290 |
+ case TBasicType::EbtUInt: \ |
| 4291 |
+ return "as_type<uint" post ">"; \ |
| 4292 |
+ case TBasicType::EbtFloat: \ |
| 4293 |
+ return "as_type<float" post ">"; \ |
| 4294 |
+ default: \ |
| 4295 |
+ TODO(); \ |
| 4296 |
+ return "TOperator_TODO"; \ |
| 4297 |
+ } \ |
| 4298 |
+ while (false) |
| 4299 |
+ |
| 4300 |
+ if (resultType.isScalar()) |
| 4301 |
+ { |
| 4302 |
+ RETURN_AS_TYPE(""); |
| 4303 |
+ } |
| 4304 |
+ else if (resultType.isVector()) |
| 4305 |
+ { |
| 4306 |
+ switch (resultType.getNominalSize()) |
| 4307 |
+ { |
| 4308 |
+ case 2: |
| 4309 |
+ RETURN_AS_TYPE("2"); |
| 4310 |
+ case 3: |
| 4311 |
+ RETURN_AS_TYPE("3"); |
| 4312 |
+ case 4: |
| 4313 |
+ RETURN_AS_TYPE("4"); |
| 4314 |
+ default: |
| 4315 |
+ LOGIC_ERROR(); |
| 4316 |
+ return nullptr; |
| 4317 |
+ } |
| 4318 |
+ } |
| 4319 |
+ else |
| 4320 |
+ { |
| 4321 |
+ TODO(); |
| 4322 |
+ return "TOperator_TODO"; |
| 4323 |
+ } |
| 4324 |
+ |
| 4325 |
+#undef RETURN_AS_TYPE |
| 4326 |
+ } |
| 4327 |
+ |
| 4328 |
+ case TOperator::EOpPackUnorm2x16: |
| 4329 |
+ return "metal::pack_float_to_unorm2x16"; |
| 4330 |
+ case TOperator::EOpPackSnorm2x16: |
| 4331 |
+ return "metal::pack_float_to_snorm2x16"; |
| 4332 |
+ |
| 4333 |
+ case TOperator::EOpPackUnorm4x8: |
| 4334 |
+ return "metal::pack_float_to_unorm4x8"; |
| 4335 |
+ case TOperator::EOpPackSnorm4x8: |
| 4336 |
+ return "metal::pack_float_to_snorm4x8"; |
| 4337 |
+ |
| 4338 |
+ case TOperator::EOpUnpackUnorm2x16: |
| 4339 |
+ return "metal::unpack_unorm2x16_to_float"; |
| 4340 |
+ case TOperator::EOpUnpackSnorm2x16: |
| 4341 |
+ return "metal::unpack_snorm2x16_to_float"; |
| 4342 |
+ |
| 4343 |
+ case TOperator::EOpUnpackUnorm4x8: |
| 4344 |
+ return "metal::unpack_unorm4x8_to_float"; |
| 4345 |
+ case TOperator::EOpUnpackSnorm4x8: |
| 4346 |
+ return "metal::unpack_snorm4x8_to_float"; |
| 4347 |
+ |
| 4348 |
+ case TOperator::EOpPackHalf2x16: |
| 4349 |
+ return "ANGLE_pack_half_2x16"; |
| 4350 |
+ case TOperator::EOpUnpackHalf2x16: |
| 4351 |
+ return "ANGLE_unpack_half_2x16"; |
| 4352 |
+ |
| 4353 |
+ case TOperator::EOpBitfieldExtract: |
| 4354 |
+ case TOperator::EOpBitfieldInsert: |
| 4355 |
+ case TOperator::EOpBitfieldReverse: |
| 4356 |
+ case TOperator::EOpBitCount: |
| 4357 |
+ case TOperator::EOpFindLSB: |
| 4358 |
+ case TOperator::EOpFindMSB: |
| 4359 |
+ case TOperator::EOpUaddCarry: |
| 4360 |
+ case TOperator::EOpUsubBorrow: |
| 4361 |
+ case TOperator::EOpUmulExtended: |
| 4362 |
+ case TOperator::EOpImulExtended: |
| 4363 |
+ case TOperator::EOpBarrier: |
| 4364 |
+ case TOperator::EOpMemoryBarrier: |
| 4365 |
+ case TOperator::EOpMemoryBarrierAtomicCounter: |
| 4366 |
+ case TOperator::EOpMemoryBarrierBuffer: |
| 4367 |
+ case TOperator::EOpMemoryBarrierImage: |
| 4368 |
+ case TOperator::EOpMemoryBarrierShared: |
| 4369 |
+ case TOperator::EOpGroupMemoryBarrier: |
| 4370 |
+ case TOperator::EOpAtomicAdd: |
| 4371 |
+ case TOperator::EOpAtomicMin: |
| 4372 |
+ case TOperator::EOpAtomicMax: |
| 4373 |
+ case TOperator::EOpAtomicAnd: |
| 4374 |
+ case TOperator::EOpAtomicOr: |
| 4375 |
+ case TOperator::EOpAtomicXor: |
| 4376 |
+ case TOperator::EOpAtomicExchange: |
| 4377 |
+ case TOperator::EOpAtomicCompSwap: |
| 4378 |
+ case TOperator::EOpEmitVertex: |
| 4379 |
+ case TOperator::EOpEndPrimitive: |
| 4380 |
+ case TOperator::EOpFTransform: |
| 4381 |
+ case TOperator::EOpPackDouble2x32: |
| 4382 |
+ case TOperator::EOpUnpackDouble2x32: |
| 4383 |
+ case TOperator::EOpArrayLength: |
| 4384 |
+ TODO(); |
| 4385 |
+ return "TOperator_TODO"; |
| 4386 |
+ |
| 4387 |
+ case TOperator::EOpNull: |
| 4388 |
+ case TOperator::EOpConstruct: |
| 4389 |
+ case TOperator::EOpCallFunctionInAST: |
| 4390 |
+ case TOperator::EOpCallInternalRawFunction: |
| 4391 |
+ case TOperator::EOpCallBuiltInFunction: |
| 4392 |
+ case TOperator::EOpIndexDirect: |
| 4393 |
+ case TOperator::EOpIndexIndirect: |
| 4394 |
+ case TOperator::EOpIndexDirectStruct: |
| 4395 |
+ case TOperator::EOpIndexDirectInterfaceBlock: |
| 4396 |
+ LOGIC_ERROR(); |
| 4397 |
+ return nullptr; |
| 4398 |
+ } |
| 4399 |
+} |
| 4400 |
+ |
| 4401 |
+#if 0 |
| 4402 |
+static int GetOperatorPrecedence(TOperator op) |
| 4403 |
+{ |
| 4404 |
+ switch (op) |
| 4405 |
+ { |
| 4406 |
+ case TOperator::EOpComma: { |
| 4407 |
+ return 17; |
| 4408 |
+ } break; |
| 4409 |
+ |
| 4410 |
+ case TOperator::EOpAssign: |
| 4411 |
+ case TOperator::EOpInitialize: |
| 4412 |
+ case TOperator::EOpAddAssign: |
| 4413 |
+ case TOperator::EOpSubAssign: |
| 4414 |
+ case TOperator::EOpMulAssign: |
| 4415 |
+ case TOperator::EOpDivAssign: |
| 4416 |
+ case TOperator::EOpIModAssign: |
| 4417 |
+ case TOperator::EOpBitShiftLeftAssign: |
| 4418 |
+ case TOperator::EOpBitShiftRightAssign: |
| 4419 |
+ case TOperator::EOpBitwiseAndAssign: |
| 4420 |
+ case TOperator::EOpBitwiseXorAssign: |
| 4421 |
+ case TOperator::EOpBitwiseOrAssign: { |
| 4422 |
+ return 16; |
| 4423 |
+ } break; |
| 4424 |
+ |
| 4425 |
+ case TOperator::EOpLogicalOr: { |
| 4426 |
+ return 15; |
| 4427 |
+ } break; |
| 4428 |
+ |
| 4429 |
+ case TOperator::EOpLogicalAnd: { |
| 4430 |
+ return 14; |
| 4431 |
+ } break; |
| 4432 |
+ |
| 4433 |
+ case TOperator::EOpBitwiseOr: { |
| 4434 |
+ return 13; |
| 4435 |
+ } break; |
| 4436 |
+ |
| 4437 |
+ case TOperator::EOpBitwiseXor: { |
| 4438 |
+ return 12; |
| 4439 |
+ } break; |
| 4440 |
+ |
| 4441 |
+ case TOperator::EOpBitwiseAnd: { |
| 4442 |
+ return 11; |
| 4443 |
+ } break; |
| 4444 |
+ |
| 4445 |
+ case TOperator::EOpLogicalXor: |
| 4446 |
+ case TOperator::EOpEqual: |
| 4447 |
+ case TOperator::EOpNotEqual: { |
| 4448 |
+ return 10; |
| 4449 |
+ } break; |
| 4450 |
+ |
| 4451 |
+ case TOperator::EOpLessThan: |
| 4452 |
+ case TOperator::EOpGreaterThan: |
| 4453 |
+ case TOperator::EOpLessThanEqual: |
| 4454 |
+ case TOperator::EOpGreaterThanEqual: { |
| 4455 |
+ return 9; |
| 4456 |
+ } break; |
| 4457 |
+ |
| 4458 |
+ case TOperator::EOpBitShiftLeft: |
| 4459 |
+ case TOperator::EOpBitShiftRight: { |
| 4460 |
+ return 7; |
| 4461 |
+ } break; |
| 4462 |
+ |
| 4463 |
+ case TOperator::EOpAdd: |
| 4464 |
+ case TOperator::EOpSub: { |
| 4465 |
+ return 6; |
| 4466 |
+ } break; |
| 4467 |
+ |
| 4468 |
+ case TOperator::EOpMul: |
| 4469 |
+ case TOperator::EOpDiv: |
| 4470 |
+ case TOperator::EOpIMod: { |
| 4471 |
+ return 5; |
| 4472 |
+ } break; |
| 4473 |
+ |
| 4474 |
+ case TOperator::EOpNegative: |
| 4475 |
+ case TOperator::EOpPositive: |
| 4476 |
+ case TOperator::EOpLogicalNot: |
| 4477 |
+ case TOperator::EOpBitwiseNot: |
| 4478 |
+ case TOperator::EOpPreIncrement: |
| 4479 |
+ case TOperator::EOpPreDecrement: { |
| 4480 |
+ return 3; |
| 4481 |
+ } break; |
| 4482 |
+ |
| 4483 |
+ case TOperator::EOpPostIncrement: |
| 4484 |
+ case TOperator::EOpPostDecrement: { |
| 4485 |
+ return 2; |
| 4486 |
+ } break; |
| 4487 |
+ |
| 4488 |
+ default: { |
| 4489 |
+ TODO(); |
| 4490 |
+ return -1; |
| 4491 |
+ } |
| 4492 |
+ } |
| 4493 |
+} |
| 4494 |
+ |
| 4495 |
+namespace |
| 4496 |
+{ |
| 4497 |
+ |
| 4498 |
+enum class Associativity |
| 4499 |
+{ |
| 4500 |
+ None, |
| 4501 |
+ Left, |
| 4502 |
+ Right, |
| 4503 |
+}; |
| 4504 |
+ |
| 4505 |
+} // anonymous namespace |
| 4506 |
+ |
| 4507 |
+static Associativity GetAssociativity(TOperator op) |
| 4508 |
+{ |
| 4509 |
+ switch (op) |
| 4510 |
+ { |
| 4511 |
+ case TOperator::EOpAdd: |
| 4512 |
+ case TOperator::EOpSub: |
| 4513 |
+ case TOperator::EOpMul: |
| 4514 |
+ case TOperator::EOpDiv: |
| 4515 |
+ case TOperator::EOpIMod: |
| 4516 |
+ case TOperator::EOpBitShiftLeft: |
| 4517 |
+ case TOperator::EOpBitShiftRight: |
| 4518 |
+ case TOperator::EOpBitwiseAnd: |
| 4519 |
+ case TOperator::EOpBitwiseXor: |
| 4520 |
+ case TOperator::EOpBitwiseOr: |
| 4521 |
+ case TOperator::EOpEqual: |
| 4522 |
+ case TOperator::EOpNotEqual: |
| 4523 |
+ case TOperator::EOpLessThan: |
| 4524 |
+ case TOperator::EOpGreaterThan: |
| 4525 |
+ case TOperator::EOpLessThanEqual: |
| 4526 |
+ case TOperator::EOpGreaterThanEqual: |
| 4527 |
+ case TOperator::EOpLogicalOr: |
| 4528 |
+ case TOperator::EOpLogicalXor: |
| 4529 |
+ case TOperator::EOpLogicalAnd: |
| 4530 |
+ case TOperator::EOpComma: { |
| 4531 |
+ return Associativity::Left; |
| 4532 |
+ } break; |
| 4533 |
+ |
| 4534 |
+ case TOperator::EOpAssign: |
| 4535 |
+ case TOperator::EOpInitialize: |
| 4536 |
+ case TOperator::EOpAddAssign: |
| 4537 |
+ case TOperator::EOpSubAssign: |
| 4538 |
+ case TOperator::EOpMulAssign: |
| 4539 |
+ case TOperator::EOpDivAssign: |
| 4540 |
+ case TOperator::EOpIModAssign: |
| 4541 |
+ case TOperator::EOpBitShiftLeftAssign: |
| 4542 |
+ case TOperator::EOpBitShiftRightAssign: |
| 4543 |
+ case TOperator::EOpBitwiseAndAssign: |
| 4544 |
+ case TOperator::EOpBitwiseXorAssign: |
| 4545 |
+ case TOperator::EOpBitwiseOrAssign: { |
| 4546 |
+ return Associativity::Right; |
| 4547 |
+ } break; |
| 4548 |
+ |
| 4549 |
+ case TOperator::EOpNegative: |
| 4550 |
+ case TOperator::EOpPositive: |
| 4551 |
+ case TOperator::EOpLogicalNot: |
| 4552 |
+ case TOperator::EOpBitwiseNot: |
| 4553 |
+ case TOperator::EOpPostIncrement: |
| 4554 |
+ case TOperator::EOpPostDecrement: |
| 4555 |
+ case TOperator::EOpPreIncrement: |
| 4556 |
+ case TOperator::EOpPreDecrement: { |
| 4557 |
+ return Associativity::None; |
| 4558 |
+ } break; |
| 4559 |
+ |
| 4560 |
+ default: { |
| 4561 |
+ TODO(); |
| 4562 |
+ return Associativity::None; |
| 4563 |
+ } |
| 4564 |
+ } |
| 4565 |
+} |
| 4566 |
+#endif |
| 4567 |
+ |
| 4568 |
+static bool IsSymbolicOperator(TOperator op, |
| 4569 |
+ const TType &resultType, |
| 4570 |
+ const TType *argType0, |
| 4571 |
+ const TType *argType1 = nullptr) |
| 4572 |
+{ |
| 4573 |
+ if (op == TOperator::EOpCallBuiltInFunction) |
| 4574 |
+ { |
| 4575 |
+ return false; |
| 4576 |
+ } |
| 4577 |
+ return !std::isalnum(GetOperatorString(op, resultType, argType0, argType1)[0]); |
| 4578 |
+} |
| 4579 |
+ |
| 4580 |
+static TIntermBinary *AsSpecificBinaryNode(TIntermNode &node, TOperator op) |
| 4581 |
+{ |
| 4582 |
+ TIntermBinary *binaryNode = node.getAsBinaryNode(); |
| 4583 |
+ if (binaryNode) |
| 4584 |
+ { |
| 4585 |
+ return binaryNode->getOp() == op ? binaryNode : nullptr; |
| 4586 |
+ } |
| 4587 |
+ return nullptr; |
| 4588 |
+} |
| 4589 |
+ |
| 4590 |
+static bool Parenthesize(TIntermNode &node) |
| 4591 |
+{ |
| 4592 |
+ if (node.getAsSymbolNode()) |
| 4593 |
+ { |
| 4594 |
+ return false; |
| 4595 |
+ } |
| 4596 |
+ if (node.getAsConstantUnion()) |
| 4597 |
+ { |
| 4598 |
+ return false; |
| 4599 |
+ } |
| 4600 |
+ if (node.getAsAggregate()) |
| 4601 |
+ { |
| 4602 |
+ return false; |
| 4603 |
+ } |
| 4604 |
+ if (node.getAsSwizzleNode()) |
| 4605 |
+ { |
| 4606 |
+ return false; |
| 4607 |
+ } |
| 4608 |
+ |
| 4609 |
+ if (TIntermUnary *unaryNode = node.getAsUnaryNode()) |
| 4610 |
+ { |
| 4611 |
+ // TODO: Use a precedence and associativity rules instead of this ad-hoc impl. |
| 4612 |
+ const TType &resultType = unaryNode->getType(); |
| 4613 |
+ const TType &argType = unaryNode->getOperand()->getType(); |
| 4614 |
+ return IsSymbolicOperator(unaryNode->getOp(), resultType, &argType); |
| 4615 |
+ } |
| 4616 |
+ |
| 4617 |
+ if (TIntermBinary *binaryNode = node.getAsBinaryNode()) |
| 4618 |
+ { |
| 4619 |
+ // TODO: Use a precedence and associativity rules instead of this ad-hoc impl. |
| 4620 |
+ const TOperator op = binaryNode->getOp(); |
| 4621 |
+ switch (op) |
| 4622 |
+ { |
| 4623 |
+ case TOperator::EOpIndexDirectStruct: |
| 4624 |
+ case TOperator::EOpIndexDirectInterfaceBlock: |
| 4625 |
+ case TOperator::EOpIndexDirect: |
| 4626 |
+ case TOperator::EOpIndexIndirect: |
| 4627 |
+ return Parenthesize(*binaryNode->getLeft()); |
| 4628 |
+ |
| 4629 |
+ case TOperator::EOpAssign: |
| 4630 |
+ case TOperator::EOpInitialize: |
| 4631 |
+ return AsSpecificBinaryNode(*binaryNode->getRight(), TOperator::EOpComma); |
| 4632 |
+ |
| 4633 |
+ default: |
| 4634 |
+ { |
| 4635 |
+ const TType &resultType = binaryNode->getType(); |
| 4636 |
+ const TType &leftType = binaryNode->getLeft()->getType(); |
| 4637 |
+ const TType &rightType = binaryNode->getRight()->getType(); |
| 4638 |
+ return IsSymbolicOperator(binaryNode->getOp(), resultType, &leftType, &rightType); |
| 4639 |
+ } |
| 4640 |
+ } |
| 4641 |
+ } |
| 4642 |
+ |
| 4643 |
+ return true; |
| 4644 |
+} |
| 4645 |
+ |
| 4646 |
+void GenMetalTraverser::groupedTraverse(TIntermNode &node) |
| 4647 |
+{ |
| 4648 |
+ const bool emitParens = Parenthesize(node); |
| 4649 |
+ |
| 4650 |
+ if (emitParens) |
| 4651 |
+ { |
| 4652 |
+ mOut << "("; |
| 4653 |
+ } |
| 4654 |
+ |
| 4655 |
+ node.traverse(this); |
| 4656 |
+ |
| 4657 |
+ if (emitParens) |
| 4658 |
+ { |
| 4659 |
+ mOut << ")"; |
| 4660 |
+ } |
| 4661 |
+} |
| 4662 |
+ |
| 4663 |
+void GenMetalTraverser::emitPostQualifier(const EmitVariableDeclarationConfig &evdConfig, |
| 4664 |
+ const VarDecl &decl, |
| 4665 |
+ const TQualifier qualifier) |
| 4666 |
+{ |
| 4667 |
+ switch (qualifier) |
| 4668 |
+ { |
| 4669 |
+ case TQualifier::EvqPosition: |
| 4670 |
+ case TQualifier::EvqFragCoord: |
| 4671 |
+ mOut << " [[position]]"; |
| 4672 |
+ break; |
| 4673 |
+ |
| 4674 |
+ case TQualifier::EvqPointSize: |
| 4675 |
+ mOut << " [[point_size]]"; |
| 4676 |
+ break; |
| 4677 |
+ |
| 4678 |
+ case TQualifier::EvqVertexID: |
| 4679 |
+ if (evdConfig.isMainParameter) |
| 4680 |
+ { |
| 4681 |
+ mOut << " [[vertex_id]]"; |
| 4682 |
+ } |
| 4683 |
+ break; |
| 4684 |
+ |
| 4685 |
+ case TQualifier::EvqPointCoord: |
| 4686 |
+ if (evdConfig.isMainParameter) |
| 4687 |
+ { |
| 4688 |
+ mOut << " [[point_coord]]"; |
| 4689 |
+ } |
| 4690 |
+ break; |
| 4691 |
+ |
| 4692 |
+ case TQualifier::EvqFrontFacing: |
| 4693 |
+ if (evdConfig.isMainParameter) |
| 4694 |
+ { |
| 4695 |
+ mOut << " [[front_facing]]"; |
| 4696 |
+ } |
| 4697 |
+ break; |
| 4698 |
+ |
| 4699 |
+ default: |
| 4700 |
+ break; |
| 4701 |
+ } |
| 4702 |
+ |
| 4703 |
+ const bool isInvariant = |
| 4704 |
+ decl.isField() ? mInvariants.contains(decl.field()) : mInvariants.contains(decl.variable()); |
| 4705 |
+ |
| 4706 |
+ if (isInvariant) |
| 4707 |
+ { |
| 4708 |
+ mOut << " [[invariant]]"; |
| 4709 |
+ } |
| 4710 |
+} |
| 4711 |
+ |
| 4712 |
+static void EmitName(Sink &out, const Name &name) |
| 4713 |
+{ |
| 4714 |
+#if defined(ANGLE_ENABLE_ASSERTS) |
| 4715 |
+ DebugSink::EscapedSink escapedOut(out.escape()); |
| 4716 |
+#else |
| 4717 |
+ TInfoSinkBase &escapedOut = out; |
| 4718 |
+#endif |
| 4719 |
+ name.emit(escapedOut); |
| 4720 |
+} |
| 4721 |
+ |
| 4722 |
+void GenMetalTraverser::emitNameOf(const TField &object) |
| 4723 |
+{ |
| 4724 |
+ EmitName(mOut, Name(object)); |
| 4725 |
+} |
| 4726 |
+ |
| 4727 |
+void GenMetalTraverser::emitNameOf(const TSymbol &object) |
| 4728 |
+{ |
| 4729 |
+ auto it = mRenamedSymbols.find(&object); |
| 4730 |
+ if (it == mRenamedSymbols.end()) |
| 4731 |
+ { |
| 4732 |
+ EmitName(mOut, Name(object)); |
| 4733 |
+ } |
| 4734 |
+ else |
| 4735 |
+ { |
| 4736 |
+ EmitName(mOut, it->second); |
| 4737 |
+ } |
| 4738 |
+} |
| 4739 |
+ |
| 4740 |
+void GenMetalTraverser::emitNameOf(const VarDecl &object) |
| 4741 |
+{ |
| 4742 |
+ if (object.isField()) |
| 4743 |
+ { |
| 4744 |
+ emitNameOf(object.field()); |
| 4745 |
+ } |
| 4746 |
+ else |
| 4747 |
+ { |
| 4748 |
+ emitNameOf(object.variable()); |
| 4749 |
+ } |
| 4750 |
+} |
| 4751 |
+ |
| 4752 |
+void GenMetalTraverser::emitBareTypeName(const TType &type, const EmitTypeConfig &etConfig) |
| 4753 |
+{ |
| 4754 |
+ const TBasicType basicType = type.getBasicType(); |
| 4755 |
+ |
| 4756 |
+ switch (basicType) |
| 4757 |
+ { |
| 4758 |
+ case TBasicType::EbtVoid: |
| 4759 |
+ case TBasicType::EbtBool: |
| 4760 |
+ case TBasicType::EbtFloat: |
| 4761 |
+ case TBasicType::EbtInt: |
| 4762 |
+ case TBasicType::EbtUInt: |
| 4763 |
+ { |
| 4764 |
+ mOut << type.getBasicString(); |
| 4765 |
+ } |
| 4766 |
+ break; |
| 4767 |
+ |
| 4768 |
+ case TBasicType::EbtStruct: |
| 4769 |
+ { |
| 4770 |
+ const TStructure &structure = *type.getStruct(); |
| 4771 |
+ emitNameOf(structure); |
| 4772 |
+ } |
| 4773 |
+ break; |
| 4774 |
+ |
| 4775 |
+ case TBasicType::EbtInterfaceBlock: |
| 4776 |
+ { |
| 4777 |
+ const TInterfaceBlock &interfaceBlock = *type.getInterfaceBlock(); |
| 4778 |
+ emitNameOf(interfaceBlock); |
| 4779 |
+ } |
| 4780 |
+ break; |
| 4781 |
+ |
| 4782 |
+ default: |
| 4783 |
+ { |
| 4784 |
+ if (IsSampler(basicType)) |
| 4785 |
+ { |
| 4786 |
+ if (etConfig.evdConfig && etConfig.evdConfig->isMainParameter) |
| 4787 |
+ { |
| 4788 |
+ EmitName(mOut, GetTextureTypeName(basicType)); |
| 4789 |
+ } |
| 4790 |
+ else |
| 4791 |
+ { |
| 4792 |
+ const TStructure &env = mSymbolEnv.getTextureEnv(basicType); |
| 4793 |
+ emitNameOf(env); |
| 4794 |
+ } |
| 4795 |
+ } |
| 4796 |
+ else |
| 4797 |
+ { |
| 4798 |
+ TODO(); |
| 4799 |
+ } |
| 4800 |
+ } |
| 4801 |
+ } |
| 4802 |
+} |
| 4803 |
+ |
| 4804 |
+void GenMetalTraverser::emitType(const TType &type, const EmitTypeConfig &etConfig) |
| 4805 |
+{ |
| 4806 |
+ if (etConfig.evdConfig) |
| 4807 |
+ { |
| 4808 |
+ const auto &evdConfig = *etConfig.evdConfig; |
| 4809 |
+ if (evdConfig.isPointer) |
| 4810 |
+ { |
| 4811 |
+ mOut << toString(*evdConfig.isPointer); |
| 4812 |
+ mOut << " "; |
| 4813 |
+ } |
| 4814 |
+ else if (evdConfig.isReference) |
| 4815 |
+ { |
| 4816 |
+ mOut << toString(*evdConfig.isReference); |
| 4817 |
+ mOut << " "; |
| 4818 |
+ } |
| 4819 |
+ } |
| 4820 |
+ |
| 4821 |
+ if (type.isArray()) |
| 4822 |
+ { |
| 4823 |
+ mOut << "ANGLE_tensor<"; |
| 4824 |
+ } |
| 4825 |
+ |
| 4826 |
+ if (type.isVector() || type.isMatrix()) |
| 4827 |
+ { |
| 4828 |
+ mOut << "metal::"; |
| 4829 |
+ } |
| 4830 |
+ |
| 4831 |
+ if (etConfig.evdConfig && etConfig.evdConfig->isPacked) |
| 4832 |
+ { |
| 4833 |
+ mOut << "packed_"; |
| 4834 |
+ } |
| 4835 |
+ |
| 4836 |
+ emitBareTypeName(type, etConfig); |
| 4837 |
+ |
| 4838 |
+ if (type.isVector()) |
| 4839 |
+ { |
| 4840 |
+ mOut << type.getNominalSize(); |
| 4841 |
+ } |
| 4842 |
+ else if (type.isMatrix()) |
| 4843 |
+ { |
| 4844 |
+ mOut << type.getCols() << "x" << type.getRows(); |
| 4845 |
+ } |
| 4846 |
+ |
| 4847 |
+ if (type.isArray()) |
| 4848 |
+ { |
| 4849 |
+ for (auto size : type.getArraySizes()) |
| 4850 |
+ { |
| 4851 |
+ mOut << ", " << size; |
| 4852 |
+ } |
| 4853 |
+ mOut << ">"; |
| 4854 |
+ } |
| 4855 |
+ |
| 4856 |
+ if (etConfig.evdConfig) |
| 4857 |
+ { |
| 4858 |
+ const auto &evdConfig = *etConfig.evdConfig; |
| 4859 |
+ if (evdConfig.isPointer) |
| 4860 |
+ { |
| 4861 |
+ mOut << " *"; |
| 4862 |
+ } |
| 4863 |
+ else if (evdConfig.isReference) |
| 4864 |
+ { |
| 4865 |
+ mOut << " &"; |
| 4866 |
+ } |
| 4867 |
+ } |
| 4868 |
+} |
| 4869 |
+ |
| 4870 |
+void GenMetalTraverser::emitFieldDeclaration(const TField &field, |
| 4871 |
+ const TStructure &parent, |
| 4872 |
+ FieldAnnotationIndices &annotationIndices) |
| 4873 |
+{ |
| 4874 |
+ const TType &type = *field.type(); |
| 4875 |
+ const TBasicType basic = type.getBasicType(); |
| 4876 |
+ |
| 4877 |
+ EmitVariableDeclarationConfig evdConfig; |
| 4878 |
+ evdConfig.emitPostQualifier = true; |
| 4879 |
+ evdConfig.disableStructSpecifier = true; |
| 4880 |
+ evdConfig.isPacked = mSymbolEnv.isPacked(field); |
| 4881 |
+ evdConfig.isPointer = mSymbolEnv.isPointer(field); |
| 4882 |
+ evdConfig.isReference = mSymbolEnv.isReference(field); |
| 4883 |
+ emitVariableDeclaration(VarDecl(field), evdConfig); |
| 4884 |
+ |
| 4885 |
+ const TQualifier qual = type.getQualifier(); |
| 4886 |
+ switch (qual) |
| 4887 |
+ { |
| 4888 |
+ case TQualifier::EvqFlatIn: |
| 4889 |
+ if (mPipelineStructs.fragmentIn.external == &parent) |
| 4890 |
+ { |
| 4891 |
+ mOut << " [[flat]]"; |
| 4892 |
+ } |
| 4893 |
+ break; |
| 4894 |
+ |
| 4895 |
+ case TQualifier::EvqFragmentOut: |
| 4896 |
+ case TQualifier::EvqFragData: |
| 4897 |
+ if (mPipelineStructs.fragmentOut.external == &parent) |
| 4898 |
+ { |
| 4899 |
+ if ((type.isVector() && |
| 4900 |
+ (basic == TBasicType::EbtInt || basic == TBasicType::EbtUInt || |
| 4901 |
+ basic == TBasicType::EbtFloat)) || |
| 4902 |
+ type.getQualifier() == EvqFragData) |
| 4903 |
+ { |
| 4904 |
+ // TODO: |
| 4905 |
+ // This is not correct in general and needs a reimplementation. |
| 4906 |
+ // In GLSL 3.0, We can't always assume this is going to be a safe index. |
| 4907 |
+ // See 4.3.8.2 |
| 4908 |
+ // https://www.khronos.org/registry/OpenGL/specs/es/3.0/GLSL_ES_Specification_3.00.pdf |
| 4909 |
+ size_t index = annotationIndices.color++; |
| 4910 |
+ mOut << " [[color(" << index << ")]]"; |
| 4911 |
+ } |
| 4912 |
+ } |
| 4913 |
+ break; |
| 4914 |
+ |
| 4915 |
+ case TQualifier::EvqFragDepth: |
| 4916 |
+ mOut << " [[depth(any)]]"; |
| 4917 |
+ break; |
| 4918 |
+ |
| 4919 |
+ default: |
| 4920 |
+ break; |
| 4921 |
+ } |
| 4922 |
+} |
| 4923 |
+ |
| 4924 |
+static std::map<Name, size_t> BuildExternalAttributeIndexMap( |
| 4925 |
+ const TCompiler &compiler, |
| 4926 |
+ const PipelineScoped<TStructure> &structure) |
| 4927 |
+{ |
| 4928 |
+ ASSERT(structure.isTotallyFull()); |
| 4929 |
+ |
| 4930 |
+ const auto &shaderVars = compiler.getAttributes(); |
| 4931 |
+ const size_t shaderVarSize = shaderVars.size(); |
| 4932 |
+ size_t shaderVarIndex = 0; |
| 4933 |
+ |
| 4934 |
+ const auto &externalFields = structure.external->fields(); |
| 4935 |
+ const size_t externalSize = externalFields.size(); |
| 4936 |
+ size_t externalIndex = 0; |
| 4937 |
+ |
| 4938 |
+ const auto &internalFields = structure.internal->fields(); |
| 4939 |
+ const size_t internalSize = internalFields.size(); |
| 4940 |
+ size_t internalIndex = 0; |
| 4941 |
+ |
| 4942 |
+ // Internal fields are never split. External fields are sometimes split. |
| 4943 |
+ ASSERT(externalSize >= internalSize); |
| 4944 |
+ |
| 4945 |
+ // Structures do not contain any inactive fields. |
| 4946 |
+ ASSERT(shaderVarSize >= internalSize); |
| 4947 |
+ |
| 4948 |
+ std::map<Name, size_t> externalNameToAttributeIndex; |
| 4949 |
+ size_t attributeIndex = 0; |
| 4950 |
+ |
| 4951 |
+ while (internalIndex < internalSize) |
| 4952 |
+ { |
| 4953 |
+ const TField &internalField = *internalFields[internalIndex]; |
| 4954 |
+ const Name internalName = Name(internalField); |
| 4955 |
+ const TType &internalType = *internalField.type(); |
| 4956 |
+ while (internalName.rawName() != shaderVars[shaderVarIndex].name) |
| 4957 |
+ { |
| 4958 |
+ // This case represents an inactive field. |
| 4959 |
+ |
| 4960 |
+ ++shaderVarIndex; |
| 4961 |
+ ASSERT(shaderVarIndex < shaderVarSize); |
| 4962 |
+ |
| 4963 |
+ ++attributeIndex; // TODO: Might need to increment more if shader var type is a matrix. |
| 4964 |
+ } |
| 4965 |
+ |
| 4966 |
+ const size_t cols = internalType.isMatrix() ? internalType.getCols() : 1; |
| 4967 |
+ |
| 4968 |
+ for (size_t c = 0; c < cols; ++c) |
| 4969 |
+ { |
| 4970 |
+ const TField &externalField = *externalFields[externalIndex]; |
| 4971 |
+ const Name externalName = Name(externalField); |
| 4972 |
+ ASSERT(!externalField.type()->isMatrix()); |
| 4973 |
+ |
| 4974 |
+ externalNameToAttributeIndex[externalName] = attributeIndex; |
| 4975 |
+ |
| 4976 |
+ ++externalIndex; |
| 4977 |
+ ++attributeIndex; |
| 4978 |
+ } |
| 4979 |
+ |
| 4980 |
+ ++shaderVarIndex; |
| 4981 |
+ ++internalIndex; |
| 4982 |
+ } |
| 4983 |
+ |
| 4984 |
+ ASSERT(shaderVarIndex <= shaderVarSize); |
| 4985 |
+ ASSERT(externalIndex <= externalSize); // less than if padding was introduced |
| 4986 |
+ ASSERT(internalIndex == internalSize); |
| 4987 |
+ |
| 4988 |
+ return externalNameToAttributeIndex; |
| 4989 |
+} |
| 4990 |
+ |
| 4991 |
+void GenMetalTraverser::emitAttributeDeclaration(const TField &field, |
| 4992 |
+ FieldAnnotationIndices &annotationIndices) |
| 4993 |
+{ |
| 4994 |
+ EmitVariableDeclarationConfig evdConfig; |
| 4995 |
+ evdConfig.disableStructSpecifier = true; |
| 4996 |
+ emitVariableDeclaration(VarDecl(field), evdConfig); |
| 4997 |
+ mOut << " [[attribute(" << annotationIndices.attribute++ << ")]]"; |
| 4998 |
+} |
| 4999 |
+ |
| 5000 |
+void GenMetalTraverser::emitStructDeclaration(const TType &type) |
| 5001 |
+{ |
| 5002 |
+ ASSERT(type.getBasicType() == TBasicType::EbtStruct); |
| 5003 |
+ ASSERT(type.isStructSpecifier()); |
| 5004 |
+ |
| 5005 |
+ mOut << "struct "; |
| 5006 |
+ emitBareTypeName(type, {}); |
| 5007 |
+ |
| 5008 |
+ mOut << "\n"; |
| 5009 |
+ emitOpenBrace(); |
| 5010 |
+ |
| 5011 |
+ const TStructure &structure = *type.getStruct(); |
| 5012 |
+ std::map<Name, size_t> fieldToAttributeIndex; |
| 5013 |
+ const bool hasAttributeIndices = mPipelineStructs.vertexIn.external == &structure; |
| 5014 |
+ const bool reclaimUnusedAttributeIndices = mCompiler.getShaderVersion() < 300; |
| 5015 |
+ |
| 5016 |
+ if (hasAttributeIndices) |
| 5017 |
+ { |
| 5018 |
+ fieldToAttributeIndex = |
| 5019 |
+ BuildExternalAttributeIndexMap(mCompiler, mPipelineStructs.vertexIn); |
| 5020 |
+ } |
| 5021 |
+ |
| 5022 |
+ FieldAnnotationIndices annotationIndices; |
| 5023 |
+ |
| 5024 |
+ for (const TField *field : structure.fields()) |
| 5025 |
+ { |
| 5026 |
+ emitIndentation(); |
| 5027 |
+ if (hasAttributeIndices) |
| 5028 |
+ { |
| 5029 |
+ const auto it = fieldToAttributeIndex.find(Name(*field)); |
| 5030 |
+ if (it == fieldToAttributeIndex.end()) |
| 5031 |
+ { |
| 5032 |
+ ASSERT(field->symbolType() == SymbolType::AngleInternal); |
| 5033 |
+ ASSERT(field->name().beginsWith("_")); |
| 5034 |
+ ASSERT(angle::EndsWith(field->name().data(), "_pad")); |
| 5035 |
+ emitFieldDeclaration(*field, structure, annotationIndices); |
| 5036 |
+ } |
| 5037 |
+ else |
| 5038 |
+ { |
| 5039 |
+ ASSERT(field->symbolType() != SymbolType::AngleInternal || |
| 5040 |
+ !field->name().beginsWith("_") || |
| 5041 |
+ !angle::EndsWith(field->name().data(), "_pad")); |
| 5042 |
+ if (!reclaimUnusedAttributeIndices) |
| 5043 |
+ { |
| 5044 |
+ annotationIndices.attribute = it->second; |
| 5045 |
+ } |
| 5046 |
+ emitAttributeDeclaration(*field, annotationIndices); |
| 5047 |
+ } |
| 5048 |
+ } |
| 5049 |
+ else |
| 5050 |
+ { |
| 5051 |
+ emitFieldDeclaration(*field, structure, annotationIndices); |
| 5052 |
+ } |
| 5053 |
+ mOut << ";\n"; |
| 5054 |
+ } |
| 5055 |
+ |
| 5056 |
+ if (!mPipelineStructs.matches(structure, true, true)) |
| 5057 |
+ { |
| 5058 |
+ MetalLayoutOfConfig layoutConfig; |
| 5059 |
+ layoutConfig.treatSamplersAsTextureEnv = true; |
| 5060 |
+ Layout layout = MetalLayoutOf(type, layoutConfig); |
| 5061 |
+ size_t pad = layout.sizeOf % 16; |
| 5062 |
+ if (pad != 0) |
| 5063 |
+ { |
| 5064 |
+ emitIndentation(); |
| 5065 |
+ mOut << "char "; |
| 5066 |
+ EmitName(mOut, mIdGen.createNewName("pad")); |
| 5067 |
+ mOut << "[" << pad << "];\n"; |
| 5068 |
+ } |
| 5069 |
+ } |
| 5070 |
+ |
| 5071 |
+ emitCloseBrace(); |
| 5072 |
+} |
| 5073 |
+ |
| 5074 |
+void GenMetalTraverser::emitOrdinaryVariableDeclaration( |
| 5075 |
+ const VarDecl &decl, |
| 5076 |
+ const EmitVariableDeclarationConfig &evdConfig) |
| 5077 |
+{ |
| 5078 |
+ EmitTypeConfig etConfig; |
| 5079 |
+ etConfig.evdConfig = &evdConfig; |
| 5080 |
+ |
| 5081 |
+ const TType &type = decl.type(); |
| 5082 |
+ emitType(type, etConfig); |
| 5083 |
+ |
| 5084 |
+ if (decl.symbolType() != SymbolType::Empty) |
| 5085 |
+ { |
| 5086 |
+ mOut << " "; |
| 5087 |
+ emitNameOf(decl); |
| 5088 |
+ } |
| 5089 |
+} |
| 5090 |
+ |
| 5091 |
+void GenMetalTraverser::emitVariableDeclaration(const VarDecl &decl, |
| 5092 |
+ const EmitVariableDeclarationConfig &evdConfig) |
| 5093 |
+{ |
| 5094 |
+ const SymbolType symbolType = decl.symbolType(); |
| 5095 |
+ const TType &type = decl.type(); |
| 5096 |
+ const TBasicType basicType = type.getBasicType(); |
| 5097 |
+ |
| 5098 |
+ switch (basicType) |
| 5099 |
+ { |
| 5100 |
+ case TBasicType::EbtStruct: |
| 5101 |
+ { |
| 5102 |
+ if (type.isStructSpecifier() && !evdConfig.disableStructSpecifier) |
| 5103 |
+ { |
| 5104 |
+ ASSERT(!evdConfig.isParameter); |
| 5105 |
+ emitStructDeclaration(type); |
| 5106 |
+ if (symbolType != SymbolType::Empty) |
| 5107 |
+ { |
| 5108 |
+ mOut << " "; |
| 5109 |
+ emitNameOf(decl); |
| 5110 |
+ } |
| 5111 |
+ } |
| 5112 |
+ else |
| 5113 |
+ { |
| 5114 |
+ emitOrdinaryVariableDeclaration(decl, evdConfig); |
| 5115 |
+ } |
| 5116 |
+ } |
| 5117 |
+ break; |
| 5118 |
+ |
| 5119 |
+ default: |
| 5120 |
+ { |
| 5121 |
+ ASSERT(symbolType != SymbolType::Empty || evdConfig.isParameter); |
| 5122 |
+ emitOrdinaryVariableDeclaration(decl, evdConfig); |
| 5123 |
+ } |
| 5124 |
+ } |
| 5125 |
+ |
| 5126 |
+ if (evdConfig.emitPostQualifier) |
| 5127 |
+ { |
| 5128 |
+ emitPostQualifier(evdConfig, decl, type.getQualifier()); |
| 5129 |
+ } |
| 5130 |
+} |
| 5131 |
+ |
| 5132 |
+void GenMetalTraverser::visitSymbol(TIntermSymbol *symbolNode) |
| 5133 |
+{ |
| 5134 |
+ const TVariable &var = symbolNode->variable(); |
| 5135 |
+ const TType &type = var.getType(); |
| 5136 |
+ |
| 5137 |
+ ASSERT(var.symbolType() != SymbolType::Empty); |
| 5138 |
+ |
| 5139 |
+ if (type.getBasicType() == TBasicType::EbtVoid) |
| 5140 |
+ { |
| 5141 |
+ mOut << "/*"; |
| 5142 |
+ emitNameOf(var); |
| 5143 |
+ mOut << "*/"; |
| 5144 |
+ } |
| 5145 |
+ else |
| 5146 |
+ { |
| 5147 |
+ emitNameOf(var); |
| 5148 |
+ } |
| 5149 |
+} |
| 5150 |
+ |
| 5151 |
+void GenMetalTraverser::emitSingleConstant(const TConstantUnion *const constUnion) |
| 5152 |
+{ |
| 5153 |
+ switch (constUnion->getType()) |
| 5154 |
+ { |
| 5155 |
+ case TBasicType::EbtBool: |
| 5156 |
+ { |
| 5157 |
+ mOut << (constUnion->getBConst() ? "true" : "false"); |
| 5158 |
+ } |
| 5159 |
+ break; |
| 5160 |
+ |
| 5161 |
+ case TBasicType::EbtFloat: |
| 5162 |
+ { |
| 5163 |
+ mOut << constUnion->getFConst() << "f"; |
| 5164 |
+ } |
| 5165 |
+ break; |
| 5166 |
+ |
| 5167 |
+ case TBasicType::EbtInt: |
| 5168 |
+ { |
| 5169 |
+ mOut << constUnion->getIConst(); |
| 5170 |
+ } |
| 5171 |
+ break; |
| 5172 |
+ |
| 5173 |
+ case TBasicType::EbtUInt: |
| 5174 |
+ { |
| 5175 |
+ mOut << constUnion->getUConst() << "u"; |
| 5176 |
+ } |
| 5177 |
+ break; |
| 5178 |
+ |
| 5179 |
+ default: |
| 5180 |
+ { |
| 5181 |
+ TODO(); |
| 5182 |
+ } |
| 5183 |
+ } |
| 5184 |
+} |
| 5185 |
+ |
| 5186 |
+const TConstantUnion *GenMetalTraverser::emitConstantUnionArray( |
| 5187 |
+ const TConstantUnion *const constUnion, |
| 5188 |
+ const size_t size) |
| 5189 |
+{ |
| 5190 |
+ const TConstantUnion *constUnionIterated = constUnion; |
| 5191 |
+ for (size_t i = 0; i < size; i++, constUnionIterated++) |
| 5192 |
+ { |
| 5193 |
+ emitSingleConstant(constUnionIterated); |
| 5194 |
+ |
| 5195 |
+ if (i != size - 1) |
| 5196 |
+ { |
| 5197 |
+ mOut << ", "; |
| 5198 |
+ } |
| 5199 |
+ } |
| 5200 |
+ return constUnionIterated; |
| 5201 |
+} |
| 5202 |
+ |
| 5203 |
+const TConstantUnion *GenMetalTraverser::emitConstantUnion(const TType &type, |
| 5204 |
+ const TConstantUnion *constUnionBegin) |
| 5205 |
+{ |
| 5206 |
+ const TConstantUnion *constUnionCurr = constUnionBegin; |
| 5207 |
+ const TStructure *structure = type.getStruct(); |
| 5208 |
+ if (structure) |
| 5209 |
+ { |
| 5210 |
+ EmitTypeConfig config = EmitTypeConfig{nullptr}; |
| 5211 |
+ emitType(type, config); |
| 5212 |
+ mOut << "{"; |
| 5213 |
+ const TFieldList &fields = structure->fields(); |
| 5214 |
+ for (size_t i = 0; i < fields.size(); ++i) |
| 5215 |
+ { |
| 5216 |
+ const TType *fieldType = fields[i]->type(); |
| 5217 |
+ constUnionCurr = emitConstantUnion(*fieldType, constUnionCurr); |
| 5218 |
+ if (i != fields.size() - 1) |
| 5219 |
+ { |
| 5220 |
+ mOut << ", "; |
| 5221 |
+ } |
| 5222 |
+ } |
| 5223 |
+ mOut << "}"; |
| 5224 |
+ } |
| 5225 |
+ else |
| 5226 |
+ { |
| 5227 |
+ size_t size = type.getObjectSize(); |
| 5228 |
+ bool writeType = size > 1; |
| 5229 |
+ if (writeType) |
| 5230 |
+ { |
| 5231 |
+ EmitTypeConfig config = EmitTypeConfig{nullptr}; |
| 5232 |
+ emitType(type, config); |
| 5233 |
+ mOut << "("; |
| 5234 |
+ } |
| 5235 |
+ constUnionCurr = emitConstantUnionArray(constUnionCurr, size); |
| 5236 |
+ if (writeType) |
| 5237 |
+ { |
| 5238 |
+ mOut << ")"; |
| 5239 |
+ } |
| 5240 |
+ } |
| 5241 |
+ return constUnionCurr; |
| 5242 |
+} |
| 5243 |
+ |
| 5244 |
+void GenMetalTraverser::visitConstantUnion(TIntermConstantUnion *constValueNode) |
| 5245 |
+{ |
| 5246 |
+ emitConstantUnion(constValueNode->getType(), constValueNode->getConstantValue()); |
| 5247 |
+} |
| 5248 |
+ |
| 5249 |
+bool GenMetalTraverser::visitSwizzle(Visit, TIntermSwizzle *swizzleNode) |
| 5250 |
+{ |
| 5251 |
+ groupedTraverse(*swizzleNode->getOperand()); |
| 5252 |
+ mOut << "."; |
| 5253 |
+ |
| 5254 |
+ { |
| 5255 |
+#if defined(ANGLE_ENABLE_ASSERTS) |
| 5256 |
+ DebugSink::EscapedSink escapedOut(mOut.escape()); |
| 5257 |
+ TInfoSinkBase &out = escapedOut.get(); |
| 5258 |
+#else |
| 5259 |
+ TInfoSinkBase &out = mOut; |
| 5260 |
+#endif |
| 5261 |
+ swizzleNode->writeOffsetsAsXYZW(&out); |
| 5262 |
+ } |
| 5263 |
+ |
| 5264 |
+ return false; |
| 5265 |
+} |
| 5266 |
+ |
| 5267 |
+const TField &GenMetalTraverser::getDirectField(const TFieldListCollection &fieldListCollection, |
| 5268 |
+ const TConstantUnion &index) |
| 5269 |
+{ |
| 5270 |
+ ASSERT(index.getType() == TBasicType::EbtInt); |
| 5271 |
+ |
| 5272 |
+ const TFieldList &fieldList = fieldListCollection.fields(); |
| 5273 |
+ const int indexVal = index.getIConst(); |
| 5274 |
+ const TField &field = *fieldList[indexVal]; |
| 5275 |
+ |
| 5276 |
+ return field; |
| 5277 |
+} |
| 5278 |
+ |
| 5279 |
+const TField &GenMetalTraverser::getDirectField(const TIntermTyped &fieldsNode, |
| 5280 |
+ TIntermTyped &indexNode) |
| 5281 |
+{ |
| 5282 |
+ const TType &fieldsType = fieldsNode.getType(); |
| 5283 |
+ |
| 5284 |
+ const TFieldListCollection *fieldListCollection = fieldsType.getStruct(); |
| 5285 |
+ if (fieldListCollection == nullptr) |
| 5286 |
+ { |
| 5287 |
+ fieldListCollection = fieldsType.getInterfaceBlock(); |
| 5288 |
+ } |
| 5289 |
+ ASSERT(fieldListCollection); |
| 5290 |
+ |
| 5291 |
+ const TIntermConstantUnion *indexNode_ = indexNode.getAsConstantUnion(); |
| 5292 |
+ ASSERT(indexNode_); |
| 5293 |
+ const TConstantUnion &index = *indexNode_->getConstantValue(); |
| 5294 |
+ |
| 5295 |
+ return getDirectField(*fieldListCollection, index); |
| 5296 |
+} |
| 5297 |
+ |
| 5298 |
+bool GenMetalTraverser::visitBinary(Visit, TIntermBinary *binaryNode) |
| 5299 |
+{ |
| 5300 |
+ const TOperator op = binaryNode->getOp(); |
| 5301 |
+ TIntermTyped &leftNode = *binaryNode->getLeft(); |
| 5302 |
+ TIntermTyped &rightNode = *binaryNode->getRight(); |
| 5303 |
+ |
| 5304 |
+ switch (op) |
| 5305 |
+ { |
| 5306 |
+ case TOperator::EOpIndexDirectStruct: |
| 5307 |
+ case TOperator::EOpIndexDirectInterfaceBlock: |
| 5308 |
+ { |
| 5309 |
+ groupedTraverse(leftNode); |
| 5310 |
+ mOut << "."; |
| 5311 |
+ emitNameOf(getDirectField(leftNode, rightNode)); |
| 5312 |
+ } |
| 5313 |
+ break; |
| 5314 |
+ |
| 5315 |
+ case TOperator::EOpIndexDirect: |
| 5316 |
+ case TOperator::EOpIndexIndirect: |
| 5317 |
+ { |
| 5318 |
+ groupedTraverse(leftNode); |
| 5319 |
+ mOut << "["; |
| 5320 |
+ rightNode.traverse(this); |
| 5321 |
+ mOut << "]"; |
| 5322 |
+ } |
| 5323 |
+ break; |
| 5324 |
+ |
| 5325 |
+ default: |
| 5326 |
+ { |
| 5327 |
+ const TType &resultType = binaryNode->getType(); |
| 5328 |
+ const TType &leftType = leftNode.getType(); |
| 5329 |
+ const TType &rightType = rightNode.getType(); |
| 5330 |
+ |
| 5331 |
+ if (IsSymbolicOperator(op, resultType, &leftType, &rightType)) |
| 5332 |
+ { |
| 5333 |
+ groupedTraverse(leftNode); |
| 5334 |
+ if (op != TOperator::EOpComma) |
| 5335 |
+ { |
| 5336 |
+ mOut << " "; |
| 5337 |
+ } |
| 5338 |
+ mOut << GetOperatorString(op, resultType, &leftType, &rightType) << " "; |
| 5339 |
+ groupedTraverse(rightNode); |
| 5340 |
+ } |
| 5341 |
+ else |
| 5342 |
+ { |
| 5343 |
+ mOut << GetOperatorString(op, resultType, &leftType, &rightType) << "("; |
| 5344 |
+ leftNode.traverse(this); |
| 5345 |
+ mOut << ", "; |
| 5346 |
+ rightNode.traverse(this); |
| 5347 |
+ mOut << ")"; |
| 5348 |
+ } |
| 5349 |
+ } |
| 5350 |
+ } |
| 5351 |
+ |
| 5352 |
+ return false; |
| 5353 |
+} |
| 5354 |
+ |
| 5355 |
+static bool IsPostfix(TOperator op) |
| 5356 |
+{ |
| 5357 |
+ switch (op) |
| 5358 |
+ { |
| 5359 |
+ case TOperator::EOpPostIncrement: |
| 5360 |
+ case TOperator::EOpPostDecrement: |
| 5361 |
+ return true; |
| 5362 |
+ |
| 5363 |
+ default: |
| 5364 |
+ return false; |
| 5365 |
+ } |
| 5366 |
+} |
| 5367 |
+ |
| 5368 |
+bool GenMetalTraverser::visitUnary(Visit, TIntermUnary *unaryNode) |
| 5369 |
+{ |
| 5370 |
+ const TOperator op = unaryNode->getOp(); |
| 5371 |
+ const TType &resultType = unaryNode->getType(); |
| 5372 |
+ |
| 5373 |
+ TIntermTyped &arg = *unaryNode->getOperand(); |
| 5374 |
+ const TType &argType = arg.getType(); |
| 5375 |
+ |
| 5376 |
+ const char *name = GetOperatorString(op, resultType, &argType); |
| 5377 |
+ |
| 5378 |
+ if (IsSymbolicOperator(op, resultType, &argType)) |
| 5379 |
+ { |
| 5380 |
+ const bool postfix = IsPostfix(op); |
| 5381 |
+ if (!postfix) |
| 5382 |
+ { |
| 5383 |
+ mOut << name; |
| 5384 |
+ } |
| 5385 |
+ groupedTraverse(arg); |
| 5386 |
+ if (postfix) |
| 5387 |
+ { |
| 5388 |
+ mOut << name; |
| 5389 |
+ } |
| 5390 |
+ } |
| 5391 |
+ else |
| 5392 |
+ { |
| 5393 |
+ mOut << name << "("; |
| 5394 |
+ arg.traverse(this); |
| 5395 |
+ mOut << ")"; |
| 5396 |
+ } |
| 5397 |
+ |
| 5398 |
+ return false; |
| 5399 |
+} |
| 5400 |
+ |
| 5401 |
+bool GenMetalTraverser::visitTernary(Visit, TIntermTernary *conditionalNode) |
| 5402 |
+{ |
| 5403 |
+ groupedTraverse(*conditionalNode->getCondition()); |
| 5404 |
+ mOut << " ? "; |
| 5405 |
+ groupedTraverse(*conditionalNode->getTrueExpression()); |
| 5406 |
+ mOut << " : "; |
| 5407 |
+ groupedTraverse(*conditionalNode->getFalseExpression()); |
| 5408 |
+ |
| 5409 |
+ return false; |
| 5410 |
+} |
| 5411 |
+ |
| 5412 |
+bool GenMetalTraverser::visitIfElse(Visit, TIntermIfElse *ifThenElseNode) |
| 5413 |
+{ |
| 5414 |
+ TIntermTyped &condNode = *ifThenElseNode->getCondition(); |
| 5415 |
+ TIntermBlock *thenNode = ifThenElseNode->getTrueBlock(); |
| 5416 |
+ TIntermBlock *elseNode = ifThenElseNode->getFalseBlock(); |
| 5417 |
+ |
| 5418 |
+ emitIndentation(); |
| 5419 |
+ mOut << "if ("; |
| 5420 |
+ condNode.traverse(this); |
| 5421 |
+ mOut << ")"; |
| 5422 |
+ |
| 5423 |
+ if (thenNode) |
| 5424 |
+ { |
| 5425 |
+ mOut << "\n"; |
| 5426 |
+ thenNode->traverse(this); |
| 5427 |
+ } |
| 5428 |
+ else |
| 5429 |
+ { |
| 5430 |
+ mOut << " {}"; |
| 5431 |
+ } |
| 5432 |
+ |
| 5433 |
+ if (elseNode) |
| 5434 |
+ { |
| 5435 |
+ mOut << "\n"; |
| 5436 |
+ emitIndentation(); |
| 5437 |
+ mOut << "else\n"; |
| 5438 |
+ elseNode->traverse(this); |
| 5439 |
+ } |
| 5440 |
+ else |
| 5441 |
+ { |
| 5442 |
+ // Always emit "else" even when empty block to avoid nested if-stmt issues. |
| 5443 |
+ mOut << " else {}"; |
| 5444 |
+ } |
| 5445 |
+ |
| 5446 |
+ return false; |
| 5447 |
+} |
| 5448 |
+ |
| 5449 |
+bool GenMetalTraverser::visitSwitch(Visit, TIntermSwitch *switchNode) |
| 5450 |
+{ |
| 5451 |
+ emitIndentation(); |
| 5452 |
+ mOut << "switch ("; |
| 5453 |
+ switchNode->getInit()->traverse(this); |
| 5454 |
+ mOut << ")\n"; |
| 5455 |
+ |
| 5456 |
+ ASSERT(!mParentIsSwitch); |
| 5457 |
+ mParentIsSwitch = true; |
| 5458 |
+ switchNode->getStatementList()->traverse(this); |
| 5459 |
+ mParentIsSwitch = false; |
| 5460 |
+ |
| 5461 |
+ return false; |
| 5462 |
+} |
| 5463 |
+ |
| 5464 |
+bool GenMetalTraverser::visitCase(Visit, TIntermCase *caseNode) |
| 5465 |
+{ |
| 5466 |
+ emitIndentation(); |
| 5467 |
+ |
| 5468 |
+ if (caseNode->hasCondition()) |
| 5469 |
+ { |
| 5470 |
+ TIntermTyped *condExpr = caseNode->getCondition(); |
| 5471 |
+ mOut << "case "; |
| 5472 |
+ condExpr->traverse(this); |
| 5473 |
+ mOut << ":"; |
| 5474 |
+ } |
| 5475 |
+ else |
| 5476 |
+ { |
| 5477 |
+ mOut << "default:\n"; |
| 5478 |
+ } |
| 5479 |
+ |
| 5480 |
+ return false; |
| 5481 |
+} |
| 5482 |
+ |
| 5483 |
+void GenMetalTraverser::emitFunctionSignature(const TFunction &func) |
| 5484 |
+{ |
| 5485 |
+ const bool isMain = func.isMain(); |
| 5486 |
+ |
| 5487 |
+ emitFunctionReturn(func); |
| 5488 |
+ |
| 5489 |
+ mOut << " "; |
| 5490 |
+ emitNameOf(func); |
| 5491 |
+ if (isMain) |
| 5492 |
+ { |
| 5493 |
+ mOut << "0"; |
| 5494 |
+ } |
| 5495 |
+ mOut << "("; |
| 5496 |
+ |
| 5497 |
+ bool emitComma = false; |
| 5498 |
+ const size_t paramCount = func.getParamCount(); |
| 5499 |
+ for (size_t i = 0; i < paramCount; ++i) |
| 5500 |
+ { |
| 5501 |
+ if (emitComma) |
| 5502 |
+ { |
| 5503 |
+ mOut << ", "; |
| 5504 |
+ } |
| 5505 |
+ emitComma = true; |
| 5506 |
+ |
| 5507 |
+ const TVariable ¶m = *func.getParam(i); |
| 5508 |
+ emitFunctionParameter(func, param); |
| 5509 |
+ } |
| 5510 |
+ |
| 5511 |
+ mOut << ")"; |
| 5512 |
+} |
| 5513 |
+ |
| 5514 |
+void GenMetalTraverser::emitFunctionReturn(const TFunction &func) |
| 5515 |
+{ |
| 5516 |
+ const bool isMain = func.isMain(); |
| 5517 |
+ |
| 5518 |
+ const TType &returnType = func.getReturnType(); |
| 5519 |
+ if (isMain) |
| 5520 |
+ { |
| 5521 |
+ const TStructure *structure = returnType.getStruct(); |
| 5522 |
+ ASSERT(structure != nullptr); |
| 5523 |
+ if (mPipelineStructs.fragmentOut.matches(*structure)) |
| 5524 |
+ { |
| 5525 |
+ mOut << "fragment "; |
| 5526 |
+ } |
| 5527 |
+ else if (mPipelineStructs.vertexOut.matches(*structure)) |
| 5528 |
+ { |
| 5529 |
+ mOut << "vertex "; |
| 5530 |
+ } |
| 5531 |
+ else |
| 5532 |
+ { |
| 5533 |
+ TODO(); |
| 5534 |
+ } |
| 5535 |
+ } |
| 5536 |
+ emitType(returnType, EmitTypeConfig()); |
| 5537 |
+} |
| 5538 |
+ |
| 5539 |
+void GenMetalTraverser::emitFunctionParameter(const TFunction &func, const TVariable ¶m) |
| 5540 |
+{ |
| 5541 |
+ const bool isMain = func.isMain(); |
| 5542 |
+ |
| 5543 |
+ const TType &type = param.getType(); |
| 5544 |
+ const TStructure *structure = type.getStruct(); |
| 5545 |
+ |
| 5546 |
+ EmitVariableDeclarationConfig evdConfig; |
| 5547 |
+ evdConfig.isParameter = true; |
| 5548 |
+ evdConfig.isMainParameter = isMain; |
| 5549 |
+ evdConfig.emitPostQualifier = isMain; |
| 5550 |
+ evdConfig.isPointer = mSymbolEnv.isPointer(param); |
| 5551 |
+ evdConfig.isReference = mSymbolEnv.isReference(param); |
| 5552 |
+ emitVariableDeclaration(VarDecl(param), evdConfig); |
| 5553 |
+ |
| 5554 |
+ if (isMain) |
| 5555 |
+ { |
| 5556 |
+ TranslatorMetalReflection *reflection = |
| 5557 |
+ ((sh::TranslatorMetalDirect *)&mCompiler)->getTranslatorMetalReflection(); |
| 5558 |
+ if (structure) |
| 5559 |
+ { |
| 5560 |
+ if (mPipelineStructs.fragmentIn.matches(*structure) || |
| 5561 |
+ mPipelineStructs.vertexIn.matches(*structure)) |
| 5562 |
+ { |
| 5563 |
+ mOut << " [[stage_in]]"; |
| 5564 |
+ } |
| 5565 |
+ else if (mPipelineStructs.angleUniforms.matches(*structure)) |
| 5566 |
+ { |
| 5567 |
+ mOut << " [[buffer(" << rx::mtl::kDriverUniformsBindingIndex << ")]]"; |
| 5568 |
+ } |
| 5569 |
+ else if (mPipelineStructs.userUniforms.matches(*structure)) |
| 5570 |
+ { |
| 5571 |
+ mOut << " [[buffer(" << mMainUniformBufferIndex << ")]]"; |
| 5572 |
+ reflection->addUniformBufferBinding(param.name().data(), mMainUniformBufferIndex); |
| 5573 |
+ mMainUniformBufferIndex += type.getArraySizeProduct(); |
| 5574 |
+ } |
| 5575 |
+ else if (structure->name() == "metal::sampler") |
| 5576 |
+ { |
| 5577 |
+ mOut << " [[sampler(" << (mMainSamplerIndex) << ")]]"; |
| 5578 |
+ const std::string originalName = |
| 5579 |
+ reflection->getOriginalName(param.uniqueId().get()); |
| 5580 |
+ reflection->addSamplerBinding(originalName, mMainSamplerIndex); |
| 5581 |
+ mMainSamplerIndex += type.getArraySizeProduct(); |
| 5582 |
+ } |
| 5583 |
+ } |
| 5584 |
+ else if (IsSampler(type.getBasicType())) |
| 5585 |
+ { |
| 5586 |
+ mOut << " [[texture(" << (mMainTextureIndex) << ")]]"; |
| 5587 |
+ const std::string originalName = reflection->getOriginalName(param.uniqueId().get()); |
| 5588 |
+ reflection->addTextureBinding(originalName, mMainSamplerIndex); |
| 5589 |
+ mMainTextureIndex += type.getArraySizeProduct(); |
| 5590 |
+ } |
| 5591 |
+ else if (Name(param) == Pipeline{Pipeline::Type::InstanceId, nullptr}.getStructInstanceName( |
| 5592 |
+ Pipeline::Variant::Modified)) |
| 5593 |
+ { |
| 5594 |
+ mOut << " [[instance_id]]"; |
| 5595 |
+ } |
| 5596 |
+ } |
| 5597 |
+} |
| 5598 |
+ |
| 5599 |
+void GenMetalTraverser::visitFunctionPrototype(TIntermFunctionPrototype *funcProtoNode) |
| 5600 |
+{ |
| 5601 |
+ const TFunction &func = *funcProtoNode->getFunction(); |
| 5602 |
+ |
| 5603 |
+ emitIndentation(); |
| 5604 |
+ emitFunctionSignature(func); |
| 5605 |
+} |
| 5606 |
+ |
| 5607 |
+bool GenMetalTraverser::visitFunctionDefinition(Visit, TIntermFunctionDefinition *funcDefNode) |
| 5608 |
+{ |
| 5609 |
+ const TFunction &func = *funcDefNode->getFunction(); |
| 5610 |
+ TIntermBlock &body = *funcDefNode->getBody(); |
| 5611 |
+ |
| 5612 |
+ emitIndentation(); |
| 5613 |
+ emitFunctionSignature(func); |
| 5614 |
+ mOut << "\n"; |
| 5615 |
+ body.traverse(this); |
| 5616 |
+ |
| 5617 |
+ return false; |
| 5618 |
+} |
| 5619 |
+ |
| 5620 |
+GenMetalTraverser::FuncToName GenMetalTraverser::BuildFuncToName() |
| 5621 |
+{ |
| 5622 |
+ FuncToName map; |
| 5623 |
+ |
| 5624 |
+ auto putAngle = [&](const char *nameStr) { |
| 5625 |
+ const ImmutableString name(nameStr); |
| 5626 |
+ ASSERT(map.find(name) == map.end()); |
| 5627 |
+ map[name] = Name(nameStr, SymbolType::AngleInternal); |
| 5628 |
+ }; |
| 5629 |
+ |
| 5630 |
+ putAngle("texelFetch"); |
| 5631 |
+ putAngle("texelFetchOffset"); |
| 5632 |
+ putAngle("texture"); |
| 5633 |
+ putAngle("texture1D"); |
| 5634 |
+ putAngle("texture1DLod"); |
| 5635 |
+ putAngle("texture1DProjLod"); |
| 5636 |
+ putAngle("texture2D"); |
| 5637 |
+ putAngle("texture2DLod"); |
| 5638 |
+ putAngle("texture2DProj"); |
| 5639 |
+ putAngle("texture2DProjLod"); |
| 5640 |
+ putAngle("texture3D"); |
| 5641 |
+ putAngle("texture3DLod"); |
| 5642 |
+ putAngle("texture3DProjLod"); |
| 5643 |
+ putAngle("textureCube"); |
| 5644 |
+ putAngle("textureCubeLod"); |
| 5645 |
+ putAngle("textureCubeProjLod"); |
| 5646 |
+ putAngle("textureGrad"); |
| 5647 |
+ putAngle("textureGradOffset"); |
| 5648 |
+ putAngle("textureLod"); |
| 5649 |
+ putAngle("textureLodOffset"); |
| 5650 |
+ putAngle("textureOffset"); |
| 5651 |
+ putAngle("textureProj"); |
| 5652 |
+ putAngle("textureProjGrad"); |
| 5653 |
+ putAngle("textureProjGradOffset"); |
| 5654 |
+ putAngle("textureProjLod"); |
| 5655 |
+ putAngle("textureProjLodOffset"); |
| 5656 |
+ putAngle("textureProjOffset"); |
| 5657 |
+ putAngle("textureSize"); |
| 5658 |
+ |
| 5659 |
+ return map; |
| 5660 |
+} |
| 5661 |
+ |
| 5662 |
+bool GenMetalTraverser::visitAggregate(Visit, TIntermAggregate *aggregateNode) |
| 5663 |
+{ |
| 5664 |
+ const TIntermSequence &args = *aggregateNode->getSequence(); |
| 5665 |
+ |
| 5666 |
+ auto emitArgList = [&](const char *open, const char *close) { |
| 5667 |
+ mOut << open; |
| 5668 |
+ |
| 5669 |
+ bool emitComma = false; |
| 5670 |
+ for (TIntermNode *arg : args) |
| 5671 |
+ { |
| 5672 |
+ if (emitComma) |
| 5673 |
+ { |
| 5674 |
+ mOut << ", "; |
| 5675 |
+ } |
| 5676 |
+ emitComma = true; |
| 5677 |
+ arg->traverse(this); |
| 5678 |
+ } |
| 5679 |
+ |
| 5680 |
+ mOut << close; |
| 5681 |
+ }; |
| 5682 |
+ |
| 5683 |
+ const TType &retType = aggregateNode->getType(); |
| 5684 |
+ |
| 5685 |
+ if (aggregateNode->isConstructor()) |
| 5686 |
+ { |
| 5687 |
+ const bool isStandalone = getParentNode()->getAsBlock(); |
| 5688 |
+ if (isStandalone) |
| 5689 |
+ { |
| 5690 |
+ // Prevent constructor from being interpreted as a declaration by wrapping in parens. |
| 5691 |
+ // This can happen if given something like: |
| 5692 |
+ // int(symbol); // <- This will be treated like `int symbol;`... don't want that. |
| 5693 |
+ // So instead emit: |
| 5694 |
+ // (int(symbol)); |
| 5695 |
+ mOut << "("; |
| 5696 |
+ } |
| 5697 |
+ |
| 5698 |
+ const EmitTypeConfig etConfig; |
| 5699 |
+ |
| 5700 |
+ if (retType.isArray()) |
| 5701 |
+ { |
| 5702 |
+ emitType(retType, etConfig); |
| 5703 |
+ emitArgList("{", "}"); |
| 5704 |
+ } |
| 5705 |
+ else if (retType.getStruct()) |
| 5706 |
+ { |
| 5707 |
+ emitType(retType, etConfig); |
| 5708 |
+ emitArgList("{", "}"); |
| 5709 |
+ } |
| 5710 |
+ else |
| 5711 |
+ { |
| 5712 |
+ emitType(retType, etConfig); |
| 5713 |
+ emitArgList("(", ")"); |
| 5714 |
+ } |
| 5715 |
+ |
| 5716 |
+ if (isStandalone) |
| 5717 |
+ { |
| 5718 |
+ mOut << ")"; |
| 5719 |
+ } |
| 5720 |
+ |
| 5721 |
+ return false; |
| 5722 |
+ } |
| 5723 |
+ else |
| 5724 |
+ { |
| 5725 |
+ const TOperator op = aggregateNode->getOp(); |
| 5726 |
+ switch (op) |
| 5727 |
+ { |
| 5728 |
+ case TOperator::EOpCallFunctionInAST: |
| 5729 |
+ case TOperator::EOpCallInternalRawFunction: |
| 5730 |
+ { |
| 5731 |
+ const TFunction &func = *aggregateNode->getFunction(); |
| 5732 |
+ emitNameOf(func); |
| 5733 |
+ emitArgList("(", ")"); |
| 5734 |
+ return false; |
| 5735 |
+ } |
| 5736 |
+ |
| 5737 |
+ case TOperator::EOpCallBuiltInFunction: |
| 5738 |
+ { |
| 5739 |
+ const TFunction &func = *aggregateNode->getFunction(); |
| 5740 |
+ auto it = mFuncToName.find(func.name()); |
| 5741 |
+ ASSERT(it != mFuncToName.end()); |
| 5742 |
+ EmitName(mOut, it->second); |
| 5743 |
+ emitArgList("(", ")"); |
| 5744 |
+ return false; |
| 5745 |
+ } |
| 5746 |
+ |
| 5747 |
+ default: |
| 5748 |
+ { |
| 5749 |
+ auto getArgType = [&](size_t index) -> const TType * { |
| 5750 |
+ if (index < args.size()) |
| 5751 |
+ { |
| 5752 |
+ TIntermTyped *arg = args[index]->getAsTyped(); |
| 5753 |
+ ASSERT(arg); |
| 5754 |
+ return &arg->getType(); |
| 5755 |
+ } |
| 5756 |
+ return nullptr; |
| 5757 |
+ }; |
| 5758 |
+ |
| 5759 |
+ ASSERT(!args.empty()); |
| 5760 |
+ const TType *argType0 = getArgType(0); |
| 5761 |
+ const TType *argType1 = getArgType(1); |
| 5762 |
+ ASSERT(argType0); |
| 5763 |
+ |
| 5764 |
+ const char *opName = GetOperatorString(op, retType, argType0, argType1); |
| 5765 |
+ |
| 5766 |
+ if (IsSymbolicOperator(op, retType, argType0, argType1)) |
| 5767 |
+ { |
| 5768 |
+ switch (args.size()) |
| 5769 |
+ { |
| 5770 |
+ case 1: |
| 5771 |
+ { |
| 5772 |
+ TIntermNode &operandNode = *aggregateNode->getChildNode(0); |
| 5773 |
+ if (IsPostfix(op)) |
| 5774 |
+ { |
| 5775 |
+ mOut << opName; |
| 5776 |
+ groupedTraverse(operandNode); |
| 5777 |
+ return false; |
| 5778 |
+ } |
| 5779 |
+ else |
| 5780 |
+ { |
| 5781 |
+ groupedTraverse(operandNode); |
| 5782 |
+ mOut << opName; |
| 5783 |
+ return false; |
| 5784 |
+ } |
| 5785 |
+ } |
| 5786 |
+ break; |
| 5787 |
+ |
| 5788 |
+ case 2: |
| 5789 |
+ { |
| 5790 |
+ TIntermNode &leftNode = *aggregateNode->getChildNode(0); |
| 5791 |
+ TIntermNode &rightNode = *aggregateNode->getChildNode(1); |
| 5792 |
+ groupedTraverse(leftNode); |
| 5793 |
+ mOut << " " << opName << " "; |
| 5794 |
+ groupedTraverse(rightNode); |
| 5795 |
+ return false; |
| 5796 |
+ } |
| 5797 |
+ break; |
| 5798 |
+ |
| 5799 |
+ default: |
| 5800 |
+ LOGIC_ERROR(); |
| 5801 |
+ return false; |
| 5802 |
+ } |
| 5803 |
+ } |
| 5804 |
+ else |
| 5805 |
+ { |
| 5806 |
+ mOut << opName; |
| 5807 |
+ emitArgList("(", ")"); |
| 5808 |
+ return false; |
| 5809 |
+ } |
| 5810 |
+ } |
| 5811 |
+ } |
| 5812 |
+ } |
| 5813 |
+} |
| 5814 |
+ |
| 5815 |
+void GenMetalTraverser::emitOpenBrace() |
| 5816 |
+{ |
| 5817 |
+ ASSERT(mIndentLevel >= 0); |
| 5818 |
+ |
| 5819 |
+ emitIndentation(); |
| 5820 |
+ mOut << "{\n"; |
| 5821 |
+ ++mIndentLevel; |
| 5822 |
+} |
| 5823 |
+ |
| 5824 |
+void GenMetalTraverser::emitCloseBrace() |
| 5825 |
+{ |
| 5826 |
+ ASSERT(mIndentLevel >= 1); |
| 5827 |
+ |
| 5828 |
+ --mIndentLevel; |
| 5829 |
+ emitIndentation(); |
| 5830 |
+ mOut << "}"; |
| 5831 |
+} |
| 5832 |
+ |
| 5833 |
+static bool RequiresSemicolonTerminator(TIntermNode &node) |
| 5834 |
+{ |
| 5835 |
+ if (node.getAsBlock()) |
| 5836 |
+ { |
| 5837 |
+ return false; |
| 5838 |
+ } |
| 5839 |
+ if (node.getAsLoopNode()) |
| 5840 |
+ { |
| 5841 |
+ return false; |
| 5842 |
+ } |
| 5843 |
+ if (node.getAsSwitchNode()) |
| 5844 |
+ { |
| 5845 |
+ return false; |
| 5846 |
+ } |
| 5847 |
+ if (node.getAsIfElseNode()) |
| 5848 |
+ { |
| 5849 |
+ return false; |
| 5850 |
+ } |
| 5851 |
+ if (node.getAsFunctionDefinition()) |
| 5852 |
+ { |
| 5853 |
+ return false; |
| 5854 |
+ } |
| 5855 |
+ if (node.getAsCaseNode()) |
| 5856 |
+ { |
| 5857 |
+ return false; |
| 5858 |
+ } |
| 5859 |
+ return true; |
| 5860 |
+} |
| 5861 |
+ |
| 5862 |
+static bool NewlinePad(TIntermNode &node) |
| 5863 |
+{ |
| 5864 |
+ if (node.getAsFunctionDefinition()) |
| 5865 |
+ { |
| 5866 |
+ return true; |
| 5867 |
+ } |
| 5868 |
+ if (TIntermDeclaration *declNode = node.getAsDeclarationNode()) |
| 5869 |
+ { |
| 5870 |
+ ASSERT(declNode->getChildCount() == 1); |
| 5871 |
+ TIntermNode &childNode = *declNode->getChildNode(0); |
| 5872 |
+ if (TIntermSymbol *symbolNode = childNode.getAsSymbolNode()) |
| 5873 |
+ { |
| 5874 |
+ const TVariable &var = symbolNode->variable(); |
| 5875 |
+ return var.getType().isStructSpecifier(); |
| 5876 |
+ } |
| 5877 |
+ return false; |
| 5878 |
+ } |
| 5879 |
+ return false; |
| 5880 |
+} |
| 5881 |
+ |
| 5882 |
+bool GenMetalTraverser::visitBlock(Visit, TIntermBlock *blockNode) |
| 5883 |
+{ |
| 5884 |
+ ASSERT(mIndentLevel >= -1); |
| 5885 |
+ const bool isGlobalScope = mIndentLevel == -1; |
| 5886 |
+ const bool parentIsSwitch = mParentIsSwitch; |
| 5887 |
+ mParentIsSwitch = false; |
| 5888 |
+ |
| 5889 |
+ if (isGlobalScope) |
| 5890 |
+ { |
| 5891 |
+ ++mIndentLevel; |
| 5892 |
+ } |
| 5893 |
+ else |
| 5894 |
+ { |
| 5895 |
+ emitOpenBrace(); |
| 5896 |
+ if (parentIsSwitch) |
| 5897 |
+ { |
| 5898 |
+ ++mIndentLevel; |
| 5899 |
+ } |
| 5900 |
+ } |
| 5901 |
+ |
| 5902 |
+ TIntermNode *prevStmtNode = nullptr; |
| 5903 |
+ |
| 5904 |
+ const size_t stmtCount = blockNode->getChildCount(); |
| 5905 |
+ for (size_t i = 0; i < stmtCount; ++i) |
| 5906 |
+ { |
| 5907 |
+ TIntermNode &stmtNode = *blockNode->getChildNode(i); |
| 5908 |
+ |
| 5909 |
+ if (isGlobalScope && prevStmtNode && (NewlinePad(*prevStmtNode) || NewlinePad(stmtNode))) |
| 5910 |
+ { |
| 5911 |
+ mOut << "\n"; |
| 5912 |
+ } |
| 5913 |
+ const bool isCase = stmtNode.getAsCaseNode(); |
| 5914 |
+ mIndentLevel -= isCase; |
| 5915 |
+ emitIndentation(); |
| 5916 |
+ mIndentLevel += isCase; |
| 5917 |
+ stmtNode.traverse(this); |
| 5918 |
+ if (RequiresSemicolonTerminator(stmtNode)) |
| 5919 |
+ { |
| 5920 |
+ mOut << ";"; |
| 5921 |
+ } |
| 5922 |
+ mOut << "\n"; |
| 5923 |
+ |
| 5924 |
+ prevStmtNode = &stmtNode; |
| 5925 |
+ } |
| 5926 |
+ |
| 5927 |
+ if (isGlobalScope) |
| 5928 |
+ { |
| 5929 |
+ ASSERT(mIndentLevel == 0); |
| 5930 |
+ --mIndentLevel; |
| 5931 |
+ } |
| 5932 |
+ else |
| 5933 |
+ { |
| 5934 |
+ if (parentIsSwitch) |
| 5935 |
+ { |
| 5936 |
+ ASSERT(mIndentLevel >= 1); |
| 5937 |
+ --mIndentLevel; |
| 5938 |
+ } |
| 5939 |
+ emitCloseBrace(); |
| 5940 |
+ mParentIsSwitch = parentIsSwitch; |
| 5941 |
+ } |
| 5942 |
+ |
| 5943 |
+ return false; |
| 5944 |
+} |
| 5945 |
+ |
| 5946 |
+bool GenMetalTraverser::visitGlobalQualifierDeclaration(Visit, TIntermGlobalQualifierDeclaration *) |
| 5947 |
+{ |
| 5948 |
+ LOGIC_ERROR(); // RewriteGlobalQualifierDecls should have been called before this. |
| 5949 |
+ return false; |
| 5950 |
+} |
| 5951 |
+ |
| 5952 |
+bool GenMetalTraverser::visitDeclaration(Visit, TIntermDeclaration *declNode) |
| 5953 |
+{ |
| 5954 |
+ ASSERT(declNode->getChildCount() == 1); |
| 5955 |
+ TIntermNode &node = *declNode->getChildNode(0); |
| 5956 |
+ |
| 5957 |
+ EmitVariableDeclarationConfig evdConfig; |
| 5958 |
+ |
| 5959 |
+ if (TIntermSymbol *symbolNode = node.getAsSymbolNode()) |
| 5960 |
+ { |
| 5961 |
+ const TVariable &var = symbolNode->variable(); |
| 5962 |
+ emitVariableDeclaration(VarDecl(var), evdConfig); |
| 5963 |
+ } |
| 5964 |
+ else if (TIntermBinary *initNode = node.getAsBinaryNode()) |
| 5965 |
+ { |
| 5966 |
+ ASSERT(initNode->getOp() == TOperator::EOpInitialize); |
| 5967 |
+ TIntermSymbol *symbolNode = initNode->getLeft()->getAsSymbolNode(); |
| 5968 |
+ TIntermTyped *valueNode = initNode->getRight()->getAsTyped(); |
| 5969 |
+ ASSERT(symbolNode && valueNode); |
| 5970 |
+ |
| 5971 |
+ if (getRootNode() == getParentBlock()) |
| 5972 |
+ { |
| 5973 |
+ // DeferGlobalInitializers should have turned non-const global initializers into |
| 5974 |
+ // deferred initializers. Note that variables marked as EvqGlobal can be treated as |
| 5975 |
+ // EvqConst in some ANGLE code but not actually have their qualifier actually changed to |
| 5976 |
+ // EvqConst. Thus just assume all EvqGlobal are actually EvqConst for all code run after |
| 5977 |
+ // DeferGlobalInitializers. |
| 5978 |
+ mOut << "constant "; |
| 5979 |
+ } |
| 5980 |
+ |
| 5981 |
+ const TVariable &var = symbolNode->variable(); |
| 5982 |
+ const Name varName(var); |
| 5983 |
+ |
| 5984 |
+ if (ExpressionContainsName(varName, *valueNode)) |
| 5985 |
+ { |
| 5986 |
+ mRenamedSymbols[&var] = mIdGen.createNewName(varName); |
| 5987 |
+ } |
| 5988 |
+ |
| 5989 |
+ emitVariableDeclaration(VarDecl(var), evdConfig); |
| 5990 |
+ mOut << " = "; |
| 5991 |
+ groupedTraverse(*valueNode); |
| 5992 |
+ } |
| 5993 |
+ else |
| 5994 |
+ { |
| 5995 |
+ LOGIC_ERROR(); |
| 5996 |
+ } |
| 5997 |
+ |
| 5998 |
+ return false; |
| 5999 |
+} |
| 6000 |
+ |
| 6001 |
+bool GenMetalTraverser::visitLoop(Visit, TIntermLoop *loopNode) |
| 6002 |
+{ |
| 6003 |
+ const TLoopType loopType = loopNode->getType(); |
| 6004 |
+ |
| 6005 |
+ switch (loopType) |
| 6006 |
+ { |
| 6007 |
+ case TLoopType::ELoopFor: |
| 6008 |
+ return visitForLoop(loopNode); |
| 6009 |
+ case TLoopType::ELoopWhile: |
| 6010 |
+ return visitWhileLoop(loopNode); |
| 6011 |
+ case TLoopType::ELoopDoWhile: |
| 6012 |
+ return visitDoWhileLoop(loopNode); |
| 6013 |
+ } |
| 6014 |
+} |
| 6015 |
+ |
| 6016 |
+bool GenMetalTraverser::visitForLoop(TIntermLoop *loopNode) |
| 6017 |
+{ |
| 6018 |
+ ASSERT(loopNode->getType() == TLoopType::ELoopFor); |
| 6019 |
+ |
| 6020 |
+ TIntermNode *initNode = loopNode->getInit(); |
| 6021 |
+ TIntermTyped *condNode = loopNode->getCondition(); |
| 6022 |
+ TIntermTyped *exprNode = loopNode->getExpression(); |
| 6023 |
+ TIntermBlock *bodyNode = loopNode->getBody(); |
| 6024 |
+ ASSERT(bodyNode); |
| 6025 |
+ |
| 6026 |
+ mOut << "for ("; |
| 6027 |
+ |
| 6028 |
+ if (initNode) |
| 6029 |
+ { |
| 6030 |
+ initNode->traverse(this); |
| 6031 |
+ } |
| 6032 |
+ else |
| 6033 |
+ { |
| 6034 |
+ mOut << " "; |
| 6035 |
+ } |
| 6036 |
+ |
| 6037 |
+ mOut << "; "; |
| 6038 |
+ |
| 6039 |
+ if (condNode) |
| 6040 |
+ { |
| 6041 |
+ condNode->traverse(this); |
| 6042 |
+ } |
| 6043 |
+ |
| 6044 |
+ mOut << "; "; |
| 6045 |
+ |
| 6046 |
+ if (exprNode) |
| 6047 |
+ { |
| 6048 |
+ exprNode->traverse(this); |
| 6049 |
+ } |
| 6050 |
+ |
| 6051 |
+ mOut << ")\n"; |
| 6052 |
+ |
| 6053 |
+ bodyNode->traverse(this); |
| 6054 |
+ |
| 6055 |
+ return false; |
| 6056 |
+} |
| 6057 |
+ |
| 6058 |
+bool GenMetalTraverser::visitWhileLoop(TIntermLoop *loopNode) |
| 6059 |
+{ |
| 6060 |
+ ASSERT(loopNode->getType() == TLoopType::ELoopWhile); |
| 6061 |
+ |
| 6062 |
+ TIntermNode *initNode = loopNode->getInit(); |
| 6063 |
+ TIntermTyped *condNode = loopNode->getCondition(); |
| 6064 |
+ TIntermTyped *exprNode = loopNode->getExpression(); |
| 6065 |
+ TIntermBlock *bodyNode = loopNode->getBody(); |
| 6066 |
+ ASSERT(condNode && bodyNode); |
| 6067 |
+ ASSERT(!initNode && !exprNode); |
| 6068 |
+ |
| 6069 |
+ emitIndentation(); |
| 6070 |
+ mOut << "while ("; |
| 6071 |
+ condNode->traverse(this); |
| 6072 |
+ mOut << ")\n"; |
| 6073 |
+ bodyNode->traverse(this); |
| 6074 |
+ |
| 6075 |
+ return false; |
| 6076 |
+} |
| 6077 |
+ |
| 6078 |
+bool GenMetalTraverser::visitDoWhileLoop(TIntermLoop *loopNode) |
| 6079 |
+{ |
| 6080 |
+ ASSERT(loopNode->getType() == TLoopType::ELoopDoWhile); |
| 6081 |
+ |
| 6082 |
+ TIntermNode *initNode = loopNode->getInit(); |
| 6083 |
+ TIntermTyped *condNode = loopNode->getCondition(); |
| 6084 |
+ TIntermTyped *exprNode = loopNode->getExpression(); |
| 6085 |
+ TIntermBlock *bodyNode = loopNode->getBody(); |
| 6086 |
+ ASSERT(condNode && bodyNode); |
| 6087 |
+ ASSERT(!initNode && !exprNode); |
| 6088 |
+ |
| 6089 |
+ emitIndentation(); |
| 6090 |
+ mOut << "do\n"; |
| 6091 |
+ bodyNode->traverse(this); |
| 6092 |
+ mOut << "\n"; |
| 6093 |
+ emitIndentation(); |
| 6094 |
+ mOut << "while ("; |
| 6095 |
+ condNode->traverse(this); |
| 6096 |
+ mOut << ");"; |
| 6097 |
+ |
| 6098 |
+ return false; |
| 6099 |
+} |
| 6100 |
+ |
| 6101 |
+bool GenMetalTraverser::visitBranch(Visit, TIntermBranch *branchNode) |
| 6102 |
+{ |
| 6103 |
+ const TOperator flowOp = branchNode->getFlowOp(); |
| 6104 |
+ TIntermTyped *exprNode = branchNode->getExpression(); |
| 6105 |
+ |
| 6106 |
+ emitIndentation(); |
| 6107 |
+ |
| 6108 |
+ switch (flowOp) |
| 6109 |
+ { |
| 6110 |
+ case TOperator::EOpKill: |
| 6111 |
+ { |
| 6112 |
+ ASSERT(exprNode == nullptr); |
| 6113 |
+ mOut << "metal::discard_fragment()"; |
| 6114 |
+ } |
| 6115 |
+ break; |
| 6116 |
+ |
| 6117 |
+ case TOperator::EOpReturn: |
| 6118 |
+ { |
| 6119 |
+ mOut << "return"; |
| 6120 |
+ if (exprNode) |
| 6121 |
+ { |
| 6122 |
+ mOut << " "; |
| 6123 |
+ exprNode->traverse(this); |
| 6124 |
+ } |
| 6125 |
+ } |
| 6126 |
+ break; |
| 6127 |
+ |
| 6128 |
+ case TOperator::EOpBreak: |
| 6129 |
+ { |
| 6130 |
+ ASSERT(exprNode == nullptr); |
| 6131 |
+ mOut << "break"; |
| 6132 |
+ } |
| 6133 |
+ break; |
| 6134 |
+ |
| 6135 |
+ case TOperator::EOpContinue: |
| 6136 |
+ { |
| 6137 |
+ ASSERT(exprNode == nullptr); |
| 6138 |
+ mOut << "continue"; |
| 6139 |
+ } |
| 6140 |
+ break; |
| 6141 |
+ |
| 6142 |
+ default: |
| 6143 |
+ { |
| 6144 |
+ LOGIC_ERROR(); |
| 6145 |
+ } |
| 6146 |
+ } |
| 6147 |
+ |
| 6148 |
+ return false; |
| 6149 |
+} |
| 6150 |
+ |
| 6151 |
+static size_t emitMetalCallCount = 0; |
| 6152 |
+ |
| 6153 |
+bool sh::EmitMetal(TCompiler &compiler, |
| 6154 |
+ TIntermBlock &root, |
| 6155 |
+ IdGen &idGen, |
| 6156 |
+ const PipelineStructs &pipelineStructs, |
| 6157 |
+ const Invariants &invariants, |
| 6158 |
+ SymbolEnv &symbolEnv, |
| 6159 |
+ const ProgramPreludeConfig &ppc) |
| 6160 |
+{ |
| 6161 |
+ TInfoSinkBase &out = compiler.getInfoSink().obj; |
| 6162 |
+ |
| 6163 |
+ { |
| 6164 |
+ ++emitMetalCallCount; |
| 6165 |
+ auto filenameProto = readStringEnvVar("GMD_FIXED_EMIT"); |
| 6166 |
+ if (!filenameProto.empty()) |
| 6167 |
+ { |
| 6168 |
+ if (filenameProto != "/dev/null") |
| 6169 |
+ { |
| 6170 |
+ auto tryOpen = [&](char const *ext) { |
| 6171 |
+ auto filename = filenameProto; |
| 6172 |
+ filename += std::to_string(emitMetalCallCount); |
| 6173 |
+ filename += "."; |
| 6174 |
+ filename += ext; |
| 6175 |
+ return fopen(filename.c_str(), "rb"); |
| 6176 |
+ }; |
| 6177 |
+ FILE *file = tryOpen("metal"); |
| 6178 |
+ if (!file) |
| 6179 |
+ { |
| 6180 |
+ file = tryOpen("cpp"); |
| 6181 |
+ } |
| 6182 |
+ ASSERT(file); |
| 6183 |
+ |
| 6184 |
+ fseek(file, 0, SEEK_END); |
| 6185 |
+ size_t fileSize = ftell(file); |
| 6186 |
+ fseek(file, 0, SEEK_SET); |
| 6187 |
+ |
| 6188 |
+ std::vector<char> buff; |
| 6189 |
+ buff.resize(fileSize + 1); |
| 6190 |
+ fread(buff.data(), fileSize, 1, file); |
| 6191 |
+ buff.back() = '\0'; |
| 6192 |
+ |
| 6193 |
+ fclose(file); |
| 6194 |
+ |
| 6195 |
+ out << buff.data(); |
| 6196 |
+ } |
| 6197 |
+ |
| 6198 |
+ return true; |
| 6199 |
+ } |
| 6200 |
+ } |
| 6201 |
+ |
| 6202 |
+ out << "\n\n"; |
| 6203 |
+ |
| 6204 |
+ if (!EmitProgramPrelude(root, out, ppc)) |
| 6205 |
+ { |
| 6206 |
+ return false; |
| 6207 |
+ } |
| 6208 |
+ |
| 6209 |
+ { |
| 6210 |
+#if defined(ANGLE_ENABLE_ASSERTS) |
| 6211 |
+ DebugSink outWrapper(out, readBoolEnvVar("GMD_STDOUT")); |
| 6212 |
+ outWrapper.watch(readStringEnvVar("GMD_WATCH_STRING")); |
| 6213 |
+#else |
| 6214 |
+ TInfoSinkBase &outWrapper = out; |
| 6215 |
+#endif |
| 6216 |
+ GenMetalTraverser gen(compiler, outWrapper, idGen, pipelineStructs, invariants, symbolEnv); |
| 6217 |
+ root.traverse(&gen); |
| 6218 |
+ } |
| 6219 |
+ |
| 6220 |
+ out << "\n"; |
| 6221 |
+ |
| 6222 |
+ return true; |
| 6223 |
+} |
| 6224 |
diff --git a/src/compiler/translator/TranslatorMetalDirect/EmitMetal.h b/src/compiler/translator/TranslatorMetalDirect/EmitMetal.h |
| 6225 |
new file mode 100644 |
| 6226 |
index 0000000..d48af9a |
| 6227 |
--- /dev/null |
| 6228 |
+++ b/src/compiler/translator/TranslatorMetalDirect/EmitMetal.h |
| 6229 |
@@ -0,0 +1,32 @@ |
| 6230 |
+// |
| 6231 |
+// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 6232 |
+// Use of this source code is governed by a BSD-style license that can be |
| 6233 |
+// found in the LICENSE file. |
| 6234 |
+// |
| 6235 |
+ |
| 6236 |
+#ifndef COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_EMITMETAL_H_ |
| 6237 |
+#define COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_EMITMETAL_H_ |
| 6238 |
+ |
| 6239 |
+#include "common/angleutils.h" |
| 6240 |
+#include "compiler/translator/Compiler.h" |
| 6241 |
+#include "compiler/translator/TranslatorMetalDirect/IdGen.h" |
| 6242 |
+#include "compiler/translator/TranslatorMetalDirect/ProgramPrelude.h" |
| 6243 |
+#include "compiler/translator/TranslatorMetalDirect/RewriteGlobalQualifierDecls.h" |
| 6244 |
+#include "compiler/translator/TranslatorMetalDirect/RewritePipelines.h" |
| 6245 |
+#include "compiler/translator/TranslatorMetalDirect/SymbolEnv.h" |
| 6246 |
+ |
| 6247 |
+namespace sh |
| 6248 |
+{ |
| 6249 |
+ |
| 6250 |
+// Walks the AST and emits Metal code. |
| 6251 |
+ANGLE_NO_DISCARD bool EmitMetal(TCompiler &compiler, |
| 6252 |
+ TIntermBlock &root, |
| 6253 |
+ IdGen &idGen, |
| 6254 |
+ const PipelineStructs &pipelineStructs, |
| 6255 |
+ const Invariants &invariants, |
| 6256 |
+ SymbolEnv &symbolEnv, |
| 6257 |
+ const ProgramPreludeConfig &ppc); |
| 6258 |
+ |
| 6259 |
+} // namespace sh |
| 6260 |
+ |
| 6261 |
+#endif // COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_EMITMETAL_H_ |
| 6262 |
diff --git a/src/compiler/translator/TranslatorMetalDirect/EnvironmentVariable.h b/src/compiler/translator/TranslatorMetalDirect/EnvironmentVariable.h |
| 6263 |
new file mode 100644 |
| 6264 |
index 0000000..d823fc7 |
| 6265 |
--- /dev/null |
| 6266 |
+++ b/src/compiler/translator/TranslatorMetalDirect/EnvironmentVariable.h |
| 6267 |
@@ -0,0 +1,45 @@ |
| 6268 |
+// |
| 6269 |
+// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 6270 |
+// Use of this source code is governed by a BSD-style license that can be |
| 6271 |
+// found in the LICENSE file. |
| 6272 |
+// |
| 6273 |
+ |
| 6274 |
+#ifndef COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_ENVIRONMENTVARIABLE_H_ |
| 6275 |
+#define COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_ENVIRONMENTVARIABLE_H_ |
| 6276 |
+ |
| 6277 |
+#include <cstdlib> |
| 6278 |
+#include <string> |
| 6279 |
+ |
| 6280 |
+#include "common/debug.h" |
| 6281 |
+ |
| 6282 |
+namespace sh |
| 6283 |
+{ |
| 6284 |
+ |
| 6285 |
+inline bool readBoolEnvVar(const char *var) |
| 6286 |
+{ |
| 6287 |
+ const char *str = std::getenv(var); |
| 6288 |
+ if (str == nullptr) |
| 6289 |
+ { |
| 6290 |
+ return false; |
| 6291 |
+ } |
| 6292 |
+ if (strcmp(str, "0") == 0) |
| 6293 |
+ { |
| 6294 |
+ return false; |
| 6295 |
+ } |
| 6296 |
+ ASSERT(strcmp(str, "1") == 0); |
| 6297 |
+ return true; |
| 6298 |
+} |
| 6299 |
+ |
| 6300 |
+inline std::string readStringEnvVar(const char *var) |
| 6301 |
+{ |
| 6302 |
+ const char *str = std::getenv(var); |
| 6303 |
+ if (str == nullptr) |
| 6304 |
+ { |
| 6305 |
+ return ""; |
| 6306 |
+ } |
| 6307 |
+ return str; |
| 6308 |
+} |
| 6309 |
+ |
| 6310 |
+} // namespace sh |
| 6311 |
+ |
| 6312 |
+#endif // COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_ENVIRONMENTVARIABLE_H_ |
| 6313 |
diff --git a/src/compiler/translator/TranslatorMetalDirect/HoistConstants.cpp b/src/compiler/translator/TranslatorMetalDirect/HoistConstants.cpp |
| 6314 |
new file mode 100644 |
| 6315 |
index 0000000..ce9c03e |
| 6316 |
--- /dev/null |
| 6317 |
+++ b/src/compiler/translator/TranslatorMetalDirect/HoistConstants.cpp |
| 6318 |
@@ -0,0 +1,96 @@ |
| 6319 |
+// |
| 6320 |
+// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 6321 |
+// Use of this source code is governed by a BSD-style license that can be |
| 6322 |
+// found in the LICENSE file. |
| 6323 |
+// |
| 6324 |
+ |
| 6325 |
+#include "compiler/translator/TranslatorMetalDirect/HoistConstants.h" |
| 6326 |
+#include "compiler/translator/TranslatorMetalDirect/AstHelpers.h" |
| 6327 |
+#include "compiler/translator/TranslatorMetalDirect/Layout.h" |
| 6328 |
+#include "compiler/translator/tree_util/FindFunction.h" |
| 6329 |
+#include "compiler/translator/tree_util/IntermRebuild.h" |
| 6330 |
+#include "compiler/translator/tree_util/ReplaceVariable.h" |
| 6331 |
+ |
| 6332 |
+using namespace sh; |
| 6333 |
+ |
| 6334 |
+//////////////////////////////////////////////////////////////////////////////// |
| 6335 |
+ |
| 6336 |
+namespace |
| 6337 |
+{ |
| 6338 |
+ |
| 6339 |
+class Rewriter : private TIntermRebuild |
| 6340 |
+{ |
| 6341 |
+ private: |
| 6342 |
+ const size_t mMinRequiredSize; |
| 6343 |
+ TIntermSequence mHoistedDeclNodes; |
| 6344 |
+ |
| 6345 |
+ public: |
| 6346 |
+ Rewriter(TCompiler &compiler, size_t minRequiredSize) |
| 6347 |
+ : TIntermRebuild(compiler, true, false), mMinRequiredSize(minRequiredSize) |
| 6348 |
+ {} |
| 6349 |
+ |
| 6350 |
+ PreResult visitDeclarationPre(TIntermDeclaration &declNode) override |
| 6351 |
+ { |
| 6352 |
+ if (getParentFunction()) |
| 6353 |
+ { |
| 6354 |
+ Declaration decl = ViewDeclaration(declNode); |
| 6355 |
+ const TType &type = decl.symbol.getType(); |
| 6356 |
+ if (type.getQualifier() == TQualifier::EvqConst) |
| 6357 |
+ { |
| 6358 |
+ if (decl.initExpr && decl.initExpr->hasConstantValue()) |
| 6359 |
+ { |
| 6360 |
+ const size_t size = MetalLayoutOf(type).sizeOf; |
| 6361 |
+ if (size >= mMinRequiredSize) |
| 6362 |
+ { |
| 6363 |
+ mHoistedDeclNodes.push_back(&declNode); |
| 6364 |
+ return nullptr; |
| 6365 |
+ } |
| 6366 |
+ } |
| 6367 |
+ } |
| 6368 |
+ } |
| 6369 |
+ return {declNode, VisitBits::Neither}; |
| 6370 |
+ } |
| 6371 |
+ |
| 6372 |
+ bool rewrite(TIntermBlock &root, IdGen &idGen) |
| 6373 |
+ { |
| 6374 |
+ if (!rebuildRoot(root)) |
| 6375 |
+ { |
| 6376 |
+ return false; |
| 6377 |
+ } |
| 6378 |
+ |
| 6379 |
+ if (mHoistedDeclNodes.empty()) |
| 6380 |
+ { |
| 6381 |
+ return true; |
| 6382 |
+ } |
| 6383 |
+ |
| 6384 |
+ root.insertChildNodes(FindFirstFunctionDefinitionIndex(&root), mHoistedDeclNodes); |
| 6385 |
+ |
| 6386 |
+ for (TIntermNode *opaqueDeclNode : mHoistedDeclNodes) |
| 6387 |
+ { |
| 6388 |
+ TIntermDeclaration *declNode = opaqueDeclNode->getAsDeclarationNode(); |
| 6389 |
+ ASSERT(declNode); |
| 6390 |
+ const TVariable &oldVar = ViewDeclaration(*declNode).symbol.variable(); |
| 6391 |
+ const Name newName = idGen.createNewName(oldVar.name()); |
| 6392 |
+ auto *newVar = new TVariable(&mSymbolTable, newName.rawName(), &oldVar.getType(), |
| 6393 |
+ newName.symbolType()); |
| 6394 |
+ if (!ReplaceVariable(&mCompiler, &root, &oldVar, newVar)) |
| 6395 |
+ { |
| 6396 |
+ return false; |
| 6397 |
+ } |
| 6398 |
+ } |
| 6399 |
+ |
| 6400 |
+ return true; |
| 6401 |
+ } |
| 6402 |
+}; |
| 6403 |
+ |
| 6404 |
+} // anonymous namespace |
| 6405 |
+ |
| 6406 |
+//////////////////////////////////////////////////////////////////////////////// |
| 6407 |
+ |
| 6408 |
+bool sh::HoistConstants(TCompiler &compiler, |
| 6409 |
+ TIntermBlock &root, |
| 6410 |
+ IdGen &idGen, |
| 6411 |
+ size_t minRequiredSize) |
| 6412 |
+{ |
| 6413 |
+ return Rewriter(compiler, minRequiredSize).rewrite(root, idGen); |
| 6414 |
+} |
| 6415 |
diff --git a/src/compiler/translator/TranslatorMetalDirect/HoistConstants.h b/src/compiler/translator/TranslatorMetalDirect/HoistConstants.h |
| 6416 |
new file mode 100644 |
| 6417 |
index 0000000..0306a5e |
| 6418 |
--- /dev/null |
| 6419 |
+++ b/src/compiler/translator/TranslatorMetalDirect/HoistConstants.h |
| 6420 |
@@ -0,0 +1,26 @@ |
| 6421 |
+// |
| 6422 |
+// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 6423 |
+// Use of this source code is governed by a BSD-style license that can be |
| 6424 |
+// found in the LICENSE file. |
| 6425 |
+// |
| 6426 |
+ |
| 6427 |
+#ifndef COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_HOISTCONSTANTS_H_ |
| 6428 |
+#define COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_HOISTCONSTANTS_H_ |
| 6429 |
+ |
| 6430 |
+#include "common/angleutils.h" |
| 6431 |
+#include "compiler/translator/Compiler.h" |
| 6432 |
+#include "compiler/translator/TranslatorMetalDirect/IdGen.h" |
| 6433 |
+ |
| 6434 |
+namespace sh |
| 6435 |
+{ |
| 6436 |
+ |
| 6437 |
+// Hoists function-local constants to the global scope if their Metal sizeof meets |
| 6438 |
+// `minRequiredSize`. |
| 6439 |
+ANGLE_NO_DISCARD bool HoistConstants(TCompiler &compiler, |
| 6440 |
+ TIntermBlock &root, |
| 6441 |
+ IdGen &idGen, |
| 6442 |
+ size_t minRequiredSize); |
| 6443 |
+ |
| 6444 |
+} // namespace sh |
| 6445 |
+ |
| 6446 |
+#endif // COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_HOISTCONSTANTS_H_ |
| 6447 |
diff --git a/src/compiler/translator/TranslatorMetalDirect/IdGen.cpp b/src/compiler/translator/TranslatorMetalDirect/IdGen.cpp |
| 6448 |
new file mode 100644 |
| 6449 |
index 0000000..84aed6b |
| 6450 |
--- /dev/null |
| 6451 |
+++ b/src/compiler/translator/TranslatorMetalDirect/IdGen.cpp |
| 6452 |
@@ -0,0 +1,97 @@ |
| 6453 |
+// |
| 6454 |
+// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 6455 |
+// Use of this source code is governed by a BSD-style license that can be |
| 6456 |
+// found in the LICENSE file. |
| 6457 |
+// |
| 6458 |
+ |
| 6459 |
+#include <cctype> |
| 6460 |
+#include <cstring> |
| 6461 |
+#include <limits> |
| 6462 |
+#include <unordered_map> |
| 6463 |
+#include <unordered_set> |
| 6464 |
+ |
| 6465 |
+#include "compiler/translator/TranslatorMetalDirect/RewriteKeywords.h" |
| 6466 |
+ |
| 6467 |
+using namespace sh; |
| 6468 |
+ |
| 6469 |
+//////////////////////////////////////////////////////////////////////////////// |
| 6470 |
+ |
| 6471 |
+IdGen::IdGen() {} |
| 6472 |
+ |
| 6473 |
+template <typename String, typename StringToImmutable> |
| 6474 |
+Name IdGen::createNewName(size_t count, |
| 6475 |
+ const String *baseNames, |
| 6476 |
+ const StringToImmutable &toImmutable) |
| 6477 |
+{ |
| 6478 |
+ const unsigned id = mNext++; |
| 6479 |
+ char idBuffer[std::numeric_limits<unsigned>::digits10 + 1]; |
| 6480 |
+ sprintf(idBuffer, "%u", id); |
| 6481 |
+ |
| 6482 |
+ mNewNameBuffer.clear(); |
| 6483 |
+ mNewNameBuffer += '_'; |
| 6484 |
+ mNewNameBuffer += idBuffer; |
| 6485 |
+ |
| 6486 |
+ // Note: |
| 6487 |
+ // Double underscores are only allowed in C++ (and thus Metal) vendor identifiers, so here we |
| 6488 |
+ // take care not to introduce any. |
| 6489 |
+ |
| 6490 |
+ for (size_t i = 0; i < count; ++i) |
| 6491 |
+ { |
| 6492 |
+ const ImmutableString baseName = toImmutable(baseNames[i]); |
| 6493 |
+ if (!baseName.empty()) |
| 6494 |
+ { |
| 6495 |
+ const char *base = baseName.data(); |
| 6496 |
+ if (baseName.beginsWith(kAngleInternalPrefix)) |
| 6497 |
+ { |
| 6498 |
+ base += sizeof(kAngleInternalPrefix) - 1; |
| 6499 |
+ } |
| 6500 |
+ if (*base == '_') |
| 6501 |
+ { |
| 6502 |
+ ++base; |
| 6503 |
+ } |
| 6504 |
+ ASSERT(*base != '_'); |
| 6505 |
+ |
| 6506 |
+ if (mNewNameBuffer.back() != '_') |
| 6507 |
+ { |
| 6508 |
+ mNewNameBuffer += '_'; |
| 6509 |
+ } |
| 6510 |
+ |
| 6511 |
+ mNewNameBuffer += base; |
| 6512 |
+ } |
| 6513 |
+ } |
| 6514 |
+ |
| 6515 |
+ return Name(ImmutableString(mNewNameBuffer), SymbolType::AngleInternal); |
| 6516 |
+} |
| 6517 |
+ |
| 6518 |
+Name IdGen::createNewName(const ImmutableString &baseName) |
| 6519 |
+{ |
| 6520 |
+ return createNewName({baseName}); |
| 6521 |
+} |
| 6522 |
+ |
| 6523 |
+Name IdGen::createNewName(const Name &baseName) |
| 6524 |
+{ |
| 6525 |
+ return createNewName(baseName.rawName()); |
| 6526 |
+} |
| 6527 |
+ |
| 6528 |
+Name IdGen::createNewName(const char *baseName) |
| 6529 |
+{ |
| 6530 |
+ return createNewName(ImmutableString(baseName)); |
| 6531 |
+} |
| 6532 |
+ |
| 6533 |
+Name IdGen::createNewName(std::initializer_list<ImmutableString> baseNames) |
| 6534 |
+{ |
| 6535 |
+ return createNewName(baseNames.size(), baseNames.begin(), |
| 6536 |
+ [](const ImmutableString &s) { return s; }); |
| 6537 |
+} |
| 6538 |
+ |
| 6539 |
+Name IdGen::createNewName(std::initializer_list<Name> baseNames) |
| 6540 |
+{ |
| 6541 |
+ return createNewName(baseNames.size(), baseNames.begin(), |
| 6542 |
+ [](const Name &s) { return s.rawName(); }); |
| 6543 |
+} |
| 6544 |
+ |
| 6545 |
+Name IdGen::createNewName(std::initializer_list<const char *> baseNames) |
| 6546 |
+{ |
| 6547 |
+ return createNewName(baseNames.size(), baseNames.begin(), |
| 6548 |
+ [](const char *s) { return ImmutableString(s); }); |
| 6549 |
+} |
| 6550 |
diff --git a/src/compiler/translator/TranslatorMetalDirect/IdGen.h b/src/compiler/translator/TranslatorMetalDirect/IdGen.h |
| 6551 |
new file mode 100644 |
| 6552 |
index 0000000..582089f |
| 6553 |
--- /dev/null |
| 6554 |
+++ b/src/compiler/translator/TranslatorMetalDirect/IdGen.h |
| 6555 |
@@ -0,0 +1,41 @@ |
| 6556 |
+// |
| 6557 |
+// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 6558 |
+// Use of this source code is governed by a BSD-style license that can be |
| 6559 |
+// found in the LICENSE file. |
| 6560 |
+// |
| 6561 |
+ |
| 6562 |
+#ifndef COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_IDGEN_H_ |
| 6563 |
+#define COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_IDGEN_H_ |
| 6564 |
+ |
| 6565 |
+#include "common/angleutils.h" |
| 6566 |
+#include "compiler/translator/TranslatorMetalDirect/Name.h" |
| 6567 |
+ |
| 6568 |
+namespace sh |
| 6569 |
+{ |
| 6570 |
+ |
| 6571 |
+// For creating new fresh names. |
| 6572 |
+// All names created are marked as SymbolType::AngleInternal. |
| 6573 |
+class IdGen : angle::NonCopyable |
| 6574 |
+{ |
| 6575 |
+ public: |
| 6576 |
+ IdGen(); |
| 6577 |
+ |
| 6578 |
+ Name createNewName(const ImmutableString &baseName); |
| 6579 |
+ Name createNewName(const Name &baseName); |
| 6580 |
+ Name createNewName(const char *baseName); |
| 6581 |
+ Name createNewName(std::initializer_list<ImmutableString> baseNames); |
| 6582 |
+ Name createNewName(std::initializer_list<Name> baseNames); |
| 6583 |
+ Name createNewName(std::initializer_list<const char *> baseNames); |
| 6584 |
+ |
| 6585 |
+ private: |
| 6586 |
+ template <typename String, typename StringToImmutable> |
| 6587 |
+ Name createNewName(size_t count, const String *baseNames, const StringToImmutable &toImmutable); |
| 6588 |
+ |
| 6589 |
+ private: |
| 6590 |
+ unsigned mNext = 0; // `unsigned` because of "%u" use in sprintf |
| 6591 |
+ std::string mNewNameBuffer; // reusable buffer to avoid tons of reallocations |
| 6592 |
+}; |
| 6593 |
+ |
| 6594 |
+} // namespace sh |
| 6595 |
+ |
| 6596 |
+#endif // COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_IDGEN_H_ |
| 6597 |
diff --git a/src/compiler/translator/TranslatorMetalDirect/Layout.cpp b/src/compiler/translator/TranslatorMetalDirect/Layout.cpp |
| 6598 |
new file mode 100644 |
| 6599 |
index 0000000..5346f6f |
| 6600 |
--- /dev/null |
| 6601 |
+++ b/src/compiler/translator/TranslatorMetalDirect/Layout.cpp |
| 6602 |
@@ -0,0 +1,401 @@ |
| 6603 |
+// |
| 6604 |
+// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 6605 |
+// Use of this source code is governed by a BSD-style license that can be |
| 6606 |
+// found in the LICENSE file. |
| 6607 |
+// |
| 6608 |
+ |
| 6609 |
+#include <algorithm> |
| 6610 |
+#include <cctype> |
| 6611 |
+#include <cstring> |
| 6612 |
+#include <limits> |
| 6613 |
+#include <unordered_map> |
| 6614 |
+#include <unordered_set> |
| 6615 |
+ |
| 6616 |
+#include "compiler/translator/Symbol.h" |
| 6617 |
+#include "compiler/translator/TranslatorMetalDirect/Debug.h" |
| 6618 |
+#include "compiler/translator/TranslatorMetalDirect/Layout.h" |
| 6619 |
+ |
| 6620 |
+using namespace sh; |
| 6621 |
+ |
| 6622 |
+//////////////////////////////////////////////////////////////////////////////// |
| 6623 |
+ |
| 6624 |
+enum class Language |
| 6625 |
+{ |
| 6626 |
+ Metal, |
| 6627 |
+ GLSL, |
| 6628 |
+}; |
| 6629 |
+ |
| 6630 |
+static size_t RoundUpToMultipleOf(size_t x, size_t multiple) |
| 6631 |
+{ |
| 6632 |
+ const size_t rem = x % multiple; |
| 6633 |
+ return rem == 0 ? x : x + (multiple - rem); |
| 6634 |
+} |
| 6635 |
+ |
| 6636 |
+void Layout::requireAlignment(size_t align, bool pad) |
| 6637 |
+{ |
| 6638 |
+ alignOf = std::max(alignOf, align); |
| 6639 |
+ if (pad) |
| 6640 |
+ { |
| 6641 |
+ sizeOf = RoundUpToMultipleOf(sizeOf, align); |
| 6642 |
+ } |
| 6643 |
+} |
| 6644 |
+ |
| 6645 |
+bool Layout::operator==(const Layout &other) const |
| 6646 |
+{ |
| 6647 |
+ return sizeOf == other.sizeOf && alignOf == other.alignOf; |
| 6648 |
+} |
| 6649 |
+ |
| 6650 |
+void Layout::operator+=(const Layout &other) |
| 6651 |
+{ |
| 6652 |
+ requireAlignment(other.alignOf, true); |
| 6653 |
+ sizeOf += other.sizeOf; |
| 6654 |
+} |
| 6655 |
+ |
| 6656 |
+void Layout::operator*=(size_t scale) |
| 6657 |
+{ |
| 6658 |
+ sizeOf *= scale; |
| 6659 |
+} |
| 6660 |
+ |
| 6661 |
+Layout Layout::operator+(const Layout &other) const |
| 6662 |
+{ |
| 6663 |
+ auto self = *this; |
| 6664 |
+ self += other; |
| 6665 |
+ return self; |
| 6666 |
+} |
| 6667 |
+ |
| 6668 |
+Layout Layout::operator*(size_t scale) const |
| 6669 |
+{ |
| 6670 |
+ auto self = *this; |
| 6671 |
+ self *= scale; |
| 6672 |
+ return self; |
| 6673 |
+} |
| 6674 |
+ |
| 6675 |
+static Layout ScalarLayoutOf(const TType &type, Language language) |
| 6676 |
+{ |
| 6677 |
+ const TBasicType basicType = type.getBasicType(); |
| 6678 |
+ switch (basicType) |
| 6679 |
+ { |
| 6680 |
+ case TBasicType::EbtBool: |
| 6681 |
+ return {1, 1}; |
| 6682 |
+ case TBasicType::EbtInt: |
| 6683 |
+ case TBasicType::EbtUInt: |
| 6684 |
+ case TBasicType::EbtFloat: |
| 6685 |
+ return {4, 4}; |
| 6686 |
+ default: |
| 6687 |
+ if (IsSampler(basicType)) |
| 6688 |
+ { |
| 6689 |
+ switch (language) |
| 6690 |
+ { |
| 6691 |
+ case Language::Metal: |
| 6692 |
+ return {8, 8}; |
| 6693 |
+ case Language::GLSL: |
| 6694 |
+ return {4, 4}; |
| 6695 |
+ } |
| 6696 |
+ } |
| 6697 |
+ TODO(); |
| 6698 |
+ return Layout::Invalid(); |
| 6699 |
+ } |
| 6700 |
+} |
| 6701 |
+ |
| 6702 |
+static const size_t innerScalesPacked[] = {0, 1, 2, 3, 4}; |
| 6703 |
+static const size_t innerScalesUnpacked[] = {0, 1, 2, 4, 4}; |
| 6704 |
+ |
| 6705 |
+Layout sh::MetalLayoutOf(const TType &type, MetalLayoutOfConfig config) |
| 6706 |
+{ |
| 6707 |
+ ASSERT(type.getNominalSize() <= 4); |
| 6708 |
+ ASSERT(type.getSecondarySize() <= 4); |
| 6709 |
+ |
| 6710 |
+ const TLayoutBlockStorage storage = type.getLayoutQualifier().blockStorage; |
| 6711 |
+ |
| 6712 |
+ const bool isPacked = !config.disablePacking && (storage == TLayoutBlockStorage::EbsPacked || |
| 6713 |
+ storage == TLayoutBlockStorage::EbsShared); |
| 6714 |
+ |
| 6715 |
+ if (type.isArray() && !config.maskArray) |
| 6716 |
+ { |
| 6717 |
+ config.maskArray = true; |
| 6718 |
+ const Layout layout = MetalLayoutOf(type, config); |
| 6719 |
+ config.maskArray = false; |
| 6720 |
+ const size_t vol = type.getArraySizeProduct(); |
| 6721 |
+ return layout * vol; |
| 6722 |
+ } |
| 6723 |
+ |
| 6724 |
+ if (const TStructure *structure = type.getStruct()) |
| 6725 |
+ { |
| 6726 |
+ ASSERT(type.getNominalSize() == 1); |
| 6727 |
+ ASSERT(type.getSecondarySize() == 1); |
| 6728 |
+ auto config2 = config; |
| 6729 |
+ config2.maskArray = false; |
| 6730 |
+ auto layout = Layout::Identity(); |
| 6731 |
+ const TFieldList &fields = structure->fields(); |
| 6732 |
+ for (const TField *field : fields) |
| 6733 |
+ { |
| 6734 |
+ layout += MetalLayoutOf(*field->type(), config2); |
| 6735 |
+ } |
| 6736 |
+ if (config.assumeStructsAreTailPadded) |
| 6737 |
+ { |
| 6738 |
+ size_t pad = layout.sizeOf % 16; |
| 6739 |
+ layout.sizeOf += pad; |
| 6740 |
+ } |
| 6741 |
+ layout.sizeOf = RoundUpToMultipleOf(layout.sizeOf, layout.alignOf); |
| 6742 |
+ return layout; |
| 6743 |
+ } |
| 6744 |
+ |
| 6745 |
+ if (config.treatSamplersAsTextureEnv && IsSampler(type.getBasicType())) |
| 6746 |
+ { |
| 6747 |
+ return {16, 8}; // pointer{8,8} and metal::sampler{8,8} |
| 6748 |
+ } |
| 6749 |
+ |
| 6750 |
+ const Layout scalarLayout = ScalarLayoutOf(type, Language::Metal); |
| 6751 |
+ |
| 6752 |
+ if (type.isRank0()) |
| 6753 |
+ { |
| 6754 |
+ return scalarLayout; |
| 6755 |
+ } |
| 6756 |
+ else if (type.isVector()) |
| 6757 |
+ { |
| 6758 |
+ if (isPacked) |
| 6759 |
+ { |
| 6760 |
+ const size_t innerScale = innerScalesPacked[type.getNominalSize()]; |
| 6761 |
+ auto layout = Layout{scalarLayout.sizeOf * innerScale, scalarLayout.alignOf}; |
| 6762 |
+ return layout; |
| 6763 |
+ } |
| 6764 |
+ else |
| 6765 |
+ { |
| 6766 |
+ const size_t innerScale = innerScalesUnpacked[type.getNominalSize()]; |
| 6767 |
+ auto layout = Layout::Both(scalarLayout.sizeOf * innerScale); |
| 6768 |
+ return layout; |
| 6769 |
+ } |
| 6770 |
+ } |
| 6771 |
+ else |
| 6772 |
+ { |
| 6773 |
+ ASSERT(type.isMatrix()); |
| 6774 |
+ ASSERT(type.getBasicType() == TBasicType::EbtFloat); |
| 6775 |
+ // typeCxR <=> typeR[C] |
| 6776 |
+ const size_t innerScale = innerScalesUnpacked[type.getRows()]; |
| 6777 |
+ const size_t outerScale = static_cast<size_t>(type.getCols()); |
| 6778 |
+ const size_t n = scalarLayout.sizeOf * innerScale; |
| 6779 |
+ return {n * outerScale, n}; |
| 6780 |
+ } |
| 6781 |
+} |
| 6782 |
+ |
| 6783 |
+TLayoutBlockStorage sh::Overlay(TLayoutBlockStorage oldStorage, const TType &type) |
| 6784 |
+{ |
| 6785 |
+ const TLayoutBlockStorage newStorage = type.getLayoutQualifier().blockStorage; |
| 6786 |
+ switch (newStorage) |
| 6787 |
+ { |
| 6788 |
+ case TLayoutBlockStorage::EbsUnspecified: |
| 6789 |
+ return oldStorage == TLayoutBlockStorage::EbsUnspecified ? kDefaultLayoutBlockStorage |
| 6790 |
+ : oldStorage; |
| 6791 |
+ default: |
| 6792 |
+ return newStorage; |
| 6793 |
+ } |
| 6794 |
+} |
| 6795 |
+ |
| 6796 |
+TLayoutMatrixPacking sh::Overlay(TLayoutMatrixPacking oldPacking, const TType &type) |
| 6797 |
+{ |
| 6798 |
+ const TLayoutMatrixPacking newPacking = type.getLayoutQualifier().matrixPacking; |
| 6799 |
+ switch (newPacking) |
| 6800 |
+ { |
| 6801 |
+ case TLayoutMatrixPacking::EmpUnspecified: |
| 6802 |
+ return oldPacking == TLayoutMatrixPacking::EmpUnspecified ? kDefaultLayoutMatrixPacking |
| 6803 |
+ : oldPacking; |
| 6804 |
+ default: |
| 6805 |
+ return newPacking; |
| 6806 |
+ } |
| 6807 |
+} |
| 6808 |
+ |
| 6809 |
+bool sh::CanBePacked(TLayoutBlockStorage storage) |
| 6810 |
+{ |
| 6811 |
+ switch (storage) |
| 6812 |
+ { |
| 6813 |
+ case TLayoutBlockStorage::EbsPacked: |
| 6814 |
+ case TLayoutBlockStorage::EbsShared: |
| 6815 |
+ return true; |
| 6816 |
+ case TLayoutBlockStorage::EbsStd140: |
| 6817 |
+ case TLayoutBlockStorage::EbsStd430: |
| 6818 |
+ return false; |
| 6819 |
+ case TLayoutBlockStorage::EbsUnspecified: |
| 6820 |
+ LOGIC_ERROR(); |
| 6821 |
+ return false; |
| 6822 |
+ } |
| 6823 |
+} |
| 6824 |
+ |
| 6825 |
+bool sh::CanBePacked(TLayoutQualifier layoutQualifier) |
| 6826 |
+{ |
| 6827 |
+ return CanBePacked(layoutQualifier.blockStorage); |
| 6828 |
+} |
| 6829 |
+ |
| 6830 |
+bool sh::CanBePacked(const TType &type) |
| 6831 |
+{ |
| 6832 |
+ if (!type.isVector()) |
| 6833 |
+ { |
| 6834 |
+ return false; |
| 6835 |
+ } |
| 6836 |
+ return CanBePacked(type.getLayoutQualifier()); |
| 6837 |
+} |
| 6838 |
+ |
| 6839 |
+void sh::SetBlockStorage(TType &type, TLayoutBlockStorage storage) |
| 6840 |
+{ |
| 6841 |
+ auto qual = type.getLayoutQualifier(); |
| 6842 |
+ qual.blockStorage = storage; |
| 6843 |
+ type.setLayoutQualifier(qual); |
| 6844 |
+} |
| 6845 |
+ |
| 6846 |
+static Layout CommonGlslStructLayoutOf(TField const *const *begin, |
| 6847 |
+ TField const *const *end, |
| 6848 |
+ const TLayoutBlockStorage storage, |
| 6849 |
+ const TLayoutMatrixPacking matrixPacking, |
| 6850 |
+ const bool maskArray, |
| 6851 |
+ const size_t baseAlignment) |
| 6852 |
+{ |
| 6853 |
+ const bool isPacked = |
| 6854 |
+ storage == TLayoutBlockStorage::EbsPacked || storage == TLayoutBlockStorage::EbsShared; |
| 6855 |
+ |
| 6856 |
+ auto layout = Layout::Identity(); |
| 6857 |
+ for (auto iter = begin; iter != end; ++iter) |
| 6858 |
+ { |
| 6859 |
+ layout += GlslLayoutOf(*(*iter)->type(), storage, matrixPacking, false); |
| 6860 |
+ } |
| 6861 |
+ if (!isPacked) // XXX: Correct? |
| 6862 |
+ { |
| 6863 |
+ layout.sizeOf = RoundUpToMultipleOf(layout.sizeOf, layout.alignOf); |
| 6864 |
+ } |
| 6865 |
+ layout.requireAlignment(baseAlignment, true); |
| 6866 |
+ return layout; |
| 6867 |
+} |
| 6868 |
+ |
| 6869 |
+static Layout CommonGlslLayoutOf(const TType &type, |
| 6870 |
+ const TLayoutBlockStorage storage, |
| 6871 |
+ const TLayoutMatrixPacking matrixPacking, |
| 6872 |
+ const bool maskArray, |
| 6873 |
+ const size_t baseAlignment) |
| 6874 |
+{ |
| 6875 |
+ ASSERT(storage != TLayoutBlockStorage::EbsUnspecified); |
| 6876 |
+ |
| 6877 |
+ const bool isPacked = |
| 6878 |
+ storage == TLayoutBlockStorage::EbsPacked || storage == TLayoutBlockStorage::EbsShared; |
| 6879 |
+ |
| 6880 |
+ if (type.isArray() && !type.isMatrix() && !maskArray) |
| 6881 |
+ { |
| 6882 |
+ auto layout = GlslLayoutOf(type, storage, matrixPacking, true); |
| 6883 |
+ layout *= type.getArraySizeProduct(); |
| 6884 |
+ layout.requireAlignment(baseAlignment, true); |
| 6885 |
+ return layout; |
| 6886 |
+ } |
| 6887 |
+ |
| 6888 |
+ if (const TStructure *structure = type.getStruct()) |
| 6889 |
+ { |
| 6890 |
+ ASSERT(type.getNominalSize() == 1); |
| 6891 |
+ ASSERT(type.getSecondarySize() == 1); |
| 6892 |
+ const TFieldList &fields = structure->fields(); |
| 6893 |
+ return CommonGlslStructLayoutOf(fields.data(), fields.data() + fields.size(), storage, |
| 6894 |
+ matrixPacking, maskArray, baseAlignment); |
| 6895 |
+ } |
| 6896 |
+ |
| 6897 |
+ const auto scalarLayout = ScalarLayoutOf(type, Language::GLSL); |
| 6898 |
+ |
| 6899 |
+ if (type.isRank0()) |
| 6900 |
+ { |
| 6901 |
+ return scalarLayout; |
| 6902 |
+ } |
| 6903 |
+ else if (type.isVector()) |
| 6904 |
+ { |
| 6905 |
+ if (isPacked) |
| 6906 |
+ { |
| 6907 |
+ const size_t sizeScale = innerScalesPacked[type.getNominalSize()]; |
| 6908 |
+ const size_t alignScale = innerScalesUnpacked[type.getNominalSize()]; |
| 6909 |
+ auto layout = |
| 6910 |
+ Layout{scalarLayout.sizeOf * sizeScale, scalarLayout.alignOf * alignScale}; |
| 6911 |
+ return layout; |
| 6912 |
+ } |
| 6913 |
+ else |
| 6914 |
+ { |
| 6915 |
+ const size_t innerScale = innerScalesUnpacked[type.getNominalSize()]; |
| 6916 |
+ auto layout = Layout::Both(scalarLayout.sizeOf * innerScale); |
| 6917 |
+ return layout; |
| 6918 |
+ } |
| 6919 |
+ } |
| 6920 |
+ else |
| 6921 |
+ { |
| 6922 |
+ ASSERT(type.isMatrix()); |
| 6923 |
+ |
| 6924 |
+ size_t innerDim; |
| 6925 |
+ size_t outerDim; |
| 6926 |
+ |
| 6927 |
+ switch (matrixPacking) |
| 6928 |
+ { |
| 6929 |
+ case TLayoutMatrixPacking::EmpColumnMajor: |
| 6930 |
+ innerDim = static_cast<size_t>(type.getRows()); |
| 6931 |
+ outerDim = static_cast<size_t>(type.getCols()); |
| 6932 |
+ break; |
| 6933 |
+ case TLayoutMatrixPacking::EmpRowMajor: |
| 6934 |
+ innerDim = static_cast<size_t>(type.getCols()); |
| 6935 |
+ outerDim = static_cast<size_t>(type.getRows()); |
| 6936 |
+ break; |
| 6937 |
+ case TLayoutMatrixPacking::EmpUnspecified: |
| 6938 |
+ LOGIC_ERROR(); |
| 6939 |
+ innerDim = 0; |
| 6940 |
+ outerDim = 0; |
| 6941 |
+ } |
| 6942 |
+ |
| 6943 |
+ outerDim *= type.getArraySizeProduct(); |
| 6944 |
+ |
| 6945 |
+ const size_t innerScale = innerScalesUnpacked[innerDim]; |
| 6946 |
+ const size_t n = innerScale * scalarLayout.sizeOf; |
| 6947 |
+ Layout layout = {outerDim * n, n}; |
| 6948 |
+ layout.requireAlignment(baseAlignment, true); |
| 6949 |
+ return layout; |
| 6950 |
+ } |
| 6951 |
+} |
| 6952 |
+ |
| 6953 |
+Layout sh::GlslLayoutOf(const TType &type, |
| 6954 |
+ TLayoutBlockStorage storage, |
| 6955 |
+ TLayoutMatrixPacking matrixPacking, |
| 6956 |
+ bool maskArray) |
| 6957 |
+{ |
| 6958 |
+ ASSERT(type.getNominalSize() <= 4); |
| 6959 |
+ ASSERT(type.getSecondarySize() <= 4); |
| 6960 |
+ |
| 6961 |
+ storage = Overlay(storage, type); |
| 6962 |
+ matrixPacking = Overlay(matrixPacking, type); |
| 6963 |
+ |
| 6964 |
+ switch (storage) |
| 6965 |
+ { |
| 6966 |
+ case TLayoutBlockStorage::EbsPacked: |
| 6967 |
+ return CommonGlslLayoutOf(type, storage, matrixPacking, maskArray, 1); |
| 6968 |
+ case TLayoutBlockStorage::EbsShared: |
| 6969 |
+ return CommonGlslLayoutOf(type, storage, matrixPacking, maskArray, 16); |
| 6970 |
+ case TLayoutBlockStorage::EbsStd140: |
| 6971 |
+ return CommonGlslLayoutOf(type, storage, matrixPacking, maskArray, 16); |
| 6972 |
+ case TLayoutBlockStorage::EbsStd430: |
| 6973 |
+ return CommonGlslLayoutOf(type, storage, matrixPacking, maskArray, 1); |
| 6974 |
+ case TLayoutBlockStorage::EbsUnspecified: |
| 6975 |
+ LOGIC_ERROR(); |
| 6976 |
+ return Layout::Invalid(); |
| 6977 |
+ } |
| 6978 |
+} |
| 6979 |
+ |
| 6980 |
+ANGLE_NO_DISCARD Layout sh::GlslStructLayoutOf(TField const *const *begin, |
| 6981 |
+ TField const *const *end, |
| 6982 |
+ TLayoutBlockStorage storage, |
| 6983 |
+ TLayoutMatrixPacking matrixPacking, |
| 6984 |
+ bool maskArray) |
| 6985 |
+{ |
| 6986 |
+ ASSERT(storage != TLayoutBlockStorage::EbsUnspecified); |
| 6987 |
+ ASSERT(matrixPacking != TLayoutMatrixPacking::EmpUnspecified); |
| 6988 |
+ |
| 6989 |
+ switch (storage) |
| 6990 |
+ { |
| 6991 |
+ case TLayoutBlockStorage::EbsPacked: |
| 6992 |
+ return CommonGlslStructLayoutOf(begin, end, storage, matrixPacking, maskArray, 1); |
| 6993 |
+ case TLayoutBlockStorage::EbsShared: |
| 6994 |
+ return CommonGlslStructLayoutOf(begin, end, storage, matrixPacking, maskArray, 16); |
| 6995 |
+ case TLayoutBlockStorage::EbsStd140: |
| 6996 |
+ return CommonGlslStructLayoutOf(begin, end, storage, matrixPacking, maskArray, 16); |
| 6997 |
+ case TLayoutBlockStorage::EbsStd430: |
| 6998 |
+ return CommonGlslStructLayoutOf(begin, end, storage, matrixPacking, maskArray, 1); |
| 6999 |
+ case TLayoutBlockStorage::EbsUnspecified: |
| 7000 |
+ LOGIC_ERROR(); |
| 7001 |
+ return Layout::Invalid(); |
| 7002 |
+ } |
| 7003 |
+} |
| 7004 |
diff --git a/src/compiler/translator/TranslatorMetalDirect/Layout.h b/src/compiler/translator/TranslatorMetalDirect/Layout.h |
| 7005 |
new file mode 100644 |
| 7006 |
index 0000000..1413edf |
| 7007 |
--- /dev/null |
| 7008 |
+++ b/src/compiler/translator/TranslatorMetalDirect/Layout.h |
| 7009 |
@@ -0,0 +1,88 @@ |
| 7010 |
+// |
| 7011 |
+// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 7012 |
+// Use of this source code is governed by a BSD-style license that can be |
| 7013 |
+// found in the LICENSE file. |
| 7014 |
+// |
| 7015 |
+ |
| 7016 |
+#ifndef COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_LAYOUT_H_ |
| 7017 |
+#define COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_LAYOUT_H_ |
| 7018 |
+ |
| 7019 |
+#include "common/angleutils.h" |
| 7020 |
+#include "compiler/translator/Types.h" |
| 7021 |
+ |
| 7022 |
+namespace sh |
| 7023 |
+{ |
| 7024 |
+ |
| 7025 |
+constexpr const auto kDefaultLayoutBlockStorage = TLayoutBlockStorage::EbsShared; |
| 7026 |
+constexpr const auto kDefaultLayoutMatrixPacking = TLayoutMatrixPacking::EmpColumnMajor; |
| 7027 |
+ |
| 7028 |
+// Returns `oldStorage` if `type` has unspecified block storage. |
| 7029 |
+// Otherwise returns block storage of `type`. |
| 7030 |
+TLayoutBlockStorage Overlay(TLayoutBlockStorage oldStorage, const TType &type); |
| 7031 |
+ |
| 7032 |
+// Returns `oldPacking` if `type` has unspecified matrix packing. |
| 7033 |
+// Otherwise returns matrix packing of `type`. |
| 7034 |
+TLayoutMatrixPacking Overlay(TLayoutMatrixPacking oldPacking, const TType &type); |
| 7035 |
+ |
| 7036 |
+// Returns whether or not it is permissable for the block storage to use a packed representation. |
| 7037 |
+bool CanBePacked(TLayoutBlockStorage storage); |
| 7038 |
+ |
| 7039 |
+// Returns whether or not it is permissable for the layout qualifier to use a packed representation. |
| 7040 |
+bool CanBePacked(TLayoutQualifier layoutQualifier); |
| 7041 |
+ |
| 7042 |
+// Returns whether or not it is permissable for the type to use a packed representation. |
| 7043 |
+bool CanBePacked(const TType &type); |
| 7044 |
+ |
| 7045 |
+// Sets the block storage for a type. |
| 7046 |
+void SetBlockStorage(TType &type, TLayoutBlockStorage storage); |
| 7047 |
+ |
| 7048 |
+// Contains `sizeof` and `alignof` information. |
| 7049 |
+struct Layout |
| 7050 |
+{ |
| 7051 |
+ size_t sizeOf; |
| 7052 |
+ size_t alignOf; |
| 7053 |
+ |
| 7054 |
+ static Layout Identity() { return {0, 1}; } |
| 7055 |
+ static Layout Invalid() { return {0, 0}; } |
| 7056 |
+ static Layout Both(size_t n) { return {n, n}; } |
| 7057 |
+ |
| 7058 |
+ void requireAlignment(size_t align, bool pad); |
| 7059 |
+ |
| 7060 |
+ bool operator==(const Layout &other) const; |
| 7061 |
+ |
| 7062 |
+ void operator+=(const Layout &other); |
| 7063 |
+ void operator*=(size_t scale); |
| 7064 |
+ |
| 7065 |
+ Layout operator+(const Layout &other) const; |
| 7066 |
+ Layout operator*(size_t scale) const; |
| 7067 |
+}; |
| 7068 |
+ |
| 7069 |
+struct MetalLayoutOfConfig |
| 7070 |
+{ |
| 7071 |
+ bool disablePacking = false; |
| 7072 |
+ bool maskArray = false; |
| 7073 |
+ bool treatSamplersAsTextureEnv = false; |
| 7074 |
+ bool assumeStructsAreTailPadded = false; // Pad to multiple of 16 |
| 7075 |
+}; |
| 7076 |
+ |
| 7077 |
+// Returns the layout of a type if it were to be represented in a Metal program. |
| 7078 |
+// This deliberately ignores the TLayoutBlockStorage and TLayoutMatrixPacking of any type. |
| 7079 |
+ANGLE_NO_DISCARD Layout MetalLayoutOf(const TType &type, MetalLayoutOfConfig config = {}); |
| 7080 |
+ |
| 7081 |
+// Returns the layout of a type if it were to be represented in a GLSL program. |
| 7082 |
+ANGLE_NO_DISCARD Layout |
| 7083 |
+GlslLayoutOf(const TType &type, |
| 7084 |
+ TLayoutBlockStorage storage = TLayoutBlockStorage::EbsUnspecified, |
| 7085 |
+ TLayoutMatrixPacking matrixPacking = TLayoutMatrixPacking::EmpUnspecified, |
| 7086 |
+ bool maskArray = false); |
| 7087 |
+ |
| 7088 |
+// Returns the layout of a structure if it were to be represented in a GLSL program. |
| 7089 |
+ANGLE_NO_DISCARD Layout GlslStructLayoutOf(TField const *const *begin, |
| 7090 |
+ TField const *const *end, |
| 7091 |
+ TLayoutBlockStorage storage, |
| 7092 |
+ TLayoutMatrixPacking matrixPacking, |
| 7093 |
+ bool maskArray = false); |
| 7094 |
+ |
| 7095 |
+} // namespace sh |
| 7096 |
+ |
| 7097 |
+#endif // COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_LAYOUT_H_ |
| 7098 |
diff --git a/src/compiler/translator/TranslatorMetalDirect/MapFunctionsToDefinitions.cpp b/src/compiler/translator/TranslatorMetalDirect/MapFunctionsToDefinitions.cpp |
| 7099 |
new file mode 100644 |
| 7100 |
index 0000000..3e30dae |
| 7101 |
--- /dev/null |
| 7102 |
+++ b/src/compiler/translator/TranslatorMetalDirect/MapFunctionsToDefinitions.cpp |
| 7103 |
@@ -0,0 +1,34 @@ |
| 7104 |
+// |
| 7105 |
+// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 7106 |
+// Use of this source code is governed by a BSD-style license that can be |
| 7107 |
+// found in the LICENSE file. |
| 7108 |
+// |
| 7109 |
+ |
| 7110 |
+#include "compiler/translator/TranslatorMetalDirect/MapFunctionsToDefinitions.h" |
| 7111 |
+#include "compiler/translator/Symbol.h" |
| 7112 |
+ |
| 7113 |
+using namespace sh; |
| 7114 |
+ |
| 7115 |
+class Mapper : public TIntermTraverser |
| 7116 |
+{ |
| 7117 |
+ public: |
| 7118 |
+ FunctionToDefinition mFuncToDef; |
| 7119 |
+ |
| 7120 |
+ public: |
| 7121 |
+ Mapper() : TIntermTraverser(true, false, false) {} |
| 7122 |
+ |
| 7123 |
+ bool visitFunctionDefinition(Visit, TIntermFunctionDefinition *funcDefNode) override |
| 7124 |
+ { |
| 7125 |
+ const TFunction *func = funcDefNode->getFunction(); |
| 7126 |
+ ASSERT(func->getBuiltInOp() == TOperator::EOpNull); |
| 7127 |
+ mFuncToDef[func] = funcDefNode; |
| 7128 |
+ return false; |
| 7129 |
+ } |
| 7130 |
+}; |
| 7131 |
+ |
| 7132 |
+FunctionToDefinition sh::MapFunctionsToDefinitions(TIntermBlock &root) |
| 7133 |
+{ |
| 7134 |
+ Mapper mapper; |
| 7135 |
+ root.traverse(&mapper); |
| 7136 |
+ return std::move(mapper.mFuncToDef); |
| 7137 |
+} |
| 7138 |
diff --git a/src/compiler/translator/TranslatorMetalDirect/MapFunctionsToDefinitions.h b/src/compiler/translator/TranslatorMetalDirect/MapFunctionsToDefinitions.h |
| 7139 |
new file mode 100644 |
| 7140 |
index 0000000..4e56dde |
| 7141 |
--- /dev/null |
| 7142 |
+++ b/src/compiler/translator/TranslatorMetalDirect/MapFunctionsToDefinitions.h |
| 7143 |
@@ -0,0 +1,25 @@ |
| 7144 |
+// |
| 7145 |
+// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 7146 |
+// Use of this source code is governed by a BSD-style license that can be |
| 7147 |
+// found in the LICENSE file. |
| 7148 |
+// |
| 7149 |
+ |
| 7150 |
+#ifndef COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_MAPFUNCTIONSTODEFINITIONS_H_ |
| 7151 |
+#define COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_MAPFUNCTIONSTODEFINITIONS_H_ |
| 7152 |
+ |
| 7153 |
+#include <unordered_map> |
| 7154 |
+ |
| 7155 |
+#include "compiler/translator/tree_util/IntermTraverse.h" |
| 7156 |
+ |
| 7157 |
+namespace sh |
| 7158 |
+{ |
| 7159 |
+ |
| 7160 |
+// A map from functions to their corresponding definitions. |
| 7161 |
+using FunctionToDefinition = std::unordered_map<const TFunction *, TIntermFunctionDefinition *>; |
| 7162 |
+ |
| 7163 |
+// Maps functions to their corresponding definitions. |
| 7164 |
+ANGLE_NO_DISCARD FunctionToDefinition MapFunctionsToDefinitions(TIntermBlock &root); |
| 7165 |
+ |
| 7166 |
+} // namespace sh |
| 7167 |
+ |
| 7168 |
+#endif // COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_MAPFUNCTIONSTODEFINITIONS_H_ |
| 7169 |
diff --git a/src/compiler/translator/TranslatorMetalDirect/MapSymbols.cpp b/src/compiler/translator/TranslatorMetalDirect/MapSymbols.cpp |
| 7170 |
new file mode 100644 |
| 7171 |
index 0000000..035c930 |
| 7172 |
--- /dev/null |
| 7173 |
+++ b/src/compiler/translator/TranslatorMetalDirect/MapSymbols.cpp |
| 7174 |
@@ -0,0 +1,46 @@ |
| 7175 |
+// |
| 7176 |
+// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 7177 |
+// Use of this source code is governed by a BSD-style license that can be |
| 7178 |
+// found in the LICENSE file. |
| 7179 |
+// |
| 7180 |
+ |
| 7181 |
+#include "compiler/translator/TranslatorMetalDirect/MapSymbols.h" |
| 7182 |
+#include "compiler/translator/tree_util/IntermRebuild.h" |
| 7183 |
+ |
| 7184 |
+using namespace sh; |
| 7185 |
+ |
| 7186 |
+//////////////////////////////////////////////////////////////////////////////// |
| 7187 |
+ |
| 7188 |
+namespace |
| 7189 |
+{ |
| 7190 |
+ |
| 7191 |
+class Rewriter : public TIntermRebuild |
| 7192 |
+{ |
| 7193 |
+ private: |
| 7194 |
+ std::function<TIntermNode &(const TFunction *, TIntermSymbol &)> mMap; |
| 7195 |
+ |
| 7196 |
+ public: |
| 7197 |
+ Rewriter(TCompiler &compiler, |
| 7198 |
+ std::function<TIntermNode &(const TFunction *, TIntermSymbol &)> map) |
| 7199 |
+ : TIntermRebuild(compiler, false, true), mMap(map) |
| 7200 |
+ {} |
| 7201 |
+ |
| 7202 |
+ PostResult visitSymbolPost(TIntermSymbol &symbolNode) override |
| 7203 |
+ { |
| 7204 |
+ return mMap(getParentFunction(), symbolNode); |
| 7205 |
+ } |
| 7206 |
+}; |
| 7207 |
+ |
| 7208 |
+} // namespace |
| 7209 |
+ |
| 7210 |
+bool sh::MapSymbols(TCompiler &compiler, |
| 7211 |
+ TIntermBlock &root, |
| 7212 |
+ std::function<TIntermNode &(const TFunction *, TIntermSymbol &)> map) |
| 7213 |
+{ |
| 7214 |
+ Rewriter rewriter(compiler, std::move(map)); |
| 7215 |
+ if (!rewriter.rebuildRoot(root)) |
| 7216 |
+ { |
| 7217 |
+ return false; |
| 7218 |
+ } |
| 7219 |
+ return true; |
| 7220 |
+} |
| 7221 |
diff --git a/src/compiler/translator/TranslatorMetalDirect/MapSymbols.h b/src/compiler/translator/TranslatorMetalDirect/MapSymbols.h |
| 7222 |
new file mode 100644 |
| 7223 |
index 0000000..656890a |
| 7224 |
--- /dev/null |
| 7225 |
+++ b/src/compiler/translator/TranslatorMetalDirect/MapSymbols.h |
| 7226 |
@@ -0,0 +1,27 @@ |
| 7227 |
+// |
| 7228 |
+// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 7229 |
+// Use of this source code is governed by a BSD-style license that can be |
| 7230 |
+// found in the LICENSE file. |
| 7231 |
+// |
| 7232 |
+ |
| 7233 |
+#ifndef COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_MAPVARIABLESTOMEMBERACCESS_H_ |
| 7234 |
+#define COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_MAPVARIABLESTOMEMBERACCESS_H_ |
| 7235 |
+ |
| 7236 |
+#include <functional> |
| 7237 |
+ |
| 7238 |
+#include "common/angleutils.h" |
| 7239 |
+#include "compiler/translator/Compiler.h" |
| 7240 |
+ |
| 7241 |
+namespace sh |
| 7242 |
+{ |
| 7243 |
+ |
| 7244 |
+// Maps TIntermSymbol nodes to TIntermNode nodes. |
| 7245 |
+// The parent function of a symbol is provided to the mapping when applicable. |
| 7246 |
+ANGLE_NO_DISCARD bool MapSymbols( |
| 7247 |
+ TCompiler &compiler, |
| 7248 |
+ TIntermBlock &root, |
| 7249 |
+ std::function<TIntermNode &(const TFunction *, TIntermSymbol &)> map); |
| 7250 |
+ |
| 7251 |
+} // namespace sh |
| 7252 |
+ |
| 7253 |
+#endif // COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_MAPVARIABLESTOMEMBERACCESS_H_ |
| 7254 |
diff --git a/src/compiler/translator/TranslatorMetalDirect/ModifyStruct.cpp b/src/compiler/translator/TranslatorMetalDirect/ModifyStruct.cpp |
| 7255 |
new file mode 100644 |
| 7256 |
index 0000000..9778d34 |
| 7257 |
--- /dev/null |
| 7258 |
+++ b/src/compiler/translator/TranslatorMetalDirect/ModifyStruct.cpp |
| 7259 |
@@ -0,0 +1,1001 @@ |
| 7260 |
+// |
| 7261 |
+// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 7262 |
+// Use of this source code is governed by a BSD-style license that can be |
| 7263 |
+// found in the LICENSE file. |
| 7264 |
+// |
| 7265 |
+ |
| 7266 |
+#include <algorithm> |
| 7267 |
+#include <cstring> |
| 7268 |
+#include <numeric> |
| 7269 |
+#include <unordered_map> |
| 7270 |
+#include <unordered_set> |
| 7271 |
+ |
| 7272 |
+#include "compiler/translator/TranslatorMetalDirect/AstHelpers.h" |
| 7273 |
+#include "compiler/translator/TranslatorMetalDirect/ModifyStruct.h" |
| 7274 |
+ |
| 7275 |
+using namespace sh; |
| 7276 |
+ |
| 7277 |
+//////////////////////////////////////////////////////////////////////////////// |
| 7278 |
+ |
| 7279 |
+size_t ModifiedStructMachineries::size() const |
| 7280 |
+{ |
| 7281 |
+ return ordering.size(); |
| 7282 |
+} |
| 7283 |
+ |
| 7284 |
+const ModifiedStructMachinery &ModifiedStructMachineries::at(size_t index) const |
| 7285 |
+{ |
| 7286 |
+ ASSERT(index < size()); |
| 7287 |
+ const TStructure *s = ordering[index]; |
| 7288 |
+ const ModifiedStructMachinery *m = find(*s); |
| 7289 |
+ ASSERT(m); |
| 7290 |
+ return *m; |
| 7291 |
+} |
| 7292 |
+ |
| 7293 |
+const ModifiedStructMachinery *ModifiedStructMachineries::find(const TStructure &s) const |
| 7294 |
+{ |
| 7295 |
+ auto iter = originalToMachinery.find(&s); |
| 7296 |
+ if (iter == originalToMachinery.end()) |
| 7297 |
+ { |
| 7298 |
+ return nullptr; |
| 7299 |
+ } |
| 7300 |
+ return &iter->second; |
| 7301 |
+} |
| 7302 |
+ |
| 7303 |
+void ModifiedStructMachineries::insert(const TStructure &s, |
| 7304 |
+ const ModifiedStructMachinery &machinery) |
| 7305 |
+{ |
| 7306 |
+ ASSERT(!find(s)); |
| 7307 |
+ originalToMachinery[&s] = machinery; |
| 7308 |
+ ordering.push_back(&s); |
| 7309 |
+} |
| 7310 |
+ |
| 7311 |
+//////////////////////////////////////////////////////////////////////////////// |
| 7312 |
+ |
| 7313 |
+namespace |
| 7314 |
+{ |
| 7315 |
+ |
| 7316 |
+TIntermTyped &Flatten(SymbolEnv &symbolEnv, TIntermTyped &node) |
| 7317 |
+{ |
| 7318 |
+ auto &type = node.getType(); |
| 7319 |
+ ASSERT(type.isArray()); |
| 7320 |
+ |
| 7321 |
+ auto &retType = InnermostType(type); |
| 7322 |
+ retType.makeArray(1); |
| 7323 |
+ |
| 7324 |
+ return symbolEnv.callFunctionOverload(Name("flatten"), retType, *new TIntermSequence{&node}); |
| 7325 |
+} |
| 7326 |
+ |
| 7327 |
+struct FlattenArray |
| 7328 |
+{}; |
| 7329 |
+ |
| 7330 |
+struct PathItem |
| 7331 |
+{ |
| 7332 |
+ enum class Type |
| 7333 |
+ { |
| 7334 |
+ Field, // Struct field indexing. |
| 7335 |
+ Index, // Array, vector, or matrix indexing. |
| 7336 |
+ FlattenArray, // Array of any rank -> pointer of innermost type. |
| 7337 |
+ }; |
| 7338 |
+ |
| 7339 |
+ PathItem(const TField &field) : field(&field), type(Type::Field) {} |
| 7340 |
+ PathItem(int index) : index(index), type(Type::Index) {} |
| 7341 |
+ PathItem(unsigned index) : PathItem(static_cast<int>(index)) {} |
| 7342 |
+ PathItem(FlattenArray flatten) : type(Type::FlattenArray) {} |
| 7343 |
+ |
| 7344 |
+ union |
| 7345 |
+ { |
| 7346 |
+ const TField *field; |
| 7347 |
+ int index; |
| 7348 |
+ }; |
| 7349 |
+ Type type; |
| 7350 |
+}; |
| 7351 |
+ |
| 7352 |
+TIntermTyped &BuildPathAccess(SymbolEnv &symbolEnv, |
| 7353 |
+ const TVariable &var, |
| 7354 |
+ const std::vector<PathItem> &path) |
| 7355 |
+{ |
| 7356 |
+ TIntermTyped *curr = new TIntermSymbol(&var); |
| 7357 |
+ for (const PathItem &item : path) |
| 7358 |
+ { |
| 7359 |
+ switch (item.type) |
| 7360 |
+ { |
| 7361 |
+ case PathItem::Type::Field: |
| 7362 |
+ curr = &AccessField(*curr, item.field->name()); |
| 7363 |
+ break; |
| 7364 |
+ case PathItem::Type::Index: |
| 7365 |
+ curr = &AccessIndex(*curr, item.index); |
| 7366 |
+ break; |
| 7367 |
+ case PathItem::Type::FlattenArray: |
| 7368 |
+ { |
| 7369 |
+ curr = &Flatten(symbolEnv, *curr); |
| 7370 |
+ } |
| 7371 |
+ break; |
| 7372 |
+ } |
| 7373 |
+ } |
| 7374 |
+ return *curr; |
| 7375 |
+} |
| 7376 |
+ |
| 7377 |
+//////////////////////////////////////////////////////////////////////////////// |
| 7378 |
+ |
| 7379 |
+using OriginalParam = const TVariable &; |
| 7380 |
+using ModifiedParam = const TVariable &; |
| 7381 |
+ |
| 7382 |
+using OriginalAccess = TIntermTyped; |
| 7383 |
+using ModifiedAccess = TIntermTyped; |
| 7384 |
+ |
| 7385 |
+struct Access |
| 7386 |
+{ |
| 7387 |
+ OriginalAccess &original; |
| 7388 |
+ ModifiedAccess &modified; |
| 7389 |
+ |
| 7390 |
+ struct Env |
| 7391 |
+ { |
| 7392 |
+ const ConvertType type; |
| 7393 |
+ }; |
| 7394 |
+}; |
| 7395 |
+ |
| 7396 |
+using ConversionFunc = std::function<Access(Access::Env &, OriginalAccess &, ModifiedAccess &)>; |
| 7397 |
+ |
| 7398 |
+class ConvertStructState : angle::NonCopyable |
| 7399 |
+{ |
| 7400 |
+ private: |
| 7401 |
+ struct ConversionInfo |
| 7402 |
+ { |
| 7403 |
+ ConversionFunc stdFunc; |
| 7404 |
+ const TFunction *astFunc; |
| 7405 |
+ std::vector<PathItem> pathItems; |
| 7406 |
+ ImmutableString pathName; |
| 7407 |
+ }; |
| 7408 |
+ |
| 7409 |
+ public: |
| 7410 |
+ ConvertStructState(SymbolEnv &symbolEnv, |
| 7411 |
+ IdGen &idGen, |
| 7412 |
+ const ModifyStructConfig &config, |
| 7413 |
+ ModifiedStructMachineries &outMachineries) |
| 7414 |
+ : config(config), |
| 7415 |
+ symbolEnv(symbolEnv), |
| 7416 |
+ modifiedFields(*new TFieldList()), |
| 7417 |
+ symbolTable(symbolEnv.symbolTable()), |
| 7418 |
+ idGen(idGen), |
| 7419 |
+ outMachineries(outMachineries) |
| 7420 |
+ {} |
| 7421 |
+ |
| 7422 |
+ ~ConvertStructState() |
| 7423 |
+ { |
| 7424 |
+ ASSERT(namePath.empty()); |
| 7425 |
+ ASSERT(namePathSizes.empty()); |
| 7426 |
+ } |
| 7427 |
+ |
| 7428 |
+ void publish(const TStructure &originalStruct, const Name &modifiedStructName) |
| 7429 |
+ { |
| 7430 |
+ const bool isOriginalToModified = config.convertType == ConvertType::OriginalToModified; |
| 7431 |
+ |
| 7432 |
+ auto &modifiedStruct = *new TStructure(&symbolTable, modifiedStructName.rawName(), |
| 7433 |
+ &modifiedFields, modifiedStructName.symbolType()); |
| 7434 |
+ |
| 7435 |
+ auto &func = *new TFunction( |
| 7436 |
+ &symbolTable, |
| 7437 |
+ idGen.createNewName(isOriginalToModified ? "originalToModified" : "modifiedToOriginal") |
| 7438 |
+ .rawName(), |
| 7439 |
+ SymbolType::AngleInternal, new TType(TBasicType::EbtVoid), false); |
| 7440 |
+ |
| 7441 |
+ OriginalParam originalParam = |
| 7442 |
+ CreateInstanceVariable(symbolTable, originalStruct, Name("original")); |
| 7443 |
+ ModifiedParam modifiedParam = |
| 7444 |
+ CreateInstanceVariable(symbolTable, modifiedStruct, Name("modified")); |
| 7445 |
+ symbolEnv.markAsReference(originalParam, AddressSpace::Thread); |
| 7446 |
+ symbolEnv.markAsReference(modifiedParam, config.externalAddressSpace); |
| 7447 |
+ if (isOriginalToModified) |
| 7448 |
+ { |
| 7449 |
+ func.addParameter(&originalParam); |
| 7450 |
+ func.addParameter(&modifiedParam); |
| 7451 |
+ } |
| 7452 |
+ else |
| 7453 |
+ { |
| 7454 |
+ func.addParameter(&modifiedParam); |
| 7455 |
+ func.addParameter(&originalParam); |
| 7456 |
+ } |
| 7457 |
+ |
| 7458 |
+ TIntermBlock &body = *new TIntermBlock(); |
| 7459 |
+ |
| 7460 |
+ Access::Env env{config.convertType}; |
| 7461 |
+ |
| 7462 |
+ for (ConversionInfo &info : conversionInfos) |
| 7463 |
+ { |
| 7464 |
+ auto convert = [&](OriginalAccess &original, ModifiedAccess &modified) { |
| 7465 |
+ if (info.astFunc) |
| 7466 |
+ { |
| 7467 |
+ ASSERT(!info.stdFunc); |
| 7468 |
+ TIntermTyped &src = isOriginalToModified ? modified : original; |
| 7469 |
+ TIntermTyped &dest = isOriginalToModified ? original : modified; |
| 7470 |
+ body.appendStatement(TIntermAggregate::CreateFunctionCall( |
| 7471 |
+ *info.astFunc, new TIntermSequence{&dest, &src})); |
| 7472 |
+ } |
| 7473 |
+ else |
| 7474 |
+ { |
| 7475 |
+ ASSERT(info.stdFunc); |
| 7476 |
+ Access access = info.stdFunc(env, original, modified); |
| 7477 |
+ TIntermTyped &src = isOriginalToModified ? access.original : access.modified; |
| 7478 |
+ TIntermTyped &dest = isOriginalToModified ? access.modified : access.original; |
| 7479 |
+ body.appendStatement(new TIntermBinary(TOperator::EOpAssign, &dest, &src)); |
| 7480 |
+ } |
| 7481 |
+ }; |
| 7482 |
+ |
| 7483 |
+ OriginalAccess *original = &BuildPathAccess(symbolEnv, originalParam, info.pathItems); |
| 7484 |
+ ModifiedAccess *modified = &AccessField(modifiedParam, info.pathName); |
| 7485 |
+ |
| 7486 |
+ const TType ot = original->getType(); |
| 7487 |
+ const TType mt = modified->getType(); |
| 7488 |
+ ASSERT(ot.isArray() == mt.isArray()); |
| 7489 |
+ |
| 7490 |
+ if (ot.isArray() && ot != mt) |
| 7491 |
+ { |
| 7492 |
+ ASSERT(ot.getArraySizes() == mt.getArraySizes()); |
| 7493 |
+ if (ot.isArrayOfArrays()) |
| 7494 |
+ { |
| 7495 |
+ original = &Flatten(symbolEnv, *original); |
| 7496 |
+ modified = &Flatten(symbolEnv, *modified); |
| 7497 |
+ } |
| 7498 |
+ const int volume = static_cast<int>(ot.getArraySizeProduct()); |
| 7499 |
+ for (int i = 0; i < volume; ++i) |
| 7500 |
+ { |
| 7501 |
+ if (i != 0) |
| 7502 |
+ { |
| 7503 |
+ original = original->deepCopy(); |
| 7504 |
+ modified = modified->deepCopy(); |
| 7505 |
+ } |
| 7506 |
+ OriginalAccess &o = AccessIndex(*original, i); |
| 7507 |
+ OriginalAccess &m = AccessIndex(*modified, i); |
| 7508 |
+ convert(o, m); |
| 7509 |
+ } |
| 7510 |
+ } |
| 7511 |
+ else |
| 7512 |
+ { |
| 7513 |
+ convert(*original, *modified); |
| 7514 |
+ } |
| 7515 |
+ } |
| 7516 |
+ |
| 7517 |
+ auto *funcProto = new TIntermFunctionPrototype(&func); |
| 7518 |
+ auto *funcDef = new TIntermFunctionDefinition(funcProto, &body); |
| 7519 |
+ |
| 7520 |
+ ModifiedStructMachinery machinery; |
| 7521 |
+ machinery.modifiedStruct = &modifiedStruct; |
| 7522 |
+ machinery.getConverter(config.convertType) = funcDef; |
| 7523 |
+ |
| 7524 |
+ outMachineries.insert(originalStruct, machinery); |
| 7525 |
+ } |
| 7526 |
+ |
| 7527 |
+ void pushPath(PathItem const &item) |
| 7528 |
+ { |
| 7529 |
+ pathItems.push_back(item); |
| 7530 |
+ |
| 7531 |
+ switch (item.type) |
| 7532 |
+ { |
| 7533 |
+ case PathItem::Type::Field: |
| 7534 |
+ pushNamePath(item.field->name().data()); |
| 7535 |
+ break; |
| 7536 |
+ |
| 7537 |
+ case PathItem::Type::Index: |
| 7538 |
+ pushNamePath(item.index); |
| 7539 |
+ break; |
| 7540 |
+ |
| 7541 |
+ case PathItem::Type::FlattenArray: |
| 7542 |
+ namePathSizes.push_back(namePath.size()); |
| 7543 |
+ break; |
| 7544 |
+ } |
| 7545 |
+ } |
| 7546 |
+ |
| 7547 |
+ void popPath() |
| 7548 |
+ { |
| 7549 |
+ ASSERT(!namePath.empty()); |
| 7550 |
+ ASSERT(!namePathSizes.empty()); |
| 7551 |
+ namePath.resize(namePathSizes.back()); |
| 7552 |
+ namePathSizes.pop_back(); |
| 7553 |
+ |
| 7554 |
+ ASSERT(!pathItems.empty()); |
| 7555 |
+ pathItems.pop_back(); |
| 7556 |
+ } |
| 7557 |
+ |
| 7558 |
+ void finalize() |
| 7559 |
+ { |
| 7560 |
+ ASSERT(!finalized); |
| 7561 |
+ finalized = true; |
| 7562 |
+ introducePacking(); |
| 7563 |
+ ASSERT(metalLayoutTotal == Layout::Identity()); |
| 7564 |
+ introducePadding(); |
| 7565 |
+ } |
| 7566 |
+ |
| 7567 |
+ void addModifiedField(const TField &field, |
| 7568 |
+ TType &newType, |
| 7569 |
+ TLayoutBlockStorage storage, |
| 7570 |
+ TLayoutMatrixPacking packing) |
| 7571 |
+ { |
| 7572 |
+ TLayoutQualifier layoutQualifier = newType.getLayoutQualifier(); |
| 7573 |
+ layoutQualifier.blockStorage = storage; |
| 7574 |
+ layoutQualifier.matrixPacking = packing; |
| 7575 |
+ newType.setLayoutQualifier(layoutQualifier); |
| 7576 |
+ |
| 7577 |
+ const ImmutableString pathName(namePath); |
| 7578 |
+ modifiedFields.push_back(new TField(&newType, pathName, field.line(), field.symbolType())); |
| 7579 |
+ } |
| 7580 |
+ |
| 7581 |
+ void addConversion(const ConversionFunc &func) |
| 7582 |
+ { |
| 7583 |
+ ASSERT(!modifiedFields.empty()); |
| 7584 |
+ conversionInfos.push_back({func, nullptr, pathItems, modifiedFields.back()->name()}); |
| 7585 |
+ } |
| 7586 |
+ |
| 7587 |
+ void addConversion(const TFunction &func) |
| 7588 |
+ { |
| 7589 |
+ ASSERT(!modifiedFields.empty()); |
| 7590 |
+ conversionInfos.push_back({{}, &func, pathItems, modifiedFields.back()->name()}); |
| 7591 |
+ } |
| 7592 |
+ |
| 7593 |
+ bool hasPacking() const { return containsPacked; } |
| 7594 |
+ |
| 7595 |
+ bool hasPadding() const { return padFieldCount > 0; } |
| 7596 |
+ |
| 7597 |
+ bool recurse(const TStructure &structure, ModifiedStructMachinery &outMachinery) |
| 7598 |
+ { |
| 7599 |
+ const ModifiedStructMachinery *m = outMachineries.find(structure); |
| 7600 |
+ if (m == nullptr) |
| 7601 |
+ { |
| 7602 |
+ const Name name = idGen.createNewName(structure.name().data()); |
| 7603 |
+ if (!TryCreateModifiedStruct(symbolEnv, idGen, config, structure, name, outMachineries)) |
| 7604 |
+ { |
| 7605 |
+ return false; |
| 7606 |
+ } |
| 7607 |
+ m = outMachineries.find(structure); |
| 7608 |
+ ASSERT(m); |
| 7609 |
+ } |
| 7610 |
+ outMachinery = *m; |
| 7611 |
+ return true; |
| 7612 |
+ } |
| 7613 |
+ |
| 7614 |
+ private: |
| 7615 |
+ void addPadding(size_t padAmount, bool updateLayout) |
| 7616 |
+ { |
| 7617 |
+ if (padAmount == 0) |
| 7618 |
+ { |
| 7619 |
+ return; |
| 7620 |
+ } |
| 7621 |
+ |
| 7622 |
+ const size_t begin = modifiedFields.size(); |
| 7623 |
+ |
| 7624 |
+ // Iteratively adding in scalar or vector padding because some struct types will not |
| 7625 |
+ // allow matrix or array members. |
| 7626 |
+ while (padAmount > 0) |
| 7627 |
+ { |
| 7628 |
+ TType *padType; |
| 7629 |
+ if (padAmount >= 16) |
| 7630 |
+ { |
| 7631 |
+ padAmount -= 16; |
| 7632 |
+ padType = new TType(TBasicType::EbtFloat, 4); |
| 7633 |
+ } |
| 7634 |
+ else if (padAmount >= 8) |
| 7635 |
+ { |
| 7636 |
+ padAmount -= 8; |
| 7637 |
+ padType = new TType(TBasicType::EbtFloat, 2); |
| 7638 |
+ } |
| 7639 |
+ else if (padAmount >= 4) |
| 7640 |
+ { |
| 7641 |
+ padAmount -= 4; |
| 7642 |
+ padType = new TType(TBasicType::EbtFloat); |
| 7643 |
+ } |
| 7644 |
+ else if (padAmount >= 2) |
| 7645 |
+ { |
| 7646 |
+ padAmount -= 2; |
| 7647 |
+ padType = new TType(TBasicType::EbtBool, 2); |
| 7648 |
+ } |
| 7649 |
+ else |
| 7650 |
+ { |
| 7651 |
+ ASSERT(padAmount == 1); |
| 7652 |
+ padAmount -= 1; |
| 7653 |
+ padType = new TType(TBasicType::EbtBool); |
| 7654 |
+ } |
| 7655 |
+ |
| 7656 |
+ if (updateLayout) |
| 7657 |
+ { |
| 7658 |
+ metalLayoutTotal += MetalLayoutOf(*padType); |
| 7659 |
+ } |
| 7660 |
+ |
| 7661 |
+ const Name name = idGen.createNewName("pad"); |
| 7662 |
+ modifiedFields.push_back( |
| 7663 |
+ new TField(padType, name.rawName(), kNoSourceLoc, name.symbolType())); |
| 7664 |
+ ++padFieldCount; |
| 7665 |
+ } |
| 7666 |
+ |
| 7667 |
+ std::reverse(modifiedFields.begin() + begin, modifiedFields.end()); |
| 7668 |
+ } |
| 7669 |
+ |
| 7670 |
+ void introducePacking() |
| 7671 |
+ { |
| 7672 |
+ if (!config.allowPacking) |
| 7673 |
+ { |
| 7674 |
+ return; |
| 7675 |
+ } |
| 7676 |
+ |
| 7677 |
+ auto setUnpackedStorage = [](TType &type) { |
| 7678 |
+ TLayoutBlockStorage storage = type.getLayoutQualifier().blockStorage; |
| 7679 |
+ switch (storage) |
| 7680 |
+ { |
| 7681 |
+ case TLayoutBlockStorage::EbsShared: |
| 7682 |
+ storage = TLayoutBlockStorage::EbsStd140; |
| 7683 |
+ break; |
| 7684 |
+ case TLayoutBlockStorage::EbsPacked: |
| 7685 |
+ storage = TLayoutBlockStorage::EbsStd430; |
| 7686 |
+ break; |
| 7687 |
+ case TLayoutBlockStorage::EbsStd140: |
| 7688 |
+ case TLayoutBlockStorage::EbsStd430: |
| 7689 |
+ case TLayoutBlockStorage::EbsUnspecified: |
| 7690 |
+ break; |
| 7691 |
+ } |
| 7692 |
+ SetBlockStorage(type, storage); |
| 7693 |
+ }; |
| 7694 |
+ |
| 7695 |
+ Layout glslLayoutTotal = Layout::Identity(); |
| 7696 |
+ const size_t size = modifiedFields.size(); |
| 7697 |
+ |
| 7698 |
+ for (size_t i = 0; i < size; ++i) |
| 7699 |
+ { |
| 7700 |
+ TField &curr = *modifiedFields[i]; |
| 7701 |
+ TType &currType = *curr.type(); |
| 7702 |
+ const bool canBePacked = CanBePacked(currType); |
| 7703 |
+ |
| 7704 |
+ auto dontPack = [&]() { |
| 7705 |
+ if (canBePacked) |
| 7706 |
+ { |
| 7707 |
+ setUnpackedStorage(currType); |
| 7708 |
+ } |
| 7709 |
+ glslLayoutTotal += GlslLayoutOf(currType); |
| 7710 |
+ }; |
| 7711 |
+ |
| 7712 |
+ if (!CanBePacked(currType)) |
| 7713 |
+ { |
| 7714 |
+ dontPack(); |
| 7715 |
+ continue; |
| 7716 |
+ } |
| 7717 |
+ |
| 7718 |
+ const Layout packedGlslLayout = GlslLayoutOf(currType); |
| 7719 |
+ const TLayoutBlockStorage packedStorage = currType.getLayoutQualifier().blockStorage; |
| 7720 |
+ setUnpackedStorage(currType); |
| 7721 |
+ const Layout unpackedGlslLayout = GlslLayoutOf(currType); |
| 7722 |
+ SetBlockStorage(currType, packedStorage); |
| 7723 |
+ |
| 7724 |
+ ASSERT(packedGlslLayout.sizeOf <= unpackedGlslLayout.sizeOf); |
| 7725 |
+ if (packedGlslLayout.sizeOf == unpackedGlslLayout.sizeOf) |
| 7726 |
+ { |
| 7727 |
+ dontPack(); |
| 7728 |
+ continue; |
| 7729 |
+ } |
| 7730 |
+ |
| 7731 |
+ const size_t j = i + 1; |
| 7732 |
+ if (j == size) |
| 7733 |
+ { |
| 7734 |
+ dontPack(); |
| 7735 |
+ break; |
| 7736 |
+ } |
| 7737 |
+ |
| 7738 |
+ const size_t pad = unpackedGlslLayout.sizeOf - packedGlslLayout.sizeOf; |
| 7739 |
+ const TField &next = *modifiedFields[j]; |
| 7740 |
+ const Layout nextGlslLayout = GlslLayoutOf(*next.type()); |
| 7741 |
+ |
| 7742 |
+ if (pad < nextGlslLayout.sizeOf) |
| 7743 |
+ { |
| 7744 |
+ dontPack(); |
| 7745 |
+ continue; |
| 7746 |
+ } |
| 7747 |
+ |
| 7748 |
+ symbolEnv.markAsPacked(curr); |
| 7749 |
+ glslLayoutTotal += packedGlslLayout; |
| 7750 |
+ containsPacked = true; |
| 7751 |
+ } |
| 7752 |
+ } |
| 7753 |
+ |
| 7754 |
+ void introducePadding() |
| 7755 |
+ { |
| 7756 |
+ if (!config.allowPadding) |
| 7757 |
+ { |
| 7758 |
+ return; |
| 7759 |
+ } |
| 7760 |
+ |
| 7761 |
+ MetalLayoutOfConfig layoutConfig; |
| 7762 |
+ layoutConfig.disablePacking = !config.allowPacking; |
| 7763 |
+ layoutConfig.assumeStructsAreTailPadded = true; |
| 7764 |
+ |
| 7765 |
+ TFieldList fields = std::move(modifiedFields); |
| 7766 |
+ ASSERT(!fields.empty()); // GLSL requires at least one member. |
| 7767 |
+ |
| 7768 |
+ const TField *const first = fields.front(); |
| 7769 |
+ |
| 7770 |
+ for (TField *field : fields) |
| 7771 |
+ { |
| 7772 |
+ const TType &type = *field->type(); |
| 7773 |
+ |
| 7774 |
+ const Layout glslLayout = GlslLayoutOf(type); |
| 7775 |
+ const Layout metalLayout = MetalLayoutOf(type, layoutConfig); |
| 7776 |
+ |
| 7777 |
+ size_t prePadAmount = 0; |
| 7778 |
+ if (glslLayout.alignOf > metalLayout.alignOf && field != first) |
| 7779 |
+ { |
| 7780 |
+ const size_t prePaddedSize = metalLayoutTotal.sizeOf; |
| 7781 |
+ metalLayoutTotal.requireAlignment(glslLayout.alignOf, true); |
| 7782 |
+ const size_t paddedSize = metalLayoutTotal.sizeOf; |
| 7783 |
+ prePadAmount = paddedSize - prePaddedSize; |
| 7784 |
+ metalLayoutTotal += metalLayout; |
| 7785 |
+ addPadding(prePadAmount, false); // Note: requireAlignment() already updated layout |
| 7786 |
+ } |
| 7787 |
+ else |
| 7788 |
+ { |
| 7789 |
+ metalLayoutTotal += metalLayout; |
| 7790 |
+ } |
| 7791 |
+ |
| 7792 |
+ modifiedFields.push_back(field); |
| 7793 |
+ |
| 7794 |
+ if (glslLayout.sizeOf > metalLayout.sizeOf && field != fields.back()) |
| 7795 |
+ { |
| 7796 |
+ const bool updateLayout = true; // XXX: Correct? |
| 7797 |
+ const size_t padAmount = glslLayout.sizeOf - metalLayout.sizeOf; |
| 7798 |
+ addPadding(padAmount, updateLayout); |
| 7799 |
+ } |
| 7800 |
+ } |
| 7801 |
+ } |
| 7802 |
+ |
| 7803 |
+ void pushNamePath(const char *extra) |
| 7804 |
+ { |
| 7805 |
+ ASSERT(extra && *extra != '\0'); |
| 7806 |
+ namePathSizes.push_back(namePath.size()); |
| 7807 |
+ const char *p = extra; |
| 7808 |
+ if (namePath.empty()) |
| 7809 |
+ { |
| 7810 |
+ namePath = p; |
| 7811 |
+ return; |
| 7812 |
+ } |
| 7813 |
+ while (*p == '_') |
| 7814 |
+ { |
| 7815 |
+ ++p; |
| 7816 |
+ } |
| 7817 |
+ if (*p == '\0') |
| 7818 |
+ { |
| 7819 |
+ p = "x"; |
| 7820 |
+ } |
| 7821 |
+ if (namePath.back() != '_') |
| 7822 |
+ { |
| 7823 |
+ namePath += '_'; |
| 7824 |
+ } |
| 7825 |
+ namePath += p; |
| 7826 |
+ } |
| 7827 |
+ |
| 7828 |
+ void pushNamePath(unsigned extra) |
| 7829 |
+ { |
| 7830 |
+ char buffer[std::numeric_limits<unsigned>::digits10 + 1]; |
| 7831 |
+ sprintf(buffer, "%u", extra); |
| 7832 |
+ pushNamePath(buffer); |
| 7833 |
+ } |
| 7834 |
+ |
| 7835 |
+ public: |
| 7836 |
+ const ModifyStructConfig &config; |
| 7837 |
+ SymbolEnv &symbolEnv; |
| 7838 |
+ |
| 7839 |
+ private: |
| 7840 |
+ TFieldList &modifiedFields; |
| 7841 |
+ Layout metalLayoutTotal = Layout::Identity(); |
| 7842 |
+ size_t padFieldCount = 0; |
| 7843 |
+ bool containsPacked = false; |
| 7844 |
+ bool finalized = false; |
| 7845 |
+ |
| 7846 |
+ std::vector<PathItem> pathItems; |
| 7847 |
+ |
| 7848 |
+ std::vector<size_t> namePathSizes; |
| 7849 |
+ std::string namePath; |
| 7850 |
+ |
| 7851 |
+ std::vector<ConversionInfo> conversionInfos; |
| 7852 |
+ TSymbolTable &symbolTable; |
| 7853 |
+ IdGen &idGen; |
| 7854 |
+ ModifiedStructMachineries &outMachineries; |
| 7855 |
+}; |
| 7856 |
+ |
| 7857 |
+//////////////////////////////////////////////////////////////////////////////// |
| 7858 |
+ |
| 7859 |
+using ModifyFunc = bool (*)(ConvertStructState &state, |
| 7860 |
+ const TField &field, |
| 7861 |
+ const TLayoutBlockStorage storage, |
| 7862 |
+ const TLayoutMatrixPacking packing); |
| 7863 |
+ |
| 7864 |
+bool ModifyRecursive(ConvertStructState &state, |
| 7865 |
+ const TField &field, |
| 7866 |
+ const TLayoutBlockStorage storage, |
| 7867 |
+ const TLayoutMatrixPacking packing); |
| 7868 |
+ |
| 7869 |
+bool IdentityModify(ConvertStructState &state, |
| 7870 |
+ const TField &field, |
| 7871 |
+ const TLayoutBlockStorage storage, |
| 7872 |
+ const TLayoutMatrixPacking packing) |
| 7873 |
+{ |
| 7874 |
+ const TType &type = *field.type(); |
| 7875 |
+ state.addModifiedField(field, CloneType(type), storage, packing); |
| 7876 |
+ state.addConversion([=](Access::Env &, OriginalAccess &o, ModifiedAccess &m) { |
| 7877 |
+ return Access{o, m}; |
| 7878 |
+ }); |
| 7879 |
+ return false; |
| 7880 |
+} |
| 7881 |
+ |
| 7882 |
+bool InlineStruct(ConvertStructState &state, |
| 7883 |
+ const TField &field, |
| 7884 |
+ const TLayoutBlockStorage storage, |
| 7885 |
+ const TLayoutMatrixPacking packing) |
| 7886 |
+{ |
| 7887 |
+ const TType &type = *field.type(); |
| 7888 |
+ const TStructure *substructure = state.symbolEnv.remap(type.getStruct()); |
| 7889 |
+ if (!substructure) |
| 7890 |
+ { |
| 7891 |
+ return false; |
| 7892 |
+ } |
| 7893 |
+ if (type.isArray()) |
| 7894 |
+ { |
| 7895 |
+ return false; |
| 7896 |
+ } |
| 7897 |
+ if (!state.config.inlineStruct(field)) |
| 7898 |
+ { |
| 7899 |
+ return false; |
| 7900 |
+ } |
| 7901 |
+ |
| 7902 |
+ const TFieldList &subfields = substructure->fields(); |
| 7903 |
+ for (const TField *subfield : subfields) |
| 7904 |
+ { |
| 7905 |
+ const TType &subtype = *subfield->type(); |
| 7906 |
+ const TLayoutBlockStorage substorage = Overlay(storage, subtype); |
| 7907 |
+ const TLayoutMatrixPacking subpacking = Overlay(packing, subtype); |
| 7908 |
+ ModifyRecursive(state, *subfield, substorage, subpacking); |
| 7909 |
+ } |
| 7910 |
+ |
| 7911 |
+ return true; |
| 7912 |
+} |
| 7913 |
+ |
| 7914 |
+bool RecurseStruct(ConvertStructState &state, |
| 7915 |
+ const TField &field, |
| 7916 |
+ const TLayoutBlockStorage storage, |
| 7917 |
+ const TLayoutMatrixPacking packing) |
| 7918 |
+{ |
| 7919 |
+ const TType &type = *field.type(); |
| 7920 |
+ const TStructure *substructure = state.symbolEnv.remap(type.getStruct()); |
| 7921 |
+ if (!substructure) |
| 7922 |
+ { |
| 7923 |
+ return false; |
| 7924 |
+ } |
| 7925 |
+ if (!state.config.recurseStruct(field)) |
| 7926 |
+ { |
| 7927 |
+ return false; |
| 7928 |
+ } |
| 7929 |
+ |
| 7930 |
+ ModifiedStructMachinery machinery; |
| 7931 |
+ if (!state.recurse(*substructure, machinery)) |
| 7932 |
+ { |
| 7933 |
+ return false; |
| 7934 |
+ } |
| 7935 |
+ |
| 7936 |
+ TType &newType = *new TType(machinery.modifiedStruct, false); |
| 7937 |
+ if (type.isArray()) |
| 7938 |
+ { |
| 7939 |
+ newType.makeArrays(type.getArraySizes()); |
| 7940 |
+ } |
| 7941 |
+ |
| 7942 |
+ TIntermFunctionDefinition *converter = machinery.getConverter(state.config.convertType); |
| 7943 |
+ ASSERT(converter); |
| 7944 |
+ |
| 7945 |
+ state.addModifiedField(field, newType, storage, packing); |
| 7946 |
+ state.addConversion(*converter->getFunction()); |
| 7947 |
+ |
| 7948 |
+ return true; |
| 7949 |
+} |
| 7950 |
+ |
| 7951 |
+bool SplitMatrixColumns(ConvertStructState &state, |
| 7952 |
+ const TField &field, |
| 7953 |
+ const TLayoutBlockStorage storage, |
| 7954 |
+ const TLayoutMatrixPacking packing) |
| 7955 |
+{ |
| 7956 |
+ const TType &type = *field.type(); |
| 7957 |
+ if (!type.isMatrix()) |
| 7958 |
+ { |
| 7959 |
+ return false; |
| 7960 |
+ } |
| 7961 |
+ if (!state.config.splitMatrixColumns(field)) |
| 7962 |
+ { |
| 7963 |
+ return false; |
| 7964 |
+ } |
| 7965 |
+ |
| 7966 |
+ const int cols = type.getCols(); |
| 7967 |
+ TType &rowType = DropColumns(type); |
| 7968 |
+ |
| 7969 |
+ for (int c = 0; c < cols; ++c) |
| 7970 |
+ { |
| 7971 |
+ state.pushPath(c); |
| 7972 |
+ |
| 7973 |
+ state.addModifiedField(field, rowType, storage, packing); |
| 7974 |
+ state.addConversion([=](Access::Env &, OriginalAccess &o, ModifiedAccess &m) { |
| 7975 |
+ return Access{o, m}; |
| 7976 |
+ }); |
| 7977 |
+ |
| 7978 |
+ state.popPath(); |
| 7979 |
+ } |
| 7980 |
+ |
| 7981 |
+ return true; |
| 7982 |
+} |
| 7983 |
+ |
| 7984 |
+bool SaturateMatrixRows(ConvertStructState &state, |
| 7985 |
+ const TField &field, |
| 7986 |
+ const TLayoutBlockStorage storage, |
| 7987 |
+ const TLayoutMatrixPacking packing) |
| 7988 |
+{ |
| 7989 |
+ const TType &type = *field.type(); |
| 7990 |
+ if (!type.isMatrix()) |
| 7991 |
+ { |
| 7992 |
+ return false; |
| 7993 |
+ } |
| 7994 |
+ const int rows = type.getRows(); |
| 7995 |
+ const int saturation = state.config.saturateMatrixRows(field); |
| 7996 |
+ if (saturation <= rows) |
| 7997 |
+ { |
| 7998 |
+ return false; |
| 7999 |
+ } |
| 8000 |
+ |
| 8001 |
+ const int cols = type.getCols(); |
| 8002 |
+ TType &satType = SetMatrixRowDim(type, saturation); |
| 8003 |
+ state.addModifiedField(field, satType, storage, packing); |
| 8004 |
+ |
| 8005 |
+ for (int c = 0; c < cols; ++c) |
| 8006 |
+ { |
| 8007 |
+ for (int r = 0; r < rows; ++r) |
| 8008 |
+ { |
| 8009 |
+ state.addConversion([=](Access::Env &, OriginalAccess &o, ModifiedAccess &m) { |
| 8010 |
+ auto &o_ = AccessIndex(AccessIndex(o, c), r); |
| 8011 |
+ auto &m_ = AccessIndex(AccessIndex(m, c), r); |
| 8012 |
+ return Access{o_, m_}; |
| 8013 |
+ }); |
| 8014 |
+ } |
| 8015 |
+ } |
| 8016 |
+ |
| 8017 |
+ return true; |
| 8018 |
+} |
| 8019 |
+ |
| 8020 |
+bool TestBoolToUint(ConvertStructState &state, const TField &field) |
| 8021 |
+{ |
| 8022 |
+ if (field.type()->getBasicType() != TBasicType::EbtBool) |
| 8023 |
+ { |
| 8024 |
+ return false; |
| 8025 |
+ } |
| 8026 |
+ if (!state.config.promoteBoolToUint(field)) |
| 8027 |
+ { |
| 8028 |
+ return false; |
| 8029 |
+ } |
| 8030 |
+ return true; |
| 8031 |
+} |
| 8032 |
+ |
| 8033 |
+Access ConvertBoolToUint(ConvertType convertType, OriginalAccess &o, ModifiedAccess &m) |
| 8034 |
+{ |
| 8035 |
+ auto coerce = [](TIntermTyped &to, TIntermTyped &from) -> TIntermTyped & { |
| 8036 |
+ return *TIntermAggregate::CreateConstructor(to.getType(), new TIntermSequence{&from}); |
| 8037 |
+ }; |
| 8038 |
+ switch (convertType) |
| 8039 |
+ { |
| 8040 |
+ case ConvertType::OriginalToModified: |
| 8041 |
+ return Access{coerce(m, o), m}; |
| 8042 |
+ case ConvertType::ModifiedToOriginal: |
| 8043 |
+ return Access{o, coerce(o, m)}; |
| 8044 |
+ } |
| 8045 |
+} |
| 8046 |
+ |
| 8047 |
+bool SaturateScalarOrVectorCommon(ConvertStructState &state, |
| 8048 |
+ const TField &field, |
| 8049 |
+ const TLayoutBlockStorage storage, |
| 8050 |
+ const TLayoutMatrixPacking packing, |
| 8051 |
+ const bool array) |
| 8052 |
+{ |
| 8053 |
+ const TType &type = *field.type(); |
| 8054 |
+ if (type.isArray() != array) |
| 8055 |
+ { |
| 8056 |
+ return false; |
| 8057 |
+ } |
| 8058 |
+ if (!((type.isRank0() && HasScalarBasicType(type)) || type.isVector())) |
| 8059 |
+ { |
| 8060 |
+ return false; |
| 8061 |
+ } |
| 8062 |
+ const auto saturator = |
| 8063 |
+ array ? state.config.saturateScalarOrVectorArrays : state.config.saturateScalarOrVector; |
| 8064 |
+ const int dim = type.getNominalSize(); |
| 8065 |
+ const int saturation = saturator(field); |
| 8066 |
+ if (saturation <= dim) |
| 8067 |
+ { |
| 8068 |
+ return false; |
| 8069 |
+ } |
| 8070 |
+ |
| 8071 |
+ TType &satType = SetVectorDim(type, saturation); |
| 8072 |
+ const bool boolToUint = TestBoolToUint(state, field); |
| 8073 |
+ if (boolToUint) |
| 8074 |
+ { |
| 8075 |
+ satType.setBasicType(TBasicType::EbtUInt); |
| 8076 |
+ } |
| 8077 |
+ state.addModifiedField(field, satType, storage, packing); |
| 8078 |
+ |
| 8079 |
+ for (int d = 0; d < dim; ++d) |
| 8080 |
+ { |
| 8081 |
+ state.addConversion([=](Access::Env &env, OriginalAccess &o, ModifiedAccess &m) { |
| 8082 |
+ auto &o_ = dim > 1 ? AccessIndex(o, d) : o; |
| 8083 |
+ auto &m_ = AccessIndex(m, d); |
| 8084 |
+ if (boolToUint) |
| 8085 |
+ { |
| 8086 |
+ return ConvertBoolToUint(env.type, o_, m_); |
| 8087 |
+ } |
| 8088 |
+ else |
| 8089 |
+ { |
| 8090 |
+ return Access{o_, m_}; |
| 8091 |
+ } |
| 8092 |
+ }); |
| 8093 |
+ } |
| 8094 |
+ |
| 8095 |
+ return true; |
| 8096 |
+} |
| 8097 |
+ |
| 8098 |
+bool SaturateScalarOrVectorArrays(ConvertStructState &state, |
| 8099 |
+ const TField &field, |
| 8100 |
+ const TLayoutBlockStorage storage, |
| 8101 |
+ const TLayoutMatrixPacking packing) |
| 8102 |
+{ |
| 8103 |
+ return SaturateScalarOrVectorCommon(state, field, storage, packing, true); |
| 8104 |
+} |
| 8105 |
+ |
| 8106 |
+bool SaturateScalarOrVector(ConvertStructState &state, |
| 8107 |
+ const TField &field, |
| 8108 |
+ const TLayoutBlockStorage storage, |
| 8109 |
+ const TLayoutMatrixPacking packing) |
| 8110 |
+{ |
| 8111 |
+ return SaturateScalarOrVectorCommon(state, field, storage, packing, false); |
| 8112 |
+} |
| 8113 |
+ |
| 8114 |
+bool PromoteBoolToUint(ConvertStructState &state, |
| 8115 |
+ const TField &field, |
| 8116 |
+ const TLayoutBlockStorage storage, |
| 8117 |
+ const TLayoutMatrixPacking packing) |
| 8118 |
+{ |
| 8119 |
+ if (!TestBoolToUint(state, field)) |
| 8120 |
+ { |
| 8121 |
+ return false; |
| 8122 |
+ } |
| 8123 |
+ |
| 8124 |
+ auto &promotedType = CloneType(*field.type()); |
| 8125 |
+ promotedType.setBasicType(TBasicType::EbtUInt); |
| 8126 |
+ state.addModifiedField(field, promotedType, storage, packing); |
| 8127 |
+ |
| 8128 |
+ state.addConversion([=](Access::Env &env, OriginalAccess &o, ModifiedAccess &m) { |
| 8129 |
+ return ConvertBoolToUint(env.type, o, m); |
| 8130 |
+ }); |
| 8131 |
+ |
| 8132 |
+ return true; |
| 8133 |
+} |
| 8134 |
+ |
| 8135 |
+bool ModifyCommon(ConvertStructState &state, |
| 8136 |
+ const TField &field, |
| 8137 |
+ const TLayoutBlockStorage storage, |
| 8138 |
+ const TLayoutMatrixPacking packing) |
| 8139 |
+{ |
| 8140 |
+ ModifyFunc funcs[] = { |
| 8141 |
+ InlineStruct, // |
| 8142 |
+ RecurseStruct, // |
| 8143 |
+ SplitMatrixColumns, // |
| 8144 |
+ SaturateMatrixRows, // |
| 8145 |
+ SaturateScalarOrVectorArrays, // |
| 8146 |
+ SaturateScalarOrVector, // |
| 8147 |
+ PromoteBoolToUint, // |
| 8148 |
+ }; |
| 8149 |
+ |
| 8150 |
+ for (ModifyFunc func : funcs) |
| 8151 |
+ { |
| 8152 |
+ if (func(state, field, storage, packing)) |
| 8153 |
+ { |
| 8154 |
+ return true; |
| 8155 |
+ } |
| 8156 |
+ } |
| 8157 |
+ |
| 8158 |
+ return IdentityModify(state, field, storage, packing); |
| 8159 |
+} |
| 8160 |
+ |
| 8161 |
+bool InlineArray(ConvertStructState &state, |
| 8162 |
+ const TField &field, |
| 8163 |
+ const TLayoutBlockStorage storage, |
| 8164 |
+ const TLayoutMatrixPacking packing) |
| 8165 |
+{ |
| 8166 |
+ const TType &type = *field.type(); |
| 8167 |
+ if (!type.isArray()) |
| 8168 |
+ { |
| 8169 |
+ return false; |
| 8170 |
+ } |
| 8171 |
+ if (!state.config.inlineArray(field)) |
| 8172 |
+ { |
| 8173 |
+ return false; |
| 8174 |
+ } |
| 8175 |
+ |
| 8176 |
+ const unsigned volume = type.getArraySizeProduct(); |
| 8177 |
+ const bool isMultiDim = type.isArrayOfArrays(); |
| 8178 |
+ |
| 8179 |
+ auto &innermostType = InnermostType(type); |
| 8180 |
+ const TField innermostField(&innermostType, field.name(), field.line(), field.symbolType()); |
| 8181 |
+ |
| 8182 |
+ if (isMultiDim) |
| 8183 |
+ { |
| 8184 |
+ state.pushPath(FlattenArray()); |
| 8185 |
+ } |
| 8186 |
+ |
| 8187 |
+ for (unsigned i = 0; i < volume; ++i) |
| 8188 |
+ { |
| 8189 |
+ state.pushPath(i); |
| 8190 |
+ ModifyCommon(state, innermostField, storage, packing); |
| 8191 |
+ state.popPath(); |
| 8192 |
+ } |
| 8193 |
+ |
| 8194 |
+ if (isMultiDim) |
| 8195 |
+ { |
| 8196 |
+ state.popPath(); |
| 8197 |
+ } |
| 8198 |
+ |
| 8199 |
+ return true; |
| 8200 |
+} |
| 8201 |
+ |
| 8202 |
+bool ModifyRecursive(ConvertStructState &state, |
| 8203 |
+ const TField &field, |
| 8204 |
+ const TLayoutBlockStorage storage, |
| 8205 |
+ const TLayoutMatrixPacking packing) |
| 8206 |
+{ |
| 8207 |
+ state.pushPath(field); |
| 8208 |
+ |
| 8209 |
+ bool modified; |
| 8210 |
+ if (InlineArray(state, field, storage, packing)) |
| 8211 |
+ { |
| 8212 |
+ modified = true; |
| 8213 |
+ } |
| 8214 |
+ else |
| 8215 |
+ { |
| 8216 |
+ modified = ModifyCommon(state, field, storage, packing); |
| 8217 |
+ } |
| 8218 |
+ |
| 8219 |
+ state.popPath(); |
| 8220 |
+ |
| 8221 |
+ return modified; |
| 8222 |
+} |
| 8223 |
+ |
| 8224 |
+} // anonymous namespace |
| 8225 |
+ |
| 8226 |
+//////////////////////////////////////////////////////////////////////////////// |
| 8227 |
+ |
| 8228 |
+bool sh::TryCreateModifiedStruct(SymbolEnv &symbolEnv, |
| 8229 |
+ IdGen &idGen, |
| 8230 |
+ const ModifyStructConfig &config, |
| 8231 |
+ const TStructure &originalStruct, |
| 8232 |
+ const Name &modifiedStructName, |
| 8233 |
+ ModifiedStructMachineries &outMachineries) |
| 8234 |
+{ |
| 8235 |
+ ConvertStructState state(symbolEnv, idGen, config, outMachineries); |
| 8236 |
+ size_t identicalFieldCount = 0; |
| 8237 |
+ |
| 8238 |
+ const TFieldList &originalFields = originalStruct.fields(); |
| 8239 |
+ for (TField *originalField : originalFields) |
| 8240 |
+ { |
| 8241 |
+ const TType &originalType = *originalField->type(); |
| 8242 |
+ const TLayoutBlockStorage storage = Overlay(config.initialBlockStorage, originalType); |
| 8243 |
+ const TLayoutMatrixPacking packing = Overlay(config.initialMatrixPacking, originalType); |
| 8244 |
+ if (!ModifyRecursive(state, *originalField, storage, packing)) |
| 8245 |
+ { |
| 8246 |
+ ++identicalFieldCount; |
| 8247 |
+ } |
| 8248 |
+ } |
| 8249 |
+ |
| 8250 |
+ state.finalize(); |
| 8251 |
+ |
| 8252 |
+ if (identicalFieldCount == originalFields.size() && !state.hasPacking() && !state.hasPadding()) |
| 8253 |
+ { |
| 8254 |
+ return false; |
| 8255 |
+ } |
| 8256 |
+ |
| 8257 |
+ state.publish(originalStruct, modifiedStructName); |
| 8258 |
+ |
| 8259 |
+ return true; |
| 8260 |
+} |
| 8261 |
diff --git a/src/compiler/translator/TranslatorMetalDirect/ModifyStruct.h b/src/compiler/translator/TranslatorMetalDirect/ModifyStruct.h |
| 8262 |
new file mode 100644 |
| 8263 |
index 0000000..4b8cfc5 |
| 8264 |
--- /dev/null |
| 8265 |
+++ b/src/compiler/translator/TranslatorMetalDirect/ModifyStruct.h |
| 8266 |
@@ -0,0 +1,135 @@ |
| 8267 |
+// |
| 8268 |
+// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 8269 |
+// Use of this source code is governed by a BSD-style license that can be |
| 8270 |
+// found in the LICENSE file. |
| 8271 |
+// |
| 8272 |
+ |
| 8273 |
+#ifndef COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_MODIFYSTRUCT_H_ |
| 8274 |
+#define COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_MODIFYSTRUCT_H_ |
| 8275 |
+ |
| 8276 |
+#include <cstring> |
| 8277 |
+#include <unordered_map> |
| 8278 |
+#include <unordered_set> |
| 8279 |
+ |
| 8280 |
+#include "compiler/translator/TranslatorMetalDirect/IdGen.h" |
| 8281 |
+#include "compiler/translator/TranslatorMetalDirect/Layout.h" |
| 8282 |
+#include "compiler/translator/TranslatorMetalDirect/Name.h" |
| 8283 |
+#include "compiler/translator/TranslatorMetalDirect/ProgramPrelude.h" |
| 8284 |
+#include "compiler/translator/TranslatorMetalDirect/SymbolEnv.h" |
| 8285 |
+ |
| 8286 |
+namespace sh |
| 8287 |
+{ |
| 8288 |
+ |
| 8289 |
+enum class ConvertType |
| 8290 |
+{ |
| 8291 |
+ OriginalToModified, |
| 8292 |
+ ModifiedToOriginal, |
| 8293 |
+}; |
| 8294 |
+ |
| 8295 |
+// Configures how struct modification is performed. |
| 8296 |
+class ModifyStructConfig |
| 8297 |
+{ |
| 8298 |
+ public: |
| 8299 |
+ struct Predicate |
| 8300 |
+ { |
| 8301 |
+ using Func = bool (*)(const TField &); |
| 8302 |
+ static bool False(const TField &) { return false; } |
| 8303 |
+ static bool True(const TField &) { return true; } |
| 8304 |
+ }; |
| 8305 |
+ |
| 8306 |
+ struct SaturateVector |
| 8307 |
+ { |
| 8308 |
+ // Valid return values are [0, 1, 2, 3, 4]. |
| 8309 |
+ // If original dim >= return value, the field remains untouched. |
| 8310 |
+ using Func = int (*)(const TField &); |
| 8311 |
+ static int DontSaturate(const TField &) { return 0; } |
| 8312 |
+ static int FullySaturate(const TField &) { return 4; } |
| 8313 |
+ }; |
| 8314 |
+ |
| 8315 |
+ public: |
| 8316 |
+ ModifyStructConfig(ConvertType convertType, bool allowPacking, bool allowPadding) |
| 8317 |
+ : convertType(convertType), allowPacking(allowPacking), allowPadding(allowPadding) |
| 8318 |
+ {} |
| 8319 |
+ |
| 8320 |
+ // Matrix field is split into multiple fields of row vectors. |
| 8321 |
+ Predicate::Func splitMatrixColumns = Predicate::False; |
| 8322 |
+ |
| 8323 |
+ // Array fields are split into multiple fields of element type. |
| 8324 |
+ Predicate::Func inlineArray = Predicate::False; |
| 8325 |
+ |
| 8326 |
+ // Struct fields have their subfields inlined directly. |
| 8327 |
+ Predicate::Func inlineStruct = Predicate::False; |
| 8328 |
+ |
| 8329 |
+ // Struct fields are modified. |
| 8330 |
+ Predicate::Func recurseStruct = Predicate::False; |
| 8331 |
+ |
| 8332 |
+ // Vector and scalar bool fields are promoted to uint fields. |
| 8333 |
+ Predicate::Func promoteBoolToUint = Predicate::False; |
| 8334 |
+ |
| 8335 |
+ // Creates a new structure where scalar or vector fields are saturated vectors. |
| 8336 |
+ // e.g. `float -> float4`. |
| 8337 |
+ // e.g. `float2 -> float4`. |
| 8338 |
+ SaturateVector::Func saturateScalarOrVector = SaturateVector::DontSaturate; |
| 8339 |
+ |
| 8340 |
+ // Creates a new structure where scalar or vector array fields are saturated. |
| 8341 |
+ // e.g. `float[10] -> float4[10]` |
| 8342 |
+ // e.g. `float2[10] -> float4[10]` |
| 8343 |
+ SaturateVector::Func saturateScalarOrVectorArrays = SaturateVector::DontSaturate; |
| 8344 |
+ |
| 8345 |
+ // Creates a new structure where matrix fields are row-saturated. |
| 8346 |
+ // e.g. `float2x2 -> float2x4`. |
| 8347 |
+ SaturateVector::Func saturateMatrixRows = SaturateVector::DontSaturate; |
| 8348 |
+ |
| 8349 |
+ TLayoutBlockStorage initialBlockStorage = kDefaultLayoutBlockStorage; |
| 8350 |
+ TLayoutMatrixPacking initialMatrixPacking = kDefaultLayoutMatrixPacking; |
| 8351 |
+ ConvertType convertType; |
| 8352 |
+ bool allowPacking; |
| 8353 |
+ bool allowPadding; |
| 8354 |
+ AddressSpace externalAddressSpace; |
| 8355 |
+}; |
| 8356 |
+ |
| 8357 |
+struct ModifiedStructMachinery |
| 8358 |
+{ |
| 8359 |
+ const TStructure *modifiedStruct = nullptr; |
| 8360 |
+ TIntermFunctionDefinition *funcOriginalToModified = nullptr; |
| 8361 |
+ TIntermFunctionDefinition *funcModifiedToOriginal = nullptr; |
| 8362 |
+ |
| 8363 |
+ TIntermFunctionDefinition *&getConverter(ConvertType convertType) |
| 8364 |
+ { |
| 8365 |
+ if (convertType == ConvertType::OriginalToModified) |
| 8366 |
+ { |
| 8367 |
+ return funcOriginalToModified; |
| 8368 |
+ } |
| 8369 |
+ else |
| 8370 |
+ { |
| 8371 |
+ return funcModifiedToOriginal; |
| 8372 |
+ } |
| 8373 |
+ } |
| 8374 |
+}; |
| 8375 |
+ |
| 8376 |
+// Indexed by topological order. |
| 8377 |
+class ModifiedStructMachineries |
| 8378 |
+{ |
| 8379 |
+ public: |
| 8380 |
+ size_t size() const; |
| 8381 |
+ const ModifiedStructMachinery &at(size_t index) const; |
| 8382 |
+ const ModifiedStructMachinery *find(const TStructure &s) const; |
| 8383 |
+ void insert(const TStructure &s, const ModifiedStructMachinery &machinery); |
| 8384 |
+ |
| 8385 |
+ private: |
| 8386 |
+ std::unordered_map<const TStructure *, ModifiedStructMachinery> originalToMachinery; |
| 8387 |
+ std::vector<const TStructure *> ordering; |
| 8388 |
+}; |
| 8389 |
+ |
| 8390 |
+// Returns true and `outMachinery` populated if modifications were performed. |
| 8391 |
+// Returns false otherwise. |
| 8392 |
+bool TryCreateModifiedStruct(SymbolEnv &symbolEnv, |
| 8393 |
+ IdGen &idGen, |
| 8394 |
+ const ModifyStructConfig &config, |
| 8395 |
+ const TStructure &originalStruct, |
| 8396 |
+ const Name &modifiedStructName, |
| 8397 |
+ ModifiedStructMachineries &outMachineries); |
| 8398 |
+ |
| 8399 |
+} // namespace sh |
| 8400 |
+ |
| 8401 |
+#endif // COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_MODIFYSTRUCT_H_ |
| 8402 |
diff --git a/src/compiler/translator/TranslatorMetalDirect/Name.cpp b/src/compiler/translator/TranslatorMetalDirect/Name.cpp |
| 8403 |
new file mode 100644 |
| 8404 |
index 0000000..07c5d18 |
| 8405 |
--- /dev/null |
| 8406 |
+++ b/src/compiler/translator/TranslatorMetalDirect/Name.cpp |
| 8407 |
@@ -0,0 +1,220 @@ |
| 8408 |
+// |
| 8409 |
+// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 8410 |
+// Use of this source code is governed by a BSD-style license that can be |
| 8411 |
+// found in the LICENSE file. |
| 8412 |
+// |
| 8413 |
+ |
| 8414 |
+#include "compiler/translator/TranslatorMetalDirect/Name.h" |
| 8415 |
+#include "common/debug.h" |
| 8416 |
+#include "compiler/translator/TranslatorMetalDirect/Debug.h" |
| 8417 |
+#include "compiler/translator/tree_util/IntermTraverse.h" |
| 8418 |
+ |
| 8419 |
+using namespace sh; |
| 8420 |
+ |
| 8421 |
+//////////////////////////////////////////////////////////////////////////////// |
| 8422 |
+ |
| 8423 |
+template <typename T> |
| 8424 |
+static ImmutableString GetName(T const &object) |
| 8425 |
+{ |
| 8426 |
+ if (object.symbolType() == SymbolType::Empty) |
| 8427 |
+ { |
| 8428 |
+ return kEmptyImmutableString; |
| 8429 |
+ } |
| 8430 |
+ return object.name(); |
| 8431 |
+} |
| 8432 |
+ |
| 8433 |
+Name::Name(const TField &field) : Name(GetName(field), field.symbolType()) {} |
| 8434 |
+ |
| 8435 |
+Name::Name(const TSymbol &symbol) : Name(GetName(symbol), symbol.symbolType()) {} |
| 8436 |
+ |
| 8437 |
+bool Name::operator==(const Name &other) const |
| 8438 |
+{ |
| 8439 |
+ return mRawName == other.mRawName && mSymbolType == other.mSymbolType; |
| 8440 |
+} |
| 8441 |
+ |
| 8442 |
+bool Name::operator!=(const Name &other) const |
| 8443 |
+{ |
| 8444 |
+ return !(*this == other); |
| 8445 |
+} |
| 8446 |
+ |
| 8447 |
+bool Name::operator<(const Name &other) const |
| 8448 |
+{ |
| 8449 |
+ if (mRawName < other.mRawName) |
| 8450 |
+ { |
| 8451 |
+ return true; |
| 8452 |
+ } |
| 8453 |
+ if (other.mRawName < mRawName) |
| 8454 |
+ { |
| 8455 |
+ return false; |
| 8456 |
+ } |
| 8457 |
+ return mSymbolType < other.mSymbolType; |
| 8458 |
+} |
| 8459 |
+ |
| 8460 |
+bool Name::empty() const |
| 8461 |
+{ |
| 8462 |
+ return mSymbolType == SymbolType::Empty; |
| 8463 |
+} |
| 8464 |
+ |
| 8465 |
+bool Name::beginsWith(const Name &prefix) const |
| 8466 |
+{ |
| 8467 |
+ if (mSymbolType != prefix.mSymbolType) |
| 8468 |
+ { |
| 8469 |
+ return false; |
| 8470 |
+ } |
| 8471 |
+ return mRawName.beginsWith(prefix.mRawName); |
| 8472 |
+} |
| 8473 |
+ |
| 8474 |
+void Name::emit(TInfoSinkBase &out) const |
| 8475 |
+{ |
| 8476 |
+ switch (mSymbolType) |
| 8477 |
+ { |
| 8478 |
+ case SymbolType::BuiltIn: |
| 8479 |
+ case SymbolType::UserDefined: |
| 8480 |
+ ASSERT(!mRawName.empty()); |
| 8481 |
+ out << mRawName; |
| 8482 |
+ break; |
| 8483 |
+ |
| 8484 |
+ case SymbolType::AngleInternal: |
| 8485 |
+ ASSERT(!mRawName.empty()); |
| 8486 |
+ if (mRawName.beginsWith(kAngleInternalPrefix)) |
| 8487 |
+ { |
| 8488 |
+ out << mRawName; |
| 8489 |
+ } |
| 8490 |
+ else if (mRawName[0] != '_') |
| 8491 |
+ { |
| 8492 |
+ out << kAngleInternalPrefix << '_' << mRawName; |
| 8493 |
+ } |
| 8494 |
+ else |
| 8495 |
+ { |
| 8496 |
+ out << kAngleInternalPrefix << mRawName; |
| 8497 |
+ } |
| 8498 |
+ break; |
| 8499 |
+ |
| 8500 |
+ case SymbolType::Empty: |
| 8501 |
+ LOGIC_ERROR(); |
| 8502 |
+ break; |
| 8503 |
+ } |
| 8504 |
+} |
| 8505 |
+ |
| 8506 |
+//////////////////////////////////////////////////////////////////////////////// |
| 8507 |
+ |
| 8508 |
+namespace |
| 8509 |
+{ |
| 8510 |
+ |
| 8511 |
+// NOTE: This matches more things than FindSymbolNode. |
| 8512 |
+class ExpressionContainsNameVisitor : public TIntermTraverser |
| 8513 |
+{ |
| 8514 |
+ Name mName; |
| 8515 |
+ bool mFoundName = false; |
| 8516 |
+ |
| 8517 |
+ public: |
| 8518 |
+ ExpressionContainsNameVisitor(const Name &name) |
| 8519 |
+ : TIntermTraverser(true, false, false), mName(name) |
| 8520 |
+ {} |
| 8521 |
+ |
| 8522 |
+ bool foundName() const { return mFoundName; } |
| 8523 |
+ |
| 8524 |
+ void visitSymbol(TIntermSymbol *node) override |
| 8525 |
+ { |
| 8526 |
+ if (Name(node->variable()) == mName) |
| 8527 |
+ { |
| 8528 |
+ mFoundName = true; |
| 8529 |
+ } |
| 8530 |
+ } |
| 8531 |
+ |
| 8532 |
+ bool visitSwizzle(Visit, TIntermSwizzle *) override { return !mFoundName; } |
| 8533 |
+ |
| 8534 |
+ bool visitBinary(Visit visit, TIntermBinary *node) override { return !mFoundName; } |
| 8535 |
+ |
| 8536 |
+ bool visitUnary(Visit visit, TIntermUnary *node) override { return !mFoundName; } |
| 8537 |
+ |
| 8538 |
+ bool visitTernary(Visit visit, TIntermTernary *node) override { return !mFoundName; } |
| 8539 |
+ |
| 8540 |
+ bool visitAggregate(Visit visit, TIntermAggregate *node) override |
| 8541 |
+ { |
| 8542 |
+ if (node->isConstructor()) |
| 8543 |
+ { |
| 8544 |
+ const TType &type = node->getType(); |
| 8545 |
+ const TStructure *structure = type.getStruct(); |
| 8546 |
+ if (structure && Name(*structure) == mName) |
| 8547 |
+ { |
| 8548 |
+ mFoundName = true; |
| 8549 |
+ } |
| 8550 |
+ } |
| 8551 |
+ else |
| 8552 |
+ { |
| 8553 |
+ const TFunction *func = node->getFunction(); |
| 8554 |
+ if (func && Name(*func) == mName) |
| 8555 |
+ { |
| 8556 |
+ mFoundName = true; |
| 8557 |
+ } |
| 8558 |
+ } |
| 8559 |
+ return !mFoundName; |
| 8560 |
+ } |
| 8561 |
+ |
| 8562 |
+ bool visitIfElse(Visit visit, TIntermIfElse *node) override |
| 8563 |
+ { |
| 8564 |
+ LOGIC_ERROR(); |
| 8565 |
+ return false; |
| 8566 |
+ } |
| 8567 |
+ |
| 8568 |
+ bool visitSwitch(Visit, TIntermSwitch *) override |
| 8569 |
+ { |
| 8570 |
+ LOGIC_ERROR(); |
| 8571 |
+ return false; |
| 8572 |
+ } |
| 8573 |
+ bool visitCase(Visit, TIntermCase *) override |
| 8574 |
+ { |
| 8575 |
+ LOGIC_ERROR(); |
| 8576 |
+ return false; |
| 8577 |
+ } |
| 8578 |
+ |
| 8579 |
+ void visitFunctionPrototype(TIntermFunctionPrototype *) override { LOGIC_ERROR(); } |
| 8580 |
+ |
| 8581 |
+ bool visitFunctionDefinition(Visit, TIntermFunctionDefinition *) override |
| 8582 |
+ { |
| 8583 |
+ LOGIC_ERROR(); |
| 8584 |
+ return false; |
| 8585 |
+ } |
| 8586 |
+ |
| 8587 |
+ bool visitBlock(Visit, TIntermBlock *) override |
| 8588 |
+ { |
| 8589 |
+ LOGIC_ERROR(); |
| 8590 |
+ return false; |
| 8591 |
+ } |
| 8592 |
+ |
| 8593 |
+ bool visitGlobalQualifierDeclaration(Visit, TIntermGlobalQualifierDeclaration *) override |
| 8594 |
+ { |
| 8595 |
+ LOGIC_ERROR(); |
| 8596 |
+ return false; |
| 8597 |
+ } |
| 8598 |
+ |
| 8599 |
+ bool visitDeclaration(Visit, TIntermDeclaration *) override |
| 8600 |
+ { |
| 8601 |
+ LOGIC_ERROR(); |
| 8602 |
+ return false; |
| 8603 |
+ } |
| 8604 |
+ |
| 8605 |
+ bool visitLoop(Visit, TIntermLoop *) override |
| 8606 |
+ { |
| 8607 |
+ LOGIC_ERROR(); |
| 8608 |
+ return false; |
| 8609 |
+ } |
| 8610 |
+ |
| 8611 |
+ bool visitBranch(Visit, TIntermBranch *) override |
| 8612 |
+ { |
| 8613 |
+ LOGIC_ERROR(); |
| 8614 |
+ return false; |
| 8615 |
+ } |
| 8616 |
+ |
| 8617 |
+ void visitPreprocessorDirective(TIntermPreprocessorDirective *) override { LOGIC_ERROR(); } |
| 8618 |
+}; |
| 8619 |
+ |
| 8620 |
+} // anonymous namespace |
| 8621 |
+ |
| 8622 |
+bool sh::ExpressionContainsName(const Name &name, TIntermTyped &node) |
| 8623 |
+{ |
| 8624 |
+ ExpressionContainsNameVisitor visitor(name); |
| 8625 |
+ node.traverse(&visitor); |
| 8626 |
+ return visitor.foundName(); |
| 8627 |
+} |
| 8628 |
diff --git a/src/compiler/translator/TranslatorMetalDirect/Name.h b/src/compiler/translator/TranslatorMetalDirect/Name.h |
| 8629 |
new file mode 100644 |
| 8630 |
index 0000000..d6eaea8 |
| 8631 |
--- /dev/null |
| 8632 |
+++ b/src/compiler/translator/TranslatorMetalDirect/Name.h |
| 8633 |
@@ -0,0 +1,68 @@ |
| 8634 |
+// |
| 8635 |
+// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 8636 |
+// Use of this source code is governed by a BSD-style license that can be |
| 8637 |
+// found in the LICENSE file. |
| 8638 |
+// |
| 8639 |
+ |
| 8640 |
+#ifndef COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_NAME_H_ |
| 8641 |
+#define COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_NAME_H_ |
| 8642 |
+ |
| 8643 |
+#include "compiler/translator/ImmutableString.h" |
| 8644 |
+#include "compiler/translator/InfoSink.h" |
| 8645 |
+#include "compiler/translator/IntermNode.h" |
| 8646 |
+#include "compiler/translator/Symbol.h" |
| 8647 |
+#include "compiler/translator/Types.h" |
| 8648 |
+ |
| 8649 |
+namespace sh |
| 8650 |
+{ |
| 8651 |
+ |
| 8652 |
+constexpr char kAngleInternalPrefix[] = "ANGLE"; |
| 8653 |
+ |
| 8654 |
+// Represents the name of a symbol. |
| 8655 |
+class Name |
| 8656 |
+{ |
| 8657 |
+ public: |
| 8658 |
+ constexpr Name(const Name &) = default; |
| 8659 |
+ |
| 8660 |
+ constexpr Name() : Name(kEmptyImmutableString, SymbolType::Empty) {} |
| 8661 |
+ |
| 8662 |
+ explicit constexpr Name(ImmutableString rawName, SymbolType symbolType) |
| 8663 |
+ : mRawName(rawName), mSymbolType(symbolType) |
| 8664 |
+ { |
| 8665 |
+ ASSERT(rawName.empty() == (symbolType == SymbolType::Empty)); |
| 8666 |
+ } |
| 8667 |
+ |
| 8668 |
+ explicit constexpr Name(const char *rawName, SymbolType symbolType = SymbolType::AngleInternal) |
| 8669 |
+ : Name(ImmutableString(rawName), symbolType) |
| 8670 |
+ {} |
| 8671 |
+ |
| 8672 |
+ explicit Name(const std::string &rawName, SymbolType symbolType) |
| 8673 |
+ : Name(ImmutableString(rawName), symbolType) |
| 8674 |
+ {} |
| 8675 |
+ |
| 8676 |
+ explicit Name(const TField &field); |
| 8677 |
+ explicit Name(const TSymbol &symbol); |
| 8678 |
+ |
| 8679 |
+ Name &operator=(const Name &) = default; |
| 8680 |
+ bool operator==(const Name &other) const; |
| 8681 |
+ bool operator!=(const Name &other) const; |
| 8682 |
+ bool operator<(const Name &other) const; |
| 8683 |
+ |
| 8684 |
+ constexpr const ImmutableString &rawName() const { return mRawName; } |
| 8685 |
+ constexpr SymbolType symbolType() const { return mSymbolType; } |
| 8686 |
+ |
| 8687 |
+ bool empty() const; |
| 8688 |
+ bool beginsWith(const Name &prefix) const; |
| 8689 |
+ |
| 8690 |
+ void emit(TInfoSinkBase &out) const; |
| 8691 |
+ |
| 8692 |
+ private: |
| 8693 |
+ ImmutableString mRawName; |
| 8694 |
+ SymbolType mSymbolType; |
| 8695 |
+}; |
| 8696 |
+ |
| 8697 |
+ANGLE_NO_DISCARD bool ExpressionContainsName(const Name &name, TIntermTyped &node); |
| 8698 |
+ |
| 8699 |
+} // namespace sh |
| 8700 |
+ |
| 8701 |
+#endif // COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_NAME_H_ |
| 8702 |
diff --git a/src/compiler/translator/TranslatorMetalDirect/Pipeline.cpp b/src/compiler/translator/TranslatorMetalDirect/Pipeline.cpp |
| 8703 |
new file mode 100644 |
| 8704 |
index 0000000..54c378a |
| 8705 |
--- /dev/null |
| 8706 |
+++ b/src/compiler/translator/TranslatorMetalDirect/Pipeline.cpp |
| 8707 |
@@ -0,0 +1,476 @@ |
| 8708 |
+// |
| 8709 |
+// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 8710 |
+// Use of this source code is governed by a BSD-style license that can be |
| 8711 |
+// found in the LICENSE file. |
| 8712 |
+// |
| 8713 |
+ |
| 8714 |
+#include "compiler/translator/TranslatorMetalDirect/Pipeline.h" |
| 8715 |
+#include "compiler/translator/TranslatorMetalDirect/Debug.h" |
| 8716 |
+#include "compiler/translator/tree_util/BuiltIn.h" |
| 8717 |
+ |
| 8718 |
+using namespace sh; |
| 8719 |
+ |
| 8720 |
+//////////////////////////////////////////////////////////////////////////////// |
| 8721 |
+ |
| 8722 |
+#define VARIANT_NAME(variant, base) (variant == Variant::Modified ? base "Mod" : base) |
| 8723 |
+ |
| 8724 |
+bool Pipeline::uses(const TVariable &var) const |
| 8725 |
+{ |
| 8726 |
+ if (var.symbolType() == SymbolType::Empty) |
| 8727 |
+ { |
| 8728 |
+ return false; |
| 8729 |
+ } |
| 8730 |
+ |
| 8731 |
+ if (globalInstanceVar) |
| 8732 |
+ { |
| 8733 |
+ return &var == globalInstanceVar; |
| 8734 |
+ } |
| 8735 |
+ |
| 8736 |
+ const TType &nodeType = var.getType(); |
| 8737 |
+ const TQualifier qualifier = nodeType.getQualifier(); |
| 8738 |
+ |
| 8739 |
+ switch (type) |
| 8740 |
+ { |
| 8741 |
+ case Type::VertexIn: |
| 8742 |
+ switch (qualifier) |
| 8743 |
+ { |
| 8744 |
+ case TQualifier::EvqAttribute: |
| 8745 |
+ case TQualifier::EvqVertexIn: |
| 8746 |
+ return true; |
| 8747 |
+ default: |
| 8748 |
+ return false; |
| 8749 |
+ } |
| 8750 |
+ |
| 8751 |
+ case Type::VertexOut: |
| 8752 |
+ switch (qualifier) |
| 8753 |
+ { |
| 8754 |
+ case TQualifier::EvqVertexOut: |
| 8755 |
+ case TQualifier::EvqPosition: |
| 8756 |
+ case TQualifier::EvqFlatOut: |
| 8757 |
+ case TQualifier::EvqPointSize: |
| 8758 |
+ case TQualifier::EvqSmoothOut: |
| 8759 |
+ case TQualifier::EvqCentroidOut: |
| 8760 |
+ case TQualifier::EvqNoPerspectiveOut: |
| 8761 |
+ case TQualifier::EvqVaryingOut: |
| 8762 |
+ return true; |
| 8763 |
+ default: |
| 8764 |
+ return false; |
| 8765 |
+ } |
| 8766 |
+ |
| 8767 |
+ case Type::FragmentIn: |
| 8768 |
+ switch (qualifier) |
| 8769 |
+ { |
| 8770 |
+ case TQualifier::EvqFragmentIn: |
| 8771 |
+ case TQualifier::EvqFlatIn: |
| 8772 |
+ case TQualifier::EvqSmoothIn: |
| 8773 |
+ case TQualifier::EvqCentroidIn: |
| 8774 |
+ case TQualifier::EvqNoPerspectiveIn: |
| 8775 |
+ case TQualifier::EvqVaryingIn: |
| 8776 |
+ return true; |
| 8777 |
+ default: |
| 8778 |
+ return false; |
| 8779 |
+ } |
| 8780 |
+ |
| 8781 |
+ case Type::FragmentOut: |
| 8782 |
+ switch (qualifier) |
| 8783 |
+ { |
| 8784 |
+ case TQualifier::EvqFragmentOut: |
| 8785 |
+ case TQualifier::EvqFragColor: |
| 8786 |
+ case TQualifier::EvqFragData: |
| 8787 |
+ case TQualifier::EvqFragDepth: |
| 8788 |
+ return true; |
| 8789 |
+ default: |
| 8790 |
+ return false; |
| 8791 |
+ } |
| 8792 |
+ |
| 8793 |
+ case Type::UserUniforms: |
| 8794 |
+ switch (qualifier) |
| 8795 |
+ { |
| 8796 |
+ case TQualifier::EvqUniform: |
| 8797 |
+ return true; |
| 8798 |
+ default: |
| 8799 |
+ return false; |
| 8800 |
+ } |
| 8801 |
+ |
| 8802 |
+ case Type::NonConstantGlobals: |
| 8803 |
+ switch (qualifier) |
| 8804 |
+ { |
| 8805 |
+ case TQualifier::EvqGlobal: |
| 8806 |
+ return true; |
| 8807 |
+ default: |
| 8808 |
+ return false; |
| 8809 |
+ } |
| 8810 |
+ |
| 8811 |
+ case Type::InvocationVertexGlobals: |
| 8812 |
+ switch (qualifier) |
| 8813 |
+ { |
| 8814 |
+ case TQualifier::EvqVertexID: |
| 8815 |
+ return true; |
| 8816 |
+ default: |
| 8817 |
+ return false; |
| 8818 |
+ } |
| 8819 |
+ |
| 8820 |
+ case Type::InvocationFragmentGlobals: |
| 8821 |
+ switch (qualifier) |
| 8822 |
+ { |
| 8823 |
+ case TQualifier::EvqFragCoord: |
| 8824 |
+ case TQualifier::EvqPointCoord: |
| 8825 |
+ case TQualifier::EvqFrontFacing: |
| 8826 |
+ return true; |
| 8827 |
+ default: |
| 8828 |
+ return false; |
| 8829 |
+ } |
| 8830 |
+ |
| 8831 |
+ case Type::AngleUniforms: |
| 8832 |
+ LOGIC_ERROR(); // globalInstanceVar should be non-null and thus never reach here. |
| 8833 |
+ return false; |
| 8834 |
+ |
| 8835 |
+ case Type::Texture: |
| 8836 |
+ return IsSampler(nodeType.getBasicType()); |
| 8837 |
+ |
| 8838 |
+ case Type::InstanceId: |
| 8839 |
+ return Name(var) == Name(*BuiltInVariable::gl_InstanceID()); |
| 8840 |
+ } |
| 8841 |
+} |
| 8842 |
+ |
| 8843 |
+Name Pipeline::getStructTypeName(Variant variant) const |
| 8844 |
+{ |
| 8845 |
+ const char *name; |
| 8846 |
+ switch (type) |
| 8847 |
+ { |
| 8848 |
+ case Type::VertexIn: |
| 8849 |
+ name = VARIANT_NAME(variant, "VertexIn"); |
| 8850 |
+ break; |
| 8851 |
+ case Type::VertexOut: |
| 8852 |
+ name = VARIANT_NAME(variant, "VertexOut"); |
| 8853 |
+ break; |
| 8854 |
+ case Type::FragmentIn: |
| 8855 |
+ name = VARIANT_NAME(variant, "FragmentIn"); |
| 8856 |
+ break; |
| 8857 |
+ case Type::FragmentOut: |
| 8858 |
+ name = VARIANT_NAME(variant, "FragmentOut"); |
| 8859 |
+ break; |
| 8860 |
+ case Type::UserUniforms: |
| 8861 |
+ name = VARIANT_NAME(variant, "UserUniforms"); |
| 8862 |
+ break; |
| 8863 |
+ case Type::AngleUniforms: |
| 8864 |
+ name = VARIANT_NAME(variant, "AngleUniforms"); |
| 8865 |
+ break; |
| 8866 |
+ case Type::NonConstantGlobals: |
| 8867 |
+ name = VARIANT_NAME(variant, "NonConstGlobals"); |
| 8868 |
+ break; |
| 8869 |
+ case Type::InvocationVertexGlobals: |
| 8870 |
+ name = VARIANT_NAME(variant, "InvocationVertexGlobals"); |
| 8871 |
+ break; |
| 8872 |
+ case Type::InvocationFragmentGlobals: |
| 8873 |
+ name = VARIANT_NAME(variant, "InvocationFragmentGlobals"); |
| 8874 |
+ break; |
| 8875 |
+ case Type::Texture: |
| 8876 |
+ name = VARIANT_NAME(variant, "TextureEnvs"); |
| 8877 |
+ break; |
| 8878 |
+ case Type::InstanceId: |
| 8879 |
+ name = VARIANT_NAME(variant, "InstanceId"); |
| 8880 |
+ break; |
| 8881 |
+ } |
| 8882 |
+ return Name(name); |
| 8883 |
+} |
| 8884 |
+ |
| 8885 |
+Name Pipeline::getStructInstanceName(Variant variant) const |
| 8886 |
+{ |
| 8887 |
+ const char *name; |
| 8888 |
+ switch (type) |
| 8889 |
+ { |
| 8890 |
+ case Type::VertexIn: |
| 8891 |
+ name = VARIANT_NAME(variant, "vertexIn"); |
| 8892 |
+ break; |
| 8893 |
+ case Type::VertexOut: |
| 8894 |
+ name = VARIANT_NAME(variant, "vertexOut"); |
| 8895 |
+ break; |
| 8896 |
+ case Type::FragmentIn: |
| 8897 |
+ name = VARIANT_NAME(variant, "fragmentIn"); |
| 8898 |
+ break; |
| 8899 |
+ case Type::FragmentOut: |
| 8900 |
+ name = VARIANT_NAME(variant, "fragmentOut"); |
| 8901 |
+ break; |
| 8902 |
+ case Type::UserUniforms: |
| 8903 |
+ name = VARIANT_NAME(variant, "userUniforms"); |
| 8904 |
+ break; |
| 8905 |
+ case Type::AngleUniforms: |
| 8906 |
+ name = VARIANT_NAME(variant, "angleUniforms"); |
| 8907 |
+ break; |
| 8908 |
+ case Type::NonConstantGlobals: |
| 8909 |
+ name = VARIANT_NAME(variant, "nonConstGlobals"); |
| 8910 |
+ break; |
| 8911 |
+ case Type::InvocationVertexGlobals: |
| 8912 |
+ name = VARIANT_NAME(variant, "invocationVertexGlobals"); |
| 8913 |
+ break; |
| 8914 |
+ case Type::InvocationFragmentGlobals: |
| 8915 |
+ name = VARIANT_NAME(variant, "invocationFragmentGlobals"); |
| 8916 |
+ break; |
| 8917 |
+ case Type::Texture: |
| 8918 |
+ name = VARIANT_NAME(variant, "textureEnvs"); |
| 8919 |
+ break; |
| 8920 |
+ case Type::InstanceId: |
| 8921 |
+ name = VARIANT_NAME(variant, "instanceId"); |
| 8922 |
+ break; |
| 8923 |
+ } |
| 8924 |
+ return Name(name); |
| 8925 |
+} |
| 8926 |
+ |
| 8927 |
+static bool AllowPacking(Pipeline::Type type) |
| 8928 |
+{ |
| 8929 |
+ using Type = Pipeline::Type; |
| 8930 |
+ |
| 8931 |
+ switch (type) |
| 8932 |
+ { |
| 8933 |
+ case Type::UserUniforms: |
| 8934 |
+ return true; |
| 8935 |
+ |
| 8936 |
+ case Type::VertexIn: |
| 8937 |
+ case Type::VertexOut: |
| 8938 |
+ case Type::FragmentIn: |
| 8939 |
+ case Type::FragmentOut: |
| 8940 |
+ case Type::AngleUniforms: |
| 8941 |
+ case Type::NonConstantGlobals: |
| 8942 |
+ case Type::InvocationVertexGlobals: |
| 8943 |
+ case Type::InvocationFragmentGlobals: |
| 8944 |
+ case Type::Texture: |
| 8945 |
+ case Type::InstanceId: |
| 8946 |
+ return false; |
| 8947 |
+ } |
| 8948 |
+} |
| 8949 |
+ |
| 8950 |
+static bool AllowPadding(Pipeline::Type type) |
| 8951 |
+{ |
| 8952 |
+ using Type = Pipeline::Type; |
| 8953 |
+ |
| 8954 |
+ switch (type) |
| 8955 |
+ { |
| 8956 |
+ case Type::UserUniforms: |
| 8957 |
+ case Type::VertexIn: |
| 8958 |
+ case Type::VertexOut: |
| 8959 |
+ case Type::FragmentIn: |
| 8960 |
+ case Type::FragmentOut: |
| 8961 |
+ case Type::AngleUniforms: |
| 8962 |
+ case Type::NonConstantGlobals: |
| 8963 |
+ case Type::InvocationVertexGlobals: |
| 8964 |
+ case Type::InvocationFragmentGlobals: |
| 8965 |
+ return true; |
| 8966 |
+ |
| 8967 |
+ case Type::Texture: |
| 8968 |
+ case Type::InstanceId: |
| 8969 |
+ return false; |
| 8970 |
+ } |
| 8971 |
+} |
| 8972 |
+enum Compare |
| 8973 |
+{ |
| 8974 |
+ LT, |
| 8975 |
+ LTE, |
| 8976 |
+ EQ, |
| 8977 |
+ GTE, |
| 8978 |
+ GT, |
| 8979 |
+}; |
| 8980 |
+ |
| 8981 |
+template <typename T> |
| 8982 |
+static bool CompareBy(Compare op, const T &x, const T &y) |
| 8983 |
+{ |
| 8984 |
+ switch (op) |
| 8985 |
+ { |
| 8986 |
+ case LT: |
| 8987 |
+ return x < y; |
| 8988 |
+ case LTE: |
| 8989 |
+ return x <= y; |
| 8990 |
+ case EQ: |
| 8991 |
+ return x == y; |
| 8992 |
+ case GTE: |
| 8993 |
+ return x >= y; |
| 8994 |
+ case GT: |
| 8995 |
+ return x > y; |
| 8996 |
+ } |
| 8997 |
+} |
| 8998 |
+ |
| 8999 |
+template <TBasicType BT, Compare Cmp, int MatchDim, int NewDim> |
| 9000 |
+static int SaturateVectorOf(const TField &field) |
| 9001 |
+{ |
| 9002 |
+ static_assert(NewDim >= MatchDim, ""); |
| 9003 |
+ |
| 9004 |
+ const TType &type = *field.type(); |
| 9005 |
+ ASSERT(type.isScalar() || type.isVector()); |
| 9006 |
+ |
| 9007 |
+ const bool cond = type.getBasicType() == BT && !type.isArray() && |
| 9008 |
+ CompareBy(Cmp, type.getNominalSize(), MatchDim); |
| 9009 |
+ |
| 9010 |
+ if (cond) |
| 9011 |
+ { |
| 9012 |
+ return NewDim; |
| 9013 |
+ } |
| 9014 |
+ return 0; |
| 9015 |
+} |
| 9016 |
+ |
| 9017 |
+ModifyStructConfig Pipeline::externalStructModifyConfig() const |
| 9018 |
+{ |
| 9019 |
+ using Pred = ModifyStructConfig::Predicate; |
| 9020 |
+ using SatVec = ModifyStructConfig::SaturateVector; |
| 9021 |
+ |
| 9022 |
+ ModifyStructConfig config( |
| 9023 |
+ isPipelineOut() ? ConvertType::OriginalToModified : ConvertType::ModifiedToOriginal, |
| 9024 |
+ AllowPacking(type), AllowPadding(type)); |
| 9025 |
+ |
| 9026 |
+ config.externalAddressSpace = externalAddressSpace(); |
| 9027 |
+ |
| 9028 |
+ switch (type) |
| 9029 |
+ { |
| 9030 |
+ case Type::VertexIn: |
| 9031 |
+ config.inlineArray = Pred::True; |
| 9032 |
+ config.splitMatrixColumns = Pred::True; |
| 9033 |
+ config.inlineStruct = Pred::True; |
| 9034 |
+ break; |
| 9035 |
+ |
| 9036 |
+ case Type::VertexOut: |
| 9037 |
+ config.inlineArray = Pred::True; |
| 9038 |
+ config.splitMatrixColumns = Pred::True; |
| 9039 |
+ config.inlineStruct = Pred::True; |
| 9040 |
+ break; |
| 9041 |
+ |
| 9042 |
+ case Type::FragmentIn: |
| 9043 |
+ config.inlineArray = Pred::True; |
| 9044 |
+ config.splitMatrixColumns = Pred::True; |
| 9045 |
+ config.inlineStruct = Pred::True; |
| 9046 |
+ break; |
| 9047 |
+ |
| 9048 |
+ case Type::FragmentOut: |
| 9049 |
+ config.inlineArray = Pred::True; |
| 9050 |
+ config.splitMatrixColumns = Pred::True; |
| 9051 |
+ config.inlineStruct = Pred::True; |
| 9052 |
+ config.saturateScalarOrVector = [](const TField &field) { |
| 9053 |
+ if (int s = SaturateVectorOf<TBasicType::EbtInt, LT, 4, 4>(field)) |
| 9054 |
+ { |
| 9055 |
+ return s; |
| 9056 |
+ } |
| 9057 |
+ if (int s = SaturateVectorOf<TBasicType::EbtUInt, LT, 4, 4>(field)) |
| 9058 |
+ { |
| 9059 |
+ return s; |
| 9060 |
+ } |
| 9061 |
+ if (int s = SaturateVectorOf<TBasicType::EbtFloat, LT, 4, 4>(field)) |
| 9062 |
+ { |
| 9063 |
+ return s; |
| 9064 |
+ } |
| 9065 |
+ return 0; |
| 9066 |
+ }; |
| 9067 |
+ break; |
| 9068 |
+ |
| 9069 |
+ case Type::UserUniforms: |
| 9070 |
+ config.promoteBoolToUint = Pred::True; |
| 9071 |
+ config.saturateMatrixRows = SatVec::FullySaturate; |
| 9072 |
+ config.saturateScalarOrVectorArrays = SatVec::FullySaturate; |
| 9073 |
+ config.recurseStruct = Pred::True; |
| 9074 |
+ break; |
| 9075 |
+ |
| 9076 |
+ case Type::AngleUniforms: |
| 9077 |
+ config.initialBlockStorage = TLayoutBlockStorage::EbsStd430; // XXX: Correct? |
| 9078 |
+ break; |
| 9079 |
+ |
| 9080 |
+ case Type::NonConstantGlobals: |
| 9081 |
+ break; |
| 9082 |
+ |
| 9083 |
+ case Type::InvocationVertexGlobals: |
| 9084 |
+ case Type::InvocationFragmentGlobals: |
| 9085 |
+ case Type::Texture: |
| 9086 |
+ case Type::InstanceId: |
| 9087 |
+ break; |
| 9088 |
+ } |
| 9089 |
+ |
| 9090 |
+ return config; |
| 9091 |
+} |
| 9092 |
+ |
| 9093 |
+bool Pipeline::alwaysRequiresLocalVariableDeclarationInMain() const |
| 9094 |
+{ |
| 9095 |
+ switch (type) |
| 9096 |
+ { |
| 9097 |
+ case Type::VertexIn: |
| 9098 |
+ case Type::FragmentIn: |
| 9099 |
+ case Type::UserUniforms: |
| 9100 |
+ case Type::AngleUniforms: |
| 9101 |
+ return false; |
| 9102 |
+ |
| 9103 |
+ case Type::VertexOut: |
| 9104 |
+ case Type::FragmentOut: |
| 9105 |
+ case Type::NonConstantGlobals: |
| 9106 |
+ case Type::InvocationVertexGlobals: |
| 9107 |
+ case Type::InvocationFragmentGlobals: |
| 9108 |
+ case Type::Texture: |
| 9109 |
+ case Type::InstanceId: |
| 9110 |
+ return true; |
| 9111 |
+ } |
| 9112 |
+} |
| 9113 |
+ |
| 9114 |
+bool Pipeline::isPipelineOut() const |
| 9115 |
+{ |
| 9116 |
+ switch (type) |
| 9117 |
+ { |
| 9118 |
+ case Type::VertexIn: |
| 9119 |
+ case Type::FragmentIn: |
| 9120 |
+ case Type::UserUniforms: |
| 9121 |
+ case Type::AngleUniforms: |
| 9122 |
+ case Type::NonConstantGlobals: |
| 9123 |
+ case Type::InvocationVertexGlobals: |
| 9124 |
+ case Type::InvocationFragmentGlobals: |
| 9125 |
+ case Type::Texture: |
| 9126 |
+ case Type::InstanceId: |
| 9127 |
+ return false; |
| 9128 |
+ |
| 9129 |
+ case Type::VertexOut: |
| 9130 |
+ case Type::FragmentOut: |
| 9131 |
+ return true; |
| 9132 |
+ } |
| 9133 |
+} |
| 9134 |
+ |
| 9135 |
+AddressSpace Pipeline::externalAddressSpace() const |
| 9136 |
+{ |
| 9137 |
+ switch (type) |
| 9138 |
+ { |
| 9139 |
+ case Type::VertexIn: |
| 9140 |
+ case Type::FragmentIn: |
| 9141 |
+ case Type::NonConstantGlobals: |
| 9142 |
+ case Type::InvocationVertexGlobals: |
| 9143 |
+ case Type::InvocationFragmentGlobals: |
| 9144 |
+ case Type::Texture: |
| 9145 |
+ case Type::InstanceId: |
| 9146 |
+ case Type::FragmentOut: |
| 9147 |
+ case Type::VertexOut: |
| 9148 |
+ return AddressSpace::Thread; |
| 9149 |
+ |
| 9150 |
+ case Type::UserUniforms: |
| 9151 |
+ case Type::AngleUniforms: |
| 9152 |
+ return AddressSpace::Constant; |
| 9153 |
+ } |
| 9154 |
+} |
| 9155 |
+ |
| 9156 |
+bool PipelineStructs::matches(const TStructure &s, bool internal, bool external) const |
| 9157 |
+{ |
| 9158 |
+ PipelineScoped<TStructure> ps[] = { |
| 9159 |
+ fragmentIn, |
| 9160 |
+ fragmentOut, |
| 9161 |
+ vertexIn, |
| 9162 |
+ vertexOut, |
| 9163 |
+ userUniforms, |
| 9164 |
+ angleUniforms, |
| 9165 |
+ nonConstantGlobals, |
| 9166 |
+ invocationVertexGlobals, |
| 9167 |
+ invocationFragmentGlobals, |
| 9168 |
+ texture, |
| 9169 |
+ instanceId, |
| 9170 |
+ }; |
| 9171 |
+ for (const auto &p : ps) |
| 9172 |
+ { |
| 9173 |
+ if (internal && p.internal == &s) |
| 9174 |
+ { |
| 9175 |
+ return true; |
| 9176 |
+ } |
| 9177 |
+ if (external && p.external == &s) |
| 9178 |
+ { |
| 9179 |
+ return true; |
| 9180 |
+ } |
| 9181 |
+ } |
| 9182 |
+ return false; |
| 9183 |
+} |
| 9184 |
diff --git a/src/compiler/translator/TranslatorMetalDirect/Pipeline.h b/src/compiler/translator/TranslatorMetalDirect/Pipeline.h |
| 9185 |
new file mode 100644 |
| 9186 |
index 0000000..9bf476a |
| 9187 |
--- /dev/null |
| 9188 |
+++ b/src/compiler/translator/TranslatorMetalDirect/Pipeline.h |
| 9189 |
@@ -0,0 +1,123 @@ |
| 9190 |
+// |
| 9191 |
+// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 9192 |
+// Use of this source code is governed by a BSD-style license that can be |
| 9193 |
+// found in the LICENSE file. |
| 9194 |
+// |
| 9195 |
+ |
| 9196 |
+#ifndef COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_PIPELINE_H_ |
| 9197 |
+#define COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_PIPELINE_H_ |
| 9198 |
+ |
| 9199 |
+#include "compiler/translator/Symbol.h" |
| 9200 |
+#include "compiler/translator/TranslatorMetalDirect/ModifyStruct.h" |
| 9201 |
+#include "compiler/translator/TranslatorMetalDirect/Name.h" |
| 9202 |
+#include "compiler/translator/TranslatorMetalDirect/SymbolEnv.h" |
| 9203 |
+ |
| 9204 |
+namespace sh |
| 9205 |
+{ |
| 9206 |
+ |
| 9207 |
+// Data that is scoped as `external` and `internal` for a given pipeline. |
| 9208 |
+template <typename T> |
| 9209 |
+struct PipelineScoped |
| 9210 |
+{ |
| 9211 |
+ // Data that is configured to talk externally to the program. |
| 9212 |
+ // May coincide with `internal`, but may also diverge from `internal`. |
| 9213 |
+ const T *external = nullptr; |
| 9214 |
+ |
| 9215 |
+ // Data that is configured to talk internally within the program. |
| 9216 |
+ // May coincide with `external`, but may also diverge from `external`. |
| 9217 |
+ const T *internal = nullptr; |
| 9218 |
+ |
| 9219 |
+ // Returns true iff the input coincides with either `external` or `internal` data. |
| 9220 |
+ bool matches(const T &object) const { return external == &object || internal == &object; } |
| 9221 |
+ |
| 9222 |
+ // Both `external` and `internal` representations are non-null. |
| 9223 |
+ bool isTotallyFull() const { return external && internal; } |
| 9224 |
+ |
| 9225 |
+ // Both `external` and `internal` representations are null. |
| 9226 |
+ bool isTotallyEmpty() const { return !external && !internal; } |
| 9227 |
+ |
| 9228 |
+ // Both `external` and `internal` representations are the same. |
| 9229 |
+ bool isUniform() const { return external == internal; } |
| 9230 |
+}; |
| 9231 |
+ |
| 9232 |
+// Represents a high-level program pipeline. |
| 9233 |
+class Pipeline |
| 9234 |
+{ |
| 9235 |
+ public: |
| 9236 |
+ enum class Type |
| 9237 |
+ { |
| 9238 |
+ VertexIn, |
| 9239 |
+ VertexOut, |
| 9240 |
+ FragmentIn, |
| 9241 |
+ FragmentOut, |
| 9242 |
+ UserUniforms, |
| 9243 |
+ AngleUniforms, |
| 9244 |
+ NonConstantGlobals, |
| 9245 |
+ InvocationVertexGlobals, |
| 9246 |
+ InvocationFragmentGlobals, |
| 9247 |
+ Texture, |
| 9248 |
+ InstanceId, |
| 9249 |
+ }; |
| 9250 |
+ |
| 9251 |
+ enum class Variant |
| 9252 |
+ { |
| 9253 |
+ // For all internal pipeline uses. |
| 9254 |
+ // For external pipeline uses if pipeline does not require splitting or saturation. |
| 9255 |
+ Original, |
| 9256 |
+ |
| 9257 |
+ // Only for external pipeline uses if the pipeline was split or saturated. |
| 9258 |
+ Modified, |
| 9259 |
+ }; |
| 9260 |
+ |
| 9261 |
+ public: |
| 9262 |
+ // The type of the pipeline. |
| 9263 |
+ Type type; |
| 9264 |
+ |
| 9265 |
+ // Non-null if a global instance of the pipeline struct already exists. |
| 9266 |
+ // If non-null struct splitting should not be needed. |
| 9267 |
+ const TVariable *globalInstanceVar; |
| 9268 |
+ |
| 9269 |
+ public: |
| 9270 |
+ // Returns true iff the variable belongs to the pipeline. |
| 9271 |
+ bool uses(const TVariable &var) const; |
| 9272 |
+ |
| 9273 |
+ // Returns the name for the struct type that stores variables of this pipeline. |
| 9274 |
+ Name getStructTypeName(Variant variant) const; |
| 9275 |
+ |
| 9276 |
+ // Returns the name for the struct instance that stores variables of this pipeline. |
| 9277 |
+ Name getStructInstanceName(Variant variant) const; |
| 9278 |
+ |
| 9279 |
+ ModifyStructConfig externalStructModifyConfig() const; |
| 9280 |
+ |
| 9281 |
+ // Returns true if the pipeline always requires a non-parameter local instance declaration of |
| 9282 |
+ // the pipeline structures. |
| 9283 |
+ bool alwaysRequiresLocalVariableDeclarationInMain() const; |
| 9284 |
+ |
| 9285 |
+ // Returns true iff the pipeline is an output pipeline. The external pipeline structure should |
| 9286 |
+ // be returned from `main`. |
| 9287 |
+ bool isPipelineOut() const; |
| 9288 |
+ |
| 9289 |
+ AddressSpace externalAddressSpace() const; |
| 9290 |
+}; |
| 9291 |
+ |
| 9292 |
+// A collection of various pipeline structures. |
| 9293 |
+struct PipelineStructs : angle::NonCopyable |
| 9294 |
+{ |
| 9295 |
+ PipelineScoped<TStructure> fragmentIn; |
| 9296 |
+ PipelineScoped<TStructure> fragmentOut; |
| 9297 |
+ PipelineScoped<TStructure> vertexIn; |
| 9298 |
+ PipelineScoped<TStructure> vertexOut; |
| 9299 |
+ PipelineScoped<TStructure> userUniforms; |
| 9300 |
+ PipelineScoped<TStructure> angleUniforms; |
| 9301 |
+ PipelineScoped<TStructure> nonConstantGlobals; |
| 9302 |
+ PipelineScoped<TStructure> invocationVertexGlobals; |
| 9303 |
+ PipelineScoped<TStructure> invocationFragmentGlobals; |
| 9304 |
+ PipelineScoped<TStructure> texture; |
| 9305 |
+ PipelineScoped<TStructure> instanceId; |
| 9306 |
+ |
| 9307 |
+ bool matches(const TStructure &s, bool internal, bool external) const; |
| 9308 |
+}; |
| 9309 |
+ |
| 9310 |
+} // namespace sh |
| 9311 |
+ |
| 9312 |
+#endif // COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_PIPELINE_H_ |
| 9313 |
diff --git a/src/compiler/translator/TranslatorMetalDirect/ProgramPrelude.cpp b/src/compiler/translator/TranslatorMetalDirect/ProgramPrelude.cpp |
| 9314 |
new file mode 100644 |
| 9315 |
index 0000000..8bf5a02 |
| 9316 |
--- /dev/null |
| 9317 |
+++ b/src/compiler/translator/TranslatorMetalDirect/ProgramPrelude.cpp |
| 9318 |
@@ -0,0 +1,3757 @@ |
| 9319 |
+// |
| 9320 |
+// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 9321 |
+// Use of this source code is governed by a BSD-style license that can be |
| 9322 |
+// found in the LICENSE file. |
| 9323 |
+// |
| 9324 |
+ |
| 9325 |
+#include <cctype> |
| 9326 |
+ |
| 9327 |
+#include "compiler/translator/InfoSink.h" |
| 9328 |
+#include "compiler/translator/Symbol.h" |
| 9329 |
+#include "compiler/translator/TranslatorMetalDirect/AstHelpers.h" |
| 9330 |
+#include "compiler/translator/TranslatorMetalDirect/ConstantNames.h" |
| 9331 |
+#include "compiler/translator/TranslatorMetalDirect/Debug.h" |
| 9332 |
+#include "compiler/translator/TranslatorMetalDirect/Name.h" |
| 9333 |
+#include "compiler/translator/TranslatorMetalDirect/ProgramPrelude.h" |
| 9334 |
+#include "compiler/translator/tree_util/IntermTraverse.h" |
| 9335 |
+ |
| 9336 |
+using namespace sh; |
| 9337 |
+ |
| 9338 |
+//////////////////////////////////////////////////////////////////////////////// |
| 9339 |
+ |
| 9340 |
+namespace |
| 9341 |
+{ |
| 9342 |
+ |
| 9343 |
+class ProgramPrelude : public TIntermTraverser |
| 9344 |
+{ |
| 9345 |
+ using LineTag = unsigned; |
| 9346 |
+ using FuncEmitter = void (*)(ProgramPrelude &, const TFunction &); |
| 9347 |
+ using FuncToEmitter = std::map<Name, FuncEmitter>; |
| 9348 |
+ |
| 9349 |
+ public: |
| 9350 |
+ ProgramPrelude(TInfoSinkBase &out, const ProgramPreludeConfig &ppc) |
| 9351 |
+ : TIntermTraverser(true, false, false), mOut(out) |
| 9352 |
+ { |
| 9353 |
+ ALWAYS_INLINE(); |
| 9354 |
+ |
| 9355 |
+ if (ppc.hasStructEq) |
| 9356 |
+ { |
| 9357 |
+ equalVector(); |
| 9358 |
+ equalMatrix(); |
| 9359 |
+ } |
| 9360 |
+ |
| 9361 |
+#if 1 |
| 9362 |
+ mOut << "#define ANGLE_tensor metal::array\n"; |
| 9363 |
+#else |
| 9364 |
+ tensor(); |
| 9365 |
+#endif |
| 9366 |
+ } |
| 9367 |
+ |
| 9368 |
+ private: |
| 9369 |
+ bool emitGuard(LineTag lineTag) |
| 9370 |
+ { |
| 9371 |
+ if (mEmitted.find(lineTag) != mEmitted.end()) |
| 9372 |
+ { |
| 9373 |
+ return false; |
| 9374 |
+ } |
| 9375 |
+ mEmitted.insert(lineTag); |
| 9376 |
+ return true; |
| 9377 |
+ } |
| 9378 |
+ |
| 9379 |
+ static FuncToEmitter BuildFuncToEmitter(); |
| 9380 |
+ |
| 9381 |
+ void visitOperator(TOperator op, |
| 9382 |
+ const TFunction *func, |
| 9383 |
+ const TType *argType0, |
| 9384 |
+ const TType *argType1 = nullptr); |
| 9385 |
+ void visitVariable(const Name &name, const TType &type); |
| 9386 |
+ void visitVariable(const TVariable &var); |
| 9387 |
+ void visitStructure(const TStructure &s); |
| 9388 |
+ |
| 9389 |
+ bool visitBinary(Visit, TIntermBinary *node) override; |
| 9390 |
+ bool visitUnary(Visit, TIntermUnary *node) override; |
| 9391 |
+ bool visitAggregate(Visit, TIntermAggregate *node) override; |
| 9392 |
+ bool visitDeclaration(Visit, TIntermDeclaration *node) override; |
| 9393 |
+ void visitSymbol(TIntermSymbol *node) override; |
| 9394 |
+ |
| 9395 |
+ private: |
| 9396 |
+ void ALWAYS_INLINE(); |
| 9397 |
+ |
| 9398 |
+ void include_metal_atomic(); |
| 9399 |
+ void include_metal_common(); |
| 9400 |
+ void include_metal_geometric(); |
| 9401 |
+ void include_metal_graphics(); |
| 9402 |
+ void include_metal_math(); |
| 9403 |
+ void include_metal_matrix(); |
| 9404 |
+ void include_metal_pack(); |
| 9405 |
+ void include_metal_relational(); |
| 9406 |
+ |
| 9407 |
+ void enable_if(); |
| 9408 |
+ void scalar_of(); |
| 9409 |
+ void is_scalar(); |
| 9410 |
+ void is_vector(); |
| 9411 |
+ void is_matrix(); |
| 9412 |
+ void addressof(); |
| 9413 |
+ void distance(); |
| 9414 |
+ void length(); |
| 9415 |
+ void dot(); |
| 9416 |
+ void normalize(); |
| 9417 |
+ void faceforward(); |
| 9418 |
+ void reflect(); |
| 9419 |
+ void refract(); |
| 9420 |
+ void degrees(); |
| 9421 |
+ void radians(); |
| 9422 |
+ void mod(); |
| 9423 |
+ void postIncrementMatrix(); |
| 9424 |
+ void preIncrementMatrix(); |
| 9425 |
+ void postDecrementMatrix(); |
| 9426 |
+ void preDecrementMatrix(); |
| 9427 |
+ void negateMatrix(); |
| 9428 |
+ void matmulAssign(); |
| 9429 |
+ void atan(); |
| 9430 |
+ void addMatrixScalarAssign(); |
| 9431 |
+ void subMatrixScalarAssign(); |
| 9432 |
+ void addMatrixScalar(); |
| 9433 |
+ void subMatrixScalar(); |
| 9434 |
+ void divMatrixScalar(); |
| 9435 |
+ void divMatrixScalarFast(); |
| 9436 |
+ void divMatrixScalarAssign(); |
| 9437 |
+ void divMatrixScalarAssignFast(); |
| 9438 |
+ void tensor(); |
| 9439 |
+ void componentWiseDivide(); |
| 9440 |
+ void componentWiseDivideAssign(); |
| 9441 |
+ void componentWiseMultiply(); |
| 9442 |
+ void outerProduct(); |
| 9443 |
+ void inverse2(); |
| 9444 |
+ void inverse3(); |
| 9445 |
+ void inverse4(); |
| 9446 |
+ void equalVector(); |
| 9447 |
+ void equalMatrix(); |
| 9448 |
+ void notEqualVector(); |
| 9449 |
+ void notEqualStruct(); |
| 9450 |
+ void equalArray(); |
| 9451 |
+ void notEqualArray(); |
| 9452 |
+ void sign(); |
| 9453 |
+ void pack_half_2x16(); |
| 9454 |
+ void unpack_half_2x16(); |
| 9455 |
+ void vectorElemRef(); |
| 9456 |
+ void swizzleRef(); |
| 9457 |
+ void out(); |
| 9458 |
+ void inout(); |
| 9459 |
+ void flattenArray(); |
| 9460 |
+ void castVector(); |
| 9461 |
+ void castMatrix(); |
| 9462 |
+ void functionConstants(); |
| 9463 |
+ void gradient(); |
| 9464 |
+ void textureEnv(); |
| 9465 |
+ void texelFetch(); |
| 9466 |
+ void texelFetchOffset(); |
| 9467 |
+ void texture(); |
| 9468 |
+ void texture_generic_float2(); |
| 9469 |
+ void texture_generic_float2_float(); |
| 9470 |
+ void texture_generic_float3(); |
| 9471 |
+ void texture_generic_float3_float(); |
| 9472 |
+ void texture_depth2d_float3(); |
| 9473 |
+ void texture_depth2d_float3_float(); |
| 9474 |
+ void texture_depth2darray_float4(); |
| 9475 |
+ void texture_depth2darray_float4_float(); |
| 9476 |
+ void texture_depthcube_float4(); |
| 9477 |
+ void texture_depthcube_float4_float(); |
| 9478 |
+ void texture_texture2darray_float3(); |
| 9479 |
+ void texture_texture2darray_float3_float(); |
| 9480 |
+ void texture_texture2darray_float4(); |
| 9481 |
+ void texture_texture2darray_float4_float(); |
| 9482 |
+ void texture1DLod(); |
| 9483 |
+ void texture1DProj(); |
| 9484 |
+ void texture1DProjLod(); |
| 9485 |
+ void texture2D(); |
| 9486 |
+ void texture2DLod(); |
| 9487 |
+ void texture2DProj(); |
| 9488 |
+ void texture2DProjLod(); |
| 9489 |
+ void texture3DLod(); |
| 9490 |
+ void texture3DProj(); |
| 9491 |
+ void texture3DProjLod(); |
| 9492 |
+ void textureCube(); |
| 9493 |
+ void textureCubeLod(); |
| 9494 |
+ void textureCubeProj(); |
| 9495 |
+ void textureCubeProjLod(); |
| 9496 |
+ void textureGrad(); |
| 9497 |
+ void textureGrad_generic_floatN_floatN_floatN(); |
| 9498 |
+ void textureGrad_generic_float3_float2_float2(); |
| 9499 |
+ void textureGrad_generic_float4_float2_float2(); |
| 9500 |
+ void textureGrad_depth2d_float3_float2_float2(); |
| 9501 |
+ void textureGrad_depth2darray_float4_float2_float2(); |
| 9502 |
+ void textureGrad_depthcube_float4_float3_float3(); |
| 9503 |
+ void textureGrad_texturecube_float3_float3_float3(); |
| 9504 |
+ void textureGradOffset(); |
| 9505 |
+ void textureGradOffset_generic_floatN_floatN_floatN_intN(); |
| 9506 |
+ void textureGradOffset_generic_float3_float2_float2_int2(); |
| 9507 |
+ void textureGradOffset_generic_float4_float2_float2_int2(); |
| 9508 |
+ void textureGradOffset_depth2d_float3_float2_float2_int2(); |
| 9509 |
+ void textureGradOffset_depth2darray_float4_float2_float2_int2(); |
| 9510 |
+ void textureGradOffset_depthcube_float4_float3_float3_int3(); |
| 9511 |
+ void textureGradOffset_texturecube_float3_float3_float3_int3(); |
| 9512 |
+ void textureLod(); |
| 9513 |
+ void textureLod_generic_float2(); |
| 9514 |
+ void textureLod_generic_float3(); |
| 9515 |
+ void textureLod_depth2d_float3(); |
| 9516 |
+ void textureLod_texture2darray_float3(); |
| 9517 |
+ void textureLod_texture2darray_float4(); |
| 9518 |
+ void textureLodOffset(); |
| 9519 |
+ void textureOffset(); |
| 9520 |
+ void textureProj(); |
| 9521 |
+ void textureProjGrad(); |
| 9522 |
+ void textureProjGrad_generic_float3_float2_float2(); |
| 9523 |
+ void textureProjGrad_generic_float4_float2_float2(); |
| 9524 |
+ void textureProjGrad_depth2d_float4_float2_float2(); |
| 9525 |
+ void textureProjGrad_texture3d_float4_float3_float3(); |
| 9526 |
+ void textureProjGradOffset(); |
| 9527 |
+ void textureProjGradOffset_generic_float3_float2_float2_int2(); |
| 9528 |
+ void textureProjGradOffset_generic_float4_float2_float2_int2(); |
| 9529 |
+ void textureProjGradOffset_depth2d_float4_float2_float2_int2(); |
| 9530 |
+ void textureProjGradOffset_texture3d_float4_float3_float3_int3(); |
| 9531 |
+ void textureProjLod(); |
| 9532 |
+ void textureProjLod_generic_float3(); |
| 9533 |
+ void textureProjLod_generic_float4(); |
| 9534 |
+ void textureProjLod_depth2d_float4(); |
| 9535 |
+ void textureProjLod_texture3d_float4(); |
| 9536 |
+ void textureProjLodOffset(); |
| 9537 |
+ void textureProjOffset(); |
| 9538 |
+ void textureSize(); |
| 9539 |
+ |
| 9540 |
+ private: |
| 9541 |
+ TInfoSinkBase &mOut; |
| 9542 |
+ std::unordered_set<LineTag> mEmitted; |
| 9543 |
+ std::unordered_set<const TSymbol *> mHandled; |
| 9544 |
+ const FuncToEmitter mFuncToEmitter = BuildFuncToEmitter(); |
| 9545 |
+}; |
| 9546 |
+ |
| 9547 |
+} // anonymous namespace |
| 9548 |
+ |
| 9549 |
+//////////////////////////////////////////////////////////////////////////////// |
| 9550 |
+ |
| 9551 |
+#define PROGRAM_PRELUDE_INCLUDE(header) \ |
| 9552 |
+ void ProgramPrelude::include_##header() \ |
| 9553 |
+ { \ |
| 9554 |
+ if (emitGuard(__LINE__)) \ |
| 9555 |
+ { \ |
| 9556 |
+ mOut << ("#include <" #header ">\n\n"); \ |
| 9557 |
+ } \ |
| 9558 |
+ } |
| 9559 |
+ |
| 9560 |
+#define PROGRAM_PRELUDE_DECLARE(name, code, ...) \ |
| 9561 |
+ void ProgramPrelude::name() \ |
| 9562 |
+ { \ |
| 9563 |
+ ASSERT(code[0] == '\n'); \ |
| 9564 |
+ if (emitGuard(__LINE__)) \ |
| 9565 |
+ { \ |
| 9566 |
+ __VA_ARGS__; /* dependencies */ \ |
| 9567 |
+ mOut << (static_cast<const char *>(code "\n") + 1); \ |
| 9568 |
+ } \ |
| 9569 |
+ } |
| 9570 |
+ |
| 9571 |
+//////////////////////////////////////////////////////////////////////////////// |
| 9572 |
+ |
| 9573 |
+PROGRAM_PRELUDE_INCLUDE(metal_atomic) |
| 9574 |
+PROGRAM_PRELUDE_INCLUDE(metal_common) |
| 9575 |
+PROGRAM_PRELUDE_INCLUDE(metal_geometric) |
| 9576 |
+PROGRAM_PRELUDE_INCLUDE(metal_graphics) |
| 9577 |
+PROGRAM_PRELUDE_INCLUDE(metal_math) |
| 9578 |
+PROGRAM_PRELUDE_INCLUDE(metal_matrix) |
| 9579 |
+PROGRAM_PRELUDE_INCLUDE(metal_pack) |
| 9580 |
+PROGRAM_PRELUDE_INCLUDE(metal_relational) |
| 9581 |
+ |
| 9582 |
+//////////////////////////////////////////////////////////////////////////////// |
| 9583 |
+ |
| 9584 |
+PROGRAM_PRELUDE_DECLARE(ALWAYS_INLINE, R"( |
| 9585 |
+#define ANGLE_ALWAYS_INLINE __attribute__((always_inline)) |
| 9586 |
+)") |
| 9587 |
+ |
| 9588 |
+PROGRAM_PRELUDE_DECLARE(enable_if, R"( |
| 9589 |
+template <bool B, typename T = void> |
| 9590 |
+struct ANGLE_enable_if {}; |
| 9591 |
+template <typename T> |
| 9592 |
+struct ANGLE_enable_if<true, T> |
| 9593 |
+{ |
| 9594 |
+ using type = T; |
| 9595 |
+}; |
| 9596 |
+template <bool B> |
| 9597 |
+using ANGLE_enable_if_t = typename ANGLE_enable_if<B>::type; |
| 9598 |
+)") |
| 9599 |
+ |
| 9600 |
+PROGRAM_PRELUDE_DECLARE(scalar_of, R"( |
| 9601 |
+template <typename T> |
| 9602 |
+struct ANGLE_scalar_of |
| 9603 |
+{ |
| 9604 |
+ using type = T; |
| 9605 |
+}; |
| 9606 |
+template <typename T> |
| 9607 |
+using ANGLE_scalar_of_t = typename ANGLE_scalar_of<T>::type; |
| 9608 |
+)") |
| 9609 |
+ |
| 9610 |
+PROGRAM_PRELUDE_DECLARE(is_scalar, R"( |
| 9611 |
+template <typename T> |
| 9612 |
+struct ANGLE_is_scalar {}; |
| 9613 |
+#define ANGLE_DEFINE_SCALAR(scalar) \ |
| 9614 |
+ template <> struct ANGLE_is_scalar<scalar> { enum { value = true }; } |
| 9615 |
+ANGLE_DEFINE_SCALAR(bool); |
| 9616 |
+ANGLE_DEFINE_SCALAR(char); |
| 9617 |
+ANGLE_DEFINE_SCALAR(short); |
| 9618 |
+ANGLE_DEFINE_SCALAR(int); |
| 9619 |
+ANGLE_DEFINE_SCALAR(long); |
| 9620 |
+ANGLE_DEFINE_SCALAR(uchar); |
| 9621 |
+ANGLE_DEFINE_SCALAR(ushort); |
| 9622 |
+ANGLE_DEFINE_SCALAR(uint); |
| 9623 |
+ANGLE_DEFINE_SCALAR(ulong); |
| 9624 |
+ANGLE_DEFINE_SCALAR(half); |
| 9625 |
+ANGLE_DEFINE_SCALAR(float); |
| 9626 |
+)") |
| 9627 |
+ |
| 9628 |
+PROGRAM_PRELUDE_DECLARE(is_vector, |
| 9629 |
+ R"( |
| 9630 |
+template <typename T> |
| 9631 |
+struct ANGLE_is_vector |
| 9632 |
+{ |
| 9633 |
+ enum { value = false }; |
| 9634 |
+}; |
| 9635 |
+#define ANGLE_DEFINE_VECTOR(scalar) \ |
| 9636 |
+ template <> struct ANGLE_is_vector<metal::scalar ## 2> { enum { value = true }; }; \ |
| 9637 |
+ template <> struct ANGLE_is_vector<metal::scalar ## 3> { enum { value = true }; }; \ |
| 9638 |
+ template <> struct ANGLE_is_vector<metal::scalar ## 4> { enum { value = true }; }; \ |
| 9639 |
+ template <> struct ANGLE_scalar_of<metal::scalar ## 2> { using type = scalar; }; \ |
| 9640 |
+ template <> struct ANGLE_scalar_of<metal::scalar ## 3> { using type = scalar; }; \ |
| 9641 |
+ template <> struct ANGLE_scalar_of<metal::scalar ## 4> { using type = scalar; } |
| 9642 |
+ANGLE_DEFINE_VECTOR(bool); |
| 9643 |
+ANGLE_DEFINE_VECTOR(char); |
| 9644 |
+ANGLE_DEFINE_VECTOR(short); |
| 9645 |
+ANGLE_DEFINE_VECTOR(int); |
| 9646 |
+ANGLE_DEFINE_VECTOR(long); |
| 9647 |
+ANGLE_DEFINE_VECTOR(uchar); |
| 9648 |
+ANGLE_DEFINE_VECTOR(ushort); |
| 9649 |
+ANGLE_DEFINE_VECTOR(uint); |
| 9650 |
+ANGLE_DEFINE_VECTOR(ulong); |
| 9651 |
+ANGLE_DEFINE_VECTOR(half); |
| 9652 |
+ANGLE_DEFINE_VECTOR(float); |
| 9653 |
+)", |
| 9654 |
+ scalar_of()) |
| 9655 |
+ |
| 9656 |
+PROGRAM_PRELUDE_DECLARE(is_matrix, |
| 9657 |
+ R"( |
| 9658 |
+template <typename T> |
| 9659 |
+struct ANGLE_is_matrix |
| 9660 |
+{ |
| 9661 |
+ enum { value = false }; |
| 9662 |
+}; |
| 9663 |
+#define ANGLE_DEFINE_MATRIX(scalar) \ |
| 9664 |
+ template <> struct ANGLE_is_matrix<metal::scalar ## 2x2> { enum { value = true }; }; \ |
| 9665 |
+ template <> struct ANGLE_is_matrix<metal::scalar ## 2x3> { enum { value = true }; }; \ |
| 9666 |
+ template <> struct ANGLE_is_matrix<metal::scalar ## 2x4> { enum { value = true }; }; \ |
| 9667 |
+ template <> struct ANGLE_is_matrix<metal::scalar ## 3x2> { enum { value = true }; }; \ |
| 9668 |
+ template <> struct ANGLE_is_matrix<metal::scalar ## 3x3> { enum { value = true }; }; \ |
| 9669 |
+ template <> struct ANGLE_is_matrix<metal::scalar ## 3x4> { enum { value = true }; }; \ |
| 9670 |
+ template <> struct ANGLE_is_matrix<metal::scalar ## 4x2> { enum { value = true }; }; \ |
| 9671 |
+ template <> struct ANGLE_is_matrix<metal::scalar ## 4x3> { enum { value = true }; }; \ |
| 9672 |
+ template <> struct ANGLE_is_matrix<metal::scalar ## 4x4> { enum { value = true }; }; \ |
| 9673 |
+ template <> struct ANGLE_scalar_of<metal::scalar ## 2x2> { using type = scalar; }; \ |
| 9674 |
+ template <> struct ANGLE_scalar_of<metal::scalar ## 2x3> { using type = scalar; }; \ |
| 9675 |
+ template <> struct ANGLE_scalar_of<metal::scalar ## 2x4> { using type = scalar; }; \ |
| 9676 |
+ template <> struct ANGLE_scalar_of<metal::scalar ## 3x2> { using type = scalar; }; \ |
| 9677 |
+ template <> struct ANGLE_scalar_of<metal::scalar ## 3x3> { using type = scalar; }; \ |
| 9678 |
+ template <> struct ANGLE_scalar_of<metal::scalar ## 3x4> { using type = scalar; }; \ |
| 9679 |
+ template <> struct ANGLE_scalar_of<metal::scalar ## 4x2> { using type = scalar; }; \ |
| 9680 |
+ template <> struct ANGLE_scalar_of<metal::scalar ## 4x3> { using type = scalar; }; \ |
| 9681 |
+ template <> struct ANGLE_scalar_of<metal::scalar ## 4x4> { using type = scalar; } |
| 9682 |
+ANGLE_DEFINE_MATRIX(half); |
| 9683 |
+ANGLE_DEFINE_MATRIX(float); |
| 9684 |
+)", |
| 9685 |
+ scalar_of()) |
| 9686 |
+ |
| 9687 |
+PROGRAM_PRELUDE_DECLARE(addressof, |
| 9688 |
+ R"( |
| 9689 |
+template <typename T> |
| 9690 |
+ANGLE_ALWAYS_INLINE thread T * ANGLE_addressof(thread T &ref) |
| 9691 |
+{ |
| 9692 |
+ return &ref; |
| 9693 |
+} |
| 9694 |
+)") |
| 9695 |
+ |
| 9696 |
+PROGRAM_PRELUDE_DECLARE(distance, |
| 9697 |
+ R"( |
| 9698 |
+template <typename T, typename Enable = void> |
| 9699 |
+struct ANGLE_distance_impl |
| 9700 |
+{ |
| 9701 |
+ static ANGLE_ALWAYS_INLINE ANGLE_scalar_of_t<T> exec(T x, T y) |
| 9702 |
+ { |
| 9703 |
+ return metal::distance(x, y); |
| 9704 |
+ } |
| 9705 |
+}; |
| 9706 |
+template <typename T> |
| 9707 |
+struct ANGLE_distance_impl<T, ANGLE_enable_if_t<ANGLE_is_scalar<T>::value>> |
| 9708 |
+{ |
| 9709 |
+ static ANGLE_ALWAYS_INLINE T exec(T x, T y) |
| 9710 |
+ { |
| 9711 |
+ return metal::abs(x - y); |
| 9712 |
+ } |
| 9713 |
+}; |
| 9714 |
+template <typename T> |
| 9715 |
+ANGLE_ALWAYS_INLINE ANGLE_scalar_of_t<T> ANGLE_distance(T x, T y) |
| 9716 |
+{ |
| 9717 |
+ return ANGLE_distance_impl<T>::exec(x, y); |
| 9718 |
+}; |
| 9719 |
+)", |
| 9720 |
+ include_metal_geometric(), |
| 9721 |
+ include_metal_math(), |
| 9722 |
+ enable_if(), |
| 9723 |
+ is_scalar(), |
| 9724 |
+ is_vector(), |
| 9725 |
+ is_matrix()) |
| 9726 |
+ |
| 9727 |
+PROGRAM_PRELUDE_DECLARE(length, |
| 9728 |
+ R"( |
| 9729 |
+template <typename T, typename Enable = void> |
| 9730 |
+struct ANGLE_length_impl |
| 9731 |
+{ |
| 9732 |
+ static ANGLE_ALWAYS_INLINE ANGLE_scalar_of_t<T> exec(T x) |
| 9733 |
+ { |
| 9734 |
+ return metal::length(x); |
| 9735 |
+ } |
| 9736 |
+}; |
| 9737 |
+template <typename T> |
| 9738 |
+struct ANGLE_length_impl<T, ANGLE_enable_if_t<ANGLE_is_scalar<T>::value>> |
| 9739 |
+{ |
| 9740 |
+ static ANGLE_ALWAYS_INLINE T exec(T x) |
| 9741 |
+ { |
| 9742 |
+ return metal::abs(x); |
| 9743 |
+ } |
| 9744 |
+}; |
| 9745 |
+template <typename T> |
| 9746 |
+ANGLE_ALWAYS_INLINE ANGLE_scalar_of_t<T> ANGLE_length(T x) |
| 9747 |
+{ |
| 9748 |
+ return ANGLE_length_impl<T>::exec(x); |
| 9749 |
+}; |
| 9750 |
+)", |
| 9751 |
+ include_metal_geometric(), |
| 9752 |
+ include_metal_math(), |
| 9753 |
+ enable_if(), |
| 9754 |
+ is_scalar(), |
| 9755 |
+ is_vector(), |
| 9756 |
+ is_matrix()) |
| 9757 |
+ |
| 9758 |
+PROGRAM_PRELUDE_DECLARE(dot, |
| 9759 |
+ R"( |
| 9760 |
+template <typename T, typename Enable = void> |
| 9761 |
+struct ANGLE_dot_impl |
| 9762 |
+{ |
| 9763 |
+ static ANGLE_ALWAYS_INLINE ANGLE_scalar_of_t<T> exec(T x, T y) |
| 9764 |
+ { |
| 9765 |
+ return metal::dot(x, y); |
| 9766 |
+ } |
| 9767 |
+}; |
| 9768 |
+template <typename T> |
| 9769 |
+struct ANGLE_dot_impl<T, ANGLE_enable_if_t<ANGLE_is_scalar<T>::value>> |
| 9770 |
+{ |
| 9771 |
+ static ANGLE_ALWAYS_INLINE T exec(T x, T y) |
| 9772 |
+ { |
| 9773 |
+ return x * y; |
| 9774 |
+ } |
| 9775 |
+}; |
| 9776 |
+template <typename T> |
| 9777 |
+ANGLE_ALWAYS_INLINE ANGLE_scalar_of_t<T> ANGLE_dot(T x, T y) |
| 9778 |
+{ |
| 9779 |
+ return ANGLE_dot_impl<T>::exec(x, y); |
| 9780 |
+}; |
| 9781 |
+)", |
| 9782 |
+ include_metal_geometric(), |
| 9783 |
+ enable_if(), |
| 9784 |
+ is_scalar(), |
| 9785 |
+ is_vector(), |
| 9786 |
+ is_matrix()) |
| 9787 |
+ |
| 9788 |
+PROGRAM_PRELUDE_DECLARE(normalize, |
| 9789 |
+ R"( |
| 9790 |
+template <typename T, typename Enable = void> |
| 9791 |
+struct ANGLE_normalize_impl |
| 9792 |
+{ |
| 9793 |
+ static ANGLE_ALWAYS_INLINE T exec(T x) |
| 9794 |
+ { |
| 9795 |
+ return metal::normalize(x); |
| 9796 |
+ } |
| 9797 |
+}; |
| 9798 |
+template <typename T> |
| 9799 |
+struct ANGLE_normalize_impl<T, ANGLE_enable_if_t<ANGLE_is_scalar<T>::value>> |
| 9800 |
+{ |
| 9801 |
+ static ANGLE_ALWAYS_INLINE T exec(T x) |
| 9802 |
+ { |
| 9803 |
+ return ANGLE_sign(x); |
| 9804 |
+ } |
| 9805 |
+}; |
| 9806 |
+template <typename T> |
| 9807 |
+ANGLE_ALWAYS_INLINE T ANGLE_normalize(T x) |
| 9808 |
+{ |
| 9809 |
+ return ANGLE_normalize_impl<T>::exec(x); |
| 9810 |
+}; |
| 9811 |
+)", |
| 9812 |
+ include_metal_common(), |
| 9813 |
+ include_metal_geometric(), |
| 9814 |
+ enable_if(), |
| 9815 |
+ is_scalar(), |
| 9816 |
+ is_vector(), |
| 9817 |
+ is_matrix(), |
| 9818 |
+ sign()) |
| 9819 |
+ |
| 9820 |
+PROGRAM_PRELUDE_DECLARE(faceforward, |
| 9821 |
+ R"( |
| 9822 |
+template <typename T, typename Enable = void> |
| 9823 |
+struct ANGLE_faceforward_impl |
| 9824 |
+{ |
| 9825 |
+ static ANGLE_ALWAYS_INLINE T exec(T n, T i, T nref) |
| 9826 |
+ { |
| 9827 |
+ return metal::faceforward(n, i, nref); |
| 9828 |
+ } |
| 9829 |
+}; |
| 9830 |
+template <typename T> |
| 9831 |
+struct ANGLE_faceforward_impl<T, ANGLE_enable_if_t<ANGLE_is_scalar<T>::value>> |
| 9832 |
+{ |
| 9833 |
+ static ANGLE_ALWAYS_INLINE T exec(T n, T i, T nref) |
| 9834 |
+ { |
| 9835 |
+ return ANGLE_dot(nref, i) < T(0) ? n : -n; |
| 9836 |
+ } |
| 9837 |
+}; |
| 9838 |
+template <typename T> |
| 9839 |
+ANGLE_ALWAYS_INLINE T ANGLE_faceforward(T n, T i, T nref) |
| 9840 |
+{ |
| 9841 |
+ return ANGLE_faceforward_impl<T>::exec(n, i, nref); |
| 9842 |
+}; |
| 9843 |
+)", |
| 9844 |
+ include_metal_geometric(), |
| 9845 |
+ enable_if(), |
| 9846 |
+ is_scalar(), |
| 9847 |
+ is_vector(), |
| 9848 |
+ is_matrix(), |
| 9849 |
+ dot()) |
| 9850 |
+ |
| 9851 |
+PROGRAM_PRELUDE_DECLARE(reflect, |
| 9852 |
+ R"( |
| 9853 |
+template <typename T, typename Enable = void> |
| 9854 |
+struct ANGLE_reflect_impl |
| 9855 |
+{ |
| 9856 |
+ static ANGLE_ALWAYS_INLINE T exec(T i, T n) |
| 9857 |
+ { |
| 9858 |
+ return metal::reflect(i, n); |
| 9859 |
+ } |
| 9860 |
+}; |
| 9861 |
+template <typename T> |
| 9862 |
+struct ANGLE_reflect_impl<T, ANGLE_enable_if_t<ANGLE_is_scalar<T>::value>> |
| 9863 |
+{ |
| 9864 |
+ static ANGLE_ALWAYS_INLINE T exec(T i, T n) |
| 9865 |
+ { |
| 9866 |
+ return i - T(2) * ANGLE_dot(n, i) * n; |
| 9867 |
+ } |
| 9868 |
+}; |
| 9869 |
+template <typename T> |
| 9870 |
+ANGLE_ALWAYS_INLINE T ANGLE_reflect(T i, T n) |
| 9871 |
+{ |
| 9872 |
+ return ANGLE_reflect_impl<T>::exec(i, n); |
| 9873 |
+}; |
| 9874 |
+)", |
| 9875 |
+ include_metal_geometric(), |
| 9876 |
+ enable_if(), |
| 9877 |
+ is_scalar(), |
| 9878 |
+ is_vector(), |
| 9879 |
+ is_matrix(), |
| 9880 |
+ dot()) |
| 9881 |
+ |
| 9882 |
+PROGRAM_PRELUDE_DECLARE(refract, |
| 9883 |
+ R"( |
| 9884 |
+template <typename T, typename Enable = void> |
| 9885 |
+struct ANGLE_refract_impl |
| 9886 |
+{ |
| 9887 |
+ static ANGLE_ALWAYS_INLINE T exec(T i, T n, ANGLE_scalar_of_t<T> eta) |
| 9888 |
+ { |
| 9889 |
+ return metal::refract(i, n, eta); |
| 9890 |
+ } |
| 9891 |
+}; |
| 9892 |
+template <typename T> |
| 9893 |
+struct ANGLE_refract_impl<T, ANGLE_enable_if_t<ANGLE_is_scalar<T>::value>> |
| 9894 |
+{ |
| 9895 |
+ static ANGLE_ALWAYS_INLINE T exec(T i, T n, T eta) |
| 9896 |
+ { |
| 9897 |
+ auto dotNI = n * i; |
| 9898 |
+ auto k = T(1) - eta * eta * (T(1) - dotNI * dotNI); |
| 9899 |
+ if (k < T(0)) |
| 9900 |
+ { |
| 9901 |
+ return T(0); |
| 9902 |
+ } |
| 9903 |
+ else |
| 9904 |
+ { |
| 9905 |
+ return eta * i - (eta * dotNI + metal::sqrt(k)) * n; |
| 9906 |
+ } |
| 9907 |
+ } |
| 9908 |
+}; |
| 9909 |
+template <typename T> |
| 9910 |
+ANGLE_ALWAYS_INLINE T ANGLE_refract(T i, T n, ANGLE_scalar_of_t<T> eta) |
| 9911 |
+{ |
| 9912 |
+ return ANGLE_refract_impl<T>::exec(i, n, eta); |
| 9913 |
+}; |
| 9914 |
+)", |
| 9915 |
+ include_metal_math(), |
| 9916 |
+ include_metal_geometric(), |
| 9917 |
+ enable_if(), |
| 9918 |
+ is_scalar(), |
| 9919 |
+ is_vector(), |
| 9920 |
+ is_matrix()) |
| 9921 |
+ |
| 9922 |
+PROGRAM_PRELUDE_DECLARE(sign, |
| 9923 |
+ R"( |
| 9924 |
+template <typename T, typename Enable = void> |
| 9925 |
+struct ANGLE_sign_impl |
| 9926 |
+{ |
| 9927 |
+ static ANGLE_ALWAYS_INLINE T exec(T x) |
| 9928 |
+ { |
| 9929 |
+ return metal::sign(x); |
| 9930 |
+ } |
| 9931 |
+}; |
| 9932 |
+template <> |
| 9933 |
+struct ANGLE_sign_impl<int> |
| 9934 |
+{ |
| 9935 |
+ static ANGLE_ALWAYS_INLINE int exec(int x) |
| 9936 |
+ { |
| 9937 |
+ return (0 < x) - (x < 0); |
| 9938 |
+ } |
| 9939 |
+}; |
| 9940 |
+template <int N> |
| 9941 |
+struct ANGLE_sign_impl<metal::vec<int, N>> |
| 9942 |
+{ |
| 9943 |
+ static ANGLE_ALWAYS_INLINE metal::vec<int, N> exec(metal::vec<int, N> x) |
| 9944 |
+ { |
| 9945 |
+ metal::vec<int, N> s; |
| 9946 |
+ for (int i = 0; i < N; ++i) |
| 9947 |
+ { |
| 9948 |
+ s[i] = ANGLE_sign_impl<int>::exec(x[i]); |
| 9949 |
+ } |
| 9950 |
+ return s; |
| 9951 |
+ } |
| 9952 |
+}; |
| 9953 |
+template <typename T> |
| 9954 |
+ANGLE_ALWAYS_INLINE T ANGLE_sign(T x) |
| 9955 |
+{ |
| 9956 |
+ return ANGLE_sign_impl<T>::exec(x); |
| 9957 |
+}; |
| 9958 |
+)", |
| 9959 |
+ include_metal_common()) |
| 9960 |
+ |
| 9961 |
+PROGRAM_PRELUDE_DECLARE(atan, |
| 9962 |
+ R"( |
| 9963 |
+template <typename T> |
| 9964 |
+ANGLE_ALWAYS_INLINE T ANGLE_atan(T yOverX) |
| 9965 |
+{ |
| 9966 |
+ return metal::atan(yOverX); |
| 9967 |
+} |
| 9968 |
+template <typename T> |
| 9969 |
+ANGLE_ALWAYS_INLINE T ANGLE_atan(T y, T x) |
| 9970 |
+{ |
| 9971 |
+ return metal::atan2(y, x); |
| 9972 |
+} |
| 9973 |
+)", |
| 9974 |
+ include_metal_math()) |
| 9975 |
+ |
| 9976 |
+PROGRAM_PRELUDE_DECLARE(degrees, R"( |
| 9977 |
+template <typename T> |
| 9978 |
+ANGLE_ALWAYS_INLINE T ANGLE_degrees(T x) |
| 9979 |
+{ |
| 9980 |
+ return static_cast<T>(57.29577951308232) * x; |
| 9981 |
+} |
| 9982 |
+)") |
| 9983 |
+ |
| 9984 |
+PROGRAM_PRELUDE_DECLARE(radians, R"( |
| 9985 |
+template <typename T> |
| 9986 |
+ANGLE_ALWAYS_INLINE T ANGLE_radians(T x) |
| 9987 |
+{ |
| 9988 |
+ return static_cast<T>(1.7453292519943295e-2) * x; |
| 9989 |
+} |
| 9990 |
+)") |
| 9991 |
+ |
| 9992 |
+PROGRAM_PRELUDE_DECLARE(mod, |
| 9993 |
+ R"( |
| 9994 |
+template <typename X, typename Y> |
| 9995 |
+ANGLE_ALWAYS_INLINE X ANGLE_mod(X x, Y y) |
| 9996 |
+{ |
| 9997 |
+ return x - y * metal::floor(x / y); |
| 9998 |
+} |
| 9999 |
+)", |
| 10000 |
+ include_metal_math()) |
| 10001 |
+ |
| 10002 |
+PROGRAM_PRELUDE_DECLARE(pack_half_2x16, |
| 10003 |
+ R"( |
| 10004 |
+ANGLE_ALWAYS_INLINE uint ANGLE_pack_half_2x16(float2 v) |
| 10005 |
+{ |
| 10006 |
+ return as_type<uint>(half2(v)); |
| 10007 |
+} |
| 10008 |
+)", ) |
| 10009 |
+ |
| 10010 |
+PROGRAM_PRELUDE_DECLARE(unpack_half_2x16, |
| 10011 |
+ R"( |
| 10012 |
+ANGLE_ALWAYS_INLINE float2 ANGLE_unpack_half_2x16(uint x) |
| 10013 |
+{ |
| 10014 |
+ return float2(as_type<half2>(x)); |
| 10015 |
+} |
| 10016 |
+)", ) |
| 10017 |
+ |
| 10018 |
+PROGRAM_PRELUDE_DECLARE(matmulAssign, R"( |
| 10019 |
+template <typename T, int N> |
| 10020 |
+ANGLE_ALWAYS_INLINE thread metal::matrix<T, N, N> &operator*=(thread metal::matrix<T, N, N> &a, metal::matrix<T, N, N> b) |
| 10021 |
+{ |
| 10022 |
+ a = a * b; |
| 10023 |
+ return a; |
| 10024 |
+} |
| 10025 |
+)") |
| 10026 |
+ |
| 10027 |
+PROGRAM_PRELUDE_DECLARE(postIncrementMatrix, |
| 10028 |
+ R"( |
| 10029 |
+template <typename T, int Cols, int Rows> |
| 10030 |
+ANGLE_ALWAYS_INLINE metal::matrix<T, Cols, Rows> operator++(thread metal::matrix<T, Cols, Rows> &a, int) |
| 10031 |
+{ |
| 10032 |
+ auto b = a; |
| 10033 |
+ a += T(1); |
| 10034 |
+ return b; |
| 10035 |
+} |
| 10036 |
+)", |
| 10037 |
+ addMatrixScalarAssign()) |
| 10038 |
+ |
| 10039 |
+PROGRAM_PRELUDE_DECLARE(preIncrementMatrix, |
| 10040 |
+ R"( |
| 10041 |
+template <typename T, int Cols, int Rows> |
| 10042 |
+ANGLE_ALWAYS_INLINE thread metal::matrix<T, Cols, Rows> &operator++(thread metal::matrix<T, Cols, Rows> &a) |
| 10043 |
+{ |
| 10044 |
+ a += T(1); |
| 10045 |
+ return a; |
| 10046 |
+} |
| 10047 |
+)", |
| 10048 |
+ addMatrixScalarAssign()) |
| 10049 |
+ |
| 10050 |
+PROGRAM_PRELUDE_DECLARE(postDecrementMatrix, |
| 10051 |
+ R"( |
| 10052 |
+template <typename T, int Cols, int Rows> |
| 10053 |
+ANGLE_ALWAYS_INLINE metal::matrix<T, Cols, Rows> operator--(thread metal::matrix<T, Cols, Rows> &a, int) |
| 10054 |
+{ |
| 10055 |
+ auto b = a; |
| 10056 |
+ a -= T(1); |
| 10057 |
+ return b; |
| 10058 |
+} |
| 10059 |
+)", |
| 10060 |
+ subMatrixScalarAssign()) |
| 10061 |
+ |
| 10062 |
+PROGRAM_PRELUDE_DECLARE(preDecrementMatrix, |
| 10063 |
+ R"( |
| 10064 |
+template <typename T, int Cols, int Rows> |
| 10065 |
+ANGLE_ALWAYS_INLINE thread metal::matrix<T, Cols, Rows> &operator--(thread metal::matrix<T, Cols, Rows> &a) |
| 10066 |
+{ |
| 10067 |
+ a -= T(1); |
| 10068 |
+ return a; |
| 10069 |
+} |
| 10070 |
+)", |
| 10071 |
+ subMatrixScalarAssign()) |
| 10072 |
+ |
| 10073 |
+PROGRAM_PRELUDE_DECLARE(negateMatrix, |
| 10074 |
+ R"( |
| 10075 |
+template <typename T, int Cols, int Rows> |
| 10076 |
+ANGLE_ALWAYS_INLINE metal::matrix<T, Cols, Rows> operator-(metal::matrix<T, Cols, Rows> m) |
| 10077 |
+{ |
| 10078 |
+ for (size_t col = 0; col < Cols; ++col) |
| 10079 |
+ { |
| 10080 |
+ thread auto &mCol = m[col]; |
| 10081 |
+ mCol = -mCol; |
| 10082 |
+ } |
| 10083 |
+ return m; |
| 10084 |
+} |
| 10085 |
+)", ) |
| 10086 |
+ |
| 10087 |
+PROGRAM_PRELUDE_DECLARE(addMatrixScalarAssign, R"( |
| 10088 |
+template <typename T, int Cols, int Rows> |
| 10089 |
+ANGLE_ALWAYS_INLINE thread metal::matrix<T, Cols, Rows> &operator+=(thread metal::matrix<T, Cols, Rows> &m, T x) |
| 10090 |
+{ |
| 10091 |
+ for (size_t col = 0; col < Cols; ++col) |
| 10092 |
+ { |
| 10093 |
+ m[col] += x; |
| 10094 |
+ } |
| 10095 |
+ return m; |
| 10096 |
+} |
| 10097 |
+)") |
| 10098 |
+ |
| 10099 |
+PROGRAM_PRELUDE_DECLARE(addMatrixScalar, |
| 10100 |
+ R"( |
| 10101 |
+template <typename T, int Cols, int Rows> |
| 10102 |
+ANGLE_ALWAYS_INLINE metal::matrix<T, Cols, Rows> operator+(metal::matrix<T, Cols, Rows> m, T x) |
| 10103 |
+{ |
| 10104 |
+ m += x; |
| 10105 |
+ return m; |
| 10106 |
+} |
| 10107 |
+)", |
| 10108 |
+ addMatrixScalarAssign()) |
| 10109 |
+ |
| 10110 |
+PROGRAM_PRELUDE_DECLARE(subMatrixScalarAssign, |
| 10111 |
+ R"( |
| 10112 |
+template <typename T, int Cols, int Rows> |
| 10113 |
+ANGLE_ALWAYS_INLINE thread metal::matrix<T, Cols, Rows> &operator-=(thread metal::matrix<T, Cols, Rows> &m, T x) |
| 10114 |
+{ |
| 10115 |
+ for (size_t col = 0; col < Cols; ++col) |
| 10116 |
+ { |
| 10117 |
+ m[col] -= x; |
| 10118 |
+ } |
| 10119 |
+ return m; |
| 10120 |
+} |
| 10121 |
+)", ) |
| 10122 |
+ |
| 10123 |
+PROGRAM_PRELUDE_DECLARE(subMatrixScalar, |
| 10124 |
+ R"( |
| 10125 |
+template <typename T, int Cols, int Rows> |
| 10126 |
+ANGLE_ALWAYS_INLINE metal::matrix<T, Cols, Rows> operator-(metal::matrix<T, Cols, Rows> m, T x) |
| 10127 |
+{ |
| 10128 |
+ m -= x; |
| 10129 |
+ return m; |
| 10130 |
+} |
| 10131 |
+)", |
| 10132 |
+ subMatrixScalarAssign()) |
| 10133 |
+ |
| 10134 |
+PROGRAM_PRELUDE_DECLARE(divMatrixScalarAssignFast, |
| 10135 |
+ R"( |
| 10136 |
+template <typename T, int Cols, int Rows> |
| 10137 |
+ANGLE_ALWAYS_INLINE thread metal::matrix<T, Cols, Rows> &operator/=(thread metal::matrix<T, Cols, Rows> &m, T x) |
| 10138 |
+{ |
| 10139 |
+ x = T(1) / x; |
| 10140 |
+ for (size_t col = 0; col < Cols; ++col) |
| 10141 |
+ { |
| 10142 |
+ m[col] *= x; |
| 10143 |
+ } |
| 10144 |
+ return m; |
| 10145 |
+} |
| 10146 |
+)", ) |
| 10147 |
+ |
| 10148 |
+PROGRAM_PRELUDE_DECLARE(divMatrixScalarAssign, |
| 10149 |
+ R"( |
| 10150 |
+template <typename T, int Cols, int Rows> |
| 10151 |
+ANGLE_ALWAYS_INLINE thread metal::matrix<T, Cols, Rows> &operator/=(thread metal::matrix<T, Cols, Rows> &m, T x) |
| 10152 |
+{ |
| 10153 |
+ for (size_t col = 0; col < Cols; ++col) |
| 10154 |
+ { |
| 10155 |
+ m[col] /= x; |
| 10156 |
+ } |
| 10157 |
+ return m; |
| 10158 |
+} |
| 10159 |
+)", ) |
| 10160 |
+ |
| 10161 |
+PROGRAM_PRELUDE_DECLARE(divMatrixScalarFast, |
| 10162 |
+ R"( |
| 10163 |
+#if __METAL_VERSION__ <= 220 |
| 10164 |
+template <typename T, int Cols, int Rows> |
| 10165 |
+ANGLE_ALWAYS_INLINE metal::matrix<T, Cols, Rows> operator/(metal::matrix<T, Cols, Rows> m, T x) |
| 10166 |
+{ |
| 10167 |
+ m /= x; |
| 10168 |
+ return m; |
| 10169 |
+} |
| 10170 |
+#endif |
| 10171 |
+)", |
| 10172 |
+ divMatrixScalarAssignFast()) |
| 10173 |
+ |
| 10174 |
+PROGRAM_PRELUDE_DECLARE(divMatrixScalar, |
| 10175 |
+ R"( |
| 10176 |
+#if __METAL_VERSION__ <= 220 |
| 10177 |
+template <typename T, int Cols, int Rows> |
| 10178 |
+ANGLE_ALWAYS_INLINE metal::matrix<T, Cols, Rows> operator/(metal::matrix<T, Cols, Rows> m, T x) |
| 10179 |
+{ |
| 10180 |
+ m /= x; |
| 10181 |
+ return m; |
| 10182 |
+} |
| 10183 |
+#endif |
| 10184 |
+)", |
| 10185 |
+ divMatrixScalarAssign()) |
| 10186 |
+ |
| 10187 |
+PROGRAM_PRELUDE_DECLARE(componentWiseDivide, R"( |
| 10188 |
+template <typename T, int Cols, int Rows> |
| 10189 |
+ANGLE_ALWAYS_INLINE metal::matrix<T, Cols, Rows> operator/(metal::matrix<T, Cols, Rows> a, metal::matrix<T, Cols, Rows> b) |
| 10190 |
+{ |
| 10191 |
+ for (size_t col = 0; col < Cols; ++col) |
| 10192 |
+ { |
| 10193 |
+ a[col] /= b[col]; |
| 10194 |
+ } |
| 10195 |
+ return a; |
| 10196 |
+} |
| 10197 |
+)") |
| 10198 |
+ |
| 10199 |
+PROGRAM_PRELUDE_DECLARE(componentWiseDivideAssign, |
| 10200 |
+ R"( |
| 10201 |
+template <typename T, int Cols, int Rows> |
| 10202 |
+ANGLE_ALWAYS_INLINE thread metal::matrix<T, Cols, Rows> &operator/=(thread metal::matrix<T, Cols, Rows> &a, metal::matrix<T, Cols, Rows> b) |
| 10203 |
+{ |
| 10204 |
+ a = a / b; |
| 10205 |
+ return a; |
| 10206 |
+} |
| 10207 |
+)", |
| 10208 |
+ componentWiseDivide()) |
| 10209 |
+ |
| 10210 |
+PROGRAM_PRELUDE_DECLARE(componentWiseMultiply, R"( |
| 10211 |
+template <typename T, int Cols, int Rows> |
| 10212 |
+ANGLE_ALWAYS_INLINE metal::matrix<T, Cols, Rows> ANGLE_componentWiseMultiply(metal::matrix<T, Cols, Rows> a, metal::matrix<T, Cols, Rows> b) |
| 10213 |
+{ |
| 10214 |
+ for (size_t col = 0; col < Cols; ++col) |
| 10215 |
+ { |
| 10216 |
+ a[col] *= b[col]; |
| 10217 |
+ } |
| 10218 |
+ return a; |
| 10219 |
+} |
| 10220 |
+)") |
| 10221 |
+ |
| 10222 |
+PROGRAM_PRELUDE_DECLARE(outerProduct, R"( |
| 10223 |
+template <typename T, int M, int N> |
| 10224 |
+ANGLE_ALWAYS_INLINE metal::matrix<T, N, M> ANGLE_outerProduct(metal::vec<T, M> u, metal::vec<T, N> v) |
| 10225 |
+{ |
| 10226 |
+ metal::matrix<T, N, M> o; |
| 10227 |
+ for (size_t n = 0; n < N; ++n) |
| 10228 |
+ { |
| 10229 |
+ o[n] = u * v[n]; |
| 10230 |
+ } |
| 10231 |
+ return o; |
| 10232 |
+} |
| 10233 |
+)") |
| 10234 |
+ |
| 10235 |
+PROGRAM_PRELUDE_DECLARE(inverse2, R"( |
| 10236 |
+template <typename T> |
| 10237 |
+ANGLE_ALWAYS_INLINE metal::matrix<T, 2, 2> ANGLE_inverse(metal::matrix<T, 2, 2> m) |
| 10238 |
+{ |
| 10239 |
+ metal::matrix<T, 2, 2> adj; |
| 10240 |
+ adj[0][0] = m[1][1]; |
| 10241 |
+ adj[0][1] = -m[0][1]; |
| 10242 |
+ adj[1][0] = -m[1][0]; |
| 10243 |
+ adj[1][1] = m[0][0]; |
| 10244 |
+ T det = (adj[0][0] * m[0][0]) + (adj[0][1] * m[1][0]); |
| 10245 |
+ return adj * (T(1) / det); |
| 10246 |
+} |
| 10247 |
+)") |
| 10248 |
+ |
| 10249 |
+PROGRAM_PRELUDE_DECLARE(inverse3, R"( |
| 10250 |
+template <typename T> |
| 10251 |
+ANGLE_ALWAYS_INLINE metal::matrix<T, 3, 3> ANGLE_inverse(metal::matrix<T, 3, 3> m) |
| 10252 |
+{ |
| 10253 |
+ T a = m[1][1] * m[2][2] - m[2][1] * m[1][2]; |
| 10254 |
+ T b = m[1][0] * m[2][2]; |
| 10255 |
+ T c = m[1][2] * m[2][0]; |
| 10256 |
+ T d = m[1][0] * m[2][1]; |
| 10257 |
+ T det = m[0][0] * (a) - |
| 10258 |
+ m[0][1] * (b - c) + |
| 10259 |
+ m[0][2] * (d - m[1][1] * m[2][0]); |
| 10260 |
+ det = T(1) / det; |
| 10261 |
+ metal::matrix<T, 3, 3> minv; |
| 10262 |
+ minv[0][0] = (a) * det; |
| 10263 |
+ minv[0][1] = (m[0][2] * m[2][1] - m[0][1] * m[2][2]) * det; |
| 10264 |
+ minv[0][2] = (m[0][1] * m[1][2] - m[0][2] * m[1][1]) * det; |
| 10265 |
+ minv[1][0] = (c - b) * det; |
| 10266 |
+ minv[1][1] = (m[0][0] * m[2][2] - m[0][2] * m[2][0]) * det; |
| 10267 |
+ minv[1][2] = (m[1][0] * m[0][2] - m[0][0] * m[1][2]) * det; |
| 10268 |
+ minv[2][0] = (d - m[2][0] * m[1][1]) * det; |
| 10269 |
+ minv[2][1] = (m[2][0] * m[0][1] - m[0][0] * m[2][1]) * det; |
| 10270 |
+ minv[2][2] = (m[0][0] * m[1][1] - m[1][0] * m[0][1]) * det; |
| 10271 |
+ return minv; |
| 10272 |
+} |
| 10273 |
+)") |
| 10274 |
+ |
| 10275 |
+PROGRAM_PRELUDE_DECLARE(inverse4, R"( |
| 10276 |
+template <typename T> |
| 10277 |
+ANGLE_ALWAYS_INLINE metal::matrix<T, 4, 4> ANGLE_inverse(metal::matrix<T, 4, 4> m) |
| 10278 |
+{ |
| 10279 |
+ T A2323 = m[2][2] * m[3][3] - m[2][3] * m[3][2]; |
| 10280 |
+ T A1323 = m[2][1] * m[3][3] - m[2][3] * m[3][1]; |
| 10281 |
+ T A1223 = m[2][1] * m[3][2] - m[2][2] * m[3][1]; |
| 10282 |
+ T A0323 = m[2][0] * m[3][3] - m[2][3] * m[3][0]; |
| 10283 |
+ T A0223 = m[2][0] * m[3][2] - m[2][2] * m[3][0]; |
| 10284 |
+ T A0123 = m[2][0] * m[3][1] - m[2][1] * m[3][0]; |
| 10285 |
+ T A2313 = m[1][2] * m[3][3] - m[1][3] * m[3][2]; |
| 10286 |
+ T A1313 = m[1][1] * m[3][3] - m[1][3] * m[3][1]; |
| 10287 |
+ T A1213 = m[1][1] * m[3][2] - m[1][2] * m[3][1]; |
| 10288 |
+ T A2312 = m[1][2] * m[2][3] - m[1][3] * m[2][2]; |
| 10289 |
+ T A1312 = m[1][1] * m[2][3] - m[1][3] * m[2][1]; |
| 10290 |
+ T A1212 = m[1][1] * m[2][2] - m[1][2] * m[2][1]; |
| 10291 |
+ T A0313 = m[1][0] * m[3][3] - m[1][3] * m[3][0]; |
| 10292 |
+ T A0213 = m[1][0] * m[3][2] - m[1][2] * m[3][0]; |
| 10293 |
+ T A0312 = m[1][0] * m[2][3] - m[1][3] * m[2][0]; |
| 10294 |
+ T A0212 = m[1][0] * m[2][2] - m[1][2] * m[2][0]; |
| 10295 |
+ T A0113 = m[1][0] * m[3][1] - m[1][1] * m[3][0]; |
| 10296 |
+ T A0112 = m[1][0] * m[2][1] - m[1][1] * m[2][0]; |
| 10297 |
+ T a = m[1][1] * A2323 - m[1][2] * A1323 + m[1][3] * A1223; |
| 10298 |
+ T b = m[1][0] * A2323 - m[1][2] * A0323 + m[1][3] * A0223; |
| 10299 |
+ T c = m[1][0] * A1323 - m[1][1] * A0323 + m[1][3] * A0123; |
| 10300 |
+ T d = m[1][0] * A1223 - m[1][1] * A0223 + m[1][2] * A0123; |
| 10301 |
+ T det = m[0][0] * ( a ) |
| 10302 |
+ - m[0][1] * ( b ) |
| 10303 |
+ + m[0][2] * ( c ) |
| 10304 |
+ - m[0][3] * ( d ); |
| 10305 |
+ det = T(1) / det; |
| 10306 |
+ metal::matrix<T, 4, 4> im; |
| 10307 |
+ im[0][0] = det * ( a ); |
| 10308 |
+ im[0][1] = det * - ( m[0][1] * A2323 - m[0][2] * A1323 + m[0][3] * A1223 ); |
| 10309 |
+ im[0][2] = det * ( m[0][1] * A2313 - m[0][2] * A1313 + m[0][3] * A1213 ); |
| 10310 |
+ im[0][3] = det * - ( m[0][1] * A2312 - m[0][2] * A1312 + m[0][3] * A1212 ); |
| 10311 |
+ im[1][0] = det * - ( b ); |
| 10312 |
+ im[1][1] = det * ( m[0][0] * A2323 - m[0][2] * A0323 + m[0][3] * A0223 ); |
| 10313 |
+ im[1][2] = det * - ( m[0][0] * A2313 - m[0][2] * A0313 + m[0][3] * A0213 ); |
| 10314 |
+ im[1][3] = det * ( m[0][0] * A2312 - m[0][2] * A0312 + m[0][3] * A0212 ); |
| 10315 |
+ im[2][0] = det * ( c ); |
| 10316 |
+ im[2][1] = det * - ( m[0][0] * A1323 - m[0][1] * A0323 + m[0][3] * A0123 ); |
| 10317 |
+ im[2][2] = det * ( m[0][0] * A1313 - m[0][1] * A0313 + m[0][3] * A0113 ); |
| 10318 |
+ im[2][3] = det * - ( m[0][0] * A1312 - m[0][1] * A0312 + m[0][3] * A0112 ); |
| 10319 |
+ im[3][0] = det * - ( d ); |
| 10320 |
+ im[3][1] = det * ( m[0][0] * A1223 - m[0][1] * A0223 + m[0][2] * A0123 ); |
| 10321 |
+ im[3][2] = det * - ( m[0][0] * A1213 - m[0][1] * A0213 + m[0][2] * A0113 ); |
| 10322 |
+ im[3][3] = det * ( m[0][0] * A1212 - m[0][1] * A0212 + m[0][2] * A0112 ); |
| 10323 |
+ return im; |
| 10324 |
+} |
| 10325 |
+)") |
| 10326 |
+ |
| 10327 |
+PROGRAM_PRELUDE_DECLARE(equalArray, |
| 10328 |
+ R"( |
| 10329 |
+template <typename T, size_t N> |
| 10330 |
+ANGLE_ALWAYS_INLINE bool ANGLE_equal(metal::array<T, N> u, metal::array<T, N> v) |
| 10331 |
+{ |
| 10332 |
+ for(size_t i = 0; i < N; i++) |
| 10333 |
+ if (u[i] != v[i]) return false; |
| 10334 |
+ return true; |
| 10335 |
+} |
| 10336 |
+)") |
| 10337 |
+ |
| 10338 |
+PROGRAM_PRELUDE_DECLARE(notEqualArray, |
| 10339 |
+ R"( |
| 10340 |
+template <typename T, size_t N> |
| 10341 |
+ANGLE_ALWAYS_INLINE bool ANGLE_notEqual(metal::array<T, N> u, metal::array<T, N> v) |
| 10342 |
+{ |
| 10343 |
+ return !ANGLE_equal(u,v); |
| 10344 |
+} |
| 10345 |
+)", |
| 10346 |
+ equalArray()) |
| 10347 |
+ |
| 10348 |
+PROGRAM_PRELUDE_DECLARE(equalVector, |
| 10349 |
+ R"( |
| 10350 |
+template <typename T, int N> |
| 10351 |
+ANGLE_ALWAYS_INLINE bool ANGLE_equal(metal::vec<T, N> u, metal::vec<T, N> v) |
| 10352 |
+{ |
| 10353 |
+ return metal::all(u == v); |
| 10354 |
+} |
| 10355 |
+)", |
| 10356 |
+ include_metal_math()) |
| 10357 |
+ |
| 10358 |
+PROGRAM_PRELUDE_DECLARE(equalMatrix, |
| 10359 |
+ R"( |
| 10360 |
+template <typename T, int C, int R> |
| 10361 |
+ANGLE_ALWAYS_INLINE bool ANGLE_equal(metal::matrix<T, C, R> a, metal::matrix<T, C, R> b) |
| 10362 |
+{ |
| 10363 |
+ for (int c = 0; c < C; ++c) |
| 10364 |
+ { |
| 10365 |
+ if (!ANGLE_equal(a[c], b[c])) |
| 10366 |
+ { |
| 10367 |
+ return false; |
| 10368 |
+ } |
| 10369 |
+ } |
| 10370 |
+ return true; |
| 10371 |
+} |
| 10372 |
+)", |
| 10373 |
+ equalVector()) |
| 10374 |
+ |
| 10375 |
+PROGRAM_PRELUDE_DECLARE(notEqualVector, |
| 10376 |
+ R"( |
| 10377 |
+template <typename T, int N> |
| 10378 |
+ANGLE_ALWAYS_INLINE bool ANGLE_notEqual(metal::vec<T, N> u, metal::vec<T, N> v) |
| 10379 |
+{ |
| 10380 |
+ return !ANGLE_equal(u, v); |
| 10381 |
+} |
| 10382 |
+)", |
| 10383 |
+ equalVector()) |
| 10384 |
+ |
| 10385 |
+PROGRAM_PRELUDE_DECLARE(notEqualStruct, |
| 10386 |
+ R"( |
| 10387 |
+template <typename T> |
| 10388 |
+ANGLE_ALWAYS_INLINE bool ANGLE_notEqualStruct(thread const T &a, thread const T &b) |
| 10389 |
+{ |
| 10390 |
+ return !ANGLE_equal(a, b); |
| 10391 |
+} |
| 10392 |
+)", |
| 10393 |
+ equalVector(), |
| 10394 |
+ equalMatrix()) |
| 10395 |
+ |
| 10396 |
+PROGRAM_PRELUDE_DECLARE(vectorElemRef, R"( |
| 10397 |
+template <typename T, int N> |
| 10398 |
+struct ANGLE_VectorElemRef |
| 10399 |
+{ |
| 10400 |
+ thread metal::vec<T, N> &mVec; |
| 10401 |
+ T mRef; |
| 10402 |
+ const int mIndex; |
| 10403 |
+ ~ANGLE_VectorElemRef() { mVec[mIndex] = mRef; } |
| 10404 |
+ ANGLE_VectorElemRef(thread metal::vec<T, N> &vec, int index) |
| 10405 |
+ : mVec(vec), mRef(vec[index]), mIndex(index) |
| 10406 |
+ {} |
| 10407 |
+ operator thread T &() { return mRef; } |
| 10408 |
+}; |
| 10409 |
+template <typename T, int N> |
| 10410 |
+ANGLE_ALWAYS_INLINE ANGLE_VectorElemRef<T, N> ANGLE_elem_ref(thread metal::vec<T, N> &vec, int index) |
| 10411 |
+{ |
| 10412 |
+ return ANGLE_VectorElemRef<T, N>(vec, index); |
| 10413 |
+} |
| 10414 |
+)") |
| 10415 |
+ |
| 10416 |
+PROGRAM_PRELUDE_DECLARE(swizzleRef, |
| 10417 |
+ R"( |
| 10418 |
+template <typename T, int VN, int SN> |
| 10419 |
+struct ANGLE_SwizzleRef |
| 10420 |
+{ |
| 10421 |
+ thread metal::vec<T, VN> &mVec; |
| 10422 |
+ metal::vec<T, SN> mRef; |
| 10423 |
+ int mIndices[SN]; |
| 10424 |
+ ~ANGLE_SwizzleRef() |
| 10425 |
+ { |
| 10426 |
+ for (int i = 0; i < SN; ++i) |
| 10427 |
+ { |
| 10428 |
+ const int j = mIndices[i]; |
| 10429 |
+ mVec[j] = mRef[i]; |
| 10430 |
+ } |
| 10431 |
+ } |
| 10432 |
+ ANGLE_SwizzleRef(thread metal::vec<T, N> &vec, thread const int *indices) |
| 10433 |
+ : mVec(vec) |
| 10434 |
+ { |
| 10435 |
+ for (int i = 0; i < SN; ++i) |
| 10436 |
+ { |
| 10437 |
+ const int j = indices[i]; |
| 10438 |
+ mIndices[i] = j; |
| 10439 |
+ mRef[i] = mVec[j]; |
| 10440 |
+ } |
| 10441 |
+ } |
| 10442 |
+ operator thread metal::vec<T, SN> &() { return mRef; } |
| 10443 |
+}; |
| 10444 |
+template <typename T, int N> |
| 10445 |
+ANGLE_ALWAYS_INLINE ANGLE_VectorElemRef<T, N> ANGLE_swizzle_ref(thread metal::vec<T, N> &vec, int i0) |
| 10446 |
+{ |
| 10447 |
+ return ANGLE_VectorElemRef<T, N>(vec, index); |
| 10448 |
+} |
| 10449 |
+template <typename T, int N> |
| 10450 |
+ANGLE_ALWAYS_INLINE ANGLE_SwizzleRef<T, N, 2> ANGLE_swizzle_ref(thread metal::vec<T, N> &vec, int i0, int i1) |
| 10451 |
+{ |
| 10452 |
+ const int is[] = { i0, i1 }; |
| 10453 |
+ return ANGLE_SwizzleRef<T, N, 2>(vec, is); |
| 10454 |
+} |
| 10455 |
+template <typename T, int N> |
| 10456 |
+ANGLE_ALWAYS_INLINE ANGLE_SwizzleRef<T, N, 3> ANGLE_swizzle_ref(thread metal::vec<T, N> &vec, int i0, int i1, int i2) |
| 10457 |
+{ |
| 10458 |
+ const int is[] = { i0, i1, i2 }; |
| 10459 |
+ return ANGLE_SwizzleRef<T, N, 3>(vec, is); |
| 10460 |
+} |
| 10461 |
+template <typename T, int N> |
| 10462 |
+ANGLE_ALWAYS_INLINE ANGLE_SwizzleRef<T, N, 4> ANGLE_swizzle_ref(thread metal::vec<T, N> &vec, int i0, int i1, int i2, int i3) |
| 10463 |
+{ |
| 10464 |
+ const int is[] = { i0, i1, i2, i3 }; |
| 10465 |
+ return ANGLE_SwizzleRef<T, N, 4>(vec, is); |
| 10466 |
+} |
| 10467 |
+)", |
| 10468 |
+ vectorElemRef()) |
| 10469 |
+ |
| 10470 |
+PROGRAM_PRELUDE_DECLARE(out, R"( |
| 10471 |
+template <typename T> |
| 10472 |
+struct ANGLE_Out |
| 10473 |
+{ |
| 10474 |
+ T mTemp; |
| 10475 |
+ thread T &mDest; |
| 10476 |
+ ~ANGLE_Out() { mDest = mTemp; } |
| 10477 |
+ ANGLE_Out(thread T &dest) |
| 10478 |
+ : mDest(dest) |
| 10479 |
+ {} |
| 10480 |
+ operator thread T &() { return mTemp; } |
| 10481 |
+}; |
| 10482 |
+template <typename T> |
| 10483 |
+ANGLE_ALWAYS_INLINE ANGLE_Out<T> ANGLE_out(thread T &dest) |
| 10484 |
+{ |
| 10485 |
+ return ANGLE_Out<T>(dest); |
| 10486 |
+} |
| 10487 |
+)") |
| 10488 |
+ |
| 10489 |
+PROGRAM_PRELUDE_DECLARE(inout, R"( |
| 10490 |
+template <typename T> |
| 10491 |
+struct ANGLE_InOut |
| 10492 |
+{ |
| 10493 |
+ T mTemp; |
| 10494 |
+ thread T &mDest; |
| 10495 |
+ ~ANGLE_InOut() { mDest = mTemp; } |
| 10496 |
+ ANGLE_InOut(thread T &dest) |
| 10497 |
+ : mTemp(dest), mDest(dest) |
| 10498 |
+ {} |
| 10499 |
+ operator thread T &() { return mTemp; } |
| 10500 |
+}; |
| 10501 |
+template <typename T> |
| 10502 |
+ANGLE_ALWAYS_INLINE ANGLE_InOut<T> ANGLE_inout(thread T &dest) |
| 10503 |
+{ |
| 10504 |
+ return ANGLE_InOut<T>(dest); |
| 10505 |
+} |
| 10506 |
+)") |
| 10507 |
+ |
| 10508 |
+PROGRAM_PRELUDE_DECLARE(flattenArray, R"( |
| 10509 |
+template <typename T> |
| 10510 |
+struct ANGLE_flatten_impl |
| 10511 |
+{ |
| 10512 |
+ static ANGLE_ALWAYS_INLINE thread T *exec(thread T &x) |
| 10513 |
+ { |
| 10514 |
+ return &x; |
| 10515 |
+ } |
| 10516 |
+}; |
| 10517 |
+template <typename T, size_t N> |
| 10518 |
+struct ANGLE_flatten_impl<metal::array<T, N>> |
| 10519 |
+{ |
| 10520 |
+ static ANGLE_ALWAYS_INLINE auto exec(thread metal::array<T, N> &arr) -> T |
| 10521 |
+ { |
| 10522 |
+ return ANGLE_flatten_impl<T>::exec(arr[0]); |
| 10523 |
+ } |
| 10524 |
+}; |
| 10525 |
+template <typename T, size_t N> |
| 10526 |
+ANGLE_ALWAYS_INLINE auto ANGLE_flatten(thread metal::array<T, N> &arr) -> T |
| 10527 |
+{ |
| 10528 |
+ return ANGLE_flatten_impl<T>::exec(arr[0]); |
| 10529 |
+} |
| 10530 |
+)") |
| 10531 |
+ |
| 10532 |
+PROGRAM_PRELUDE_DECLARE(castVector, R"( |
| 10533 |
+template <typename T, int N1, int N2> |
| 10534 |
+struct ANGLE_castVector {}; |
| 10535 |
+template <typename T, int N> |
| 10536 |
+struct ANGLE_castVector<T, N, N> |
| 10537 |
+{ |
| 10538 |
+ static ANGLE_ALWAYS_INLINE metal::vec<T, N> exec(thread metal::vec<T, N> const &v) |
| 10539 |
+ { |
| 10540 |
+ return v; |
| 10541 |
+ } |
| 10542 |
+}; |
| 10543 |
+template <typename T> |
| 10544 |
+struct ANGLE_castVector<T, 2, 3> |
| 10545 |
+{ |
| 10546 |
+ static ANGLE_ALWAYS_INLINE metal::vec<T, 2> exec(thread metal::vec<T, 3> const &v) |
| 10547 |
+ { |
| 10548 |
+ return v.xy; |
| 10549 |
+ } |
| 10550 |
+}; |
| 10551 |
+template <typename T> |
| 10552 |
+struct ANGLE_castVector<T, 2, 4> |
| 10553 |
+{ |
| 10554 |
+ static ANGLE_ALWAYS_INLINE metal::vec<T, 2> exec(thread metal::vec<T, 4> const &v) |
| 10555 |
+ { |
| 10556 |
+ return v.xy; |
| 10557 |
+ } |
| 10558 |
+}; |
| 10559 |
+template <typename T> |
| 10560 |
+struct ANGLE_castVector<T, 3, 4> |
| 10561 |
+{ |
| 10562 |
+ static ANGLE_ALWAYS_INLINE metal::vec<T, 3> exec(thread metal::vec<T, 4> const &v) |
| 10563 |
+ { |
| 10564 |
+ return as_type<metal::vec<T, 3>>(v); |
| 10565 |
+ } |
| 10566 |
+}; |
| 10567 |
+template <int N1, int N2, typename T> |
| 10568 |
+ANGLE_ALWAYS_INLINE metal::vec<T, N1> ANGLE_cast(thread metal::vec<T, N2> const &v) |
| 10569 |
+{ |
| 10570 |
+ return ANGLE_castVector<T, N1, N2>::exec(v); |
| 10571 |
+} |
| 10572 |
+)") |
| 10573 |
+ |
| 10574 |
+PROGRAM_PRELUDE_DECLARE(castMatrix, |
| 10575 |
+ R"( |
| 10576 |
+template <typename T, int C1, int R1, int C2, int R2, typename Enable = void> |
| 10577 |
+struct ANGLE_castMatrix |
| 10578 |
+{ |
| 10579 |
+ static ANGLE_ALWAYS_INLINE metal::matrix<T, C1, R1> exec(thread metal::matrix<T, C2, R2> const &m2) |
| 10580 |
+ { |
| 10581 |
+ metal::matrix<T, C1, R1> m1; |
| 10582 |
+ const int MinC = C1 <= C2 ? C1 : C2; |
| 10583 |
+ const int MinR = R1 <= R2 ? R1 : R2; |
| 10584 |
+ for (int c = 0; c < MinC; ++c) |
| 10585 |
+ { |
| 10586 |
+ for (int r = 0; r < MinR; ++r) |
| 10587 |
+ { |
| 10588 |
+ m1[c][r] = m2[c][r]; |
| 10589 |
+ } |
| 10590 |
+ for (int r = R2; r < R1; ++r) |
| 10591 |
+ { |
| 10592 |
+ m1[c][r] = c == r ? T(1) : T(0); |
| 10593 |
+ } |
| 10594 |
+ } |
| 10595 |
+ for (int c = C2; c < C1; ++c) |
| 10596 |
+ { |
| 10597 |
+ for (int r = 0; r < R1; ++r) |
| 10598 |
+ { |
| 10599 |
+ m1[c][r] = c == r ? T(1) : T(0); |
| 10600 |
+ } |
| 10601 |
+ } |
| 10602 |
+ return m1; |
| 10603 |
+ } |
| 10604 |
+}; |
| 10605 |
+template <typename T, int C1, int R1, int C2, int R2> |
| 10606 |
+struct ANGLE_castMatrix<T, C1, R1, C2, R2, ANGLE_enable_if_t<(C1 <= C2 && R1 <= R2)>> |
| 10607 |
+{ |
| 10608 |
+ static ANGLE_ALWAYS_INLINE metal::matrix<T, C1, R1> exec(thread metal::matrix<T, C2, R2> const &m2) |
| 10609 |
+ { |
| 10610 |
+ metal::matrix<T, C1, R1> m1; |
| 10611 |
+ for (size_t c = 0; c < C1; ++c) |
| 10612 |
+ { |
| 10613 |
+ m1[c] = ANGLE_cast<R1>(m2[c]); |
| 10614 |
+ } |
| 10615 |
+ return m1; |
| 10616 |
+ } |
| 10617 |
+}; |
| 10618 |
+template <int C1, int R1, int C2, int R2, typename T> |
| 10619 |
+ANGLE_ALWAYS_INLINE metal::matrix<T, C1, R1> ANGLE_cast(thread metal::matrix<T, C2, R2> const &m) |
| 10620 |
+{ |
| 10621 |
+ return ANGLE_castMatrix<T, C1, R1, C2, R2>::exec(m); |
| 10622 |
+}; |
| 10623 |
+)", |
| 10624 |
+ enable_if(), |
| 10625 |
+ castVector()) |
| 10626 |
+ |
| 10627 |
+PROGRAM_PRELUDE_DECLARE(tensor, R"( |
| 10628 |
+template <typename T, size_t... DS> |
| 10629 |
+struct ANGLE_tensor_traits; |
| 10630 |
+template <typename T, size_t D> |
| 10631 |
+struct ANGLE_tensor_traits<T, D> |
| 10632 |
+{ |
| 10633 |
+ enum : size_t { outer_dim = D }; |
| 10634 |
+ using inner_type = T; |
| 10635 |
+ using outer_type = inner_type[D]; |
| 10636 |
+}; |
| 10637 |
+template <typename T, size_t D, size_t... DS> |
| 10638 |
+struct ANGLE_tensor_traits<T, D, DS...> |
| 10639 |
+{ |
| 10640 |
+ enum : size_t { outer_dim = D }; |
| 10641 |
+ using inner_type = typename ANGLE_tensor_traits<T, DS...>::outer_type; |
| 10642 |
+ using outer_type = inner_type[D]; |
| 10643 |
+}; |
| 10644 |
+template <size_t D, typename value_type_, typename inner_type_> |
| 10645 |
+struct ANGLE_tensor_impl |
| 10646 |
+{ |
| 10647 |
+ enum : size_t { outer_dim = D }; |
| 10648 |
+ using value_type = value_type_; |
| 10649 |
+ using inner_type = inner_type_; |
| 10650 |
+ using outer_type = inner_type[D]; |
| 10651 |
+ outer_type _data; |
| 10652 |
+ ANGLE_ALWAYS_INLINE size_t size() const { return outer_dim; } |
| 10653 |
+ ANGLE_ALWAYS_INLINE inner_type &operator[](size_t i) { return _data[i]; } |
| 10654 |
+ ANGLE_ALWAYS_INLINE const inner_type &operator[](size_t i) const { return _data[i]; } |
| 10655 |
+}; |
| 10656 |
+template <typename T, size_t... DS> |
| 10657 |
+using ANGLE_tensor = ANGLE_tensor_impl< |
| 10658 |
+ ANGLE_tensor_traits<T, DS...>::outer_dim, |
| 10659 |
+ T, |
| 10660 |
+ typename ANGLE_tensor_traits<T, DS...>::inner_type>; |
| 10661 |
+)") |
| 10662 |
+ |
| 10663 |
+PROGRAM_PRELUDE_DECLARE(gradient, |
| 10664 |
+ R"( |
| 10665 |
+template <int N> |
| 10666 |
+struct ANGLE_gradient_traits; |
| 10667 |
+template <> |
| 10668 |
+struct ANGLE_gradient_traits<2> { using type = metal::gradient2d; }; |
| 10669 |
+template <> |
| 10670 |
+struct ANGLE_gradient_traits<3> { using type = metal::gradient3d; }; |
| 10671 |
+ |
| 10672 |
+template <int N> |
| 10673 |
+using ANGLE_gradient = typename ANGLE_gradient_traits<N>::type; |
| 10674 |
+)") |
| 10675 |
+ |
| 10676 |
+PROGRAM_PRELUDE_DECLARE(textureEnv, |
| 10677 |
+ R"( |
| 10678 |
+template <typename T> |
| 10679 |
+struct ANGLE_TextureEnv |
| 10680 |
+{ |
| 10681 |
+ thread T *texture; |
| 10682 |
+ thread metal::sampler *sampler; |
| 10683 |
+}; |
| 10684 |
+)") |
| 10685 |
+ |
| 10686 |
+PROGRAM_PRELUDE_DECLARE(functionConstants, |
| 10687 |
+ R"( |
| 10688 |
+#define ANGLE_SAMPLE_COMPARE_GRADIENT_INDEX 0 |
| 10689 |
+#define ANGLE_SAMPLE_COMPARE_LOD_INDEX 1 |
| 10690 |
+#define ANGLE_RASTERIZATION_DISCARD_INDEX 2 |
| 10691 |
+ |
| 10692 |
+constant bool ANGLE_UseSampleCompareGradient [[function_constant(ANGLE_SAMPLE_COMPARE_GRADIENT_INDEX)]]; |
| 10693 |
+constant bool ANGLE_UseSampleCompareLod [[function_constant(ANGLE_SAMPLE_COMPARE_LOD_INDEX)]]; |
| 10694 |
+constant bool ANGLE_RasterizationDiscard [[function_constant(ANGLE_RASTERIZATION_DISCARD_INDEX)]]; |
| 10695 |
+)") |
| 10696 |
+ |
| 10697 |
+PROGRAM_PRELUDE_DECLARE(texelFetch, |
| 10698 |
+ R"( |
| 10699 |
+#define ANGLE_texelFetch(env, ...) ANGLE_texelFetch_impl(*env.texture, __VA_ARGS__) |
| 10700 |
+ |
| 10701 |
+template <typename Texture> |
| 10702 |
+ANGLE_ALWAYS_INLINE auto ANGLE_texelFetch_impl( |
| 10703 |
+ thread Texture &texture, |
| 10704 |
+ thread metal::int2 const &coord, |
| 10705 |
+ uint level) |
| 10706 |
+{ |
| 10707 |
+ return texture.read(uint2(coord), level); |
| 10708 |
+} |
| 10709 |
+ |
| 10710 |
+template <typename Texture> |
| 10711 |
+ANGLE_ALWAYS_INLINE auto ANGLE_texelFetch_impl( |
| 10712 |
+ thread Texture &texture, |
| 10713 |
+ thread metal::int3 const &coord, |
| 10714 |
+ uint level) |
| 10715 |
+{ |
| 10716 |
+ return texture.read(uint3(coord), level); |
| 10717 |
+} |
| 10718 |
+ |
| 10719 |
+template <typename T> |
| 10720 |
+ANGLE_ALWAYS_INLINE auto ANGLE_texelFetch_impl( |
| 10721 |
+ thread metal::texture2d_array<T> &texture, |
| 10722 |
+ thread metal::int3 const &coord, |
| 10723 |
+ uint level) |
| 10724 |
+{ |
| 10725 |
+ return texture.read(uint2(coord.xy), uint(coord.z), level); |
| 10726 |
+} |
| 10727 |
+)", |
| 10728 |
+ textureEnv()) |
| 10729 |
+ |
| 10730 |
+PROGRAM_PRELUDE_DECLARE(texelFetchOffset, |
| 10731 |
+ R"( |
| 10732 |
+#define ANGLE_texelFetchOffset(env, ...) ANGLE_texelFetchOffset_impl(*env.texture, __VA_ARGS__) |
| 10733 |
+ |
| 10734 |
+template <typename Texture> |
| 10735 |
+ANGLE_ALWAYS_INLINE auto ANGLE_texelFetchOffset_impl( |
| 10736 |
+ thread Texture &texture, |
| 10737 |
+ thread metal::int2 const &coord, |
| 10738 |
+ uint level, |
| 10739 |
+ thread metal::int2 const &offset) |
| 10740 |
+{ |
| 10741 |
+ return texture.read(uint2(coord + offset), level); |
| 10742 |
+} |
| 10743 |
+ |
| 10744 |
+template <typename Texture> |
| 10745 |
+ANGLE_ALWAYS_INLINE auto ANGLE_texelFetchOffset_impl( |
| 10746 |
+ thread Texture &texture, |
| 10747 |
+ thread metal::int3 const &coord, |
| 10748 |
+ uint level, |
| 10749 |
+ thread metal::int3 const &offset) |
| 10750 |
+{ |
| 10751 |
+ return texture.read(uint3(coord + offset), level); |
| 10752 |
+} |
| 10753 |
+ |
| 10754 |
+template <typename T> |
| 10755 |
+ANGLE_ALWAYS_INLINE auto ANGLE_texelFetchOffset_impl( |
| 10756 |
+ thread metal::texture2d_array<T> &texture, |
| 10757 |
+ thread metal::int3 const &coord, |
| 10758 |
+ uint level, |
| 10759 |
+ thread metal::int2 const &offset) |
| 10760 |
+{ |
| 10761 |
+ return texture.read(uint2(coord.xy + offset), uint(coord.z), level); |
| 10762 |
+} |
| 10763 |
+)", |
| 10764 |
+ textureEnv()) |
| 10765 |
+ |
| 10766 |
+PROGRAM_PRELUDE_DECLARE(texture, |
| 10767 |
+ R"( |
| 10768 |
+#define ANGLE_texture(env, ...) ANGLE_texture_impl(*env.texture, *env.sampler, __VA_ARGS__) |
| 10769 |
+)", |
| 10770 |
+ textureEnv()) |
| 10771 |
+ |
| 10772 |
+PROGRAM_PRELUDE_DECLARE(texture_generic_float2, |
| 10773 |
+ R"( |
| 10774 |
+template <typename Texture> |
| 10775 |
+ANGLE_ALWAYS_INLINE auto ANGLE_texture_impl( |
| 10776 |
+ thread Texture &texture, |
| 10777 |
+ thread metal::sampler const &sampler, |
| 10778 |
+ thread metal::float2 const &coord) |
| 10779 |
+{ |
| 10780 |
+ return texture.sample(sampler, coord); |
| 10781 |
+} |
| 10782 |
+)", |
| 10783 |
+ texture()) |
| 10784 |
+ |
| 10785 |
+PROGRAM_PRELUDE_DECLARE(texture_generic_float2_float, |
| 10786 |
+ R"( |
| 10787 |
+template <typename Texture> |
| 10788 |
+ANGLE_ALWAYS_INLINE auto ANGLE_texture_impl( |
| 10789 |
+ thread Texture &texture, |
| 10790 |
+ thread metal::sampler const &sampler, |
| 10791 |
+ thread metal::float2 const &coord, |
| 10792 |
+ float bias) |
| 10793 |
+{ |
| 10794 |
+ return texture.sample(sampler, coord, metal::bias(bias)); |
| 10795 |
+} |
| 10796 |
+)", |
| 10797 |
+ texture()) |
| 10798 |
+ |
| 10799 |
+PROGRAM_PRELUDE_DECLARE(texture_generic_float3, |
| 10800 |
+ R"( |
| 10801 |
+template <typename Texture> |
| 10802 |
+ANGLE_ALWAYS_INLINE auto ANGLE_texture_impl( |
| 10803 |
+ thread Texture &texture, |
| 10804 |
+ thread metal::sampler const &sampler, |
| 10805 |
+ thread metal::float3 const &coord) |
| 10806 |
+{ |
| 10807 |
+ return texture.sample(sampler, coord); |
| 10808 |
+} |
| 10809 |
+)", |
| 10810 |
+ texture()) |
| 10811 |
+ |
| 10812 |
+PROGRAM_PRELUDE_DECLARE(texture_generic_float3_float, |
| 10813 |
+ R"( |
| 10814 |
+template <typename Texture> |
| 10815 |
+ANGLE_ALWAYS_INLINE auto ANGLE_texture_impl( |
| 10816 |
+ thread Texture &texture, |
| 10817 |
+ thread metal::sampler const &sampler, |
| 10818 |
+ thread metal::float3 const &coord, |
| 10819 |
+ float bias) |
| 10820 |
+{ |
| 10821 |
+ return texture.sample(sampler, coord, metal::bias(bias)); |
| 10822 |
+} |
| 10823 |
+)", |
| 10824 |
+ texture()) |
| 10825 |
+ |
| 10826 |
+PROGRAM_PRELUDE_DECLARE(texture_depth2d_float3, |
| 10827 |
+ R"( |
| 10828 |
+template <typename T> |
| 10829 |
+ANGLE_ALWAYS_INLINE auto ANGLE_texture_impl( |
| 10830 |
+ thread metal::depth2d<T> &texture, |
| 10831 |
+ thread metal::sampler const &sampler, |
| 10832 |
+ thread metal::float3 const &coord) |
| 10833 |
+{ |
| 10834 |
+ return texture.sample(sampler, coord.xy); |
| 10835 |
+} |
| 10836 |
+)", |
| 10837 |
+ texture()) |
| 10838 |
+ |
| 10839 |
+PROGRAM_PRELUDE_DECLARE(texture_depth2d_float3_float, |
| 10840 |
+ R"( |
| 10841 |
+template <typename T> |
| 10842 |
+ANGLE_ALWAYS_INLINE auto ANGLE_texture_impl( |
| 10843 |
+ thread metal::depth2d<T> &texture, |
| 10844 |
+ thread metal::sampler const &sampler, |
| 10845 |
+ thread metal::float3 const &coord, |
| 10846 |
+ float bias) |
| 10847 |
+{ |
| 10848 |
+ return texture.sample(sampler, coord.xy, metal::bias(bias)); |
| 10849 |
+} |
| 10850 |
+)", |
| 10851 |
+ texture()) |
| 10852 |
+ |
| 10853 |
+PROGRAM_PRELUDE_DECLARE(texture_depth2darray_float4, |
| 10854 |
+ R"( |
| 10855 |
+template <typename T> |
| 10856 |
+ANGLE_ALWAYS_INLINE auto ANGLE_texture_impl( |
| 10857 |
+ thread metal::depth2d_array<T> &texture, |
| 10858 |
+ thread metal::sampler const &sampler, |
| 10859 |
+ thread metal::float4 const &coord) |
| 10860 |
+{ |
| 10861 |
+ return texture.sample_compare(sampler, coord.xy, uint(metal::round(coord.z)), coord.w); |
| 10862 |
+} |
| 10863 |
+)", |
| 10864 |
+ texture()) |
| 10865 |
+ |
| 10866 |
+PROGRAM_PRELUDE_DECLARE(texture_depth2darray_float4_float, |
| 10867 |
+ R"( |
| 10868 |
+template <typename T> |
| 10869 |
+ANGLE_ALWAYS_INLINE auto ANGLE_texture_impl( |
| 10870 |
+ thread metal::depth2d_array<T> &texture, |
| 10871 |
+ thread metal::sampler const &sampler, |
| 10872 |
+ thread metal::float4 const &coord, |
| 10873 |
+ float compare) |
| 10874 |
+{ |
| 10875 |
+ return texture.sample_compare(sampler, coord.xyz, uint(metal::round(coord.w)), compare); |
| 10876 |
+} |
| 10877 |
+)", |
| 10878 |
+ texture()) |
| 10879 |
+ |
| 10880 |
+PROGRAM_PRELUDE_DECLARE(texture_depthcube_float4, |
| 10881 |
+ R"( |
| 10882 |
+template <typename T> |
| 10883 |
+ANGLE_ALWAYS_INLINE auto ANGLE_texture_impl( |
| 10884 |
+ thread metal::depthcube<T> &texture, |
| 10885 |
+ thread metal::sampler const &sampler, |
| 10886 |
+ thread metal::float4 const &coord) |
| 10887 |
+{ |
| 10888 |
+ return texture.sample(sampler, coord.xyz); |
| 10889 |
+} |
| 10890 |
+)", |
| 10891 |
+ texture()) |
| 10892 |
+ |
| 10893 |
+PROGRAM_PRELUDE_DECLARE(texture_depthcube_float4_float, |
| 10894 |
+ R"( |
| 10895 |
+template <typename T> |
| 10896 |
+ANGLE_ALWAYS_INLINE auto ANGLE_texture_impl( |
| 10897 |
+ thread metal::depthcube<T> &texture, |
| 10898 |
+ thread metal::sampler const &sampler, |
| 10899 |
+ thread metal::float4 const &coord, |
| 10900 |
+ float bias) |
| 10901 |
+{ |
| 10902 |
+ return texture.sample(sampler, coord.xyz, metal::bias(bias)); |
| 10903 |
+} |
| 10904 |
+)", |
| 10905 |
+ texture()) |
| 10906 |
+ |
| 10907 |
+PROGRAM_PRELUDE_DECLARE(texture_texture2darray_float3, |
| 10908 |
+ R"( |
| 10909 |
+template <typename T> |
| 10910 |
+ANGLE_ALWAYS_INLINE auto ANGLE_texture_impl( |
| 10911 |
+ thread metal::texture2d_array<T> &texture, |
| 10912 |
+ thread metal::sampler const &sampler, |
| 10913 |
+ thread metal::float3 const &coord) |
| 10914 |
+{ |
| 10915 |
+ return texture.sample(sampler, coord.xy, uint(metal::round(coord.z))); |
| 10916 |
+} |
| 10917 |
+)", |
| 10918 |
+ texture()) |
| 10919 |
+ |
| 10920 |
+PROGRAM_PRELUDE_DECLARE(texture_texture2darray_float3_float, |
| 10921 |
+ R"( |
| 10922 |
+template <typename T> |
| 10923 |
+ANGLE_ALWAYS_INLINE auto ANGLE_texture_impl( |
| 10924 |
+ thread metal::texture2d_array<T> &texture, |
| 10925 |
+ thread metal::sampler const &sampler, |
| 10926 |
+ thread metal::float3 const &coord, |
| 10927 |
+ float bias) |
| 10928 |
+{ |
| 10929 |
+ return texture.sample(sampler, coord.xy, uint(metal::round(coord.z)), metal::bias(bias)); |
| 10930 |
+} |
| 10931 |
+)", |
| 10932 |
+ texture()) |
| 10933 |
+ |
| 10934 |
+PROGRAM_PRELUDE_DECLARE(texture_texture2darray_float4, |
| 10935 |
+ R"( |
| 10936 |
+template <typename T> |
| 10937 |
+ANGLE_ALWAYS_INLINE auto ANGLE_texture_impl( |
| 10938 |
+ thread metal::texture2d_array<T> &texture, |
| 10939 |
+ thread metal::sampler const &sampler, |
| 10940 |
+ thread metal::float4 const &coord) |
| 10941 |
+{ |
| 10942 |
+ return texture.sample(sampler, coord.xyz, uint(metal::round(coord.w))); |
| 10943 |
+} |
| 10944 |
+)", |
| 10945 |
+ texture()) |
| 10946 |
+ |
| 10947 |
+PROGRAM_PRELUDE_DECLARE(texture_texture2darray_float4_float, |
| 10948 |
+ R"( |
| 10949 |
+template <typename T> |
| 10950 |
+ANGLE_ALWAYS_INLINE auto ANGLE_texture_impl( |
| 10951 |
+ thread metal::texture2d_array<T> &texture, |
| 10952 |
+ thread metal::sampler const &sampler, |
| 10953 |
+ thread metal::float4 const &coord, |
| 10954 |
+ float bias) |
| 10955 |
+{ |
| 10956 |
+ return texture.sample(sampler, coord.xyz, uint(metal::round(coord.w)), metal::bias(bias)); |
| 10957 |
+} |
| 10958 |
+)", |
| 10959 |
+ texture()) |
| 10960 |
+ |
| 10961 |
+PROGRAM_PRELUDE_DECLARE(texture1DLod, |
| 10962 |
+ R"( |
| 10963 |
+#define ANGLE_texture1DLod(env, ...) ANGLE_texture1DLod_impl(*env.texture, *env.sampler, __VA_ARGS__) |
| 10964 |
+ |
| 10965 |
+template <typename Texture> |
| 10966 |
+ANGLE_ALWAYS_INLINE auto ANGLE_texture1DLod_impl( |
| 10967 |
+ thread Texture &texture, |
| 10968 |
+ thread metal::sampler const &sampler, |
| 10969 |
+ thread float const &coord, |
| 10970 |
+ float level) |
| 10971 |
+{ |
| 10972 |
+ return texture.sample(sampler, coord, metal::level(level)); |
| 10973 |
+} |
| 10974 |
+)", |
| 10975 |
+ textureEnv()) |
| 10976 |
+ |
| 10977 |
+PROGRAM_PRELUDE_DECLARE(texture1DProj, |
| 10978 |
+ R"( |
| 10979 |
+#define ANGLE_texture1DProj(env, ...) ANGLE_texture1DProj_impl(*env.texture, *env.sampler, __VA_ARGS__) |
| 10980 |
+ |
| 10981 |
+template <typename Texture> |
| 10982 |
+ANGLE_ALWAYS_INLINE auto ANGLE_texture1DProj_impl( |
| 10983 |
+ thread Texture &texture, |
| 10984 |
+ thread metal::sampler const &sampler, |
| 10985 |
+ thread metal::float2 const &coord, |
| 10986 |
+ float bias = 0) |
| 10987 |
+{ |
| 10988 |
+ return texture.sample(sampler, coord.x/coord.y, metal::bias(bias)); |
| 10989 |
+} |
| 10990 |
+ |
| 10991 |
+template <typename Texture> |
| 10992 |
+ANGLE_ALWAYS_INLINE auto ANGLE_texture1DProj_impl( |
| 10993 |
+ thread Texture &texture, |
| 10994 |
+ thread metal::sampler const &sampler, |
| 10995 |
+ thread metal::float4 const &coord, |
| 10996 |
+ float bias = 0) |
| 10997 |
+{ |
| 10998 |
+ return texture.sample(sampler, coord.x/coord.w, metal::bias(bias)); |
| 10999 |
+} |
| 11000 |
+)", |
| 11001 |
+ textureEnv()) |
| 11002 |
+ |
| 11003 |
+PROGRAM_PRELUDE_DECLARE(texture1DProjLod, |
| 11004 |
+ R"( |
| 11005 |
+#define ANGLE_texture1DProjLod(env, ...) ANGLE_texture1DProjLod_impl(*env.texture, *env.sampler, __VA_ARGS__) |
| 11006 |
+ |
| 11007 |
+template <typename Texture> |
| 11008 |
+ANGLE_ALWAYS_INLINE auto ANGLE_texture1DProjLod_impl( |
| 11009 |
+ thread Texture &texture, |
| 11010 |
+ thread metal::sampler const &sampler, |
| 11011 |
+ thread metal::float2 const &coord, |
| 11012 |
+ float level) |
| 11013 |
+{ |
| 11014 |
+ return texture.sample(sampler, coord.x/coord.y, metal::level(level)); |
| 11015 |
+} |
| 11016 |
+ |
| 11017 |
+template <typename Texture> |
| 11018 |
+ANGLE_ALWAYS_INLINE auto ANGLE_texture1DProjLod_impl( |
| 11019 |
+ thread Texture &texture, |
| 11020 |
+ thread metal::sampler const &sampler, |
| 11021 |
+ thread metal::float4 const &coord, |
| 11022 |
+ float level) |
| 11023 |
+{ |
| 11024 |
+ return texture.sample(sampler, coord.x/coord.w, metal::level(level)); |
| 11025 |
+} |
| 11026 |
+)", |
| 11027 |
+ textureEnv()) |
| 11028 |
+ |
| 11029 |
+PROGRAM_PRELUDE_DECLARE(texture2D, |
| 11030 |
+ R"( |
| 11031 |
+#define ANGLE_texture2D(env, ...) ANGLE_texture2D_impl(*env.texture, *env.sampler, __VA_ARGS__) |
| 11032 |
+ |
| 11033 |
+template <typename Texture> |
| 11034 |
+ANGLE_ALWAYS_INLINE auto ANGLE_texture2D_impl( |
| 11035 |
+ thread Texture &texture, |
| 11036 |
+ thread metal::sampler const &sampler, |
| 11037 |
+ thread metal::float2 const &coord) |
| 11038 |
+{ |
| 11039 |
+ return texture.sample(sampler, coord); |
| 11040 |
+} |
| 11041 |
+ |
| 11042 |
+template <typename Texture> |
| 11043 |
+ANGLE_ALWAYS_INLINE auto ANGLE_texture2D_impl( |
| 11044 |
+ thread Texture &texture, |
| 11045 |
+ thread metal::sampler const &sampler, |
| 11046 |
+ thread metal::float2 const &coord, |
| 11047 |
+ float bias) |
| 11048 |
+{ |
| 11049 |
+ return texture.sample(sampler, coord, metal::bias(bias)); |
| 11050 |
+} |
| 11051 |
+ |
| 11052 |
+template <typename Texture> |
| 11053 |
+ANGLE_ALWAYS_INLINE auto ANGLE_texture2D_impl( |
| 11054 |
+ thread Texture &texture, |
| 11055 |
+ thread metal::sampler const &sampler, |
| 11056 |
+ thread metal::float3 const &coord) |
| 11057 |
+{ |
| 11058 |
+ return texture.sample(sampler, coord); |
| 11059 |
+} |
| 11060 |
+ |
| 11061 |
+template <typename Texture> |
| 11062 |
+ANGLE_ALWAYS_INLINE auto ANGLE_texture2D_impl( |
| 11063 |
+ thread Texture &texture, |
| 11064 |
+ thread metal::sampler const &sampler, |
| 11065 |
+ thread metal::float3 const &coord, |
| 11066 |
+ float bias) |
| 11067 |
+{ |
| 11068 |
+ return texture.sample(sampler, coord, metal::bias(bias)); |
| 11069 |
+} |
| 11070 |
+)", |
| 11071 |
+ textureEnv()) |
| 11072 |
+ |
| 11073 |
+PROGRAM_PRELUDE_DECLARE(texture2DLod, |
| 11074 |
+ R"( |
| 11075 |
+#define ANGLE_texture2DLod(env, ...) ANGLE_texture2DLod_impl(*env.texture, *env.sampler, __VA_ARGS__) |
| 11076 |
+ |
| 11077 |
+template <typename Texture> |
| 11078 |
+ANGLE_ALWAYS_INLINE auto ANGLE_texture2DLod_impl( |
| 11079 |
+ thread Texture &texture, |
| 11080 |
+ thread metal::sampler const &sampler, |
| 11081 |
+ thread metal::float2 const &coord, |
| 11082 |
+ float level) |
| 11083 |
+{ |
| 11084 |
+ return texture.sample(sampler, coord, metal::level(level)); |
| 11085 |
+} |
| 11086 |
+)", |
| 11087 |
+ textureEnv()) |
| 11088 |
+ |
| 11089 |
+PROGRAM_PRELUDE_DECLARE(texture2DProj, |
| 11090 |
+ R"( |
| 11091 |
+#define ANGLE_texture2DProj(env, ...) ANGLE_texture2DProj_impl(*env.texture, *env.sampler, __VA_ARGS__) |
| 11092 |
+ |
| 11093 |
+template <typename Texture> |
| 11094 |
+ANGLE_ALWAYS_INLINE auto ANGLE_texture2DProj_impl( |
| 11095 |
+ thread Texture &texture, |
| 11096 |
+ thread metal::sampler const &sampler, |
| 11097 |
+ thread metal::float3 const &coord, |
| 11098 |
+ float bias = 0) |
| 11099 |
+{ |
| 11100 |
+ return texture.sample(sampler, coord.xy/coord.z, metal::bias(bias)); |
| 11101 |
+} |
| 11102 |
+ |
| 11103 |
+template <typename Texture> |
| 11104 |
+ANGLE_ALWAYS_INLINE auto ANGLE_texture2DProj_impl( |
| 11105 |
+ thread Texture &texture, |
| 11106 |
+ thread metal::sampler const &sampler, |
| 11107 |
+ thread metal::float4 const &coord, |
| 11108 |
+ float bias = 0) |
| 11109 |
+{ |
| 11110 |
+ return texture.sample(sampler, coord.xy/coord.w, metal::bias(bias)); |
| 11111 |
+} |
| 11112 |
+)", |
| 11113 |
+ textureEnv()) |
| 11114 |
+ |
| 11115 |
+PROGRAM_PRELUDE_DECLARE(texture2DProjLod, |
| 11116 |
+ R"( |
| 11117 |
+#define ANGLE_texture2DProjLod(env, ...) ANGLE_texture2DProjLod_impl(*env.texture, *env.sampler, __VA_ARGS__) |
| 11118 |
+ |
| 11119 |
+template <typename Texture> |
| 11120 |
+ANGLE_ALWAYS_INLINE auto ANGLE_texture2DProjLod_impl( |
| 11121 |
+ thread Texture &texture, |
| 11122 |
+ thread metal::sampler const &sampler, |
| 11123 |
+ thread metal::float3 const &coord, |
| 11124 |
+ float level) |
| 11125 |
+{ |
| 11126 |
+ return texture.sample(sampler, coord.xy/coord.z, metal::level(level)); |
| 11127 |
+} |
| 11128 |
+ |
| 11129 |
+template <typename Texture> |
| 11130 |
+ANGLE_ALWAYS_INLINE auto ANGLE_texture2DProjLod_impl( |
| 11131 |
+ thread Texture &texture, |
| 11132 |
+ thread metal::sampler const &sampler, |
| 11133 |
+ thread metal::float4 const &coord, |
| 11134 |
+ float level) |
| 11135 |
+{ |
| 11136 |
+ return texture.sample(sampler, coord.xy/coord.w, metal::level(level)); |
| 11137 |
+} |
| 11138 |
+)", |
| 11139 |
+ textureEnv()) |
| 11140 |
+ |
| 11141 |
+PROGRAM_PRELUDE_DECLARE(texture3DLod, |
| 11142 |
+ R"( |
| 11143 |
+#define ANGLE_texture3DLod(env, ...) ANGLE_texture3DLod_impl(*env.texture, *env.sampler, __VA_ARGS__) |
| 11144 |
+ |
| 11145 |
+template <typename Texture> |
| 11146 |
+ANGLE_ALWAYS_INLINE auto ANGLE_texture3DLod_impl( |
| 11147 |
+ thread Texture &texture, |
| 11148 |
+ thread metal::sampler const &sampler, |
| 11149 |
+ thread metal::float3 const &coord, |
| 11150 |
+ float level) |
| 11151 |
+{ |
| 11152 |
+ return texture.sample(sampler, coord, metal::level(level)); |
| 11153 |
+} |
| 11154 |
+)", |
| 11155 |
+ textureEnv()) |
| 11156 |
+ |
| 11157 |
+PROGRAM_PRELUDE_DECLARE(texture3DProj, |
| 11158 |
+ R"( |
| 11159 |
+#define ANGLE_texture3DProj(env, ...) ANGLE_texture3DProj_impl(*env.texture, *env.sampler, __VA_ARGS__) |
| 11160 |
+ |
| 11161 |
+template <typename Texture> |
| 11162 |
+ANGLE_ALWAYS_INLINE auto ANGLE_texture3DProj_impl( |
| 11163 |
+ thread Texture &texture, |
| 11164 |
+ thread metal::sampler const &sampler, |
| 11165 |
+ thread metal::float4 const &coord, |
| 11166 |
+ float bias = 0) |
| 11167 |
+{ |
| 11168 |
+ return texture.sample(sampler, coord.xyz/coord.w, metal::bias(bias)); |
| 11169 |
+} |
| 11170 |
+)", |
| 11171 |
+ textureEnv()) |
| 11172 |
+ |
| 11173 |
+PROGRAM_PRELUDE_DECLARE(texture3DProjLod, |
| 11174 |
+ R"( |
| 11175 |
+#define ANGLE_texture3DProjLod(env, ...) ANGLE_texture3DProjLod_impl(*env.texture, *env.sampler, __VA_ARGS__) |
| 11176 |
+ |
| 11177 |
+template <typename Texture> |
| 11178 |
+ANGLE_ALWAYS_INLINE auto ANGLE_texture3DProjLod_impl( |
| 11179 |
+ thread Texture &texture, |
| 11180 |
+ thread metal::sampler const &sampler, |
| 11181 |
+ thread metal::float4 const &coord, |
| 11182 |
+ float level) |
| 11183 |
+{ |
| 11184 |
+ return texture.sample(sampler, coord.xyz/coord.w, metal::level(level)); |
| 11185 |
+} |
| 11186 |
+)", |
| 11187 |
+ textureEnv()) |
| 11188 |
+ |
| 11189 |
+PROGRAM_PRELUDE_DECLARE(textureCube, |
| 11190 |
+ R"( |
| 11191 |
+#define ANGLE_textureCube(env, ...) ANGLE_textureCube_impl(*env.texture, *env.sampler, __VA_ARGS__) |
| 11192 |
+ |
| 11193 |
+template <typename Texture> |
| 11194 |
+ANGLE_ALWAYS_INLINE auto ANGLE_textureCube_impl( |
| 11195 |
+ thread Texture &texture, |
| 11196 |
+ thread metal::sampler const &sampler, |
| 11197 |
+ thread metal::float3 const &coord) |
| 11198 |
+{ |
| 11199 |
+ return texture.sample(sampler, coord); |
| 11200 |
+} |
| 11201 |
+ |
| 11202 |
+template <typename Texture> |
| 11203 |
+ANGLE_ALWAYS_INLINE auto ANGLE_textureCube_impl( |
| 11204 |
+ thread Texture &texture, |
| 11205 |
+ thread metal::sampler const &sampler, |
| 11206 |
+ thread metal::float3 const &coord, |
| 11207 |
+ float bias) |
| 11208 |
+{ |
| 11209 |
+ return texture.sample(sampler, coord, metal::bias(bias)); |
| 11210 |
+} |
| 11211 |
+)", |
| 11212 |
+ textureEnv()) |
| 11213 |
+ |
| 11214 |
+PROGRAM_PRELUDE_DECLARE(textureCubeLod, |
| 11215 |
+ R"( |
| 11216 |
+#define ANGLE_textureCubeLod(env, ...) ANGLE_textureCubeLod_impl(*env.texture, *env.sampler, __VA_ARGS__) |
| 11217 |
+ |
| 11218 |
+template <typename Texture> |
| 11219 |
+ANGLE_ALWAYS_INLINE auto ANGLE_textureCubeLod_impl( |
| 11220 |
+ thread Texture &texture, |
| 11221 |
+ thread metal::sampler const &sampler, |
| 11222 |
+ thread metal::float3 const &coord, |
| 11223 |
+ float level) |
| 11224 |
+{ |
| 11225 |
+ return texture.sample(sampler, coord, metal::level(level)); |
| 11226 |
+} |
| 11227 |
+)", |
| 11228 |
+ textureEnv()) |
| 11229 |
+ |
| 11230 |
+PROGRAM_PRELUDE_DECLARE(textureCubeProj, |
| 11231 |
+ R"( |
| 11232 |
+#define ANGLE_textureCubeProj(env, ...) ANGLE_textureCubeProj_impl(*env.texture, *env.sampler, __VA_ARGS__) |
| 11233 |
+ |
| 11234 |
+template <typename Texture> |
| 11235 |
+ANGLE_ALWAYS_INLINE auto ANGLE_textureCubeProj_impl( |
| 11236 |
+ thread Texture &texture, |
| 11237 |
+ thread metal::sampler const &sampler, |
| 11238 |
+ thread metal::float4 const &coord, |
| 11239 |
+ float bias = 0) |
| 11240 |
+{ |
| 11241 |
+ return texture.sample(sampler, coord.xyz/coord.w, metal::bias(bias)); |
| 11242 |
+} |
| 11243 |
+)", |
| 11244 |
+ textureEnv()) |
| 11245 |
+ |
| 11246 |
+PROGRAM_PRELUDE_DECLARE(textureCubeProjLod, |
| 11247 |
+ R"( |
| 11248 |
+#define ANGLE_textureCubeProjLod(env, ...) ANGLE_textureCubeProjLod_impl(*env.texture, *env.sampler, __VA_ARGS__) |
| 11249 |
+ |
| 11250 |
+template <typename Texture> |
| 11251 |
+ANGLE_ALWAYS_INLINE auto ANGLE_textureCubeProjLod_impl( |
| 11252 |
+ thread Texture &texture, |
| 11253 |
+ thread metal::sampler const &sampler, |
| 11254 |
+ thread metal::float4 const &coord, |
| 11255 |
+ float level) |
| 11256 |
+{ |
| 11257 |
+ return texture.sample(sampler, coord.xyz/coord.w, metal::level(level)); |
| 11258 |
+} |
| 11259 |
+)", |
| 11260 |
+ textureEnv()) |
| 11261 |
+ |
| 11262 |
+PROGRAM_PRELUDE_DECLARE(textureGrad, |
| 11263 |
+ R"( |
| 11264 |
+#define ANGLE_textureGrad(env, ...) ANGLE_textureGrad_impl(*env.texture, *env.sampler, __VA_ARGS__) |
| 11265 |
+)", |
| 11266 |
+ textureEnv()) |
| 11267 |
+ |
| 11268 |
+PROGRAM_PRELUDE_DECLARE(textureGrad_generic_floatN_floatN_floatN, |
| 11269 |
+ R"( |
| 11270 |
+template <typename Texture, int N> |
| 11271 |
+ANGLE_ALWAYS_INLINE auto ANGLE_textureGrad_impl( |
| 11272 |
+ thread Texture &texture, |
| 11273 |
+ thread metal::sampler const &sampler, |
| 11274 |
+ thread metal::vec<float, N> const &coord, |
| 11275 |
+ thread metal::vec<float, N> const &dPdx, |
| 11276 |
+ thread metal::vec<float, N> const &dPdy) |
| 11277 |
+{ |
| 11278 |
+ return texture.sample(sampler, coord, ANGLE_gradient<N>(dPdx, dPdy)); |
| 11279 |
+} |
| 11280 |
+)", |
| 11281 |
+ gradient(), |
| 11282 |
+ textureGrad()) |
| 11283 |
+ |
| 11284 |
+PROGRAM_PRELUDE_DECLARE(textureGrad_generic_float3_float2_float2, |
| 11285 |
+ R"( |
| 11286 |
+template <typename Texture> |
| 11287 |
+ANGLE_ALWAYS_INLINE auto ANGLE_textureGrad_impl( |
| 11288 |
+ thread Texture &texture, |
| 11289 |
+ thread metal::sampler const &sampler, |
| 11290 |
+ thread metal::float3 const &coord, |
| 11291 |
+ thread metal::float2 const &dPdx, |
| 11292 |
+ thread metal::float2 const &dPdy) |
| 11293 |
+{ |
| 11294 |
+ return texture.sample(sampler, coord.xy, uint(metal::round(coord.z)), metal::gradient2d(dPdx, dPdy)); |
| 11295 |
+} |
| 11296 |
+)", |
| 11297 |
+ textureGrad()) |
| 11298 |
+ |
| 11299 |
+PROGRAM_PRELUDE_DECLARE(textureGrad_generic_float4_float2_float2, |
| 11300 |
+ R"( |
| 11301 |
+template <typename Texture> |
| 11302 |
+ANGLE_ALWAYS_INLINE auto ANGLE_textureGrad_impl( |
| 11303 |
+ thread Texture &texture, |
| 11304 |
+ thread metal::sampler const &sampler, |
| 11305 |
+ thread metal::float4 const &coord, |
| 11306 |
+ thread metal::float2 const &dPdx, |
| 11307 |
+ thread metal::float2 const &dPdy) |
| 11308 |
+{ |
| 11309 |
+ return texture.sample(sampler, coord.xy, uint(metal::round(coord.z)), metal::gradient2d(dPdx, dPdy)); |
| 11310 |
+} |
| 11311 |
+)", |
| 11312 |
+ textureGrad()) |
| 11313 |
+ |
| 11314 |
+PROGRAM_PRELUDE_DECLARE(textureGrad_depth2d_float3_float2_float2, |
| 11315 |
+ R"( |
| 11316 |
+template <typename T> |
| 11317 |
+ANGLE_ALWAYS_INLINE auto ANGLE_textureGrad_impl( |
| 11318 |
+ thread metal::depth2d<T> &texture, |
| 11319 |
+ thread metal::sampler const &sampler, |
| 11320 |
+ thread metal::float3 const &coord, |
| 11321 |
+ thread metal::float2 const &dPdx, |
| 11322 |
+ thread metal::float2 const &dPdy) |
| 11323 |
+{ |
| 11324 |
+ if (ANGLE_UseSampleCompareGradient) |
| 11325 |
+ { |
| 11326 |
+ return static_cast<T>(texture.sample_compare(sampler, coord.xy, coord.z, metal::gradient2d(dPdx, dPdy))); |
| 11327 |
+ } |
| 11328 |
+ else |
| 11329 |
+ { |
| 11330 |
+ return static_cast<T>(texture.sample(sampler, coord.xy, metal::gradient2d(dPdx, dPdy)) > coord.z); |
| 11331 |
+ } |
| 11332 |
+} |
| 11333 |
+)", |
| 11334 |
+ functionConstants(), |
| 11335 |
+ textureGrad()) |
| 11336 |
+ |
| 11337 |
+PROGRAM_PRELUDE_DECLARE(textureGrad_depth2darray_float4_float2_float2, |
| 11338 |
+ R"( |
| 11339 |
+template <typename T> |
| 11340 |
+ANGLE_ALWAYS_INLINE auto ANGLE_textureGrad_impl( |
| 11341 |
+ thread metal::depth2d_array<T> &texture, |
| 11342 |
+ thread metal::sampler const &sampler, |
| 11343 |
+ thread metal::float4 const &coord, |
| 11344 |
+ thread metal::float2 const &dPdx, |
| 11345 |
+ thread metal::float2 const &dPdy) |
| 11346 |
+{ |
| 11347 |
+ if (ANGLE_UseSampleCompareGradient) |
| 11348 |
+ { |
| 11349 |
+ return static_cast<T>(texture.sample_compare(sampler, coord.xy, uint(metal::round(coord.z)), coord.w, metal::gradient2d(dPdx, dPdy))); |
| 11350 |
+ } |
| 11351 |
+ else |
| 11352 |
+ { |
| 11353 |
+ return static_cast<T>(texture.sample(sampler, coord.xy, uint(metal::round(coord.z)), metal::gradient2d(dPdx, dPdy)) > coord.w); |
| 11354 |
+ } |
| 11355 |
+} |
| 11356 |
+)", |
| 11357 |
+ functionConstants(), |
| 11358 |
+ textureGrad()) |
| 11359 |
+ |
| 11360 |
+PROGRAM_PRELUDE_DECLARE(textureGrad_depthcube_float4_float3_float3, |
| 11361 |
+ R"( |
| 11362 |
+template <typename T> |
| 11363 |
+ANGLE_ALWAYS_INLINE auto ANGLE_textureGrad_impl( |
| 11364 |
+ thread metal::depthcube<T> &texture, |
| 11365 |
+ thread metal::sampler const &sampler, |
| 11366 |
+ thread metal::float4 const &coord, |
| 11367 |
+ thread metal::float3 const &dPdx, |
| 11368 |
+ thread metal::float3 const &dPdy) |
| 11369 |
+{ |
| 11370 |
+ if (ANGLE_UseSampleCompareGradient) |
| 11371 |
+ { |
| 11372 |
+ return static_cast<T>(texture.sample_compare(sampler, coord.xyz, coord.w, metal::gradientcube(dPdx, dPdy))); |
| 11373 |
+ } |
| 11374 |
+ else |
| 11375 |
+ { |
| 11376 |
+ return static_cast<T>(texture.sample(sampler, coord.xyz, metal::gradientcube(dPdx, dPdy)) > coord.w); |
| 11377 |
+ } |
| 11378 |
+} |
| 11379 |
+)", |
| 11380 |
+ functionConstants(), |
| 11381 |
+ textureGrad()) |
| 11382 |
+ |
| 11383 |
+PROGRAM_PRELUDE_DECLARE(textureGrad_texturecube_float3_float3_float3, |
| 11384 |
+ R"( |
| 11385 |
+template <typename T> |
| 11386 |
+ANGLE_ALWAYS_INLINE auto ANGLE_textureGrad_impl( |
| 11387 |
+ thread metal::texturecube<T> &texture, |
| 11388 |
+ thread metal::sampler const &sampler, |
| 11389 |
+ thread metal::float3 const &coord, |
| 11390 |
+ thread metal::float3 const &dPdx, |
| 11391 |
+ thread metal::float3 const &dPdy) |
| 11392 |
+{ |
| 11393 |
+ return texture.sample(sampler, coord, metal::gradientcube(dPdx, dPdy)); |
| 11394 |
+} |
| 11395 |
+)", |
| 11396 |
+ textureGrad()) |
| 11397 |
+ |
| 11398 |
+PROGRAM_PRELUDE_DECLARE(textureGradOffset, |
| 11399 |
+ R"( |
| 11400 |
+#define ANGLE_textureGradOffset(env, ...) ANGLE_textureGradOffset_impl(*env.texture, *env.sampler, __VA_ARGS__) |
| 11401 |
+)", |
| 11402 |
+ textureEnv()) |
| 11403 |
+ |
| 11404 |
+PROGRAM_PRELUDE_DECLARE(textureGradOffset_generic_floatN_floatN_floatN_intN, |
| 11405 |
+ R"( |
| 11406 |
+template <typename Texture, int N> |
| 11407 |
+ANGLE_ALWAYS_INLINE auto ANGLE_textureGradOffset_impl( |
| 11408 |
+ thread Texture &texture, |
| 11409 |
+ thread metal::sampler const &sampler, |
| 11410 |
+ thread metal::vec<float, N> const &coord, |
| 11411 |
+ thread metal::vec<float, N> const &dPdx, |
| 11412 |
+ thread metal::vec<float, N> const &dPdy, |
| 11413 |
+ thread metal::vec<int, N> const &offset) |
| 11414 |
+{ |
| 11415 |
+ return texture.sample(sampler, coord, ANGLE_gradient<N>(dPdx, dPdy), offset); |
| 11416 |
+} |
| 11417 |
+)", |
| 11418 |
+ gradient(), |
| 11419 |
+ textureGradOffset()) |
| 11420 |
+ |
| 11421 |
+PROGRAM_PRELUDE_DECLARE(textureGradOffset_generic_float3_float2_float2_int2, |
| 11422 |
+ R"( |
| 11423 |
+template <typename Texture> |
| 11424 |
+ANGLE_ALWAYS_INLINE auto ANGLE_textureGradOffset_impl( |
| 11425 |
+ thread Texture &texture, |
| 11426 |
+ thread metal::sampler const &sampler, |
| 11427 |
+ thread metal::float3 const &coord, |
| 11428 |
+ thread metal::float2 const &dPdx, |
| 11429 |
+ thread metal::float2 const &dPdy, |
| 11430 |
+ thread metal::int2 const &offset) |
| 11431 |
+{ |
| 11432 |
+ return texture.sample(sampler, coord.xy, uint(metal::round(coord.z)), metal::gradient2d(dPdx, dPdy), offset); |
| 11433 |
+} |
| 11434 |
+)", |
| 11435 |
+ textureGradOffset()) |
| 11436 |
+ |
| 11437 |
+PROGRAM_PRELUDE_DECLARE(textureGradOffset_generic_float4_float2_float2_int2, |
| 11438 |
+ R"( |
| 11439 |
+template <typename Texture> |
| 11440 |
+ANGLE_ALWAYS_INLINE auto ANGLE_textureGradOffset_impl( |
| 11441 |
+ thread Texture &texture, |
| 11442 |
+ thread metal::sampler const &sampler, |
| 11443 |
+ thread metal::float4 const &coord, |
| 11444 |
+ thread metal::float2 const &dPdx, |
| 11445 |
+ thread metal::float2 const &dPdy, |
| 11446 |
+ thread metal::int2 const &offset) |
| 11447 |
+{ |
| 11448 |
+ return texture.sample(sampler, coord.xy, uint(metal::round(coord.z)), metal::gradient2d(dPdx, dPdy), offset); |
| 11449 |
+} |
| 11450 |
+)", |
| 11451 |
+ textureGradOffset()) |
| 11452 |
+ |
| 11453 |
+PROGRAM_PRELUDE_DECLARE(textureGradOffset_depth2d_float3_float2_float2_int2, |
| 11454 |
+ R"( |
| 11455 |
+template <typename T> |
| 11456 |
+ANGLE_ALWAYS_INLINE auto ANGLE_textureGradOffset_impl( |
| 11457 |
+ thread metal::depth2d<T> &texture, |
| 11458 |
+ thread metal::sampler const &sampler, |
| 11459 |
+ thread metal::float3 const &coord, |
| 11460 |
+ thread metal::float2 const &dPdx, |
| 11461 |
+ thread metal::float2 const &dPdy, |
| 11462 |
+ thread metal::int2 const &offset) |
| 11463 |
+{ |
| 11464 |
+ if (ANGLE_UseSampleCompareGradient) |
| 11465 |
+ { |
| 11466 |
+ return static_cast<T>(texture.sample_compare(sampler, coord.xy, coord.z, metal::gradient2d(dPdx, dPdy), offset)); |
| 11467 |
+ } |
| 11468 |
+ else |
| 11469 |
+ { |
| 11470 |
+ return static_cast<T>(texture.sample(sampler, coord.xy, metal::gradient2d(dPdx, dPdy), offset) > coord.z); |
| 11471 |
+ } |
| 11472 |
+} |
| 11473 |
+)", |
| 11474 |
+ functionConstants(), |
| 11475 |
+ textureGradOffset()) |
| 11476 |
+ |
| 11477 |
+PROGRAM_PRELUDE_DECLARE(textureGradOffset_depth2darray_float4_float2_float2_int2, |
| 11478 |
+ R"( |
| 11479 |
+template <typename T> |
| 11480 |
+ANGLE_ALWAYS_INLINE auto ANGLE_textureGradOffset_impl( |
| 11481 |
+ thread metal::depth2d_array<T> &texture, |
| 11482 |
+ thread metal::sampler const &sampler, |
| 11483 |
+ thread metal::float4 const &coord, |
| 11484 |
+ thread metal::float2 const &dPdx, |
| 11485 |
+ thread metal::float2 const &dPdy, |
| 11486 |
+ thread metal::int2 const &offset) |
| 11487 |
+{ |
| 11488 |
+ if (ANGLE_UseSampleCompareGradient) |
| 11489 |
+ { |
| 11490 |
+ return static_cast<T>(texture.sample_compare(sampler, coord.xy, uint(metal::round(coord.z)), coord.w, metal::gradient2d(dPdx, dPdy), offset)); |
| 11491 |
+ } |
| 11492 |
+ else |
| 11493 |
+ { |
| 11494 |
+ return static_cast<T>(texture.sample(sampler, coord.xy, uint(metal::round(coord.z)), metal::gradient2d(dPdx, dPdy), offset) > coord.w); |
| 11495 |
+ } |
| 11496 |
+} |
| 11497 |
+)", |
| 11498 |
+ functionConstants(), |
| 11499 |
+ textureGradOffset()) |
| 11500 |
+ |
| 11501 |
+PROGRAM_PRELUDE_DECLARE(textureGradOffset_depthcube_float4_float3_float3_int3, |
| 11502 |
+ R"( |
| 11503 |
+template <typename T> |
| 11504 |
+ANGLE_ALWAYS_INLINE auto ANGLE_textureGradOffset_impl( |
| 11505 |
+ thread metal::depthcube<T> &texture, |
| 11506 |
+ thread metal::sampler const &sampler, |
| 11507 |
+ thread metal::float4 const &coord, |
| 11508 |
+ thread metal::float3 const &dPdx, |
| 11509 |
+ thread metal::float3 const &dPdy, |
| 11510 |
+ thread metal::int3 const &offset) |
| 11511 |
+{ |
| 11512 |
+ return texture.sample(sampler, coord.xyz, metal::gradientcube(dPdx, dPdy), offset); |
| 11513 |
+} |
| 11514 |
+)", |
| 11515 |
+ textureGradOffset()) |
| 11516 |
+ |
| 11517 |
+PROGRAM_PRELUDE_DECLARE(textureGradOffset_texturecube_float3_float3_float3_int3, |
| 11518 |
+ R"( |
| 11519 |
+template <typename T> |
| 11520 |
+ANGLE_ALWAYS_INLINE auto ANGLE_textureGradOffset_impl( |
| 11521 |
+ thread metal::texturecube<T> &texture, |
| 11522 |
+ thread metal::sampler const &sampler, |
| 11523 |
+ thread metal::float3 const &coord, |
| 11524 |
+ thread metal::float3 const &dPdx, |
| 11525 |
+ thread metal::float3 const &dPdy, |
| 11526 |
+ thread metal::int3 const &offset) |
| 11527 |
+{ |
| 11528 |
+ return texture.sample(sampler, coord, metal::gradientcube(dPdx, dPdy), offset); |
| 11529 |
+} |
| 11530 |
+)", |
| 11531 |
+ textureGradOffset()) |
| 11532 |
+ |
| 11533 |
+PROGRAM_PRELUDE_DECLARE(textureLod, |
| 11534 |
+ R"( |
| 11535 |
+#define ANGLE_textureLod(env, ...) ANGLE_textureLod_impl(*env.texture, *env.sampler, __VA_ARGS__) |
| 11536 |
+)", |
| 11537 |
+ textureEnv()) |
| 11538 |
+ |
| 11539 |
+PROGRAM_PRELUDE_DECLARE(textureLod_generic_float2, |
| 11540 |
+ R"( |
| 11541 |
+template <typename Texture> |
| 11542 |
+ANGLE_ALWAYS_INLINE auto ANGLE_textureLod_impl( |
| 11543 |
+ thread Texture &texture, |
| 11544 |
+ thread metal::sampler const &sampler, |
| 11545 |
+ thread metal::float2 const &coord, |
| 11546 |
+ float level) |
| 11547 |
+{ |
| 11548 |
+ return texture.sample(sampler, coord, metal::level(level)); |
| 11549 |
+} |
| 11550 |
+)", |
| 11551 |
+ textureLod()) |
| 11552 |
+ |
| 11553 |
+PROGRAM_PRELUDE_DECLARE(textureLod_generic_float3, |
| 11554 |
+ R"( |
| 11555 |
+template <typename Texture> |
| 11556 |
+ANGLE_ALWAYS_INLINE auto ANGLE_textureLod_impl( |
| 11557 |
+ thread Texture &texture, |
| 11558 |
+ thread metal::sampler const &sampler, |
| 11559 |
+ thread metal::float3 const &coord, |
| 11560 |
+ float level) |
| 11561 |
+{ |
| 11562 |
+ return texture.sample(sampler, coord, metal::level(level)); |
| 11563 |
+} |
| 11564 |
+)", |
| 11565 |
+ textureLod()) |
| 11566 |
+ |
| 11567 |
+PROGRAM_PRELUDE_DECLARE(textureLod_depth2d_float3, |
| 11568 |
+ R"( |
| 11569 |
+template <typename T> |
| 11570 |
+ANGLE_ALWAYS_INLINE auto ANGLE_textureLod_impl( |
| 11571 |
+ thread metal::depth2d<T> &texture, |
| 11572 |
+ thread metal::sampler const &sampler, |
| 11573 |
+ thread metal::float3 const &coord, |
| 11574 |
+ float level) |
| 11575 |
+{ |
| 11576 |
+ if (ANGLE_UseSampleCompareLod) |
| 11577 |
+ { |
| 11578 |
+ return static_cast<T>(texture.sample_compare(sampler, coord.xy, coord.z, metal::level(level))); |
| 11579 |
+ } |
| 11580 |
+ else |
| 11581 |
+ { |
| 11582 |
+ return static_cast<T>(texture.sample(sampler, coord.xy, metal::level(level)) > coord.z); |
| 11583 |
+ } |
| 11584 |
+} |
| 11585 |
+)", |
| 11586 |
+ functionConstants(), |
| 11587 |
+ textureLod()) |
| 11588 |
+ |
| 11589 |
+PROGRAM_PRELUDE_DECLARE(textureLod_texture2darray_float3, |
| 11590 |
+ R"( |
| 11591 |
+template <typename T> |
| 11592 |
+ANGLE_ALWAYS_INLINE auto ANGLE_textureLod_impl( |
| 11593 |
+ thread metal::texture2d_array<T> &texture, |
| 11594 |
+ thread metal::sampler const &sampler, |
| 11595 |
+ thread metal::float3 const &coord, |
| 11596 |
+ float level) |
| 11597 |
+{ |
| 11598 |
+ return texture.sample(sampler, coord.xy, uint(metal::round(coord.z)), metal::level(level)); |
| 11599 |
+} |
| 11600 |
+)", |
| 11601 |
+ textureLod()) |
| 11602 |
+ |
| 11603 |
+PROGRAM_PRELUDE_DECLARE(textureLod_texture2darray_float4, |
| 11604 |
+ R"( |
| 11605 |
+template <typename T> |
| 11606 |
+ANGLE_ALWAYS_INLINE auto ANGLE_textureLod_impl( |
| 11607 |
+ thread metal::texture2d_array<T> &texture, |
| 11608 |
+ thread metal::sampler const &sampler, |
| 11609 |
+ thread metal::float4 const &coord, |
| 11610 |
+ float level) |
| 11611 |
+{ |
| 11612 |
+ return texture.sample(sampler, coord.xyz, uint(metal::round(coord.w)), metal::level(level)); |
| 11613 |
+} |
| 11614 |
+)", |
| 11615 |
+ textureLod()) |
| 11616 |
+ |
| 11617 |
+PROGRAM_PRELUDE_DECLARE(textureLodOffset, |
| 11618 |
+ R"( |
| 11619 |
+#define ANGLE_textureLodOffset(env, ...) ANGLE_textureLodOffset_impl(*env.texture, *env.sampler, __VA_ARGS__) |
| 11620 |
+ |
| 11621 |
+template <typename Texture> |
| 11622 |
+ANGLE_ALWAYS_INLINE auto ANGLE_textureLodOffset_impl( |
| 11623 |
+ thread Texture &texture, |
| 11624 |
+ thread metal::sampler const &sampler, |
| 11625 |
+ thread metal::float2 const &coord, |
| 11626 |
+ float level, |
| 11627 |
+ thread int2 const &offset) |
| 11628 |
+{ |
| 11629 |
+ return texture.sample(sampler, coord, metal::level(level), offset); |
| 11630 |
+} |
| 11631 |
+ |
| 11632 |
+template <typename Texture> |
| 11633 |
+ANGLE_ALWAYS_INLINE auto ANGLE_textureLodOffset_impl( |
| 11634 |
+ thread Texture &texture, |
| 11635 |
+ thread metal::sampler const &sampler, |
| 11636 |
+ thread metal::float3 const &coord, |
| 11637 |
+ float level, |
| 11638 |
+ thread int3 const &offset) |
| 11639 |
+{ |
| 11640 |
+ return texture.sample(sampler, coord, metal::level(level), offset); |
| 11641 |
+} |
| 11642 |
+ |
| 11643 |
+template <typename T> |
| 11644 |
+ANGLE_ALWAYS_INLINE auto ANGLE_textureLodOffset_impl( |
| 11645 |
+ thread metal::depth2d<T> &texture, |
| 11646 |
+ thread metal::sampler const &sampler, |
| 11647 |
+ thread metal::float3 const &coord, |
| 11648 |
+ float level, |
| 11649 |
+ thread int2 const &offset) |
| 11650 |
+{ |
| 11651 |
+ if (ANGLE_UseSampleCompareLod) |
| 11652 |
+ { |
| 11653 |
+ return static_cast<T>(texture.sample_compare(sampler, coord.xy, coord.z, metal::level(level), offset)); |
| 11654 |
+ } |
| 11655 |
+ else |
| 11656 |
+ { |
| 11657 |
+ return static_cast<T>(texture.sample(sampler, coord.xy, metal::level(level), offset) > coord.z); |
| 11658 |
+ } |
| 11659 |
+} |
| 11660 |
+ |
| 11661 |
+template <typename T> |
| 11662 |
+ANGLE_ALWAYS_INLINE auto ANGLE_textureLodOffset_impl( |
| 11663 |
+ thread metal::texture2d_array<T> &texture, |
| 11664 |
+ thread metal::sampler const &sampler, |
| 11665 |
+ thread metal::float3 const &coord, |
| 11666 |
+ float level, |
| 11667 |
+ thread int2 const &offset) |
| 11668 |
+{ |
| 11669 |
+ return texture.sample(sampler, coord.xy, uint(metal::round(coord.z)), metal::level(level), offset); |
| 11670 |
+} |
| 11671 |
+ |
| 11672 |
+template <typename T> |
| 11673 |
+ANGLE_ALWAYS_INLINE auto ANGLE_textureLodOffset_impl( |
| 11674 |
+ thread metal::texture2d_array<T> &texture, |
| 11675 |
+ thread metal::sampler const &sampler, |
| 11676 |
+ thread metal::float4 const &coord, |
| 11677 |
+ float level, |
| 11678 |
+ thread int3 const &offset) |
| 11679 |
+{ |
| 11680 |
+ return texture.sample(sampler, coord.xyz, uint(metal::round(coord.w)), metal::level(level), offset); |
| 11681 |
+} |
| 11682 |
+)", |
| 11683 |
+ functionConstants(), |
| 11684 |
+ textureEnv()) |
| 11685 |
+ |
| 11686 |
+PROGRAM_PRELUDE_DECLARE(textureOffset, |
| 11687 |
+ R"( |
| 11688 |
+#define ANGLE_textureOffset(env, ...) ANGLE_textureOffset_impl(*env.texture, *env.sampler, __VA_ARGS__) |
| 11689 |
+ |
| 11690 |
+template <typename Texture> |
| 11691 |
+ANGLE_ALWAYS_INLINE auto ANGLE_textureOffset_impl( |
| 11692 |
+ thread Texture &texture, |
| 11693 |
+ thread metal::sampler const &sampler, |
| 11694 |
+ thread float2 const &coord, |
| 11695 |
+ thread int2 const &offset) |
| 11696 |
+{ |
| 11697 |
+ return texture.sample(sampler, coord, offset); |
| 11698 |
+} |
| 11699 |
+ |
| 11700 |
+template <typename Texture> |
| 11701 |
+ANGLE_ALWAYS_INLINE auto ANGLE_textureOffset_impl( |
| 11702 |
+ thread Texture &texture, |
| 11703 |
+ thread metal::sampler const &sampler, |
| 11704 |
+ thread float2 const &coord, |
| 11705 |
+ thread int2 const &offset, |
| 11706 |
+ float bias) |
| 11707 |
+{ |
| 11708 |
+ return texture.sample(sampler, coord, metal::bias(bias), offset); |
| 11709 |
+} |
| 11710 |
+ |
| 11711 |
+template <typename Texture> |
| 11712 |
+ANGLE_ALWAYS_INLINE auto ANGLE_textureOffset_impl( |
| 11713 |
+ thread Texture &texture, |
| 11714 |
+ thread metal::sampler const &sampler, |
| 11715 |
+ thread float3 const &coord, |
| 11716 |
+ thread int2 const &offset) |
| 11717 |
+{ |
| 11718 |
+ return texture.sample(sampler, coord.xy, uint(metal::round(coord.z)), offset); |
| 11719 |
+} |
| 11720 |
+ |
| 11721 |
+template <typename Texture> |
| 11722 |
+ANGLE_ALWAYS_INLINE auto ANGLE_textureOffset_impl( |
| 11723 |
+ thread Texture &texture, |
| 11724 |
+ thread metal::sampler const &sampler, |
| 11725 |
+ thread float3 const &coord, |
| 11726 |
+ thread int2 const &offset, |
| 11727 |
+ float bias) |
| 11728 |
+{ |
| 11729 |
+ return texture.sample(sampler, coord.xy, uint(metal::round(coord.z)), metal::bias(bias), offset); |
| 11730 |
+} |
| 11731 |
+ |
| 11732 |
+template <typename Texture> |
| 11733 |
+ANGLE_ALWAYS_INLINE auto ANGLE_textureOffset_impl( |
| 11734 |
+ thread Texture &texture, |
| 11735 |
+ thread metal::sampler const &sampler, |
| 11736 |
+ thread float3 const &coord, |
| 11737 |
+ thread int3 const &offset) |
| 11738 |
+{ |
| 11739 |
+ return texture.sample(sampler, coord, offset); |
| 11740 |
+} |
| 11741 |
+ |
| 11742 |
+template <typename Texture> |
| 11743 |
+ANGLE_ALWAYS_INLINE auto ANGLE_textureOffset_impl( |
| 11744 |
+ thread Texture &texture, |
| 11745 |
+ thread metal::sampler const &sampler, |
| 11746 |
+ thread float3 const &coord, |
| 11747 |
+ thread int3 const &offset, |
| 11748 |
+ float bias) |
| 11749 |
+{ |
| 11750 |
+ return texture.sample(sampler, coord, metal::bias(bias), offset); |
| 11751 |
+} |
| 11752 |
+ |
| 11753 |
+template <typename T> |
| 11754 |
+ANGLE_ALWAYS_INLINE auto ANGLE_textureOffset_impl( |
| 11755 |
+ thread metal::depth2d<T> &texture, |
| 11756 |
+ thread metal::sampler const &sampler, |
| 11757 |
+ thread float3 const &coord, |
| 11758 |
+ thread int2 const &offset) |
| 11759 |
+{ |
| 11760 |
+ return texture.sample(sampler, coord.xy, offset); |
| 11761 |
+} |
| 11762 |
+ |
| 11763 |
+template <typename T> |
| 11764 |
+ANGLE_ALWAYS_INLINE auto ANGLE_textureOffset_impl( |
| 11765 |
+ thread metal::depth2d<T> &texture, |
| 11766 |
+ thread metal::sampler const &sampler, |
| 11767 |
+ thread float3 const &coord, |
| 11768 |
+ thread int2 const &offset, |
| 11769 |
+ float bias) |
| 11770 |
+{ |
| 11771 |
+ return texture.sample(sampler, coord.xy, metal::bias(bias), offset); |
| 11772 |
+} |
| 11773 |
+)", |
| 11774 |
+ textureEnv()) |
| 11775 |
+ |
| 11776 |
+PROGRAM_PRELUDE_DECLARE(textureProj, |
| 11777 |
+ R"( |
| 11778 |
+#define ANGLE_textureProj(env, ...) ANGLE_textureProj_impl(*env.texture, *env.sampler, __VA_ARGS__) |
| 11779 |
+ |
| 11780 |
+template <typename Texture> |
| 11781 |
+ANGLE_ALWAYS_INLINE auto ANGLE_textureProj_impl( |
| 11782 |
+ thread Texture &texture, |
| 11783 |
+ thread metal::sampler const &sampler, |
| 11784 |
+ thread metal::float3 const &coord, |
| 11785 |
+ float bias = 0) |
| 11786 |
+{ |
| 11787 |
+ return texture.sample(sampler, coord.xy/coord.z, metal::bias(bias)); |
| 11788 |
+} |
| 11789 |
+ |
| 11790 |
+template <typename Texture> |
| 11791 |
+ANGLE_ALWAYS_INLINE auto ANGLE_textureProj_impl( |
| 11792 |
+ thread Texture &texture, |
| 11793 |
+ thread metal::sampler const &sampler, |
| 11794 |
+ thread metal::float4 const &coord, |
| 11795 |
+ float bias = 0) |
| 11796 |
+{ |
| 11797 |
+ return texture.sample(sampler, coord.xy/coord.w, metal::bias(bias)); |
| 11798 |
+} |
| 11799 |
+ |
| 11800 |
+template <typename T> |
| 11801 |
+ANGLE_ALWAYS_INLINE auto ANGLE_textureProj_impl( |
| 11802 |
+ thread metal::texture3d<T> &texture, |
| 11803 |
+ thread metal::sampler const &sampler, |
| 11804 |
+ thread metal::float4 const &coord, |
| 11805 |
+ float bias = 0) |
| 11806 |
+{ |
| 11807 |
+ return texture.sample(sampler, coord.xyz/coord.w, metal::bias(bias)); |
| 11808 |
+} |
| 11809 |
+)", |
| 11810 |
+ textureEnv()) |
| 11811 |
+ |
| 11812 |
+PROGRAM_PRELUDE_DECLARE(textureProjGrad, |
| 11813 |
+ R"( |
| 11814 |
+#define ANGLE_textureProjGrad(env, ...) ANGLE_textureProjGrad_impl(*env.texture, *env.sampler, __VA_ARGS__) |
| 11815 |
+)", |
| 11816 |
+ textureEnv()) |
| 11817 |
+ |
| 11818 |
+PROGRAM_PRELUDE_DECLARE(textureProjGrad_generic_float3_float2_float2, |
| 11819 |
+ R"( |
| 11820 |
+template <typename Texture> |
| 11821 |
+ANGLE_ALWAYS_INLINE auto ANGLE_textureProjGrad_impl( |
| 11822 |
+ thread Texture &texture, |
| 11823 |
+ thread metal::sampler const &sampler, |
| 11824 |
+ thread metal::float3 const &coord, |
| 11825 |
+ thread metal::float2 const &dPdx, |
| 11826 |
+ thread metal::float2 const &dPdy) |
| 11827 |
+{ |
| 11828 |
+ return texture.sample(sampler, coord.xy/coord.z, metal::gradient2d(dPdx, dPdy)); |
| 11829 |
+} |
| 11830 |
+)", |
| 11831 |
+ textureProjGrad()) |
| 11832 |
+ |
| 11833 |
+PROGRAM_PRELUDE_DECLARE(textureProjGrad_generic_float4_float2_float2, |
| 11834 |
+ R"( |
| 11835 |
+template <typename Texture> |
| 11836 |
+ANGLE_ALWAYS_INLINE auto ANGLE_textureProjGrad_impl( |
| 11837 |
+ thread Texture &texture, |
| 11838 |
+ thread metal::sampler const &sampler, |
| 11839 |
+ thread metal::float4 const &coord, |
| 11840 |
+ thread metal::float2 const &dPdx, |
| 11841 |
+ thread metal::float2 const &dPdy) |
| 11842 |
+{ |
| 11843 |
+ return texture.sample(sampler, coord.xy/coord.w, metal::gradient2d(dPdx, dPdy)); |
| 11844 |
+} |
| 11845 |
+)", |
| 11846 |
+ textureProjGrad()) |
| 11847 |
+ |
| 11848 |
+PROGRAM_PRELUDE_DECLARE(textureProjGrad_depth2d_float4_float2_float2, |
| 11849 |
+ R"( |
| 11850 |
+template <typename T> |
| 11851 |
+ANGLE_ALWAYS_INLINE auto ANGLE_textureProjGrad_impl( |
| 11852 |
+ thread metal::depth2d<T> &texture, |
| 11853 |
+ thread metal::sampler const &sampler, |
| 11854 |
+ thread metal::float4 const &coord, |
| 11855 |
+ thread metal::float2 const &dPdx, |
| 11856 |
+ thread metal::float2 const &dPdy) |
| 11857 |
+{ |
| 11858 |
+ if (ANGLE_UseSampleCompareGradient) |
| 11859 |
+ { |
| 11860 |
+ return static_cast<T>(texture.sample_compare(sampler, coord.xy/coord.w, coord.z/coord.w, metal::gradient2d(dPdx, dPdy))); |
| 11861 |
+ } |
| 11862 |
+ else |
| 11863 |
+ { |
| 11864 |
+ return static_cast<T>(texture.sample(sampler, coord.xy/coord.w, metal::gradient2d(dPdx, dPdy)) > coord.z/coord.w); |
| 11865 |
+ } |
| 11866 |
+} |
| 11867 |
+)", |
| 11868 |
+ functionConstants(), |
| 11869 |
+ textureProjGrad()) |
| 11870 |
+ |
| 11871 |
+PROGRAM_PRELUDE_DECLARE(textureProjGrad_texture3d_float4_float3_float3, |
| 11872 |
+ R"( |
| 11873 |
+template <typename T> |
| 11874 |
+ANGLE_ALWAYS_INLINE auto ANGLE_textureProjGrad_impl( |
| 11875 |
+ thread metal::texture3d<T> &texture, |
| 11876 |
+ thread metal::sampler const &sampler, |
| 11877 |
+ thread metal::float4 const &coord, |
| 11878 |
+ thread metal::float3 const &dPdx, |
| 11879 |
+ thread metal::float3 const &dPdy) |
| 11880 |
+{ |
| 11881 |
+ return texture.sample(sampler, coord.xyz/coord.w, metal::gradient3d(dPdx, dPdy)); |
| 11882 |
+} |
| 11883 |
+)", |
| 11884 |
+ textureProjGrad()) |
| 11885 |
+ |
| 11886 |
+PROGRAM_PRELUDE_DECLARE(textureProjGradOffset, |
| 11887 |
+ R"( |
| 11888 |
+#define ANGLE_textureProjGradOffset(env, ...) ANGLE_textureProjGradOffset_impl(*env.texture, *env.sampler, __VA_ARGS__) |
| 11889 |
+)", |
| 11890 |
+ textureEnv()) |
| 11891 |
+ |
| 11892 |
+PROGRAM_PRELUDE_DECLARE(textureProjGradOffset_generic_float3_float2_float2_int2, |
| 11893 |
+ R"( |
| 11894 |
+template <typename Texture> |
| 11895 |
+ANGLE_ALWAYS_INLINE auto ANGLE_textureProjGradOffset_impl( |
| 11896 |
+ thread Texture &texture, |
| 11897 |
+ thread metal::sampler const &sampler, |
| 11898 |
+ thread metal::float3 const &coord, |
| 11899 |
+ thread metal::float2 const &dPdx, |
| 11900 |
+ thread metal::float2 const &dPdy, |
| 11901 |
+ thread int2 const &offset) |
| 11902 |
+{ |
| 11903 |
+ return texture.sample(sampler, coord.xy/coord.z, metal::gradient2d(dPdx, dPdy), offset); |
| 11904 |
+} |
| 11905 |
+)", |
| 11906 |
+ textureProjGradOffset()) |
| 11907 |
+ |
| 11908 |
+PROGRAM_PRELUDE_DECLARE(textureProjGradOffset_generic_float4_float2_float2_int2, |
| 11909 |
+ R"( |
| 11910 |
+template <typename Texture> |
| 11911 |
+ANGLE_ALWAYS_INLINE auto ANGLE_textureProjGradOffset_impl( |
| 11912 |
+ thread Texture &texture, |
| 11913 |
+ thread metal::sampler const &sampler, |
| 11914 |
+ thread metal::float4 const &coord, |
| 11915 |
+ thread metal::float2 const &dPdx, |
| 11916 |
+ thread metal::float2 const &dPdy, |
| 11917 |
+ thread int2 const &offset) |
| 11918 |
+{ |
| 11919 |
+ return texture.sample(sampler, coord.xy/coord.w, metal::gradient2d(dPdx, dPdy), offset); |
| 11920 |
+} |
| 11921 |
+)", |
| 11922 |
+ textureProjGradOffset()) |
| 11923 |
+ |
| 11924 |
+PROGRAM_PRELUDE_DECLARE(textureProjGradOffset_depth2d_float4_float2_float2_int2, |
| 11925 |
+ R"( |
| 11926 |
+template <typename T> |
| 11927 |
+ANGLE_ALWAYS_INLINE auto ANGLE_textureProjGradOffset_impl( |
| 11928 |
+ thread metal::depth2d<T> &texture, |
| 11929 |
+ thread metal::sampler const &sampler, |
| 11930 |
+ thread metal::float4 const &coord, |
| 11931 |
+ thread metal::float2 const &dPdx, |
| 11932 |
+ thread metal::float2 const &dPdy, |
| 11933 |
+ thread int2 const &offset) |
| 11934 |
+{ |
| 11935 |
+ if (ANGLE_UseSampleCompareGradient) |
| 11936 |
+ { |
| 11937 |
+ return static_cast<T>(texture.sample_compare(sampler, coord.xy/coord.w, coord.z/coord.w, metal::gradient2d(dPdx, dPdy), offset)); |
| 11938 |
+ } |
| 11939 |
+ else |
| 11940 |
+ { |
| 11941 |
+ return static_cast<T>(texture.sample(sampler, coord.xy/coord.w, metal::gradient2d(dPdx, dPdy), offset) > coord.z/coord.w); |
| 11942 |
+ } |
| 11943 |
+} |
| 11944 |
+)", |
| 11945 |
+ functionConstants(), |
| 11946 |
+ textureProjGradOffset()) |
| 11947 |
+ |
| 11948 |
+PROGRAM_PRELUDE_DECLARE(textureProjGradOffset_texture3d_float4_float3_float3_int3, |
| 11949 |
+ R"( |
| 11950 |
+template <typename T> |
| 11951 |
+ANGLE_ALWAYS_INLINE auto ANGLE_textureProjGradOffset_impl( |
| 11952 |
+ thread metal::texture3d<T> &texture, |
| 11953 |
+ thread metal::sampler const &sampler, |
| 11954 |
+ thread metal::float4 const &coord, |
| 11955 |
+ thread metal::float3 const &dPdx, |
| 11956 |
+ thread metal::float3 const &dPdy, |
| 11957 |
+ thread int3 const &offset) |
| 11958 |
+{ |
| 11959 |
+ return texture.sample(sampler, coord.xyz/coord.w, metal::gradient3d(dPdx, dPdy), offset); |
| 11960 |
+} |
| 11961 |
+)", |
| 11962 |
+ textureProjGradOffset()) |
| 11963 |
+ |
| 11964 |
+PROGRAM_PRELUDE_DECLARE(textureProjLod, |
| 11965 |
+ R"( |
| 11966 |
+#define ANGLE_textureProjLod(env, ...) ANGLE_textureProjLod_impl(*env.texture, *env.sampler, __VA_ARGS__) |
| 11967 |
+)", |
| 11968 |
+ textureEnv()) |
| 11969 |
+ |
| 11970 |
+PROGRAM_PRELUDE_DECLARE(textureProjLod_generic_float3, |
| 11971 |
+ R"( |
| 11972 |
+template <typename Texture> |
| 11973 |
+ANGLE_ALWAYS_INLINE auto ANGLE_textureProjLod_impl( |
| 11974 |
+ thread Texture &texture, |
| 11975 |
+ thread metal::sampler const &sampler, |
| 11976 |
+ thread metal::float3 const &coord, |
| 11977 |
+ float level) |
| 11978 |
+{ |
| 11979 |
+ return texture.sample(sampler, coord.xy/coord.z, metal::level(level)); |
| 11980 |
+} |
| 11981 |
+)", |
| 11982 |
+ textureProjLod()) |
| 11983 |
+ |
| 11984 |
+PROGRAM_PRELUDE_DECLARE(textureProjLod_generic_float4, |
| 11985 |
+ R"( |
| 11986 |
+template <typename Texture> |
| 11987 |
+ANGLE_ALWAYS_INLINE auto ANGLE_textureProjLod_impl( |
| 11988 |
+ thread Texture &texture, |
| 11989 |
+ thread metal::sampler const &sampler, |
| 11990 |
+ thread metal::float4 const &coord, |
| 11991 |
+ float level) |
| 11992 |
+{ |
| 11993 |
+ return texture.sample(sampler, coord.xy/coord.w, metal::level(level)); |
| 11994 |
+} |
| 11995 |
+)", |
| 11996 |
+ textureProjLod()) |
| 11997 |
+ |
| 11998 |
+PROGRAM_PRELUDE_DECLARE(textureProjLod_depth2d_float4, |
| 11999 |
+ R"( |
| 12000 |
+template <typename T> |
| 12001 |
+ANGLE_ALWAYS_INLINE auto ANGLE_textureProjLod_impl( |
| 12002 |
+ thread metal::depth2d<T> &texture, |
| 12003 |
+ thread metal::sampler const &sampler, |
| 12004 |
+ thread metal::float4 const &coord, |
| 12005 |
+ float level) |
| 12006 |
+{ |
| 12007 |
+ if (ANGLE_UseSampleCompareLod) |
| 12008 |
+ { |
| 12009 |
+ return static_cast<T>(texture.sample_compare(sampler, coord.xy/coord.w, coord.z/coord.w, metal::level(level))); |
| 12010 |
+ } |
| 12011 |
+ else |
| 12012 |
+ { |
| 12013 |
+ return static_cast<T>(texture.sample(sampler, coord.xy/coord.w, metal::level(level)) > coord.z/coord.w); |
| 12014 |
+ } |
| 12015 |
+} |
| 12016 |
+)", |
| 12017 |
+ functionConstants(), |
| 12018 |
+ textureProjLod()) |
| 12019 |
+ |
| 12020 |
+PROGRAM_PRELUDE_DECLARE(textureProjLod_texture3d_float4, |
| 12021 |
+ R"( |
| 12022 |
+template <typename T> |
| 12023 |
+ANGLE_ALWAYS_INLINE auto ANGLE_textureProjLod_impl( |
| 12024 |
+ thread metal::texture3d<T> &texture, |
| 12025 |
+ thread metal::sampler const &sampler, |
| 12026 |
+ thread metal::float4 const &coord, |
| 12027 |
+ float level) |
| 12028 |
+{ |
| 12029 |
+ return texture.sample(sampler, coord.xyz/coord.w, metal::level(level)); |
| 12030 |
+} |
| 12031 |
+)", |
| 12032 |
+ textureProjLod()) |
| 12033 |
+ |
| 12034 |
+PROGRAM_PRELUDE_DECLARE(textureProjLodOffset, |
| 12035 |
+ R"( |
| 12036 |
+#define ANGLE_textureProjLodOffset(env, ...) ANGLE_textureProjLodOffset_impl(*env.texture, *env.sampler, __VA_ARGS__) |
| 12037 |
+ |
| 12038 |
+template <typename Texture> |
| 12039 |
+ANGLE_ALWAYS_INLINE auto ANGLE_textureProjLodOffset_impl( |
| 12040 |
+ thread Texture &texture, |
| 12041 |
+ thread metal::sampler const &sampler, |
| 12042 |
+ thread metal::float3 const &coord, |
| 12043 |
+ float level, |
| 12044 |
+ thread int2 const &offset) |
| 12045 |
+{ |
| 12046 |
+ return texture.sample(sampler, coord.xy/coord.z, metal::level(level), offset); |
| 12047 |
+} |
| 12048 |
+ |
| 12049 |
+template <typename Texture> |
| 12050 |
+ANGLE_ALWAYS_INLINE auto ANGLE_textureProjLodOffset_impl( |
| 12051 |
+ thread Texture &texture, |
| 12052 |
+ thread metal::sampler const &sampler, |
| 12053 |
+ thread metal::float4 const &coord, |
| 12054 |
+ float level, |
| 12055 |
+ thread int2 const &offset) |
| 12056 |
+{ |
| 12057 |
+ return texture.sample(sampler, coord.xy/coord.w, metal::level(level), offset); |
| 12058 |
+} |
| 12059 |
+ |
| 12060 |
+template <typename T> |
| 12061 |
+ANGLE_ALWAYS_INLINE auto ANGLE_textureProjLodOffset_impl( |
| 12062 |
+ thread metal::depth2d<T> &texture, |
| 12063 |
+ thread metal::sampler const &sampler, |
| 12064 |
+ thread metal::float4 const &coord, |
| 12065 |
+ float level, |
| 12066 |
+ thread int2 const &offset) |
| 12067 |
+{ |
| 12068 |
+ if (ANGLE_UseSampleCompareLod) |
| 12069 |
+ { |
| 12070 |
+ return static_cast<T>(texture.sample_compare(sampler, coord.xy/coord.w, coord.z/coord.w, metal::level(level), offset)); |
| 12071 |
+ } |
| 12072 |
+ else |
| 12073 |
+ { |
| 12074 |
+ return static_cast<T>(texture.sample(sampler, coord.xy/coord.w, metal::level(level), offset) > coord.z/coord.w); |
| 12075 |
+ } |
| 12076 |
+} |
| 12077 |
+ |
| 12078 |
+template <typename T> |
| 12079 |
+ANGLE_ALWAYS_INLINE auto ANGLE_textureProjLodOffset_impl( |
| 12080 |
+ thread metal::texture3d<T> &texture, |
| 12081 |
+ thread metal::sampler const &sampler, |
| 12082 |
+ thread metal::float4 const &coord, |
| 12083 |
+ float level, |
| 12084 |
+ thread int3 const &offset) |
| 12085 |
+{ |
| 12086 |
+ return texture.sample(sampler, coord.xyz/coord.w, metal::level(level), offset); |
| 12087 |
+} |
| 12088 |
+)", |
| 12089 |
+ functionConstants(), |
| 12090 |
+ textureEnv()) |
| 12091 |
+ |
| 12092 |
+PROGRAM_PRELUDE_DECLARE(textureProjOffset, |
| 12093 |
+ R"( |
| 12094 |
+#define ANGLE_textureProjOffset(env, ...) ANGLE_textureProjOffset_impl(*env.texture, *env.sampler, __VA_ARGS__) |
| 12095 |
+ |
| 12096 |
+template <typename Texture> |
| 12097 |
+ANGLE_ALWAYS_INLINE auto ANGLE_textureProjOffset_impl( |
| 12098 |
+ thread Texture &texture, |
| 12099 |
+ thread metal::sampler const &sampler, |
| 12100 |
+ thread metal::float3 const &coord, |
| 12101 |
+ thread int2 const &offset, |
| 12102 |
+ float bias = 0) |
| 12103 |
+{ |
| 12104 |
+ return texture.sample(sampler, coord.xy/coord.z, metal::bias(bias), offset); |
| 12105 |
+} |
| 12106 |
+ |
| 12107 |
+template <typename Texture> |
| 12108 |
+ANGLE_ALWAYS_INLINE auto ANGLE_textureProjOffset_impl( |
| 12109 |
+ thread Texture &texture, |
| 12110 |
+ thread metal::sampler const &sampler, |
| 12111 |
+ thread metal::float4 const &coord, |
| 12112 |
+ thread int2 const &offset, |
| 12113 |
+ float bias = 0) |
| 12114 |
+{ |
| 12115 |
+ return texture.sample(sampler, coord.xy/coord.w, metal::bias(bias), offset); |
| 12116 |
+} |
| 12117 |
+ |
| 12118 |
+template <typename T> |
| 12119 |
+ANGLE_ALWAYS_INLINE auto ANGLE_textureProjOffset_impl( |
| 12120 |
+ thread metal::texture3d<T> &texture, |
| 12121 |
+ thread metal::sampler const &sampler, |
| 12122 |
+ thread metal::float4 const &coord, |
| 12123 |
+ thread int3 const &offset, |
| 12124 |
+ float bias = 0) |
| 12125 |
+{ |
| 12126 |
+ return texture.sample(sampler, coord.xyz/coord.w, metal::bias(bias), offset); |
| 12127 |
+} |
| 12128 |
+)", |
| 12129 |
+ textureEnv()) |
| 12130 |
+ |
| 12131 |
+PROGRAM_PRELUDE_DECLARE(textureSize, |
| 12132 |
+ R"( |
| 12133 |
+#define ANGLE_textureSize(env, ...) ANGLE_textureSize_impl(*env.texture, __VA_ARGS__) |
| 12134 |
+ |
| 12135 |
+template <typename Texture> |
| 12136 |
+ANGLE_ALWAYS_INLINE auto ANGLE_textureSize_impl( |
| 12137 |
+ thread Texture &texture, |
| 12138 |
+ int level) |
| 12139 |
+{ |
| 12140 |
+ return int2(texture.get_width(uint(level)), texture.get_height(uint(level))); |
| 12141 |
+} |
| 12142 |
+ |
| 12143 |
+template <typename T> |
| 12144 |
+ANGLE_ALWAYS_INLINE auto ANGLE_textureSize_impl( |
| 12145 |
+ thread metal::texture3d<T> &texture, |
| 12146 |
+ int level) |
| 12147 |
+{ |
| 12148 |
+ return int3(texture.get_width(uint(level)), texture.get_height(uint(level)), texture.get_depth(uint(level))); |
| 12149 |
+} |
| 12150 |
+ |
| 12151 |
+template <typename T> |
| 12152 |
+ANGLE_ALWAYS_INLINE auto ANGLE_textureSize_impl( |
| 12153 |
+ thread metal::depth2d_array<T> &texture, |
| 12154 |
+ int level) |
| 12155 |
+{ |
| 12156 |
+ return int3(texture.get_width(uint(level)), texture.get_height(uint(level)), texture.get_array_size()); |
| 12157 |
+} |
| 12158 |
+ |
| 12159 |
+template <typename T> |
| 12160 |
+ANGLE_ALWAYS_INLINE auto ANGLE_textureSize_impl( |
| 12161 |
+ thread metal::texture2d_array<T> &texture, |
| 12162 |
+ int level) |
| 12163 |
+{ |
| 12164 |
+ return int3(texture.get_width(uint(level)), texture.get_height(uint(level)), texture.get_array_size()); |
| 12165 |
+} |
| 12166 |
+)", |
| 12167 |
+ textureEnv()) |
| 12168 |
+ |
| 12169 |
+//////////////////////////////////////////////////////////////////////////////// |
| 12170 |
+ |
| 12171 |
+// Returned Name is valid for as long as `buffer` is still alive. |
| 12172 |
+// Returns false if no template args exist. |
| 12173 |
+// Returns false if buffer is not large enough. |
| 12174 |
+// |
| 12175 |
+// Example: |
| 12176 |
+// "foo<1,2>" --> "foo<>" |
| 12177 |
+static std::pair<Name, bool> MaskTemplateArgs(const Name &name, size_t bufferSize, char *buffer) |
| 12178 |
+{ |
| 12179 |
+ const char *begin = name.rawName().data(); |
| 12180 |
+ const char *end = strchr(begin, '<'); |
| 12181 |
+ if (!end) |
| 12182 |
+ { |
| 12183 |
+ return {{}, false}; |
| 12184 |
+ } |
| 12185 |
+ size_t n = end - begin; |
| 12186 |
+ if (n + 3 > bufferSize) |
| 12187 |
+ { |
| 12188 |
+ return {{}, false}; |
| 12189 |
+ } |
| 12190 |
+ for (size_t i = 0; i < n; ++i) |
| 12191 |
+ { |
| 12192 |
+ buffer[i] = begin[i]; |
| 12193 |
+ } |
| 12194 |
+ buffer[n + 0] = '<'; |
| 12195 |
+ buffer[n + 1] = '>'; |
| 12196 |
+ buffer[n + 2] = '\0'; |
| 12197 |
+ return {Name(buffer, name.symbolType()), true}; |
| 12198 |
+} |
| 12199 |
+ |
| 12200 |
+ProgramPrelude::FuncToEmitter ProgramPrelude::BuildFuncToEmitter() |
| 12201 |
+{ |
| 12202 |
+#define EMIT_METHOD(method) \ |
| 12203 |
+ [](ProgramPrelude &pp, const TFunction &) -> void { return pp.method(); } |
| 12204 |
+ FuncToEmitter map; |
| 12205 |
+ |
| 12206 |
+ auto put = [&](Name name, FuncEmitter emitter) { |
| 12207 |
+ FuncEmitter &dest = map[name]; |
| 12208 |
+ ASSERT(!dest); |
| 12209 |
+ dest = emitter; |
| 12210 |
+ }; |
| 12211 |
+ |
| 12212 |
+ auto putAngle = [&](const char *nameStr, FuncEmitter emitter) { |
| 12213 |
+ Name name(nameStr, SymbolType::AngleInternal); |
| 12214 |
+ put(name, emitter); |
| 12215 |
+ }; |
| 12216 |
+ |
| 12217 |
+ auto putBuiltIn = [&](const char *nameStr, FuncEmitter emitter) { |
| 12218 |
+ Name name(nameStr, SymbolType::BuiltIn); |
| 12219 |
+ put(name, emitter); |
| 12220 |
+ }; |
| 12221 |
+ |
| 12222 |
+ putAngle("addressof", EMIT_METHOD(addressof)); |
| 12223 |
+ putAngle("cast<>", EMIT_METHOD(castMatrix)); |
| 12224 |
+ putAngle("elem_ref", EMIT_METHOD(vectorElemRef)); |
| 12225 |
+ putAngle("flatten", EMIT_METHOD(flattenArray)); |
| 12226 |
+ putAngle("inout", EMIT_METHOD(inout)); |
| 12227 |
+ putAngle("out", EMIT_METHOD(out)); |
| 12228 |
+ putAngle("swizzle_ref", EMIT_METHOD(swizzleRef)); |
| 12229 |
+ |
| 12230 |
+ putBuiltIn("texelFetch", EMIT_METHOD(texelFetch)); |
| 12231 |
+ putBuiltIn("texelFetchOffset", EMIT_METHOD(texelFetchOffset)); |
| 12232 |
+ putBuiltIn("texture", [](ProgramPrelude &pp, const TFunction &func) { |
| 12233 |
+ const ImmutableString textureName = |
| 12234 |
+ GetTextureTypeName(func.getParam(0)->getType().getBasicType()).rawName(); |
| 12235 |
+ const TType &coord = func.getParam(1)->getType(); |
| 12236 |
+ const TBasicType coordBasic = coord.getBasicType(); |
| 12237 |
+ const int coordN = coord.getNominalSize(); |
| 12238 |
+ const bool bias = func.getParamCount() >= 3; |
| 12239 |
+ if (textureName.beginsWith("metal::depth2d<")) |
| 12240 |
+ { |
| 12241 |
+ if (coordBasic == TBasicType::EbtFloat && coordN == 3) |
| 12242 |
+ { |
| 12243 |
+ if (bias) |
| 12244 |
+ { |
| 12245 |
+ return pp.texture_depth2d_float3_float(); |
| 12246 |
+ } |
| 12247 |
+ return pp.texture_depth2d_float3(); |
| 12248 |
+ } |
| 12249 |
+ } |
| 12250 |
+ if (textureName.beginsWith("metal::depthcube<")) |
| 12251 |
+ { |
| 12252 |
+ if (coordBasic == TBasicType::EbtFloat && coordN == 4) |
| 12253 |
+ { |
| 12254 |
+ if (bias) |
| 12255 |
+ { |
| 12256 |
+ return pp.texture_depthcube_float4_float(); |
| 12257 |
+ } |
| 12258 |
+ return pp.texture_depthcube_float4(); |
| 12259 |
+ } |
| 12260 |
+ } |
| 12261 |
+ if (textureName.beginsWith("metal::depth2d_array<")) |
| 12262 |
+ { |
| 12263 |
+ if (coordBasic == TBasicType::EbtFloat && coordN == 4) |
| 12264 |
+ { |
| 12265 |
+ if (bias) |
| 12266 |
+ { |
| 12267 |
+ return pp.texture_depth2darray_float4_float(); |
| 12268 |
+ } |
| 12269 |
+ return pp.texture_depth2darray_float4(); |
| 12270 |
+ } |
| 12271 |
+ } |
| 12272 |
+ if (textureName.beginsWith("metal::texture2d_array<")) |
| 12273 |
+ { |
| 12274 |
+ if (coordBasic == TBasicType::EbtFloat && coordN == 3) |
| 12275 |
+ { |
| 12276 |
+ if (bias) |
| 12277 |
+ { |
| 12278 |
+ return pp.texture_texture2darray_float3_float(); |
| 12279 |
+ } |
| 12280 |
+ return pp.texture_texture2darray_float3(); |
| 12281 |
+ } |
| 12282 |
+ if (coordBasic == TBasicType::EbtFloat && coordN == 4) |
| 12283 |
+ { |
| 12284 |
+ if (bias) |
| 12285 |
+ { |
| 12286 |
+ return pp.texture_texture2darray_float4_float(); |
| 12287 |
+ } |
| 12288 |
+ return pp.texture_texture2darray_float4(); |
| 12289 |
+ } |
| 12290 |
+ } |
| 12291 |
+ if (coordBasic == TBasicType::EbtFloat && coordN == 2) |
| 12292 |
+ { |
| 12293 |
+ if (bias) |
| 12294 |
+ { |
| 12295 |
+ return pp.texture_generic_float2_float(); |
| 12296 |
+ } |
| 12297 |
+ return pp.texture_generic_float2(); |
| 12298 |
+ } |
| 12299 |
+ if (coordBasic == TBasicType::EbtFloat && coordN == 3) |
| 12300 |
+ { |
| 12301 |
+ if (bias) |
| 12302 |
+ { |
| 12303 |
+ return pp.texture_generic_float3_float(); |
| 12304 |
+ } |
| 12305 |
+ return pp.texture_generic_float3(); |
| 12306 |
+ } |
| 12307 |
+ TODO(); |
| 12308 |
+ }); |
| 12309 |
+ putBuiltIn("texture1DLod", EMIT_METHOD(texture1DLod)); |
| 12310 |
+ putBuiltIn("texture1DProj", EMIT_METHOD(texture1DProj)); |
| 12311 |
+ putBuiltIn("texture1DProjLod", EMIT_METHOD(texture1DProjLod)); |
| 12312 |
+ putBuiltIn("texture2D", EMIT_METHOD(texture2D)); |
| 12313 |
+ putBuiltIn("texture2DLod", EMIT_METHOD(texture2DLod)); |
| 12314 |
+ putBuiltIn("texture2DProj", EMIT_METHOD(texture2DProj)); |
| 12315 |
+ putBuiltIn("texture3DLod", EMIT_METHOD(texture3DLod)); |
| 12316 |
+ putBuiltIn("texture3DProj", EMIT_METHOD(texture3DProj)); |
| 12317 |
+ putBuiltIn("texture3DProjLod", EMIT_METHOD(texture3DProjLod)); |
| 12318 |
+ putBuiltIn("textureCube", EMIT_METHOD(textureCube)); |
| 12319 |
+ putBuiltIn("textureCubeLod", EMIT_METHOD(textureCubeLod)); |
| 12320 |
+ putBuiltIn("textureCubeProj", EMIT_METHOD(textureCubeProj)); |
| 12321 |
+ putBuiltIn("textureCubeProjLod", EMIT_METHOD(textureCubeProjLod)); |
| 12322 |
+ putBuiltIn("texture2DProjLod", EMIT_METHOD(texture2DProjLod)); |
| 12323 |
+ putBuiltIn("textureGrad", [](ProgramPrelude &pp, const TFunction &func) { |
| 12324 |
+ const ImmutableString textureName = |
| 12325 |
+ GetTextureTypeName(func.getParam(0)->getType().getBasicType()).rawName(); |
| 12326 |
+ const TType &coord = func.getParam(1)->getType(); |
| 12327 |
+ const TBasicType coordBasic = coord.getBasicType(); |
| 12328 |
+ const int coordN = coord.getNominalSize(); |
| 12329 |
+ const TType &dPdx = func.getParam(2)->getType(); |
| 12330 |
+ const int dPdxN = dPdx.getNominalSize(); |
| 12331 |
+ if (textureName.beginsWith("metal::depth2d<")) |
| 12332 |
+ { |
| 12333 |
+ if (coordBasic == TBasicType::EbtFloat && coordN == 3 && dPdxN == 2) |
| 12334 |
+ { |
| 12335 |
+ return pp.textureGrad_depth2d_float3_float2_float2(); |
| 12336 |
+ } |
| 12337 |
+ } |
| 12338 |
+ if (textureName.beginsWith("metal::depth2d_array<")) |
| 12339 |
+ { |
| 12340 |
+ if (coordBasic == TBasicType::EbtFloat && coordN == 4 && dPdxN == 2) |
| 12341 |
+ { |
| 12342 |
+ return pp.textureGrad_depth2darray_float4_float2_float2(); |
| 12343 |
+ } |
| 12344 |
+ } |
| 12345 |
+ if (textureName.beginsWith("metal::depthcube<")) |
| 12346 |
+ { |
| 12347 |
+ if (coordBasic == TBasicType::EbtFloat && coordN == 4 && dPdxN == 3) |
| 12348 |
+ { |
| 12349 |
+ return pp.textureGrad_depthcube_float4_float3_float3(); |
| 12350 |
+ } |
| 12351 |
+ } |
| 12352 |
+ if (textureName.beginsWith("metal::texturecube<")) |
| 12353 |
+ { |
| 12354 |
+ if (coordBasic == TBasicType::EbtFloat && coordN == 3 && dPdxN == 3) |
| 12355 |
+ { |
| 12356 |
+ return pp.textureGrad_texturecube_float3_float3_float3(); |
| 12357 |
+ } |
| 12358 |
+ } |
| 12359 |
+ if (coordBasic == TBasicType::EbtFloat && coordN == 3 && dPdxN == 2) |
| 12360 |
+ { |
| 12361 |
+ return pp.textureGrad_generic_float3_float2_float2(); |
| 12362 |
+ } |
| 12363 |
+ if (coordBasic == TBasicType::EbtFloat && coordN == 4 && dPdxN == 2) |
| 12364 |
+ { |
| 12365 |
+ return pp.textureGrad_generic_float4_float2_float2(); |
| 12366 |
+ } |
| 12367 |
+ if (coordBasic == TBasicType::EbtFloat && coordN == dPdxN) |
| 12368 |
+ { |
| 12369 |
+ return pp.textureGrad_generic_floatN_floatN_floatN(); |
| 12370 |
+ } |
| 12371 |
+ TODO(); |
| 12372 |
+ }); |
| 12373 |
+ putBuiltIn("textureGradOffset", [](ProgramPrelude &pp, const TFunction &func) { |
| 12374 |
+ const ImmutableString textureName = |
| 12375 |
+ GetTextureTypeName(func.getParam(0)->getType().getBasicType()).rawName(); |
| 12376 |
+ const TType &coord = func.getParam(1)->getType(); |
| 12377 |
+ const TBasicType coordBasic = coord.getBasicType(); |
| 12378 |
+ const int coordN = coord.getNominalSize(); |
| 12379 |
+ const TType &dPdx = func.getParam(2)->getType(); |
| 12380 |
+ const int dPdxN = dPdx.getNominalSize(); |
| 12381 |
+ if (textureName.beginsWith("metal::depth2d<")) |
| 12382 |
+ { |
| 12383 |
+ if (coordBasic == TBasicType::EbtFloat && coordN == 3 && dPdxN == 2) |
| 12384 |
+ { |
| 12385 |
+ return pp.textureGradOffset_depth2d_float3_float2_float2_int2(); |
| 12386 |
+ } |
| 12387 |
+ } |
| 12388 |
+ if (textureName.beginsWith("metal::depth2d_array<")) |
| 12389 |
+ { |
| 12390 |
+ if (coordBasic == TBasicType::EbtFloat && coordN == 4 && dPdxN == 2) |
| 12391 |
+ { |
| 12392 |
+ return pp.textureGradOffset_depth2darray_float4_float2_float2_int2(); |
| 12393 |
+ } |
| 12394 |
+ } |
| 12395 |
+ if (textureName.beginsWith("metal::depthcube<")) |
| 12396 |
+ { |
| 12397 |
+ if (coordBasic == TBasicType::EbtFloat && coordN == 4 && dPdxN == 3) |
| 12398 |
+ { |
| 12399 |
+ return pp.textureGradOffset_depthcube_float4_float3_float3_int3(); |
| 12400 |
+ } |
| 12401 |
+ } |
| 12402 |
+ if (textureName.beginsWith("metal::texturecube<")) |
| 12403 |
+ { |
| 12404 |
+ if (coordBasic == TBasicType::EbtFloat && coordN == 3 && dPdxN == 3) |
| 12405 |
+ { |
| 12406 |
+ return pp.textureGradOffset_texturecube_float3_float3_float3_int3(); |
| 12407 |
+ } |
| 12408 |
+ } |
| 12409 |
+ if (coordBasic == TBasicType::EbtFloat && coordN == 3 && dPdxN == 2) |
| 12410 |
+ { |
| 12411 |
+ return pp.textureGradOffset_generic_float3_float2_float2_int2(); |
| 12412 |
+ } |
| 12413 |
+ if (coordBasic == TBasicType::EbtFloat && coordN == 4 && dPdxN == 2) |
| 12414 |
+ { |
| 12415 |
+ return pp.textureGradOffset_generic_float4_float2_float2_int2(); |
| 12416 |
+ } |
| 12417 |
+ if (coordBasic == TBasicType::EbtFloat && coordN == dPdxN) |
| 12418 |
+ { |
| 12419 |
+ return pp.textureGradOffset_generic_floatN_floatN_floatN_intN(); |
| 12420 |
+ } |
| 12421 |
+ TODO(); |
| 12422 |
+ }); |
| 12423 |
+ putBuiltIn("textureLod", [](ProgramPrelude &pp, const TFunction &func) { |
| 12424 |
+ const ImmutableString textureName = |
| 12425 |
+ GetTextureTypeName(func.getParam(0)->getType().getBasicType()).rawName(); |
| 12426 |
+ const TType &coord = func.getParam(1)->getType(); |
| 12427 |
+ const TBasicType coordBasic = coord.getBasicType(); |
| 12428 |
+ const int coordN = coord.getNominalSize(); |
| 12429 |
+ if (textureName.beginsWith("metal::depth2d<")) |
| 12430 |
+ { |
| 12431 |
+ if (coordBasic == TBasicType::EbtFloat && coordN == 3) |
| 12432 |
+ { |
| 12433 |
+ return pp.textureLod_depth2d_float3(); |
| 12434 |
+ } |
| 12435 |
+ } |
| 12436 |
+ if (textureName.beginsWith("metal::texture2d_array<")) |
| 12437 |
+ { |
| 12438 |
+ if (coordBasic == TBasicType::EbtFloat && coordN == 3) |
| 12439 |
+ { |
| 12440 |
+ return pp.textureLod_texture2darray_float3(); |
| 12441 |
+ } |
| 12442 |
+ if (coordBasic == TBasicType::EbtFloat && coordN == 4) |
| 12443 |
+ { |
| 12444 |
+ return pp.textureLod_texture2darray_float4(); |
| 12445 |
+ } |
| 12446 |
+ } |
| 12447 |
+ if (coordBasic == TBasicType::EbtFloat && coordN == 2) |
| 12448 |
+ { |
| 12449 |
+ return pp.textureLod_generic_float2(); |
| 12450 |
+ } |
| 12451 |
+ if (coordBasic == TBasicType::EbtFloat && coordN == 3) |
| 12452 |
+ { |
| 12453 |
+ return pp.textureLod_generic_float3(); |
| 12454 |
+ } |
| 12455 |
+ TODO(); |
| 12456 |
+ }); |
| 12457 |
+ putBuiltIn("textureLodOffset", EMIT_METHOD(textureLodOffset)); |
| 12458 |
+ putBuiltIn("textureOffset", EMIT_METHOD(textureOffset)); |
| 12459 |
+ putBuiltIn("textureProj", EMIT_METHOD(textureProj)); |
| 12460 |
+ putBuiltIn("textureProjGrad", [](ProgramPrelude &pp, const TFunction &func) { |
| 12461 |
+ const ImmutableString textureName = |
| 12462 |
+ GetTextureTypeName(func.getParam(0)->getType().getBasicType()).rawName(); |
| 12463 |
+ const TType &coord = func.getParam(1)->getType(); |
| 12464 |
+ const TBasicType coordBasic = coord.getBasicType(); |
| 12465 |
+ const int coordN = coord.getNominalSize(); |
| 12466 |
+ const TType &dPdx = func.getParam(2)->getType(); |
| 12467 |
+ const int dPdxN = dPdx.getNominalSize(); |
| 12468 |
+ if (textureName.beginsWith("metal::depth2d<")) |
| 12469 |
+ { |
| 12470 |
+ if (coordBasic == TBasicType::EbtFloat && coordN == 4 && dPdxN == 2) |
| 12471 |
+ { |
| 12472 |
+ return pp.textureProjGrad_depth2d_float4_float2_float2(); |
| 12473 |
+ } |
| 12474 |
+ } |
| 12475 |
+ if (textureName.beginsWith("metal::texture3d<")) |
| 12476 |
+ { |
| 12477 |
+ if (coordBasic == TBasicType::EbtFloat && coordN == 4 && dPdxN == 3) |
| 12478 |
+ { |
| 12479 |
+ return pp.textureProjGrad_texture3d_float4_float3_float3(); |
| 12480 |
+ } |
| 12481 |
+ } |
| 12482 |
+ if (coordBasic == TBasicType::EbtFloat && coordN == 3 && dPdxN == 2) |
| 12483 |
+ { |
| 12484 |
+ return pp.textureProjGrad_generic_float3_float2_float2(); |
| 12485 |
+ } |
| 12486 |
+ if (coordBasic == TBasicType::EbtFloat && coordN == 4 && dPdxN == 2) |
| 12487 |
+ { |
| 12488 |
+ return pp.textureProjGrad_generic_float4_float2_float2(); |
| 12489 |
+ } |
| 12490 |
+ TODO(); |
| 12491 |
+ }); |
| 12492 |
+ putBuiltIn("textureProjGradOffset", [](ProgramPrelude &pp, const TFunction &func) { |
| 12493 |
+ const ImmutableString textureName = |
| 12494 |
+ GetTextureTypeName(func.getParam(0)->getType().getBasicType()).rawName(); |
| 12495 |
+ const TType &coord = func.getParam(1)->getType(); |
| 12496 |
+ const TBasicType coordBasic = coord.getBasicType(); |
| 12497 |
+ const int coordN = coord.getNominalSize(); |
| 12498 |
+ const TType &dPdx = func.getParam(2)->getType(); |
| 12499 |
+ const int dPdxN = dPdx.getNominalSize(); |
| 12500 |
+ if (textureName.beginsWith("metal::depth2d<")) |
| 12501 |
+ { |
| 12502 |
+ if (coordBasic == TBasicType::EbtFloat && coordN == 4 && dPdxN == 2) |
| 12503 |
+ { |
| 12504 |
+ return pp.textureProjGradOffset_depth2d_float4_float2_float2_int2(); |
| 12505 |
+ } |
| 12506 |
+ } |
| 12507 |
+ if (textureName.beginsWith("metal::texture3d<")) |
| 12508 |
+ { |
| 12509 |
+ if (coordBasic == TBasicType::EbtFloat && coordN == 4 && dPdxN == 3) |
| 12510 |
+ { |
| 12511 |
+ return pp.textureProjGradOffset_texture3d_float4_float3_float3_int3(); |
| 12512 |
+ } |
| 12513 |
+ } |
| 12514 |
+ if (coordBasic == TBasicType::EbtFloat && coordN == 3 && dPdxN == 2) |
| 12515 |
+ { |
| 12516 |
+ return pp.textureProjGradOffset_generic_float3_float2_float2_int2(); |
| 12517 |
+ } |
| 12518 |
+ if (coordBasic == TBasicType::EbtFloat && coordN == 4 && dPdxN == 2) |
| 12519 |
+ { |
| 12520 |
+ return pp.textureProjGradOffset_generic_float4_float2_float2_int2(); |
| 12521 |
+ } |
| 12522 |
+ TODO(); |
| 12523 |
+ }); |
| 12524 |
+ putBuiltIn("textureProjLod", [](ProgramPrelude &pp, const TFunction &func) { |
| 12525 |
+ const ImmutableString textureName = |
| 12526 |
+ GetTextureTypeName(func.getParam(0)->getType().getBasicType()).rawName(); |
| 12527 |
+ const TType &coord = func.getParam(1)->getType(); |
| 12528 |
+ const TBasicType coordBasic = coord.getBasicType(); |
| 12529 |
+ const int coordN = coord.getNominalSize(); |
| 12530 |
+ if (textureName.beginsWith("metal::depth2d<")) |
| 12531 |
+ { |
| 12532 |
+ if (coordBasic == TBasicType::EbtFloat && coordN == 4) |
| 12533 |
+ { |
| 12534 |
+ return pp.textureProjLod_depth2d_float4(); |
| 12535 |
+ } |
| 12536 |
+ } |
| 12537 |
+ if (textureName.beginsWith("metal::texture3d<")) |
| 12538 |
+ { |
| 12539 |
+ if (coordBasic == TBasicType::EbtFloat && coordN == 4) |
| 12540 |
+ { |
| 12541 |
+ return pp.textureProjLod_texture3d_float4(); |
| 12542 |
+ } |
| 12543 |
+ } |
| 12544 |
+ if (coordBasic == TBasicType::EbtFloat && coordN == 3) |
| 12545 |
+ { |
| 12546 |
+ return pp.textureProjLod_generic_float3(); |
| 12547 |
+ } |
| 12548 |
+ if (coordBasic == TBasicType::EbtFloat && coordN == 4) |
| 12549 |
+ { |
| 12550 |
+ return pp.textureProjLod_generic_float4(); |
| 12551 |
+ } |
| 12552 |
+ TODO(); |
| 12553 |
+ }); |
| 12554 |
+ putBuiltIn("textureProjLodOffset", EMIT_METHOD(textureProjLodOffset)); |
| 12555 |
+ putBuiltIn("textureProjOffset", EMIT_METHOD(textureProjOffset)); |
| 12556 |
+ putBuiltIn("textureSize", EMIT_METHOD(textureSize)); |
| 12557 |
+ |
| 12558 |
+ return map; |
| 12559 |
+ |
| 12560 |
+#undef EMIT_METHOD |
| 12561 |
+} |
| 12562 |
+ |
| 12563 |
+void ProgramPrelude::visitOperator(TOperator op, |
| 12564 |
+ const TFunction *func, |
| 12565 |
+ const TType *argType0, |
| 12566 |
+ const TType *argType1) |
| 12567 |
+{ |
| 12568 |
+ switch (op) |
| 12569 |
+ { |
| 12570 |
+ case TOperator::EOpRadians: |
| 12571 |
+ radians(); |
| 12572 |
+ break; |
| 12573 |
+ case TOperator::EOpDegrees: |
| 12574 |
+ degrees(); |
| 12575 |
+ break; |
| 12576 |
+ case TOperator::EOpAtan: |
| 12577 |
+ atan(); |
| 12578 |
+ break; |
| 12579 |
+ case TOperator::EOpMod: |
| 12580 |
+ mod(); |
| 12581 |
+ break; |
| 12582 |
+ case TOperator::EOpRefract: |
| 12583 |
+ refract(); |
| 12584 |
+ break; |
| 12585 |
+ case TOperator::EOpDistance: |
| 12586 |
+ distance(); |
| 12587 |
+ break; |
| 12588 |
+ case TOperator::EOpLength: |
| 12589 |
+ length(); |
| 12590 |
+ break; |
| 12591 |
+ case TOperator::EOpDot: |
| 12592 |
+ dot(); |
| 12593 |
+ break; |
| 12594 |
+ case TOperator::EOpNormalize: |
| 12595 |
+ normalize(); |
| 12596 |
+ break; |
| 12597 |
+ case TOperator::EOpFaceforward: |
| 12598 |
+ faceforward(); |
| 12599 |
+ break; |
| 12600 |
+ case TOperator::EOpReflect: |
| 12601 |
+ reflect(); |
| 12602 |
+ break; |
| 12603 |
+ |
| 12604 |
+ case TOperator::EOpSin: |
| 12605 |
+ case TOperator::EOpCos: |
| 12606 |
+ case TOperator::EOpTan: |
| 12607 |
+ case TOperator::EOpAsin: |
| 12608 |
+ case TOperator::EOpAcos: |
| 12609 |
+ case TOperator::EOpSinh: |
| 12610 |
+ case TOperator::EOpCosh: |
| 12611 |
+ case TOperator::EOpTanh: |
| 12612 |
+ case TOperator::EOpAsinh: |
| 12613 |
+ case TOperator::EOpAcosh: |
| 12614 |
+ case TOperator::EOpAtanh: |
| 12615 |
+ case TOperator::EOpAbs: |
| 12616 |
+ case TOperator::EOpFma: |
| 12617 |
+ case TOperator::EOpPow: |
| 12618 |
+ case TOperator::EOpExp: |
| 12619 |
+ case TOperator::EOpExp2: |
| 12620 |
+ case TOperator::EOpLog: |
| 12621 |
+ case TOperator::EOpLog2: |
| 12622 |
+ case TOperator::EOpSqrt: |
| 12623 |
+ case TOperator::EOpFloor: |
| 12624 |
+ case TOperator::EOpTrunc: |
| 12625 |
+ case TOperator::EOpCeil: |
| 12626 |
+ case TOperator::EOpFract: |
| 12627 |
+ case TOperator::EOpRound: |
| 12628 |
+ case TOperator::EOpRoundEven: |
| 12629 |
+ case TOperator::EOpModf: |
| 12630 |
+ case TOperator::EOpLdexp: |
| 12631 |
+ case TOperator::EOpFrexp: |
| 12632 |
+ case TOperator::EOpInversesqrt: |
| 12633 |
+ include_metal_math(); |
| 12634 |
+ break; |
| 12635 |
+ |
| 12636 |
+ case TOperator::EOpEqual: |
| 12637 |
+ if (argType0->isVector() && argType1->isVector()) |
| 12638 |
+ { |
| 12639 |
+ equalVector(); |
| 12640 |
+ } |
| 12641 |
+ // Even if Arg0 is a vector or matrix, it could also be an array. |
| 12642 |
+ if (argType0->isArray() && argType1->isArray()) |
| 12643 |
+ { |
| 12644 |
+ equalArray(); |
| 12645 |
+ } |
| 12646 |
+ break; |
| 12647 |
+ |
| 12648 |
+ case TOperator::EOpNotEqual: |
| 12649 |
+ if (argType0->isVector() && argType1->isVector()) |
| 12650 |
+ { |
| 12651 |
+ notEqualVector(); |
| 12652 |
+ } |
| 12653 |
+ else if (argType0->getStruct() && argType1->getStruct()) |
| 12654 |
+ { |
| 12655 |
+ notEqualStruct(); |
| 12656 |
+ } |
| 12657 |
+ // Same as above. |
| 12658 |
+ if (argType0->isArray() && argType1->isArray()) |
| 12659 |
+ { |
| 12660 |
+ notEqualArray(); |
| 12661 |
+ } |
| 12662 |
+ break; |
| 12663 |
+ |
| 12664 |
+ case TOperator::EOpCross: |
| 12665 |
+ include_metal_geometric(); |
| 12666 |
+ break; |
| 12667 |
+ |
| 12668 |
+ case TOperator::EOpSign: |
| 12669 |
+ sign(); |
| 12670 |
+ break; |
| 12671 |
+ |
| 12672 |
+ case TOperator::EOpClamp: |
| 12673 |
+ case TOperator::EOpMin: |
| 12674 |
+ case TOperator::EOpMax: |
| 12675 |
+ case TOperator::EOpMix: |
| 12676 |
+ case TOperator::EOpStep: |
| 12677 |
+ case TOperator::EOpSmoothstep: |
| 12678 |
+ include_metal_common(); |
| 12679 |
+ break; |
| 12680 |
+ |
| 12681 |
+ case TOperator::EOpAll: |
| 12682 |
+ case TOperator::EOpAny: |
| 12683 |
+ case TOperator::EOpIsnan: |
| 12684 |
+ case TOperator::EOpIsinf: |
| 12685 |
+ include_metal_relational(); |
| 12686 |
+ break; |
| 12687 |
+ |
| 12688 |
+ case TOperator::EOpDFdx: |
| 12689 |
+ case TOperator::EOpDFdy: |
| 12690 |
+ case TOperator::EOpFwidth: |
| 12691 |
+ include_metal_graphics(); |
| 12692 |
+ break; |
| 12693 |
+ |
| 12694 |
+ case TOperator::EOpTranspose: |
| 12695 |
+ case TOperator::EOpDeterminant: |
| 12696 |
+ include_metal_matrix(); |
| 12697 |
+ break; |
| 12698 |
+ |
| 12699 |
+ case TOperator::EOpAdd: |
| 12700 |
+ if (argType0->isMatrix() && argType1->isScalar()) |
| 12701 |
+ { |
| 12702 |
+ addMatrixScalar(); |
| 12703 |
+ } |
| 12704 |
+ break; |
| 12705 |
+ |
| 12706 |
+ case TOperator::EOpSub: |
| 12707 |
+ if (argType0->isMatrix() && argType1->isScalar()) |
| 12708 |
+ { |
| 12709 |
+ subMatrixScalar(); |
| 12710 |
+ } |
| 12711 |
+ break; |
| 12712 |
+ |
| 12713 |
+ case TOperator::EOpDiv: |
| 12714 |
+ if (argType0->isMatrix()) |
| 12715 |
+ { |
| 12716 |
+ if (argType1->isMatrix()) |
| 12717 |
+ { |
| 12718 |
+ componentWiseDivide(); |
| 12719 |
+ } |
| 12720 |
+ else if (argType1->isScalar()) |
| 12721 |
+ { |
| 12722 |
+ divMatrixScalar(); |
| 12723 |
+ } |
| 12724 |
+ } |
| 12725 |
+ break; |
| 12726 |
+ |
| 12727 |
+ case TOperator::EOpDivAssign: |
| 12728 |
+ if (argType0->isMatrix() && argType1->isMatrix()) |
| 12729 |
+ { |
| 12730 |
+ componentWiseDivideAssign(); |
| 12731 |
+ } |
| 12732 |
+ break; |
| 12733 |
+ |
| 12734 |
+ case TOperator::EOpMulMatrixComponentWise: |
| 12735 |
+ if (argType0->isMatrix() && argType1->isMatrix()) |
| 12736 |
+ { |
| 12737 |
+ componentWiseMultiply(); |
| 12738 |
+ } |
| 12739 |
+ break; |
| 12740 |
+ |
| 12741 |
+ case TOperator::EOpOuterProduct: |
| 12742 |
+ outerProduct(); |
| 12743 |
+ break; |
| 12744 |
+ |
| 12745 |
+ case TOperator::EOpInverse: |
| 12746 |
+ switch (argType0->getCols()) |
| 12747 |
+ { |
| 12748 |
+ case 2: |
| 12749 |
+ inverse2(); |
| 12750 |
+ break; |
| 12751 |
+ case 3: |
| 12752 |
+ inverse3(); |
| 12753 |
+ break; |
| 12754 |
+ case 4: |
| 12755 |
+ inverse4(); |
| 12756 |
+ break; |
| 12757 |
+ default: |
| 12758 |
+ LOGIC_ERROR(); |
| 12759 |
+ } |
| 12760 |
+ break; |
| 12761 |
+ |
| 12762 |
+ case TOperator::EOpMatrixTimesMatrixAssign: |
| 12763 |
+ matmulAssign(); |
| 12764 |
+ break; |
| 12765 |
+ |
| 12766 |
+ case TOperator::EOpPreIncrement: |
| 12767 |
+ if (argType0->isMatrix()) |
| 12768 |
+ { |
| 12769 |
+ preIncrementMatrix(); |
| 12770 |
+ } |
| 12771 |
+ break; |
| 12772 |
+ |
| 12773 |
+ case TOperator::EOpPostIncrement: |
| 12774 |
+ if (argType0->isMatrix()) |
| 12775 |
+ { |
| 12776 |
+ postIncrementMatrix(); |
| 12777 |
+ } |
| 12778 |
+ break; |
| 12779 |
+ |
| 12780 |
+ case TOperator::EOpPreDecrement: |
| 12781 |
+ if (argType0->isMatrix()) |
| 12782 |
+ { |
| 12783 |
+ preDecrementMatrix(); |
| 12784 |
+ } |
| 12785 |
+ break; |
| 12786 |
+ |
| 12787 |
+ case TOperator::EOpPostDecrement: |
| 12788 |
+ if (argType0->isMatrix()) |
| 12789 |
+ { |
| 12790 |
+ postDecrementMatrix(); |
| 12791 |
+ } |
| 12792 |
+ break; |
| 12793 |
+ |
| 12794 |
+ break; |
| 12795 |
+ |
| 12796 |
+ case TOperator::EOpNegative: |
| 12797 |
+ if (argType0->isMatrix()) |
| 12798 |
+ { |
| 12799 |
+ negateMatrix(); |
| 12800 |
+ } |
| 12801 |
+ break; |
| 12802 |
+ |
| 12803 |
+ case TOperator::EOpComma: |
| 12804 |
+ case TOperator::EOpAssign: |
| 12805 |
+ case TOperator::EOpInitialize: |
| 12806 |
+ case TOperator::EOpAddAssign: |
| 12807 |
+ case TOperator::EOpSubAssign: |
| 12808 |
+ case TOperator::EOpMulAssign: |
| 12809 |
+ case TOperator::EOpIModAssign: |
| 12810 |
+ case TOperator::EOpBitShiftLeftAssign: |
| 12811 |
+ case TOperator::EOpBitShiftRightAssign: |
| 12812 |
+ case TOperator::EOpBitwiseAndAssign: |
| 12813 |
+ case TOperator::EOpBitwiseXorAssign: |
| 12814 |
+ case TOperator::EOpBitwiseOrAssign: |
| 12815 |
+ case TOperator::EOpMul: |
| 12816 |
+ case TOperator::EOpIMod: |
| 12817 |
+ case TOperator::EOpBitShiftLeft: |
| 12818 |
+ case TOperator::EOpBitShiftRight: |
| 12819 |
+ case TOperator::EOpBitwiseAnd: |
| 12820 |
+ case TOperator::EOpBitwiseXor: |
| 12821 |
+ case TOperator::EOpBitwiseOr: |
| 12822 |
+ case TOperator::EOpLessThan: |
| 12823 |
+ case TOperator::EOpGreaterThan: |
| 12824 |
+ case TOperator::EOpLessThanEqual: |
| 12825 |
+ case TOperator::EOpGreaterThanEqual: |
| 12826 |
+ case TOperator::EOpLessThanComponentWise: |
| 12827 |
+ case TOperator::EOpLessThanEqualComponentWise: |
| 12828 |
+ case TOperator::EOpGreaterThanEqualComponentWise: |
| 12829 |
+ case TOperator::EOpGreaterThanComponentWise: |
| 12830 |
+ case TOperator::EOpLogicalOr: |
| 12831 |
+ case TOperator::EOpLogicalXor: |
| 12832 |
+ case TOperator::EOpLogicalAnd: |
| 12833 |
+ case TOperator::EOpPositive: |
| 12834 |
+ case TOperator::EOpLogicalNot: |
| 12835 |
+ case TOperator::EOpLogicalNotComponentWise: |
| 12836 |
+ case TOperator::EOpBitwiseNot: |
| 12837 |
+ case TOperator::EOpVectorTimesScalarAssign: |
| 12838 |
+ case TOperator::EOpVectorTimesMatrixAssign: |
| 12839 |
+ case TOperator::EOpMatrixTimesScalarAssign: |
| 12840 |
+ case TOperator::EOpVectorTimesScalar: |
| 12841 |
+ case TOperator::EOpVectorTimesMatrix: |
| 12842 |
+ case TOperator::EOpMatrixTimesVector: |
| 12843 |
+ case TOperator::EOpMatrixTimesScalar: |
| 12844 |
+ case TOperator::EOpMatrixTimesMatrix: |
| 12845 |
+ case TOperator::EOpReturn: |
| 12846 |
+ case TOperator::EOpBreak: |
| 12847 |
+ case TOperator::EOpContinue: |
| 12848 |
+ case TOperator::EOpEqualComponentWise: |
| 12849 |
+ case TOperator::EOpNotEqualComponentWise: |
| 12850 |
+ case TOperator::EOpIndexDirect: |
| 12851 |
+ case TOperator::EOpIndexIndirect: |
| 12852 |
+ case TOperator::EOpIndexDirectStruct: |
| 12853 |
+ case TOperator::EOpIndexDirectInterfaceBlock: |
| 12854 |
+ case TOperator::EOpFloatBitsToInt: |
| 12855 |
+ case TOperator::EOpIntBitsToFloat: |
| 12856 |
+ case TOperator::EOpUintBitsToFloat: |
| 12857 |
+ case TOperator::EOpFloatBitsToUint: |
| 12858 |
+ case TOperator::EOpNull: |
| 12859 |
+ // do nothing |
| 12860 |
+ break; |
| 12861 |
+ |
| 12862 |
+ case TOperator::EOpKill: |
| 12863 |
+ include_metal_graphics(); |
| 12864 |
+ break; |
| 12865 |
+ |
| 12866 |
+ case TOperator::EOpPackUnorm2x16: |
| 12867 |
+ case TOperator::EOpPackSnorm2x16: |
| 12868 |
+ case TOperator::EOpPackUnorm4x8: |
| 12869 |
+ case TOperator::EOpPackSnorm4x8: |
| 12870 |
+ case TOperator::EOpUnpackSnorm2x16: |
| 12871 |
+ case TOperator::EOpUnpackUnorm2x16: |
| 12872 |
+ case TOperator::EOpUnpackUnorm4x8: |
| 12873 |
+ case TOperator::EOpUnpackSnorm4x8: |
| 12874 |
+ include_metal_pack(); |
| 12875 |
+ break; |
| 12876 |
+ |
| 12877 |
+ case TOperator::EOpPackHalf2x16: |
| 12878 |
+ pack_half_2x16(); |
| 12879 |
+ break; |
| 12880 |
+ case TOperator::EOpUnpackHalf2x16: |
| 12881 |
+ unpack_half_2x16(); |
| 12882 |
+ break; |
| 12883 |
+ |
| 12884 |
+ case TOperator::EOpBitfieldExtract: |
| 12885 |
+ case TOperator::EOpBitfieldInsert: |
| 12886 |
+ case TOperator::EOpBitfieldReverse: |
| 12887 |
+ case TOperator::EOpBitCount: |
| 12888 |
+ case TOperator::EOpFindLSB: |
| 12889 |
+ case TOperator::EOpFindMSB: |
| 12890 |
+ case TOperator::EOpUaddCarry: |
| 12891 |
+ case TOperator::EOpUsubBorrow: |
| 12892 |
+ case TOperator::EOpUmulExtended: |
| 12893 |
+ case TOperator::EOpImulExtended: |
| 12894 |
+ case TOperator::EOpBarrier: |
| 12895 |
+ case TOperator::EOpMemoryBarrier: |
| 12896 |
+ case TOperator::EOpMemoryBarrierAtomicCounter: |
| 12897 |
+ case TOperator::EOpMemoryBarrierBuffer: |
| 12898 |
+ case TOperator::EOpMemoryBarrierImage: |
| 12899 |
+ case TOperator::EOpMemoryBarrierShared: |
| 12900 |
+ case TOperator::EOpGroupMemoryBarrier: |
| 12901 |
+ case TOperator::EOpAtomicAdd: |
| 12902 |
+ case TOperator::EOpAtomicMin: |
| 12903 |
+ case TOperator::EOpAtomicMax: |
| 12904 |
+ case TOperator::EOpAtomicAnd: |
| 12905 |
+ case TOperator::EOpAtomicOr: |
| 12906 |
+ case TOperator::EOpAtomicXor: |
| 12907 |
+ case TOperator::EOpAtomicExchange: |
| 12908 |
+ case TOperator::EOpAtomicCompSwap: |
| 12909 |
+ case TOperator::EOpEmitVertex: |
| 12910 |
+ case TOperator::EOpEndPrimitive: |
| 12911 |
+ case TOperator::EOpFTransform: |
| 12912 |
+ case TOperator::EOpPackDouble2x32: |
| 12913 |
+ case TOperator::EOpUnpackDouble2x32: |
| 12914 |
+ case TOperator::EOpArrayLength: |
| 12915 |
+ TODO(); |
| 12916 |
+ break; |
| 12917 |
+ |
| 12918 |
+ case TOperator::EOpConstruct: |
| 12919 |
+ ASSERT(!func); |
| 12920 |
+ break; |
| 12921 |
+ |
| 12922 |
+ case TOperator::EOpCallFunctionInAST: |
| 12923 |
+ case TOperator::EOpCallInternalRawFunction: |
| 12924 |
+ case TOperator::EOpCallBuiltInFunction: |
| 12925 |
+ ASSERT(func); |
| 12926 |
+ if (mHandled.insert(func).second) |
| 12927 |
+ { |
| 12928 |
+ const Name name(*func); |
| 12929 |
+ const auto end = mFuncToEmitter.end(); |
| 12930 |
+ auto iter = mFuncToEmitter.find(name); |
| 12931 |
+ if (iter == end) |
| 12932 |
+ { |
| 12933 |
+ char buffer[32]; |
| 12934 |
+ auto mask = MaskTemplateArgs(name, sizeof(buffer), buffer); |
| 12935 |
+ if (mask.second) |
| 12936 |
+ { |
| 12937 |
+ iter = mFuncToEmitter.find(mask.first); |
| 12938 |
+ } |
| 12939 |
+ } |
| 12940 |
+ if (iter != end) |
| 12941 |
+ { |
| 12942 |
+ const auto &emitter = iter->second; |
| 12943 |
+ emitter(*this, *func); |
| 12944 |
+ } |
| 12945 |
+ } |
| 12946 |
+ break; |
| 12947 |
+ } |
| 12948 |
+} |
| 12949 |
+ |
| 12950 |
+void ProgramPrelude::visitVariable(const Name &name, const TType &type) |
| 12951 |
+{ |
| 12952 |
+ if (const TStructure *s = type.getStruct()) |
| 12953 |
+ { |
| 12954 |
+ const Name typeName(*s); |
| 12955 |
+ if (typeName.beginsWith(Name("TextureEnv<"))) |
| 12956 |
+ { |
| 12957 |
+ textureEnv(); |
| 12958 |
+ } |
| 12959 |
+ } |
| 12960 |
+ else |
| 12961 |
+ { |
| 12962 |
+ if (name == constant_names::kRasterizationDiscardEnabled) |
| 12963 |
+ { |
| 12964 |
+ functionConstants(); |
| 12965 |
+ } |
| 12966 |
+ } |
| 12967 |
+} |
| 12968 |
+ |
| 12969 |
+void ProgramPrelude::visitVariable(const TVariable &var) |
| 12970 |
+{ |
| 12971 |
+ if (mHandled.insert(&var).second) |
| 12972 |
+ { |
| 12973 |
+ visitVariable(Name(var), var.getType()); |
| 12974 |
+ } |
| 12975 |
+} |
| 12976 |
+ |
| 12977 |
+void ProgramPrelude::visitStructure(const TStructure &s) |
| 12978 |
+{ |
| 12979 |
+ if (mHandled.insert(&s).second) |
| 12980 |
+ { |
| 12981 |
+ for (const TField *field : s.fields()) |
| 12982 |
+ { |
| 12983 |
+ const TType &type = *field->type(); |
| 12984 |
+ visitVariable(Name(*field), type); |
| 12985 |
+ } |
| 12986 |
+ } |
| 12987 |
+} |
| 12988 |
+ |
| 12989 |
+bool ProgramPrelude::visitBinary(Visit visit, TIntermBinary *node) |
| 12990 |
+{ |
| 12991 |
+ const TType &leftType = node->getLeft()->getType(); |
| 12992 |
+ const TType &rightType = node->getRight()->getType(); |
| 12993 |
+ visitOperator(node->getOp(), nullptr, &leftType, &rightType); |
| 12994 |
+ return true; |
| 12995 |
+} |
| 12996 |
+ |
| 12997 |
+bool ProgramPrelude::visitUnary(Visit visit, TIntermUnary *node) |
| 12998 |
+{ |
| 12999 |
+ const TType &argType = node->getOperand()->getType(); |
| 13000 |
+ visitOperator(node->getOp(), nullptr, &argType); |
| 13001 |
+ return true; |
| 13002 |
+} |
| 13003 |
+ |
| 13004 |
+bool ProgramPrelude::visitAggregate(Visit visit, TIntermAggregate *node) |
| 13005 |
+{ |
| 13006 |
+ const size_t argCount = node->getChildCount(); |
| 13007 |
+ |
| 13008 |
+ auto getArgType = [node, argCount](size_t index) -> const TType & { |
| 13009 |
+ ASSERT(index < argCount); |
| 13010 |
+ TIntermTyped *arg = node->getChildNode(index)->getAsTyped(); |
| 13011 |
+ ASSERT(arg); |
| 13012 |
+ return arg->getType(); |
| 13013 |
+ }; |
| 13014 |
+ |
| 13015 |
+ const TFunction *func = node->getFunction(); |
| 13016 |
+ |
| 13017 |
+ switch (node->getChildCount()) |
| 13018 |
+ { |
| 13019 |
+ case 0: |
| 13020 |
+ { |
| 13021 |
+ visitOperator(node->getOp(), func, nullptr); |
| 13022 |
+ } |
| 13023 |
+ break; |
| 13024 |
+ |
| 13025 |
+ case 1: |
| 13026 |
+ { |
| 13027 |
+ const TType &argType0 = getArgType(0); |
| 13028 |
+ visitOperator(node->getOp(), func, &argType0); |
| 13029 |
+ } |
| 13030 |
+ break; |
| 13031 |
+ |
| 13032 |
+ case 2: |
| 13033 |
+ { |
| 13034 |
+ const TType &argType0 = getArgType(0); |
| 13035 |
+ const TType &argType1 = getArgType(1); |
| 13036 |
+ visitOperator(node->getOp(), func, &argType0, &argType1); |
| 13037 |
+ } |
| 13038 |
+ break; |
| 13039 |
+ |
| 13040 |
+ default: |
| 13041 |
+ { |
| 13042 |
+ const TType &argType0 = getArgType(0); |
| 13043 |
+ const TType &argType1 = getArgType(1); |
| 13044 |
+ visitOperator(node->getOp(), func, &argType0, &argType1); |
| 13045 |
+ } |
| 13046 |
+ break; |
| 13047 |
+ } |
| 13048 |
+ |
| 13049 |
+ return true; |
| 13050 |
+} |
| 13051 |
+ |
| 13052 |
+bool ProgramPrelude::visitDeclaration(Visit, TIntermDeclaration *node) |
| 13053 |
+{ |
| 13054 |
+ Declaration decl = ViewDeclaration(*node); |
| 13055 |
+ const TType &type = decl.symbol.getType(); |
| 13056 |
+ if (type.isStructSpecifier()) |
| 13057 |
+ { |
| 13058 |
+ const TStructure *s = type.getStruct(); |
| 13059 |
+ ASSERT(s); |
| 13060 |
+ visitStructure(*s); |
| 13061 |
+ } |
| 13062 |
+ return true; |
| 13063 |
+} |
| 13064 |
+ |
| 13065 |
+void ProgramPrelude::visitSymbol(TIntermSymbol *node) |
| 13066 |
+{ |
| 13067 |
+ visitVariable(node->variable()); |
| 13068 |
+} |
| 13069 |
+ |
| 13070 |
+bool sh::EmitProgramPrelude(TIntermBlock &root, TInfoSinkBase &out, const ProgramPreludeConfig &ppc) |
| 13071 |
+{ |
| 13072 |
+ ProgramPrelude programPrelude(out, ppc); |
| 13073 |
+ root.traverse(&programPrelude); |
| 13074 |
+ return true; |
| 13075 |
+} |
| 13076 |
diff --git a/src/compiler/translator/TranslatorMetalDirect/ProgramPrelude.h b/src/compiler/translator/TranslatorMetalDirect/ProgramPrelude.h |
| 13077 |
new file mode 100644 |
| 13078 |
index 0000000..e00413f |
| 13079 |
--- /dev/null |
| 13080 |
+++ b/src/compiler/translator/TranslatorMetalDirect/ProgramPrelude.h |
| 13081 |
@@ -0,0 +1,35 @@ |
| 13082 |
+// |
| 13083 |
+// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 13084 |
+// Use of this source code is governed by a BSD-style license that can be |
| 13085 |
+// found in the LICENSE file. |
| 13086 |
+// |
| 13087 |
+ |
| 13088 |
+#ifndef COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_PROGRAMPRELUDE_H_ |
| 13089 |
+#define COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_PROGRAMPRELUDE_H_ |
| 13090 |
+ |
| 13091 |
+#include <unordered_set> |
| 13092 |
+ |
| 13093 |
+#include "common/angleutils.h" |
| 13094 |
+ |
| 13095 |
+namespace sh |
| 13096 |
+{ |
| 13097 |
+ |
| 13098 |
+class TInfoSinkBase; |
| 13099 |
+class TIntermBlock; |
| 13100 |
+ |
| 13101 |
+struct ProgramPreludeConfig |
| 13102 |
+{ |
| 13103 |
+ bool hasStructEq = false; |
| 13104 |
+}; |
| 13105 |
+ |
| 13106 |
+// This emits fixed helper Metal code directly without adding code to the AST. This walks the AST to |
| 13107 |
+// figure out the required what prelude MSL code is needed for various things in the AST. You can |
| 13108 |
+// think of this as effectively inlining various portions of a helper library into the emitted |
| 13109 |
+// Metal program. |
| 13110 |
+ANGLE_NO_DISCARD bool EmitProgramPrelude(TIntermBlock &root, |
| 13111 |
+ TInfoSinkBase &out, |
| 13112 |
+ const ProgramPreludeConfig &ppc); |
| 13113 |
+ |
| 13114 |
+} // namespace sh |
| 13115 |
+ |
| 13116 |
+#endif // COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_PROGRAMPRELUDE_H_ |
| 13117 |
diff --git a/src/compiler/translator/TranslatorMetalDirect/ReduceInterfaceBlocks.cpp b/src/compiler/translator/TranslatorMetalDirect/ReduceInterfaceBlocks.cpp |
| 13118 |
new file mode 100644 |
| 13119 |
index 0000000..aa81696 |
| 13120 |
--- /dev/null |
| 13121 |
+++ b/src/compiler/translator/TranslatorMetalDirect/ReduceInterfaceBlocks.cpp |
| 13122 |
@@ -0,0 +1,130 @@ |
| 13123 |
+// |
| 13124 |
+// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 13125 |
+// Use of this source code is governed by a BSD-style license that can be |
| 13126 |
+// found in the LICENSE file. |
| 13127 |
+// |
| 13128 |
+ |
| 13129 |
+#include <algorithm> |
| 13130 |
+#include <unordered_map> |
| 13131 |
+ |
| 13132 |
+#include "compiler/translator/TranslatorMetalDirect/AstHelpers.h" |
| 13133 |
+#include "compiler/translator/TranslatorMetalDirect/ReduceInterfaceBlocks.h" |
| 13134 |
+#include "compiler/translator/tree_ops/SeparateDeclarations.h" |
| 13135 |
+#include "compiler/translator/tree_util/IntermRebuild.h" |
| 13136 |
+ |
| 13137 |
+using namespace sh; |
| 13138 |
+ |
| 13139 |
+//////////////////////////////////////////////////////////////////////////////// |
| 13140 |
+ |
| 13141 |
+namespace |
| 13142 |
+{ |
| 13143 |
+ |
| 13144 |
+class Reducer : public TIntermRebuild |
| 13145 |
+{ |
| 13146 |
+ std::unordered_map<const TInterfaceBlock *, std::map<ImmutableString, const TVariable *>> |
| 13147 |
+ mLiftedMap; |
| 13148 |
+ std::unordered_map<const TVariable *, const TVariable *> mInstanceMap; |
| 13149 |
+ |
| 13150 |
+ public: |
| 13151 |
+ Reducer(TCompiler &compiler) : TIntermRebuild(compiler, true, false) {} |
| 13152 |
+ |
| 13153 |
+ PreResult visitDeclarationPre(TIntermDeclaration &declNode) override |
| 13154 |
+ { |
| 13155 |
+ ASSERT(declNode.getChildCount() == 1); |
| 13156 |
+ TIntermNode &node = *declNode.getChildNode(0); |
| 13157 |
+ |
| 13158 |
+ if (TIntermSymbol *symbolNode = node.getAsSymbolNode()) |
| 13159 |
+ { |
| 13160 |
+ const TVariable &var = symbolNode->variable(); |
| 13161 |
+ const TType &type = var.getType(); |
| 13162 |
+ const SymbolType symbolType = var.symbolType(); |
| 13163 |
+ if (const TInterfaceBlock *interfaceBlock = type.getInterfaceBlock()) |
| 13164 |
+ { |
| 13165 |
+ if (symbolType == SymbolType::Empty) |
| 13166 |
+ { |
| 13167 |
+ auto &nameToVar = mLiftedMap[interfaceBlock]; |
| 13168 |
+ std::vector<TIntermNode *> replacements; |
| 13169 |
+ for (TField *field : interfaceBlock->fields()) |
| 13170 |
+ { |
| 13171 |
+ auto &liftedType = CloneType(*field->type()); |
| 13172 |
+ ASSERT(liftedType.getQualifier() == TQualifier::EvqUniform || |
| 13173 |
+ liftedType.getQualifier() == TQualifier::EvqGlobal); |
| 13174 |
+ liftedType.setQualifier(TQualifier::EvqUniform); |
| 13175 |
+ auto *liftedVar = new TVariable(&mSymbolTable, field->name(), &liftedType, |
| 13176 |
+ field->symbolType()); |
| 13177 |
+ |
| 13178 |
+ nameToVar[field->name()] = liftedVar; |
| 13179 |
+ |
| 13180 |
+ replacements.push_back( |
| 13181 |
+ new TIntermDeclaration{new TIntermSymbol(liftedVar)}); |
| 13182 |
+ } |
| 13183 |
+ return PreResult::Multi(std::move(replacements)); |
| 13184 |
+ } |
| 13185 |
+ else |
| 13186 |
+ { |
| 13187 |
+ ASSERT(type.getQualifier() == TQualifier::EvqUniform); |
| 13188 |
+ |
| 13189 |
+ auto &structure = |
| 13190 |
+ *new TStructure(&mSymbolTable, interfaceBlock->name(), |
| 13191 |
+ &interfaceBlock->fields(), interfaceBlock->symbolType()); |
| 13192 |
+ auto &structVar = CreateStructTypeVariable(mSymbolTable, structure); |
| 13193 |
+ auto &instanceVar = |
| 13194 |
+ CreateInstanceVariable(mSymbolTable, structure, Name(var), |
| 13195 |
+ TQualifier::EvqUniform, &type.getArraySizes()); |
| 13196 |
+ |
| 13197 |
+ mInstanceMap[&var] = &instanceVar; |
| 13198 |
+ |
| 13199 |
+ TIntermNode *replacements[] = { |
| 13200 |
+ new TIntermDeclaration{new TIntermSymbol(&structVar)}, |
| 13201 |
+ new TIntermDeclaration{new TIntermSymbol(&instanceVar)}}; |
| 13202 |
+ return PreResult::Multi(std::begin(replacements), std::end(replacements)); |
| 13203 |
+ } |
| 13204 |
+ } |
| 13205 |
+ } |
| 13206 |
+ |
| 13207 |
+ return {declNode, VisitBits::Neither}; |
| 13208 |
+ } |
| 13209 |
+ |
| 13210 |
+ PreResult visitSymbolPre(TIntermSymbol &symbolNode) override |
| 13211 |
+ { |
| 13212 |
+ const TVariable &var = symbolNode.variable(); |
| 13213 |
+ { |
| 13214 |
+ auto it = mInstanceMap.find(&var); |
| 13215 |
+ if (it != mInstanceMap.end()) |
| 13216 |
+ { |
| 13217 |
+ return *new TIntermSymbol(it->second); |
| 13218 |
+ } |
| 13219 |
+ } |
| 13220 |
+ if (const TInterfaceBlock *ib = var.getType().getInterfaceBlock()) |
| 13221 |
+ { |
| 13222 |
+ auto it = mLiftedMap.find(ib); |
| 13223 |
+ if (it != mLiftedMap.end()) |
| 13224 |
+ { |
| 13225 |
+ auto *liftedVar = it->second[var.name()]; |
| 13226 |
+ ASSERT(liftedVar); |
| 13227 |
+ return *new TIntermSymbol(liftedVar); |
| 13228 |
+ } |
| 13229 |
+ } |
| 13230 |
+ return symbolNode; |
| 13231 |
+ } |
| 13232 |
+}; |
| 13233 |
+ |
| 13234 |
+} // anonymous namespace |
| 13235 |
+ |
| 13236 |
+//////////////////////////////////////////////////////////////////////////////// |
| 13237 |
+ |
| 13238 |
+bool sh::ReduceInterfaceBlocks(TCompiler &compiler, TIntermBlock &root) |
| 13239 |
+{ |
| 13240 |
+ Reducer reducer(compiler); |
| 13241 |
+ if (!reducer.rebuildRoot(root)) |
| 13242 |
+ { |
| 13243 |
+ return false; |
| 13244 |
+ } |
| 13245 |
+ |
| 13246 |
+ if (!SeparateDeclarations(&compiler, &root)) |
| 13247 |
+ { |
| 13248 |
+ return false; |
| 13249 |
+ } |
| 13250 |
+ |
| 13251 |
+ return true; |
| 13252 |
+} |
| 13253 |
diff --git a/src/compiler/translator/TranslatorMetalDirect/ReduceInterfaceBlocks.h b/src/compiler/translator/TranslatorMetalDirect/ReduceInterfaceBlocks.h |
| 13254 |
new file mode 100644 |
| 13255 |
index 0000000..3695cba |
| 13256 |
--- /dev/null |
| 13257 |
+++ b/src/compiler/translator/TranslatorMetalDirect/ReduceInterfaceBlocks.h |
| 13258 |
@@ -0,0 +1,35 @@ |
| 13259 |
+// |
| 13260 |
+// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 13261 |
+// Use of this source code is governed by a BSD-style license that can be |
| 13262 |
+// found in the LICENSE file. |
| 13263 |
+// |
| 13264 |
+ |
| 13265 |
+#ifndef COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_REDUCEINTERFACEBLOCKS_H_ |
| 13266 |
+#define COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_REDUCEINTERFACEBLOCKS_H_ |
| 13267 |
+ |
| 13268 |
+#include "common/angleutils.h" |
| 13269 |
+#include "compiler/translator/Compiler.h" |
| 13270 |
+ |
| 13271 |
+namespace sh |
| 13272 |
+{ |
| 13273 |
+ |
| 13274 |
+// This rewrites interface block declarations only. |
| 13275 |
+// |
| 13276 |
+// Access of interface blocks is not rewritten (e.g. TOperator::EOpIndexDirectInterfaceBlock). // |
| 13277 |
+// XXX: ^ Still true? |
| 13278 |
+// |
| 13279 |
+// Example: |
| 13280 |
+// uniform Foo { int x; }; |
| 13281 |
+// Becomes: |
| 13282 |
+// uniform int x; |
| 13283 |
+// |
| 13284 |
+// Example: |
| 13285 |
+// uniform Foo { int x; } foo; |
| 13286 |
+// Becomes: |
| 13287 |
+// struct Foo { int x; }; uniform Foo x; |
| 13288 |
+// |
| 13289 |
+ANGLE_NO_DISCARD bool ReduceInterfaceBlocks(TCompiler &compiler, TIntermBlock &root); |
| 13290 |
+ |
| 13291 |
+} // namespace sh |
| 13292 |
+ |
| 13293 |
+#endif // COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_REDUCEINTERFACEBLOCKS_H_ |
| 13294 |
diff --git a/src/compiler/translator/TranslatorMetalDirect/Reference.h b/src/compiler/translator/TranslatorMetalDirect/Reference.h |
| 13295 |
new file mode 100644 |
| 13296 |
index 0000000..4b5d86c |
| 13297 |
--- /dev/null |
| 13298 |
+++ b/src/compiler/translator/TranslatorMetalDirect/Reference.h |
| 13299 |
@@ -0,0 +1,50 @@ |
| 13300 |
+// |
| 13301 |
+// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 13302 |
+// Use of this source code is governed by a BSD-style license that can be |
| 13303 |
+// found in the LICENSE file. |
| 13304 |
+// |
| 13305 |
+ |
| 13306 |
+#ifndef COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_REFERENCE_H_ |
| 13307 |
+#define COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_REFERENCE_H_ |
| 13308 |
+ |
| 13309 |
+namespace sh |
| 13310 |
+{ |
| 13311 |
+ |
| 13312 |
+// Similar to std::reference_wrapper, but also lifts comparison operators. |
| 13313 |
+template <typename T> |
| 13314 |
+class Ref |
| 13315 |
+{ |
| 13316 |
+ public: |
| 13317 |
+ Ref(const Ref &) = default; |
| 13318 |
+ Ref(Ref &&) = default; |
| 13319 |
+ Ref(T &ref) : mPtr(&ref) {} |
| 13320 |
+ |
| 13321 |
+ Ref &operator=(const Ref &) = default; |
| 13322 |
+ Ref &operator=(Ref &&) = default; |
| 13323 |
+ |
| 13324 |
+ bool operator==(const Ref &other) const { return *mPtr == *other.mPtr; } |
| 13325 |
+ bool operator!=(const Ref &other) const { return *mPtr != *other.mPtr; } |
| 13326 |
+ bool operator<=(const Ref &other) const { return *mPtr <= *other.mPtr; } |
| 13327 |
+ bool operator>=(const Ref &other) const { return *mPtr >= *other.mPtr; } |
| 13328 |
+ bool operator<(const Ref &other) const { return *mPtr < *other.mPtr; } |
| 13329 |
+ bool operator>(const Ref &other) const { return *mPtr > *other.mPtr; } |
| 13330 |
+ |
| 13331 |
+ T &get() { return *mPtr; } |
| 13332 |
+ T const &get() const { return *mPtr; } |
| 13333 |
+ |
| 13334 |
+ operator T &() { return *mPtr; } |
| 13335 |
+ operator T const &() const { return *mPtr; } |
| 13336 |
+ |
| 13337 |
+ operator T *() { return *mPtr; } |
| 13338 |
+ operator T const *() const { return *mPtr; } |
| 13339 |
+ |
| 13340 |
+ private: |
| 13341 |
+ T *mPtr; |
| 13342 |
+}; |
| 13343 |
+ |
| 13344 |
+template <typename T> |
| 13345 |
+using CRef = Ref<T const>; |
| 13346 |
+ |
| 13347 |
+} // namespace sh |
| 13348 |
+ |
| 13349 |
+#endif // COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_REFERENCE_H_ |
| 13350 |
diff --git a/src/compiler/translator/TranslatorMetalDirect/RewriteCaseDeclarations.cpp b/src/compiler/translator/TranslatorMetalDirect/RewriteCaseDeclarations.cpp |
| 13351 |
new file mode 100644 |
| 13352 |
index 0000000..c778177 |
| 13353 |
--- /dev/null |
| 13354 |
+++ b/src/compiler/translator/TranslatorMetalDirect/RewriteCaseDeclarations.cpp |
| 13355 |
@@ -0,0 +1,91 @@ |
| 13356 |
+// |
| 13357 |
+// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 13358 |
+// Use of this source code is governed by a BSD-style license that can be |
| 13359 |
+// found in the LICENSE file. |
| 13360 |
+// |
| 13361 |
+ |
| 13362 |
+#include "compiler/translator/TranslatorMetalDirect/RewriteCaseDeclarations.h" |
| 13363 |
+#include "compiler/translator/TranslatorMetalDirect/AstHelpers.h" |
| 13364 |
+#include "compiler/translator/tree_util/IntermRebuild.h" |
| 13365 |
+ |
| 13366 |
+using namespace sh; |
| 13367 |
+ |
| 13368 |
+//////////////////////////////////////////////////////////////////////////////// |
| 13369 |
+ |
| 13370 |
+namespace |
| 13371 |
+{ |
| 13372 |
+ |
| 13373 |
+class Rewriter : public TIntermRebuild |
| 13374 |
+{ |
| 13375 |
+ std::vector<std::vector<const TVariable *>> mDeclaredVarStack; |
| 13376 |
+ |
| 13377 |
+ public: |
| 13378 |
+ Rewriter(TCompiler &compiler) : TIntermRebuild(compiler, true, true) {} |
| 13379 |
+ |
| 13380 |
+ ~Rewriter() override { ASSERT(mDeclaredVarStack.empty()); } |
| 13381 |
+ |
| 13382 |
+ private: |
| 13383 |
+ PreResult visitSwitchPre(TIntermSwitch &node) override |
| 13384 |
+ { |
| 13385 |
+ mDeclaredVarStack.emplace_back(); |
| 13386 |
+ return node; |
| 13387 |
+ } |
| 13388 |
+ |
| 13389 |
+ PostResult visitSwitchPost(TIntermSwitch &node) override |
| 13390 |
+ { |
| 13391 |
+ ASSERT(!mDeclaredVarStack.empty()); |
| 13392 |
+ const auto vars = std::move(mDeclaredVarStack.back()); |
| 13393 |
+ mDeclaredVarStack.pop_back(); |
| 13394 |
+ if (!vars.empty()) |
| 13395 |
+ { |
| 13396 |
+ auto &block = *new TIntermBlock(); |
| 13397 |
+ for (const TVariable *var : vars) |
| 13398 |
+ { |
| 13399 |
+ block.appendStatement(new TIntermDeclaration{var}); |
| 13400 |
+ } |
| 13401 |
+ block.appendStatement(&node); |
| 13402 |
+ return block; |
| 13403 |
+ } |
| 13404 |
+ return node; |
| 13405 |
+ } |
| 13406 |
+ |
| 13407 |
+ PreResult visitDeclarationPre(TIntermDeclaration &node) override |
| 13408 |
+ { |
| 13409 |
+ if (!mDeclaredVarStack.empty()) |
| 13410 |
+ { |
| 13411 |
+ TIntermNode *parent = getParentNode(); |
| 13412 |
+ if (parent->getAsBlock()) |
| 13413 |
+ { |
| 13414 |
+ TIntermNode *grandparent = getParentNode(1); |
| 13415 |
+ if (grandparent && grandparent->getAsSwitchNode()) |
| 13416 |
+ { |
| 13417 |
+ Declaration decl = ViewDeclaration(node); |
| 13418 |
+ mDeclaredVarStack.back().push_back(&decl.symbol.variable()); |
| 13419 |
+ if (decl.initExpr) |
| 13420 |
+ { |
| 13421 |
+ return *new TIntermBinary(TOperator::EOpAssign, &decl.symbol, |
| 13422 |
+ decl.initExpr); |
| 13423 |
+ } |
| 13424 |
+ else |
| 13425 |
+ { |
| 13426 |
+ return nullptr; |
| 13427 |
+ } |
| 13428 |
+ } |
| 13429 |
+ } |
| 13430 |
+ } |
| 13431 |
+ return node; |
| 13432 |
+ } |
| 13433 |
+}; |
| 13434 |
+ |
| 13435 |
+} // anonymous namespace |
| 13436 |
+ |
| 13437 |
+//////////////////////////////////////////////////////////////////////////////// |
| 13438 |
+ |
| 13439 |
+bool sh::RewriteCaseDeclarations(TCompiler &compiler, TIntermBlock &root) |
| 13440 |
+{ |
| 13441 |
+ if (!Rewriter(compiler).rebuildRoot(root)) |
| 13442 |
+ { |
| 13443 |
+ return false; |
| 13444 |
+ } |
| 13445 |
+ return true; |
| 13446 |
+} |
| 13447 |
diff --git a/src/compiler/translator/TranslatorMetalDirect/RewriteCaseDeclarations.h b/src/compiler/translator/TranslatorMetalDirect/RewriteCaseDeclarations.h |
| 13448 |
new file mode 100644 |
| 13449 |
index 0000000..e5a8821 |
| 13450 |
--- /dev/null |
| 13451 |
+++ b/src/compiler/translator/TranslatorMetalDirect/RewriteCaseDeclarations.h |
| 13452 |
@@ -0,0 +1,50 @@ |
| 13453 |
+// |
| 13454 |
+// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 13455 |
+// Use of this source code is governed by a BSD-style license that can be |
| 13456 |
+// found in the LICENSE file. |
| 13457 |
+// |
| 13458 |
+ |
| 13459 |
+#ifndef COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_REWRITECASEDECLARATIONS_H_ |
| 13460 |
+#define COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_REWRITECASEDECLARATIONS_H_ |
| 13461 |
+ |
| 13462 |
+#include "common/angleutils.h" |
| 13463 |
+#include "compiler/translator/Compiler.h" |
| 13464 |
+ |
| 13465 |
+namespace sh |
| 13466 |
+{ |
| 13467 |
+ |
| 13468 |
+// EXAMPLE |
| 13469 |
+// switch (expr) |
| 13470 |
+// { |
| 13471 |
+// case 0: |
| 13472 |
+// int x = 0; |
| 13473 |
+// break; |
| 13474 |
+// case 1: |
| 13475 |
+// int y = 0; |
| 13476 |
+// { |
| 13477 |
+// int z = 0; |
| 13478 |
+// } |
| 13479 |
+// break; |
| 13480 |
+// } |
| 13481 |
+// Becomes |
| 13482 |
+// { |
| 13483 |
+// int x; |
| 13484 |
+// int y; |
| 13485 |
+// switch (expr) |
| 13486 |
+// { |
| 13487 |
+// case 0: |
| 13488 |
+// x = 0; |
| 13489 |
+// break; |
| 13490 |
+// case 1: |
| 13491 |
+// y = 0; |
| 13492 |
+// { |
| 13493 |
+// int z = 0; |
| 13494 |
+// } |
| 13495 |
+// break; |
| 13496 |
+// } |
| 13497 |
+// } |
| 13498 |
+ANGLE_NO_DISCARD bool RewriteCaseDeclarations(TCompiler &compiler, TIntermBlock &root); |
| 13499 |
+ |
| 13500 |
+} // namespace sh |
| 13501 |
+ |
| 13502 |
+#endif // COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_REWRITECASEDECLARATIONS_H_ |
| 13503 |
diff --git a/src/compiler/translator/TranslatorMetalDirect/RewriteGlobalQualifierDecls.cpp b/src/compiler/translator/TranslatorMetalDirect/RewriteGlobalQualifierDecls.cpp |
| 13504 |
new file mode 100644 |
| 13505 |
index 0000000..4ad5a36 |
| 13506 |
--- /dev/null |
| 13507 |
+++ b/src/compiler/translator/TranslatorMetalDirect/RewriteGlobalQualifierDecls.cpp |
| 13508 |
@@ -0,0 +1,114 @@ |
| 13509 |
+// |
| 13510 |
+// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 13511 |
+// Use of this source code is governed by a BSD-style license that can be |
| 13512 |
+// found in the LICENSE file. |
| 13513 |
+// |
| 13514 |
+ |
| 13515 |
+#include "compiler/translator/TranslatorMetalDirect/RewriteGlobalQualifierDecls.h" |
| 13516 |
+#include "compiler/translator/TranslatorMetalDirect/Debug.h" |
| 13517 |
+#include "compiler/translator/tree_util/IntermRebuild.h" |
| 13518 |
+ |
| 13519 |
+using namespace sh; |
| 13520 |
+ |
| 13521 |
+namespace |
| 13522 |
+{ |
| 13523 |
+ |
| 13524 |
+class FindDeclaredGlobals : public TIntermRebuild |
| 13525 |
+{ |
| 13526 |
+ public: |
| 13527 |
+ std::unordered_set<const TVariable *> mDeclaredGlobals; |
| 13528 |
+ |
| 13529 |
+ FindDeclaredGlobals(TCompiler &compiler) : TIntermRebuild(compiler, true, false) {} |
| 13530 |
+ |
| 13531 |
+ PreResult visitDeclarationPre(TIntermDeclaration &declNode) override |
| 13532 |
+ { |
| 13533 |
+ TIntermNode *declaratorNode = declNode.getChildNode(0); |
| 13534 |
+ TIntermSymbol *symbolNode = nullptr; |
| 13535 |
+ |
| 13536 |
+ if (TIntermBinary *initNode = declaratorNode->getAsBinaryNode()) |
| 13537 |
+ { |
| 13538 |
+ symbolNode = initNode->getLeft()->getAsSymbolNode(); |
| 13539 |
+ } |
| 13540 |
+ else |
| 13541 |
+ { |
| 13542 |
+ symbolNode = declaratorNode->getAsSymbolNode(); |
| 13543 |
+ } |
| 13544 |
+ |
| 13545 |
+ ASSERT(symbolNode); |
| 13546 |
+ const TVariable &var = symbolNode->variable(); |
| 13547 |
+ |
| 13548 |
+ mDeclaredGlobals.insert(&var); |
| 13549 |
+ |
| 13550 |
+ return {declNode, VisitBits::Neither}; |
| 13551 |
+ } |
| 13552 |
+ |
| 13553 |
+ PreResult visitFunctionDefinitionPre(TIntermFunctionDefinition &node) override |
| 13554 |
+ { |
| 13555 |
+ return {node, VisitBits::Neither}; |
| 13556 |
+ } |
| 13557 |
+}; |
| 13558 |
+ |
| 13559 |
+class Rewriter : public TIntermRebuild |
| 13560 |
+{ |
| 13561 |
+ const std::unordered_set<const TVariable *> &mDeclaredGlobals; |
| 13562 |
+ Invariants &mOutInvariants; |
| 13563 |
+ |
| 13564 |
+ public: |
| 13565 |
+ Rewriter(TCompiler &compiler, |
| 13566 |
+ const std::unordered_set<const TVariable *> &declaredGlobals, |
| 13567 |
+ Invariants &outInvariants) |
| 13568 |
+ : TIntermRebuild(compiler, true, false), |
| 13569 |
+ mDeclaredGlobals(declaredGlobals), |
| 13570 |
+ mOutInvariants(outInvariants) |
| 13571 |
+ {} |
| 13572 |
+ |
| 13573 |
+ PreResult visitGlobalQualifierDeclarationPre( |
| 13574 |
+ TIntermGlobalQualifierDeclaration &gqDeclNode) override |
| 13575 |
+ { |
| 13576 |
+ TIntermSymbol &symbolNode = *gqDeclNode.getSymbol(); |
| 13577 |
+ const TVariable &var = symbolNode.variable(); |
| 13578 |
+ |
| 13579 |
+ if (gqDeclNode.isInvariant()) |
| 13580 |
+ { |
| 13581 |
+ mOutInvariants.insert(var); |
| 13582 |
+ } |
| 13583 |
+ |
| 13584 |
+ if (mDeclaredGlobals.find(&var) == mDeclaredGlobals.end()) |
| 13585 |
+ { |
| 13586 |
+ return *new TIntermDeclaration{&symbolNode}; |
| 13587 |
+ } |
| 13588 |
+ return nullptr; |
| 13589 |
+ } |
| 13590 |
+ |
| 13591 |
+ PreResult visitDeclarationPre(TIntermDeclaration &node) override |
| 13592 |
+ { |
| 13593 |
+ return {node, VisitBits::Neither}; |
| 13594 |
+ } |
| 13595 |
+ |
| 13596 |
+ PreResult visitFunctionDefinitionPre(TIntermFunctionDefinition &node) override |
| 13597 |
+ { |
| 13598 |
+ return {node, VisitBits::Neither}; |
| 13599 |
+ } |
| 13600 |
+}; |
| 13601 |
+ |
| 13602 |
+} // anonymous namespace |
| 13603 |
+ |
| 13604 |
+bool sh::RewriteGlobalQualifierDecls(TCompiler &compiler, |
| 13605 |
+ TIntermBlock &root, |
| 13606 |
+ Invariants &outInvariants) |
| 13607 |
+{ |
| 13608 |
+ FindDeclaredGlobals fdg(compiler); |
| 13609 |
+ if (!fdg.rebuildRoot(root)) |
| 13610 |
+ { |
| 13611 |
+ LOGIC_ERROR(); |
| 13612 |
+ return false; |
| 13613 |
+ } |
| 13614 |
+ |
| 13615 |
+ Rewriter rewriter(compiler, fdg.mDeclaredGlobals, outInvariants); |
| 13616 |
+ if (!rewriter.rebuildRoot(root)) |
| 13617 |
+ { |
| 13618 |
+ return false; |
| 13619 |
+ } |
| 13620 |
+ |
| 13621 |
+ return true; |
| 13622 |
+} |
| 13623 |
diff --git a/src/compiler/translator/TranslatorMetalDirect/RewriteGlobalQualifierDecls.h b/src/compiler/translator/TranslatorMetalDirect/RewriteGlobalQualifierDecls.h |
| 13624 |
new file mode 100644 |
| 13625 |
index 0000000..9131bca |
| 13626 |
--- /dev/null |
| 13627 |
+++ b/src/compiler/translator/TranslatorMetalDirect/RewriteGlobalQualifierDecls.h |
| 13628 |
@@ -0,0 +1,48 @@ |
| 13629 |
+// |
| 13630 |
+// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 13631 |
+// Use of this source code is governed by a BSD-style license that can be |
| 13632 |
+// found in the LICENSE file. |
| 13633 |
+// |
| 13634 |
+ |
| 13635 |
+#ifndef COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_REWRITEGLOBALQUALIFIERDECLS_H_ |
| 13636 |
+#define COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_REWRITEGLOBALQUALIFIERDECLS_H_ |
| 13637 |
+ |
| 13638 |
+#include <unordered_set> |
| 13639 |
+ |
| 13640 |
+#include "compiler/translator/Compiler.h" |
| 13641 |
+ |
| 13642 |
+namespace sh |
| 13643 |
+{ |
| 13644 |
+ |
| 13645 |
+// Tracks TVariables and TFields that are marked as "invariant". |
| 13646 |
+class Invariants |
| 13647 |
+{ |
| 13648 |
+ public: |
| 13649 |
+ void insert(const TVariable &var) { mInvariants.insert(&var); } |
| 13650 |
+ |
| 13651 |
+ void insert(const TField &field) { mInvariants.insert(&field); } |
| 13652 |
+ |
| 13653 |
+ bool contains(const TVariable &var) const |
| 13654 |
+ { |
| 13655 |
+ return mInvariants.find(&var) != mInvariants.end(); |
| 13656 |
+ } |
| 13657 |
+ |
| 13658 |
+ bool contains(const TField &field) const |
| 13659 |
+ { |
| 13660 |
+ return mInvariants.find(&field) != mInvariants.end(); |
| 13661 |
+ } |
| 13662 |
+ |
| 13663 |
+ private: |
| 13664 |
+ std::unordered_set<const void *> mInvariants; |
| 13665 |
+}; |
| 13666 |
+ |
| 13667 |
+// This rewrites TIntermGlobalQualifierDeclarations as TIntermDeclarations. |
| 13668 |
+// `outInvariants` is populated with the information that would otherwise be lost by such a |
| 13669 |
+// transform. |
| 13670 |
+ANGLE_NO_DISCARD bool RewriteGlobalQualifierDecls(TCompiler &compiler, |
| 13671 |
+ TIntermBlock &root, |
| 13672 |
+ Invariants &outInvariants); |
| 13673 |
+ |
| 13674 |
+} // namespace sh |
| 13675 |
+ |
| 13676 |
+#endif // COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_REWRITEGLOBALQUALIFIERDECLS_H_ |
| 13677 |
diff --git a/src/compiler/translator/TranslatorMetalDirect/RewriteKeywords.cpp b/src/compiler/translator/TranslatorMetalDirect/RewriteKeywords.cpp |
| 13678 |
new file mode 100644 |
| 13679 |
index 0000000..e014f40 |
| 13680 |
--- /dev/null |
| 13681 |
+++ b/src/compiler/translator/TranslatorMetalDirect/RewriteKeywords.cpp |
| 13682 |
@@ -0,0 +1,434 @@ |
| 13683 |
+// |
| 13684 |
+// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 13685 |
+// Use of this source code is governed by a BSD-style license that can be |
| 13686 |
+// found in the LICENSE file. |
| 13687 |
+// |
| 13688 |
+ |
| 13689 |
+#include <cctype> |
| 13690 |
+#include <cstring> |
| 13691 |
+#include <limits> |
| 13692 |
+#include <unordered_map> |
| 13693 |
+#include <unordered_set> |
| 13694 |
+ |
| 13695 |
+#include "compiler/translator/TranslatorMetalDirect/AstHelpers.h" |
| 13696 |
+#include "compiler/translator/TranslatorMetalDirect/Debug.h" |
| 13697 |
+#include "compiler/translator/TranslatorMetalDirect/RewriteKeywords.h" |
| 13698 |
+#include "compiler/translator/tree_util/IntermRebuild.h" |
| 13699 |
+ |
| 13700 |
+using namespace sh; |
| 13701 |
+ |
| 13702 |
+//////////////////////////////////////////////////////////////////////////////// |
| 13703 |
+ |
| 13704 |
+namespace |
| 13705 |
+{ |
| 13706 |
+ |
| 13707 |
+template <typename T> |
| 13708 |
+using Remapping = std::unordered_map<const T *, const T *>; |
| 13709 |
+ |
| 13710 |
+class Rewriter : public TIntermRebuild |
| 13711 |
+{ |
| 13712 |
+ private: |
| 13713 |
+ const std::set<ImmutableString> &mKeywords; |
| 13714 |
+ IdGen &mIdGen; |
| 13715 |
+ Remapping<TField> modifiedFields; |
| 13716 |
+ Remapping<TFieldList> mFieldLists; |
| 13717 |
+ Remapping<TFunction> mFunctions; |
| 13718 |
+ Remapping<TInterfaceBlock> mInterfaceBlocks; |
| 13719 |
+ Remapping<TStructure> mStructures; |
| 13720 |
+ Remapping<TVariable> mVariables; |
| 13721 |
+ std::string mNewNameBuffer; |
| 13722 |
+ |
| 13723 |
+ private: |
| 13724 |
+ template <typename T> |
| 13725 |
+ ImmutableString maybeCreateNewName(T const &object) |
| 13726 |
+ { |
| 13727 |
+ if (needsRenaming(object, false)) |
| 13728 |
+ { |
| 13729 |
+ return mIdGen.createNewName(Name(object)).rawName(); |
| 13730 |
+ } |
| 13731 |
+ return Name(object).rawName(); |
| 13732 |
+ } |
| 13733 |
+ |
| 13734 |
+ const TField *createRenamed(const TField &field) |
| 13735 |
+ { |
| 13736 |
+ auto *renamed = |
| 13737 |
+ new TField(const_cast<TType *>(&getRenamedOrOriginal(*field.type())), |
| 13738 |
+ maybeCreateNewName(field), field.line(), SymbolType::AngleInternal); |
| 13739 |
+ |
| 13740 |
+ return renamed; |
| 13741 |
+ } |
| 13742 |
+ |
| 13743 |
+ const TFieldList *createRenamed(const TFieldList &fieldList) |
| 13744 |
+ { |
| 13745 |
+ auto *renamed = new TFieldList(); |
| 13746 |
+ for (const TField *field : fieldList) |
| 13747 |
+ { |
| 13748 |
+ renamed->push_back(const_cast<TField *>(&getRenamedOrOriginal(*field))); |
| 13749 |
+ } |
| 13750 |
+ return renamed; |
| 13751 |
+ } |
| 13752 |
+ |
| 13753 |
+ const TFunction *createRenamed(const TFunction &function) |
| 13754 |
+ { |
| 13755 |
+ auto *renamed = |
| 13756 |
+ new TFunction(&mSymbolTable, maybeCreateNewName(function), SymbolType::AngleInternal, |
| 13757 |
+ &getRenamedOrOriginal(function.getReturnType()), |
| 13758 |
+ function.isKnownToNotHaveSideEffects()); |
| 13759 |
+ |
| 13760 |
+ const size_t paramCount = function.getParamCount(); |
| 13761 |
+ for (size_t i = 0; i < paramCount; ++i) |
| 13762 |
+ { |
| 13763 |
+ const TVariable ¶m = *function.getParam(i); |
| 13764 |
+ renamed->addParameter(&getRenamedOrOriginal(param)); |
| 13765 |
+ } |
| 13766 |
+ |
| 13767 |
+ if (function.isDefined()) |
| 13768 |
+ { |
| 13769 |
+ renamed->setDefined(); |
| 13770 |
+ } |
| 13771 |
+ |
| 13772 |
+ if (function.hasPrototypeDeclaration()) |
| 13773 |
+ { |
| 13774 |
+ renamed->setHasPrototypeDeclaration(); |
| 13775 |
+ } |
| 13776 |
+ |
| 13777 |
+ return renamed; |
| 13778 |
+ } |
| 13779 |
+ |
| 13780 |
+ const TInterfaceBlock *createRenamed(const TInterfaceBlock &interfaceBlock) |
| 13781 |
+ { |
| 13782 |
+ TLayoutQualifier layoutQualifier = TLayoutQualifier::Create(); |
| 13783 |
+ layoutQualifier.blockStorage = interfaceBlock.blockStorage(); |
| 13784 |
+ layoutQualifier.binding = interfaceBlock.blockBinding(); |
| 13785 |
+ |
| 13786 |
+ auto *renamed = |
| 13787 |
+ new TInterfaceBlock(&mSymbolTable, maybeCreateNewName(interfaceBlock), |
| 13788 |
+ &getRenamedOrOriginal(interfaceBlock.fields()), layoutQualifier, |
| 13789 |
+ SymbolType::AngleInternal, interfaceBlock.extension()); |
| 13790 |
+ |
| 13791 |
+ return renamed; |
| 13792 |
+ } |
| 13793 |
+ |
| 13794 |
+ const TStructure *createRenamed(const TStructure &structure) |
| 13795 |
+ { |
| 13796 |
+ auto *renamed = |
| 13797 |
+ new TStructure(&mSymbolTable, maybeCreateNewName(structure), |
| 13798 |
+ &getRenamedOrOriginal(structure.fields()), SymbolType::AngleInternal); |
| 13799 |
+ |
| 13800 |
+ renamed->setAtGlobalScope(structure.atGlobalScope()); |
| 13801 |
+ |
| 13802 |
+ return renamed; |
| 13803 |
+ } |
| 13804 |
+ |
| 13805 |
+ const TType *createRenamed(const TType &type) |
| 13806 |
+ { |
| 13807 |
+ TType *renamed; |
| 13808 |
+ |
| 13809 |
+ if (const TStructure *structure = type.getStruct()) |
| 13810 |
+ { |
| 13811 |
+ renamed = new TType(&getRenamedOrOriginal(*structure), type.isStructSpecifier()); |
| 13812 |
+ } |
| 13813 |
+ else if (const TInterfaceBlock *interfaceBlock = type.getInterfaceBlock()) |
| 13814 |
+ { |
| 13815 |
+ renamed = new TType(&getRenamedOrOriginal(*interfaceBlock), type.getQualifier(), |
| 13816 |
+ type.getLayoutQualifier()); |
| 13817 |
+ } |
| 13818 |
+ else |
| 13819 |
+ { |
| 13820 |
+ LOGIC_ERROR(); // Can't rename built-in types. |
| 13821 |
+ renamed = nullptr; |
| 13822 |
+ } |
| 13823 |
+ |
| 13824 |
+ if (type.isArray()) |
| 13825 |
+ { |
| 13826 |
+ renamed->makeArrays(type.getArraySizes()); |
| 13827 |
+ } |
| 13828 |
+ renamed->setPrecise(type.isPrecise()); |
| 13829 |
+ renamed->setInvariant(type.isInvariant()); |
| 13830 |
+ renamed->setMemoryQualifier(type.getMemoryQualifier()); |
| 13831 |
+ renamed->setLayoutQualifier(type.getLayoutQualifier()); |
| 13832 |
+ |
| 13833 |
+ return renamed; |
| 13834 |
+ } |
| 13835 |
+ |
| 13836 |
+ const TVariable *createRenamed(const TVariable &variable) |
| 13837 |
+ { |
| 13838 |
+ auto *renamed = new TVariable(&mSymbolTable, maybeCreateNewName(variable), |
| 13839 |
+ &getRenamedOrOriginal(variable.getType()), |
| 13840 |
+ SymbolType::AngleInternal, variable.extension()); |
| 13841 |
+ |
| 13842 |
+ return renamed; |
| 13843 |
+ } |
| 13844 |
+ |
| 13845 |
+ template <typename T> |
| 13846 |
+ const T *tryGetRenamedImpl(const T &object, Remapping<T> *remapping) |
| 13847 |
+ { |
| 13848 |
+ if (!needsRenaming(object, true)) |
| 13849 |
+ { |
| 13850 |
+ return nullptr; |
| 13851 |
+ } |
| 13852 |
+ |
| 13853 |
+ if (remapping) |
| 13854 |
+ { |
| 13855 |
+ auto it = remapping->find(&object); |
| 13856 |
+ if (it != remapping->end()) |
| 13857 |
+ { |
| 13858 |
+ return it->second; |
| 13859 |
+ } |
| 13860 |
+ } |
| 13861 |
+ |
| 13862 |
+ const T *renamedObject = createRenamed(object); |
| 13863 |
+ |
| 13864 |
+ if (remapping) |
| 13865 |
+ { |
| 13866 |
+ (*remapping)[&object] = renamedObject; |
| 13867 |
+ } |
| 13868 |
+ |
| 13869 |
+ return renamedObject; |
| 13870 |
+ } |
| 13871 |
+ |
| 13872 |
+ const TField *tryGetRenamed(const TField &field) |
| 13873 |
+ { |
| 13874 |
+ return tryGetRenamedImpl(field, &modifiedFields); |
| 13875 |
+ } |
| 13876 |
+ |
| 13877 |
+ const TFieldList *tryGetRenamed(const TFieldList &fieldList) |
| 13878 |
+ { |
| 13879 |
+ return tryGetRenamedImpl(fieldList, &mFieldLists); |
| 13880 |
+ } |
| 13881 |
+ |
| 13882 |
+ const TFunction *tryGetRenamed(const TFunction &func) |
| 13883 |
+ { |
| 13884 |
+ return tryGetRenamedImpl(func, &mFunctions); |
| 13885 |
+ } |
| 13886 |
+ |
| 13887 |
+ const TInterfaceBlock *tryGetRenamed(const TInterfaceBlock &interfaceBlock) |
| 13888 |
+ { |
| 13889 |
+ return tryGetRenamedImpl(interfaceBlock, &mInterfaceBlocks); |
| 13890 |
+ } |
| 13891 |
+ |
| 13892 |
+ const TStructure *tryGetRenamed(const TStructure &structure) |
| 13893 |
+ { |
| 13894 |
+ return tryGetRenamedImpl(structure, &mStructures); |
| 13895 |
+ } |
| 13896 |
+ |
| 13897 |
+ const TType *tryGetRenamed(const TType &type) |
| 13898 |
+ { |
| 13899 |
+ return tryGetRenamedImpl(type, static_cast<Remapping<TType> *>(nullptr)); |
| 13900 |
+ } |
| 13901 |
+ |
| 13902 |
+ const TVariable *tryGetRenamed(const TVariable &variable) |
| 13903 |
+ { |
| 13904 |
+ return tryGetRenamedImpl(variable, &mVariables); |
| 13905 |
+ } |
| 13906 |
+ |
| 13907 |
+ template <typename T> |
| 13908 |
+ const T &getRenamedOrOriginal(const T &object) |
| 13909 |
+ { |
| 13910 |
+ const T *renamed = tryGetRenamed(object); |
| 13911 |
+ if (renamed) |
| 13912 |
+ { |
| 13913 |
+ return *renamed; |
| 13914 |
+ } |
| 13915 |
+ return object; |
| 13916 |
+ } |
| 13917 |
+ |
| 13918 |
+ template <typename T> |
| 13919 |
+ bool needsRenamingImpl(const T &object) const |
| 13920 |
+ { |
| 13921 |
+ const SymbolType symbolType = object.symbolType(); |
| 13922 |
+ switch (symbolType) |
| 13923 |
+ { |
| 13924 |
+ case SymbolType::BuiltIn: |
| 13925 |
+ case SymbolType::AngleInternal: |
| 13926 |
+ case SymbolType::Empty: |
| 13927 |
+ return false; |
| 13928 |
+ |
| 13929 |
+ case SymbolType::UserDefined: |
| 13930 |
+ break; |
| 13931 |
+ } |
| 13932 |
+ |
| 13933 |
+ const ImmutableString name = Name(object).rawName(); |
| 13934 |
+ if (mKeywords.find(name) != mKeywords.end()) |
| 13935 |
+ { |
| 13936 |
+ return true; |
| 13937 |
+ } |
| 13938 |
+ |
| 13939 |
+ if (name.beginsWith(kAngleInternalPrefix)) |
| 13940 |
+ { |
| 13941 |
+ return true; |
| 13942 |
+ } |
| 13943 |
+ |
| 13944 |
+ return false; |
| 13945 |
+ } |
| 13946 |
+ |
| 13947 |
+ bool needsRenaming(const TField &field, bool recursive) const |
| 13948 |
+ { |
| 13949 |
+ return needsRenamingImpl(field) || (recursive && needsRenaming(*field.type(), true)); |
| 13950 |
+ } |
| 13951 |
+ |
| 13952 |
+ bool needsRenaming(const TFieldList &fieldList, bool recursive) const |
| 13953 |
+ { |
| 13954 |
+ ASSERT(recursive); |
| 13955 |
+ for (const TField *field : fieldList) |
| 13956 |
+ { |
| 13957 |
+ if (needsRenaming(*field, true)) |
| 13958 |
+ { |
| 13959 |
+ return true; |
| 13960 |
+ } |
| 13961 |
+ } |
| 13962 |
+ return false; |
| 13963 |
+ } |
| 13964 |
+ |
| 13965 |
+ bool needsRenaming(const TFunction &function, bool recursive) const |
| 13966 |
+ { |
| 13967 |
+ if (needsRenamingImpl(function)) |
| 13968 |
+ { |
| 13969 |
+ return true; |
| 13970 |
+ } |
| 13971 |
+ |
| 13972 |
+ if (!recursive) |
| 13973 |
+ { |
| 13974 |
+ return false; |
| 13975 |
+ } |
| 13976 |
+ |
| 13977 |
+ const size_t paramCount = function.getParamCount(); |
| 13978 |
+ for (size_t i = 0; i < paramCount; ++i) |
| 13979 |
+ { |
| 13980 |
+ const TVariable ¶m = *function.getParam(i); |
| 13981 |
+ if (needsRenaming(param, true)) |
| 13982 |
+ { |
| 13983 |
+ return true; |
| 13984 |
+ } |
| 13985 |
+ } |
| 13986 |
+ |
| 13987 |
+ return false; |
| 13988 |
+ } |
| 13989 |
+ |
| 13990 |
+ bool needsRenaming(const TInterfaceBlock &interfaceBlock, bool recursive) const |
| 13991 |
+ { |
| 13992 |
+ return needsRenamingImpl(interfaceBlock) || |
| 13993 |
+ (recursive && needsRenaming(interfaceBlock.fields(), true)); |
| 13994 |
+ } |
| 13995 |
+ |
| 13996 |
+ bool needsRenaming(const TStructure &structure, bool recursive) const |
| 13997 |
+ { |
| 13998 |
+ return needsRenamingImpl(structure) || |
| 13999 |
+ (recursive && needsRenaming(structure.fields(), true)); |
| 14000 |
+ } |
| 14001 |
+ |
| 14002 |
+ bool needsRenaming(const TType &type, bool recursive) const |
| 14003 |
+ { |
| 14004 |
+ if (const TStructure *structure = type.getStruct()) |
| 14005 |
+ { |
| 14006 |
+ return needsRenaming(*structure, recursive); |
| 14007 |
+ } |
| 14008 |
+ else if (const TInterfaceBlock *interfaceBlock = type.getInterfaceBlock()) |
| 14009 |
+ { |
| 14010 |
+ return needsRenaming(*interfaceBlock, recursive); |
| 14011 |
+ } |
| 14012 |
+ else |
| 14013 |
+ { |
| 14014 |
+ return false; |
| 14015 |
+ } |
| 14016 |
+ } |
| 14017 |
+ |
| 14018 |
+ bool needsRenaming(const TVariable &variable, bool recursive) const |
| 14019 |
+ { |
| 14020 |
+ return needsRenamingImpl(variable) || |
| 14021 |
+ (recursive && needsRenaming(variable.getType(), true)); |
| 14022 |
+ } |
| 14023 |
+ |
| 14024 |
+ public: |
| 14025 |
+ Rewriter(TCompiler &compiler, IdGen &idGen, const std::set<ImmutableString> &keywords) |
| 14026 |
+ : TIntermRebuild(compiler, false, true), mKeywords(keywords), mIdGen(idGen) |
| 14027 |
+ {} |
| 14028 |
+ |
| 14029 |
+ PostResult visitSymbol(TIntermSymbol &symbolNode) |
| 14030 |
+ { |
| 14031 |
+ const TVariable &var = symbolNode.variable(); |
| 14032 |
+ if (needsRenaming(var, true)) |
| 14033 |
+ { |
| 14034 |
+ const TVariable &rVar = getRenamedOrOriginal(var); |
| 14035 |
+ return *new TIntermSymbol(&rVar); |
| 14036 |
+ } |
| 14037 |
+ return symbolNode; |
| 14038 |
+ } |
| 14039 |
+ |
| 14040 |
+ PostResult visitFunctionPrototype(TIntermFunctionPrototype &funcProtoNode) |
| 14041 |
+ { |
| 14042 |
+ const TFunction &func = *funcProtoNode.getFunction(); |
| 14043 |
+ if (needsRenaming(func, true)) |
| 14044 |
+ { |
| 14045 |
+ const TFunction &rFunc = getRenamedOrOriginal(func); |
| 14046 |
+ return *new TIntermFunctionPrototype(&rFunc); |
| 14047 |
+ } |
| 14048 |
+ return funcProtoNode; |
| 14049 |
+ } |
| 14050 |
+ |
| 14051 |
+ PostResult visitFunctionDefinitionPost(TIntermFunctionDefinition &funcDefNode) override |
| 14052 |
+ { |
| 14053 |
+ TIntermFunctionPrototype &funcProtoNode = *funcDefNode.getFunctionPrototype(); |
| 14054 |
+ const TFunction &func = *funcProtoNode.getFunction(); |
| 14055 |
+ if (needsRenaming(func, true)) |
| 14056 |
+ { |
| 14057 |
+ const TFunction &rFunc = getRenamedOrOriginal(func); |
| 14058 |
+ auto *rFuncProtoNode = new TIntermFunctionPrototype(&rFunc); |
| 14059 |
+ return *new TIntermFunctionDefinition(rFuncProtoNode, funcDefNode.getBody()); |
| 14060 |
+ } |
| 14061 |
+ return funcDefNode; |
| 14062 |
+ } |
| 14063 |
+ |
| 14064 |
+ PostResult visitAggregatePost(TIntermAggregate &aggregateNode) override |
| 14065 |
+ { |
| 14066 |
+ if (aggregateNode.isConstructor()) |
| 14067 |
+ { |
| 14068 |
+ const TType &type = aggregateNode.getType(); |
| 14069 |
+ if (needsRenaming(type, true)) |
| 14070 |
+ { |
| 14071 |
+ const TType &rType = getRenamedOrOriginal(type); |
| 14072 |
+ return TIntermAggregate::CreateConstructor(rType, aggregateNode.getSequence()); |
| 14073 |
+ } |
| 14074 |
+ } |
| 14075 |
+ else |
| 14076 |
+ { |
| 14077 |
+ const TFunction &func = *aggregateNode.getFunction(); |
| 14078 |
+ if (needsRenaming(func, true)) |
| 14079 |
+ { |
| 14080 |
+ const TFunction &rFunc = getRenamedOrOriginal(func); |
| 14081 |
+ switch (aggregateNode.getOp()) |
| 14082 |
+ { |
| 14083 |
+ case TOperator::EOpCallFunctionInAST: |
| 14084 |
+ return TIntermAggregate::CreateFunctionCall(rFunc, |
| 14085 |
+ aggregateNode.getSequence()); |
| 14086 |
+ |
| 14087 |
+ case TOperator::EOpCallInternalRawFunction: |
| 14088 |
+ return TIntermAggregate::CreateRawFunctionCall(rFunc, |
| 14089 |
+ aggregateNode.getSequence()); |
| 14090 |
+ |
| 14091 |
+ default: |
| 14092 |
+ return TIntermAggregate::CreateBuiltInFunctionCall( |
| 14093 |
+ rFunc, aggregateNode.getSequence()); |
| 14094 |
+ } |
| 14095 |
+ } |
| 14096 |
+ } |
| 14097 |
+ return aggregateNode; |
| 14098 |
+ } |
| 14099 |
+}; |
| 14100 |
+ |
| 14101 |
+} // anonymous namespace |
| 14102 |
+ |
| 14103 |
+//////////////////////////////////////////////////////////////////////////////// |
| 14104 |
+ |
| 14105 |
+bool sh::RewriteKeywords(TCompiler &compiler, |
| 14106 |
+ TIntermBlock &root, |
| 14107 |
+ IdGen &idGen, |
| 14108 |
+ const std::set<ImmutableString> &keywords) |
| 14109 |
+{ |
| 14110 |
+ Rewriter rewriter(compiler, idGen, keywords); |
| 14111 |
+ if (!rewriter.rebuildRoot(root)) |
| 14112 |
+ { |
| 14113 |
+ return false; |
| 14114 |
+ } |
| 14115 |
+ return true; |
| 14116 |
+} |
| 14117 |
diff --git a/src/compiler/translator/TranslatorMetalDirect/RewriteKeywords.h b/src/compiler/translator/TranslatorMetalDirect/RewriteKeywords.h |
| 14118 |
new file mode 100644 |
| 14119 |
index 0000000..b162bc7 |
| 14120 |
--- /dev/null |
| 14121 |
+++ b/src/compiler/translator/TranslatorMetalDirect/RewriteKeywords.h |
| 14122 |
@@ -0,0 +1,27 @@ |
| 14123 |
+// |
| 14124 |
+// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 14125 |
+// Use of this source code is governed by a BSD-style license that can be |
| 14126 |
+// found in the LICENSE file. |
| 14127 |
+// |
| 14128 |
+ |
| 14129 |
+#ifndef COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_REWRITEKEYWORDS_H_ |
| 14130 |
+#define COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_REWRITEKEYWORDS_H_ |
| 14131 |
+ |
| 14132 |
+#include <set> |
| 14133 |
+ |
| 14134 |
+#include "common/angleutils.h" |
| 14135 |
+#include "compiler/translator/Compiler.h" |
| 14136 |
+#include "compiler/translator/TranslatorMetalDirect/IdGen.h" |
| 14137 |
+ |
| 14138 |
+namespace sh |
| 14139 |
+{ |
| 14140 |
+ |
| 14141 |
+// This walks the tree and renames all names that conflict with the input `keywords`. |
| 14142 |
+ANGLE_NO_DISCARD bool RewriteKeywords(TCompiler &compiler, |
| 14143 |
+ TIntermBlock &root, |
| 14144 |
+ IdGen &idGen, |
| 14145 |
+ const std::set<ImmutableString> &keywords); |
| 14146 |
+ |
| 14147 |
+} // namespace sh |
| 14148 |
+ |
| 14149 |
+#endif // COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_REWRITEKEYWORDS_H_ |
| 14150 |
diff --git a/src/compiler/translator/TranslatorMetalDirect/RewriteOutArgs.cpp b/src/compiler/translator/TranslatorMetalDirect/RewriteOutArgs.cpp |
| 14151 |
new file mode 100644 |
| 14152 |
index 0000000..91c037d |
| 14153 |
--- /dev/null |
| 14154 |
+++ b/src/compiler/translator/TranslatorMetalDirect/RewriteOutArgs.cpp |
| 14155 |
@@ -0,0 +1,204 @@ |
| 14156 |
+// |
| 14157 |
+// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 14158 |
+// Use of this source code is governed by a BSD-style license that can be |
| 14159 |
+// found in the LICENSE file. |
| 14160 |
+// |
| 14161 |
+ |
| 14162 |
+#include "compiler/translator/TranslatorMetalDirect/RewriteOutArgs.h" |
| 14163 |
+#include "compiler/translator/tree_util/IntermRebuild.h" |
| 14164 |
+ |
| 14165 |
+using namespace sh; |
| 14166 |
+ |
| 14167 |
+namespace |
| 14168 |
+{ |
| 14169 |
+ |
| 14170 |
+template <typename T> |
| 14171 |
+class SmallMultiSet |
| 14172 |
+{ |
| 14173 |
+ public: |
| 14174 |
+ struct Entry |
| 14175 |
+ { |
| 14176 |
+ T elem; |
| 14177 |
+ size_t count; |
| 14178 |
+ }; |
| 14179 |
+ |
| 14180 |
+ const Entry *find(const T &x) const |
| 14181 |
+ { |
| 14182 |
+ for (auto &entry : mEntries) |
| 14183 |
+ { |
| 14184 |
+ if (x == entry.elem) |
| 14185 |
+ { |
| 14186 |
+ return &entry; |
| 14187 |
+ } |
| 14188 |
+ } |
| 14189 |
+ return nullptr; |
| 14190 |
+ } |
| 14191 |
+ |
| 14192 |
+ size_t multiplicity(const T &x) const |
| 14193 |
+ { |
| 14194 |
+ const Entry *entry = find(x); |
| 14195 |
+ return entry ? entry->count : 0; |
| 14196 |
+ } |
| 14197 |
+ |
| 14198 |
+ const Entry &insert(const T &x) |
| 14199 |
+ { |
| 14200 |
+ Entry *entry = findMutable(x); |
| 14201 |
+ if (entry) |
| 14202 |
+ { |
| 14203 |
+ ++entry->count; |
| 14204 |
+ return *entry; |
| 14205 |
+ } |
| 14206 |
+ else |
| 14207 |
+ { |
| 14208 |
+ mEntries.push_back({x, 1}); |
| 14209 |
+ return mEntries.back(); |
| 14210 |
+ } |
| 14211 |
+ } |
| 14212 |
+ |
| 14213 |
+ void clear() { mEntries.clear(); } |
| 14214 |
+ |
| 14215 |
+ bool empty() const { return mEntries.empty(); } |
| 14216 |
+ |
| 14217 |
+ size_t uniqueSize() const { return mEntries.size(); } |
| 14218 |
+ |
| 14219 |
+ private: |
| 14220 |
+ ANGLE_INLINE Entry *findMutable(const T &x) { return const_cast<Entry *>(find(x)); } |
| 14221 |
+ |
| 14222 |
+ private: |
| 14223 |
+ std::vector<Entry> mEntries; |
| 14224 |
+}; |
| 14225 |
+ |
| 14226 |
+const TVariable *GetVariable(TIntermNode &node) |
| 14227 |
+{ |
| 14228 |
+ TIntermTyped *tyNode = node.getAsTyped(); |
| 14229 |
+ ASSERT(tyNode); |
| 14230 |
+ if (TIntermSymbol *symbol = tyNode->getAsSymbolNode()) |
| 14231 |
+ { |
| 14232 |
+ return &symbol->variable(); |
| 14233 |
+ } |
| 14234 |
+ return nullptr; |
| 14235 |
+} |
| 14236 |
+ |
| 14237 |
+class Rewriter : public TIntermRebuild |
| 14238 |
+{ |
| 14239 |
+ SmallMultiSet<const TVariable *> mVarBuffer; // reusable buffer |
| 14240 |
+ SymbolEnv &mSymbolEnv; |
| 14241 |
+ |
| 14242 |
+ public: |
| 14243 |
+ ~Rewriter() override { ASSERT(mVarBuffer.empty()); } |
| 14244 |
+ |
| 14245 |
+ Rewriter(TCompiler &compiler, SymbolEnv &symbolEnv) |
| 14246 |
+ : TIntermRebuild(compiler, false, true), mSymbolEnv(symbolEnv) |
| 14247 |
+ {} |
| 14248 |
+ |
| 14249 |
+ PostResult visitAggregatePost(TIntermAggregate &aggregateNode) override |
| 14250 |
+ { |
| 14251 |
+ ASSERT(mVarBuffer.empty()); |
| 14252 |
+ |
| 14253 |
+ const TFunction *func = aggregateNode.getFunction(); |
| 14254 |
+ if (!func) |
| 14255 |
+ { |
| 14256 |
+ return aggregateNode; |
| 14257 |
+ } |
| 14258 |
+ |
| 14259 |
+ TIntermSequence &args = *aggregateNode.getSequence(); |
| 14260 |
+ size_t argCount = args.size(); |
| 14261 |
+ |
| 14262 |
+ auto getParamQualifier = [&](size_t i) { |
| 14263 |
+ const TVariable ¶m = *func->getParam(i); |
| 14264 |
+ const TType ¶mType = param.getType(); |
| 14265 |
+ const TQualifier paramQual = paramType.getQualifier(); |
| 14266 |
+ switch (paramQual) |
| 14267 |
+ { |
| 14268 |
+ case TQualifier::EvqOut: |
| 14269 |
+ case TQualifier::EvqInOut: |
| 14270 |
+ if (!mSymbolEnv.isReference(param)) |
| 14271 |
+ { |
| 14272 |
+ mSymbolEnv.markAsReference(param, AddressSpace::Thread); |
| 14273 |
+ } |
| 14274 |
+ break; |
| 14275 |
+ default: |
| 14276 |
+ break; |
| 14277 |
+ } |
| 14278 |
+ return paramQual; |
| 14279 |
+ }; |
| 14280 |
+ |
| 14281 |
+ bool mightAlias = false; |
| 14282 |
+ |
| 14283 |
+ for (size_t i = 0; i < argCount; ++i) |
| 14284 |
+ { |
| 14285 |
+ const TQualifier paramQual = getParamQualifier(i); |
| 14286 |
+ |
| 14287 |
+ switch (paramQual) |
| 14288 |
+ { |
| 14289 |
+ case TQualifier::EvqOut: |
| 14290 |
+ case TQualifier::EvqInOut: |
| 14291 |
+ { |
| 14292 |
+ const TVariable *var = GetVariable(*args[i]); |
| 14293 |
+ if (mVarBuffer.insert(var).count > 1) |
| 14294 |
+ { |
| 14295 |
+ mightAlias = true; |
| 14296 |
+ i = argCount; |
| 14297 |
+ } |
| 14298 |
+ } |
| 14299 |
+ break; |
| 14300 |
+ |
| 14301 |
+ default: |
| 14302 |
+ break; |
| 14303 |
+ } |
| 14304 |
+ } |
| 14305 |
+ |
| 14306 |
+ const bool hasIndeterminateVar = mVarBuffer.find(nullptr); |
| 14307 |
+ |
| 14308 |
+ if (!mightAlias) |
| 14309 |
+ { |
| 14310 |
+ mightAlias = hasIndeterminateVar && mVarBuffer.uniqueSize() > 1; |
| 14311 |
+ } |
| 14312 |
+ |
| 14313 |
+ if (mightAlias) |
| 14314 |
+ { |
| 14315 |
+ for (size_t i = 0; i < argCount; ++i) |
| 14316 |
+ { |
| 14317 |
+ TIntermTyped *arg = args[i]->getAsTyped(); |
| 14318 |
+ ASSERT(arg); |
| 14319 |
+ const TVariable *var = GetVariable(*arg); |
| 14320 |
+ const TQualifier paramQual = getParamQualifier(i); |
| 14321 |
+ |
| 14322 |
+ if (hasIndeterminateVar || mVarBuffer.multiplicity(var) > 1) |
| 14323 |
+ { |
| 14324 |
+ switch (paramQual) |
| 14325 |
+ { |
| 14326 |
+ case TQualifier::EvqOut: |
| 14327 |
+ args[i] = &mSymbolEnv.callFunctionOverload(Name("out"), arg->getType(), |
| 14328 |
+ *new TIntermSequence{arg}); |
| 14329 |
+ break; |
| 14330 |
+ |
| 14331 |
+ case TQualifier::EvqInOut: |
| 14332 |
+ args[i] = &mSymbolEnv.callFunctionOverload( |
| 14333 |
+ Name("inout"), arg->getType(), *new TIntermSequence{arg}); |
| 14334 |
+ break; |
| 14335 |
+ |
| 14336 |
+ default: |
| 14337 |
+ break; |
| 14338 |
+ } |
| 14339 |
+ } |
| 14340 |
+ } |
| 14341 |
+ } |
| 14342 |
+ |
| 14343 |
+ mVarBuffer.clear(); |
| 14344 |
+ |
| 14345 |
+ return aggregateNode; |
| 14346 |
+ } |
| 14347 |
+}; |
| 14348 |
+ |
| 14349 |
+} // anonymous namespace |
| 14350 |
+ |
| 14351 |
+bool sh::RewriteOutArgs(TCompiler &compiler, TIntermBlock &root, SymbolEnv &symbolEnv) |
| 14352 |
+{ |
| 14353 |
+ Rewriter rewriter(compiler, symbolEnv); |
| 14354 |
+ if (!rewriter.rebuildRoot(root)) |
| 14355 |
+ { |
| 14356 |
+ return false; |
| 14357 |
+ } |
| 14358 |
+ return true; |
| 14359 |
+} |
| 14360 |
diff --git a/src/compiler/translator/TranslatorMetalDirect/RewriteOutArgs.h b/src/compiler/translator/TranslatorMetalDirect/RewriteOutArgs.h |
| 14361 |
new file mode 100644 |
| 14362 |
index 0000000..982b747 |
| 14363 |
--- /dev/null |
| 14364 |
+++ b/src/compiler/translator/TranslatorMetalDirect/RewriteOutArgs.h |
| 14365 |
@@ -0,0 +1,33 @@ |
| 14366 |
+// |
| 14367 |
+// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 14368 |
+// Use of this source code is governed by a BSD-style license that can be |
| 14369 |
+// found in the LICENSE file. |
| 14370 |
+// |
| 14371 |
+ |
| 14372 |
+#ifndef COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_REWRITEOUTARGS_H_ |
| 14373 |
+#define COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_REWRITEOUTARGS_H_ |
| 14374 |
+ |
| 14375 |
+#include "compiler/translator/Compiler.h" |
| 14376 |
+#include "compiler/translator/TranslatorMetalDirect/ProgramPrelude.h" |
| 14377 |
+#include "compiler/translator/TranslatorMetalDirect/SymbolEnv.h" |
| 14378 |
+ |
| 14379 |
+namespace sh |
| 14380 |
+{ |
| 14381 |
+ |
| 14382 |
+// e.g.: |
| 14383 |
+// /*void foo(out int x, inout int y)*/ |
| 14384 |
+// foo(z, w); |
| 14385 |
+// becomes |
| 14386 |
+// foo(Out(z), InOut(w)); |
| 14387 |
+// unless `z` and `w` are detected to never alias. |
| 14388 |
+// The translated example effectively behaves the same as: |
| 14389 |
+// int _1; |
| 14390 |
+// int _2 = w; |
| 14391 |
+// foo(_1, _2); |
| 14392 |
+// z = _1; |
| 14393 |
+// w = _2; |
| 14394 |
+ANGLE_NO_DISCARD bool RewriteOutArgs(TCompiler &compiler, TIntermBlock &root, SymbolEnv &symbolEnv); |
| 14395 |
+ |
| 14396 |
+} // namespace sh |
| 14397 |
+ |
| 14398 |
+#endif // COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_REWRITEOUTARGS_H_ |
| 14399 |
diff --git a/src/compiler/translator/TranslatorMetalDirect/RewritePipelines.cpp b/src/compiler/translator/TranslatorMetalDirect/RewritePipelines.cpp |
| 14400 |
new file mode 100644 |
| 14401 |
index 0000000..3637e23 |
| 14402 |
--- /dev/null |
| 14403 |
+++ b/src/compiler/translator/TranslatorMetalDirect/RewritePipelines.cpp |
| 14404 |
@@ -0,0 +1,938 @@ |
| 14405 |
+// |
| 14406 |
+// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 14407 |
+// Use of this source code is governed by a BSD-style license that can be |
| 14408 |
+// found in the LICENSE file. |
| 14409 |
+// |
| 14410 |
+ |
| 14411 |
+#include <cstring> |
| 14412 |
+#include <unordered_map> |
| 14413 |
+#include <unordered_set> |
| 14414 |
+ |
| 14415 |
+#include "compiler/translator/TranslatorMetalDirect.h" |
| 14416 |
+#include "compiler/translator/TranslatorMetalDirect/AstHelpers.h" |
| 14417 |
+#include "compiler/translator/TranslatorMetalDirect/DiscoverDependentFunctions.h" |
| 14418 |
+#include "compiler/translator/TranslatorMetalDirect/IdGen.h" |
| 14419 |
+#include "compiler/translator/TranslatorMetalDirect/MapSymbols.h" |
| 14420 |
+#include "compiler/translator/TranslatorMetalDirect/Pipeline.h" |
| 14421 |
+#include "compiler/translator/TranslatorMetalDirect/RewritePipelines.h" |
| 14422 |
+#include "compiler/translator/tree_ops/PruneNoOps.h" |
| 14423 |
+#include "compiler/translator/tree_util/FindMain.h" |
| 14424 |
+#include "compiler/translator/tree_util/IntermRebuild.h" |
| 14425 |
+#include "compiler/translator/tree_util/IntermTraverse.h" |
| 14426 |
+ |
| 14427 |
+using namespace sh; |
| 14428 |
+ |
| 14429 |
+//////////////////////////////////////////////////////////////////////////////// |
| 14430 |
+ |
| 14431 |
+namespace |
| 14432 |
+{ |
| 14433 |
+ |
| 14434 |
+using VariableSet = std::unordered_set<const TVariable *>; |
| 14435 |
+using VariableList = std::vector<const TVariable *>; |
| 14436 |
+ |
| 14437 |
+//////////////////////////////////////////////////////////////////////////////// |
| 14438 |
+ |
| 14439 |
+struct PipelineStructInfo |
| 14440 |
+{ |
| 14441 |
+ VariableSet pipelineVariables; |
| 14442 |
+ PipelineScoped<TStructure> pipelineStruct; |
| 14443 |
+ const TFunction *funcOriginalToModified = nullptr; |
| 14444 |
+ const TFunction *funcModifiedToOriginal = nullptr; |
| 14445 |
+ |
| 14446 |
+ bool isEmpty() const |
| 14447 |
+ { |
| 14448 |
+ if (pipelineStruct.isTotallyEmpty()) |
| 14449 |
+ { |
| 14450 |
+ ASSERT(pipelineVariables.empty()); |
| 14451 |
+ return true; |
| 14452 |
+ } |
| 14453 |
+ else |
| 14454 |
+ { |
| 14455 |
+ ASSERT(pipelineStruct.isTotallyFull()); |
| 14456 |
+ ASSERT(!pipelineVariables.empty()); |
| 14457 |
+ return false; |
| 14458 |
+ } |
| 14459 |
+ } |
| 14460 |
+}; |
| 14461 |
+ |
| 14462 |
+class GeneratePipelineStruct : private TIntermRebuild |
| 14463 |
+{ |
| 14464 |
+ private: |
| 14465 |
+ const Pipeline &mPipeline; |
| 14466 |
+ SymbolEnv &mSymbolEnv; |
| 14467 |
+ Invariants &mInvariants; |
| 14468 |
+ VariableList mPipelineVariableList; |
| 14469 |
+ IdGen &mIdGen; |
| 14470 |
+ PipelineStructInfo mInfo; |
| 14471 |
+ |
| 14472 |
+ public: |
| 14473 |
+ static bool Exec(PipelineStructInfo &out, |
| 14474 |
+ TCompiler &compiler, |
| 14475 |
+ TIntermBlock &root, |
| 14476 |
+ IdGen &idGen, |
| 14477 |
+ const Pipeline &pipeline, |
| 14478 |
+ SymbolEnv &symbolEnv, |
| 14479 |
+ Invariants &invariants) |
| 14480 |
+ { |
| 14481 |
+ GeneratePipelineStruct self(compiler, idGen, pipeline, symbolEnv, invariants); |
| 14482 |
+ if (!self.exec(root)) |
| 14483 |
+ { |
| 14484 |
+ return false; |
| 14485 |
+ } |
| 14486 |
+ out = self.mInfo; |
| 14487 |
+ return true; |
| 14488 |
+ } |
| 14489 |
+ |
| 14490 |
+ private: |
| 14491 |
+ GeneratePipelineStruct(TCompiler &compiler, |
| 14492 |
+ IdGen &idGen, |
| 14493 |
+ const Pipeline &pipeline, |
| 14494 |
+ SymbolEnv &symbolEnv, |
| 14495 |
+ Invariants &invariants) |
| 14496 |
+ : TIntermRebuild(compiler, true, true), |
| 14497 |
+ mPipeline(pipeline), |
| 14498 |
+ mSymbolEnv(symbolEnv), |
| 14499 |
+ mInvariants(invariants), |
| 14500 |
+ mIdGen(idGen) |
| 14501 |
+ {} |
| 14502 |
+ |
| 14503 |
+ bool exec(TIntermBlock &root) |
| 14504 |
+ { |
| 14505 |
+ if (!rebuildRoot(root)) |
| 14506 |
+ { |
| 14507 |
+ return false; |
| 14508 |
+ } |
| 14509 |
+ |
| 14510 |
+ if (mInfo.pipelineVariables.empty()) |
| 14511 |
+ { |
| 14512 |
+ return true; |
| 14513 |
+ } |
| 14514 |
+ |
| 14515 |
+ TIntermSequence seq; |
| 14516 |
+ |
| 14517 |
+ const TStructure &pipelineStruct = [&]() -> const TStructure & { |
| 14518 |
+ if (mPipeline.globalInstanceVar) |
| 14519 |
+ { |
| 14520 |
+ return *mPipeline.globalInstanceVar->getType().getStruct(); |
| 14521 |
+ } |
| 14522 |
+ else |
| 14523 |
+ { |
| 14524 |
+ return createInternalPipelineStruct(root, seq); |
| 14525 |
+ } |
| 14526 |
+ }(); |
| 14527 |
+ |
| 14528 |
+ ModifiedStructMachineries modifiedMachineries; |
| 14529 |
+ const bool modified = TryCreateModifiedStruct( |
| 14530 |
+ mSymbolEnv, mIdGen, mPipeline.externalStructModifyConfig(), pipelineStruct, |
| 14531 |
+ mPipeline.getStructTypeName(Pipeline::Variant::Modified), modifiedMachineries); |
| 14532 |
+ |
| 14533 |
+ if (modified) |
| 14534 |
+ { |
| 14535 |
+ ASSERT(mPipeline.type != Pipeline::Type::Texture); |
| 14536 |
+ ASSERT(!mPipeline.globalInstanceVar); // This shouldn't happen by construction. |
| 14537 |
+ |
| 14538 |
+ auto getFunction = [](sh::TIntermFunctionDefinition *funcDecl) { |
| 14539 |
+ return funcDecl ? funcDecl->getFunction() : nullptr; |
| 14540 |
+ }; |
| 14541 |
+ |
| 14542 |
+ const size_t size = modifiedMachineries.size(); |
| 14543 |
+ ASSERT(size > 0); |
| 14544 |
+ for (size_t i = 0; i < size; ++i) |
| 14545 |
+ { |
| 14546 |
+ const ModifiedStructMachinery &machinery = modifiedMachineries.at(i); |
| 14547 |
+ ASSERT(machinery.modifiedStruct); |
| 14548 |
+ |
| 14549 |
+ seq.push_back(new TIntermDeclaration{ |
| 14550 |
+ &CreateStructTypeVariable(mSymbolTable, *machinery.modifiedStruct)}); |
| 14551 |
+ |
| 14552 |
+ if (mPipeline.isPipelineOut()) |
| 14553 |
+ { |
| 14554 |
+ ASSERT(machinery.funcOriginalToModified); |
| 14555 |
+ ASSERT(!machinery.funcModifiedToOriginal); |
| 14556 |
+ seq.push_back(machinery.funcOriginalToModified); |
| 14557 |
+ } |
| 14558 |
+ else |
| 14559 |
+ { |
| 14560 |
+ ASSERT(machinery.funcModifiedToOriginal); |
| 14561 |
+ ASSERT(!machinery.funcOriginalToModified); |
| 14562 |
+ seq.push_back(machinery.funcModifiedToOriginal); |
| 14563 |
+ } |
| 14564 |
+ |
| 14565 |
+ if (i == size - 1) |
| 14566 |
+ { |
| 14567 |
+ mInfo.funcOriginalToModified = getFunction(machinery.funcOriginalToModified); |
| 14568 |
+ mInfo.funcModifiedToOriginal = getFunction(machinery.funcModifiedToOriginal); |
| 14569 |
+ |
| 14570 |
+ mInfo.pipelineStruct.internal = &pipelineStruct; |
| 14571 |
+ mInfo.pipelineStruct.external = |
| 14572 |
+ modified ? machinery.modifiedStruct : &pipelineStruct; |
| 14573 |
+ } |
| 14574 |
+ } |
| 14575 |
+ } |
| 14576 |
+ else |
| 14577 |
+ { |
| 14578 |
+ mInfo.pipelineStruct.internal = &pipelineStruct; |
| 14579 |
+ mInfo.pipelineStruct.external = &pipelineStruct; |
| 14580 |
+ } |
| 14581 |
+ |
| 14582 |
+ root.insertChildNodes(FindMainIndex(&root), seq); |
| 14583 |
+ |
| 14584 |
+ return true; |
| 14585 |
+ } |
| 14586 |
+ |
| 14587 |
+ private: |
| 14588 |
+ PreResult visitFunctionDefinitionPre(TIntermFunctionDefinition &node) override |
| 14589 |
+ { |
| 14590 |
+ return {node, VisitBits::Neither}; |
| 14591 |
+ } |
| 14592 |
+ |
| 14593 |
+ PostResult visitDeclarationPost(TIntermDeclaration &declNode) override |
| 14594 |
+ { |
| 14595 |
+ Declaration decl = ViewDeclaration(declNode); |
| 14596 |
+ const TVariable &var = decl.symbol.variable(); |
| 14597 |
+ |
| 14598 |
+ if (mPipeline.uses(var)) |
| 14599 |
+ { |
| 14600 |
+ ASSERT(mInfo.pipelineVariables.find(&var) == mInfo.pipelineVariables.end()); |
| 14601 |
+ mInfo.pipelineVariables.insert(&var); |
| 14602 |
+ mPipelineVariableList.push_back(&var); |
| 14603 |
+ return nullptr; |
| 14604 |
+ } |
| 14605 |
+ |
| 14606 |
+ return declNode; |
| 14607 |
+ } |
| 14608 |
+ |
| 14609 |
+ const TStructure &createInternalPipelineStruct(TIntermBlock &root, TIntermSequence &outDeclSeq) |
| 14610 |
+ { |
| 14611 |
+ auto &fields = *new TFieldList(); |
| 14612 |
+ |
| 14613 |
+ switch (mPipeline.type) |
| 14614 |
+ { |
| 14615 |
+ case Pipeline::Type::Texture: |
| 14616 |
+ { |
| 14617 |
+ for (const TVariable *var : mPipelineVariableList) |
| 14618 |
+ { |
| 14619 |
+ ASSERT(!mInvariants.contains(*var)); |
| 14620 |
+ const TType &varType = var->getType(); |
| 14621 |
+ const TBasicType samplerType = varType.getBasicType(); |
| 14622 |
+ |
| 14623 |
+ const TStructure &textureEnv = mSymbolEnv.getTextureEnv(samplerType); |
| 14624 |
+ auto *textureEnvType = new TType(&textureEnv, false); |
| 14625 |
+ if (varType.isArray()) |
| 14626 |
+ { |
| 14627 |
+ textureEnvType->makeArrays(varType.getArraySizes()); |
| 14628 |
+ } |
| 14629 |
+ |
| 14630 |
+ fields.push_back( |
| 14631 |
+ new TField(textureEnvType, var->name(), kNoSourceLoc, var->symbolType())); |
| 14632 |
+ } |
| 14633 |
+ } |
| 14634 |
+ break; |
| 14635 |
+ |
| 14636 |
+ default: |
| 14637 |
+ { |
| 14638 |
+ for (const TVariable *var : mPipelineVariableList) |
| 14639 |
+ { |
| 14640 |
+ auto &type = CloneType(var->getType()); |
| 14641 |
+ auto *field = new TField(&type, var->name(), kNoSourceLoc, var->symbolType()); |
| 14642 |
+ fields.push_back(field); |
| 14643 |
+ |
| 14644 |
+ if (mInvariants.contains(*var)) |
| 14645 |
+ { |
| 14646 |
+ mInvariants.insert(*field); |
| 14647 |
+ } |
| 14648 |
+ } |
| 14649 |
+ } |
| 14650 |
+ break; |
| 14651 |
+ } |
| 14652 |
+ |
| 14653 |
+ Name pipelineStructName = mPipeline.getStructTypeName(Pipeline::Variant::Original); |
| 14654 |
+ auto &s = *new TStructure(&mSymbolTable, pipelineStructName.rawName(), &fields, |
| 14655 |
+ pipelineStructName.symbolType()); |
| 14656 |
+ |
| 14657 |
+ outDeclSeq.push_back(new TIntermDeclaration{&CreateStructTypeVariable(mSymbolTable, s)}); |
| 14658 |
+ |
| 14659 |
+ return s; |
| 14660 |
+ } |
| 14661 |
+}; |
| 14662 |
+ |
| 14663 |
+//////////////////////////////////////////////////////////////////////////////// |
| 14664 |
+ |
| 14665 |
+PipelineScoped<TVariable> CreatePipelineMainLocalVar(TSymbolTable &symbolTable, |
| 14666 |
+ const Pipeline &pipeline, |
| 14667 |
+ PipelineScoped<TStructure> pipelineStruct) |
| 14668 |
+{ |
| 14669 |
+ ASSERT(pipelineStruct.isTotallyFull()); |
| 14670 |
+ |
| 14671 |
+ PipelineScoped<TVariable> pipelineMainLocalVar; |
| 14672 |
+ |
| 14673 |
+ auto populateExternalMainLocalVar = [&]() { |
| 14674 |
+ ASSERT(!pipelineMainLocalVar.external); |
| 14675 |
+ pipelineMainLocalVar.external = &CreateInstanceVariable( |
| 14676 |
+ symbolTable, *pipelineStruct.external, |
| 14677 |
+ pipeline.getStructInstanceName(pipelineStruct.isUniform() |
| 14678 |
+ ? Pipeline::Variant::Original |
| 14679 |
+ : Pipeline::Variant::Modified)); |
| 14680 |
+ }; |
| 14681 |
+ |
| 14682 |
+ auto populateDistinctInternalMainLocalVar = [&]() { |
| 14683 |
+ ASSERT(!pipelineMainLocalVar.internal); |
| 14684 |
+ pipelineMainLocalVar.internal = |
| 14685 |
+ &CreateInstanceVariable(symbolTable, *pipelineStruct.internal, |
| 14686 |
+ pipeline.getStructInstanceName(Pipeline::Variant::Original)); |
| 14687 |
+ }; |
| 14688 |
+ |
| 14689 |
+ if (pipeline.type == Pipeline::Type::InstanceId) |
| 14690 |
+ { |
| 14691 |
+ populateDistinctInternalMainLocalVar(); |
| 14692 |
+ } |
| 14693 |
+ else if (pipeline.alwaysRequiresLocalVariableDeclarationInMain()) |
| 14694 |
+ { |
| 14695 |
+ populateExternalMainLocalVar(); |
| 14696 |
+ |
| 14697 |
+ if (pipelineStruct.isUniform()) |
| 14698 |
+ { |
| 14699 |
+ pipelineMainLocalVar.internal = pipelineMainLocalVar.external; |
| 14700 |
+ } |
| 14701 |
+ else |
| 14702 |
+ { |
| 14703 |
+ populateDistinctInternalMainLocalVar(); |
| 14704 |
+ } |
| 14705 |
+ } |
| 14706 |
+ else if (!pipelineStruct.isUniform()) |
| 14707 |
+ { |
| 14708 |
+ populateDistinctInternalMainLocalVar(); |
| 14709 |
+ } |
| 14710 |
+ |
| 14711 |
+ return pipelineMainLocalVar; |
| 14712 |
+} |
| 14713 |
+ |
| 14714 |
+class PipelineFunctionEnv |
| 14715 |
+{ |
| 14716 |
+ private: |
| 14717 |
+ TCompiler &mCompiler; |
| 14718 |
+ SymbolEnv &mSymbolEnv; |
| 14719 |
+ TSymbolTable &mSymbolTable; |
| 14720 |
+ IdGen &mIdGen; |
| 14721 |
+ const Pipeline &mPipeline; |
| 14722 |
+ const std::unordered_set<const TFunction *> &mPipelineFunctions; |
| 14723 |
+ const PipelineScoped<TStructure> mPipelineStruct; |
| 14724 |
+ PipelineScoped<TVariable> &mPipelineMainLocalVar; |
| 14725 |
+ |
| 14726 |
+ std::unordered_map<const TFunction *, const TFunction *> mFuncMap; |
| 14727 |
+ |
| 14728 |
+ public: |
| 14729 |
+ PipelineFunctionEnv(TCompiler &compiler, |
| 14730 |
+ SymbolEnv &symbolEnv, |
| 14731 |
+ IdGen &idGen, |
| 14732 |
+ const Pipeline &pipeline, |
| 14733 |
+ const std::unordered_set<const TFunction *> &pipelineFunctions, |
| 14734 |
+ PipelineScoped<TStructure> pipelineStruct, |
| 14735 |
+ PipelineScoped<TVariable> &pipelineMainLocalVar) |
| 14736 |
+ : mCompiler(compiler), |
| 14737 |
+ mSymbolEnv(symbolEnv), |
| 14738 |
+ mSymbolTable(symbolEnv.symbolTable()), |
| 14739 |
+ mIdGen(idGen), |
| 14740 |
+ mPipeline(pipeline), |
| 14741 |
+ mPipelineFunctions(pipelineFunctions), |
| 14742 |
+ mPipelineStruct(pipelineStruct), |
| 14743 |
+ mPipelineMainLocalVar(pipelineMainLocalVar) |
| 14744 |
+ {} |
| 14745 |
+ |
| 14746 |
+ bool isOriginalPipelineFunction(const TFunction &func) const |
| 14747 |
+ { |
| 14748 |
+ return mPipelineFunctions.find(&func) != mPipelineFunctions.end(); |
| 14749 |
+ } |
| 14750 |
+ |
| 14751 |
+ bool isUpdatedPipelineFunction(const TFunction &func) const |
| 14752 |
+ { |
| 14753 |
+ auto it = mFuncMap.find(&func); |
| 14754 |
+ if (it == mFuncMap.end()) |
| 14755 |
+ { |
| 14756 |
+ return false; |
| 14757 |
+ } |
| 14758 |
+ return &func == it->second; |
| 14759 |
+ } |
| 14760 |
+ |
| 14761 |
+ const TFunction &getUpdatedFunction(const TFunction &func) |
| 14762 |
+ { |
| 14763 |
+ ASSERT(isOriginalPipelineFunction(func) || isUpdatedPipelineFunction(func)); |
| 14764 |
+ |
| 14765 |
+ const TFunction *newFunc; |
| 14766 |
+ |
| 14767 |
+ auto it = mFuncMap.find(&func); |
| 14768 |
+ if (it == mFuncMap.end()) |
| 14769 |
+ { |
| 14770 |
+ const bool isMain = func.isMain(); |
| 14771 |
+ |
| 14772 |
+ if (isMain && mPipeline.isPipelineOut()) |
| 14773 |
+ { |
| 14774 |
+ ASSERT(func.getReturnType().getBasicType() == TBasicType::EbtVoid); |
| 14775 |
+ newFunc = &CloneFunctionAndChangeReturnType(mSymbolTable, nullptr, func, |
| 14776 |
+ *mPipelineStruct.external); |
| 14777 |
+ } |
| 14778 |
+ else if (isMain && (mPipeline.type == Pipeline::Type::InvocationVertexGlobals || |
| 14779 |
+ mPipeline.type == Pipeline::Type::InvocationFragmentGlobals)) |
| 14780 |
+ { |
| 14781 |
+ std::vector<const TVariable *> variables; |
| 14782 |
+ for (const TField *field : mPipelineStruct.external->fields()) |
| 14783 |
+ { |
| 14784 |
+ variables.push_back(new TVariable(&mSymbolTable, field->name(), field->type(), |
| 14785 |
+ field->symbolType())); |
| 14786 |
+ } |
| 14787 |
+ newFunc = &CloneFunctionAndAppendParams(mSymbolTable, nullptr, func, variables); |
| 14788 |
+ } |
| 14789 |
+ else if (isMain && mPipeline.type == Pipeline::Type::Texture) |
| 14790 |
+ { |
| 14791 |
+ std::vector<const TVariable *> variables; |
| 14792 |
+ TranslatorMetalReflection *reflection = |
| 14793 |
+ ((sh::TranslatorMetalDirect *)&mCompiler)->getTranslatorMetalReflection(); |
| 14794 |
+ for (const TField *field : mPipelineStruct.external->fields()) |
| 14795 |
+ { |
| 14796 |
+ const TStructure *textureEnv = field->type()->getStruct(); |
| 14797 |
+ ASSERT(textureEnv && textureEnv->fields().size() == 2); |
| 14798 |
+ for (const TField *subfield : textureEnv->fields()) |
| 14799 |
+ { |
| 14800 |
+ const Name name = mIdGen.createNewName({field->name(), subfield->name()}); |
| 14801 |
+ TType &type = *new TType(*subfield->type()); |
| 14802 |
+ ASSERT(!type.isArray()); |
| 14803 |
+ type.makeArrays(field->type()->getArraySizes()); |
| 14804 |
+ auto *var = |
| 14805 |
+ new TVariable(&mSymbolTable, name.rawName(), &type, name.symbolType()); |
| 14806 |
+ variables.push_back(var); |
| 14807 |
+ reflection->addOriginalName(var->uniqueId().get(), field->name().data()); |
| 14808 |
+ } |
| 14809 |
+ } |
| 14810 |
+ newFunc = &CloneFunctionAndAppendParams(mSymbolTable, nullptr, func, variables); |
| 14811 |
+ } |
| 14812 |
+ else if (isMain && mPipeline.type == Pipeline::Type::InstanceId) |
| 14813 |
+ { |
| 14814 |
+ Name name = mPipeline.getStructInstanceName(Pipeline::Variant::Modified); |
| 14815 |
+ auto *var = new TVariable(&mSymbolTable, name.rawName(), |
| 14816 |
+ new TType(TBasicType::EbtUInt), name.symbolType()); |
| 14817 |
+ newFunc = &CloneFunctionAndPrependParam(mSymbolTable, nullptr, func, *var); |
| 14818 |
+ mSymbolEnv.markAsReference(*var, mPipeline.externalAddressSpace()); |
| 14819 |
+ mPipelineMainLocalVar.external = var; |
| 14820 |
+ } |
| 14821 |
+ else if (isMain && mPipeline.alwaysRequiresLocalVariableDeclarationInMain()) |
| 14822 |
+ { |
| 14823 |
+ ASSERT(mPipelineMainLocalVar.isTotallyFull()); |
| 14824 |
+ newFunc = &func; |
| 14825 |
+ } |
| 14826 |
+ else |
| 14827 |
+ { |
| 14828 |
+ const TVariable *var; |
| 14829 |
+ AddressSpace addressSpace; |
| 14830 |
+ |
| 14831 |
+ if (isMain && !mPipelineMainLocalVar.isUniform()) |
| 14832 |
+ { |
| 14833 |
+ var = &CreateInstanceVariable( |
| 14834 |
+ mSymbolTable, *mPipelineStruct.external, |
| 14835 |
+ mPipeline.getStructInstanceName(Pipeline::Variant::Modified)); |
| 14836 |
+ addressSpace = mPipeline.externalAddressSpace(); |
| 14837 |
+ } |
| 14838 |
+ else |
| 14839 |
+ { |
| 14840 |
+ var = &CreateInstanceVariable( |
| 14841 |
+ mSymbolTable, *mPipelineStruct.internal, |
| 14842 |
+ mPipeline.getStructInstanceName(Pipeline::Variant::Original)); |
| 14843 |
+ addressSpace = mPipelineMainLocalVar.isUniform() |
| 14844 |
+ ? mPipeline.externalAddressSpace() |
| 14845 |
+ : AddressSpace::Thread; |
| 14846 |
+ } |
| 14847 |
+ |
| 14848 |
+ bool markAsReference = true; |
| 14849 |
+ if (isMain) |
| 14850 |
+ { |
| 14851 |
+ switch (mPipeline.type) |
| 14852 |
+ { |
| 14853 |
+ case Pipeline::Type::VertexIn: |
| 14854 |
+ case Pipeline::Type::FragmentIn: |
| 14855 |
+ markAsReference = false; |
| 14856 |
+ break; |
| 14857 |
+ |
| 14858 |
+ default: |
| 14859 |
+ break; |
| 14860 |
+ } |
| 14861 |
+ } |
| 14862 |
+ |
| 14863 |
+ if (markAsReference) |
| 14864 |
+ { |
| 14865 |
+ mSymbolEnv.markAsReference(*var, addressSpace); |
| 14866 |
+ } |
| 14867 |
+ |
| 14868 |
+ newFunc = &CloneFunctionAndPrependParam(mSymbolTable, nullptr, func, *var); |
| 14869 |
+ } |
| 14870 |
+ |
| 14871 |
+ mFuncMap[&func] = newFunc; |
| 14872 |
+ mFuncMap[newFunc] = newFunc; |
| 14873 |
+ } |
| 14874 |
+ else |
| 14875 |
+ { |
| 14876 |
+ newFunc = it->second; |
| 14877 |
+ } |
| 14878 |
+ |
| 14879 |
+ return *newFunc; |
| 14880 |
+ } |
| 14881 |
+ |
| 14882 |
+ TIntermFunctionPrototype *createUpdatedFunctionPrototype( |
| 14883 |
+ TIntermFunctionPrototype &funcProtoNode) |
| 14884 |
+ { |
| 14885 |
+ const TFunction &func = *funcProtoNode.getFunction(); |
| 14886 |
+ if (!isOriginalPipelineFunction(func) && !isUpdatedPipelineFunction(func)) |
| 14887 |
+ { |
| 14888 |
+ return nullptr; |
| 14889 |
+ } |
| 14890 |
+ const TFunction &newFunc = getUpdatedFunction(func); |
| 14891 |
+ return new TIntermFunctionPrototype(&newFunc); |
| 14892 |
+ } |
| 14893 |
+}; |
| 14894 |
+ |
| 14895 |
+class UpdatePipelineFunctions : private TIntermRebuild |
| 14896 |
+{ |
| 14897 |
+ private: |
| 14898 |
+ const Pipeline &mPipeline; |
| 14899 |
+ const PipelineScoped<TStructure> mPipelineStruct; |
| 14900 |
+ PipelineScoped<TVariable> &mPipelineMainLocalVar; |
| 14901 |
+ SymbolEnv &mSymbolEnv; |
| 14902 |
+ PipelineFunctionEnv mEnv; |
| 14903 |
+ const TFunction *mFuncOriginalToModified; |
| 14904 |
+ const TFunction *mFuncModifiedToOriginal; |
| 14905 |
+ |
| 14906 |
+ public: |
| 14907 |
+ static bool ThreadPipeline(TCompiler &compiler, |
| 14908 |
+ TIntermBlock &root, |
| 14909 |
+ const Pipeline &pipeline, |
| 14910 |
+ const std::unordered_set<const TFunction *> &pipelineFunctions, |
| 14911 |
+ PipelineScoped<TStructure> pipelineStruct, |
| 14912 |
+ PipelineScoped<TVariable> &pipelineMainLocalVar, |
| 14913 |
+ IdGen &idGen, |
| 14914 |
+ SymbolEnv &symbolEnv, |
| 14915 |
+ const TFunction *funcOriginalToModified, |
| 14916 |
+ const TFunction *funcModifiedToOriginal) |
| 14917 |
+ { |
| 14918 |
+ UpdatePipelineFunctions self(compiler, pipeline, pipelineFunctions, pipelineStruct, |
| 14919 |
+ pipelineMainLocalVar, idGen, symbolEnv, funcOriginalToModified, |
| 14920 |
+ funcModifiedToOriginal); |
| 14921 |
+ if (!self.rebuildRoot(root)) |
| 14922 |
+ { |
| 14923 |
+ return false; |
| 14924 |
+ } |
| 14925 |
+ return true; |
| 14926 |
+ } |
| 14927 |
+ |
| 14928 |
+ private: |
| 14929 |
+ UpdatePipelineFunctions(TCompiler &compiler, |
| 14930 |
+ const Pipeline &pipeline, |
| 14931 |
+ const std::unordered_set<const TFunction *> &pipelineFunctions, |
| 14932 |
+ PipelineScoped<TStructure> pipelineStruct, |
| 14933 |
+ PipelineScoped<TVariable> &pipelineMainLocalVar, |
| 14934 |
+ IdGen &idGen, |
| 14935 |
+ SymbolEnv &symbolEnv, |
| 14936 |
+ const TFunction *funcOriginalToModified, |
| 14937 |
+ const TFunction *funcModifiedToOriginal) |
| 14938 |
+ : TIntermRebuild(compiler, false, true), |
| 14939 |
+ mPipeline(pipeline), |
| 14940 |
+ mPipelineStruct(pipelineStruct), |
| 14941 |
+ mPipelineMainLocalVar(pipelineMainLocalVar), |
| 14942 |
+ mSymbolEnv(symbolEnv), |
| 14943 |
+ mEnv(compiler, |
| 14944 |
+ symbolEnv, |
| 14945 |
+ idGen, |
| 14946 |
+ pipeline, |
| 14947 |
+ pipelineFunctions, |
| 14948 |
+ pipelineStruct, |
| 14949 |
+ mPipelineMainLocalVar), |
| 14950 |
+ mFuncOriginalToModified(funcOriginalToModified), |
| 14951 |
+ mFuncModifiedToOriginal(funcModifiedToOriginal) |
| 14952 |
+ { |
| 14953 |
+ ASSERT(mPipelineStruct.isTotallyFull()); |
| 14954 |
+ } |
| 14955 |
+ |
| 14956 |
+ const TVariable &getInternalPipelineVariable(const TFunction &pipelineFunc) |
| 14957 |
+ { |
| 14958 |
+ if (pipelineFunc.isMain() && (mPipeline.alwaysRequiresLocalVariableDeclarationInMain() || |
| 14959 |
+ !mPipelineMainLocalVar.isUniform())) |
| 14960 |
+ { |
| 14961 |
+ ASSERT(mPipelineMainLocalVar.internal); |
| 14962 |
+ return *mPipelineMainLocalVar.internal; |
| 14963 |
+ } |
| 14964 |
+ else |
| 14965 |
+ { |
| 14966 |
+ ASSERT(pipelineFunc.getParamCount() > 0); |
| 14967 |
+ return *pipelineFunc.getParam(0); |
| 14968 |
+ } |
| 14969 |
+ } |
| 14970 |
+ |
| 14971 |
+ const TVariable &getExternalPipelineVariable(const TFunction &mainFunc) |
| 14972 |
+ { |
| 14973 |
+ ASSERT(mainFunc.isMain()); |
| 14974 |
+ if (mPipelineMainLocalVar.external) |
| 14975 |
+ { |
| 14976 |
+ return *mPipelineMainLocalVar.external; |
| 14977 |
+ } |
| 14978 |
+ else |
| 14979 |
+ { |
| 14980 |
+ ASSERT(mainFunc.getParamCount() > 0); |
| 14981 |
+ return *mainFunc.getParam(0); |
| 14982 |
+ } |
| 14983 |
+ } |
| 14984 |
+ |
| 14985 |
+ PostResult visitAggregatePost(TIntermAggregate &callNode) override |
| 14986 |
+ { |
| 14987 |
+ if (callNode.isConstructor()) |
| 14988 |
+ { |
| 14989 |
+ return callNode; |
| 14990 |
+ } |
| 14991 |
+ else |
| 14992 |
+ { |
| 14993 |
+ const TFunction &oldCalledFunc = *callNode.getFunction(); |
| 14994 |
+ if (!mEnv.isOriginalPipelineFunction(oldCalledFunc)) |
| 14995 |
+ { |
| 14996 |
+ return callNode; |
| 14997 |
+ } |
| 14998 |
+ const TFunction &newCalledFunc = mEnv.getUpdatedFunction(oldCalledFunc); |
| 14999 |
+ |
| 15000 |
+ const TFunction *oldOwnerFunc = getParentFunction(); |
| 15001 |
+ ASSERT(oldOwnerFunc); |
| 15002 |
+ const TFunction &newOwnerFunc = mEnv.getUpdatedFunction(*oldOwnerFunc); |
| 15003 |
+ |
| 15004 |
+ return *TIntermAggregate::CreateFunctionCall( |
| 15005 |
+ newCalledFunc, &CloneSequenceAndPrepend( |
| 15006 |
+ *callNode.getSequence(), |
| 15007 |
+ *new TIntermSymbol(&getInternalPipelineVariable(newOwnerFunc)))); |
| 15008 |
+ } |
| 15009 |
+ } |
| 15010 |
+ |
| 15011 |
+ PostResult visitFunctionPrototypePost(TIntermFunctionPrototype &funcProtoNode) override |
| 15012 |
+ { |
| 15013 |
+ TIntermFunctionPrototype *newFuncProtoNode = |
| 15014 |
+ mEnv.createUpdatedFunctionPrototype(funcProtoNode); |
| 15015 |
+ if (newFuncProtoNode == nullptr) |
| 15016 |
+ { |
| 15017 |
+ return funcProtoNode; |
| 15018 |
+ } |
| 15019 |
+ return *newFuncProtoNode; |
| 15020 |
+ } |
| 15021 |
+ |
| 15022 |
+ PostResult visitFunctionDefinitionPost(TIntermFunctionDefinition &funcDefNode) override |
| 15023 |
+ { |
| 15024 |
+ if (funcDefNode.getFunction()->isMain()) |
| 15025 |
+ { |
| 15026 |
+ return visitMain(funcDefNode); |
| 15027 |
+ } |
| 15028 |
+ else |
| 15029 |
+ { |
| 15030 |
+ return visitNonMain(funcDefNode); |
| 15031 |
+ } |
| 15032 |
+ } |
| 15033 |
+ |
| 15034 |
+ TIntermNode &visitNonMain(TIntermFunctionDefinition &funcDefNode) |
| 15035 |
+ { |
| 15036 |
+ TIntermFunctionPrototype &funcProtoNode = *funcDefNode.getFunctionPrototype(); |
| 15037 |
+ ASSERT(!funcProtoNode.getFunction()->isMain()); |
| 15038 |
+ |
| 15039 |
+ TIntermFunctionPrototype *newFuncProtoNode = |
| 15040 |
+ mEnv.createUpdatedFunctionPrototype(funcProtoNode); |
| 15041 |
+ if (newFuncProtoNode == nullptr) |
| 15042 |
+ { |
| 15043 |
+ return funcDefNode; |
| 15044 |
+ } |
| 15045 |
+ |
| 15046 |
+ const TFunction &func = *newFuncProtoNode->getFunction(); |
| 15047 |
+ ASSERT(!func.isMain()); |
| 15048 |
+ |
| 15049 |
+ TIntermBlock *body = funcDefNode.getBody(); |
| 15050 |
+ |
| 15051 |
+ return *new TIntermFunctionDefinition(newFuncProtoNode, body); |
| 15052 |
+ } |
| 15053 |
+ |
| 15054 |
+ TIntermNode &visitMain(TIntermFunctionDefinition &funcDefNode) |
| 15055 |
+ { |
| 15056 |
+ TIntermFunctionPrototype &funcProtoNode = *funcDefNode.getFunctionPrototype(); |
| 15057 |
+ ASSERT(funcProtoNode.getFunction()->isMain()); |
| 15058 |
+ |
| 15059 |
+ TIntermFunctionPrototype *newFuncProtoNode = |
| 15060 |
+ mEnv.createUpdatedFunctionPrototype(funcProtoNode); |
| 15061 |
+ if (newFuncProtoNode == nullptr) |
| 15062 |
+ { |
| 15063 |
+ return funcDefNode; |
| 15064 |
+ } |
| 15065 |
+ |
| 15066 |
+ const TFunction &func = *newFuncProtoNode->getFunction(); |
| 15067 |
+ ASSERT(func.isMain()); |
| 15068 |
+ |
| 15069 |
+ auto callModifiedToOriginal = [&](TIntermBlock &body) { |
| 15070 |
+ ASSERT(mPipelineMainLocalVar.internal); |
| 15071 |
+ if (!mPipeline.isPipelineOut()) |
| 15072 |
+ { |
| 15073 |
+ ASSERT(mFuncModifiedToOriginal); |
| 15074 |
+ auto *m = new TIntermSymbol(&getExternalPipelineVariable(func)); |
| 15075 |
+ auto *o = new TIntermSymbol(mPipelineMainLocalVar.internal); |
| 15076 |
+ body.appendStatement(TIntermAggregate::CreateFunctionCall( |
| 15077 |
+ *mFuncModifiedToOriginal, new TIntermSequence{m, o})); |
| 15078 |
+ } |
| 15079 |
+ }; |
| 15080 |
+ |
| 15081 |
+ auto callOriginalToModified = [&](TIntermBlock &body) { |
| 15082 |
+ ASSERT(mPipelineMainLocalVar.internal); |
| 15083 |
+ if (mPipeline.isPipelineOut()) |
| 15084 |
+ { |
| 15085 |
+ ASSERT(mFuncOriginalToModified); |
| 15086 |
+ auto *o = new TIntermSymbol(mPipelineMainLocalVar.internal); |
| 15087 |
+ auto *m = new TIntermSymbol(&getExternalPipelineVariable(func)); |
| 15088 |
+ body.appendStatement(TIntermAggregate::CreateFunctionCall( |
| 15089 |
+ *mFuncOriginalToModified, new TIntermSequence{o, m})); |
| 15090 |
+ } |
| 15091 |
+ }; |
| 15092 |
+ |
| 15093 |
+ TIntermBlock *body = funcDefNode.getBody(); |
| 15094 |
+ |
| 15095 |
+ if (mPipeline.alwaysRequiresLocalVariableDeclarationInMain()) |
| 15096 |
+ { |
| 15097 |
+ ASSERT(mPipelineMainLocalVar.isTotallyFull()); |
| 15098 |
+ |
| 15099 |
+ auto *newBody = new TIntermBlock(); |
| 15100 |
+ newBody->appendStatement(new TIntermDeclaration{mPipelineMainLocalVar.internal}); |
| 15101 |
+ |
| 15102 |
+ if (mPipeline.type == Pipeline::Type::InvocationVertexGlobals || |
| 15103 |
+ mPipeline.type == Pipeline::Type::InvocationFragmentGlobals) |
| 15104 |
+ { |
| 15105 |
+ // Populate struct instance with references to global pipeline variables. |
| 15106 |
+ for (const TField *field : mPipelineStruct.external->fields()) |
| 15107 |
+ { |
| 15108 |
+ auto *var = new TVariable(&mSymbolTable, field->name(), field->type(), |
| 15109 |
+ field->symbolType()); |
| 15110 |
+ auto *symbol = new TIntermSymbol(var); |
| 15111 |
+ auto &accessNode = AccessField(*mPipelineMainLocalVar.internal, var->name()); |
| 15112 |
+ auto *assignNode = new TIntermBinary(TOperator::EOpAssign, &accessNode, symbol); |
| 15113 |
+ newBody->appendStatement(assignNode); |
| 15114 |
+ } |
| 15115 |
+ } |
| 15116 |
+ else if (mPipeline.type == Pipeline::Type::Texture) |
| 15117 |
+ { |
| 15118 |
+ const TFieldList &fields = mPipelineStruct.external->fields(); |
| 15119 |
+ |
| 15120 |
+ ASSERT(func.getParamCount() >= 2 * fields.size()); |
| 15121 |
+ size_t paramIndex = func.getParamCount() - 2 * fields.size(); |
| 15122 |
+ |
| 15123 |
+ for (const TField *field : fields) |
| 15124 |
+ { |
| 15125 |
+ const TVariable &textureParam = *func.getParam(paramIndex++); |
| 15126 |
+ const TVariable &samplerParam = *func.getParam(paramIndex++); |
| 15127 |
+ |
| 15128 |
+ auto go = [&](TIntermTyped &env, const int *index) { |
| 15129 |
+ TIntermTyped &textureField = AccessField( |
| 15130 |
+ AccessIndex(*env.deepCopy(), index), ImmutableString("texture")); |
| 15131 |
+ TIntermTyped &samplerField = AccessField( |
| 15132 |
+ AccessIndex(*env.deepCopy(), index), ImmutableString("sampler")); |
| 15133 |
+ |
| 15134 |
+ auto mkAssign = [&](TIntermTyped &field, const TVariable ¶m) { |
| 15135 |
+ return new TIntermBinary(TOperator::EOpAssign, &field, |
| 15136 |
+ &mSymbolEnv.callFunctionOverload( |
| 15137 |
+ Name("addressof"), field.getType(), |
| 15138 |
+ *new TIntermSequence{&AccessIndex( |
| 15139 |
+ *new TIntermSymbol(¶m), index)})); |
| 15140 |
+ }; |
| 15141 |
+ |
| 15142 |
+ newBody->appendStatement(mkAssign(textureField, textureParam)); |
| 15143 |
+ newBody->appendStatement(mkAssign(samplerField, samplerParam)); |
| 15144 |
+ }; |
| 15145 |
+ |
| 15146 |
+ TIntermTyped &env = AccessField(*mPipelineMainLocalVar.internal, field->name()); |
| 15147 |
+ const TType &envType = env.getType(); |
| 15148 |
+ |
| 15149 |
+ if (envType.isArray()) |
| 15150 |
+ { |
| 15151 |
+ ASSERT(!envType.isArrayOfArrays()); |
| 15152 |
+ const auto n = static_cast<int>(envType.getArraySizeProduct()); |
| 15153 |
+ for (int i = 0; i < n; ++i) |
| 15154 |
+ { |
| 15155 |
+ go(env, &i); |
| 15156 |
+ } |
| 15157 |
+ } |
| 15158 |
+ else |
| 15159 |
+ { |
| 15160 |
+ go(env, nullptr); |
| 15161 |
+ } |
| 15162 |
+ } |
| 15163 |
+ } |
| 15164 |
+ else if (mPipeline.type == Pipeline::Type::InstanceId) |
| 15165 |
+ { |
| 15166 |
+ newBody->appendStatement(new TIntermBinary( |
| 15167 |
+ TOperator::EOpAssign, |
| 15168 |
+ &AccessFieldByIndex(*new TIntermSymbol(&getInternalPipelineVariable(func)), 0), |
| 15169 |
+ &AsType(mSymbolEnv, *new TType(TBasicType::EbtInt), |
| 15170 |
+ *new TIntermSymbol(&getExternalPipelineVariable(func))))); |
| 15171 |
+ } |
| 15172 |
+ else if (!mPipelineMainLocalVar.isUniform()) |
| 15173 |
+ { |
| 15174 |
+ newBody->appendStatement(new TIntermDeclaration{mPipelineMainLocalVar.external}); |
| 15175 |
+ callModifiedToOriginal(*newBody); |
| 15176 |
+ } |
| 15177 |
+ |
| 15178 |
+ newBody->appendStatement(body); |
| 15179 |
+ |
| 15180 |
+ if (!mPipelineMainLocalVar.isUniform()) |
| 15181 |
+ { |
| 15182 |
+ callOriginalToModified(*newBody); |
| 15183 |
+ } |
| 15184 |
+ |
| 15185 |
+ if (mPipeline.isPipelineOut()) |
| 15186 |
+ { |
| 15187 |
+ newBody->appendStatement(new TIntermBranch( |
| 15188 |
+ TOperator::EOpReturn, new TIntermSymbol(mPipelineMainLocalVar.external))); |
| 15189 |
+ } |
| 15190 |
+ |
| 15191 |
+ body = newBody; |
| 15192 |
+ } |
| 15193 |
+ else if (!mPipelineMainLocalVar.isUniform()) |
| 15194 |
+ { |
| 15195 |
+ ASSERT(!mPipelineMainLocalVar.external); |
| 15196 |
+ ASSERT(mPipelineMainLocalVar.internal); |
| 15197 |
+ |
| 15198 |
+ auto *newBody = new TIntermBlock(); |
| 15199 |
+ newBody->appendStatement(new TIntermDeclaration{mPipelineMainLocalVar.internal}); |
| 15200 |
+ callModifiedToOriginal(*newBody); |
| 15201 |
+ newBody->appendStatement(body); |
| 15202 |
+ callOriginalToModified(*newBody); |
| 15203 |
+ body = newBody; |
| 15204 |
+ } |
| 15205 |
+ |
| 15206 |
+ return *new TIntermFunctionDefinition(newFuncProtoNode, body); |
| 15207 |
+ } |
| 15208 |
+}; |
| 15209 |
+ |
| 15210 |
+//////////////////////////////////////////////////////////////////////////////// |
| 15211 |
+ |
| 15212 |
+bool UpdatePipelineSymbols(Pipeline::Type pipelineType, |
| 15213 |
+ TCompiler &compiler, |
| 15214 |
+ TIntermBlock &root, |
| 15215 |
+ SymbolEnv &symbolEnv, |
| 15216 |
+ const VariableSet &pipelineVariables, |
| 15217 |
+ PipelineScoped<TVariable> pipelineMainLocalVar) |
| 15218 |
+{ |
| 15219 |
+ auto map = [&](const TFunction *owner, TIntermSymbol &symbol) -> TIntermNode & { |
| 15220 |
+ const TVariable &var = symbol.variable(); |
| 15221 |
+ if (pipelineVariables.find(&var) == pipelineVariables.end()) |
| 15222 |
+ { |
| 15223 |
+ return symbol; |
| 15224 |
+ } |
| 15225 |
+ ASSERT(owner); |
| 15226 |
+ const TVariable *structInstanceVar; |
| 15227 |
+ if (owner->isMain()) |
| 15228 |
+ { |
| 15229 |
+ ASSERT(pipelineMainLocalVar.internal); |
| 15230 |
+ structInstanceVar = pipelineMainLocalVar.internal; |
| 15231 |
+ } |
| 15232 |
+ else |
| 15233 |
+ { |
| 15234 |
+ ASSERT(owner->getParamCount() > 0); |
| 15235 |
+ structInstanceVar = owner->getParam(0); |
| 15236 |
+ } |
| 15237 |
+ ASSERT(structInstanceVar); |
| 15238 |
+ return AccessField(*structInstanceVar, var.name()); |
| 15239 |
+ }; |
| 15240 |
+ return MapSymbols(compiler, root, map); |
| 15241 |
+} |
| 15242 |
+ |
| 15243 |
+//////////////////////////////////////////////////////////////////////////////// |
| 15244 |
+ |
| 15245 |
+bool RewritePipeline(TCompiler &compiler, |
| 15246 |
+ TIntermBlock &root, |
| 15247 |
+ IdGen &idGen, |
| 15248 |
+ const Pipeline &pipeline, |
| 15249 |
+ SymbolEnv &symbolEnv, |
| 15250 |
+ Invariants &invariants, |
| 15251 |
+ PipelineScoped<TStructure> &outStruct) |
| 15252 |
+{ |
| 15253 |
+ ASSERT(outStruct.isTotallyEmpty()); |
| 15254 |
+ |
| 15255 |
+ TSymbolTable &symbolTable = compiler.getSymbolTable(); |
| 15256 |
+ |
| 15257 |
+ PipelineStructInfo psi; |
| 15258 |
+ if (!GeneratePipelineStruct::Exec(psi, compiler, root, idGen, pipeline, symbolEnv, invariants)) |
| 15259 |
+ { |
| 15260 |
+ return false; |
| 15261 |
+ } |
| 15262 |
+ |
| 15263 |
+ if (psi.isEmpty()) |
| 15264 |
+ { |
| 15265 |
+ return true; |
| 15266 |
+ } |
| 15267 |
+ |
| 15268 |
+ const auto pipelineFunctions = DiscoverDependentFunctions(root, [&](const TVariable &var) { |
| 15269 |
+ return psi.pipelineVariables.find(&var) != psi.pipelineVariables.end(); |
| 15270 |
+ }); |
| 15271 |
+ |
| 15272 |
+ auto pipelineMainLocalVar = |
| 15273 |
+ CreatePipelineMainLocalVar(symbolTable, pipeline, psi.pipelineStruct); |
| 15274 |
+ |
| 15275 |
+ if (!UpdatePipelineFunctions::ThreadPipeline( |
| 15276 |
+ compiler, root, pipeline, pipelineFunctions, psi.pipelineStruct, pipelineMainLocalVar, |
| 15277 |
+ idGen, symbolEnv, psi.funcOriginalToModified, psi.funcModifiedToOriginal)) |
| 15278 |
+ { |
| 15279 |
+ return false; |
| 15280 |
+ } |
| 15281 |
+ |
| 15282 |
+ if (!pipeline.globalInstanceVar) |
| 15283 |
+ { |
| 15284 |
+ if (!UpdatePipelineSymbols(pipeline.type, compiler, root, symbolEnv, psi.pipelineVariables, |
| 15285 |
+ pipelineMainLocalVar)) |
| 15286 |
+ { |
| 15287 |
+ return false; |
| 15288 |
+ } |
| 15289 |
+ } |
| 15290 |
+ |
| 15291 |
+ if (!PruneNoOps(&compiler, &root, &compiler.getSymbolTable())) |
| 15292 |
+ { |
| 15293 |
+ return false; |
| 15294 |
+ } |
| 15295 |
+ |
| 15296 |
+ outStruct = psi.pipelineStruct; |
| 15297 |
+ return true; |
| 15298 |
+} |
| 15299 |
+ |
| 15300 |
+} // anonymous namespace |
| 15301 |
+ |
| 15302 |
+bool sh::RewritePipelines(TCompiler &compiler, |
| 15303 |
+ TIntermBlock &root, |
| 15304 |
+ IdGen &idGen, |
| 15305 |
+ const TVariable &angleUniformsGlobalInstanceVar, |
| 15306 |
+ SymbolEnv &symbolEnv, |
| 15307 |
+ Invariants &invariants, |
| 15308 |
+ PipelineStructs &outStructs) |
| 15309 |
+{ |
| 15310 |
+ struct Info |
| 15311 |
+ { |
| 15312 |
+ Pipeline::Type pipelineType; |
| 15313 |
+ PipelineScoped<TStructure> &outStruct; |
| 15314 |
+ const TVariable *globalInstanceVar; |
| 15315 |
+ }; |
| 15316 |
+ |
| 15317 |
+ Info infos[] = { |
| 15318 |
+ {Pipeline::Type::InstanceId, outStructs.instanceId, nullptr}, |
| 15319 |
+ {Pipeline::Type::Texture, outStructs.texture, nullptr}, |
| 15320 |
+ {Pipeline::Type::NonConstantGlobals, outStructs.nonConstantGlobals, nullptr}, |
| 15321 |
+ {Pipeline::Type::AngleUniforms, outStructs.angleUniforms, &angleUniformsGlobalInstanceVar}, |
| 15322 |
+ {Pipeline::Type::UserUniforms, outStructs.userUniforms, nullptr}, |
| 15323 |
+ {Pipeline::Type::VertexIn, outStructs.vertexIn, nullptr}, |
| 15324 |
+ {Pipeline::Type::VertexOut, outStructs.vertexOut, nullptr}, |
| 15325 |
+ {Pipeline::Type::FragmentIn, outStructs.fragmentIn, nullptr}, |
| 15326 |
+ {Pipeline::Type::FragmentOut, outStructs.fragmentOut, nullptr}, |
| 15327 |
+ {Pipeline::Type::InvocationVertexGlobals, outStructs.invocationVertexGlobals, nullptr}, |
| 15328 |
+ {Pipeline::Type::InvocationFragmentGlobals, outStructs.invocationFragmentGlobals, nullptr}, |
| 15329 |
+ }; |
| 15330 |
+ |
| 15331 |
+ for (Info &info : infos) |
| 15332 |
+ { |
| 15333 |
+ Pipeline pipeline{info.pipelineType, info.globalInstanceVar}; |
| 15334 |
+ if (!RewritePipeline(compiler, root, idGen, pipeline, symbolEnv, invariants, |
| 15335 |
+ info.outStruct)) |
| 15336 |
+ { |
| 15337 |
+ return false; |
| 15338 |
+ } |
| 15339 |
+ } |
| 15340 |
+ |
| 15341 |
+ return true; |
| 15342 |
+} |
| 15343 |
diff --git a/src/compiler/translator/TranslatorMetalDirect/RewritePipelines.h b/src/compiler/translator/TranslatorMetalDirect/RewritePipelines.h |
| 15344 |
new file mode 100644 |
| 15345 |
index 0000000..791ba82 |
| 15346 |
--- /dev/null |
| 15347 |
+++ b/src/compiler/translator/TranslatorMetalDirect/RewritePipelines.h |
| 15348 |
@@ -0,0 +1,45 @@ |
| 15349 |
+// |
| 15350 |
+// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 15351 |
+// Use of this source code is governed by a BSD-style license that can be |
| 15352 |
+// found in the LICENSE file. |
| 15353 |
+// |
| 15354 |
+ |
| 15355 |
+#ifndef COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_REWRITEPIPELINES_H_ |
| 15356 |
+#define COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_REWRITEPIPELINES_H_ |
| 15357 |
+ |
| 15358 |
+#include "common/angleutils.h" |
| 15359 |
+#include "compiler/translator/Compiler.h" |
| 15360 |
+#include "compiler/translator/TranslatorMetalDirect/IdGen.h" |
| 15361 |
+#include "compiler/translator/TranslatorMetalDirect/Pipeline.h" |
| 15362 |
+#include "compiler/translator/TranslatorMetalDirect/RewriteGlobalQualifierDecls.h" |
| 15363 |
+#include "compiler/translator/TranslatorMetalDirect/SymbolEnv.h" |
| 15364 |
+ |
| 15365 |
+namespace sh |
| 15366 |
+{ |
| 15367 |
+ |
| 15368 |
+// This rewrites all pipelines. |
| 15369 |
+// |
| 15370 |
+// For each pipeline: |
| 15371 |
+// - Discover all variables that are used by the pipeline |
| 15372 |
+// - Move the variables into an internal pipeline struct instance and update old variables to be |
| 15373 |
+// member access instead. |
| 15374 |
+// - Dependency inject the internal pipeline struct to all functions that access variables from |
| 15375 |
+// the struct. |
| 15376 |
+// - A new external pipeline struct is created if needed for impedance reasons. Otherwise the |
| 15377 |
+// external and internal pipeline structs are the same. |
| 15378 |
+// - Add `main` parameter or return value for the external pipeline struct as needed. |
| 15379 |
+// - Inside `main`, map the external struct to the internal struct if they differ and is provided |
| 15380 |
+// as a parameter to `main`. |
| 15381 |
+// - Inside `main`, map the internal struct to the external struct if they differ and is returned |
| 15382 |
+// from `main`. |
| 15383 |
+ANGLE_NO_DISCARD bool RewritePipelines(TCompiler &compiler, |
| 15384 |
+ TIntermBlock &root, |
| 15385 |
+ IdGen &idGen, |
| 15386 |
+ const TVariable &angleUniformsGlobalInstanceVar, |
| 15387 |
+ SymbolEnv &symbolEnv, |
| 15388 |
+ Invariants &invariants, |
| 15389 |
+ PipelineStructs &outStructs); |
| 15390 |
+ |
| 15391 |
+} // namespace sh |
| 15392 |
+ |
| 15393 |
+#endif // COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_REWRITEPIPELINES_H_ |
| 15394 |
diff --git a/src/compiler/translator/TranslatorMetalDirect/RewriteUnaddressableReferences.cpp b/src/compiler/translator/TranslatorMetalDirect/RewriteUnaddressableReferences.cpp |
| 15395 |
new file mode 100644 |
| 15396 |
index 0000000..e77c1a5 |
| 15397 |
--- /dev/null |
| 15398 |
+++ b/src/compiler/translator/TranslatorMetalDirect/RewriteUnaddressableReferences.cpp |
| 15399 |
@@ -0,0 +1,376 @@ |
| 15400 |
+// |
| 15401 |
+// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 15402 |
+// Use of this source code is governed by a BSD-style license that can be |
| 15403 |
+// found in the LICENSE file. |
| 15404 |
+// |
| 15405 |
+ |
| 15406 |
+#include "compiler/translator/TranslatorMetalDirect/RewriteUnaddressableReferences.h" |
| 15407 |
+#include "compiler/translator/TranslatorMetalDirect/AstHelpers.h" |
| 15408 |
+#include "compiler/translator/TranslatorMetalDirect/Debug.h" |
| 15409 |
+#include "compiler/translator/tree_util/AsNode.h" |
| 15410 |
+#include "compiler/translator/tree_util/IntermRebuild.h" |
| 15411 |
+ |
| 15412 |
+using namespace sh; |
| 15413 |
+ |
| 15414 |
+namespace |
| 15415 |
+{ |
| 15416 |
+ |
| 15417 |
+bool IsOutParam(const TType ¶mType) |
| 15418 |
+{ |
| 15419 |
+ const TQualifier qual = paramType.getQualifier(); |
| 15420 |
+ switch (qual) |
| 15421 |
+ { |
| 15422 |
+ case TQualifier::EvqInOut: |
| 15423 |
+ case TQualifier::EvqOut: |
| 15424 |
+ return true; |
| 15425 |
+ |
| 15426 |
+ default: |
| 15427 |
+ return false; |
| 15428 |
+ } |
| 15429 |
+} |
| 15430 |
+ |
| 15431 |
+bool IsVectorAccess(TIntermBinary &binary) |
| 15432 |
+{ |
| 15433 |
+ TOperator op = binary.getOp(); |
| 15434 |
+ switch (op) |
| 15435 |
+ { |
| 15436 |
+ case TOperator::EOpIndexDirect: |
| 15437 |
+ case TOperator::EOpIndexIndirect: |
| 15438 |
+ break; |
| 15439 |
+ |
| 15440 |
+ default: |
| 15441 |
+ return false; |
| 15442 |
+ } |
| 15443 |
+ |
| 15444 |
+ const TType &leftType = binary.getLeft()->getType(); |
| 15445 |
+ if (!leftType.isVector() || leftType.isArray()) |
| 15446 |
+ { |
| 15447 |
+ return false; |
| 15448 |
+ } |
| 15449 |
+ |
| 15450 |
+ ASSERT(IsScalarBasicType(binary.getType())); |
| 15451 |
+ |
| 15452 |
+ return true; |
| 15453 |
+} |
| 15454 |
+ |
| 15455 |
+bool IsVectorAccess(TIntermNode &node) |
| 15456 |
+{ |
| 15457 |
+ if (auto *bin = node.getAsBinaryNode()) |
| 15458 |
+ { |
| 15459 |
+ return IsVectorAccess(*bin); |
| 15460 |
+ } |
| 15461 |
+ return false; |
| 15462 |
+} |
| 15463 |
+ |
| 15464 |
+// Differs from IsAssignment in that it does not include (++) or (--). |
| 15465 |
+bool IsAssignEqualsSign(TOperator op) |
| 15466 |
+{ |
| 15467 |
+ switch (op) |
| 15468 |
+ { |
| 15469 |
+ case TOperator::EOpAssign: |
| 15470 |
+ case TOperator::EOpInitialize: |
| 15471 |
+ case TOperator::EOpAddAssign: |
| 15472 |
+ case TOperator::EOpSubAssign: |
| 15473 |
+ case TOperator::EOpMulAssign: |
| 15474 |
+ case TOperator::EOpVectorTimesMatrixAssign: |
| 15475 |
+ case TOperator::EOpVectorTimesScalarAssign: |
| 15476 |
+ case TOperator::EOpMatrixTimesScalarAssign: |
| 15477 |
+ case TOperator::EOpMatrixTimesMatrixAssign: |
| 15478 |
+ case TOperator::EOpDivAssign: |
| 15479 |
+ case TOperator::EOpIModAssign: |
| 15480 |
+ case TOperator::EOpBitShiftLeftAssign: |
| 15481 |
+ case TOperator::EOpBitShiftRightAssign: |
| 15482 |
+ case TOperator::EOpBitwiseAndAssign: |
| 15483 |
+ case TOperator::EOpBitwiseXorAssign: |
| 15484 |
+ case TOperator::EOpBitwiseOrAssign: |
| 15485 |
+ return true; |
| 15486 |
+ |
| 15487 |
+ default: |
| 15488 |
+ return false; |
| 15489 |
+ } |
| 15490 |
+} |
| 15491 |
+ |
| 15492 |
+// Only includes ($=) style assigns, where ($) is a binary op. |
| 15493 |
+bool IsCompoundAssign(TOperator op) |
| 15494 |
+{ |
| 15495 |
+ switch (op) |
| 15496 |
+ { |
| 15497 |
+ case TOperator::EOpAddAssign: |
| 15498 |
+ case TOperator::EOpSubAssign: |
| 15499 |
+ case TOperator::EOpMulAssign: |
| 15500 |
+ case TOperator::EOpVectorTimesMatrixAssign: |
| 15501 |
+ case TOperator::EOpVectorTimesScalarAssign: |
| 15502 |
+ case TOperator::EOpMatrixTimesScalarAssign: |
| 15503 |
+ case TOperator::EOpMatrixTimesMatrixAssign: |
| 15504 |
+ case TOperator::EOpDivAssign: |
| 15505 |
+ case TOperator::EOpIModAssign: |
| 15506 |
+ case TOperator::EOpBitShiftLeftAssign: |
| 15507 |
+ case TOperator::EOpBitShiftRightAssign: |
| 15508 |
+ case TOperator::EOpBitwiseAndAssign: |
| 15509 |
+ case TOperator::EOpBitwiseXorAssign: |
| 15510 |
+ case TOperator::EOpBitwiseOrAssign: |
| 15511 |
+ return true; |
| 15512 |
+ |
| 15513 |
+ default: |
| 15514 |
+ return false; |
| 15515 |
+ } |
| 15516 |
+} |
| 15517 |
+ |
| 15518 |
+bool ReturnsReference(TOperator op) |
| 15519 |
+{ |
| 15520 |
+ switch (op) |
| 15521 |
+ { |
| 15522 |
+ case TOperator::EOpAssign: |
| 15523 |
+ case TOperator::EOpInitialize: |
| 15524 |
+ case TOperator::EOpAddAssign: |
| 15525 |
+ case TOperator::EOpSubAssign: |
| 15526 |
+ case TOperator::EOpMulAssign: |
| 15527 |
+ case TOperator::EOpVectorTimesMatrixAssign: |
| 15528 |
+ case TOperator::EOpVectorTimesScalarAssign: |
| 15529 |
+ case TOperator::EOpMatrixTimesScalarAssign: |
| 15530 |
+ case TOperator::EOpMatrixTimesMatrixAssign: |
| 15531 |
+ case TOperator::EOpDivAssign: |
| 15532 |
+ case TOperator::EOpIModAssign: |
| 15533 |
+ case TOperator::EOpBitShiftLeftAssign: |
| 15534 |
+ case TOperator::EOpBitShiftRightAssign: |
| 15535 |
+ case TOperator::EOpBitwiseAndAssign: |
| 15536 |
+ case TOperator::EOpBitwiseXorAssign: |
| 15537 |
+ case TOperator::EOpBitwiseOrAssign: |
| 15538 |
+ |
| 15539 |
+ case TOperator::EOpPostIncrement: |
| 15540 |
+ case TOperator::EOpPostDecrement: |
| 15541 |
+ case TOperator::EOpPreIncrement: |
| 15542 |
+ case TOperator::EOpPreDecrement: |
| 15543 |
+ |
| 15544 |
+ case TOperator::EOpIndexDirect: |
| 15545 |
+ case TOperator::EOpIndexIndirect: |
| 15546 |
+ case TOperator::EOpIndexDirectStruct: |
| 15547 |
+ case TOperator::EOpIndexDirectInterfaceBlock: |
| 15548 |
+ |
| 15549 |
+ return true; |
| 15550 |
+ |
| 15551 |
+ default: |
| 15552 |
+ return false; |
| 15553 |
+ } |
| 15554 |
+} |
| 15555 |
+ |
| 15556 |
+TIntermTyped &DecomposeCompoundAssignment(TIntermBinary &node) |
| 15557 |
+{ |
| 15558 |
+ TOperator op = node.getOp(); |
| 15559 |
+ switch (op) |
| 15560 |
+ { |
| 15561 |
+ case TOperator::EOpAddAssign: |
| 15562 |
+ op = TOperator::EOpAdd; |
| 15563 |
+ break; |
| 15564 |
+ case TOperator::EOpSubAssign: |
| 15565 |
+ op = TOperator::EOpSub; |
| 15566 |
+ break; |
| 15567 |
+ case TOperator::EOpMulAssign: |
| 15568 |
+ op = TOperator::EOpMul; |
| 15569 |
+ break; |
| 15570 |
+ case TOperator::EOpVectorTimesMatrixAssign: |
| 15571 |
+ op = TOperator::EOpVectorTimesMatrix; |
| 15572 |
+ break; |
| 15573 |
+ case TOperator::EOpVectorTimesScalarAssign: |
| 15574 |
+ op = TOperator::EOpVectorTimesScalar; |
| 15575 |
+ break; |
| 15576 |
+ case TOperator::EOpMatrixTimesScalarAssign: |
| 15577 |
+ op = TOperator::EOpMatrixTimesScalar; |
| 15578 |
+ break; |
| 15579 |
+ case TOperator::EOpMatrixTimesMatrixAssign: |
| 15580 |
+ op = TOperator::EOpMatrixTimesMatrix; |
| 15581 |
+ break; |
| 15582 |
+ case TOperator::EOpDivAssign: |
| 15583 |
+ op = TOperator::EOpDiv; |
| 15584 |
+ break; |
| 15585 |
+ case TOperator::EOpIModAssign: |
| 15586 |
+ op = TOperator::EOpIMod; |
| 15587 |
+ break; |
| 15588 |
+ case TOperator::EOpBitShiftLeftAssign: |
| 15589 |
+ op = TOperator::EOpBitShiftLeft; |
| 15590 |
+ break; |
| 15591 |
+ case TOperator::EOpBitShiftRightAssign: |
| 15592 |
+ op = TOperator::EOpBitShiftRight; |
| 15593 |
+ break; |
| 15594 |
+ case TOperator::EOpBitwiseAndAssign: |
| 15595 |
+ op = TOperator::EOpBitwiseAnd; |
| 15596 |
+ break; |
| 15597 |
+ case TOperator::EOpBitwiseXorAssign: |
| 15598 |
+ op = TOperator::EOpBitwiseXor; |
| 15599 |
+ break; |
| 15600 |
+ case TOperator::EOpBitwiseOrAssign: |
| 15601 |
+ op = TOperator::EOpBitwiseOr; |
| 15602 |
+ break; |
| 15603 |
+ default: |
| 15604 |
+ LOGIC_ERROR(); |
| 15605 |
+ } |
| 15606 |
+ |
| 15607 |
+ // This assumes SeparateCompoundExpressions has already been called. |
| 15608 |
+ // This assumption allows this code to not need to introduce temporaries. |
| 15609 |
+ // |
| 15610 |
+ // e.g. dont have to worry about: |
| 15611 |
+ // vec[hasSideEffect()] *= 4 |
| 15612 |
+ // becoming |
| 15613 |
+ // vec[hasSideEffect()] = vec[hasSideEffect()] * 4 |
| 15614 |
+ |
| 15615 |
+ TIntermTyped *left = node.getLeft(); |
| 15616 |
+ TIntermTyped *right = node.getRight(); |
| 15617 |
+ return *new TIntermBinary(TOperator::EOpAssign, left->deepCopy(), |
| 15618 |
+ new TIntermBinary(op, left, right)); |
| 15619 |
+} |
| 15620 |
+ |
| 15621 |
+class Rewriter1 : public TIntermRebuild |
| 15622 |
+{ |
| 15623 |
+ public: |
| 15624 |
+ Rewriter1(TCompiler &compiler) : TIntermRebuild(compiler, false, true) {} |
| 15625 |
+ |
| 15626 |
+ PostResult visitBinaryPost(TIntermBinary &binaryNode) override |
| 15627 |
+ { |
| 15628 |
+ const TOperator op = binaryNode.getOp(); |
| 15629 |
+ if (IsCompoundAssign(op)) |
| 15630 |
+ { |
| 15631 |
+ TIntermTyped &left = *binaryNode.getLeft(); |
| 15632 |
+ if (left.getAsSwizzleNode() || IsVectorAccess(left)) |
| 15633 |
+ { |
| 15634 |
+ return DecomposeCompoundAssignment(binaryNode); |
| 15635 |
+ } |
| 15636 |
+ } |
| 15637 |
+ return binaryNode; |
| 15638 |
+ } |
| 15639 |
+}; |
| 15640 |
+ |
| 15641 |
+class Rewriter2 : public TIntermRebuild |
| 15642 |
+{ |
| 15643 |
+ std::vector<bool> mRequiresAddressingStack; |
| 15644 |
+ SymbolEnv &mSymbolEnv; |
| 15645 |
+ |
| 15646 |
+ private: |
| 15647 |
+ bool requiresAddressing() const |
| 15648 |
+ { |
| 15649 |
+ if (mRequiresAddressingStack.empty()) |
| 15650 |
+ { |
| 15651 |
+ return false; |
| 15652 |
+ } |
| 15653 |
+ return mRequiresAddressingStack.back(); |
| 15654 |
+ } |
| 15655 |
+ |
| 15656 |
+ public: |
| 15657 |
+ ~Rewriter2() override { ASSERT(mRequiresAddressingStack.empty()); } |
| 15658 |
+ |
| 15659 |
+ Rewriter2(TCompiler &compiler, SymbolEnv &symbolEnv) |
| 15660 |
+ : TIntermRebuild(compiler, true, true), mSymbolEnv(symbolEnv) |
| 15661 |
+ {} |
| 15662 |
+ |
| 15663 |
+ PreResult visitAggregatePre(TIntermAggregate &aggregateNode) override |
| 15664 |
+ { |
| 15665 |
+ const TFunction *func = aggregateNode.getFunction(); |
| 15666 |
+ if (!func) |
| 15667 |
+ { |
| 15668 |
+ return aggregateNode; |
| 15669 |
+ } |
| 15670 |
+ |
| 15671 |
+ TIntermSequence &args = *aggregateNode.getSequence(); |
| 15672 |
+ size_t argCount = args.size(); |
| 15673 |
+ |
| 15674 |
+ for (size_t i = 0; i < argCount; ++i) |
| 15675 |
+ { |
| 15676 |
+ const TVariable ¶m = *func->getParam(i); |
| 15677 |
+ const TType ¶mType = param.getType(); |
| 15678 |
+ TIntermNode *arg = args[i]; |
| 15679 |
+ ASSERT(arg); |
| 15680 |
+ |
| 15681 |
+ mRequiresAddressingStack.push_back(IsOutParam(paramType)); |
| 15682 |
+ args[i] = rebuild(*arg).single(); |
| 15683 |
+ ASSERT(args[i]); |
| 15684 |
+ ASSERT(!mRequiresAddressingStack.empty()); |
| 15685 |
+ mRequiresAddressingStack.pop_back(); |
| 15686 |
+ } |
| 15687 |
+ |
| 15688 |
+ return {aggregateNode, VisitBits::Neither}; |
| 15689 |
+ } |
| 15690 |
+ |
| 15691 |
+ PostResult visitSwizzlePost(TIntermSwizzle &swizzleNode) override |
| 15692 |
+ { |
| 15693 |
+ if (!requiresAddressing()) |
| 15694 |
+ { |
| 15695 |
+ return swizzleNode; |
| 15696 |
+ } |
| 15697 |
+ |
| 15698 |
+ TIntermTyped &vecNode = *swizzleNode.getOperand(); |
| 15699 |
+ const TQualifierList &offsets = swizzleNode.getSwizzleOffsets(); |
| 15700 |
+ ASSERT(!offsets.empty()); |
| 15701 |
+ ASSERT(offsets.size() <= 4); |
| 15702 |
+ |
| 15703 |
+ auto &args = *new TIntermSequence(); |
| 15704 |
+ args.reserve(offsets.size() + 1); |
| 15705 |
+ args.push_back(&vecNode); |
| 15706 |
+ for (int offset : offsets) |
| 15707 |
+ { |
| 15708 |
+ args.push_back(new TIntermConstantUnion(new TConstantUnion(offset), |
| 15709 |
+ *new TType(TBasicType::EbtInt))); |
| 15710 |
+ } |
| 15711 |
+ |
| 15712 |
+ return mSymbolEnv.callFunctionOverload(Name("swizzle_ref"), swizzleNode.getType(), args); |
| 15713 |
+ } |
| 15714 |
+ |
| 15715 |
+ PreResult visitBinaryPre(TIntermBinary &binaryNode) override |
| 15716 |
+ { |
| 15717 |
+ const TOperator op = binaryNode.getOp(); |
| 15718 |
+ |
| 15719 |
+ const bool isAccess = IsVectorAccess(binaryNode); |
| 15720 |
+ |
| 15721 |
+ const bool disableTop = !ReturnsReference(op) || !requiresAddressing(); |
| 15722 |
+ const bool disableLeft = disableTop; |
| 15723 |
+ const bool disableRight = disableTop || isAccess || IsAssignEqualsSign(op); |
| 15724 |
+ |
| 15725 |
+ auto traverse = [&](TIntermTyped &node, const bool disable) -> TIntermTyped & { |
| 15726 |
+ if (disable) |
| 15727 |
+ { |
| 15728 |
+ mRequiresAddressingStack.push_back(false); |
| 15729 |
+ } |
| 15730 |
+ auto *newNode = asNode<TIntermTyped>(rebuild(node).single()); |
| 15731 |
+ ASSERT(newNode); |
| 15732 |
+ if (disable) |
| 15733 |
+ { |
| 15734 |
+ mRequiresAddressingStack.pop_back(); |
| 15735 |
+ } |
| 15736 |
+ return *newNode; |
| 15737 |
+ }; |
| 15738 |
+ |
| 15739 |
+ TIntermTyped &leftNode = *binaryNode.getLeft(); |
| 15740 |
+ TIntermTyped &rightNode = *binaryNode.getRight(); |
| 15741 |
+ |
| 15742 |
+ TIntermTyped &newLeft = traverse(leftNode, disableLeft); |
| 15743 |
+ TIntermTyped &newRight = traverse(rightNode, disableRight); |
| 15744 |
+ |
| 15745 |
+ if (!isAccess || disableTop) |
| 15746 |
+ { |
| 15747 |
+ if (&leftNode == &newLeft && &rightNode == &newRight) |
| 15748 |
+ { |
| 15749 |
+ return {&binaryNode, VisitBits::Neither}; |
| 15750 |
+ } |
| 15751 |
+ return {*new TIntermBinary(op, &newLeft, &newRight), VisitBits::Neither}; |
| 15752 |
+ } |
| 15753 |
+ |
| 15754 |
+ return {mSymbolEnv.callFunctionOverload(Name("elem_ref"), binaryNode.getType(), |
| 15755 |
+ *new TIntermSequence{&newLeft, &newRight}), |
| 15756 |
+ VisitBits::Neither}; |
| 15757 |
+ } |
| 15758 |
+}; |
| 15759 |
+ |
| 15760 |
+} // anonymous namespace |
| 15761 |
+ |
| 15762 |
+bool sh::RewriteUnaddressableReferences(TCompiler &compiler, |
| 15763 |
+ TIntermBlock &root, |
| 15764 |
+ SymbolEnv &symbolEnv) |
| 15765 |
+{ |
| 15766 |
+ if (!Rewriter1(compiler).rebuildRoot(root)) |
| 15767 |
+ { |
| 15768 |
+ return false; |
| 15769 |
+ } |
| 15770 |
+ if (!Rewriter2(compiler, symbolEnv).rebuildRoot(root)) |
| 15771 |
+ { |
| 15772 |
+ return false; |
| 15773 |
+ } |
| 15774 |
+ return true; |
| 15775 |
+} |
| 15776 |
diff --git a/src/compiler/translator/TranslatorMetalDirect/RewriteUnaddressableReferences.h b/src/compiler/translator/TranslatorMetalDirect/RewriteUnaddressableReferences.h |
| 15777 |
new file mode 100644 |
| 15778 |
index 0000000..77da984 |
| 15779 |
--- /dev/null |
| 15780 |
+++ b/src/compiler/translator/TranslatorMetalDirect/RewriteUnaddressableReferences.h |
| 15781 |
@@ -0,0 +1,31 @@ |
| 15782 |
+// |
| 15783 |
+// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 15784 |
+// Use of this source code is governed by a BSD-style license that can be |
| 15785 |
+// found in the LICENSE file. |
| 15786 |
+// |
| 15787 |
+ |
| 15788 |
+#ifndef COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_REWRITEUNADDRESSABLEREFERENCES_H_ |
| 15789 |
+#define COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_REWRITEUNADDRESSABLEREFERENCES_H_ |
| 15790 |
+ |
| 15791 |
+#include "compiler/translator/Compiler.h" |
| 15792 |
+#include "compiler/translator/TranslatorMetalDirect/ProgramPrelude.h" |
| 15793 |
+#include "compiler/translator/TranslatorMetalDirect/SymbolEnv.h" |
| 15794 |
+ |
| 15795 |
+namespace sh |
| 15796 |
+{ |
| 15797 |
+ |
| 15798 |
+// Given: |
| 15799 |
+// void foo(out x); |
| 15800 |
+// It is possible for the following to be legal in GLSL but not in Metal: |
| 15801 |
+// foo(expression); |
| 15802 |
+// This can happen in cases where `expression` is a vector swizzle or vector element access. |
| 15803 |
+// This rewrite functionality introduces temporaries that serve as proxies to be passed to the |
| 15804 |
+// out/inout parameters as needed. The corresponding expressions get populated with their |
| 15805 |
+// proxies after the function call. |
| 15806 |
+ANGLE_NO_DISCARD bool RewriteUnaddressableReferences(TCompiler &compiler, |
| 15807 |
+ TIntermBlock &root, |
| 15808 |
+ SymbolEnv &symbolEnv); |
| 15809 |
+ |
| 15810 |
+} // namespace sh |
| 15811 |
+ |
| 15812 |
+#endif // COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_REWRITEUNADDRESSABLEREFERENCES_H_ |
| 15813 |
diff --git a/src/compiler/translator/TranslatorMetalDirect/SeparateCompoundExpressions.cpp b/src/compiler/translator/TranslatorMetalDirect/SeparateCompoundExpressions.cpp |
| 15814 |
new file mode 100644 |
| 15815 |
index 0000000..5a7b373 |
| 15816 |
--- /dev/null |
| 15817 |
+++ b/src/compiler/translator/TranslatorMetalDirect/SeparateCompoundExpressions.cpp |
| 15818 |
@@ -0,0 +1,655 @@ |
| 15819 |
+// |
| 15820 |
+// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 15821 |
+// Use of this source code is governed by a BSD-style license that can be |
| 15822 |
+// found in the LICENSE file. |
| 15823 |
+// |
| 15824 |
+ |
| 15825 |
+#include <unordered_map> |
| 15826 |
+ |
| 15827 |
+#include "compiler/translator/TranslatorMetalDirect/AstHelpers.h" |
| 15828 |
+#include "compiler/translator/TranslatorMetalDirect/Debug.h" |
| 15829 |
+#include "compiler/translator/TranslatorMetalDirect/EnvironmentVariable.h" |
| 15830 |
+#include "compiler/translator/TranslatorMetalDirect/SeparateCompoundExpressions.h" |
| 15831 |
+#include "compiler/translator/tree_ops/SimplifyLoopConditions.h" |
| 15832 |
+#include "compiler/translator/tree_util/IntermRebuild.h" |
| 15833 |
+ |
| 15834 |
+using namespace sh; |
| 15835 |
+ |
| 15836 |
+//////////////////////////////////////////////////////////////////////////////// |
| 15837 |
+ |
| 15838 |
+namespace |
| 15839 |
+{ |
| 15840 |
+ |
| 15841 |
+bool IsIndex(TOperator op) |
| 15842 |
+{ |
| 15843 |
+ switch (op) |
| 15844 |
+ { |
| 15845 |
+ case TOperator::EOpIndexDirect: |
| 15846 |
+ case TOperator::EOpIndexDirectInterfaceBlock: |
| 15847 |
+ case TOperator::EOpIndexDirectStruct: |
| 15848 |
+ case TOperator::EOpIndexIndirect: |
| 15849 |
+ return true; |
| 15850 |
+ default: |
| 15851 |
+ return false; |
| 15852 |
+ } |
| 15853 |
+} |
| 15854 |
+ |
| 15855 |
+bool IsIndex(TIntermTyped &expr) |
| 15856 |
+{ |
| 15857 |
+ if (auto *binary = expr.getAsBinaryNode()) |
| 15858 |
+ { |
| 15859 |
+ return IsIndex(binary->getOp()); |
| 15860 |
+ } |
| 15861 |
+ return expr.getAsSwizzleNode(); |
| 15862 |
+} |
| 15863 |
+ |
| 15864 |
+bool ViewBinaryChain(TOperator op, TIntermTyped &node, std::vector<TIntermTyped *> &out) |
| 15865 |
+{ |
| 15866 |
+ TIntermBinary *binary = node.getAsBinaryNode(); |
| 15867 |
+ if (!binary || binary->getOp() != op) |
| 15868 |
+ { |
| 15869 |
+ return false; |
| 15870 |
+ } |
| 15871 |
+ |
| 15872 |
+ TIntermTyped *left = binary->getLeft(); |
| 15873 |
+ TIntermTyped *right = binary->getRight(); |
| 15874 |
+ |
| 15875 |
+ if (!ViewBinaryChain(op, *left, out)) |
| 15876 |
+ { |
| 15877 |
+ out.push_back(left); |
| 15878 |
+ } |
| 15879 |
+ |
| 15880 |
+ if (!ViewBinaryChain(op, *right, out)) |
| 15881 |
+ { |
| 15882 |
+ out.push_back(right); |
| 15883 |
+ } |
| 15884 |
+ |
| 15885 |
+ return true; |
| 15886 |
+} |
| 15887 |
+ |
| 15888 |
+std::vector<TIntermTyped *> ViewBinaryChain(TIntermBinary &node) |
| 15889 |
+{ |
| 15890 |
+ std::vector<TIntermTyped *> chain; |
| 15891 |
+ ViewBinaryChain(node.getOp(), node, chain); |
| 15892 |
+ ASSERT(chain.size() >= 2); |
| 15893 |
+ return chain; |
| 15894 |
+} |
| 15895 |
+ |
| 15896 |
+class PrePass : public TIntermRebuild |
| 15897 |
+{ |
| 15898 |
+ public: |
| 15899 |
+ PrePass(TCompiler &compiler) : TIntermRebuild(compiler, true, true) {} |
| 15900 |
+ |
| 15901 |
+ private: |
| 15902 |
+ // Change chains of |
| 15903 |
+ // x OP y OP z |
| 15904 |
+ // to |
| 15905 |
+ // x OP (y OP z) |
| 15906 |
+ // regardless of original parenthesization. |
| 15907 |
+ TIntermTyped &reassociateRight(TIntermBinary &node) |
| 15908 |
+ { |
| 15909 |
+ const TOperator op = node.getOp(); |
| 15910 |
+ std::vector<TIntermTyped *> chain = ViewBinaryChain(node); |
| 15911 |
+ |
| 15912 |
+ TIntermTyped *result = chain.back(); |
| 15913 |
+ chain.pop_back(); |
| 15914 |
+ ASSERT(result); |
| 15915 |
+ |
| 15916 |
+ const auto begin = chain.rbegin(); |
| 15917 |
+ const auto end = chain.rend(); |
| 15918 |
+ |
| 15919 |
+ for (auto iter = begin; iter != end; ++iter) |
| 15920 |
+ { |
| 15921 |
+ TIntermTyped *part = *iter; |
| 15922 |
+ ASSERT(part); |
| 15923 |
+ TIntermNode *temp = rebuild(*part).single(); |
| 15924 |
+ ASSERT(temp); |
| 15925 |
+ part = temp->getAsTyped(); |
| 15926 |
+ ASSERT(part); |
| 15927 |
+ result = new TIntermBinary(op, part, result); |
| 15928 |
+ } |
| 15929 |
+ return *result; |
| 15930 |
+ } |
| 15931 |
+ |
| 15932 |
+ private: |
| 15933 |
+ PreResult visitBinaryPre(TIntermBinary &node) override |
| 15934 |
+ { |
| 15935 |
+ const TOperator op = node.getOp(); |
| 15936 |
+ if (op == TOperator::EOpLogicalAnd || op == TOperator::EOpLogicalOr) |
| 15937 |
+ { |
| 15938 |
+ return {reassociateRight(node), VisitBits::Neither}; |
| 15939 |
+ } |
| 15940 |
+ return node; |
| 15941 |
+ } |
| 15942 |
+}; |
| 15943 |
+ |
| 15944 |
+class Separator : public TIntermRebuild |
| 15945 |
+{ |
| 15946 |
+ IdGen &mIdGen; |
| 15947 |
+ std::vector<std::vector<TIntermNode *>> mStmtsStack; |
| 15948 |
+ std::vector<std::unordered_map<const TVariable *, TIntermDeclaration *>> mBindingMapStack; |
| 15949 |
+ std::unordered_map<TIntermTyped *, TIntermTyped *> mExprMap; |
| 15950 |
+ std::unordered_set<TIntermDeclaration *> mMaskedDecls; |
| 15951 |
+ |
| 15952 |
+ public: |
| 15953 |
+ Separator(TCompiler &compiler, SymbolEnv &symbolEnv, IdGen &idGen) |
| 15954 |
+ : TIntermRebuild(compiler, true, true), mIdGen(idGen) |
| 15955 |
+ {} |
| 15956 |
+ |
| 15957 |
+ ~Separator() override |
| 15958 |
+ { |
| 15959 |
+ ASSERT(mStmtsStack.empty()); |
| 15960 |
+ ASSERT(mExprMap.empty()); |
| 15961 |
+ ASSERT(mBindingMapStack.empty()); |
| 15962 |
+ } |
| 15963 |
+ |
| 15964 |
+ private: |
| 15965 |
+ std::vector<TIntermNode *> &getCurrStmts() |
| 15966 |
+ { |
| 15967 |
+ ASSERT(!mStmtsStack.empty()); |
| 15968 |
+ return mStmtsStack.back(); |
| 15969 |
+ } |
| 15970 |
+ |
| 15971 |
+ std::unordered_map<const TVariable *, TIntermDeclaration *> &getCurrBindingMap() |
| 15972 |
+ { |
| 15973 |
+ ASSERT(!mBindingMapStack.empty()); |
| 15974 |
+ return mBindingMapStack.back(); |
| 15975 |
+ } |
| 15976 |
+ |
| 15977 |
+ void pushStmt(TIntermNode &node) { getCurrStmts().push_back(&node); } |
| 15978 |
+ |
| 15979 |
+ bool isTerminalExpr(TIntermNode &node) |
| 15980 |
+ { |
| 15981 |
+ NodeType nodeType = getNodeType(node); |
| 15982 |
+ switch (nodeType) |
| 15983 |
+ { |
| 15984 |
+ case NodeType::Symbol: |
| 15985 |
+ case NodeType::ConstantUnion: |
| 15986 |
+ return true; |
| 15987 |
+ default: |
| 15988 |
+ return false; |
| 15989 |
+ } |
| 15990 |
+ } |
| 15991 |
+ |
| 15992 |
+ TIntermTyped *pullMappedExpr(TIntermTyped *node, bool allowBacktrack) |
| 15993 |
+ { |
| 15994 |
+ TIntermTyped *expr; |
| 15995 |
+ |
| 15996 |
+ { |
| 15997 |
+ auto iter = mExprMap.find(node); |
| 15998 |
+ if (iter == mExprMap.end()) |
| 15999 |
+ { |
| 16000 |
+ return node; |
| 16001 |
+ } |
| 16002 |
+ ASSERT(node); |
| 16003 |
+ expr = iter->second; |
| 16004 |
+ ASSERT(expr); |
| 16005 |
+ mExprMap.erase(iter); |
| 16006 |
+ } |
| 16007 |
+ |
| 16008 |
+ if (allowBacktrack) |
| 16009 |
+ { |
| 16010 |
+ auto &bindingMap = getCurrBindingMap(); |
| 16011 |
+ while (TIntermSymbol *symbol = expr->getAsSymbolNode()) |
| 16012 |
+ { |
| 16013 |
+ const TVariable &var = symbol->variable(); |
| 16014 |
+ auto iter = bindingMap.find(&var); |
| 16015 |
+ if (iter == bindingMap.end()) |
| 16016 |
+ { |
| 16017 |
+ return expr; |
| 16018 |
+ } |
| 16019 |
+ ASSERT(var.symbolType() == SymbolType::AngleInternal); |
| 16020 |
+ TIntermDeclaration *decl = iter->second; |
| 16021 |
+ ASSERT(decl); |
| 16022 |
+ expr = ViewDeclaration(*decl).initExpr; |
| 16023 |
+ ASSERT(expr); |
| 16024 |
+ bindingMap.erase(iter); |
| 16025 |
+ mMaskedDecls.insert(decl); |
| 16026 |
+ } |
| 16027 |
+ } |
| 16028 |
+ |
| 16029 |
+ return expr; |
| 16030 |
+ } |
| 16031 |
+ |
| 16032 |
+ bool isStandaloneExpr(TIntermTyped &expr) |
| 16033 |
+ { |
| 16034 |
+ if (getParentNode()->getAsBlock()) |
| 16035 |
+ { |
| 16036 |
+ return true; |
| 16037 |
+ } |
| 16038 |
+ ASSERT(expr.getType().getBasicType() != TBasicType::EbtVoid); |
| 16039 |
+ return false; |
| 16040 |
+ } |
| 16041 |
+ |
| 16042 |
+ void pushBinding(TIntermTyped &oldExpr, TIntermTyped &newExpr) |
| 16043 |
+ { |
| 16044 |
+ if (isStandaloneExpr(newExpr)) |
| 16045 |
+ { |
| 16046 |
+ pushStmt(newExpr); |
| 16047 |
+ return; |
| 16048 |
+ } |
| 16049 |
+ if (IsIndex(newExpr)) |
| 16050 |
+ { |
| 16051 |
+ mExprMap[&oldExpr] = &newExpr; |
| 16052 |
+ return; |
| 16053 |
+ } |
| 16054 |
+ auto &bindingMap = getCurrBindingMap(); |
| 16055 |
+ const Name name = mIdGen.createNewName(""); |
| 16056 |
+ auto *var = |
| 16057 |
+ new TVariable(&mSymbolTable, name.rawName(), &newExpr.getType(), name.symbolType()); |
| 16058 |
+ auto *decl = new TIntermDeclaration(var, &newExpr); |
| 16059 |
+ pushStmt(*decl); |
| 16060 |
+ mExprMap[&oldExpr] = new TIntermSymbol(var); |
| 16061 |
+ bindingMap[var] = decl; |
| 16062 |
+ } |
| 16063 |
+ |
| 16064 |
+ void pushStacks() |
| 16065 |
+ { |
| 16066 |
+ mStmtsStack.emplace_back(); |
| 16067 |
+ mBindingMapStack.emplace_back(); |
| 16068 |
+ } |
| 16069 |
+ |
| 16070 |
+ void popStacks() |
| 16071 |
+ { |
| 16072 |
+ ASSERT(!mBindingMapStack.empty()); |
| 16073 |
+ ASSERT(!mStmtsStack.empty()); |
| 16074 |
+ ASSERT(mStmtsStack.back().empty()); |
| 16075 |
+ mBindingMapStack.pop_back(); |
| 16076 |
+ mStmtsStack.pop_back(); |
| 16077 |
+ } |
| 16078 |
+ |
| 16079 |
+ void pushStmtsIntoBlock(TIntermBlock &block, std::vector<TIntermNode *> &stmts) |
| 16080 |
+ { |
| 16081 |
+ TIntermSequence &seq = *block.getSequence(); |
| 16082 |
+ for (TIntermNode *stmt : stmts) |
| 16083 |
+ { |
| 16084 |
+ if (TIntermDeclaration *decl = stmt->getAsDeclarationNode()) |
| 16085 |
+ { |
| 16086 |
+ auto iter = mMaskedDecls.find(decl); |
| 16087 |
+ if (iter != mMaskedDecls.end()) |
| 16088 |
+ { |
| 16089 |
+ mMaskedDecls.erase(iter); |
| 16090 |
+ continue; |
| 16091 |
+ } |
| 16092 |
+ } |
| 16093 |
+ seq.push_back(stmt); |
| 16094 |
+ } |
| 16095 |
+ } |
| 16096 |
+ |
| 16097 |
+ TIntermBlock &buildBlockWithTailAssign(const TVariable &var, TIntermTyped &newExpr) |
| 16098 |
+ { |
| 16099 |
+ std::vector<TIntermNode *> stmts = std::move(getCurrStmts()); |
| 16100 |
+ popStacks(); |
| 16101 |
+ |
| 16102 |
+ auto &block = *new TIntermBlock(); |
| 16103 |
+ auto &seq = *block.getSequence(); |
| 16104 |
+ seq.reserve(1 + stmts.size()); |
| 16105 |
+ pushStmtsIntoBlock(block, stmts); |
| 16106 |
+ seq.push_back(new TIntermBinary(TOperator::EOpAssign, new TIntermSymbol(&var), &newExpr)); |
| 16107 |
+ |
| 16108 |
+ return block; |
| 16109 |
+ } |
| 16110 |
+ |
| 16111 |
+ private: |
| 16112 |
+ PreResult visitBlockPre(TIntermBlock &node) override |
| 16113 |
+ { |
| 16114 |
+ pushStacks(); |
| 16115 |
+ return node; |
| 16116 |
+ } |
| 16117 |
+ |
| 16118 |
+ PostResult visitBlockPost(TIntermBlock &node) override |
| 16119 |
+ { |
| 16120 |
+ std::vector<TIntermNode *> stmts = std::move(getCurrStmts()); |
| 16121 |
+ popStacks(); |
| 16122 |
+ |
| 16123 |
+ TIntermSequence &seq = *node.getSequence(); |
| 16124 |
+ seq.clear(); |
| 16125 |
+ seq.reserve(stmts.size()); |
| 16126 |
+ pushStmtsIntoBlock(node, stmts); |
| 16127 |
+ |
| 16128 |
+ TIntermNode *parent = getParentNode(); |
| 16129 |
+ if (parent && parent->getAsBlock()) |
| 16130 |
+ { |
| 16131 |
+ pushStmt(node); |
| 16132 |
+ } |
| 16133 |
+ |
| 16134 |
+ return node; |
| 16135 |
+ } |
| 16136 |
+ |
| 16137 |
+ PreResult visitDeclarationPre(TIntermDeclaration &node) override |
| 16138 |
+ { |
| 16139 |
+ Declaration decl = ViewDeclaration(node); |
| 16140 |
+ if (!decl.initExpr || isTerminalExpr(*decl.initExpr)) |
| 16141 |
+ { |
| 16142 |
+ pushStmt(node); |
| 16143 |
+ return {node, VisitBits::Neither}; |
| 16144 |
+ } |
| 16145 |
+ return node; |
| 16146 |
+ } |
| 16147 |
+ |
| 16148 |
+ PostResult visitDeclarationPost(TIntermDeclaration &node) override |
| 16149 |
+ { |
| 16150 |
+ Declaration decl = ViewDeclaration(node); |
| 16151 |
+ ASSERT(decl.symbol.variable().symbolType() != SymbolType::Empty); |
| 16152 |
+ ASSERT(!decl.symbol.variable().getType().isStructSpecifier()); |
| 16153 |
+ |
| 16154 |
+ TIntermTyped *newInitExpr = pullMappedExpr(decl.initExpr, true); |
| 16155 |
+ if (decl.initExpr == newInitExpr) |
| 16156 |
+ { |
| 16157 |
+ pushStmt(node); |
| 16158 |
+ } |
| 16159 |
+ else |
| 16160 |
+ { |
| 16161 |
+ auto &newNode = *new TIntermDeclaration(); |
| 16162 |
+ newNode.appendDeclarator( |
| 16163 |
+ new TIntermBinary(TOperator::EOpInitialize, &decl.symbol, newInitExpr)); |
| 16164 |
+ pushStmt(newNode); |
| 16165 |
+ } |
| 16166 |
+ return node; |
| 16167 |
+ } |
| 16168 |
+ |
| 16169 |
+ PostResult visitUnaryPost(TIntermUnary &node) override |
| 16170 |
+ { |
| 16171 |
+ TIntermTyped *expr = node.getOperand(); |
| 16172 |
+ TIntermTyped *newExpr = pullMappedExpr(expr, false); |
| 16173 |
+ if (expr == newExpr) |
| 16174 |
+ { |
| 16175 |
+ pushBinding(node, node); |
| 16176 |
+ } |
| 16177 |
+ else |
| 16178 |
+ { |
| 16179 |
+ pushBinding(node, *new TIntermUnary(node.getOp(), newExpr, node.getFunction())); |
| 16180 |
+ } |
| 16181 |
+ return node; |
| 16182 |
+ } |
| 16183 |
+ |
| 16184 |
+ PreResult visitBinaryPre(TIntermBinary &node) override |
| 16185 |
+ { |
| 16186 |
+ const TOperator op = node.getOp(); |
| 16187 |
+ if (op == TOperator::EOpLogicalAnd || op == TOperator::EOpLogicalOr) |
| 16188 |
+ { |
| 16189 |
+ TIntermTyped *left = node.getLeft(); |
| 16190 |
+ TIntermTyped *right = node.getRight(); |
| 16191 |
+ |
| 16192 |
+ PostResult leftResult = rebuild(*left); |
| 16193 |
+ ASSERT(leftResult.single()); |
| 16194 |
+ |
| 16195 |
+ pushStacks(); |
| 16196 |
+ PostResult rightResult = rebuild(*right); |
| 16197 |
+ ASSERT(rightResult.single()); |
| 16198 |
+ |
| 16199 |
+ return {node, VisitBits::Post}; |
| 16200 |
+ } |
| 16201 |
+ |
| 16202 |
+ return node; |
| 16203 |
+ } |
| 16204 |
+ |
| 16205 |
+ PostResult visitBinaryPost(TIntermBinary &node) override |
| 16206 |
+ { |
| 16207 |
+ const TOperator op = node.getOp(); |
| 16208 |
+ if (op == TOperator::EOpInitialize && getParentNode()->getAsDeclarationNode()) |
| 16209 |
+ { |
| 16210 |
+ // Special case is handled by visitDeclarationPost |
| 16211 |
+ return node; |
| 16212 |
+ } |
| 16213 |
+ |
| 16214 |
+ TIntermTyped *left = node.getLeft(); |
| 16215 |
+ TIntermTyped *right = node.getRight(); |
| 16216 |
+ |
| 16217 |
+ if (op == TOperator::EOpLogicalAnd || op == TOperator::EOpLogicalOr) |
| 16218 |
+ { |
| 16219 |
+ const Name name = mIdGen.createNewName(""); |
| 16220 |
+ auto *var = new TVariable(&mSymbolTable, name.rawName(), new TType(TBasicType::EbtBool), |
| 16221 |
+ name.symbolType()); |
| 16222 |
+ |
| 16223 |
+ TIntermTyped *newRight = pullMappedExpr(right, true); |
| 16224 |
+ TIntermBlock *rightBlock = &buildBlockWithTailAssign(*var, *newRight); |
| 16225 |
+ TIntermTyped *newLeft = pullMappedExpr(left, true); |
| 16226 |
+ |
| 16227 |
+ TIntermTyped *cond = new TIntermSymbol(var); |
| 16228 |
+ if (op == TOperator::EOpLogicalOr) |
| 16229 |
+ { |
| 16230 |
+ cond = new TIntermUnary(TOperator::EOpLogicalNot, cond, nullptr); |
| 16231 |
+ } |
| 16232 |
+ |
| 16233 |
+ pushStmt(*new TIntermDeclaration(var, newLeft)); |
| 16234 |
+ pushStmt(*new TIntermIfElse(cond, rightBlock, nullptr)); |
| 16235 |
+ if (!isStandaloneExpr(node)) |
| 16236 |
+ { |
| 16237 |
+ mExprMap[&node] = new TIntermSymbol(var); |
| 16238 |
+ } |
| 16239 |
+ |
| 16240 |
+ return node; |
| 16241 |
+ } |
| 16242 |
+ |
| 16243 |
+ const bool isAssign = IsAssignment(op); |
| 16244 |
+ TIntermTyped *newLeft = pullMappedExpr(left, false); |
| 16245 |
+ TIntermTyped *newRight = pullMappedExpr(right, isAssign); |
| 16246 |
+ |
| 16247 |
+ if (op == TOperator::EOpComma) |
| 16248 |
+ { |
| 16249 |
+ pushBinding(node, *newRight); |
| 16250 |
+ return node; |
| 16251 |
+ } |
| 16252 |
+ else |
| 16253 |
+ { |
| 16254 |
+ TIntermBinary *newNode; |
| 16255 |
+ if (left == newLeft && right == newRight) |
| 16256 |
+ { |
| 16257 |
+ newNode = &node; |
| 16258 |
+ } |
| 16259 |
+ else |
| 16260 |
+ { |
| 16261 |
+ newNode = new TIntermBinary(op, newLeft, newRight); |
| 16262 |
+ } |
| 16263 |
+ pushBinding(node, *newNode); |
| 16264 |
+ return node; |
| 16265 |
+ } |
| 16266 |
+ } |
| 16267 |
+ |
| 16268 |
+ PreResult visitTernaryPre(TIntermTernary &node) override |
| 16269 |
+ { |
| 16270 |
+ PostResult condResult = rebuild(*node.getCondition()); |
| 16271 |
+ ASSERT(condResult.single()); |
| 16272 |
+ |
| 16273 |
+ pushStacks(); |
| 16274 |
+ PostResult thenResult = rebuild(*node.getTrueExpression()); |
| 16275 |
+ ASSERT(thenResult.single()); |
| 16276 |
+ |
| 16277 |
+ pushStacks(); |
| 16278 |
+ PostResult elseResult = rebuild(*node.getFalseExpression()); |
| 16279 |
+ ASSERT(elseResult.single()); |
| 16280 |
+ |
| 16281 |
+ return {node, VisitBits::Post}; |
| 16282 |
+ } |
| 16283 |
+ |
| 16284 |
+ PostResult visitTernaryPost(TIntermTernary &node) override |
| 16285 |
+ { |
| 16286 |
+ TIntermTyped *cond = node.getCondition(); |
| 16287 |
+ TIntermTyped *then = node.getTrueExpression(); |
| 16288 |
+ TIntermTyped *else_ = node.getFalseExpression(); |
| 16289 |
+ |
| 16290 |
+ const Name name = mIdGen.createNewName(""); |
| 16291 |
+ auto *var = |
| 16292 |
+ new TVariable(&mSymbolTable, name.rawName(), &node.getType(), name.symbolType()); |
| 16293 |
+ |
| 16294 |
+ TIntermTyped *newElse = pullMappedExpr(else_, false); |
| 16295 |
+ TIntermBlock *elseBlock = &buildBlockWithTailAssign(*var, *newElse); |
| 16296 |
+ TIntermTyped *newThen = pullMappedExpr(then, true); |
| 16297 |
+ TIntermBlock *thenBlock = &buildBlockWithTailAssign(*var, *newThen); |
| 16298 |
+ TIntermTyped *newCond = pullMappedExpr(cond, true); |
| 16299 |
+ |
| 16300 |
+ pushStmt(*new TIntermDeclaration{var}); |
| 16301 |
+ pushStmt(*new TIntermIfElse(newCond, thenBlock, elseBlock)); |
| 16302 |
+ if (!isStandaloneExpr(node)) |
| 16303 |
+ { |
| 16304 |
+ mExprMap[&node] = new TIntermSymbol(var); |
| 16305 |
+ } |
| 16306 |
+ |
| 16307 |
+ return node; |
| 16308 |
+ } |
| 16309 |
+ |
| 16310 |
+ PostResult visitSwizzlePost(TIntermSwizzle &node) override |
| 16311 |
+ { |
| 16312 |
+ TIntermTyped *expr = node.getOperand(); |
| 16313 |
+ TIntermTyped *newExpr = pullMappedExpr(expr, false); |
| 16314 |
+ if (expr == newExpr) |
| 16315 |
+ { |
| 16316 |
+ pushBinding(node, node); |
| 16317 |
+ } |
| 16318 |
+ else |
| 16319 |
+ { |
| 16320 |
+ pushBinding(node, *new TIntermSwizzle(newExpr, node.getSwizzleOffsets())); |
| 16321 |
+ } |
| 16322 |
+ return node; |
| 16323 |
+ } |
| 16324 |
+ |
| 16325 |
+ PostResult visitAggregatePost(TIntermAggregate &node) override |
| 16326 |
+ { |
| 16327 |
+ TIntermSequence &args = *node.getSequence(); |
| 16328 |
+ for (TIntermNode *&arg : args) |
| 16329 |
+ { |
| 16330 |
+ TIntermTyped *targ = arg->getAsTyped(); |
| 16331 |
+ ASSERT(targ); |
| 16332 |
+ arg = pullMappedExpr(targ, false); |
| 16333 |
+ } |
| 16334 |
+ pushBinding(node, node); |
| 16335 |
+ return node; |
| 16336 |
+ } |
| 16337 |
+ |
| 16338 |
+ PostResult visitPreprocessorDirectivePost(TIntermPreprocessorDirective &node) override |
| 16339 |
+ { |
| 16340 |
+ pushStmt(node); |
| 16341 |
+ return node; |
| 16342 |
+ } |
| 16343 |
+ |
| 16344 |
+ PostResult visitFunctionPrototypePost(TIntermFunctionPrototype &node) override |
| 16345 |
+ { |
| 16346 |
+ if (!getParentFunction()) |
| 16347 |
+ { |
| 16348 |
+ pushStmt(node); |
| 16349 |
+ } |
| 16350 |
+ return node; |
| 16351 |
+ } |
| 16352 |
+ |
| 16353 |
+ PreResult visitCasePre(TIntermCase &node) override |
| 16354 |
+ { |
| 16355 |
+ if (TIntermTyped *cond = node.getCondition()) |
| 16356 |
+ { |
| 16357 |
+ ASSERT(isTerminalExpr(*cond)); |
| 16358 |
+ } |
| 16359 |
+ pushStmt(node); |
| 16360 |
+ return {node, VisitBits::Neither}; |
| 16361 |
+ } |
| 16362 |
+ |
| 16363 |
+ PostResult visitSwitchPost(TIntermSwitch &node) override |
| 16364 |
+ { |
| 16365 |
+ TIntermTyped *init = node.getInit(); |
| 16366 |
+ TIntermTyped *newInit = pullMappedExpr(init, false); |
| 16367 |
+ if (init == newInit) |
| 16368 |
+ { |
| 16369 |
+ pushStmt(node); |
| 16370 |
+ } |
| 16371 |
+ else |
| 16372 |
+ { |
| 16373 |
+ pushStmt(*new TIntermSwitch(newInit, node.getStatementList())); |
| 16374 |
+ } |
| 16375 |
+ |
| 16376 |
+ return node; |
| 16377 |
+ } |
| 16378 |
+ |
| 16379 |
+ PostResult visitFunctionDefinitionPost(TIntermFunctionDefinition &node) override |
| 16380 |
+ { |
| 16381 |
+ pushStmt(node); |
| 16382 |
+ return node; |
| 16383 |
+ } |
| 16384 |
+ |
| 16385 |
+ PostResult visitIfElsePost(TIntermIfElse &node) override |
| 16386 |
+ { |
| 16387 |
+ TIntermTyped *cond = node.getCondition(); |
| 16388 |
+ TIntermTyped *newCond = pullMappedExpr(cond, false); |
| 16389 |
+ if (cond == newCond) |
| 16390 |
+ { |
| 16391 |
+ pushStmt(node); |
| 16392 |
+ } |
| 16393 |
+ else |
| 16394 |
+ { |
| 16395 |
+ pushStmt(*new TIntermIfElse(newCond, node.getTrueBlock(), node.getFalseBlock())); |
| 16396 |
+ } |
| 16397 |
+ return node; |
| 16398 |
+ } |
| 16399 |
+ |
| 16400 |
+ PostResult visitBranchPost(TIntermBranch &node) override |
| 16401 |
+ { |
| 16402 |
+ TIntermTyped *expr = node.getExpression(); |
| 16403 |
+ TIntermTyped *newExpr = pullMappedExpr(expr, false); |
| 16404 |
+ if (expr == newExpr) |
| 16405 |
+ { |
| 16406 |
+ pushStmt(node); |
| 16407 |
+ } |
| 16408 |
+ else |
| 16409 |
+ { |
| 16410 |
+ pushStmt(*new TIntermBranch(node.getFlowOp(), newExpr)); |
| 16411 |
+ } |
| 16412 |
+ return node; |
| 16413 |
+ } |
| 16414 |
+ |
| 16415 |
+ PreResult visitLoopPre(TIntermLoop &node) override |
| 16416 |
+ { |
| 16417 |
+ if (!rebuildInPlace(*node.getBody())) |
| 16418 |
+ { |
| 16419 |
+ LOGIC_ERROR(); |
| 16420 |
+ } |
| 16421 |
+ pushStmt(node); |
| 16422 |
+ return {node, VisitBits::Neither}; |
| 16423 |
+ } |
| 16424 |
+ |
| 16425 |
+ PostResult visitConstantUnionPost(TIntermConstantUnion &node) override |
| 16426 |
+ { |
| 16427 |
+ const TType &type = node.getType(); |
| 16428 |
+ if (!type.isScalar()) |
| 16429 |
+ { |
| 16430 |
+ pushBinding(node, node); |
| 16431 |
+ } |
| 16432 |
+ return node; |
| 16433 |
+ } |
| 16434 |
+ |
| 16435 |
+ PostResult visitGlobalQualifierDeclarationPost(TIntermGlobalQualifierDeclaration &node) override |
| 16436 |
+ { |
| 16437 |
+ ASSERT(false); // These should be scrubbed from AST before rewriter is called. |
| 16438 |
+ pushStmt(node); |
| 16439 |
+ return node; |
| 16440 |
+ } |
| 16441 |
+}; |
| 16442 |
+ |
| 16443 |
+} // anonymous namespace |
| 16444 |
+ |
| 16445 |
+//////////////////////////////////////////////////////////////////////////////// |
| 16446 |
+ |
| 16447 |
+bool sh::SeparateCompoundExpressions(TCompiler &compiler, |
| 16448 |
+ SymbolEnv &symbolEnv, |
| 16449 |
+ IdGen &idGen, |
| 16450 |
+ TIntermBlock &root) |
| 16451 |
+{ |
| 16452 |
+ if (readBoolEnvVar("GMT_DISABLE_SEPARATE_COMPOUND_EXPRESSIONS")) |
| 16453 |
+ { |
| 16454 |
+ return true; |
| 16455 |
+ } |
| 16456 |
+ |
| 16457 |
+ if (!SimplifyLoopConditions(&compiler, &root, &compiler.getSymbolTable())) |
| 16458 |
+ { |
| 16459 |
+ return false; |
| 16460 |
+ } |
| 16461 |
+ |
| 16462 |
+ if (!PrePass(compiler).rebuildRoot(root)) |
| 16463 |
+ { |
| 16464 |
+ return false; |
| 16465 |
+ } |
| 16466 |
+ |
| 16467 |
+ if (!Separator(compiler, symbolEnv, idGen).rebuildRoot(root)) |
| 16468 |
+ { |
| 16469 |
+ return false; |
| 16470 |
+ } |
| 16471 |
+ |
| 16472 |
+ return true; |
| 16473 |
+} |
| 16474 |
diff --git a/src/compiler/translator/TranslatorMetalDirect/SeparateCompoundExpressions.h b/src/compiler/translator/TranslatorMetalDirect/SeparateCompoundExpressions.h |
| 16475 |
new file mode 100644 |
| 16476 |
index 0000000..5e40a55 |
| 16477 |
--- /dev/null |
| 16478 |
+++ b/src/compiler/translator/TranslatorMetalDirect/SeparateCompoundExpressions.h |
| 16479 |
@@ -0,0 +1,47 @@ |
| 16480 |
+// |
| 16481 |
+// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 16482 |
+// Use of this source code is governed by a BSD-style license that can be |
| 16483 |
+// found in the LICENSE file. |
| 16484 |
+// |
| 16485 |
+ |
| 16486 |
+#ifndef COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_SEPARATECOMPOUNDEXPRESSIONS_H_ |
| 16487 |
+#define COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_SEPARATECOMPOUNDEXPRESSIONS_H_ |
| 16488 |
+ |
| 16489 |
+#include "common/angleutils.h" |
| 16490 |
+#include "compiler/translator/Compiler.h" |
| 16491 |
+#include "compiler/translator/TranslatorMetalDirect/IdGen.h" |
| 16492 |
+#include "compiler/translator/TranslatorMetalDirect/SymbolEnv.h" |
| 16493 |
+ |
| 16494 |
+namespace sh |
| 16495 |
+{ |
| 16496 |
+ |
| 16497 |
+// Transforms code to (usually) have most one non-terminal expression per statement. |
| 16498 |
+// This also rewrites (&&), (||), and (?:) into raw if/if-not/if-else statements, respectively. |
| 16499 |
+// |
| 16500 |
+// e.g. |
| 16501 |
+// int x = 6 + foo(y, bar()); |
| 16502 |
+// becomes |
| 16503 |
+// auto _1 = bar(); |
| 16504 |
+// auto _2 = foo(y, _1); |
| 16505 |
+// auto _3 = 6 + _2; |
| 16506 |
+// int x = _3; |
| 16507 |
+// |
| 16508 |
+// WARNING: |
| 16509 |
+// - This does not rewrite object indexing operators as a whole (e.g. foo.x, foo[x]), but will |
| 16510 |
+// rewrite the arguments to the operator (when applicable). |
| 16511 |
+// e.g. |
| 16512 |
+// foo(getVec()[i + 2] + 1); |
| 16513 |
+// becomes |
| 16514 |
+// auto _1 = getVec(); |
| 16515 |
+// auto _2 = i + 2; |
| 16516 |
+// auto _3 = _1[_2] + 1; // Index operator remains in (+) expr here. |
| 16517 |
+// foo(_3); |
| 16518 |
+// |
| 16519 |
+ANGLE_NO_DISCARD bool SeparateCompoundExpressions(TCompiler &compiler, |
| 16520 |
+ SymbolEnv &symbolEnv, |
| 16521 |
+ IdGen &idGen, |
| 16522 |
+ TIntermBlock &root); |
| 16523 |
+ |
| 16524 |
+} // namespace sh |
| 16525 |
+ |
| 16526 |
+#endif // COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_SEPARATECOMPOUNDEXPRESSIONS_H_ |
| 16527 |
diff --git a/src/compiler/translator/TranslatorMetalDirect/SeparateCompoundStructDeclarations.cpp b/src/compiler/translator/TranslatorMetalDirect/SeparateCompoundStructDeclarations.cpp |
| 16528 |
new file mode 100644 |
| 16529 |
index 0000000..4ba8c6d |
| 16530 |
--- /dev/null |
| 16531 |
+++ b/src/compiler/translator/TranslatorMetalDirect/SeparateCompoundStructDeclarations.cpp |
| 16532 |
@@ -0,0 +1,77 @@ |
| 16533 |
+// |
| 16534 |
+// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 16535 |
+// Use of this source code is governed by a BSD-style license that can be |
| 16536 |
+// found in the LICENSE file. |
| 16537 |
+// |
| 16538 |
+ |
| 16539 |
+#include <algorithm> |
| 16540 |
+ |
| 16541 |
+#include "compiler/translator/TranslatorMetalDirect/SeparateCompoundStructDeclarations.h" |
| 16542 |
+#include "compiler/translator/tree_ops/SeparateDeclarations.h" |
| 16543 |
+#include "compiler/translator/tree_util/IntermTraverse.h" |
| 16544 |
+ |
| 16545 |
+using namespace sh; |
| 16546 |
+ |
| 16547 |
+//////////////////////////////////////////////////////////////////////////////// |
| 16548 |
+ |
| 16549 |
+namespace |
| 16550 |
+{ |
| 16551 |
+ |
| 16552 |
+class Separator : public TIntermTraverser |
| 16553 |
+{ |
| 16554 |
+ public: |
| 16555 |
+ Separator(TSymbolTable &symbolTable) : TIntermTraverser(false, false, true, &symbolTable) {} |
| 16556 |
+ |
| 16557 |
+ bool visitDeclaration(Visit, TIntermDeclaration *declNode) override |
| 16558 |
+ { |
| 16559 |
+ ASSERT(declNode->getChildCount() == 1); |
| 16560 |
+ TIntermNode &node = *declNode->getChildNode(0); |
| 16561 |
+ |
| 16562 |
+ if (TIntermSymbol *symbolNode = node.getAsSymbolNode()) |
| 16563 |
+ { |
| 16564 |
+ const TVariable &var = symbolNode->variable(); |
| 16565 |
+ const TType &type = var.getType(); |
| 16566 |
+ const SymbolType symbolType = var.symbolType(); |
| 16567 |
+ if (type.isStructSpecifier() && symbolType != SymbolType::Empty) |
| 16568 |
+ { |
| 16569 |
+ const TStructure *structure = type.getStruct(); |
| 16570 |
+ auto *structVar = new TVariable(mSymbolTable, ImmutableString(""), |
| 16571 |
+ new TType(structure, true), SymbolType::Empty); |
| 16572 |
+ |
| 16573 |
+ auto *instanceType = new TType(structure, false); |
| 16574 |
+ instanceType->setQualifier(type.getQualifier()); |
| 16575 |
+ auto *instanceVar = new TVariable(mSymbolTable, var.name(), instanceType, |
| 16576 |
+ symbolType, var.extension()); |
| 16577 |
+ |
| 16578 |
+ TIntermSequence replacements; |
| 16579 |
+ replacements.push_back(new TIntermSymbol(structVar)); |
| 16580 |
+ replacements.push_back(new TIntermSymbol(instanceVar)); |
| 16581 |
+ mMultiReplacements.push_back( |
| 16582 |
+ NodeReplaceWithMultipleEntry(declNode, symbolNode, std::move(replacements))); |
| 16583 |
+ } |
| 16584 |
+ } |
| 16585 |
+ |
| 16586 |
+ return false; |
| 16587 |
+ } |
| 16588 |
+}; |
| 16589 |
+ |
| 16590 |
+} // anonymous namespace |
| 16591 |
+ |
| 16592 |
+//////////////////////////////////////////////////////////////////////////////// |
| 16593 |
+ |
| 16594 |
+bool sh::SeparateCompoundStructDeclarations(TCompiler &compiler, TIntermBlock &root) |
| 16595 |
+{ |
| 16596 |
+ Separator separator(compiler.getSymbolTable()); |
| 16597 |
+ root.traverse(&separator); |
| 16598 |
+ if (!separator.updateTree(&compiler, &root)) |
| 16599 |
+ { |
| 16600 |
+ return false; |
| 16601 |
+ } |
| 16602 |
+ |
| 16603 |
+ if (!SeparateDeclarations(&compiler, &root)) |
| 16604 |
+ { |
| 16605 |
+ return false; |
| 16606 |
+ } |
| 16607 |
+ |
| 16608 |
+ return true; |
| 16609 |
+} |
| 16610 |
diff --git a/src/compiler/translator/TranslatorMetalDirect/SeparateCompoundStructDeclarations.h b/src/compiler/translator/TranslatorMetalDirect/SeparateCompoundStructDeclarations.h |
| 16611 |
new file mode 100644 |
| 16612 |
index 0000000..0712e80 |
| 16613 |
--- /dev/null |
| 16614 |
+++ b/src/compiler/translator/TranslatorMetalDirect/SeparateCompoundStructDeclarations.h |
| 16615 |
@@ -0,0 +1,24 @@ |
| 16616 |
+// |
| 16617 |
+// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 16618 |
+// Use of this source code is governed by a BSD-style license that can be |
| 16619 |
+// found in the LICENSE file. |
| 16620 |
+// |
| 16621 |
+ |
| 16622 |
+#ifndef COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_SEPARATECOMPOUNDSTRUCTDECLARATIONS_H_ |
| 16623 |
+#define COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_SEPARATECOMPOUNDSTRUCTDECLARATIONS_H_ |
| 16624 |
+ |
| 16625 |
+#include "common/angleutils.h" |
| 16626 |
+#include "compiler/translator/Compiler.h" |
| 16627 |
+ |
| 16628 |
+namespace sh |
| 16629 |
+{ |
| 16630 |
+ |
| 16631 |
+// Example: |
| 16632 |
+// struct Foo { int x; } foo; |
| 16633 |
+// Becomes: |
| 16634 |
+// struct Foo {int x; }; Foo foo; |
| 16635 |
+ANGLE_NO_DISCARD bool SeparateCompoundStructDeclarations(TCompiler &compiler, TIntermBlock &root); |
| 16636 |
+ |
| 16637 |
+} // namespace sh |
| 16638 |
+ |
| 16639 |
+#endif // COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_SEPARATECOMPOUNDSTRUCTDECLARATIONS_H_ |
| 16640 |
diff --git a/src/compiler/translator/TranslatorMetalDirect/SkippingTraverser.h b/src/compiler/translator/TranslatorMetalDirect/SkippingTraverser.h |
| 16641 |
new file mode 100644 |
| 16642 |
index 0000000..ff49dad |
| 16643 |
--- /dev/null |
| 16644 |
+++ b/src/compiler/translator/TranslatorMetalDirect/SkippingTraverser.h |
| 16645 |
@@ -0,0 +1,47 @@ |
| 16646 |
+// |
| 16647 |
+// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 16648 |
+// Use of this source code is governed by a BSD-style license that can be |
| 16649 |
+// found in the LICENSE file. |
| 16650 |
+// |
| 16651 |
+ |
| 16652 |
+#ifndef COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_SKIPPINGTRAVERSER_H_ |
| 16653 |
+#define COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_SKIPPINGTRAVERSER_H_ |
| 16654 |
+ |
| 16655 |
+#include "compiler/translator/tree_util/IntermTraverse.h" |
| 16656 |
+ |
| 16657 |
+namespace sh |
| 16658 |
+{ |
| 16659 |
+ |
| 16660 |
+// A TIntermTraverser that skips traversing childen by default. |
| 16661 |
+class SkippingTraverser : public TIntermTraverser |
| 16662 |
+{ |
| 16663 |
+ public: |
| 16664 |
+ SkippingTraverser(bool preVisit_, |
| 16665 |
+ bool inVisit_, |
| 16666 |
+ bool postVisit_, |
| 16667 |
+ TSymbolTable *symbolTable = nullptr) |
| 16668 |
+ : TIntermTraverser(preVisit_, inVisit_, postVisit_, symbolTable) |
| 16669 |
+ {} |
| 16670 |
+ |
| 16671 |
+ bool visitSwizzle(Visit, TIntermSwizzle *) { return false; } |
| 16672 |
+ bool visitUnary(Visit, TIntermUnary *) { return false; } |
| 16673 |
+ bool visitBinary(Visit, TIntermBinary *) { return false; } |
| 16674 |
+ bool visitTernary(Visit, TIntermTernary *) { return false; } |
| 16675 |
+ bool visitIfElse(Visit, TIntermIfElse *) { return false; } |
| 16676 |
+ bool visitSwitch(Visit, TIntermSwitch *) { return false; } |
| 16677 |
+ bool visitCase(Visit, TIntermCase *) { return false; } |
| 16678 |
+ bool visitFunctionDefinition(Visit, TIntermFunctionDefinition *) { return false; } |
| 16679 |
+ bool visitAggregate(Visit, TIntermAggregate *) { return false; } |
| 16680 |
+ bool visitBlock(Visit, TIntermBlock *) { return false; } |
| 16681 |
+ bool visitDeclaration(Visit, TIntermDeclaration *) { return false; } |
| 16682 |
+ bool visitLoop(Visit, TIntermLoop *) { return false; } |
| 16683 |
+ bool visitBranch(Visit, TIntermBranch *) { return false; } |
| 16684 |
+ bool visitGlobalQualifierDeclaration(Visit, TIntermGlobalQualifierDeclaration *) |
| 16685 |
+ { |
| 16686 |
+ return false; |
| 16687 |
+ } |
| 16688 |
+}; |
| 16689 |
+ |
| 16690 |
+} // namespace sh |
| 16691 |
+ |
| 16692 |
+#endif // COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_SKIPPINGTRAVERSER_H_ |
| 16693 |
diff --git a/src/compiler/translator/TranslatorMetalDirect/SymbolEnv.cpp b/src/compiler/translator/TranslatorMetalDirect/SymbolEnv.cpp |
| 16694 |
new file mode 100644 |
| 16695 |
index 0000000..4753dac |
| 16696 |
--- /dev/null |
| 16697 |
+++ b/src/compiler/translator/TranslatorMetalDirect/SymbolEnv.cpp |
| 16698 |
@@ -0,0 +1,681 @@ |
| 16699 |
+// |
| 16700 |
+// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 16701 |
+// Use of this source code is governed by a BSD-style license that can be |
| 16702 |
+// found in the LICENSE file. |
| 16703 |
+// |
| 16704 |
+ |
| 16705 |
+#include <algorithm> |
| 16706 |
+#include <limits> |
| 16707 |
+ |
| 16708 |
+#include "compiler/translator/ImmutableStringBuilder.h" |
| 16709 |
+#include "compiler/translator/TranslatorMetalDirect/AstHelpers.h" |
| 16710 |
+#include "compiler/translator/TranslatorMetalDirect/Debug.h" |
| 16711 |
+#include "compiler/translator/TranslatorMetalDirect/SymbolEnv.h" |
| 16712 |
+#include "compiler/translator/tree_util/IntermRebuild.h" |
| 16713 |
+ |
| 16714 |
+using namespace sh; |
| 16715 |
+ |
| 16716 |
+//////////////////////////////////////////////////////////////////////////////// |
| 16717 |
+ |
| 16718 |
+constexpr AddressSpace kAddressSpaces[] = { |
| 16719 |
+ AddressSpace::Constant, |
| 16720 |
+ AddressSpace::Device, |
| 16721 |
+ AddressSpace::Thread, |
| 16722 |
+}; |
| 16723 |
+ |
| 16724 |
+char const *sh::toString(AddressSpace space) |
| 16725 |
+{ |
| 16726 |
+ switch (space) |
| 16727 |
+ { |
| 16728 |
+ case AddressSpace::Constant: |
| 16729 |
+ return "constant"; |
| 16730 |
+ case AddressSpace::Device: |
| 16731 |
+ return "device"; |
| 16732 |
+ case AddressSpace::Thread: |
| 16733 |
+ return "thread"; |
| 16734 |
+ } |
| 16735 |
+} |
| 16736 |
+ |
| 16737 |
+//////////////////////////////////////////////////////////////////////////////// |
| 16738 |
+ |
| 16739 |
+using NameToStruct = std::map<Name, const TStructure *>; |
| 16740 |
+ |
| 16741 |
+class StructFinder : TIntermRebuild |
| 16742 |
+{ |
| 16743 |
+ NameToStruct nameToStruct; |
| 16744 |
+ |
| 16745 |
+ StructFinder(TCompiler &compiler) : TIntermRebuild(compiler, true, false) {} |
| 16746 |
+ |
| 16747 |
+ PreResult visitDeclarationPre(TIntermDeclaration &node) override |
| 16748 |
+ { |
| 16749 |
+ Declaration decl = ViewDeclaration(node); |
| 16750 |
+ const TVariable &var = decl.symbol.variable(); |
| 16751 |
+ const TType &type = var.getType(); |
| 16752 |
+ |
| 16753 |
+ if (var.symbolType() == SymbolType::Empty && type.isStructSpecifier()) |
| 16754 |
+ { |
| 16755 |
+ const TStructure *s = type.getStruct(); |
| 16756 |
+ ASSERT(s); |
| 16757 |
+ const Name name(*s); |
| 16758 |
+ const TStructure *&z = nameToStruct[name]; |
| 16759 |
+ ASSERT(!z); |
| 16760 |
+ z = s; |
| 16761 |
+ } |
| 16762 |
+ |
| 16763 |
+ return node; |
| 16764 |
+ } |
| 16765 |
+ |
| 16766 |
+ PreResult visitFunctionDefinitionPre(TIntermFunctionDefinition &node) override |
| 16767 |
+ { |
| 16768 |
+ return {node, VisitBits::Neither}; |
| 16769 |
+ } |
| 16770 |
+ |
| 16771 |
+ public: |
| 16772 |
+ static NameToStruct FindStructs(TCompiler &compiler, TIntermBlock &root) |
| 16773 |
+ { |
| 16774 |
+ StructFinder finder(compiler); |
| 16775 |
+ if (!finder.rebuildRoot(root)) |
| 16776 |
+ { |
| 16777 |
+ LOGIC_ERROR(); |
| 16778 |
+ } |
| 16779 |
+ return std::move(finder.nameToStruct); |
| 16780 |
+ } |
| 16781 |
+}; |
| 16782 |
+ |
| 16783 |
+//////////////////////////////////////////////////////////////////////////////// |
| 16784 |
+ |
| 16785 |
+TemplateArg::TemplateArg(bool value) : mKind(Kind::Bool), mValue(value) {} |
| 16786 |
+ |
| 16787 |
+TemplateArg::TemplateArg(int value) : mKind(Kind::Int), mValue(value) {} |
| 16788 |
+ |
| 16789 |
+TemplateArg::TemplateArg(unsigned value) : mKind(Kind::UInt), mValue(value) {} |
| 16790 |
+ |
| 16791 |
+TemplateArg::TemplateArg(const TType &value) : mKind(Kind::Type), mValue(value) {} |
| 16792 |
+ |
| 16793 |
+bool TemplateArg::operator==(const TemplateArg &other) const |
| 16794 |
+{ |
| 16795 |
+ if (mKind != other.mKind) |
| 16796 |
+ { |
| 16797 |
+ return false; |
| 16798 |
+ } |
| 16799 |
+ |
| 16800 |
+ switch (mKind) |
| 16801 |
+ { |
| 16802 |
+ case Kind::Bool: |
| 16803 |
+ return mValue.b == other.mValue.b; |
| 16804 |
+ case Kind::Int: |
| 16805 |
+ return mValue.i == other.mValue.i; |
| 16806 |
+ case Kind::UInt: |
| 16807 |
+ return mValue.u == other.mValue.u; |
| 16808 |
+ case Kind::Type: |
| 16809 |
+ return *mValue.t == *other.mValue.t; |
| 16810 |
+ } |
| 16811 |
+} |
| 16812 |
+ |
| 16813 |
+bool TemplateArg::operator<(const TemplateArg &other) const |
| 16814 |
+{ |
| 16815 |
+ if (mKind < other.mKind) |
| 16816 |
+ { |
| 16817 |
+ return true; |
| 16818 |
+ } |
| 16819 |
+ |
| 16820 |
+ if (mKind > other.mKind) |
| 16821 |
+ { |
| 16822 |
+ return false; |
| 16823 |
+ } |
| 16824 |
+ |
| 16825 |
+ switch (mKind) |
| 16826 |
+ { |
| 16827 |
+ case Kind::Bool: |
| 16828 |
+ return mValue.b < other.mValue.b; |
| 16829 |
+ case Kind::Int: |
| 16830 |
+ return mValue.i < other.mValue.i; |
| 16831 |
+ case Kind::UInt: |
| 16832 |
+ return mValue.u < other.mValue.u; |
| 16833 |
+ case Kind::Type: |
| 16834 |
+ return *mValue.t < *other.mValue.t; |
| 16835 |
+ } |
| 16836 |
+} |
| 16837 |
+ |
| 16838 |
+//////////////////////////////////////////////////////////////////////////////// |
| 16839 |
+ |
| 16840 |
+bool SymbolEnv::TemplateName::operator==(const TemplateName &other) const |
| 16841 |
+{ |
| 16842 |
+ return baseName == other.baseName && templateArgs == other.templateArgs; |
| 16843 |
+} |
| 16844 |
+ |
| 16845 |
+bool SymbolEnv::TemplateName::operator<(const TemplateName &other) const |
| 16846 |
+{ |
| 16847 |
+ if (baseName < other.baseName) |
| 16848 |
+ { |
| 16849 |
+ return true; |
| 16850 |
+ } |
| 16851 |
+ if (other.baseName < baseName) |
| 16852 |
+ { |
| 16853 |
+ return false; |
| 16854 |
+ } |
| 16855 |
+ return templateArgs < other.templateArgs; |
| 16856 |
+} |
| 16857 |
+ |
| 16858 |
+bool SymbolEnv::TemplateName::empty() const |
| 16859 |
+{ |
| 16860 |
+ return baseName.empty() && templateArgs.empty(); |
| 16861 |
+} |
| 16862 |
+ |
| 16863 |
+void SymbolEnv::TemplateName::clear() |
| 16864 |
+{ |
| 16865 |
+ baseName = Name(); |
| 16866 |
+ templateArgs.clear(); |
| 16867 |
+} |
| 16868 |
+ |
| 16869 |
+Name SymbolEnv::TemplateName::fullName(std::string &buffer) const |
| 16870 |
+{ |
| 16871 |
+ ASSERT(buffer.empty()); |
| 16872 |
+ |
| 16873 |
+ if (templateArgs.empty()) |
| 16874 |
+ { |
| 16875 |
+ return baseName; |
| 16876 |
+ } |
| 16877 |
+ |
| 16878 |
+ static constexpr size_t n = std::max({ |
| 16879 |
+ std::numeric_limits<unsigned>::digits10, // |
| 16880 |
+ std::numeric_limits<int>::digits10, // |
| 16881 |
+ 5, // max_length("true", "false") |
| 16882 |
+ }); |
| 16883 |
+ |
| 16884 |
+ buffer.reserve(baseName.rawName().length() + (n + 2) * templateArgs.size() + 1); |
| 16885 |
+ buffer += baseName.rawName().data(); |
| 16886 |
+ |
| 16887 |
+ if (!templateArgs.empty()) |
| 16888 |
+ { |
| 16889 |
+ buffer += "<"; |
| 16890 |
+ |
| 16891 |
+ bool first = true; |
| 16892 |
+ char argBuffer[n + 1]; |
| 16893 |
+ for (const TemplateArg &arg : templateArgs) |
| 16894 |
+ { |
| 16895 |
+ if (first) |
| 16896 |
+ { |
| 16897 |
+ first = false; |
| 16898 |
+ } |
| 16899 |
+ else |
| 16900 |
+ { |
| 16901 |
+ buffer += ", "; |
| 16902 |
+ } |
| 16903 |
+ |
| 16904 |
+ const TemplateArg::Value value = arg.value(); |
| 16905 |
+ const TemplateArg::Kind kind = arg.kind(); |
| 16906 |
+ switch (kind) |
| 16907 |
+ { |
| 16908 |
+ case TemplateArg::Kind::Bool: |
| 16909 |
+ if (value.b) |
| 16910 |
+ { |
| 16911 |
+ buffer += "true"; |
| 16912 |
+ } |
| 16913 |
+ else |
| 16914 |
+ { |
| 16915 |
+ buffer += "false"; |
| 16916 |
+ } |
| 16917 |
+ break; |
| 16918 |
+ |
| 16919 |
+ case TemplateArg::Kind::Int: |
| 16920 |
+ sprintf(argBuffer, "%i", value.i); |
| 16921 |
+ buffer += argBuffer; |
| 16922 |
+ break; |
| 16923 |
+ |
| 16924 |
+ case TemplateArg::Kind::UInt: |
| 16925 |
+ sprintf(argBuffer, "%u", value.u); |
| 16926 |
+ buffer += argBuffer; |
| 16927 |
+ break; |
| 16928 |
+ |
| 16929 |
+ case TemplateArg::Kind::Type: |
| 16930 |
+ { |
| 16931 |
+ const TType &type = *value.t; |
| 16932 |
+ if (const TStructure *s = type.getStruct()) |
| 16933 |
+ { |
| 16934 |
+ buffer += s->name().data(); |
| 16935 |
+ } |
| 16936 |
+ else if (HasScalarBasicType(type)) |
| 16937 |
+ { |
| 16938 |
+ ASSERT(!type.isArray()); // TODO |
| 16939 |
+ buffer += type.getBasicString(); |
| 16940 |
+ if (type.isVector()) |
| 16941 |
+ { |
| 16942 |
+ sprintf(argBuffer, "%i", type.getNominalSize()); |
| 16943 |
+ buffer += argBuffer; |
| 16944 |
+ } |
| 16945 |
+ else if (type.isMatrix()) |
| 16946 |
+ { |
| 16947 |
+ sprintf(argBuffer, "%i", type.getCols()); |
| 16948 |
+ buffer += argBuffer; |
| 16949 |
+ buffer += "x"; |
| 16950 |
+ sprintf(argBuffer, "%i", type.getRows()); |
| 16951 |
+ buffer += argBuffer; |
| 16952 |
+ } |
| 16953 |
+ } |
| 16954 |
+ } |
| 16955 |
+ break; |
| 16956 |
+ } |
| 16957 |
+ } |
| 16958 |
+ |
| 16959 |
+ buffer += ">"; |
| 16960 |
+ } |
| 16961 |
+ |
| 16962 |
+ const ImmutableString name(buffer); |
| 16963 |
+ buffer.clear(); |
| 16964 |
+ |
| 16965 |
+ return Name(name, baseName.symbolType()); |
| 16966 |
+} |
| 16967 |
+ |
| 16968 |
+void SymbolEnv::TemplateName::assign(const Name &name, size_t argCount, const TemplateArg *args) |
| 16969 |
+{ |
| 16970 |
+ baseName = name; |
| 16971 |
+ templateArgs.clear(); |
| 16972 |
+ for (size_t i = 0; i < argCount; ++i) |
| 16973 |
+ { |
| 16974 |
+ templateArgs.push_back(args[i]); |
| 16975 |
+ } |
| 16976 |
+} |
| 16977 |
+ |
| 16978 |
+//////////////////////////////////////////////////////////////////////////////// |
| 16979 |
+ |
| 16980 |
+SymbolEnv::SymbolEnv(TCompiler &compiler, TIntermBlock &root) |
| 16981 |
+ : mSymbolTable(compiler.getSymbolTable()), |
| 16982 |
+ mNameToStruct(StructFinder::FindStructs(compiler, root)) |
| 16983 |
+{} |
| 16984 |
+ |
| 16985 |
+const TStructure &SymbolEnv::remap(const TStructure &s) const |
| 16986 |
+{ |
| 16987 |
+ const Name name(s); |
| 16988 |
+ auto iter = mNameToStruct.find(name); |
| 16989 |
+ if (iter == mNameToStruct.end()) |
| 16990 |
+ { |
| 16991 |
+ return s; |
| 16992 |
+ } |
| 16993 |
+ const TStructure &z = *iter->second; |
| 16994 |
+ return z; |
| 16995 |
+} |
| 16996 |
+ |
| 16997 |
+const TStructure *SymbolEnv::remap(const TStructure *s) const |
| 16998 |
+{ |
| 16999 |
+ if (s) |
| 17000 |
+ { |
| 17001 |
+ return &remap(*s); |
| 17002 |
+ } |
| 17003 |
+ return nullptr; |
| 17004 |
+} |
| 17005 |
+ |
| 17006 |
+const TFunction &SymbolEnv::getFunctionOverloadImpl() |
| 17007 |
+{ |
| 17008 |
+ ASSERT(!mReusableSigBuffer.empty()); |
| 17009 |
+ |
| 17010 |
+ SigToFunc &sigToFunc = mOverloads[mReusableTemplateNameBuffer]; |
| 17011 |
+ TFunction *&func = sigToFunc[mReusableSigBuffer]; |
| 17012 |
+ |
| 17013 |
+ if (!func) |
| 17014 |
+ { |
| 17015 |
+ const TType &returnType = mReusableSigBuffer.back(); |
| 17016 |
+ mReusableSigBuffer.pop_back(); |
| 17017 |
+ |
| 17018 |
+ const Name name = mReusableTemplateNameBuffer.fullName(mReusableStringBuffer); |
| 17019 |
+ |
| 17020 |
+ func = new TFunction(&mSymbolTable, name.rawName(), name.symbolType(), &returnType, false); |
| 17021 |
+ for (const TType ¶mType : mReusableSigBuffer) |
| 17022 |
+ { |
| 17023 |
+ func->addParameter( |
| 17024 |
+ new TVariable(&mSymbolTable, kEmptyImmutableString, ¶mType, SymbolType::Empty)); |
| 17025 |
+ } |
| 17026 |
+ } |
| 17027 |
+ |
| 17028 |
+ mReusableSigBuffer.clear(); |
| 17029 |
+ mReusableTemplateNameBuffer.clear(); |
| 17030 |
+ |
| 17031 |
+ return *func; |
| 17032 |
+} |
| 17033 |
+ |
| 17034 |
+const TFunction &SymbolEnv::getFunctionOverload(const Name &name, |
| 17035 |
+ const TType &returnType, |
| 17036 |
+ size_t paramCount, |
| 17037 |
+ const TType **paramTypes, |
| 17038 |
+ size_t templateArgCount, |
| 17039 |
+ const TemplateArg *templateArgs) |
| 17040 |
+{ |
| 17041 |
+ ASSERT(mReusableSigBuffer.empty()); |
| 17042 |
+ ASSERT(mReusableTemplateNameBuffer.empty()); |
| 17043 |
+ |
| 17044 |
+ for (size_t i = 0; i < paramCount; ++i) |
| 17045 |
+ { |
| 17046 |
+ mReusableSigBuffer.push_back(*paramTypes[i]); |
| 17047 |
+ } |
| 17048 |
+ mReusableSigBuffer.push_back(returnType); |
| 17049 |
+ mReusableTemplateNameBuffer.assign(name, templateArgCount, templateArgs); |
| 17050 |
+ return getFunctionOverloadImpl(); |
| 17051 |
+} |
| 17052 |
+ |
| 17053 |
+TIntermAggregate &SymbolEnv::callFunctionOverload(const Name &name, |
| 17054 |
+ const TType &returnType, |
| 17055 |
+ TIntermSequence &args, |
| 17056 |
+ size_t templateArgCount, |
| 17057 |
+ const TemplateArg *templateArgs) |
| 17058 |
+{ |
| 17059 |
+ ASSERT(mReusableSigBuffer.empty()); |
| 17060 |
+ ASSERT(mReusableTemplateNameBuffer.empty()); |
| 17061 |
+ |
| 17062 |
+ for (TIntermNode *arg : args) |
| 17063 |
+ { |
| 17064 |
+ TIntermTyped *targ = arg->getAsTyped(); |
| 17065 |
+ ASSERT(targ); |
| 17066 |
+ mReusableSigBuffer.push_back(targ->getType()); |
| 17067 |
+ } |
| 17068 |
+ mReusableSigBuffer.push_back(returnType); |
| 17069 |
+ mReusableTemplateNameBuffer.assign(name, templateArgCount, templateArgs); |
| 17070 |
+ const TFunction &func = getFunctionOverloadImpl(); |
| 17071 |
+ return *TIntermAggregate::CreateRawFunctionCall(func, &args); |
| 17072 |
+} |
| 17073 |
+ |
| 17074 |
+const TStructure &SymbolEnv::newStructure(const Name &name, TFieldList &fields) |
| 17075 |
+{ |
| 17076 |
+ ASSERT(name.symbolType() == SymbolType::AngleInternal); |
| 17077 |
+ |
| 17078 |
+ TStructure *&s = mAngleStructs[name.rawName()]; |
| 17079 |
+ ASSERT(!s); |
| 17080 |
+ s = new TStructure(&mSymbolTable, name.rawName(), &fields, name.symbolType()); |
| 17081 |
+ return *s; |
| 17082 |
+} |
| 17083 |
+ |
| 17084 |
+const TStructure &SymbolEnv::getTextureEnv(TBasicType samplerType) |
| 17085 |
+{ |
| 17086 |
+ ASSERT(IsSampler(samplerType)); |
| 17087 |
+ const TStructure *&env = mTextureEnvs[samplerType]; |
| 17088 |
+ if (env == nullptr) |
| 17089 |
+ { |
| 17090 |
+ auto *textureType = new TType(samplerType); |
| 17091 |
+ auto *texture = new TField(textureType, ImmutableString("texture"), kNoSourceLoc, |
| 17092 |
+ SymbolType::UserDefined); |
| 17093 |
+ markAsPointer(*texture, AddressSpace::Thread); |
| 17094 |
+ |
| 17095 |
+ auto *sampler = |
| 17096 |
+ new TField(new TType(&getSamplerStruct(), false), ImmutableString("sampler"), |
| 17097 |
+ kNoSourceLoc, SymbolType::UserDefined); |
| 17098 |
+ markAsPointer(*sampler, AddressSpace::Thread); |
| 17099 |
+ |
| 17100 |
+ std::string envName; |
| 17101 |
+ envName += "TextureEnv<"; |
| 17102 |
+ envName += GetTextureTypeName(samplerType).rawName().data(); |
| 17103 |
+ envName += ">"; |
| 17104 |
+ |
| 17105 |
+ env = &newStructure(Name(envName, SymbolType::AngleInternal), |
| 17106 |
+ *new TFieldList{texture, sampler}); |
| 17107 |
+ } |
| 17108 |
+ return *env; |
| 17109 |
+} |
| 17110 |
+ |
| 17111 |
+const TStructure &SymbolEnv::getSamplerStruct() |
| 17112 |
+{ |
| 17113 |
+ if (!mSampler) |
| 17114 |
+ { |
| 17115 |
+ mSampler = new TStructure(&mSymbolTable, ImmutableString("metal::sampler"), |
| 17116 |
+ new TFieldList(), SymbolType::UserDefined); |
| 17117 |
+ } |
| 17118 |
+ return *mSampler; |
| 17119 |
+} |
| 17120 |
+ |
| 17121 |
+void SymbolEnv::markSpace(VarField x, |
| 17122 |
+ AddressSpace space, |
| 17123 |
+ std::unordered_map<VarField, AddressSpace> &map) |
| 17124 |
+{ |
| 17125 |
+ // It is in principle permissible to have references to pointers or multiple pointers, but this |
| 17126 |
+ // is not required for now and would require code changes to get right. |
| 17127 |
+ ASSERT(!isPointer(x)); |
| 17128 |
+ ASSERT(!isReference(x)); |
| 17129 |
+ |
| 17130 |
+ map[x] = space; |
| 17131 |
+} |
| 17132 |
+ |
| 17133 |
+const AddressSpace *SymbolEnv::isSpace(VarField x, |
| 17134 |
+ const std::unordered_map<VarField, AddressSpace> &map) const |
| 17135 |
+{ |
| 17136 |
+ const auto iter = map.find(x); |
| 17137 |
+ if (iter == map.end()) |
| 17138 |
+ { |
| 17139 |
+ return nullptr; |
| 17140 |
+ } |
| 17141 |
+ const AddressSpace space = iter->second; |
| 17142 |
+ const auto index = static_cast<std::underlying_type_t<AddressSpace>>(space); |
| 17143 |
+ return &kAddressSpaces[index]; |
| 17144 |
+} |
| 17145 |
+ |
| 17146 |
+void SymbolEnv::markAsPointer(VarField x, AddressSpace space) |
| 17147 |
+{ |
| 17148 |
+ return markSpace(x, space, mPointers); |
| 17149 |
+} |
| 17150 |
+ |
| 17151 |
+void SymbolEnv::markAsReference(VarField x, AddressSpace space) |
| 17152 |
+{ |
| 17153 |
+ return markSpace(x, space, mReferences); |
| 17154 |
+} |
| 17155 |
+ |
| 17156 |
+const AddressSpace *SymbolEnv::isPointer(VarField x) const |
| 17157 |
+{ |
| 17158 |
+ return isSpace(x, mPointers); |
| 17159 |
+} |
| 17160 |
+ |
| 17161 |
+const AddressSpace *SymbolEnv::isReference(VarField x) const |
| 17162 |
+{ |
| 17163 |
+ return isSpace(x, mReferences); |
| 17164 |
+} |
| 17165 |
+ |
| 17166 |
+void SymbolEnv::markAsPacked(const TField &field) |
| 17167 |
+{ |
| 17168 |
+ mPackedFields.insert(&field); |
| 17169 |
+} |
| 17170 |
+ |
| 17171 |
+bool SymbolEnv::isPacked(const TField &field) const |
| 17172 |
+{ |
| 17173 |
+ return mPackedFields.find(&field) != mPackedFields.end(); |
| 17174 |
+} |
| 17175 |
+ |
| 17176 |
+static TBasicType GetTextureBasicType(TBasicType basicType) |
| 17177 |
+{ |
| 17178 |
+ ASSERT(IsSampler(basicType)); |
| 17179 |
+ |
| 17180 |
+ switch (basicType) |
| 17181 |
+ { |
| 17182 |
+ case EbtSampler2D: |
| 17183 |
+ case EbtSampler3D: |
| 17184 |
+ case EbtSamplerCube: |
| 17185 |
+ case EbtSampler2DArray: |
| 17186 |
+ case EbtSamplerExternalOES: |
| 17187 |
+ case EbtSamplerExternal2DY2YEXT: |
| 17188 |
+ case EbtSampler2DRect: |
| 17189 |
+ case EbtSampler2DMS: |
| 17190 |
+ case EbtSampler2DMSArray: |
| 17191 |
+ case EbtSamplerVideoWEBGL: |
| 17192 |
+ case EbtSampler2DShadow: |
| 17193 |
+ case EbtSamplerCubeShadow: |
| 17194 |
+ case EbtSampler2DArrayShadow: |
| 17195 |
+ case EbtSampler1D: |
| 17196 |
+ case EbtSampler1DArray: |
| 17197 |
+ case EbtSampler1DArrayShadow: |
| 17198 |
+ case EbtSamplerBuffer: |
| 17199 |
+ case EbtSamplerCubeArray: |
| 17200 |
+ case EbtSamplerCubeArrayShadow: |
| 17201 |
+ case EbtSampler1DShadow: |
| 17202 |
+ case EbtSampler2DRectShadow: |
| 17203 |
+ return TBasicType::EbtFloat; |
| 17204 |
+ |
| 17205 |
+ case EbtISampler2D: |
| 17206 |
+ case EbtISampler3D: |
| 17207 |
+ case EbtISamplerCube: |
| 17208 |
+ case EbtISampler2DArray: |
| 17209 |
+ case EbtISampler2DMS: |
| 17210 |
+ case EbtISampler2DMSArray: |
| 17211 |
+ case EbtISampler1D: |
| 17212 |
+ case EbtISampler1DArray: |
| 17213 |
+ case EbtISampler2DRect: |
| 17214 |
+ case EbtISamplerBuffer: |
| 17215 |
+ case EbtISamplerCubeArray: |
| 17216 |
+ return TBasicType::EbtInt; |
| 17217 |
+ |
| 17218 |
+ case EbtUSampler2D: |
| 17219 |
+ case EbtUSampler3D: |
| 17220 |
+ case EbtUSamplerCube: |
| 17221 |
+ case EbtUSampler2DArray: |
| 17222 |
+ case EbtUSampler2DMS: |
| 17223 |
+ case EbtUSampler2DMSArray: |
| 17224 |
+ case EbtUSampler1D: |
| 17225 |
+ case EbtUSampler1DArray: |
| 17226 |
+ case EbtUSampler2DRect: |
| 17227 |
+ case EbtUSamplerBuffer: |
| 17228 |
+ case EbtUSamplerCubeArray: |
| 17229 |
+ return TBasicType::EbtUInt; |
| 17230 |
+ |
| 17231 |
+ default: |
| 17232 |
+ LOGIC_ERROR(); |
| 17233 |
+ return TBasicType::EbtVoid; |
| 17234 |
+ } |
| 17235 |
+} |
| 17236 |
+ |
| 17237 |
+Name sh::GetTextureTypeName(TBasicType samplerType) |
| 17238 |
+{ |
| 17239 |
+ ASSERT(IsSampler(samplerType)); |
| 17240 |
+ |
| 17241 |
+ const TBasicType textureType = GetTextureBasicType(samplerType); |
| 17242 |
+ const char *name; |
| 17243 |
+ |
| 17244 |
+#define HANDLE_TEXTURE_NAME(baseName) \ |
| 17245 |
+ do \ |
| 17246 |
+ { \ |
| 17247 |
+ switch (textureType) \ |
| 17248 |
+ { \ |
| 17249 |
+ case TBasicType::EbtFloat: \ |
| 17250 |
+ name = "metal::" baseName "<float>"; \ |
| 17251 |
+ break; \ |
| 17252 |
+ case TBasicType::EbtInt: \ |
| 17253 |
+ name = "metal::" baseName "<int>"; \ |
| 17254 |
+ break; \ |
| 17255 |
+ case TBasicType::EbtUInt: \ |
| 17256 |
+ name = "metal::" baseName "<uint>"; \ |
| 17257 |
+ break; \ |
| 17258 |
+ default: \ |
| 17259 |
+ LOGIC_ERROR(); \ |
| 17260 |
+ name = nullptr; \ |
| 17261 |
+ break; \ |
| 17262 |
+ } \ |
| 17263 |
+ } while (false) |
| 17264 |
+ |
| 17265 |
+ switch (samplerType) |
| 17266 |
+ { |
| 17267 |
+ // 1d |
| 17268 |
+ case EbtSampler1D: // Desktop GLSL sampler type: |
| 17269 |
+ case EbtISampler1D: |
| 17270 |
+ case EbtUSampler1D: |
| 17271 |
+ HANDLE_TEXTURE_NAME("texture1d"); |
| 17272 |
+ break; |
| 17273 |
+ |
| 17274 |
+ // 1d array |
| 17275 |
+ case EbtSampler1DArray: |
| 17276 |
+ case EbtISampler1DArray: |
| 17277 |
+ case EbtUSampler1DArray: |
| 17278 |
+ HANDLE_TEXTURE_NAME("texture1d_array"); |
| 17279 |
+ break; |
| 17280 |
+ |
| 17281 |
+ // Buffer textures |
| 17282 |
+ case EbtSamplerBuffer: |
| 17283 |
+ case EbtISamplerBuffer: |
| 17284 |
+ case EbtUSamplerBuffer: |
| 17285 |
+ HANDLE_TEXTURE_NAME("texture_buffer"); |
| 17286 |
+ break; |
| 17287 |
+ |
| 17288 |
+ // 2d textures |
| 17289 |
+ case EbtSampler2D: |
| 17290 |
+ case EbtISampler2D: |
| 17291 |
+ case EbtUSampler2D: |
| 17292 |
+ case EbtSampler2DRect: |
| 17293 |
+ case EbtUSampler2DRect: |
| 17294 |
+ case EbtISampler2DRect: |
| 17295 |
+ HANDLE_TEXTURE_NAME("texture2d"); |
| 17296 |
+ break; |
| 17297 |
+ |
| 17298 |
+ // 3d textures |
| 17299 |
+ case EbtSampler3D: |
| 17300 |
+ case EbtISampler3D: |
| 17301 |
+ case EbtUSampler3D: |
| 17302 |
+ HANDLE_TEXTURE_NAME("texture3d"); |
| 17303 |
+ break; |
| 17304 |
+ |
| 17305 |
+ // Cube textures |
| 17306 |
+ case EbtSamplerCube: |
| 17307 |
+ case EbtISamplerCube: |
| 17308 |
+ case EbtUSamplerCube: |
| 17309 |
+ HANDLE_TEXTURE_NAME("texturecube"); |
| 17310 |
+ break; |
| 17311 |
+ |
| 17312 |
+ // 2d array textures |
| 17313 |
+ case EbtSampler2DArray: |
| 17314 |
+ case EbtUSampler2DArray: |
| 17315 |
+ case EbtISampler2DArray: |
| 17316 |
+ HANDLE_TEXTURE_NAME("texture2d_array"); |
| 17317 |
+ break; |
| 17318 |
+ |
| 17319 |
+ case EbtSampler2DMS: |
| 17320 |
+ case EbtISampler2DMS: |
| 17321 |
+ case EbtUSampler2DMS: |
| 17322 |
+ HANDLE_TEXTURE_NAME("texture2d_ms"); |
| 17323 |
+ break; |
| 17324 |
+ |
| 17325 |
+ case EbtSampler2DMSArray: |
| 17326 |
+ case EbtISampler2DMSArray: |
| 17327 |
+ case EbtUSampler2DMSArray: |
| 17328 |
+ HANDLE_TEXTURE_NAME("texture2d_ms_array"); |
| 17329 |
+ break; |
| 17330 |
+ |
| 17331 |
+ // cube array |
| 17332 |
+ case EbtSamplerCubeArray: |
| 17333 |
+ case EbtISamplerCubeArray: |
| 17334 |
+ case EbtUSamplerCubeArray: |
| 17335 |
+ HANDLE_TEXTURE_NAME("texturecube_array"); |
| 17336 |
+ break; |
| 17337 |
+ |
| 17338 |
+ // Shadow |
| 17339 |
+ case EbtSampler1DShadow: |
| 17340 |
+ case EbtSampler1DArrayShadow: |
| 17341 |
+ TODO(); |
| 17342 |
+ HANDLE_TEXTURE_NAME("TODO"); |
| 17343 |
+ break; |
| 17344 |
+ |
| 17345 |
+ case EbtSampler2DRectShadow: |
| 17346 |
+ case EbtSampler2DShadow: |
| 17347 |
+ HANDLE_TEXTURE_NAME("depth2d"); |
| 17348 |
+ break; |
| 17349 |
+ |
| 17350 |
+ case EbtSamplerCubeShadow: |
| 17351 |
+ HANDLE_TEXTURE_NAME("depthcube"); |
| 17352 |
+ break; |
| 17353 |
+ |
| 17354 |
+ case EbtSampler2DArrayShadow: |
| 17355 |
+ HANDLE_TEXTURE_NAME("depth2d_array"); |
| 17356 |
+ break; |
| 17357 |
+ |
| 17358 |
+ case EbtSamplerCubeArrayShadow: |
| 17359 |
+ HANDLE_TEXTURE_NAME("depthcube_array"); |
| 17360 |
+ break; |
| 17361 |
+ |
| 17362 |
+ // Extentions |
| 17363 |
+ case EbtSamplerExternalOES: // Only valid if OES_EGL_image_external exists: |
| 17364 |
+ case EbtSamplerExternal2DY2YEXT: // Only valid if GL_EXT_YUV_target exists: |
| 17365 |
+ case EbtSamplerVideoWEBGL: |
| 17366 |
+ TODO(); |
| 17367 |
+ HANDLE_TEXTURE_NAME("TODO"); |
| 17368 |
+ break; |
| 17369 |
+ |
| 17370 |
+ default: |
| 17371 |
+ LOGIC_ERROR(); |
| 17372 |
+ name = nullptr; |
| 17373 |
+ break; |
| 17374 |
+ } |
| 17375 |
+ |
| 17376 |
+#undef HANDLE_TEXTURE_NAME |
| 17377 |
+ |
| 17378 |
+ return Name(name, SymbolType::UserDefined); |
| 17379 |
+} |
| 17380 |
diff --git a/src/compiler/translator/TranslatorMetalDirect/SymbolEnv.h b/src/compiler/translator/TranslatorMetalDirect/SymbolEnv.h |
| 17381 |
new file mode 100644 |
| 17382 |
index 0000000..4c9645e |
| 17383 |
--- /dev/null |
| 17384 |
+++ b/src/compiler/translator/TranslatorMetalDirect/SymbolEnv.h |
| 17385 |
@@ -0,0 +1,218 @@ |
| 17386 |
+// |
| 17387 |
+// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 17388 |
+// Use of this source code is governed by a BSD-style license that can be |
| 17389 |
+// found in the LICENSE file. |
| 17390 |
+// |
| 17391 |
+ |
| 17392 |
+#ifndef COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_SYMBOLENV_H_ |
| 17393 |
+#define COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_SYMBOLENV_H_ |
| 17394 |
+ |
| 17395 |
+#include <unordered_set> |
| 17396 |
+ |
| 17397 |
+#include "compiler/translator/Compiler.h" |
| 17398 |
+#include "compiler/translator/TranslatorMetalDirect/Name.h" |
| 17399 |
+#include "compiler/translator/TranslatorMetalDirect/Reference.h" |
| 17400 |
+#include "compiler/translator/Types.h" |
| 17401 |
+ |
| 17402 |
+namespace sh |
| 17403 |
+{ |
| 17404 |
+ |
| 17405 |
+enum class AddressSpace |
| 17406 |
+{ |
| 17407 |
+ Constant, |
| 17408 |
+ Device, |
| 17409 |
+ Thread, |
| 17410 |
+}; |
| 17411 |
+ |
| 17412 |
+char const *toString(AddressSpace space); |
| 17413 |
+ |
| 17414 |
+class VarField |
| 17415 |
+{ |
| 17416 |
+ public: |
| 17417 |
+ VarField(const TVariable &var) : mVariable(&var) {} |
| 17418 |
+ VarField(const TField &field) : mField(&field) {} |
| 17419 |
+ |
| 17420 |
+ ANGLE_INLINE const TVariable *variable() const { return mVariable; } |
| 17421 |
+ |
| 17422 |
+ ANGLE_INLINE const TField *field() const { return mField; } |
| 17423 |
+ |
| 17424 |
+ ANGLE_INLINE bool operator==(const VarField &other) const |
| 17425 |
+ { |
| 17426 |
+ return mVariable == other.mVariable && mField == other.mField; |
| 17427 |
+ } |
| 17428 |
+ |
| 17429 |
+ private: |
| 17430 |
+ const TVariable *mVariable = nullptr; |
| 17431 |
+ const TField *mField = nullptr; |
| 17432 |
+}; |
| 17433 |
+ |
| 17434 |
+} // namespace sh |
| 17435 |
+ |
| 17436 |
+namespace std |
| 17437 |
+{ |
| 17438 |
+ |
| 17439 |
+template <> |
| 17440 |
+struct hash<sh::VarField> |
| 17441 |
+{ |
| 17442 |
+ size_t operator()(const sh::VarField &x) const |
| 17443 |
+ { |
| 17444 |
+ const sh::TVariable *var = x.variable(); |
| 17445 |
+ if (var) |
| 17446 |
+ { |
| 17447 |
+ return std::hash<const sh::TVariable *>()(var); |
| 17448 |
+ } |
| 17449 |
+ const sh::TField *field = x.field(); |
| 17450 |
+ return std::hash<const sh::TField *>()(field); |
| 17451 |
+ } |
| 17452 |
+}; |
| 17453 |
+ |
| 17454 |
+} // namespace std |
| 17455 |
+ |
| 17456 |
+namespace sh |
| 17457 |
+{ |
| 17458 |
+ |
| 17459 |
+class TemplateArg |
| 17460 |
+{ |
| 17461 |
+ public: |
| 17462 |
+ enum class Kind |
| 17463 |
+ { |
| 17464 |
+ Bool, |
| 17465 |
+ Int, |
| 17466 |
+ UInt, |
| 17467 |
+ Type, |
| 17468 |
+ }; |
| 17469 |
+ |
| 17470 |
+ union Value |
| 17471 |
+ { |
| 17472 |
+ Value(bool value) : b(value) {} |
| 17473 |
+ Value(int value) : i(value) {} |
| 17474 |
+ Value(unsigned value) : u(value) {} |
| 17475 |
+ Value(const TType &value) : t(&value) {} |
| 17476 |
+ |
| 17477 |
+ bool b; |
| 17478 |
+ int i; |
| 17479 |
+ unsigned u; |
| 17480 |
+ const TType *t; |
| 17481 |
+ }; |
| 17482 |
+ |
| 17483 |
+ TemplateArg(bool value); |
| 17484 |
+ TemplateArg(int value); |
| 17485 |
+ TemplateArg(unsigned value); |
| 17486 |
+ TemplateArg(const TType &value); |
| 17487 |
+ |
| 17488 |
+ bool operator==(const TemplateArg &other) const; |
| 17489 |
+ bool operator<(const TemplateArg &other) const; |
| 17490 |
+ |
| 17491 |
+ Kind kind() const { return mKind; } |
| 17492 |
+ Value value() const { return mValue; } |
| 17493 |
+ |
| 17494 |
+ public: |
| 17495 |
+ Kind mKind; |
| 17496 |
+ Value mValue; |
| 17497 |
+}; |
| 17498 |
+ |
| 17499 |
+// An environment for creating and uniquely sharing TSymbol objects. |
| 17500 |
+class SymbolEnv |
| 17501 |
+{ |
| 17502 |
+ class TemplateName |
| 17503 |
+ { |
| 17504 |
+ Name baseName; |
| 17505 |
+ std::vector<TemplateArg> templateArgs; |
| 17506 |
+ |
| 17507 |
+ public: |
| 17508 |
+ bool operator==(const TemplateName &other) const; |
| 17509 |
+ bool operator<(const TemplateName &other) const; |
| 17510 |
+ |
| 17511 |
+ bool empty() const; |
| 17512 |
+ void clear(); |
| 17513 |
+ |
| 17514 |
+ Name fullName(std::string &buffer) const; |
| 17515 |
+ |
| 17516 |
+ void assign(const Name &name, size_t argCount, const TemplateArg *args); |
| 17517 |
+ }; |
| 17518 |
+ |
| 17519 |
+ using TypeRef = CRef<TType>; |
| 17520 |
+ using Sig = std::vector<TypeRef>; // Param0, Param1, ... ParamN, Return |
| 17521 |
+ using SigToFunc = std::map<Sig, TFunction *>; |
| 17522 |
+ using Overloads = std::map<TemplateName, SigToFunc>; |
| 17523 |
+ using AngleStructs = std::map<ImmutableString, TStructure *>; |
| 17524 |
+ using TextureStructs = std::map<TBasicType, TStructure *>; |
| 17525 |
+ |
| 17526 |
+ public: |
| 17527 |
+ SymbolEnv(TCompiler &compiler, TIntermBlock &root); |
| 17528 |
+ |
| 17529 |
+ TSymbolTable &symbolTable() { return mSymbolTable; } |
| 17530 |
+ |
| 17531 |
+ // There exist Angle rewrites that can lead to incoherent structs |
| 17532 |
+ // |
| 17533 |
+ // Example |
| 17534 |
+ // struct A { ... } |
| 17535 |
+ // struct B { A' a; } // A' has same name as A but is not identical. |
| 17536 |
+ // becomes |
| 17537 |
+ // struct A { ... } |
| 17538 |
+ // struct B { A a; } |
| 17539 |
+ // |
| 17540 |
+ // This notably happens when A contains a sampler in the original GLSL code but is rewritten to |
| 17541 |
+ // not have a sampler, yet the A' struct field still contains the sampler field. |
| 17542 |
+ const TStructure &remap(const TStructure &s) const; |
| 17543 |
+ |
| 17544 |
+ // Like `TStructure &remap(const TStructure &s)` but additionally maps null to null. |
| 17545 |
+ const TStructure *remap(const TStructure *s) const; |
| 17546 |
+ |
| 17547 |
+ const TFunction &getFunctionOverload(const Name &name, |
| 17548 |
+ const TType &returnType, |
| 17549 |
+ size_t paramCount, |
| 17550 |
+ const TType **paramTypes, |
| 17551 |
+ size_t templateArgCount = 0, |
| 17552 |
+ const TemplateArg *templateArgs = nullptr); |
| 17553 |
+ |
| 17554 |
+ TIntermAggregate &callFunctionOverload(const Name &name, |
| 17555 |
+ const TType &returnType, |
| 17556 |
+ TIntermSequence &args, |
| 17557 |
+ size_t templateArgCount = 0, |
| 17558 |
+ const TemplateArg *templateArgs = nullptr); |
| 17559 |
+ |
| 17560 |
+ const TStructure &newStructure(const Name &name, TFieldList &fields); |
| 17561 |
+ |
| 17562 |
+ const TStructure &getTextureEnv(TBasicType samplerType); |
| 17563 |
+ const TStructure &getSamplerStruct(); |
| 17564 |
+ |
| 17565 |
+ void markAsPointer(VarField x, AddressSpace space); |
| 17566 |
+ const AddressSpace *isPointer(VarField x) const; |
| 17567 |
+ |
| 17568 |
+ void markAsReference(VarField x, AddressSpace space); |
| 17569 |
+ const AddressSpace *isReference(VarField x) const; |
| 17570 |
+ |
| 17571 |
+ void markAsPacked(const TField &field); |
| 17572 |
+ bool isPacked(const TField &field) const; |
| 17573 |
+ |
| 17574 |
+ private: |
| 17575 |
+ const TFunction &getFunctionOverloadImpl(); |
| 17576 |
+ |
| 17577 |
+ void markSpace(VarField x, AddressSpace space, std::unordered_map<VarField, AddressSpace> &map); |
| 17578 |
+ const AddressSpace *isSpace(VarField x, |
| 17579 |
+ const std::unordered_map<VarField, AddressSpace> &map) const; |
| 17580 |
+ |
| 17581 |
+ private: |
| 17582 |
+ TSymbolTable &mSymbolTable; |
| 17583 |
+ |
| 17584 |
+ std::map<Name, const TStructure *> mNameToStruct; |
| 17585 |
+ Overloads mOverloads; |
| 17586 |
+ Sig mReusableSigBuffer; |
| 17587 |
+ TemplateName mReusableTemplateNameBuffer; |
| 17588 |
+ std::string mReusableStringBuffer; |
| 17589 |
+ |
| 17590 |
+ AngleStructs mAngleStructs; |
| 17591 |
+ std::unordered_map<TBasicType, const TStructure *> mTextureEnvs; |
| 17592 |
+ const TStructure *mSampler = nullptr; |
| 17593 |
+ |
| 17594 |
+ std::unordered_map<VarField, AddressSpace> mPointers; |
| 17595 |
+ std::unordered_map<VarField, AddressSpace> mReferences; |
| 17596 |
+ std::unordered_set<const TField *> mPackedFields; |
| 17597 |
+}; |
| 17598 |
+ |
| 17599 |
+Name GetTextureTypeName(TBasicType samplerType); |
| 17600 |
+ |
| 17601 |
+} // namespace sh |
| 17602 |
+ |
| 17603 |
+#endif // COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_SYMBOLENV_H_ |
| 17604 |
diff --git a/src/compiler/translator/TranslatorMetalDirect/ToposortStructs.cpp b/src/compiler/translator/TranslatorMetalDirect/ToposortStructs.cpp |
| 17605 |
new file mode 100644 |
| 17606 |
index 0000000..9843332 |
| 17607 |
--- /dev/null |
| 17608 |
+++ b/src/compiler/translator/TranslatorMetalDirect/ToposortStructs.cpp |
| 17609 |
@@ -0,0 +1,383 @@ |
| 17610 |
+// |
| 17611 |
+// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 17612 |
+// Use of this source code is governed by a BSD-style license that can be |
| 17613 |
+// found in the LICENSE file. |
| 17614 |
+// |
| 17615 |
+ |
| 17616 |
+#include <functional> |
| 17617 |
+#include <unordered_map> |
| 17618 |
+#include <unordered_set> |
| 17619 |
+#include <vector> |
| 17620 |
+ |
| 17621 |
+#include "compiler/translator/ImmutableStringBuilder.h" |
| 17622 |
+#include "compiler/translator/TranslatorMetalDirect/AstHelpers.h" |
| 17623 |
+#include "compiler/translator/TranslatorMetalDirect/Debug.h" |
| 17624 |
+#include "compiler/translator/TranslatorMetalDirect/ToposortStructs.h" |
| 17625 |
+#include "compiler/translator/tree_util/IntermNode_util.h" |
| 17626 |
+#include "compiler/translator/tree_util/IntermTraverse.h" |
| 17627 |
+ |
| 17628 |
+using namespace sh; |
| 17629 |
+ |
| 17630 |
+//////////////////////////////////////////////////////////////////////////////// |
| 17631 |
+ |
| 17632 |
+namespace |
| 17633 |
+{ |
| 17634 |
+ |
| 17635 |
+template <typename T> |
| 17636 |
+using Edges = std::unordered_set<T>; |
| 17637 |
+ |
| 17638 |
+template <typename T> |
| 17639 |
+using Graph = std::unordered_map<T, Edges<T>>; |
| 17640 |
+ |
| 17641 |
+void BuildGraphImpl(SymbolEnv &symbolEnv, Graph<const TStructure *> &g, const TStructure *s) |
| 17642 |
+{ |
| 17643 |
+ if (g.find(s) != g.end()) |
| 17644 |
+ { |
| 17645 |
+ return; |
| 17646 |
+ } |
| 17647 |
+ |
| 17648 |
+ Edges<const TStructure *> &es = g[s]; |
| 17649 |
+ |
| 17650 |
+ const TFieldList &fs = s->fields(); |
| 17651 |
+ for (const TField *f : fs) |
| 17652 |
+ { |
| 17653 |
+ if (const TStructure *z = symbolEnv.remap(f->type()->getStruct())) |
| 17654 |
+ { |
| 17655 |
+ es.insert(z); |
| 17656 |
+ BuildGraphImpl(symbolEnv, g, z); |
| 17657 |
+ Edges<const TStructure *> &ez = g[z]; |
| 17658 |
+ es.insert(ez.begin(), ez.end()); |
| 17659 |
+ } |
| 17660 |
+ } |
| 17661 |
+} |
| 17662 |
+ |
| 17663 |
+Graph<const TStructure *> BuildGraph(SymbolEnv &symbolEnv, |
| 17664 |
+ const std::vector<const TStructure *> &structs) |
| 17665 |
+{ |
| 17666 |
+ Graph<const TStructure *> g; |
| 17667 |
+ for (const TStructure *s : structs) |
| 17668 |
+ { |
| 17669 |
+ BuildGraphImpl(symbolEnv, g, s); |
| 17670 |
+ } |
| 17671 |
+ return g; |
| 17672 |
+} |
| 17673 |
+ |
| 17674 |
+// Algorthm: https://en.wikipedia.org/wiki/Topological_sorting#Depth-first_search |
| 17675 |
+template <typename T> |
| 17676 |
+std::vector<T> Toposort(const Graph<T> &g) |
| 17677 |
+{ |
| 17678 |
+ // nodes with temporary mark |
| 17679 |
+ std::unordered_set<T> temps; |
| 17680 |
+ |
| 17681 |
+ // nodes without permanent mark |
| 17682 |
+ std::unordered_set<T> invPerms; |
| 17683 |
+ for (const auto &entry : g) |
| 17684 |
+ { |
| 17685 |
+ invPerms.insert(entry.first); |
| 17686 |
+ } |
| 17687 |
+ |
| 17688 |
+ // L ← Empty list that will contain the sorted elements |
| 17689 |
+ std::vector<T> L; |
| 17690 |
+ |
| 17691 |
+ // function visit(node n) |
| 17692 |
+ std::function<void(T)> visit = [&](T n) -> void { |
| 17693 |
+ // if n has a permanent mark then |
| 17694 |
+ if (invPerms.find(n) == invPerms.end()) |
| 17695 |
+ { |
| 17696 |
+ // return |
| 17697 |
+ return; |
| 17698 |
+ } |
| 17699 |
+ // if n has a temporary mark then |
| 17700 |
+ if (temps.find(n) != temps.end()) |
| 17701 |
+ { |
| 17702 |
+ // stop (not a DAG) |
| 17703 |
+ LOGIC_ERROR(); |
| 17704 |
+ } |
| 17705 |
+ |
| 17706 |
+ // mark n with a temporary mark |
| 17707 |
+ temps.insert(n); |
| 17708 |
+ |
| 17709 |
+ // for each node m with an edge from n to m do |
| 17710 |
+ auto enIter = g.find(n); |
| 17711 |
+ ASSERT(enIter != g.end()); |
| 17712 |
+ const Edges<T> &en = enIter->second; |
| 17713 |
+ for (T m : en) |
| 17714 |
+ { |
| 17715 |
+ // visit(m) |
| 17716 |
+ visit(m); |
| 17717 |
+ } |
| 17718 |
+ |
| 17719 |
+ // remove temporary mark from n |
| 17720 |
+ temps.erase(n); |
| 17721 |
+ // mark n with a permanent mark |
| 17722 |
+ invPerms.erase(n); |
| 17723 |
+ // add n to head of L |
| 17724 |
+ L.push_back(n); |
| 17725 |
+ }; |
| 17726 |
+ |
| 17727 |
+ // while exists nodes without a permanent mark do |
| 17728 |
+ while (!invPerms.empty()) |
| 17729 |
+ { |
| 17730 |
+ // select an unmarked node n |
| 17731 |
+ T n = *invPerms.begin(); |
| 17732 |
+ // visit(n) |
| 17733 |
+ visit(n); |
| 17734 |
+ } |
| 17735 |
+ |
| 17736 |
+ return L; |
| 17737 |
+} |
| 17738 |
+ |
| 17739 |
+TIntermFunctionDefinition *CreateStructEqualityFunction(TSymbolTable &symbolTable, |
| 17740 |
+ const TStructure &aStructType) |
| 17741 |
+{ |
| 17742 |
+ //////////////////// |
| 17743 |
+ |
| 17744 |
+ auto &funcEquality = |
| 17745 |
+ *new TFunction(&symbolTable, ImmutableString("equal"), SymbolType::AngleInternal, |
| 17746 |
+ new TType(TBasicType::EbtBool), true); |
| 17747 |
+ auto &aStruct = CreateInstanceVariable(symbolTable, aStructType, Name("a")); |
| 17748 |
+ auto &bStruct = CreateInstanceVariable(symbolTable, aStructType, Name("b")); |
| 17749 |
+ funcEquality.addParameter(&aStruct); |
| 17750 |
+ funcEquality.addParameter(&bStruct); |
| 17751 |
+ |
| 17752 |
+ auto &bodyEquality = *new TIntermBlock(); |
| 17753 |
+ std::vector<TIntermTyped *> andNodes; |
| 17754 |
+ //////////////////// |
| 17755 |
+ |
| 17756 |
+ const TFieldList &aFields = aStructType.fields(); |
| 17757 |
+ const size_t size = aFields.size(); |
| 17758 |
+ |
| 17759 |
+ auto testEquality = [&](TIntermTyped &a, TIntermTyped &b) -> TIntermTyped * { |
| 17760 |
+ ASSERT(a.getType() == b.getType()); |
| 17761 |
+ const TType &type = a.getType(); |
| 17762 |
+ if (type.isVector() || type.isMatrix() || type.getStruct()) |
| 17763 |
+ { |
| 17764 |
+ auto *func = |
| 17765 |
+ new TFunction(&symbolTable, ImmutableString("equal"), SymbolType::AngleInternal, |
| 17766 |
+ new TType(TBasicType::EbtBool), true); |
| 17767 |
+ return TIntermAggregate::CreateFunctionCall(*func, new TIntermSequence{&a, &b}); |
| 17768 |
+ } |
| 17769 |
+ else |
| 17770 |
+ { |
| 17771 |
+ return new TIntermBinary(TOperator::EOpEqual, &a, &b); |
| 17772 |
+ } |
| 17773 |
+ }; |
| 17774 |
+ |
| 17775 |
+ for (size_t idx = 0; idx < size; ++idx) |
| 17776 |
+ { |
| 17777 |
+ const TField &aField = *aFields[idx]; |
| 17778 |
+ const TType &aFieldType = *aField.type(); |
| 17779 |
+ auto &aFieldName = aField.name(); |
| 17780 |
+ |
| 17781 |
+ if (aFieldType.isArray()) |
| 17782 |
+ { |
| 17783 |
+ ASSERT(!aFieldType.isArrayOfArrays()); // TODO |
| 17784 |
+ int dim = aFieldType.getOutermostArraySize(); |
| 17785 |
+ for (int d = 0; d < dim; ++d) |
| 17786 |
+ { |
| 17787 |
+ auto &aAccess = AccessIndex(AccessField(aStruct, aFieldName), d); |
| 17788 |
+ auto &bAccess = AccessIndex(AccessField(bStruct, aFieldName), d); |
| 17789 |
+ auto *eqNode = testEquality(bAccess, aAccess); |
| 17790 |
+ andNodes.push_back(eqNode); |
| 17791 |
+ } |
| 17792 |
+ } |
| 17793 |
+ else |
| 17794 |
+ { |
| 17795 |
+ auto &aAccess = AccessField(aStruct, aFieldName); |
| 17796 |
+ auto &bAccess = AccessField(bStruct, aFieldName); |
| 17797 |
+ auto *eqNode = testEquality(bAccess, aAccess); |
| 17798 |
+ andNodes.push_back(eqNode); |
| 17799 |
+ } |
| 17800 |
+ } |
| 17801 |
+ |
| 17802 |
+ ASSERT(andNodes.size() > 0); // Empty structs are not allowed in GLSL |
| 17803 |
+ TIntermTyped *outNode = andNodes.back(); |
| 17804 |
+ andNodes.pop_back(); |
| 17805 |
+ for (TIntermTyped *andNode : andNodes) |
| 17806 |
+ { |
| 17807 |
+ outNode = new TIntermBinary(TOperator::EOpLogicalAnd, andNode, outNode); |
| 17808 |
+ } |
| 17809 |
+ bodyEquality.appendStatement(new TIntermBranch(TOperator::EOpReturn, outNode)); |
| 17810 |
+ auto *funcProtoEquality = new TIntermFunctionPrototype(&funcEquality); |
| 17811 |
+ return new TIntermFunctionDefinition(funcProtoEquality, &bodyEquality); |
| 17812 |
+} |
| 17813 |
+ |
| 17814 |
+struct DeclaredStructure |
| 17815 |
+{ |
| 17816 |
+ TIntermDeclaration *declNode; |
| 17817 |
+ TIntermFunctionDefinition *equalityFunctionDefinition; |
| 17818 |
+ const TStructure *structure; |
| 17819 |
+}; |
| 17820 |
+ |
| 17821 |
+bool GetAsDeclaredStructure(SymbolEnv &symbolEnv, |
| 17822 |
+ TIntermNode &node, |
| 17823 |
+ DeclaredStructure &out, |
| 17824 |
+ TSymbolTable &symbolTable, |
| 17825 |
+ const std::unordered_set<const TStructure *> &usedStructs) |
| 17826 |
+{ |
| 17827 |
+ if (TIntermDeclaration *declNode = node.getAsDeclarationNode()) |
| 17828 |
+ { |
| 17829 |
+ ASSERT(declNode->getChildCount() == 1); |
| 17830 |
+ TIntermNode &node = *declNode->getChildNode(0); |
| 17831 |
+ |
| 17832 |
+ if (TIntermSymbol *symbolNode = node.getAsSymbolNode()) |
| 17833 |
+ { |
| 17834 |
+ const TVariable &var = symbolNode->variable(); |
| 17835 |
+ const TType &type = var.getType(); |
| 17836 |
+ if (const TStructure *structure = symbolEnv.remap(type.getStruct())) |
| 17837 |
+ { |
| 17838 |
+ if (type.isStructSpecifier()) |
| 17839 |
+ { |
| 17840 |
+ out.declNode = declNode; |
| 17841 |
+ out.structure = structure; |
| 17842 |
+ out.equalityFunctionDefinition = |
| 17843 |
+ usedStructs.find(structure) == usedStructs.end() |
| 17844 |
+ ? nullptr |
| 17845 |
+ : CreateStructEqualityFunction(symbolTable, *structure); |
| 17846 |
+ return true; |
| 17847 |
+ } |
| 17848 |
+ } |
| 17849 |
+ } |
| 17850 |
+ } |
| 17851 |
+ return false; |
| 17852 |
+} |
| 17853 |
+ |
| 17854 |
+class FindStructEqualityUse : public TIntermTraverser |
| 17855 |
+{ |
| 17856 |
+ public: |
| 17857 |
+ SymbolEnv &mSymbolEnv; |
| 17858 |
+ std::unordered_set<const TStructure *> mUsedStructs; |
| 17859 |
+ |
| 17860 |
+ FindStructEqualityUse(SymbolEnv &symbolEnv) |
| 17861 |
+ : TIntermTraverser(false, false, true), mSymbolEnv(symbolEnv) |
| 17862 |
+ {} |
| 17863 |
+ |
| 17864 |
+ bool visitBinary(Visit, TIntermBinary *binary) override |
| 17865 |
+ { |
| 17866 |
+ const TOperator op = binary->getOp(); |
| 17867 |
+ |
| 17868 |
+ switch (op) |
| 17869 |
+ { |
| 17870 |
+ case TOperator::EOpEqual: |
| 17871 |
+ case TOperator::EOpNotEqual: |
| 17872 |
+ { |
| 17873 |
+ const TType &leftType = binary->getLeft()->getType(); |
| 17874 |
+ const TType &rightType = binary->getRight()->getType(); |
| 17875 |
+ ASSERT(leftType.getStruct() == rightType.getStruct()); |
| 17876 |
+ if (const TStructure *structure = mSymbolEnv.remap(leftType.getStruct())) |
| 17877 |
+ { |
| 17878 |
+ useStruct(*structure); |
| 17879 |
+ } |
| 17880 |
+ } |
| 17881 |
+ break; |
| 17882 |
+ |
| 17883 |
+ default: |
| 17884 |
+ break; |
| 17885 |
+ } |
| 17886 |
+ |
| 17887 |
+ return true; |
| 17888 |
+ } |
| 17889 |
+ |
| 17890 |
+ private: |
| 17891 |
+ void useStruct(const TStructure &structure) |
| 17892 |
+ { |
| 17893 |
+ if (mUsedStructs.insert(&structure).second) |
| 17894 |
+ { |
| 17895 |
+ for (const TField *field : structure.fields()) |
| 17896 |
+ { |
| 17897 |
+ if (const TStructure *subStruct = mSymbolEnv.remap(field->type()->getStruct())) |
| 17898 |
+ { |
| 17899 |
+ useStruct(*subStruct); |
| 17900 |
+ } |
| 17901 |
+ } |
| 17902 |
+ } |
| 17903 |
+ } |
| 17904 |
+}; |
| 17905 |
+ |
| 17906 |
+} // anonymous namespace |
| 17907 |
+ |
| 17908 |
+//////////////////////////////////////////////////////////////////////////////// |
| 17909 |
+ |
| 17910 |
+bool sh::ToposortStructs(TCompiler &compiler, |
| 17911 |
+ SymbolEnv &symbolEnv, |
| 17912 |
+ TIntermBlock &root, |
| 17913 |
+ ProgramPreludeConfig &ppc) |
| 17914 |
+{ |
| 17915 |
+ FindStructEqualityUse finder(symbolEnv); |
| 17916 |
+ root.traverse(&finder); |
| 17917 |
+ ppc.hasStructEq = !finder.mUsedStructs.empty(); |
| 17918 |
+ |
| 17919 |
+ DeclaredStructure declaredStruct; |
| 17920 |
+ std::vector<DeclaredStructure> declaredStructs; |
| 17921 |
+ std::vector<TIntermNode *> nonStructStmtNodes; |
| 17922 |
+ |
| 17923 |
+ { |
| 17924 |
+ const size_t stmtCount = root.getChildCount(); |
| 17925 |
+ for (size_t i = 0; i < stmtCount; ++i) |
| 17926 |
+ { |
| 17927 |
+ TIntermNode &stmtNode = *root.getChildNode(i); |
| 17928 |
+ if (GetAsDeclaredStructure(symbolEnv, stmtNode, declaredStruct, |
| 17929 |
+ compiler.getSymbolTable(), finder.mUsedStructs)) |
| 17930 |
+ { |
| 17931 |
+ declaredStructs.push_back(declaredStruct); |
| 17932 |
+ } |
| 17933 |
+ else |
| 17934 |
+ { |
| 17935 |
+ nonStructStmtNodes.push_back(&stmtNode); |
| 17936 |
+ } |
| 17937 |
+ } |
| 17938 |
+ } |
| 17939 |
+ |
| 17940 |
+ { |
| 17941 |
+ std::vector<const TStructure *> structs; |
| 17942 |
+ std::unordered_map<const TStructure *, DeclaredStructure> rawToDeclared; |
| 17943 |
+ |
| 17944 |
+ for (const DeclaredStructure &d : declaredStructs) |
| 17945 |
+ { |
| 17946 |
+ structs.push_back(d.structure); |
| 17947 |
+ ASSERT(rawToDeclared.find(d.structure) == rawToDeclared.end()); |
| 17948 |
+ rawToDeclared[d.structure] = d; |
| 17949 |
+ } |
| 17950 |
+ |
| 17951 |
+ // Note: Graph may contain more than only explicitly declared structures. |
| 17952 |
+ Graph<const TStructure *> g = BuildGraph(symbolEnv, structs); |
| 17953 |
+ std::vector<const TStructure *> sortedStructs = Toposort(g); |
| 17954 |
+ ASSERT(declaredStructs.size() <= sortedStructs.size()); |
| 17955 |
+ |
| 17956 |
+ declaredStructs.clear(); |
| 17957 |
+ for (const TStructure *s : sortedStructs) |
| 17958 |
+ { |
| 17959 |
+ auto it = rawToDeclared.find(s); |
| 17960 |
+ if (it != rawToDeclared.end()) |
| 17961 |
+ { |
| 17962 |
+ auto &d = it->second; |
| 17963 |
+ ASSERT(d.declNode); |
| 17964 |
+ declaredStructs.push_back(d); |
| 17965 |
+ } |
| 17966 |
+ } |
| 17967 |
+ } |
| 17968 |
+ |
| 17969 |
+ { |
| 17970 |
+ TIntermSequence newStmtNodes; |
| 17971 |
+ |
| 17972 |
+ for (DeclaredStructure &declaredStruct : declaredStructs) |
| 17973 |
+ { |
| 17974 |
+ ASSERT(declaredStruct.declNode); |
| 17975 |
+ newStmtNodes.push_back(declaredStruct.declNode); |
| 17976 |
+ if (declaredStruct.equalityFunctionDefinition) |
| 17977 |
+ { |
| 17978 |
+ newStmtNodes.push_back(declaredStruct.equalityFunctionDefinition); |
| 17979 |
+ } |
| 17980 |
+ } |
| 17981 |
+ |
| 17982 |
+ for (TIntermNode *stmtNode : nonStructStmtNodes) |
| 17983 |
+ { |
| 17984 |
+ ASSERT(stmtNode); |
| 17985 |
+ newStmtNodes.push_back(stmtNode); |
| 17986 |
+ } |
| 17987 |
+ |
| 17988 |
+ *root.getSequence() = newStmtNodes; |
| 17989 |
+ } |
| 17990 |
+ |
| 17991 |
+ return compiler.validateAST(&root); |
| 17992 |
+} |
| 17993 |
diff --git a/src/compiler/translator/TranslatorMetalDirect/ToposortStructs.h b/src/compiler/translator/TranslatorMetalDirect/ToposortStructs.h |
| 17994 |
new file mode 100644 |
| 17995 |
index 0000000..a3908e3 |
| 17996 |
--- /dev/null |
| 17997 |
+++ b/src/compiler/translator/TranslatorMetalDirect/ToposortStructs.h |
| 17998 |
@@ -0,0 +1,27 @@ |
| 17999 |
+// |
| 18000 |
+// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 18001 |
+// Use of this source code is governed by a BSD-style license that can be |
| 18002 |
+// found in the LICENSE file. |
| 18003 |
+// |
| 18004 |
+ |
| 18005 |
+#ifndef COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_TOPOSORTSTRUCTS_H_ |
| 18006 |
+#define COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_TOPOSORTSTRUCTS_H_ |
| 18007 |
+ |
| 18008 |
+#include "common/angleutils.h" |
| 18009 |
+#include "compiler/translator/Compiler.h" |
| 18010 |
+#include "compiler/translator/TranslatorMetalDirect/ProgramPrelude.h" |
| 18011 |
+#include "compiler/translator/TranslatorMetalDirect/SymbolEnv.h" |
| 18012 |
+ |
| 18013 |
+namespace sh |
| 18014 |
+{ |
| 18015 |
+ |
| 18016 |
+// Does a toposort on structs based on type dependencies. |
| 18017 |
+// Struct type declarations are moved to the top of the root block. |
| 18018 |
+ANGLE_NO_DISCARD bool ToposortStructs(TCompiler &compiler, |
| 18019 |
+ SymbolEnv &symbolEnv, |
| 18020 |
+ TIntermBlock &root, |
| 18021 |
+ ProgramPreludeConfig &ppc); |
| 18022 |
+ |
| 18023 |
+} // namespace sh |
| 18024 |
+ |
| 18025 |
+#endif // COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_TOPOSORTSTRUCTS_H_ |
| 18026 |
diff --git a/src/compiler/translator/TranslatorMetalDirect/WrapMain.cpp b/src/compiler/translator/TranslatorMetalDirect/WrapMain.cpp |
| 18027 |
new file mode 100644 |
| 18028 |
index 0000000..014bc63 |
| 18029 |
--- /dev/null |
| 18030 |
+++ b/src/compiler/translator/TranslatorMetalDirect/WrapMain.cpp |
| 18031 |
@@ -0,0 +1,94 @@ |
| 18032 |
+// |
| 18033 |
+// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 18034 |
+// Use of this source code is governed by a BSD-style license that can be |
| 18035 |
+// found in the LICENSE file. |
| 18036 |
+// |
| 18037 |
+ |
| 18038 |
+#include "compiler/translator/TranslatorMetalDirect/WrapMain.h" |
| 18039 |
+#include "compiler/translator/Compiler.h" |
| 18040 |
+#include "compiler/translator/TranslatorMetalDirect/AstHelpers.h" |
| 18041 |
+ |
| 18042 |
+using namespace sh; |
| 18043 |
+ |
| 18044 |
+//////////////////////////////////////////////////////////////////////////////// |
| 18045 |
+ |
| 18046 |
+namespace |
| 18047 |
+{ |
| 18048 |
+ |
| 18049 |
+class Wrapper : public TIntermTraverser |
| 18050 |
+{ |
| 18051 |
+ private: |
| 18052 |
+ IdGen &mIdGen; |
| 18053 |
+ |
| 18054 |
+ public: |
| 18055 |
+ Wrapper(TSymbolTable &symbolTable, IdGen &idGen) |
| 18056 |
+ : TIntermTraverser(false, false, true, &symbolTable), mIdGen(idGen) |
| 18057 |
+ {} |
| 18058 |
+ |
| 18059 |
+ bool visitBlock(Visit, TIntermBlock *blockNode) override |
| 18060 |
+ { |
| 18061 |
+ if (blockNode != getRootNode()) |
| 18062 |
+ { |
| 18063 |
+ return true; |
| 18064 |
+ } |
| 18065 |
+ |
| 18066 |
+ for (TIntermNode *node : *blockNode->getSequence()) |
| 18067 |
+ { |
| 18068 |
+ if (TIntermFunctionDefinition *funcDefNode = node->getAsFunctionDefinition()) |
| 18069 |
+ { |
| 18070 |
+ const TFunction &func = *funcDefNode->getFunction(); |
| 18071 |
+ if (func.isMain()) |
| 18072 |
+ { |
| 18073 |
+ visitMain(*blockNode, funcDefNode); |
| 18074 |
+ break; |
| 18075 |
+ } |
| 18076 |
+ } |
| 18077 |
+ } |
| 18078 |
+ |
| 18079 |
+ return true; |
| 18080 |
+ } |
| 18081 |
+ |
| 18082 |
+ private: |
| 18083 |
+ void visitMain(TIntermBlock &root, TIntermFunctionDefinition *funcDefNode) |
| 18084 |
+ { |
| 18085 |
+ const TFunction &func = *funcDefNode->getFunction(); |
| 18086 |
+ ASSERT(func.isMain()); |
| 18087 |
+ ASSERT(func.getReturnType().getBasicType() == TBasicType::EbtVoid); |
| 18088 |
+ ASSERT(func.getParamCount() == 0); |
| 18089 |
+ |
| 18090 |
+ const TFunction &externalMainFunc = *funcDefNode->getFunction(); |
| 18091 |
+ const TFunction &internalMainFunc = CloneFunction(*mSymbolTable, mIdGen, externalMainFunc); |
| 18092 |
+ |
| 18093 |
+ TIntermFunctionPrototype *externalMainProto = funcDefNode->getFunctionPrototype(); |
| 18094 |
+ TIntermFunctionPrototype *internalMainProto = |
| 18095 |
+ new TIntermFunctionPrototype(&internalMainFunc); |
| 18096 |
+ |
| 18097 |
+ TIntermBlock *externalMainBody = new TIntermBlock(); |
| 18098 |
+ externalMainBody->appendStatement( |
| 18099 |
+ TIntermAggregate::CreateFunctionCall(internalMainFunc, new TIntermSequence())); |
| 18100 |
+ |
| 18101 |
+ TIntermBlock *internalMainBody = funcDefNode->getBody(); |
| 18102 |
+ |
| 18103 |
+ TIntermFunctionDefinition *externalMainDef = |
| 18104 |
+ new TIntermFunctionDefinition(externalMainProto, externalMainBody); |
| 18105 |
+ TIntermFunctionDefinition *internalMainDef = |
| 18106 |
+ new TIntermFunctionDefinition(internalMainProto, internalMainBody); |
| 18107 |
+ |
| 18108 |
+ mMultiReplacements.push_back(NodeReplaceWithMultipleEntry( |
| 18109 |
+ &root, funcDefNode, TIntermSequence{internalMainDef, externalMainDef})); |
| 18110 |
+ } |
| 18111 |
+}; |
| 18112 |
+ |
| 18113 |
+} // namespace |
| 18114 |
+ |
| 18115 |
+bool sh::WrapMain(TCompiler &compiler, IdGen &idGen, TIntermBlock &root) |
| 18116 |
+{ |
| 18117 |
+ TSymbolTable &symbolTable = compiler.getSymbolTable(); |
| 18118 |
+ Wrapper wrapper(symbolTable, idGen); |
| 18119 |
+ root.traverse(&wrapper); |
| 18120 |
+ if (!wrapper.updateTree(&compiler, &root)) |
| 18121 |
+ { |
| 18122 |
+ return false; |
| 18123 |
+ } |
| 18124 |
+ return true; |
| 18125 |
+} |
| 18126 |
diff --git a/src/compiler/translator/TranslatorMetalDirect/WrapMain.h b/src/compiler/translator/TranslatorMetalDirect/WrapMain.h |
| 18127 |
new file mode 100644 |
| 18128 |
index 0000000..5b0edff |
| 18129 |
--- /dev/null |
| 18130 |
+++ b/src/compiler/translator/TranslatorMetalDirect/WrapMain.h |
| 18131 |
@@ -0,0 +1,28 @@ |
| 18132 |
+// |
| 18133 |
+// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 18134 |
+// Use of this source code is governed by a BSD-style license that can be |
| 18135 |
+// found in the LICENSE file. |
| 18136 |
+// |
| 18137 |
+ |
| 18138 |
+#ifndef COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_WRAPMAIN_H_ |
| 18139 |
+#define COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_WRAPMAIN_H_ |
| 18140 |
+ |
| 18141 |
+#include "compiler/translator/TranslatorMetalDirect/IdGen.h" |
| 18142 |
+#include "compiler/translator/tree_util/IntermTraverse.h" |
| 18143 |
+ |
| 18144 |
+namespace sh |
| 18145 |
+{ |
| 18146 |
+ |
| 18147 |
+// Changes |
| 18148 |
+// void main(args) { main-body } |
| 18149 |
+// To |
| 18150 |
+// void FRESH_NAME(args) { main-body } |
| 18151 |
+// void main(args) { FRESH_NAME(args); } |
| 18152 |
+// |
| 18153 |
+// This transformation is useful if the original `main` has multiple return paths because this |
| 18154 |
+// reduces down to a single path in the new `main`. Nice for inserting cleanup code in `main`. |
| 18155 |
+ANGLE_NO_DISCARD bool WrapMain(TCompiler &compiler, IdGen &idGen, TIntermBlock &root); |
| 18156 |
+ |
| 18157 |
+} // namespace sh |
| 18158 |
+ |
| 18159 |
+#endif // COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_WRAPMAIN_H_ |
| 18160 |
diff --git a/src/compiler/translator/TranslatorMetalUtils.cpp b/src/compiler/translator/TranslatorMetalUtils.cpp |
| 18161 |
new file mode 100644 |
| 18162 |
index 0000000..e0a8bf3 |
| 18163 |
--- /dev/null |
| 18164 |
+++ b/src/compiler/translator/TranslatorMetalUtils.cpp |
| 18165 |
@@ -0,0 +1,305 @@ |
| 18166 |
+// |
| 18167 |
+// Copyright 2002 The ANGLE Project Authors. All rights reserved. |
| 18168 |
+// Use of this source code is governed by a BSD-style license that can be |
| 18169 |
+// found in the LICENSE file. |
| 18170 |
+// |
| 18171 |
+ |
| 18172 |
+#if defined(_MSC_VER) |
| 18173 |
+# pragma warning(disable : 4718) |
| 18174 |
+#endif |
| 18175 |
+#include "compiler/translator/TranslatorMetalUtils.h" |
| 18176 |
+#include <algorithm> |
| 18177 |
+#include <climits> |
| 18178 |
+#include "compiler/translator/HashNames.h" |
| 18179 |
+#include "compiler/translator/ImmutableString.h" |
| 18180 |
+#include "compiler/translator/InfoSink.h" |
| 18181 |
+#include "compiler/translator/IntermNode.h" |
| 18182 |
+#include "compiler/translator/SymbolTable.h" |
| 18183 |
+#include "compiler/translator/Types.h" |
| 18184 |
+ |
| 18185 |
+namespace sh |
| 18186 |
+{ |
| 18187 |
+ |
| 18188 |
+const char *getBasicMetalString(const TType *t) |
| 18189 |
+{ |
| 18190 |
+ switch (t->getBasicType()) |
| 18191 |
+ { |
| 18192 |
+ case EbtVoid: |
| 18193 |
+ return "void"; |
| 18194 |
+ case EbtFloat: |
| 18195 |
+ return "float"; |
| 18196 |
+ case EbtInt: |
| 18197 |
+ return "int"; |
| 18198 |
+ case EbtUInt: |
| 18199 |
+ return "uint"; |
| 18200 |
+ case EbtBool: |
| 18201 |
+ return "bool"; |
| 18202 |
+ case EbtYuvCscStandardEXT: |
| 18203 |
+ return "yuvCscStandardEXT"; |
| 18204 |
+ case EbtSampler2D: |
| 18205 |
+ return "sampler2D"; |
| 18206 |
+ case EbtSampler3D: |
| 18207 |
+ return "sampler3D"; |
| 18208 |
+ case EbtSamplerCube: |
| 18209 |
+ return "samplerCube"; |
| 18210 |
+ case EbtSamplerExternalOES: |
| 18211 |
+ return "samplerExternalOES"; |
| 18212 |
+ case EbtSamplerExternal2DY2YEXT: |
| 18213 |
+ return "__samplerExternal2DY2YEXT"; |
| 18214 |
+ case EbtSampler2DRect: |
| 18215 |
+ return "sampler2DRect"; |
| 18216 |
+ case EbtSampler2DArray: |
| 18217 |
+ return "sampler2DArray"; |
| 18218 |
+ case EbtSampler2DMS: |
| 18219 |
+ return "sampler2DMS"; |
| 18220 |
+ case EbtSampler2DMSArray: |
| 18221 |
+ return "sampler2DMSArray"; |
| 18222 |
+ case EbtSamplerCubeArray: |
| 18223 |
+ return "samplerCubeArray"; |
| 18224 |
+ case EbtISampler2D: |
| 18225 |
+ return "isampler2D"; |
| 18226 |
+ case EbtISampler3D: |
| 18227 |
+ return "isampler3D"; |
| 18228 |
+ case EbtISamplerCube: |
| 18229 |
+ return "isamplerCube"; |
| 18230 |
+ case EbtISampler2DArray: |
| 18231 |
+ return "isampler2DArray"; |
| 18232 |
+ case EbtISampler2DMS: |
| 18233 |
+ return "isampler2DMS"; |
| 18234 |
+ case EbtISampler2DMSArray: |
| 18235 |
+ return "isampler2DMSArray"; |
| 18236 |
+ case EbtISamplerCubeArray: |
| 18237 |
+ return "isamplerCubeArray"; |
| 18238 |
+ case EbtUSampler2D: |
| 18239 |
+ return "usampler2D"; |
| 18240 |
+ case EbtUSampler3D: |
| 18241 |
+ return "usampler3D"; |
| 18242 |
+ case EbtUSamplerCube: |
| 18243 |
+ return "usamplerCube"; |
| 18244 |
+ case EbtUSampler2DArray: |
| 18245 |
+ return "usampler2DArray"; |
| 18246 |
+ case EbtUSampler2DMS: |
| 18247 |
+ return "usampler2DMS"; |
| 18248 |
+ case EbtUSampler2DMSArray: |
| 18249 |
+ return "usampler2DMSArray"; |
| 18250 |
+ case EbtUSamplerCubeArray: |
| 18251 |
+ return "usamplerCubeArray"; |
| 18252 |
+ case EbtSampler2DShadow: |
| 18253 |
+ return "sampler2DShadow"; |
| 18254 |
+ case EbtSamplerCubeShadow: |
| 18255 |
+ return "samplerCubeShadow"; |
| 18256 |
+ case EbtSampler2DArrayShadow: |
| 18257 |
+ return "sampler2DArrayShadow"; |
| 18258 |
+ case EbtSamplerCubeArrayShadow: |
| 18259 |
+ return "samplerCubeArrayShadow"; |
| 18260 |
+ case EbtStruct: |
| 18261 |
+ return "structure"; |
| 18262 |
+ case EbtInterfaceBlock: |
| 18263 |
+ return "interface block"; |
| 18264 |
+ case EbtImage2D: |
| 18265 |
+ return "texture2d"; |
| 18266 |
+ case EbtIImage2D: |
| 18267 |
+ return "texture2d<int>"; |
| 18268 |
+ case EbtUImage2D: |
| 18269 |
+ return "texture2d<uint>"; |
| 18270 |
+ case EbtImage3D: |
| 18271 |
+ return "texture3d"; |
| 18272 |
+ case EbtIImage3D: |
| 18273 |
+ return "texture3d<int>"; |
| 18274 |
+ case EbtUImage3D: |
| 18275 |
+ return "texture3d<uint>"; |
| 18276 |
+ case EbtImage2DArray: |
| 18277 |
+ if (t->isUnsizedArray()) |
| 18278 |
+ { |
| 18279 |
+ return "array_ref<texture2d>"; |
| 18280 |
+ } |
| 18281 |
+ else |
| 18282 |
+ { |
| 18283 |
+ return "NOT_IMPLEMENTED"; |
| 18284 |
+ } |
| 18285 |
+ case EbtIImage2DArray: |
| 18286 |
+ if (t->isUnsizedArray()) |
| 18287 |
+ { |
| 18288 |
+ return "array_ref<texture2d<int>>"; |
| 18289 |
+ } |
| 18290 |
+ else |
| 18291 |
+ { |
| 18292 |
+ return "NOT_IMPLEMENTED"; |
| 18293 |
+ } |
| 18294 |
+ case EbtUImage2DArray: |
| 18295 |
+ if (t->isUnsizedArray()) |
| 18296 |
+ { |
| 18297 |
+ return "array_ref<texture2d<uint>>"; |
| 18298 |
+ } |
| 18299 |
+ else |
| 18300 |
+ { |
| 18301 |
+ return "NOT_IMPLEMENTED"; |
| 18302 |
+ } |
| 18303 |
+ case EbtImageCube: |
| 18304 |
+ return "texturecube"; |
| 18305 |
+ case EbtIImageCube: |
| 18306 |
+ return "texturecube<int>"; |
| 18307 |
+ case EbtUImageCube: |
| 18308 |
+ return "texturecube<uint>"; |
| 18309 |
+ case EbtImageCubeArray: |
| 18310 |
+ if (t->isUnsizedArray()) |
| 18311 |
+ { |
| 18312 |
+ return "array_ref<texturecube>"; |
| 18313 |
+ } |
| 18314 |
+ else |
| 18315 |
+ { |
| 18316 |
+ return "NOT_IMPLEMENTED"; |
| 18317 |
+ } |
| 18318 |
+ case EbtIImageCubeArray: |
| 18319 |
+ if (t->isUnsizedArray()) |
| 18320 |
+ { |
| 18321 |
+ return "array_ref<texturecube<int>>"; |
| 18322 |
+ } |
| 18323 |
+ else |
| 18324 |
+ { |
| 18325 |
+ return "NOT_IMPLEMENTED"; |
| 18326 |
+ } |
| 18327 |
+ case EbtUImageCubeArray: |
| 18328 |
+ if (t->isUnsizedArray()) |
| 18329 |
+ { |
| 18330 |
+ return "array_ref<texturecube<uint>>"; |
| 18331 |
+ } |
| 18332 |
+ else |
| 18333 |
+ { |
| 18334 |
+ return "NOT_IMPLEMENTED"; |
| 18335 |
+ } |
| 18336 |
+ case EbtAtomicCounter: |
| 18337 |
+ return "atomic_uint"; |
| 18338 |
+ case EbtSamplerVideoWEBGL: |
| 18339 |
+ return "$samplerVideoWEBGL"; |
| 18340 |
+ default: |
| 18341 |
+ UNREACHABLE(); |
| 18342 |
+ return "unknown type"; |
| 18343 |
+ } |
| 18344 |
+} |
| 18345 |
+ |
| 18346 |
+const char *getBuiltInMetalTypeNameString(const TType *t) |
| 18347 |
+{ |
| 18348 |
+ if (t->isMatrix()) |
| 18349 |
+ { |
| 18350 |
+ switch (t->getCols()) |
| 18351 |
+ { |
| 18352 |
+ case 2: |
| 18353 |
+ switch (t->getRows()) |
| 18354 |
+ { |
| 18355 |
+ case 2: |
| 18356 |
+ return "float2"; |
| 18357 |
+ case 3: |
| 18358 |
+ return "float2x3"; |
| 18359 |
+ case 4: |
| 18360 |
+ return "float2x4"; |
| 18361 |
+ default: |
| 18362 |
+ UNREACHABLE(); |
| 18363 |
+ return nullptr; |
| 18364 |
+ } |
| 18365 |
+ case 3: |
| 18366 |
+ switch (t->getRows()) |
| 18367 |
+ { |
| 18368 |
+ case 2: |
| 18369 |
+ return "float3x2"; |
| 18370 |
+ case 3: |
| 18371 |
+ return "float3"; |
| 18372 |
+ case 4: |
| 18373 |
+ return "float3x4"; |
| 18374 |
+ default: |
| 18375 |
+ UNREACHABLE(); |
| 18376 |
+ return nullptr; |
| 18377 |
+ } |
| 18378 |
+ case 4: |
| 18379 |
+ switch (t->getRows()) |
| 18380 |
+ { |
| 18381 |
+ case 2: |
| 18382 |
+ return "float4x2"; |
| 18383 |
+ case 3: |
| 18384 |
+ return "float4x3"; |
| 18385 |
+ case 4: |
| 18386 |
+ return "float4"; |
| 18387 |
+ default: |
| 18388 |
+ UNREACHABLE(); |
| 18389 |
+ return nullptr; |
| 18390 |
+ } |
| 18391 |
+ default: |
| 18392 |
+ UNREACHABLE(); |
| 18393 |
+ return nullptr; |
| 18394 |
+ } |
| 18395 |
+ } |
| 18396 |
+ if (t->isVector()) |
| 18397 |
+ { |
| 18398 |
+ switch (t->getBasicType()) |
| 18399 |
+ { |
| 18400 |
+ case EbtFloat: |
| 18401 |
+ switch (t->getNominalSize()) |
| 18402 |
+ { |
| 18403 |
+ case 2: |
| 18404 |
+ return "float2"; |
| 18405 |
+ case 3: |
| 18406 |
+ return "float3"; |
| 18407 |
+ case 4: |
| 18408 |
+ return "float4"; |
| 18409 |
+ default: |
| 18410 |
+ UNREACHABLE(); |
| 18411 |
+ return nullptr; |
| 18412 |
+ } |
| 18413 |
+ case EbtInt: |
| 18414 |
+ switch (t->getNominalSize()) |
| 18415 |
+ { |
| 18416 |
+ case 2: |
| 18417 |
+ return "int2"; |
| 18418 |
+ case 3: |
| 18419 |
+ return "int3"; |
| 18420 |
+ case 4: |
| 18421 |
+ return "int4"; |
| 18422 |
+ default: |
| 18423 |
+ UNREACHABLE(); |
| 18424 |
+ return nullptr; |
| 18425 |
+ } |
| 18426 |
+ case EbtBool: |
| 18427 |
+ switch (t->getNominalSize()) |
| 18428 |
+ { |
| 18429 |
+ case 2: |
| 18430 |
+ return "bool2"; |
| 18431 |
+ case 3: |
| 18432 |
+ return "bool3"; |
| 18433 |
+ case 4: |
| 18434 |
+ return "bool4"; |
| 18435 |
+ default: |
| 18436 |
+ UNREACHABLE(); |
| 18437 |
+ return nullptr; |
| 18438 |
+ } |
| 18439 |
+ case EbtUInt: |
| 18440 |
+ switch (t->getNominalSize()) |
| 18441 |
+ { |
| 18442 |
+ case 2: |
| 18443 |
+ return "uint2"; |
| 18444 |
+ case 3: |
| 18445 |
+ return "uint3"; |
| 18446 |
+ case 4: |
| 18447 |
+ return "uint4"; |
| 18448 |
+ default: |
| 18449 |
+ UNREACHABLE(); |
| 18450 |
+ return nullptr; |
| 18451 |
+ } |
| 18452 |
+ default: |
| 18453 |
+ UNREACHABLE(); |
| 18454 |
+ return nullptr; |
| 18455 |
+ } |
| 18456 |
+ } |
| 18457 |
+ ASSERT(t->getBasicType() != EbtStruct); |
| 18458 |
+ ASSERT(t->getBasicType() != EbtInterfaceBlock); |
| 18459 |
+ return getBasicMetalString(t); |
| 18460 |
+} |
| 18461 |
+ |
| 18462 |
+ImmutableString GetMetalTypeName(const TType &type, ShHashFunction64 hashFunction, NameMap *nameMap) |
| 18463 |
+{ |
| 18464 |
+ if (type.getBasicType() == EbtStruct) |
| 18465 |
+ return HashName(type.getStruct(), hashFunction, nameMap); |
| 18466 |
+ else |
| 18467 |
+ return ImmutableString(getBuiltInMetalTypeNameString(&type)); |
| 18468 |
+} |
| 18469 |
+ |
| 18470 |
+} // namespace sh |
| 18471 |
diff --git a/src/compiler/translator/TranslatorMetalUtils.h b/src/compiler/translator/TranslatorMetalUtils.h |
| 18472 |
new file mode 100644 |
| 18473 |
index 0000000..ce3ce3c |
| 18474 |
--- /dev/null |
| 18475 |
+++ b/src/compiler/translator/TranslatorMetalUtils.h |
| 18476 |
@@ -0,0 +1,31 @@ |
| 18477 |
+// |
| 18478 |
+// Copyright 2002 The ANGLE Project Authors. All rights reserved. |
| 18479 |
+// Use of this source code is governed by a BSD-style license that can be |
| 18480 |
+// found in the LICENSE file. |
| 18481 |
+// |
| 18482 |
+ |
| 18483 |
+#ifndef TRANSLATOR_METAL_UTILS_H_ |
| 18484 |
+#define TRANSLATOR_METAL_UTILS_H_ |
| 18485 |
+ |
| 18486 |
+#include "common/angleutils.h" |
| 18487 |
+#include "common/debug.h" |
| 18488 |
+#include "compiler/translator/BaseTypes.h" |
| 18489 |
+#include "compiler/translator/Common.h" |
| 18490 |
+#include "compiler/translator/HashNames.h" |
| 18491 |
+#include "compiler/translator/ImmutableString.h" |
| 18492 |
+#include "compiler/translator/SymbolUniqueId.h" |
| 18493 |
+#include "compiler/translator/Types.h" |
| 18494 |
+namespace sh |
| 18495 |
+{ |
| 18496 |
+ |
| 18497 |
+const char *getBasicMetalString(const TType *t); |
| 18498 |
+ |
| 18499 |
+const char *getBuiltInMetalTypeNameString(const TType *t); |
| 18500 |
+ |
| 18501 |
+ImmutableString GetMetalTypeName(const TType &type, |
| 18502 |
+ ShHashFunction64 hashFunction, |
| 18503 |
+ NameMap *nameMap); |
| 18504 |
+ |
| 18505 |
+} // namespace sh |
| 18506 |
+ |
| 18507 |
+#endif // TRANSLATOR_METAL_UTILS_H_ |
| 18508 |
diff --git a/src/compiler/translator/TranslatorVulkan.cpp b/src/compiler/translator/TranslatorVulkan.cpp |
| 18509 |
index 201cbc9..c5ec67d 100644 |
| 18510 |
--- a/src/compiler/translator/TranslatorVulkan.cpp |
| 18511 |
+++ b/src/compiler/translator/TranslatorVulkan.cpp |
| 18512 |
@@ -163,6 +163,8 @@ class DeclareDefaultUniformsTraverser : public TIntermTraverser |
| 18513 |
constexpr ImmutableString kFlippedPointCoordName = ImmutableString("flippedPointCoord"); |
| 18514 |
constexpr ImmutableString kFlippedFragCoordName = ImmutableString("flippedFragCoord"); |
| 18515 |
constexpr ImmutableString kEmulatedDepthRangeParams = ImmutableString("ANGLEDepthRangeParams"); |
| 18516 |
+constexpr ImmutableString kUniformsBlockName = ImmutableString("ANGLEUniformBlock"); |
| 18517 |
+constexpr ImmutableString kUniformsVarName = ImmutableString("ANGLEUniforms"); |
| 18518 |
|
| 18519 |
constexpr gl::ShaderMap<const char *> kDefaultUniformNames = { |
| 18520 |
{gl::ShaderType::Vertex, vk::kDefaultUniformsNameVS}, |
| 18521 |
@@ -450,9 +452,9 @@ const TVariable *AddGraphicsDriverUniformsToShader(TIntermBlock *root, |
| 18522 |
additionalFields.end()); |
| 18523 |
|
| 18524 |
// Define a driver uniform block "ANGLEUniformBlock" with instance name "ANGLEUniforms". |
| 18525 |
- return DeclareInterfaceBlock( |
| 18526 |
- root, symbolTable, driverFieldList, EvqUniform, TMemoryQualifier::Create(), 0, |
| 18527 |
- ImmutableString(vk::kDriverUniformsBlockName), ImmutableString(vk::kDriverUniformsVarName)); |
| 18528 |
+ return DeclareInterfaceBlock(root, symbolTable, driverFieldList, EvqUniform, |
| 18529 |
+ TMemoryQualifier::Create(), 0, kUniformsBlockName, |
| 18530 |
+ kUniformsVarName); |
| 18531 |
} |
| 18532 |
|
| 18533 |
const TVariable *AddComputeDriverUniformsToShader(TIntermBlock *root, TSymbolTable *symbolTable) |
| 18534 |
diff --git a/src/compiler/translator/Types.h b/src/compiler/translator/Types.h |
| 18535 |
index a3e0399..8f6fc46 100644 |
| 18536 |
--- a/src/compiler/translator/Types.h |
| 18537 |
+++ b/src/compiler/translator/Types.h |
| 18538 |
@@ -232,6 +232,7 @@ class TType |
| 18539 |
|
| 18540 |
bool isVector() const { return primarySize > 1 && secondarySize == 1; } |
| 18541 |
bool isVectorArray() const { return primarySize > 1 && secondarySize == 1 && isArray(); } |
| 18542 |
+ bool isRank0() const { return primarySize == 1 && secondarySize == 1; } |
| 18543 |
bool isScalar() const |
| 18544 |
{ |
| 18545 |
return primarySize == 1 && secondarySize == 1 && !mStructure && !isArray(); |
| 18546 |
diff --git a/src/compiler/translator/ValidateAST.cpp b/src/compiler/translator/ValidateAST.cpp |
| 18547 |
index 76a8bc2..ba4d6f3 100644 |
| 18548 |
--- a/src/compiler/translator/ValidateAST.cpp |
| 18549 |
+++ b/src/compiler/translator/ValidateAST.cpp |
| 18550 |
@@ -76,12 +76,7 @@ ValidateAST::ValidateAST(TIntermNode *root, |
| 18551 |
TDiagnostics *diagnostics, |
| 18552 |
const ValidateASTOptions &options) |
| 18553 |
: TIntermTraverser(true, false, true, nullptr), mOptions(options), mDiagnostics(diagnostics) |
| 18554 |
-{ |
| 18555 |
- if (mOptions.validateSingleParent) |
| 18556 |
- { |
| 18557 |
- mParent[root] = nullptr; |
| 18558 |
- } |
| 18559 |
-} |
| 18560 |
+{} |
| 18561 |
|
| 18562 |
void ValidateAST::visitNode(Visit visit, TIntermNode *node) |
| 18563 |
{ |
| 18564 |
@@ -91,11 +86,12 @@ void ValidateAST::visitNode(Visit visit, TIntermNode *node) |
| 18565 |
for (size_t i = 0; i < childCount; ++i) |
| 18566 |
{ |
| 18567 |
TIntermNode *child = node->getChildNode(i); |
| 18568 |
- if (mParent.find(child) != mParent.end()) |
| 18569 |
+ TIntermNode *&parent = mParent[child]; |
| 18570 |
+ if (parent) |
| 18571 |
{ |
| 18572 |
// If child is visited twice but through the same parent, the problem is in one of |
| 18573 |
// the ancestors. |
| 18574 |
- if (mParent[child] != node) |
| 18575 |
+ if (parent != node) |
| 18576 |
{ |
| 18577 |
mDiagnostics->error(node->getLine(), "Found child with two parents", |
| 18578 |
"<validateSingleParent>"); |
| 18579 |
@@ -103,17 +99,17 @@ void ValidateAST::visitNode(Visit visit, TIntermNode *node) |
| 18580 |
} |
| 18581 |
} |
| 18582 |
|
| 18583 |
- mParent[child] = node; |
| 18584 |
+ parent = node; |
| 18585 |
} |
| 18586 |
} |
| 18587 |
} |
| 18588 |
|
| 18589 |
-void ValidateAST::expectNonNullChildren(Visit visit, TIntermNode *node, size_t least_count) |
| 18590 |
+void ValidateAST::expectNonNullChildren(Visit visit, TIntermNode *node, size_t leastCount) |
| 18591 |
{ |
| 18592 |
if (visit == PreVisit && mOptions.validateNullNodes) |
| 18593 |
{ |
| 18594 |
size_t childCount = node->getChildCount(); |
| 18595 |
- if (childCount < least_count) |
| 18596 |
+ if (childCount < leastCount) |
| 18597 |
{ |
| 18598 |
mDiagnostics->error(node->getLine(), "Too few children", "<validateNullNodes>"); |
| 18599 |
mNullNodesFailed = true; |
| 18600 |
diff --git a/src/compiler/translator/glslang_tab_autogen.cpp b/src/compiler/translator/glslang_tab_autogen.cpp |
| 18601 |
index 130b98a..33b83db 100644 |
| 18602 |
--- a/src/compiler/translator/glslang_tab_autogen.cpp |
| 18603 |
+++ b/src/compiler/translator/glslang_tab_autogen.cpp |
| 18604 |
@@ -1,5 +1,7 @@ |
| 18605 |
/* A Bison parser, made by GNU Bison 3.3.2. */ |
| 18606 |
|
| 18607 |
+/* Apple Note: For the avoidance of doubt, Apple elects to distribute this file under the terms of the BSD license. */ |
| 18608 |
+ |
| 18609 |
/* Bison implementation for Yacc-like parsers in C |
| 18610 |
|
| 18611 |
Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2019 Free Software Foundation, |
| 18612 |
diff --git a/src/compiler/translator/glslang_tab_autogen.h b/src/compiler/translator/glslang_tab_autogen.h |
| 18613 |
index 5306032..0250300 100644 |
| 18614 |
--- a/src/compiler/translator/glslang_tab_autogen.h |
| 18615 |
+++ b/src/compiler/translator/glslang_tab_autogen.h |
| 18616 |
@@ -1,5 +1,7 @@ |
| 18617 |
/* A Bison parser, made by GNU Bison 3.3.2. */ |
| 18618 |
|
| 18619 |
+/* Apple Note: For the avoidance of doubt, Apple elects to distribute this file under the terms of the BSD license. */ |
| 18620 |
+ |
| 18621 |
/* Bison interface for Yacc-like parsers in C |
| 18622 |
|
| 18623 |
Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2019 Free Software Foundation, |
| 18624 |
diff --git a/src/compiler/translator/tree_ops/DeferGlobalInitializers.cpp b/src/compiler/translator/tree_ops/DeferGlobalInitializers.cpp |
| 18625 |
index dfa23aa..bbc8dcd 100644 |
| 18626 |
--- a/src/compiler/translator/tree_ops/DeferGlobalInitializers.cpp |
| 18627 |
+++ b/src/compiler/translator/tree_ops/DeferGlobalInitializers.cpp |
| 18628 |
@@ -53,7 +53,8 @@ void GetDeferredInitializers(TIntermDeclaration *declaration, |
| 18629 |
ASSERT(symbolNode); |
| 18630 |
TIntermTyped *expression = init->getRight(); |
| 18631 |
|
| 18632 |
- if (expression->getQualifier() != EvqConst || !expression->hasConstantValue()) |
| 18633 |
+ if (expression->getQualifier() != EvqConst || !expression->hasConstantValue() || |
| 18634 |
+ symbolNode->getQualifier() == EvqGlobal) |
| 18635 |
{ |
| 18636 |
// For variables which are not constant, defer their real initialization until |
| 18637 |
// after we initialize uniforms. |
| 18638 |
diff --git a/src/compiler/translator/tree_ops/PruneEmptyCases.cpp b/src/compiler/translator/tree_ops/PruneEmptyCases.cpp |
| 18639 |
index 289de21..2ee8239 100644 |
| 18640 |
--- a/src/compiler/translator/tree_ops/PruneEmptyCases.cpp |
| 18641 |
+++ b/src/compiler/translator/tree_ops/PruneEmptyCases.cpp |
| 18642 |
@@ -17,7 +17,7 @@ namespace sh |
| 18643 |
namespace |
| 18644 |
{ |
| 18645 |
|
| 18646 |
-bool AreEmptyBlocks(TIntermSequence *statements); |
| 18647 |
+bool AreEmptyBlocks(const TIntermSequence *statements); |
| 18648 |
|
| 18649 |
bool IsEmptyBlock(TIntermNode *node) |
| 18650 |
{ |
| 18651 |
@@ -37,7 +37,7 @@ bool IsEmptyBlock(TIntermNode *node) |
| 18652 |
|
| 18653 |
// Return true if all statements in "statements" consist only of empty blocks and no-op statements. |
| 18654 |
// Returns true also if there are no statements. |
| 18655 |
-bool AreEmptyBlocks(TIntermSequence *statements) |
| 18656 |
+bool AreEmptyBlocks(const TIntermSequence *statements) |
| 18657 |
{ |
| 18658 |
for (size_t i = 0u; i < statements->size(); ++i) |
| 18659 |
{ |
| 18660 |
diff --git a/src/compiler/translator/tree_ops/RemoveSwitchFallThrough.cpp b/src/compiler/translator/tree_ops/RemoveSwitchFallThrough.cpp |
| 18661 |
index 4500aea..dd8dd54 100644 |
| 18662 |
--- a/src/compiler/translator/tree_ops/RemoveSwitchFallThrough.cpp |
| 18663 |
+++ b/src/compiler/translator/tree_ops/RemoveSwitchFallThrough.cpp |
| 18664 |
@@ -44,7 +44,7 @@ class RemoveSwitchFallThroughTraverser : public TIntermTraverser |
| 18665 |
bool visitLoop(Visit, TIntermLoop *node) override; |
| 18666 |
bool visitBranch(Visit, TIntermBranch *node) override; |
| 18667 |
|
| 18668 |
- void outputSequence(TIntermSequence *sequence, size_t startIndex); |
| 18669 |
+ void outputSequence(const TIntermSequence *sequence, size_t startIndex); |
| 18670 |
void handlePreviousCase(); |
| 18671 |
|
| 18672 |
TIntermBlock *mStatementList; |
| 18673 |
@@ -153,11 +153,13 @@ bool RemoveSwitchFallThroughTraverser::visitSwitch(Visit, TIntermSwitch *node) |
| 18674 |
return false; |
| 18675 |
} |
| 18676 |
|
| 18677 |
-void RemoveSwitchFallThroughTraverser::outputSequence(TIntermSequence *sequence, size_t startIndex) |
| 18678 |
+void RemoveSwitchFallThroughTraverser::outputSequence(const TIntermSequence *sequence, |
| 18679 |
+ size_t startIndex) |
| 18680 |
{ |
| 18681 |
+ auto &outSeq = *mStatementListOut->getSequence(); |
| 18682 |
for (size_t i = startIndex; i < sequence->size(); ++i) |
| 18683 |
{ |
| 18684 |
- mStatementListOut->getSequence()->push_back(sequence->at(i)); |
| 18685 |
+ outSeq.push_back(sequence->at(i)); |
| 18686 |
} |
| 18687 |
} |
| 18688 |
|
| 18689 |
diff --git a/src/compiler/translator/tree_ops/SimplifyLoopConditions.cpp b/src/compiler/translator/tree_ops/SimplifyLoopConditions.cpp |
| 18690 |
index 7414540..0c2aa8f 100644 |
| 18691 |
--- a/src/compiler/translator/tree_ops/SimplifyLoopConditions.cpp |
| 18692 |
+++ b/src/compiler/translator/tree_ops/SimplifyLoopConditions.cpp |
| 18693 |
@@ -21,10 +21,17 @@ namespace sh |
| 18694 |
namespace |
| 18695 |
{ |
| 18696 |
|
| 18697 |
+struct LoopInfo |
| 18698 |
+{ |
| 18699 |
+ const TVariable *conditionVariable = nullptr; |
| 18700 |
+ TIntermTyped *condition = nullptr; |
| 18701 |
+ TIntermTyped *expression = nullptr; |
| 18702 |
+}; |
| 18703 |
+ |
| 18704 |
class SimplifyLoopConditionsTraverser : public TLValueTrackingTraverser |
| 18705 |
{ |
| 18706 |
public: |
| 18707 |
- SimplifyLoopConditionsTraverser(unsigned int conditionsToSimplifyMask, |
| 18708 |
+ SimplifyLoopConditionsTraverser(const IntermNodePatternMatcher *conditionsToSimplify, |
| 18709 |
TSymbolTable *symbolTable); |
| 18710 |
|
| 18711 |
void traverseLoop(TIntermLoop *node) override; |
| 18712 |
@@ -34,6 +41,7 @@ class SimplifyLoopConditionsTraverser : public TLValueTrackingTraverser |
| 18713 |
bool visitAggregate(Visit visit, TIntermAggregate *node) override; |
| 18714 |
bool visitTernary(Visit visit, TIntermTernary *node) override; |
| 18715 |
bool visitDeclaration(Visit visit, TIntermDeclaration *node) override; |
| 18716 |
+ bool visitBranch(Visit visit, TIntermBranch *node) override; |
| 18717 |
|
| 18718 |
bool foundLoopToChange() const { return mFoundLoopToChange; } |
| 18719 |
|
| 18720 |
@@ -42,16 +50,19 @@ class SimplifyLoopConditionsTraverser : public TLValueTrackingTraverser |
| 18721 |
// found. |
| 18722 |
bool mFoundLoopToChange; |
| 18723 |
bool mInsideLoopInitConditionOrExpression; |
| 18724 |
- IntermNodePatternMatcher mConditionsToSimplify; |
| 18725 |
+ const IntermNodePatternMatcher *mConditionsToSimplify; |
| 18726 |
+ |
| 18727 |
+ private: |
| 18728 |
+ LoopInfo mLoop; |
| 18729 |
}; |
| 18730 |
|
| 18731 |
SimplifyLoopConditionsTraverser::SimplifyLoopConditionsTraverser( |
| 18732 |
- unsigned int conditionsToSimplifyMask, |
| 18733 |
+ const IntermNodePatternMatcher *conditionsToSimplify, |
| 18734 |
TSymbolTable *symbolTable) |
| 18735 |
: TLValueTrackingTraverser(true, false, false, symbolTable), |
| 18736 |
mFoundLoopToChange(false), |
| 18737 |
mInsideLoopInitConditionOrExpression(false), |
| 18738 |
- mConditionsToSimplify(conditionsToSimplifyMask) |
| 18739 |
+ mConditionsToSimplify(conditionsToSimplify) |
| 18740 |
{} |
| 18741 |
|
| 18742 |
// If we're inside a loop initialization, condition, or expression, we check for expressions that |
| 18743 |
@@ -68,7 +79,8 @@ bool SimplifyLoopConditionsTraverser::visitUnary(Visit visit, TIntermUnary *node |
| 18744 |
if (mFoundLoopToChange) |
| 18745 |
return false; // Already decided to change this loop. |
| 18746 |
|
| 18747 |
- mFoundLoopToChange = mConditionsToSimplify.match(node); |
| 18748 |
+ ASSERT(mConditionsToSimplify); |
| 18749 |
+ mFoundLoopToChange = mConditionsToSimplify->match(node); |
| 18750 |
return !mFoundLoopToChange; |
| 18751 |
} |
| 18752 |
|
| 18753 |
@@ -80,7 +92,9 @@ bool SimplifyLoopConditionsTraverser::visitBinary(Visit visit, TIntermBinary *no |
| 18754 |
if (mFoundLoopToChange) |
| 18755 |
return false; // Already decided to change this loop. |
| 18756 |
|
| 18757 |
- mFoundLoopToChange = mConditionsToSimplify.match(node, getParentNode(), isLValueRequiredHere()); |
| 18758 |
+ ASSERT(mConditionsToSimplify); |
| 18759 |
+ mFoundLoopToChange = |
| 18760 |
+ mConditionsToSimplify->match(node, getParentNode(), isLValueRequiredHere()); |
| 18761 |
return !mFoundLoopToChange; |
| 18762 |
} |
| 18763 |
|
| 18764 |
@@ -92,7 +106,8 @@ bool SimplifyLoopConditionsTraverser::visitAggregate(Visit visit, TIntermAggrega |
| 18765 |
if (mFoundLoopToChange) |
| 18766 |
return false; // Already decided to change this loop. |
| 18767 |
|
| 18768 |
- mFoundLoopToChange = mConditionsToSimplify.match(node, getParentNode()); |
| 18769 |
+ ASSERT(mConditionsToSimplify); |
| 18770 |
+ mFoundLoopToChange = mConditionsToSimplify->match(node, getParentNode()); |
| 18771 |
return !mFoundLoopToChange; |
| 18772 |
} |
| 18773 |
|
| 18774 |
@@ -104,7 +119,8 @@ bool SimplifyLoopConditionsTraverser::visitTernary(Visit visit, TIntermTernary * |
| 18775 |
if (mFoundLoopToChange) |
| 18776 |
return false; // Already decided to change this loop. |
| 18777 |
|
| 18778 |
- mFoundLoopToChange = mConditionsToSimplify.match(node); |
| 18779 |
+ ASSERT(mConditionsToSimplify); |
| 18780 |
+ mFoundLoopToChange = mConditionsToSimplify->match(node); |
| 18781 |
return !mFoundLoopToChange; |
| 18782 |
} |
| 18783 |
|
| 18784 |
@@ -116,10 +132,35 @@ bool SimplifyLoopConditionsTraverser::visitDeclaration(Visit visit, TIntermDecla |
| 18785 |
if (mFoundLoopToChange) |
| 18786 |
return false; // Already decided to change this loop. |
| 18787 |
|
| 18788 |
- mFoundLoopToChange = mConditionsToSimplify.match(node); |
| 18789 |
+ ASSERT(mConditionsToSimplify); |
| 18790 |
+ mFoundLoopToChange = mConditionsToSimplify->match(node); |
| 18791 |
return !mFoundLoopToChange; |
| 18792 |
} |
| 18793 |
|
| 18794 |
+bool SimplifyLoopConditionsTraverser::visitBranch(Visit visit, TIntermBranch *node) |
| 18795 |
+{ |
| 18796 |
+ if (node->getFlowOp() == EOpContinue && (mLoop.condition || mLoop.expression)) |
| 18797 |
+ { |
| 18798 |
+ TIntermBlock *parent = getParentNode()->getAsBlock(); |
| 18799 |
+ ASSERT(parent); |
| 18800 |
+ TIntermSequence seq; |
| 18801 |
+ if (mLoop.expression) |
| 18802 |
+ { |
| 18803 |
+ seq.push_back(mLoop.expression->deepCopy()); |
| 18804 |
+ } |
| 18805 |
+ if (mLoop.condition) |
| 18806 |
+ { |
| 18807 |
+ ASSERT(mLoop.conditionVariable); |
| 18808 |
+ seq.push_back( |
| 18809 |
+ CreateTempAssignmentNode(mLoop.conditionVariable, mLoop.condition->deepCopy())); |
| 18810 |
+ } |
| 18811 |
+ seq.push_back(node); |
| 18812 |
+ mMultiReplacements.push_back(NodeReplaceWithMultipleEntry(parent, node, std::move(seq))); |
| 18813 |
+ } |
| 18814 |
+ |
| 18815 |
+ return true; |
| 18816 |
+} |
| 18817 |
+ |
| 18818 |
void SimplifyLoopConditionsTraverser::traverseLoop(TIntermLoop *node) |
| 18819 |
{ |
| 18820 |
// Mark that we're inside a loop condition or expression, and determine if the loop needs to be |
| 18821 |
@@ -128,7 +169,7 @@ void SimplifyLoopConditionsTraverser::traverseLoop(TIntermLoop *node) |
| 18822 |
ScopedNodeInTraversalPath addToPath(this, node); |
| 18823 |
|
| 18824 |
mInsideLoopInitConditionOrExpression = true; |
| 18825 |
- mFoundLoopToChange = false; |
| 18826 |
+ mFoundLoopToChange = !mConditionsToSimplify; |
| 18827 |
|
| 18828 |
if (!mFoundLoopToChange && node->getInit()) |
| 18829 |
{ |
| 18830 |
@@ -147,22 +188,54 @@ void SimplifyLoopConditionsTraverser::traverseLoop(TIntermLoop *node) |
| 18831 |
|
| 18832 |
mInsideLoopInitConditionOrExpression = false; |
| 18833 |
|
| 18834 |
+ const LoopInfo prevLoop = mLoop; |
| 18835 |
+ |
| 18836 |
if (mFoundLoopToChange) |
| 18837 |
{ |
| 18838 |
const TType *boolType = StaticType::Get<EbtBool, EbpUndefined, EvqTemporary, 1, 1>(); |
| 18839 |
- TVariable *conditionVariable = CreateTempVariable(mSymbolTable, boolType); |
| 18840 |
+ mLoop.conditionVariable = CreateTempVariable(mSymbolTable, boolType); |
| 18841 |
+ mLoop.condition = node->getCondition(); |
| 18842 |
+ mLoop.expression = node->getExpression(); |
| 18843 |
|
| 18844 |
// Replace the loop condition with a boolean variable that's updated on each iteration. |
| 18845 |
TLoopType loopType = node->getType(); |
| 18846 |
if (loopType == ELoopWhile) |
| 18847 |
+ { |
| 18848 |
+ ASSERT(!mLoop.expression); |
| 18849 |
+ |
| 18850 |
+ if (mLoop.condition->getAsSymbolNode()) |
| 18851 |
+ { |
| 18852 |
+ // Mask continue statement condition variable update. |
| 18853 |
+ mLoop.condition = nullptr; |
| 18854 |
+ } |
| 18855 |
+ else if (mLoop.condition->getAsConstantUnion()) |
| 18856 |
+ { |
| 18857 |
+ // Transform: |
| 18858 |
+ // while (expr) { body; } |
| 18859 |
+ // into |
| 18860 |
+ // bool s0 = expr; |
| 18861 |
+ // while (s0) { body; } |
| 18862 |
+ TIntermDeclaration *tempInitDeclaration = |
| 18863 |
+ CreateTempInitDeclarationNode(mLoop.conditionVariable, mLoop.condition); |
| 18864 |
+ insertStatementInParentBlock(tempInitDeclaration); |
| 18865 |
+ |
| 18866 |
+ node->setCondition(CreateTempSymbolNode(mLoop.conditionVariable)); |
| 18867 |
+ |
| 18868 |
+ // Mask continue statement condition variable update. |
| 18869 |
+ mLoop.condition = nullptr; |
| 18870 |
+ } |
| 18871 |
+ else |
| 18872 |
{ |
| 18873 |
// Transform: |
| 18874 |
// while (expr) { body; } |
| 18875 |
// into |
| 18876 |
// bool s0 = expr; |
| 18877 |
// while (s0) { { body; } s0 = expr; } |
| 18878 |
+ // |
| 18879 |
+ // Local case statements are transformed into: |
| 18880 |
+ // s0 = expr; continue; |
| 18881 |
TIntermDeclaration *tempInitDeclaration = |
| 18882 |
- CreateTempInitDeclarationNode(conditionVariable, node->getCondition()->deepCopy()); |
| 18883 |
+ CreateTempInitDeclarationNode(mLoop.conditionVariable, mLoop.condition); |
| 18884 |
insertStatementInParentBlock(tempInitDeclaration); |
| 18885 |
|
| 18886 |
TIntermBlock *newBody = new TIntermBlock(); |
| 18887 |
@@ -171,28 +244,60 @@ void SimplifyLoopConditionsTraverser::traverseLoop(TIntermLoop *node) |
| 18888 |
newBody->getSequence()->push_back(node->getBody()); |
| 18889 |
} |
| 18890 |
newBody->getSequence()->push_back( |
| 18891 |
- CreateTempAssignmentNode(conditionVariable, node->getCondition()->deepCopy())); |
| 18892 |
+ CreateTempAssignmentNode(mLoop.conditionVariable, mLoop.condition->deepCopy())); |
| 18893 |
|
| 18894 |
// Can't use queueReplacement to replace old body, since it may have been nullptr. |
| 18895 |
// It's safe to do the replacements in place here - the new body will still be |
| 18896 |
// traversed, but that won't create any problems. |
| 18897 |
node->setBody(newBody); |
| 18898 |
- node->setCondition(CreateTempSymbolNode(conditionVariable)); |
| 18899 |
+ node->setCondition(CreateTempSymbolNode(mLoop.conditionVariable)); |
| 18900 |
+ } |
| 18901 |
} |
| 18902 |
else if (loopType == ELoopDoWhile) |
| 18903 |
+ { |
| 18904 |
+ ASSERT(!mLoop.expression); |
| 18905 |
+ |
| 18906 |
+ if (mLoop.condition->getAsSymbolNode()) |
| 18907 |
+ { |
| 18908 |
+ // Mask continue statement condition variable update. |
| 18909 |
+ mLoop.condition = nullptr; |
| 18910 |
+ } |
| 18911 |
+ else if (mLoop.condition->getAsConstantUnion()) |
| 18912 |
+ { |
| 18913 |
+ // Transform: |
| 18914 |
+ // do { |
| 18915 |
+ // body; |
| 18916 |
+ // } while (expr); |
| 18917 |
+ // into |
| 18918 |
+ // bool s0 = expr; |
| 18919 |
+ // do { |
| 18920 |
+ // body; |
| 18921 |
+ // } while (s0); |
| 18922 |
+ TIntermDeclaration *tempInitDeclaration = |
| 18923 |
+ CreateTempInitDeclarationNode(mLoop.conditionVariable, mLoop.condition); |
| 18924 |
+ insertStatementInParentBlock(tempInitDeclaration); |
| 18925 |
+ |
| 18926 |
+ node->setCondition(CreateTempSymbolNode(mLoop.conditionVariable)); |
| 18927 |
+ |
| 18928 |
+ // Mask continue statement condition variable update. |
| 18929 |
+ mLoop.condition = nullptr; |
| 18930 |
+ } |
| 18931 |
+ else |
| 18932 |
{ |
| 18933 |
// Transform: |
| 18934 |
// do { |
| 18935 |
// body; |
| 18936 |
// } while (expr); |
| 18937 |
// into |
| 18938 |
- // bool s0 = true; |
| 18939 |
+ // bool s0; |
| 18940 |
// do { |
| 18941 |
// { body; } |
| 18942 |
// s0 = expr; |
| 18943 |
// } while (s0); |
| 18944 |
+ // Local case statements are transformed into: |
| 18945 |
+ // s0 = expr; continue; |
| 18946 |
TIntermDeclaration *tempInitDeclaration = |
| 18947 |
- CreateTempInitDeclarationNode(conditionVariable, CreateBoolNode(true)); |
| 18948 |
+ CreateTempDeclarationNode(mLoop.conditionVariable); |
| 18949 |
insertStatementInParentBlock(tempInitDeclaration); |
| 18950 |
|
| 18951 |
TIntermBlock *newBody = new TIntermBlock(); |
| 18952 |
@@ -201,15 +306,68 @@ void SimplifyLoopConditionsTraverser::traverseLoop(TIntermLoop *node) |
| 18953 |
newBody->getSequence()->push_back(node->getBody()); |
| 18954 |
} |
| 18955 |
newBody->getSequence()->push_back( |
| 18956 |
- CreateTempAssignmentNode(conditionVariable, node->getCondition()->deepCopy())); |
| 18957 |
+ CreateTempAssignmentNode(mLoop.conditionVariable, mLoop.condition)); |
| 18958 |
|
| 18959 |
// Can't use queueReplacement to replace old body, since it may have been nullptr. |
| 18960 |
// It's safe to do the replacements in place here - the new body will still be |
| 18961 |
// traversed, but that won't create any problems. |
| 18962 |
node->setBody(newBody); |
| 18963 |
- node->setCondition(CreateTempSymbolNode(conditionVariable)); |
| 18964 |
+ node->setCondition(CreateTempSymbolNode(mLoop.conditionVariable)); |
| 18965 |
+ } |
| 18966 |
} |
| 18967 |
else if (loopType == ELoopFor) |
| 18968 |
+ { |
| 18969 |
+ if (!mLoop.condition) |
| 18970 |
+ { |
| 18971 |
+ mLoop.condition = CreateBoolNode(true); |
| 18972 |
+ } |
| 18973 |
+ |
| 18974 |
+ TIntermLoop *whileLoop; |
| 18975 |
+ TIntermBlock *loopScope = new TIntermBlock(); |
| 18976 |
+ TIntermSequence *loopScopeSequence = loopScope->getSequence(); |
| 18977 |
+ |
| 18978 |
+ // Insert "init;" |
| 18979 |
+ if (node->getInit()) |
| 18980 |
+ { |
| 18981 |
+ loopScopeSequence->push_back(node->getInit()); |
| 18982 |
+ } |
| 18983 |
+ |
| 18984 |
+ if (mLoop.condition->getAsSymbolNode()) |
| 18985 |
+ { |
| 18986 |
+ // Move the loop condition inside the loop. |
| 18987 |
+ // Transform: |
| 18988 |
+ // for (init; expr; exprB) { body; } |
| 18989 |
+ // into |
| 18990 |
+ // { |
| 18991 |
+ // init; |
| 18992 |
+ // while (expr) { |
| 18993 |
+ // { body; } |
| 18994 |
+ // exprB; |
| 18995 |
+ // } |
| 18996 |
+ // } |
| 18997 |
+ // |
| 18998 |
+ // Local case statements are transformed into: |
| 18999 |
+ // exprB; continue; |
| 19000 |
+ |
| 19001 |
+ // Insert "{ body; }" in the while loop |
| 19002 |
+ TIntermBlock *whileLoopBody = new TIntermBlock(); |
| 19003 |
+ if (node->getBody()) |
| 19004 |
+ { |
| 19005 |
+ whileLoopBody->getSequence()->push_back(node->getBody()); |
| 19006 |
+ } |
| 19007 |
+ // Insert "exprB;" in the while loop |
| 19008 |
+ if (node->getExpression()) |
| 19009 |
+ { |
| 19010 |
+ whileLoopBody->getSequence()->push_back(node->getExpression()); |
| 19011 |
+ } |
| 19012 |
+ // Create "while(expr) { whileLoopBody }" |
| 19013 |
+ whileLoop = |
| 19014 |
+ new TIntermLoop(ELoopWhile, nullptr, mLoop.condition, nullptr, whileLoopBody); |
| 19015 |
+ |
| 19016 |
+ // Mask continue statement condition variable update. |
| 19017 |
+ mLoop.condition = nullptr; |
| 19018 |
+ } |
| 19019 |
+ else if (mLoop.condition->getAsConstantUnion()) |
| 19020 |
{ |
| 19021 |
// Move the loop condition inside the loop. |
| 19022 |
// Transform: |
| 19023 |
@@ -221,31 +379,56 @@ void SimplifyLoopConditionsTraverser::traverseLoop(TIntermLoop *node) |
| 19024 |
// while (s0) { |
| 19025 |
// { body; } |
| 19026 |
// exprB; |
| 19027 |
- // s0 = expr; |
| 19028 |
// } |
| 19029 |
// } |
| 19030 |
- TIntermBlock *loopScope = new TIntermBlock(); |
| 19031 |
- TIntermSequence *loopScopeSequence = loopScope->getSequence(); |
| 19032 |
+ // |
| 19033 |
+ // Local case statements are transformed into: |
| 19034 |
+ // exprB; continue; |
| 19035 |
|
| 19036 |
- // Insert "init;" |
| 19037 |
- if (node->getInit()) |
| 19038 |
+ // Insert "bool s0 = expr;" |
| 19039 |
+ loopScopeSequence->push_back( |
| 19040 |
+ CreateTempInitDeclarationNode(mLoop.conditionVariable, mLoop.condition)); |
| 19041 |
+ // Insert "{ body; }" in the while loop |
| 19042 |
+ TIntermBlock *whileLoopBody = new TIntermBlock(); |
| 19043 |
+ if (node->getBody()) |
| 19044 |
{ |
| 19045 |
- loopScopeSequence->push_back(node->getInit()); |
| 19046 |
+ whileLoopBody->getSequence()->push_back(node->getBody()); |
| 19047 |
} |
| 19048 |
- |
| 19049 |
- // Insert "bool s0 = expr;" if applicable, "bool s0 = true;" otherwise |
| 19050 |
- TIntermTyped *conditionInitializer = nullptr; |
| 19051 |
- if (node->getCondition()) |
| 19052 |
+ // Insert "exprB;" in the while loop |
| 19053 |
+ if (node->getExpression()) |
| 19054 |
{ |
| 19055 |
- conditionInitializer = node->getCondition()->deepCopy(); |
| 19056 |
+ whileLoopBody->getSequence()->push_back(node->getExpression()); |
| 19057 |
+ } |
| 19058 |
+ // Create "while(s0) { whileLoopBody }" |
| 19059 |
+ whileLoop = new TIntermLoop(ELoopWhile, nullptr, |
| 19060 |
+ CreateTempSymbolNode(mLoop.conditionVariable), nullptr, |
| 19061 |
+ whileLoopBody); |
| 19062 |
+ |
| 19063 |
+ // Mask continue statement condition variable update. |
| 19064 |
+ mLoop.condition = nullptr; |
| 19065 |
} |
| 19066 |
else |
| 19067 |
{ |
| 19068 |
- conditionInitializer = CreateBoolNode(true); |
| 19069 |
- } |
| 19070 |
- loopScopeSequence->push_back( |
| 19071 |
- CreateTempInitDeclarationNode(conditionVariable, conditionInitializer)); |
| 19072 |
+ // Move the loop condition inside the loop. |
| 19073 |
+ // Transform: |
| 19074 |
+ // for (init; expr; exprB) { body; } |
| 19075 |
+ // into |
| 19076 |
+ // { |
| 19077 |
+ // init; |
| 19078 |
+ // bool s0 = expr; |
| 19079 |
+ // while (s0) { |
| 19080 |
+ // { body; } |
| 19081 |
+ // exprB; |
| 19082 |
+ // s0 = expr; |
| 19083 |
+ // } |
| 19084 |
+ // } |
| 19085 |
+ // |
| 19086 |
+ // Local case statements are transformed into: |
| 19087 |
+ // exprB; s0 = expr; continue; |
| 19088 |
|
| 19089 |
+ // Insert "bool s0 = expr;" |
| 19090 |
+ loopScopeSequence->push_back( |
| 19091 |
+ CreateTempInitDeclarationNode(mLoop.conditionVariable, mLoop.condition)); |
| 19092 |
// Insert "{ body; }" in the while loop |
| 19093 |
TIntermBlock *whileLoopBody = new TIntermBlock(); |
| 19094 |
if (node->getBody()) |
| 19095 |
@@ -258,23 +441,21 @@ void SimplifyLoopConditionsTraverser::traverseLoop(TIntermLoop *node) |
| 19096 |
whileLoopBody->getSequence()->push_back(node->getExpression()); |
| 19097 |
} |
| 19098 |
// Insert "s0 = expr;" in the while loop |
| 19099 |
- if (node->getCondition()) |
| 19100 |
- { |
| 19101 |
whileLoopBody->getSequence()->push_back( |
| 19102 |
- CreateTempAssignmentNode(conditionVariable, node->getCondition()->deepCopy())); |
| 19103 |
+ CreateTempAssignmentNode(mLoop.conditionVariable, mLoop.condition->deepCopy())); |
| 19104 |
+ // Create "while(s0) { whileLoopBody }" |
| 19105 |
+ whileLoop = new TIntermLoop(ELoopWhile, nullptr, |
| 19106 |
+ CreateTempSymbolNode(mLoop.conditionVariable), nullptr, |
| 19107 |
+ whileLoopBody); |
| 19108 |
} |
| 19109 |
|
| 19110 |
- // Create "while(s0) { whileLoopBody }" |
| 19111 |
- TIntermLoop *whileLoop = |
| 19112 |
- new TIntermLoop(ELoopWhile, nullptr, CreateTempSymbolNode(conditionVariable), |
| 19113 |
- nullptr, whileLoopBody); |
| 19114 |
loopScope->getSequence()->push_back(whileLoop); |
| 19115 |
queueReplacement(loopScope, OriginalNode::IS_DROPPED); |
| 19116 |
|
| 19117 |
// After this the old body node will be traversed and loops inside it may be |
| 19118 |
- // transformed. This is fine, since the old body node will still be in the AST after the |
| 19119 |
- // transformation that's queued here, and transforming loops inside it doesn't need to |
| 19120 |
- // know the exact post-transform path to it. |
| 19121 |
+ // transformed. This is fine, since the old body node will still be in the AST after |
| 19122 |
+ // the transformation that's queued here, and transforming loops inside it doesn't |
| 19123 |
+ // need to know the exact post-transform path to it. |
| 19124 |
} |
| 19125 |
} |
| 19126 |
|
| 19127 |
@@ -283,16 +464,26 @@ void SimplifyLoopConditionsTraverser::traverseLoop(TIntermLoop *node) |
| 19128 |
// We traverse the body of the loop even if the loop is transformed. |
| 19129 |
if (node->getBody()) |
| 19130 |
node->getBody()->traverse(this); |
| 19131 |
+ |
| 19132 |
+ mLoop = prevLoop; |
| 19133 |
} |
| 19134 |
|
| 19135 |
} // namespace |
| 19136 |
|
| 19137 |
+bool SimplifyLoopConditions(TCompiler *compiler, TIntermNode *root, TSymbolTable *symbolTable) |
| 19138 |
+{ |
| 19139 |
+ SimplifyLoopConditionsTraverser traverser(nullptr, symbolTable); |
| 19140 |
+ root->traverse(&traverser); |
| 19141 |
+ return traverser.updateTree(compiler, root); |
| 19142 |
+} |
| 19143 |
+ |
| 19144 |
bool SimplifyLoopConditions(TCompiler *compiler, |
| 19145 |
TIntermNode *root, |
| 19146 |
unsigned int conditionsToSimplifyMask, |
| 19147 |
TSymbolTable *symbolTable) |
| 19148 |
{ |
| 19149 |
- SimplifyLoopConditionsTraverser traverser(conditionsToSimplifyMask, symbolTable); |
| 19150 |
+ IntermNodePatternMatcher conditionsToSimplify(conditionsToSimplifyMask); |
| 19151 |
+ SimplifyLoopConditionsTraverser traverser(&conditionsToSimplify, symbolTable); |
| 19152 |
root->traverse(&traverser); |
| 19153 |
return traverser.updateTree(compiler, root); |
| 19154 |
} |
| 19155 |
diff --git a/src/compiler/translator/tree_ops/SimplifyLoopConditions.h b/src/compiler/translator/tree_ops/SimplifyLoopConditions.h |
| 19156 |
index 4cdede6..68b98f8 100644 |
| 19157 |
--- a/src/compiler/translator/tree_ops/SimplifyLoopConditions.h |
| 19158 |
+++ b/src/compiler/translator/tree_ops/SimplifyLoopConditions.h |
| 19159 |
@@ -19,6 +19,10 @@ class TCompiler; |
| 19160 |
class TIntermNode; |
| 19161 |
class TSymbolTable; |
| 19162 |
|
| 19163 |
+ANGLE_NO_DISCARD bool SimplifyLoopConditions(TCompiler *compiler, |
| 19164 |
+ TIntermNode *root, |
| 19165 |
+ TSymbolTable *symbolTable); |
| 19166 |
+ |
| 19167 |
ANGLE_NO_DISCARD bool SimplifyLoopConditions(TCompiler *compiler, |
| 19168 |
TIntermNode *root, |
| 19169 |
unsigned int conditionsToSimplify, |
| 19170 |
diff --git a/src/compiler/translator/tree_util/AsNode.h b/src/compiler/translator/tree_util/AsNode.h |
| 19171 |
new file mode 100644 |
| 19172 |
index 0000000..1c6de18 |
| 19173 |
--- /dev/null |
| 19174 |
+++ b/src/compiler/translator/tree_util/AsNode.h |
| 19175 |
@@ -0,0 +1,212 @@ |
| 19176 |
+// |
| 19177 |
+// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 19178 |
+// Use of this source code is governed by a BSD-style license that can be |
| 19179 |
+// found in the LICENSE file. |
| 19180 |
+// |
| 19181 |
+ |
| 19182 |
+#ifndef COMPILER_TRANSLATOR_TREEUTIL_INTERMASNODE_H_ |
| 19183 |
+#define COMPILER_TRANSLATOR_TREEUTIL_INTERMASNODE_H_ |
| 19184 |
+ |
| 19185 |
+#include "common/angleutils.h" |
| 19186 |
+#include "compiler/translator/IntermNode.h" |
| 19187 |
+ |
| 19188 |
+#include <utility> |
| 19189 |
+ |
| 19190 |
+namespace sh |
| 19191 |
+{ |
| 19192 |
+ |
| 19193 |
+namespace priv |
| 19194 |
+{ |
| 19195 |
+ |
| 19196 |
+template <typename T> |
| 19197 |
+struct AsNode |
| 19198 |
+{}; |
| 19199 |
+ |
| 19200 |
+template <> |
| 19201 |
+struct AsNode<TIntermNode> |
| 19202 |
+{ |
| 19203 |
+ static ANGLE_INLINE TIntermNode *exec(TIntermNode *node) { return node; } |
| 19204 |
+}; |
| 19205 |
+ |
| 19206 |
+template <> |
| 19207 |
+struct AsNode<TIntermTyped> |
| 19208 |
+{ |
| 19209 |
+ static ANGLE_INLINE TIntermTyped *exec(TIntermNode *node) |
| 19210 |
+ { |
| 19211 |
+ return node ? node->getAsTyped() : nullptr; |
| 19212 |
+ } |
| 19213 |
+}; |
| 19214 |
+ |
| 19215 |
+template <> |
| 19216 |
+struct AsNode<TIntermSymbol> |
| 19217 |
+{ |
| 19218 |
+ static ANGLE_INLINE TIntermSymbol *exec(TIntermNode *node) |
| 19219 |
+ { |
| 19220 |
+ return node ? node->getAsSymbolNode() : nullptr; |
| 19221 |
+ } |
| 19222 |
+}; |
| 19223 |
+ |
| 19224 |
+template <> |
| 19225 |
+struct AsNode<TIntermConstantUnion> |
| 19226 |
+{ |
| 19227 |
+ static ANGLE_INLINE TIntermConstantUnion *exec(TIntermNode *node) |
| 19228 |
+ { |
| 19229 |
+ return node ? node->getAsConstantUnion() : nullptr; |
| 19230 |
+ } |
| 19231 |
+}; |
| 19232 |
+ |
| 19233 |
+template <> |
| 19234 |
+struct AsNode<TIntermFunctionPrototype> |
| 19235 |
+{ |
| 19236 |
+ static ANGLE_INLINE TIntermFunctionPrototype *exec(TIntermNode *node) |
| 19237 |
+ { |
| 19238 |
+ return node ? node->getAsFunctionPrototypeNode() : nullptr; |
| 19239 |
+ } |
| 19240 |
+}; |
| 19241 |
+ |
| 19242 |
+template <> |
| 19243 |
+struct AsNode<TIntermPreprocessorDirective> |
| 19244 |
+{ |
| 19245 |
+ static ANGLE_INLINE TIntermPreprocessorDirective *exec(TIntermNode *node) |
| 19246 |
+ { |
| 19247 |
+ return node ? node->getAsPreprocessorDirective() : nullptr; |
| 19248 |
+ } |
| 19249 |
+}; |
| 19250 |
+ |
| 19251 |
+template <> |
| 19252 |
+struct AsNode<TIntermSwizzle> |
| 19253 |
+{ |
| 19254 |
+ static ANGLE_INLINE TIntermSwizzle *exec(TIntermNode *node) |
| 19255 |
+ { |
| 19256 |
+ return node ? node->getAsSwizzleNode() : nullptr; |
| 19257 |
+ } |
| 19258 |
+}; |
| 19259 |
+ |
| 19260 |
+template <> |
| 19261 |
+struct AsNode<TIntermBinary> |
| 19262 |
+{ |
| 19263 |
+ static ANGLE_INLINE TIntermBinary *exec(TIntermNode *node) |
| 19264 |
+ { |
| 19265 |
+ return node ? node->getAsBinaryNode() : nullptr; |
| 19266 |
+ } |
| 19267 |
+}; |
| 19268 |
+ |
| 19269 |
+template <> |
| 19270 |
+struct AsNode<TIntermUnary> |
| 19271 |
+{ |
| 19272 |
+ static ANGLE_INLINE TIntermUnary *exec(TIntermNode *node) |
| 19273 |
+ { |
| 19274 |
+ return node ? node->getAsUnaryNode() : nullptr; |
| 19275 |
+ } |
| 19276 |
+}; |
| 19277 |
+ |
| 19278 |
+template <> |
| 19279 |
+struct AsNode<TIntermTernary> |
| 19280 |
+{ |
| 19281 |
+ static ANGLE_INLINE TIntermTernary *exec(TIntermNode *node) |
| 19282 |
+ { |
| 19283 |
+ return node ? node->getAsTernaryNode() : nullptr; |
| 19284 |
+ } |
| 19285 |
+}; |
| 19286 |
+ |
| 19287 |
+template <> |
| 19288 |
+struct AsNode<TIntermIfElse> |
| 19289 |
+{ |
| 19290 |
+ static ANGLE_INLINE TIntermIfElse *exec(TIntermNode *node) |
| 19291 |
+ { |
| 19292 |
+ return node ? node->getAsIfElseNode() : nullptr; |
| 19293 |
+ } |
| 19294 |
+}; |
| 19295 |
+ |
| 19296 |
+template <> |
| 19297 |
+struct AsNode<TIntermSwitch> |
| 19298 |
+{ |
| 19299 |
+ static ANGLE_INLINE TIntermSwitch *exec(TIntermNode *node) |
| 19300 |
+ { |
| 19301 |
+ return node ? node->getAsSwitchNode() : nullptr; |
| 19302 |
+ } |
| 19303 |
+}; |
| 19304 |
+ |
| 19305 |
+template <> |
| 19306 |
+struct AsNode<TIntermCase> |
| 19307 |
+{ |
| 19308 |
+ static ANGLE_INLINE TIntermCase *exec(TIntermNode *node) |
| 19309 |
+ { |
| 19310 |
+ return node ? node->getAsCaseNode() : nullptr; |
| 19311 |
+ } |
| 19312 |
+}; |
| 19313 |
+ |
| 19314 |
+template <> |
| 19315 |
+struct AsNode<TIntermFunctionDefinition> |
| 19316 |
+{ |
| 19317 |
+ static ANGLE_INLINE TIntermFunctionDefinition *exec(TIntermNode *node) |
| 19318 |
+ { |
| 19319 |
+ return node ? node->getAsFunctionDefinition() : nullptr; |
| 19320 |
+ } |
| 19321 |
+}; |
| 19322 |
+ |
| 19323 |
+template <> |
| 19324 |
+struct AsNode<TIntermAggregate> |
| 19325 |
+{ |
| 19326 |
+ static ANGLE_INLINE TIntermAggregate *exec(TIntermNode *node) |
| 19327 |
+ { |
| 19328 |
+ return node ? node->getAsAggregate() : nullptr; |
| 19329 |
+ } |
| 19330 |
+}; |
| 19331 |
+ |
| 19332 |
+template <> |
| 19333 |
+struct AsNode<TIntermBlock> |
| 19334 |
+{ |
| 19335 |
+ static ANGLE_INLINE TIntermBlock *exec(TIntermNode *node) |
| 19336 |
+ { |
| 19337 |
+ return node ? node->getAsBlock() : nullptr; |
| 19338 |
+ } |
| 19339 |
+}; |
| 19340 |
+ |
| 19341 |
+template <> |
| 19342 |
+struct AsNode<TIntermGlobalQualifierDeclaration> |
| 19343 |
+{ |
| 19344 |
+ static ANGLE_INLINE TIntermGlobalQualifierDeclaration *exec(TIntermNode *node) |
| 19345 |
+ { |
| 19346 |
+ return node ? node->getAsGlobalQualifierDeclarationNode() : nullptr; |
| 19347 |
+ } |
| 19348 |
+}; |
| 19349 |
+ |
| 19350 |
+template <> |
| 19351 |
+struct AsNode<TIntermDeclaration> |
| 19352 |
+{ |
| 19353 |
+ static ANGLE_INLINE TIntermDeclaration *exec(TIntermNode *node) |
| 19354 |
+ { |
| 19355 |
+ return node ? node->getAsDeclarationNode() : nullptr; |
| 19356 |
+ } |
| 19357 |
+}; |
| 19358 |
+ |
| 19359 |
+template <> |
| 19360 |
+struct AsNode<TIntermLoop> |
| 19361 |
+{ |
| 19362 |
+ static ANGLE_INLINE TIntermLoop *exec(TIntermNode *node) |
| 19363 |
+ { |
| 19364 |
+ return node ? node->getAsLoopNode() : nullptr; |
| 19365 |
+ } |
| 19366 |
+}; |
| 19367 |
+ |
| 19368 |
+template <> |
| 19369 |
+struct AsNode<TIntermBranch> |
| 19370 |
+{ |
| 19371 |
+ static ANGLE_INLINE TIntermBranch *exec(TIntermNode *node) |
| 19372 |
+ { |
| 19373 |
+ return node ? node->getAsBranchNode() : nullptr; |
| 19374 |
+ } |
| 19375 |
+}; |
| 19376 |
+ |
| 19377 |
+} // namespace priv |
| 19378 |
+ |
| 19379 |
+template <typename T> |
| 19380 |
+ANGLE_INLINE T *asNode(TIntermNode *node) |
| 19381 |
+{ |
| 19382 |
+ return priv::AsNode<T>::exec(node); |
| 19383 |
+} |
| 19384 |
+ |
| 19385 |
+} // namespace sh |
| 19386 |
+ |
| 19387 |
+#endif // COMPILER_TRANSLATOR_TREEUTIL_INTERMASNODE_H_ |
| 19388 |
diff --git a/src/compiler/translator/tree_util/IntermNodePatternMatcher.cpp b/src/compiler/translator/tree_util/IntermNodePatternMatcher.cpp |
| 19389 |
index d08c386..acc7892 100644 |
| 19390 |
--- a/src/compiler/translator/tree_util/IntermNodePatternMatcher.cpp |
| 19391 |
+++ b/src/compiler/translator/tree_util/IntermNodePatternMatcher.cpp |
| 19392 |
@@ -65,7 +65,7 @@ bool IntermNodePatternMatcher::IsDynamicIndexingOfSwizzledVector(TIntermBinary * |
| 19393 |
return IsDynamicIndexingOfVectorOrMatrix(node) && node->getLeft()->getAsSwizzleNode(); |
| 19394 |
} |
| 19395 |
|
| 19396 |
-bool IntermNodePatternMatcher::matchInternal(TIntermBinary *node, TIntermNode *parentNode) |
| 19397 |
+bool IntermNodePatternMatcher::matchInternal(TIntermBinary *node, TIntermNode *parentNode) const |
| 19398 |
{ |
| 19399 |
if ((mMask & kExpressionReturningArray) != 0) |
| 19400 |
{ |
| 19401 |
@@ -87,7 +87,7 @@ bool IntermNodePatternMatcher::matchInternal(TIntermBinary *node, TIntermNode *p |
| 19402 |
return false; |
| 19403 |
} |
| 19404 |
|
| 19405 |
-bool IntermNodePatternMatcher::match(TIntermUnary *node) |
| 19406 |
+bool IntermNodePatternMatcher::match(TIntermUnary *node) const |
| 19407 |
{ |
| 19408 |
if ((mMask & kArrayLengthMethod) != 0) |
| 19409 |
{ |
| 19410 |
@@ -99,7 +99,7 @@ bool IntermNodePatternMatcher::match(TIntermUnary *node) |
| 19411 |
return false; |
| 19412 |
} |
| 19413 |
|
| 19414 |
-bool IntermNodePatternMatcher::match(TIntermBinary *node, TIntermNode *parentNode) |
| 19415 |
+bool IntermNodePatternMatcher::match(TIntermBinary *node, TIntermNode *parentNode) const |
| 19416 |
{ |
| 19417 |
// L-value tracking information is needed to check for dynamic indexing in L-value. |
| 19418 |
// Traversers that don't track l-values can still use this class and match binary nodes with |
| 19419 |
@@ -110,7 +110,7 @@ bool IntermNodePatternMatcher::match(TIntermBinary *node, TIntermNode *parentNod |
| 19420 |
|
| 19421 |
bool IntermNodePatternMatcher::match(TIntermBinary *node, |
| 19422 |
TIntermNode *parentNode, |
| 19423 |
- bool isLValueRequiredHere) |
| 19424 |
+ bool isLValueRequiredHere) const |
| 19425 |
{ |
| 19426 |
if (matchInternal(node, parentNode)) |
| 19427 |
{ |
| 19428 |
@@ -126,7 +126,7 @@ bool IntermNodePatternMatcher::match(TIntermBinary *node, |
| 19429 |
return false; |
| 19430 |
} |
| 19431 |
|
| 19432 |
-bool IntermNodePatternMatcher::match(TIntermAggregate *node, TIntermNode *parentNode) |
| 19433 |
+bool IntermNodePatternMatcher::match(TIntermAggregate *node, TIntermNode *parentNode) const |
| 19434 |
{ |
| 19435 |
if ((mMask & kExpressionReturningArray) != 0) |
| 19436 |
{ |
| 19437 |
@@ -161,7 +161,7 @@ bool IntermNodePatternMatcher::match(TIntermAggregate *node, TIntermNode *parent |
| 19438 |
return false; |
| 19439 |
} |
| 19440 |
|
| 19441 |
-bool IntermNodePatternMatcher::match(TIntermTernary *node) |
| 19442 |
+bool IntermNodePatternMatcher::match(TIntermTernary *node) const |
| 19443 |
{ |
| 19444 |
if ((mMask & kUnfoldedShortCircuitExpression) != 0) |
| 19445 |
{ |
| 19446 |
@@ -170,7 +170,7 @@ bool IntermNodePatternMatcher::match(TIntermTernary *node) |
| 19447 |
return false; |
| 19448 |
} |
| 19449 |
|
| 19450 |
-bool IntermNodePatternMatcher::match(TIntermDeclaration *node) |
| 19451 |
+bool IntermNodePatternMatcher::match(TIntermDeclaration *node) const |
| 19452 |
{ |
| 19453 |
if ((mMask & kMultiDeclaration) != 0) |
| 19454 |
{ |
| 19455 |
diff --git a/src/compiler/translator/tree_util/IntermNodePatternMatcher.h b/src/compiler/translator/tree_util/IntermNodePatternMatcher.h |
| 19456 |
index e9c4bcf..6f3d873 100644 |
| 19457 |
--- a/src/compiler/translator/tree_util/IntermNodePatternMatcher.h |
| 19458 |
+++ b/src/compiler/translator/tree_util/IntermNodePatternMatcher.h |
| 19459 |
@@ -28,52 +28,52 @@ class IntermNodePatternMatcher |
| 19460 |
static bool IsDynamicIndexingOfVectorOrMatrix(TIntermBinary *node); |
| 19461 |
static bool IsDynamicIndexingOfSwizzledVector(TIntermBinary *node); |
| 19462 |
|
| 19463 |
- enum PatternType |
| 19464 |
+ enum PatternType : unsigned int |
| 19465 |
{ |
| 19466 |
// Matches expressions that are unfolded to if statements by UnfoldShortCircuitToIf |
| 19467 |
- kUnfoldedShortCircuitExpression = 0x0001, |
| 19468 |
+ kUnfoldedShortCircuitExpression = 1u << 0u, |
| 19469 |
|
| 19470 |
// Matches expressions that return arrays with the exception of simple statements where a |
| 19471 |
// constructor or function call result is assigned. |
| 19472 |
- kExpressionReturningArray = 0x0001 << 1, |
| 19473 |
+ kExpressionReturningArray = 1u << 1u, |
| 19474 |
|
| 19475 |
// Matches dynamic indexing of vectors or matrices in l-values. |
| 19476 |
- kDynamicIndexingOfVectorOrMatrixInLValue = 0x0001 << 2, |
| 19477 |
+ kDynamicIndexingOfVectorOrMatrixInLValue = 1u << 2u, |
| 19478 |
|
| 19479 |
// Matches declarations with more than one declared variables. |
| 19480 |
- kMultiDeclaration = 0x0001 << 3, |
| 19481 |
+ kMultiDeclaration = 1u << 3u, |
| 19482 |
|
| 19483 |
// Matches declarations of arrays. |
| 19484 |
- kArrayDeclaration = 0x0001 << 4, |
| 19485 |
+ kArrayDeclaration = 1u << 4u, |
| 19486 |
|
| 19487 |
// Matches declarations of structs where the struct type does not have a name. |
| 19488 |
- kNamelessStructDeclaration = 0x0001 << 5, |
| 19489 |
+ kNamelessStructDeclaration = 1u << 5u, |
| 19490 |
|
| 19491 |
// Matches array length() method. |
| 19492 |
- kArrayLengthMethod = 0x0001 << 6, |
| 19493 |
+ kArrayLengthMethod = 1u << 6u, |
| 19494 |
|
| 19495 |
// Matches a vector or matrix constructor whose arguments are scalarized by the |
| 19496 |
// SH_SCALARIZE_VEC_OR_MAT_CONSTRUCTOR_ARGUMENTS workaround. |
| 19497 |
- kScalarizedVecOrMatConstructor = 0x0001 << 7 |
| 19498 |
+ kScalarizedVecOrMatConstructor = 1u << 7u, |
| 19499 |
}; |
| 19500 |
IntermNodePatternMatcher(const unsigned int mask); |
| 19501 |
|
| 19502 |
- bool match(TIntermUnary *node); |
| 19503 |
+ bool match(TIntermUnary *node) const; |
| 19504 |
|
| 19505 |
- bool match(TIntermBinary *node, TIntermNode *parentNode); |
| 19506 |
+ bool match(TIntermBinary *node, TIntermNode *parentNode) const; |
| 19507 |
|
| 19508 |
// Use this version for checking binary node matches in case you're using flag |
| 19509 |
// kDynamicIndexingOfVectorOrMatrixInLValue. |
| 19510 |
- bool match(TIntermBinary *node, TIntermNode *parentNode, bool isLValueRequiredHere); |
| 19511 |
+ bool match(TIntermBinary *node, TIntermNode *parentNode, bool isLValueRequiredHere) const; |
| 19512 |
|
| 19513 |
- bool match(TIntermAggregate *node, TIntermNode *parentNode); |
| 19514 |
- bool match(TIntermTernary *node); |
| 19515 |
- bool match(TIntermDeclaration *node); |
| 19516 |
+ bool match(TIntermAggregate *node, TIntermNode *parentNode) const; |
| 19517 |
+ bool match(TIntermTernary *node) const; |
| 19518 |
+ bool match(TIntermDeclaration *node) const; |
| 19519 |
|
| 19520 |
private: |
| 19521 |
const unsigned int mMask; |
| 19522 |
|
| 19523 |
- bool matchInternal(TIntermBinary *node, TIntermNode *parentNode); |
| 19524 |
+ bool matchInternal(TIntermBinary *node, TIntermNode *parentNode) const; |
| 19525 |
}; |
| 19526 |
|
| 19527 |
} // namespace sh |
| 19528 |
diff --git a/src/compiler/translator/tree_util/IntermNode_util.cpp b/src/compiler/translator/tree_util/IntermNode_util.cpp |
| 19529 |
index 6ab13ba..d3e1fca 100644 |
| 19530 |
--- a/src/compiler/translator/tree_util/IntermNode_util.cpp |
| 19531 |
+++ b/src/compiler/translator/tree_util/IntermNode_util.cpp |
| 19532 |
@@ -224,6 +224,50 @@ TVariable *DeclareTempVariable(TSymbolTable *symbolTable, |
| 19533 |
return variable; |
| 19534 |
} |
| 19535 |
|
| 19536 |
+std::pair<const TVariable *, const TVariable *> DeclareStructure( |
| 19537 |
+ TIntermBlock *root, |
| 19538 |
+ TSymbolTable *symbolTable, |
| 19539 |
+ TFieldList *fieldList, |
| 19540 |
+ TQualifier qualifier, |
| 19541 |
+ const TMemoryQualifier &memoryQualifier, |
| 19542 |
+ uint32_t arraySize, |
| 19543 |
+ const ImmutableString &structTypeName, |
| 19544 |
+ const ImmutableString *structInstanceName) |
| 19545 |
+{ |
| 19546 |
+ TStructure *structure = |
| 19547 |
+ new TStructure(symbolTable, structTypeName, fieldList, SymbolType::AngleInternal); |
| 19548 |
+ |
| 19549 |
+ auto makeStructureType = [&](bool isStructSpecifier) { |
| 19550 |
+ TType *structureType = new TType(structure, isStructSpecifier); |
| 19551 |
+ structureType->setQualifier(qualifier); |
| 19552 |
+ structureType->setMemoryQualifier(memoryQualifier); |
| 19553 |
+ if (arraySize > 0) |
| 19554 |
+ { |
| 19555 |
+ structureType->makeArray(arraySize); |
| 19556 |
+ } |
| 19557 |
+ return structureType; |
| 19558 |
+ }; |
| 19559 |
+ |
| 19560 |
+ TIntermSequence insertSequence; |
| 19561 |
+ |
| 19562 |
+ TVariable *typeVar = new TVariable(symbolTable, kEmptyImmutableString, makeStructureType(true), |
| 19563 |
+ SymbolType::Empty); |
| 19564 |
+ insertSequence.push_back(new TIntermDeclaration{typeVar}); |
| 19565 |
+ |
| 19566 |
+ TVariable *instanceVar = nullptr; |
| 19567 |
+ if (structInstanceName) |
| 19568 |
+ { |
| 19569 |
+ instanceVar = new TVariable(symbolTable, *structInstanceName, makeStructureType(false), |
| 19570 |
+ SymbolType::AngleInternal); |
| 19571 |
+ insertSequence.push_back(new TIntermDeclaration{instanceVar}); |
| 19572 |
+ } |
| 19573 |
+ |
| 19574 |
+ size_t firstFunctionIndex = FindFirstFunctionDefinitionIndex(root); |
| 19575 |
+ root->insertChildNodes(firstFunctionIndex, insertSequence); |
| 19576 |
+ |
| 19577 |
+ return {typeVar, instanceVar}; |
| 19578 |
+} |
| 19579 |
+ |
| 19580 |
const TVariable *DeclareInterfaceBlock(TIntermBlock *root, |
| 19581 |
TSymbolTable *symbolTable, |
| 19582 |
TFieldList *fieldList, |
| 19583 |
diff --git a/src/compiler/translator/tree_util/IntermNode_util.h b/src/compiler/translator/tree_util/IntermNode_util.h |
| 19584 |
index 39b86dd..f5d1c93 100644 |
| 19585 |
--- a/src/compiler/translator/tree_util/IntermNode_util.h |
| 19586 |
+++ b/src/compiler/translator/tree_util/IntermNode_util.h |
| 19587 |
@@ -45,6 +45,15 @@ TVariable *DeclareTempVariable(TSymbolTable *symbolTable, |
| 19588 |
TIntermTyped *initializer, |
| 19589 |
TQualifier qualifier, |
| 19590 |
TIntermDeclaration **declarationOut); |
| 19591 |
+std::pair<const TVariable *, const TVariable *> DeclareStructure( |
| 19592 |
+ TIntermBlock *root, |
| 19593 |
+ TSymbolTable *symbolTable, |
| 19594 |
+ TFieldList *fieldList, |
| 19595 |
+ TQualifier qualifier, |
| 19596 |
+ const TMemoryQualifier &memoryQualifier, |
| 19597 |
+ uint32_t arraySize, |
| 19598 |
+ const ImmutableString &structTypeName, |
| 19599 |
+ const ImmutableString *structInstanceName); |
| 19600 |
const TVariable *DeclareInterfaceBlock(TIntermBlock *root, |
| 19601 |
TSymbolTable *symbolTable, |
| 19602 |
TFieldList *fieldList, |
| 19603 |
diff --git a/src/compiler/translator/tree_util/IntermRebuild.cpp b/src/compiler/translator/tree_util/IntermRebuild.cpp |
| 19604 |
new file mode 100644 |
| 19605 |
index 0000000..d883473 |
| 19606 |
--- /dev/null |
| 19607 |
+++ b/src/compiler/translator/tree_util/IntermRebuild.cpp |
| 19608 |
@@ -0,0 +1,1028 @@ |
| 19609 |
+// |
| 19610 |
+// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 19611 |
+// Use of this source code is governed by a BSD-style license that can be |
| 19612 |
+// found in the LICENSE file. |
| 19613 |
+// |
| 19614 |
+ |
| 19615 |
+#include <algorithm> |
| 19616 |
+ |
| 19617 |
+#include "compiler/translator/Compiler.h" |
| 19618 |
+#include "compiler/translator/SymbolTable.h" |
| 19619 |
+#include "compiler/translator/tree_util/AsNode.h" |
| 19620 |
+#include "compiler/translator/tree_util/IntermRebuild.h" |
| 19621 |
+ |
| 19622 |
+#define GUARD2(cond, failVal) \ |
| 19623 |
+ do \ |
| 19624 |
+ { \ |
| 19625 |
+ if (!(cond)) \ |
| 19626 |
+ { \ |
| 19627 |
+ return failVal; \ |
| 19628 |
+ } \ |
| 19629 |
+ } while (false) |
| 19630 |
+ |
| 19631 |
+#define GUARD(cond) GUARD2(cond, nullptr) |
| 19632 |
+ |
| 19633 |
+namespace sh |
| 19634 |
+{ |
| 19635 |
+ |
| 19636 |
+template <typename T, typename U> |
| 19637 |
+ANGLE_INLINE bool AllBits(T haystack, U needle) |
| 19638 |
+{ |
| 19639 |
+ return (haystack & needle) == needle; |
| 19640 |
+} |
| 19641 |
+ |
| 19642 |
+template <typename T, typename U> |
| 19643 |
+ANGLE_INLINE bool AnyBits(T haystack, U needle) |
| 19644 |
+{ |
| 19645 |
+ return (haystack & needle) != 0; |
| 19646 |
+} |
| 19647 |
+ |
| 19648 |
+//////////////////////////////////////////////////////////////////////////////// |
| 19649 |
+ |
| 19650 |
+TIntermRebuild::BaseResult::BaseResult(BaseResult &other) |
| 19651 |
+ : mAction(other.mAction), |
| 19652 |
+ mVisit(other.mVisit), |
| 19653 |
+ mSingle(other.mSingle), |
| 19654 |
+ mMulti(std::move(other.mMulti)) |
| 19655 |
+{} |
| 19656 |
+ |
| 19657 |
+TIntermRebuild::BaseResult::BaseResult(TIntermNode &node, VisitBits visit) |
| 19658 |
+ : mAction(Action::ReplaceSingle), mVisit(visit), mSingle(&node) |
| 19659 |
+{} |
| 19660 |
+ |
| 19661 |
+TIntermRebuild::BaseResult::BaseResult(TIntermNode *node, VisitBits visit) |
| 19662 |
+ : mAction(node ? Action::ReplaceSingle : Action::Drop), |
| 19663 |
+ mVisit(node ? visit : VisitBits::Neither), |
| 19664 |
+ mSingle(node) |
| 19665 |
+{} |
| 19666 |
+ |
| 19667 |
+TIntermRebuild::BaseResult::BaseResult(nullptr_t) |
| 19668 |
+ : mAction(Action::Drop), mVisit(VisitBits::Neither), mSingle(nullptr) |
| 19669 |
+{} |
| 19670 |
+ |
| 19671 |
+TIntermRebuild::BaseResult::BaseResult(Fail) |
| 19672 |
+ : mAction(Action::Fail), mVisit(VisitBits::Neither), mSingle(nullptr) |
| 19673 |
+{} |
| 19674 |
+ |
| 19675 |
+TIntermRebuild::BaseResult::BaseResult(std::vector<TIntermNode *> &&nodes) |
| 19676 |
+ : mAction(Action::ReplaceMulti), |
| 19677 |
+ mVisit(VisitBits::Neither), |
| 19678 |
+ mSingle(nullptr), |
| 19679 |
+ mMulti(std::move(nodes)) |
| 19680 |
+{} |
| 19681 |
+ |
| 19682 |
+void TIntermRebuild::BaseResult::moveAssignImpl(BaseResult &other) |
| 19683 |
+{ |
| 19684 |
+ mAction = other.mAction; |
| 19685 |
+ mVisit = other.mVisit; |
| 19686 |
+ mSingle = other.mSingle; |
| 19687 |
+ mMulti = std::move(other.mMulti); |
| 19688 |
+} |
| 19689 |
+ |
| 19690 |
+TIntermRebuild::BaseResult TIntermRebuild::BaseResult::Multi(std::vector<TIntermNode *> &&nodes) |
| 19691 |
+{ |
| 19692 |
+ auto it = std::remove(nodes.begin(), nodes.end(), nullptr); |
| 19693 |
+ nodes.erase(it, nodes.end()); |
| 19694 |
+ return std::move(nodes); |
| 19695 |
+} |
| 19696 |
+ |
| 19697 |
+bool TIntermRebuild::BaseResult::isFail() const |
| 19698 |
+{ |
| 19699 |
+ return mAction == Action::Fail; |
| 19700 |
+} |
| 19701 |
+ |
| 19702 |
+bool TIntermRebuild::BaseResult::isDrop() const |
| 19703 |
+{ |
| 19704 |
+ return mAction == Action::Drop; |
| 19705 |
+} |
| 19706 |
+ |
| 19707 |
+TIntermNode *TIntermRebuild::BaseResult::single() const |
| 19708 |
+{ |
| 19709 |
+ return mSingle; |
| 19710 |
+} |
| 19711 |
+ |
| 19712 |
+const std::vector<TIntermNode *> *TIntermRebuild::BaseResult::multi() const |
| 19713 |
+{ |
| 19714 |
+ if (mAction == Action::ReplaceMulti) |
| 19715 |
+ { |
| 19716 |
+ return &mMulti; |
| 19717 |
+ } |
| 19718 |
+ return nullptr; |
| 19719 |
+} |
| 19720 |
+ |
| 19721 |
+//////////////////////////////////////////////////////////////////////////////// |
| 19722 |
+ |
| 19723 |
+using PreResult = TIntermRebuild::PreResult; |
| 19724 |
+ |
| 19725 |
+PreResult::PreResult(TIntermNode &node, VisitBits visit) : BaseResult(node, visit) {} |
| 19726 |
+PreResult::PreResult(TIntermNode *node, VisitBits visit) : BaseResult(node, visit) {} |
| 19727 |
+PreResult::PreResult(nullptr_t) : BaseResult(nullptr) {} |
| 19728 |
+PreResult::PreResult(Fail) : BaseResult(Fail()) {} |
| 19729 |
+ |
| 19730 |
+PreResult::PreResult(BaseResult &&other) : BaseResult(other) {} |
| 19731 |
+PreResult::PreResult(PreResult &&other) : BaseResult(other) {} |
| 19732 |
+ |
| 19733 |
+void PreResult::operator=(PreResult &&other) |
| 19734 |
+{ |
| 19735 |
+ moveAssignImpl(other); |
| 19736 |
+} |
| 19737 |
+ |
| 19738 |
+//////////////////////////////////////////////////////////////////////////////// |
| 19739 |
+ |
| 19740 |
+using PostResult = TIntermRebuild::PostResult; |
| 19741 |
+ |
| 19742 |
+PostResult::PostResult(TIntermNode &node) : BaseResult(node, VisitBits::Neither) {} |
| 19743 |
+PostResult::PostResult(TIntermNode *node) : BaseResult(node, VisitBits::Neither) {} |
| 19744 |
+PostResult::PostResult(nullptr_t) : BaseResult(nullptr) {} |
| 19745 |
+PostResult::PostResult(Fail) : BaseResult(Fail()) {} |
| 19746 |
+ |
| 19747 |
+PostResult::PostResult(PostResult &&other) : BaseResult(other) {} |
| 19748 |
+PostResult::PostResult(BaseResult &&other) : BaseResult(other) {} |
| 19749 |
+ |
| 19750 |
+void PostResult::operator=(PostResult &&other) |
| 19751 |
+{ |
| 19752 |
+ moveAssignImpl(other); |
| 19753 |
+} |
| 19754 |
+ |
| 19755 |
+//////////////////////////////////////////////////////////////////////////////// |
| 19756 |
+ |
| 19757 |
+TIntermRebuild::TIntermRebuild(TCompiler &compiler, bool preVisit, bool postVisit) |
| 19758 |
+ : mCompiler(compiler), |
| 19759 |
+ mSymbolTable(compiler.getSymbolTable()), |
| 19760 |
+ mPreVisit(preVisit), |
| 19761 |
+ mPostVisit(postVisit) |
| 19762 |
+{ |
| 19763 |
+ ASSERT(preVisit || postVisit); |
| 19764 |
+} |
| 19765 |
+ |
| 19766 |
+TIntermRebuild::~TIntermRebuild() |
| 19767 |
+{ |
| 19768 |
+ ASSERT(!mNodeStack.value); |
| 19769 |
+ ASSERT(!mNodeStack.tail); |
| 19770 |
+} |
| 19771 |
+ |
| 19772 |
+const TFunction *TIntermRebuild::getParentFunction() const |
| 19773 |
+{ |
| 19774 |
+ return mParentFunc; |
| 19775 |
+} |
| 19776 |
+ |
| 19777 |
+TIntermNode *TIntermRebuild::getParentNode(size_t offset) const |
| 19778 |
+{ |
| 19779 |
+ ASSERT(mNodeStack.tail); |
| 19780 |
+ auto parent = *mNodeStack.tail; |
| 19781 |
+ while (offset > 0) |
| 19782 |
+ { |
| 19783 |
+ --offset; |
| 19784 |
+ ASSERT(parent.tail); |
| 19785 |
+ parent = *parent.tail; |
| 19786 |
+ } |
| 19787 |
+ return parent.value; |
| 19788 |
+} |
| 19789 |
+ |
| 19790 |
+bool TIntermRebuild::rebuildRoot(TIntermBlock &root) |
| 19791 |
+{ |
| 19792 |
+ if (!rebuildInPlace(root)) |
| 19793 |
+ { |
| 19794 |
+ return false; |
| 19795 |
+ } |
| 19796 |
+ return mCompiler.validateAST(&root); |
| 19797 |
+} |
| 19798 |
+ |
| 19799 |
+bool TIntermRebuild::rebuildInPlace(TIntermAggregate &node) |
| 19800 |
+{ |
| 19801 |
+ return rebuildInPlaceImpl(node); |
| 19802 |
+} |
| 19803 |
+ |
| 19804 |
+bool TIntermRebuild::rebuildInPlace(TIntermBlock &node) |
| 19805 |
+{ |
| 19806 |
+ return rebuildInPlaceImpl(node); |
| 19807 |
+} |
| 19808 |
+ |
| 19809 |
+bool TIntermRebuild::rebuildInPlace(TIntermDeclaration &node) |
| 19810 |
+{ |
| 19811 |
+ return rebuildInPlaceImpl(node); |
| 19812 |
+} |
| 19813 |
+ |
| 19814 |
+template <typename Node> |
| 19815 |
+bool TIntermRebuild::rebuildInPlaceImpl(Node &node) |
| 19816 |
+{ |
| 19817 |
+ auto *newNode = traverseAnyAs<Node>(node); |
| 19818 |
+ if (!newNode) |
| 19819 |
+ { |
| 19820 |
+ return false; |
| 19821 |
+ } |
| 19822 |
+ |
| 19823 |
+ if (newNode != &node) |
| 19824 |
+ { |
| 19825 |
+ *node.getSequence() = std::move(*newNode->getSequence()); |
| 19826 |
+ } |
| 19827 |
+ |
| 19828 |
+ return true; |
| 19829 |
+} |
| 19830 |
+ |
| 19831 |
+PostResult TIntermRebuild::rebuild(TIntermNode &node) |
| 19832 |
+{ |
| 19833 |
+ return traverseAny(node); |
| 19834 |
+} |
| 19835 |
+ |
| 19836 |
+//////////////////////////////////////////////////////////////////////////////// |
| 19837 |
+ |
| 19838 |
+template <typename Node> |
| 19839 |
+Node *TIntermRebuild::traverseAnyAs(TIntermNode &node) |
| 19840 |
+{ |
| 19841 |
+ PostResult result(traverseAny(node)); |
| 19842 |
+ if (result.mAction == Action::Fail || !result.mSingle) |
| 19843 |
+ { |
| 19844 |
+ return nullptr; |
| 19845 |
+ } |
| 19846 |
+ return asNode<Node>(result.mSingle); |
| 19847 |
+} |
| 19848 |
+ |
| 19849 |
+template <typename Node> |
| 19850 |
+bool TIntermRebuild::traverseAnyAs(TIntermNode &node, Node *&out) |
| 19851 |
+{ |
| 19852 |
+ PostResult result(traverseAny(node)); |
| 19853 |
+ if (result.mAction == Action::Fail || result.mAction == Action::ReplaceMulti) |
| 19854 |
+ { |
| 19855 |
+ return false; |
| 19856 |
+ } |
| 19857 |
+ if (!result.mSingle) |
| 19858 |
+ { |
| 19859 |
+ return true; |
| 19860 |
+ } |
| 19861 |
+ out = asNode<Node>(result.mSingle); |
| 19862 |
+ return out; |
| 19863 |
+} |
| 19864 |
+ |
| 19865 |
+bool TIntermRebuild::traverseAggregateBaseChildren(TIntermAggregateBase &node) |
| 19866 |
+{ |
| 19867 |
+ auto *const children = node.getSequence(); |
| 19868 |
+ ASSERT(children); |
| 19869 |
+ TIntermSequence newChildren; |
| 19870 |
+ |
| 19871 |
+ for (TIntermNode *child : *children) |
| 19872 |
+ { |
| 19873 |
+ ASSERT(child); |
| 19874 |
+ PostResult result(traverseAny(*child)); |
| 19875 |
+ |
| 19876 |
+ switch (result.mAction) |
| 19877 |
+ { |
| 19878 |
+ case Action::ReplaceSingle: |
| 19879 |
+ newChildren.push_back(result.mSingle); |
| 19880 |
+ break; |
| 19881 |
+ |
| 19882 |
+ case Action::ReplaceMulti: |
| 19883 |
+ for (TIntermNode *newNode : result.mMulti) |
| 19884 |
+ { |
| 19885 |
+ if (newNode) |
| 19886 |
+ { |
| 19887 |
+ newChildren.push_back(newNode); |
| 19888 |
+ } |
| 19889 |
+ } |
| 19890 |
+ break; |
| 19891 |
+ |
| 19892 |
+ case Action::Drop: |
| 19893 |
+ break; |
| 19894 |
+ |
| 19895 |
+ case Action::Fail: |
| 19896 |
+ return false; |
| 19897 |
+ } |
| 19898 |
+ } |
| 19899 |
+ |
| 19900 |
+ *children = std::move(newChildren); |
| 19901 |
+ |
| 19902 |
+ return true; |
| 19903 |
+} |
| 19904 |
+ |
| 19905 |
+//////////////////////////////////////////////////////////////////////////////// |
| 19906 |
+ |
| 19907 |
+struct TIntermRebuild::NodeStackGuard |
| 19908 |
+{ |
| 19909 |
+ ConsList<TIntermNode *> oldNodeStack; |
| 19910 |
+ ConsList<TIntermNode *> &nodeStack; |
| 19911 |
+ NodeStackGuard(ConsList<TIntermNode *> &nodeStack) |
| 19912 |
+ : oldNodeStack(nodeStack), nodeStack(nodeStack) |
| 19913 |
+ {} |
| 19914 |
+ ~NodeStackGuard() { nodeStack = oldNodeStack; } |
| 19915 |
+}; |
| 19916 |
+ |
| 19917 |
+PostResult TIntermRebuild::traverseAny(TIntermNode &originalNode) |
| 19918 |
+{ |
| 19919 |
+ PreResult preResult = traversePre(originalNode); |
| 19920 |
+ if (!preResult.mSingle) |
| 19921 |
+ { |
| 19922 |
+ ASSERT(preResult.mVisit == VisitBits::Neither); |
| 19923 |
+ return std::move(preResult); |
| 19924 |
+ } |
| 19925 |
+ |
| 19926 |
+ TIntermNode *currNode = preResult.mSingle; |
| 19927 |
+ const VisitBits visit = preResult.mVisit; |
| 19928 |
+ const NodeType currNodeType = getNodeType(*currNode); |
| 19929 |
+ |
| 19930 |
+ currNode = traverseChildren(currNodeType, originalNode, *currNode, visit); |
| 19931 |
+ if (!currNode) |
| 19932 |
+ { |
| 19933 |
+ return Fail(); |
| 19934 |
+ } |
| 19935 |
+ |
| 19936 |
+ return traversePost(currNodeType, originalNode, *currNode, visit); |
| 19937 |
+} |
| 19938 |
+ |
| 19939 |
+PreResult TIntermRebuild::traversePre(TIntermNode &originalNode) |
| 19940 |
+{ |
| 19941 |
+ if (!mPreVisit) |
| 19942 |
+ { |
| 19943 |
+ return {originalNode, VisitBits::Both}; |
| 19944 |
+ } |
| 19945 |
+ |
| 19946 |
+ NodeStackGuard guard(mNodeStack); |
| 19947 |
+ mNodeStack = {&originalNode, &guard.oldNodeStack}; |
| 19948 |
+ |
| 19949 |
+ const NodeType originalNodeType = getNodeType(originalNode); |
| 19950 |
+ |
| 19951 |
+ switch (originalNodeType) |
| 19952 |
+ { |
| 19953 |
+ case NodeType::Unknown: |
| 19954 |
+ ASSERT(false); |
| 19955 |
+ return Fail(); |
| 19956 |
+ case NodeType::Symbol: |
| 19957 |
+ return visitSymbolPre(*originalNode.getAsSymbolNode()); |
| 19958 |
+ case NodeType::ConstantUnion: |
| 19959 |
+ return visitConstantUnionPre(*originalNode.getAsConstantUnion()); |
| 19960 |
+ case NodeType::FunctionPrototype: |
| 19961 |
+ return visitFunctionPrototypePre(*originalNode.getAsFunctionPrototypeNode()); |
| 19962 |
+ case NodeType::PreprocessorDirective: |
| 19963 |
+ return visitPreprocessorDirectivePre(*originalNode.getAsPreprocessorDirective()); |
| 19964 |
+ case NodeType::Unary: |
| 19965 |
+ return visitUnaryPre(*originalNode.getAsUnaryNode()); |
| 19966 |
+ case NodeType::Binary: |
| 19967 |
+ return visitBinaryPre(*originalNode.getAsBinaryNode()); |
| 19968 |
+ case NodeType::Ternary: |
| 19969 |
+ return visitTernaryPre(*originalNode.getAsTernaryNode()); |
| 19970 |
+ case NodeType::Swizzle: |
| 19971 |
+ return visitSwizzlePre(*originalNode.getAsSwizzleNode()); |
| 19972 |
+ case NodeType::IfElse: |
| 19973 |
+ return visitIfElsePre(*originalNode.getAsIfElseNode()); |
| 19974 |
+ case NodeType::Switch: |
| 19975 |
+ return visitSwitchPre(*originalNode.getAsSwitchNode()); |
| 19976 |
+ case NodeType::Case: |
| 19977 |
+ return visitCasePre(*originalNode.getAsCaseNode()); |
| 19978 |
+ case NodeType::FunctionDefinition: |
| 19979 |
+ return visitFunctionDefinitionPre(*originalNode.getAsFunctionDefinition()); |
| 19980 |
+ case NodeType::Aggregate: |
| 19981 |
+ return visitAggregatePre(*originalNode.getAsAggregate()); |
| 19982 |
+ case NodeType::Block: |
| 19983 |
+ return visitBlockPre(*originalNode.getAsBlock()); |
| 19984 |
+ case NodeType::GlobalQualifierDeclaration: |
| 19985 |
+ return visitGlobalQualifierDeclarationPre( |
| 19986 |
+ *originalNode.getAsGlobalQualifierDeclarationNode()); |
| 19987 |
+ case NodeType::Declaration: |
| 19988 |
+ return visitDeclarationPre(*originalNode.getAsDeclarationNode()); |
| 19989 |
+ case NodeType::Loop: |
| 19990 |
+ return visitLoopPre(*originalNode.getAsLoopNode()); |
| 19991 |
+ case NodeType::Branch: |
| 19992 |
+ return visitBranchPre(*originalNode.getAsBranchNode()); |
| 19993 |
+ } |
| 19994 |
+} |
| 19995 |
+ |
| 19996 |
+TIntermNode *TIntermRebuild::traverseChildren(NodeType currNodeType, |
| 19997 |
+ const TIntermNode &originalNode, |
| 19998 |
+ TIntermNode &currNode, |
| 19999 |
+ VisitBits visit) |
| 20000 |
+{ |
| 20001 |
+ if (!AnyBits(visit, VisitBits::Children)) |
| 20002 |
+ { |
| 20003 |
+ return &currNode; |
| 20004 |
+ } |
| 20005 |
+ |
| 20006 |
+ if (AnyBits(visit, VisitBits::ChildrenRequiresSame) && &originalNode != &currNode) |
| 20007 |
+ { |
| 20008 |
+ return &currNode; |
| 20009 |
+ } |
| 20010 |
+ |
| 20011 |
+ NodeStackGuard guard(mNodeStack); |
| 20012 |
+ mNodeStack = {&currNode, &guard.oldNodeStack}; |
| 20013 |
+ |
| 20014 |
+ switch (currNodeType) |
| 20015 |
+ { |
| 20016 |
+ case NodeType::Unknown: |
| 20017 |
+ ASSERT(false); |
| 20018 |
+ return nullptr; |
| 20019 |
+ case NodeType::Symbol: |
| 20020 |
+ return &currNode; |
| 20021 |
+ case NodeType::ConstantUnion: |
| 20022 |
+ return &currNode; |
| 20023 |
+ case NodeType::FunctionPrototype: |
| 20024 |
+ return &currNode; |
| 20025 |
+ case NodeType::PreprocessorDirective: |
| 20026 |
+ return &currNode; |
| 20027 |
+ case NodeType::Unary: |
| 20028 |
+ return traverseUnaryChildren(*currNode.getAsUnaryNode()); |
| 20029 |
+ case NodeType::Binary: |
| 20030 |
+ return traverseBinaryChildren(*currNode.getAsBinaryNode()); |
| 20031 |
+ case NodeType::Ternary: |
| 20032 |
+ return traverseTernaryChildren(*currNode.getAsTernaryNode()); |
| 20033 |
+ case NodeType::Swizzle: |
| 20034 |
+ return traverseSwizzleChildren(*currNode.getAsSwizzleNode()); |
| 20035 |
+ case NodeType::IfElse: |
| 20036 |
+ return traverseIfElseChildren(*currNode.getAsIfElseNode()); |
| 20037 |
+ case NodeType::Switch: |
| 20038 |
+ return traverseSwitchChildren(*currNode.getAsSwitchNode()); |
| 20039 |
+ case NodeType::Case: |
| 20040 |
+ return traverseCaseChildren(*currNode.getAsCaseNode()); |
| 20041 |
+ case NodeType::FunctionDefinition: |
| 20042 |
+ return traverseFunctionDefinitionChildren(*currNode.getAsFunctionDefinition()); |
| 20043 |
+ case NodeType::Aggregate: |
| 20044 |
+ return traverseAggregateChildren(*currNode.getAsAggregate()); |
| 20045 |
+ case NodeType::Block: |
| 20046 |
+ return traverseBlockChildren(*currNode.getAsBlock()); |
| 20047 |
+ case NodeType::GlobalQualifierDeclaration: |
| 20048 |
+ return traverseGlobalQualifierDeclarationChildren( |
| 20049 |
+ *currNode.getAsGlobalQualifierDeclarationNode()); |
| 20050 |
+ case NodeType::Declaration: |
| 20051 |
+ return traverseDeclarationChildren(*currNode.getAsDeclarationNode()); |
| 20052 |
+ case NodeType::Loop: |
| 20053 |
+ return traverseLoopChildren(*currNode.getAsLoopNode()); |
| 20054 |
+ case NodeType::Branch: |
| 20055 |
+ return traverseBranchChildren(*currNode.getAsBranchNode()); |
| 20056 |
+ } |
| 20057 |
+} |
| 20058 |
+ |
| 20059 |
+PostResult TIntermRebuild::traversePost(NodeType currNodeType, |
| 20060 |
+ const TIntermNode &originalNode, |
| 20061 |
+ TIntermNode &currNode, |
| 20062 |
+ VisitBits visit) |
| 20063 |
+{ |
| 20064 |
+ if (!mPostVisit) |
| 20065 |
+ { |
| 20066 |
+ return currNode; |
| 20067 |
+ } |
| 20068 |
+ |
| 20069 |
+ if (!AnyBits(visit, VisitBits::Post)) |
| 20070 |
+ { |
| 20071 |
+ return currNode; |
| 20072 |
+ } |
| 20073 |
+ |
| 20074 |
+ if (AnyBits(visit, VisitBits::PostRequiresSame) && &originalNode != &currNode) |
| 20075 |
+ { |
| 20076 |
+ return currNode; |
| 20077 |
+ } |
| 20078 |
+ |
| 20079 |
+ NodeStackGuard guard(mNodeStack); |
| 20080 |
+ mNodeStack = {&currNode, &guard.oldNodeStack}; |
| 20081 |
+ |
| 20082 |
+ switch (currNodeType) |
| 20083 |
+ { |
| 20084 |
+ case NodeType::Unknown: |
| 20085 |
+ ASSERT(false); |
| 20086 |
+ return Fail(); |
| 20087 |
+ case NodeType::Symbol: |
| 20088 |
+ return visitSymbolPost(*currNode.getAsSymbolNode()); |
| 20089 |
+ case NodeType::ConstantUnion: |
| 20090 |
+ return visitConstantUnionPost(*currNode.getAsConstantUnion()); |
| 20091 |
+ case NodeType::FunctionPrototype: |
| 20092 |
+ return visitFunctionPrototypePost(*currNode.getAsFunctionPrototypeNode()); |
| 20093 |
+ case NodeType::PreprocessorDirective: |
| 20094 |
+ return visitPreprocessorDirectivePost(*currNode.getAsPreprocessorDirective()); |
| 20095 |
+ case NodeType::Unary: |
| 20096 |
+ return visitUnaryPost(*currNode.getAsUnaryNode()); |
| 20097 |
+ case NodeType::Binary: |
| 20098 |
+ return visitBinaryPost(*currNode.getAsBinaryNode()); |
| 20099 |
+ case NodeType::Ternary: |
| 20100 |
+ return visitTernaryPost(*currNode.getAsTernaryNode()); |
| 20101 |
+ case NodeType::Swizzle: |
| 20102 |
+ return visitSwizzlePost(*currNode.getAsSwizzleNode()); |
| 20103 |
+ case NodeType::IfElse: |
| 20104 |
+ return visitIfElsePost(*currNode.getAsIfElseNode()); |
| 20105 |
+ case NodeType::Switch: |
| 20106 |
+ return visitSwitchPost(*currNode.getAsSwitchNode()); |
| 20107 |
+ case NodeType::Case: |
| 20108 |
+ return visitCasePost(*currNode.getAsCaseNode()); |
| 20109 |
+ case NodeType::FunctionDefinition: |
| 20110 |
+ return visitFunctionDefinitionPost(*currNode.getAsFunctionDefinition()); |
| 20111 |
+ case NodeType::Aggregate: |
| 20112 |
+ return visitAggregatePost(*currNode.getAsAggregate()); |
| 20113 |
+ case NodeType::Block: |
| 20114 |
+ return visitBlockPost(*currNode.getAsBlock()); |
| 20115 |
+ case NodeType::GlobalQualifierDeclaration: |
| 20116 |
+ return visitGlobalQualifierDeclarationPost( |
| 20117 |
+ *currNode.getAsGlobalQualifierDeclarationNode()); |
| 20118 |
+ case NodeType::Declaration: |
| 20119 |
+ return visitDeclarationPost(*currNode.getAsDeclarationNode()); |
| 20120 |
+ case NodeType::Loop: |
| 20121 |
+ return visitLoopPost(*currNode.getAsLoopNode()); |
| 20122 |
+ case NodeType::Branch: |
| 20123 |
+ return visitBranchPost(*currNode.getAsBranchNode()); |
| 20124 |
+ } |
| 20125 |
+} |
| 20126 |
+ |
| 20127 |
+//////////////////////////////////////////////////////////////////////////////// |
| 20128 |
+ |
| 20129 |
+TIntermNode *TIntermRebuild::traverseAggregateChildren(TIntermAggregate &node) |
| 20130 |
+{ |
| 20131 |
+ if (traverseAggregateBaseChildren(node)) |
| 20132 |
+ { |
| 20133 |
+ return &node; |
| 20134 |
+ } |
| 20135 |
+ return nullptr; |
| 20136 |
+} |
| 20137 |
+ |
| 20138 |
+TIntermNode *TIntermRebuild::traverseBlockChildren(TIntermBlock &node) |
| 20139 |
+{ |
| 20140 |
+ if (traverseAggregateBaseChildren(node)) |
| 20141 |
+ { |
| 20142 |
+ return &node; |
| 20143 |
+ } |
| 20144 |
+ return nullptr; |
| 20145 |
+} |
| 20146 |
+ |
| 20147 |
+TIntermNode *TIntermRebuild::traverseDeclarationChildren(TIntermDeclaration &node) |
| 20148 |
+{ |
| 20149 |
+ if (traverseAggregateBaseChildren(node)) |
| 20150 |
+ { |
| 20151 |
+ return &node; |
| 20152 |
+ } |
| 20153 |
+ return nullptr; |
| 20154 |
+} |
| 20155 |
+ |
| 20156 |
+TIntermNode *TIntermRebuild::traverseSwizzleChildren(TIntermSwizzle &node) |
| 20157 |
+{ |
| 20158 |
+ auto *const operand = node.getOperand(); |
| 20159 |
+ ASSERT(operand); |
| 20160 |
+ |
| 20161 |
+ auto *newOperand = traverseAnyAs<TIntermTyped>(*operand); |
| 20162 |
+ GUARD(newOperand); |
| 20163 |
+ |
| 20164 |
+ if (newOperand != operand) |
| 20165 |
+ { |
| 20166 |
+ return new TIntermSwizzle(newOperand, node.getSwizzleOffsets()); |
| 20167 |
+ } |
| 20168 |
+ |
| 20169 |
+ return &node; |
| 20170 |
+} |
| 20171 |
+ |
| 20172 |
+TIntermNode *TIntermRebuild::traverseBinaryChildren(TIntermBinary &node) |
| 20173 |
+{ |
| 20174 |
+ auto *const left = node.getLeft(); |
| 20175 |
+ ASSERT(left); |
| 20176 |
+ auto *const right = node.getRight(); |
| 20177 |
+ ASSERT(right); |
| 20178 |
+ |
| 20179 |
+ auto *const newLeft = traverseAnyAs<TIntermTyped>(*left); |
| 20180 |
+ GUARD(newLeft); |
| 20181 |
+ auto *const newRight = traverseAnyAs<TIntermTyped>(*right); |
| 20182 |
+ GUARD(newRight); |
| 20183 |
+ |
| 20184 |
+ if (newLeft != left || newRight != right) |
| 20185 |
+ { |
| 20186 |
+ TOperator op = node.getOp(); |
| 20187 |
+ switch (op) |
| 20188 |
+ { |
| 20189 |
+ case TOperator::EOpIndexDirectStruct: |
| 20190 |
+ { |
| 20191 |
+ if (newLeft->getType().getInterfaceBlock()) |
| 20192 |
+ { |
| 20193 |
+ op = TOperator::EOpIndexDirectInterfaceBlock; |
| 20194 |
+ } |
| 20195 |
+ } |
| 20196 |
+ break; |
| 20197 |
+ |
| 20198 |
+ case TOperator::EOpIndexDirectInterfaceBlock: |
| 20199 |
+ { |
| 20200 |
+ if (newLeft->getType().getStruct()) |
| 20201 |
+ { |
| 20202 |
+ op = TOperator::EOpIndexDirectStruct; |
| 20203 |
+ } |
| 20204 |
+ } |
| 20205 |
+ break; |
| 20206 |
+ |
| 20207 |
+ case TOperator::EOpComma: |
| 20208 |
+ return TIntermBinary::CreateComma(newLeft, newRight, mCompiler.getShaderVersion()); |
| 20209 |
+ |
| 20210 |
+ default: |
| 20211 |
+ break; |
| 20212 |
+ } |
| 20213 |
+ |
| 20214 |
+ return new TIntermBinary(op, newLeft, newRight); |
| 20215 |
+ } |
| 20216 |
+ |
| 20217 |
+ return &node; |
| 20218 |
+} |
| 20219 |
+ |
| 20220 |
+TIntermNode *TIntermRebuild::traverseUnaryChildren(TIntermUnary &node) |
| 20221 |
+{ |
| 20222 |
+ auto *const operand = node.getOperand(); |
| 20223 |
+ ASSERT(operand); |
| 20224 |
+ |
| 20225 |
+ auto *const newOperand = traverseAnyAs<TIntermTyped>(*operand); |
| 20226 |
+ GUARD(newOperand); |
| 20227 |
+ |
| 20228 |
+ if (newOperand != operand) |
| 20229 |
+ { |
| 20230 |
+ return new TIntermUnary(node.getOp(), newOperand, node.getFunction()); |
| 20231 |
+ } |
| 20232 |
+ |
| 20233 |
+ return &node; |
| 20234 |
+} |
| 20235 |
+ |
| 20236 |
+TIntermNode *TIntermRebuild::traverseTernaryChildren(TIntermTernary &node) |
| 20237 |
+{ |
| 20238 |
+ auto *const cond = node.getCondition(); |
| 20239 |
+ ASSERT(cond); |
| 20240 |
+ auto *const true_ = node.getTrueExpression(); |
| 20241 |
+ ASSERT(true_); |
| 20242 |
+ auto *const false_ = node.getFalseExpression(); |
| 20243 |
+ ASSERT(false_); |
| 20244 |
+ |
| 20245 |
+ auto *const newCond = traverseAnyAs<TIntermTyped>(*cond); |
| 20246 |
+ GUARD(newCond); |
| 20247 |
+ auto *const newTrue = traverseAnyAs<TIntermTyped>(*true_); |
| 20248 |
+ GUARD(newTrue); |
| 20249 |
+ auto *const newFalse = traverseAnyAs<TIntermTyped>(*false_); |
| 20250 |
+ GUARD(newFalse); |
| 20251 |
+ |
| 20252 |
+ if (newCond != cond || newTrue != true_ || newFalse != false_) |
| 20253 |
+ { |
| 20254 |
+ return new TIntermTernary(newCond, newTrue, newFalse); |
| 20255 |
+ } |
| 20256 |
+ |
| 20257 |
+ return &node; |
| 20258 |
+} |
| 20259 |
+ |
| 20260 |
+TIntermNode *TIntermRebuild::traverseIfElseChildren(TIntermIfElse &node) |
| 20261 |
+{ |
| 20262 |
+ auto *const cond = node.getCondition(); |
| 20263 |
+ ASSERT(cond); |
| 20264 |
+ auto *const true_ = node.getTrueBlock(); |
| 20265 |
+ auto *const false_ = node.getFalseBlock(); |
| 20266 |
+ |
| 20267 |
+ auto *const newCond = traverseAnyAs<TIntermTyped>(*cond); |
| 20268 |
+ GUARD(newCond); |
| 20269 |
+ TIntermBlock *newTrue = nullptr; |
| 20270 |
+ if (true_) |
| 20271 |
+ { |
| 20272 |
+ GUARD(traverseAnyAs(*true_, newTrue)); |
| 20273 |
+ } |
| 20274 |
+ TIntermBlock *newFalse = nullptr; |
| 20275 |
+ if (false_) |
| 20276 |
+ { |
| 20277 |
+ GUARD(traverseAnyAs(*false_, newFalse)); |
| 20278 |
+ } |
| 20279 |
+ |
| 20280 |
+ if (newCond != cond || newTrue != true_ || newFalse != false_) |
| 20281 |
+ { |
| 20282 |
+ return new TIntermIfElse(newCond, newTrue, newFalse); |
| 20283 |
+ } |
| 20284 |
+ |
| 20285 |
+ return &node; |
| 20286 |
+} |
| 20287 |
+ |
| 20288 |
+TIntermNode *TIntermRebuild::traverseSwitchChildren(TIntermSwitch &node) |
| 20289 |
+{ |
| 20290 |
+ auto *const init = node.getInit(); |
| 20291 |
+ ASSERT(init); |
| 20292 |
+ auto *const stmts = node.getStatementList(); |
| 20293 |
+ ASSERT(stmts); |
| 20294 |
+ |
| 20295 |
+ auto *const newInit = traverseAnyAs<TIntermTyped>(*init); |
| 20296 |
+ GUARD(newInit); |
| 20297 |
+ auto *const newStmts = traverseAnyAs<TIntermBlock>(*stmts); |
| 20298 |
+ GUARD(newStmts); |
| 20299 |
+ |
| 20300 |
+ if (newInit != init || newStmts != stmts) |
| 20301 |
+ { |
| 20302 |
+ return new TIntermSwitch(newInit, newStmts); |
| 20303 |
+ } |
| 20304 |
+ |
| 20305 |
+ return &node; |
| 20306 |
+} |
| 20307 |
+ |
| 20308 |
+TIntermNode *TIntermRebuild::traverseCaseChildren(TIntermCase &node) |
| 20309 |
+{ |
| 20310 |
+ auto *const cond = node.getCondition(); |
| 20311 |
+ |
| 20312 |
+ TIntermTyped *newCond = nullptr; |
| 20313 |
+ if (cond) |
| 20314 |
+ { |
| 20315 |
+ GUARD(traverseAnyAs(*cond, newCond)); |
| 20316 |
+ } |
| 20317 |
+ |
| 20318 |
+ if (newCond != cond) |
| 20319 |
+ { |
| 20320 |
+ return new TIntermCase(newCond); |
| 20321 |
+ } |
| 20322 |
+ |
| 20323 |
+ return &node; |
| 20324 |
+} |
| 20325 |
+ |
| 20326 |
+TIntermNode *TIntermRebuild::traverseFunctionDefinitionChildren(TIntermFunctionDefinition &node) |
| 20327 |
+{ |
| 20328 |
+ GUARD(!mParentFunc); // Function definitions cannot be nested. |
| 20329 |
+ mParentFunc = node.getFunction(); |
| 20330 |
+ struct OnExit |
| 20331 |
+ { |
| 20332 |
+ const TFunction *&parentFunc; |
| 20333 |
+ OnExit(const TFunction *&parentFunc) : parentFunc(parentFunc) {} |
| 20334 |
+ ~OnExit() { parentFunc = nullptr; } |
| 20335 |
+ } onExit(mParentFunc); |
| 20336 |
+ |
| 20337 |
+ auto *const proto = node.getFunctionPrototype(); |
| 20338 |
+ ASSERT(proto); |
| 20339 |
+ auto *const body = node.getBody(); |
| 20340 |
+ ASSERT(body); |
| 20341 |
+ |
| 20342 |
+ auto *const newProto = traverseAnyAs<TIntermFunctionPrototype>(*proto); |
| 20343 |
+ GUARD(newProto); |
| 20344 |
+ auto *const newBody = traverseAnyAs<TIntermBlock>(*body); |
| 20345 |
+ GUARD(newBody); |
| 20346 |
+ |
| 20347 |
+ if (newProto != proto || newBody != body) |
| 20348 |
+ { |
| 20349 |
+ return new TIntermFunctionDefinition(newProto, newBody); |
| 20350 |
+ } |
| 20351 |
+ |
| 20352 |
+ return &node; |
| 20353 |
+} |
| 20354 |
+ |
| 20355 |
+TIntermNode *TIntermRebuild::traverseGlobalQualifierDeclarationChildren( |
| 20356 |
+ TIntermGlobalQualifierDeclaration &node) |
| 20357 |
+{ |
| 20358 |
+ auto *const symbol = node.getSymbol(); |
| 20359 |
+ ASSERT(symbol); |
| 20360 |
+ |
| 20361 |
+ auto *const newSymbol = traverseAnyAs<TIntermSymbol>(*symbol); |
| 20362 |
+ GUARD(newSymbol); |
| 20363 |
+ |
| 20364 |
+ if (newSymbol != symbol) |
| 20365 |
+ { |
| 20366 |
+ return new TIntermGlobalQualifierDeclaration(newSymbol, node.isPrecise(), node.getLine()); |
| 20367 |
+ } |
| 20368 |
+ |
| 20369 |
+ return &node; |
| 20370 |
+} |
| 20371 |
+ |
| 20372 |
+TIntermNode *TIntermRebuild::traverseLoopChildren(TIntermLoop &node) |
| 20373 |
+{ |
| 20374 |
+ const TLoopType loopType = node.getType(); |
| 20375 |
+ |
| 20376 |
+ auto *const init = node.getInit(); |
| 20377 |
+ auto *const cond = node.getCondition(); |
| 20378 |
+ auto *const expr = node.getExpression(); |
| 20379 |
+ auto *const body = node.getBody(); |
| 20380 |
+ ASSERT(body); |
| 20381 |
+ |
| 20382 |
+#if defined(ANGLE_ENABLE_ASSERTS) |
| 20383 |
+ switch (loopType) |
| 20384 |
+ { |
| 20385 |
+ case TLoopType::ELoopFor: |
| 20386 |
+ break; |
| 20387 |
+ case TLoopType::ELoopWhile: |
| 20388 |
+ case TLoopType::ELoopDoWhile: |
| 20389 |
+ ASSERT(cond); |
| 20390 |
+ ASSERT(!init && !expr); |
| 20391 |
+ break; |
| 20392 |
+ } |
| 20393 |
+#endif |
| 20394 |
+ |
| 20395 |
+ auto *const newBody = traverseAnyAs<TIntermBlock>(*body); |
| 20396 |
+ GUARD(newBody); |
| 20397 |
+ TIntermNode *newInit = nullptr; |
| 20398 |
+ if (init) |
| 20399 |
+ { |
| 20400 |
+ GUARD(traverseAnyAs(*init, newInit)); |
| 20401 |
+ } |
| 20402 |
+ TIntermTyped *newCond = nullptr; |
| 20403 |
+ if (cond) |
| 20404 |
+ { |
| 20405 |
+ GUARD(traverseAnyAs(*cond, newCond)); |
| 20406 |
+ } |
| 20407 |
+ TIntermTyped *newExpr = nullptr; |
| 20408 |
+ if (expr) |
| 20409 |
+ { |
| 20410 |
+ GUARD(traverseAnyAs(*expr, newExpr)); |
| 20411 |
+ } |
| 20412 |
+ |
| 20413 |
+ if (newInit != init || newCond != cond || newExpr != expr || newBody != body) |
| 20414 |
+ { |
| 20415 |
+ switch (loopType) |
| 20416 |
+ { |
| 20417 |
+ case TLoopType::ELoopFor: |
| 20418 |
+ GUARD(newBody); |
| 20419 |
+ break; |
| 20420 |
+ case TLoopType::ELoopWhile: |
| 20421 |
+ case TLoopType::ELoopDoWhile: |
| 20422 |
+ GUARD(newCond && newBody); |
| 20423 |
+ GUARD(!newInit && !newExpr); |
| 20424 |
+ break; |
| 20425 |
+ } |
| 20426 |
+ return new TIntermLoop(loopType, newInit, newCond, newExpr, newBody); |
| 20427 |
+ } |
| 20428 |
+ |
| 20429 |
+ return &node; |
| 20430 |
+} |
| 20431 |
+ |
| 20432 |
+TIntermNode *TIntermRebuild::traverseBranchChildren(TIntermBranch &node) |
| 20433 |
+{ |
| 20434 |
+ auto *const expr = node.getExpression(); |
| 20435 |
+ |
| 20436 |
+ TIntermTyped *newExpr = nullptr; |
| 20437 |
+ if (expr) |
| 20438 |
+ { |
| 20439 |
+ GUARD(traverseAnyAs<TIntermTyped>(*expr, newExpr)); |
| 20440 |
+ } |
| 20441 |
+ |
| 20442 |
+ if (newExpr != expr) |
| 20443 |
+ { |
| 20444 |
+ return new TIntermBranch(node.getFlowOp(), newExpr); |
| 20445 |
+ } |
| 20446 |
+ |
| 20447 |
+ return &node; |
| 20448 |
+} |
| 20449 |
+ |
| 20450 |
+//////////////////////////////////////////////////////////////////////////////// |
| 20451 |
+ |
| 20452 |
+PreResult TIntermRebuild::visitSymbolPre(TIntermSymbol &node) |
| 20453 |
+{ |
| 20454 |
+ return {node, VisitBits::Both}; |
| 20455 |
+} |
| 20456 |
+ |
| 20457 |
+PreResult TIntermRebuild::visitConstantUnionPre(TIntermConstantUnion &node) |
| 20458 |
+{ |
| 20459 |
+ return {node, VisitBits::Both}; |
| 20460 |
+} |
| 20461 |
+ |
| 20462 |
+PreResult TIntermRebuild::visitFunctionPrototypePre(TIntermFunctionPrototype &node) |
| 20463 |
+{ |
| 20464 |
+ return {node, VisitBits::Both}; |
| 20465 |
+} |
| 20466 |
+ |
| 20467 |
+PreResult TIntermRebuild::visitPreprocessorDirectivePre(TIntermPreprocessorDirective &node) |
| 20468 |
+{ |
| 20469 |
+ return {node, VisitBits::Both}; |
| 20470 |
+} |
| 20471 |
+ |
| 20472 |
+PreResult TIntermRebuild::visitUnaryPre(TIntermUnary &node) |
| 20473 |
+{ |
| 20474 |
+ return {node, VisitBits::Both}; |
| 20475 |
+} |
| 20476 |
+ |
| 20477 |
+PreResult TIntermRebuild::visitBinaryPre(TIntermBinary &node) |
| 20478 |
+{ |
| 20479 |
+ return {node, VisitBits::Both}; |
| 20480 |
+} |
| 20481 |
+ |
| 20482 |
+PreResult TIntermRebuild::visitTernaryPre(TIntermTernary &node) |
| 20483 |
+{ |
| 20484 |
+ return {node, VisitBits::Both}; |
| 20485 |
+} |
| 20486 |
+ |
| 20487 |
+PreResult TIntermRebuild::visitSwizzlePre(TIntermSwizzle &node) |
| 20488 |
+{ |
| 20489 |
+ return {node, VisitBits::Both}; |
| 20490 |
+} |
| 20491 |
+ |
| 20492 |
+PreResult TIntermRebuild::visitIfElsePre(TIntermIfElse &node) |
| 20493 |
+{ |
| 20494 |
+ return {node, VisitBits::Both}; |
| 20495 |
+} |
| 20496 |
+ |
| 20497 |
+PreResult TIntermRebuild::visitSwitchPre(TIntermSwitch &node) |
| 20498 |
+{ |
| 20499 |
+ return {node, VisitBits::Both}; |
| 20500 |
+} |
| 20501 |
+ |
| 20502 |
+PreResult TIntermRebuild::visitCasePre(TIntermCase &node) |
| 20503 |
+{ |
| 20504 |
+ return {node, VisitBits::Both}; |
| 20505 |
+} |
| 20506 |
+ |
| 20507 |
+PreResult TIntermRebuild::visitLoopPre(TIntermLoop &node) |
| 20508 |
+{ |
| 20509 |
+ return {node, VisitBits::Both}; |
| 20510 |
+} |
| 20511 |
+ |
| 20512 |
+PreResult TIntermRebuild::visitBranchPre(TIntermBranch &node) |
| 20513 |
+{ |
| 20514 |
+ return {node, VisitBits::Both}; |
| 20515 |
+} |
| 20516 |
+ |
| 20517 |
+PreResult TIntermRebuild::visitDeclarationPre(TIntermDeclaration &node) |
| 20518 |
+{ |
| 20519 |
+ return {node, VisitBits::Both}; |
| 20520 |
+} |
| 20521 |
+ |
| 20522 |
+PreResult TIntermRebuild::visitBlockPre(TIntermBlock &node) |
| 20523 |
+{ |
| 20524 |
+ return {node, VisitBits::Both}; |
| 20525 |
+} |
| 20526 |
+ |
| 20527 |
+PreResult TIntermRebuild::visitAggregatePre(TIntermAggregate &node) |
| 20528 |
+{ |
| 20529 |
+ return {node, VisitBits::Both}; |
| 20530 |
+} |
| 20531 |
+ |
| 20532 |
+PreResult TIntermRebuild::visitFunctionDefinitionPre(TIntermFunctionDefinition &node) |
| 20533 |
+{ |
| 20534 |
+ return {node, VisitBits::Both}; |
| 20535 |
+} |
| 20536 |
+ |
| 20537 |
+PreResult TIntermRebuild::visitGlobalQualifierDeclarationPre( |
| 20538 |
+ TIntermGlobalQualifierDeclaration &node) |
| 20539 |
+{ |
| 20540 |
+ return {node, VisitBits::Both}; |
| 20541 |
+} |
| 20542 |
+ |
| 20543 |
+//////////////////////////////////////////////////////////////////////////////// |
| 20544 |
+ |
| 20545 |
+PostResult TIntermRebuild::visitSymbolPost(TIntermSymbol &node) |
| 20546 |
+{ |
| 20547 |
+ return node; |
| 20548 |
+} |
| 20549 |
+ |
| 20550 |
+PostResult TIntermRebuild::visitConstantUnionPost(TIntermConstantUnion &node) |
| 20551 |
+{ |
| 20552 |
+ return node; |
| 20553 |
+} |
| 20554 |
+ |
| 20555 |
+PostResult TIntermRebuild::visitFunctionPrototypePost(TIntermFunctionPrototype &node) |
| 20556 |
+{ |
| 20557 |
+ return node; |
| 20558 |
+} |
| 20559 |
+ |
| 20560 |
+PostResult TIntermRebuild::visitPreprocessorDirectivePost(TIntermPreprocessorDirective &node) |
| 20561 |
+{ |
| 20562 |
+ return node; |
| 20563 |
+} |
| 20564 |
+ |
| 20565 |
+PostResult TIntermRebuild::visitUnaryPost(TIntermUnary &node) |
| 20566 |
+{ |
| 20567 |
+ return node; |
| 20568 |
+} |
| 20569 |
+ |
| 20570 |
+PostResult TIntermRebuild::visitBinaryPost(TIntermBinary &node) |
| 20571 |
+{ |
| 20572 |
+ return node; |
| 20573 |
+} |
| 20574 |
+ |
| 20575 |
+PostResult TIntermRebuild::visitTernaryPost(TIntermTernary &node) |
| 20576 |
+{ |
| 20577 |
+ return node; |
| 20578 |
+} |
| 20579 |
+ |
| 20580 |
+PostResult TIntermRebuild::visitSwizzlePost(TIntermSwizzle &node) |
| 20581 |
+{ |
| 20582 |
+ return node; |
| 20583 |
+} |
| 20584 |
+ |
| 20585 |
+PostResult TIntermRebuild::visitIfElsePost(TIntermIfElse &node) |
| 20586 |
+{ |
| 20587 |
+ return node; |
| 20588 |
+} |
| 20589 |
+ |
| 20590 |
+PostResult TIntermRebuild::visitSwitchPost(TIntermSwitch &node) |
| 20591 |
+{ |
| 20592 |
+ return node; |
| 20593 |
+} |
| 20594 |
+ |
| 20595 |
+PostResult TIntermRebuild::visitCasePost(TIntermCase &node) |
| 20596 |
+{ |
| 20597 |
+ return node; |
| 20598 |
+} |
| 20599 |
+ |
| 20600 |
+PostResult TIntermRebuild::visitLoopPost(TIntermLoop &node) |
| 20601 |
+{ |
| 20602 |
+ return node; |
| 20603 |
+} |
| 20604 |
+ |
| 20605 |
+PostResult TIntermRebuild::visitBranchPost(TIntermBranch &node) |
| 20606 |
+{ |
| 20607 |
+ return node; |
| 20608 |
+} |
| 20609 |
+ |
| 20610 |
+PostResult TIntermRebuild::visitDeclarationPost(TIntermDeclaration &node) |
| 20611 |
+{ |
| 20612 |
+ return node; |
| 20613 |
+} |
| 20614 |
+ |
| 20615 |
+PostResult TIntermRebuild::visitBlockPost(TIntermBlock &node) |
| 20616 |
+{ |
| 20617 |
+ return node; |
| 20618 |
+} |
| 20619 |
+ |
| 20620 |
+PostResult TIntermRebuild::visitAggregatePost(TIntermAggregate &node) |
| 20621 |
+{ |
| 20622 |
+ return node; |
| 20623 |
+} |
| 20624 |
+ |
| 20625 |
+PostResult TIntermRebuild::visitFunctionDefinitionPost(TIntermFunctionDefinition &node) |
| 20626 |
+{ |
| 20627 |
+ return node; |
| 20628 |
+} |
| 20629 |
+ |
| 20630 |
+PostResult TIntermRebuild::visitGlobalQualifierDeclarationPost( |
| 20631 |
+ TIntermGlobalQualifierDeclaration &node) |
| 20632 |
+{ |
| 20633 |
+ return node; |
| 20634 |
+} |
| 20635 |
+ |
| 20636 |
+} // namespace sh |
| 20637 |
diff --git a/src/compiler/translator/tree_util/IntermRebuild.h b/src/compiler/translator/tree_util/IntermRebuild.h |
| 20638 |
new file mode 100644 |
| 20639 |
index 0000000..3097e40 |
| 20640 |
--- /dev/null |
| 20641 |
+++ b/src/compiler/translator/tree_util/IntermRebuild.h |
| 20642 |
@@ -0,0 +1,328 @@ |
| 20643 |
+// |
| 20644 |
+// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 20645 |
+// Use of this source code is governed by a BSD-style license that can be |
| 20646 |
+// found in the LICENSE file. |
| 20647 |
+// |
| 20648 |
+ |
| 20649 |
+#ifndef COMPILER_TRANSLATOR_TREEUTIL_INTERMREBUILD_H_ |
| 20650 |
+#define COMPILER_TRANSLATOR_TREEUTIL_INTERMREBUILD_H_ |
| 20651 |
+ |
| 20652 |
+#include "compiler/translator/tree_util/IntermTraverse.h" |
| 20653 |
+#include "compiler/translator/tree_util/NodeType.h" |
| 20654 |
+ |
| 20655 |
+namespace sh |
| 20656 |
+{ |
| 20657 |
+ |
| 20658 |
+// Walks the tree to rebuild nodes. |
| 20659 |
+// This class is intended to be derived with overridden visitXXX functions. |
| 20660 |
+// |
| 20661 |
+// Each visitXXX function that does not have a Visit parameter simply has the visitor called |
| 20662 |
+// exactly once, regardless of (preVisit) or (postVisit) values. |
| 20663 |
+ |
| 20664 |
+// Each visitXXX function that has a Visit parameter behaves as follows: |
| 20665 |
+// * If (preVisit): |
| 20666 |
+// - The node is visited before children are traversed. |
| 20667 |
+// - The returned value is used to replace the visited node. The returned value may be the same |
| 20668 |
+// as the original node. |
| 20669 |
+// - If multiple nodes are returned, children and post visits of the returned nodes are not |
| 20670 |
+// preformed, even if it is a singleton collection. |
| 20671 |
+// * If (childVisit) |
| 20672 |
+// - If any new children are returned, the node is automatically rebuilt with the new children |
| 20673 |
+// before post visit. |
| 20674 |
+// - Depending on the type of the node, null children may be discarded. |
| 20675 |
+// - Ill-typed children cause rebuild errors. Ill-typed means the node to automatically rebuild |
| 20676 |
+// cannot accept a child of a certain type as input to its constructor. |
| 20677 |
+// - Only instances of TIntermAggregateBase can accept Multi results for any of its children. |
| 20678 |
+// If supplied, the nodes are spliced children at the spot of the original child. |
| 20679 |
+// * If (postVisit) |
| 20680 |
+// - The node is visited after any children are traversed. |
| 20681 |
+// - Only after such a rebuild (or lack thereof), the post-visit is performed. |
| 20682 |
+// |
| 20683 |
+// Nodes in visit functions are allowed to be modified in place, including TIntermAggregateBase |
| 20684 |
+// child sequences. |
| 20685 |
+// |
| 20686 |
+// The default implementations of all the visitXXX functions support full pre and post traversal |
| 20687 |
+// without modifying the visited nodes. |
| 20688 |
+// |
| 20689 |
+class TIntermRebuild : angle::NonCopyable |
| 20690 |
+{ |
| 20691 |
+ |
| 20692 |
+ enum class Action |
| 20693 |
+ { |
| 20694 |
+ ReplaceSingle, |
| 20695 |
+ ReplaceMulti, |
| 20696 |
+ Drop, |
| 20697 |
+ Fail, |
| 20698 |
+ }; |
| 20699 |
+ |
| 20700 |
+ public: |
| 20701 |
+ struct Fail |
| 20702 |
+ {}; |
| 20703 |
+ |
| 20704 |
+ enum VisitBits : size_t |
| 20705 |
+ { |
| 20706 |
+ // No bits are set. |
| 20707 |
+ Empty = 0u, |
| 20708 |
+ |
| 20709 |
+ // Allow visit of returned node's children. |
| 20710 |
+ Children = 1u << 0u, |
| 20711 |
+ |
| 20712 |
+ // Allow post visit of returned node. |
| 20713 |
+ Post = 1u << 1u, |
| 20714 |
+ |
| 20715 |
+ // If (Children) bit, only visit if the returned node is the same as the original node. |
| 20716 |
+ ChildrenRequiresSame = 1u << 2u, |
| 20717 |
+ |
| 20718 |
+ // If (Post) bit, only visit if the returned node is the same as the original node. |
| 20719 |
+ PostRequiresSame = 1u << 3u, |
| 20720 |
+ |
| 20721 |
+ RequireSame = ChildrenRequiresSame | PostRequiresSame, |
| 20722 |
+ Neither = Empty, |
| 20723 |
+ Both = Children | Post, |
| 20724 |
+ BothWhenSame = Both | RequireSame, |
| 20725 |
+ }; |
| 20726 |
+ |
| 20727 |
+ private: |
| 20728 |
+ struct NodeStackGuard; |
| 20729 |
+ |
| 20730 |
+ template <typename T> |
| 20731 |
+ struct ConsList |
| 20732 |
+ { |
| 20733 |
+ T value; |
| 20734 |
+ ConsList<T> *tail; |
| 20735 |
+ }; |
| 20736 |
+ |
| 20737 |
+ class BaseResult |
| 20738 |
+ { |
| 20739 |
+ BaseResult(const BaseResult &) = delete; |
| 20740 |
+ BaseResult &operator=(const BaseResult &) = delete; |
| 20741 |
+ |
| 20742 |
+ public: |
| 20743 |
+ BaseResult(BaseResult &&other) = default; |
| 20744 |
+ BaseResult(BaseResult &other); // For subclass move constructor impls |
| 20745 |
+ BaseResult(TIntermNode &node, VisitBits visit); |
| 20746 |
+ BaseResult(TIntermNode *node, VisitBits visit); |
| 20747 |
+ BaseResult(nullptr_t); |
| 20748 |
+ BaseResult(Fail); |
| 20749 |
+ BaseResult(std::vector<TIntermNode *> &&nodes); |
| 20750 |
+ |
| 20751 |
+ void moveAssignImpl(BaseResult &other); // For subclass move assign impls |
| 20752 |
+ |
| 20753 |
+ static BaseResult Multi(std::vector<TIntermNode *> &&nodes); |
| 20754 |
+ |
| 20755 |
+ template <typename Iter> |
| 20756 |
+ static BaseResult Multi(Iter nodesBegin, Iter nodesEnd) |
| 20757 |
+ { |
| 20758 |
+ std::vector<TIntermNode *> nodes; |
| 20759 |
+ for (Iter nodesCurr = nodesBegin; nodesCurr != nodesEnd; ++nodesCurr) |
| 20760 |
+ { |
| 20761 |
+ nodes.push_back(*nodesCurr); |
| 20762 |
+ } |
| 20763 |
+ return std::move(nodes); |
| 20764 |
+ } |
| 20765 |
+ |
| 20766 |
+ bool isFail() const; |
| 20767 |
+ bool isDrop() const; |
| 20768 |
+ TIntermNode *single() const; |
| 20769 |
+ const std::vector<TIntermNode *> *multi() const; |
| 20770 |
+ |
| 20771 |
+ public: |
| 20772 |
+ Action mAction; |
| 20773 |
+ VisitBits mVisit; |
| 20774 |
+ TIntermNode *mSingle; |
| 20775 |
+ std::vector<TIntermNode *> mMulti; |
| 20776 |
+ }; |
| 20777 |
+ |
| 20778 |
+ public: |
| 20779 |
+ class PreResult : private BaseResult |
| 20780 |
+ { |
| 20781 |
+ friend class TIntermRebuild; |
| 20782 |
+ |
| 20783 |
+ public: |
| 20784 |
+ PreResult(PreResult &&other); |
| 20785 |
+ PreResult(TIntermNode &node, VisitBits visit = VisitBits::BothWhenSame); |
| 20786 |
+ PreResult(TIntermNode *node, VisitBits visit = VisitBits::BothWhenSame); |
| 20787 |
+ PreResult(nullptr_t); // Used to drop a node. |
| 20788 |
+ PreResult(Fail); // Used to signal failure. |
| 20789 |
+ |
| 20790 |
+ void operator=(PreResult &&other); |
| 20791 |
+ |
| 20792 |
+ static PreResult Multi(std::vector<TIntermNode *> &&nodes) |
| 20793 |
+ { |
| 20794 |
+ return BaseResult::Multi(std::move(nodes)); |
| 20795 |
+ } |
| 20796 |
+ |
| 20797 |
+ template <typename Iter> |
| 20798 |
+ static PreResult Multi(Iter nodesBegin, Iter nodesEnd) |
| 20799 |
+ { |
| 20800 |
+ return BaseResult::Multi(nodesBegin, nodesEnd); |
| 20801 |
+ } |
| 20802 |
+ |
| 20803 |
+ using BaseResult::isDrop; |
| 20804 |
+ using BaseResult::isFail; |
| 20805 |
+ using BaseResult::multi; |
| 20806 |
+ using BaseResult::single; |
| 20807 |
+ |
| 20808 |
+ private: |
| 20809 |
+ PreResult(BaseResult &&other); |
| 20810 |
+ }; |
| 20811 |
+ |
| 20812 |
+ class PostResult : private BaseResult |
| 20813 |
+ { |
| 20814 |
+ friend class TIntermRebuild; |
| 20815 |
+ |
| 20816 |
+ public: |
| 20817 |
+ PostResult(PostResult &&other); |
| 20818 |
+ PostResult(TIntermNode &node); |
| 20819 |
+ PostResult(TIntermNode *node); |
| 20820 |
+ PostResult(nullptr_t); // Used to drop a node |
| 20821 |
+ PostResult(Fail); // Used to signal failure. |
| 20822 |
+ |
| 20823 |
+ void operator=(PostResult &&other); |
| 20824 |
+ |
| 20825 |
+ static PostResult Multi(std::vector<TIntermNode *> &&nodes) |
| 20826 |
+ { |
| 20827 |
+ return BaseResult::Multi(std::move(nodes)); |
| 20828 |
+ } |
| 20829 |
+ |
| 20830 |
+ template <typename Iter> |
| 20831 |
+ static PostResult Multi(Iter nodesBegin, Iter nodesEnd) |
| 20832 |
+ { |
| 20833 |
+ return BaseResult::Multi(nodesBegin, nodesEnd); |
| 20834 |
+ } |
| 20835 |
+ |
| 20836 |
+ using BaseResult::isDrop; |
| 20837 |
+ using BaseResult::isFail; |
| 20838 |
+ using BaseResult::multi; |
| 20839 |
+ using BaseResult::single; |
| 20840 |
+ |
| 20841 |
+ private: |
| 20842 |
+ PostResult(BaseResult &&other); |
| 20843 |
+ }; |
| 20844 |
+ |
| 20845 |
+ public: |
| 20846 |
+ TIntermRebuild(TCompiler &compiler, bool preVisit, bool postVisit); |
| 20847 |
+ |
| 20848 |
+ virtual ~TIntermRebuild(); |
| 20849 |
+ |
| 20850 |
+ // Rebuilds the tree starting at the provided root. If a new node would be returned for the |
| 20851 |
+ // root, the root node's children become that of the new node instead. Returns false if failure |
| 20852 |
+ // occurred. |
| 20853 |
+ ANGLE_NO_DISCARD bool rebuildRoot(TIntermBlock &root); |
| 20854 |
+ |
| 20855 |
+ protected: |
| 20856 |
+ virtual PreResult visitSymbolPre(TIntermSymbol &node); |
| 20857 |
+ virtual PreResult visitConstantUnionPre(TIntermConstantUnion &node); |
| 20858 |
+ virtual PreResult visitFunctionPrototypePre(TIntermFunctionPrototype &node); |
| 20859 |
+ virtual PreResult visitPreprocessorDirectivePre(TIntermPreprocessorDirective &node); |
| 20860 |
+ virtual PreResult visitUnaryPre(TIntermUnary &node); |
| 20861 |
+ virtual PreResult visitBinaryPre(TIntermBinary &node); |
| 20862 |
+ virtual PreResult visitTernaryPre(TIntermTernary &node); |
| 20863 |
+ virtual PreResult visitSwizzlePre(TIntermSwizzle &node); |
| 20864 |
+ virtual PreResult visitIfElsePre(TIntermIfElse &node); |
| 20865 |
+ virtual PreResult visitSwitchPre(TIntermSwitch &node); |
| 20866 |
+ virtual PreResult visitCasePre(TIntermCase &node); |
| 20867 |
+ virtual PreResult visitLoopPre(TIntermLoop &node); |
| 20868 |
+ virtual PreResult visitBranchPre(TIntermBranch &node); |
| 20869 |
+ virtual PreResult visitDeclarationPre(TIntermDeclaration &node); |
| 20870 |
+ virtual PreResult visitBlockPre(TIntermBlock &node); |
| 20871 |
+ virtual PreResult visitAggregatePre(TIntermAggregate &node); |
| 20872 |
+ virtual PreResult visitFunctionDefinitionPre(TIntermFunctionDefinition &node); |
| 20873 |
+ virtual PreResult visitGlobalQualifierDeclarationPre(TIntermGlobalQualifierDeclaration &node); |
| 20874 |
+ |
| 20875 |
+ virtual PostResult visitSymbolPost(TIntermSymbol &node); |
| 20876 |
+ virtual PostResult visitConstantUnionPost(TIntermConstantUnion &node); |
| 20877 |
+ virtual PostResult visitFunctionPrototypePost(TIntermFunctionPrototype &node); |
| 20878 |
+ virtual PostResult visitPreprocessorDirectivePost(TIntermPreprocessorDirective &node); |
| 20879 |
+ virtual PostResult visitUnaryPost(TIntermUnary &node); |
| 20880 |
+ virtual PostResult visitBinaryPost(TIntermBinary &node); |
| 20881 |
+ virtual PostResult visitTernaryPost(TIntermTernary &node); |
| 20882 |
+ virtual PostResult visitSwizzlePost(TIntermSwizzle &node); |
| 20883 |
+ virtual PostResult visitIfElsePost(TIntermIfElse &node); |
| 20884 |
+ virtual PostResult visitSwitchPost(TIntermSwitch &node); |
| 20885 |
+ virtual PostResult visitCasePost(TIntermCase &node); |
| 20886 |
+ virtual PostResult visitLoopPost(TIntermLoop &node); |
| 20887 |
+ virtual PostResult visitBranchPost(TIntermBranch &node); |
| 20888 |
+ virtual PostResult visitDeclarationPost(TIntermDeclaration &node); |
| 20889 |
+ virtual PostResult visitBlockPost(TIntermBlock &node); |
| 20890 |
+ virtual PostResult visitAggregatePost(TIntermAggregate &node); |
| 20891 |
+ virtual PostResult visitFunctionDefinitionPost(TIntermFunctionDefinition &node); |
| 20892 |
+ virtual PostResult visitGlobalQualifierDeclarationPost(TIntermGlobalQualifierDeclaration &node); |
| 20893 |
+ |
| 20894 |
+ // Can be used to rebuild a specific node during a traversal. Useful for fine control of |
| 20895 |
+ // rebuilding a node's children. |
| 20896 |
+ ANGLE_NO_DISCARD PostResult rebuild(TIntermNode &node); |
| 20897 |
+ |
| 20898 |
+ // Rebuilds the provided node in place. If a new node would be returned, the old node's children |
| 20899 |
+ // become that of the new node instead. Returns false if failure occurred. |
| 20900 |
+ ANGLE_NO_DISCARD bool rebuildInPlace(TIntermAggregate &node); |
| 20901 |
+ |
| 20902 |
+ // Rebuilds the provided node in place. If a new node would be returned, the old node's children |
| 20903 |
+ // become that of the new node instead. Returns false if failure occurred. |
| 20904 |
+ ANGLE_NO_DISCARD bool rebuildInPlace(TIntermBlock &node); |
| 20905 |
+ |
| 20906 |
+ // Rebuilds the provided node in place. If a new node would be returned, the old node's children |
| 20907 |
+ // become that of the new node instead. Returns false if failure occurred. |
| 20908 |
+ ANGLE_NO_DISCARD bool rebuildInPlace(TIntermDeclaration &node); |
| 20909 |
+ |
| 20910 |
+ // If currently at or below a function declaration body, this returns the function that encloses |
| 20911 |
+ // the currently visited node. (This returns null if at a function declaration node.) |
| 20912 |
+ const TFunction *getParentFunction() const; |
| 20913 |
+ |
| 20914 |
+ TIntermNode *getParentNode(size_t offset = 0) const; |
| 20915 |
+ |
| 20916 |
+ private: |
| 20917 |
+ template <typename Node> |
| 20918 |
+ ANGLE_NO_DISCARD bool rebuildInPlaceImpl(Node &node); |
| 20919 |
+ |
| 20920 |
+ PostResult traverseAny(TIntermNode &node); |
| 20921 |
+ |
| 20922 |
+ template <typename Node> |
| 20923 |
+ Node *traverseAnyAs(TIntermNode &node); |
| 20924 |
+ |
| 20925 |
+ template <typename Node> |
| 20926 |
+ bool traverseAnyAs(TIntermNode &node, Node *&out); |
| 20927 |
+ |
| 20928 |
+ PreResult traversePre(TIntermNode &originalNode); |
| 20929 |
+ TIntermNode *traverseChildren(NodeType currNodeType, |
| 20930 |
+ const TIntermNode &originalNode, |
| 20931 |
+ TIntermNode &currNode, |
| 20932 |
+ VisitBits visit); |
| 20933 |
+ PostResult traversePost(NodeType nodeType, |
| 20934 |
+ const TIntermNode &originalNode, |
| 20935 |
+ TIntermNode &currNode, |
| 20936 |
+ VisitBits visit); |
| 20937 |
+ |
| 20938 |
+ bool traverseAggregateBaseChildren(TIntermAggregateBase &node); |
| 20939 |
+ |
| 20940 |
+ TIntermNode *traverseUnaryChildren(TIntermUnary &node); |
| 20941 |
+ TIntermNode *traverseBinaryChildren(TIntermBinary &node); |
| 20942 |
+ TIntermNode *traverseTernaryChildren(TIntermTernary &node); |
| 20943 |
+ TIntermNode *traverseSwizzleChildren(TIntermSwizzle &node); |
| 20944 |
+ TIntermNode *traverseIfElseChildren(TIntermIfElse &node); |
| 20945 |
+ TIntermNode *traverseSwitchChildren(TIntermSwitch &node); |
| 20946 |
+ TIntermNode *traverseCaseChildren(TIntermCase &node); |
| 20947 |
+ TIntermNode *traverseLoopChildren(TIntermLoop &node); |
| 20948 |
+ TIntermNode *traverseBranchChildren(TIntermBranch &node); |
| 20949 |
+ TIntermNode *traverseDeclarationChildren(TIntermDeclaration &node); |
| 20950 |
+ TIntermNode *traverseBlockChildren(TIntermBlock &node); |
| 20951 |
+ TIntermNode *traverseAggregateChildren(TIntermAggregate &node); |
| 20952 |
+ TIntermNode *traverseFunctionDefinitionChildren(TIntermFunctionDefinition &node); |
| 20953 |
+ TIntermNode *traverseGlobalQualifierDeclarationChildren( |
| 20954 |
+ TIntermGlobalQualifierDeclaration &node); |
| 20955 |
+ |
| 20956 |
+ protected: |
| 20957 |
+ TCompiler &mCompiler; |
| 20958 |
+ TSymbolTable &mSymbolTable; |
| 20959 |
+ const TFunction *mParentFunc = nullptr; |
| 20960 |
+ GetNodeType getNodeType; |
| 20961 |
+ |
| 20962 |
+ private: |
| 20963 |
+ ConsList<TIntermNode *> mNodeStack{nullptr, nullptr}; |
| 20964 |
+ bool mPreVisit; |
| 20965 |
+ bool mPostVisit; |
| 20966 |
+}; |
| 20967 |
+ |
| 20968 |
+} // namespace sh |
| 20969 |
+ |
| 20970 |
+#endif // COMPILER_TRANSLATOR_TREEUTIL_INTERMREBUILD_H_ |
| 20971 |
diff --git a/src/compiler/translator/tree_util/NodeType.h b/src/compiler/translator/tree_util/NodeType.h |
| 20972 |
new file mode 100644 |
| 20973 |
index 0000000..a59e5af |
| 20974 |
--- /dev/null |
| 20975 |
+++ b/src/compiler/translator/tree_util/NodeType.h |
| 20976 |
@@ -0,0 +1,155 @@ |
| 20977 |
+// |
| 20978 |
+// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 20979 |
+// Use of this source code is governed by a BSD-style license that can be |
| 20980 |
+// found in the LICENSE file. |
| 20981 |
+// |
| 20982 |
+ |
| 20983 |
+#ifndef COMPILER_TRANSLATOR_TREEUTIL_NODETYPE_H_ |
| 20984 |
+#define COMPILER_TRANSLATOR_TREEUTIL_NODETYPE_H_ |
| 20985 |
+ |
| 20986 |
+#include "compiler/translator/tree_util/IntermTraverse.h" |
| 20987 |
+ |
| 20988 |
+namespace sh |
| 20989 |
+{ |
| 20990 |
+ |
| 20991 |
+enum class NodeType |
| 20992 |
+{ |
| 20993 |
+ Unknown, |
| 20994 |
+ Symbol, |
| 20995 |
+ ConstantUnion, |
| 20996 |
+ FunctionPrototype, |
| 20997 |
+ PreprocessorDirective, |
| 20998 |
+ Unary, |
| 20999 |
+ Binary, |
| 21000 |
+ Ternary, |
| 21001 |
+ Swizzle, |
| 21002 |
+ IfElse, |
| 21003 |
+ Switch, |
| 21004 |
+ Case, |
| 21005 |
+ FunctionDefinition, |
| 21006 |
+ Aggregate, |
| 21007 |
+ Block, |
| 21008 |
+ GlobalQualifierDeclaration, |
| 21009 |
+ Declaration, |
| 21010 |
+ Loop, |
| 21011 |
+ Branch, |
| 21012 |
+}; |
| 21013 |
+ |
| 21014 |
+// This is a function like object instead of a function that stack allocates this because |
| 21015 |
+// TIntermTraverser is a heavy object to construct. |
| 21016 |
+class GetNodeType : private TIntermTraverser |
| 21017 |
+{ |
| 21018 |
+ NodeType nodeType; |
| 21019 |
+ |
| 21020 |
+ public: |
| 21021 |
+ GetNodeType() : TIntermTraverser(true, false, false) {} |
| 21022 |
+ |
| 21023 |
+ NodeType operator()(TIntermNode &node) |
| 21024 |
+ { |
| 21025 |
+ node.visit(Visit::PreVisit, this); |
| 21026 |
+ return nodeType; |
| 21027 |
+ } |
| 21028 |
+ |
| 21029 |
+ private: |
| 21030 |
+ void visitSymbol(TIntermSymbol *) override { nodeType = NodeType::Symbol; } |
| 21031 |
+ |
| 21032 |
+ void visitConstantUnion(TIntermConstantUnion *) override { nodeType = NodeType::ConstantUnion; } |
| 21033 |
+ |
| 21034 |
+ void visitFunctionPrototype(TIntermFunctionPrototype *) override |
| 21035 |
+ { |
| 21036 |
+ nodeType = NodeType::FunctionPrototype; |
| 21037 |
+ } |
| 21038 |
+ |
| 21039 |
+ void visitPreprocessorDirective(TIntermPreprocessorDirective *) override |
| 21040 |
+ { |
| 21041 |
+ nodeType = NodeType::PreprocessorDirective; |
| 21042 |
+ } |
| 21043 |
+ |
| 21044 |
+ bool visitSwizzle(Visit, TIntermSwizzle *) override |
| 21045 |
+ { |
| 21046 |
+ nodeType = NodeType::Swizzle; |
| 21047 |
+ return false; |
| 21048 |
+ } |
| 21049 |
+ |
| 21050 |
+ bool visitBinary(Visit, TIntermBinary *) override |
| 21051 |
+ { |
| 21052 |
+ nodeType = NodeType::Binary; |
| 21053 |
+ return false; |
| 21054 |
+ } |
| 21055 |
+ |
| 21056 |
+ bool visitUnary(Visit, TIntermUnary *) override |
| 21057 |
+ { |
| 21058 |
+ nodeType = NodeType::Unary; |
| 21059 |
+ return false; |
| 21060 |
+ } |
| 21061 |
+ |
| 21062 |
+ bool visitTernary(Visit, TIntermTernary *) override |
| 21063 |
+ { |
| 21064 |
+ nodeType = NodeType::Ternary; |
| 21065 |
+ return false; |
| 21066 |
+ } |
| 21067 |
+ |
| 21068 |
+ bool visitIfElse(Visit, TIntermIfElse *) override |
| 21069 |
+ { |
| 21070 |
+ nodeType = NodeType::IfElse; |
| 21071 |
+ return false; |
| 21072 |
+ } |
| 21073 |
+ |
| 21074 |
+ bool visitSwitch(Visit, TIntermSwitch *) override |
| 21075 |
+ { |
| 21076 |
+ nodeType = NodeType::Switch; |
| 21077 |
+ return false; |
| 21078 |
+ } |
| 21079 |
+ |
| 21080 |
+ bool visitCase(Visit, TIntermCase *) override |
| 21081 |
+ { |
| 21082 |
+ nodeType = NodeType::Case; |
| 21083 |
+ return false; |
| 21084 |
+ } |
| 21085 |
+ |
| 21086 |
+ bool visitFunctionDefinition(Visit, TIntermFunctionDefinition *) override |
| 21087 |
+ { |
| 21088 |
+ nodeType = NodeType::FunctionDefinition; |
| 21089 |
+ return false; |
| 21090 |
+ } |
| 21091 |
+ |
| 21092 |
+ bool visitAggregate(Visit, TIntermAggregate *) override |
| 21093 |
+ { |
| 21094 |
+ nodeType = NodeType::Aggregate; |
| 21095 |
+ return false; |
| 21096 |
+ } |
| 21097 |
+ |
| 21098 |
+ bool visitBlock(Visit, TIntermBlock *) override |
| 21099 |
+ { |
| 21100 |
+ nodeType = NodeType::Block; |
| 21101 |
+ return false; |
| 21102 |
+ } |
| 21103 |
+ |
| 21104 |
+ bool visitGlobalQualifierDeclaration(Visit, TIntermGlobalQualifierDeclaration *) override |
| 21105 |
+ { |
| 21106 |
+ nodeType = NodeType::GlobalQualifierDeclaration; |
| 21107 |
+ return false; |
| 21108 |
+ } |
| 21109 |
+ |
| 21110 |
+ bool visitDeclaration(Visit, TIntermDeclaration *) override |
| 21111 |
+ { |
| 21112 |
+ nodeType = NodeType::Declaration; |
| 21113 |
+ return false; |
| 21114 |
+ } |
| 21115 |
+ |
| 21116 |
+ bool visitLoop(Visit, TIntermLoop *) override |
| 21117 |
+ { |
| 21118 |
+ nodeType = NodeType::Loop; |
| 21119 |
+ return false; |
| 21120 |
+ } |
| 21121 |
+ |
| 21122 |
+ bool visitBranch(Visit, TIntermBranch *) override |
| 21123 |
+ { |
| 21124 |
+ nodeType = NodeType::Branch; |
| 21125 |
+ return false; |
| 21126 |
+ } |
| 21127 |
+}; |
| 21128 |
+ |
| 21129 |
+} // namespace sh |
| 21130 |
+ |
| 21131 |
+#endif // COMPILER_TRANSLATOR_TREEUTIL_NODETYPE_H_ |
| 21132 |
diff --git a/src/compiler/translator/util.cpp b/src/compiler/translator/util.cpp |
| 21133 |
index 346470e..582ddc7 100644 |
| 21134 |
--- a/src/compiler/translator/util.cpp |
| 21135 |
+++ b/src/compiler/translator/util.cpp |
| 21136 |
@@ -804,6 +804,10 @@ bool IsOutputMetal(ShShaderOutput output) |
| 21137 |
{ |
| 21138 |
return output == SH_GLSL_METAL_OUTPUT; |
| 21139 |
} |
| 21140 |
+bool IsOutputMetalDirect(ShShaderOutput output) |
| 21141 |
+{ |
| 21142 |
+ return output == SH_MSL_METAL_OUTPUT; |
| 21143 |
+} |
| 21144 |
|
| 21145 |
bool IsInShaderStorageBlock(TIntermTyped *node) |
| 21146 |
{ |
| 21147 |
diff --git a/src/compiler/translator/util.h b/src/compiler/translator/util.h |
| 21148 |
index 53ee755..f9ae9bb 100644 |
| 21149 |
--- a/src/compiler/translator/util.h |
| 21150 |
+++ b/src/compiler/translator/util.h |
| 21151 |
@@ -77,6 +77,7 @@ bool IsOutputGLSL(ShShaderOutput output); |
| 21152 |
bool IsOutputHLSL(ShShaderOutput output); |
| 21153 |
bool IsOutputVulkan(ShShaderOutput output); |
| 21154 |
bool IsOutputMetal(ShShaderOutput output); |
| 21155 |
+bool IsOutputMetalDirect(ShShaderOutput output); |
| 21156 |
|
| 21157 |
bool IsInShaderStorageBlock(TIntermTyped *node); |
| 21158 |
|
| 21159 |
diff --git a/src/gpu_info_util/SystemInfo.cpp b/src/gpu_info_util/SystemInfo.cpp |
| 21160 |
index f748949..54c3db5 100644 |
| 21161 |
--- a/src/gpu_info_util/SystemInfo.cpp |
| 21162 |
+++ b/src/gpu_info_util/SystemInfo.cpp |
| 21163 |
@@ -47,6 +47,8 @@ std::string VendorName(VendorID vendor) |
| 21164 |
return "Vivante"; |
| 21165 |
case kVendorID_VMWare: |
| 21166 |
return "VMWare"; |
| 21167 |
+ case kVendorID_Apple: |
| 21168 |
+ return "Apple"; |
| 21169 |
default: |
| 21170 |
return "Unknown (" + std::to_string(vendor) + ")"; |
| 21171 |
} |
| 21172 |
@@ -160,6 +162,11 @@ bool IsVivante(VendorID vendorId) |
| 21173 |
return vendorId == kVendorID_Vivante; |
| 21174 |
} |
| 21175 |
|
| 21176 |
+bool IsApple(VendorID vendorId) |
| 21177 |
+{ |
| 21178 |
+ return vendorId == kVendorID_Apple; |
| 21179 |
+} |
| 21180 |
+ |
| 21181 |
bool ParseAMDBrahmaDriverVersion(const std::string &content, std::string *version) |
| 21182 |
{ |
| 21183 |
const size_t begin = content.find_first_of("0123456789"); |
| 21184 |
diff --git a/src/gpu_info_util/SystemInfo.h b/src/gpu_info_util/SystemInfo.h |
| 21185 |
index ad17698..509a1e9 100644 |
| 21186 |
--- a/src/gpu_info_util/SystemInfo.h |
| 21187 |
+++ b/src/gpu_info_util/SystemInfo.h |
| 21188 |
@@ -67,9 +67,8 @@ struct SystemInfo |
| 21189 |
bool isAMDSwitchable = false; |
| 21190 |
// Only true on dual-GPU Mac laptops. |
| 21191 |
bool isMacSwitchable = false; |
| 21192 |
- // Only true on Apple Silicon Macs when running iOS binaries. |
| 21193 |
- // See https://developer.apple.com/documentation/foundation/nsprocessinfo/3608556-iosapponmac |
| 21194 |
- bool isiOSAppOnMac = false; |
| 21195 |
+ // Only true on Apple Silicon Macs when running in macCatalyst. |
| 21196 |
+ bool needsEAGLOnMac = false; |
| 21197 |
|
| 21198 |
// Only available on Android |
| 21199 |
std::string machineManufacturer; |
| 21200 |
@@ -99,6 +98,7 @@ constexpr VendorID kVendorID_Intel = 0x8086; |
| 21201 |
constexpr VendorID kVendorID_NVIDIA = 0x10DE; |
| 21202 |
constexpr VendorID kVendorID_Qualcomm = 0x5143; |
| 21203 |
constexpr VendorID kVendorID_VMWare = 0x15ad; |
| 21204 |
+constexpr VendorID kVendorID_Apple = 0x106B; |
| 21205 |
|
| 21206 |
// Known non-PCI (i.e. Khronos-registered) vendor IDs |
| 21207 |
constexpr VendorID kVendorID_Vivante = 0x10001; |
| 21208 |
@@ -124,6 +124,7 @@ bool IsSwiftshader(VendorID vendorId); |
| 21209 |
bool IsVeriSilicon(VendorID vendorId); |
| 21210 |
bool IsVMWare(VendorID vendorId); |
| 21211 |
bool IsVivante(VendorID vendorId); |
| 21212 |
+bool IsApple(VendorID vendorId); |
| 21213 |
|
| 21214 |
// Use a heuristic to attempt to find the GPU used for 3D graphics. Sets activeGPUIndex, |
| 21215 |
// isOptimus, and isAMDSwitchable. |
| 21216 |
diff --git a/src/gpu_info_util/SystemInfo_apple.mm b/src/gpu_info_util/SystemInfo_apple.mm |
| 21217 |
index c7756f6..1500fff 100644 |
| 21218 |
--- a/src/gpu_info_util/SystemInfo_apple.mm |
| 21219 |
+++ b/src/gpu_info_util/SystemInfo_apple.mm |
| 21220 |
@@ -1,5 +1,5 @@ |
| 21221 |
// |
| 21222 |
-// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 21223 |
+// Copyright 2020 Apple, Inc. All rights reserved. |
| 21224 |
// Use of this source code is governed by a BSD-style license that can be |
| 21225 |
// found in the LICENSE file. |
| 21226 |
// |
| 21227 |
diff --git a/src/gpu_info_util/SystemInfo_ios.cpp b/src/gpu_info_util/SystemInfo_ios.cpp |
| 21228 |
index 323af2c..7a9d9fa 100644 |
| 21229 |
--- a/src/gpu_info_util/SystemInfo_ios.cpp |
| 21230 |
+++ b/src/gpu_info_util/SystemInfo_ios.cpp |
| 21231 |
@@ -18,8 +18,16 @@ namespace angle |
| 21232 |
bool GetSystemInfo_ios(SystemInfo *info) |
| 21233 |
{ |
| 21234 |
{ |
| 21235 |
+ // GPUDeviceInfo deviceInfo; |
| 21236 |
+ // deviceInfo.vendorId = kVendorID_Apple; |
| 21237 |
+ // deviceInfo.deviceId = 0; |
| 21238 |
+ // deviceInfo.driverVendor = "Apple"; |
| 21239 |
+ // deviceInfo.driverVersion = "0.0"; |
| 21240 |
+ // deviceInfo.driverDate = "1/1/1970"; |
| 21241 |
+ |
| 21242 |
// TODO(anglebug.com/4275): Get the actual system version. |
| 21243 |
info->machineModelVersion = "0.0"; |
| 21244 |
+ // info->gpus.push_back(deviceInfo); |
| 21245 |
} |
| 21246 |
|
| 21247 |
return true; |
| 21248 |
diff --git a/src/gpu_info_util/SystemInfo_macos.mm b/src/gpu_info_util/SystemInfo_macos.mm |
| 21249 |
index b1cd055..c5e039e 100644 |
| 21250 |
--- a/src/gpu_info_util/SystemInfo_macos.mm |
| 21251 |
+++ b/src/gpu_info_util/SystemInfo_macos.mm |
| 21252 |
@@ -322,6 +322,10 @@ bool GetSystemInfo_mac(SystemInfo *info) |
| 21253 |
info->isMacSwitchable = true; |
| 21254 |
} |
| 21255 |
|
| 21256 |
+#if defined(ANGLE_PLATFORM_MACCATALYST) && defined(ANGLE_CPU_ARM64) |
| 21257 |
+ info->needsEAGLOnMac = true; |
| 21258 |
+#endif |
| 21259 |
+ |
| 21260 |
return true; |
| 21261 |
} |
| 21262 |
|
| 21263 |
diff --git a/src/libANGLE/Caps.cpp b/src/libANGLE/Caps.cpp |
| 21264 |
index f906783..7931009 100644 |
| 21265 |
--- a/src/libANGLE/Caps.cpp |
| 21266 |
+++ b/src/libANGLE/Caps.cpp |
| 21267 |
@@ -170,8 +170,8 @@ static bool GetFormatSupportBase(const TextureCapsMap &textureCaps, |
| 21268 |
{ |
| 21269 |
for (size_t i = 0; i < requiredFormatsSize; i++) |
| 21270 |
{ |
| 21271 |
- const TextureCaps &cap = textureCaps.get(requiredFormats[i]); |
| 21272 |
|
| 21273 |
+ const TextureCaps &cap = textureCaps.get(requiredFormats[i]); |
| 21274 |
if (requiresTexturing && !cap.texturable) |
| 21275 |
{ |
| 21276 |
return false; |
| 21277 |
@@ -462,7 +462,6 @@ static bool DetermineASTCLDRTextureSupport(const TextureCapsMap &textureCaps) |
| 21278 |
GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR, |
| 21279 |
GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR, |
| 21280 |
}; |
| 21281 |
- |
| 21282 |
return GetFormatSupport(textureCaps, requiredFormats, true, true, false, false, false); |
| 21283 |
} |
| 21284 |
|
| 21285 |
diff --git a/src/libANGLE/Display.cpp b/src/libANGLE/Display.cpp |
| 21286 |
index dde4337..657814f 100644 |
| 21287 |
--- a/src/libANGLE/Display.cpp |
| 21288 |
+++ b/src/libANGLE/Display.cpp |
| 21289 |
@@ -181,7 +181,13 @@ EGLAttrib GetDisplayTypeFromEnvironment() |
| 21290 |
return EGL_PLATFORM_ANGLE_TYPE_NULL_ANGLE; |
| 21291 |
} |
| 21292 |
#endif |
| 21293 |
+#if defined(ANGLE_ENABLE_METAL) |
| 21294 |
+ if (angleDefaultEnv == "metal") |
| 21295 |
+ { |
| 21296 |
+ return EGL_PLATFORM_ANGLE_TYPE_METAL_ANGLE; |
| 21297 |
+ } |
| 21298 |
|
| 21299 |
+#endif |
| 21300 |
#if defined(ANGLE_ENABLE_D3D11) |
| 21301 |
return EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE; |
| 21302 |
#elif defined(ANGLE_ENABLE_D3D9) |
| 21303 |
@@ -1325,6 +1331,47 @@ Error Display::makeCurrent(gl::Context *previousContext, |
| 21304 |
return NoError(); |
| 21305 |
} |
| 21306 |
|
| 21307 |
+Error Display::makeCurrent(const Thread *thread, |
| 21308 |
+ egl::Surface *drawSurface, |
| 21309 |
+ egl::Surface *readSurface, |
| 21310 |
+ gl::Context *context) |
| 21311 |
+{ |
| 21312 |
+ if (!mInitialized) |
| 21313 |
+ { |
| 21314 |
+ return NoError(); |
| 21315 |
+ } |
| 21316 |
+ |
| 21317 |
+ gl::Context *previousContext = thread->getContext(); |
| 21318 |
+ if (previousContext) |
| 21319 |
+ { |
| 21320 |
+ ANGLE_TRY(previousContext->unMakeCurrent(this)); |
| 21321 |
+ } |
| 21322 |
+ |
| 21323 |
+ ANGLE_TRY(mImplementation->makeCurrent(this, drawSurface, readSurface, context)); |
| 21324 |
+ |
| 21325 |
+ if (context != nullptr) |
| 21326 |
+ { |
| 21327 |
+ ANGLE_TRY(context->makeCurrent(this, drawSurface, readSurface)); |
| 21328 |
+ } |
| 21329 |
+ |
| 21330 |
+ // Tick all the scratch buffers to make sure they get cleaned up eventually if they stop being |
| 21331 |
+ // used. |
| 21332 |
+ { |
| 21333 |
+ std::lock_guard<std::mutex> lock(mScratchBufferMutex); |
| 21334 |
+ |
| 21335 |
+ for (angle::ScratchBuffer &scatchBuffer : mScratchBuffers) |
| 21336 |
+ { |
| 21337 |
+ scatchBuffer.tick(); |
| 21338 |
+ } |
| 21339 |
+ for (angle::ScratchBuffer &zeroFilledBuffer : mZeroFilledBuffers) |
| 21340 |
+ { |
| 21341 |
+ zeroFilledBuffer.tick(); |
| 21342 |
+ } |
| 21343 |
+ } |
| 21344 |
+ |
| 21345 |
+ return NoError(); |
| 21346 |
+} |
| 21347 |
+ |
| 21348 |
Error Display::restoreLostDevice() |
| 21349 |
{ |
| 21350 |
for (ContextSet::iterator ctx = mContextSet.begin(); ctx != mContextSet.end(); ctx++) |
| 21351 |
diff --git a/src/libANGLE/Display.h b/src/libANGLE/Display.h |
| 21352 |
index 4ac6336..16faf2b 100644 |
| 21353 |
--- a/src/libANGLE/Display.h |
| 21354 |
+++ b/src/libANGLE/Display.h |
| 21355 |
@@ -166,6 +166,11 @@ class Display final : public LabeledObject, |
| 21356 |
const AttributeMap &attribs, |
| 21357 |
gl::Context **outContext); |
| 21358 |
|
| 21359 |
+ Error makeCurrent(const Thread *thread, |
| 21360 |
+ Surface *drawSurface, |
| 21361 |
+ Surface *readSurface, |
| 21362 |
+ gl::Context *context); |
| 21363 |
+ |
| 21364 |
Error createSync(const gl::Context *currentContext, |
| 21365 |
EGLenum type, |
| 21366 |
const AttributeMap &attribs, |
| 21367 |
diff --git a/src/libANGLE/Program.h b/src/libANGLE/Program.h |
| 21368 |
index fe3ec28..ba9267a 100644 |
| 21369 |
--- a/src/libANGLE/Program.h |
| 21370 |
+++ b/src/libANGLE/Program.h |
| 21371 |
@@ -276,6 +276,11 @@ class ProgramState final : angle::NonCopyable |
| 21372 |
{ |
| 21373 |
return mExecutable->getLinkedTransformFeedbackVaryings(); |
| 21374 |
} |
| 21375 |
+ void setLinkedTransformFeedbackVaryings( |
| 21376 |
+ const std::vector<TransformFeedbackVarying> _mLinkedTransformFeedbackVaryings) const |
| 21377 |
+ { |
| 21378 |
+ return mExecutable->setLinkedTransformFeedbackVaryings(_mLinkedTransformFeedbackVaryings); |
| 21379 |
+ } |
| 21380 |
const std::vector<GLsizei> &getTransformFeedbackStrides() const |
| 21381 |
{ |
| 21382 |
return mExecutable->getTransformFeedbackStrides(); |
| 21383 |
diff --git a/src/libANGLE/ProgramExecutable.h b/src/libANGLE/ProgramExecutable.h |
| 21384 |
index 950832b..48f3bd2 100644 |
| 21385 |
--- a/src/libANGLE/ProgramExecutable.h |
| 21386 |
+++ b/src/libANGLE/ProgramExecutable.h |
| 21387 |
@@ -229,6 +229,11 @@ class ProgramExecutable final : public angle::Subject |
| 21388 |
{ |
| 21389 |
return mLinkedTransformFeedbackVaryings; |
| 21390 |
} |
| 21391 |
+ void setLinkedTransformFeedbackVaryings( |
| 21392 |
+ const std::vector<TransformFeedbackVarying> _mLinkedTransformFeedbackVaryings) |
| 21393 |
+ { |
| 21394 |
+ mLinkedTransformFeedbackVaryings = _mLinkedTransformFeedbackVaryings; |
| 21395 |
+ } |
| 21396 |
GLint getTransformFeedbackBufferMode() const { return mTransformFeedbackBufferMode; } |
| 21397 |
GLuint getUniformBlockBinding(GLuint uniformBlockIndex) const |
| 21398 |
{ |
| 21399 |
diff --git a/src/libANGLE/Shader.cpp b/src/libANGLE/Shader.cpp |
| 21400 |
index 6f9a78a..96006d9 100644 |
| 21401 |
--- a/src/libANGLE/Shader.cpp |
| 21402 |
+++ b/src/libANGLE/Shader.cpp |
| 21403 |
@@ -655,7 +655,9 @@ std::string Shader::getTransformFeedbackVaryingMappedName(const std::string &tfV |
| 21404 |
{ |
| 21405 |
GLuint fieldIndex = 0; |
| 21406 |
const auto *field = varying.findField(tfVaryingName, &fieldIndex); |
| 21407 |
- ASSERT(field != nullptr && !field->isStruct() && !field->isArray()); |
| 21408 |
+ if (!field) |
| 21409 |
+ continue; |
| 21410 |
+ ASSERT(!field->isStruct() && !field->isArray()); |
| 21411 |
return varying.mappedName + "." + field->mappedName; |
| 21412 |
} |
| 21413 |
} |
| 21414 |
diff --git a/src/libANGLE/State.cpp b/src/libANGLE/State.cpp |
| 21415 |
index 7b08d8d..a804486 100644 |
| 21416 |
--- a/src/libANGLE/State.cpp |
| 21417 |
+++ b/src/libANGLE/State.cpp |
| 21418 |
@@ -6,6 +6,9 @@ |
| 21419 |
|
| 21420 |
// State.cpp: Implements the State class, encapsulating raw GL state. |
| 21421 |
|
| 21422 |
+// Older clang versions have a false positive on this warning here. |
| 21423 |
+#pragma clang diagnostic ignored "-Wglobal-constructors" |
| 21424 |
+ |
| 21425 |
#include "libANGLE/State.h" |
| 21426 |
|
| 21427 |
#include <string.h> |
| 21428 |
diff --git a/src/libANGLE/formatutils.cpp b/src/libANGLE/formatutils.cpp |
| 21429 |
index 3f9f37d..5e628f2 100644 |
| 21430 |
--- a/src/libANGLE/formatutils.cpp |
| 21431 |
+++ b/src/libANGLE/formatutils.cpp |
| 21432 |
@@ -1034,7 +1034,7 @@ static InternalFormatInfoMap BuildInternalFormatInfoMap() |
| 21433 |
angle::SystemInfo info; |
| 21434 |
if (angle::GetSystemInfo(&info)) |
| 21435 |
{ |
| 21436 |
- if (info.isiOSAppOnMac) |
| 21437 |
+ if (info.needsEAGLOnMac) |
| 21438 |
{ |
| 21439 |
// Using OpenGLES.framework. |
| 21440 |
AddRGBAFormat(&map, GL_BGRA_EXT, false, 8, 8, 8, 8, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireES<2, 0>, AlwaysSupported, RequireES<2, 0>, NeverSupported, NeverSupported); |
| 21441 |
diff --git a/src/libANGLE/renderer/driver_utils.cpp b/src/libANGLE/renderer/driver_utils.cpp |
| 21442 |
index d4c6aed..22364b3 100644 |
| 21443 |
--- a/src/libANGLE/renderer/driver_utils.cpp |
| 21444 |
+++ b/src/libANGLE/renderer/driver_utils.cpp |
| 21445 |
@@ -205,7 +205,7 @@ bool operator>=(const OSVersion &a, const OSVersion &b) |
| 21446 |
std::tie(b.majorVersion, b.minorVersion, b.patchVersion); |
| 21447 |
} |
| 21448 |
|
| 21449 |
-#if !defined(ANGLE_PLATFORM_APPLE) |
| 21450 |
+#if !defined(ANGLE_PLATFORM_MACOS) |
| 21451 |
OSVersion GetMacOSVersion() |
| 21452 |
{ |
| 21453 |
// Return a default version |
| 21454 |
@@ -213,6 +213,14 @@ OSVersion GetMacOSVersion() |
| 21455 |
} |
| 21456 |
#endif |
| 21457 |
|
| 21458 |
+#if !defined(ANGLE_PLATFORM_IOS) |
| 21459 |
+OSVersion GetiOSVersion() |
| 21460 |
+{ |
| 21461 |
+ // Return a default version |
| 21462 |
+ return OSVersion(0, 0, 0); |
| 21463 |
+} |
| 21464 |
+#endif |
| 21465 |
+ |
| 21466 |
#if defined(ANGLE_PLATFORM_LINUX) |
| 21467 |
bool ParseLinuxOSVersion(const char *version, int *major, int *minor, int *patch) |
| 21468 |
{ |
| 21469 |
diff --git a/src/libANGLE/renderer/driver_utils.h b/src/libANGLE/renderer/driver_utils.h |
| 21470 |
index 2619bc3..78772ae 100644 |
| 21471 |
--- a/src/libANGLE/renderer/driver_utils.h |
| 21472 |
+++ b/src/libANGLE/renderer/driver_utils.h |
| 21473 |
@@ -167,6 +167,15 @@ inline bool IsApple() |
| 21474 |
#endif |
| 21475 |
} |
| 21476 |
|
| 21477 |
+inline bool IsMac() |
| 21478 |
+{ |
| 21479 |
+#if defined(ANGLE_PLATFORM_APPLE) && defined(ANGLE_PLATFORM_MACOS) |
| 21480 |
+ return true; |
| 21481 |
+#else |
| 21482 |
+ return false; |
| 21483 |
+#endif |
| 21484 |
+} |
| 21485 |
+ |
| 21486 |
inline bool IsFuchsia() |
| 21487 |
{ |
| 21488 |
#if defined(ANGLE_PLATFORM_FUCHSIA) |
| 21489 |
@@ -204,6 +213,8 @@ bool operator>=(const OSVersion &a, const OSVersion &b); |
| 21490 |
|
| 21491 |
OSVersion GetMacOSVersion(); |
| 21492 |
|
| 21493 |
+OSVersion GetiOSVersion(); |
| 21494 |
+ |
| 21495 |
OSVersion GetLinuxOSVersion(); |
| 21496 |
|
| 21497 |
inline bool IsAndroid() |
| 21498 |
diff --git a/src/libANGLE/renderer/driver_utils_ios.mm b/src/libANGLE/renderer/driver_utils_ios.mm |
| 21499 |
new file mode 100644 |
| 21500 |
index 0000000..e7a845c |
| 21501 |
--- /dev/null |
| 21502 |
+++ b/src/libANGLE/renderer/driver_utils_ios.mm |
| 21503 |
@@ -0,0 +1,28 @@ |
| 21504 |
+// |
| 21505 |
+// Copyright 2019 The ANGLE Project Authors. All rights reserved. |
| 21506 |
+// Use of this source code is governed by a BSD-style license that can be |
| 21507 |
+// found in the LICENSE file. |
| 21508 |
+// |
| 21509 |
+ |
| 21510 |
+// driver_utils_ios.mm : provides ios-specific information about current driver. |
| 21511 |
+ |
| 21512 |
+#include "libANGLE/renderer/driver_utils.h" |
| 21513 |
+ |
| 21514 |
+#import <Foundation/Foundation.h> |
| 21515 |
+ |
| 21516 |
+namespace rx |
| 21517 |
+{ |
| 21518 |
+ |
| 21519 |
+OSVersion GetiOSVersion() |
| 21520 |
+{ |
| 21521 |
+ OSVersion result; |
| 21522 |
+ |
| 21523 |
+ NSOperatingSystemVersion version = [[NSProcessInfo processInfo] operatingSystemVersion]; |
| 21524 |
+ result.majorVersion = static_cast<int>(version.majorVersion); |
| 21525 |
+ result.minorVersion = static_cast<int>(version.minorVersion); |
| 21526 |
+ result.patchVersion = static_cast<int>(version.patchVersion); |
| 21527 |
+ |
| 21528 |
+ return result; |
| 21529 |
+} |
| 21530 |
+ |
| 21531 |
+} |
| 21532 |
diff --git a/src/libANGLE/renderer/driver_utils_mac.mm b/src/libANGLE/renderer/driver_utils_mac.mm |
| 21533 |
index 3af46fc..9b53eb7 100644 |
| 21534 |
--- a/src/libANGLE/renderer/driver_utils_mac.mm |
| 21535 |
+++ b/src/libANGLE/renderer/driver_utils_mac.mm |
| 21536 |
@@ -13,6 +13,7 @@ |
| 21537 |
namespace rx |
| 21538 |
{ |
| 21539 |
|
| 21540 |
+#if !TARGET_OS_IOS |
| 21541 |
OSVersion GetMacOSVersion() |
| 21542 |
{ |
| 21543 |
OSVersion result; |
| 21544 |
@@ -24,5 +25,5 @@ OSVersion GetMacOSVersion() |
| 21545 |
|
| 21546 |
return result; |
| 21547 |
} |
| 21548 |
- |
| 21549 |
+#endif |
| 21550 |
} |
| 21551 |
diff --git a/src/libANGLE/renderer/gl/SoftLinking_apple.h b/src/libANGLE/renderer/gl/SoftLinking_apple.h |
| 21552 |
new file mode 100644 |
| 21553 |
index 0000000..ef3a6d7 |
| 21554 |
--- /dev/null |
| 21555 |
+++ b/src/libANGLE/renderer/gl/SoftLinking_apple.h |
| 21556 |
@@ -0,0 +1,112 @@ |
| 21557 |
+// |
| 21558 |
+// Copyright 2020 Apple, Inc. All rights reserved. |
| 21559 |
+// Use of this source code is governed by a BSD-style license that can be |
| 21560 |
+// found in the LICENSE file. |
| 21561 |
+// |
| 21562 |
+ |
| 21563 |
+// SoftLinking_apple.cpp: Macros for soft-linking Frameworks and Functions. |
| 21564 |
+ |
| 21565 |
+#ifndef SOFT_LINKING_APPLE_H_ |
| 21566 |
+#define SOFT_LINKING_APPLE_H_ |
| 21567 |
+ |
| 21568 |
+#include "common/platform.h" |
| 21569 |
+ |
| 21570 |
+#if defined(ANGLE_PLATFORM_APPLE) |
| 21571 |
+ |
| 21572 |
+# include "common/debug.h" |
| 21573 |
+ |
| 21574 |
+# import <dispatch/dispatch.h> |
| 21575 |
+# import <dlfcn.h> |
| 21576 |
+# import <objc/runtime.h> |
| 21577 |
+ |
| 21578 |
+# define RELEASE_ASSERT(expression, message) \ |
| 21579 |
+ (expression \ |
| 21580 |
+ ? static_cast<void>(0) \ |
| 21581 |
+ : (FATAL() << "\t! Assert failed in " << __FUNCTION__ << " (" << __FILE__ << ":" \ |
| 21582 |
+ << __LINE__ << "): " << #expression << "\n\t! Message: " << message)) |
| 21583 |
+ |
| 21584 |
+# ifdef __cplusplus |
| 21585 |
+# define EXTERN_C_BEGIN extern "C" { |
| 21586 |
+# define EXTERN_C_END } |
| 21587 |
+# else |
| 21588 |
+# define EXTERN_C_BEGIN |
| 21589 |
+# define EXTERN_C_END |
| 21590 |
+# endif |
| 21591 |
+ |
| 21592 |
+# define SOFT_LINK_FRAMEWORK_HEADER(framework) extern void *framework##Library(); |
| 21593 |
+ |
| 21594 |
+# define SOFT_LINK_FRAMEWORK_SOURCE(framework) \ |
| 21595 |
+ void *framework##Library() \ |
| 21596 |
+ { \ |
| 21597 |
+ static dispatch_once_t once = 0; \ |
| 21598 |
+ static void *frameworkLibrary = NULL; \ |
| 21599 |
+ dispatch_once(&once, ^{ \ |
| 21600 |
+ frameworkLibrary = dlopen( \ |
| 21601 |
+ "/System/Library/Frameworks/" #framework ".framework/" #framework, RTLD_NOW); \ |
| 21602 |
+ RELEASE_ASSERT(frameworkLibrary, "Unable to load " #framework ".framework"); \ |
| 21603 |
+ }); \ |
| 21604 |
+ return frameworkLibrary; \ |
| 21605 |
+ } |
| 21606 |
+ |
| 21607 |
+# define SOFT_LINK_FUNCTION_HEADER(framework, functionName, resultType, parameterDeclarations, \ |
| 21608 |
+ parameterNames) \ |
| 21609 |
+ EXTERN_C_BEGIN \ |
| 21610 |
+ resultType functionName parameterDeclarations; \ |
| 21611 |
+ EXTERN_C_END \ |
| 21612 |
+ extern resultType init##framework##functionName parameterDeclarations; \ |
| 21613 |
+ extern resultType(*softLink##framework##functionName) parameterDeclarations; \ |
| 21614 |
+ inline __attribute__((__always_inline__)) resultType functionName parameterDeclarations \ |
| 21615 |
+ { \ |
| 21616 |
+ return softLink##framework##functionName parameterNames; \ |
| 21617 |
+ } |
| 21618 |
+ |
| 21619 |
+# define SOFT_LINK_FUNCTION_SOURCE(framework, functionName, resultType, parameterDeclarations, \ |
| 21620 |
+ parameterNames) \ |
| 21621 |
+ resultType(*softLink##framework##functionName) parameterDeclarations = \ |
| 21622 |
+ init##framework##functionName; \ |
| 21623 |
+ resultType init##framework##functionName parameterDeclarations \ |
| 21624 |
+ { \ |
| 21625 |
+ static dispatch_once_t once; \ |
| 21626 |
+ dispatch_once(&once, ^{ \ |
| 21627 |
+ softLink##framework##functionName = \ |
| 21628 |
+ (resultType(*) parameterDeclarations)dlsym(framework##Library(), #functionName); \ |
| 21629 |
+ }); \ |
| 21630 |
+ return softLink##framework##functionName parameterNames; \ |
| 21631 |
+ } |
| 21632 |
+ |
| 21633 |
+# define SOFT_LINK_CLASS_HEADER(className) \ |
| 21634 |
+ @class className; \ |
| 21635 |
+ extern Class (*get##className##Class)(); \ |
| 21636 |
+ className *alloc##className##Instance(); \ |
| 21637 |
+ inline className *alloc##className##Instance() { return [get##className##Class() alloc]; } |
| 21638 |
+ |
| 21639 |
+# define SOFT_LINK_CLASS(framework, className) \ |
| 21640 |
+ @class className; \ |
| 21641 |
+ static Class init##className(); \ |
| 21642 |
+ Class (*get##className##Class)() = init##className; \ |
| 21643 |
+ static Class class##className; \ |
| 21644 |
+ \ |
| 21645 |
+ static Class className##Function() { return class##className; } \ |
| 21646 |
+ \ |
| 21647 |
+ static Class init##className() \ |
| 21648 |
+ { \ |
| 21649 |
+ static dispatch_once_t once; \ |
| 21650 |
+ dispatch_once(&once, ^{ \ |
| 21651 |
+ framework##Library(); \ |
| 21652 |
+ class##className = objc_getClass(#className); \ |
| 21653 |
+ RELEASE_ASSERT(class##className, "objc_getClass failed for " #className); \ |
| 21654 |
+ get##className##Class = className##Function; \ |
| 21655 |
+ }); \ |
| 21656 |
+ return class##className; \ |
| 21657 |
+ } \ |
| 21658 |
+ _Pragma("clang diagnostic push") \ |
| 21659 |
+ _Pragma("clang diagnostic ignored \"-Wunused-function\"") static className \ |
| 21660 |
+ *alloc##className##Instance() \ |
| 21661 |
+ { \ |
| 21662 |
+ return [get##className##Class() alloc]; \ |
| 21663 |
+ } \ |
| 21664 |
+ _Pragma("clang diagnostic pop") |
| 21665 |
+ |
| 21666 |
+#endif // defined(ANGLE_PLATFORM_APPLE) |
| 21667 |
+ |
| 21668 |
+#endif // SOFT_LINKING_APPLE_H_ |
| 21669 |
diff --git a/src/libANGLE/renderer/gl/apple/DisplayApple_api.cpp b/src/libANGLE/renderer/gl/apple/DisplayApple_api.cpp |
| 21670 |
index de216fb..55dcd90 100644 |
| 21671 |
--- a/src/libANGLE/renderer/gl/apple/DisplayApple_api.cpp |
| 21672 |
+++ b/src/libANGLE/renderer/gl/apple/DisplayApple_api.cpp |
| 21673 |
@@ -10,6 +10,7 @@ |
| 21674 |
#ifndef LIBANGLE_RENDERER_GL_APPLE_DISPLAYAPPLE_API_H_ |
| 21675 |
#define LIBANGLE_RENDERER_GL_APPLE_DISPLAYAPPLE_API_H_ |
| 21676 |
|
| 21677 |
+#include "gpu_info_util/SystemInfo.h" |
| 21678 |
#include "libANGLE/renderer/DisplayImpl.h" |
| 21679 |
|
| 21680 |
#if defined(ANGLE_PLATFORM_MACOS) || defined(ANGLE_PLATFORM_MACCATALYST) |
| 21681 |
@@ -33,11 +34,10 @@ DisplayImpl *CreateDisplayCGLOrEAGL(const egl::DisplayState &state) |
| 21682 |
angle::SystemInfo info; |
| 21683 |
if (!angle::GetSystemInfo(&info)) |
| 21684 |
{ |
| 21685 |
- impl = nullptr; |
| 21686 |
- break; |
| 21687 |
+ return nullptr; |
| 21688 |
} |
| 21689 |
|
| 21690 |
- if (info.isiOSAppOnMac) |
| 21691 |
+ if (info.needsEAGLOnMac) |
| 21692 |
{ |
| 21693 |
return new rx::DisplayEAGL(state); |
| 21694 |
} |
| 21695 |
diff --git a/src/libANGLE/renderer/gl/cgl/CGLFunctions.cpp b/src/libANGLE/renderer/gl/cgl/CGLFunctions.cpp |
| 21696 |
new file mode 100644 |
| 21697 |
index 0000000..e95c0f6 |
| 21698 |
--- /dev/null |
| 21699 |
+++ b/src/libANGLE/renderer/gl/cgl/CGLFunctions.cpp |
| 21700 |
@@ -0,0 +1,77 @@ |
| 21701 |
+// |
| 21702 |
+// Copyright 2020 Apple, Inc. All rights reserved. |
| 21703 |
+// Use of this source code is governed by a BSD-style license that can be |
| 21704 |
+// found in the LICENSE file. |
| 21705 |
+// |
| 21706 |
+ |
| 21707 |
+// CGLFunctions.cpp: Exposing the soft-linked CGL interface. |
| 21708 |
+ |
| 21709 |
+#include "libANGLE/renderer/gl/cgl/CGLFunctions.h" |
| 21710 |
+#include "common/platform.h" |
| 21711 |
+ |
| 21712 |
+#if defined(ANGLE_PLATFORM_MACOS) || defined(ANGLE_PLATFORM_MACCATALYST) |
| 21713 |
+ |
| 21714 |
+SOFT_LINK_FRAMEWORK_SOURCE(OpenGL) |
| 21715 |
+ |
| 21716 |
+SOFT_LINK_FUNCTION_SOURCE(OpenGL, |
| 21717 |
+ CGLChoosePixelFormat, |
| 21718 |
+ CGLError, |
| 21719 |
+ (const CGLPixelFormatAttribute *attribs, |
| 21720 |
+ CGLPixelFormatObj *pix, |
| 21721 |
+ GLint *npix), |
| 21722 |
+ (attribs, pix, npix)) |
| 21723 |
+SOFT_LINK_FUNCTION_SOURCE(OpenGL, |
| 21724 |
+ CGLCreateContext, |
| 21725 |
+ CGLError, |
| 21726 |
+ (CGLPixelFormatObj pix, CGLContextObj share, CGLContextObj *ctx), |
| 21727 |
+ (pix, share, ctx)) |
| 21728 |
+SOFT_LINK_FUNCTION_SOURCE( |
| 21729 |
+ OpenGL, |
| 21730 |
+ CGLDescribePixelFormat, |
| 21731 |
+ CGLError, |
| 21732 |
+ (CGLPixelFormatObj pix, GLint pix_num, CGLPixelFormatAttribute attrib, GLint *value), |
| 21733 |
+ (pix, pix_num, attrib, value)) |
| 21734 |
+SOFT_LINK_FUNCTION_SOURCE(OpenGL, CGLDestroyContext, CGLError, (CGLContextObj ctx), (ctx)) |
| 21735 |
+SOFT_LINK_FUNCTION_SOURCE(OpenGL, CGLDestroyPixelFormat, CGLError, (CGLPixelFormatObj pix), (pix)) |
| 21736 |
+SOFT_LINK_FUNCTION_SOURCE(OpenGL, CGLErrorString, const char *, (CGLError error), (error)) |
| 21737 |
+SOFT_LINK_FUNCTION_SOURCE(OpenGL, CGLReleaseContext, void, (CGLContextObj ctx), (ctx)) |
| 21738 |
+SOFT_LINK_FUNCTION_SOURCE(OpenGL, CGLSetCurrentContext, CGLError, (CGLContextObj ctx), (ctx)) |
| 21739 |
+SOFT_LINK_FUNCTION_SOURCE(OpenGL, |
| 21740 |
+ CGLSetVirtualScreen, |
| 21741 |
+ CGLError, |
| 21742 |
+ (CGLContextObj ctx, GLint screen), |
| 21743 |
+ (ctx, screen)) |
| 21744 |
+SOFT_LINK_FUNCTION_SOURCE( |
| 21745 |
+ OpenGL, |
| 21746 |
+ CGLTexImageIOSurface2D, |
| 21747 |
+ CGLError, |
| 21748 |
+ (CGLContextObj ctx, |
| 21749 |
+ GLenum target, |
| 21750 |
+ GLenum internal_format, |
| 21751 |
+ GLsizei width, |
| 21752 |
+ GLsizei height, |
| 21753 |
+ GLenum format, |
| 21754 |
+ GLenum type, |
| 21755 |
+ IOSurfaceRef ioSurface, |
| 21756 |
+ GLuint plane), |
| 21757 |
+ (ctx, target, internal_format, width, height, format, type, ioSurface, plane)) |
| 21758 |
+SOFT_LINK_FUNCTION_SOURCE(OpenGL, CGLUpdateContext, CGLError, (CGLContextObj ctx), (ctx)) |
| 21759 |
+ |
| 21760 |
+SOFT_LINK_FUNCTION_SOURCE( |
| 21761 |
+ OpenGL, |
| 21762 |
+ CGLDescribeRenderer, |
| 21763 |
+ CGLError, |
| 21764 |
+ (CGLRendererInfoObj rend, GLint rend_num, CGLRendererProperty prop, GLint *value), |
| 21765 |
+ (rend, rend_num, prop, value)) |
| 21766 |
+SOFT_LINK_FUNCTION_SOURCE(OpenGL, |
| 21767 |
+ CGLDestroyRendererInfo, |
| 21768 |
+ CGLError, |
| 21769 |
+ (CGLRendererInfoObj rend), |
| 21770 |
+ (rend)) |
| 21771 |
+SOFT_LINK_FUNCTION_SOURCE(OpenGL, |
| 21772 |
+ CGLQueryRendererInfo, |
| 21773 |
+ CGLError, |
| 21774 |
+ (GLuint display_mask, CGLRendererInfoObj *rend, GLint *nrend), |
| 21775 |
+ (display_mask, rend, nrend)) |
| 21776 |
+ |
| 21777 |
+#endif // defined(ANGLE_PLATFORM_MACOS) || defined(ANGLE_PLATFORM_MACCATALYST) |
| 21778 |
diff --git a/src/libANGLE/renderer/gl/cgl/CGLFunctions.h b/src/libANGLE/renderer/gl/cgl/CGLFunctions.h |
| 21779 |
new file mode 100644 |
| 21780 |
index 0000000..a6b871e |
| 21781 |
--- /dev/null |
| 21782 |
+++ b/src/libANGLE/renderer/gl/cgl/CGLFunctions.h |
| 21783 |
@@ -0,0 +1,84 @@ |
| 21784 |
+// |
| 21785 |
+// Copyright 2020 Apple, Inc. All rights reserved. |
| 21786 |
+// Use of this source code is governed by a BSD-style license that can be |
| 21787 |
+// found in the LICENSE file. |
| 21788 |
+// |
| 21789 |
+ |
| 21790 |
+// CGLFunctions.h: Exposing the soft-linked CGL interface. |
| 21791 |
+ |
| 21792 |
+#ifndef CGL_FUNCTIONS_H_ |
| 21793 |
+#define CGL_FUNCTIONS_H_ |
| 21794 |
+ |
| 21795 |
+#include "common/platform.h" |
| 21796 |
+ |
| 21797 |
+#if defined(ANGLE_PLATFORM_MACOS) || defined(ANGLE_PLATFORM_MACCATALYST) |
| 21798 |
+ |
| 21799 |
+# include <OpenGL/OpenGL.h> |
| 21800 |
+ |
| 21801 |
+# include "libANGLE/renderer/gl/SoftLinking_apple.h" |
| 21802 |
+ |
| 21803 |
+SOFT_LINK_FRAMEWORK_HEADER(OpenGL) |
| 21804 |
+ |
| 21805 |
+SOFT_LINK_FUNCTION_HEADER(OpenGL, |
| 21806 |
+ CGLChoosePixelFormat, |
| 21807 |
+ CGLError, |
| 21808 |
+ (const CGLPixelFormatAttribute *attribs, |
| 21809 |
+ CGLPixelFormatObj *pix, |
| 21810 |
+ GLint *npix), |
| 21811 |
+ (attribs, pix, npix)) |
| 21812 |
+SOFT_LINK_FUNCTION_HEADER(OpenGL, |
| 21813 |
+ CGLCreateContext, |
| 21814 |
+ CGLError, |
| 21815 |
+ (CGLPixelFormatObj pix, CGLContextObj share, CGLContextObj *ctx), |
| 21816 |
+ (pix, share, ctx)) |
| 21817 |
+SOFT_LINK_FUNCTION_HEADER( |
| 21818 |
+ OpenGL, |
| 21819 |
+ CGLDescribePixelFormat, |
| 21820 |
+ CGLError, |
| 21821 |
+ (CGLPixelFormatObj pix, GLint pix_num, CGLPixelFormatAttribute attrib, GLint *value), |
| 21822 |
+ (pix, pix_num, attrib, value)) |
| 21823 |
+SOFT_LINK_FUNCTION_HEADER( |
| 21824 |
+ OpenGL, |
| 21825 |
+ CGLDescribeRenderer, |
| 21826 |
+ CGLError, |
| 21827 |
+ (CGLRendererInfoObj rend, GLint rend_num, CGLRendererProperty prop, GLint *value), |
| 21828 |
+ (rend, rend_num, prop, value)) |
| 21829 |
+SOFT_LINK_FUNCTION_HEADER(OpenGL, CGLDestroyContext, CGLError, (CGLContextObj ctx), (ctx)) |
| 21830 |
+SOFT_LINK_FUNCTION_HEADER(OpenGL, CGLDestroyPixelFormat, CGLError, (CGLPixelFormatObj pix), (pix)) |
| 21831 |
+SOFT_LINK_FUNCTION_HEADER(OpenGL, |
| 21832 |
+ CGLDestroyRendererInfo, |
| 21833 |
+ CGLError, |
| 21834 |
+ (CGLRendererInfoObj rend), |
| 21835 |
+ (rend)) |
| 21836 |
+SOFT_LINK_FUNCTION_HEADER(OpenGL, CGLErrorString, const char *, (CGLError error), (error)) |
| 21837 |
+SOFT_LINK_FUNCTION_HEADER(OpenGL, |
| 21838 |
+ CGLQueryRendererInfo, |
| 21839 |
+ CGLError, |
| 21840 |
+ (GLuint display_mask, CGLRendererInfoObj *rend, GLint *nrend), |
| 21841 |
+ (display_mask, rend, nrend)) |
| 21842 |
+SOFT_LINK_FUNCTION_HEADER(OpenGL, CGLReleaseContext, void, (CGLContextObj ctx), (ctx)) |
| 21843 |
+SOFT_LINK_FUNCTION_HEADER(OpenGL, CGLSetCurrentContext, CGLError, (CGLContextObj ctx), (ctx)) |
| 21844 |
+SOFT_LINK_FUNCTION_HEADER(OpenGL, |
| 21845 |
+ CGLSetVirtualScreen, |
| 21846 |
+ CGLError, |
| 21847 |
+ (CGLContextObj ctx, GLint screen), |
| 21848 |
+ (ctx, screen)) |
| 21849 |
+SOFT_LINK_FUNCTION_HEADER( |
| 21850 |
+ OpenGL, |
| 21851 |
+ CGLTexImageIOSurface2D, |
| 21852 |
+ CGLError, |
| 21853 |
+ (CGLContextObj ctx, |
| 21854 |
+ GLenum target, |
| 21855 |
+ GLenum internal_format, |
| 21856 |
+ GLsizei width, |
| 21857 |
+ GLsizei height, |
| 21858 |
+ GLenum format, |
| 21859 |
+ GLenum type, |
| 21860 |
+ IOSurfaceRef ioSurface, |
| 21861 |
+ GLuint plane), |
| 21862 |
+ (ctx, target, internal_format, width, height, format, type, ioSurface, plane)) |
| 21863 |
+SOFT_LINK_FUNCTION_HEADER(OpenGL, CGLUpdateContext, CGLError, (CGLContextObj ctx), (ctx)) |
| 21864 |
+ |
| 21865 |
+#endif // defined(ANGLE_PLATFORM_MACOS) || defined(ANGLE_PLATFORM_MACCATALYST) |
| 21866 |
+ |
| 21867 |
+#endif // CGL_FUNCTIONS_H_ |
| 21868 |
diff --git a/src/libANGLE/renderer/gl/cgl/ContextCGL.cpp b/src/libANGLE/renderer/gl/cgl/ContextCGL.cpp |
| 21869 |
index bdf5597..be99b85 100644 |
| 21870 |
--- a/src/libANGLE/renderer/gl/cgl/ContextCGL.cpp |
| 21871 |
+++ b/src/libANGLE/renderer/gl/cgl/ContextCGL.cpp |
| 21872 |
@@ -13,6 +13,8 @@ |
| 21873 |
#include "libANGLE/Display.h" |
| 21874 |
#include "libANGLE/renderer/gl/cgl/DisplayCGL.h" |
| 21875 |
|
| 21876 |
+#if defined(ANGLE_PLATFORM_MACOS) || defined(ANGLE_PLATFORM_MACCATALYST) |
| 21877 |
+ |
| 21878 |
namespace rx |
| 21879 |
{ |
| 21880 |
|
| 21881 |
@@ -63,3 +65,5 @@ void ContextCGL::onDestroy(const gl::Context *context) |
| 21882 |
} |
| 21883 |
|
| 21884 |
} // namespace rx |
| 21885 |
+ |
| 21886 |
+#endif // defined(ANGLE_PLATFORM_MACOS) || defined(ANGLE_PLATFORM_MACCATALYST) |
| 21887 |
\ No newline at end of file |
| 21888 |
diff --git a/src/libANGLE/renderer/gl/cgl/DisplayCGL.mm b/src/libANGLE/renderer/gl/cgl/DisplayCGL.mm |
| 21889 |
index b5a631a..90e8058 100644 |
| 21890 |
--- a/src/libANGLE/renderer/gl/cgl/DisplayCGL.mm |
| 21891 |
+++ b/src/libANGLE/renderer/gl/cgl/DisplayCGL.mm |
| 21892 |
@@ -29,6 +29,8 @@ |
| 21893 |
# include "libANGLE/renderer/gl/cgl/WindowSurfaceCGL.h" |
| 21894 |
# include "platform/PlatformMethods.h" |
| 21895 |
|
| 21896 |
+# include "libANGLE/renderer/gl/cgl/CGLFunctions.h" |
| 21897 |
+ |
| 21898 |
namespace |
| 21899 |
{ |
| 21900 |
|
| 21901 |
@@ -163,9 +165,10 @@ static void SetGPUByRegistryID(CGLContextObj contextObj, |
| 21902 |
mEGLDisplay = display; |
| 21903 |
|
| 21904 |
angle::SystemInfo info; |
| 21905 |
- // It's legal for GetSystemInfo to return false and thereby |
| 21906 |
- // contain incomplete information. |
| 21907 |
- (void)angle::GetSystemInfo(&info); |
| 21908 |
+ if (!angle::GetSystemInfo(&info)) |
| 21909 |
+ { |
| 21910 |
+ return egl::EglNotInitialized() << "Unable to query ANGLE's SystemInfo."; |
| 21911 |
+ } |
| 21912 |
|
| 21913 |
// This code implements the effect of the |
| 21914 |
// disableGPUSwitchingSupport workaround in FeaturesGL. |
| 21915 |
@@ -440,7 +443,7 @@ static void SetGPUByRegistryID(CGLContextObj contextObj, |
| 21916 |
|
| 21917 |
bool DisplayCGL::isValidNativeWindow(EGLNativeWindowType window) const |
| 21918 |
{ |
| 21919 |
- NSObject *layer = (__bridge NSObject *)window; |
| 21920 |
+ NSObject *layer = reinterpret_cast<NSObject *>(window); |
| 21921 |
return [layer isKindOfClass:[CALayer class]]; |
| 21922 |
} |
| 21923 |
|
| 21924 |
diff --git a/src/libANGLE/renderer/gl/eagl/DisplayEAGL.mm b/src/libANGLE/renderer/gl/eagl/DisplayEAGL.mm |
| 21925 |
index a795037..c55ae7f 100644 |
| 21926 |
--- a/src/libANGLE/renderer/gl/eagl/DisplayEAGL.mm |
| 21927 |
+++ b/src/libANGLE/renderer/gl/eagl/DisplayEAGL.mm |
| 21928 |
@@ -27,6 +27,8 @@ |
| 21929 |
# import <QuartzCore/QuartzCore.h> |
| 21930 |
# import <dlfcn.h> |
| 21931 |
|
| 21932 |
+# import "libANGLE/renderer/gl/eagl/EAGLFunctions.h" |
| 21933 |
+ |
| 21934 |
namespace |
| 21935 |
{ |
| 21936 |
|
| 21937 |
@@ -64,9 +66,10 @@ |
| 21938 |
mEGLDisplay = display; |
| 21939 |
|
| 21940 |
angle::SystemInfo info; |
| 21941 |
- // It's legal for GetSystemInfo to return false and thereby |
| 21942 |
- // contain incomplete information. |
| 21943 |
- (void)angle::GetSystemInfo(&info); |
| 21944 |
+ if (!angle::GetSystemInfo(&info)) |
| 21945 |
+ { |
| 21946 |
+ return egl::EglNotInitialized() << "Unable to query ANGLE's SystemInfo."; |
| 21947 |
+ } |
| 21948 |
|
| 21949 |
mContext = [allocEAGLContextInstance() initWithAPI:kEAGLRenderingAPIOpenGLES3]; |
| 21950 |
if (mContext == nullptr) |
| 21951 |
@@ -113,6 +116,7 @@ |
| 21952 |
if (mContext != nullptr) |
| 21953 |
{ |
| 21954 |
[getEAGLContextClass() setCurrentContext:nil]; |
| 21955 |
+ [mContext release]; |
| 21956 |
mContext = nullptr; |
| 21957 |
mThreadsWithContextCurrent.clear(); |
| 21958 |
} |
| 21959 |
@@ -275,7 +279,7 @@ |
| 21960 |
|
| 21961 |
bool DisplayEAGL::isValidNativeWindow(EGLNativeWindowType window) const |
| 21962 |
{ |
| 21963 |
- NSObject *layer = (__bridge NSObject *)window; |
| 21964 |
+ NSObject *layer = reinterpret_cast<NSObject *>(window); |
| 21965 |
return [layer isKindOfClass:[CALayer class]]; |
| 21966 |
} |
| 21967 |
|
| 21968 |
@@ -311,9 +315,8 @@ |
| 21969 |
outExtensions->surfacelessContext = true; |
| 21970 |
outExtensions->deviceQuery = true; |
| 21971 |
|
| 21972 |
- // Contexts are virtualized so textures ans semaphores can be shared globally |
| 21973 |
+ // Contexts are virtualized so textures can be shared globally |
| 21974 |
outExtensions->displayTextureShareGroup = true; |
| 21975 |
- outExtensions->displaySemaphoreShareGroup = true; |
| 21976 |
|
| 21977 |
outExtensions->powerPreference = false; |
| 21978 |
|
| 21979 |
diff --git a/src/libANGLE/renderer/gl/eagl/EAGLFunctions.h b/src/libANGLE/renderer/gl/eagl/EAGLFunctions.h |
| 21980 |
new file mode 100644 |
| 21981 |
index 0000000..9212513 |
| 21982 |
--- /dev/null |
| 21983 |
+++ b/src/libANGLE/renderer/gl/eagl/EAGLFunctions.h |
| 21984 |
@@ -0,0 +1,30 @@ |
| 21985 |
+// |
| 21986 |
+// Copyright 2020 Apple, Inc. All rights reserved. |
| 21987 |
+// Use of this source code is governed by a BSD-style license that can be |
| 21988 |
+// found in the LICENSE file. |
| 21989 |
+// |
| 21990 |
+ |
| 21991 |
+// EAGLFunctions.h: Exposing the soft-linked EAGL interface. |
| 21992 |
+ |
| 21993 |
+#ifndef EAGL_FUNCTIONS_H_ |
| 21994 |
+#define EAGL_FUNCTIONS_H_ |
| 21995 |
+ |
| 21996 |
+#include "common/platform.h" |
| 21997 |
+ |
| 21998 |
+#if (defined(ANGLE_PLATFORM_IOS) && !defined(ANGLE_PLATFORM_MACCATALYST)) || \ |
| 21999 |
+ (defined(ANGLE_PLATFORM_MACCATALYST) && defined(ANGLE_CPU_ARM64)) |
| 22000 |
+ |
| 22001 |
+# import <OpenGLES/EAGL.h> |
| 22002 |
+# import <OpenGLES/EAGLDrawable.h> |
| 22003 |
+# import <OpenGLES/EAGLIOSurface.h> |
| 22004 |
+ |
| 22005 |
+# include "libANGLE/renderer/gl/SoftLinking_apple.h" |
| 22006 |
+ |
| 22007 |
+SOFT_LINK_FRAMEWORK_HEADER(OpenGLES) |
| 22008 |
+ |
| 22009 |
+SOFT_LINK_CLASS_HEADER(EAGLContext) |
| 22010 |
+ |
| 22011 |
+#endif // (defined(ANGLE_PLATFORM_IOS) && !defined(ANGLE_PLATFORM_MACCATALYST)) || |
| 22012 |
+ // (defined(ANGLE_PLATFORM_MACCATALYST) && defined(ANGLE_CPU_ARM64)) |
| 22013 |
+ |
| 22014 |
+#endif // CGL_FUNCTIONS_H_ |
| 22015 |
diff --git a/src/libANGLE/renderer/gl/eagl/EAGLFunctions.mm b/src/libANGLE/renderer/gl/eagl/EAGLFunctions.mm |
| 22016 |
new file mode 100644 |
| 22017 |
index 0000000..0b1eb70 |
| 22018 |
--- /dev/null |
| 22019 |
+++ b/src/libANGLE/renderer/gl/eagl/EAGLFunctions.mm |
| 22020 |
@@ -0,0 +1,25 @@ |
| 22021 |
+// |
| 22022 |
+// Copyright 2020 Apple, Inc. All rights reserved. |
| 22023 |
+// Use of this source code is governed by a BSD-style license that can be |
| 22024 |
+// found in the LICENSE file. |
| 22025 |
+// |
| 22026 |
+ |
| 22027 |
+// EAGLFunctions.cpp: Exposing the soft-linked EAGL interface. |
| 22028 |
+ |
| 22029 |
+#include "common/platform.h" |
| 22030 |
+ |
| 22031 |
+#if (defined(ANGLE_PLATFORM_IOS) && !defined(ANGLE_PLATFORM_MACCATALYST)) || \ |
| 22032 |
+ (defined(ANGLE_PLATFORM_MACCATALYST) && defined(ANGLE_CPU_ARM64)) |
| 22033 |
+ |
| 22034 |
+# import <OpenGLES/EAGL.h> |
| 22035 |
+# import <OpenGLES/EAGLDrawable.h> |
| 22036 |
+# import <OpenGLES/EAGLIOSurface.h> |
| 22037 |
+ |
| 22038 |
+# include "libANGLE/renderer/gl/SoftLinking_apple.h" |
| 22039 |
+ |
| 22040 |
+SOFT_LINK_FRAMEWORK_SOURCE(OpenGLES) |
| 22041 |
+ |
| 22042 |
+SOFT_LINK_CLASS(OpenGLES, EAGLContext) |
| 22043 |
+ |
| 22044 |
+#endif // (defined(ANGLE_PLATFORM_IOS) && !defined(ANGLE_PLATFORM_MACCATALYST)) || |
| 22045 |
+ // (defined(ANGLE_PLATFORM_MACCATALYST) && defined(ANGLE_CPU_ARM64)) |
| 22046 |
\ No newline at end of file |
| 297 |
diff --git a/src/libANGLE/renderer/gl/eagl/FunctionsEAGL.h b/src/libANGLE/renderer/gl/eagl/FunctionsEAGL.h |
22047 |
diff --git a/src/libANGLE/renderer/gl/eagl/FunctionsEAGL.h b/src/libANGLE/renderer/gl/eagl/FunctionsEAGL.h |
| 298 |
index ece235a..ae0207b 100644 |
22048 |
index ece235a..ae0207b 100644 |
| 299 |
--- a/src/libANGLE/renderer/gl/eagl/FunctionsEAGL.h |
22049 |
--- a/src/libANGLE/renderer/gl/eagl/FunctionsEAGL.h |
|
Lines 302-361
index ece235a..ae0207b 100644
a/Source/ThirdParty/ANGLE/changes.diff_sec4
|
| 302 |
# import <OpenGLES/EAGLDrawable.h> |
22052 |
# import <OpenGLES/EAGLDrawable.h> |
| 303 |
# import <OpenGLES/EAGLIOSurface.h> |
22053 |
# import <OpenGLES/EAGLIOSurface.h> |
| 304 |
|
22054 |
|
| 305 |
-# include "libANGLE/renderer/gl/apple/SoftLinking.h" |
22055 |
-# include "libANGLE/renderer/gl/apple/SoftLinking.h" |
| 306 |
+# include "common/apple/SoftLinking.h" |
22056 |
+# include "common/apple/SoftLinking.h" |
|
|
22057 |
|
| 22058 |
SOFT_LINK_FRAMEWORK_HEADER(OpenGLES) |
| 22059 |
|
| 22060 |
diff --git a/src/libANGLE/renderer/gl/eagl/FunctionsEAGL.mm b/src/libANGLE/renderer/gl/eagl/FunctionsEAGL.mm |
| 22061 |
index 7779792..076d072 100644 |
| 22062 |
--- a/src/libANGLE/renderer/gl/eagl/FunctionsEAGL.mm |
| 22063 |
+++ b/src/libANGLE/renderer/gl/eagl/FunctionsEAGL.mm |
| 22064 |
@@ -14,7 +14,7 @@ |
| 22065 |
# import <OpenGLES/EAGLDrawable.h> |
| 22066 |
# import <OpenGLES/EAGLIOSurface.h> |
| 22067 |
|
| 22068 |
-# include "libANGLE/renderer/gl/apple/SoftLinking.h" |
| 22069 |
+# include "common/apple/SoftLinking.h" |
| 22070 |
|
| 22071 |
SOFT_LINK_FRAMEWORK_SOURCE(OpenGLES) |
| 22072 |
|
| 22073 |
diff --git a/src/libANGLE/renderer/gl/eagl/IOSurfaceSurfaceEAGL.mm b/src/libANGLE/renderer/gl/eagl/IOSurfaceSurfaceEAGL.mm |
| 22074 |
index f16c3e7..e309a86 100644 |
| 22075 |
--- a/src/libANGLE/renderer/gl/eagl/IOSurfaceSurfaceEAGL.mm |
| 22076 |
+++ b/src/libANGLE/renderer/gl/eagl/IOSurfaceSurfaceEAGL.mm |
| 22077 |
@@ -83,8 +83,8 @@ int FindIOSurfaceFormatIndex(GLenum internalFormat, GLenum type) |
| 22078 |
mWidth(0), |
| 22079 |
mHeight(0), |
| 22080 |
mPlane(0), |
| 22081 |
- mRowStrideInPixels(0), |
| 22082 |
mFormatIndex(-1), |
| 22083 |
+ mRowStrideInPixels(0), |
| 22084 |
mAlphaInitialized(false) |
| 22085 |
{ |
| 22086 |
// Keep reference to the IOSurface so it doesn't get deleted while the pbuffer exists. |
| 22087 |
diff --git a/src/libANGLE/renderer/gl/renderergl_utils.cpp b/src/libANGLE/renderer/gl/renderergl_utils.cpp |
| 22088 |
index 99772c4..11f47e6 100644 |
| 22089 |
--- a/src/libANGLE/renderer/gl/renderergl_utils.cpp |
| 22090 |
+++ b/src/libANGLE/renderer/gl/renderergl_utils.cpp |
| 22091 |
@@ -1358,7 +1358,7 @@ void GenerateCaps(const FunctionsGL *functions, |
| 22092 |
|
| 22093 |
#if defined(ANGLE_PLATFORM_MACOS) || defined(ANGLE_PLATFORM_MACCATALYST) |
| 22094 |
angle::SystemInfo info; |
| 22095 |
- if (angle::GetSystemInfo(&info) && !info.isiOSAppOnMac) |
| 22096 |
+ if (angle::GetSystemInfo(&info) && !info.needsEAGLOnMac) |
| 22097 |
{ |
| 22098 |
VendorID vendor = GetVendorID(functions); |
| 22099 |
if ((IsAMD(vendor) || IsIntel(vendor)) && *maxSupportedESVersion >= gl::Version(3, 0)) |
| 22100 |
diff --git a/src/libANGLE/renderer/glslang_wrapper_utils.cpp b/src/libANGLE/renderer/glslang_wrapper_utils.cpp |
| 22101 |
index d70ae58..615dd44 100644 |
| 22102 |
--- a/src/libANGLE/renderer/glslang_wrapper_utils.cpp |
| 22103 |
+++ b/src/libANGLE/renderer/glslang_wrapper_utils.cpp |
| 22104 |
@@ -281,9 +281,11 @@ std::string SubstituteTransformFeedbackMarkers(const std::string &originalSource |
| 22105 |
const std::string &xfbOut) |
| 22106 |
{ |
| 22107 |
const size_t xfbDeclMarkerStart = originalSource.find(kXfbDeclMarker); |
| 22108 |
+ ASSERT(xfbDeclMarkerStart != std::string::npos); |
| 22109 |
const size_t xfbDeclMarkerEnd = xfbDeclMarkerStart + ConstStrLen(kXfbDeclMarker); |
| 22110 |
|
| 22111 |
const size_t xfbOutMarkerStart = originalSource.find(kXfbOutMarker, xfbDeclMarkerStart); |
| 22112 |
+ ASSERT(xfbOutMarkerStart != std::string::npos); |
| 22113 |
const size_t xfbOutMarkerEnd = xfbOutMarkerStart + ConstStrLen(kXfbOutMarker); |
| 22114 |
|
| 22115 |
// The shader is the following form: |
| 22116 |
@@ -362,7 +364,8 @@ void GenerateTransformFeedbackEmulationOutputs(const GlslangSourceOptions &optio |
| 22117 |
const gl::ProgramState &programState, |
| 22118 |
GlslangProgramInterfaceInfo *programInterfaceInfo, |
| 22119 |
std::string *vertexShader, |
| 22120 |
- ShaderInterfaceVariableInfoMap *variableInfoMapOut) |
| 22121 |
+ ShaderInterfaceVariableInfoMap *variableInfoMapOut, |
| 22122 |
+ bool earlyReturn) |
| 22123 |
{ |
| 22124 |
const std::vector<gl::TransformFeedbackVarying> &varyings = |
| 22125 |
programState.getLinkedTransformFeedbackVaryings(); |
| 22126 |
@@ -413,6 +416,10 @@ void GenerateTransformFeedbackEmulationOutputs(const GlslangSourceOptions &optio |
| 22127 |
outputOffset += info.columnCount * info.rowCount * varying.size(); |
| 22128 |
} |
| 22129 |
} |
| 22130 |
+ if (earlyReturn) |
| 22131 |
+ { |
| 22132 |
+ xfbOut += "return;"; |
| 22133 |
+ } |
| 22134 |
xfbOut += "}\n"; |
| 22135 |
|
| 22136 |
*vertexShader = SubstituteTransformFeedbackMarkers(*vertexShader, xfbDecl, xfbOut); |
| 22137 |
@@ -3368,11 +3375,6 @@ std::string GlslangGetMappedSamplerName(const std::string &originalName) |
| 22138 |
return samplerName; |
| 22139 |
} |
| 22140 |
|
| 22141 |
-std::string GetXfbBufferName(const uint32_t bufferIndex) |
| 22142 |
-{ |
| 22143 |
- return "xfbBuffer" + Str(bufferIndex); |
| 22144 |
-} |
| 22145 |
- |
| 22146 |
void GlslangGenTransformFeedbackEmulationOutputs(const GlslangSourceOptions &options, |
| 22147 |
const gl::ProgramState &programState, |
| 22148 |
GlslangProgramInterfaceInfo *programInterfaceInfo, |
| 22149 |
@@ -3380,7 +3382,7 @@ void GlslangGenTransformFeedbackEmulationOutputs(const GlslangSourceOptions &opt |
| 22150 |
ShaderInterfaceVariableInfoMap *variableInfoMapOut) |
| 22151 |
{ |
| 22152 |
GenerateTransformFeedbackEmulationOutputs(options, programState, programInterfaceInfo, |
| 22153 |
- vertexShader, variableInfoMapOut); |
| 22154 |
+ vertexShader, variableInfoMapOut, false); |
| 22155 |
} |
| 22156 |
|
| 22157 |
void GlslangAssignLocations(const GlslangSourceOptions &options, |
| 22158 |
@@ -3428,6 +3430,57 @@ void GlslangAssignLocations(const GlslangSourceOptions &options, |
| 22159 |
variableInfoMapOut); |
| 22160 |
} |
| 22161 |
|
| 22162 |
+std::string GetXfbBufferName(const uint32_t bufferIndex) |
| 22163 |
+{ |
| 22164 |
+ return "xfbBuffer" + Str(bufferIndex); |
| 22165 |
+} |
| 22166 |
+ |
| 22167 |
+ |
| 22168 |
+void GlslangAssignLocations(GlslangSourceOptions &options, |
| 22169 |
+ const gl::ProgramExecutable &programExecutable, |
| 22170 |
+ const gl::ShaderType shaderType, |
| 22171 |
+ GlslangProgramInterfaceInfo *programInterfaceInfo, |
| 22172 |
+ ShaderMapInterfaceVariableInfoMap *variableInfoMapOut) |
| 22173 |
+{ |
| 22174 |
+ // Assign outputs to the fragment shader, if any. |
| 22175 |
+ if ((shaderType == gl::ShaderType::Fragment) && |
| 22176 |
+ programExecutable.hasLinkedShaderStage(gl::ShaderType::Fragment)) |
| 22177 |
+ { |
| 22178 |
+ AssignOutputLocations(programExecutable, gl::ShaderType::Fragment, |
| 22179 |
+ &(*variableInfoMapOut)[gl::ShaderType::Fragment]); |
| 22180 |
+ } |
| 22181 |
+ |
| 22182 |
+ // Assign attributes to the vertex shader, if any. |
| 22183 |
+ if ((shaderType == gl::ShaderType::Vertex) && |
| 22184 |
+ programExecutable.hasLinkedShaderStage(gl::ShaderType::Vertex)) |
| 22185 |
+ { |
| 22186 |
+ AssignAttributeLocations(programExecutable, gl::ShaderType::Vertex, |
| 22187 |
+ &(*variableInfoMapOut)[gl::ShaderType::Vertex]); |
| 22188 |
+ } |
| 22189 |
+ |
| 22190 |
+ if (!programExecutable.hasLinkedShaderStage(gl::ShaderType::Compute)) |
| 22191 |
+ { |
| 22192 |
+ // Assign varying locations. |
| 22193 |
+ AssignVaryingLocations(options, programExecutable, shaderType, programInterfaceInfo, |
| 22194 |
+ variableInfoMapOut); |
| 22195 |
+ |
| 22196 |
+ if (!programExecutable.getLinkedTransformFeedbackVaryings().empty() && |
| 22197 |
+ options.supportsTransformFeedbackExtension && (shaderType == gl::ShaderType::Vertex)) |
| 22198 |
+ { |
| 22199 |
+ AssignTransformFeedbackExtensionQualifiers( |
| 22200 |
+ programExecutable, programInterfaceInfo->locationsUsedForXfbExtension, |
| 22201 |
+ gl::ShaderType::Vertex, &(*variableInfoMapOut)[gl::ShaderType::Vertex]); |
| 22202 |
+ } |
| 22203 |
+ } |
| 22204 |
+ |
| 22205 |
+ AssignUniformBindings(options, programExecutable, shaderType, programInterfaceInfo, |
| 22206 |
+ variableInfoMapOut); |
| 22207 |
+ AssignTextureBindings(options, programExecutable, shaderType, programInterfaceInfo, |
| 22208 |
+ variableInfoMapOut); |
| 22209 |
+ AssignNonTextureBindings(options, programExecutable, shaderType, programInterfaceInfo, |
| 22210 |
+ variableInfoMapOut); |
| 22211 |
+} |
| 22212 |
+ |
| 22213 |
void GlslangGetShaderSource(const GlslangSourceOptions &options, |
| 22214 |
const gl::ProgramState &programState, |
| 22215 |
const gl::ProgramLinkedResources &resources, |
| 22216 |
@@ -3462,7 +3515,8 @@ void GlslangGetShaderSource(const GlslangSourceOptions &options, |
| 22217 |
{ |
| 22218 |
GenerateTransformFeedbackEmulationOutputs( |
| 22219 |
options, programState, programInterfaceInfo, vertexSource, |
| 22220 |
- &(*variableInfoMapOut)[gl::ShaderType::Vertex]); |
| 22221 |
+ &(*variableInfoMapOut)[gl::ShaderType::Vertex], |
| 22222 |
+ options.transformFeedbackEarlyReturn); |
| 22223 |
} |
| 22224 |
else |
| 22225 |
{ |
| 22226 |
diff --git a/src/libANGLE/renderer/glslang_wrapper_utils.h b/src/libANGLE/renderer/glslang_wrapper_utils.h |
| 22227 |
index 2bd2c61..60248cd 100644 |
| 22228 |
--- a/src/libANGLE/renderer/glslang_wrapper_utils.h |
| 22229 |
+++ b/src/libANGLE/renderer/glslang_wrapper_utils.h |
| 22230 |
@@ -51,6 +51,7 @@ struct GlslangSourceOptions |
| 22231 |
bool supportsTransformFeedbackExtension = false; |
| 22232 |
bool emulateTransformFeedback = false; |
| 22233 |
bool emulateBresenhamLines = false; |
| 22234 |
+ bool transformFeedbackEarlyReturn = false; |
| 22235 |
}; |
| 22236 |
|
| 22237 |
using SpirvBlob = std::vector<uint32_t>; |
| 22238 |
diff --git a/src/libANGLE/renderer/load_functions_data.json b/src/libANGLE/renderer/load_functions_data.json |
| 22239 |
index 8c3fd05..7bcded0 100644 |
| 22240 |
--- a/src/libANGLE/renderer/load_functions_data.json |
| 22241 |
+++ b/src/libANGLE/renderer/load_functions_data.json |
| 22242 |
@@ -672,6 +672,9 @@ |
| 22243 |
"D32_FLOAT_S8X24_UINT": { |
| 22244 |
"GL_UNSIGNED_INT_24_8": "LoadD24S8ToD32FS8X24", |
| 22245 |
"GL_UNSIGNED_INT": "LoadD32ToD32FX32" |
| 22246 |
+ }, |
| 22247 |
+ "D32_FLOAT": { |
| 22248 |
+ "GL_UNSIGNED_INT": "LoadD24S8ToD32F" |
| 22249 |
} |
| 22250 |
}, |
| 22251 |
"GL_R32I": { |
| 22252 |
diff --git a/src/libANGLE/renderer/load_functions_table_autogen.cpp b/src/libANGLE/renderer/load_functions_table_autogen.cpp |
| 22253 |
index 20e706f..2ef01ca 100644 |
| 22254 |
--- a/src/libANGLE/renderer/load_functions_table_autogen.cpp |
| 22255 |
+++ b/src/libANGLE/renderer/load_functions_table_autogen.cpp |
| 22256 |
@@ -446,8 +446,7 @@ LoadImageFunctionInfo COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE_to_BC1_RGB_UNORM_B |
| 22257 |
} |
| 22258 |
} |
| 22259 |
|
| 22260 |
-LoadImageFunctionInfo COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2_to_ETC2_R8G8B8A1_UNORM_BLOCK( |
| 22261 |
- GLenum type) |
| 22262 |
+LoadImageFunctionInfo COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2_to_ETC2_R8G8B8A1_UNORM_BLOCK(GLenum type) |
| 22263 |
{ |
| 22264 |
switch (type) |
| 22265 |
{ |
| 22266 |
@@ -471,8 +470,7 @@ LoadImageFunctionInfo COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2_to_R8G8B8A8_UNORM |
| 22267 |
} |
| 22268 |
} |
| 22269 |
|
| 22270 |
-LoadImageFunctionInfo |
| 22271 |
-COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE_to_BC1_RGBA_UNORM_BLOCK(GLenum type) |
| 22272 |
+LoadImageFunctionInfo COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE_to_BC1_RGBA_UNORM_BLOCK(GLenum type) |
| 22273 |
{ |
| 22274 |
switch (type) |
| 22275 |
{ |
| 22276 |
@@ -1312,8 +1310,7 @@ LoadImageFunctionInfo COMPRESSED_SRGB8_ETC2_to_R8G8B8A8_UNORM_SRGB(GLenum type) |
| 22277 |
} |
| 22278 |
} |
| 22279 |
|
| 22280 |
-LoadImageFunctionInfo COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE_to_BC1_RGB_UNORM_SRGB_BLOCK( |
| 22281 |
- GLenum type) |
| 22282 |
+LoadImageFunctionInfo COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE_to_BC1_RGB_UNORM_SRGB_BLOCK(GLenum type) |
| 22283 |
{ |
| 22284 |
switch (type) |
| 22285 |
{ |
| 22286 |
@@ -1325,8 +1322,7 @@ LoadImageFunctionInfo COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE_to_BC1_RGB_UNORM_ |
| 22287 |
} |
| 22288 |
} |
| 22289 |
|
| 22290 |
-LoadImageFunctionInfo COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2_to_ETC2_R8G8B8A1_SRGB_BLOCK( |
| 22291 |
- GLenum type) |
| 22292 |
+LoadImageFunctionInfo COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2_to_ETC2_R8G8B8A1_SRGB_BLOCK(GLenum type) |
| 22293 |
{ |
| 22294 |
switch (type) |
| 22295 |
{ |
| 22296 |
@@ -1350,9 +1346,7 @@ LoadImageFunctionInfo COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2_to_R8G8B8A8_UNOR |
| 22297 |
} |
| 22298 |
} |
| 22299 |
|
| 22300 |
-LoadImageFunctionInfo |
| 22301 |
-COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE_to_BC1_RGBA_UNORM_SRGB_BLOCK( |
| 22302 |
- GLenum type) |
| 22303 |
+LoadImageFunctionInfo COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE_to_BC1_RGBA_UNORM_SRGB_BLOCK(GLenum type) |
| 22304 |
{ |
| 22305 |
switch (type) |
| 22306 |
{ |
| 22307 |
@@ -1510,6 +1504,18 @@ LoadImageFunctionInfo DEPTH_COMPONENT24_to_D24_UNORM_X8_UINT(GLenum type) |
| 22308 |
} |
| 22309 |
} |
| 22310 |
|
| 22311 |
+LoadImageFunctionInfo DEPTH_COMPONENT24_to_D32_FLOAT(GLenum type) |
| 22312 |
+{ |
| 22313 |
+ switch (type) |
| 22314 |
+ { |
| 22315 |
+ case GL_UNSIGNED_INT: |
| 22316 |
+ return LoadImageFunctionInfo(LoadD24S8ToD32F, true); |
| 22317 |
+ default: |
| 22318 |
+ UNREACHABLE(); |
| 22319 |
+ return LoadImageFunctionInfo(UnreachableLoadFunction, true); |
| 22320 |
+ } |
| 22321 |
+} |
| 22322 |
+ |
| 22323 |
LoadImageFunctionInfo DEPTH_COMPONENT24_to_D32_FLOAT_S8X24_UINT(GLenum type) |
| 22324 |
{ |
| 22325 |
switch (type) |
| 22326 |
@@ -3624,6 +3630,8 @@ LoadFunctionMap GetLoadFunctionsMap(GLenum internalFormat, FormatID angleFormat) |
| 22327 |
return DEPTH_COMPONENT24_to_D24_UNORM_S8_UINT; |
| 22328 |
case FormatID::D24_UNORM_X8_UINT: |
| 22329 |
return DEPTH_COMPONENT24_to_D24_UNORM_X8_UINT; |
| 22330 |
+ case FormatID::D32_FLOAT: |
| 22331 |
+ return DEPTH_COMPONENT24_to_D32_FLOAT; |
| 22332 |
case FormatID::D32_FLOAT_S8X24_UINT: |
| 22333 |
return DEPTH_COMPONENT24_to_D32_FLOAT_S8X24_UINT; |
| 22334 |
default: |
| 22335 |
diff --git a/src/libANGLE/renderer/metal/BUILD.gn b/src/libANGLE/renderer/metal/BUILD.gn |
| 22336 |
index 868c476..0d50d81 100644 |
| 22337 |
--- a/src/libANGLE/renderer/metal/BUILD.gn |
| 22338 |
+++ b/src/libANGLE/renderer/metal/BUILD.gn |
| 22339 |
@@ -6,7 +6,7 @@ |
| 22340 |
|
| 22341 |
import("../../../../gni/angle.gni") |
| 22342 |
|
| 22343 |
-assert(is_mac) |
| 22344 |
+assert(is_mac || is_ios) |
| 22345 |
assert(angle_enable_metal) |
| 22346 |
|
| 22347 |
_metal_backend_sources = [ |
| 22348 |
@@ -21,6 +21,8 @@ _metal_backend_sources = [ |
| 22349 |
"DisplayMtl_api.h", |
| 22350 |
"FrameBufferMtl.h", |
| 22351 |
"FrameBufferMtl.mm", |
| 22352 |
+ "IOSurfaceSurfaceMtl.h", |
| 22353 |
+ "IOSurfaceSurfaceMtl.mm", |
| 22354 |
"ProgramMtl.h", |
| 22355 |
"ProgramMtl.mm", |
| 22356 |
"QueryMtl.h", |
| 22357 |
@@ -52,6 +54,8 @@ _metal_backend_sources = [ |
| 22358 |
"mtl_format_table_autogen.mm", |
| 22359 |
"mtl_format_utils.h", |
| 22360 |
"mtl_format_utils.mm", |
| 22361 |
+ "mtl_glslang_mtl_utils.h", |
| 22362 |
+ "mtl_glslang_mtl_utils.mm", |
| 22363 |
"mtl_glslang_utils.h", |
| 22364 |
"mtl_glslang_utils.mm", |
| 22365 |
"mtl_occlusion_query_pool.h", |
| 22366 |
@@ -65,12 +69,11 @@ _metal_backend_sources = [ |
| 22367 |
"mtl_utils.h", |
| 22368 |
"mtl_utils.mm", |
| 22369 |
"shaders/constants.h", |
| 22370 |
- "shaders/format_autogen.h", |
| 22371 |
- "shaders/mtl_default_shaders_src_autogen.inc", |
| 22372 |
+ "shaders/mtl_default_shaders_src_autogen.inc" |
| 22373 |
] |
| 22374 |
|
| 22375 |
config("angle_metal_backend_config") { |
| 22376 |
- defines = [ "ANGLE_ENABLE_METAL" ] |
| 22377 |
+ defines = [ "ANGLE_ENABLE_METAL", "ANGLE_ENABLE_METAL_SPIRV" ] |
| 22378 |
ldflags = [ |
| 22379 |
"-weak_framework", |
| 22380 |
"Metal", |
| 22381 |
@@ -96,12 +99,16 @@ angle_source_set("angle_metal_backend") { |
| 22382 |
"${angle_root}:libANGLE_headers", |
| 22383 |
] |
| 22384 |
|
| 22385 |
- deps = [ "${angle_spirv_cross_dir}/gn:spirv_cross_sources" ] |
| 22386 |
+ deps = [ |
| 22387 |
+ "$angle_spirv_tools_dir:spvtools_val", |
| 22388 |
+ "${angle_spirv_cross_dir}/gn:spirv_cross_sources", |
| 22389 |
+ ] |
| 22390 |
|
| 22391 |
objc_flags = [ |
| 22392 |
"-Wno-nullability-completeness", |
| 22393 |
"-Wno-unguarded-availability", |
| 22394 |
"-fno-objc-arc", |
| 22395 |
+ "-Wno-extra-semi-stmt", |
| 22396 |
] |
| 22397 |
cflags_objc += objc_flags |
| 22398 |
cflags_objcc += objc_flags |
| 22399 |
diff --git a/src/libANGLE/renderer/metal/BufferMtl.h b/src/libANGLE/renderer/metal/BufferMtl.h |
| 22400 |
index 762549e..9f9ec6c 100644 |
| 22401 |
--- a/src/libANGLE/renderer/metal/BufferMtl.h |
| 22402 |
+++ b/src/libANGLE/renderer/metal/BufferMtl.h |
| 22403 |
@@ -152,10 +152,15 @@ class BufferMtl : public BufferImpl, public BufferHolderMtl |
| 22404 |
|
| 22405 |
ConversionBufferMtl *getUniformConversionBuffer(ContextMtl *context, size_t offset); |
| 22406 |
|
| 22407 |
+ // NOTE(hqle): If the buffer is modifed by GPU, this function must be explicitly |
| 22408 |
+ // called. |
| 22409 |
+ void markConversionBuffersDirty(); |
| 22410 |
+ |
| 22411 |
size_t size() const { return static_cast<size_t>(mState.getSize()); } |
| 22412 |
|
| 22413 |
private: |
| 22414 |
angle::Result setDataImpl(const gl::Context *context, |
| 22415 |
+ gl::BufferBinding target, |
| 22416 |
const void *data, |
| 22417 |
size_t size, |
| 22418 |
gl::BufferUsage usage); |
| 22419 |
@@ -167,20 +172,24 @@ class BufferMtl : public BufferImpl, public BufferHolderMtl |
| 22420 |
angle::Result commitShadowCopy(const gl::Context *context); |
| 22421 |
angle::Result commitShadowCopy(const gl::Context *context, size_t size); |
| 22422 |
|
| 22423 |
- void markConversionBuffersDirty(); |
| 22424 |
- |
| 22425 |
void clearConversionBuffers(); |
| 22426 |
+ |
| 22427 |
bool clientShadowCopyDataNeedSync(ContextMtl *contextMtl); |
| 22428 |
void ensureShadowCopySyncedFromGPU(ContextMtl *contextMtl); |
| 22429 |
uint8_t *syncAndObtainShadowCopy(ContextMtl *contextMtl); |
| 22430 |
|
| 22431 |
+ // Convenient method |
| 22432 |
+ const uint8_t *getClientShadowCopyData(const gl::Context *context) |
| 22433 |
+ { |
| 22434 |
+ return getClientShadowCopyData(mtl::GetImpl(context)); |
| 22435 |
+ } |
| 22436 |
// Client side shadow buffer |
| 22437 |
angle::MemoryBuffer mShadowCopy; |
| 22438 |
|
| 22439 |
// GPU side buffers pool |
| 22440 |
mtl::BufferPool mBufferPool; |
| 22441 |
|
| 22442 |
- // A cache of converted buffer data. |
| 22443 |
+ // A cache of converted vertex data. |
| 22444 |
std::vector<VertexConversionBufferMtl> mVertexConversionBuffers; |
| 22445 |
|
| 22446 |
std::vector<IndexConversionBufferMtl> mIndexConversionBuffers; |
| 22447 |
diff --git a/src/libANGLE/renderer/metal/BufferMtl.mm b/src/libANGLE/renderer/metal/BufferMtl.mm |
| 22448 |
index 64c7de8..8096996 100644 |
| 22449 |
--- a/src/libANGLE/renderer/metal/BufferMtl.mm |
| 22450 |
+++ b/src/libANGLE/renderer/metal/BufferMtl.mm |
| 22451 |
@@ -23,6 +23,10 @@ |
| 22452 |
// Start with a fairly small buffer size. We can increase this dynamically as we convert more data. |
| 22453 |
constexpr size_t kConvertedElementArrayBufferInitialSize = 1024 * 8; |
| 22454 |
|
| 22455 |
+// The max size that we will use buffer pool for dynamic update. |
| 22456 |
+// If the buffer size exceeds this limit, we will use only one buffer instead of using the pool. |
| 22457 |
+constexpr size_t kDynamicBufferPoolMaxBufSize = 128 * 1024; |
| 22458 |
+ |
| 22459 |
template <typename IndexType> |
| 22460 |
angle::Result GetFirstLastIndices(const IndexType *indices, |
| 22461 |
size_t count, |
| 22462 |
@@ -105,7 +109,7 @@ |
| 22463 |
size_t intendedSize, |
| 22464 |
gl::BufferUsage usage) |
| 22465 |
{ |
| 22466 |
- return setDataImpl(context, data, intendedSize, usage); |
| 22467 |
+ return setDataImpl(context, target, data, intendedSize, usage); |
| 22468 |
} |
| 22469 |
|
| 22470 |
angle::Result BufferMtl::setSubData(const gl::Context *context, |
| 22471 |
@@ -164,7 +168,8 @@ |
| 22472 |
{ |
| 22473 |
if (access & GL_MAP_INVALIDATE_BUFFER_BIT) |
| 22474 |
{ |
| 22475 |
- ANGLE_TRY(setDataImpl(context, nullptr, size(), mState.getUsage())); |
| 22476 |
+ ANGLE_TRY(setDataImpl(context, gl::BufferBinding::InvalidEnum, nullptr, size(), |
| 22477 |
+ mState.getUsage())); |
| 22478 |
} |
| 22479 |
|
| 22480 |
if (mapPtr) |
| 22481 |
@@ -395,6 +400,7 @@ |
| 22482 |
} |
| 22483 |
|
| 22484 |
angle::Result BufferMtl::setDataImpl(const gl::Context *context, |
| 22485 |
+ gl::BufferBinding target, |
| 22486 |
const void *data, |
| 22487 |
size_t intendedSize, |
| 22488 |
gl::BufferUsage usage) |
| 22489 |
@@ -413,6 +419,13 @@ |
| 22490 |
|
| 22491 |
size_t adjustedSize = std::max<size_t>(1, intendedSize); |
| 22492 |
|
| 22493 |
+ // Ensures no validation layer issues in std140 with data types like vec3 being 12 bytes vs 16 |
| 22494 |
+ // in MSL. |
| 22495 |
+ if (target == gl::BufferBinding::Uniform) |
| 22496 |
+ { |
| 22497 |
+ adjustedSize = roundUpPow2(adjustedSize, (size_t)16); |
| 22498 |
+ } |
| 22499 |
+ |
| 22500 |
size_t maxBuffers; |
| 22501 |
switch (usage) |
| 22502 |
{ |
| 22503 |
@@ -427,7 +440,7 @@ |
| 22504 |
default: |
| 22505 |
// dynamic buffer, allow up to 10 update per frame/encoding without |
| 22506 |
// waiting for GPU. |
| 22507 |
- if (adjustedSize <= mtl::kSharedMemBufferMaxBufSizeHint) |
| 22508 |
+ if (adjustedSize <= kDynamicBufferPoolMaxBufSize) |
| 22509 |
{ |
| 22510 |
maxBuffers = 10; |
| 22511 |
mBufferPool.setAlwaysUseSharedMem(); |
| 22512 |
diff --git a/src/libANGLE/renderer/metal/CompilerMtl.mm b/src/libANGLE/renderer/metal/CompilerMtl.mm |
| 22513 |
index a586670..3e29b4d 100644 |
| 22514 |
--- a/src/libANGLE/renderer/metal/CompilerMtl.mm |
| 22515 |
+++ b/src/libANGLE/renderer/metal/CompilerMtl.mm |
| 22516 |
@@ -10,6 +10,7 @@ |
| 22517 |
#include "libANGLE/renderer/metal/CompilerMtl.h" |
| 22518 |
|
| 22519 |
#include "common/debug.h" |
| 22520 |
+#include "compiler/translator/TranslatorMetalDirect/EnvironmentVariable.h" |
| 22521 |
|
| 22522 |
namespace rx |
| 22523 |
{ |
| 22524 |
@@ -20,7 +21,16 @@ |
| 22525 |
|
| 22526 |
ShShaderOutput CompilerMtl::getTranslatorOutputType() const |
| 22527 |
{ |
| 22528 |
+ if (sh::readBoolEnvVar("ANGLE_GEN_MTL_WITH_SPIRV")) |
| 22529 |
+ { |
| 22530 |
+ // We want to return GL output first, we can't actually |
| 22531 |
+ // get MSL code until link time. Translation time is too early |
| 22532 |
return SH_GLSL_METAL_OUTPUT; |
| 22533 |
+ } |
| 22534 |
+ else |
| 22535 |
+ { |
| 22536 |
+ return SH_MSL_METAL_OUTPUT; |
| 22537 |
+ } |
| 22538 |
} |
| 22539 |
|
| 22540 |
} // namespace rx |
| 22541 |
diff --git a/src/libANGLE/renderer/metal/ContextMtl.h b/src/libANGLE/renderer/metal/ContextMtl.h |
| 22542 |
index 1687c8c..2f39371 100644 |
| 22543 |
--- a/src/libANGLE/renderer/metal/ContextMtl.h |
| 22544 |
+++ b/src/libANGLE/renderer/metal/ContextMtl.h |
| 22545 |
@@ -29,8 +29,8 @@ class FramebufferMtl; |
| 22546 |
class VertexArrayMtl; |
| 22547 |
class ProgramMtl; |
| 22548 |
class RenderTargetMtl; |
| 22549 |
-class WindowSurfaceMtl; |
| 22550 |
-class TransformFeedbackMtl; |
| 22551 |
+class SurfaceMtlProtocol; |
| 22552 |
+class BufferMtl; |
| 22553 |
|
| 22554 |
class ContextMtl : public ContextImpl, public mtl::Context |
| 22555 |
{ |
| 22556 |
@@ -85,7 +85,7 @@ class ContextMtl : public ContextImpl, public mtl::Context |
| 22557 |
GLsizei count, |
| 22558 |
gl::DrawElementsType type, |
| 22559 |
const void *indices, |
| 22560 |
- GLsizei instanceCount, |
| 22561 |
+ GLsizei instances, |
| 22562 |
GLint baseVertex) override; |
| 22563 |
angle::Result drawElementsInstancedBaseVertexBaseInstance(const gl::Context *context, |
| 22564 |
gl::PrimitiveMode mode, |
| 22565 |
@@ -157,6 +157,12 @@ class ContextMtl : public ContextImpl, public mtl::Context |
| 22566 |
const GLint *baseVertices, |
| 22567 |
const GLuint *baseInstances, |
| 22568 |
GLsizei drawcount) override; |
| 22569 |
+ angle::Result drawElementsSimpleTypesPrimitiveRestart(const gl::Context *context, |
| 22570 |
+ gl::PrimitiveMode mode, |
| 22571 |
+ GLsizei count, |
| 22572 |
+ gl::DrawElementsType type, |
| 22573 |
+ const void *indices, |
| 22574 |
+ GLsizei instances); |
| 22575 |
|
| 22576 |
// Device loss |
| 22577 |
gl::GraphicsResetStatus getResetStatus() override; |
| 22578 |
@@ -196,6 +202,8 @@ class ContextMtl : public ContextImpl, public mtl::Context |
| 22579 |
const gl::Extensions &getNativeExtensions() const override; |
| 22580 |
const gl::Limitations &getNativeLimitations() const override; |
| 22581 |
|
| 22582 |
+ const ProgramMtl *getProgram() const { return mProgram; } |
| 22583 |
+ |
| 22584 |
// Shader creation |
| 22585 |
CompilerImpl *createCompiler() override; |
| 22586 |
ShaderImpl *createShader(const gl::ShaderState &state) override; |
| 22587 |
@@ -249,12 +257,24 @@ class ContextMtl : public ContextImpl, public mtl::Context |
| 22588 |
angle::Result memoryBarrier(const gl::Context *context, GLbitfield barriers) override; |
| 22589 |
angle::Result memoryBarrierByRegion(const gl::Context *context, GLbitfield barriers) override; |
| 22590 |
|
| 22591 |
+ void invalidateCurrentTransformFeedbackBuffers(); |
| 22592 |
+ void onTransformFeedbackStateChanged(); |
| 22593 |
+ angle::Result onBeginTransformFeedback( |
| 22594 |
+ size_t bufferCount, |
| 22595 |
+ const gl::TransformFeedbackBuffersArray<BufferMtl *> &buffers); |
| 22596 |
+ |
| 22597 |
+ void onEndTransformFeedback(); |
| 22598 |
+ angle::Result onPauseTransformFeedback(); |
| 22599 |
+ |
| 22600 |
+ void populateTransformFeedbackBufferSet( |
| 22601 |
+ size_t bufferCount, |
| 22602 |
+ const gl::TransformFeedbackBuffersArray<BufferMtl *> &buffers); |
| 22603 |
// override mtl::ErrorHandler |
| 22604 |
void handleError(GLenum error, |
| 22605 |
const char *file, |
| 22606 |
const char *function, |
| 22607 |
unsigned int line) override; |
| 22608 |
- void handleError(NSError *_Nullable error, |
| 22609 |
+ void handleError(NSError *error, |
| 22610 |
const char *file, |
| 22611 |
const char *function, |
| 22612 |
unsigned int line) override; |
| 22613 |
@@ -272,12 +292,12 @@ class ContextMtl : public ContextImpl, public mtl::Context |
| 22614 |
void onDrawFrameBufferChangedState(const gl::Context *context, |
| 22615 |
FramebufferMtl *framebuffer, |
| 22616 |
bool renderPassChanged); |
| 22617 |
- void onBackbufferResized(const gl::Context *context, WindowSurfaceMtl *backbuffer); |
| 22618 |
+ void onBackbufferResized(const gl::Context *context, SurfaceMtlProtocol *backbuffer); |
| 22619 |
|
| 22620 |
// Invoke by QueryMtl |
| 22621 |
- angle::Result onOcclusionQueryBegin(const gl::Context *context, QueryMtl *query); |
| 22622 |
- void onOcclusionQueryEnd(const gl::Context *context, QueryMtl *query); |
| 22623 |
- void onOcclusionQueryDestroy(const gl::Context *context, QueryMtl *query); |
| 22624 |
+ angle::Result onOcclusionQueryBegan(const gl::Context *context, QueryMtl *query); |
| 22625 |
+ void onOcclusionQueryEnded(const gl::Context *context, QueryMtl *query); |
| 22626 |
+ void onOcclusionQueryDestroyed(const gl::Context *context, QueryMtl *query); |
| 22627 |
|
| 22628 |
// Useful for temporarily pause then restart occlusion query during clear/blit with draw. |
| 22629 |
bool hasActiveOcclusionQuery() const { return mOcclusionQuery; } |
| 22630 |
@@ -367,7 +387,7 @@ class ContextMtl : public ContextImpl, public mtl::Context |
| 22631 |
GLsizei instanceCount, |
| 22632 |
gl::DrawElementsType indexTypeOrNone, |
| 22633 |
const void *indices, |
| 22634 |
- bool xfbPass); |
| 22635 |
+ bool transformFeedbackDraw); |
| 22636 |
|
| 22637 |
angle::Result drawTriFanArrays(const gl::Context *context, |
| 22638 |
GLint first, |
| 22639 |
@@ -417,6 +437,18 @@ class ContextMtl : public ContextImpl, public mtl::Context |
| 22640 |
const void *indices, |
| 22641 |
GLsizei instanceCount); |
| 22642 |
|
| 22643 |
+ void execDrawInstanced(MTLPrimitiveType primitiveType, |
| 22644 |
+ uint32_t vertexStart, |
| 22645 |
+ uint32_t vertexCount, |
| 22646 |
+ uint32_t instances); |
| 22647 |
+ |
| 22648 |
+ void execDrawIndexedInstanced(MTLPrimitiveType primitiveType, |
| 22649 |
+ uint32_t indexCount, |
| 22650 |
+ MTLIndexType indexType, |
| 22651 |
+ const mtl::BufferRef &indexBuffer, |
| 22652 |
+ size_t bufferOffset, |
| 22653 |
+ uint32_t instances); |
| 22654 |
+ |
| 22655 |
void updateExtendedState(const gl::State &glState); |
| 22656 |
|
| 22657 |
void updateViewport(FramebufferMtl *framebufferMtl, |
| 22658 |
@@ -442,6 +474,7 @@ class ContextMtl : public ContextImpl, public mtl::Context |
| 22659 |
angle::Result fillDriverXFBUniforms(GLint drawCallFirstVertex, |
| 22660 |
uint32_t verticesPerInstance, |
| 22661 |
uint32_t skippedInstances); |
| 22662 |
+ angle::Result handleDirtyGraphicsTransformFeedbackBuffersEmulation(const gl::Context *context); |
| 22663 |
angle::Result handleDirtyDepthStencilState(const gl::Context *context); |
| 22664 |
angle::Result handleDirtyDepthBias(const gl::Context *context); |
| 22665 |
angle::Result handleDirtyRenderPass(const gl::Context *context); |
| 22666 |
@@ -470,6 +503,7 @@ class ContextMtl : public ContextImpl, public mtl::Context |
| 22667 |
DIRTY_BIT_RENDER_PIPELINE, |
| 22668 |
DIRTY_BIT_UNIFORM_BUFFERS_BINDING, |
| 22669 |
DIRTY_BIT_RASTERIZER_DISCARD, |
| 22670 |
+ DIRTY_BIT_TRANSFORM_FEEDBACK_BUFFERS, |
| 22671 |
DIRTY_BIT_MAX, |
| 22672 |
}; |
| 22673 |
|
| 22674 |
@@ -488,7 +522,7 @@ class ContextMtl : public ContextImpl, public mtl::Context |
| 22675 |
uint32_t xfbActiveUnpaused; |
| 22676 |
uint32_t xfbVerticesPerDraw; |
| 22677 |
// NOTE: Explicit padding. Fill in with useful data when needed in the future. |
| 22678 |
- int32_t padding[3]; |
| 22679 |
+ int32_t padding_0[3]; |
| 22680 |
|
| 22681 |
int32_t xfbBufferOffsets[4]; |
| 22682 |
uint32_t acbBufferOffsets[4]; |
| 22683 |
@@ -508,12 +542,15 @@ class ContextMtl : public ContextImpl, public mtl::Context |
| 22684 |
|
| 22685 |
uint32_t coverageMask; |
| 22686 |
|
| 22687 |
- float padding2[3]; |
| 22688 |
+ int32_t emulatedInstanceID; |
| 22689 |
+ |
| 22690 |
+ // NOTE: Explicit padding. Fill in with useful data when needed in the future. |
| 22691 |
+ int32_t padding_1[2]; |
| 22692 |
}; |
| 22693 |
|
| 22694 |
struct DefaultAttribute |
| 22695 |
{ |
| 22696 |
- uint8_t values[sizeof(float) * 4]; |
| 22697 |
+ float values[4]; |
| 22698 |
}; |
| 22699 |
|
| 22700 |
mtl::OcclusionQueryPool mOcclusionQueryPool; |
| 22701 |
@@ -522,6 +559,13 @@ class ContextMtl : public ContextImpl, public mtl::Context |
| 22702 |
mtl::RenderCommandEncoder mRenderEncoder; |
| 22703 |
mtl::BlitCommandEncoder mBlitEncoder; |
| 22704 |
mtl::ComputeCommandEncoder mComputeEncoder; |
| 22705 |
+ // TODO(jcunningham): |
| 22706 |
+ // Cache the current draw call's firstVertex to be passed to |
| 22707 |
+ // TransformFeedbackMtl::getBufferOffsets. We should switch |
| 22708 |
+ // to using gl_BaseVertex -> base_vertex in MSL |
| 22709 |
+ GLint mXfbBaseVertex; |
| 22710 |
+ // Cache the current draw call's vertex count as well to support instanced draw calls |
| 22711 |
+ GLuint mXfbVertexCountPerInstance; |
| 22712 |
|
| 22713 |
// Cached back-end objects |
| 22714 |
FramebufferMtl *mDrawFramebuffer = nullptr; |
| 22715 |
@@ -554,6 +598,8 @@ class ContextMtl : public ContextImpl, public mtl::Context |
| 22716 |
mtl::BufferPool mTriFanIndexBuffer; |
| 22717 |
// one buffer can be reused for any starting vertex in DrawArrays() |
| 22718 |
mtl::BufferRef mTriFanArraysIndexBuffer; |
| 22719 |
+ // |
| 22720 |
+ mtl::BufferPool mPrimitiveRestartBuffer; |
| 22721 |
|
| 22722 |
// Dummy texture to be used for transform feedback only pass. |
| 22723 |
mtl::TextureRef mDummyXFBRenderTexture; |
| 22724 |
@@ -562,6 +608,9 @@ class ContextMtl : public ContextImpl, public mtl::Context |
| 22725 |
|
| 22726 |
DefaultAttribute mDefaultAttributes[mtl::kMaxVertexAttribs]; |
| 22727 |
|
| 22728 |
+ // Transform feedback buffers. |
| 22729 |
+ std::unordered_set<const BufferMtl *> mCurrentTransformFeedbackBuffers; |
| 22730 |
+ |
| 22731 |
IncompleteTextureSet mIncompleteTextures; |
| 22732 |
bool mIncompleteTexturesInitialized = false; |
| 22733 |
}; |
| 22734 |
diff --git a/src/libANGLE/renderer/metal/ContextMtl.mm b/src/libANGLE/renderer/metal/ContextMtl.mm |
| 22735 |
index 27e6978..45a0928 100644 |
| 22736 |
--- a/src/libANGLE/renderer/metal/ContextMtl.mm |
| 22737 |
+++ b/src/libANGLE/renderer/metal/ContextMtl.mm |
| 22738 |
@@ -44,25 +44,6 @@ |
| 22739 |
constexpr uint32_t kMaxTriFanLineLoopBuffersPerFrame = 10; |
| 22740 |
#endif |
| 22741 |
|
| 22742 |
-#define ANGLE_MTL_XFB_DRAW(DRAW_PROC) \ |
| 22743 |
- if (!mState.isTransformFeedbackActiveUnpaused()) \ |
| 22744 |
- { \ |
| 22745 |
- /* Normal draw call */ \ |
| 22746 |
- DRAW_PROC(false); \ |
| 22747 |
- } \ |
| 22748 |
- else \ |
| 22749 |
- { \ |
| 22750 |
- /* First pass: write to XFB buffers in vertex shader, fragment shader inactive */ \ |
| 22751 |
- DRAW_PROC(true); \ |
| 22752 |
- if (!mState.isRasterizerDiscardEnabled()) \ |
| 22753 |
- { \ |
| 22754 |
- /* Second pass: full rasterization: vertex shader + fragment shader are active. \ |
| 22755 |
- Vertex shader writes to stage output but won't write to XFB buffers */ \ |
| 22756 |
- invalidateRenderPipeline(); \ |
| 22757 |
- DRAW_PROC(false); \ |
| 22758 |
- } \ |
| 22759 |
- } |
| 22760 |
- |
| 22761 |
angle::Result AllocateTriangleFanBufferFromPool(ContextMtl *context, |
| 22762 |
GLsizei vertexCount, |
| 22763 |
mtl::BufferPool *pool, |
| 22764 |
@@ -84,7 +65,7 @@ |
| 22765 |
return angle::Result::Continue; |
| 22766 |
} |
| 22767 |
|
| 22768 |
-angle::Result AllocateLineLoopBufferFromPool(ContextMtl *context, |
| 22769 |
+angle::Result AllocateBufferFromPool(ContextMtl *context, |
| 22770 |
GLsizei indicesToReserve, |
| 22771 |
mtl::BufferPool *pool, |
| 22772 |
mtl::BufferRef *bufferOut, |
| 22773 |
@@ -105,12 +86,7 @@ bool NeedToInvertDepthRange(float near, float far) |
| 22774 |
return near > far; |
| 22775 |
} |
| 22776 |
|
| 22777 |
-bool IsTransformFeedbackOnly(const gl::State &glState) |
| 22778 |
-{ |
| 22779 |
- return glState.isTransformFeedbackActiveUnpaused() && glState.isRasterizerDiscardEnabled(); |
| 22780 |
-} |
| 22781 |
- |
| 22782 |
-std::string ConvertMarkerToString(GLsizei length, const char *marker) |
| 22783 |
+std::string ConvertMarkerToCpp(GLsizei length, const char *marker) |
| 22784 |
{ |
| 22785 |
std::string cppString; |
| 22786 |
if (length == 0) |
| 22787 |
@@ -173,7 +149,7 @@ bool IsTransformFeedbackOnly(const gl::State &glState) |
| 22788 |
{indexTypeOrNone, vertexOrIndexCount, indices, mLineLoopIndexBuffer, 0})); |
| 22789 |
} |
| 22790 |
|
| 22791 |
- ANGLE_TRY(indexBufferPool->commit(mContextMtl)); |
| 22792 |
+ ANGLE_TRY(indexBufferPool->commit(mContextMtl, false)); |
| 22793 |
|
| 22794 |
return angle::Result::Continue; |
| 22795 |
} |
| 22796 |
@@ -191,7 +167,8 @@ bool IsTransformFeedbackOnly(const gl::State &glState) |
| 22797 |
mCmdBuffer(&display->cmdQueue()), |
| 22798 |
mRenderEncoder(&mCmdBuffer, mOcclusionQueryPool), |
| 22799 |
mBlitEncoder(&mCmdBuffer), |
| 22800 |
- mComputeEncoder(&mCmdBuffer) |
| 22801 |
+ mComputeEncoder(&mCmdBuffer), |
| 22802 |
+ mXfbVertexCountPerInstance(0) |
| 22803 |
{} |
| 22804 |
|
| 22805 |
ContextMtl::~ContextMtl() {} |
| 22806 |
@@ -208,6 +185,8 @@ bool IsTransformFeedbackOnly(const gl::State &glState) |
| 22807 |
mLineLoopLastSegmentIndexBuffer.initialize(this, 2 * sizeof(uint32_t), |
| 22808 |
mtl::kIndexBufferOffsetAlignment, |
| 22809 |
kMaxTriFanLineLoopBuffersPerFrame); |
| 22810 |
+ mPrimitiveRestartBuffer.initialize(this, 0, mtl::kIndexBufferOffsetAlignment, |
| 22811 |
+ kMaxTriFanLineLoopBuffersPerFrame); |
| 22812 |
|
| 22813 |
return angle::Result::Continue; |
| 22814 |
} |
| 22815 |
@@ -227,23 +206,20 @@ bool IsTransformFeedbackOnly(const gl::State &glState) |
| 22816 |
|
| 22817 |
angle::Result ContextMtl::ensureIncompleteTexturesCreated(const gl::Context *context) |
| 22818 |
{ |
| 22819 |
- if (ANGLE_LIKELY(mIncompleteTexturesInitialized)) |
| 22820 |
+ if (ANGLE_UNLIKELY(!mIncompleteTexturesInitialized)) |
| 22821 |
{ |
| 22822 |
- return angle::Result::Continue; |
| 22823 |
- } |
| 22824 |
- constexpr gl::TextureType supportedTextureTypes[] = {gl::TextureType::_2D, gl::TextureType::_3D, |
| 22825 |
- gl::TextureType::_2DArray, |
| 22826 |
+ constexpr gl::TextureType supportedTextureTypes[] = { |
| 22827 |
+ gl::TextureType::_2D, gl::TextureType::_2DArray, gl::TextureType::_3D, |
| 22828 |
gl::TextureType::CubeMap}; |
| 22829 |
- for (gl::TextureType texType : supportedTextureTypes) |
| 22830 |
+ for (auto texType : supportedTextureTypes) |
| 22831 |
{ |
| 22832 |
gl::Texture *texture; |
| 22833 |
- ANGLE_TRY(mIncompleteTextures.getIncompleteTexture(context, texType, nullptr, &texture)); |
| 22834 |
- |
| 22835 |
- TextureMtl *textureMtl = mtl::GetImpl(texture); |
| 22836 |
- textureMtl->getNativeTexture()->get().label = @"IncompleteTexture"; |
| 22837 |
+ ANGLE_UNUSED_VARIABLE(texture); |
| 22838 |
+ ANGLE_TRY( |
| 22839 |
+ mIncompleteTextures.getIncompleteTexture(context, texType, nullptr, &texture)); |
| 22840 |
} |
| 22841 |
mIncompleteTexturesInitialized = true; |
| 22842 |
- |
| 22843 |
+ } |
| 22844 |
return angle::Result::Continue; |
| 22845 |
} |
| 22846 |
|
| 22847 |
@@ -282,7 +258,17 @@ bool IsTransformFeedbackOnly(const gl::State &glState) |
| 22848 |
this, {0, static_cast<uint32_t>(count), mTriFanArraysIndexBuffer, 0})); |
| 22849 |
} |
| 22850 |
|
| 22851 |
- ASSERT(!getState().isTransformFeedbackActiveUnpaused()); |
| 22852 |
+ if (mState.isTransformFeedbackActiveUnpaused()) |
| 22853 |
+ { |
| 22854 |
+ ANGLE_TRY(setupDraw(context, gl::PrimitiveMode::TriangleFan, first, count, instances, |
| 22855 |
+ gl::DrawElementsType::InvalidEnum, reinterpret_cast<const void *>(0), |
| 22856 |
+ true)); |
| 22857 |
+ // Draw with the zero starting index buffer, shift the vertex index using baseVertex |
| 22858 |
+ // instanced draw: |
| 22859 |
+ mRenderEncoder.drawIndexedInstancedBaseVertex(MTLPrimitiveTypeTriangle, genIndicesCount, |
| 22860 |
+ MTLIndexTypeUInt32, mTriFanArraysIndexBuffer, |
| 22861 |
+ 0, instances, first); |
| 22862 |
+ } |
| 22863 |
|
| 22864 |
ANGLE_TRY(setupDraw(context, gl::PrimitiveMode::TriangleFan, first, count, instances, |
| 22865 |
gl::DrawElementsType::InvalidEnum, reinterpret_cast<const void *>(0), |
| 22866 |
@@ -311,16 +297,23 @@ bool IsTransformFeedbackOnly(const gl::State &glState) |
| 22867 |
this, {static_cast<uint32_t>(first), static_cast<uint32_t>(count), genIdxBuffer, |
| 22868 |
genIdxBufferOffset})); |
| 22869 |
|
| 22870 |
- ANGLE_TRY(mTriFanIndexBuffer.commit(this)); |
| 22871 |
+ ANGLE_TRY(mTriFanIndexBuffer.commit(this, false)); |
| 22872 |
|
| 22873 |
- ASSERT(!getState().isTransformFeedbackActiveUnpaused()); |
| 22874 |
+ if (mState.isTransformFeedbackActiveUnpaused()) |
| 22875 |
+ { |
| 22876 |
+ ANGLE_TRY(setupDraw(context, gl::PrimitiveMode::TriangleFan, first, count, instances, |
| 22877 |
+ gl::DrawElementsType::InvalidEnum, reinterpret_cast<const void *>(0), |
| 22878 |
+ true)); |
| 22879 |
|
| 22880 |
+ execDrawIndexedInstanced(MTLPrimitiveTypeTriangle, genIndicesCount, MTLIndexTypeUInt32, |
| 22881 |
+ genIdxBuffer, genIdxBufferOffset, instances); |
| 22882 |
+ } |
| 22883 |
ANGLE_TRY(setupDraw(context, gl::PrimitiveMode::TriangleFan, first, count, instances, |
| 22884 |
gl::DrawElementsType::InvalidEnum, reinterpret_cast<const void *>(0), |
| 22885 |
false)); |
| 22886 |
|
| 22887 |
- mRenderEncoder.drawIndexed(MTLPrimitiveTypeTriangle, genIndicesCount, MTLIndexTypeUInt32, |
| 22888 |
- genIdxBuffer, genIdxBufferOffset); |
| 22889 |
+ execDrawIndexedInstanced(MTLPrimitiveTypeTriangle, genIndicesCount, MTLIndexTypeUInt32, |
| 22890 |
+ genIdxBuffer, genIdxBufferOffset, instances); |
| 22891 |
|
| 22892 |
return angle::Result::Continue; |
| 22893 |
} |
| 22894 |
@@ -368,22 +361,27 @@ bool IsTransformFeedbackOnly(const gl::State &glState) |
| 22895 |
uint32_t genIdxBufferOffset; |
| 22896 |
uint32_t genIndicesCount = count + 1; |
| 22897 |
|
| 22898 |
- ANGLE_TRY(AllocateLineLoopBufferFromPool(this, genIndicesCount, &mLineLoopIndexBuffer, |
| 22899 |
- &genIdxBuffer, &genIdxBufferOffset)); |
| 22900 |
+ ANGLE_TRY(AllocateBufferFromPool(this, genIndicesCount, &mLineLoopIndexBuffer, &genIdxBuffer, |
| 22901 |
+ &genIdxBufferOffset)); |
| 22902 |
ANGLE_TRY(getDisplay()->getUtils().generateLineLoopBufferFromArrays( |
| 22903 |
this, {static_cast<uint32_t>(first), static_cast<uint32_t>(count), genIdxBuffer, |
| 22904 |
genIdxBufferOffset})); |
| 22905 |
|
| 22906 |
- ANGLE_TRY(mLineLoopIndexBuffer.commit(this)); |
| 22907 |
+ ANGLE_TRY(mLineLoopIndexBuffer.commit(this, false)); |
| 22908 |
|
| 22909 |
- ASSERT(!getState().isTransformFeedbackActiveUnpaused()); |
| 22910 |
+ if (mState.isTransformFeedbackActiveUnpaused()) |
| 22911 |
+ { |
| 22912 |
+ ANGLE_TRY(setupDraw(context, gl::PrimitiveMode::LineLoop, first, count, instances, |
| 22913 |
+ gl::DrawElementsType::InvalidEnum, nullptr, true)); |
| 22914 |
|
| 22915 |
+ execDrawIndexedInstanced(MTLPrimitiveTypeLineStrip, genIndicesCount, MTLIndexTypeUInt32, |
| 22916 |
+ genIdxBuffer, genIdxBufferOffset, instances); |
| 22917 |
+ } |
| 22918 |
ANGLE_TRY(setupDraw(context, gl::PrimitiveMode::LineLoop, first, count, instances, |
| 22919 |
gl::DrawElementsType::InvalidEnum, nullptr, false)); |
| 22920 |
|
| 22921 |
- mRenderEncoder.drawIndexedInstanced(MTLPrimitiveTypeLineStrip, genIndicesCount, |
| 22922 |
- MTLIndexTypeUInt32, genIdxBuffer, genIdxBufferOffset, |
| 22923 |
- instances); |
| 22924 |
+ execDrawIndexedInstanced(MTLPrimitiveTypeLineStrip, genIndicesCount, MTLIndexTypeUInt32, |
| 22925 |
+ genIdxBuffer, genIdxBufferOffset, instances); |
| 22926 |
|
| 22927 |
return angle::Result::Continue; |
| 22928 |
} |
| 22929 |
@@ -413,21 +411,33 @@ bool IsTransformFeedbackOnly(const gl::State &glState) |
| 22930 |
|
| 22931 |
MTLPrimitiveType mtlType = mtl::GetPrimitiveType(mode); |
| 22932 |
|
| 22933 |
-#define DRAW_GENERIC_ARRAY(xfbPass) \ |
| 22934 |
- ANGLE_TRY(setupDraw(context, mode, first, count, instances, gl::DrawElementsType::InvalidEnum, \ |
| 22935 |
- nullptr, xfbPass)); \ |
| 22936 |
- \ |
| 22937 |
- if (instances == 0) \ |
| 22938 |
- { \ |
| 22939 |
- /* This method is called from normal drawArrays() */ \ |
| 22940 |
- mRenderEncoder.draw(mtlType, first, count); \ |
| 22941 |
- } \ |
| 22942 |
- else \ |
| 22943 |
- { \ |
| 22944 |
- mRenderEncoder.drawInstanced(mtlType, first, count, instanceCount); \ |
| 22945 |
+ if (mState.isTransformFeedbackActiveUnpaused()) |
| 22946 |
+ { |
| 22947 |
+ ANGLE_TRY(setupDraw(context, mode, first, count, instances, |
| 22948 |
+ gl::DrawElementsType::InvalidEnum, nullptr, true)); |
| 22949 |
+ |
| 22950 |
+ if (instances == 0) |
| 22951 |
+ { |
| 22952 |
+ // This method is called from normal drawArrays() |
| 22953 |
+ mRenderEncoder.draw(mtlType, first, count); |
| 22954 |
+ } |
| 22955 |
+ else |
| 22956 |
+ { |
| 22957 |
+ execDrawInstanced(mtlType, first, count, instanceCount); |
| 22958 |
+ } |
| 22959 |
} |
| 22960 |
+ ANGLE_TRY(setupDraw(context, mode, first, count, instances, gl::DrawElementsType::InvalidEnum, |
| 22961 |
+ nullptr, false)); |
| 22962 |
|
| 22963 |
- ANGLE_MTL_XFB_DRAW(DRAW_GENERIC_ARRAY) |
| 22964 |
+ if (instances == 0) |
| 22965 |
+ { |
| 22966 |
+ // This method is called from normal drawArrays() |
| 22967 |
+ mRenderEncoder.draw(mtlType, first, count); |
| 22968 |
+ } |
| 22969 |
+ else |
| 22970 |
+ { |
| 22971 |
+ execDrawInstanced(mtlType, first, count, instanceCount); |
| 22972 |
+ } |
| 22973 |
|
| 22974 |
return angle::Result::Continue; |
| 22975 |
} |
| 22976 |
@@ -480,16 +490,25 @@ bool IsTransformFeedbackOnly(const gl::State &glState) |
| 22977 |
&genIdxBufferOffset, &genIndicesCount)); |
| 22978 |
|
| 22979 |
ANGLE_TRY(getDisplay()->getUtils().generateTriFanBufferFromElementsArray( |
| 22980 |
- this, {type, count, indices, genIdxBuffer, genIdxBufferOffset, primitiveRestart})); |
| 22981 |
+ this, {type, count, indices, genIdxBuffer, genIdxBufferOffset, primitiveRestart}, |
| 22982 |
+ &genIndicesCount)); |
| 22983 |
|
| 22984 |
- ANGLE_TRY(mTriFanIndexBuffer.commit(this)); |
| 22985 |
+ ANGLE_TRY(mTriFanIndexBuffer.commit(this, false)); |
| 22986 |
+ |
| 22987 |
+ if (mState.isTransformFeedbackActiveUnpaused()) |
| 22988 |
+ { |
| 22989 |
+ ANGLE_TRY(setupDraw(context, gl::PrimitiveMode::TriangleFan, 0, count, instances, type, |
| 22990 |
+ indices, true)); |
| 22991 |
+ |
| 22992 |
+ execDrawIndexedInstanced(MTLPrimitiveTypeTriangle, genIndicesCount, MTLIndexTypeUInt32, |
| 22993 |
+ genIdxBuffer, genIdxBufferOffset, instances); |
| 22994 |
+ } |
| 22995 |
|
| 22996 |
ANGLE_TRY(setupDraw(context, gl::PrimitiveMode::TriangleFan, 0, count, instances, type, |
| 22997 |
indices, false)); |
| 22998 |
|
| 22999 |
- mRenderEncoder.drawIndexedInstanced(MTLPrimitiveTypeTriangle, genIndicesCount, |
| 23000 |
- MTLIndexTypeUInt32, genIdxBuffer, genIdxBufferOffset, |
| 23001 |
- instances); |
| 23002 |
+ execDrawIndexedInstanced(MTLPrimitiveTypeTriangle, genIndicesCount, MTLIndexTypeUInt32, |
| 23003 |
+ genIdxBuffer, genIdxBufferOffset, instances); |
| 23004 |
|
| 23005 |
return angle::Result::Continue; |
| 23006 |
} // if (count > 3) |
| 23007 |
@@ -532,27 +551,87 @@ bool IsTransformFeedbackOnly(const gl::State &glState) |
| 23008 |
uint32_t genIdxBufferOffset; |
| 23009 |
uint32_t reservedIndices = count * 2; |
| 23010 |
uint32_t genIndicesCount; |
| 23011 |
- ANGLE_TRY(AllocateLineLoopBufferFromPool(this, reservedIndices, &mLineLoopIndexBuffer, |
| 23012 |
+ ANGLE_TRY(AllocateBufferFromPool(this, reservedIndices, &mLineLoopIndexBuffer, |
| 23013 |
&genIdxBuffer, &genIdxBufferOffset)); |
| 23014 |
|
| 23015 |
ANGLE_TRY(getDisplay()->getUtils().generateLineLoopBufferFromElementsArray( |
| 23016 |
this, {type, count, indices, genIdxBuffer, genIdxBufferOffset, primitiveRestart}, |
| 23017 |
&genIndicesCount)); |
| 23018 |
|
| 23019 |
- ANGLE_TRY(mLineLoopIndexBuffer.commit(this)); |
| 23020 |
+ ANGLE_TRY(mLineLoopIndexBuffer.commit(this, false)); |
| 23021 |
+ |
| 23022 |
+ if (mState.isTransformFeedbackActiveUnpaused()) |
| 23023 |
+ { |
| 23024 |
+ ANGLE_TRY(setupDraw(context, gl::PrimitiveMode::LineLoop, 0, count, instances, type, |
| 23025 |
+ indices, true)); |
| 23026 |
+ |
| 23027 |
+ execDrawIndexedInstanced(MTLPrimitiveTypeLineStrip, genIndicesCount, MTLIndexTypeUInt32, |
| 23028 |
+ genIdxBuffer, genIdxBufferOffset, instances); |
| 23029 |
+ } |
| 23030 |
|
| 23031 |
ANGLE_TRY(setupDraw(context, gl::PrimitiveMode::LineLoop, 0, count, instances, type, |
| 23032 |
indices, false)); |
| 23033 |
|
| 23034 |
- mRenderEncoder.drawIndexedInstanced(MTLPrimitiveTypeLineStrip, genIndicesCount, |
| 23035 |
- MTLIndexTypeUInt32, genIdxBuffer, genIdxBufferOffset, |
| 23036 |
- instances); |
| 23037 |
+ execDrawIndexedInstanced(MTLPrimitiveTypeLineStrip, genIndicesCount, MTLIndexTypeUInt32, |
| 23038 |
+ genIdxBuffer, genIdxBufferOffset, instances); |
| 23039 |
|
| 23040 |
return angle::Result::Continue; |
| 23041 |
} // if (count >= 2) |
| 23042 |
return drawElementsInstanced(context, gl::PrimitiveMode::Lines, count, type, indices, |
| 23043 |
instances); |
| 23044 |
} |
| 23045 |
+angle::Result ContextMtl::drawElementsSimpleTypesPrimitiveRestart(const gl::Context *context, |
| 23046 |
+ gl::PrimitiveMode mode, |
| 23047 |
+ GLsizei count, |
| 23048 |
+ gl::DrawElementsType type, |
| 23049 |
+ const void *indices, |
| 23050 |
+ GLsizei instances) |
| 23051 |
+{ |
| 23052 |
+ |
| 23053 |
+ mtl::BufferRef genIdxBuffer; |
| 23054 |
+ uint32_t genIdxBufferOffset; |
| 23055 |
+ uint32_t reservedIndices = count; |
| 23056 |
+ size_t genIndicesCount; |
| 23057 |
+ ANGLE_TRY(AllocateBufferFromPool(this, reservedIndices, &mPrimitiveRestartBuffer, &genIdxBuffer, |
| 23058 |
+ &genIdxBufferOffset)); |
| 23059 |
+ switch (mode) |
| 23060 |
+ { |
| 23061 |
+ case gl::PrimitiveMode::Points: |
| 23062 |
+ ANGLE_TRY(getDisplay()->getUtils().generatePrimitiveRestartPointsBuffer( |
| 23063 |
+ this, {type, count, indices, genIdxBuffer, genIdxBufferOffset, true}, |
| 23064 |
+ &genIndicesCount)); |
| 23065 |
+ break; |
| 23066 |
+ case gl::PrimitiveMode::Lines: |
| 23067 |
+ ANGLE_TRY(getDisplay()->getUtils().generatePrimitiveRestartLinesBuffer( |
| 23068 |
+ this, {type, count, indices, genIdxBuffer, genIdxBufferOffset, true}, |
| 23069 |
+ &genIndicesCount)); |
| 23070 |
+ break; |
| 23071 |
+ case gl::PrimitiveMode::Triangles: |
| 23072 |
+ ANGLE_TRY(getDisplay()->getUtils().generatePrimitiveRestartTrianglesBuffer( |
| 23073 |
+ this, {type, count, indices, genIdxBuffer, genIdxBufferOffset, true}, |
| 23074 |
+ &genIndicesCount)); |
| 23075 |
+ break; |
| 23076 |
+ default: |
| 23077 |
+ UNREACHABLE(); |
| 23078 |
+ return angle::Result::Stop; |
| 23079 |
+ } |
| 23080 |
+ ANGLE_TRY(mPrimitiveRestartBuffer.commit(this)); |
| 23081 |
+ MTLPrimitiveType mtlType = mtl::GetPrimitiveType(mode); |
| 23082 |
+ if (mState.isTransformFeedbackActiveUnpaused()) |
| 23083 |
+ { |
| 23084 |
+ ANGLE_TRY(setupDraw(context, mode, 0, count, instances, type, |
| 23085 |
+ reinterpret_cast<const void *>(0), true)); |
| 23086 |
+ |
| 23087 |
+ execDrawIndexedInstanced(mtlType, (uint32_t)genIndicesCount, MTLIndexTypeUInt32, |
| 23088 |
+ genIdxBuffer, genIdxBufferOffset, instances); |
| 23089 |
+ } |
| 23090 |
+ ANGLE_TRY(setupDraw(context, mode, 0, count, instances, type, indices, false)); |
| 23091 |
+ |
| 23092 |
+ execDrawIndexedInstanced(mtlType, (uint32_t)genIndicesCount, MTLIndexTypeUInt32, genIdxBuffer, |
| 23093 |
+ genIdxBufferOffset, instances); |
| 23094 |
+ |
| 23095 |
+ return angle::Result::Continue; |
| 23096 |
+} |
| 23097 |
|
| 23098 |
angle::Result ContextMtl::drawElementsImpl(const gl::Context *context, |
| 23099 |
gl::PrimitiveMode mode, |
| 23100 |
@@ -563,7 +642,6 @@ bool IsTransformFeedbackOnly(const gl::State &glState) |
| 23101 |
{ |
| 23102 |
// Real instances count. Zero means this is not instanced draw. |
| 23103 |
GLsizei instanceCount = instances ? instances : 1; |
| 23104 |
- |
| 23105 |
if (mCullAllPolygons && gl::IsPolygonMode(mode)) |
| 23106 |
{ |
| 23107 |
return angle::Result::Continue; |
| 23108 |
@@ -577,18 +655,39 @@ bool IsTransformFeedbackOnly(const gl::State &glState) |
| 23109 |
{ |
| 23110 |
return drawLineLoopElements(context, count, type, indices, instanceCount); |
| 23111 |
} |
| 23112 |
- |
| 23113 |
mtl::BufferRef idxBuffer; |
| 23114 |
size_t convertedOffset = 0; |
| 23115 |
gl::DrawElementsType convertedType = type; |
| 23116 |
+ size_t convertedCount = (size_t)count; |
| 23117 |
|
| 23118 |
- ANGLE_TRY(mVertexArray->getIndexBuffer(context, type, count, indices, &idxBuffer, |
| 23119 |
- &convertedOffset, &convertedType)); |
| 23120 |
+ ANGLE_TRY(mVertexArray->getIndexBuffer(context, type, mode, count, indices, &idxBuffer, |
| 23121 |
+ &convertedOffset, &convertedType, &convertedCount)); |
| 23122 |
|
| 23123 |
ASSERT(idxBuffer); |
| 23124 |
ASSERT((convertedOffset % mtl::kIndexBufferOffsetAlignment) == 0); |
| 23125 |
+ uint32_t convertedCounti32 = (uint32_t)convertedCount; |
| 23126 |
+ if (mState.isTransformFeedbackActiveUnpaused()) |
| 23127 |
+ { |
| 23128 |
+ ANGLE_TRY(setupDraw(context, mode, 0, convertedCounti32, instances, type, indices, true)); |
| 23129 |
+ MTLPrimitiveType mtlType = mtl::GetPrimitiveType(mode); |
| 23130 |
|
| 23131 |
- ANGLE_TRY(setupDraw(context, mode, 0, count, instances, type, indices, false)); |
| 23132 |
+ MTLIndexType mtlIdxType = mtl::GetIndexType(convertedType); |
| 23133 |
+ |
| 23134 |
+ if (instances == 0) |
| 23135 |
+ { |
| 23136 |
+ // Normal draw |
| 23137 |
+ mRenderEncoder.drawIndexed(mtlType, convertedCounti32, mtlIdxType, idxBuffer, |
| 23138 |
+ convertedOffset); |
| 23139 |
+ } |
| 23140 |
+ else |
| 23141 |
+ { |
| 23142 |
+ // Instanced draw |
| 23143 |
+ execDrawIndexedInstanced(mtlType, convertedCounti32, mtlIdxType, idxBuffer, |
| 23144 |
+ convertedOffset, instanceCount); |
| 23145 |
+ } |
| 23146 |
+ } |
| 23147 |
+ |
| 23148 |
+ ANGLE_TRY(setupDraw(context, mode, 0, convertedCounti32, instances, type, indices, false)); |
| 23149 |
|
| 23150 |
MTLPrimitiveType mtlType = mtl::GetPrimitiveType(mode); |
| 23151 |
|
| 23152 |
@@ -597,12 +696,13 @@ bool IsTransformFeedbackOnly(const gl::State &glState) |
| 23153 |
if (instances == 0) |
| 23154 |
{ |
| 23155 |
// Normal draw |
| 23156 |
- mRenderEncoder.drawIndexed(mtlType, count, mtlIdxType, idxBuffer, convertedOffset); |
| 23157 |
+ mRenderEncoder.drawIndexed(mtlType, convertedCounti32, mtlIdxType, idxBuffer, |
| 23158 |
+ convertedOffset); |
| 23159 |
} |
| 23160 |
else |
| 23161 |
{ |
| 23162 |
// Instanced draw |
| 23163 |
- mRenderEncoder.drawIndexedInstanced(mtlType, count, mtlIdxType, idxBuffer, convertedOffset, |
| 23164 |
+ execDrawIndexedInstanced(mtlType, convertedCounti32, mtlIdxType, idxBuffer, convertedOffset, |
| 23165 |
instanceCount); |
| 23166 |
} |
| 23167 |
|
| 23168 |
@@ -625,7 +725,6 @@ bool IsTransformFeedbackOnly(const gl::State &glState) |
| 23169 |
const void *indices, |
| 23170 |
GLint baseVertex) |
| 23171 |
{ |
| 23172 |
- // NOTE(hqle): ES 3.2 |
| 23173 |
UNIMPLEMENTED(); |
| 23174 |
return angle::Result::Stop; |
| 23175 |
} |
| 23176 |
@@ -649,10 +748,9 @@ bool IsTransformFeedbackOnly(const gl::State &glState) |
| 23177 |
GLsizei count, |
| 23178 |
gl::DrawElementsType type, |
| 23179 |
const void *indices, |
| 23180 |
- GLsizei instanceCount, |
| 23181 |
+ GLsizei instances, |
| 23182 |
GLint baseVertex) |
| 23183 |
{ |
| 23184 |
- // NOTE(hqle): ES 3.2 |
| 23185 |
UNIMPLEMENTED(); |
| 23186 |
return angle::Result::Stop; |
| 23187 |
} |
| 23188 |
@@ -669,7 +767,6 @@ bool IsTransformFeedbackOnly(const gl::State &glState) |
| 23189 |
UNIMPLEMENTED(); |
| 23190 |
return angle::Result::Stop; |
| 23191 |
} |
| 23192 |
- |
| 23193 |
angle::Result ContextMtl::drawRangeElements(const gl::Context *context, |
| 23194 |
gl::PrimitiveMode mode, |
| 23195 |
GLuint start, |
| 23196 |
@@ -690,7 +787,6 @@ bool IsTransformFeedbackOnly(const gl::State &glState) |
| 23197 |
const void *indices, |
| 23198 |
GLint baseVertex) |
| 23199 |
{ |
| 23200 |
- // NOTE(hqle): ES 3.2 |
| 23201 |
UNIMPLEMENTED(); |
| 23202 |
return angle::Result::Stop; |
| 23203 |
} |
| 23204 |
@@ -713,6 +809,64 @@ bool IsTransformFeedbackOnly(const gl::State &glState) |
| 23205 |
return angle::Result::Stop; |
| 23206 |
} |
| 23207 |
|
| 23208 |
+void ContextMtl::execDrawInstanced(MTLPrimitiveType primitiveType, |
| 23209 |
+ uint32_t vertexStart, |
| 23210 |
+ uint32_t vertexCount, |
| 23211 |
+ uint32_t instances) |
| 23212 |
+{ |
| 23213 |
+ if (getDisplay()->getFeatures().hasBaseVertexInstancedDraw.enabled) |
| 23214 |
+ { |
| 23215 |
+ mRenderEncoder.drawInstanced(primitiveType, vertexStart, vertexCount, instances); |
| 23216 |
+ } |
| 23217 |
+ else |
| 23218 |
+ { |
| 23219 |
+ mRenderEncoder.draw(primitiveType, vertexStart, vertexCount); |
| 23220 |
+ for (uint32_t inst = 1; inst < instances; ++inst) |
| 23221 |
+ { |
| 23222 |
+ mDriverUniforms.emulatedInstanceID = inst; |
| 23223 |
+ |
| 23224 |
+ mRenderEncoder.setVertexData(mDriverUniforms, mtl::kDriverUniformsBindingIndex); |
| 23225 |
+ |
| 23226 |
+ mVertexArray->emulateInstanceDrawStep(&mRenderEncoder, inst); |
| 23227 |
+ |
| 23228 |
+ mRenderEncoder.draw(primitiveType, vertexStart, vertexCount); |
| 23229 |
+ } |
| 23230 |
+ // Reset instance ID to zero |
| 23231 |
+ mVertexArray->emulateInstanceDrawStep(&mRenderEncoder, 0); |
| 23232 |
+ } |
| 23233 |
+} |
| 23234 |
+ |
| 23235 |
+void ContextMtl::execDrawIndexedInstanced(MTLPrimitiveType primitiveType, |
| 23236 |
+ uint32_t indexCount, |
| 23237 |
+ MTLIndexType indexType, |
| 23238 |
+ const mtl::BufferRef &indexBuffer, |
| 23239 |
+ size_t bufferOffset, |
| 23240 |
+ uint32_t instances) |
| 23241 |
+{ |
| 23242 |
+ if (getDisplay()->getFeatures().hasBaseVertexInstancedDraw.enabled) |
| 23243 |
+ { |
| 23244 |
+ mRenderEncoder.drawIndexedInstanced(primitiveType, indexCount, indexType, indexBuffer, |
| 23245 |
+ bufferOffset, instances); |
| 23246 |
+ } |
| 23247 |
+ else |
| 23248 |
+ { |
| 23249 |
+ mRenderEncoder.drawIndexed(primitiveType, indexCount, indexType, indexBuffer, bufferOffset); |
| 23250 |
+ for (uint32_t inst = 1; inst < instances; ++inst) |
| 23251 |
+ { |
| 23252 |
+ mDriverUniforms.emulatedInstanceID = inst; |
| 23253 |
+ |
| 23254 |
+ mRenderEncoder.setVertexData(mDriverUniforms, mtl::kDriverUniformsBindingIndex); |
| 23255 |
+ |
| 23256 |
+ mVertexArray->emulateInstanceDrawStep(&mRenderEncoder, inst); |
| 23257 |
+ |
| 23258 |
+ mRenderEncoder.drawIndexed(primitiveType, indexCount, indexType, indexBuffer, |
| 23259 |
+ bufferOffset); |
| 23260 |
+ } |
| 23261 |
+ // Reset instance ID to zero |
| 23262 |
+ mVertexArray->emulateInstanceDrawStep(&mRenderEncoder, 0); |
| 23263 |
+ } |
| 23264 |
+} |
| 23265 |
+ |
| 23266 |
angle::Result ContextMtl::multiDrawArrays(const gl::Context *context, |
| 23267 |
gl::PrimitiveMode mode, |
| 23268 |
const GLint *firsts, |
| 23269 |
@@ -802,15 +956,15 @@ bool IsTransformFeedbackOnly(const gl::State &glState) |
| 23270 |
// EXT_debug_marker |
| 23271 |
angle::Result ContextMtl::insertEventMarker(GLsizei length, const char *marker) |
| 23272 |
{ |
| 23273 |
+ mCmdBuffer.insertDebugSign(ConvertMarkerToCpp(length, marker)); |
| 23274 |
return angle::Result::Continue; |
| 23275 |
} |
| 23276 |
|
| 23277 |
angle::Result ContextMtl::pushGroupMarker(GLsizei length, const char *marker) |
| 23278 |
{ |
| 23279 |
- mCmdBuffer.pushDebugGroup(ConvertMarkerToString(length, marker)); |
| 23280 |
+ mCmdBuffer.pushDebugGroup(ConvertMarkerToCpp(length, marker)); |
| 23281 |
return angle::Result::Continue; |
| 23282 |
} |
| 23283 |
- |
| 23284 |
angle::Result ContextMtl::popGroupMarker() |
| 23285 |
{ |
| 23286 |
mCmdBuffer.popDebugGroup(); |
| 23287 |
@@ -1155,10 +1309,12 @@ bool IsTransformFeedbackOnly(const gl::State &glState) |
| 23288 |
{ |
| 23289 |
return new QueryMtl(type); |
| 23290 |
} |
| 23291 |
+ |
| 23292 |
FenceNVImpl *ContextMtl::createFenceNV() |
| 23293 |
{ |
| 23294 |
return new FenceNVMtl(); |
| 23295 |
} |
| 23296 |
+ |
| 23297 |
SyncImpl *ContextMtl::createSync() |
| 23298 |
{ |
| 23299 |
return new SyncMtl(); |
| 23300 |
@@ -1205,6 +1361,69 @@ bool IsTransformFeedbackOnly(const gl::State &glState) |
| 23301 |
return nullptr; |
| 23302 |
} |
| 23303 |
|
| 23304 |
+void ContextMtl::invalidateCurrentTransformFeedbackBuffers() |
| 23305 |
+{ |
| 23306 |
+ if (getDisplay()->getFeatures().emulateTransformFeedback.enabled) |
| 23307 |
+ { |
| 23308 |
+ mDirtyBits.set(DIRTY_BIT_TRANSFORM_FEEDBACK_BUFFERS); |
| 23309 |
+ } |
| 23310 |
+} |
| 23311 |
+ |
| 23312 |
+void ContextMtl::onTransformFeedbackStateChanged() |
| 23313 |
+{ |
| 23314 |
+ if (getDisplay()->getFeatures().emulateTransformFeedback.enabled) |
| 23315 |
+ { |
| 23316 |
+ invalidateDriverUniforms(); |
| 23317 |
+ } |
| 23318 |
+} |
| 23319 |
+ |
| 23320 |
+angle::Result ContextMtl::onBeginTransformFeedback( |
| 23321 |
+ size_t bufferCount, |
| 23322 |
+ const gl::TransformFeedbackBuffersArray<BufferMtl *> &buffers) |
| 23323 |
+{ |
| 23324 |
+ onTransformFeedbackStateChanged(); |
| 23325 |
+ |
| 23326 |
+ for (size_t bufferIndex = 0; bufferIndex < bufferCount; ++bufferIndex) |
| 23327 |
+ { |
| 23328 |
+ if (mCurrentTransformFeedbackBuffers.count(buffers[bufferIndex]) != 0) |
| 23329 |
+ { |
| 23330 |
+ endEncoding(mRenderEncoder); |
| 23331 |
+ break; |
| 23332 |
+ } |
| 23333 |
+ } |
| 23334 |
+ |
| 23335 |
+ populateTransformFeedbackBufferSet(bufferCount, buffers); |
| 23336 |
+ |
| 23337 |
+ return angle::Result::Continue; |
| 23338 |
+} |
| 23339 |
+ |
| 23340 |
+void ContextMtl::populateTransformFeedbackBufferSet( |
| 23341 |
+ size_t bufferCount, |
| 23342 |
+ const gl::TransformFeedbackBuffersArray<BufferMtl *> &buffers) |
| 23343 |
+{ |
| 23344 |
+ for (size_t bufferIndex = 0; bufferIndex < bufferCount; ++bufferIndex) |
| 23345 |
+ { |
| 23346 |
+ mCurrentTransformFeedbackBuffers.insert(buffers[bufferIndex]); |
| 23347 |
+ } |
| 23348 |
+} |
| 23349 |
+ |
| 23350 |
+void ContextMtl::onEndTransformFeedback() |
| 23351 |
+{ |
| 23352 |
+ if (getDisplay()->getFeatures().emulateTransformFeedback.enabled) |
| 23353 |
+ { |
| 23354 |
+ onTransformFeedbackStateChanged(); |
| 23355 |
+ } |
| 23356 |
+} |
| 23357 |
+ |
| 23358 |
+angle::Result ContextMtl::onPauseTransformFeedback() |
| 23359 |
+{ |
| 23360 |
+ if (getDisplay()->getFeatures().emulateTransformFeedback.enabled) |
| 23361 |
+ { |
| 23362 |
+ onTransformFeedbackStateChanged(); |
| 23363 |
+ } |
| 23364 |
+ return angle::Result::Continue; |
| 23365 |
+} |
| 23366 |
+ |
| 23367 |
angle::Result ContextMtl::dispatchCompute(const gl::Context *context, |
| 23368 |
GLuint numGroupsX, |
| 23369 |
GLuint numGroupsY, |
| 23370 |
@@ -1331,6 +1550,11 @@ bool IsTransformFeedbackOnly(const gl::State &glState) |
| 23371 |
return getDisplay()->getPixelFormat(angleFormatId); |
| 23372 |
} |
| 23373 |
|
| 23374 |
+const mtl::FormatCaps &ContextMtl::getNativeFormatCaps(MTLPixelFormat mtlFormat) const |
| 23375 |
+{ |
| 23376 |
+ return getDisplay()->getNativeFormatCaps(mtlFormat); |
| 23377 |
+} |
| 23378 |
+ |
| 23379 |
// See mtl::FormatTable::getVertexFormat() |
| 23380 |
const mtl::VertexFormat &ContextMtl::getVertexFormat(angle::FormatID angleFormatId, |
| 23381 |
bool tightlyPacked) const |
| 23382 |
@@ -1338,11 +1562,6 @@ bool IsTransformFeedbackOnly(const gl::State &glState) |
| 23383 |
return getDisplay()->getVertexFormat(angleFormatId, tightlyPacked); |
| 23384 |
} |
| 23385 |
|
| 23386 |
-const mtl::FormatCaps &ContextMtl::getNativeFormatCaps(MTLPixelFormat mtlFormat) const |
| 23387 |
-{ |
| 23388 |
- return getDisplay()->getNativeFormatCaps(mtlFormat); |
| 23389 |
-} |
| 23390 |
- |
| 23391 |
angle::Result ContextMtl::getIncompleteTexture(const gl::Context *context, |
| 23392 |
gl::TextureType type, |
| 23393 |
gl::Texture **textureOut) |
| 23394 |
@@ -1362,6 +1581,22 @@ bool IsTransformFeedbackOnly(const gl::State &glState) |
| 23395 |
|
| 23396 |
// Resolve visibility results |
| 23397 |
mOcclusionQueryPool.resolveVisibilityResults(this); |
| 23398 |
+ |
| 23399 |
+ mCurrentTransformFeedbackBuffers.clear(); |
| 23400 |
+ |
| 23401 |
+ // Reset serials for XFB if active. |
| 23402 |
+ if (mState.isTransformFeedbackActiveUnpaused()) |
| 23403 |
+ { |
| 23404 |
+ const gl::ProgramExecutable *executable = mState.getProgramExecutable(); |
| 23405 |
+ ASSERT(executable); |
| 23406 |
+ size_t xfbBufferCount = executable->getTransformFeedbackBufferCount(); |
| 23407 |
+ |
| 23408 |
+ TransformFeedbackMtl *transformFeedbackMtl = |
| 23409 |
+ mtl::GetImpl(mState.getCurrentTransformFeedback()); |
| 23410 |
+ |
| 23411 |
+ populateTransformFeedbackBufferSet(xfbBufferCount, |
| 23412 |
+ transformFeedbackMtl->getBufferHandles()); |
| 23413 |
+ } |
| 23414 |
} |
| 23415 |
|
| 23416 |
void ContextMtl::endEncoding(bool forceSaveRenderPassContent) |
| 23417 |
@@ -1390,7 +1625,7 @@ bool IsTransformFeedbackOnly(const gl::State &glState) |
| 23418 |
|
| 23419 |
void ContextMtl::flushCommandBufer() |
| 23420 |
{ |
| 23421 |
- if (!mCmdBuffer.ready()) |
| 23422 |
+ if (!mCmdBuffer.valid()) |
| 23423 |
{ |
| 23424 |
return; |
| 23425 |
} |
| 23426 |
@@ -1454,6 +1689,27 @@ bool IsTransformFeedbackOnly(const gl::State &glState) |
| 23427 |
// Need to re-apply everything on next draw call. |
| 23428 |
mDirtyBits.set(); |
| 23429 |
|
| 23430 |
+ id<MTLDevice> metalDevice = getDisplay()->getMetalDevice(); |
| 23431 |
+ if (mtl::DeviceHasMaximumRenderTargetSize(metalDevice)) |
| 23432 |
+ { |
| 23433 |
+ MTLRenderPassDescriptor *objCDesc = [MTLRenderPassDescriptor renderPassDescriptor]; |
| 23434 |
+ desc.convertToMetalDesc(objCDesc); |
| 23435 |
+ NSUInteger maxSize = mtl::GetMaxRenderTargetSizeForDeviceInBytes(metalDevice); |
| 23436 |
+ NSUInteger renderTargetSize = |
| 23437 |
+ ComputeTotalSizeUsedForMTLRenderPassDescriptor(objCDesc, this, metalDevice); |
| 23438 |
+ if (renderTargetSize > maxSize) |
| 23439 |
+ { |
| 23440 |
+ NSString *errorString = |
| 23441 |
+ [NSString stringWithFormat:@"This set of render targets requires %lu bytes of " |
| 23442 |
+ @"pixel storage. This device supports %lu bytes.", |
| 23443 |
+ renderTargetSize, maxSize]; |
| 23444 |
+ NSError *err = [NSError errorWithDomain:@"MTLValidationError" |
| 23445 |
+ code:-1 |
| 23446 |
+ userInfo:@{NSLocalizedDescriptionKey : errorString}]; |
| 23447 |
+ this->handleError(err, __FILE__, ANGLE_FUNCTION, __LINE__); |
| 23448 |
+ return nil; |
| 23449 |
+ } |
| 23450 |
+ } |
| 23451 |
return &mRenderEncoder.restart(desc); |
| 23452 |
} |
| 23453 |
|
| 23454 |
@@ -1467,9 +1723,10 @@ bool IsTransformFeedbackOnly(const gl::State &glState) |
| 23455 |
|
| 23456 |
mtl::RenderPassDesc rpDesc; |
| 23457 |
|
| 23458 |
- rpDesc.colorAttachments[0].texture = textureTarget; |
| 23459 |
- rpDesc.colorAttachments[0].level = index.getNativeLevel(); |
| 23460 |
- rpDesc.colorAttachments[0].sliceOrDepth = index.hasLayer() ? index.getLayerIndex() : 0; |
| 23461 |
+ rpDesc.colorAttachments[0].renderTarget->texture = textureTarget; |
| 23462 |
+ rpDesc.colorAttachments[0].renderTarget->level = index.getNativeLevel(); |
| 23463 |
+ rpDesc.colorAttachments[0].renderTarget->sliceOrDepth = |
| 23464 |
+ index.hasLayer() ? index.getLayerIndex() : 0; |
| 23465 |
rpDesc.numColorAttachments = 1; |
| 23466 |
rpDesc.sampleCount = textureTarget->samples(); |
| 23467 |
|
| 23468 |
@@ -1536,12 +1793,12 @@ bool IsTransformFeedbackOnly(const gl::State &glState) |
| 23469 |
|
| 23470 |
void ContextMtl::ensureCommandBufferReady() |
| 23471 |
{ |
| 23472 |
- if (!mCmdBuffer.ready()) |
| 23473 |
+ if (!mCmdBuffer.valid()) |
| 23474 |
{ |
| 23475 |
mCmdBuffer.restart(); |
| 23476 |
} |
| 23477 |
|
| 23478 |
- ASSERT(mCmdBuffer.ready()); |
| 23479 |
+ ASSERT(mCmdBuffer.valid()); |
| 23480 |
} |
| 23481 |
|
| 23482 |
void ContextMtl::updateViewport(FramebufferMtl *framebufferMtl, |
| 23483 |
@@ -1677,7 +1934,7 @@ bool IsTransformFeedbackOnly(const gl::State &glState) |
| 23484 |
} |
| 23485 |
} |
| 23486 |
|
| 23487 |
-void ContextMtl::onBackbufferResized(const gl::Context *context, WindowSurfaceMtl *backbuffer) |
| 23488 |
+void ContextMtl::onBackbufferResized(const gl::Context *context, SurfaceMtlProtocol *backbuffer) |
| 23489 |
{ |
| 23490 |
const gl::State &glState = getState(); |
| 23491 |
FramebufferMtl *framebuffer = mtl::GetImpl(glState.getDrawFramebuffer()); |
| 23492 |
@@ -1686,10 +1943,13 @@ bool IsTransformFeedbackOnly(const gl::State &glState) |
| 23493 |
return; |
| 23494 |
} |
| 23495 |
|
| 23496 |
+ updateViewport(framebuffer, glState.getViewport(), glState.getNearPlane(), |
| 23497 |
+ glState.getFarPlane()); |
| 23498 |
+ updateScissor(glState); |
| 23499 |
onDrawFrameBufferChangedState(context, framebuffer, true); |
| 23500 |
} |
| 23501 |
|
| 23502 |
-angle::Result ContextMtl::onOcclusionQueryBegin(const gl::Context *context, QueryMtl *query) |
| 23503 |
+angle::Result ContextMtl::onOcclusionQueryBegan(const gl::Context *context, QueryMtl *query) |
| 23504 |
{ |
| 23505 |
ASSERT(mOcclusionQuery == nullptr); |
| 23506 |
mOcclusionQuery = query; |
| 23507 |
@@ -1706,7 +1966,7 @@ bool IsTransformFeedbackOnly(const gl::State &glState) |
| 23508 |
|
| 23509 |
return angle::Result::Continue; |
| 23510 |
} |
| 23511 |
-void ContextMtl::onOcclusionQueryEnd(const gl::Context *context, QueryMtl *query) |
| 23512 |
+void ContextMtl::onOcclusionQueryEnded(const gl::Context *context, QueryMtl *query) |
| 23513 |
{ |
| 23514 |
ASSERT(mOcclusionQuery == query); |
| 23515 |
|
| 23516 |
@@ -1718,7 +1978,7 @@ bool IsTransformFeedbackOnly(const gl::State &glState) |
| 23517 |
|
| 23518 |
mOcclusionQuery = nullptr; |
| 23519 |
} |
| 23520 |
-void ContextMtl::onOcclusionQueryDestroy(const gl::Context *context, QueryMtl *query) |
| 23521 |
+void ContextMtl::onOcclusionQueryDestroyed(const gl::Context *context, QueryMtl *query) |
| 23522 |
{ |
| 23523 |
if (query->getAllocatedVisibilityOffsets().empty()) |
| 23524 |
{ |
| 23525 |
@@ -1726,7 +1986,7 @@ bool IsTransformFeedbackOnly(const gl::State &glState) |
| 23526 |
} |
| 23527 |
if (mOcclusionQuery == query) |
| 23528 |
{ |
| 23529 |
- onOcclusionQueryEnd(context, query); |
| 23530 |
+ onOcclusionQueryEnded(context, query); |
| 23531 |
} |
| 23532 |
mOcclusionQueryPool.deallocateQueryOffset(this, query); |
| 23533 |
} |
| 23534 |
@@ -1770,20 +2030,6 @@ bool IsTransformFeedbackOnly(const gl::State &glState) |
| 23535 |
return angle::Result::Continue; |
| 23536 |
} |
| 23537 |
|
| 23538 |
-void ContextMtl::onTransformFeedbackActive(const gl::Context *context, TransformFeedbackMtl *xfb) |
| 23539 |
-{ |
| 23540 |
- // NOTE(hqle): We have to end current render pass to enable synchronization before XFB |
| 23541 |
- // buffers could be used as vertex input. Consider a better approach. |
| 23542 |
- endEncoding(true); |
| 23543 |
-} |
| 23544 |
- |
| 23545 |
-void ContextMtl::onTransformFeedbackInactive(const gl::Context *context, TransformFeedbackMtl *xfb) |
| 23546 |
-{ |
| 23547 |
- // NOTE(hqle): We have to end current render pass to enable synchronization before XFB |
| 23548 |
- // buffers could be used as vertex input. Consider a better approach. |
| 23549 |
- endEncoding(true); |
| 23550 |
-} |
| 23551 |
- |
| 23552 |
void ContextMtl::queueEventSignal(const mtl::SharedEventRef &event, uint64_t value) |
| 23553 |
{ |
| 23554 |
ensureCommandBufferReady(); |
| 23555 |
@@ -1842,10 +2088,19 @@ bool IsTransformFeedbackOnly(const gl::State &glState) |
| 23556 |
GLsizei instances, |
| 23557 |
gl::DrawElementsType indexTypeOrNone, |
| 23558 |
const void *indices, |
| 23559 |
- bool xfbPass) |
| 23560 |
+ bool transformFeedbackDraw) |
| 23561 |
{ |
| 23562 |
ASSERT(mProgram); |
| 23563 |
|
| 23564 |
+ // Update transform feedback offsets on every draw call. |
| 23565 |
+ if (mState.isTransformFeedbackActiveUnpaused()) |
| 23566 |
+ { |
| 23567 |
+ ASSERT(firstVertex != -1); |
| 23568 |
+ mXfbBaseVertex = firstVertex; |
| 23569 |
+ mXfbVertexCountPerInstance = vertexOrIndexCount; |
| 23570 |
+ invalidateDriverUniforms(); |
| 23571 |
+ } |
| 23572 |
+ |
| 23573 |
// instances=0 means no instanced draw. |
| 23574 |
GLsizei instanceCount = instances ? instances : 1; |
| 23575 |
|
| 23576 |
@@ -1862,20 +2117,6 @@ bool IsTransformFeedbackOnly(const gl::State &glState) |
| 23577 |
ANGLE_TRY(handleDirtyActiveTextures(context)); |
| 23578 |
} |
| 23579 |
|
| 23580 |
- if (mDirtyBits.test(DIRTY_BIT_RASTERIZER_DISCARD)) |
| 23581 |
- { |
| 23582 |
- if (getState().isTransformFeedbackActiveUnpaused()) |
| 23583 |
- { |
| 23584 |
- // If XFB is active we need to reset render pass since we could use a dummy render |
| 23585 |
- // target if only XFB is needed. |
| 23586 |
- invalidateState(context); |
| 23587 |
- } |
| 23588 |
- else |
| 23589 |
- { |
| 23590 |
- invalidateRenderPipeline(); |
| 23591 |
- } |
| 23592 |
- } |
| 23593 |
- |
| 23594 |
if (!mRenderEncoder.valid()) |
| 23595 |
{ |
| 23596 |
// re-apply everything |
| 23597 |
@@ -1884,7 +2125,11 @@ bool IsTransformFeedbackOnly(const gl::State &glState) |
| 23598 |
|
| 23599 |
if (mDirtyBits.test(DIRTY_BIT_DRAW_FRAMEBUFFER)) |
| 23600 |
{ |
| 23601 |
- ANGLE_TRY(handleDirtyRenderPass(context)); |
| 23602 |
+ // Start new render command encoder |
| 23603 |
+ ANGLE_MTL_TRY(this, mDrawFramebuffer->ensureRenderPassStarted(context)); |
| 23604 |
+ |
| 23605 |
+ // re-apply everything |
| 23606 |
+ invalidateState(context); |
| 23607 |
} |
| 23608 |
|
| 23609 |
if (mOcclusionQuery && mOcclusionQueryPool.getNumRenderPassAllocatedQueries() == 0) |
| 23610 |
@@ -1894,17 +2139,11 @@ bool IsTransformFeedbackOnly(const gl::State &glState) |
| 23611 |
ANGLE_TRY(startOcclusionQueryInRenderPass(mOcclusionQuery, false)); |
| 23612 |
} |
| 23613 |
|
| 23614 |
- bool isPipelineDescChanged; |
| 23615 |
- ANGLE_TRY(checkIfPipelineChanged(context, mode, xfbPass, &isPipelineDescChanged)); |
| 23616 |
+ bool changedPipeline; |
| 23617 |
+ ANGLE_TRY(checkIfPipelineChanged(context, mode, mState.isTransformFeedbackActive(), |
| 23618 |
+ &changedPipeline)); |
| 23619 |
|
| 23620 |
bool uniformBuffersDirty = false; |
| 23621 |
- |
| 23622 |
- if (IsTransformFeedbackOnly(getState())) |
| 23623 |
- { |
| 23624 |
- // Filter out unneeded dirty bits |
| 23625 |
- filterOutXFBOnlyDirtyBits(context); |
| 23626 |
- } |
| 23627 |
- |
| 23628 |
for (size_t bit : mDirtyBits) |
| 23629 |
{ |
| 23630 |
switch (bit) |
| 23631 |
@@ -1953,8 +2192,10 @@ bool IsTransformFeedbackOnly(const gl::State &glState) |
| 23632 |
case DIRTY_BIT_UNIFORM_BUFFERS_BINDING: |
| 23633 |
uniformBuffersDirty = true; |
| 23634 |
break; |
| 23635 |
+ case DIRTY_BIT_TRANSFORM_FEEDBACK_BUFFERS: |
| 23636 |
+ ANGLE_TRY(handleDirtyGraphicsTransformFeedbackBuffersEmulation(context)); |
| 23637 |
+ break; |
| 23638 |
case DIRTY_BIT_RASTERIZER_DISCARD: |
| 23639 |
- // Already handled. |
| 23640 |
break; |
| 23641 |
default: |
| 23642 |
UNREACHABLE(); |
| 23643 |
@@ -1962,71 +2203,20 @@ bool IsTransformFeedbackOnly(const gl::State &glState) |
| 23644 |
} |
| 23645 |
} |
| 23646 |
|
| 23647 |
- if (xfbPass && !mDirtyBits.test(DIRTY_BIT_DRIVER_UNIFORMS)) |
| 23648 |
- { |
| 23649 |
- // If handleDirtyDriverUniforms() was not called and this is XFB pass, we still need to |
| 23650 |
- // update XFB related uniforms |
| 23651 |
- ANGLE_TRY( |
| 23652 |
- fillDriverXFBUniforms(firstVertex, vertexOrIndexCount, /** skippedInstances */ 0)); |
| 23653 |
- mRenderEncoder.setVertexData(mDriverUniforms, mtl::kDriverUniformsBindingIndex); |
| 23654 |
- } |
| 23655 |
- |
| 23656 |
mDirtyBits.reset(); |
| 23657 |
|
| 23658 |
- ANGLE_TRY(mProgram->setupDraw(context, &mRenderEncoder, mRenderPipelineDesc, |
| 23659 |
- isPipelineDescChanged, textureChanged, uniformBuffersDirty)); |
| 23660 |
- |
| 23661 |
- return angle::Result::Continue; |
| 23662 |
-} |
| 23663 |
- |
| 23664 |
-void ContextMtl::filterOutXFBOnlyDirtyBits(const gl::Context *context) |
| 23665 |
-{ |
| 23666 |
- ASSERT(IsTransformFeedbackOnly(getState())); |
| 23667 |
- |
| 23668 |
- ASSERT(mRenderEncoder.renderPassDesc().colorAttachments[0].texture == mDummyXFBRenderTexture); |
| 23669 |
- |
| 23670 |
- // In transform feedback only pass, only vertex shader's related states are needed. |
| 23671 |
- constexpr size_t kUnneededBits = |
| 23672 |
- angle::Bit<size_t>(DIRTY_BIT_DEPTH_STENCIL_DESC) | |
| 23673 |
- angle::Bit<size_t>(DIRTY_BIT_DEPTH_BIAS) | angle::Bit<size_t>(DIRTY_BIT_STENCIL_REF) | |
| 23674 |
- angle::Bit<size_t>(DIRTY_BIT_BLEND_COLOR) | angle::Bit<size_t>(DIRTY_BIT_VIEWPORT) | |
| 23675 |
- angle::Bit<size_t>(DIRTY_BIT_SCISSOR) | angle::Bit<size_t>(DIRTY_BIT_CULL_MODE) | |
| 23676 |
- angle::Bit<size_t>(DIRTY_BIT_WINDING); |
| 23677 |
- |
| 23678 |
- mDirtyBits &= ~kUnneededBits; |
| 23679 |
-} |
| 23680 |
- |
| 23681 |
-angle::Result ContextMtl::handleDirtyRenderPass(const gl::Context *context) |
| 23682 |
-{ |
| 23683 |
- if (!IsTransformFeedbackOnly(mState)) |
| 23684 |
+ if (transformFeedbackDraw) |
| 23685 |
{ |
| 23686 |
- // Start new render command encoder |
| 23687 |
- ANGLE_MTL_TRY(this, mDrawFramebuffer->ensureRenderPassStarted(context)); |
| 23688 |
- } |
| 23689 |
- else |
| 23690 |
- { |
| 23691 |
- // XFB is active and rasterization is disabled. Use dummy render target. |
| 23692 |
- // We currently need to end the render pass when XFB is activated/deactivated so using |
| 23693 |
- // a small dummy render target would make the render pass ending very cheap. |
| 23694 |
- if (!mDummyXFBRenderTexture) |
| 23695 |
- { |
| 23696 |
- ANGLE_TRY(mtl::Texture::Make2DTexture(this, |
| 23697 |
- getPixelFormat(angle::FormatID::R8G8B8A8_UNORM), |
| 23698 |
- 1, 1, 1, true, false, &mDummyXFBRenderTexture)); |
| 23699 |
- } |
| 23700 |
- mtl::RenderCommandEncoder *encoder = getTextureRenderCommandEncoder( |
| 23701 |
- mDummyXFBRenderTexture, |
| 23702 |
- mtl::ImageNativeIndex::FromBaseZeroGLIndex(gl::ImageIndex::Make2D(0))); |
| 23703 |
- encoder->setColorLoadAction(MTLLoadActionDontCare, MTLClearColor(), 0); |
| 23704 |
- encoder->setColorStoreAction(MTLStoreActionDontCare); |
| 23705 |
- |
| 23706 |
-#ifndef NDEBUG |
| 23707 |
- encoder->setLabel(@"TransformFeedbackOnlyPass"); |
| 23708 |
-#endif |
| 23709 |
+ mtl::RenderUtils &utils = getDisplay()->getUtils(); |
| 23710 |
+ angle::Result result = |
| 23711 |
+ utils.createTransformFeedbackPSO(context, &mRenderEncoder, mRenderPipelineDesc); |
| 23712 |
+ ANGLE_UNUSED_VARIABLE(result); |
| 23713 |
+ assert(result == angle::Result::Continue); |
| 23714 |
+ changedPipeline = true; |
| 23715 |
} |
| 23716 |
|
| 23717 |
- // re-apply everything |
| 23718 |
- invalidateState(context); |
| 23719 |
+ ANGLE_TRY(mProgram->setupDraw(context, &mRenderEncoder, mRenderPipelineDesc, changedPipeline, |
| 23720 |
+ textureChanged, uniformBuffersDirty, transformFeedbackDraw)); |
| 23721 |
|
| 23722 |
return angle::Result::Continue; |
| 23723 |
} |
| 23724 |
@@ -2034,10 +2224,10 @@ bool IsTransformFeedbackOnly(const gl::State &glState) |
| 23725 |
angle::Result ContextMtl::handleDirtyActiveTextures(const gl::Context *context) |
| 23726 |
{ |
| 23727 |
const gl::State &glState = mState; |
| 23728 |
- const gl::Program *program = glState.getProgram(); |
| 23729 |
+ const gl::ProgramExecutable *executable = context->getState().getProgramExecutable(); |
| 23730 |
|
| 23731 |
const gl::ActiveTexturesCache &textures = glState.getActiveTexturesCache(); |
| 23732 |
- const gl::ActiveTextureMask &activeTextures = program->getExecutable().getActiveSamplersMask(); |
| 23733 |
+ const gl::ActiveTextureMask &activeTextures = executable->getActiveSamplersMask(); |
| 23734 |
|
| 23735 |
for (size_t textureUnit : activeTextures) |
| 23736 |
{ |
| 23737 |
@@ -2067,6 +2257,7 @@ bool IsTransformFeedbackOnly(const gl::State &glState) |
| 23738 |
} |
| 23739 |
|
| 23740 |
ASSERT(mRenderEncoder.valid()); |
| 23741 |
+ mRenderEncoder.setFragmentData(mDefaultAttributes, mtl::kDefaultAttribsBindingIndex); |
| 23742 |
mRenderEncoder.setVertexData(mDefaultAttributes, mtl::kDefaultAttribsBindingIndex); |
| 23743 |
|
| 23744 |
mDirtyDefaultAttribsMask.reset(); |
| 23745 |
@@ -2120,9 +2311,6 @@ bool IsTransformFeedbackOnly(const gl::State &glState) |
| 23746 |
} |
| 23747 |
mDriverUniforms.coverageMask = coverageMask; |
| 23748 |
|
| 23749 |
- ANGLE_TRY( |
| 23750 |
- fillDriverXFBUniforms(drawCallFirstVertex, verticesPerInstance, /** skippedInstances */ 0)); |
| 23751 |
- |
| 23752 |
ASSERT(mRenderEncoder.valid()); |
| 23753 |
mRenderEncoder.setFragmentData(mDriverUniforms, mtl::kDriverUniformsBindingIndex); |
| 23754 |
mRenderEncoder.setVertexData(mDriverUniforms, mtl::kDriverUniformsBindingIndex); |
| 23755 |
@@ -2130,25 +2318,33 @@ bool IsTransformFeedbackOnly(const gl::State &glState) |
| 23756 |
return angle::Result::Continue; |
| 23757 |
} |
| 23758 |
|
| 23759 |
-angle::Result ContextMtl::fillDriverXFBUniforms(GLint drawCallFirstVertex, |
| 23760 |
- uint32_t verticesPerInstance, |
| 23761 |
- uint32_t skippedInstances) |
| 23762 |
+angle::Result ContextMtl::handleDirtyGraphicsTransformFeedbackBuffersEmulation( |
| 23763 |
+ const gl::Context *context) |
| 23764 |
{ |
| 23765 |
- gl::TransformFeedback *transformFeedback = getState().getCurrentTransformFeedback(); |
| 23766 |
+ const gl::ProgramExecutable *executable = mState.getProgramExecutable(); |
| 23767 |
+ ASSERT(executable); |
| 23768 |
|
| 23769 |
- mDriverUniforms.xfbActiveUnpaused = getState().isTransformFeedbackActiveUnpaused(); |
| 23770 |
- if (!transformFeedback || !mDriverUniforms.xfbActiveUnpaused) |
| 23771 |
+ if (!executable->hasTransformFeedbackOutput() || !mState.isTransformFeedbackActive()) |
| 23772 |
{ |
| 23773 |
return angle::Result::Continue; |
| 23774 |
} |
| 23775 |
|
| 23776 |
- mDriverUniforms.xfbVerticesPerDraw = verticesPerInstance; |
| 23777 |
+ TransformFeedbackMtl *transformFeedbackMtl = mtl::GetImpl(mState.getCurrentTransformFeedback()); |
| 23778 |
+ size_t bufferCount = executable->getTransformFeedbackBufferCount(); |
| 23779 |
+ const gl::TransformFeedbackBuffersArray<BufferMtl *> &bufferHandles = |
| 23780 |
+ transformFeedbackMtl->getBufferHandles(); |
| 23781 |
|
| 23782 |
- TransformFeedbackMtl *transformFeedbackMtl = mtl::GetImpl(transformFeedback); |
| 23783 |
+ for (size_t bufferIndex = 0; bufferIndex < bufferCount; ++bufferIndex) |
| 23784 |
+ { |
| 23785 |
+ BufferMtl *bufferHandle = bufferHandles[bufferIndex]; |
| 23786 |
+ ASSERT(bufferHandle); |
| 23787 |
+ ASSERT(mRenderEncoder.valid()); |
| 23788 |
+ mRenderEncoder.setBufferForWrite( |
| 23789 |
+ gl::ShaderType::Vertex, bufferHandle->getCurrentBuffer(), 0, |
| 23790 |
+ mtl::kTransformFeedbackBindingIndex + (uint32_t)bufferIndex); |
| 23791 |
+ } |
| 23792 |
|
| 23793 |
- return transformFeedbackMtl->getBufferOffsets(this, drawCallFirstVertex, |
| 23794 |
- verticesPerInstance * skippedInstances, |
| 23795 |
- mDriverUniforms.xfbBufferOffsets); |
| 23796 |
+ return angle::Result::Continue; |
| 23797 |
} |
| 23798 |
|
| 23799 |
angle::Result ContextMtl::handleDirtyDepthStencilState(const gl::Context *context) |
| 23800 |
@@ -2159,13 +2355,13 @@ bool IsTransformFeedbackOnly(const gl::State &glState) |
| 23801 |
mtl::DepthStencilDesc dsDesc = mDepthStencilDesc; |
| 23802 |
const mtl::RenderPassDesc &renderPassDesc = mRenderEncoder.renderPassDesc(); |
| 23803 |
|
| 23804 |
- if (!renderPassDesc.depthAttachment.texture) |
| 23805 |
+ if (!renderPassDesc.depthAttachment.texture()) |
| 23806 |
{ |
| 23807 |
dsDesc.depthWriteEnabled = false; |
| 23808 |
dsDesc.depthCompareFunction = MTLCompareFunctionAlways; |
| 23809 |
} |
| 23810 |
|
| 23811 |
- if (!renderPassDesc.stencilAttachment.texture) |
| 23812 |
+ if (!renderPassDesc.stencilAttachment.texture()) |
| 23813 |
{ |
| 23814 |
dsDesc.frontFaceStencil.reset(); |
| 23815 |
dsDesc.backFaceStencil.reset(); |
| 23816 |
@@ -2196,8 +2392,8 @@ bool IsTransformFeedbackOnly(const gl::State &glState) |
| 23817 |
|
| 23818 |
angle::Result ContextMtl::checkIfPipelineChanged(const gl::Context *context, |
| 23819 |
gl::PrimitiveMode primitiveMode, |
| 23820 |
- bool xfbPass, |
| 23821 |
- bool *isPipelineDescChanged) |
| 23822 |
+ bool xbfPass, |
| 23823 |
+ bool *pipelineDescChanged) |
| 23824 |
{ |
| 23825 |
ASSERT(mRenderEncoder.valid()); |
| 23826 |
mtl::PrimitiveTopologyClass topologyClass = mtl::GetPrimitiveTopologyClass(primitiveMode); |
| 23827 |
@@ -2216,24 +2412,10 @@ bool IsTransformFeedbackOnly(const gl::State &glState) |
| 23828 |
renderPassDesc.populateRenderPipelineOutputDesc(mBlendDesc, |
| 23829 |
&mRenderPipelineDesc.outputDescriptor); |
| 23830 |
|
| 23831 |
- if (xfbPass) |
| 23832 |
- { |
| 23833 |
- // In XFB pass, we disable fragment shader. |
| 23834 |
- mRenderPipelineDesc.rasterizationType = mtl::RenderPipelineRasterization::Disabled; |
| 23835 |
- } |
| 23836 |
- else if (mState.isRasterizerDiscardEnabled()) |
| 23837 |
- { |
| 23838 |
- // If XFB is not active and rasterizer discard is enabled, we need to emulate the |
| 23839 |
- // discard. Because in this case, vertex shader might write to stage output values and |
| 23840 |
- // Metal doesn't allow rasterization to be disabled. |
| 23841 |
- mRenderPipelineDesc.rasterizationType = |
| 23842 |
- mtl::RenderPipelineRasterization::EmulatedDiscard; |
| 23843 |
- } |
| 23844 |
- else |
| 23845 |
- { |
| 23846 |
- mRenderPipelineDesc.rasterizationType = mtl::RenderPipelineRasterization::Enabled; |
| 23847 |
- } |
| 23848 |
mRenderPipelineDesc.inputPrimitiveTopology = topologyClass; |
| 23849 |
+ mRenderPipelineDesc.rasterizationType = |
| 23850 |
+ (mState.isRasterizerDiscardEnabled() ? mtl::RenderPipelineRasterization::EmulatedDiscard |
| 23851 |
+ : mtl::RenderPipelineRasterization::Enabled); |
| 23852 |
mRenderPipelineDesc.alphaToCoverageEnabled = mState.isSampleAlphaToCoverageEnabled(); |
| 23853 |
mRenderPipelineDesc.emulateCoverageMask = mState.isSampleCoverageEnabled(); |
| 23854 |
|
| 23855 |
@@ -2241,7 +2423,7 @@ bool IsTransformFeedbackOnly(const gl::State &glState) |
| 23856 |
mDrawFramebuffer->getState().getEnabledDrawBuffers()); |
| 23857 |
} |
| 23858 |
|
| 23859 |
- *isPipelineDescChanged = rppChange; |
| 23860 |
+ *pipelineDescChanged = rppChange; |
| 23861 |
|
| 23862 |
return angle::Result::Continue; |
| 23863 |
} |
| 23864 |
diff --git a/src/libANGLE/renderer/metal/DisplayMtl.h b/src/libANGLE/renderer/metal/DisplayMtl.h |
| 23865 |
index b00de1b..2417122 100644 |
| 23866 |
--- a/src/libANGLE/renderer/metal/DisplayMtl.h |
| 23867 |
+++ b/src/libANGLE/renderer/metal/DisplayMtl.h |
| 23868 |
@@ -52,6 +52,10 @@ class DisplayMtl : public DisplayImpl |
| 23869 |
|
| 23870 |
egl::Error waitClient(const gl::Context *context) override; |
| 23871 |
egl::Error waitNative(const gl::Context *context, EGLint engine) override; |
| 23872 |
+ egl::Error validateClientBuffer(const egl::Config *configuration, |
| 23873 |
+ EGLenum buftype, |
| 23874 |
+ EGLClientBuffer clientBuffer, |
| 23875 |
+ const egl::AttributeMap &attribs) const override; |
| 23876 |
|
| 23877 |
SurfaceImpl *createWindowSurface(const egl::SurfaceState &state, |
| 23878 |
EGLNativeWindowType window, |
| 23879 |
@@ -96,11 +100,6 @@ class DisplayMtl : public DisplayImpl |
| 23880 |
|
| 23881 |
bool isValidNativeWindow(EGLNativeWindowType window) const override; |
| 23882 |
|
| 23883 |
- egl::Error validateClientBuffer(const egl::Config *configuration, |
| 23884 |
- EGLenum buftype, |
| 23885 |
- EGLClientBuffer clientBuffer, |
| 23886 |
- const egl::AttributeMap &attribs) const override; |
| 23887 |
- |
| 23888 |
egl::ConfigSet generateConfigs() override; |
| 23889 |
|
| 23890 |
std::string getRendererDescription() const; |
| 23891 |
@@ -165,6 +164,8 @@ class DisplayMtl : public DisplayImpl |
| 23892 |
void initializeExtensions() const; |
| 23893 |
void initializeTextureCaps() const; |
| 23894 |
void initializeFeatures(); |
| 23895 |
+ void initializeLimitations(); |
| 23896 |
+ |
| 23897 |
angle::Result initializeShaderLibrary(); |
| 23898 |
|
| 23899 |
mtl::AutoObjCPtr<id<MTLDevice>> mMetalDevice = nil; |
| 23900 |
diff --git a/src/libANGLE/renderer/metal/DisplayMtl.mm b/src/libANGLE/renderer/metal/DisplayMtl.mm |
| 23901 |
index 247d76a..c159c05 100644 |
| 23902 |
--- a/src/libANGLE/renderer/metal/DisplayMtl.mm |
| 23903 |
+++ b/src/libANGLE/renderer/metal/DisplayMtl.mm |
| 23904 |
@@ -8,12 +8,14 @@ |
| 23905 |
|
| 23906 |
#include "libANGLE/renderer/metal/DisplayMtl.h" |
| 23907 |
|
| 23908 |
+#include "common/system_utils.h" |
| 23909 |
#include "gpu_info_util/SystemInfo.h" |
| 23910 |
#include "libANGLE/Context.h" |
| 23911 |
#include "libANGLE/Display.h" |
| 23912 |
#include "libANGLE/Surface.h" |
| 23913 |
#include "libANGLE/renderer/glslang_wrapper_utils.h" |
| 23914 |
#include "libANGLE/renderer/metal/ContextMtl.h" |
| 23915 |
+#include "libANGLE/renderer/metal/IOSurfaceSurfaceMtl.h" |
| 23916 |
#include "libANGLE/renderer/metal/SurfaceMtl.h" |
| 23917 |
#include "libANGLE/renderer/metal/SyncMtl.h" |
| 23918 |
#include "libANGLE/renderer/metal/mtl_common.h" |
| 23919 |
@@ -22,9 +24,62 @@ |
| 23920 |
|
| 23921 |
#include "EGL/eglext.h" |
| 23922 |
|
| 23923 |
+#if defined(ANGLE_PLATFORM_MACOS) || defined(ANGLE_PLATFORM_MACCATALYST) |
| 23924 |
+constexpr char kANGLEPreferredDeviceEnv[] = "ANGLE_PREFERRED_DEVICE"; |
| 23925 |
+#endif |
| 23926 |
+constexpr char kANGLETransformFeedbackEnv[] = "ANGLE_METAL_XFB_ENABLE"; |
| 23927 |
+ |
| 23928 |
namespace rx |
| 23929 |
{ |
| 23930 |
|
| 23931 |
+static EGLint GetDepthSize(GLint internalformat) |
| 23932 |
+{ |
| 23933 |
+ switch (internalformat) |
| 23934 |
+ { |
| 23935 |
+ case GL_STENCIL_INDEX8: |
| 23936 |
+ return 0; |
| 23937 |
+ case GL_DEPTH_COMPONENT16: |
| 23938 |
+ return 16; |
| 23939 |
+ case GL_DEPTH_COMPONENT24: |
| 23940 |
+ return 24; |
| 23941 |
+ case GL_DEPTH_COMPONENT32_OES: |
| 23942 |
+ return 32; |
| 23943 |
+ case GL_DEPTH_COMPONENT32F: |
| 23944 |
+ return 32; |
| 23945 |
+ case GL_DEPTH24_STENCIL8: |
| 23946 |
+ return 24; |
| 23947 |
+ case GL_DEPTH32F_STENCIL8: |
| 23948 |
+ return 32; |
| 23949 |
+ default: |
| 23950 |
+ // UNREACHABLE(internalformat); |
| 23951 |
+ return 0; |
| 23952 |
+ } |
| 23953 |
+} |
| 23954 |
+ |
| 23955 |
+static EGLint GetStencilSize(GLint internalformat) |
| 23956 |
+{ |
| 23957 |
+ switch (internalformat) |
| 23958 |
+ { |
| 23959 |
+ case GL_STENCIL_INDEX8: |
| 23960 |
+ return 8; |
| 23961 |
+ case GL_DEPTH_COMPONENT16: |
| 23962 |
+ return 0; |
| 23963 |
+ case GL_DEPTH_COMPONENT24: |
| 23964 |
+ return 0; |
| 23965 |
+ case GL_DEPTH_COMPONENT32_OES: |
| 23966 |
+ return 0; |
| 23967 |
+ case GL_DEPTH_COMPONENT32F: |
| 23968 |
+ return 0; |
| 23969 |
+ case GL_DEPTH24_STENCIL8: |
| 23970 |
+ return 8; |
| 23971 |
+ case GL_DEPTH32F_STENCIL8: |
| 23972 |
+ return 8; |
| 23973 |
+ default: |
| 23974 |
+ // UNREACHABLE(internalformat); |
| 23975 |
+ return 0; |
| 23976 |
+ } |
| 23977 |
+} |
| 23978 |
+ |
| 23979 |
bool IsMetalDisplayAvailable() |
| 23980 |
{ |
| 23981 |
// We only support macos 10.13+ and 11 for now. Since they are requirements for Metal 2.0. |
| 23982 |
@@ -57,7 +112,7 @@ bool IsMetalDisplayAvailable() |
| 23983 |
}; |
| 23984 |
|
| 23985 |
DisplayMtl::DisplayMtl(const egl::DisplayState &state) |
| 23986 |
- : DisplayImpl(state), mUtils(this), mGlslangInitialized(false) |
| 23987 |
+ : DisplayImpl(state), mStateCache(mFeatures), mUtils(this) |
| 23988 |
{} |
| 23989 |
|
| 23990 |
DisplayMtl::~DisplayMtl() {} |
| 23991 |
@@ -78,10 +133,27 @@ bool IsMetalDisplayAvailable() |
| 23992 |
{ |
| 23993 |
ANGLE_MTL_OBJC_SCOPE |
| 23994 |
{ |
| 23995 |
- mMetalDevice = [MTLCreateSystemDefaultDevice() ANGLE_MTL_AUTORELEASE]; |
| 23996 |
+#if defined(ANGLE_PLATFORM_MACOS) || defined(ANGLE_PLATFORM_MACCATALYST) |
| 23997 |
+ const std::string anglePreferredDevice = angle::GetEnvironmentVar(kANGLEPreferredDeviceEnv); |
| 23998 |
+ if (anglePreferredDevice != "") |
| 23999 |
+ { |
| 24000 |
+ NSArray<id<MTLDevice>> *devices = [MTLCopyAllDevices() ANGLE_MTL_AUTORELEASE]; |
| 24001 |
+ for (id<MTLDevice> device in devices) |
| 24002 |
+ { |
| 24003 |
+ if ([device.name.lowercaseString |
| 24004 |
+ containsString:[NSString stringWithUTF8String:anglePreferredDevice.c_str()] |
| 24005 |
+ .lowercaseString]) |
| 24006 |
+ { |
| 24007 |
+ NSLog(@"Using Metal Device: %@", [device name]); |
| 24008 |
+ mMetalDevice = [device ANGLE_MTL_AUTORELEASE]; |
| 24009 |
+ break; |
| 24010 |
+ } |
| 24011 |
+ } |
| 24012 |
+ } |
| 24013 |
+#endif |
| 24014 |
if (!mMetalDevice) |
| 24015 |
{ |
| 24016 |
- return angle::Result::Stop; |
| 24017 |
+ mMetalDevice = [MTLCreateSystemDefaultDevice() ANGLE_MTL_AUTORELEASE]; |
| 24018 |
} |
| 24019 |
|
| 24020 |
mMetalDeviceVendorId = mtl::GetDeviceVendorId(mMetalDevice); |
| 24021 |
@@ -89,12 +161,13 @@ bool IsMetalDisplayAvailable() |
| 24022 |
mCmdQueue.set([[mMetalDevice.get() newCommandQueue] ANGLE_MTL_AUTORELEASE]); |
| 24023 |
|
| 24024 |
mCapsInitialized = false; |
| 24025 |
- |
| 24026 |
+#if ANGLE_ENABLE_METAL_SPIRV |
| 24027 |
if (!mGlslangInitialized) |
| 24028 |
{ |
| 24029 |
GlslangInitialize(); |
| 24030 |
mGlslangInitialized = true; |
| 24031 |
} |
| 24032 |
+#endif |
| 24033 |
|
| 24034 |
if (!mState.featuresAllDisabled) |
| 24035 |
{ |
| 24036 |
@@ -120,12 +193,13 @@ bool IsMetalDisplayAvailable() |
| 24037 |
mCapsInitialized = false; |
| 24038 |
|
| 24039 |
mMetalDeviceVendorId = 0; |
| 24040 |
- |
| 24041 |
+#if ANGLE_ENABLE_METAL_SPIRV |
| 24042 |
if (mGlslangInitialized) |
| 24043 |
{ |
| 24044 |
GlslangRelease(); |
| 24045 |
mGlslangInitialized = false; |
| 24046 |
} |
| 24047 |
+#endif |
| 24048 |
} |
| 24049 |
|
| 24050 |
bool DisplayMtl::testDeviceLost() |
| 24051 |
@@ -171,6 +245,15 @@ bool IsMetalDisplayAvailable() |
| 24052 |
return egl::NoError(); |
| 24053 |
} |
| 24054 |
|
| 24055 |
+egl::Error DisplayMtl::validateClientBuffer(const egl::Config *configuration, |
| 24056 |
+ EGLenum buftype, |
| 24057 |
+ EGLClientBuffer clientBuffer, |
| 24058 |
+ const egl::AttributeMap &attribs) const |
| 24059 |
+{ |
| 24060 |
+ // TODO: Fill out properly |
| 24061 |
+ return egl::NoError(); |
| 24062 |
+} |
| 24063 |
+ |
| 24064 |
egl::Error DisplayMtl::waitNative(const gl::Context *context, EGLint engine) |
| 24065 |
{ |
| 24066 |
UNIMPLEMENTED(); |
| 24067 |
@@ -187,7 +270,8 @@ bool IsMetalDisplayAvailable() |
| 24068 |
SurfaceImpl *DisplayMtl::createPbufferSurface(const egl::SurfaceState &state, |
| 24069 |
const egl::AttributeMap &attribs) |
| 24070 |
{ |
| 24071 |
- return new PBufferSurfaceMtl(this, state, attribs); |
| 24072 |
+ UNIMPLEMENTED(); |
| 24073 |
+ return static_cast<SurfaceImpl *>(0); |
| 24074 |
} |
| 24075 |
|
| 24076 |
SurfaceImpl *DisplayMtl::createPbufferFromClientBuffer(const egl::SurfaceState &state, |
| 24077 |
@@ -195,15 +279,7 @@ bool IsMetalDisplayAvailable() |
| 24078 |
EGLClientBuffer clientBuffer, |
| 24079 |
const egl::AttributeMap &attribs) |
| 24080 |
{ |
| 24081 |
- switch (buftype) |
| 24082 |
- { |
| 24083 |
- case EGL_IOSURFACE_ANGLE: |
| 24084 |
return new IOSurfaceSurfaceMtl(this, state, clientBuffer, attribs); |
| 24085 |
- break; |
| 24086 |
- default: |
| 24087 |
- UNREACHABLE(); |
| 24088 |
- } |
| 24089 |
- return nullptr; |
| 24090 |
} |
| 24091 |
|
| 24092 |
SurfaceImpl *DisplayMtl::createPixmapSurface(const egl::SurfaceState &state, |
| 24093 |
@@ -240,17 +316,12 @@ bool IsMetalDisplayAvailable() |
| 24094 |
return nullptr; |
| 24095 |
} |
| 24096 |
|
| 24097 |
-ShareGroupImpl *DisplayMtl::createShareGroup() |
| 24098 |
-{ |
| 24099 |
- return new ShareGroupMtl(); |
| 24100 |
-} |
| 24101 |
- |
| 24102 |
gl::Version DisplayMtl::getMaxSupportedESVersion() const |
| 24103 |
{ |
| 24104 |
// NOTE(hqle): Supports GLES 3.0 on iOS GPU family 4+ for now. |
| 24105 |
if (supportsEitherGPUFamily(4, 1)) |
| 24106 |
{ |
| 24107 |
- return mtl::kMaxSupportedGLVersion; |
| 24108 |
+ return gl::Version(3, 0); |
| 24109 |
} |
| 24110 |
return gl::Version(2, 0); |
| 24111 |
} |
| 24112 |
@@ -265,6 +336,11 @@ bool IsMetalDisplayAvailable() |
| 24113 |
return new EGLSyncMtl(attribs); |
| 24114 |
} |
| 24115 |
|
| 24116 |
+ShareGroupImpl *DisplayMtl::createShareGroup() |
| 24117 |
+{ |
| 24118 |
+ return new ShareGroupImpl(); |
| 24119 |
+} |
| 24120 |
+ |
| 24121 |
egl::Error DisplayMtl::makeCurrent(egl::Display *display, |
| 24122 |
egl::Surface *drawSurface, |
| 24123 |
egl::Surface *readSurface, |
| 24124 |
@@ -326,7 +402,7 @@ bool IsMetalDisplayAvailable() |
| 24125 |
config.transparentType = EGL_NONE; |
| 24126 |
|
| 24127 |
// Pbuffer |
| 24128 |
- config.bindToTextureTarget = EGL_TEXTURE_2D; |
| 24129 |
+ config.bindToTextureTarget = EGL_TEXTURE_RECTANGLE_ANGLE; |
| 24130 |
config.maxPBufferWidth = 4096; |
| 24131 |
config.maxPBufferHeight = 4096; |
| 24132 |
config.maxPBufferPixels = 4096 * 4096; |
| 24133 |
@@ -361,13 +437,6 @@ bool IsMetalDisplayAvailable() |
| 24134 |
|
| 24135 |
config.colorComponentType = EGL_COLOR_COMPONENT_TYPE_FIXED_EXT; |
| 24136 |
|
| 24137 |
- constexpr int samplesSupported[] = {0, 4}; |
| 24138 |
- |
| 24139 |
- for (int samples : samplesSupported) |
| 24140 |
- { |
| 24141 |
- config.samples = samples; |
| 24142 |
- config.sampleBuffers = (samples == 0) ? 0 : 1; |
| 24143 |
- |
| 24144 |
// Buffer sizes |
| 24145 |
config.redSize = 8; |
| 24146 |
config.greenSize = 8; |
| 24147 |
@@ -375,28 +444,12 @@ bool IsMetalDisplayAvailable() |
| 24148 |
config.alphaSize = 8; |
| 24149 |
config.bufferSize = config.redSize + config.greenSize + config.blueSize + config.alphaSize; |
| 24150 |
|
| 24151 |
- // With DS |
| 24152 |
- config.depthSize = 24; |
| 24153 |
- config.stencilSize = 8; |
| 24154 |
- |
| 24155 |
- configs.add(config); |
| 24156 |
- |
| 24157 |
- // With D |
| 24158 |
- config.depthSize = 24; |
| 24159 |
- config.stencilSize = 0; |
| 24160 |
- configs.add(config); |
| 24161 |
- |
| 24162 |
- // With S |
| 24163 |
- config.depthSize = 0; |
| 24164 |
- config.stencilSize = 8; |
| 24165 |
+ // Tests like dEQP-GLES2.functional.depth_range.* assume EGL_DEPTH_SIZE is properly set even if |
| 24166 |
+ // renderConfig attributes are set to glu::RenderConfig::DONT_CARE |
| 24167 |
+ config.depthSize = GetDepthSize(config.depthStencilFormat); |
| 24168 |
+ config.stencilSize = GetStencilSize(config.depthStencilFormat); |
| 24169 |
configs.add(config); |
| 24170 |
|
| 24171 |
- // No DS |
| 24172 |
- config.depthSize = 0; |
| 24173 |
- config.stencilSize = 0; |
| 24174 |
- configs.add(config); |
| 24175 |
- } |
| 24176 |
- |
| 24177 |
return configs; |
| 24178 |
} |
| 24179 |
|
| 24180 |
@@ -409,26 +462,6 @@ bool IsMetalDisplayAvailable() |
| 24181 |
} |
| 24182 |
} |
| 24183 |
|
| 24184 |
-egl::Error DisplayMtl::validateClientBuffer(const egl::Config *configuration, |
| 24185 |
- EGLenum buftype, |
| 24186 |
- EGLClientBuffer clientBuffer, |
| 24187 |
- const egl::AttributeMap &attribs) const |
| 24188 |
-{ |
| 24189 |
- switch (buftype) |
| 24190 |
- { |
| 24191 |
- case EGL_IOSURFACE_ANGLE: |
| 24192 |
- if (!IOSurfaceSurfaceMtl::ValidateAttributes(clientBuffer, attribs)) |
| 24193 |
- { |
| 24194 |
- return egl::EglBadAttribute(); |
| 24195 |
- } |
| 24196 |
- break; |
| 24197 |
- default: |
| 24198 |
- UNREACHABLE(); |
| 24199 |
- return egl::EglBadAttribute(); |
| 24200 |
- } |
| 24201 |
- return egl::NoError(); |
| 24202 |
-} |
| 24203 |
- |
| 24204 |
std::string DisplayMtl::getRendererDescription() const |
| 24205 |
{ |
| 24206 |
ANGLE_MTL_OBJC_SCOPE |
| 24207 |
@@ -512,10 +545,16 @@ bool IsMetalDisplayAvailable() |
| 24208 |
mNativeCaps.maxRenderbufferSize = mNativeCaps.max2DTextureSize; |
| 24209 |
mNativeCaps.minAliasedPointSize = 1; |
| 24210 |
// NOTE(hqle): Metal has some problems drawing big point size even though |
| 24211 |
- // Metal-Feature-Set-Tables.pdf says that max supported point size is 511. We limit it to 64 for |
| 24212 |
- // now. |
| 24213 |
- // http://anglebug.com/4816 |
| 24214 |
+ // Metal-Feature-Set-Tables.pdf says that max supported point size is 511. We limit it to 255 |
| 24215 |
+ // on Intel and 64 on AMD for now. |
| 24216 |
+ if ([mMetalDevice.get().name rangeOfString:@"Intel"].location != NSNotFound) |
| 24217 |
+ { |
| 24218 |
+ mNativeCaps.maxAliasedPointSize = 255; |
| 24219 |
+ } |
| 24220 |
+ else |
| 24221 |
+ { |
| 24222 |
mNativeCaps.maxAliasedPointSize = 64; |
| 24223 |
+ } |
| 24224 |
|
| 24225 |
mNativeCaps.minAliasedLineWidth = 1.0f; |
| 24226 |
mNativeCaps.maxAliasedLineWidth = 1.0f; |
| 24227 |
@@ -615,6 +654,9 @@ bool IsMetalDisplayAvailable() |
| 24228 |
mNativeCaps.maxTransformFeedbackSeparateComponents = |
| 24229 |
gl::IMPLEMENTATION_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS; |
| 24230 |
|
| 24231 |
+ // GL_OES_get_program_binary |
| 24232 |
+ mNativeCaps.programBinaryFormats.push_back(GL_PROGRAM_BINARY_ANGLE); |
| 24233 |
+ |
| 24234 |
// GL_APPLE_clip_distance |
| 24235 |
mNativeCaps.maxClipDistances = 8; |
| 24236 |
|
| 24237 |
@@ -647,6 +689,15 @@ bool IsMetalDisplayAvailable() |
| 24238 |
mNativeExtensions.textureBorderClampOES = false; // not implemented yet |
| 24239 |
mNativeExtensions.translatedShaderSource = true; |
| 24240 |
mNativeExtensions.discardFramebuffer = true; |
| 24241 |
+ // Not implemented but expose |
| 24242 |
+ mNativeExtensions.textureRectangle = true; |
| 24243 |
+ |
| 24244 |
+ // EXT_multisampled_render_to_texture |
| 24245 |
+ if (mFeatures.allowMultisampleStoreAndResolve.enabled && |
| 24246 |
+ mFeatures.hasDepthAutoResolve.enabled && mFeatures.hasStencilAutoResolve.enabled) |
| 24247 |
+ { |
| 24248 |
+ mNativeExtensions.multisampledRenderToTexture = true; |
| 24249 |
+ } |
| 24250 |
|
| 24251 |
// Enable EXT_blend_minmax |
| 24252 |
mNativeExtensions.blendMinMax = true; |
| 24253 |
@@ -662,8 +713,8 @@ bool IsMetalDisplayAvailable() |
| 24254 |
mNativeExtensions.semaphore = false; |
| 24255 |
mNativeExtensions.semaphoreFd = false; |
| 24256 |
|
| 24257 |
- mNativeExtensions.instancedArraysANGLE = mFeatures.hasBaseVertexInstancedDraw.enabled; |
| 24258 |
- mNativeExtensions.instancedArraysEXT = mNativeExtensions.instancedArraysANGLE; |
| 24259 |
+ mNativeExtensions.instancedArraysANGLE = true; |
| 24260 |
+ mNativeExtensions.instancedArraysEXT = true; |
| 24261 |
|
| 24262 |
mNativeExtensions.robustBufferAccessBehavior = false; |
| 24263 |
|
| 24264 |
@@ -686,6 +737,9 @@ bool IsMetalDisplayAvailable() |
| 24265 |
|
| 24266 |
mNativeExtensions.elementIndexUintOES = true; |
| 24267 |
|
| 24268 |
+ // GL_OES_get_program_binary |
| 24269 |
+ mNativeExtensions.getProgramBinaryOES = true; |
| 24270 |
+ |
| 24271 |
// GL_APPLE_clip_distance |
| 24272 |
mNativeExtensions.clipDistanceAPPLE = true; |
| 24273 |
|
| 24274 |
@@ -713,11 +767,17 @@ bool IsMetalDisplayAvailable() |
| 24275 |
|
| 24276 |
// Re-verify texture extensions. |
| 24277 |
mNativeExtensions.setTextureExtensionSupport(mNativeTextureCaps); |
| 24278 |
- |
| 24279 |
+ // Modify extensions based off of support |
| 24280 |
// Disable all depth buffer and stencil buffer readback extensions until we need them |
| 24281 |
mNativeExtensions.readDepthNV = false; |
| 24282 |
mNativeExtensions.readStencilNV = false; |
| 24283 |
mNativeExtensions.depthBufferFloat2NV = false; |
| 24284 |
+ mNativeExtensions.textureCompressionASTCLDRKHR &= supportsIOSGPUFamily(2); |
| 24285 |
+} |
| 24286 |
+ |
| 24287 |
+void DisplayMtl::initializeLimitations() |
| 24288 |
+{ |
| 24289 |
+ mNativeLimitations.noVertexAttributeAliasing = true; |
| 24290 |
} |
| 24291 |
|
| 24292 |
void DisplayMtl::initializeFeatures() |
| 24293 |
@@ -779,6 +839,9 @@ bool IsMetalDisplayAvailable() |
| 24294 |
ANGLE_FEATURE_CONDITION((&mFeatures), allowSeparatedDepthStencilBuffers, |
| 24295 |
!isOSX && !isCatalyst && !isSimulator); |
| 24296 |
|
| 24297 |
+ mFeatures.emulateTransformFeedback.enabled = |
| 24298 |
+ angle::GetEnvironmentVar(kANGLETransformFeedbackEnv)[0] == '1'; |
| 24299 |
+ |
| 24300 |
angle::PlatformMethods *platform = ANGLEPlatformCurrent(); |
| 24301 |
platform->overrideFeaturesMtl(platform, &mFeatures); |
| 24302 |
|
| 24303 |
@@ -787,6 +850,27 @@ bool IsMetalDisplayAvailable() |
| 24304 |
|
| 24305 |
angle::Result DisplayMtl::initializeShaderLibrary() |
| 24306 |
{ |
| 24307 |
+ #ifdef ANGLE_METAL_XCODE_BUILDS_SHADERS |
| 24308 |
+ mDefaultShadersAsyncInfo.reset(new DefaultShaderAsyncInfoMtl); |
| 24309 |
+ |
| 24310 |
+ |
| 24311 |
+ NSString *path = [NSBundle bundleWithIdentifier:@"com.apple.WebKit"].bundlePath; |
| 24312 |
+ NSError * error = nullptr; |
| 24313 |
+ mDefaultShadersAsyncInfo->defaultShaders = [getMetalDevice() newDefaultLibraryWithBundle:[NSBundle bundleWithPath:path] error:&error]; |
| 24314 |
+ |
| 24315 |
+ if (error && !mDefaultShadersAsyncInfo->defaultShaders) |
| 24316 |
+ { |
| 24317 |
+ ANGLE_MTL_OBJC_SCOPE |
| 24318 |
+ { |
| 24319 |
+ ERR() << "Internal error: newDefaultLibraryWithBundle failed. " << error.localizedDescription.UTF8String; |
| 24320 |
+ } |
| 24321 |
+ mDefaultShadersAsyncInfo->defaultShadersCompileError = std::move(error); |
| 24322 |
+ return angle::Result::Stop; |
| 24323 |
+ |
| 24324 |
+ } |
| 24325 |
+ mDefaultShadersAsyncInfo->compiled = true; |
| 24326 |
+ |
| 24327 |
+ #else |
| 24328 |
mDefaultShadersAsyncInfo.reset(new DefaultShaderAsyncInfoMtl); |
| 24329 |
|
| 24330 |
// Create references to async info struct since it might be released in terminate(), but the |
| 24331 |
@@ -815,7 +899,7 @@ bool IsMetalDisplayAvailable() |
| 24332 |
|
| 24333 |
[nsSource ANGLE_MTL_AUTORELEASE]; |
| 24334 |
} |
| 24335 |
- |
| 24336 |
+ #endif |
| 24337 |
return angle::Result::Continue; |
| 24338 |
} |
| 24339 |
|
| 24340 |
diff --git a/src/libANGLE/renderer/metal/FrameBufferMtl.h b/src/libANGLE/renderer/metal/FrameBufferMtl.h |
| 24341 |
index b458bd9..5e5cce9 100644 |
| 24342 |
--- a/src/libANGLE/renderer/metal/FrameBufferMtl.h |
| 24343 |
+++ b/src/libANGLE/renderer/metal/FrameBufferMtl.h |
| 24344 |
@@ -23,12 +23,14 @@ namespace mtl |
| 24345 |
class RenderCommandEncoder; |
| 24346 |
} // namespace mtl |
| 24347 |
class ContextMtl; |
| 24348 |
-class WindowSurfaceMtl; |
| 24349 |
+class SurfaceMtl; |
| 24350 |
|
| 24351 |
class FramebufferMtl : public FramebufferImpl |
| 24352 |
{ |
| 24353 |
public: |
| 24354 |
- FramebufferMtl(const gl::FramebufferState &state, bool flipY, WindowSurfaceMtl *backbuffer); |
| 24355 |
+ explicit FramebufferMtl(const gl::FramebufferState &state, |
| 24356 |
+ bool flipY, |
| 24357 |
+ SurfaceMtlProtocol *backbuffer); |
| 24358 |
~FramebufferMtl() override; |
| 24359 |
void destroy(const gl::Context *context) override; |
| 24360 |
|
| 24361 |
@@ -97,7 +99,7 @@ class FramebufferMtl : public FramebufferImpl |
| 24362 |
|
| 24363 |
gl::Rectangle getCompleteRenderArea() const; |
| 24364 |
int getSamples() const; |
| 24365 |
- WindowSurfaceMtl *getAttachedBackbuffer() const { return mBackbuffer; } |
| 24366 |
+ SurfaceMtlProtocol *getAttachedBackbuffer() const { return mBackbuffer; } |
| 24367 |
|
| 24368 |
bool renderPassHasStarted(ContextMtl *contextMtl) const; |
| 24369 |
mtl::RenderCommandEncoder *ensureRenderPassStarted(const gl::Context *context); |
| 24370 |
@@ -162,6 +164,10 @@ class FramebufferMtl : public FramebufferImpl |
| 24371 |
mtl::RenderCommandEncoder *ensureRenderPassStarted(const gl::Context *context, |
| 24372 |
const mtl::RenderPassDesc &desc); |
| 24373 |
|
| 24374 |
+ void overrideClearColor(const mtl::TextureRef &texture, |
| 24375 |
+ MTLClearColor clearColor, |
| 24376 |
+ MTLClearColor *colorOut); |
| 24377 |
+ |
| 24378 |
angle::Result updateColorRenderTarget(const gl::Context *context, size_t colorIndexGL); |
| 24379 |
angle::Result updateDepthRenderTarget(const gl::Context *context); |
| 24380 |
angle::Result updateStencilRenderTarget(const gl::Context *context); |
| 24381 |
@@ -169,11 +175,37 @@ class FramebufferMtl : public FramebufferImpl |
| 24382 |
const gl::FramebufferAttachment *attachment, |
| 24383 |
RenderTargetMtl **cachedRenderTarget); |
| 24384 |
|
| 24385 |
+ // This function either returns the render target's texture itself if the texture is readable |
| 24386 |
+ // or create a copy of that texture that is readable if not. This function is typically used |
| 24387 |
+ // for packed depth stencil where reading stencil requires a stencil view. However if a texture |
| 24388 |
+ // has both render target, pixel format view & shader readable usage flags, there will be |
| 24389 |
+ // some glitches happen in Metal framework. |
| 24390 |
+ // So the solution is creating a depth stencil texture without pixel format view flag but has |
| 24391 |
+ // render target flag, then during blitting process, this texture is copied to another |
| 24392 |
+ // intermidiate texture having pixel format view flag, but not render target flag. |
| 24393 |
+ angle::Result getReadableViewForRenderTarget(const gl::Context *context, |
| 24394 |
+ const RenderTargetMtl &rtt, |
| 24395 |
+ const gl::Rectangle &readArea, |
| 24396 |
+ mtl::TextureRef *readableDepthView, |
| 24397 |
+ mtl::TextureRef *readableStencilView, |
| 24398 |
+ uint32_t *readableViewLevel, |
| 24399 |
+ uint32_t *readableViewLayer, |
| 24400 |
+ gl::Rectangle *readableViewArea); |
| 24401 |
+ |
| 24402 |
angle::Result readPixelsToPBO(const gl::Context *context, |
| 24403 |
const gl::Rectangle &area, |
| 24404 |
const PackPixelsParams &packPixelsParams, |
| 24405 |
const RenderTargetMtl *renderTarget) const; |
| 24406 |
|
| 24407 |
+ angle::Result readPixelsToBuffer(const gl::Context *context, |
| 24408 |
+ const gl::Rectangle &area, |
| 24409 |
+ const RenderTargetMtl *renderTarget, |
| 24410 |
+ bool reverseRowOrder, |
| 24411 |
+ const angle::Format &dstAngleFormat, |
| 24412 |
+ uint32_t dstBufferOffset, |
| 24413 |
+ uint32_t dstBufferRowPitch, |
| 24414 |
+ const mtl::BufferRef *dstBuffer) const; |
| 24415 |
+ |
| 24416 |
// NOTE: we cannot use RenderTargetCache here because it doesn't support separate |
| 24417 |
// depth & stencil attachments as of now. Separate depth & stencil could be useful to |
| 24418 |
// save spaces on iOS devices. See doc/PackedDepthStencilSupport.md. |
| 24419 |
@@ -189,8 +221,10 @@ class FramebufferMtl : public FramebufferImpl |
| 24420 |
// as by a compute pass. |
| 24421 |
bool mRenderPassCleanStart = false; |
| 24422 |
|
| 24423 |
- WindowSurfaceMtl *mBackbuffer = nullptr; |
| 24424 |
+ SurfaceMtlProtocol *mBackbuffer = nullptr; |
| 24425 |
const bool mFlipY = false; |
| 24426 |
+ |
| 24427 |
+ mtl::BufferRef mReadPixelBuffer; |
| 24428 |
}; |
| 24429 |
} // namespace rx |
| 24430 |
|
| 24431 |
diff --git a/src/libANGLE/renderer/metal/FrameBufferMtl.mm b/src/libANGLE/renderer/metal/FrameBufferMtl.mm |
| 24432 |
index 84e4227..d71de72 100644 |
| 24433 |
--- a/src/libANGLE/renderer/metal/FrameBufferMtl.mm |
| 24434 |
+++ b/src/libANGLE/renderer/metal/FrameBufferMtl.mm |
| 24435 |
@@ -33,12 +33,30 @@ void OverrideMTLClearColor(const mtl::TextureRef &texture, |
| 24436 |
*colorOut = |
| 24437 |
mtl::EmulatedAlphaClearColor(clearColor.toMTLClearColor(), texture->getColorWritableMask()); |
| 24438 |
} |
| 24439 |
+ |
| 24440 |
+const gl::InternalFormat &GetReadAttachmentInfo(const gl::Context *context, |
| 24441 |
+ RenderTargetMtl *renderTarget) |
| 24442 |
+{ |
| 24443 |
+ GLenum implFormat; |
| 24444 |
+ |
| 24445 |
+ if (renderTarget && renderTarget->getFormat()) |
| 24446 |
+ { |
| 24447 |
+ implFormat = renderTarget->getFormat()->actualAngleFormat().fboImplementationInternalFormat; |
| 24448 |
+ } |
| 24449 |
+ else |
| 24450 |
+ { |
| 24451 |
+ implFormat = GL_NONE; |
| 24452 |
+ } |
| 24453 |
+ |
| 24454 |
+ return gl::GetSizedInternalFormatInfo(implFormat); |
| 24455 |
+} |
| 24456 |
+ |
| 24457 |
} |
| 24458 |
|
| 24459 |
// FramebufferMtl implementation |
| 24460 |
FramebufferMtl::FramebufferMtl(const gl::FramebufferState &state, |
| 24461 |
bool flipY, |
| 24462 |
- WindowSurfaceMtl *backbuffer) |
| 24463 |
+ SurfaceMtlProtocol *backbuffer) |
| 24464 |
: FramebufferImpl(state), mBackbuffer(backbuffer), mFlipY(flipY) |
| 24465 |
{ |
| 24466 |
reset(); |
| 24467 |
@@ -55,6 +73,8 @@ void OverrideMTLClearColor(const mtl::TextureRef &texture, |
| 24468 |
mDepthRenderTarget = mStencilRenderTarget = nullptr; |
| 24469 |
|
| 24470 |
mRenderPassFirstColorAttachmentFormat = nullptr; |
| 24471 |
+ |
| 24472 |
+ mReadPixelBuffer = nullptr; |
| 24473 |
} |
| 24474 |
|
| 24475 |
void FramebufferMtl::destroy(const gl::Context *context) |
| 24476 |
@@ -122,7 +142,6 @@ void OverrideMTLClearColor(const mtl::TextureRef &texture, |
| 24477 |
const GLfloat *values) |
| 24478 |
{ |
| 24479 |
mtl::ClearRectParams clearOpts; |
| 24480 |
- |
| 24481 |
gl::DrawBufferMask clearColorBuffers; |
| 24482 |
if (buffer == GL_DEPTH) |
| 24483 |
{ |
| 24484 |
@@ -133,7 +152,6 @@ void OverrideMTLClearColor(const mtl::TextureRef &texture, |
| 24485 |
clearColorBuffers.set(drawbuffer); |
| 24486 |
clearOpts.clearColor = mtl::ClearColorValue(values[0], values[1], values[2], values[3]); |
| 24487 |
} |
| 24488 |
- |
| 24489 |
return clearImpl(context, clearColorBuffers, &clearOpts); |
| 24490 |
} |
| 24491 |
angle::Result FramebufferMtl::clearBufferuiv(const gl::Context *context, |
| 24492 |
@@ -146,7 +164,6 @@ void OverrideMTLClearColor(const mtl::TextureRef &texture, |
| 24493 |
|
| 24494 |
mtl::ClearRectParams clearOpts; |
| 24495 |
clearOpts.clearColor = mtl::ClearColorValue(values[0], values[1], values[2], values[3]); |
| 24496 |
- |
| 24497 |
return clearImpl(context, clearColorBuffers, &clearOpts); |
| 24498 |
} |
| 24499 |
angle::Result FramebufferMtl::clearBufferiv(const gl::Context *context, |
| 24500 |
@@ -159,7 +176,7 @@ void OverrideMTLClearColor(const mtl::TextureRef &texture, |
| 24501 |
gl::DrawBufferMask clearColorBuffers; |
| 24502 |
if (buffer == GL_STENCIL) |
| 24503 |
{ |
| 24504 |
- clearOpts.clearStencil = values[0] & mtl::kStencilMaskAll; |
| 24505 |
+ clearOpts.clearStencil = gl::clamp(values[0], 0, static_cast<GLint>(mtl::kStencilMaskAll)); |
| 24506 |
} |
| 24507 |
else |
| 24508 |
{ |
| 24509 |
@@ -177,7 +194,7 @@ void OverrideMTLClearColor(const mtl::TextureRef &texture, |
| 24510 |
{ |
| 24511 |
mtl::ClearRectParams clearOpts; |
| 24512 |
clearOpts.clearDepth = depth; |
| 24513 |
- clearOpts.clearStencil = stencil & mtl::kStencilMaskAll; |
| 24514 |
+ clearOpts.clearStencil = gl::clamp(stencil, 0, static_cast<GLint>(mtl::kStencilMaskAll)); |
| 24515 |
|
| 24516 |
return clearImpl(context, gl::DrawBufferMask(), &clearOpts); |
| 24517 |
} |
| 24518 |
@@ -185,12 +202,7 @@ void OverrideMTLClearColor(const mtl::TextureRef &texture, |
| 24519 |
const gl::InternalFormat &FramebufferMtl::getImplementationColorReadFormat( |
| 24520 |
const gl::Context *context) const |
| 24521 |
{ |
| 24522 |
- ContextMtl *contextMtl = mtl::GetImpl(context); |
| 24523 |
- GLenum sizedFormat = mState.getReadAttachment()->getFormat().info->sizedInternalFormat; |
| 24524 |
- angle::FormatID formatID = angle::Format::InternalFormatToID(sizedFormat); |
| 24525 |
- const mtl::Format &mtlFormat = contextMtl->getDisplay()->getPixelFormat(formatID); |
| 24526 |
- GLenum implFormat = mtlFormat.actualAngleFormat().fboImplementationInternalFormat; |
| 24527 |
- return gl::GetSizedInternalFormatInfo(implFormat); |
| 24528 |
+ return GetReadAttachmentInfo(context, getColorReadRenderTarget(context)); |
| 24529 |
} |
| 24530 |
|
| 24531 |
angle::Result FramebufferMtl::readPixels(const gl::Context *context, |
| 24532 |
@@ -590,6 +602,9 @@ PackPixelsParams params(flippedArea, angleFormat, outputPitch, pack.reverseRowOr |
| 24533 |
{ |
| 24534 |
contextMtl->onDrawFrameBufferChangedState(context, this, renderPassChanged); |
| 24535 |
} |
| 24536 |
+ |
| 24537 |
+ // Recreate pixel reading buffer if needed in future. |
| 24538 |
+ mReadPixelBuffer = nullptr; |
| 24539 |
} |
| 24540 |
|
| 24541 |
return angle::Result::Continue; |
| 24542 |
@@ -748,7 +763,7 @@ PackPixelsParams params(flippedArea, angleFormat, outputPitch, pack.reverseRowOr |
| 24543 |
|
| 24544 |
void FramebufferMtl::onFrameEnd(const gl::Context *context) |
| 24545 |
{ |
| 24546 |
- if (!mBackbuffer) |
| 24547 |
+ if (!mBackbuffer || mBackbuffer->preserveBuffer()) |
| 24548 |
{ |
| 24549 |
return; |
| 24550 |
} |
| 24551 |
@@ -812,6 +827,92 @@ PackPixelsParams params(flippedArea, angleFormat, outputPitch, pack.reverseRowOr |
| 24552 |
return angle::Result::Continue; |
| 24553 |
} |
| 24554 |
|
| 24555 |
+angle::Result FramebufferMtl::getReadableViewForRenderTarget( |
| 24556 |
+ const gl::Context *context, |
| 24557 |
+ const RenderTargetMtl &rtt, |
| 24558 |
+ const gl::Rectangle &readArea, |
| 24559 |
+ mtl::TextureRef *readableDepthViewOut, |
| 24560 |
+ mtl::TextureRef *readableStencilViewOut, |
| 24561 |
+ uint32_t *readableViewLevel, |
| 24562 |
+ uint32_t *readableViewLayer, |
| 24563 |
+ gl::Rectangle *readableViewArea) |
| 24564 |
+{ |
| 24565 |
+ ContextMtl *contextMtl = mtl::GetImpl(context); |
| 24566 |
+ mtl::TextureRef srcTexture = rtt.getTexture(); |
| 24567 |
+ uint32_t level = rtt.getLevelIndex().get(); |
| 24568 |
+ uint32_t slice = rtt.getLayerIndex(); |
| 24569 |
+ |
| 24570 |
+ // NOTE(hqle): slice is not used atm. |
| 24571 |
+ ASSERT(slice == 0); |
| 24572 |
+ |
| 24573 |
+ bool readStencil = readableStencilViewOut; |
| 24574 |
+ |
| 24575 |
+ if (!srcTexture) |
| 24576 |
+ { |
| 24577 |
+ if (readableDepthViewOut) |
| 24578 |
+ { |
| 24579 |
+ *readableDepthViewOut = nullptr; |
| 24580 |
+ } |
| 24581 |
+ if (readableStencilViewOut) |
| 24582 |
+ { |
| 24583 |
+ *readableStencilViewOut = nullptr; |
| 24584 |
+ } |
| 24585 |
+ *readableViewArea = readArea; |
| 24586 |
+ return angle::Result::Continue; |
| 24587 |
+ } |
| 24588 |
+ |
| 24589 |
+ bool skipCopy = srcTexture->isShaderReadable(); |
| 24590 |
+ if (rtt.getFormat()->hasDepthAndStencilBits() && readStencil) |
| 24591 |
+ { |
| 24592 |
+ // If the texture is packed depth stencil, and we need stencil view, |
| 24593 |
+ // then it must support creating different format view. |
| 24594 |
+ skipCopy = skipCopy && srcTexture->supportFormatView(); |
| 24595 |
+ } |
| 24596 |
+ |
| 24597 |
+ if (skipCopy) |
| 24598 |
+ { |
| 24599 |
+ // Texture supports stencil view, just use it directly |
| 24600 |
+ if (readableDepthViewOut) |
| 24601 |
+ { |
| 24602 |
+ *readableDepthViewOut = srcTexture; |
| 24603 |
+ } |
| 24604 |
+ if (readableStencilViewOut) |
| 24605 |
+ { |
| 24606 |
+ *readableStencilViewOut = srcTexture; |
| 24607 |
+ } |
| 24608 |
+ *readableViewLevel = level; |
| 24609 |
+ *readableViewLayer = slice; |
| 24610 |
+ *readableViewArea = readArea; |
| 24611 |
+ } |
| 24612 |
+ else |
| 24613 |
+ { |
| 24614 |
+ ASSERT(srcTexture->textureType() != MTLTextureType3D); |
| 24615 |
+ |
| 24616 |
+ // Texture doesn't support stencil view or not shader readable, copy to an interminate |
| 24617 |
+ // texture that supports stencil view and shader read. |
| 24618 |
+ mtl::TextureRef formatableView = srcTexture->getReadableCopy( |
| 24619 |
+ contextMtl, contextMtl->getBlitCommandEncoder(), level, slice, |
| 24620 |
+ MTLRegionMake2D(readArea.x, readArea.y, readArea.width, readArea.height)); |
| 24621 |
+ |
| 24622 |
+ ANGLE_CHECK_GL_ALLOC(contextMtl, formatableView); |
| 24623 |
+ |
| 24624 |
+ if (readableDepthViewOut) |
| 24625 |
+ { |
| 24626 |
+ *readableDepthViewOut = formatableView; |
| 24627 |
+ } |
| 24628 |
+ if (readableStencilViewOut) |
| 24629 |
+ { |
| 24630 |
+ *readableStencilViewOut = formatableView->getStencilView(); |
| 24631 |
+ } |
| 24632 |
+ |
| 24633 |
+ *readableViewLevel = 0; |
| 24634 |
+ *readableViewLayer = 0; |
| 24635 |
+ *readableViewArea = gl::Rectangle(0, 0, readArea.width, readArea.height); |
| 24636 |
+ } |
| 24637 |
+ |
| 24638 |
+ return angle::Result::Continue; |
| 24639 |
+} |
| 24640 |
+ |
| 24641 |
angle::Result FramebufferMtl::prepareRenderPass(const gl::Context *context, |
| 24642 |
mtl::RenderPassDesc *pDescOut) |
| 24643 |
{ |
| 24644 |
@@ -832,9 +933,9 @@ PackPixelsParams params(flippedArea, angleFormat, outputPitch, pack.reverseRowOr |
| 24645 |
if (colorRenderTarget) |
| 24646 |
{ |
| 24647 |
colorRenderTarget->toRenderPassAttachmentDesc(&colorAttachment); |
| 24648 |
+ desc.sampleCount = std::max(desc.sampleCount, colorRenderTarget->getRenderSamples()); |
| 24649 |
|
| 24650 |
desc.numColorAttachments = std::max(desc.numColorAttachments, colorIndexGL + 1); |
| 24651 |
- desc.sampleCount = std::max(desc.sampleCount, colorRenderTarget->getRenderSamples()); |
| 24652 |
|
| 24653 |
if (!mRenderPassFirstColorAttachmentFormat) |
| 24654 |
{ |
| 24655 |
@@ -862,22 +963,29 @@ PackPixelsParams params(flippedArea, angleFormat, outputPitch, pack.reverseRowOr |
| 24656 |
mDepthRenderTarget->toRenderPassAttachmentDesc(&desc.depthAttachment); |
| 24657 |
desc.sampleCount = std::max(desc.sampleCount, mDepthRenderTarget->getRenderSamples()); |
| 24658 |
} |
| 24659 |
- else |
| 24660 |
- { |
| 24661 |
- desc.depthAttachment.reset(); |
| 24662 |
- } |
| 24663 |
|
| 24664 |
if (mStencilRenderTarget) |
| 24665 |
{ |
| 24666 |
mStencilRenderTarget->toRenderPassAttachmentDesc(&desc.stencilAttachment); |
| 24667 |
desc.sampleCount = std::max(desc.sampleCount, mStencilRenderTarget->getRenderSamples()); |
| 24668 |
} |
| 24669 |
+ |
| 24670 |
+ return angle::Result::Continue; |
| 24671 |
+} |
| 24672 |
+ |
| 24673 |
+// Override clear color based on texture's write mask |
| 24674 |
+void FramebufferMtl::overrideClearColor(const mtl::TextureRef &texture, |
| 24675 |
+ MTLClearColor clearColor, |
| 24676 |
+ MTLClearColor *colorOut) |
| 24677 |
+{ |
| 24678 |
+ if (texture) |
| 24679 |
+ { |
| 24680 |
+ *colorOut = mtl::EmulatedAlphaClearColor(clearColor, texture->getColorWritableMask()); |
| 24681 |
+ } |
| 24682 |
else |
| 24683 |
{ |
| 24684 |
- desc.stencilAttachment.reset(); |
| 24685 |
+ *colorOut = clearColor; |
| 24686 |
} |
| 24687 |
- |
| 24688 |
- return angle::Result::Continue; |
| 24689 |
} |
| 24690 |
|
| 24691 |
angle::Result FramebufferMtl::clearWithLoadOp(const gl::Context *context, |
| 24692 |
@@ -923,7 +1031,7 @@ PackPixelsParams params(flippedArea, angleFormat, outputPitch, pack.reverseRowOr |
| 24693 |
|
| 24694 |
mtl::RenderPassColorAttachmentDesc &colorAttachment = |
| 24695 |
tempDesc.colorAttachments[colorIndexGL]; |
| 24696 |
- const mtl::TextureRef &texture = colorAttachment.texture; |
| 24697 |
+ const mtl::TextureRef &texture = colorAttachment.texture(); |
| 24698 |
|
| 24699 |
if (clearColorBuffers.test(colorIndexGL)) |
| 24700 |
{ |
| 24701 |
@@ -966,7 +1074,7 @@ PackPixelsParams params(flippedArea, angleFormat, outputPitch, pack.reverseRowOr |
| 24702 |
|
| 24703 |
mtl::RenderPassColorAttachmentDesc &colorAttachment = |
| 24704 |
mRenderPassDesc.colorAttachments[colorIndexGL]; |
| 24705 |
- const mtl::TextureRef &texture = colorAttachment.texture; |
| 24706 |
+ const mtl::TextureRef &texture = colorAttachment.texture(); |
| 24707 |
|
| 24708 |
if (clearColorBuffers.test(colorIndexGL)) |
| 24709 |
{ |
| 24710 |
@@ -1193,8 +1301,9 @@ PackPixelsParams params(flippedArea, angleFormat, outputPitch, pack.reverseRowOr |
| 24711 |
gl::Rectangle flippedArea = glArea; |
| 24712 |
if (mFlipY) |
| 24713 |
{ |
| 24714 |
- flippedArea.y = readRT->getTexture()->height(readRT->getLevelIndex()) - flippedArea.y - |
| 24715 |
- flippedArea.height; |
| 24716 |
+ flippedArea.y = |
| 24717 |
+ readRT->getTexture()->height(readRT->getLevelIndex()) - |
| 24718 |
+ flippedArea.y - flippedArea.height; |
| 24719 |
} |
| 24720 |
|
| 24721 |
return flippedArea; |
| 24722 |
@@ -1211,7 +1320,6 @@ PackPixelsParams params(flippedArea, angleFormat, outputPitch, pack.reverseRowOr |
| 24723 |
{ |
| 24724 |
return angle::Result::Continue; |
| 24725 |
} |
| 24726 |
- |
| 24727 |
if (packPixelsParams.packBuffer) |
| 24728 |
{ |
| 24729 |
return readPixelsToPBO(context, area, packPixelsParams, renderTarget); |
| 24730 |
@@ -1279,19 +1387,36 @@ PackPixelsParams params(flippedArea, angleFormat, outputPitch, pack.reverseRowOr |
| 24731 |
|
| 24732 |
ANGLE_MTL_CHECK(contextMtl, packPixelsParams.offset <= std::numeric_limits<uint32_t>::max(), |
| 24733 |
GL_INVALID_OPERATION); |
| 24734 |
- const uint32_t dstBufferOffset = static_cast<uint32_t>(packPixelsParams.offset); |
| 24735 |
- const uint32_t dstBufferRowPitch = packPixelsParams.outputPitch; |
| 24736 |
- const angle::Format &dstAngleFormat = *packPixelsParams.destFormat; |
| 24737 |
- const bool reverseRowOrder = packPixelsParams.reverseRowOrder; |
| 24738 |
+ uint32_t offset = static_cast<uint32_t>(packPixelsParams.offset); |
| 24739 |
|
| 24740 |
BufferMtl *packBufferMtl = mtl::GetImpl(packPixelsParams.packBuffer); |
| 24741 |
mtl::BufferRef dstBuffer = packBufferMtl->getCurrentBuffer(); |
| 24742 |
|
| 24743 |
+ return readPixelsToBuffer(context, area, renderTarget, packPixelsParams.reverseRowOrder, |
| 24744 |
+ *packPixelsParams.destFormat, offset, packPixelsParams.outputPitch, |
| 24745 |
+ &dstBuffer); |
| 24746 |
+} |
| 24747 |
+ |
| 24748 |
+angle::Result FramebufferMtl::readPixelsToBuffer(const gl::Context *context, |
| 24749 |
+ const gl::Rectangle &area, |
| 24750 |
+ const RenderTargetMtl *renderTarget, |
| 24751 |
+ bool reverseRowOrder, |
| 24752 |
+ const angle::Format &dstAngleFormat, |
| 24753 |
+ uint32_t dstBufferOffset, |
| 24754 |
+ uint32_t dstBufferRowPitch, |
| 24755 |
+ const mtl::BufferRef *pDstBuffer) const |
| 24756 |
+{ |
| 24757 |
+ ASSERT(renderTarget); |
| 24758 |
+ |
| 24759 |
+ ContextMtl *contextMtl = mtl::GetImpl(context); |
| 24760 |
+ |
| 24761 |
const mtl::Format &readFormat = *renderTarget->getFormat(); |
| 24762 |
const angle::Format &readAngleFormat = readFormat.actualAngleFormat(); |
| 24763 |
|
| 24764 |
mtl::TextureRef texture = renderTarget->getTexture(); |
| 24765 |
|
| 24766 |
+ const mtl::BufferRef &dstBuffer = *pDstBuffer; |
| 24767 |
+ |
| 24768 |
if (dstAngleFormat.id != readAngleFormat.id || texture->samples() > 1 || |
| 24769 |
(dstBufferOffset % dstAngleFormat.pixelBytes) || |
| 24770 |
(dstBufferOffset % mtl::kTextureToBufferBlittingAlignment)) |
| 24771 |
@@ -1359,8 +1484,8 @@ PackPixelsParams params(flippedArea, angleFormat, outputPitch, pack.reverseRowOr |
| 24772 |
|
| 24773 |
uint32_t bufferRowOffset = dstBufferOffset; |
| 24774 |
// Copy pixels row by row |
| 24775 |
- for (int r = startRow, copiedRows = 0; copiedRows < area.height; |
| 24776 |
- ++copiedRows, --r, bufferRowOffset += dstBufferRowPitch) |
| 24777 |
+ for (int r = startRow, i = 0; i < area.height; |
| 24778 |
+ ++i, --r, bufferRowOffset += dstBufferRowPitch) |
| 24779 |
{ |
| 24780 |
srcRowRegion.y = r; |
| 24781 |
|
| 24782 |
@@ -1375,5 +1500,4 @@ PackPixelsParams params(flippedArea, angleFormat, outputPitch, pack.reverseRowOr |
| 24783 |
|
| 24784 |
return angle::Result::Continue; |
| 24785 |
} |
| 24786 |
- |
| 24787 |
} |
| 24788 |
diff --git a/src/libANGLE/renderer/metal/IOSurfaceSurfaceMtl.h b/src/libANGLE/renderer/metal/IOSurfaceSurfaceMtl.h |
| 24789 |
new file mode 100644 |
| 24790 |
index 0000000..9548e5d |
| 24791 |
--- /dev/null |
| 24792 |
+++ b/src/libANGLE/renderer/metal/IOSurfaceSurfaceMtl.h |
| 24793 |
@@ -0,0 +1,126 @@ |
| 24794 |
+// |
| 24795 |
+// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 24796 |
+// Use of this source code is governed by a BSD-style license that can be |
| 24797 |
+// found in the LICENSE file. |
| 24798 |
+// |
| 24799 |
+ |
| 24800 |
+#ifndef LIBANGLE_RENDERER_METAL_IOSURFACESURFACEMTL_H_ |
| 24801 |
+#define LIBANGLE_RENDERER_METAL_IOSURFACESURFACEMTL_H_ |
| 24802 |
+ |
| 24803 |
+#include <IOSurface/IOSurfaceRef.h> |
| 24804 |
+#include "libANGLE/renderer/SurfaceImpl.h" |
| 24805 |
+#include "libANGLE/renderer/metal/DisplayMtl.h" |
| 24806 |
+#include "libANGLE/renderer/metal/SurfaceMtl.h" |
| 24807 |
+ |
| 24808 |
+namespace metal |
| 24809 |
+{ |
| 24810 |
+class AttributeMap; |
| 24811 |
+} // namespace metal |
| 24812 |
+ |
| 24813 |
+namespace rx |
| 24814 |
+{ |
| 24815 |
+ |
| 24816 |
+class DisplayMTL; |
| 24817 |
+ |
| 24818 |
+class IOSurfaceSurfaceMtl : public SurfaceMtlProtocol |
| 24819 |
+{ |
| 24820 |
+ public: |
| 24821 |
+ IOSurfaceSurfaceMtl(DisplayMtl *display, |
| 24822 |
+ const egl::SurfaceState &state, |
| 24823 |
+ EGLClientBuffer buffer, |
| 24824 |
+ const egl::AttributeMap &attribs); |
| 24825 |
+ ~IOSurfaceSurfaceMtl() override; |
| 24826 |
+ |
| 24827 |
+ void destroy(const egl::Display *display) override; |
| 24828 |
+ |
| 24829 |
+ egl::Error initialize(const egl::Display *display) override; |
| 24830 |
+ FramebufferImpl *createDefaultFramebuffer(const gl::Context *context, |
| 24831 |
+ const gl::FramebufferState &state) override; |
| 24832 |
+ |
| 24833 |
+ egl::Error makeCurrent(const gl::Context *context) override; |
| 24834 |
+ egl::Error unMakeCurrent(const gl::Context *context) override; |
| 24835 |
+ egl::Error swap(const gl::Context *context) override; |
| 24836 |
+ egl::Error postSubBuffer(const gl::Context *context, |
| 24837 |
+ EGLint x, |
| 24838 |
+ EGLint y, |
| 24839 |
+ EGLint width, |
| 24840 |
+ EGLint height) override; |
| 24841 |
+ |
| 24842 |
+ egl::Error querySurfacePointerANGLE(EGLint attribute, void **value) override; |
| 24843 |
+ egl::Error bindTexImage(const gl::Context *context, |
| 24844 |
+ gl::Texture *texture, |
| 24845 |
+ EGLint buffer) override; |
| 24846 |
+ egl::Error releaseTexImage(const gl::Context *context, EGLint buffer) override; |
| 24847 |
+ egl::Error getSyncValues(EGLuint64KHR *ust, EGLuint64KHR *msc, EGLuint64KHR *sbc) override; |
| 24848 |
+ egl::Error getMscRate(EGLint *numerator, EGLint *denominator) override; |
| 24849 |
+ void setSwapInterval(EGLint interval) override; |
| 24850 |
+ void setFixedWidth(EGLint width) override; |
| 24851 |
+ void setFixedHeight(EGLint height) override; |
| 24852 |
+ |
| 24853 |
+ // Width can change when the client window resizes. |
| 24854 |
+ EGLint getWidth() const override; |
| 24855 |
+ // Height can change when the client window resizes. |
| 24856 |
+ EGLint getHeight() const override; |
| 24857 |
+ |
| 24858 |
+ EGLint isPostSubBufferSupported() const override; |
| 24859 |
+ EGLint getSwapBehavior() const override; |
| 24860 |
+ |
| 24861 |
+ angle::Result getAttachmentRenderTarget(const gl::Context *context, |
| 24862 |
+ GLenum binding, |
| 24863 |
+ const gl::ImageIndex &imageIndex, |
| 24864 |
+ GLsizei samples, |
| 24865 |
+ FramebufferAttachmentRenderTarget **rtOut) override; |
| 24866 |
+ |
| 24867 |
+ angle::Result ensureCurrentDrawableObtained(const gl::Context *context) override; |
| 24868 |
+ angle::Result ensureCurrentDrawableObtained(const gl::Context *context, |
| 24869 |
+ bool *newDrawableOut) override; |
| 24870 |
+ int getSamples() const override { return 1; } |
| 24871 |
+ bool preserveBuffer() const override { return false; } |
| 24872 |
+ mtl::TextureRef getTexture(const gl::Context *context); |
| 24873 |
+ bool hasRobustResourceInit() const override { return false; } |
| 24874 |
+ angle::Result ensureColorTextureReadyForReadPixels(const gl::Context *context) override |
| 24875 |
+ { |
| 24876 |
+ return angle::Result::Continue; |
| 24877 |
+ } |
| 24878 |
+ const mtl::TextureRef &getColorTexture() override { return mIOSurfaceTexture; } |
| 24879 |
+ |
| 24880 |
+ private: |
| 24881 |
+ angle::Result ensureTextureCreated(const gl::Context *context); |
| 24882 |
+ angle::Result createBackingTexture(const gl::Context *context); |
| 24883 |
+ angle::Result createTexture(const gl::Context *context, |
| 24884 |
+ const mtl::Format &format, |
| 24885 |
+ uint32_t width, |
| 24886 |
+ uint32_t height, |
| 24887 |
+ bool renderTargetOnly, |
| 24888 |
+ mtl::TextureRef *textureOut); |
| 24889 |
+ |
| 24890 |
+ angle::Result initializeAlphaChannel(const gl::Context *context, GLuint texture); |
| 24891 |
+ |
| 24892 |
+#if defined(ANGLE_PLATFORM_IOS_SIMULATOR) |
| 24893 |
+ IOSurfaceLockOptions getIOSurfaceLockOptions() const; |
| 24894 |
+#endif |
| 24895 |
+ |
| 24896 |
+ ContextMtl *contextMTL; |
| 24897 |
+ IOSurfaceRef mIOSurface; |
| 24898 |
+ mtl::TextureRef mIOSurfaceTexture; |
| 24899 |
+ mtl::TextureRef mIOSurfaceTextureView; |
| 24900 |
+ mtl::Format mFormat; |
| 24901 |
+ mtl::Format mInternalFormat; |
| 24902 |
+ RenderTargetMtl mRenderTarget; |
| 24903 |
+ bool mIOSurfaceTextureCreated; |
| 24904 |
+ int mWidth; |
| 24905 |
+ int mHeight; |
| 24906 |
+ int mPlane; |
| 24907 |
+ int mFormatIndex; |
| 24908 |
+ int mRowStrideInPixels; |
| 24909 |
+ |
| 24910 |
+#if defined(ANGLE_PLATFORM_IOS_SIMULATOR) |
| 24911 |
+ GLuint mBoundTextureID; |
| 24912 |
+ bool mUploadFromIOSurface; |
| 24913 |
+ bool mReadbackToIOSurface; |
| 24914 |
+#endif |
| 24915 |
+}; |
| 24916 |
+ |
| 24917 |
+} // namespace rx |
| 24918 |
+ |
| 24919 |
+#endif // LIBANGLE_RENDERER_GL_EAGL_IOSURFACESURFACEEAGL_H_ |
| 24920 |
diff --git a/src/libANGLE/renderer/metal/IOSurfaceSurfaceMtl.mm b/src/libANGLE/renderer/metal/IOSurfaceSurfaceMtl.mm |
| 24921 |
new file mode 100644 |
| 24922 |
index 0000000..8b94859 |
| 24923 |
--- /dev/null |
| 24924 |
+++ b/src/libANGLE/renderer/metal/IOSurfaceSurfaceMtl.mm |
| 24925 |
@@ -0,0 +1,467 @@ |
| 24926 |
+// |
| 24927 |
+// Copyright 2019 The ANGLE Project Authors. All rights reserved. |
| 24928 |
+// Use of this source code is governed by a BSD-style license that can be |
| 24929 |
+// found in the LICENSE file. |
| 24930 |
+// |
| 24931 |
+// IOSurfaceSurfaceMtl.mm: |
| 24932 |
+// Implements the class methods for IOSurfaceSurfaceMtl. |
| 24933 |
+// |
| 24934 |
+ |
| 24935 |
+#include "libANGLE/renderer/metal/IOSurfaceSurfaceMtl.h" |
| 24936 |
+ |
| 24937 |
+#include <TargetConditionals.h> |
| 24938 |
+ |
| 24939 |
+#include "libANGLE/Display.h" |
| 24940 |
+#include "libANGLE/Surface.h" |
| 24941 |
+#include "libANGLE/renderer/metal/ContextMtl.h" |
| 24942 |
+#include "libANGLE/renderer/metal/DisplayMtl.h" |
| 24943 |
+#include "libANGLE/renderer/metal/FrameBufferMtl.h" |
| 24944 |
+#include "libANGLE/renderer/metal/mtl_format_utils.h" |
| 24945 |
+ |
| 24946 |
+// Compiler can turn on programmatical frame capture in release build by defining |
| 24947 |
+// ANGLE_METAL_FRAME_CAPTURE flag. |
| 24948 |
+#if defined(NDEBUG) && !defined(ANGLE_METAL_FRAME_CAPTURE) |
| 24949 |
+# define ANGLE_METAL_FRAME_CAPTURE_ENABLED 0 |
| 24950 |
+#else |
| 24951 |
+# define ANGLE_METAL_FRAME_CAPTURE_ENABLED 1 |
| 24952 |
+#endif |
| 24953 |
+namespace rx |
| 24954 |
+{ |
| 24955 |
+ |
| 24956 |
+namespace |
| 24957 |
+{ |
| 24958 |
+ |
| 24959 |
+struct IOSurfaceFormatInfo |
| 24960 |
+{ |
| 24961 |
+ GLenum internalFormat; |
| 24962 |
+ GLenum type; |
| 24963 |
+ angle::FormatID pixelFormat; |
| 24964 |
+ angle::FormatID internalPixelFormat; |
| 24965 |
+}; |
| 24966 |
+ |
| 24967 |
+static const IOSurfaceFormatInfo kIOSurfaceFormats[] = { |
| 24968 |
+ {GL_RED, GL_UNSIGNED_BYTE, angle::FormatID::R8_UNORM, angle::FormatID::R8_UNORM}, |
| 24969 |
+ {GL_R16UI, GL_UNSIGNED_SHORT, angle::FormatID::R16G16_UINT, angle::FormatID::R16G16_UINT}, |
| 24970 |
+ {GL_RG, GL_UNSIGNED_BYTE, angle::FormatID::R8G8_UNORM, angle::FormatID::R8G8_UNORM}, |
| 24971 |
+ {GL_RGB, GL_UNSIGNED_BYTE, angle::FormatID::R8G8B8A8_UNORM, angle::FormatID::B8G8R8A8_UNORM}, |
| 24972 |
+ {GL_BGRA_EXT, GL_UNSIGNED_BYTE, angle::FormatID::B8G8R8A8_UNORM, |
| 24973 |
+ angle::FormatID::B8G8R8A8_UNORM}, |
| 24974 |
+ {GL_RGB10_A2, GL_UNSIGNED_INT_2_10_10_10_REV, angle::FormatID::R10G10B10A2_UNORM, |
| 24975 |
+ angle::FormatID::R10G10B10A2_UNORM}, |
| 24976 |
+ {GL_RGBA, GL_HALF_FLOAT, angle::FormatID::R16G16B16A16_FLOAT, |
| 24977 |
+ angle::FormatID::R16G16B16A16_FLOAT}, |
| 24978 |
+}; |
| 24979 |
+ |
| 24980 |
+int FindIOSurfaceFormatIndex(GLenum internalFormat, GLenum type) |
| 24981 |
+{ |
| 24982 |
+ for (size_t i = 0; i < static_cast<size_t>(ArraySize(kIOSurfaceFormats)); ++i) |
| 24983 |
+ { |
| 24984 |
+ const auto &formatInfo = kIOSurfaceFormats[i]; |
| 24985 |
+ if (formatInfo.internalFormat == internalFormat && formatInfo.type == type) |
| 24986 |
+ { |
| 24987 |
+ return static_cast<int>(i); |
| 24988 |
+ } |
| 24989 |
+ } |
| 24990 |
+ return -1; |
| 24991 |
+} |
| 24992 |
+ |
| 24993 |
+// TODO(jcunningham) : refactor this and surfacemtl to reduce copy+pasted code |
| 24994 |
+ |
| 24995 |
+ANGLE_MTL_UNUSED |
| 24996 |
+bool IsFrameCaptureEnabled() |
| 24997 |
+{ |
| 24998 |
+#if !ANGLE_METAL_FRAME_CAPTURE_ENABLED |
| 24999 |
+ return false; |
| 25000 |
+#else |
| 25001 |
+ // We only support frame capture programmatically if the ANGLE_METAL_FRAME_CAPTURE |
| 25002 |
+ // environment flag is set. Otherwise, it will slow down the rendering. This allows user to |
| 25003 |
+ // finely control whether they want to capture the frame for particular application or not. |
| 25004 |
+ auto var = std::getenv("ANGLE_METAL_FRAME_CAPTURE"); |
| 25005 |
+ static const bool enabled = var ? (strcmp(var, "1") == 0) : false; |
| 25006 |
+ |
| 25007 |
+ return enabled; |
| 25008 |
+#endif |
| 25009 |
+} |
| 25010 |
+ |
| 25011 |
+ANGLE_MTL_UNUSED |
| 25012 |
+std::string GetMetalCaptureFile() |
| 25013 |
+{ |
| 25014 |
+#if !ANGLE_METAL_FRAME_CAPTURE_ENABLED |
| 25015 |
+ return ""; |
| 25016 |
+#else |
| 25017 |
+ auto var = std::getenv("ANGLE_METAL_FRAME_CAPTURE_FILE"); |
| 25018 |
+ const std::string filePath = var ? var : ""; |
| 25019 |
+ |
| 25020 |
+ return filePath; |
| 25021 |
+#endif |
| 25022 |
+} |
| 25023 |
+ |
| 25024 |
+ANGLE_MTL_UNUSED |
| 25025 |
+size_t MaxAllowedFrameCapture() |
| 25026 |
+{ |
| 25027 |
+#if !ANGLE_METAL_FRAME_CAPTURE_ENABLED |
| 25028 |
+ return 0; |
| 25029 |
+#else |
| 25030 |
+ auto var = std::getenv("ANGLE_METAL_FRAME_CAPTURE_MAX"); |
| 25031 |
+ static const size_t maxFrames = var ? std::atoi(var) : 100; |
| 25032 |
+ |
| 25033 |
+ return maxFrames; |
| 25034 |
+#endif |
| 25035 |
+} |
| 25036 |
+ |
| 25037 |
+ANGLE_MTL_UNUSED |
| 25038 |
+size_t MinAllowedFrameCapture() |
| 25039 |
+{ |
| 25040 |
+#if !ANGLE_METAL_FRAME_CAPTURE_ENABLED |
| 25041 |
+ return 0; |
| 25042 |
+#else |
| 25043 |
+ auto var = std::getenv("ANGLE_METAL_FRAME_CAPTURE_MIN"); |
| 25044 |
+ static const size_t minFrame = var ? std::atoi(var) : 0; |
| 25045 |
+ |
| 25046 |
+ return minFrame; |
| 25047 |
+#endif |
| 25048 |
+} |
| 25049 |
+ |
| 25050 |
+ANGLE_MTL_UNUSED |
| 25051 |
+bool FrameCaptureDeviceScope() |
| 25052 |
+{ |
| 25053 |
+#if !ANGLE_METAL_FRAME_CAPTURE_ENABLED |
| 25054 |
+ return false; |
| 25055 |
+#else |
| 25056 |
+ auto var = std::getenv("ANGLE_METAL_FRAME_CAPTURE_SCOPE"); |
| 25057 |
+ static const bool scopeDevice = var ? (strcmp(var, "device") == 0) : false; |
| 25058 |
+ |
| 25059 |
+ return scopeDevice; |
| 25060 |
+#endif |
| 25061 |
+} |
| 25062 |
+ |
| 25063 |
+ANGLE_MTL_UNUSED |
| 25064 |
+std::atomic<size_t> gFrameCaptured(0); |
| 25065 |
+ |
| 25066 |
+ANGLE_MTL_UNUSED |
| 25067 |
+void StartFrameCapture(id<MTLDevice> metalDevice, id<MTLCommandQueue> metalCmdQueue) |
| 25068 |
+{ |
| 25069 |
+#if ANGLE_METAL_FRAME_CAPTURE_ENABLED |
| 25070 |
+ if (!IsFrameCaptureEnabled()) |
| 25071 |
+ { |
| 25072 |
+ return; |
| 25073 |
+ } |
| 25074 |
+ |
| 25075 |
+ if (gFrameCaptured >= MaxAllowedFrameCapture()) |
| 25076 |
+ { |
| 25077 |
+ return; |
| 25078 |
+ } |
| 25079 |
+ |
| 25080 |
+ MTLCaptureManager *captureManager = [MTLCaptureManager sharedCaptureManager]; |
| 25081 |
+ if (captureManager.isCapturing) |
| 25082 |
+ { |
| 25083 |
+ return; |
| 25084 |
+ } |
| 25085 |
+ |
| 25086 |
+ gFrameCaptured++; |
| 25087 |
+ |
| 25088 |
+ if (gFrameCaptured < MinAllowedFrameCapture()) |
| 25089 |
+ { |
| 25090 |
+ return; |
| 25091 |
+ } |
| 25092 |
+ |
| 25093 |
+# ifdef __MAC_10_15 |
| 25094 |
+ if (ANGLE_APPLE_AVAILABLE_XCI(10.15, 13.0, 13)) |
| 25095 |
+ { |
| 25096 |
+ MTLCaptureDescriptor *captureDescriptor = [[MTLCaptureDescriptor alloc] init]; |
| 25097 |
+ captureDescriptor.captureObject = metalDevice; |
| 25098 |
+ const std::string filePath = GetMetalCaptureFile(); |
| 25099 |
+ if (filePath != "") |
| 25100 |
+ { |
| 25101 |
+ const std::string numberedPath = |
| 25102 |
+ filePath + std::to_string(gFrameCaptured - 1) + ".gputrace"; |
| 25103 |
+ captureDescriptor.destination = MTLCaptureDestinationGPUTraceDocument; |
| 25104 |
+ captureDescriptor.outputURL = |
| 25105 |
+ [NSURL fileURLWithPath:[NSString stringWithUTF8String:numberedPath.c_str()] |
| 25106 |
+ isDirectory:false]; |
| 25107 |
+ } |
| 25108 |
+ else |
| 25109 |
+ { |
| 25110 |
+ // This will pause execution only if application is being debugged inside Xcode |
| 25111 |
+ captureDescriptor.destination = MTLCaptureDestinationDeveloperTools; |
| 25112 |
+ } |
| 25113 |
+ |
| 25114 |
+ NSError *error; |
| 25115 |
+ if (![captureManager startCaptureWithDescriptor:captureDescriptor error:&error]) |
| 25116 |
+ { |
| 25117 |
+ NSLog(@"Failed to start capture, error %@", error); |
| 25118 |
+ } |
| 25119 |
+ } |
| 25120 |
+ else |
| 25121 |
+# endif // __MAC_10_15 |
| 25122 |
+ if (ANGLE_APPLE_AVAILABLE_XCI(10.15, 13.0, 13)) |
| 25123 |
+ { |
| 25124 |
+ MTLCaptureDescriptor *captureDescriptor = [[MTLCaptureDescriptor alloc] init]; |
| 25125 |
+ captureDescriptor.captureObject = metalDevice; |
| 25126 |
+ |
| 25127 |
+ NSError *error; |
| 25128 |
+ if (![captureManager startCaptureWithDescriptor:captureDescriptor error:&error]) |
| 25129 |
+ { |
| 25130 |
+ NSLog(@"Failed to start capture, error %@", error); |
| 25131 |
+ } |
| 25132 |
+ } |
| 25133 |
+#endif // ANGLE_METAL_FRAME_CAPTURE_ENABLED |
| 25134 |
+} |
| 25135 |
+ |
| 25136 |
+void StartFrameCapture(ContextMtl *context) |
| 25137 |
+{ |
| 25138 |
+ StartFrameCapture(context->getMetalDevice(), context->cmdQueue().get()); |
| 25139 |
+} |
| 25140 |
+ |
| 25141 |
+void StopFrameCapture() |
| 25142 |
+{ |
| 25143 |
+#if ANGLE_METAL_FRAME_CAPTURE_ENABLED |
| 25144 |
+ if (!IsFrameCaptureEnabled()) |
| 25145 |
+ { |
| 25146 |
+ return; |
| 25147 |
+ } |
| 25148 |
+ MTLCaptureManager *captureManager = [MTLCaptureManager sharedCaptureManager]; |
| 25149 |
+ if (captureManager.isCapturing) |
| 25150 |
+ { |
| 25151 |
+ [captureManager stopCapture]; |
| 25152 |
+ } |
| 25153 |
+#endif |
| 25154 |
+} |
| 25155 |
+ |
| 25156 |
+} // anonymous namespace |
| 25157 |
+ |
| 25158 |
+IOSurfaceSurfaceMtl::IOSurfaceSurfaceMtl(DisplayMtl *display, |
| 25159 |
+ const egl::SurfaceState &state, |
| 25160 |
+ EGLClientBuffer buffer, |
| 25161 |
+ const egl::AttributeMap &attribs) |
| 25162 |
+ : SurfaceMtlProtocol(state) |
| 25163 |
+{ |
| 25164 |
+ // Keep reference to the IOSurface so it doesn't get deleted while the pbuffer exists. |
| 25165 |
+ mIOSurface = reinterpret_cast<IOSurfaceRef>(buffer); |
| 25166 |
+ CFRetain(mIOSurface); |
| 25167 |
+ |
| 25168 |
+ // Extract attribs useful for the call to EAGLTexImageIOSurface2D |
| 25169 |
+ mWidth = static_cast<int>(attribs.get(EGL_WIDTH)); |
| 25170 |
+ mHeight = static_cast<int>(attribs.get(EGL_HEIGHT)); |
| 25171 |
+ mPlane = static_cast<int>(attribs.get(EGL_IOSURFACE_PLANE_ANGLE)); |
| 25172 |
+ // Hopefully the number of bytes per row is always an integer number of pixels. We use |
| 25173 |
+ // glReadPixels to fill the IOSurface in the simulator and it can only support strides that are |
| 25174 |
+ // an integer number of pixels. |
| 25175 |
+ ASSERT(IOSurfaceGetBytesPerRowOfPlane(mIOSurface, mPlane) % |
| 25176 |
+ IOSurfaceGetBytesPerElementOfPlane(mIOSurface, mPlane) == |
| 25177 |
+ 0); |
| 25178 |
+ mRowStrideInPixels = static_cast<int>(IOSurfaceGetBytesPerRowOfPlane(mIOSurface, mPlane) / |
| 25179 |
+ IOSurfaceGetBytesPerElementOfPlane(mIOSurface, mPlane)); |
| 25180 |
+ |
| 25181 |
+ EGLAttrib internalFormat = attribs.get(EGL_TEXTURE_INTERNAL_FORMAT_ANGLE); |
| 25182 |
+ EGLAttrib type = attribs.get(EGL_TEXTURE_TYPE_ANGLE); |
| 25183 |
+ mFormatIndex = |
| 25184 |
+ FindIOSurfaceFormatIndex(static_cast<GLenum>(internalFormat), static_cast<GLenum>(type)); |
| 25185 |
+ ASSERT(mFormatIndex >= 0); |
| 25186 |
+ mFormat = display->getPixelFormat(kIOSurfaceFormats[mFormatIndex].pixelFormat); |
| 25187 |
+ mInternalFormat = display->getPixelFormat(kIOSurfaceFormats[mFormatIndex].internalPixelFormat); |
| 25188 |
+} |
| 25189 |
+ |
| 25190 |
+IOSurfaceSurfaceMtl::~IOSurfaceSurfaceMtl() |
| 25191 |
+{ |
| 25192 |
+ StopFrameCapture(); |
| 25193 |
+ if (mIOSurface != nullptr) |
| 25194 |
+ { |
| 25195 |
+ CFRelease(mIOSurface); |
| 25196 |
+ mIOSurface = nullptr; |
| 25197 |
+ } |
| 25198 |
+} |
| 25199 |
+ |
| 25200 |
+void IOSurfaceSurfaceMtl::destroy(const egl::Display *display) {} |
| 25201 |
+ |
| 25202 |
+egl::Error IOSurfaceSurfaceMtl::initialize(const egl::Display *display) |
| 25203 |
+{ |
| 25204 |
+ DisplayMtl *displayMtl = mtl::GetImpl(display); |
| 25205 |
+ id<MTLDevice> metalDevice = displayMtl->getMetalDevice(); |
| 25206 |
+ |
| 25207 |
+ StartFrameCapture(metalDevice, displayMtl->cmdQueue().get()); |
| 25208 |
+ return egl::NoError(); |
| 25209 |
+} |
| 25210 |
+ |
| 25211 |
+FramebufferImpl *IOSurfaceSurfaceMtl::createDefaultFramebuffer(const gl::Context *context, |
| 25212 |
+ const gl::FramebufferState &state) |
| 25213 |
+{ |
| 25214 |
+ auto fbo = new FramebufferMtl(state, /* flipY */ true, /* backbuffer */ this); |
| 25215 |
+ return fbo; |
| 25216 |
+} |
| 25217 |
+ |
| 25218 |
+egl::Error IOSurfaceSurfaceMtl::makeCurrent(const gl::Context *context) |
| 25219 |
+{ |
| 25220 |
+ ContextMtl *contextMtl = mtl::GetImpl(context); |
| 25221 |
+ StartFrameCapture(contextMtl); |
| 25222 |
+ return egl::NoError(); |
| 25223 |
+} |
| 25224 |
+ |
| 25225 |
+egl::Error IOSurfaceSurfaceMtl::unMakeCurrent(const gl::Context *context) |
| 25226 |
+{ |
| 25227 |
+ StopFrameCapture(); |
| 25228 |
+ return egl::NoError(); |
| 25229 |
+} |
| 25230 |
+ |
| 25231 |
+egl::Error IOSurfaceSurfaceMtl::swap(const gl::Context *context) |
| 25232 |
+{ |
| 25233 |
+ StopFrameCapture(); |
| 25234 |
+ ContextMtl *contextMtl = mtl::GetImpl(context); |
| 25235 |
+ StartFrameCapture(contextMtl); |
| 25236 |
+ return egl::NoError(); |
| 25237 |
+} |
| 25238 |
+ |
| 25239 |
+egl::Error IOSurfaceSurfaceMtl::postSubBuffer(const gl::Context *context, |
| 25240 |
+ EGLint x, |
| 25241 |
+ EGLint y, |
| 25242 |
+ EGLint width, |
| 25243 |
+ EGLint height) |
| 25244 |
+{ |
| 25245 |
+ UNIMPLEMENTED(); |
| 25246 |
+ return egl::EglBadAccess(); |
| 25247 |
+} |
| 25248 |
+ |
| 25249 |
+egl::Error IOSurfaceSurfaceMtl::querySurfacePointerANGLE(EGLint attribute, void **value) |
| 25250 |
+{ |
| 25251 |
+ UNIMPLEMENTED(); |
| 25252 |
+ return egl::EglBadAccess(); |
| 25253 |
+} |
| 25254 |
+ |
| 25255 |
+egl::Error IOSurfaceSurfaceMtl::bindTexImage(const gl::Context *context, |
| 25256 |
+ gl::Texture *texture, |
| 25257 |
+ EGLint buffer) |
| 25258 |
+{ |
| 25259 |
+ |
| 25260 |
+ angle::Result res = createBackingTexture(context); |
| 25261 |
+ if (res == angle::Result::Continue) |
| 25262 |
+ return egl::NoError(); |
| 25263 |
+ else |
| 25264 |
+ return egl::EglBadAccess(); |
| 25265 |
+} |
| 25266 |
+ |
| 25267 |
+egl::Error IOSurfaceSurfaceMtl::releaseTexImage(const gl::Context *context, EGLint buffer) |
| 25268 |
+{ |
| 25269 |
+ // This will need implementation |
| 25270 |
+ ContextMtl *contextMtl = mtl::GetImpl(context); |
| 25271 |
+ if (contextMtl->flush(context) == angle::Result::Continue) |
| 25272 |
+ { |
| 25273 |
+ mIOSurfaceTextureCreated = false; |
| 25274 |
+ return egl::NoError(); |
| 25275 |
+ } |
| 25276 |
+ return egl::EglBadAccess(); |
| 25277 |
+} |
| 25278 |
+ |
| 25279 |
+egl::Error IOSurfaceSurfaceMtl::getSyncValues(EGLuint64KHR *ust, |
| 25280 |
+ EGLuint64KHR *msc, |
| 25281 |
+ EGLuint64KHR *sbc) |
| 25282 |
+{ |
| 25283 |
+ UNIMPLEMENTED(); |
| 25284 |
+ return egl::EglBadAccess(); |
| 25285 |
+} |
| 25286 |
+ |
| 25287 |
+egl::Error IOSurfaceSurfaceMtl::getMscRate(EGLint *numerator, EGLint *denominator) |
| 25288 |
+{ |
| 25289 |
+ UNIMPLEMENTED(); |
| 25290 |
+ return egl::EglBadAccess(); |
| 25291 |
+} |
| 25292 |
+ |
| 25293 |
+void IOSurfaceSurfaceMtl::setSwapInterval(EGLint interval) |
| 25294 |
+{ |
| 25295 |
+ UNIMPLEMENTED(); |
| 25296 |
+} |
| 25297 |
+ |
| 25298 |
+void IOSurfaceSurfaceMtl::setFixedWidth(EGLint width) |
| 25299 |
+{ |
| 25300 |
+ UNIMPLEMENTED(); |
| 25301 |
+} |
| 25302 |
+ |
| 25303 |
+void IOSurfaceSurfaceMtl::setFixedHeight(EGLint height) |
| 25304 |
+{ |
| 25305 |
+ UNIMPLEMENTED(); |
| 25306 |
+} |
| 25307 |
+ |
| 25308 |
+// width and height can change with client window resizing |
| 25309 |
+EGLint IOSurfaceSurfaceMtl::getWidth() const |
| 25310 |
+{ |
| 25311 |
+ return static_cast<EGLint>(mWidth); |
| 25312 |
+} |
| 25313 |
+ |
| 25314 |
+EGLint IOSurfaceSurfaceMtl::getHeight() const |
| 25315 |
+{ |
| 25316 |
+ return static_cast<EGLint>(mHeight); |
| 25317 |
+} |
| 25318 |
+ |
| 25319 |
+EGLint IOSurfaceSurfaceMtl::isPostSubBufferSupported() const |
| 25320 |
+{ |
| 25321 |
+ return EGL_FALSE; |
| 25322 |
+} |
| 25323 |
+ |
| 25324 |
+EGLint IOSurfaceSurfaceMtl::getSwapBehavior() const |
| 25325 |
+{ |
| 25326 |
+ return EGL_BUFFER_DESTROYED; |
| 25327 |
+} |
| 25328 |
+ |
| 25329 |
+angle::Result IOSurfaceSurfaceMtl::getAttachmentRenderTarget( |
| 25330 |
+ const gl::Context *context, |
| 25331 |
+ GLenum binding, |
| 25332 |
+ const gl::ImageIndex &imageIndex, |
| 25333 |
+ GLsizei samples, |
| 25334 |
+ FramebufferAttachmentRenderTarget **rtOut) |
| 25335 |
+{ |
| 25336 |
+ ANGLE_TRY(ensureTextureCreated(context)); |
| 25337 |
+ *rtOut = &mRenderTarget; |
| 25338 |
+ return angle::Result::Continue; |
| 25339 |
+} |
| 25340 |
+ |
| 25341 |
+angle::Result IOSurfaceSurfaceMtl::ensureCurrentDrawableObtained(const gl::Context *context, bool *newDrawableOut) |
| 25342 |
+{ |
| 25343 |
+ return angle::Result::Continue; |
| 25344 |
+} |
| 25345 |
+angle::Result IOSurfaceSurfaceMtl::ensureCurrentDrawableObtained(const gl::Context *context) |
| 25346 |
+{ |
| 25347 |
+ return angle::Result::Continue; |
| 25348 |
+} |
| 25349 |
+ |
| 25350 |
+angle::Result IOSurfaceSurfaceMtl::createBackingTexture(const gl::Context *context) |
| 25351 |
+{ |
| 25352 |
+ mtl::TextureRef mTemporarySurfaceRef; |
| 25353 |
+ ANGLE_TRY(createTexture(context, mFormat, mWidth, mHeight, false, &mTemporarySurfaceRef)); |
| 25354 |
+ // Create texture view around the base format of the texture. |
| 25355 |
+ mIOSurfaceTexture = |
| 25356 |
+ mTemporarySurfaceRef->createViewWithDifferentFormat(MTLPixelFormatBGRA8Unorm); |
| 25357 |
+ mRenderTarget.set(mIOSurfaceTexture, mtl::kZeroNativeMipLevel, 0, mInternalFormat); |
| 25358 |
+ mIOSurfaceTextureCreated = true; |
| 25359 |
+ return angle::Result::Continue; |
| 25360 |
+} |
| 25361 |
+ |
| 25362 |
+angle::Result IOSurfaceSurfaceMtl::ensureTextureCreated(const gl::Context *context) |
| 25363 |
+{ |
| 25364 |
+ if (!mIOSurfaceTextureCreated) |
| 25365 |
+ { |
| 25366 |
+ return createBackingTexture(context); |
| 25367 |
+ } |
| 25368 |
+ return angle::Result::Continue; |
| 25369 |
+} |
| 25370 |
+ |
| 25371 |
+mtl::TextureRef IOSurfaceSurfaceMtl::getTexture(const gl::Context *context) |
| 25372 |
+{ |
| 25373 |
+ if (ensureCurrentDrawableObtained(context) == angle::Result::Continue) |
| 25374 |
+ { |
| 25375 |
+ return mIOSurfaceTexture; |
| 25376 |
+ } |
| 25377 |
+ return nullptr; |
| 25378 |
+} |
| 25379 |
+ |
| 25380 |
+angle::Result IOSurfaceSurfaceMtl::createTexture(const gl::Context *context, |
| 25381 |
+ const mtl::Format &format, |
| 25382 |
+ uint32_t width, |
| 25383 |
+ uint32_t height, |
| 25384 |
+ bool renderTargetOnly, |
| 25385 |
+ mtl::TextureRef *textureOut) |
| 25386 |
+{ |
| 25387 |
+ ContextMtl *contextMtl = mtl::GetImpl(context); |
| 25388 |
+ ANGLE_TRY(mtl::Texture::MakeIOSurfaceTexture(contextMtl, format, width, height, mIOSurface, |
| 25389 |
+ mPlane, textureOut)); |
| 25390 |
+ return angle::Result::Continue; |
| 25391 |
+} |
| 25392 |
+} |
| 25393 |
diff --git a/src/libANGLE/renderer/metal/ProgramMtl.h b/src/libANGLE/renderer/metal/ProgramMtl.h |
| 25394 |
index 389ece7..eb9bb01 100644 |
| 25395 |
--- a/src/libANGLE/renderer/metal/ProgramMtl.h |
| 25396 |
+++ b/src/libANGLE/renderer/metal/ProgramMtl.h |
| 25397 |
@@ -20,12 +20,13 @@ |
| 25398 |
#include "libANGLE/renderer/glslang_wrapper_utils.h" |
| 25399 |
#include "libANGLE/renderer/metal/mtl_buffer_pool.h" |
| 25400 |
#include "libANGLE/renderer/metal/mtl_command_buffer.h" |
| 25401 |
-#include "libANGLE/renderer/metal/mtl_glslang_utils.h" |
| 25402 |
+#include "libANGLE/renderer/metal/mtl_glslang_mtl_utils.h" |
| 25403 |
#include "libANGLE/renderer/metal/mtl_resources.h" |
| 25404 |
#include "libANGLE/renderer/metal/mtl_state_cache.h" |
| 25405 |
|
| 25406 |
namespace rx |
| 25407 |
{ |
| 25408 |
+#define SHADER_ENTRY_NAME @"main0" |
| 25409 |
class ContextMtl; |
| 25410 |
|
| 25411 |
struct ProgramArgumentBufferEncoderMtl |
| 25412 |
@@ -134,6 +135,10 @@ class ProgramMtl : public ProgramImpl, public mtl::RenderPipelineCacheSpecialize |
| 25413 |
bool hasSpecializedShader(gl::ShaderType shaderType, |
| 25414 |
const mtl::RenderPipelineDesc &renderPipelineDesc) override; |
| 25415 |
|
| 25416 |
+ angle::Result createMslShaderLib(mtl::Context *context, |
| 25417 |
+ gl::ShaderType shaderType, |
| 25418 |
+ gl::InfoLog &infoLog, |
| 25419 |
+ mtl::TranslatedShaderInfo *translatedMslInfo); |
| 25420 |
// Calls this before drawing, changedPipelineDesc is passed when vertex attributes desc and/or |
| 25421 |
// shader program changed. |
| 25422 |
angle::Result setupDraw(const gl::Context *glContext, |
| 25423 |
@@ -141,7 +146,12 @@ class ProgramMtl : public ProgramImpl, public mtl::RenderPipelineCacheSpecialize |
| 25424 |
const mtl::RenderPipelineDesc &pipelineDesc, |
| 25425 |
bool pipelineDescChanged, |
| 25426 |
bool forceTexturesSetting, |
| 25427 |
- bool uniformBuffersDirty); |
| 25428 |
+ bool uniformBuffersDirty, |
| 25429 |
+ bool transformFeedbackDraw); |
| 25430 |
+ |
| 25431 |
+ std::string getXfbMslSource() const { return mXfbMslSource; } |
| 25432 |
+ |
| 25433 |
+ mtl::RenderPipelineCache *mMetalXfbRenderPipelineCache; |
| 25434 |
|
| 25435 |
private: |
| 25436 |
template <int cols, int rows> |
| 25437 |
@@ -156,6 +166,11 @@ class ProgramMtl : public ProgramImpl, public mtl::RenderPipelineCacheSpecialize |
| 25438 |
void setUniformImpl(GLint location, GLsizei count, const T *v, GLenum entryPointType); |
| 25439 |
|
| 25440 |
angle::Result initDefaultUniformBlocks(const gl::Context *glContext); |
| 25441 |
+ angle::Result resizeDefaultUniformBlocksMemory(const gl::Context *glContext, |
| 25442 |
+ const gl::ShaderMap<size_t> &requiredBufferSize); |
| 25443 |
+ void saveDefaultUniformBlocksInfo(gl::BinaryOutputStream *stream); |
| 25444 |
+ angle::Result loadDefaultUniformBlocksInfo(const gl::Context *glContext, |
| 25445 |
+ gl::BinaryInputStream *stream); |
| 25446 |
|
| 25447 |
angle::Result commitUniforms(ContextMtl *context, mtl::RenderCommandEncoder *cmdEncoder); |
| 25448 |
angle::Result updateTextures(const gl::Context *glContext, |
| 25449 |
@@ -177,21 +192,33 @@ class ProgramMtl : public ProgramImpl, public mtl::RenderPipelineCacheSpecialize |
| 25450 |
const std::vector<gl::InterfaceBlock> &blocks, |
| 25451 |
gl::ShaderType shaderType); |
| 25452 |
|
| 25453 |
- angle::Result updateXfbBuffers(ContextMtl *context, |
| 25454 |
- mtl::RenderCommandEncoder *cmdEncoder, |
| 25455 |
- const mtl::RenderPipelineDesc &pipelineDesc); |
| 25456 |
- |
| 25457 |
void reset(ContextMtl *context); |
| 25458 |
|
| 25459 |
+ void saveTranslatedShaders(gl::BinaryOutputStream *stream); |
| 25460 |
+ void loadTranslatedShaders(gl::BinaryInputStream *stream); |
| 25461 |
+ |
| 25462 |
+ void saveShaderInternalInfo(gl::BinaryOutputStream *stream); |
| 25463 |
+ void loadShaderInternalInfo(gl::BinaryInputStream *stream); |
| 25464 |
+ |
| 25465 |
+#if ANGLE_ENABLE_METAL_SPIRV |
| 25466 |
+ |
| 25467 |
+ angle::Result linkImplSpirv(const gl::Context *glContext, |
| 25468 |
+ const gl::ProgramLinkedResources &resources, |
| 25469 |
+ gl::InfoLog &infoLog); |
| 25470 |
+#endif |
| 25471 |
+ |
| 25472 |
+ angle::Result linkImplDirect(const gl::Context *glContext, |
| 25473 |
+ const gl::ProgramLinkedResources &resources, |
| 25474 |
+ gl::InfoLog &infoLog); |
| 25475 |
+ |
| 25476 |
void linkResources(const gl::ProgramLinkedResources &resources); |
| 25477 |
angle::Result linkImpl(const gl::Context *glContext, |
| 25478 |
const gl::ProgramLinkedResources &resources, |
| 25479 |
gl::InfoLog &infoLog); |
| 25480 |
|
| 25481 |
- angle::Result createMslShaderLib(mtl::Context *context, |
| 25482 |
- gl::ShaderType shaderType, |
| 25483 |
- gl::InfoLog &infoLog, |
| 25484 |
- mtl::TranslatedShaderInfo *translatedMslInfo); |
| 25485 |
+ angle::Result linkTranslatedShaders(const gl::Context *glContext, |
| 25486 |
+ gl::BinaryInputStream *stream, |
| 25487 |
+ gl::InfoLog &infoLog); |
| 25488 |
|
| 25489 |
// State for the default uniform blocks. |
| 25490 |
struct DefaultUniformBlock final : private angle::NonCopyable |
| 25491 |
@@ -230,6 +257,7 @@ class ProgramMtl : public ProgramImpl, public mtl::RenderPipelineCacheSpecialize |
| 25492 |
// Cached references of current shader variants. |
| 25493 |
gl::ShaderMap<ProgramShaderObjVariantMtl *> mCurrentShaderVariants; |
| 25494 |
|
| 25495 |
+ ShaderMapInterfaceVariableInfoMap mVariableInfoMap; |
| 25496 |
// Scratch data: |
| 25497 |
// Legalized buffers and their offsets. For example, uniform buffer's offset=1 is not a valid |
| 25498 |
// offset, it will be converted to legal offset and the result is stored in this array. |
| 25499 |
@@ -238,7 +266,10 @@ class ProgramMtl : public ProgramImpl, public mtl::RenderPipelineCacheSpecialize |
| 25500 |
// into an argument buffer. |
| 25501 |
std::vector<uint32_t> mArgumentBufferRenderStageUsages; |
| 25502 |
|
| 25503 |
+ uint32_t mShadowCompareModes[mtl::kMaxShaderSamplers] = {0}; |
| 25504 |
+ |
| 25505 |
mtl::RenderPipelineCache mMetalRenderPipelineCache; |
| 25506 |
+ std::string mXfbMslSource; |
| 25507 |
}; |
| 25508 |
|
| 25509 |
} // namespace rx |
| 25510 |
diff --git a/src/libANGLE/renderer/metal/ProgramMtl.mm b/src/libANGLE/renderer/metal/ProgramMtl.mm |
| 25511 |
index 50e2f63..6da8664 100644 |
| 25512 |
--- a/src/libANGLE/renderer/metal/ProgramMtl.mm |
| 25513 |
+++ b/src/libANGLE/renderer/metal/ProgramMtl.mm |
| 25514 |
@@ -14,25 +14,31 @@ |
| 25515 |
#include <sstream> |
| 25516 |
|
| 25517 |
#include "common/debug.h" |
| 25518 |
+#include "compiler/translator/TranslatorMetal.h" |
| 25519 |
+#include "compiler/translator/TranslatorMetalDirect.h" |
| 25520 |
+#include "compiler/translator/TranslatorMetalDirect/EnvironmentVariable.h" |
| 25521 |
#include "libANGLE/Context.h" |
| 25522 |
#include "libANGLE/ProgramLinkedResources.h" |
| 25523 |
#include "libANGLE/renderer/metal/BufferMtl.h" |
| 25524 |
#include "libANGLE/renderer/metal/ContextMtl.h" |
| 25525 |
#include "libANGLE/renderer/metal/DisplayMtl.h" |
| 25526 |
#include "libANGLE/renderer/metal/TextureMtl.h" |
| 25527 |
-#include "libANGLE/renderer/metal/mtl_glslang_utils.h" |
| 25528 |
+#include "libANGLE/renderer/metal/mtl_glslang_mtl_utils.h" |
| 25529 |
#include "libANGLE/renderer/metal/mtl_utils.h" |
| 25530 |
#include "libANGLE/renderer/renderer_utils.h" |
| 25531 |
|
| 25532 |
+#if ANGLE_ENABLE_METAL_SPIRV |
| 25533 |
+# include "libANGLE/renderer/metal/mtl_glslang_utils.h" |
| 25534 |
+#endif |
| 25535 |
+ |
| 25536 |
namespace rx |
| 25537 |
{ |
| 25538 |
|
| 25539 |
namespace |
| 25540 |
{ |
| 25541 |
- |
| 25542 |
-#define SHADER_ENTRY_NAME @"main0" |
| 25543 |
+#if ANGLE_ENABLE_METAL_SPIRV |
| 25544 |
constexpr char kSpirvCrossSpecConstSuffix[] = "_tmp"; |
| 25545 |
- |
| 25546 |
+#endif |
| 25547 |
template <typename T> |
| 25548 |
class ScopedAutoClearVector |
| 25549 |
{ |
| 25550 |
@@ -78,6 +84,7 @@ void InitDefaultUniformBlock(const std::vector<sh::Uniform> &uniforms, |
| 25551 |
|
| 25552 |
size_t blockSize = blockEncoder.getCurrentOffset(); |
| 25553 |
|
| 25554 |
+ // TODO(jmadill): I think we still need a valid block for the pipeline even if zero sized. |
| 25555 |
if (blockSize == 0) |
| 25556 |
{ |
| 25557 |
*blockSizeOut = 0; |
| 25558 |
@@ -228,11 +235,16 @@ void InitArgumentBufferEncoder(mtl::Context *context, |
| 25559 |
|
| 25560 |
ProgramMtl::DefaultUniformBlock::~DefaultUniformBlock() = default; |
| 25561 |
|
| 25562 |
-ProgramMtl::ProgramMtl(const gl::ProgramState &state) |
| 25563 |
- : ProgramImpl(state), mMetalRenderPipelineCache(this) |
| 25564 |
-{} |
| 25565 |
+ProgramMtl::ProgramMtl(const gl::ProgramState &state) : ProgramImpl(state), |
| 25566 |
+ mMetalRenderPipelineCache(this) |
| 25567 |
+{ |
| 25568 |
+ mMetalXfbRenderPipelineCache = new mtl::RenderPipelineCache(); |
| 25569 |
+} |
| 25570 |
|
| 25571 |
-ProgramMtl::~ProgramMtl() {} |
| 25572 |
+ProgramMtl::~ProgramMtl() |
| 25573 |
+{ |
| 25574 |
+ delete mMetalXfbRenderPipelineCache; |
| 25575 |
+} |
| 25576 |
|
| 25577 |
void ProgramMtl::destroy(const gl::Context *context) |
| 25578 |
{ |
| 25579 |
@@ -262,25 +274,46 @@ void InitArgumentBufferEncoder(mtl::Context *context, |
| 25580 |
{ |
| 25581 |
var.reset(context); |
| 25582 |
} |
| 25583 |
- |
| 25584 |
mMetalRenderPipelineCache.clear(); |
| 25585 |
+ mMetalXfbRenderPipelineCache->clear(); |
| 25586 |
+} |
| 25587 |
+ |
| 25588 |
+void ProgramMtl::saveTranslatedShaders(gl::BinaryOutputStream *stream) |
| 25589 |
+{ |
| 25590 |
+ // Write out shader sources for all shader types |
| 25591 |
+ for (const gl::ShaderType shaderType : gl::AllShaderTypes()) |
| 25592 |
+ { |
| 25593 |
+ stream->writeString(mMslShaderTranslateInfo[shaderType].metalShaderSource); |
| 25594 |
+ } |
| 25595 |
+ stream->writeString(mXfbMslSource); |
| 25596 |
+} |
| 25597 |
+ |
| 25598 |
+void ProgramMtl::loadTranslatedShaders(gl::BinaryInputStream *stream) |
| 25599 |
+{ |
| 25600 |
+ // Read in shader sources for all shader types |
| 25601 |
+ for (const gl::ShaderType shaderType : gl::AllShaderTypes()) |
| 25602 |
+ { |
| 25603 |
+ mMslShaderTranslateInfo[shaderType].metalShaderSource = stream->readString(); |
| 25604 |
+ } |
| 25605 |
+ mXfbMslSource = stream->readString(); |
| 25606 |
} |
| 25607 |
|
| 25608 |
std::unique_ptr<rx::LinkEvent> ProgramMtl::load(const gl::Context *context, |
| 25609 |
gl::BinaryInputStream *stream, |
| 25610 |
gl::InfoLog &infoLog) |
| 25611 |
{ |
| 25612 |
- // NOTE(hqle): support binary shader |
| 25613 |
- UNIMPLEMENTED(); |
| 25614 |
- return std::make_unique<LinkEventDone>(angle::Result::Stop); |
| 25615 |
+ |
| 25616 |
+ return std::make_unique<LinkEventDone>(linkTranslatedShaders(context, stream, infoLog)); |
| 25617 |
} |
| 25618 |
|
| 25619 |
void ProgramMtl::save(const gl::Context *context, gl::BinaryOutputStream *stream) |
| 25620 |
{ |
| 25621 |
- // NOTE(hqle): support binary shader |
| 25622 |
- UNIMPLEMENTED(); |
| 25623 |
+ saveTranslatedShaders(stream); |
| 25624 |
+ saveShaderInternalInfo(stream); |
| 25625 |
+ saveDefaultUniformBlocksInfo(stream); |
| 25626 |
} |
| 25627 |
|
| 25628 |
+ |
| 25629 |
void ProgramMtl::setBinaryRetrievableHint(bool retrievable) |
| 25630 |
{ |
| 25631 |
UNIMPLEMENTED(); |
| 25632 |
@@ -294,7 +327,7 @@ void InitArgumentBufferEncoder(mtl::Context *context, |
| 25633 |
std::unique_ptr<LinkEvent> ProgramMtl::link(const gl::Context *context, |
| 25634 |
const gl::ProgramLinkedResources &resources, |
| 25635 |
gl::InfoLog &infoLog, |
| 25636 |
- const gl::ProgramMergedVaryings & /* mergedVaryings */) |
| 25637 |
+ const gl::ProgramMergedVaryings &mergedVaryings) |
| 25638 |
{ |
| 25639 |
// Link resources before calling GetShaderSource to make sure they are ready for the set/binding |
| 25640 |
// assignment done in that function. |
| 25641 |
@@ -304,7 +337,8 @@ void InitArgumentBufferEncoder(mtl::Context *context, |
| 25642 |
return std::make_unique<LinkEventDone>(linkImpl(context, resources, infoLog)); |
| 25643 |
} |
| 25644 |
|
| 25645 |
-angle::Result ProgramMtl::linkImpl(const gl::Context *glContext, |
| 25646 |
+#if ANGLE_ENABLE_METAL_SPIRV |
| 25647 |
+angle::Result ProgramMtl::linkImplSpirv(const gl::Context *glContext, |
| 25648 |
const gl::ProgramLinkedResources &resources, |
| 25649 |
gl::InfoLog &infoLog) |
| 25650 |
{ |
| 25651 |
@@ -355,6 +389,75 @@ void InitArgumentBufferEncoder(mtl::Context *context, |
| 25652 |
|
| 25653 |
return angle::Result::Continue; |
| 25654 |
} |
| 25655 |
+#endif |
| 25656 |
+ |
| 25657 |
+angle::Result ProgramMtl::linkImplDirect(const gl::Context *glContext, |
| 25658 |
+ const gl::ProgramLinkedResources &resources, |
| 25659 |
+ gl::InfoLog &infoLog) |
| 25660 |
+{ |
| 25661 |
+ ContextMtl *contextMtl = mtl::GetImpl(glContext); |
| 25662 |
+ |
| 25663 |
+ reset(contextMtl); |
| 25664 |
+ ANGLE_TRY(initDefaultUniformBlocks(glContext)); |
| 25665 |
+ ShaderMapInterfaceVariableInfoMap variableInfoMap; |
| 25666 |
+ |
| 25667 |
+ gl::ShaderMap<std::string> shaderSources; |
| 25668 |
+ gl::ShaderMap<std::string> translatedMslShaders; |
| 25669 |
+ mtl::MSLGetShaderSource(mState, resources, &shaderSources, &variableInfoMap); |
| 25670 |
+ |
| 25671 |
+ ANGLE_TRY(mtl::GlslangGetMSL(glContext, mState, contextMtl->getCaps(), shaderSources, |
| 25672 |
+ variableInfoMap, &mMslShaderTranslateInfo, |
| 25673 |
+ &translatedMslShaders, |
| 25674 |
+ mState.getExecutable().getTransformFeedbackBufferCount())); |
| 25675 |
+ |
| 25676 |
+ |
| 25677 |
+ for (gl::ShaderType shaderType : gl::AllGLES2ShaderTypes()) |
| 25678 |
+ { |
| 25679 |
+ // Create actual Metal shader |
| 25680 |
+ ANGLE_TRY( |
| 25681 |
+ createMslShaderLib(contextMtl, shaderType, infoLog, &mMslShaderTranslateInfo[shaderType])); |
| 25682 |
+ } |
| 25683 |
+ return angle::Result::Continue; |
| 25684 |
+} |
| 25685 |
+ |
| 25686 |
+angle::Result ProgramMtl::linkImpl(const gl::Context *glContext, |
| 25687 |
+ const gl::ProgramLinkedResources &resources, |
| 25688 |
+ gl::InfoLog &infoLog) |
| 25689 |
+{ |
| 25690 |
+ // TODO: We need some way of toggling this. |
| 25691 |
+#if ANGLE_ENABLE_METAL_SPIRV |
| 25692 |
+ if (sh::readBoolEnvVar("ANGLE_GEN_MTL_WITH_SPIRV")) |
| 25693 |
+ { |
| 25694 |
+ return linkImplSpirv(glContext, resources, infoLog); |
| 25695 |
+ } |
| 25696 |
+ else |
| 25697 |
+#endif |
| 25698 |
+ { |
| 25699 |
+ return linkImplDirect(glContext, resources, infoLog); |
| 25700 |
+ } |
| 25701 |
+} |
| 25702 |
+ |
| 25703 |
+ |
| 25704 |
+angle::Result ProgramMtl::linkTranslatedShaders(const gl::Context *glContext, |
| 25705 |
+ gl::BinaryInputStream *stream, |
| 25706 |
+ gl::InfoLog &infoLog) |
| 25707 |
+{ |
| 25708 |
+ ContextMtl *contextMtl = mtl::GetImpl(glContext); |
| 25709 |
+ // NOTE(hqle): No transform feedbacks for now, since we only support ES 2.0 atm |
| 25710 |
+ |
| 25711 |
+ reset(contextMtl); |
| 25712 |
+ |
| 25713 |
+ loadTranslatedShaders(stream); |
| 25714 |
+ loadShaderInternalInfo(stream); |
| 25715 |
+ ANGLE_TRY(loadDefaultUniformBlocksInfo(glContext, stream)); |
| 25716 |
+ |
| 25717 |
+ ANGLE_TRY(createMslShaderLib(contextMtl, gl::ShaderType::Vertex, infoLog, |
| 25718 |
+ &mMslShaderTranslateInfo[gl::ShaderType::Vertex])); |
| 25719 |
+ ANGLE_TRY(createMslShaderLib(contextMtl, gl::ShaderType::Fragment, infoLog, |
| 25720 |
+ &mMslShaderTranslateInfo[gl::ShaderType::Fragment])); |
| 25721 |
+ |
| 25722 |
+ return angle::Result::Continue; |
| 25723 |
+} |
| 25724 |
|
| 25725 |
void ProgramMtl::linkResources(const gl::ProgramLinkedResources &resources) |
| 25726 |
{ |
| 25727 |
@@ -366,8 +469,6 @@ void InitArgumentBufferEncoder(mtl::Context *context, |
| 25728 |
|
| 25729 |
angle::Result ProgramMtl::initDefaultUniformBlocks(const gl::Context *glContext) |
| 25730 |
{ |
| 25731 |
- ContextMtl *contextMtl = mtl::GetImpl(glContext); |
| 25732 |
- |
| 25733 |
// Process vertex and fragment uniforms into std140 packing. |
| 25734 |
gl::ShaderMap<sh::BlockLayoutMap> layoutMap; |
| 25735 |
gl::ShaderMap<size_t> requiredBufferSize; |
| 25736 |
@@ -426,6 +527,15 @@ void InitArgumentBufferEncoder(mtl::Context *context, |
| 25737 |
} |
| 25738 |
} |
| 25739 |
|
| 25740 |
+ return resizeDefaultUniformBlocksMemory(glContext, requiredBufferSize); |
| 25741 |
+} |
| 25742 |
+ |
| 25743 |
+angle::Result ProgramMtl::resizeDefaultUniformBlocksMemory( |
| 25744 |
+ const gl::Context *glContext, |
| 25745 |
+ const gl::ShaderMap<size_t> &requiredBufferSize) |
| 25746 |
+{ |
| 25747 |
+ ContextMtl *contextMtl = mtl::GetImpl(glContext); |
| 25748 |
+ |
| 25749 |
for (gl::ShaderType shaderType : gl::AllGLES2ShaderTypes()) |
| 25750 |
{ |
| 25751 |
if (requiredBufferSize[shaderType] > 0) |
| 25752 |
@@ -453,6 +563,9 @@ void InitArgumentBufferEncoder(mtl::Context *context, |
| 25753 |
id<MTLFunction> *shaderOut) |
| 25754 |
{ |
| 25755 |
static_assert(YES == 1, "YES should have value of 1"); |
| 25756 |
+ #if ANGLE_ENABLE_METAL_SPIRV |
| 25757 |
+ static const bool useSpirv = sh::readBoolEnvVar("ANGLE_GEN_MTL_WITH_SPIRV"); |
| 25758 |
+ #endif |
| 25759 |
|
| 25760 |
mtl::TranslatedShaderInfo *translatedMslInfo = &mMslShaderTranslateInfo[shaderType]; |
| 25761 |
ProgramShaderObjVariantMtl *shaderVariant; |
| 25762 |
@@ -490,9 +603,22 @@ void InitArgumentBufferEncoder(mtl::Context *context, |
| 25763 |
BOOL emulateDiscard = renderPipelineDesc.rasterizationType == |
| 25764 |
mtl::RenderPipelineRasterization::EmulatedDiscard; |
| 25765 |
|
| 25766 |
- NSString *discardEnabledStr = |
| 25767 |
- [NSString stringWithFormat:@"%s%s", sh::mtl::kRasterizerDiscardEnabledConstName, |
| 25768 |
+ NSString *discardEnabledStr; |
| 25769 |
+#if ANGLE_ENABLE_METAL_SPIRV |
| 25770 |
+ if (useSpirv) |
| 25771 |
+ { |
| 25772 |
+ discardEnabledStr = [NSString |
| 25773 |
+ stringWithFormat:@"%s%s", |
| 25774 |
+ sh::TranslatorMetal::GetRasterizationDiscardEnabledConstName(), |
| 25775 |
kSpirvCrossSpecConstSuffix]; |
| 25776 |
+ } |
| 25777 |
+ else |
| 25778 |
+#endif |
| 25779 |
+ { |
| 25780 |
+ discardEnabledStr = |
| 25781 |
+ [NSString stringWithUTF8String:sh::TranslatorMetalDirect:: |
| 25782 |
+ GetRasterizationDiscardEnabledConstName()]; |
| 25783 |
+ } |
| 25784 |
|
| 25785 |
funcConstants = [[MTLFunctionConstantValues alloc] init]; |
| 25786 |
[funcConstants setConstantValue:&emulateDiscard |
| 25787 |
@@ -515,9 +641,22 @@ void InitArgumentBufferEncoder(mtl::Context *context, |
| 25788 |
|
| 25789 |
ANGLE_MTL_OBJC_SCOPE |
| 25790 |
{ |
| 25791 |
- NSString *coverageMaskEnabledStr = |
| 25792 |
- [NSString stringWithFormat:@"%s%s", sh::mtl::kCoverageMaskEnabledConstName, |
| 25793 |
+ NSString *coverageMaskEnabledStr; |
| 25794 |
+#if ANGLE_ENABLE_METAL_SPIRV |
| 25795 |
+ if (useSpirv) |
| 25796 |
+ { |
| 25797 |
+ coverageMaskEnabledStr = [NSString |
| 25798 |
+ stringWithFormat:@"%s%s", |
| 25799 |
+ sh::TranslatorMetal::GetCoverageMaskEnabledConstName(), |
| 25800 |
kSpirvCrossSpecConstSuffix]; |
| 25801 |
+ } |
| 25802 |
+ else |
| 25803 |
+#endif |
| 25804 |
+ { |
| 25805 |
+ coverageMaskEnabledStr = |
| 25806 |
+ [NSString stringWithUTF8String:sh::TranslatorMetalDirect:: |
| 25807 |
+ GetCoverageMaskEnabledConstName()]; |
| 25808 |
+ } |
| 25809 |
|
| 25810 |
funcConstants = [[MTLFunctionConstantValues alloc] init]; |
| 25811 |
[funcConstants setConstantValue:&emulateCoverageMask |
| 25812 |
@@ -555,6 +694,7 @@ void InitArgumentBufferEncoder(mtl::Context *context, |
| 25813 |
|
| 25814 |
return angle::Result::Continue; |
| 25815 |
} |
| 25816 |
+ |
| 25817 |
bool ProgramMtl::hasSpecializedShader(gl::ShaderType shaderType, |
| 25818 |
const mtl::RenderPipelineDesc &renderPipelineDesc) |
| 25819 |
{ |
| 25820 |
@@ -592,6 +732,93 @@ void InitArgumentBufferEncoder(mtl::Context *context, |
| 25821 |
} |
| 25822 |
} |
| 25823 |
|
| 25824 |
+void ProgramMtl::saveDefaultUniformBlocksInfo(gl::BinaryOutputStream *stream) |
| 25825 |
+{ |
| 25826 |
+ // Serializes the uniformLayout data of mDefaultUniformBlocks |
| 25827 |
+ for (gl::ShaderType shaderType : gl::AllShaderTypes()) |
| 25828 |
+ { |
| 25829 |
+ const size_t uniformCount = mDefaultUniformBlocks[shaderType].uniformLayout.size(); |
| 25830 |
+ stream->writeInt<size_t>(uniformCount); |
| 25831 |
+ for (unsigned int uniformIndex = 0; uniformIndex < uniformCount; ++uniformIndex) |
| 25832 |
+ { |
| 25833 |
+ sh::BlockMemberInfo &blockInfo = |
| 25834 |
+ mDefaultUniformBlocks[shaderType].uniformLayout[uniformIndex]; |
| 25835 |
+ gl::WriteBlockMemberInfo(stream, blockInfo); |
| 25836 |
+ } |
| 25837 |
+ } |
| 25838 |
+ |
| 25839 |
+ // Serializes required uniform block memory sizes |
| 25840 |
+ for (gl::ShaderType shaderType : gl::AllShaderTypes()) |
| 25841 |
+ { |
| 25842 |
+ stream->writeInt(mDefaultUniformBlocks[shaderType].uniformData.size()); |
| 25843 |
+ } |
| 25844 |
+} |
| 25845 |
+ |
| 25846 |
+angle::Result ProgramMtl::loadDefaultUniformBlocksInfo(const gl::Context *glContext, |
| 25847 |
+ gl::BinaryInputStream *stream) |
| 25848 |
+{ |
| 25849 |
+ gl::ShaderMap<size_t> requiredBufferSize; |
| 25850 |
+ requiredBufferSize.fill(0); |
| 25851 |
+ |
| 25852 |
+ // Deserializes the uniformLayout data of mDefaultUniformBlocks |
| 25853 |
+ for (gl::ShaderType shaderType : gl::AllShaderTypes()) |
| 25854 |
+ { |
| 25855 |
+ const size_t uniformCount = stream->readInt<size_t>(); |
| 25856 |
+ for (unsigned int uniformIndex = 0; uniformIndex < uniformCount; ++uniformIndex) |
| 25857 |
+ { |
| 25858 |
+ sh::BlockMemberInfo blockInfo; |
| 25859 |
+ gl::LoadBlockMemberInfo(stream, &blockInfo); |
| 25860 |
+ mDefaultUniformBlocks[shaderType].uniformLayout.push_back(blockInfo); |
| 25861 |
+ } |
| 25862 |
+ } |
| 25863 |
+ |
| 25864 |
+ // Deserializes required uniform block memory sizes |
| 25865 |
+ for (gl::ShaderType shaderType : gl::AllShaderTypes()) |
| 25866 |
+ { |
| 25867 |
+ requiredBufferSize[shaderType] = stream->readInt<size_t>(); |
| 25868 |
+ } |
| 25869 |
+ |
| 25870 |
+ return resizeDefaultUniformBlocksMemory(glContext, requiredBufferSize); |
| 25871 |
+} |
| 25872 |
+ |
| 25873 |
+void ProgramMtl::saveShaderInternalInfo(gl::BinaryOutputStream *stream) |
| 25874 |
+{ |
| 25875 |
+ for (gl::ShaderType shaderType : gl::AllShaderTypes()) |
| 25876 |
+ { |
| 25877 |
+ stream->writeInt<int>(mMslShaderTranslateInfo[shaderType].hasUBOArgumentBuffer); |
| 25878 |
+ for (const mtl::SamplerBinding &binding : |
| 25879 |
+ mMslShaderTranslateInfo[shaderType].actualSamplerBindings) |
| 25880 |
+ { |
| 25881 |
+ stream->writeInt<uint32_t>(binding.textureBinding); |
| 25882 |
+ stream->writeInt<uint32_t>(binding.samplerBinding); |
| 25883 |
+ } |
| 25884 |
+ |
| 25885 |
+ for (uint32_t uboBinding : mMslShaderTranslateInfo[shaderType].actualUBOBindings) |
| 25886 |
+ { |
| 25887 |
+ stream->writeInt<uint32_t>(uboBinding); |
| 25888 |
+ } |
| 25889 |
+ } |
| 25890 |
+} |
| 25891 |
+ |
| 25892 |
+void ProgramMtl::loadShaderInternalInfo(gl::BinaryInputStream *stream) |
| 25893 |
+{ |
| 25894 |
+ for (gl::ShaderType shaderType : gl::AllShaderTypes()) |
| 25895 |
+ { |
| 25896 |
+ mMslShaderTranslateInfo[shaderType].hasUBOArgumentBuffer = stream->readInt<int>() != 0; |
| 25897 |
+ for (mtl::SamplerBinding &binding : |
| 25898 |
+ mMslShaderTranslateInfo[shaderType].actualSamplerBindings) |
| 25899 |
+ { |
| 25900 |
+ binding.textureBinding = stream->readInt<uint32_t>(); |
| 25901 |
+ binding.samplerBinding = stream->readInt<uint32_t>(); |
| 25902 |
+ } |
| 25903 |
+ |
| 25904 |
+ for (uint32_t &uboBinding : mMslShaderTranslateInfo[shaderType].actualUBOBindings) |
| 25905 |
+ { |
| 25906 |
+ uboBinding = stream->readInt<uint32_t>(); |
| 25907 |
+ } |
| 25908 |
+ } |
| 25909 |
+} |
| 25910 |
+ |
| 25911 |
GLboolean ProgramMtl::validate(const gl::Caps &caps, gl::InfoLog *infoLog) |
| 25912 |
{ |
| 25913 |
// No-op. The spec is very vague about the behavior of validation. |
| 25914 |
@@ -877,14 +1104,25 @@ void InitArgumentBufferEncoder(mtl::Context *context, |
| 25915 |
const mtl::RenderPipelineDesc &pipelineDesc, |
| 25916 |
bool pipelineDescChanged, |
| 25917 |
bool forceTexturesSetting, |
| 25918 |
- bool uniformBuffersDirty) |
| 25919 |
+ bool uniformBuffersDirty, |
| 25920 |
+ bool transformFeedbackDraw) |
| 25921 |
{ |
| 25922 |
ContextMtl *context = mtl::GetImpl(glContext); |
| 25923 |
if (pipelineDescChanged) |
| 25924 |
{ |
| 25925 |
// Render pipeline state needs to be changed |
| 25926 |
- id<MTLRenderPipelineState> pipelineState = |
| 25927 |
- mMetalRenderPipelineCache.getRenderPipelineState(context, pipelineDesc); |
| 25928 |
+ id<MTLRenderPipelineState> pipelineState = nil; |
| 25929 |
+ if (transformFeedbackDraw) |
| 25930 |
+ { |
| 25931 |
+ mtl::RenderPipelineDesc xfbPipelineDesc = mtl::RenderPipelineDesc(pipelineDesc); |
| 25932 |
+ xfbPipelineDesc.rasterizationType = mtl::RenderPipelineRasterization::Disabled; |
| 25933 |
+ pipelineState = |
| 25934 |
+ mMetalXfbRenderPipelineCache->getRenderPipelineState(context, xfbPipelineDesc); |
| 25935 |
+ } |
| 25936 |
+ else |
| 25937 |
+ { |
| 25938 |
+ pipelineState = mMetalRenderPipelineCache.getRenderPipelineState(context, pipelineDesc); |
| 25939 |
+ } |
| 25940 |
if (!pipelineState) |
| 25941 |
{ |
| 25942 |
// Error already logged inside getRenderPipelineState() |
| 25943 |
@@ -913,11 +1151,6 @@ void InitArgumentBufferEncoder(mtl::Context *context, |
| 25944 |
ANGLE_TRY(updateUniformBuffers(context, cmdEncoder, pipelineDesc)); |
| 25945 |
} |
| 25946 |
|
| 25947 |
- if (pipelineDescChanged) |
| 25948 |
- { |
| 25949 |
- ANGLE_TRY(updateXfbBuffers(context, cmdEncoder, pipelineDesc)); |
| 25950 |
- } |
| 25951 |
- |
| 25952 |
return angle::Result::Continue; |
| 25953 |
} |
| 25954 |
|
| 25955 |
@@ -950,8 +1183,10 @@ void InitArgumentBufferEncoder(mtl::Context *context, |
| 25956 |
{ |
| 25957 |
ContextMtl *contextMtl = mtl::GetImpl(glContext); |
| 25958 |
const auto &glState = glContext->getState(); |
| 25959 |
+ const gl::ProgramExecutable *executable = glContext->getState().getProgramExecutable(); |
| 25960 |
|
| 25961 |
const gl::ActiveTexturesCache &completeTextures = glState.getActiveTexturesCache(); |
| 25962 |
+ const gl::ActiveTextureTypeArray &textureTypes = executable->getActiveSamplerTypes(); |
| 25963 |
|
| 25964 |
for (gl::ShaderType shaderType : gl::AllGLES2ShaderTypes()) |
| 25965 |
{ |
| 25966 |
@@ -964,6 +1199,8 @@ void InitArgumentBufferEncoder(mtl::Context *context, |
| 25967 |
const mtl::TranslatedShaderInfo &shaderInfo = |
| 25968 |
*mCurrentShaderVariants[shaderType]->translatedSrcInfo; |
| 25969 |
|
| 25970 |
+ bool hasDepthSampler = false; |
| 25971 |
+ |
| 25972 |
for (uint32_t textureIndex = 0; textureIndex < mState.getSamplerBindings().size(); |
| 25973 |
++textureIndex) |
| 25974 |
{ |
| 25975 |
@@ -975,7 +1212,6 @@ void InitArgumentBufferEncoder(mtl::Context *context, |
| 25976 |
continue; |
| 25977 |
} |
| 25978 |
|
| 25979 |
- gl::TextureType textureType = samplerBinding.textureType; |
| 25980 |
|
| 25981 |
for (uint32_t arrayElement = 0; arrayElement < samplerBinding.boundTextureUnits.size(); |
| 25982 |
++arrayElement) |
| 25983 |
@@ -983,6 +1219,7 @@ void InitArgumentBufferEncoder(mtl::Context *context, |
| 25984 |
GLuint textureUnit = samplerBinding.boundTextureUnits[arrayElement]; |
| 25985 |
gl::Texture *texture = completeTextures[textureUnit]; |
| 25986 |
gl::Sampler *sampler = contextMtl->getState().getSampler(textureUnit); |
| 25987 |
+ gl::TextureType textureType = textureTypes[textureUnit]; |
| 25988 |
uint32_t textureSlot = mslBinding.textureBinding + arrayElement; |
| 25989 |
uint32_t samplerSlot = mslBinding.samplerBinding + arrayElement; |
| 25990 |
if (!texture) |
| 25991 |
@@ -994,24 +1231,21 @@ void InitArgumentBufferEncoder(mtl::Context *context, |
| 25992 |
TextureMtl *textureMtl = mtl::GetImpl(texture); |
| 25993 |
if (samplerBinding.format == gl::SamplerFormat::Shadow) |
| 25994 |
{ |
| 25995 |
- // http://anglebug.com/5107 |
| 25996 |
- // Metal doesn't support a compare mode where sampling a shadow sampler could |
| 25997 |
- // return a same value as if sampling from a normal sampler. |
| 25998 |
- // Supporting this could require hacking spirv-cross to change sample_compare() |
| 25999 |
- // to sample(). |
| 26000 |
- if (ANGLE_UNLIKELY(samplerState->getCompareMode() != GL_COMPARE_REF_TO_TEXTURE)) |
| 26001 |
- { |
| 26002 |
- ERR() << "GL_TEXTURE_COMPARE_MODE != GL_COMPARE_REF_TO_TEXTURE is not " |
| 26003 |
- "supported"; |
| 26004 |
- ANGLE_MTL_TRY(contextMtl, |
| 26005 |
- samplerState->getCompareMode() == GL_COMPARE_REF_TO_TEXTURE); |
| 26006 |
- } |
| 26007 |
+ hasDepthSampler = true; |
| 26008 |
+ mShadowCompareModes[textureSlot] = mtl::MslGetShaderShadowCompareMode( |
| 26009 |
+ samplerState->getCompareMode(), samplerState->getCompareFunc()); |
| 26010 |
} |
| 26011 |
|
| 26012 |
ANGLE_TRY(textureMtl->bindToShader(glContext, cmdEncoder, shaderType, sampler, |
| 26013 |
textureSlot, samplerSlot)); |
| 26014 |
} // for array elements |
| 26015 |
} // for sampler bindings |
| 26016 |
+ |
| 26017 |
+ if (hasDepthSampler) |
| 26018 |
+ { |
| 26019 |
+ cmdEncoder->setData(shaderType, mShadowCompareModes, |
| 26020 |
+ mtl::kShadowSamplerCompareModesBindingIndex); |
| 26021 |
+ } |
| 26022 |
} // for shader types |
| 26023 |
|
| 26024 |
return angle::Result::Continue; |
| 26025 |
@@ -1040,11 +1274,6 @@ void InitArgumentBufferEncoder(mtl::Context *context, |
| 26026 |
|
| 26027 |
for (gl::ShaderType shaderType : gl::AllGLES2ShaderTypes()) |
| 26028 |
{ |
| 26029 |
- if (!mCurrentShaderVariants[shaderType]) |
| 26030 |
- { |
| 26031 |
- continue; |
| 26032 |
- } |
| 26033 |
- |
| 26034 |
if (mCurrentShaderVariants[shaderType]->translatedSrcInfo->hasUBOArgumentBuffer) |
| 26035 |
{ |
| 26036 |
ANGLE_TRY( |
| 26037 |
@@ -1149,8 +1378,6 @@ void InitArgumentBufferEncoder(mtl::Context *context, |
| 26038 |
gl::ShaderType shaderType) |
| 26039 |
{ |
| 26040 |
const gl::State &glState = context->getState(); |
| 26041 |
- const mtl::TranslatedShaderInfo &shaderInfo = |
| 26042 |
- *mCurrentShaderVariants[shaderType]->translatedSrcInfo; |
| 26043 |
for (uint32_t bufferIndex = 0; bufferIndex < blocks.size(); ++bufferIndex) |
| 26044 |
{ |
| 26045 |
const gl::InterfaceBlock &block = blocks[bufferIndex]; |
| 26046 |
@@ -1162,7 +1389,8 @@ void InitArgumentBufferEncoder(mtl::Context *context, |
| 26047 |
continue; |
| 26048 |
} |
| 26049 |
|
| 26050 |
- uint32_t actualBufferIdx = shaderInfo.actualUBOBindings[bufferIndex]; |
| 26051 |
+ uint32_t actualBufferIdx = |
| 26052 |
+ mMslShaderTranslateInfo[shaderType].actualUBOBindings[bufferIndex]; |
| 26053 |
|
| 26054 |
if (actualBufferIdx >= mtl::kMaxShaderBuffers) |
| 26055 |
{ |
| 26056 |
@@ -1199,12 +1427,12 @@ void InitArgumentBufferEncoder(mtl::Context *context, |
| 26057 |
[bufferEncoder.metalArgBufferEncoder setArgumentBuffer:argumentBuffer->get() |
| 26058 |
offset:argumentBufferOffset]; |
| 26059 |
|
| 26060 |
- static_assert(MTLRenderStageVertex == (0x1 << static_cast<uint32_t>(gl::ShaderType::Vertex)), |
| 26061 |
- "Expected gl ShaderType enum and Metal enum to relative to each other"); |
| 26062 |
- static_assert( |
| 26063 |
- MTLRenderStageFragment == (0x1 << static_cast<uint32_t>(gl::ShaderType::Fragment)), |
| 26064 |
- "Expected gl ShaderType enum and Metal enum to relative to each other"); |
| 26065 |
- auto mtlRenderStage = static_cast<MTLRenderStages>(0x1 << static_cast<uint32_t>(shaderType)); |
| 26066 |
+ constexpr gl::ShaderMap<MTLRenderStages> kShaderStageMap = { |
| 26067 |
+ {gl::ShaderType::Vertex, mtl::kRenderStageVertex}, |
| 26068 |
+ {gl::ShaderType::Fragment, mtl::kRenderStageFragment}, |
| 26069 |
+ }; |
| 26070 |
+ |
| 26071 |
+ auto mtlRenderStage = kShaderStageMap[shaderType]; |
| 26072 |
|
| 26073 |
for (uint32_t bufferIndex = 0; bufferIndex < blocks.size(); ++bufferIndex) |
| 26074 |
{ |
| 26075 |
@@ -1239,49 +1467,4 @@ void InitArgumentBufferEncoder(mtl::Context *context, |
| 26076 |
return angle::Result::Continue; |
| 26077 |
} |
| 26078 |
|
| 26079 |
-angle::Result ProgramMtl::updateXfbBuffers(ContextMtl *context, |
| 26080 |
- mtl::RenderCommandEncoder *cmdEncoder, |
| 26081 |
- const mtl::RenderPipelineDesc &pipelineDesc) |
| 26082 |
-{ |
| 26083 |
- const gl::State &glState = context->getState(); |
| 26084 |
- gl::TransformFeedback *transformFeedback = glState.getCurrentTransformFeedback(); |
| 26085 |
- |
| 26086 |
- if (pipelineDesc.rasterizationEnabled() || !glState.isTransformFeedbackActiveUnpaused() || |
| 26087 |
- ANGLE_UNLIKELY(!transformFeedback)) |
| 26088 |
- { |
| 26089 |
- // XFB output can only be used with rasterization disabled. |
| 26090 |
- return angle::Result::Continue; |
| 26091 |
- } |
| 26092 |
- |
| 26093 |
- size_t xfbBufferCount = glState.getProgramExecutable()->getTransformFeedbackBufferCount(); |
| 26094 |
- |
| 26095 |
- ASSERT(xfbBufferCount > 0); |
| 26096 |
- ASSERT(mState.getTransformFeedbackBufferMode() != GL_INTERLEAVED_ATTRIBS || |
| 26097 |
- xfbBufferCount == 1); |
| 26098 |
- |
| 26099 |
- for (size_t bufferIndex = 0; bufferIndex < xfbBufferCount; ++bufferIndex) |
| 26100 |
- { |
| 26101 |
- uint32_t actualBufferIdx = mMslXfbOnlyVertexShaderInfo.actualXFBBindings[bufferIndex]; |
| 26102 |
- |
| 26103 |
- if (actualBufferIdx >= mtl::kMaxShaderBuffers) |
| 26104 |
- { |
| 26105 |
- continue; |
| 26106 |
- } |
| 26107 |
- |
| 26108 |
- const gl::OffsetBindingPointer<gl::Buffer> &bufferBinding = |
| 26109 |
- transformFeedback->getIndexedBuffer(bufferIndex); |
| 26110 |
- gl::Buffer *buffer = bufferBinding.get(); |
| 26111 |
- ASSERT((bufferBinding.getOffset() % 4) == 0); |
| 26112 |
- ASSERT(buffer != nullptr); |
| 26113 |
- |
| 26114 |
- BufferMtl *bufferMtl = mtl::GetImpl(buffer); |
| 26115 |
- |
| 26116 |
- // Use offset=0, actual offset will be set in Driver Uniform inside ContextMtl. |
| 26117 |
- cmdEncoder->setBufferForWrite(gl::ShaderType::Vertex, bufferMtl->getCurrentBuffer(), 0, |
| 26118 |
- actualBufferIdx); |
| 26119 |
- } |
| 26120 |
- |
| 26121 |
- return angle::Result::Continue; |
| 26122 |
-} |
| 26123 |
- |
| 26124 |
} // namespace rx |
| 26125 |
diff --git a/src/libANGLE/renderer/metal/QueryMtl.h b/src/libANGLE/renderer/metal/QueryMtl.h |
| 26126 |
index 21854f6..278f1df 100644 |
| 26127 |
--- a/src/libANGLE/renderer/metal/QueryMtl.h |
| 26128 |
+++ b/src/libANGLE/renderer/metal/QueryMtl.h |
| 26129 |
@@ -1,5 +1,5 @@ |
| 26130 |
// |
| 26131 |
-// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 26132 |
+// Copyright (c) 2020 The ANGLE Project Authors. All rights reserved. |
| 26133 |
// Use of this source code is governed by a BSD-style license that can be |
| 26134 |
// found in the LICENSE file. |
| 26135 |
// |
| 26136 |
@@ -98,8 +98,7 @@ class QueryMtl : public QueryImpl |
| 26137 |
const mtl::BufferRef &getVisibilityResultBuffer() const { return mVisibilityResultBuffer; } |
| 26138 |
// Reset the occlusion query result stored in buffer to zero |
| 26139 |
void resetVisibilityResult(ContextMtl *contextMtl); |
| 26140 |
- |
| 26141 |
- void onTransformFeedbackEnd(const gl::Context *context); |
| 26142 |
+ void onTransformFeedbackEnd(GLsizeiptr primitivesDrawn); |
| 26143 |
|
| 26144 |
private: |
| 26145 |
template <typename T> |
| 26146 |
@@ -108,8 +107,13 @@ class QueryMtl : public QueryImpl |
| 26147 |
// List of offsets in the render pass's occlusion query pool buffer allocated for this query |
| 26148 |
VisibilityBufferOffsetsMtl mVisibilityBufferOffsets; |
| 26149 |
mtl::BufferRef mVisibilityResultBuffer; |
| 26150 |
+ // Used with TransformFeedbackPrimitivesWritten when transform feedback is emulated. |
| 26151 |
+ size_t mTransformFeedbackPrimitivesDrawn; |
| 26152 |
|
| 26153 |
- size_t mTransformFeedbackPrimitivesDrawn = 0; |
| 26154 |
+ // TODO(jcunningham): currently only used for mTransformFeedbackPrimitivesDrawn |
| 26155 |
+ // but can be used for rest of results |
| 26156 |
+ uint64_t mCachedResult; |
| 26157 |
+ bool mCachedResultValid; |
| 26158 |
}; |
| 26159 |
|
| 26160 |
} // namespace rx |
| 26161 |
diff --git a/src/libANGLE/renderer/metal/QueryMtl.mm b/src/libANGLE/renderer/metal/QueryMtl.mm |
| 26162 |
index f5e9bf3..ab0e7bf 100644 |
| 26163 |
--- a/src/libANGLE/renderer/metal/QueryMtl.mm |
| 26164 |
+++ b/src/libANGLE/renderer/metal/QueryMtl.mm |
| 26165 |
@@ -1,5 +1,5 @@ |
| 26166 |
// |
| 26167 |
-// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 26168 |
+// Copyright (c) 2020 The ANGLE Project Authors. All rights reserved. |
| 26169 |
// Use of this source code is governed by a BSD-style license that can be |
| 26170 |
// found in the LICENSE file. |
| 26171 |
// |
| 26172 |
@@ -13,7 +13,12 @@ |
| 26173 |
|
| 26174 |
namespace rx |
| 26175 |
{ |
| 26176 |
-QueryMtl::QueryMtl(gl::QueryType type) : QueryImpl(type) {} |
| 26177 |
+QueryMtl::QueryMtl(gl::QueryType type) |
| 26178 |
+ : QueryImpl(type), |
| 26179 |
+ mTransformFeedbackPrimitivesDrawn(0), |
| 26180 |
+ mCachedResult(0), |
| 26181 |
+ mCachedResultValid(false) |
| 26182 |
+{} |
| 26183 |
|
| 26184 |
QueryMtl::~QueryMtl() {} |
| 26185 |
|
| 26186 |
@@ -22,13 +27,14 @@ |
| 26187 |
ContextMtl *contextMtl = mtl::GetImpl(context); |
| 26188 |
if (!getAllocatedVisibilityOffsets().empty()) |
| 26189 |
{ |
| 26190 |
- contextMtl->onOcclusionQueryDestroy(context, this); |
| 26191 |
+ contextMtl->onOcclusionQueryDestroyed(context, this); |
| 26192 |
} |
| 26193 |
mVisibilityResultBuffer = nullptr; |
| 26194 |
} |
| 26195 |
|
| 26196 |
angle::Result QueryMtl::begin(const gl::Context *context) |
| 26197 |
{ |
| 26198 |
+ mCachedResultValid = false; |
| 26199 |
ContextMtl *contextMtl = mtl::GetImpl(context); |
| 26200 |
switch (getType()) |
| 26201 |
{ |
| 26202 |
@@ -47,7 +53,7 @@ |
| 26203 |
} |
| 26204 |
} |
| 26205 |
|
| 26206 |
- ANGLE_TRY(contextMtl->onOcclusionQueryBegin(context, this)); |
| 26207 |
+ ANGLE_TRY(contextMtl->onOcclusionQueryBegan(context, this)); |
| 26208 |
break; |
| 26209 |
case gl::QueryType::TransformFeedbackPrimitivesWritten: |
| 26210 |
mTransformFeedbackPrimitivesDrawn = 0; |
| 26211 |
@@ -66,12 +72,22 @@ |
| 26212 |
{ |
| 26213 |
case gl::QueryType::AnySamples: |
| 26214 |
case gl::QueryType::AnySamplesConservative: |
| 26215 |
- contextMtl->onOcclusionQueryEnd(context, this); |
| 26216 |
+ contextMtl->onOcclusionQueryEnded(context, this); |
| 26217 |
break; |
| 26218 |
case gl::QueryType::TransformFeedbackPrimitivesWritten: |
| 26219 |
+ { |
| 26220 |
+ mCachedResult = mTransformFeedbackPrimitivesDrawn; |
| 26221 |
+ |
| 26222 |
// There could be transform feedback in progress, so add the primitives drawn so far |
| 26223 |
// from the current transform feedback object. |
| 26224 |
- onTransformFeedbackEnd(context); |
| 26225 |
+ gl::TransformFeedback *transformFeedback = |
| 26226 |
+ context->getState().getCurrentTransformFeedback(); |
| 26227 |
+ if (transformFeedback) |
| 26228 |
+ { |
| 26229 |
+ mCachedResult += transformFeedback->getPrimitivesDrawn(); |
| 26230 |
+ } |
| 26231 |
+ mCachedResultValid = true; |
| 26232 |
+ } |
| 26233 |
break; |
| 26234 |
default: |
| 26235 |
UNIMPLEMENTED(); |
| 26236 |
@@ -110,7 +126,7 @@ |
| 26237 |
} |
| 26238 |
break; |
| 26239 |
case gl::QueryType::TransformFeedbackPrimitivesWritten: |
| 26240 |
- *params = static_cast<T>(mTransformFeedbackPrimitivesDrawn); |
| 26241 |
+ *params = static_cast<T>(mCachedResult); |
| 26242 |
break; |
| 26243 |
default: |
| 26244 |
UNIMPLEMENTED(); |
| 26245 |
@@ -137,7 +153,7 @@ |
| 26246 |
*available = !mVisibilityResultBuffer->isBeingUsedByGPU(contextMtl); |
| 26247 |
break; |
| 26248 |
case gl::QueryType::TransformFeedbackPrimitivesWritten: |
| 26249 |
- *available = true; |
| 26250 |
+ *available = mCachedResultValid; |
| 26251 |
break; |
| 26252 |
default: |
| 26253 |
UNIMPLEMENTED(); |
| 26254 |
@@ -175,13 +191,9 @@ |
| 26255 |
mVisibilityResultBuffer->syncContent(contextMtl, blitEncoder); |
| 26256 |
} |
| 26257 |
|
| 26258 |
-void QueryMtl::onTransformFeedbackEnd(const gl::Context *context) |
| 26259 |
+void QueryMtl::onTransformFeedbackEnd(GLsizeiptr primitivesDrawn) |
| 26260 |
{ |
| 26261 |
- gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback(); |
| 26262 |
- if (transformFeedback) |
| 26263 |
- { |
| 26264 |
- mTransformFeedbackPrimitivesDrawn += transformFeedback->getPrimitivesDrawn(); |
| 26265 |
- } |
| 26266 |
+ mTransformFeedbackPrimitivesDrawn += primitivesDrawn; |
| 26267 |
} |
| 26268 |
|
| 26269 |
} |
| 26270 |
diff --git a/src/libANGLE/renderer/metal/RenderBufferMtl.h b/src/libANGLE/renderer/metal/RenderBufferMtl.h |
| 26271 |
index 6fd7b1b..053020c 100644 |
| 26272 |
--- a/src/libANGLE/renderer/metal/RenderBufferMtl.h |
| 26273 |
+++ b/src/libANGLE/renderer/metal/RenderBufferMtl.h |
| 26274 |
@@ -57,6 +57,7 @@ class RenderbufferMtl : public RenderbufferImpl |
| 26275 |
|
| 26276 |
mtl::Format mFormat; |
| 26277 |
mtl::TextureRef mTexture; |
| 26278 |
+ mtl::TextureRef mImplicitMSTexture; |
| 26279 |
RenderTargetMtl mRenderTarget; |
| 26280 |
}; |
| 26281 |
|
| 26282 |
diff --git a/src/libANGLE/renderer/metal/RenderBufferMtl.mm b/src/libANGLE/renderer/metal/RenderBufferMtl.mm |
| 26283 |
index 63d6f4b..2f9b5f6 100644 |
| 26284 |
--- a/src/libANGLE/renderer/metal/RenderBufferMtl.mm |
| 26285 |
+++ b/src/libANGLE/renderer/metal/RenderBufferMtl.mm |
| 26286 |
@@ -28,6 +28,7 @@ |
| 26287 |
void RenderbufferMtl::releaseTexture() |
| 26288 |
{ |
| 26289 |
mTexture = nullptr; |
| 26290 |
+ mImplicitMSTexture = nullptr; |
| 26291 |
} |
| 26292 |
|
| 26293 |
angle::Result RenderbufferMtl::setStorageImpl(const gl::Context *context, |
| 26294 |
@@ -42,8 +43,9 @@ |
| 26295 |
{ |
| 26296 |
// Check against the state if we need to recreate the storage. |
| 26297 |
if (internalformat != mState.getFormat().info->internalFormat || |
| 26298 |
- width != mState.getWidth() || height != mState.getHeight() || |
| 26299 |
- samples != mState.getSamples()) |
| 26300 |
+ static_cast<GLsizei>(width) != mState.getWidth() || |
| 26301 |
+ static_cast<GLsizei>(height) != mState.getHeight() || |
| 26302 |
+ static_cast<GLsizei>(samples) != mState.getSamples()) |
| 26303 |
{ |
| 26304 |
releaseTexture(); |
| 26305 |
} |
| 26306 |
@@ -72,30 +74,62 @@ |
| 26307 |
|
| 26308 |
if ((mTexture == nullptr || !mTexture->valid()) && (width != 0 && height != 0)) |
| 26309 |
{ |
| 26310 |
- if (actualSamples == 1) |
| 26311 |
+ if (actualSamples == 1 || (mFormat.hasDepthAndStencilBits() && mFormat.getCaps().resolve)) |
| 26312 |
{ |
| 26313 |
- ANGLE_TRY(mtl::Texture::Make2DTexture(contextMtl, mFormat, width, height, 1, false, |
| 26314 |
- mFormat.hasDepthAndStencilBits(), &mTexture)); |
| 26315 |
+ ANGLE_TRY(mtl::Texture::Make2DTexture(contextMtl, mFormat, static_cast<uint32_t>(width), |
| 26316 |
+ static_cast<uint32_t>(height), 1, |
| 26317 |
+ /* renderTargetOnly */ false, |
| 26318 |
+ /* allowFormatView */ false, &mTexture)); |
| 26319 |
+ |
| 26320 |
+ // Use implicit resolve for depth stencil texture whenever possible. This is because |
| 26321 |
+ // for depth stencil texture, if stencil needs to be blitted, a formatted clone has |
| 26322 |
+ // to be created. And it is expensive to clone a multisample texture. |
| 26323 |
+ if (actualSamples > 1) |
| 26324 |
+ { |
| 26325 |
+ // This format must supports implicit resolve |
| 26326 |
+ ASSERT(mFormat.getCaps().resolve); |
| 26327 |
+ |
| 26328 |
+ ANGLE_TRY(mtl::Texture::Make2DMSTexture( |
| 26329 |
+ contextMtl, mFormat, static_cast<uint32_t>(width), |
| 26330 |
+ static_cast<uint32_t>(height), actualSamples, |
| 26331 |
+ /* renderTargetOnly */ true, |
| 26332 |
+ /* allowFormatView */ false, &mImplicitMSTexture)); |
| 26333 |
+ } |
| 26334 |
} |
| 26335 |
else |
| 26336 |
{ |
| 26337 |
- ANGLE_TRY(mtl::Texture::Make2DMSTexture( |
| 26338 |
- contextMtl, mFormat, width, height, actualSamples, |
| 26339 |
+ ANGLE_TRY(mtl::Texture::Make2DMSTexture(contextMtl, mFormat, |
| 26340 |
+ static_cast<uint32_t>(width), |
| 26341 |
+ static_cast<uint32_t>(height), actualSamples, |
| 26342 |
/* renderTargetOnly */ false, |
| 26343 |
- /* allowFormatView */ mFormat.hasDepthAndStencilBits(), &mTexture)); |
| 26344 |
+ /* allowFormatView */ false, &mTexture)); |
| 26345 |
} |
| 26346 |
|
| 26347 |
- mRenderTarget.set(mTexture, mtl::kZeroNativeMipLevel, 0, mFormat); |
| 26348 |
+ mRenderTarget.setWithImplicitMSTexture(mTexture, mImplicitMSTexture, mtl::kZeroNativeMipLevel, 0, mFormat); |
| 26349 |
|
| 26350 |
// For emulated channels that GL texture intends to not have, |
| 26351 |
// we need to initialize their content. |
| 26352 |
bool emulatedChannels = mtl::IsFormatEmulated(mFormat); |
| 26353 |
if (emulatedChannels) |
| 26354 |
{ |
| 26355 |
- auto index = mtl::ImageNativeIndex::FromBaseZeroGLIndex(gl::ImageIndex::Make2D(0)); |
| 26356 |
+ gl::ImageIndex index; |
| 26357 |
|
| 26358 |
- ANGLE_TRY(mtl::InitializeTextureContents(context, mTexture, mFormat, index)); |
| 26359 |
+ if (actualSamples > 1) |
| 26360 |
+ { |
| 26361 |
+ index = gl::ImageIndex::Make2DMultisample(); |
| 26362 |
+ } |
| 26363 |
+ else |
| 26364 |
+ { |
| 26365 |
+ index = gl::ImageIndex::Make2D(0); |
| 26366 |
+ } |
| 26367 |
+ |
| 26368 |
+ ANGLE_TRY(mtl::InitializeTextureContents(context, mTexture, mFormat, mtl::ImageNativeIndex(index, 0))); |
| 26369 |
+ if (mImplicitMSTexture) |
| 26370 |
+ { |
| 26371 |
+ ANGLE_TRY(mtl::InitializeTextureContents(context, mImplicitMSTexture, mFormat, |
| 26372 |
+ mtl::ImageNativeIndex(gl::ImageIndex::Make2DMultisample(), 0))); |
| 26373 |
} |
| 26374 |
+ } // if (emulatedChannels) |
| 26375 |
} |
| 26376 |
|
| 26377 |
return angle::Result::Continue; |
| 26378 |
@@ -133,7 +167,6 @@ |
| 26379 |
GLsizei samples, |
| 26380 |
FramebufferAttachmentRenderTarget **rtOut) |
| 26381 |
{ |
| 26382 |
- // NOTE(hqle): Support MSAA. |
| 26383 |
ASSERT(mTexture && mTexture->valid()); |
| 26384 |
*rtOut = &mRenderTarget; |
| 26385 |
return angle::Result::Continue; |
| 26386 |
diff --git a/src/libANGLE/renderer/metal/RenderTargetMtl.h b/src/libANGLE/renderer/metal/RenderTargetMtl.h |
| 26387 |
index baf4e4d..0c57517 100644 |
| 26388 |
--- a/src/libANGLE/renderer/metal/RenderTargetMtl.h |
| 26389 |
+++ b/src/libANGLE/renderer/metal/RenderTargetMtl.h |
| 26390 |
@@ -46,20 +46,18 @@ class RenderTargetMtl final : public FramebufferAttachmentRenderTarget |
| 26391 |
void duplicateFrom(const RenderTargetMtl &src); |
| 26392 |
void reset(); |
| 26393 |
|
| 26394 |
- mtl::TextureRef getTexture() const { return mTexture.lock(); } |
| 26395 |
- mtl::TextureRef getImplicitMSTexture() const { return mImplicitMSTexture.lock(); } |
| 26396 |
- const mtl::MipmapNativeLevel &getLevelIndex() const { return mLevelIndex; } |
| 26397 |
- uint32_t getLayerIndex() const { return mLayerIndex; } |
| 26398 |
+ mtl::TextureRef getTexture() const { return mTextureRenderTargetInfo->getTextureRef(); } |
| 26399 |
+ mtl::TextureRef getImplicitMSTexture() const { return mTextureRenderTargetInfo->getImplicitMSTextureRef(); } |
| 26400 |
+ const mtl::MipmapNativeLevel &getLevelIndex() const { return mTextureRenderTargetInfo->level; } |
| 26401 |
+ uint32_t getLayerIndex() const { return mTextureRenderTargetInfo->sliceOrDepth; } |
| 26402 |
uint32_t getRenderSamples() const; |
| 26403 |
const mtl::Format *getFormat() const { return mFormat; } |
| 26404 |
|
| 26405 |
void toRenderPassAttachmentDesc(mtl::RenderPassAttachmentDesc *rpaDescOut) const; |
| 26406 |
|
| 26407 |
private: |
| 26408 |
- mtl::TextureWeakRef mTexture; |
| 26409 |
- mtl::TextureWeakRef mImplicitMSTexture; |
| 26410 |
- mtl::MipmapNativeLevel mLevelIndex = mtl::kZeroNativeMipLevel; |
| 26411 |
- uint32_t mLayerIndex = 0; |
| 26412 |
+// This is shared pointer to avoid crashing when texture deleted after bound to a frame buffer. |
| 26413 |
+ std::shared_ptr<mtl::RenderPassAttachmentTextureTargetDesc> mTextureRenderTargetInfo; |
| 26414 |
const mtl::Format *mFormat = nullptr; |
| 26415 |
}; |
| 26416 |
} // namespace rx |
| 26417 |
diff --git a/src/libANGLE/renderer/metal/RenderTargetMtl.mm b/src/libANGLE/renderer/metal/RenderTargetMtl.mm |
| 26418 |
index e89e761..e126dbb 100644 |
| 26419 |
--- a/src/libANGLE/renderer/metal/RenderTargetMtl.mm |
| 26420 |
+++ b/src/libANGLE/renderer/metal/RenderTargetMtl.mm |
| 26421 |
@@ -11,7 +11,10 @@ |
| 26422 |
|
| 26423 |
namespace rx |
| 26424 |
{ |
| 26425 |
-RenderTargetMtl::RenderTargetMtl() {} |
| 26426 |
+RenderTargetMtl::RenderTargetMtl() : |
| 26427 |
+ mTextureRenderTargetInfo(std::make_shared<mtl::RenderPassAttachmentTextureTargetDesc>()), |
| 26428 |
+ mFormat(nullptr) |
| 26429 |
+{} |
| 26430 |
|
| 26431 |
RenderTargetMtl::~RenderTargetMtl() |
| 26432 |
{ |
| 26433 |
@@ -19,10 +22,7 @@ |
| 26434 |
} |
| 26435 |
|
| 26436 |
RenderTargetMtl::RenderTargetMtl(RenderTargetMtl &&other) |
| 26437 |
- : mTexture(std::move(other.mTexture)), |
| 26438 |
- mImplicitMSTexture(std::move(other.mImplicitMSTexture)), |
| 26439 |
- mLevelIndex(other.mLevelIndex), |
| 26440 |
- mLayerIndex(other.mLayerIndex) |
| 26441 |
+ : mTextureRenderTargetInfo(std::move(other.mTextureRenderTargetInfo)) |
| 26442 |
{} |
| 26443 |
|
| 26444 |
void RenderTargetMtl::set(const mtl::TextureRef &texture, |
| 26445 |
@@ -39,21 +39,21 @@ |
| 26446 |
uint32_t layer, |
| 26447 |
const mtl::Format &format) |
| 26448 |
{ |
| 26449 |
- mTexture = texture; |
| 26450 |
- mImplicitMSTexture = implicitMSTexture; |
| 26451 |
- mLevelIndex = level; |
| 26452 |
- mLayerIndex = layer; |
| 26453 |
+ mTextureRenderTargetInfo->texture = texture; |
| 26454 |
+ mTextureRenderTargetInfo->implicitMSTexture = implicitMSTexture; |
| 26455 |
+ mTextureRenderTargetInfo->level = level; |
| 26456 |
+ mTextureRenderTargetInfo->sliceOrDepth = layer; |
| 26457 |
mFormat = &format; |
| 26458 |
} |
| 26459 |
|
| 26460 |
void RenderTargetMtl::setTexture(const mtl::TextureRef &texture) |
| 26461 |
{ |
| 26462 |
- mTexture = texture; |
| 26463 |
+ mTextureRenderTargetInfo->texture = texture; |
| 26464 |
} |
| 26465 |
|
| 26466 |
void RenderTargetMtl::setImplicitMSTexture(const mtl::TextureRef &implicitMSTexture) |
| 26467 |
{ |
| 26468 |
- mImplicitMSTexture = implicitMSTexture; |
| 26469 |
+ mTextureRenderTargetInfo->implicitMSTexture = implicitMSTexture; |
| 26470 |
} |
| 26471 |
|
| 26472 |
void RenderTargetMtl::duplicateFrom(const RenderTargetMtl &src) |
| 26473 |
@@ -64,25 +64,19 @@ |
| 26474 |
|
| 26475 |
void RenderTargetMtl::reset() |
| 26476 |
{ |
| 26477 |
- mTexture.reset(); |
| 26478 |
- mImplicitMSTexture.reset(); |
| 26479 |
- mLevelIndex = mtl::kZeroNativeMipLevel; |
| 26480 |
- mLayerIndex = 0; |
| 26481 |
+ mTextureRenderTargetInfo->texture.reset(); |
| 26482 |
+ mTextureRenderTargetInfo->implicitMSTexture.reset(); |
| 26483 |
+ mTextureRenderTargetInfo->level = mtl::kZeroNativeMipLevel; |
| 26484 |
+ mTextureRenderTargetInfo->sliceOrDepth = 0; |
| 26485 |
mFormat = nullptr; |
| 26486 |
} |
| 26487 |
|
| 26488 |
uint32_t RenderTargetMtl::getRenderSamples() const |
| 26489 |
{ |
| 26490 |
- mtl::TextureRef implicitMSTex = getImplicitMSTexture(); |
| 26491 |
- mtl::TextureRef tex = getTexture(); |
| 26492 |
- return implicitMSTex ? implicitMSTex->samples() : (tex ? tex->samples() : 1); |
| 26493 |
+ return mTextureRenderTargetInfo->getRenderSamples(); |
| 26494 |
} |
| 26495 |
void RenderTargetMtl::toRenderPassAttachmentDesc(mtl::RenderPassAttachmentDesc *rpaDescOut) const |
| 26496 |
{ |
| 26497 |
- rpaDescOut->texture = mTexture.lock(); |
| 26498 |
- rpaDescOut->implicitMSTexture = mImplicitMSTexture.lock(); |
| 26499 |
- rpaDescOut->level = mLevelIndex; |
| 26500 |
- rpaDescOut->sliceOrDepth = mLayerIndex; |
| 26501 |
- rpaDescOut->blendable = mFormat ? mFormat->getCaps().blendable : false; |
| 26502 |
+ rpaDescOut->renderTarget = mTextureRenderTargetInfo; |
| 26503 |
} |
| 26504 |
} |
| 26505 |
diff --git a/src/libANGLE/renderer/metal/ShaderMtl.h b/src/libANGLE/renderer/metal/ShaderMtl.h |
| 26506 |
index 7b2cfd5..52e91af 100644 |
| 26507 |
--- a/src/libANGLE/renderer/metal/ShaderMtl.h |
| 26508 |
+++ b/src/libANGLE/renderer/metal/ShaderMtl.h |
| 26509 |
@@ -11,8 +11,8 @@ |
| 26510 |
|
| 26511 |
#include <map> |
| 26512 |
|
| 26513 |
+#include "compiler/translator/TranslatorMetalDirect.h" |
| 26514 |
#include "libANGLE/renderer/ShaderImpl.h" |
| 26515 |
- |
| 26516 |
namespace rx |
| 26517 |
{ |
| 26518 |
|
| 26519 |
@@ -26,7 +26,19 @@ class ShaderMtl : public ShaderImpl |
| 26520 |
gl::ShCompilerInstance *compilerInstance, |
| 26521 |
ShCompileOptions options) override; |
| 26522 |
|
| 26523 |
+ sh::TranslatorMetalReflection *getTranslatorMetalReflection() |
| 26524 |
+ { |
| 26525 |
+ return &translatorMetalReflection; |
| 26526 |
+ } |
| 26527 |
std::string getDebugInfo() const override; |
| 26528 |
+ |
| 26529 |
+ sh::TranslatorMetalReflection translatorMetalReflection = {}; |
| 26530 |
+ |
| 26531 |
+ private: |
| 26532 |
+ std::shared_ptr<WaitableCompileEvent> compileImplMtl(const gl::Context *context, |
| 26533 |
+ gl::ShCompilerInstance *compilerInstance, |
| 26534 |
+ const std::string &source, |
| 26535 |
+ ShCompileOptions compileOptions); |
| 26536 |
}; |
| 26537 |
|
| 26538 |
} // namespace rx |
| 26539 |
diff --git a/src/libANGLE/renderer/metal/ShaderMtl.mm b/src/libANGLE/renderer/metal/ShaderMtl.mm |
| 26540 |
index f909fb5..ad01dbf 100644 |
| 26541 |
--- a/src/libANGLE/renderer/metal/ShaderMtl.mm |
| 26542 |
+++ b/src/libANGLE/renderer/metal/ShaderMtl.mm |
| 26543 |
@@ -10,8 +10,13 @@ |
| 26544 |
#include "libANGLE/renderer/metal/ShaderMtl.h" |
| 26545 |
|
| 26546 |
#include "common/debug.h" |
| 26547 |
+#include "compiler/translator/TranslatorMetal.h" |
| 26548 |
+#include "compiler/translator/TranslatorMetalDirect.h" |
| 26549 |
#include "libANGLE/Context.h" |
| 26550 |
+#include "libANGLE/Shader.h" |
| 26551 |
+#include "libANGLE/WorkerThread.h" |
| 26552 |
#include "libANGLE/renderer/metal/ContextMtl.h" |
| 26553 |
+#include "libANGLE/renderer/metal/DisplayMtl.h" |
| 26554 |
|
| 26555 |
namespace rx |
| 26556 |
{ |
| 26557 |
@@ -20,10 +25,100 @@ |
| 26558 |
|
| 26559 |
ShaderMtl::~ShaderMtl() {} |
| 26560 |
|
| 26561 |
+class TranslateTask : public angle::Closure |
| 26562 |
+{ |
| 26563 |
+ public: |
| 26564 |
+ TranslateTask(ShHandle handle, ShCompileOptions options, const std::string &source) |
| 26565 |
+ : mHandle(handle), mOptions(options), mSource(source), mResult(false) |
| 26566 |
+ {} |
| 26567 |
+ |
| 26568 |
+ void operator()() override |
| 26569 |
+ { |
| 26570 |
+ const char *source = mSource.c_str(); |
| 26571 |
+ mResult = sh::Compile(mHandle, &source, 1, mOptions); |
| 26572 |
+ } |
| 26573 |
+ |
| 26574 |
+ bool getResult() { return mResult; } |
| 26575 |
+ |
| 26576 |
+ ShHandle getHandle() { return mHandle; } |
| 26577 |
+ |
| 26578 |
+ private: |
| 26579 |
+ ShHandle mHandle; |
| 26580 |
+ ShCompileOptions mOptions; |
| 26581 |
+ std::string mSource; |
| 26582 |
+ bool mResult; |
| 26583 |
+}; |
| 26584 |
+ |
| 26585 |
+class MTLWaitableCompileEventImpl final : public WaitableCompileEvent |
| 26586 |
+{ |
| 26587 |
+ public: |
| 26588 |
+ MTLWaitableCompileEventImpl(ShaderMtl *shader, |
| 26589 |
+ std::shared_ptr<angle::WaitableEvent> waitableEvent, |
| 26590 |
+ std::shared_ptr<TranslateTask> translateTask) |
| 26591 |
+ : WaitableCompileEvent(waitableEvent), mTranslateTask(translateTask), mShader(shader) |
| 26592 |
+ {} |
| 26593 |
+ |
| 26594 |
+ bool getResult() override { return mTranslateTask->getResult(); } |
| 26595 |
+ |
| 26596 |
+ bool postTranslate(std::string *infoLog) override |
| 26597 |
+ { |
| 26598 |
+ sh::TShHandleBase *base = static_cast<sh::TShHandleBase *>(mTranslateTask->getHandle()); |
| 26599 |
+ auto translatorMetalDirect = base->getAsTranslatorMetalDirect(); |
| 26600 |
+ if (translatorMetalDirect != nullptr) |
| 26601 |
+ { |
| 26602 |
+ // Copy reflection from translation. |
| 26603 |
+ mShader->translatorMetalReflection = |
| 26604 |
+ *(translatorMetalDirect->getTranslatorMetalReflection()); |
| 26605 |
+ translatorMetalDirect->getTranslatorMetalReflection()->reset(); |
| 26606 |
+ } |
| 26607 |
+ return true; |
| 26608 |
+ } |
| 26609 |
+ |
| 26610 |
+ private: |
| 26611 |
+ std::shared_ptr<TranslateTask> mTranslateTask; |
| 26612 |
+ ShaderMtl *mShader; |
| 26613 |
+}; |
| 26614 |
+ |
| 26615 |
+std::shared_ptr<WaitableCompileEvent> ShaderMtl::compileImplMtl( |
| 26616 |
+ const gl::Context *context, |
| 26617 |
+ gl::ShCompilerInstance *compilerInstance, |
| 26618 |
+ const std::string &source, |
| 26619 |
+ ShCompileOptions compileOptions) |
| 26620 |
+{ |
| 26621 |
+#if defined(ANGLE_ENABLE_ASSERTS) |
| 26622 |
+ compileOptions |= SH_VALIDATE_AST; |
| 26623 |
+#endif |
| 26624 |
+ |
| 26625 |
+ auto workerThreadPool = context->getWorkerThreadPool(); |
| 26626 |
+ auto translateTask = |
| 26627 |
+ std::make_shared<TranslateTask>(compilerInstance->getHandle(), compileOptions, source); |
| 26628 |
+ |
| 26629 |
+ return std::make_shared<MTLWaitableCompileEventImpl>( |
| 26630 |
+ this, angle::WorkerThreadPool::PostWorkerTask(workerThreadPool, translateTask), |
| 26631 |
+ translateTask); |
| 26632 |
+} |
| 26633 |
+ |
| 26634 |
std::shared_ptr<WaitableCompileEvent> ShaderMtl::compile(const gl::Context *context, |
| 26635 |
gl::ShCompilerInstance *compilerInstance, |
| 26636 |
ShCompileOptions options) |
| 26637 |
{ |
| 26638 |
+ ContextMtl *contextMtl = mtl::GetImpl(context); |
| 26639 |
+ if (getState().getShaderType() == gl::ShaderType::Vertex && |
| 26640 |
+ !contextMtl->getDisplay()->getFeatures().hasBaseVertexInstancedDraw.enabled) |
| 26641 |
+ { |
| 26642 |
+ // Emulate gl_InstanceID |
| 26643 |
+ sh::TShHandleBase *base = static_cast<sh::TShHandleBase *>(compilerInstance->getHandle()); |
| 26644 |
+ auto translatorMetalDirect = base->getAsTranslatorMetalDirect(); |
| 26645 |
+ if (translatorMetalDirect == nullptr) |
| 26646 |
+ { |
| 26647 |
+ auto translatorMetal = static_cast<sh::TranslatorMetal *>(base->getAsCompiler()); |
| 26648 |
+ translatorMetal->enableEmulatedInstanceID(true); |
| 26649 |
+ } |
| 26650 |
+ else |
| 26651 |
+ { |
| 26652 |
+ translatorMetalDirect->enableEmulatedInstanceID(true); |
| 26653 |
+ } |
| 26654 |
+ } |
| 26655 |
ShCompileOptions compileOptions = SH_INITIALIZE_UNINITIALIZED_LOCALS; |
| 26656 |
|
| 26657 |
bool isWebGL = context->getExtensions().webglCompatibility; |
| 26658 |
@@ -33,8 +128,11 @@ |
| 26659 |
} |
| 26660 |
|
| 26661 |
compileOptions |= SH_CLAMP_POINT_SIZE; |
| 26662 |
+#if defined(ANGLE_PLATFORM_IOS) && !defined(ANGLE_PLATFORM_MACCATALYST) |
| 26663 |
+ compileOptions |= SH_CLAMP_FRAG_DEPTH; |
| 26664 |
+#endif |
| 26665 |
|
| 26666 |
- return compileImpl(context, compilerInstance, mState.getSource(), compileOptions | options); |
| 26667 |
+ return compileImplMtl(context, compilerInstance, getState().getSource(), compileOptions | options); |
| 26668 |
} |
| 26669 |
|
| 26670 |
std::string ShaderMtl::getDebugInfo() const |
| 26671 |
diff --git a/src/libANGLE/renderer/metal/SurfaceMtl.h b/src/libANGLE/renderer/metal/SurfaceMtl.h |
| 26672 |
index 9e84f88..0adc360 100644 |
| 26673 |
--- a/src/libANGLE/renderer/metal/SurfaceMtl.h |
| 26674 |
+++ b/src/libANGLE/renderer/metal/SurfaceMtl.h |
| 26675 |
@@ -24,7 +24,27 @@ namespace rx |
| 26676 |
|
| 26677 |
class DisplayMtl; |
| 26678 |
|
| 26679 |
-class SurfaceMtl : public SurfaceImpl |
| 26680 |
+class SurfaceMtlProtocol : public SurfaceImpl |
| 26681 |
+{ |
| 26682 |
+ public: |
| 26683 |
+ SurfaceMtlProtocol(const egl::SurfaceState &state) : SurfaceImpl(state) {} |
| 26684 |
+ virtual int getSamples() const = 0; |
| 26685 |
+ virtual bool preserveBuffer() const = 0; |
| 26686 |
+ |
| 26687 |
+ virtual angle::Result getAttachmentRenderTarget(const gl::Context *context, |
| 26688 |
+ GLenum binding, |
| 26689 |
+ const gl::ImageIndex &imageIndex, |
| 26690 |
+ GLsizei samples, |
| 26691 |
+ FramebufferAttachmentRenderTarget **rtOut) override = 0; |
| 26692 |
+ |
| 26693 |
+ virtual bool hasRobustResourceInit() const = 0; |
| 26694 |
+ virtual angle::Result ensureCurrentDrawableObtained(const gl::Context *context) = 0; |
| 26695 |
+ virtual angle::Result ensureCurrentDrawableObtained(const gl::Context *context, bool *newDrawableOut) = 0; |
| 26696 |
+ virtual angle::Result ensureColorTextureReadyForReadPixels(const gl::Context *context) = 0; |
| 26697 |
+ virtual const mtl::TextureRef & getColorTexture() = 0; |
| 26698 |
+}; |
| 26699 |
+ |
| 26700 |
+class SurfaceMtl : public SurfaceMtlProtocol |
| 26701 |
{ |
| 26702 |
public: |
| 26703 |
SurfaceMtl(DisplayMtl *display, |
| 26704 |
@@ -67,11 +87,11 @@ class SurfaceMtl : public SurfaceImpl |
| 26705 |
angle::Result initializeContents(const gl::Context *context, |
| 26706 |
const gl::ImageIndex &imageIndex) override; |
| 26707 |
|
| 26708 |
- const mtl::TextureRef &getColorTexture() { return mColorTexture; } |
| 26709 |
+ const mtl::TextureRef &getColorTexture() override { return mColorTexture; } |
| 26710 |
const mtl::Format &getColorFormat() const { return mColorFormat; } |
| 26711 |
- int getSamples() const { return mSamples; } |
| 26712 |
+ int getSamples() const override { return mSamples; } |
| 26713 |
|
| 26714 |
- bool hasRobustResourceInit() const { return mRobustResourceInit; } |
| 26715 |
+ bool hasRobustResourceInit() const override { return mRobustResourceInit; } |
| 26716 |
|
| 26717 |
angle::Result getAttachmentRenderTarget(const gl::Context *context, |
| 26718 |
GLenum binding, |
| 26719 |
@@ -144,13 +164,14 @@ class WindowSurfaceMtl : public SurfaceMtl |
| 26720 |
GLsizei samples, |
| 26721 |
FramebufferAttachmentRenderTarget **rtOut) override; |
| 26722 |
|
| 26723 |
+ angle::Result ensureCurrentDrawableObtained(const gl::Context *context) override; |
| 26724 |
angle::Result ensureCurrentDrawableObtained(const gl::Context *context, |
| 26725 |
- bool *newDrawableOut /** nullable */); |
| 26726 |
+ bool *newDrawableOut /** nullable */) override; |
| 26727 |
|
| 26728 |
// Ensure the the texture returned from getColorTexture() is ready for glReadPixels(). This |
| 26729 |
// implicitly calls ensureCurrentDrawableObtained(). |
| 26730 |
- angle::Result ensureColorTextureReadyForReadPixels(const gl::Context *context); |
| 26731 |
- |
| 26732 |
+ angle::Result ensureColorTextureReadyForReadPixels(const gl::Context *context) override; |
| 26733 |
+ bool preserveBuffer() const override { return mRetainBuffer; } |
| 26734 |
private: |
| 26735 |
angle::Result swapImpl(const gl::Context *context); |
| 26736 |
angle::Result obtainNextDrawable(const gl::Context *context); |
| 26737 |
@@ -168,6 +189,8 @@ class WindowSurfaceMtl : public SurfaceMtl |
| 26738 |
// event. We don't use mMetalLayer.drawableSize directly since it might be changed internally by |
| 26739 |
// metal runtime. |
| 26740 |
CGSize mCurrentKnownDrawableSize; |
| 26741 |
+ |
| 26742 |
+ bool mRetainBuffer = false; |
| 26743 |
}; |
| 26744 |
|
| 26745 |
// Offscreen surface, base class of PBuffer, IOSurface. |
| 26746 |
@@ -212,37 +235,5 @@ class PBufferSurfaceMtl : public OffscreenSurfaceMtl |
| 26747 |
void setFixedHeight(EGLint height) override; |
| 26748 |
}; |
| 26749 |
|
| 26750 |
-// Offscreen created from IOSurface |
| 26751 |
-class IOSurfaceSurfaceMtl : public OffscreenSurfaceMtl |
| 26752 |
-{ |
| 26753 |
- public: |
| 26754 |
- IOSurfaceSurfaceMtl(DisplayMtl *display, |
| 26755 |
- const egl::SurfaceState &state, |
| 26756 |
- EGLClientBuffer buffer, |
| 26757 |
- const egl::AttributeMap &attribs); |
| 26758 |
- ~IOSurfaceSurfaceMtl() override; |
| 26759 |
- |
| 26760 |
- egl::Error bindTexImage(const gl::Context *context, |
| 26761 |
- gl::Texture *texture, |
| 26762 |
- EGLint buffer) override; |
| 26763 |
- egl::Error releaseTexImage(const gl::Context *context, EGLint buffer) override; |
| 26764 |
- |
| 26765 |
- angle::Result getAttachmentRenderTarget(const gl::Context *context, |
| 26766 |
- GLenum binding, |
| 26767 |
- const gl::ImageIndex &imageIndex, |
| 26768 |
- GLsizei samples, |
| 26769 |
- FramebufferAttachmentRenderTarget **rtOut) override; |
| 26770 |
- |
| 26771 |
- static bool ValidateAttributes(EGLClientBuffer buffer, const egl::AttributeMap &attribs); |
| 26772 |
- |
| 26773 |
- private: |
| 26774 |
- angle::Result ensureColorTextureCreated(const gl::Context *context); |
| 26775 |
- |
| 26776 |
- IOSurfaceRef mIOSurface; |
| 26777 |
- NSUInteger mIOSurfacePlane; |
| 26778 |
- int mIOSurfaceFormatIdx; |
| 26779 |
-}; |
| 26780 |
- |
| 26781 |
} // namespace rx |
| 26782 |
- |
| 26783 |
#endif /* LIBANGLE_RENDERER_METAL_SURFACEMTL_H_ */ |
| 26784 |
diff --git a/src/libANGLE/renderer/metal/SurfaceMtl.mm b/src/libANGLE/renderer/metal/SurfaceMtl.mm |
| 26785 |
index 303fb16..c9ee24b 100644 |
| 26786 |
--- a/src/libANGLE/renderer/metal/SurfaceMtl.mm |
| 26787 |
+++ b/src/libANGLE/renderer/metal/SurfaceMtl.mm |
| 26788 |
@@ -33,55 +33,19 @@ |
| 26789 |
{ |
| 26790 |
|
| 26791 |
#define ANGLE_TO_EGL_TRY(EXPR) \ |
| 26792 |
- do \ |
| 26793 |
- { \ |
| 26794 |
+do \ |
| 26795 |
+{ \ |
| 26796 |
if (ANGLE_UNLIKELY((EXPR) != angle::Result::Continue)) \ |
| 26797 |
{ \ |
| 26798 |
return egl::EglBadSurface(); \ |
| 26799 |
} \ |
| 26800 |
- } while (0) |
| 26801 |
+} while (0) |
| 26802 |
|
| 26803 |
constexpr angle::FormatID kDefaultFrameBufferDepthFormatId = angle::FormatID::D32_FLOAT; |
| 26804 |
constexpr angle::FormatID kDefaultFrameBufferStencilFormatId = angle::FormatID::S8_UINT; |
| 26805 |
constexpr angle::FormatID kDefaultFrameBufferDepthStencilFormatId = |
| 26806 |
angle::FormatID::D24_UNORM_S8_UINT; |
| 26807 |
|
| 26808 |
-struct IOSurfaceFormatInfo |
| 26809 |
-{ |
| 26810 |
- GLenum internalFormat; |
| 26811 |
- GLenum type; |
| 26812 |
- size_t componentBytes; |
| 26813 |
- |
| 26814 |
- angle::FormatID nativeAngleFormatId; |
| 26815 |
-}; |
| 26816 |
- |
| 26817 |
-// clang-format off |
| 26818 |
-// NOTE(hqle): Support R16_UINT once GLES3 is complete. |
| 26819 |
-constexpr std::array<IOSurfaceFormatInfo, 8> kIOSurfaceFormats = {{ |
| 26820 |
- {GL_RED, GL_UNSIGNED_BYTE, 1, angle::FormatID::R8_UNORM}, |
| 26821 |
- {GL_RED, GL_UNSIGNED_SHORT, 2, angle::FormatID::R16_UNORM}, |
| 26822 |
- {GL_RG, GL_UNSIGNED_BYTE, 2, angle::FormatID::R8G8_UNORM}, |
| 26823 |
- {GL_RG, GL_UNSIGNED_SHORT, 4, angle::FormatID::R16G16_UNORM}, |
| 26824 |
- {GL_RGB, GL_UNSIGNED_BYTE, 4, angle::FormatID::B8G8R8A8_UNORM}, |
| 26825 |
- {GL_BGRA_EXT, GL_UNSIGNED_BYTE, 4, angle::FormatID::B8G8R8A8_UNORM}, |
| 26826 |
- {GL_RGBA, GL_HALF_FLOAT, 8, angle::FormatID::R16G16B16A16_FLOAT}, |
| 26827 |
- {GL_RGB10_A2, GL_UNSIGNED_INT_2_10_10_10_REV, 4, angle::FormatID::B10G10R10A2_UNORM}, |
| 26828 |
-}}; |
| 26829 |
-// clang-format on |
| 26830 |
- |
| 26831 |
-int FindIOSurfaceFormatIndex(GLenum internalFormat, GLenum type) |
| 26832 |
-{ |
| 26833 |
- for (int i = 0; i < static_cast<int>(kIOSurfaceFormats.size()); ++i) |
| 26834 |
- { |
| 26835 |
- const auto &formatInfo = kIOSurfaceFormats[i]; |
| 26836 |
- if (formatInfo.internalFormat == internalFormat && formatInfo.type == type) |
| 26837 |
- { |
| 26838 |
- return i; |
| 26839 |
- } |
| 26840 |
- } |
| 26841 |
- return -1; |
| 26842 |
-} |
| 26843 |
- |
| 26844 |
angle::Result CreateOrResizeTexture(const gl::Context *context, |
| 26845 |
const mtl::Format &format, |
| 26846 |
uint32_t width, |
| 26847 |
@@ -128,6 +92,19 @@ bool IsFrameCaptureEnabled() |
| 26848 |
#endif |
| 26849 |
} |
| 26850 |
|
| 26851 |
+ANGLE_MTL_UNUSED |
| 26852 |
+std::string GetMetalCaptureFile() |
| 26853 |
+{ |
| 26854 |
+#if !ANGLE_METAL_FRAME_CAPTURE_ENABLED |
| 26855 |
+ return ""; |
| 26856 |
+#else |
| 26857 |
+ auto var = std::getenv("ANGLE_METAL_FRAME_CAPTURE_FILE"); |
| 26858 |
+ const std::string filePath = var ? var : ""; |
| 26859 |
+ |
| 26860 |
+ return filePath; |
| 26861 |
+#endif |
| 26862 |
+} |
| 26863 |
+ |
| 26864 |
ANGLE_MTL_UNUSED |
| 26865 |
size_t MaxAllowedFrameCapture() |
| 26866 |
{ |
| 26867 |
@@ -202,6 +179,21 @@ void StartFrameCapture(id<MTLDevice> metalDevice, id<MTLCommandQueue> metalCmdQu |
| 26868 |
{ |
| 26869 |
MTLCaptureDescriptor *captureDescriptor = [[MTLCaptureDescriptor alloc] init]; |
| 26870 |
captureDescriptor.captureObject = metalDevice; |
| 26871 |
+ const std::string filePath = GetMetalCaptureFile(); |
| 26872 |
+ if (filePath != "") |
| 26873 |
+ { |
| 26874 |
+ const std::string numberedPath = |
| 26875 |
+ filePath + std::to_string(gFrameCaptured - 1) + ".gputrace"; |
| 26876 |
+ captureDescriptor.destination = MTLCaptureDestinationGPUTraceDocument; |
| 26877 |
+ captureDescriptor.outputURL = |
| 26878 |
+ [NSURL fileURLWithPath:[NSString stringWithUTF8String:numberedPath.c_str()] |
| 26879 |
+ isDirectory:false]; |
| 26880 |
+ } |
| 26881 |
+ else |
| 26882 |
+ { |
| 26883 |
+ // This will pause execution only if application is being debugged inside Xcode |
| 26884 |
+ captureDescriptor.destination = MTLCaptureDestinationDeveloperTools; |
| 26885 |
+ } |
| 26886 |
|
| 26887 |
NSError *error; |
| 26888 |
if (![captureManager startCaptureWithDescriptor:captureDescriptor error:&error]) |
| 26889 |
@@ -211,14 +203,15 @@ void StartFrameCapture(id<MTLDevice> metalDevice, id<MTLCommandQueue> metalCmdQu |
| 26890 |
} |
| 26891 |
else |
| 26892 |
# endif // __MAC_10_15 |
| 26893 |
+ if (ANGLE_APPLE_AVAILABLE_XCI(10.15, 13.0, 13)) |
| 26894 |
{ |
| 26895 |
- if (FrameCaptureDeviceScope()) |
| 26896 |
- { |
| 26897 |
- [captureManager startCaptureWithDevice:metalDevice]; |
| 26898 |
- } |
| 26899 |
- else |
| 26900 |
+ MTLCaptureDescriptor *captureDescriptor = [[MTLCaptureDescriptor alloc] init]; |
| 26901 |
+ captureDescriptor.captureObject = metalDevice; |
| 26902 |
+ |
| 26903 |
+ NSError *error; |
| 26904 |
+ if (![captureManager startCaptureWithDescriptor:captureDescriptor error:&error]) |
| 26905 |
{ |
| 26906 |
- [captureManager startCaptureWithCommandQueue:metalCmdQueue]; |
| 26907 |
+ NSLog(@"Failed to start capture, error %@", error); |
| 26908 |
} |
| 26909 |
} |
| 26910 |
#endif // ANGLE_METAL_FRAME_CAPTURE_ENABLED |
| 26911 |
@@ -245,11 +238,10 @@ void StopFrameCapture() |
| 26912 |
} |
| 26913 |
} |
| 26914 |
|
| 26915 |
-// SurfaceMtl implementation |
| 26916 |
SurfaceMtl::SurfaceMtl(DisplayMtl *display, |
| 26917 |
const egl::SurfaceState &state, |
| 26918 |
const egl::AttributeMap &attribs) |
| 26919 |
- : SurfaceImpl(state) |
| 26920 |
+ : SurfaceMtlProtocol(state) |
| 26921 |
{ |
| 26922 |
mRobustResourceInit = |
| 26923 |
attribs.get(EGL_ROBUST_RESOURCE_INITIALIZATION_ANGLE, EGL_FALSE) == EGL_TRUE; |
| 26924 |
@@ -693,6 +685,10 @@ void StopFrameCapture() |
| 26925 |
return SurfaceMtl::getAttachmentRenderTarget(context, binding, imageIndex, samples, rtOut); |
| 26926 |
} |
| 26927 |
|
| 26928 |
+angle::Result WindowSurfaceMtl::ensureCurrentDrawableObtained(const gl::Context *context) |
| 26929 |
+{ |
| 26930 |
+ return ensureCurrentDrawableObtained(context, nullptr); |
| 26931 |
+} |
| 26932 |
angle::Result WindowSurfaceMtl::ensureCurrentDrawableObtained(const gl::Context *context, |
| 26933 |
bool *newDrawableOut) |
| 26934 |
{ |
| 26935 |
@@ -943,157 +939,5 @@ void StopFrameCapture() |
| 26936 |
mSize.height = height; |
| 26937 |
} |
| 26938 |
|
| 26939 |
-// IOSurfaceSurfaceMtl implementation. |
| 26940 |
-IOSurfaceSurfaceMtl::IOSurfaceSurfaceMtl(DisplayMtl *display, |
| 26941 |
- const egl::SurfaceState &state, |
| 26942 |
- EGLClientBuffer buffer, |
| 26943 |
- const egl::AttributeMap &attribs) |
| 26944 |
- : OffscreenSurfaceMtl(display, state, attribs), mIOSurface((__bridge IOSurfaceRef)(buffer)) |
| 26945 |
-{ |
| 26946 |
- CFRetain(mIOSurface); |
| 26947 |
- |
| 26948 |
- mIOSurfacePlane = static_cast<int>(attribs.get(EGL_IOSURFACE_PLANE_ANGLE)); |
| 26949 |
- |
| 26950 |
- EGLAttrib internalFormat = attribs.get(EGL_TEXTURE_INTERNAL_FORMAT_ANGLE); |
| 26951 |
- EGLAttrib type = attribs.get(EGL_TEXTURE_TYPE_ANGLE); |
| 26952 |
- mIOSurfaceFormatIdx = |
| 26953 |
- FindIOSurfaceFormatIndex(static_cast<GLenum>(internalFormat), static_cast<GLenum>(type)); |
| 26954 |
- ASSERT(mIOSurfaceFormatIdx >= 0); |
| 26955 |
- |
| 26956 |
- mColorFormat = |
| 26957 |
- display->getPixelFormat(kIOSurfaceFormats[mIOSurfaceFormatIdx].nativeAngleFormatId); |
| 26958 |
-} |
| 26959 |
-IOSurfaceSurfaceMtl::~IOSurfaceSurfaceMtl() |
| 26960 |
-{ |
| 26961 |
- if (mIOSurface != nullptr) |
| 26962 |
- { |
| 26963 |
- CFRelease(mIOSurface); |
| 26964 |
- mIOSurface = nullptr; |
| 26965 |
- } |
| 26966 |
-} |
| 26967 |
- |
| 26968 |
-egl::Error IOSurfaceSurfaceMtl::bindTexImage(const gl::Context *context, |
| 26969 |
- gl::Texture *texture, |
| 26970 |
- EGLint buffer) |
| 26971 |
-{ |
| 26972 |
- ContextMtl *contextMtl = mtl::GetImpl(context); |
| 26973 |
- StartFrameCapture(contextMtl); |
| 26974 |
- |
| 26975 |
- // Initialize offscreen texture if needed: |
| 26976 |
- ANGLE_TO_EGL_TRY(ensureColorTextureCreated(context)); |
| 26977 |
- |
| 26978 |
- return OffscreenSurfaceMtl::bindTexImage(context, texture, buffer); |
| 26979 |
-} |
| 26980 |
- |
| 26981 |
-egl::Error IOSurfaceSurfaceMtl::releaseTexImage(const gl::Context *context, EGLint buffer) |
| 26982 |
-{ |
| 26983 |
- egl::Error re = OffscreenSurfaceMtl::releaseTexImage(context, buffer); |
| 26984 |
- StopFrameCapture(); |
| 26985 |
- return re; |
| 26986 |
-} |
| 26987 |
- |
| 26988 |
-angle::Result IOSurfaceSurfaceMtl::getAttachmentRenderTarget( |
| 26989 |
- const gl::Context *context, |
| 26990 |
- GLenum binding, |
| 26991 |
- const gl::ImageIndex &imageIndex, |
| 26992 |
- GLsizei samples, |
| 26993 |
- FramebufferAttachmentRenderTarget **rtOut) |
| 26994 |
-{ |
| 26995 |
- // Initialize offscreen texture if needed: |
| 26996 |
- ANGLE_TRY(ensureColorTextureCreated(context)); |
| 26997 |
- |
| 26998 |
- return OffscreenSurfaceMtl::getAttachmentRenderTarget(context, binding, imageIndex, samples, |
| 26999 |
- rtOut); |
| 27000 |
-} |
| 27001 |
- |
| 27002 |
-angle::Result IOSurfaceSurfaceMtl::ensureColorTextureCreated(const gl::Context *context) |
| 27003 |
-{ |
| 27004 |
- if (mColorTexture) |
| 27005 |
- { |
| 27006 |
- return angle::Result::Continue; |
| 27007 |
- } |
| 27008 |
- ContextMtl *contextMtl = mtl::GetImpl(context); |
| 27009 |
- ANGLE_MTL_OBJC_SCOPE |
| 27010 |
- { |
| 27011 |
- auto texDesc = |
| 27012 |
- [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:mColorFormat.metalFormat |
| 27013 |
- width:mSize.width |
| 27014 |
- height:mSize.height |
| 27015 |
- mipmapped:NO]; |
| 27016 |
- |
| 27017 |
- texDesc.usage = MTLTextureUsageShaderRead | MTLTextureUsageRenderTarget; |
| 27018 |
- |
| 27019 |
- id<MTLTexture> texture = |
| 27020 |
- [contextMtl->getMetalDevice() newTextureWithDescriptor:texDesc |
| 27021 |
- iosurface:mIOSurface |
| 27022 |
- plane:mIOSurfacePlane]; |
| 27023 |
- |
| 27024 |
- mColorTexture = mtl::Texture::MakeFromMetal([texture ANGLE_MTL_AUTORELEASE]); |
| 27025 |
- } |
| 27026 |
- |
| 27027 |
- mColorRenderTarget.set(mColorTexture, mtl::kZeroNativeMipLevel, 0, mColorFormat); |
| 27028 |
- |
| 27029 |
- if (kIOSurfaceFormats[mIOSurfaceFormatIdx].internalFormat == GL_RGB) |
| 27030 |
- { |
| 27031 |
- // This format has emulated alpha channel. Initialize texture's alpha channel to 1.0. |
| 27032 |
- const mtl::Format &rgbClearFormat = |
| 27033 |
- contextMtl->getPixelFormat(angle::FormatID::R8G8B8_UNORM); |
| 27034 |
- ANGLE_TRY(mtl::InitializeTextureContentsGPU( |
| 27035 |
- context, mColorTexture, rgbClearFormat, |
| 27036 |
- mtl::ImageNativeIndex::FromBaseZeroGLIndex(gl::ImageIndex::Make2D(0)), |
| 27037 |
- MTLColorWriteMaskAlpha)); |
| 27038 |
- |
| 27039 |
- // Disable subsequent rendering to alpha channel. |
| 27040 |
- mColorTexture->setColorWritableMask(MTLColorWriteMaskAll & (~MTLColorWriteMaskAlpha)); |
| 27041 |
- } |
| 27042 |
- |
| 27043 |
- return angle::Result::Continue; |
| 27044 |
-} |
| 27045 |
- |
| 27046 |
-// static |
| 27047 |
-bool IOSurfaceSurfaceMtl::ValidateAttributes(EGLClientBuffer buffer, |
| 27048 |
- const egl::AttributeMap &attribs) |
| 27049 |
-{ |
| 27050 |
- IOSurfaceRef ioSurface = (__bridge IOSurfaceRef)(buffer); |
| 27051 |
- |
| 27052 |
- // The plane must exist for this IOSurface. IOSurfaceGetPlaneCount can return 0 for non-planar |
| 27053 |
- // ioSurfaces but we will treat non-planar like it is a single plane. |
| 27054 |
- size_t surfacePlaneCount = std::max(size_t(1), IOSurfaceGetPlaneCount(ioSurface)); |
| 27055 |
- EGLAttrib plane = attribs.get(EGL_IOSURFACE_PLANE_ANGLE); |
| 27056 |
- if (plane < 0 || static_cast<size_t>(plane) >= surfacePlaneCount) |
| 27057 |
- { |
| 27058 |
- return false; |
| 27059 |
- } |
| 27060 |
- |
| 27061 |
- // The width height specified must be at least (1, 1) and at most the plane size |
| 27062 |
- EGLAttrib width = attribs.get(EGL_WIDTH); |
| 27063 |
- EGLAttrib height = attribs.get(EGL_HEIGHT); |
| 27064 |
- if (width <= 0 || static_cast<size_t>(width) > IOSurfaceGetWidthOfPlane(ioSurface, plane) || |
| 27065 |
- height <= 0 || static_cast<size_t>(height) > IOSurfaceGetHeightOfPlane(ioSurface, plane)) |
| 27066 |
- { |
| 27067 |
- return false; |
| 27068 |
- } |
| 27069 |
- |
| 27070 |
- // Find this IOSurface format |
| 27071 |
- EGLAttrib internalFormat = attribs.get(EGL_TEXTURE_INTERNAL_FORMAT_ANGLE); |
| 27072 |
- EGLAttrib type = attribs.get(EGL_TEXTURE_TYPE_ANGLE); |
| 27073 |
- |
| 27074 |
- int formatIndex = |
| 27075 |
- FindIOSurfaceFormatIndex(static_cast<GLenum>(internalFormat), static_cast<GLenum>(type)); |
| 27076 |
- |
| 27077 |
- if (formatIndex < 0) |
| 27078 |
- { |
| 27079 |
- return false; |
| 27080 |
- } |
| 27081 |
- |
| 27082 |
- // Check that the format matches this IOSurface plane |
| 27083 |
- if (IOSurfaceGetBytesPerElementOfPlane(ioSurface, plane) != |
| 27084 |
- kIOSurfaceFormats[formatIndex].componentBytes) |
| 27085 |
- { |
| 27086 |
- return false; |
| 27087 |
- } |
| 27088 |
- |
| 27089 |
- return true; |
| 27090 |
-} |
| 27091 |
|
| 27092 |
} |
| 27093 |
diff --git a/src/libANGLE/renderer/metal/SyncMtl.h b/src/libANGLE/renderer/metal/SyncMtl.h |
| 27094 |
index 62f96ee..f4bcae9 100644 |
| 27095 |
--- a/src/libANGLE/renderer/metal/SyncMtl.h |
| 27096 |
+++ b/src/libANGLE/renderer/metal/SyncMtl.h |
| 27097 |
@@ -1,5 +1,5 @@ |
| 27098 |
// |
| 27099 |
-// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 27100 |
+// Copyright (c) 2020 The ANGLE Project Authors. All rights reserved. |
| 27101 |
// Use of this source code is governed by a BSD-style license that can be |
| 27102 |
// found in the LICENSE file. |
| 27103 |
// |
| 27104 |
@@ -33,7 +33,7 @@ namespace mtl |
| 27105 |
|
| 27106 |
// Common class to be used by both SyncImpl and EGLSyncImpl. |
| 27107 |
// NOTE: SharedEvent is only declared on iOS 12.0+ or mac 10.14+ |
| 27108 |
-#if ANGLE_MTL_EVENT_AVAILABLE |
| 27109 |
+#if defined(__IPHONE_12_0) || defined(__MAC_10_14) |
| 27110 |
class Sync |
| 27111 |
{ |
| 27112 |
public: |
| 27113 |
@@ -59,7 +59,7 @@ class Sync |
| 27114 |
std::shared_ptr<std::condition_variable> mCv; |
| 27115 |
std::shared_ptr<std::mutex> mLock; |
| 27116 |
}; |
| 27117 |
-#else // #if ANGLE_MTL_EVENT_AVAILABLE |
| 27118 |
+#else // #if defined(__IPHONE_12_0) || defined(__MAC_10_14) |
| 27119 |
class Sync |
| 27120 |
{ |
| 27121 |
public: |
| 27122 |
@@ -90,7 +90,7 @@ class Sync |
| 27123 |
return angle::Result::Stop; |
| 27124 |
} |
| 27125 |
}; |
| 27126 |
-#endif // #if ANGLE_MTL_EVENT_AVAILABLE |
| 27127 |
+#endif // #if defined(__IPHONE_12_0) || defined(__MAC_10_14) |
| 27128 |
} // namespace mtl |
| 27129 |
|
| 27130 |
class FenceNVMtl : public FenceNVImpl |
| 27131 |
@@ -98,9 +98,7 @@ class FenceNVMtl : public FenceNVImpl |
| 27132 |
public: |
| 27133 |
FenceNVMtl(); |
| 27134 |
~FenceNVMtl() override; |
| 27135 |
- |
| 27136 |
void onDestroy(const gl::Context *context) override; |
| 27137 |
- |
| 27138 |
angle::Result set(const gl::Context *context, GLenum condition) override; |
| 27139 |
angle::Result test(const gl::Context *context, GLboolean *outFinished) override; |
| 27140 |
angle::Result finish(const gl::Context *context) override; |
| 27141 |
@@ -152,6 +150,8 @@ class EGLSyncMtl final : public EGLSyncImpl |
| 27142 |
EGLint flags) override; |
| 27143 |
egl::Error getStatus(const egl::Display *display, EGLint *outStatus) override; |
| 27144 |
|
| 27145 |
+ egl::Error dupNativeFenceFD(const egl::Display *display, EGLint *result) const override; |
| 27146 |
+ |
| 27147 |
private: |
| 27148 |
mtl::Sync mSync; |
| 27149 |
}; |
| 27150 |
diff --git a/src/libANGLE/renderer/metal/SyncMtl.mm b/src/libANGLE/renderer/metal/SyncMtl.mm |
| 27151 |
index dff8003..f8f3ee6 100644 |
| 27152 |
--- a/src/libANGLE/renderer/metal/SyncMtl.mm |
| 27153 |
+++ b/src/libANGLE/renderer/metal/SyncMtl.mm |
| 27154 |
@@ -1,5 +1,5 @@ |
| 27155 |
// |
| 27156 |
-// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 27157 |
+// Copyright (c) 2020 The ANGLE Project Authors. All rights reserved. |
| 27158 |
// Use of this source code is governed by a BSD-style license that can be |
| 27159 |
// found in the LICENSE file. |
| 27160 |
// |
| 27161 |
@@ -22,7 +22,7 @@ |
| 27162 |
namespace mtl |
| 27163 |
{ |
| 27164 |
// SharedEvent is only available on iOS 12.0+ or mac 10.14+ |
| 27165 |
-#if ANGLE_MTL_EVENT_AVAILABLE |
| 27166 |
+#if defined(__IPHONE_12_0) || defined(__MAC_10_14) |
| 27167 |
Sync::Sync() {} |
| 27168 |
Sync::~Sync() {} |
| 27169 |
|
| 27170 |
@@ -87,7 +87,7 @@ |
| 27171 |
// onDestroy(), but the callback might still not be fired yet. |
| 27172 |
std::shared_ptr<std::condition_variable> cvRef = mCv; |
| 27173 |
std::shared_ptr<std::mutex> lockRef = mLock; |
| 27174 |
- |
| 27175 |
+#if ANGLE_MTL_EVENT_AVAILABLE |
| 27176 |
AutoObjCObj<MTLSharedEventListener> eventListener = |
| 27177 |
contextMtl->getDisplay()->getOrCreateSharedEventListener(); |
| 27178 |
[mMetalSharedEvent.get() notifyListener:eventListener |
| 27179 |
@@ -106,6 +106,7 @@ |
| 27180 |
|
| 27181 |
ASSERT(mMetalSharedEvent.get().signaledValue >= mSetCounter); |
| 27182 |
*outResult = GL_CONDITION_SATISFIED; |
| 27183 |
+#endif |
| 27184 |
|
| 27185 |
return angle::Result::Continue; |
| 27186 |
} |
| 27187 |
@@ -118,7 +119,7 @@ |
| 27188 |
*signaled = mMetalSharedEvent.get().signaledValue >= mSetCounter; |
| 27189 |
return angle::Result::Continue; |
| 27190 |
} |
| 27191 |
-#endif // #if ANGLE_MTL_EVENT_AVAILABLE |
| 27192 |
+#endif // #if defined(__IPHONE_12_0) || defined(__MAC_10_14) |
| 27193 |
} // namespace mtl |
| 27194 |
|
| 27195 |
// FenceNVMtl implementation |
| 27196 |
@@ -128,7 +129,8 @@ |
| 27197 |
|
| 27198 |
void FenceNVMtl::onDestroy(const gl::Context *context) |
| 27199 |
{ |
| 27200 |
- mSync.onDestroy(); |
| 27201 |
+ UNIMPLEMENTED(); |
| 27202 |
+ return; |
| 27203 |
} |
| 27204 |
|
| 27205 |
angle::Result FenceNVMtl::set(const gl::Context *context, GLenum condition) |
| 27206 |
@@ -307,4 +309,10 @@ |
| 27207 |
return egl::NoError(); |
| 27208 |
} |
| 27209 |
|
| 27210 |
+egl::Error EGLSyncMtl::dupNativeFenceFD(const egl::Display *display, EGLint *result) const |
| 27211 |
+{ |
| 27212 |
+ UNREACHABLE(); |
| 27213 |
+ return egl::EglBadDisplay(); |
| 27214 |
+} |
| 27215 |
+ |
| 27216 |
} |
| 27217 |
diff --git a/src/libANGLE/renderer/metal/TextureMtl.h b/src/libANGLE/renderer/metal/TextureMtl.h |
| 27218 |
index 5c2141b..5f4b2d4 100644 |
| 27219 |
--- a/src/libANGLE/renderer/metal/TextureMtl.h |
| 27220 |
+++ b/src/libANGLE/renderer/metal/TextureMtl.h |
| 27221 |
@@ -15,9 +15,9 @@ |
| 27222 |
#include "common/PackedEnums.h" |
| 27223 |
#include "libANGLE/renderer/TextureImpl.h" |
| 27224 |
#include "libANGLE/renderer/metal/RenderTargetMtl.h" |
| 27225 |
+#include "libANGLE/renderer/metal/SurfaceMtl.h" |
| 27226 |
#include "libANGLE/renderer/metal/mtl_command_buffer.h" |
| 27227 |
#include "libANGLE/renderer/metal/mtl_resources.h" |
| 27228 |
- |
| 27229 |
namespace rx |
| 27230 |
{ |
| 27231 |
|
| 27232 |
@@ -32,6 +32,8 @@ class TextureMtl : public TextureImpl |
| 27233 |
{ |
| 27234 |
public: |
| 27235 |
TextureMtl(const gl::TextureState &state); |
| 27236 |
+ // Texture view |
| 27237 |
+ TextureMtl(const TextureMtl &mtl, GLenum format); |
| 27238 |
~TextureMtl() override; |
| 27239 |
void onDestroy(const gl::Context *context) override; |
| 27240 |
|
| 27241 |
@@ -193,6 +195,7 @@ class TextureMtl : public TextureImpl |
| 27242 |
ImageDefinitionMtl &getImageDefinition(const gl::ImageIndex &imageIndex); |
| 27243 |
RenderTargetMtl &getRenderTarget(const gl::ImageIndex &imageIndex); |
| 27244 |
bool isIndexWithinMinMaxLevels(const gl::ImageIndex &imageIndex) const; |
| 27245 |
+ mtl::TextureRef &getImplicitMSTexture(const gl::ImageIndex &imageIndex); |
| 27246 |
|
| 27247 |
// If levels = 0, this function will create full mipmaps texture. |
| 27248 |
angle::Result setStorageImpl(const gl::Context *context, |
| 27249 |
@@ -312,8 +315,9 @@ class TextureMtl : public TextureImpl |
| 27250 |
angle::Result generateMipmapCPU(const gl::Context *context); |
| 27251 |
|
| 27252 |
mtl::Format mFormat; |
| 27253 |
+ SurfaceMtlProtocol *mBoundSurface = nil; |
| 27254 |
// The real texture used by Metal draw calls. |
| 27255 |
- mtl::TextureRef mNativeTexture; |
| 27256 |
+ mtl::TextureRef mNativeTexture = nil; |
| 27257 |
id<MTLSamplerState> mMetalSamplerState = nil; |
| 27258 |
|
| 27259 |
// Number of slices |
| 27260 |
@@ -323,18 +327,14 @@ class TextureMtl : public TextureImpl |
| 27261 |
// Once the images array is complete, they will be transferred to real texture object. |
| 27262 |
// NOTE: |
| 27263 |
// - The second dimension is indexed by configured base level + actual native level |
| 27264 |
- // - For Cube map, there will be at most 6 entries in the mTexImageDefs table, one for each |
| 27265 |
- // face. This is because the Cube map's image is defined per face & per level. |
| 27266 |
+ // - For Cube map, there will be at most 6 entries in the map table, one for each face. This is |
| 27267 |
+ // because the Cube map's image is defined per face & per level. |
| 27268 |
// - For other texture types, there will be only one entry in the map table. All other textures |
| 27269 |
// except Cube map has texture image defined per level (all slices included). |
| 27270 |
+ // - These three variables' second dimension are indexed by image index (base level included). |
| 27271 |
std::map<int, gl::TexLevelArray<ImageDefinitionMtl>> mTexImageDefs; |
| 27272 |
- |
| 27273 |
- // Render Target per slice/depth/cube face. |
| 27274 |
- // - For 2D texture: There will be one key entry in the map. |
| 27275 |
- // - For Cube map: There will be at most 6 key entries. |
| 27276 |
- // - For array/3D texture: There will be at most slices/depths number of key entries. |
| 27277 |
- // - The second dimension is indexed by configured base level + actual native level |
| 27278 |
std::map<int, gl::TexLevelArray<RenderTargetMtl>> mPerLayerRenderTargets; |
| 27279 |
+ std::map<int, gl::TexLevelArray<mtl::TextureRef>> mImplicitMSTextures; |
| 27280 |
|
| 27281 |
// Mipmap views are indexed by native level (ignored base level): |
| 27282 |
mtl::NativeTexLevelArray mNativeLevelViews; |
| 27283 |
diff --git a/src/libANGLE/renderer/metal/TextureMtl.mm b/src/libANGLE/renderer/metal/TextureMtl.mm |
| 27284 |
index 623c104..3b1c8af 100644 |
| 27285 |
--- a/src/libANGLE/renderer/metal/TextureMtl.mm |
| 27286 |
+++ b/src/libANGLE/renderer/metal/TextureMtl.mm |
| 27287 |
@@ -20,8 +20,8 @@ |
| 27288 |
#include "libANGLE/renderer/metal/ContextMtl.h" |
| 27289 |
#include "libANGLE/renderer/metal/DisplayMtl.h" |
| 27290 |
#include "libANGLE/renderer/metal/FrameBufferMtl.h" |
| 27291 |
+#include "libANGLE/renderer/metal/IOSurfaceSurfaceMtl.h" |
| 27292 |
#include "libANGLE/renderer/metal/SamplerMtl.h" |
| 27293 |
-#include "libANGLE/renderer/metal/SurfaceMtl.h" |
| 27294 |
#include "libANGLE/renderer/metal/mtl_common.h" |
| 27295 |
#include "libANGLE/renderer/metal/mtl_format_utils.h" |
| 27296 |
#include "libANGLE/renderer/metal/mtl_utils.h" |
| 27297 |
@@ -534,6 +534,10 @@ GLenum OverrideSwizzleValue(const gl::Context *context, |
| 27298 |
|
| 27299 |
angle::Result TextureMtl::ensureTextureCreated(const gl::Context *context) |
| 27300 |
{ |
| 27301 |
+ if (mBoundSurface) |
| 27302 |
+ { |
| 27303 |
+ return angle::Result::Continue; |
| 27304 |
+ } |
| 27305 |
if (mNativeTexture) |
| 27306 |
{ |
| 27307 |
return angle::Result::Continue; |
| 27308 |
@@ -1207,25 +1211,15 @@ GLenum OverrideSwizzleValue(const gl::Context *context, |
| 27309 |
|
| 27310 |
angle::Result TextureMtl::bindTexImage(const gl::Context *context, egl::Surface *surface) |
| 27311 |
{ |
| 27312 |
- releaseTexture(true); |
| 27313 |
- |
| 27314 |
- auto pBuffer = GetImplAs<OffscreenSurfaceMtl>(surface); |
| 27315 |
- mNativeTexture = pBuffer->getColorTexture(); |
| 27316 |
- mFormat = pBuffer->getColorFormat(); |
| 27317 |
- gl::Extents size = mNativeTexture->sizeAt0(); |
| 27318 |
- mIsPow2 = gl::isPow2(size.width) && gl::isPow2(size.height) && gl::isPow2(size.depth); |
| 27319 |
- ANGLE_TRY(ensureSamplerStateCreated(context)); |
| 27320 |
- |
| 27321 |
- // Tell context to rebind textures |
| 27322 |
- ContextMtl *contextMtl = mtl::GetImpl(context); |
| 27323 |
- contextMtl->invalidateCurrentTextures(); |
| 27324 |
- |
| 27325 |
+ IOSurfaceSurfaceMtl *surfaceMtl = (IOSurfaceSurfaceMtl *)mtl::GetImpl(surface); |
| 27326 |
+ mBoundSurface = surfaceMtl; |
| 27327 |
return angle::Result::Continue; |
| 27328 |
} |
| 27329 |
|
| 27330 |
angle::Result TextureMtl::releaseTexImage(const gl::Context *context) |
| 27331 |
{ |
| 27332 |
- releaseTexture(true); |
| 27333 |
+ mBoundSurface = nil; |
| 27334 |
+ |
| 27335 |
return angle::Result::Continue; |
| 27336 |
} |
| 27337 |
|
| 27338 |
@@ -1235,6 +1229,12 @@ GLenum OverrideSwizzleValue(const gl::Context *context, |
| 27339 |
GLsizei samples, |
| 27340 |
FramebufferAttachmentRenderTarget **rtOut) |
| 27341 |
{ |
| 27342 |
+ if (mBoundSurface) |
| 27343 |
+ { |
| 27344 |
+ ANGLE_TRY( |
| 27345 |
+ mBoundSurface->getAttachmentRenderTarget(context, binding, imageIndex, samples, rtOut)); |
| 27346 |
+ return angle::Result::Continue; |
| 27347 |
+ } |
| 27348 |
ANGLE_TRY(ensureTextureCreated(context)); |
| 27349 |
|
| 27350 |
ContextMtl *contextMtl = mtl::GetImpl(context); |
| 27351 |
diff --git a/src/libANGLE/renderer/metal/TransformFeedbackMtl.h b/src/libANGLE/renderer/metal/TransformFeedbackMtl.h |
| 27352 |
index aa45bf9..20a2c20 100644 |
| 27353 |
--- a/src/libANGLE/renderer/metal/TransformFeedbackMtl.h |
| 27354 |
+++ b/src/libANGLE/renderer/metal/TransformFeedbackMtl.h |
| 27355 |
@@ -10,12 +10,20 @@ |
| 27356 |
#ifndef LIBANGLE_RENDERER_METAL_TRANSFORMFEEDBACKMTL_H_ |
| 27357 |
#define LIBANGLE_RENDERER_METAL_TRANSFORMFEEDBACKMTL_H_ |
| 27358 |
|
| 27359 |
+#include <Metal/Metal.h> |
| 27360 |
#include "libANGLE/renderer/TransformFeedbackImpl.h" |
| 27361 |
+#include "libANGLE/renderer/metal/BufferMtl.h" |
| 27362 |
+#include "libANGLE/renderer/metal/mtl_resources.h" |
| 27363 |
|
| 27364 |
-namespace rx |
| 27365 |
+typedef uint64_t MtlDeviceSize; |
| 27366 |
+ |
| 27367 |
+namespace gl |
| 27368 |
{ |
| 27369 |
+class ProgramState; |
| 27370 |
+} // namespace gl |
| 27371 |
|
| 27372 |
-class ContextMtl; |
| 27373 |
+namespace rx |
| 27374 |
+{ |
| 27375 |
|
| 27376 |
class TransformFeedbackMtl : public TransformFeedbackImpl |
| 27377 |
{ |
| 27378 |
@@ -32,17 +40,23 @@ class TransformFeedbackMtl : public TransformFeedbackImpl |
| 27379 |
size_t index, |
| 27380 |
const gl::OffsetBindingPointer<gl::Buffer> &binding) override; |
| 27381 |
|
| 27382 |
- // Params: |
| 27383 |
- // - drawCallFirstVertex is first vertex used by glDrawArrays*. This is important because |
| 27384 |
- // gl_VertexIndex is starting from this. |
| 27385 |
- // - skippedVertices is number of skipped vertices (useful for multiple metal draws per GL draw |
| 27386 |
- // call). |
| 27387 |
- angle::Result getBufferOffsets(ContextMtl *contextMtl, |
| 27388 |
+ void getBufferOffsets(ContextMtl *contextMtl, |
| 27389 |
GLint drawCallFirstVertex, |
| 27390 |
- uint32_t skippedVertices, |
| 27391 |
- int32_t *offsetsOut); |
| 27392 |
+ int32_t *offsetsOut, |
| 27393 |
+ size_t offsetsSize) const; |
| 27394 |
+ |
| 27395 |
+ const gl::TransformFeedbackBuffersArray<BufferMtl *> &getBufferHandles() const |
| 27396 |
+ { |
| 27397 |
+ return mBufferHandles; |
| 27398 |
+ } |
| 27399 |
|
| 27400 |
private: |
| 27401 |
+ gl::TransformFeedbackBuffersArray<BufferMtl *> mBufferHandles; |
| 27402 |
+ gl::TransformFeedbackBuffersArray<MtlDeviceSize> mBufferOffsets; |
| 27403 |
+ gl::TransformFeedbackBuffersArray<MtlDeviceSize> mBufferSizes; |
| 27404 |
+ |
| 27405 |
+ // Aligned offset for emulation. Could be smaller than offset. |
| 27406 |
+ gl::TransformFeedbackBuffersArray<MtlDeviceSize> mAlignedBufferOffsets; |
| 27407 |
}; |
| 27408 |
|
| 27409 |
} // namespace rx |
| 27410 |
diff --git a/src/libANGLE/renderer/metal/TransformFeedbackMtl.mm b/src/libANGLE/renderer/metal/TransformFeedbackMtl.mm |
| 27411 |
index d940c3d..de7a909 100644 |
| 27412 |
--- a/src/libANGLE/renderer/metal/TransformFeedbackMtl.mm |
| 27413 |
+++ b/src/libANGLE/renderer/metal/TransformFeedbackMtl.mm |
| 27414 |
@@ -8,18 +8,27 @@ |
| 27415 |
// |
| 27416 |
|
| 27417 |
#include "libANGLE/renderer/metal/TransformFeedbackMtl.h" |
| 27418 |
+#include "libANGLE/renderer/metal/BufferMtl.h" |
| 27419 |
+#include "libANGLE/renderer/metal/ContextMtl.h" |
| 27420 |
+#include "libANGLE/renderer/metal/DisplayMtl.h" |
| 27421 |
+#include "libANGLE/renderer/metal/ProgramMtl.h" |
| 27422 |
+#include "libANGLE/renderer/metal/QueryMtl.h" |
| 27423 |
+#include "libANGLE/renderer/metal/mtl_common.h" |
| 27424 |
|
| 27425 |
-#include "common/debug.h" |
| 27426 |
#include "libANGLE/Context.h" |
| 27427 |
#include "libANGLE/Query.h" |
| 27428 |
-#include "libANGLE/renderer/metal/ContextMtl.h" |
| 27429 |
-#include "libANGLE/renderer/metal/QueryMtl.h" |
| 27430 |
+ |
| 27431 |
+#include "common/debug.h" |
| 27432 |
|
| 27433 |
namespace rx |
| 27434 |
{ |
| 27435 |
|
| 27436 |
TransformFeedbackMtl::TransformFeedbackMtl(const gl::TransformFeedbackState &state) |
| 27437 |
- : TransformFeedbackImpl(state) |
| 27438 |
+ : TransformFeedbackImpl(state), |
| 27439 |
+ mBufferHandles{}, |
| 27440 |
+ mBufferOffsets{}, |
| 27441 |
+ mBufferSizes{}, |
| 27442 |
+ mAlignedBufferOffsets{} |
| 27443 |
{} |
| 27444 |
|
| 27445 |
TransformFeedbackMtl::~TransformFeedbackMtl() {} |
| 27446 |
@@ -27,40 +36,79 @@ |
| 27447 |
angle::Result TransformFeedbackMtl::begin(const gl::Context *context, |
| 27448 |
gl::PrimitiveMode primitiveMode) |
| 27449 |
{ |
| 27450 |
- mtl::GetImpl(context)->onTransformFeedbackActive(context, this); |
| 27451 |
+ ContextMtl *contextMtl = mtl::GetImpl(context); |
| 27452 |
+ // Not currently supported with msl compiler |
| 27453 |
+ if (!contextMtl->getDisplay()->getFeatures().emulateTransformFeedback.enabled) |
| 27454 |
+ { |
| 27455 |
+ return angle::Result::Stop; |
| 27456 |
+ } |
| 27457 |
|
| 27458 |
- return angle::Result::Continue; |
| 27459 |
+ const gl::ProgramExecutable *executable = contextMtl->getState().getProgramExecutable(); |
| 27460 |
+ ASSERT(executable); |
| 27461 |
+ size_t xfbBufferCount = executable->getTransformFeedbackBufferCount(); |
| 27462 |
+ |
| 27463 |
+ for (size_t bufferIndex = 0; bufferIndex < xfbBufferCount; ++bufferIndex) |
| 27464 |
+ { |
| 27465 |
+ const gl::OffsetBindingPointer<gl::Buffer> &binding = mState.getIndexedBuffer(bufferIndex); |
| 27466 |
+ ASSERT(binding.get()); |
| 27467 |
+ |
| 27468 |
+ BufferMtl *bufferMtl = mtl::GetImpl(binding.get()); |
| 27469 |
+ |
| 27470 |
+ assert(bufferMtl); |
| 27471 |
+ mBufferOffsets[bufferIndex] = binding.getOffset(); |
| 27472 |
+ mBufferSizes[bufferIndex] = gl::GetBoundBufferAvailableSize(binding); |
| 27473 |
+ mBufferHandles[bufferIndex] = bufferMtl; |
| 27474 |
+ |
| 27475 |
+ ASSERT(contextMtl->getDisplay()->getFeatures().emulateTransformFeedback.enabled); |
| 27476 |
+ const MtlDeviceSize offsetAlignment = mtl::kUniformBufferSettingOffsetMinAlignment; |
| 27477 |
+ |
| 27478 |
+ // Make sure there's no possible under/overflow with binding size. |
| 27479 |
+ static_assert(sizeof(MtlDeviceSize) >= sizeof(binding.getSize()), |
| 27480 |
+ "MtlDeviceSize too small"); |
| 27481 |
+ |
| 27482 |
+ // Set the offset as close as possible to the requested offset while remaining aligned. |
| 27483 |
+ mAlignedBufferOffsets[bufferIndex] = |
| 27484 |
+ (mBufferOffsets[bufferIndex] / offsetAlignment) * offsetAlignment; |
| 27485 |
+ } |
| 27486 |
+ |
| 27487 |
+ return contextMtl->onBeginTransformFeedback(xfbBufferCount, mBufferHandles); |
| 27488 |
} |
| 27489 |
|
| 27490 |
angle::Result TransformFeedbackMtl::end(const gl::Context *context) |
| 27491 |
{ |
| 27492 |
+ ContextMtl *contextMtl = mtl::GetImpl(context); |
| 27493 |
+ // Not currently supported with msl compiler |
| 27494 |
+ if (!contextMtl->getDisplay()->getFeatures().emulateTransformFeedback.enabled) |
| 27495 |
+ { |
| 27496 |
+ return angle::Result::Stop; |
| 27497 |
+ } |
| 27498 |
+ |
| 27499 |
+ // If there's an active transform feedback query, accumulate the primitives drawn. |
| 27500 |
const gl::State &glState = context->getState(); |
| 27501 |
gl::Query *transformFeedbackQuery = |
| 27502 |
glState.getActiveQuery(gl::QueryType::TransformFeedbackPrimitivesWritten); |
| 27503 |
+ |
| 27504 |
if (transformFeedbackQuery) |
| 27505 |
{ |
| 27506 |
- mtl::GetImpl(transformFeedbackQuery)->onTransformFeedbackEnd(context); |
| 27507 |
+ mtl::GetImpl(transformFeedbackQuery)->onTransformFeedbackEnd(mState.getPrimitivesDrawn()); |
| 27508 |
} |
| 27509 |
- |
| 27510 |
- mtl::GetImpl(context)->onTransformFeedbackInactive(context, this); |
| 27511 |
- |
| 27512 |
+ contextMtl->onEndTransformFeedback(); |
| 27513 |
return angle::Result::Continue; |
| 27514 |
} |
| 27515 |
|
| 27516 |
angle::Result TransformFeedbackMtl::pause(const gl::Context *context) |
| 27517 |
{ |
| 27518 |
- // When XFB is paused, OpenGL allows XFB buffers to be bound for other purposes. We need to call |
| 27519 |
- // onTransformFeedbackInactive() to issue a sync. |
| 27520 |
- mtl::GetImpl(context)->onTransformFeedbackInactive(context, this); |
| 27521 |
- |
| 27522 |
- return angle::Result::Continue; |
| 27523 |
+ ContextMtl *contextMtl = mtl::GetImpl(context); |
| 27524 |
+ return contextMtl->onPauseTransformFeedback(); |
| 27525 |
} |
| 27526 |
|
| 27527 |
angle::Result TransformFeedbackMtl::resume(const gl::Context *context) |
| 27528 |
{ |
| 27529 |
- mtl::GetImpl(context)->onTransformFeedbackActive(context, this); |
| 27530 |
- |
| 27531 |
- return angle::Result::Continue; |
| 27532 |
+ ContextMtl *contextMtl = mtl::GetImpl(context); |
| 27533 |
+ const gl::ProgramExecutable *executable = contextMtl->getState().getProgramExecutable(); |
| 27534 |
+ ASSERT(executable); |
| 27535 |
+ size_t xfbBufferCount = executable->getTransformFeedbackBufferCount(); |
| 27536 |
+ return contextMtl->onBeginTransformFeedback(xfbBufferCount, mBufferHandles); |
| 27537 |
} |
| 27538 |
|
| 27539 |
angle::Result TransformFeedbackMtl::bindIndexedBuffer( |
| 27540 |
@@ -68,17 +116,20 @@ |
| 27541 |
size_t index, |
| 27542 |
const gl::OffsetBindingPointer<gl::Buffer> &binding) |
| 27543 |
{ |
| 27544 |
- // Do nothing for now |
| 27545 |
+ UNIMPLEMENTED(); |
| 27546 |
|
| 27547 |
return angle::Result::Continue; |
| 27548 |
} |
| 27549 |
|
| 27550 |
-angle::Result TransformFeedbackMtl::getBufferOffsets(ContextMtl *contextMtl, |
| 27551 |
+void TransformFeedbackMtl::getBufferOffsets(ContextMtl *contextMtl, |
| 27552 |
GLint drawCallFirstVertex, |
| 27553 |
- uint32_t skippedVertices, |
| 27554 |
- int32_t *offsetsOut) |
| 27555 |
+ int32_t *offsetsOut, |
| 27556 |
+ size_t offsetsSize) const |
| 27557 |
{ |
| 27558 |
- int64_t verticesDrawn = static_cast<int64_t>(mState.getVerticesDrawn()) + skippedVertices; |
| 27559 |
+ if (!contextMtl->getDisplay()->getFeatures().emulateTransformFeedback.enabled) |
| 27560 |
+ return; |
| 27561 |
+ |
| 27562 |
+ GLsizeiptr verticesDrawn = mState.getVerticesDrawn(); |
| 27563 |
const std::vector<GLsizei> &bufferStrides = |
| 27564 |
mState.getBoundProgram()->getTransformFeedbackStrides(); |
| 27565 |
const gl::ProgramExecutable *executable = contextMtl->getState().getProgramExecutable(); |
| 27566 |
@@ -87,27 +138,25 @@ |
| 27567 |
|
| 27568 |
ASSERT(xfbBufferCount > 0); |
| 27569 |
|
| 27570 |
+ // The caller should make sure the offsets array has enough space. The maximum possible |
| 27571 |
+ // number of outputs is gl::IMPLEMENTATION_MAX_TRANSFORM_FEEDBACK_BUFFERS. |
| 27572 |
+ ASSERT(offsetsSize >= xfbBufferCount); |
| 27573 |
+ |
| 27574 |
for (size_t bufferIndex = 0; bufferIndex < xfbBufferCount; ++bufferIndex) |
| 27575 |
{ |
| 27576 |
- const gl::OffsetBindingPointer<gl::Buffer> &bufferBinding = |
| 27577 |
- mState.getIndexedBuffer(bufferIndex); |
| 27578 |
- |
| 27579 |
- ASSERT((bufferBinding.getOffset() % 4) == 0); |
| 27580 |
- |
| 27581 |
- // Offset the gl_VertexIndex by drawCallFirstVertex |
| 27582 |
+ int64_t offsetFromDescriptor = |
| 27583 |
+ static_cast<int64_t>(mBufferOffsets[bufferIndex] - mAlignedBufferOffsets[bufferIndex]); |
| 27584 |
int64_t drawCallVertexOffset = static_cast<int64_t>(verticesDrawn) - drawCallFirstVertex; |
| 27585 |
|
| 27586 |
int64_t writeOffset = |
| 27587 |
- (bufferBinding.getOffset() + drawCallVertexOffset * bufferStrides[bufferIndex]) / |
| 27588 |
+ (offsetFromDescriptor + drawCallVertexOffset * bufferStrides[bufferIndex]) / |
| 27589 |
static_cast<int64_t>(sizeof(uint32_t)); |
| 27590 |
|
| 27591 |
offsetsOut[bufferIndex] = static_cast<int32_t>(writeOffset); |
| 27592 |
|
| 27593 |
- // Check for overflow. |
| 27594 |
- ANGLE_CHECK_GL_ALLOC(contextMtl, offsetsOut[bufferIndex] == writeOffset); |
| 27595 |
+ // Assert on overflow. For now, support transform feedback up to 2GB. |
| 27596 |
+ ASSERT(offsetsOut[bufferIndex] == writeOffset); |
| 27597 |
} |
| 27598 |
- |
| 27599 |
- return angle::Result::Continue; |
| 27600 |
} |
| 27601 |
|
| 27602 |
} // namespace rx |
| 27603 |
diff --git a/src/libANGLE/renderer/metal/VertexArrayMtl.h b/src/libANGLE/renderer/metal/VertexArrayMtl.h |
| 27604 |
index c2fb846..fe6b5f7 100644 |
| 27605 |
--- a/src/libANGLE/renderer/metal/VertexArrayMtl.h |
| 27606 |
+++ b/src/libANGLE/renderer/metal/VertexArrayMtl.h |
| 27607 |
@@ -43,8 +43,9 @@ class VertexArrayMtl : public VertexArrayImpl |
| 27608 |
const void *indices); |
| 27609 |
|
| 27610 |
// vertexDescChanged is both input and output, the input value if is true, will force new |
| 27611 |
- // mtl::VertexDesc to be returned via vertexDescOut. Otherwise, it is only returned when the |
| 27612 |
- // vertex array is dirty |
| 27613 |
+ // mtl::VertexDesc to be returned via vertexDescOut. This typically happens when active shader |
| 27614 |
+ // program is changed. |
| 27615 |
+ // Otherwise, it is only returned when the vertex array is dirty. |
| 27616 |
angle::Result setupDraw(const gl::Context *glContext, |
| 27617 |
mtl::RenderCommandEncoder *cmdEncoder, |
| 27618 |
bool *vertexDescChanged, |
| 27619 |
@@ -52,11 +53,24 @@ class VertexArrayMtl : public VertexArrayImpl |
| 27620 |
|
| 27621 |
angle::Result getIndexBuffer(const gl::Context *glContext, |
| 27622 |
gl::DrawElementsType indexType, |
| 27623 |
+ gl::PrimitiveMode primitiveMode, |
| 27624 |
size_t indexCount, |
| 27625 |
const void *sourcePointer, |
| 27626 |
mtl::BufferRef *idxBufferOut, |
| 27627 |
size_t *idxBufferOffsetOut, |
| 27628 |
- gl::DrawElementsType *indexTypeOut); |
| 27629 |
+ gl::DrawElementsType *indexTypeOut, |
| 27630 |
+ size_t *indexBufferCountOut); |
| 27631 |
+ |
| 27632 |
+ // Use to emulate instanced draw for instance <instanceId>. |
| 27633 |
+ // The typical call sequence for emulated instance draw is: |
| 27634 |
+ // - setupDraw() |
| 27635 |
+ // - draw. |
| 27636 |
+ // - emulateInstanceDrawStep(1) |
| 27637 |
+ // - draw. |
| 27638 |
+ // - emulateInstanceDrawStep(n) |
| 27639 |
+ // - draw. |
| 27640 |
+ // - emulateInstanceDrawStep(0) |
| 27641 |
+ void emulateInstanceDrawStep(mtl::RenderCommandEncoder *cmdEncoder, uint32_t instanceId); |
| 27642 |
|
| 27643 |
private: |
| 27644 |
void reset(ContextMtl *context); |
| 27645 |
@@ -72,15 +86,19 @@ class VertexArrayMtl : public VertexArrayImpl |
| 27646 |
|
| 27647 |
angle::Result convertIndexBuffer(const gl::Context *glContext, |
| 27648 |
gl::DrawElementsType indexType, |
| 27649 |
+ gl::PrimitiveMode mode, |
| 27650 |
size_t offset, |
| 27651 |
mtl::BufferRef *idxBufferOut, |
| 27652 |
- size_t *idxBufferOffsetOut); |
| 27653 |
+ size_t *idxBufferOffsetOut, |
| 27654 |
+ size_t *indexBufferCountOut); |
| 27655 |
angle::Result streamIndexBufferFromClient(const gl::Context *glContext, |
| 27656 |
gl::DrawElementsType indexType, |
| 27657 |
+ gl::PrimitiveMode primitiveType, |
| 27658 |
size_t indexCount, |
| 27659 |
const void *sourcePointer, |
| 27660 |
mtl::BufferRef *idxBufferOut, |
| 27661 |
- size_t *idxBufferOffsetOut); |
| 27662 |
+ size_t *idxBufferOffsetOut, |
| 27663 |
+ size_t *idxBufferCountOut); |
| 27664 |
|
| 27665 |
angle::Result convertIndexBufferGPU(const gl::Context *glContext, |
| 27666 |
gl::DrawElementsType indexType, |
| 27667 |
@@ -117,7 +135,20 @@ class VertexArrayMtl : public VertexArrayImpl |
| 27668 |
gl::AttribArray<BufferHolderMtl *> mCurrentArrayBuffers; |
| 27669 |
gl::AttribArray<SimpleWeakBufferHolderMtl> mConvertedArrayBufferHolders; |
| 27670 |
gl::AttribArray<size_t> mCurrentArrayBufferOffsets; |
| 27671 |
+ |
| 27672 |
+ // Size to be uploaded as inline constant data. Used for client vertex attribute's data that |
| 27673 |
+ // is small enough that we can send directly as inline constant data instead of streaming |
| 27674 |
+ // through a buffer. |
| 27675 |
+ gl::AttribArray<size_t> mCurrentArrayInlineDataSizes; |
| 27676 |
+ // Array of host buffers storing converted data for client attributes that are small enough. |
| 27677 |
+ gl::AttribArray<angle::MemoryBuffer> mConvertedClientSmallArrays; |
| 27678 |
+ gl::AttribArray<const uint8_t *> mCurrentArrayInlineDataPointers; |
| 27679 |
+ // Max size of inline constant data that can be used for client vertex attribute. |
| 27680 |
+ size_t mInlineDataMaxSize; |
| 27681 |
+ |
| 27682 |
+ // Stride per vertex attribute |
| 27683 |
gl::AttribArray<GLuint> mCurrentArrayBufferStrides; |
| 27684 |
+ // Format per vertex attribute |
| 27685 |
gl::AttribArray<const mtl::VertexFormat *> mCurrentArrayBufferFormats; |
| 27686 |
|
| 27687 |
const mtl::VertexFormat &mDefaultFloatVertexFormat; |
| 27688 |
@@ -127,6 +158,8 @@ class VertexArrayMtl : public VertexArrayImpl |
| 27689 |
mtl::BufferPool mDynamicVertexData; |
| 27690 |
mtl::BufferPool mDynamicIndexData; |
| 27691 |
|
| 27692 |
+ std::vector<uint32_t> mEmulatedInstanceAttribs; |
| 27693 |
+ |
| 27694 |
bool mVertexArrayDirty = true; |
| 27695 |
}; |
| 27696 |
} // namespace rx |
| 27697 |
diff --git a/src/libANGLE/renderer/metal/VertexArrayMtl.mm b/src/libANGLE/renderer/metal/VertexArrayMtl.mm |
| 27698 |
index cd961c1..02195d8 100644 |
| 27699 |
--- a/src/libANGLE/renderer/metal/VertexArrayMtl.mm |
| 27700 |
+++ b/src/libANGLE/renderer/metal/VertexArrayMtl.mm |
| 27701 |
@@ -8,6 +8,9 @@ |
| 27702 |
// |
| 27703 |
|
| 27704 |
#include "libANGLE/renderer/metal/VertexArrayMtl.h" |
| 27705 |
+ |
| 27706 |
+#include <TargetConditionals.h> |
| 27707 |
+ |
| 27708 |
#include "libANGLE/renderer/metal/BufferMtl.h" |
| 27709 |
#include "libANGLE/renderer/metal/ContextMtl.h" |
| 27710 |
#include "libANGLE/renderer/metal/DisplayMtl.h" |
| 27711 |
@@ -76,15 +79,15 @@ size_t GetIndexConvertedBufferSize(gl::DrawElementsType indexType, size_t indexC |
| 27712 |
const uint8_t *sourcePointer, |
| 27713 |
gl::DrawElementsType indexType, |
| 27714 |
size_t indexCount, |
| 27715 |
+ gl::PrimitiveMode mode, |
| 27716 |
bool primitiveRestartEnabled, |
| 27717 |
mtl::BufferRef *bufferOut, |
| 27718 |
- size_t *bufferOffsetOut) |
| 27719 |
+ size_t *bufferOffsetOut, |
| 27720 |
+ size_t *indexCountOut) |
| 27721 |
{ |
| 27722 |
dynamicBuffer->releaseInFlightBuffers(contextMtl); |
| 27723 |
- |
| 27724 |
const size_t amount = GetIndexConvertedBufferSize(indexType, indexCount); |
| 27725 |
GLubyte *dst = nullptr; |
| 27726 |
- |
| 27727 |
ANGLE_TRY( |
| 27728 |
dynamicBuffer->allocate(contextMtl, amount, &dst, bufferOut, bufferOffsetOut, nullptr)); |
| 27729 |
|
| 27730 |
@@ -121,6 +124,7 @@ size_t GetIndexConvertedBufferSize(gl::DrawElementsType indexType, size_t indexC |
| 27731 |
{ |
| 27732 |
memcpy(dst, sourcePointer, amount); |
| 27733 |
} |
| 27734 |
+ *indexCountOut = indexCount; |
| 27735 |
ANGLE_TRY(dynamicBuffer->commit(contextMtl)); |
| 27736 |
|
| 27737 |
return angle::Result::Continue; |
| 27738 |
@@ -208,6 +212,30 @@ inline void SetDefaultVertexBufferLayout(mtl::VertexBufferLayoutDesc *layout) |
| 27739 |
format = &mDefaultFloatVertexFormat; |
| 27740 |
} |
| 27741 |
|
| 27742 |
+ for (size_t &inlineDataSize : mCurrentArrayInlineDataSizes) |
| 27743 |
+ { |
| 27744 |
+ inlineDataSize = 0; |
| 27745 |
+ } |
| 27746 |
+ |
| 27747 |
+ for (angle::MemoryBuffer &convertedClientArray : mConvertedClientSmallArrays) |
| 27748 |
+ { |
| 27749 |
+ convertedClientArray.clear(); |
| 27750 |
+ } |
| 27751 |
+ |
| 27752 |
+ for (const uint8_t *&clientPointer : mCurrentArrayInlineDataPointers) |
| 27753 |
+ { |
| 27754 |
+ clientPointer = nullptr; |
| 27755 |
+ } |
| 27756 |
+ |
| 27757 |
+ if (context->getDisplay()->getFeatures().allowInlineConstVertexData.enabled) |
| 27758 |
+ { |
| 27759 |
+ mInlineDataMaxSize = mtl::kInlineConstDataMaxSize; |
| 27760 |
+ } |
| 27761 |
+ else |
| 27762 |
+ { |
| 27763 |
+ mInlineDataMaxSize = 0; |
| 27764 |
+ } |
| 27765 |
+ |
| 27766 |
mVertexArrayDirty = true; |
| 27767 |
} |
| 27768 |
|
| 27769 |
@@ -315,22 +343,28 @@ inline void SetDefaultVertexBufferLayout(mtl::VertexBufferLayoutDesc *layout) |
| 27770 |
} |
| 27771 |
|
| 27772 |
// vertexDescChanged is both input and output, the input value if is true, will force new |
| 27773 |
-// mtl::VertexDesc to be returned via vertexDescOut. Otherwise, it is only returned when the |
| 27774 |
-// vertex array is dirty |
| 27775 |
+// mtl::VertexDesc to be returned via vertexDescOut. This typically happens when active shader |
| 27776 |
+// program is changed. |
| 27777 |
+// Otherwise, it is only returned when the vertex array is dirty. |
| 27778 |
angle::Result VertexArrayMtl::setupDraw(const gl::Context *glContext, |
| 27779 |
mtl::RenderCommandEncoder *cmdEncoder, |
| 27780 |
bool *vertexDescChanged, |
| 27781 |
mtl::VertexDesc *vertexDescOut) |
| 27782 |
{ |
| 27783 |
+ // NOTE(hqle): consider only updating dirty attributes |
| 27784 |
bool dirty = mVertexArrayDirty || *vertexDescChanged; |
| 27785 |
|
| 27786 |
if (dirty) |
| 27787 |
{ |
| 27788 |
+ ContextMtl *contextMtl = mtl::GetImpl(glContext); |
| 27789 |
+ |
| 27790 |
mVertexArrayDirty = false; |
| 27791 |
+ mEmulatedInstanceAttribs.clear(); |
| 27792 |
|
| 27793 |
- const gl::ProgramState &programState = glContext->getState().getProgram()->getState(); |
| 27794 |
+ const gl::ProgramExecutable *executable = glContext->getState().getProgramExecutable(); |
| 27795 |
const gl::AttributesMask &programActiveAttribsMask = |
| 27796 |
- glContext->getState().getProgram()->getExecutable().getActiveAttribLocationsMask(); |
| 27797 |
+ executable->getActiveAttribLocationsMask(); |
| 27798 |
+ const gl::ProgramState &programState = glContext->getState().getProgram()->getState(); |
| 27799 |
|
| 27800 |
const std::vector<gl::VertexAttribute> &attribs = mState.getVertexAttributes(); |
| 27801 |
const std::vector<gl::VertexBinding> &bindings = mState.getVertexBindings(); |
| 27802 |
@@ -360,8 +394,7 @@ inline void SetDefaultVertexBufferLayout(mtl::VertexBufferLayoutDesc *layout) |
| 27803 |
const gl::VertexBinding &binding = bindings[attrib.bindingIndex]; |
| 27804 |
|
| 27805 |
bool attribEnabled = attrib.enabled; |
| 27806 |
- if (attribEnabled && |
| 27807 |
- (!mCurrentArrayBuffers[v] || !mCurrentArrayBuffers[v]->getCurrentBuffer())) |
| 27808 |
+ if (attribEnabled && !mCurrentArrayBuffers[v] && !mCurrentArrayInlineDataPointers[v]) |
| 27809 |
{ |
| 27810 |
// Disable it to avoid crash. |
| 27811 |
attribEnabled = false; |
| 27812 |
@@ -369,33 +402,30 @@ inline void SetDefaultVertexBufferLayout(mtl::VertexBufferLayoutDesc *layout) |
| 27813 |
|
| 27814 |
if (!attribEnabled) |
| 27815 |
{ |
| 27816 |
- // Use default attribute |
| 27817 |
+ desc.attributes[v].bufferIndex = mtl::kDefaultAttribsBindingIndex; |
| 27818 |
+ desc.attributes[v].offset = v * mtl::kDefaultAttributeSize; |
| 27819 |
// Need to find the attribute having the exact binding location = v in the program |
| 27820 |
// inputs list to retrieve its coresponding data type: |
| 27821 |
const std::vector<sh::ShaderVariable> &programInputs = |
| 27822 |
programState.getProgramInputs(); |
| 27823 |
std::vector<sh::ShaderVariable>::const_iterator attribInfoIte = std::find_if( |
| 27824 |
begin(programInputs), end(programInputs), [v](const sh::ShaderVariable &sv) { |
| 27825 |
- return static_cast<uint32_t>(sv.location) == v; |
| 27826 |
+ return static_cast<uint32_t>(sv.location) <= v && |
| 27827 |
+ v < static_cast<uint32_t>(sv.location) + |
| 27828 |
+ gl::VariableAttributeCount(sv.type); |
| 27829 |
}); |
| 27830 |
|
| 27831 |
- if (attribInfoIte == end(programInputs)) |
| 27832 |
+ ASSERT(attribInfoIte != end(programInputs)); |
| 27833 |
+ switch (gl::VariableComponentType(attribInfoIte->type)) |
| 27834 |
{ |
| 27835 |
- // Most likely this is array element with index > 0. |
| 27836 |
- // Already handled when encounter first element. |
| 27837 |
- continue; |
| 27838 |
- } |
| 27839 |
- |
| 27840 |
- uint32_t arraySize; |
| 27841 |
- MTLVertexFormat format; |
| 27842 |
- |
| 27843 |
- getVertexAttribFormatAndArraySize(*attribInfoIte, &format, &arraySize); |
| 27844 |
- |
| 27845 |
- for (uint32_t vaIdx = v; vaIdx < v + arraySize; ++vaIdx) |
| 27846 |
- { |
| 27847 |
- desc.attributes[vaIdx].bufferIndex = mtl::kDefaultAttribsBindingIndex; |
| 27848 |
- desc.attributes[vaIdx].offset = vaIdx * mtl::kDefaultAttributeSize; |
| 27849 |
- desc.attributes[vaIdx].format = format; |
| 27850 |
+ case GL_INT: |
| 27851 |
+ desc.attributes[v].format = mDefaultIntVertexFormat.metalFormat; |
| 27852 |
+ break; |
| 27853 |
+ case GL_UNSIGNED_INT: |
| 27854 |
+ desc.attributes[v].format = mDefaultUIntVertexFormat.metalFormat; |
| 27855 |
+ break; |
| 27856 |
+ default: |
| 27857 |
+ desc.attributes[v].format = mDefaultFloatVertexFormat.metalFormat; |
| 27858 |
} |
| 27859 |
} |
| 27860 |
else |
| 27861 |
@@ -417,17 +447,35 @@ inline void SetDefaultVertexBufferLayout(mtl::VertexBufferLayoutDesc *layout) |
| 27862 |
desc.layouts[bufferIdx].stepFunction = MTLVertexStepFunctionPerVertex; |
| 27863 |
desc.layouts[bufferIdx].stepRate = 1; |
| 27864 |
} |
| 27865 |
- else |
| 27866 |
+ else if (contextMtl->getDisplay()->getFeatures().hasBaseVertexInstancedDraw.enabled) |
| 27867 |
{ |
| 27868 |
desc.layouts[bufferIdx].stepFunction = MTLVertexStepFunctionPerInstance; |
| 27869 |
desc.layouts[bufferIdx].stepRate = binding.getDivisor(); |
| 27870 |
} |
| 27871 |
+ else |
| 27872 |
+ { |
| 27873 |
+ // Emulate instance attribute |
| 27874 |
+ mEmulatedInstanceAttribs.push_back(v); |
| 27875 |
+ desc.layouts[bufferIdx].stepFunction = MTLVertexStepFunctionConstant; |
| 27876 |
+ desc.layouts[bufferIdx].stepRate = 0; |
| 27877 |
+ } |
| 27878 |
+ |
| 27879 |
desc.layouts[bufferIdx].stride = mCurrentArrayBufferStrides[v]; |
| 27880 |
|
| 27881 |
+ if (mCurrentArrayBuffers[v]) |
| 27882 |
+ { |
| 27883 |
cmdEncoder->setVertexBuffer(mCurrentArrayBuffers[v]->getCurrentBuffer(), |
| 27884 |
bufferOffset, bufferIdx); |
| 27885 |
} |
| 27886 |
+ else |
| 27887 |
+ { |
| 27888 |
+ // No buffer specified, use the client memory directly as inline constant data |
| 27889 |
+ ASSERT(mCurrentArrayInlineDataSizes[v] <= mInlineDataMaxSize); |
| 27890 |
+ cmdEncoder->setVertexBytes(mCurrentArrayInlineDataPointers[v], |
| 27891 |
+ mCurrentArrayInlineDataSizes[v], bufferIdx); |
| 27892 |
+ } |
| 27893 |
} |
| 27894 |
+ } // for (v) |
| 27895 |
} |
| 27896 |
|
| 27897 |
*vertexDescChanged = dirty; |
| 27898 |
@@ -435,6 +483,42 @@ inline void SetDefaultVertexBufferLayout(mtl::VertexBufferLayoutDesc *layout) |
| 27899 |
return angle::Result::Continue; |
| 27900 |
} |
| 27901 |
|
| 27902 |
+void VertexArrayMtl::emulateInstanceDrawStep(mtl::RenderCommandEncoder *cmdEncoder, |
| 27903 |
+ uint32_t instanceId) |
| 27904 |
+{ |
| 27905 |
+ |
| 27906 |
+ const std::vector<gl::VertexAttribute> &attribs = mState.getVertexAttributes(); |
| 27907 |
+ const std::vector<gl::VertexBinding> &bindings = mState.getVertexBindings(); |
| 27908 |
+ |
| 27909 |
+ for (uint32_t instanceAttribIdx : mEmulatedInstanceAttribs) |
| 27910 |
+ { |
| 27911 |
+ uint32_t bufferIdx = mtl::kVboBindingIndexStart + instanceAttribIdx; |
| 27912 |
+ const auto &attrib = attribs[instanceAttribIdx]; |
| 27913 |
+ const gl::VertexBinding &binding = bindings[attrib.bindingIndex]; |
| 27914 |
+ uint32_t offset = |
| 27915 |
+ instanceId / binding.getDivisor() * mCurrentArrayBufferStrides[instanceAttribIdx]; |
| 27916 |
+ if (mCurrentArrayBuffers[instanceAttribIdx]) |
| 27917 |
+ { |
| 27918 |
+ offset += static_cast<uint32_t>(mCurrentArrayBufferOffsets[instanceAttribIdx]); |
| 27919 |
+ |
| 27920 |
+ cmdEncoder->setVertexBuffer(mCurrentArrayBuffers[instanceAttribIdx]->getCurrentBuffer(), |
| 27921 |
+ offset, bufferIdx); |
| 27922 |
+ } |
| 27923 |
+ else |
| 27924 |
+ { |
| 27925 |
+ // No buffer specified, use the client memory directly as inline constant data |
| 27926 |
+ ASSERT(mCurrentArrayInlineDataSizes[instanceAttribIdx] <= mInlineDataMaxSize); |
| 27927 |
+ if (offset > mCurrentArrayInlineDataSizes[instanceAttribIdx]) |
| 27928 |
+ { |
| 27929 |
+ offset = static_cast<uint32_t>(mCurrentArrayInlineDataSizes[instanceAttribIdx]); |
| 27930 |
+ } |
| 27931 |
+ cmdEncoder->setVertexBytes(mCurrentArrayInlineDataPointers[instanceAttribIdx] + offset, |
| 27932 |
+ mCurrentArrayInlineDataSizes[instanceAttribIdx] - offset, |
| 27933 |
+ bufferIdx); |
| 27934 |
+ } |
| 27935 |
+ } |
| 27936 |
+} |
| 27937 |
+ |
| 27938 |
angle::Result VertexArrayMtl::updateClientAttribs(const gl::Context *context, |
| 27939 |
GLint firstVertex, |
| 27940 |
GLsizei vertexOrIndexCount, |
| 27941 |
@@ -463,10 +547,7 @@ inline void SetDefaultVertexBufferLayout(mtl::VertexBufferLayoutDesc *layout) |
| 27942 |
const gl::VertexBinding &binding = bindings[attrib.bindingIndex]; |
| 27943 |
ASSERT(attrib.enabled && binding.getBuffer().get() == nullptr); |
| 27944 |
|
| 27945 |
- GLuint stride; |
| 27946 |
- const mtl::VertexFormat &vertexFormat = |
| 27947 |
- GetVertexConversionFormat(contextMtl, attrib.format->id, &stride); |
| 27948 |
- |
| 27949 |
+ // Source client memory pointer |
| 27950 |
const uint8_t *src = static_cast<const uint8_t *>(attrib.pointer); |
| 27951 |
ASSERT(src); |
| 27952 |
|
| 27953 |
@@ -484,22 +565,76 @@ inline void SetDefaultVertexBufferLayout(mtl::VertexBufferLayoutDesc *layout) |
| 27954 |
startElement = 0; |
| 27955 |
elementCount = UnsignedCeilDivide(instanceCount, binding.getDivisor()); |
| 27956 |
} |
| 27957 |
+ size_t bytesIntendedToUse = (startElement + elementCount) * binding.getStride(); |
| 27958 |
+ |
| 27959 |
+ const mtl::VertexFormat &format = contextMtl->getVertexFormat(attrib.format->id, false); |
| 27960 |
+ bool needStreaming = format.actualFormatId != format.intendedFormatId || |
| 27961 |
+ (binding.getStride() % mtl::kVertexAttribBufferStrideAlignment) != 0 || |
| 27962 |
+ (binding.getStride() < format.actualAngleFormat().pixelBytes) || |
| 27963 |
+ bytesIntendedToUse > mInlineDataMaxSize; |
| 27964 |
+ |
| 27965 |
+ if (!needStreaming) |
| 27966 |
+ { |
| 27967 |
+ // Data will be uploaded directly as inline constant data |
| 27968 |
+ mCurrentArrayBuffers[attribIndex] = nullptr; |
| 27969 |
+ mCurrentArrayInlineDataPointers[attribIndex] = src; |
| 27970 |
+ mCurrentArrayInlineDataSizes[attribIndex] = bytesIntendedToUse; |
| 27971 |
+ mCurrentArrayBufferOffsets[attribIndex] = 0; |
| 27972 |
+ mCurrentArrayBufferFormats[attribIndex] = &format; |
| 27973 |
+ mCurrentArrayBufferStrides[attribIndex] = binding.getStride(); |
| 27974 |
+ } |
| 27975 |
+ else |
| 27976 |
+ { |
| 27977 |
+ GLuint convertedStride; |
| 27978 |
+ // Need to stream the client vertex data to a buffer. |
| 27979 |
+ const mtl::VertexFormat &streamFormat = |
| 27980 |
+ GetVertexConversionFormat(contextMtl, attrib.format->id, &convertedStride); |
| 27981 |
+ |
| 27982 |
// Allocate space for startElement + elementCount so indexing will work. If we don't |
| 27983 |
// start at zero all the indices will be off. |
| 27984 |
// Only elementCount vertices will be used by the upcoming draw so that is all we copy. |
| 27985 |
- size_t bytesToAllocate = (startElement + elementCount) * stride; |
| 27986 |
+ size_t bytesToAllocate = (startElement + elementCount) * convertedStride; |
| 27987 |
src += startElement * binding.getStride(); |
| 27988 |
- size_t destOffset = startElement * stride; |
| 27989 |
+ size_t destOffset = startElement * convertedStride; |
| 27990 |
|
| 27991 |
- mDynamicVertexData.updateAlignment(contextMtl, vertexFormat.actualAngleFormat().pixelBytes); |
| 27992 |
- ANGLE_TRY(StreamVertexData( |
| 27993 |
- contextMtl, &mDynamicVertexData, src, bytesToAllocate, destOffset, elementCount, |
| 27994 |
- binding.getStride(), vertexFormat.vertexLoadFunction, |
| 27995 |
- &mConvertedArrayBufferHolders[attribIndex], &mCurrentArrayBufferOffsets[attribIndex])); |
| 27996 |
+ mCurrentArrayBufferFormats[attribIndex] = &streamFormat; |
| 27997 |
+ mCurrentArrayBufferStrides[attribIndex] = convertedStride; |
| 27998 |
+ |
| 27999 |
+ if (bytesToAllocate <= mInlineDataMaxSize) |
| 28000 |
+ { |
| 28001 |
+ // If the data is small enough, use host memory instead of creating GPU buffer. To |
| 28002 |
+ // avoid synchronizing access to GPU buffer that is still in use. |
| 28003 |
+ angle::MemoryBuffer &convertedClientArray = |
| 28004 |
+ mConvertedClientSmallArrays[attribIndex]; |
| 28005 |
+ if (bytesToAllocate > convertedClientArray.size()) |
| 28006 |
+ { |
| 28007 |
+ ANGLE_CHECK_GL_ALLOC(contextMtl, convertedClientArray.resize(bytesToAllocate)); |
| 28008 |
+ } |
| 28009 |
+ |
| 28010 |
+ ASSERT(streamFormat.vertexLoadFunction); |
| 28011 |
+ streamFormat.vertexLoadFunction(src, binding.getStride(), elementCount, |
| 28012 |
+ convertedClientArray.data() + destOffset); |
| 28013 |
+ |
| 28014 |
+ mCurrentArrayBuffers[attribIndex] = nullptr; |
| 28015 |
+ mCurrentArrayInlineDataPointers[attribIndex] = convertedClientArray.data(); |
| 28016 |
+ mCurrentArrayInlineDataSizes[attribIndex] = bytesToAllocate; |
| 28017 |
+ mCurrentArrayBufferOffsets[attribIndex] = 0; |
| 28018 |
+ } |
| 28019 |
+ else |
| 28020 |
+ { |
| 28021 |
+ // Stream the client data to a GPU buffer. Synchronization might happen if buffer is |
| 28022 |
+ // in use. |
| 28023 |
+ mDynamicVertexData.updateAlignment(contextMtl, |
| 28024 |
+ streamFormat.actualAngleFormat().pixelBytes); |
| 28025 |
+ ANGLE_TRY(StreamVertexData(contextMtl, &mDynamicVertexData, src, bytesToAllocate, |
| 28026 |
+ destOffset, elementCount, binding.getStride(), |
| 28027 |
+ streamFormat.vertexLoadFunction, |
| 28028 |
+ &mConvertedArrayBufferHolders[attribIndex], |
| 28029 |
+ &mCurrentArrayBufferOffsets[attribIndex])); |
| 28030 |
|
| 28031 |
mCurrentArrayBuffers[attribIndex] = &mConvertedArrayBufferHolders[attribIndex]; |
| 28032 |
- mCurrentArrayBufferFormats[attribIndex] = &vertexFormat; |
| 28033 |
- mCurrentArrayBufferStrides[attribIndex] = stride; |
| 28034 |
+ } |
| 28035 |
+ } // if (needStreaming) |
| 28036 |
} |
| 28037 |
|
| 28038 |
mVertexArrayDirty = true; |
| 28039 |
@@ -526,7 +661,7 @@ inline void SetDefaultVertexBufferLayout(mtl::VertexBufferLayoutDesc *layout) |
| 28040 |
bool needConversion = |
| 28041 |
format.actualFormatId != format.intendedFormatId || |
| 28042 |
(binding.getOffset() % format.actualAngleFormat().pixelBytes) != 0 || |
| 28043 |
- (binding.getOffset() % mtl::kVertexAttribBufferStrideAlignment) != 0 || |
| 28044 |
+ (binding.getOffset() % 4) != 0 || |
| 28045 |
(binding.getStride() < format.actualAngleFormat().pixelBytes) || |
| 28046 |
(binding.getStride() % mtl::kVertexAttribBufferStrideAlignment) != 0; |
| 28047 |
|
| 28048 |
@@ -563,19 +698,21 @@ inline void SetDefaultVertexBufferLayout(mtl::VertexBufferLayoutDesc *layout) |
| 28049 |
|
| 28050 |
angle::Result VertexArrayMtl::getIndexBuffer(const gl::Context *context, |
| 28051 |
gl::DrawElementsType type, |
| 28052 |
+ gl::PrimitiveMode mode, |
| 28053 |
size_t count, |
| 28054 |
const void *indices, |
| 28055 |
mtl::BufferRef *idxBufferOut, |
| 28056 |
size_t *idxBufferOffsetOut, |
| 28057 |
- gl::DrawElementsType *indexTypeOut) |
| 28058 |
+ gl::DrawElementsType *indexTypeOut, |
| 28059 |
+ size_t *indexBufferCountOut) |
| 28060 |
{ |
| 28061 |
const gl::Buffer *glElementArrayBuffer = getState().getElementArrayBuffer(); |
| 28062 |
|
| 28063 |
size_t convertedOffset = reinterpret_cast<size_t>(indices); |
| 28064 |
if (!glElementArrayBuffer) |
| 28065 |
{ |
| 28066 |
- ANGLE_TRY(streamIndexBufferFromClient(context, type, count, indices, idxBufferOut, |
| 28067 |
- idxBufferOffsetOut)); |
| 28068 |
+ ANGLE_TRY(streamIndexBufferFromClient(context, type, mode, count, indices, idxBufferOut, |
| 28069 |
+ idxBufferOffsetOut, indexBufferCountOut)); |
| 28070 |
} |
| 28071 |
else |
| 28072 |
{ |
| 28073 |
@@ -583,8 +720,8 @@ inline void SetDefaultVertexBufferLayout(mtl::VertexBufferLayoutDesc *layout) |
| 28074 |
(convertedOffset % mtl::kIndexBufferOffsetAlignment) != 0; |
| 28075 |
if (needConversion) |
| 28076 |
{ |
| 28077 |
- ANGLE_TRY(convertIndexBuffer(context, type, convertedOffset, idxBufferOut, |
| 28078 |
- idxBufferOffsetOut)); |
| 28079 |
+ ANGLE_TRY(convertIndexBuffer(context, type, mode, convertedOffset, idxBufferOut, |
| 28080 |
+ idxBufferOffsetOut, indexBufferCountOut)); |
| 28081 |
} |
| 28082 |
else |
| 28083 |
{ |
| 28084 |
@@ -592,6 +729,7 @@ inline void SetDefaultVertexBufferLayout(mtl::VertexBufferLayoutDesc *layout) |
| 28085 |
BufferMtl *bufferMtl = mtl::GetImpl(glElementArrayBuffer); |
| 28086 |
*idxBufferOut = bufferMtl->getCurrentBuffer(); |
| 28087 |
*idxBufferOffsetOut = convertedOffset; |
| 28088 |
+ *indexBufferCountOut = count; |
| 28089 |
} |
| 28090 |
} |
| 28091 |
|
| 28092 |
@@ -607,9 +745,11 @@ inline void SetDefaultVertexBufferLayout(mtl::VertexBufferLayoutDesc *layout) |
| 28093 |
|
| 28094 |
angle::Result VertexArrayMtl::convertIndexBuffer(const gl::Context *glContext, |
| 28095 |
gl::DrawElementsType indexType, |
| 28096 |
+ gl::PrimitiveMode mode, |
| 28097 |
size_t offset, |
| 28098 |
mtl::BufferRef *idxBufferOut, |
| 28099 |
- size_t *idxBufferOffsetOut) |
| 28100 |
+ size_t *idxBufferOffsetOut, |
| 28101 |
+ size_t *indexBufferCountOut) |
| 28102 |
{ |
| 28103 |
size_t offsetModulo = offset % mtl::kIndexBufferOffsetAlignment; |
| 28104 |
ASSERT(offsetModulo != 0 || indexType == gl::DrawElementsType::UnsignedByte); |
| 28105 |
@@ -638,15 +778,15 @@ inline void SetDefaultVertexBufferLayout(mtl::VertexBufferLayoutDesc *layout) |
| 28106 |
} |
| 28107 |
|
| 28108 |
size_t indexCount = GetIndexCount(idxBuffer, offsetModulo, indexType); |
| 28109 |
- |
| 28110 |
- if (!contextMtl->getDisplay()->getFeatures().hasCheapRenderPass.enabled && |
| 28111 |
- contextMtl->getRenderCommandEncoder()) |
| 28112 |
+ if ((!contextMtl->getDisplay()->getFeatures().breakRenderPassIsCheap.enabled && |
| 28113 |
+ contextMtl->getRenderCommandEncoder())) |
| 28114 |
{ |
| 28115 |
// We shouldn't use GPU to convert when we are in a middle of a render pass. |
| 28116 |
ANGLE_TRY(StreamIndexData(contextMtl, &conversion->data, |
| 28117 |
idxBuffer->getClientShadowCopyData(contextMtl) + offsetModulo, |
| 28118 |
- indexType, indexCount, glState.isPrimitiveRestartEnabled(), |
| 28119 |
- &conversion->convertedBuffer, &conversion->convertedOffset)); |
| 28120 |
+ indexType, indexCount, mode, glState.isPrimitiveRestartEnabled(), |
| 28121 |
+ &conversion->convertedBuffer, &conversion->convertedOffset, |
| 28122 |
+ indexBufferCountOut)); |
| 28123 |
} |
| 28124 |
else |
| 28125 |
{ |
| 28126 |
@@ -695,18 +835,20 @@ inline void SetDefaultVertexBufferLayout(mtl::VertexBufferLayoutDesc *layout) |
| 28127 |
|
| 28128 |
angle::Result VertexArrayMtl::streamIndexBufferFromClient(const gl::Context *context, |
| 28129 |
gl::DrawElementsType indexType, |
| 28130 |
+ gl::PrimitiveMode mode, |
| 28131 |
size_t indexCount, |
| 28132 |
const void *sourcePointer, |
| 28133 |
mtl::BufferRef *idxBufferOut, |
| 28134 |
- size_t *idxBufferOffsetOut) |
| 28135 |
+ size_t *idxBufferOffsetOut, |
| 28136 |
+ size_t *idxBufferCountOut) |
| 28137 |
{ |
| 28138 |
ASSERT(getState().getElementArrayBuffer() == nullptr); |
| 28139 |
ContextMtl *contextMtl = mtl::GetImpl(context); |
| 28140 |
|
| 28141 |
auto srcData = static_cast<const uint8_t *>(sourcePointer); |
| 28142 |
- ANGLE_TRY(StreamIndexData(contextMtl, &mDynamicIndexData, srcData, indexType, indexCount, |
| 28143 |
+ ANGLE_TRY(StreamIndexData(contextMtl, &mDynamicIndexData, srcData, indexType, indexCount, mode, |
| 28144 |
context->getState().isPrimitiveRestartEnabled(), idxBufferOut, |
| 28145 |
- idxBufferOffsetOut)); |
| 28146 |
+ idxBufferOffsetOut, idxBufferCountOut)); |
| 28147 |
|
| 28148 |
return angle::Result::Continue; |
| 28149 |
} |
| 28150 |
@@ -744,7 +886,6 @@ inline void SetDefaultVertexBufferLayout(mtl::VertexBufferLayoutDesc *layout) |
| 28151 |
// Has the content of the buffer has changed since last conversion? |
| 28152 |
if (!conversion->dirty) |
| 28153 |
{ |
| 28154 |
- // Buffer's data hasn't been changed. Re-use last converted results |
| 28155 |
mConvertedArrayBufferHolders[attribIndex].set(conversion->convertedBuffer); |
| 28156 |
mCurrentArrayBufferOffsets[attribIndex] = conversion->convertedOffset; |
| 28157 |
|
| 28158 |
@@ -761,7 +902,7 @@ inline void SetDefaultVertexBufferLayout(mtl::VertexBufferLayoutDesc *layout) |
| 28159 |
bool canExpandComponentsOnGPU = convertedFormat.actualSameGLType; |
| 28160 |
|
| 28161 |
if (contextMtl->getRenderCommandEncoder() && |
| 28162 |
- !contextMtl->getDisplay()->getFeatures().hasCheapRenderPass.enabled && |
| 28163 |
+ !contextMtl->getDisplay()->getFeatures().breakRenderPassIsCheap.enabled && |
| 28164 |
!contextMtl->getDisplay()->getFeatures().hasExplicitMemBarrier.enabled) |
| 28165 |
{ |
| 28166 |
// Cannot use GPU to convert when we are in a middle of a render pass. |
| 28167 |
@@ -792,6 +933,9 @@ inline void SetDefaultVertexBufferLayout(mtl::VertexBufferLayoutDesc *layout) |
| 28168 |
conversion->convertedBuffer = mConvertedArrayBufferHolders[attribIndex].getCurrentBuffer(); |
| 28169 |
conversion->convertedOffset = mCurrentArrayBufferOffsets[attribIndex]; |
| 28170 |
|
| 28171 |
+ ASSERT(conversion->dirty); |
| 28172 |
+ conversion->dirty = false; |
| 28173 |
+ |
| 28174 |
#ifndef NDEBUG |
| 28175 |
ANGLE_MTL_OBJC_SCOPE |
| 28176 |
{ |
| 28177 |
@@ -801,9 +945,6 @@ inline void SetDefaultVertexBufferLayout(mtl::VertexBufferLayoutDesc *layout) |
| 28178 |
} |
| 28179 |
#endif |
| 28180 |
|
| 28181 |
- ASSERT(conversion->dirty); |
| 28182 |
- conversion->dirty = false; |
| 28183 |
- |
| 28184 |
return angle::Result::Continue; |
| 28185 |
} |
| 28186 |
|
| 28187 |
diff --git a/src/libANGLE/renderer/metal/doc/APPLE_clip_distance.md b/src/libANGLE/renderer/metal/doc/APPLE_clip_distance.md |
| 28188 |
index fa073ae..13afdc3 100644 |
| 28189 |
--- a/src/libANGLE/renderer/metal/doc/APPLE_clip_distance.md |
| 28190 |
+++ b/src/libANGLE/renderer/metal/doc/APPLE_clip_distance.md |
| 28191 |
@@ -6,6 +6,31 @@ level side. Writing to `gl_ClipDistance[i]` in shader will be ignored if it is d |
| 28192 |
doesn't have any equivalent API to disable/enable the writing, though writing to a `clip_distance` |
| 28193 |
variable automatically enables it. |
| 28194 |
|
| 28195 |
-To emulate this enabling/disabling API, the Metal back-end uses a similar implementation as what |
| 28196 |
-[Vulkan back-end does](../../vulkan/doc/APPLE_clip_distance.md). Please refer to that document for |
| 28197 |
-more details. |
| 28198 |
+To implement this enabling/disabling API in Metal back-end: |
| 28199 |
+ |
| 28200 |
+- The shader compiler will translate each `gl_ClipDistance[i]` assignment to an assignment to |
| 28201 |
+ `ANGLEClipDistance[i]` variable. |
| 28202 |
+- A special driver uniform variable `clipDistancesEnabled` will contain one bit flag for each |
| 28203 |
+ enabled `gl_ClipDistance[i]`. This variable supports up to 32 `gl_ClipDistance` indices. |
| 28204 |
+- At the end of vertex shader, the enabled `gl_ClipDistance[i]` will be assigned the respective |
| 28205 |
+ value from `ANGLEClipDistance[i]`. On the other hand, those disabled elements will be assigned |
| 28206 |
+ zero value. This step is described in the following code: |
| 28207 |
+ ``` |
| 28208 |
+ for (int index : arraylength(gl_ClipDistance)) |
| 28209 |
+ { |
| 28210 |
+ if (ANGLEUniforms.clipDistancesEnabled & (0x1 << index)) |
| 28211 |
+ gl_ClipDistance[index] = ANGLEClipDistance[index]; |
| 28212 |
+ else |
| 28213 |
+ gl_ClipDistance[index] = 0; |
| 28214 |
+ } |
| 28215 |
+ ``` |
| 28216 |
+- Some minor optimizations: |
| 28217 |
+ - Only those indices that are referenced in the original code will be used in if else block |
| 28218 |
+ above. |
| 28219 |
+ - Those elements whose index not referenced in the original code will be zeroised instead. |
| 28220 |
+ - If the original code only uses up to an index < `gl_MaxClipDistances`, then |
| 28221 |
+ the loop will have at most `index+1` iterations. If there is at least one index not being |
| 28222 |
+ integral constant value known at compile time then declared size of `gl_ClipDistance` |
| 28223 |
+ will be the loop size. |
| 28224 |
+ - Finally, if the original code doesn't use `gl_ClipDistance`, then all the steps above will be |
| 28225 |
+ omitted. |
| 28226 |
\ No newline at end of file |
| 28227 |
diff --git a/src/libANGLE/renderer/metal/gen_mtl_format_table.py b/src/libANGLE/renderer/metal/gen_mtl_format_table.py |
| 28228 |
index 3ce142e..6eab409 100644 |
| 28229 |
--- a/src/libANGLE/renderer/metal/gen_mtl_format_table.py |
| 28230 |
+++ b/src/libANGLE/renderer/metal/gen_mtl_format_table.py |
| 28231 |
@@ -48,7 +48,6 @@ namespace mtl |
| 28232 |
void Format::init(const DisplayMtl *display, angle::FormatID intendedFormatId_) |
| 28233 |
{{ |
| 28234 |
this->intendedFormatId = intendedFormatId_; |
| 28235 |
- |
| 28236 |
id<MTLDevice> metalDevice = display->getMetalDevice(); |
| 28237 |
|
| 28238 |
// Actual conversion |
| 28239 |
@@ -109,6 +108,23 @@ image_format_assign_template2 = """ |
| 28240 |
this->initFunction = {init_function_fallback}; |
| 28241 |
}} |
| 28242 |
""" |
| 28243 |
+#D16 is fully supported on Apple3+. However, on |
| 28244 |
+#previous versions of Apple hardware, some operations can cause |
| 28245 |
+#undefined behavior. |
| 28246 |
+image_format_assign_template3 = """ |
| 28247 |
+ if ([metalDevice supportsFamily:MTLGPUFamilyApple3]) |
| 28248 |
+ {{ |
| 28249 |
+ this->metalFormat = {mtl_format}; |
| 28250 |
+ this->actualFormatId = angle::FormatID::{actual_angle_format}; |
| 28251 |
+ this->initFunction = {init_function}; |
| 28252 |
+ }} |
| 28253 |
+ else |
| 28254 |
+ {{ |
| 28255 |
+ this->metalFormat = {mtl_format_fallback}; |
| 28256 |
+ this->actualFormatId = angle::FormatID::{actual_angle_format_fallback}; |
| 28257 |
+ this->initFunction = {init_function_fallback}; |
| 28258 |
+ }} |
| 28259 |
+""" |
| 28260 |
|
| 28261 |
case_image_format_template1 = """ case angle::FormatID::{angle_format}: |
| 28262 |
{image_format_assign} |
| 28263 |
@@ -213,6 +229,8 @@ def get_vertex_copy_function_and_default_alpha(src_format, dst_format): |
| 28264 |
|
| 28265 |
|
| 28266 |
# Generate format conversion switch case (generic case) |
| 28267 |
+ |
| 28268 |
+ |
| 28269 |
def gen_image_map_switch_case(angle_format, actual_angle_format_info, angle_to_mtl_map, |
| 28270 |
assign_gen_func): |
| 28271 |
if isinstance(actual_angle_format_info, dict): |
| 28272 |
@@ -255,6 +273,8 @@ def gen_image_map_switch_case(angle_format, actual_angle_format_info, angle_to_m |
| 28273 |
|
| 28274 |
|
| 28275 |
# Generate format conversion switch case (simple case) |
| 28276 |
+ |
| 28277 |
+ |
| 28278 |
def gen_image_map_switch_simple_case(angle_format, actual_angle_format_info, angle_to_gl, |
| 28279 |
angle_to_mtl_map): |
| 28280 |
|
| 28281 |
@@ -270,6 +290,8 @@ def gen_image_map_switch_simple_case(angle_format, actual_angle_format_info, ang |
| 28282 |
|
| 28283 |
|
| 28284 |
# Generate format conversion switch case (Mac case) |
| 28285 |
+ |
| 28286 |
+ |
| 28287 |
def gen_image_map_switch_mac_case(angle_format, actual_angle_format_info, angle_to_gl, |
| 28288 |
angle_to_mtl_map, mac_fallbacks): |
| 28289 |
gl_format = angle_to_gl[angle_format] |
| 28290 |
@@ -301,11 +323,43 @@ def gen_image_map_switch_mac_case(angle_format, actual_angle_format_info, angle_ |
| 28291 |
gen_format_assign_code) |
| 28292 |
|
| 28293 |
|
| 28294 |
+def gen_image_map_switch_ios_case(angle_format, actual_angle_format_info, angle_to_gl, |
| 28295 |
+ angle_to_mtl_map, ios_fallbacks): |
| 28296 |
+ gl_format = angle_to_gl[angle_format] |
| 28297 |
+ |
| 28298 |
+ def gen_format_assign_code(actual_angle_format, angle_to_mtl_map): |
| 28299 |
+ if actual_angle_format in ios_fallbacks: |
| 28300 |
+ # This format (Depth16Uniform) requires fallback when iOS hardware does not fully support depth16. |
| 28301 |
+ # Fallback format: |
| 28302 |
+ actual_angle_format_fallback = ios_fallbacks[actual_angle_format] |
| 28303 |
+ # return if else block: |
| 28304 |
+ return image_format_assign_template3.format( |
| 28305 |
+ actual_angle_format=actual_angle_format, |
| 28306 |
+ mtl_format=angle_to_mtl_map[actual_angle_format], |
| 28307 |
+ init_function=angle_format_utils.get_internal_format_initializer( |
| 28308 |
+ gl_format, actual_angle_format), |
| 28309 |
+ actual_angle_format_fallback=actual_angle_format_fallback, |
| 28310 |
+ mtl_format_fallback=angle_to_mtl_map[actual_angle_format_fallback], |
| 28311 |
+ init_function_fallback=angle_format_utils.get_internal_format_initializer( |
| 28312 |
+ gl_format, actual_angle_format_fallback)) |
| 28313 |
+ else: |
| 28314 |
+ # return ordinary block: |
| 28315 |
+ return image_format_assign_template1.format( |
| 28316 |
+ actual_angle_format=actual_angle_format, |
| 28317 |
+ mtl_format=angle_to_mtl_map[actual_angle_format], |
| 28318 |
+ init_function=angle_format_utils.get_internal_format_initializer( |
| 28319 |
+ gl_format, actual_angle_format)) |
| 28320 |
+ |
| 28321 |
+ return gen_image_map_switch_case(angle_format, actual_angle_format_info, angle_to_mtl_map, |
| 28322 |
+ gen_format_assign_code) |
| 28323 |
+ |
| 28324 |
+ |
| 28325 |
def gen_image_map_switch_string(image_table, angle_to_gl): |
| 28326 |
angle_override = image_table["override"] |
| 28327 |
mac_override = image_table["override_mac"] |
| 28328 |
ios_override = image_table["override_ios"] |
| 28329 |
- mac_fallbacks = image_table["d24s8_fallbacks_mac"] |
| 28330 |
+ mac_fallbacks = image_table["fallbacks_mac"] |
| 28331 |
+ ios_fallbacks = image_table["fallbacks_ios"] |
| 28332 |
angle_to_mtl = image_table["map"] |
| 28333 |
mac_specific_map = image_table["map_mac"] |
| 28334 |
ios_specific_map = image_table["map_ios"] |
| 28335 |
@@ -322,8 +376,8 @@ def gen_image_map_switch_string(image_table, angle_to_gl): |
| 28336 |
def gen_image_map_switch_common_case(angle_format, actual_angle_format): |
| 28337 |
mac_case = gen_image_map_switch_mac_case(angle_format, actual_angle_format, angle_to_gl, |
| 28338 |
mac_angle_to_mtl, mac_fallbacks) |
| 28339 |
- non_mac_case = gen_image_map_switch_simple_case(angle_format, actual_angle_format, |
| 28340 |
- angle_to_gl, angle_to_mtl) |
| 28341 |
+ non_mac_case = gen_image_map_switch_ios_case(angle_format, actual_angle_format, |
| 28342 |
+ angle_to_gl, angle_to_mtl, ios_fallbacks) |
| 28343 |
if mac_case == non_mac_case: |
| 28344 |
return mac_case |
| 28345 |
|
| 28346 |
diff --git a/src/libANGLE/renderer/metal/mtl_buffer_pool.h b/src/libANGLE/renderer/metal/mtl_buffer_pool.h |
| 28347 |
index 2079fd7..204ebb9 100644 |
| 28348 |
--- a/src/libANGLE/renderer/metal/mtl_buffer_pool.h |
| 28349 |
+++ b/src/libANGLE/renderer/metal/mtl_buffer_pool.h |
| 28350 |
@@ -81,7 +81,7 @@ class BufferPool |
| 28351 |
bool *newBufferAllocatedOut = nullptr); |
| 28352 |
|
| 28353 |
// After a sequence of CPU writes, call commit to ensure the data is visible to the device. |
| 28354 |
- angle::Result commit(ContextMtl *contextMtl); |
| 28355 |
+ angle::Result commit(ContextMtl *contextMtl, bool flushEntireBuffer = false); |
| 28356 |
|
| 28357 |
// This releases all the buffers that have been allocated since this was last called. |
| 28358 |
void releaseInFlightBuffers(ContextMtl *contextMtl); |
| 28359 |
@@ -114,7 +114,6 @@ class BufferPool |
| 28360 |
angle::Result allocateNewBuffer(ContextMtl *contextMtl); |
| 28361 |
void destroyBufferList(ContextMtl *contextMtl, std::deque<BufferRef> *buffers); |
| 28362 |
angle::Result finalizePendingBuffer(ContextMtl *contextMtl); |
| 28363 |
- |
| 28364 |
size_t mInitialSize; |
| 28365 |
BufferRef mBuffer; |
| 28366 |
uint32_t mNextAllocationOffset; |
| 28367 |
@@ -127,7 +126,7 @@ class BufferPool |
| 28368 |
|
| 28369 |
size_t mBuffersAllocated; |
| 28370 |
size_t mMaxBuffers; |
| 28371 |
- BufferPoolMemPolicy mMemPolicy; |
| 28372 |
+ BufferPoolMemPolicy mMemPolicy = BufferPoolMemPolicy::Auto; |
| 28373 |
bool mAlwaysAllocateNewBuffer; |
| 28374 |
}; |
| 28375 |
|
| 28376 |
diff --git a/src/libANGLE/renderer/metal/mtl_buffer_pool.mm b/src/libANGLE/renderer/metal/mtl_buffer_pool.mm |
| 28377 |
index 04238ef..a58b5a5 100644 |
| 28378 |
--- a/src/libANGLE/renderer/metal/mtl_buffer_pool.mm |
| 28379 |
+++ b/src/libANGLE/renderer/metal/mtl_buffer_pool.mm |
| 28380 |
@@ -250,11 +250,18 @@ |
| 28381 |
return angle::Result::Continue; |
| 28382 |
} |
| 28383 |
|
| 28384 |
-angle::Result BufferPool::commit(ContextMtl *contextMtl) |
| 28385 |
+angle::Result BufferPool::commit(ContextMtl *contextMtl, bool flushEntireBuffer) |
| 28386 |
{ |
| 28387 |
if (mBuffer && mNextAllocationOffset > mLastFlushOffset) |
| 28388 |
+ { |
| 28389 |
+ if (flushEntireBuffer) |
| 28390 |
+ { |
| 28391 |
+ mBuffer->flush(contextMtl, 0, mLastFlushOffset); |
| 28392 |
+ } |
| 28393 |
+ else |
| 28394 |
{ |
| 28395 |
mBuffer->flush(contextMtl, mLastFlushOffset, mNextAllocationOffset - mLastFlushOffset); |
| 28396 |
+ } |
| 28397 |
mLastFlushOffset = mNextAllocationOffset; |
| 28398 |
} |
| 28399 |
return angle::Result::Continue; |
| 28400 |
diff --git a/src/libANGLE/renderer/metal/mtl_command_buffer.h b/src/libANGLE/renderer/metal/mtl_command_buffer.h |
| 28401 |
index 55ff649..3aa826a 100644 |
| 28402 |
--- a/src/libANGLE/renderer/metal/mtl_command_buffer.h |
| 28403 |
+++ b/src/libANGLE/renderer/metal/mtl_command_buffer.h |
| 28404 |
@@ -102,7 +102,7 @@ class CommandBuffer final : public WrappedObject<id<MTLCommandBuffer>>, angle::N |
| 28405 |
|
| 28406 |
// Return true if command buffer can be encoded into. Return false if it has been committed |
| 28407 |
// and hasn't been restarted. |
| 28408 |
- bool ready() const; |
| 28409 |
+ bool valid() const; |
| 28410 |
void commit(); |
| 28411 |
// wait for committed command buffer to finish. |
| 28412 |
void finish(); |
| 28413 |
@@ -115,6 +115,8 @@ class CommandBuffer final : public WrappedObject<id<MTLCommandBuffer>>, angle::N |
| 28414 |
|
| 28415 |
void queueEventSignal(const mtl::SharedEventRef &event, uint64_t value); |
| 28416 |
void serverWaitEvent(const mtl::SharedEventRef &event, uint64_t value); |
| 28417 |
+ |
| 28418 |
+ void insertDebugSign(const std::string &marker); |
| 28419 |
void pushDebugGroup(const std::string &marker); |
| 28420 |
void popDebugGroup(); |
| 28421 |
|
| 28422 |
@@ -128,7 +130,7 @@ class CommandBuffer final : public WrappedObject<id<MTLCommandBuffer>>, angle::N |
| 28423 |
void set(id<MTLCommandBuffer> metalBuffer); |
| 28424 |
void cleanup(); |
| 28425 |
|
| 28426 |
- bool readyImpl() const; |
| 28427 |
+ bool validImpl() const; |
| 28428 |
void commitImpl(); |
| 28429 |
void forceEndingCurrentEncoder(); |
| 28430 |
|
| 28431 |
@@ -149,6 +151,7 @@ class CommandBuffer final : public WrappedObject<id<MTLCommandBuffer>>, angle::N |
| 28432 |
|
| 28433 |
mutable std::mutex mLock; |
| 28434 |
|
| 28435 |
+ std::vector<std::string> mPendingDebugSigns; |
| 28436 |
std::vector<std::pair<mtl::SharedEventRef, uint64_t>> mPendingSignalEvents; |
| 28437 |
|
| 28438 |
std::vector<std::string> mDebugGroups; |
| 28439 |
@@ -176,6 +179,8 @@ class CommandEncoder : public WrappedObject<id<MTLCommandEncoder>>, angle::NonCo |
| 28440 |
CommandEncoder &markResourceBeingWrittenByGPU(const BufferRef &buffer); |
| 28441 |
CommandEncoder &markResourceBeingWrittenByGPU(const TextureRef &texture); |
| 28442 |
|
| 28443 |
+ void insertDebugSign(NSString *label); |
| 28444 |
+ |
| 28445 |
virtual void pushDebugGroup(NSString *label); |
| 28446 |
virtual void popDebugGroup(); |
| 28447 |
|
| 28448 |
@@ -189,6 +194,8 @@ class CommandEncoder : public WrappedObject<id<MTLCommandEncoder>>, angle::NonCo |
| 28449 |
|
| 28450 |
void set(id<MTLCommandEncoder> metalCmdEncoder); |
| 28451 |
|
| 28452 |
+ virtual void insertDebugSignImpl(NSString *marker); |
| 28453 |
+ |
| 28454 |
private: |
| 28455 |
const Type mType; |
| 28456 |
CommandBuffer &mCmdBuffer; |
| 28457 |
@@ -201,7 +208,7 @@ class IntermediateCommandStream |
| 28458 |
template <typename T> |
| 28459 |
inline IntermediateCommandStream &push(const T &val) |
| 28460 |
{ |
| 28461 |
- const uint8_t *ptr = reinterpret_cast<const uint8_t *>(&val); |
| 28462 |
+ auto ptr = reinterpret_cast<const uint8_t *>(&val); |
| 28463 |
mBuffer.insert(mBuffer.end(), ptr, ptr + sizeof(T)); |
| 28464 |
return *this; |
| 28465 |
} |
| 28466 |
@@ -217,7 +224,7 @@ class IntermediateCommandStream |
| 28467 |
{ |
| 28468 |
ASSERT(mReadPtr <= mBuffer.size() - sizeof(T)); |
| 28469 |
T re; |
| 28470 |
- uint8_t *ptr = reinterpret_cast<uint8_t *>(&re); |
| 28471 |
+ auto ptr = reinterpret_cast<uint8_t *>(&re); |
| 28472 |
std::copy(mBuffer.data() + mReadPtr, mBuffer.data() + mReadPtr + sizeof(T), ptr); |
| 28473 |
return re; |
| 28474 |
} |
| 28475 |
@@ -225,7 +232,7 @@ class IntermediateCommandStream |
| 28476 |
template <typename T> |
| 28477 |
inline T fetch() |
| 28478 |
{ |
| 28479 |
- T re = peek<T>(); |
| 28480 |
+ auto re = peek<T>(); |
| 28481 |
mReadPtr += sizeof(T); |
| 28482 |
return re; |
| 28483 |
} |
| 28484 |
@@ -233,7 +240,7 @@ class IntermediateCommandStream |
| 28485 |
inline const uint8_t *fetch(size_t bytes) |
| 28486 |
{ |
| 28487 |
ASSERT(mReadPtr <= mBuffer.size() - bytes); |
| 28488 |
- size_t cur = mReadPtr; |
| 28489 |
+ auto cur = mReadPtr; |
| 28490 |
mReadPtr += bytes; |
| 28491 |
return mBuffer.data() + cur; |
| 28492 |
} |
| 28493 |
@@ -479,12 +486,16 @@ class RenderCommandEncoder final : public CommandEncoder |
| 28494 |
{ |
| 28495 |
return static_cast<id<MTLRenderCommandEncoder>>(CommandEncoder::get()); |
| 28496 |
} |
| 28497 |
+ void insertDebugSignImpl(NSString *label) override; |
| 28498 |
|
| 28499 |
void initAttachmentWriteDependencyAndScissorRect(const RenderPassAttachmentDesc &attachment); |
| 28500 |
+ void initWriteDependency(const TextureRef &texture); |
| 28501 |
|
| 28502 |
void finalizeLoadStoreAction(MTLRenderPassAttachmentDescriptor *objCRenderPassAttachment); |
| 28503 |
|
| 28504 |
void encodeMetalEncoder(); |
| 28505 |
+ void simulateDiscardFramebuffer(); |
| 28506 |
+ void endEncodingImpl(bool considerDiscardSimulation); |
| 28507 |
|
| 28508 |
RenderCommandEncoder &commonSetBuffer(gl::ShaderType shaderType, |
| 28509 |
id<MTLBuffer> mtlBuffer, |
| 28510 |
@@ -560,11 +571,20 @@ class BlitCommandEncoder final : public CommandEncoder |
| 28511 |
uint32_t sliceCount, |
| 28512 |
uint32_t levelCount); |
| 28513 |
|
| 28514 |
+ BlitCommandEncoder ©Texture(const TextureRef &src, |
| 28515 |
+ uint32_t srcSlice, |
| 28516 |
+ uint32_t srcLevel, |
| 28517 |
+ const TextureRef &dst, |
| 28518 |
+ uint32_t dstSlice, |
| 28519 |
+ uint32_t dstLevel, |
| 28520 |
+ uint32_t sliceCount, |
| 28521 |
+ uint32_t levelCount); |
| 28522 |
+ |
| 28523 |
BlitCommandEncoder &fillBuffer(const BufferRef &buffer, NSRange range, uint8_t value); |
| 28524 |
|
| 28525 |
BlitCommandEncoder &generateMipmapsForTexture(const TextureRef &texture); |
| 28526 |
- BlitCommandEncoder &synchronizeResource(Buffer *bufferPtr); |
| 28527 |
- BlitCommandEncoder &synchronizeResource(Texture *texturePtr); |
| 28528 |
+ BlitCommandEncoder &synchronizeResource(const BufferRef &buffer); |
| 28529 |
+ BlitCommandEncoder &synchronizeResource(const TextureRef &texture); |
| 28530 |
|
| 28531 |
private: |
| 28532 |
id<MTLBlitCommandEncoder> get() |
| 28533 |
diff --git a/src/libANGLE/renderer/metal/mtl_command_buffer.mm b/src/libANGLE/renderer/metal/mtl_command_buffer.mm |
| 28534 |
index 4433b02..b4a3347 100644 |
| 28535 |
--- a/src/libANGLE/renderer/metal/mtl_command_buffer.mm |
| 28536 |
+++ b/src/libANGLE/renderer/metal/mtl_command_buffer.mm |
| 28537 |
@@ -11,6 +11,9 @@ |
| 28538 |
#include "libANGLE/renderer/metal/mtl_command_buffer.h" |
| 28539 |
|
| 28540 |
#include <cassert> |
| 28541 |
+#if ANGLE_MTL_SIMULATE_DISCARD_FRAMEBUFFER |
| 28542 |
+# include <random> |
| 28543 |
+#endif |
| 28544 |
|
| 28545 |
#include "common/debug.h" |
| 28546 |
#include "libANGLE/renderer/metal/mtl_occlusion_query_pool.h" |
| 28547 |
@@ -65,6 +68,7 @@ |
| 28548 |
PROC(SetVisibilityResultMode) \ |
| 28549 |
PROC(UseResource) \ |
| 28550 |
PROC(MemoryBarrierWithResource) \ |
| 28551 |
+ PROC(InsertDebugsign) \ |
| 28552 |
PROC(PushDebugGroup) \ |
| 28553 |
PROC(PopDebugGroup) |
| 28554 |
|
| 28555 |
@@ -85,42 +89,42 @@ void InvalidCmd(id<MTLRenderCommandEncoder> encoder, IntermediateCommandStream * |
| 28556 |
void SetRenderPipelineStateCmd(id<MTLRenderCommandEncoder> encoder, |
| 28557 |
IntermediateCommandStream *stream) |
| 28558 |
{ |
| 28559 |
- id<MTLRenderPipelineState> state = stream->fetch<id<MTLRenderPipelineState>>(); |
| 28560 |
+ auto state = stream->fetch<id<MTLRenderPipelineState>>(); |
| 28561 |
[encoder setRenderPipelineState:state]; |
| 28562 |
[state ANGLE_MTL_RELEASE]; |
| 28563 |
} |
| 28564 |
|
| 28565 |
void SetTriangleFillModeCmd(id<MTLRenderCommandEncoder> encoder, IntermediateCommandStream *stream) |
| 28566 |
{ |
| 28567 |
- MTLTriangleFillMode mode = stream->fetch<MTLTriangleFillMode>(); |
| 28568 |
+ auto mode = stream->fetch<MTLTriangleFillMode>(); |
| 28569 |
[encoder setTriangleFillMode:mode]; |
| 28570 |
} |
| 28571 |
|
| 28572 |
void SetFrontFacingWindingCmd(id<MTLRenderCommandEncoder> encoder, |
| 28573 |
IntermediateCommandStream *stream) |
| 28574 |
{ |
| 28575 |
- MTLWinding winding = stream->fetch<MTLWinding>(); |
| 28576 |
+ auto winding = stream->fetch<MTLWinding>(); |
| 28577 |
[encoder setFrontFacingWinding:winding]; |
| 28578 |
} |
| 28579 |
|
| 28580 |
void SetCullModeCmd(id<MTLRenderCommandEncoder> encoder, IntermediateCommandStream *stream) |
| 28581 |
{ |
| 28582 |
- MTLCullMode mode = stream->fetch<MTLCullMode>(); |
| 28583 |
+ auto mode = stream->fetch<MTLCullMode>(); |
| 28584 |
[encoder setCullMode:mode]; |
| 28585 |
} |
| 28586 |
|
| 28587 |
void SetDepthStencilStateCmd(id<MTLRenderCommandEncoder> encoder, IntermediateCommandStream *stream) |
| 28588 |
{ |
| 28589 |
- id<MTLDepthStencilState> state = stream->fetch<id<MTLDepthStencilState>>(); |
| 28590 |
+ auto state = stream->fetch<id<MTLDepthStencilState>>(); |
| 28591 |
[encoder setDepthStencilState:state]; |
| 28592 |
[state ANGLE_MTL_RELEASE]; |
| 28593 |
} |
| 28594 |
|
| 28595 |
void SetDepthBiasCmd(id<MTLRenderCommandEncoder> encoder, IntermediateCommandStream *stream) |
| 28596 |
{ |
| 28597 |
- float depthBias = stream->fetch<float>(); |
| 28598 |
- float slopeScale = stream->fetch<float>(); |
| 28599 |
- float clamp = stream->fetch<float>(); |
| 28600 |
+ auto depthBias = stream->fetch<float>(); |
| 28601 |
+ auto slopeScale = stream->fetch<float>(); |
| 28602 |
+ auto clamp = stream->fetch<float>(); |
| 28603 |
[encoder setDepthBias:depthBias slopeScale:slopeScale clamp:clamp]; |
| 28604 |
} |
| 28605 |
|
| 28606 |
@@ -134,13 +138,13 @@ void SetStencilRefValsCmd(id<MTLRenderCommandEncoder> encoder, IntermediateComma |
| 28607 |
|
| 28608 |
void SetViewportCmd(id<MTLRenderCommandEncoder> encoder, IntermediateCommandStream *stream) |
| 28609 |
{ |
| 28610 |
- MTLViewport viewport = stream->fetch<MTLViewport>(); |
| 28611 |
+ auto viewport = stream->fetch<MTLViewport>(); |
| 28612 |
[encoder setViewport:viewport]; |
| 28613 |
} |
| 28614 |
|
| 28615 |
void SetScissorRectCmd(id<MTLRenderCommandEncoder> encoder, IntermediateCommandStream *stream) |
| 28616 |
{ |
| 28617 |
- MTLScissorRect rect = stream->fetch<MTLScissorRect>(); |
| 28618 |
+ auto rect = stream->fetch<MTLScissorRect>(); |
| 28619 |
[encoder setScissorRect:rect]; |
| 28620 |
} |
| 28621 |
|
| 28622 |
@@ -155,9 +159,9 @@ void SetBlendColorCmd(id<MTLRenderCommandEncoder> encoder, IntermediateCommandSt |
| 28623 |
|
| 28624 |
void SetVertexBufferCmd(id<MTLRenderCommandEncoder> encoder, IntermediateCommandStream *stream) |
| 28625 |
{ |
| 28626 |
- id<MTLBuffer> buffer = stream->fetch<id<MTLBuffer>>(); |
| 28627 |
- uint32_t offset = stream->fetch<uint32_t>(); |
| 28628 |
- uint32_t index = stream->fetch<uint32_t>(); |
| 28629 |
+ auto buffer = stream->fetch<id<MTLBuffer>>(); |
| 28630 |
+ auto offset = stream->fetch<uint32_t>(); |
| 28631 |
+ auto index = stream->fetch<uint32_t>(); |
| 28632 |
[encoder setVertexBuffer:buffer offset:offset atIndex:index]; |
| 28633 |
[buffer ANGLE_MTL_RELEASE]; |
| 28634 |
} |
| 28635 |
@@ -165,26 +169,26 @@ void SetVertexBufferCmd(id<MTLRenderCommandEncoder> encoder, IntermediateCommand |
| 28636 |
void SetVertexBufferOffsetCmd(id<MTLRenderCommandEncoder> encoder, |
| 28637 |
IntermediateCommandStream *stream) |
| 28638 |
{ |
| 28639 |
- uint32_t offset = stream->fetch<uint32_t>(); |
| 28640 |
- uint32_t index = stream->fetch<uint32_t>(); |
| 28641 |
+ auto offset = stream->fetch<uint32_t>(); |
| 28642 |
+ auto index = stream->fetch<uint32_t>(); |
| 28643 |
[encoder setVertexBufferOffset:offset atIndex:index]; |
| 28644 |
} |
| 28645 |
|
| 28646 |
void SetVertexBytesCmd(id<MTLRenderCommandEncoder> encoder, IntermediateCommandStream *stream) |
| 28647 |
{ |
| 28648 |
- size_t size = stream->fetch<size_t>(); |
| 28649 |
- const uint8_t *bytes = stream->fetch(size); |
| 28650 |
- uint32_t index = stream->fetch<uint32_t>(); |
| 28651 |
+ auto size = stream->fetch<size_t>(); |
| 28652 |
+ auto bytes = stream->fetch(size); |
| 28653 |
+ auto index = stream->fetch<uint32_t>(); |
| 28654 |
[encoder setVertexBytes:bytes length:size atIndex:index]; |
| 28655 |
} |
| 28656 |
|
| 28657 |
void SetVertexSamplerStateCmd(id<MTLRenderCommandEncoder> encoder, |
| 28658 |
IntermediateCommandStream *stream) |
| 28659 |
{ |
| 28660 |
- id<MTLSamplerState> state = stream->fetch<id<MTLSamplerState>>(); |
| 28661 |
+ auto state = stream->fetch<id<MTLSamplerState>>(); |
| 28662 |
float lodMinClamp = stream->fetch<float>(); |
| 28663 |
float lodMaxClamp = stream->fetch<float>(); |
| 28664 |
- uint32_t index = stream->fetch<uint32_t>(); |
| 28665 |
+ auto index = stream->fetch<uint32_t>(); |
| 28666 |
[encoder setVertexSamplerState:state |
| 28667 |
lodMinClamp:lodMinClamp |
| 28668 |
lodMaxClamp:lodMaxClamp |
| 28669 |
@@ -195,17 +199,17 @@ void SetVertexSamplerStateCmd(id<MTLRenderCommandEncoder> encoder, |
| 28670 |
|
| 28671 |
void SetVertexTextureCmd(id<MTLRenderCommandEncoder> encoder, IntermediateCommandStream *stream) |
| 28672 |
{ |
| 28673 |
- id<MTLTexture> texture = stream->fetch<id<MTLTexture>>(); |
| 28674 |
- uint32_t index = stream->fetch<uint32_t>(); |
| 28675 |
+ auto texture = stream->fetch<id<MTLTexture>>(); |
| 28676 |
+ auto index = stream->fetch<uint32_t>(); |
| 28677 |
[encoder setVertexTexture:texture atIndex:index]; |
| 28678 |
[texture ANGLE_MTL_RELEASE]; |
| 28679 |
} |
| 28680 |
|
| 28681 |
void SetFragmentBufferCmd(id<MTLRenderCommandEncoder> encoder, IntermediateCommandStream *stream) |
| 28682 |
{ |
| 28683 |
- id<MTLBuffer> buffer = stream->fetch<id<MTLBuffer>>(); |
| 28684 |
- uint32_t offset = stream->fetch<uint32_t>(); |
| 28685 |
- uint32_t index = stream->fetch<uint32_t>(); |
| 28686 |
+ auto buffer = stream->fetch<id<MTLBuffer>>(); |
| 28687 |
+ auto offset = stream->fetch<uint32_t>(); |
| 28688 |
+ auto index = stream->fetch<uint32_t>(); |
| 28689 |
[encoder setFragmentBuffer:buffer offset:offset atIndex:index]; |
| 28690 |
[buffer ANGLE_MTL_RELEASE]; |
| 28691 |
} |
| 28692 |
@@ -213,26 +217,26 @@ void SetFragmentBufferCmd(id<MTLRenderCommandEncoder> encoder, IntermediateComma |
| 28693 |
void SetFragmentBufferOffsetCmd(id<MTLRenderCommandEncoder> encoder, |
| 28694 |
IntermediateCommandStream *stream) |
| 28695 |
{ |
| 28696 |
- uint32_t offset = stream->fetch<uint32_t>(); |
| 28697 |
- uint32_t index = stream->fetch<uint32_t>(); |
| 28698 |
+ auto offset = stream->fetch<uint32_t>(); |
| 28699 |
+ auto index = stream->fetch<uint32_t>(); |
| 28700 |
[encoder setFragmentBufferOffset:offset atIndex:index]; |
| 28701 |
} |
| 28702 |
|
| 28703 |
void SetFragmentBytesCmd(id<MTLRenderCommandEncoder> encoder, IntermediateCommandStream *stream) |
| 28704 |
{ |
| 28705 |
- size_t size = stream->fetch<size_t>(); |
| 28706 |
- const uint8_t *bytes = stream->fetch(size); |
| 28707 |
- uint32_t index = stream->fetch<uint32_t>(); |
| 28708 |
+ auto size = stream->fetch<size_t>(); |
| 28709 |
+ auto bytes = stream->fetch(size); |
| 28710 |
+ auto index = stream->fetch<uint32_t>(); |
| 28711 |
[encoder setFragmentBytes:bytes length:size atIndex:index]; |
| 28712 |
} |
| 28713 |
|
| 28714 |
void SetFragmentSamplerStateCmd(id<MTLRenderCommandEncoder> encoder, |
| 28715 |
IntermediateCommandStream *stream) |
| 28716 |
{ |
| 28717 |
- id<MTLSamplerState> state = stream->fetch<id<MTLSamplerState>>(); |
| 28718 |
+ auto state = stream->fetch<id<MTLSamplerState>>(); |
| 28719 |
float lodMinClamp = stream->fetch<float>(); |
| 28720 |
float lodMaxClamp = stream->fetch<float>(); |
| 28721 |
- uint32_t index = stream->fetch<uint32_t>(); |
| 28722 |
+ auto index = stream->fetch<uint32_t>(); |
| 28723 |
[encoder setFragmentSamplerState:state |
| 28724 |
lodMinClamp:lodMinClamp |
| 28725 |
lodMaxClamp:lodMaxClamp |
| 28726 |
@@ -242,26 +246,26 @@ void SetFragmentSamplerStateCmd(id<MTLRenderCommandEncoder> encoder, |
| 28727 |
|
| 28728 |
void SetFragmentTextureCmd(id<MTLRenderCommandEncoder> encoder, IntermediateCommandStream *stream) |
| 28729 |
{ |
| 28730 |
- id<MTLTexture> texture = stream->fetch<id<MTLTexture>>(); |
| 28731 |
- uint32_t index = stream->fetch<uint32_t>(); |
| 28732 |
+ auto texture = stream->fetch<id<MTLTexture>>(); |
| 28733 |
+ auto index = stream->fetch<uint32_t>(); |
| 28734 |
[encoder setFragmentTexture:texture atIndex:index]; |
| 28735 |
[texture ANGLE_MTL_RELEASE]; |
| 28736 |
} |
| 28737 |
|
| 28738 |
void DrawCmd(id<MTLRenderCommandEncoder> encoder, IntermediateCommandStream *stream) |
| 28739 |
{ |
| 28740 |
- MTLPrimitiveType primitiveType = stream->fetch<MTLPrimitiveType>(); |
| 28741 |
- uint32_t vertexStart = stream->fetch<uint32_t>(); |
| 28742 |
- uint32_t vertexCount = stream->fetch<uint32_t>(); |
| 28743 |
+ auto primitiveType = stream->fetch<MTLPrimitiveType>(); |
| 28744 |
+ auto vertexStart = stream->fetch<uint32_t>(); |
| 28745 |
+ auto vertexCount = stream->fetch<uint32_t>(); |
| 28746 |
[encoder drawPrimitives:primitiveType vertexStart:vertexStart vertexCount:vertexCount]; |
| 28747 |
} |
| 28748 |
|
| 28749 |
void DrawInstancedCmd(id<MTLRenderCommandEncoder> encoder, IntermediateCommandStream *stream) |
| 28750 |
{ |
| 28751 |
- MTLPrimitiveType primitiveType = stream->fetch<MTLPrimitiveType>(); |
| 28752 |
- uint32_t vertexStart = stream->fetch<uint32_t>(); |
| 28753 |
- uint32_t vertexCount = stream->fetch<uint32_t>(); |
| 28754 |
- uint32_t instances = stream->fetch<uint32_t>(); |
| 28755 |
+ auto primitiveType = stream->fetch<MTLPrimitiveType>(); |
| 28756 |
+ auto vertexStart = stream->fetch<uint32_t>(); |
| 28757 |
+ auto vertexCount = stream->fetch<uint32_t>(); |
| 28758 |
+ auto instances = stream->fetch<uint32_t>(); |
| 28759 |
[encoder drawPrimitives:primitiveType |
| 28760 |
vertexStart:vertexStart |
| 28761 |
vertexCount:vertexCount |
| 28762 |
@@ -270,11 +274,11 @@ void DrawInstancedCmd(id<MTLRenderCommandEncoder> encoder, IntermediateCommandSt |
| 28763 |
|
| 28764 |
void DrawIndexedCmd(id<MTLRenderCommandEncoder> encoder, IntermediateCommandStream *stream) |
| 28765 |
{ |
| 28766 |
- MTLPrimitiveType primitiveType = stream->fetch<MTLPrimitiveType>(); |
| 28767 |
- uint32_t indexCount = stream->fetch<uint32_t>(); |
| 28768 |
- MTLIndexType indexType = stream->fetch<MTLIndexType>(); |
| 28769 |
- id<MTLBuffer> indexBuffer = stream->fetch<id<MTLBuffer>>(); |
| 28770 |
- size_t bufferOffset = stream->fetch<size_t>(); |
| 28771 |
+ auto primitiveType = stream->fetch<MTLPrimitiveType>(); |
| 28772 |
+ auto indexCount = stream->fetch<uint32_t>(); |
| 28773 |
+ auto indexType = stream->fetch<MTLIndexType>(); |
| 28774 |
+ auto indexBuffer = stream->fetch<id<MTLBuffer>>(); |
| 28775 |
+ auto bufferOffset = stream->fetch<size_t>(); |
| 28776 |
[encoder drawIndexedPrimitives:primitiveType |
| 28777 |
indexCount:indexCount |
| 28778 |
indexType:indexType |
| 28779 |
@@ -285,12 +289,12 @@ void DrawIndexedCmd(id<MTLRenderCommandEncoder> encoder, IntermediateCommandStre |
| 28780 |
|
| 28781 |
void DrawIndexedInstancedCmd(id<MTLRenderCommandEncoder> encoder, IntermediateCommandStream *stream) |
| 28782 |
{ |
| 28783 |
- MTLPrimitiveType primitiveType = stream->fetch<MTLPrimitiveType>(); |
| 28784 |
- uint32_t indexCount = stream->fetch<uint32_t>(); |
| 28785 |
- MTLIndexType indexType = stream->fetch<MTLIndexType>(); |
| 28786 |
- id<MTLBuffer> indexBuffer = stream->fetch<id<MTLBuffer>>(); |
| 28787 |
- size_t bufferOffset = stream->fetch<size_t>(); |
| 28788 |
- uint32_t instances = stream->fetch<uint32_t>(); |
| 28789 |
+ auto primitiveType = stream->fetch<MTLPrimitiveType>(); |
| 28790 |
+ auto indexCount = stream->fetch<uint32_t>(); |
| 28791 |
+ auto indexType = stream->fetch<MTLIndexType>(); |
| 28792 |
+ auto indexBuffer = stream->fetch<id<MTLBuffer>>(); |
| 28793 |
+ auto bufferOffset = stream->fetch<size_t>(); |
| 28794 |
+ auto instances = stream->fetch<uint32_t>(); |
| 28795 |
[encoder drawIndexedPrimitives:primitiveType |
| 28796 |
indexCount:indexCount |
| 28797 |
indexType:indexType |
| 28798 |
@@ -303,13 +307,13 @@ void DrawIndexedInstancedCmd(id<MTLRenderCommandEncoder> encoder, IntermediateCo |
| 28799 |
void DrawIndexedInstancedBaseVertexCmd(id<MTLRenderCommandEncoder> encoder, |
| 28800 |
IntermediateCommandStream *stream) |
| 28801 |
{ |
| 28802 |
- MTLPrimitiveType primitiveType = stream->fetch<MTLPrimitiveType>(); |
| 28803 |
- uint32_t indexCount = stream->fetch<uint32_t>(); |
| 28804 |
- MTLIndexType indexType = stream->fetch<MTLIndexType>(); |
| 28805 |
- id<MTLBuffer> indexBuffer = stream->fetch<id<MTLBuffer>>(); |
| 28806 |
- size_t bufferOffset = stream->fetch<size_t>(); |
| 28807 |
- uint32_t instances = stream->fetch<uint32_t>(); |
| 28808 |
- uint32_t baseVertex = stream->fetch<uint32_t>(); |
| 28809 |
+ auto primitiveType = stream->fetch<MTLPrimitiveType>(); |
| 28810 |
+ auto indexCount = stream->fetch<uint32_t>(); |
| 28811 |
+ auto indexType = stream->fetch<MTLIndexType>(); |
| 28812 |
+ auto indexBuffer = stream->fetch<id<MTLBuffer>>(); |
| 28813 |
+ auto bufferOffset = stream->fetch<size_t>(); |
| 28814 |
+ auto instances = stream->fetch<uint32_t>(); |
| 28815 |
+ auto baseVertex = stream->fetch<uint32_t>(); |
| 28816 |
[encoder drawIndexedPrimitives:primitiveType |
| 28817 |
indexCount:indexCount |
| 28818 |
indexType:indexType |
| 28819 |
@@ -324,16 +328,16 @@ void DrawIndexedInstancedBaseVertexCmd(id<MTLRenderCommandEncoder> encoder, |
| 28820 |
void SetVisibilityResultModeCmd(id<MTLRenderCommandEncoder> encoder, |
| 28821 |
IntermediateCommandStream *stream) |
| 28822 |
{ |
| 28823 |
- MTLVisibilityResultMode mode = stream->fetch<MTLVisibilityResultMode>(); |
| 28824 |
- size_t offset = stream->fetch<size_t>(); |
| 28825 |
+ auto mode = stream->fetch<MTLVisibilityResultMode>(); |
| 28826 |
+ auto offset = stream->fetch<size_t>(); |
| 28827 |
[encoder setVisibilityResultMode:mode offset:offset]; |
| 28828 |
} |
| 28829 |
|
| 28830 |
void UseResourceCmd(id<MTLRenderCommandEncoder> encoder, IntermediateCommandStream *stream) |
| 28831 |
{ |
| 28832 |
- id<MTLResource> resource = stream->fetch<id<MTLResource>>(); |
| 28833 |
- MTLResourceUsage usage = stream->fetch<MTLResourceUsage>(); |
| 28834 |
- mtl::RenderStages stages = stream->fetch<mtl::RenderStages>(); |
| 28835 |
+ auto resource = stream->fetch<id<MTLResource>>(); |
| 28836 |
+ auto usage = stream->fetch<MTLResourceUsage>(); |
| 28837 |
+ auto stages = stream->fetch<mtl::RenderStages>(); |
| 28838 |
ANGLE_UNUSED_VARIABLE(stages); |
| 28839 |
#if defined(__IPHONE_13_0) || defined(__MAC_10_15) |
| 28840 |
if (ANGLE_APPLE_AVAILABLE_XCI(10.15, 13.0, 13.0)) |
| 28841 |
@@ -351,9 +355,9 @@ void UseResourceCmd(id<MTLRenderCommandEncoder> encoder, IntermediateCommandStre |
| 28842 |
void MemoryBarrierWithResourceCmd(id<MTLRenderCommandEncoder> encoder, |
| 28843 |
IntermediateCommandStream *stream) |
| 28844 |
{ |
| 28845 |
- id<MTLResource> resource = stream->fetch<id<MTLResource>>(); |
| 28846 |
- mtl::RenderStages after = stream->fetch<mtl::RenderStages>(); |
| 28847 |
- mtl::RenderStages before = stream->fetch<mtl::RenderStages>(); |
| 28848 |
+ auto resource = stream->fetch<id<MTLResource>>(); |
| 28849 |
+ auto after = stream->fetch<mtl::RenderStages>(); |
| 28850 |
+ auto before = stream->fetch<mtl::RenderStages>(); |
| 28851 |
ANGLE_UNUSED_VARIABLE(after); |
| 28852 |
ANGLE_UNUSED_VARIABLE(before); |
| 28853 |
#if defined(__MAC_10_14) && (TARGET_OS_OSX || TARGET_OS_MACCATALYST) |
| 28854 |
@@ -368,9 +372,16 @@ void MemoryBarrierWithResourceCmd(id<MTLRenderCommandEncoder> encoder, |
| 28855 |
[resource ANGLE_MTL_RELEASE]; |
| 28856 |
} |
| 28857 |
|
| 28858 |
+void InsertDebugsignCmd(id<MTLRenderCommandEncoder> encoder, IntermediateCommandStream *stream) |
| 28859 |
+{ |
| 28860 |
+ auto label = stream->fetch<NSString *>(); |
| 28861 |
+ [encoder insertDebugSignpost:label]; |
| 28862 |
+ [label ANGLE_MTL_RELEASE]; |
| 28863 |
+} |
| 28864 |
+ |
| 28865 |
void PushDebugGroupCmd(id<MTLRenderCommandEncoder> encoder, IntermediateCommandStream *stream) |
| 28866 |
{ |
| 28867 |
- NSString *label = stream->fetch<NSString *>(); |
| 28868 |
+ auto label = stream->fetch<NSString *>(); |
| 28869 |
[encoder pushDebugGroup:label]; |
| 28870 |
[label ANGLE_MTL_RELEASE]; |
| 28871 |
} |
| 28872 |
@@ -388,7 +399,7 @@ void PopDebugGroupCmd(id<MTLRenderCommandEncoder> encoder, IntermediateCommandSt |
| 28873 |
|
| 28874 |
NSString *cppLabelToObjC(const std::string &marker) |
| 28875 |
{ |
| 28876 |
- NSString *label = [NSString stringWithUTF8String:marker.c_str()]; |
| 28877 |
+ auto label = [NSString stringWithUTF8String:marker.c_str()]; |
| 28878 |
if (!label) |
| 28879 |
{ |
| 28880 |
// This can happen if the string is not a valid ascii string. |
| 28881 |
@@ -396,7 +407,6 @@ void PopDebugGroupCmd(id<MTLRenderCommandEncoder> encoder, IntermediateCommandSt |
| 28882 |
} |
| 28883 |
return label; |
| 28884 |
} |
| 28885 |
- |
| 28886 |
} |
| 28887 |
|
| 28888 |
// CommandQueue implementation |
| 28889 |
@@ -565,11 +575,11 @@ void PopDebugGroupCmd(id<MTLRenderCommandEncoder> encoder, IntermediateCommandSt |
| 28890 |
cleanup(); |
| 28891 |
} |
| 28892 |
|
| 28893 |
-bool CommandBuffer::ready() const |
| 28894 |
+bool CommandBuffer::valid() const |
| 28895 |
{ |
| 28896 |
std::lock_guard<std::mutex> lg(mLock); |
| 28897 |
|
| 28898 |
- return readyImpl(); |
| 28899 |
+ return validImpl(); |
| 28900 |
} |
| 28901 |
|
| 28902 |
void CommandBuffer::commit() |
| 28903 |
@@ -598,7 +608,7 @@ void PopDebugGroupCmd(id<MTLRenderCommandEncoder> encoder, IntermediateCommandSt |
| 28904 |
|
| 28905 |
std::lock_guard<std::mutex> lg(mLock); |
| 28906 |
|
| 28907 |
- if (!readyImpl()) |
| 28908 |
+ if (!validImpl()) |
| 28909 |
{ |
| 28910 |
return; |
| 28911 |
} |
| 28912 |
@@ -620,7 +630,7 @@ void PopDebugGroupCmd(id<MTLRenderCommandEncoder> encoder, IntermediateCommandSt |
| 28913 |
|
| 28914 |
std::lock_guard<std::mutex> lg(mLock); |
| 28915 |
|
| 28916 |
- if (!readyImpl()) |
| 28917 |
+ if (!validImpl()) |
| 28918 |
{ |
| 28919 |
return; |
| 28920 |
} |
| 28921 |
@@ -647,57 +657,57 @@ void PopDebugGroupCmd(id<MTLRenderCommandEncoder> encoder, IntermediateCommandSt |
| 28922 |
ASSERT(metalCmdBuffer); |
| 28923 |
} |
| 28924 |
|
| 28925 |
-void CommandBuffer::queueEventSignal(const mtl::SharedEventRef &event, uint64_t value) |
| 28926 |
+void CommandBuffer::insertDebugSign(const std::string &marker) |
| 28927 |
{ |
| 28928 |
- std::lock_guard<std::mutex> lg(mLock); |
| 28929 |
- |
| 28930 |
- ASSERT(readyImpl()); |
| 28931 |
- |
| 28932 |
- if (mActiveCommandEncoder && mActiveCommandEncoder->getType() == CommandEncoder::RENDER) |
| 28933 |
+ mtl::CommandEncoder *currentEncoder = mActiveCommandEncoder; |
| 28934 |
+ if (currentEncoder) |
| 28935 |
{ |
| 28936 |
- // We cannot set event when there is an active render pass, defer the setting until the |
| 28937 |
- // pass end. |
| 28938 |
- mPendingSignalEvents.push_back({event, value}); |
| 28939 |
+ ANGLE_MTL_OBJC_SCOPE |
| 28940 |
+ { |
| 28941 |
+ auto label = cppLabelToObjC(marker); |
| 28942 |
+ currentEncoder->insertDebugSign(label); |
| 28943 |
+ } |
| 28944 |
} |
| 28945 |
else |
| 28946 |
{ |
| 28947 |
- setEventImpl(event, value); |
| 28948 |
+ mPendingDebugSigns.push_back(marker); |
| 28949 |
} |
| 28950 |
} |
| 28951 |
|
| 28952 |
-void CommandBuffer::serverWaitEvent(const mtl::SharedEventRef &event, uint64_t value) |
| 28953 |
+void CommandBuffer::pushDebugGroup(const std::string &marker) |
| 28954 |
{ |
| 28955 |
- std::lock_guard<std::mutex> lg(mLock); |
| 28956 |
- ASSERT(readyImpl()); |
| 28957 |
- |
| 28958 |
- waitEventImpl(event, value); |
| 28959 |
+ // NOTE(hqle): to implement this |
| 28960 |
} |
| 28961 |
|
| 28962 |
-void CommandBuffer::pushDebugGroup(const std::string &marker) |
| 28963 |
+void CommandBuffer::popDebugGroup() |
| 28964 |
{ |
| 28965 |
- mDebugGroups.push_back(marker); |
| 28966 |
+ // NOTE(hqle): to implement this |
| 28967 |
+} |
| 28968 |
|
| 28969 |
+void CommandBuffer::queueEventSignal(const mtl::SharedEventRef &event, uint64_t value) |
| 28970 |
+{ |
| 28971 |
std::lock_guard<std::mutex> lg(mLock); |
| 28972 |
|
| 28973 |
- if (readyImpl()) |
| 28974 |
+ ASSERT(validImpl()); |
| 28975 |
+ |
| 28976 |
+ if (mActiveCommandEncoder && mActiveCommandEncoder->getType() == CommandEncoder::RENDER) |
| 28977 |
{ |
| 28978 |
- pushDebugGroupImpl(marker); |
| 28979 |
+ // We cannot set event when there is an active render pass, defer the setting until the |
| 28980 |
+ // pass end. |
| 28981 |
+ mPendingSignalEvents.push_back({event, value}); |
| 28982 |
} |
| 28983 |
-} |
| 28984 |
- |
| 28985 |
-void CommandBuffer::popDebugGroup() |
| 28986 |
-{ |
| 28987 |
- if (!mDebugGroups.empty()) |
| 28988 |
+ else |
| 28989 |
{ |
| 28990 |
- mDebugGroups.pop_back(); |
| 28991 |
+ setEventImpl(event, value); |
| 28992 |
} |
| 28993 |
+} |
| 28994 |
|
| 28995 |
+void CommandBuffer::serverWaitEvent(const mtl::SharedEventRef &event, uint64_t value) |
| 28996 |
+{ |
| 28997 |
std::lock_guard<std::mutex> lg(mLock); |
| 28998 |
+ ASSERT(validImpl()); |
| 28999 |
|
| 29000 |
- if (readyImpl()) |
| 29001 |
- { |
| 29002 |
- return; |
| 29003 |
- } |
| 29004 |
+ waitEventImpl(event, value); |
| 29005 |
} |
| 29006 |
|
| 29007 |
/** private use only */ |
| 29008 |
@@ -709,6 +719,15 @@ void PopDebugGroupCmd(id<MTLRenderCommandEncoder> encoder, IntermediateCommandSt |
| 29009 |
void CommandBuffer::setActiveCommandEncoder(CommandEncoder *encoder) |
| 29010 |
{ |
| 29011 |
mActiveCommandEncoder = encoder; |
| 29012 |
+ for (auto &marker : mPendingDebugSigns) |
| 29013 |
+ { |
| 29014 |
+ ANGLE_MTL_OBJC_SCOPE |
| 29015 |
+ { |
| 29016 |
+ auto label = cppLabelToObjC(marker); |
| 29017 |
+ encoder->insertDebugSign(label); |
| 29018 |
+ } |
| 29019 |
+ } |
| 29020 |
+ mPendingDebugSigns.clear(); |
| 29021 |
} |
| 29022 |
|
| 29023 |
void CommandBuffer::invalidateActiveCommandEncoder(CommandEncoder *encoder) |
| 29024 |
@@ -729,7 +748,7 @@ void PopDebugGroupCmd(id<MTLRenderCommandEncoder> encoder, IntermediateCommandSt |
| 29025 |
ParentClass::set(nil); |
| 29026 |
} |
| 29027 |
|
| 29028 |
-bool CommandBuffer::readyImpl() const |
| 29029 |
+bool CommandBuffer::validImpl() const |
| 29030 |
{ |
| 29031 |
if (!ParentClass::valid()) |
| 29032 |
{ |
| 29033 |
@@ -741,7 +760,7 @@ void PopDebugGroupCmd(id<MTLRenderCommandEncoder> encoder, IntermediateCommandSt |
| 29034 |
|
| 29035 |
void CommandBuffer::commitImpl() |
| 29036 |
{ |
| 29037 |
- if (!readyImpl()) |
| 29038 |
+ if (!validImpl()) |
| 29039 |
{ |
| 29040 |
return; |
| 29041 |
} |
| 29042 |
@@ -889,6 +908,17 @@ void PopDebugGroupCmd(id<MTLRenderCommandEncoder> encoder, IntermediateCommandSt |
| 29043 |
[get() popDebugGroup]; |
| 29044 |
} |
| 29045 |
|
| 29046 |
+void CommandEncoder::insertDebugSign(NSString *label) |
| 29047 |
+{ |
| 29048 |
+ insertDebugSignImpl(label); |
| 29049 |
+} |
| 29050 |
+ |
| 29051 |
+void CommandEncoder::insertDebugSignImpl(NSString *label) |
| 29052 |
+{ |
| 29053 |
+ // Default implementation |
| 29054 |
+ [get() insertDebugSignpost:label]; |
| 29055 |
+} |
| 29056 |
+ |
| 29057 |
// RenderCommandEncoderShaderStates implementation |
| 29058 |
RenderCommandEncoderShaderStates::RenderCommandEncoderShaderStates() |
| 29059 |
{ |
| 29060 |
@@ -951,6 +981,9 @@ void PopDebugGroupCmd(id<MTLRenderCommandEncoder> encoder, IntermediateCommandSt |
| 29061 |
{ |
| 29062 |
shaderStates.reset(); |
| 29063 |
} |
| 29064 |
+ |
| 29065 |
+ visibilityResultMode = MTLVisibilityResultModeDisabled; |
| 29066 |
+ visibilityResultBufferOffset = 0; |
| 29067 |
} |
| 29068 |
|
| 29069 |
// RenderCommandEncoder implemtation |
| 29070 |
@@ -1014,11 +1047,12 @@ void PopDebugGroupCmd(id<MTLRenderCommandEncoder> encoder, IntermediateCommandSt |
| 29071 |
{ |
| 29072 |
if (objCRenderPassAttachment.storeAction == MTLStoreActionStore) |
| 29073 |
{ |
| 29074 |
- // NOTE(hqle): Currently if the store action with implicit MS texture is |
| 29075 |
- // MTLStoreActionStore, it is automatically convert to store and resolve action. It |
| 29076 |
- // might introduce unnecessary overhead. Consider an improvement such as only store the |
| 29077 |
- // MS texture, and resolve only at the end of real render pass (not render pass the is |
| 29078 |
- // interrupted by compute pass) or before glBlitFramebuffer operation starts. |
| 29079 |
+ // NOTE(hqle): Currently if the store action with implicit MS texture is MTLStoreAction, |
| 29080 |
+ // it is automatically convert to store and resolve action. It might introduce |
| 29081 |
+ // unnecessary overhead. |
| 29082 |
+ // Consider an improvement such as only store the MS texture, and resolve only at |
| 29083 |
+ // the end of real render pass (not render pass the was interrupted by compute pass) |
| 29084 |
+ // or before glBlitFramebuffer operation starts. |
| 29085 |
objCRenderPassAttachment.storeAction = MTLStoreActionStoreAndMultisampleResolve; |
| 29086 |
} |
| 29087 |
else if (objCRenderPassAttachment.storeAction == MTLStoreActionDontCare) |
| 29088 |
@@ -1036,6 +1070,11 @@ void PopDebugGroupCmd(id<MTLRenderCommandEncoder> encoder, IntermediateCommandSt |
| 29089 |
} |
| 29090 |
|
| 29091 |
void RenderCommandEncoder::endEncoding() |
| 29092 |
+{ |
| 29093 |
+ endEncodingImpl(true); |
| 29094 |
+} |
| 29095 |
+ |
| 29096 |
+void RenderCommandEncoder::endEncodingImpl(bool considerDiscardSimulation) |
| 29097 |
{ |
| 29098 |
if (!valid()) |
| 29099 |
return; |
| 29100 |
@@ -1050,11 +1089,11 @@ void PopDebugGroupCmd(id<MTLRenderCommandEncoder> encoder, IntermediateCommandSt |
| 29101 |
finalizeLoadStoreAction(objCRenderPassDesc.colorAttachments[i]); |
| 29102 |
} |
| 29103 |
|
| 29104 |
- // Update depth store action set between restart() and endEncoding() |
| 29105 |
+ // Update store action set between restart() and endEncoding() |
| 29106 |
objCRenderPassDesc.depthAttachment.storeAction = mRenderPassDesc.depthAttachment.storeAction; |
| 29107 |
finalizeLoadStoreAction(objCRenderPassDesc.depthAttachment); |
| 29108 |
|
| 29109 |
- // Update stencil store action set between restart() and endEncoding() |
| 29110 |
+ // Update store action set between restart() and endEncoding() |
| 29111 |
objCRenderPassDesc.stencilAttachment.storeAction = |
| 29112 |
mRenderPassDesc.stencilAttachment.storeAction; |
| 29113 |
finalizeLoadStoreAction(objCRenderPassDesc.stencilAttachment); |
| 29114 |
@@ -1075,26 +1114,78 @@ void PopDebugGroupCmd(id<MTLRenderCommandEncoder> encoder, IntermediateCommandSt |
| 29115 |
|
| 29116 |
CommandEncoder::endEncoding(); |
| 29117 |
|
| 29118 |
+#if ANGLE_MTL_SIMULATE_DISCARD_FRAMEBUFFER |
| 29119 |
+ if (considerDiscardSimulation) |
| 29120 |
+ { |
| 29121 |
+ simulateDiscardFramebuffer(); |
| 29122 |
+ } |
| 29123 |
+#endif |
| 29124 |
+ |
| 29125 |
// reset state |
| 29126 |
mRenderPassDesc = RenderPassDesc(); |
| 29127 |
mStateCache.reset(); |
| 29128 |
} |
| 29129 |
|
| 29130 |
-inline void RenderCommandEncoder::initAttachmentWriteDependencyAndScissorRect( |
| 29131 |
- const RenderPassAttachmentDesc &attachment) |
| 29132 |
+inline void RenderCommandEncoder::initWriteDependency(const TextureRef &texture) |
| 29133 |
{ |
| 29134 |
- TextureRef texture = attachment.texture; |
| 29135 |
if (texture) |
| 29136 |
{ |
| 29137 |
cmdBuffer().setWriteDependency(texture); |
| 29138 |
+ } |
| 29139 |
+} |
| 29140 |
+ |
| 29141 |
+void RenderCommandEncoder::simulateDiscardFramebuffer() |
| 29142 |
+{ |
| 29143 |
+ // Simulate true framebuffer discard operation by clearing the framebuffer |
| 29144 |
+#if ANGLE_MTL_SIMULATE_DISCARD_FRAMEBUFFER |
| 29145 |
+ std::random_device rd; // Will be used to obtain a seed for the random number engine |
| 29146 |
+ std::mt19937 gen(rd()); // Standard mersenne_twister_engine seeded with rd() |
| 29147 |
+ std::uniform_real_distribution<float> dis(0.0, 1.0f); |
| 29148 |
+ bool hasDiscard = false; |
| 29149 |
+ for (uint32_t i = 0; i < mRenderPassDesc.numColorAttachments; ++i) |
| 29150 |
+ { |
| 29151 |
+ if (mRenderPassDesc.colorAttachments[i].storeAction == MTLStoreActionDontCare) |
| 29152 |
+ { |
| 29153 |
+ hasDiscard = true; |
| 29154 |
+ mRenderPassDesc.colorAttachments[i].loadAction = MTLLoadActionClear; |
| 29155 |
+ mRenderPassDesc.colorAttachments[i].clearColor = |
| 29156 |
+ MTLClearColorMake(dis(gen), dis(gen), dis(gen), dis(gen)); |
| 29157 |
+ } |
| 29158 |
+ else |
| 29159 |
+ { |
| 29160 |
+ mRenderPassDesc.colorAttachments[i].loadAction = MTLLoadActionLoad; |
| 29161 |
+ } |
| 29162 |
+ } |
| 29163 |
+ |
| 29164 |
+ if (mRenderPassDesc.depthAttachment.storeAction == MTLStoreActionDontCare) |
| 29165 |
+ { |
| 29166 |
+ hasDiscard = true; |
| 29167 |
+ mRenderPassDesc.depthAttachment.loadAction = MTLLoadActionClear; |
| 29168 |
+ mRenderPassDesc.depthAttachment.clearDepth = dis(gen); |
| 29169 |
+ } |
| 29170 |
+ else |
| 29171 |
+ { |
| 29172 |
+ mRenderPassDesc.depthAttachment.loadAction = MTLLoadActionLoad; |
| 29173 |
+ } |
| 29174 |
|
| 29175 |
- const MipmapNativeLevel &mipLevel = attachment.level; |
| 29176 |
+ if (mRenderPassDesc.stencilAttachment.storeAction == MTLStoreActionDontCare) |
| 29177 |
+ { |
| 29178 |
+ hasDiscard = true; |
| 29179 |
+ mRenderPassDesc.stencilAttachment.loadAction = MTLLoadActionClear; |
| 29180 |
+ mRenderPassDesc.stencilAttachment.clearStencil = rand(); |
| 29181 |
+ } |
| 29182 |
+ else |
| 29183 |
+ { |
| 29184 |
+ mRenderPassDesc.stencilAttachment.loadAction = MTLLoadActionLoad; |
| 29185 |
+ } |
| 29186 |
|
| 29187 |
- mRenderPassMaxScissorRect.width = |
| 29188 |
- std::min<NSUInteger>(mRenderPassMaxScissorRect.width, texture->width(mipLevel)); |
| 29189 |
- mRenderPassMaxScissorRect.height = |
| 29190 |
- std::min<NSUInteger>(mRenderPassMaxScissorRect.height, texture->height(mipLevel)); |
| 29191 |
+ if (hasDiscard) |
| 29192 |
+ { |
| 29193 |
+ auto tmpDesc = mRenderPassDesc; |
| 29194 |
+ restart(tmpDesc); |
| 29195 |
+ endEncodingImpl(false); |
| 29196 |
} |
| 29197 |
+#endif // ANGLE_MTL_SIMULATE_DISCARD_FRAMEBUFFER |
| 29198 |
} |
| 29199 |
|
| 29200 |
void RenderCommandEncoder::encodeMetalEncoder() |
| 29201 |
@@ -1102,7 +1193,7 @@ void PopDebugGroupCmd(id<MTLRenderCommandEncoder> encoder, IntermediateCommandSt |
| 29202 |
ANGLE_MTL_OBJC_SCOPE |
| 29203 |
{ |
| 29204 |
ANGLE_MTL_LOG("Creating new render command encoder with desc: %@", |
| 29205 |
- mCachedRenderPassDescObjC.get()); |
| 29206 |
+ [mCachedRenderPassDescObjC description]); |
| 29207 |
|
| 29208 |
id<MTLRenderCommandEncoder> metalCmdEncoder = |
| 29209 |
[cmdBuffer().get() renderCommandEncoderWithDescriptor:mCachedRenderPassDescObjC]; |
| 29210 |
@@ -1110,7 +1201,11 @@ void PopDebugGroupCmd(id<MTLRenderCommandEncoder> encoder, IntermediateCommandSt |
| 29211 |
set(metalCmdEncoder); |
| 29212 |
|
| 29213 |
// Verify that it was created successfully |
| 29214 |
- ASSERT(metalCmdEncoder); |
| 29215 |
+ ASSERT(get()); |
| 29216 |
+ |
| 29217 |
+ // Work-around driver bug on iOS devices: stencil must be explicitly set to zero |
| 29218 |
+ // even if the doc says the default value is already zero. |
| 29219 |
+ [metalCmdEncoder setStencilReferenceValue:0]; |
| 29220 |
|
| 29221 |
if (mLabel) |
| 29222 |
{ |
| 29223 |
@@ -1119,7 +1214,7 @@ void PopDebugGroupCmd(id<MTLRenderCommandEncoder> encoder, IntermediateCommandSt |
| 29224 |
|
| 29225 |
while (mCommands.good()) |
| 29226 |
{ |
| 29227 |
- CmdType cmdType = mCommands.fetch<CmdType>(); |
| 29228 |
+ auto cmdType = mCommands.fetch<CmdType>(); |
| 29229 |
CommandEncoderFunc encoder = gCommandEncoders[static_cast<int>(cmdType)]; |
| 29230 |
encoder(metalCmdEncoder, &mCommands); |
| 29231 |
} |
| 29232 |
@@ -1142,41 +1237,34 @@ void PopDebugGroupCmd(id<MTLRenderCommandEncoder> encoder, IntermediateCommandSt |
| 29233 |
endEncoding(); |
| 29234 |
} |
| 29235 |
|
| 29236 |
- if (!cmdBuffer().ready()) |
| 29237 |
+ if (!cmdBuffer().valid()) |
| 29238 |
{ |
| 29239 |
reset(); |
| 29240 |
return *this; |
| 29241 |
} |
| 29242 |
|
| 29243 |
- mLabel.reset(); |
| 29244 |
- |
| 29245 |
mRenderPassDesc = desc; |
| 29246 |
mRecording = true; |
| 29247 |
mHasDrawCalls = false; |
| 29248 |
- mRenderPassMaxScissorRect = {.x = 0, |
| 29249 |
- .y = 0, |
| 29250 |
- .width = std::numeric_limits<NSUInteger>::max(), |
| 29251 |
- .height = std::numeric_limits<NSUInteger>::max()}; |
| 29252 |
|
| 29253 |
- // Set writing dependency & constrain the scissor rect |
| 29254 |
+ // mask writing dependency & set appropriate store options |
| 29255 |
for (uint32_t i = 0; i < mRenderPassDesc.numColorAttachments; ++i) |
| 29256 |
{ |
| 29257 |
- initAttachmentWriteDependencyAndScissorRect(mRenderPassDesc.colorAttachments[i]); |
| 29258 |
+ initWriteDependency(mRenderPassDesc.colorAttachments[i].texture()); |
| 29259 |
} |
| 29260 |
|
| 29261 |
- initAttachmentWriteDependencyAndScissorRect(mRenderPassDesc.depthAttachment); |
| 29262 |
+ initWriteDependency(mRenderPassDesc.depthAttachment.texture()); |
| 29263 |
|
| 29264 |
- initAttachmentWriteDependencyAndScissorRect(mRenderPassDesc.stencilAttachment); |
| 29265 |
+ initWriteDependency(mRenderPassDesc.stencilAttachment.texture()); |
| 29266 |
|
| 29267 |
// Convert to Objective-C descriptor |
| 29268 |
mRenderPassDesc.convertToMetalDesc(mCachedRenderPassDescObjC); |
| 29269 |
|
| 29270 |
- // The actual Objective-C encoder will be created later in endEncoding(), we do so in |
| 29271 |
- // order to be able to sort the commands or do the preprocessing before the actual |
| 29272 |
- // encoding. |
| 29273 |
+ // The actual Objective-C encoder will be created later in endEncoding(), we do so in order |
| 29274 |
+ // to be able to sort the commands or do the preprocessing before the actual encoding. |
| 29275 |
|
| 29276 |
- // Since we defer the native encoder creation, we need to explicitly tell command buffer |
| 29277 |
- // that this object is the active encoder: |
| 29278 |
+ // Since we defer the native encoder creation, we need to explicitly tell command buffer that |
| 29279 |
+ // this object is the active encoder: |
| 29280 |
cmdBuffer().setActiveCommandEncoder(this); |
| 29281 |
|
| 29282 |
return *this; |
| 29283 |
@@ -1302,16 +1390,6 @@ void PopDebugGroupCmd(id<MTLRenderCommandEncoder> encoder, IntermediateCommandSt |
| 29284 |
{ |
| 29285 |
return *this; |
| 29286 |
} |
| 29287 |
- |
| 29288 |
- if (ANGLE_UNLIKELY(rect.x + rect.width > mRenderPassMaxScissorRect.width || |
| 29289 |
- rect.y + rect.height > mRenderPassMaxScissorRect.height)) |
| 29290 |
- { |
| 29291 |
- WARN() << "Out of bound scissor rect detected " << rect.x << " " << rect.y << " " |
| 29292 |
- << rect.width << " " << rect.height; |
| 29293 |
- // Out of bound rect will crash the metal runtime, ignore it. |
| 29294 |
- return *this; |
| 29295 |
- } |
| 29296 |
- |
| 29297 |
mStateCache.scissorRect = rect; |
| 29298 |
|
| 29299 |
mCommands.push(CmdType::SetScissorRect).push(rect); |
| 29300 |
@@ -1383,7 +1461,7 @@ void PopDebugGroupCmd(id<MTLRenderCommandEncoder> encoder, IntermediateCommandSt |
| 29301 |
return *this; |
| 29302 |
} |
| 29303 |
|
| 29304 |
- // If buffer already bound but with different offset, then update the offset only. |
| 29305 |
+ // If buffer already bound but with different offset, then update the offer only. |
| 29306 |
shaderStates.bufferOffsets[index] = offset; |
| 29307 |
|
| 29308 |
mCommands.push(static_cast<CmdType>(mSetBufferOffsetCmds[shaderType])) |
| 29309 |
@@ -1490,12 +1568,6 @@ void PopDebugGroupCmd(id<MTLRenderCommandEncoder> encoder, IntermediateCommandSt |
| 29310 |
uint32_t vertexStart, |
| 29311 |
uint32_t vertexCount) |
| 29312 |
{ |
| 29313 |
- if (ANGLE_UNLIKELY(!mStateCache.renderPipeline)) |
| 29314 |
- { |
| 29315 |
- // Ignore draw call if there is no render pipeline state set prior to this. |
| 29316 |
- return *this; |
| 29317 |
- } |
| 29318 |
- |
| 29319 |
mHasDrawCalls = true; |
| 29320 |
mCommands.push(CmdType::Draw).push(primitiveType).push(vertexStart).push(vertexCount); |
| 29321 |
|
| 29322 |
@@ -1507,12 +1579,6 @@ void PopDebugGroupCmd(id<MTLRenderCommandEncoder> encoder, IntermediateCommandSt |
| 29323 |
uint32_t vertexCount, |
| 29324 |
uint32_t instances) |
| 29325 |
{ |
| 29326 |
- if (ANGLE_UNLIKELY(!mStateCache.renderPipeline)) |
| 29327 |
- { |
| 29328 |
- // Ignore draw call if there is no render pipeline state set prior to this. |
| 29329 |
- return *this; |
| 29330 |
- } |
| 29331 |
- |
| 29332 |
mHasDrawCalls = true; |
| 29333 |
mCommands.push(CmdType::DrawInstanced) |
| 29334 |
.push(primitiveType) |
| 29335 |
@@ -1529,13 +1595,7 @@ void PopDebugGroupCmd(id<MTLRenderCommandEncoder> encoder, IntermediateCommandSt |
| 29336 |
const BufferRef &indexBuffer, |
| 29337 |
size_t bufferOffset) |
| 29338 |
{ |
| 29339 |
- if (ANGLE_UNLIKELY(!mStateCache.renderPipeline)) |
| 29340 |
- { |
| 29341 |
- // Ignore draw call if there is no render pipeline state set prior to this. |
| 29342 |
- return *this; |
| 29343 |
- } |
| 29344 |
- |
| 29345 |
- if (ANGLE_UNLIKELY(!indexBuffer)) |
| 29346 |
+ if (!indexBuffer) |
| 29347 |
{ |
| 29348 |
return *this; |
| 29349 |
} |
| 29350 |
@@ -1560,13 +1620,7 @@ void PopDebugGroupCmd(id<MTLRenderCommandEncoder> encoder, IntermediateCommandSt |
| 29351 |
size_t bufferOffset, |
| 29352 |
uint32_t instances) |
| 29353 |
{ |
| 29354 |
- if (ANGLE_UNLIKELY(!mStateCache.renderPipeline)) |
| 29355 |
- { |
| 29356 |
- // Ignore draw call if there is no render pipeline state set prior to this. |
| 29357 |
- return *this; |
| 29358 |
- } |
| 29359 |
- |
| 29360 |
- if (ANGLE_UNLIKELY(!indexBuffer)) |
| 29361 |
+ if (!indexBuffer) |
| 29362 |
{ |
| 29363 |
return *this; |
| 29364 |
} |
| 29365 |
@@ -1594,13 +1648,7 @@ void PopDebugGroupCmd(id<MTLRenderCommandEncoder> encoder, IntermediateCommandSt |
| 29366 |
uint32_t instances, |
| 29367 |
uint32_t baseVertex) |
| 29368 |
{ |
| 29369 |
- if (ANGLE_UNLIKELY(!mStateCache.renderPipeline)) |
| 29370 |
- { |
| 29371 |
- // Ignore draw call if there is no render pipeline state set prior to this. |
| 29372 |
- return *this; |
| 29373 |
- } |
| 29374 |
- |
| 29375 |
- if (ANGLE_UNLIKELY(!indexBuffer)) |
| 29376 |
+ if (!indexBuffer) |
| 29377 |
{ |
| 29378 |
return *this; |
| 29379 |
} |
| 29380 |
@@ -1673,6 +1721,12 @@ void PopDebugGroupCmd(id<MTLRenderCommandEncoder> encoder, IntermediateCommandSt |
| 29381 |
return *this; |
| 29382 |
} |
| 29383 |
|
| 29384 |
+void RenderCommandEncoder::insertDebugSignImpl(NSString *label) |
| 29385 |
+{ |
| 29386 |
+ // Defer the insertion until endEncoding() |
| 29387 |
+ mCommands.push(CmdType::InsertDebugsign).push([label ANGLE_MTL_RETAIN]); |
| 29388 |
+} |
| 29389 |
+ |
| 29390 |
void RenderCommandEncoder::pushDebugGroup(NSString *label) |
| 29391 |
{ |
| 29392 |
// Defer the insertion until endEncoding() |
| 29393 |
@@ -1799,7 +1853,7 @@ void PopDebugGroupCmd(id<MTLRenderCommandEncoder> encoder, IntermediateCommandSt |
| 29394 |
return *this; |
| 29395 |
} |
| 29396 |
|
| 29397 |
- if (!cmdBuffer().ready()) |
| 29398 |
+ if (!cmdBuffer().valid()) |
| 29399 |
{ |
| 29400 |
reset(); |
| 29401 |
return *this; |
| 29402 |
@@ -1962,6 +2016,66 @@ void PopDebugGroupCmd(id<MTLRenderCommandEncoder> encoder, IntermediateCommandSt |
| 29403 |
return *this; |
| 29404 |
} |
| 29405 |
|
| 29406 |
+BlitCommandEncoder &BlitCommandEncoder::copyTexture(const TextureRef &src, |
| 29407 |
+ uint32_t srcStartSlice, |
| 29408 |
+ uint32_t srcStartLevel, |
| 29409 |
+ const TextureRef &dst, |
| 29410 |
+ uint32_t dstStartSlice, |
| 29411 |
+ uint32_t dstStartLevel, |
| 29412 |
+ uint32_t sliceCount, |
| 29413 |
+ uint32_t levelCount) |
| 29414 |
+{ |
| 29415 |
+ if (!src || !dst) |
| 29416 |
+ { |
| 29417 |
+ return *this; |
| 29418 |
+ } |
| 29419 |
+ |
| 29420 |
+ cmdBuffer().setReadDependency(src); |
| 29421 |
+ cmdBuffer().setWriteDependency(dst); |
| 29422 |
+ |
| 29423 |
+#if defined(__IPHONE_13_0) || defined(__MAC_10_15) |
| 29424 |
+ if (ANGLE_APPLE_AVAILABLE_XCI(10.15, 13.0, 13.0)) |
| 29425 |
+ { |
| 29426 |
+ [get() copyFromTexture:src->get() |
| 29427 |
+ sourceSlice:srcStartSlice |
| 29428 |
+ sourceLevel:srcStartLevel |
| 29429 |
+ toTexture:dst->get() |
| 29430 |
+ destinationSlice:dstStartSlice |
| 29431 |
+ destinationLevel:dstStartLevel |
| 29432 |
+ sliceCount:sliceCount |
| 29433 |
+ levelCount:levelCount]; |
| 29434 |
+ } |
| 29435 |
+ else |
| 29436 |
+#endif |
| 29437 |
+ { |
| 29438 |
+ MTLOrigin origin = MTLOriginMake(0, 0, 0); |
| 29439 |
+ for (uint32_t slice = 0; slice < sliceCount; ++slice) |
| 29440 |
+ { |
| 29441 |
+ uint32_t srcSlice = srcStartSlice + slice; |
| 29442 |
+ uint32_t dstSlice = dstStartSlice + slice; |
| 29443 |
+ for (uint32_t level = 0; level < levelCount; ++level) |
| 29444 |
+ { |
| 29445 |
+ mtl::MipmapNativeLevel srcLevel = mtl::MipmapNativeLevel(srcStartLevel + level); |
| 29446 |
+ uint32_t dstLevel = dstStartLevel + level; |
| 29447 |
+ MTLSize srcSize = |
| 29448 |
+ MTLSizeMake(src->width(srcLevel), src->height(srcLevel), src->depth(srcLevel)); |
| 29449 |
+ |
| 29450 |
+ [get() copyFromTexture:src->get() |
| 29451 |
+ sourceSlice:srcSlice |
| 29452 |
+ sourceLevel:srcLevel.get() |
| 29453 |
+ sourceOrigin:origin |
| 29454 |
+ sourceSize:srcSize |
| 29455 |
+ toTexture:dst->get() |
| 29456 |
+ destinationSlice:dstSlice |
| 29457 |
+ destinationLevel:dstLevel |
| 29458 |
+ destinationOrigin:origin]; |
| 29459 |
+ } |
| 29460 |
+ } |
| 29461 |
+ } |
| 29462 |
+ |
| 29463 |
+ return *this; |
| 29464 |
+} |
| 29465 |
+ |
| 29466 |
BlitCommandEncoder &BlitCommandEncoder::generateMipmapsForTexture(const TextureRef &texture) |
| 29467 |
{ |
| 29468 |
if (!texture) |
| 29469 |
@@ -1974,7 +2088,7 @@ void PopDebugGroupCmd(id<MTLRenderCommandEncoder> encoder, IntermediateCommandSt |
| 29470 |
|
| 29471 |
return *this; |
| 29472 |
} |
| 29473 |
-BlitCommandEncoder &BlitCommandEncoder::synchronizeResource(Buffer *buffer) |
| 29474 |
+BlitCommandEncoder &BlitCommandEncoder::synchronizeResource(const BufferRef &buffer) |
| 29475 |
{ |
| 29476 |
if (!buffer) |
| 29477 |
{ |
| 29478 |
@@ -1989,7 +2103,7 @@ void PopDebugGroupCmd(id<MTLRenderCommandEncoder> encoder, IntermediateCommandSt |
| 29479 |
#endif |
| 29480 |
return *this; |
| 29481 |
} |
| 29482 |
-BlitCommandEncoder &BlitCommandEncoder::synchronizeResource(Texture *texture) |
| 29483 |
+BlitCommandEncoder &BlitCommandEncoder::synchronizeResource(const TextureRef &texture) |
| 29484 |
{ |
| 29485 |
if (!texture) |
| 29486 |
{ |
| 29487 |
@@ -2028,7 +2142,7 @@ void PopDebugGroupCmd(id<MTLRenderCommandEncoder> encoder, IntermediateCommandSt |
| 29488 |
return *this; |
| 29489 |
} |
| 29490 |
|
| 29491 |
- if (!cmdBuffer().ready()) |
| 29492 |
+ if (!cmdBuffer().valid()) |
| 29493 |
{ |
| 29494 |
reset(); |
| 29495 |
return *this; |
| 29496 |
diff --git a/src/libANGLE/renderer/metal/mtl_common.h b/src/libANGLE/renderer/metal/mtl_common.h |
| 29497 |
index 97ccb93..3fc5e39 100644 |
| 29498 |
--- a/src/libANGLE/renderer/metal/mtl_common.h |
| 29499 |
+++ b/src/libANGLE/renderer/metal/mtl_common.h |
| 29500 |
@@ -27,9 +27,18 @@ |
| 29501 |
#include "libANGLE/angletypes.h" |
| 29502 |
|
| 29503 |
#if TARGET_OS_IPHONE |
| 29504 |
+# if !defined(__IPHONE_11_0) |
| 29505 |
+# define __IPHONE_11_0 110000 |
| 29506 |
+# endif |
| 29507 |
# if !defined(ANGLE_IOS_DEPLOY_TARGET) |
| 29508 |
# define ANGLE_IOS_DEPLOY_TARGET __IPHONE_11_0 |
| 29509 |
# endif |
| 29510 |
+# if !defined(__IPHONE_OS_VERSION_MAX_ALLOWED) |
| 29511 |
+# define __IPHONE_OS_VERSION_MAX_ALLOWED __IPHONE_11_0 |
| 29512 |
+# endif |
| 29513 |
+# if !defined(__TV_OS_VERSION_MAX_ALLOWED) |
| 29514 |
+# define __TV_OS_VERSION_MAX_ALLOWED __IPHONE_11_0 |
| 29515 |
+# endif |
| 29516 |
#endif |
| 29517 |
|
| 29518 |
#if !defined(TARGET_OS_MACCATALYST) |
| 29519 |
@@ -66,6 +75,7 @@ namespace egl |
| 29520 |
{ |
| 29521 |
class Display; |
| 29522 |
class Image; |
| 29523 |
+class Surface; |
| 29524 |
} // namespace egl |
| 29525 |
|
| 29526 |
#define ANGLE_GL_OBJECTS_X(PROC) \ |
| 29527 |
@@ -102,6 +112,7 @@ class TextureMtl; |
| 29528 |
class ProgramMtl; |
| 29529 |
class SamplerMtl; |
| 29530 |
class TransformFeedbackMtl; |
| 29531 |
+class SurfaceMtlProtocol; |
| 29532 |
|
| 29533 |
ANGLE_GL_OBJECTS_X(ANGLE_PRE_DECLARE_MTL_OBJECT) |
| 29534 |
|
| 29535 |
@@ -128,7 +139,8 @@ constexpr size_t kDefaultAttributeSize = 4 * sizeof(float); |
| 29536 |
// Metal limits |
| 29537 |
constexpr uint32_t kMaxShaderBuffers = 31; |
| 29538 |
constexpr uint32_t kMaxShaderSamplers = 16; |
| 29539 |
-constexpr size_t kDefaultUniformsMaxSize = 4 * 1024; |
| 29540 |
+constexpr size_t kInlineConstDataMaxSize = 4 * 1024; |
| 29541 |
+constexpr size_t kDefaultUniformsMaxSize = kInlineConstDataMaxSize; |
| 29542 |
constexpr uint32_t kMaxViewports = 1; |
| 29543 |
|
| 29544 |
constexpr uint32_t kVertexAttribBufferStrideAlignment = 4; |
| 29545 |
@@ -142,7 +154,7 @@ constexpr uint32_t kIndexBufferOffsetAlignment = 4; |
| 29546 |
constexpr uint32_t kArgumentBufferOffsetAlignment = kUniformBufferSettingOffsetMinAlignment; |
| 29547 |
constexpr uint32_t kTextureToBufferBlittingAlignment = 256; |
| 29548 |
|
| 29549 |
-// Front end binding limits |
| 29550 |
+// Font end binding limits |
| 29551 |
constexpr uint32_t kMaxGLSamplerBindings = 2 * kMaxShaderSamplers; |
| 29552 |
constexpr uint32_t kMaxGLUBOBindings = 2 * kMaxShaderUBOs; |
| 29553 |
|
| 29554 |
@@ -155,21 +167,23 @@ constexpr uint32_t kDefaultAttribsBindingIndex = kVboBindingIndexStart + kMaxVer |
| 29555 |
constexpr uint32_t kDriverUniformsBindingIndex = kDefaultAttribsBindingIndex + 1; |
| 29556 |
// Binding index for default uniforms: |
| 29557 |
constexpr uint32_t kDefaultUniformsBindingIndex = kDefaultAttribsBindingIndex + 3; |
| 29558 |
-// Binding index for UBO's argument buffer or starting discrete slot |
| 29559 |
-constexpr uint32_t kUBOArgumentBufferBindingIndex = kDefaultUniformsBindingIndex + 1; |
| 29560 |
+// Binding index for Transform Feedback Buffers (4) |
| 29561 |
+constexpr uint32_t kTransformFeedbackBindingIndex = kDefaultUniformsBindingIndex + 1; |
| 29562 |
+// Binding index for shadow samplers' compare modes |
| 29563 |
+constexpr uint32_t kShadowSamplerCompareModesBindingIndex = kTransformFeedbackBindingIndex + 4; |
| 29564 |
+// Binding index for UBO's argument buffer |
| 29565 |
+constexpr uint32_t kUBOArgumentBufferBindingIndex = kShadowSamplerCompareModesBindingIndex + 1; |
| 29566 |
|
| 29567 |
-constexpr uint32_t kStencilMaskAll = 0xff; // Only 8 bits stencil is supported |
| 29568 |
+constexpr uint32_t kStencilMaskAll = 0xff; // Only 8 bit stencil is supported |
| 29569 |
|
| 29570 |
// This special constant is used to indicate that a particular vertex descriptor's buffer layout |
| 29571 |
// index is unused. |
| 29572 |
constexpr MTLVertexStepFunction kVertexStepFunctionInvalid = |
| 29573 |
static_cast<MTLVertexStepFunction>(0xff); |
| 29574 |
|
| 29575 |
-constexpr int kEmulatedAlphaValue = 1; |
| 29576 |
- |
| 29577 |
-constexpr size_t kOcclusionQueryResultSize = sizeof(uint64_t); |
| 29578 |
+constexpr float kEmulatedAlphaValue = 1.0f; |
| 29579 |
|
| 29580 |
-constexpr gl::Version kMaxSupportedGLVersion = gl::Version(3, 0); |
| 29581 |
+constexpr uint32_t kOcclusionQueryResultSize = sizeof(uint64_t); |
| 29582 |
|
| 29583 |
// Work-around the enum is not available on macOS |
| 29584 |
#if TARGET_OS_OSX || TARGET_OS_MACCATALYST |
| 29585 |
@@ -179,13 +193,11 @@ constexpr MTLBlitOption kBlitOptionRowLinearPVRTC = MTLBlitOptionRowLin |
| 29586 |
#endif |
| 29587 |
|
| 29588 |
#if defined(__IPHONE_13_0) || defined(__MAC_10_15) |
| 29589 |
-# define ANGLE_MTL_SWIZZLE_AVAILABLE 1 |
| 29590 |
using TextureSwizzleChannels = MTLTextureSwizzleChannels; |
| 29591 |
using RenderStages = MTLRenderStages; |
| 29592 |
constexpr MTLRenderStages kRenderStageVertex = MTLRenderStageVertex; |
| 29593 |
constexpr MTLRenderStages kRenderStageFragment = MTLRenderStageFragment; |
| 29594 |
#else |
| 29595 |
-# define ANGLE_MTL_SWIZZLE_AVAILABLE 0 |
| 29596 |
using TextureSwizzleChannels = int; |
| 29597 |
using RenderStages = int; |
| 29598 |
constexpr RenderStages kRenderStageVertex = 1; |
| 29599 |
@@ -219,12 +231,16 @@ struct ImplTypeHelper<egl::Display> |
| 29600 |
{ |
| 29601 |
using ImplType = DisplayMtl; |
| 29602 |
}; |
| 29603 |
- |
| 29604 |
+template <> |
| 29605 |
+struct ImplTypeHelper<egl::Surface> |
| 29606 |
+{ |
| 29607 |
+ using ImplType = SurfaceMtlProtocol; |
| 29608 |
+}; |
| 29609 |
template <typename T> |
| 29610 |
using GetImplType = typename ImplTypeHelper<T>::ImplType; |
| 29611 |
|
| 29612 |
template <typename T> |
| 29613 |
-GetImplType<T> *GetImpl(const T *_Nonnull glObject) |
| 29614 |
+GetImplType<T> *GetImpl(const T *glObject) |
| 29615 |
{ |
| 29616 |
return GetImplAs<GetImplType<T>>(glObject); |
| 29617 |
} |
| 29618 |
@@ -346,21 +362,16 @@ using AutoObjCObj = AutoObjCPtr<T *>; |
| 29619 |
|
| 29620 |
// NOTE: SharedEvent is only declared on iOS 12.0+ or mac 10.14+ |
| 29621 |
#if defined(__IPHONE_12_0) || defined(__MAC_10_14) |
| 29622 |
-# define ANGLE_MTL_EVENT_AVAILABLE 1 |
| 29623 |
using SharedEventRef = AutoObjCPtr<id<MTLSharedEvent>>; |
| 29624 |
#else |
| 29625 |
-# define ANGLE_MTL_EVENT_AVAILABLE 0 |
| 29626 |
using SharedEventRef = AutoObjCObj<NSObject>; |
| 29627 |
#endif |
| 29628 |
|
| 29629 |
// The native image index used by Metal back-end, the image index uses native mipmap level instead |
| 29630 |
// of "virtual" level modified by OpenGL's base level. |
| 29631 |
using MipmapNativeLevel = gl::LevelIndexWrapper<uint32_t>; |
| 29632 |
- |
| 29633 |
constexpr MipmapNativeLevel kZeroNativeMipLevel(0); |
| 29634 |
- |
| 29635 |
class ImageNativeIndexIterator; |
| 29636 |
- |
| 29637 |
class ImageNativeIndex final |
| 29638 |
{ |
| 29639 |
public: |
| 29640 |
@@ -370,55 +381,42 @@ class ImageNativeIndex final |
| 29641 |
mNativeIndex = gl::ImageIndex::MakeFromType(src.getType(), src.getLevelIndex() - baseLevel, |
| 29642 |
src.getLayerIndex(), src.getLayerCount()); |
| 29643 |
} |
| 29644 |
- |
| 29645 |
static ImageNativeIndex FromBaseZeroGLIndex(const gl::ImageIndex &src) |
| 29646 |
{ |
| 29647 |
return ImageNativeIndex(src, 0); |
| 29648 |
} |
| 29649 |
- |
| 29650 |
MipmapNativeLevel getNativeLevel() const |
| 29651 |
{ |
| 29652 |
return MipmapNativeLevel(mNativeIndex.getLevelIndex()); |
| 29653 |
} |
| 29654 |
- |
| 29655 |
gl::TextureType getType() const { return mNativeIndex.getType(); } |
| 29656 |
GLint getLayerIndex() const { return mNativeIndex.getLayerIndex(); } |
| 29657 |
GLint getLayerCount() const { return mNativeIndex.getLayerCount(); } |
| 29658 |
GLint cubeMapFaceIndex() const { return mNativeIndex.cubeMapFaceIndex(); } |
| 29659 |
- |
| 29660 |
bool isLayered() const { return mNativeIndex.isLayered(); } |
| 29661 |
bool hasLayer() const { return mNativeIndex.hasLayer(); } |
| 29662 |
bool has3DLayer() const { return mNativeIndex.has3DLayer(); } |
| 29663 |
bool usesTex3D() const { return mNativeIndex.usesTex3D(); } |
| 29664 |
- |
| 29665 |
bool valid() const { return mNativeIndex.valid(); } |
| 29666 |
- |
| 29667 |
ImageNativeIndexIterator getLayerIterator(GLint layerCount) const; |
| 29668 |
- |
| 29669 |
private: |
| 29670 |
gl::ImageIndex mNativeIndex; |
| 29671 |
}; |
| 29672 |
- |
| 29673 |
class ImageNativeIndexIterator final |
| 29674 |
{ |
| 29675 |
public: |
| 29676 |
ImageNativeIndex next() { return ImageNativeIndex(mNativeIndexIte.next(), 0); } |
| 29677 |
ImageNativeIndex current() const { return ImageNativeIndex(mNativeIndexIte.current(), 0); } |
| 29678 |
bool hasNext() const { return mNativeIndexIte.hasNext(); } |
| 29679 |
- |
| 29680 |
private: |
| 29681 |
// This class is only constructable from ImageNativeIndex |
| 29682 |
friend class ImageNativeIndex; |
| 29683 |
- |
| 29684 |
explicit ImageNativeIndexIterator(const gl::ImageIndexIterator &baseZeroSrc) |
| 29685 |
: mNativeIndexIte(baseZeroSrc) |
| 29686 |
{} |
| 29687 |
- |
| 29688 |
gl::ImageIndexIterator mNativeIndexIte; |
| 29689 |
}; |
| 29690 |
- |
| 29691 |
using ClearColorValueBytes = std::array<uint8_t, 4 * sizeof(float)>; |
| 29692 |
- |
| 29693 |
class ClearColorValue |
| 29694 |
{ |
| 29695 |
public: |
| 29696 |
@@ -437,22 +435,15 @@ class ClearColorValue |
| 29697 |
constexpr ClearColorValue(const ClearColorValue &src) |
| 29698 |
: mType(src.mType), mValueBytes(src.mValueBytes) |
| 29699 |
{} |
| 29700 |
- |
| 29701 |
MTLClearColor toMTLClearColor() const; |
| 29702 |
- |
| 29703 |
PixelType getType() const { return mType; } |
| 29704 |
- |
| 29705 |
const ClearColorValueBytes &getValueBytes() const { return mValueBytes; } |
| 29706 |
- |
| 29707 |
ClearColorValue &operator=(const ClearColorValue &src); |
| 29708 |
- |
| 29709 |
void setAsFloat(float r, float g, float b, float a); |
| 29710 |
void setAsInt(int32_t r, int32_t g, int32_t b, int32_t a); |
| 29711 |
void setAsUInt(uint32_t r, uint32_t g, uint32_t b, uint32_t a); |
| 29712 |
- |
| 29713 |
private: |
| 29714 |
PixelType mType; |
| 29715 |
- |
| 29716 |
union |
| 29717 |
{ |
| 29718 |
struct |
| 29719 |
@@ -467,7 +458,6 @@ class ClearColorValue |
| 29720 |
{ |
| 29721 |
uint32_t mRedU, mGreenU, mBlueU, mAlphaU; |
| 29722 |
}; |
| 29723 |
- |
| 29724 |
ClearColorValueBytes mValueBytes; |
| 29725 |
}; |
| 29726 |
}; |
| 29727 |
@@ -483,7 +473,7 @@ class ErrorHandler |
| 29728 |
const char *function, |
| 29729 |
unsigned int line) = 0; |
| 29730 |
|
| 29731 |
- virtual void handleError(NSError *_Nullable error, |
| 29732 |
+ virtual void handleError(NSError *error, |
| 29733 |
const char *file, |
| 29734 |
const char *function, |
| 29735 |
unsigned int line) = 0; |
| 29736 |
@@ -493,7 +483,7 @@ class Context : public ErrorHandler |
| 29737 |
{ |
| 29738 |
public: |
| 29739 |
Context(DisplayMtl *displayMtl); |
| 29740 |
- _Nullable id<MTLDevice> getMetalDevice() const; |
| 29741 |
+ id<MTLDevice> getMetalDevice() const; |
| 29742 |
mtl::CommandQueue &cmdQueue(); |
| 29743 |
|
| 29744 |
DisplayMtl *getDisplay() const { return mDisplay; } |
| 29745 |
diff --git a/src/libANGLE/renderer/metal/mtl_constants.h b/src/libANGLE/renderer/metal/mtl_constants.h |
| 29746 |
new file mode 100644 |
| 29747 |
index 0000000..a20b2cd |
| 29748 |
--- /dev/null |
| 29749 |
+++ b/src/libANGLE/renderer/metal/mtl_constants.h |
| 29750 |
@@ -0,0 +1,73 @@ |
| 29751 |
+// |
| 29752 |
+// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 29753 |
+// Use of this source code is governed by a BSD-style license that can be |
| 29754 |
+// found in the LICENSE file. |
| 29755 |
+// |
| 29756 |
+// mtl_common.h: |
| 29757 |
+// Declares numerical constants used in Metal. |
| 29758 |
+// error handler base class. |
| 29759 |
+// |
| 29760 |
+ |
| 29761 |
+#ifndef LIBANGLE_RENDERER_METAL_MTL_CONSTANTS_H |
| 29762 |
+#define LIBANGLE_RENDERER_METAL_MTL_CONSTANTS_H |
| 29763 |
+#include "libANGLE/Constants.h" |
| 29764 |
+#include "libANGLE/Version.h" |
| 29765 |
+#include "libANGLE/angletypes.h" |
| 29766 |
+ |
| 29767 |
+namespace rx |
| 29768 |
+{ |
| 29769 |
+namespace mtl |
| 29770 |
+{ |
| 29771 |
+ |
| 29772 |
+// NOTE(hqle): support variable max number of vertex attributes |
| 29773 |
+constexpr uint32_t kMaxVertexAttribs = gl::MAX_VERTEX_ATTRIBS; |
| 29774 |
+// NOTE(hqle): support variable max number of render targets |
| 29775 |
+constexpr uint32_t kMaxRenderTargets = 4; |
| 29776 |
+ |
| 29777 |
+constexpr uint32_t kMaxShaderUBOs = 12; |
| 29778 |
+constexpr uint32_t kMaxUBOSize = 16384; |
| 29779 |
+ |
| 29780 |
+constexpr size_t kDefaultAttributeSize = 4 * sizeof(float); |
| 29781 |
+ |
| 29782 |
+// Metal limits |
| 29783 |
+constexpr uint32_t kMaxShaderBuffers = 31; |
| 29784 |
+constexpr uint32_t kMaxShaderSamplers = 16; |
| 29785 |
+constexpr size_t kInlineConstDataMaxSize = 4 * 1024; |
| 29786 |
+constexpr size_t kDefaultUniformsMaxSize = kInlineConstDataMaxSize; |
| 29787 |
+constexpr uint32_t kMaxViewports = 1; |
| 29788 |
+ |
| 29789 |
+constexpr uint32_t kVertexAttribBufferStrideAlignment = 4; |
| 29790 |
+// Alignment requirement for offset passed to setVertex|FragmentBuffer |
| 29791 |
+#if TARGET_OS_OSX || TARGET_OS_MACCATALYST |
| 29792 |
+constexpr uint32_t kUniformBufferSettingOffsetMinAlignment = 256; |
| 29793 |
+#else |
| 29794 |
+constexpr uint32_t kUniformBufferSettingOffsetMinAlignment = 4; |
| 29795 |
+#endif |
| 29796 |
+constexpr uint32_t kIndexBufferOffsetAlignment = 4; |
| 29797 |
+constexpr uint32_t kTextureToBufferBlittingAlignment = 256; |
| 29798 |
+ |
| 29799 |
+// Font end binding limits |
| 29800 |
+constexpr uint32_t kMaxGLSamplerBindings = 2 * kMaxShaderSamplers; |
| 29801 |
+constexpr uint32_t kMaxGLUBOBindings = 2 * kMaxShaderUBOs; |
| 29802 |
+ |
| 29803 |
+// Binding index start for vertex data buffers: |
| 29804 |
+constexpr uint32_t kVboBindingIndexStart = 0; |
| 29805 |
+ |
| 29806 |
+// Binding index for default attribute buffer: |
| 29807 |
+constexpr uint32_t kDefaultAttribsBindingIndex = kVboBindingIndexStart + kMaxVertexAttribs; |
| 29808 |
+// Binding index for driver uniforms: |
| 29809 |
+constexpr uint32_t kDriverUniformsBindingIndex = kDefaultAttribsBindingIndex + 1; |
| 29810 |
+// Binding index for default uniforms: |
| 29811 |
+constexpr uint32_t kDefaultUniformsBindingIndex = kDefaultAttribsBindingIndex + 3; |
| 29812 |
+// Binding index for Transform Feedback Buffers (4) |
| 29813 |
+constexpr uint32_t kTransformFeedbackBindingIndex = kDefaultUniformsBindingIndex + 1; |
| 29814 |
+// Binding index for shadow samplers' compare modes |
| 29815 |
+constexpr uint32_t kShadowSamplerCompareModesBindingIndex = kTransformFeedbackBindingIndex + 4; |
| 29816 |
+// Binding index for UBO's argument buffer |
| 29817 |
+constexpr uint32_t kUBOArgumentBufferBindingIndex = kShadowSamplerCompareModesBindingIndex + 1; |
| 29818 |
+ |
| 29819 |
+constexpr uint32_t kStencilMaskAll = 0xff; // Only 8 bits stencil is supported |
| 29820 |
+ |
| 29821 |
+} // namespace mtl |
| 29822 |
+} // namespace rx |
| 29823 |
+#endif |
| 29824 |
diff --git a/src/libANGLE/renderer/metal/mtl_format_map.json b/src/libANGLE/renderer/metal/mtl_format_map.json |
| 29825 |
index 4a12a90..2da7421 100644 |
| 29826 |
--- a/src/libANGLE/renderer/metal/mtl_format_map.json |
| 29827 |
+++ b/src/libANGLE/renderer/metal/mtl_format_map.json |
| 29828 |
@@ -74,11 +74,11 @@ |
| 29829 |
"D32_FLOAT": "MTLPixelFormatDepth32Float", |
| 29830 |
"S8_UINT": "MTLPixelFormatStencil8", |
| 29831 |
"D32_FLOAT_S8X24_UINT": "MTLPixelFormatDepth32Float_Stencil8", |
| 29832 |
- "B10G10R10A2_UNORM": "MTLPixelFormatBGR10A2Unorm", |
| 29833 |
"R10G10B10A2_UINT": "MTLPixelFormatRGB10A2Uint", |
| 29834 |
"R10G10B10A2_UNORM": "MTLPixelFormatRGB10A2Unorm", |
| 29835 |
"R11G11B10_FLOAT": "MTLPixelFormatRG11B10Float", |
| 29836 |
- "R9G9B9E5_SHAREDEXP": "MTLPixelFormatRGB9E5Float" |
| 29837 |
+ "R9G9B9E5_SHAREDEXP": "MTLPixelFormatRGB9E5Float", |
| 29838 |
+ "D16_UNORM": "MTLPixelFormatDepth16Unorm" |
| 29839 |
}, |
| 29840 |
"map_ios": { |
| 29841 |
"R5G6B5_UNORM": "MTLPixelFormatB5G6R5Unorm", |
| 29842 |
@@ -92,6 +92,7 @@ |
| 29843 |
"PVRTC1_RGB_4BPP_UNORM_SRGB_BLOCK": "MTLPixelFormatPVRTC_RGB_4BPP_sRGB", |
| 29844 |
"PVRTC1_RGBA_2BPP_UNORM_SRGB_BLOCK": "MTLPixelFormatPVRTC_RGBA_2BPP_sRGB", |
| 29845 |
"PVRTC1_RGBA_4BPP_UNORM_SRGB_BLOCK": "MTLPixelFormatPVRTC_RGBA_4BPP_sRGB", |
| 29846 |
+ "ETC1_R8G8B8_UNORM_BLOCK": "MTLPixelFormatETC2_RGB8", |
| 29847 |
"ETC2_R8G8B8_UNORM_BLOCK": "MTLPixelFormatETC2_RGB8", |
| 29848 |
"ETC2_R8G8B8_SRGB_BLOCK": "MTLPixelFormatETC2_RGB8_sRGB", |
| 29849 |
"ETC2_R8G8B8A1_UNORM_BLOCK": "MTLPixelFormatETC2_RGB8A1", |
| 29850 |
@@ -100,39 +101,38 @@ |
| 29851 |
"ETC2_R8G8B8A8_SRGB_BLOCK": "MTLPixelFormatEAC_RGBA8_sRGB", |
| 29852 |
"EAC_R11_UNORM_BLOCK": "MTLPixelFormatEAC_R11Unorm", |
| 29853 |
"EAC_R11_SNORM_BLOCK": "MTLPixelFormatEAC_R11Snorm", |
| 29854 |
- "EAC_R11G11_UNORM_BLOCK": "MTLPixelFormatEAC_RG11Unorm", |
| 29855 |
+ "EAC_R11G11_UNORM_BLOCK": "MTLPixelFormatEAC_R11Unorm", |
| 29856 |
"EAC_R11G11_SNORM_BLOCK": "MTLPixelFormatEAC_RG11Snorm", |
| 29857 |
- "ASTC_4x4_UNORM_BLOCK": "MTLPixelFormatASTC_4x4_LDR", |
| 29858 |
- "ASTC_4x4_SRGB_BLOCK": "MTLPixelFormatASTC_4x4_sRGB", |
| 29859 |
- "ASTC_5x4_UNORM_BLOCK": "MTLPixelFormatASTC_5x4_LDR", |
| 29860 |
- "ASTC_5x4_SRGB_BLOCK": "MTLPixelFormatASTC_5x4_sRGB", |
| 29861 |
- "ASTC_5x5_UNORM_BLOCK": "MTLPixelFormatASTC_5x5_LDR", |
| 29862 |
- "ASTC_5x5_SRGB_BLOCK": "MTLPixelFormatASTC_5x5_sRGB", |
| 29863 |
- "ASTC_6x5_UNORM_BLOCK": "MTLPixelFormatASTC_6x5_LDR", |
| 29864 |
- "ASTC_6x5_SRGB_BLOCK": "MTLPixelFormatASTC_6x5_sRGB", |
| 29865 |
- "ASTC_6x6_UNORM_BLOCK": "MTLPixelFormatASTC_6x6_LDR", |
| 29866 |
- "ASTC_6x6_SRGB_BLOCK": "MTLPixelFormatASTC_6x6_sRGB", |
| 29867 |
- "ASTC_8x5_UNORM_BLOCK": "MTLPixelFormatASTC_8x5_LDR", |
| 29868 |
- "ASTC_8x5_SRGB_BLOCK": "MTLPixelFormatASTC_8x5_sRGB", |
| 29869 |
- "ASTC_8x6_UNORM_BLOCK": "MTLPixelFormatASTC_8x6_LDR", |
| 29870 |
- "ASTC_8x6_SRGB_BLOCK": "MTLPixelFormatASTC_8x6_sRGB", |
| 29871 |
- "ASTC_8x8_UNORM_BLOCK": "MTLPixelFormatASTC_8x8_LDR", |
| 29872 |
- "ASTC_8x8_SRGB_BLOCK": "MTLPixelFormatASTC_8x8_sRGB", |
| 29873 |
- "ASTC_10x5_UNORM_BLOCK": "MTLPixelFormatASTC_10x5_LDR", |
| 29874 |
- "ASTC_10x5_SRGB_BLOCK": "MTLPixelFormatASTC_10x5_sRGB", |
| 29875 |
- "ASTC_10x6_UNORM_BLOCK": "MTLPixelFormatASTC_10x6_LDR", |
| 29876 |
- "ASTC_10x6_SRGB_BLOCK": "MTLPixelFormatASTC_10x6_sRGB", |
| 29877 |
- "ASTC_10x8_UNORM_BLOCK": "MTLPixelFormatASTC_10x8_LDR", |
| 29878 |
- "ASTC_10x8_SRGB_BLOCK": "MTLPixelFormatASTC_10x8_sRGB", |
| 29879 |
- "ASTC_10x10_UNORM_BLOCK": "MTLPixelFormatASTC_10x10_LDR", |
| 29880 |
- "ASTC_10x10_SRGB_BLOCK": "MTLPixelFormatASTC_10x10_sRGB", |
| 29881 |
- "ASTC_12x10_UNORM_BLOCK": "MTLPixelFormatASTC_12x10_LDR", |
| 29882 |
- "ASTC_12x10_SRGB_BLOCK": "MTLPixelFormatASTC_12x10_sRGB", |
| 29883 |
- "ASTC_12x12_UNORM_BLOCK": "MTLPixelFormatASTC_12x12_LDR", |
| 29884 |
- "ASTC_12x12_SRGB_BLOCK": "MTLPixelFormatASTC_12x12_sRGB" |
| 29885 |
+ "ASTC_4x4_SRGB_BLOCK" : "MTLPixelFormatASTC_4x4_sRGB", |
| 29886 |
+ "ASTC_5x4_SRGB_BLOCK" : "MTLPixelFormatASTC_5x4_sRGB", |
| 29887 |
+ "ASTC_5x5_SRGB_BLOCK" : "MTLPixelFormatASTC_5x5_sRGB", |
| 29888 |
+ "ASTC_6x5_SRGB_BLOCK" : "MTLPixelFormatASTC_6x5_sRGB", |
| 29889 |
+ "ASTC_6x6_SRGB_BLOCK" : "MTLPixelFormatASTC_6x6_sRGB", |
| 29890 |
+ "ASTC_8x5_SRGB_BLOCK" : "MTLPixelFormatASTC_8x5_sRGB", |
| 29891 |
+ "ASTC_8x6_SRGB_BLOCK" : "MTLPixelFormatASTC_8x6_sRGB", |
| 29892 |
+ "ASTC_8x8_SRGB_BLOCK" : "MTLPixelFormatASTC_8x8_sRGB", |
| 29893 |
+ "ASTC_10x5_SRGB_BLOCK" : "MTLPixelFormatASTC_10x5_sRGB", |
| 29894 |
+ "ASTC_10x6_SRGB_BLOCK" : "MTLPixelFormatASTC_10x6_sRGB", |
| 29895 |
+ "ASTC_10x8_SRGB_BLOCK" : "MTLPixelFormatASTC_10x8_sRGB", |
| 29896 |
+ "ASTC_10x10_SRGB_BLOCK" : "MTLPixelFormatASTC_10x10_sRGB", |
| 29897 |
+ "ASTC_12x10_SRGB_BLOCK" : "MTLPixelFormatASTC_12x10_sRGB", |
| 29898 |
+ "ASTC_12x12_SRGB_BLOCK" : "MTLPixelFormatASTC_12x12_sRGB", |
| 29899 |
+ "ASTC_4x4_UNORM_BLOCK" : "MTLPixelFormatASTC_4x4_LDR", |
| 29900 |
+ "ASTC_5x4_UNORM_BLOCK" : "MTLPixelFormatASTC_5x4_LDR", |
| 29901 |
+ "ASTC_5x5_UNORM_BLOCK" : "MTLPixelFormatASTC_5x5_LDR", |
| 29902 |
+ "ASTC_6x5_UNORM_BLOCK" : "MTLPixelFormatASTC_6x5_LDR", |
| 29903 |
+ "ASTC_6x6_UNORM_BLOCK" : "MTLPixelFormatASTC_6x6_LDR", |
| 29904 |
+ "ASTC_8x5_UNORM_BLOCK" : "MTLPixelFormatASTC_8x5_LDR", |
| 29905 |
+ "ASTC_8x6_UNORM_BLOCK" : "MTLPixelFormatASTC_8x6_LDR", |
| 29906 |
+ "ASTC_8x8_UNORM_BLOCK" : "MTLPixelFormatASTC_8x8_LDR", |
| 29907 |
+ "ASTC_10x5_UNORM_BLOCK" : "MTLPixelFormatASTC_10x5_LDR", |
| 29908 |
+ "ASTC_10x6_UNORM_BLOCK" : "MTLPixelFormatASTC_10x6_LDR", |
| 29909 |
+ "ASTC_10x8_UNORM_BLOCK" : "MTLPixelFormatASTC_10x8_LDR", |
| 29910 |
+ "ASTC_10x10_UNORM_BLOCK" : "MTLPixelFormatASTC_10x10_LDR", |
| 29911 |
+ "ASTC_12x10_UNORM_BLOCK" : "MTLPixelFormatASTC_12x10_LDR", |
| 29912 |
+ "ASTC_12x12_UNORM_BLOCK" : "MTLPixelFormatASTC_12x12_LDR" |
| 29913 |
}, |
| 29914 |
"map_mac": { |
| 29915 |
- "D16_UNORM": "MTLPixelFormatDepth16Unorm", |
| 29916 |
"D24_UNORM_S8_UINT": "MTLPixelFormatDepth24Unorm_Stencil8", |
| 29917 |
"BC1_RGBA_UNORM_BLOCK": "MTLPixelFormatBC1_RGBA", |
| 29918 |
"BC1_RGBA_UNORM_SRGB_BLOCK": "MTLPixelFormatBC1_RGBA_sRGB", |
| 29919 |
@@ -175,9 +175,7 @@ |
| 29920 |
"D32_UNORM": "D32_FLOAT" |
| 29921 |
}, |
| 29922 |
"override_ios": { |
| 29923 |
- "D24_UNORM_S8_UINT": "D32_FLOAT_S8X24_UINT", |
| 29924 |
- "D16_UNORM": "D32_FLOAT", |
| 29925 |
- "ETC1_R8G8B8_UNORM_BLOCK": "ETC2_R8G8B8_UNORM_BLOCK" |
| 29926 |
+ "D24_UNORM_S8_UINT": "D32_FLOAT_S8X24_UINT" |
| 29927 |
}, |
| 29928 |
"override_mac": { |
| 29929 |
"R5G6B5_UNORM": "R8G8B8A8_UNORM", |
| 29930 |
@@ -203,7 +201,8 @@ |
| 29931 |
"EAC_R11G11_UNORM_BLOCK": "R16G16_UNORM", |
| 29932 |
"EAC_R11G11_SNORM_BLOCK": "R16G16_SNORM" |
| 29933 |
}, |
| 29934 |
- "d24s8_fallbacks_mac": { |
| 29935 |
+ "fallbacks_mac": { |
| 29936 |
+ "B8G8R8A8_UNORM": "R8G8B8A8_UNORM", |
| 29937 |
"D24_UNORM_S8_UINT": "D32_FLOAT_S8X24_UINT" |
| 29938 |
}, |
| 29939 |
"caps": { |
| 29940 |
diff --git a/src/libANGLE/renderer/metal/mtl_format_table_autogen.mm b/src/libANGLE/renderer/metal/mtl_format_table_autogen.mm |
| 29941 |
index c21c593..d3ea5b0 100644 |
| 29942 |
--- a/src/libANGLE/renderer/metal/mtl_format_table_autogen.mm |
| 29943 |
+++ b/src/libANGLE/renderer/metal/mtl_format_table_autogen.mm |
| 29944 |
@@ -28,7 +28,6 @@ |
| 29945 |
void Format::init(const DisplayMtl *display, angle::FormatID intendedFormatId_) |
| 29946 |
{ |
| 29947 |
this->intendedFormatId = intendedFormatId_; |
| 29948 |
- |
| 29949 |
id<MTLDevice> metalDevice = display->getMetalDevice(); |
| 29950 |
|
| 29951 |
// Actual conversion |
| 29952 |
@@ -43,15 +42,26 @@ |
| 29953 |
this->swizzled = false; |
| 29954 |
break; |
| 29955 |
|
| 29956 |
- case angle::FormatID::B10G10R10A2_UNORM: |
| 29957 |
+#if TARGET_OS_OSX || TARGET_OS_MACCATALYST |
| 29958 |
+ case angle::FormatID::B8G8R8A8_UNORM: |
| 29959 |
|
| 29960 |
- this->metalFormat = MTLPixelFormatBGR10A2Unorm; |
| 29961 |
- this->actualFormatId = angle::FormatID::B10G10R10A2_UNORM; |
| 29962 |
+ if (metalDevice.depth24Stencil8PixelFormatSupported) |
| 29963 |
+ { |
| 29964 |
+ this->metalFormat = MTLPixelFormatBGRA8Unorm; |
| 29965 |
+ this->actualFormatId = angle::FormatID::B8G8R8A8_UNORM; |
| 29966 |
+ this->initFunction = nullptr; |
| 29967 |
+ } |
| 29968 |
+ else |
| 29969 |
+ { |
| 29970 |
+ this->metalFormat = MTLPixelFormatRGBA8Unorm; |
| 29971 |
+ this->actualFormatId = angle::FormatID::R8G8B8A8_UNORM; |
| 29972 |
this->initFunction = nullptr; |
| 29973 |
+ } |
| 29974 |
|
| 29975 |
this->swizzled = false; |
| 29976 |
break; |
| 29977 |
|
| 29978 |
+#else // TARGET_OS_OSX || TARGET_OS_MACCATALYST |
| 29979 |
case angle::FormatID::B8G8R8A8_UNORM: |
| 29980 |
|
| 29981 |
this->metalFormat = MTLPixelFormatBGRA8Unorm; |
| 29982 |
@@ -61,6 +71,7 @@ |
| 29983 |
this->swizzled = false; |
| 29984 |
break; |
| 29985 |
|
| 29986 |
+#endif // TARGET_OS_OSX || TARGET_OS_MACCATALYST |
| 29987 |
case angle::FormatID::B8G8R8A8_UNORM_SRGB: |
| 29988 |
|
| 29989 |
this->metalFormat = MTLPixelFormatBGRA8Unorm_sRGB; |
| 29990 |
@@ -70,6 +81,36 @@ |
| 29991 |
this->swizzled = false; |
| 29992 |
break; |
| 29993 |
|
| 29994 |
+#if TARGET_OS_OSX || TARGET_OS_MACCATALYST |
| 29995 |
+ case angle::FormatID::D16_UNORM: |
| 29996 |
+ |
| 29997 |
+ this->metalFormat = MTLPixelFormatDepth16Unorm; |
| 29998 |
+ this->actualFormatId = angle::FormatID::D16_UNORM; |
| 29999 |
+ this->initFunction = nullptr; |
| 30000 |
+ |
| 30001 |
+ this->swizzled = false; |
| 30002 |
+ break; |
| 30003 |
+ |
| 30004 |
+#else // TARGET_OS_OSX || TARGET_OS_MACCATALYST |
| 30005 |
+ case angle::FormatID::D16_UNORM: |
| 30006 |
+ |
| 30007 |
+ if ([metalDevice supportsFamily:MTLGPUFamilyApple3]) |
| 30008 |
+ { |
| 30009 |
+ this->metalFormat = MTLPixelFormatDepth16Unorm; |
| 30010 |
+ this->actualFormatId = angle::FormatID::D16_UNORM; |
| 30011 |
+ this->initFunction = nullptr; |
| 30012 |
+ } |
| 30013 |
+ else |
| 30014 |
+ { |
| 30015 |
+ this->metalFormat = MTLPixelFormatDepth32Float; |
| 30016 |
+ this->actualFormatId = angle::FormatID::D32_FLOAT; |
| 30017 |
+ this->initFunction = nullptr; |
| 30018 |
+ } |
| 30019 |
+ |
| 30020 |
+ this->swizzled = false; |
| 30021 |
+ break; |
| 30022 |
+ |
| 30023 |
+#endif // TARGET_OS_OSX || TARGET_OS_MACCATALYST |
| 30024 |
case angle::FormatID::D32_FLOAT: |
| 30025 |
|
| 30026 |
this->metalFormat = MTLPixelFormatDepth32Float; |
| 30027 |
@@ -815,15 +856,6 @@ |
| 30028 |
this->swizzled = false; |
| 30029 |
break; |
| 30030 |
|
| 30031 |
- case angle::FormatID::D16_UNORM: |
| 30032 |
- |
| 30033 |
- this->metalFormat = MTLPixelFormatDepth16Unorm; |
| 30034 |
- this->actualFormatId = angle::FormatID::D16_UNORM; |
| 30035 |
- this->initFunction = nullptr; |
| 30036 |
- |
| 30037 |
- this->swizzled = false; |
| 30038 |
- break; |
| 30039 |
- |
| 30040 |
case angle::FormatID::D24_UNORM_S8_UINT: |
| 30041 |
|
| 30042 |
if (metalDevice.depth24Stencil8PixelFormatSupported && |
| 30043 |
@@ -1281,7 +1313,7 @@ |
| 30044 |
|
| 30045 |
case angle::FormatID::EAC_R11G11_UNORM_BLOCK: |
| 30046 |
|
| 30047 |
- this->metalFormat = MTLPixelFormatEAC_RG11Unorm; |
| 30048 |
+ this->metalFormat = MTLPixelFormatEAC_R11Unorm; |
| 30049 |
this->actualFormatId = angle::FormatID::EAC_R11G11_UNORM_BLOCK; |
| 30050 |
this->initFunction = nullptr; |
| 30051 |
|
| 30052 |
@@ -1306,6 +1338,15 @@ |
| 30053 |
this->swizzled = false; |
| 30054 |
break; |
| 30055 |
|
| 30056 |
+ case angle::FormatID::ETC1_R8G8B8_UNORM_BLOCK: |
| 30057 |
+ |
| 30058 |
+ this->metalFormat = MTLPixelFormatETC2_RGB8; |
| 30059 |
+ this->actualFormatId = angle::FormatID::ETC1_R8G8B8_UNORM_BLOCK; |
| 30060 |
+ this->initFunction = nullptr; |
| 30061 |
+ |
| 30062 |
+ this->swizzled = false; |
| 30063 |
+ break; |
| 30064 |
+ |
| 30065 |
case angle::FormatID::ETC2_R8G8B8A1_SRGB_BLOCK: |
| 30066 |
|
| 30067 |
this->metalFormat = MTLPixelFormatETC2_RGB8A1_sRGB; |
| 30068 |
@@ -1459,15 +1500,6 @@ |
| 30069 |
this->swizzled = false; |
| 30070 |
break; |
| 30071 |
|
| 30072 |
- case angle::FormatID::D16_UNORM: |
| 30073 |
- |
| 30074 |
- this->metalFormat = MTLPixelFormatDepth32Float; |
| 30075 |
- this->actualFormatId = angle::FormatID::D32_FLOAT; |
| 30076 |
- this->initFunction = nullptr; |
| 30077 |
- |
| 30078 |
- this->swizzled = false; |
| 30079 |
- break; |
| 30080 |
- |
| 30081 |
case angle::FormatID::D24_UNORM_S8_UINT: |
| 30082 |
|
| 30083 |
this->metalFormat = MTLPixelFormatDepth32Float_Stencil8; |
| 30084 |
@@ -1477,15 +1509,6 @@ |
| 30085 |
this->swizzled = false; |
| 30086 |
break; |
| 30087 |
|
| 30088 |
- case angle::FormatID::ETC1_R8G8B8_UNORM_BLOCK: |
| 30089 |
- |
| 30090 |
- this->metalFormat = MTLPixelFormatETC2_RGB8; |
| 30091 |
- this->actualFormatId = angle::FormatID::ETC2_R8G8B8_UNORM_BLOCK; |
| 30092 |
- this->initFunction = nullptr; |
| 30093 |
- |
| 30094 |
- this->swizzled = false; |
| 30095 |
- break; |
| 30096 |
- |
| 30097 |
#endif // TARGET_OS_OSX || TARGET_OS_MACCATALYST |
| 30098 |
default: |
| 30099 |
this->metalFormat = MTLPixelFormatInvalid; |
| 30100 |
diff --git a/src/libANGLE/renderer/metal/mtl_format_utils.h b/src/libANGLE/renderer/metal/mtl_format_utils.h |
| 30101 |
index bbb27d4..f39681d 100644 |
| 30102 |
--- a/src/libANGLE/renderer/metal/mtl_format_utils.h |
| 30103 |
+++ b/src/libANGLE/renderer/metal/mtl_format_utils.h |
| 30104 |
@@ -55,6 +55,11 @@ struct FormatCaps |
| 30105 |
bool blendable = false; |
| 30106 |
bool multisample = false; // can be used as MSAA target |
| 30107 |
bool resolve = false; // Can be used as resolve target |
| 30108 |
+ bool compressed = false; |
| 30109 |
+ NSUInteger pixelBytes = 0; |
| 30110 |
+ NSUInteger pixelBytesMSAA = 0; |
| 30111 |
+ NSUInteger channels = 0; |
| 30112 |
+ uint8_t alignment = 0; |
| 30113 |
}; |
| 30114 |
|
| 30115 |
// Pixel format |
| 30116 |
@@ -143,6 +148,7 @@ class FormatTable final : angle::NonCopyable |
| 30117 |
private: |
| 30118 |
void initNativeFormatCapsAutogen(const DisplayMtl *display); |
| 30119 |
void initNativeFormatCaps(const DisplayMtl *display); |
| 30120 |
+ |
| 30121 |
void setFormatCaps(MTLPixelFormat formatId, |
| 30122 |
bool filterable, |
| 30123 |
bool writable, |
| 30124 |
@@ -150,6 +156,17 @@ class FormatTable final : angle::NonCopyable |
| 30125 |
bool multisample, |
| 30126 |
bool resolve, |
| 30127 |
bool colorRenderable); |
| 30128 |
+ |
| 30129 |
+ void setFormatCaps(MTLPixelFormat formatId, |
| 30130 |
+ bool filterable, |
| 30131 |
+ bool writable, |
| 30132 |
+ bool blendable, |
| 30133 |
+ bool multisample, |
| 30134 |
+ bool resolve, |
| 30135 |
+ bool colorRenderable, |
| 30136 |
+ NSUInteger bytesPerChannel, |
| 30137 |
+ NSUInteger channels); |
| 30138 |
+ |
| 30139 |
void setFormatCaps(MTLPixelFormat formatId, |
| 30140 |
bool filterable, |
| 30141 |
bool writable, |
| 30142 |
@@ -159,8 +176,24 @@ class FormatTable final : angle::NonCopyable |
| 30143 |
bool colorRenderable, |
| 30144 |
bool depthRenderable); |
| 30145 |
|
| 30146 |
+ void setFormatCaps(MTLPixelFormat formatId, |
| 30147 |
+ bool filterable, |
| 30148 |
+ bool writable, |
| 30149 |
+ bool blendable, |
| 30150 |
+ bool multisample, |
| 30151 |
+ bool resolve, |
| 30152 |
+ bool colorRenderable, |
| 30153 |
+ bool depthRenderable, |
| 30154 |
+ NSUInteger bytesPerChannel, |
| 30155 |
+ NSUInteger channels); |
| 30156 |
+ |
| 30157 |
void setCompressedFormatCaps(MTLPixelFormat formatId, bool filterable); |
| 30158 |
|
| 30159 |
+ void adjustFormatCapsForDevice(id<MTLDevice> device, |
| 30160 |
+ MTLPixelFormat id, |
| 30161 |
+ bool supportsiOS2, |
| 30162 |
+ bool supportsiOS4); |
| 30163 |
+ |
| 30164 |
std::array<Format, angle::kNumANGLEFormats> mPixelFormatTable; |
| 30165 |
std::unordered_map<MTLPixelFormat, FormatCaps> mNativePixelFormatCapsTable; |
| 30166 |
// One for tightly packed buffers, one for general cases. |
| 30167 |
diff --git a/src/libANGLE/renderer/metal/mtl_format_utils.mm b/src/libANGLE/renderer/metal/mtl_format_utils.mm |
| 30168 |
index fb1d5ca..416ad5c 100644 |
| 30169 |
--- a/src/libANGLE/renderer/metal/mtl_format_utils.mm |
| 30170 |
+++ b/src/libANGLE/renderer/metal/mtl_format_utils.mm |
| 30171 |
@@ -77,8 +77,8 @@ void GenerateTextureCapsMap(const FormatTable &formatTable, |
| 30172 |
textureCaps.renderbuffer = |
| 30173 |
mtlFormat.getCaps().colorRenderable || mtlFormat.getCaps().depthRenderable; |
| 30174 |
textureCaps.texturable = true; |
| 30175 |
- textureCaps.blendable = mtlFormat.getCaps().blendable; |
| 30176 |
textureCaps.textureAttachment = textureCaps.renderbuffer; |
| 30177 |
+ textureCaps.blendable = mtlFormat.getCaps().blendable; |
| 30178 |
} |
| 30179 |
|
| 30180 |
if (formatCaps.multisample) |
| 30181 |
@@ -148,12 +148,6 @@ void GenerateTextureCapsMap(const FormatTable &formatTable, |
| 30182 |
// WebGL allows unswizzled mapping when swizzling is not available. No need to convert. |
| 30183 |
return false; |
| 30184 |
} |
| 30185 |
- if (srcFormatId == angle::FormatID::ETC1_R8G8B8_UNORM_BLOCK && |
| 30186 |
- actualFormatId == angle::FormatID::ETC2_R8G8B8_UNORM_BLOCK) |
| 30187 |
- { |
| 30188 |
- // ETC1 RGB & ETC2 RGB are technically the same. |
| 30189 |
- return false; |
| 30190 |
- } |
| 30191 |
return srcFormatId != actualFormatId; |
| 30192 |
} |
| 30193 |
|
| 30194 |
@@ -192,8 +186,7 @@ void GenerateTextureCapsMap(const FormatTable &formatTable, |
| 30195 |
mPixelFormatTable[i].init(display, formatId); |
| 30196 |
mPixelFormatTable[i].caps = &mNativePixelFormatCapsTable[mPixelFormatTable[i].metalFormat]; |
| 30197 |
|
| 30198 |
- if (!mPixelFormatTable[i].caps->depthRenderable && |
| 30199 |
- mPixelFormatTable[i].actualFormatId != mPixelFormatTable[i].intendedFormatId) |
| 30200 |
+ if (mPixelFormatTable[i].actualFormatId != mPixelFormatTable[i].intendedFormatId) |
| 30201 |
{ |
| 30202 |
mPixelFormatTable[i].textureLoadFunctions = angle::GetLoadFunctionsMap( |
| 30203 |
mPixelFormatTable[i].intendedAngleFormat().glInternalFormat, |
| 30204 |
@@ -204,6 +197,19 @@ void GenerateTextureCapsMap(const FormatTable &formatTable, |
| 30205 |
mVertexFormatTables[1][i].init(formatId, true); |
| 30206 |
} |
| 30207 |
|
| 30208 |
+ // NOTE(hqle): Work-around AMD's issue that D24S8 format sometimes returns zero during sampling: |
| 30209 |
+ if (display->getRendererDescription().find("AMD") != std::string::npos) |
| 30210 |
+ { |
| 30211 |
+ // Fallback to D32_FLOAT_S8X24_UINT. |
| 30212 |
+ Format &format = |
| 30213 |
+ mPixelFormatTable[static_cast<uint32_t>(angle::FormatID::D24_UNORM_S8_UINT)]; |
| 30214 |
+ format.actualFormatId = angle::FormatID::D32_FLOAT_S8X24_UINT; |
| 30215 |
+ format.metalFormat = MTLPixelFormatDepth32Float_Stencil8; |
| 30216 |
+ format.initFunction = nullptr; |
| 30217 |
+ format.textureLoadFunctions = nullptr; |
| 30218 |
+ format.caps = &mNativePixelFormatCapsTable[MTLPixelFormatDepth32Float_Stencil8]; |
| 30219 |
+ } |
| 30220 |
+ |
| 30221 |
return angle::Result::Continue; |
| 30222 |
} |
| 30223 |
|
| 30224 |
@@ -239,10 +245,23 @@ void GenerateTextureCapsMap(const FormatTable &formatTable, |
| 30225 |
bool colorRenderable) |
| 30226 |
{ |
| 30227 |
setFormatCaps(formatId, filterable, writable, blendable, multisample, resolve, colorRenderable, |
| 30228 |
- false); |
| 30229 |
+ false, 0); |
| 30230 |
+} |
| 30231 |
+void FormatTable::setFormatCaps(MTLPixelFormat formatId, |
| 30232 |
+ bool filterable, |
| 30233 |
+ bool writable, |
| 30234 |
+ bool blendable, |
| 30235 |
+ bool multisample, |
| 30236 |
+ bool resolve, |
| 30237 |
+ bool colorRenderable, |
| 30238 |
+ NSUInteger pixelBytes, |
| 30239 |
+ NSUInteger channels) |
| 30240 |
+{ |
| 30241 |
+ setFormatCaps(formatId, filterable, writable, blendable, multisample, resolve, colorRenderable, |
| 30242 |
+ false, pixelBytes, channels); |
| 30243 |
} |
| 30244 |
|
| 30245 |
-void FormatTable::setFormatCaps(MTLPixelFormat id, |
| 30246 |
+void FormatTable::setFormatCaps(MTLPixelFormat formatId, |
| 30247 |
bool filterable, |
| 30248 |
bool writable, |
| 30249 |
bool blendable, |
| 30250 |
@@ -250,6 +269,20 @@ void GenerateTextureCapsMap(const FormatTable &formatTable, |
| 30251 |
bool resolve, |
| 30252 |
bool colorRenderable, |
| 30253 |
bool depthRenderable) |
| 30254 |
+{ |
| 30255 |
+ setFormatCaps(formatId, filterable, writable, blendable, multisample, resolve, colorRenderable, |
| 30256 |
+ depthRenderable, 0, 0); |
| 30257 |
+} |
| 30258 |
+void FormatTable::setFormatCaps(MTLPixelFormat id, |
| 30259 |
+ bool filterable, |
| 30260 |
+ bool writable, |
| 30261 |
+ bool blendable, |
| 30262 |
+ bool multisample, |
| 30263 |
+ bool resolve, |
| 30264 |
+ bool colorRenderable, |
| 30265 |
+ bool depthRenderable, |
| 30266 |
+ NSUInteger pixelBytes, |
| 30267 |
+ NSUInteger channels) |
| 30268 |
{ |
| 30269 |
mNativePixelFormatCapsTable[id].filterable = filterable; |
| 30270 |
mNativePixelFormatCapsTable[id].writable = writable; |
| 30271 |
@@ -258,6 +291,11 @@ void GenerateTextureCapsMap(const FormatTable &formatTable, |
| 30272 |
mNativePixelFormatCapsTable[id].blendable = blendable; |
| 30273 |
mNativePixelFormatCapsTable[id].multisample = multisample; |
| 30274 |
mNativePixelFormatCapsTable[id].resolve = resolve; |
| 30275 |
+ mNativePixelFormatCapsTable[id].pixelBytes = pixelBytes; |
| 30276 |
+ mNativePixelFormatCapsTable[id].pixelBytesMSAA = pixelBytes; |
| 30277 |
+ mNativePixelFormatCapsTable[id].channels = channels; |
| 30278 |
+ if (channels != 0) |
| 30279 |
+ mNativePixelFormatCapsTable[id].alignment = MAX(pixelBytes / channels, 1U); |
| 30280 |
} |
| 30281 |
|
| 30282 |
void FormatTable::setCompressedFormatCaps(MTLPixelFormat formatId, bool filterable) |
| 30283 |
@@ -265,9 +303,274 @@ void GenerateTextureCapsMap(const FormatTable &formatTable, |
| 30284 |
setFormatCaps(formatId, filterable, false, false, false, false, false, false); |
| 30285 |
} |
| 30286 |
|
| 30287 |
+void FormatTable::adjustFormatCapsForDevice(id<MTLDevice> device, |
| 30288 |
+ MTLPixelFormat id, |
| 30289 |
+ bool supportsiOS2, |
| 30290 |
+ bool supportsiOS4) |
| 30291 |
+{ |
| 30292 |
+#if !(TARGET_OS_OSX || TARGET_OS_MACCATALYST) |
| 30293 |
+ |
| 30294 |
+ NSUInteger pixelBytesRender = mNativePixelFormatCapsTable[id].pixelBytes; |
| 30295 |
+ NSUInteger pixelBytesRenderMSAA = mNativePixelFormatCapsTable[id].pixelBytesMSAA; |
| 30296 |
+ NSUInteger alignment = mNativePixelFormatCapsTable[id].alignment; |
| 30297 |
+ |
| 30298 |
+// Override the current pixelBytesRender |
| 30299 |
+# define SPECIFIC(_pixelFormat, _pixelBytesRender) \ |
| 30300 |
+ case _pixelFormat: \ |
| 30301 |
+ pixelBytesRender = _pixelBytesRender; \ |
| 30302 |
+ pixelBytesRenderMSAA = _pixelBytesRender; \ |
| 30303 |
+ alignment = \ |
| 30304 |
+ supportsiOS4 ? _pixelBytesRender / mNativePixelFormatCapsTable[id].channels : 4; \ |
| 30305 |
+ break |
| 30306 |
+// Override the current pixel bytes render, and MSAA |
| 30307 |
+# define SPECIFIC_MSAA(_pixelFormat, _pixelBytesRender, _pixelBytesRenderMSAA) \ |
| 30308 |
+ case _pixelFormat: \ |
| 30309 |
+ pixelBytesRender = _pixelBytesRender; \ |
| 30310 |
+ pixelBytesRenderMSAA = _pixelBytesRenderMSAA; \ |
| 30311 |
+ alignment = \ |
| 30312 |
+ supportsiOS4 ? _pixelBytesRender / mNativePixelFormatCapsTable[id].channels : 4; \ |
| 30313 |
+ break |
| 30314 |
+// Override the current pixelBytesRender, and alignment |
| 30315 |
+# define SPECIFIC_ALIGN(_pixelFormat, _pixelBytesRender, _alignment) \ |
| 30316 |
+ case _pixelFormat: \ |
| 30317 |
+ pixelBytesRender = _pixelBytesRender; \ |
| 30318 |
+ pixelBytesRenderMSAA = _pixelBytesRender; \ |
| 30319 |
+ alignment = _alignment; \ |
| 30320 |
+ break |
| 30321 |
+ |
| 30322 |
+ if (!mNativePixelFormatCapsTable[id].compressed) |
| 30323 |
+ { |
| 30324 |
+ // On AppleGPUFamily4+, there is no 4byte minimum requirement for render targets |
| 30325 |
+ uint32_t minSize = supportsiOS4 ? 1U : 4U; |
| 30326 |
+ pixelBytesRender = MAX(mNativePixelFormatCapsTable[id].pixelBytes, minSize); |
| 30327 |
+ pixelBytesRenderMSAA = pixelBytesRender; |
| 30328 |
+ alignment = |
| 30329 |
+ supportsiOS4 ? MAX(pixelBytesRender / mNativePixelFormatCapsTable[id].channels, 1U) : 4; |
| 30330 |
+ } |
| 30331 |
+ |
| 30332 |
+ // This list of tables starts from a general multi-platform table, |
| 30333 |
+ // to specific platforms (i.e. ios2, ios4) inheriting from the previous tables |
| 30334 |
+ |
| 30335 |
+ // Start off with the general case |
| 30336 |
+ switch ((NSUInteger)id) |
| 30337 |
+ { |
| 30338 |
+ SPECIFIC(MTLPixelFormatB5G6R5Unorm, 4U); |
| 30339 |
+ SPECIFIC(MTLPixelFormatA1BGR5Unorm, 4U); |
| 30340 |
+ SPECIFIC(MTLPixelFormatABGR4Unorm, 4U); |
| 30341 |
+ SPECIFIC(MTLPixelFormatBGR5A1Unorm, 4U); |
| 30342 |
+ |
| 30343 |
+ SPECIFIC(MTLPixelFormatRGBA8Unorm, 4U); |
| 30344 |
+ SPECIFIC(MTLPixelFormatBGRA8Unorm, 4U); |
| 30345 |
+ |
| 30346 |
+ SPECIFIC_MSAA(MTLPixelFormatRGBA8Unorm_sRGB, 4U, 8U); |
| 30347 |
+ SPECIFIC_MSAA(MTLPixelFormatBGRA8Unorm_sRGB, 4U, 8U); |
| 30348 |
+ SPECIFIC_MSAA(MTLPixelFormatRGBA8Snorm, 4U, 8U); |
| 30349 |
+ SPECIFIC_MSAA(MTLPixelFormatRGB10A2Uint, 4U, 8U); |
| 30350 |
+ |
| 30351 |
+ SPECIFIC(MTLPixelFormatRGB10A2Unorm, 8U); |
| 30352 |
+ SPECIFIC(MTLPixelFormatBGR10A2Unorm, 8U); |
| 30353 |
+ |
| 30354 |
+ SPECIFIC(MTLPixelFormatRG11B10Float, 8U); |
| 30355 |
+ |
| 30356 |
+ SPECIFIC(MTLPixelFormatRGB9E5Float, 8U); |
| 30357 |
+ |
| 30358 |
+ SPECIFIC(MTLPixelFormatStencil8, 1U); |
| 30359 |
+ } |
| 30360 |
+ |
| 30361 |
+ // Override based ios2 |
| 30362 |
+ if (supportsiOS2) |
| 30363 |
+ { |
| 30364 |
+ switch ((NSUInteger)id) |
| 30365 |
+ { |
| 30366 |
+ SPECIFIC(MTLPixelFormatB5G6R5Unorm, 8U); |
| 30367 |
+ SPECIFIC(MTLPixelFormatA1BGR5Unorm, 8U); |
| 30368 |
+ SPECIFIC(MTLPixelFormatABGR4Unorm, 8U); |
| 30369 |
+ SPECIFIC(MTLPixelFormatBGR5A1Unorm, 8U); |
| 30370 |
+ SPECIFIC_MSAA(MTLPixelFormatRGBA8Unorm, 4U, 8U); |
| 30371 |
+ SPECIFIC_MSAA(MTLPixelFormatBGRA8Unorm, 4U, 8U); |
| 30372 |
+ } |
| 30373 |
+ } |
| 30374 |
+ |
| 30375 |
+ // Override based on ios4 |
| 30376 |
+ if (supportsiOS4) |
| 30377 |
+ { |
| 30378 |
+ switch ((NSUInteger)id) |
| 30379 |
+ { |
| 30380 |
+ SPECIFIC_ALIGN(MTLPixelFormatB5G6R5Unorm, 6U, 2U); |
| 30381 |
+ SPECIFIC(MTLPixelFormatRGBA8Unorm, 4U); |
| 30382 |
+ SPECIFIC(MTLPixelFormatBGRA8Unorm, 4U); |
| 30383 |
+ |
| 30384 |
+ SPECIFIC(MTLPixelFormatRGBA8Unorm_sRGB, 4U); |
| 30385 |
+ SPECIFIC(MTLPixelFormatBGRA8Unorm_sRGB, 4U); |
| 30386 |
+ |
| 30387 |
+ SPECIFIC(MTLPixelFormatRGBA8Snorm, 4U); |
| 30388 |
+ |
| 30389 |
+ SPECIFIC_ALIGN(MTLPixelFormatRGB10A2Unorm, 4U, 4U); |
| 30390 |
+ SPECIFIC_ALIGN(MTLPixelFormatBGR10A2Unorm, 4U, 4U); |
| 30391 |
+ SPECIFIC(MTLPixelFormatRGB10A2Uint, 8U); |
| 30392 |
+ |
| 30393 |
+ SPECIFIC_ALIGN(MTLPixelFormatRG11B10Float, 4U, 4U); |
| 30394 |
+ |
| 30395 |
+ SPECIFIC_ALIGN(MTLPixelFormatRGB9E5Float, 4U, 4U); |
| 30396 |
+ } |
| 30397 |
+ } |
| 30398 |
+ mNativePixelFormatCapsTable[id].pixelBytes = pixelBytesRender; |
| 30399 |
+ mNativePixelFormatCapsTable[id].pixelBytesMSAA = pixelBytesRenderMSAA; |
| 30400 |
+ mNativePixelFormatCapsTable[id].alignment = alignment; |
| 30401 |
+ |
| 30402 |
+# undef SPECIFIC |
| 30403 |
+# undef SPECIFIC_ALIGN |
| 30404 |
+# undef SPECIFIC_MSAA |
| 30405 |
+#endif |
| 30406 |
+ // macOS does not need to perform any additoinal adjustment. These values are only used to check |
| 30407 |
+ // valid MRT sizes on iOS. |
| 30408 |
+} |
| 30409 |
+ |
| 30410 |
void FormatTable::initNativeFormatCaps(const DisplayMtl *display) |
| 30411 |
{ |
| 30412 |
- initNativeFormatCapsAutogen(display); |
| 30413 |
+ const angle::FeaturesMtl &featuresMtl = display->getFeatures(); |
| 30414 |
+ // Skip auto resolve if either hasDepth/StencilAutoResolve or allowMultisampleStoreAndResolve |
| 30415 |
+ // feature are disabled. |
| 30416 |
+ bool supportDepthAutoResolve = featuresMtl.hasDepthAutoResolve.enabled && |
| 30417 |
+ featuresMtl.allowMultisampleStoreAndResolve.enabled; |
| 30418 |
+ bool supportStencilAutoResolve = featuresMtl.hasStencilAutoResolve.enabled && |
| 30419 |
+ featuresMtl.allowMultisampleStoreAndResolve.enabled; |
| 30420 |
+ bool supportDepthStencilAutoResolve = supportDepthAutoResolve && supportStencilAutoResolve; |
| 30421 |
+ |
| 30422 |
+ // Source: https://developer.apple.com/metal/Metal-Feature-Set-Tables.pdf |
| 30423 |
+ // clang-format off |
| 30424 |
+ |
| 30425 |
+ // | formatId | filterable | writable | blendable | multisample | resolve | colorRenderable | bytesPerChannel | channel |
| 30426 |
+ setFormatCaps(MTLPixelFormatA8Unorm, true, false, false, false, false, false, 1U, 1U); |
| 30427 |
+ setFormatCaps(MTLPixelFormatR8Unorm, true, true, true, true, true, true, 1U, 1U); |
| 30428 |
+ setFormatCaps(MTLPixelFormatR8Snorm, true, true, true, true, display->supportsEitherGPUFamily(2, 1), true, 1U, 1U); |
| 30429 |
+ setFormatCaps(MTLPixelFormatR16Unorm, true, true, true, true, display->supportsEitherGPUFamily(1, 1), true, 2U, 1U); |
| 30430 |
+ setFormatCaps(MTLPixelFormatR16Snorm, true, true, true, true, display->supportsEitherGPUFamily(1, 1), true, 2U, 1U); |
| 30431 |
+ setFormatCaps(MTLPixelFormatRG8Unorm, true, true, true, true, true, true, 1U, 1U); |
| 30432 |
+ setFormatCaps(MTLPixelFormatRG8Snorm, true, true, true, true, display->supportsEitherGPUFamily(2, 1), true, 2U, 2U); |
| 30433 |
+ setFormatCaps(MTLPixelFormatRG16Unorm, true, true, true, true, display->supportsEitherGPUFamily(1, 1), true, 4U, 2U); |
| 30434 |
+ setFormatCaps(MTLPixelFormatRG16Snorm, true, true, true, true, display->supportsEitherGPUFamily(1, 1), true, 4U, 2U); |
| 30435 |
+ setFormatCaps(MTLPixelFormatRGBA16Unorm, true, true, true, true, display->supportsEitherGPUFamily(1, 1), true, 8U, 4U); |
| 30436 |
+ setFormatCaps(MTLPixelFormatRGBA16Snorm, true, true, true, true, display->supportsEitherGPUFamily(1, 1), true, 8U, 4U); |
| 30437 |
+ setFormatCaps(MTLPixelFormatRGBA16Float, true, true, true, true, true, true, 8U, 4U); |
| 30438 |
+ |
| 30439 |
+ // | formatId | filterable | writable | blendable | multisample | resolve | colorRenderable | |
| 30440 |
+ setFormatCaps(MTLPixelFormatRGBA8Unorm, true, true, true, true, true, true, 4U, 4U); |
| 30441 |
+ setFormatCaps(MTLPixelFormatRGBA8Unorm_sRGB, true, display->supportsIOSGPUFamily(2), true, true, true, true, 4U, 4U); |
| 30442 |
+ setFormatCaps(MTLPixelFormatRGBA8Snorm, true, true, true, true, display->supportsEitherGPUFamily(2, 1), true, 4U, 4U); |
| 30443 |
+ setFormatCaps(MTLPixelFormatBGRA8Unorm, true, true, true, true, true, true, 4U, 4U); |
| 30444 |
+ setFormatCaps(MTLPixelFormatBGRA8Unorm_sRGB, true, display->supportsIOSGPUFamily(2), true, true, true, true, 4U, 4U); |
| 30445 |
+ |
| 30446 |
+ // | formatId | filterable | writable | blendable | multisample | resolve | colorRenderable | |
| 30447 |
+ setFormatCaps(MTLPixelFormatR16Float, true, true, true, true, true, true, 2U, 1U); |
| 30448 |
+ setFormatCaps(MTLPixelFormatRG16Float, true, true, true, true, true, true, 4U, 2U); |
| 30449 |
+ setFormatCaps(MTLPixelFormatR32Float, display->supportsEitherGPUFamily(1,1), true, true, true, display->supportsEitherGPUFamily(1,1), true, 4U, 1U); |
| 30450 |
+ |
| 30451 |
+#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST |
| 30452 |
+ // | formatId | filterable | writable | blendable | multisample | resolve | colorRenderable | |
| 30453 |
+ setFormatCaps(MTLPixelFormatB5G6R5Unorm, true, false, true, true, true, true, 2U, 3U); |
| 30454 |
+ setFormatCaps(MTLPixelFormatABGR4Unorm, true, false, true, true, true, true, 2U, 4U); |
| 30455 |
+ setFormatCaps(MTLPixelFormatBGR5A1Unorm, true, false, true, true, true, true, 2U, 4U); |
| 30456 |
+ setFormatCaps(MTLPixelFormatA1BGR5Unorm, true, false, true, true, true, true, 2U, 4U); |
| 30457 |
+#endif |
| 30458 |
+ |
| 30459 |
+ // | formatId | filterable | writable | blendable | multisample | resolve | colorRenderable | |
| 30460 |
+ setFormatCaps(MTLPixelFormatBGR10A2Unorm, true, display->supportsEitherGPUFamily(3, 1), true, true, true, true, 4U, 4U); |
| 30461 |
+ setFormatCaps(MTLPixelFormatRGB10A2Unorm, true, display->supportsEitherGPUFamily(3, 1), true, true, true, true, 4U, 4U); |
| 30462 |
+ setFormatCaps(MTLPixelFormatRGB10A2Uint, false, display->supportsEitherGPUFamily(3, 1), false, true, false, true, 4U, 4U); |
| 30463 |
+ setFormatCaps(MTLPixelFormatRG11B10Float, true, display->supportsEitherGPUFamily(3, 1), true, true, true, true, 4U, 3U); |
| 30464 |
+ |
| 30465 |
+ // | formatId | filterable | writable | blendable | multisample | resolve | colorRenderable | |
| 30466 |
+ setFormatCaps(MTLPixelFormatRGB9E5Float, true, display->supportsIOSGPUFamily(3), display->supportsIOSGPUFamily(1), display->supportsIOSGPUFamily(1), display->supportsIOSGPUFamily(1), display->supportsIOSGPUFamily(1), 4U, 3U); |
| 30467 |
+ |
| 30468 |
+ // | formatId | filterable | writable | blendable | multisample | resolve | colorRenderable | |
| 30469 |
+ setFormatCaps(MTLPixelFormatR8Uint, false, true, false, true, false, true, 1U, 1U); |
| 30470 |
+ setFormatCaps(MTLPixelFormatR8Sint, false, true, false, true, false, true, 1U, 1U); |
| 30471 |
+ setFormatCaps(MTLPixelFormatR16Uint, false, true, false, true, false, true, 2U, 1U); |
| 30472 |
+ setFormatCaps(MTLPixelFormatR16Sint, false, true, false, true, false, true, 4U, 1U); |
| 30473 |
+ setFormatCaps(MTLPixelFormatRG8Uint, false, true, false, true, false, true, 2U, 2U); |
| 30474 |
+ setFormatCaps(MTLPixelFormatRG8Sint, false, true, false, true, false, true, 2U, 2U); |
| 30475 |
+ setFormatCaps(MTLPixelFormatR32Uint, false, true, false, display->supportsEitherGPUFamily(1,1), false, true, 4U, 1U); |
| 30476 |
+ setFormatCaps(MTLPixelFormatR32Sint, false, true, false, display->supportsEitherGPUFamily(1,1), false, true, 4U, 1U); |
| 30477 |
+ setFormatCaps(MTLPixelFormatRG16Uint, false, true, false, true, false, true, 4U, 2U); |
| 30478 |
+ setFormatCaps(MTLPixelFormatRG16Sint, false, true, false, true, false, true, 4U, 2U); |
| 30479 |
+ setFormatCaps(MTLPixelFormatRGBA8Uint, false, true, false, true, false, true, 4U, 1U); |
| 30480 |
+ setFormatCaps(MTLPixelFormatRGBA8Sint, false, true, false, true, false, true, 4U, 1U); |
| 30481 |
+ setFormatCaps(MTLPixelFormatRG32Uint, false, true, false, display->supportsEitherGPUFamily(1,1), false, true, 8U, 2U); |
| 30482 |
+ setFormatCaps(MTLPixelFormatRG32Sint, false, true, false, display->supportsEitherGPUFamily(1,1), false, true, 8U, 2U); |
| 30483 |
+ setFormatCaps(MTLPixelFormatRGBA16Uint, false, true, false, true, false, true, 8U, 4U); |
| 30484 |
+ setFormatCaps(MTLPixelFormatRGBA16Sint, false, true, false, true, false, true, 8U, 4U); |
| 30485 |
+ setFormatCaps(MTLPixelFormatRGBA32Uint, false, true, false, display->supportsEitherGPUFamily(1,1), false, true, 16U, 4U); |
| 30486 |
+ setFormatCaps(MTLPixelFormatRGBA32Sint, false, true, false, display->supportsEitherGPUFamily(1,1), false, true, 16U, 4U); |
| 30487 |
+ |
| 30488 |
+ // | formatId | filterable | writable | blendable | multisample | resolve | colorRenderable | |
| 30489 |
+ setFormatCaps(MTLPixelFormatRG32Float, display->supportsEitherGPUFamily(1,1), true, true, display->supportsEitherGPUFamily(1,1), display->supportsEitherGPUFamily(1,1), true, 8U, 2U); |
| 30490 |
+ setFormatCaps(MTLPixelFormatRGBA32Float, display->supportsEitherGPUFamily(1,1), true, display->supportsEitherGPUFamily(1,1), display->supportsEitherGPUFamily(1,1), display->supportsEitherGPUFamily(1,1), true, 16U, 4U); |
| 30491 |
+ |
| 30492 |
+ // | formatId | filterable | writable | blendable | multisample | resolve | colorRenderable | depthRenderable | |
| 30493 |
+ setFormatCaps(MTLPixelFormatDepth32Float, display->supportsEitherGPUFamily(1,1), false, false, true, supportDepthAutoResolve, false, true, 4U, 1U); |
| 30494 |
+ setFormatCaps(MTLPixelFormatStencil8, false, false, false, true, false, false, true, 1U, 1U); |
| 30495 |
+ setFormatCaps(MTLPixelFormatDepth32Float_Stencil8, display->supportsEitherGPUFamily(1,1), false, false, true, supportDepthStencilAutoResolve, false, true, 8U, 2U); |
| 30496 |
+//ToDo: @available on 13.0 |
| 30497 |
+ setFormatCaps(MTLPixelFormatDepth16Unorm, true, false, false, true, supportDepthAutoResolve, false, true, 2U, 1U); |
| 30498 |
+#if TARGET_OS_OSX || TARGET_OS_MACCATALYST |
| 30499 |
+ setFormatCaps(MTLPixelFormatDepth24Unorm_Stencil8, display->supportsEitherGPUFamily(1,1), false, false, true, supportDepthStencilAutoResolve, false, display->supportsEitherGPUFamily(1,1), 4U, 2U); |
| 30500 |
+ |
| 30501 |
+ setCompressedFormatCaps(MTLPixelFormatBC1_RGBA, true); |
| 30502 |
+ setCompressedFormatCaps(MTLPixelFormatBC1_RGBA_sRGB, true); |
| 30503 |
+ setCompressedFormatCaps(MTLPixelFormatBC2_RGBA, true); |
| 30504 |
+ setCompressedFormatCaps(MTLPixelFormatBC2_RGBA_sRGB, true); |
| 30505 |
+ setCompressedFormatCaps(MTLPixelFormatBC3_RGBA, true); |
| 30506 |
+ setCompressedFormatCaps(MTLPixelFormatBC3_RGBA_sRGB, true); |
| 30507 |
+#else |
| 30508 |
+ setCompressedFormatCaps(MTLPixelFormatPVRTC_RGB_2BPP, true); |
| 30509 |
+ setCompressedFormatCaps(MTLPixelFormatPVRTC_RGB_2BPP_sRGB, true); |
| 30510 |
+ setCompressedFormatCaps(MTLPixelFormatPVRTC_RGB_4BPP, true); |
| 30511 |
+ setCompressedFormatCaps(MTLPixelFormatPVRTC_RGB_4BPP_sRGB, true); |
| 30512 |
+ setCompressedFormatCaps(MTLPixelFormatPVRTC_RGBA_2BPP, true); |
| 30513 |
+ setCompressedFormatCaps(MTLPixelFormatPVRTC_RGBA_2BPP_sRGB, true); |
| 30514 |
+ setCompressedFormatCaps(MTLPixelFormatPVRTC_RGBA_4BPP, true); |
| 30515 |
+ setCompressedFormatCaps(MTLPixelFormatPVRTC_RGBA_4BPP_sRGB, true); |
| 30516 |
+ setCompressedFormatCaps(MTLPixelFormatEAC_R11Unorm, true); |
| 30517 |
+ setCompressedFormatCaps(MTLPixelFormatEAC_R11Snorm, true); |
| 30518 |
+ setCompressedFormatCaps(MTLPixelFormatEAC_RG11Unorm, true); |
| 30519 |
+ setCompressedFormatCaps(MTLPixelFormatEAC_RG11Snorm, true); |
| 30520 |
+ setCompressedFormatCaps(MTLPixelFormatEAC_RGBA8, true); |
| 30521 |
+ setCompressedFormatCaps(MTLPixelFormatEAC_RGBA8_sRGB, true); |
| 30522 |
+ setCompressedFormatCaps(MTLPixelFormatETC2_RGB8, true); |
| 30523 |
+ setCompressedFormatCaps(MTLPixelFormatETC2_RGB8_sRGB, true); |
| 30524 |
+ setCompressedFormatCaps(MTLPixelFormatETC2_RGB8A1, true); |
| 30525 |
+ setCompressedFormatCaps(MTLPixelFormatETC2_RGB8A1_sRGB, true); |
| 30526 |
+ setCompressedFormatCaps(MTLPixelFormatASTC_4x4_sRGB, true); |
| 30527 |
+ setCompressedFormatCaps(MTLPixelFormatASTC_5x4_sRGB, true); |
| 30528 |
+ setCompressedFormatCaps(MTLPixelFormatASTC_5x5_sRGB, true); |
| 30529 |
+ setCompressedFormatCaps(MTLPixelFormatASTC_6x5_sRGB, true); |
| 30530 |
+ setCompressedFormatCaps(MTLPixelFormatASTC_6x6_sRGB, true); |
| 30531 |
+ setCompressedFormatCaps(MTLPixelFormatASTC_8x5_sRGB, true); |
| 30532 |
+ setCompressedFormatCaps(MTLPixelFormatASTC_8x6_sRGB, true); |
| 30533 |
+ setCompressedFormatCaps(MTLPixelFormatASTC_8x8_sRGB, true); |
| 30534 |
+ setCompressedFormatCaps(MTLPixelFormatASTC_10x5_sRGB, true); |
| 30535 |
+ setCompressedFormatCaps(MTLPixelFormatASTC_10x6_sRGB, true); |
| 30536 |
+ setCompressedFormatCaps(MTLPixelFormatASTC_10x8_sRGB, true); |
| 30537 |
+ setCompressedFormatCaps(MTLPixelFormatASTC_10x10_sRGB, true); |
| 30538 |
+ setCompressedFormatCaps(MTLPixelFormatASTC_12x10_sRGB, true); |
| 30539 |
+ setCompressedFormatCaps(MTLPixelFormatASTC_12x12_sRGB, true); |
| 30540 |
+ setCompressedFormatCaps(MTLPixelFormatASTC_4x4_LDR, true); |
| 30541 |
+ setCompressedFormatCaps(MTLPixelFormatASTC_5x4_LDR, true); |
| 30542 |
+ setCompressedFormatCaps(MTLPixelFormatASTC_5x5_LDR, true); |
| 30543 |
+ setCompressedFormatCaps(MTLPixelFormatASTC_6x5_LDR, true); |
| 30544 |
+ setCompressedFormatCaps(MTLPixelFormatASTC_6x6_LDR, true); |
| 30545 |
+ setCompressedFormatCaps(MTLPixelFormatASTC_8x5_LDR, true); |
| 30546 |
+ setCompressedFormatCaps(MTLPixelFormatASTC_8x6_LDR, true); |
| 30547 |
+ setCompressedFormatCaps(MTLPixelFormatASTC_8x8_LDR, true); |
| 30548 |
+ setCompressedFormatCaps(MTLPixelFormatASTC_10x5_LDR, true); |
| 30549 |
+ setCompressedFormatCaps(MTLPixelFormatASTC_10x6_LDR, true); |
| 30550 |
+ setCompressedFormatCaps(MTLPixelFormatASTC_10x8_LDR, true); |
| 30551 |
+ setCompressedFormatCaps(MTLPixelFormatASTC_10x10_LDR, true); |
| 30552 |
+ setCompressedFormatCaps(MTLPixelFormatASTC_12x10_LDR, true); |
| 30553 |
+ setCompressedFormatCaps(MTLPixelFormatASTC_12x12_LDR, true); |
| 30554 |
+#endif |
| 30555 |
+ // clang-format on |
| 30556 |
} |
| 30557 |
|
| 30558 |
} // namespace mtl |
| 30559 |
diff --git a/src/libANGLE/renderer/metal/mtl_glslang_mtl_utils.h b/src/libANGLE/renderer/metal/mtl_glslang_mtl_utils.h |
| 30560 |
new file mode 100644 |
| 30561 |
index 0000000..dbc1099 |
| 30562 |
--- /dev/null |
| 30563 |
+++ b/src/libANGLE/renderer/metal/mtl_glslang_mtl_utils.h |
| 30564 |
@@ -0,0 +1,57 @@ |
| 30565 |
+// |
| 30566 |
+// mtl_glslang_mtl_utils.h |
| 30567 |
+// ANGLE |
| 30568 |
+// |
| 30569 |
+// Created by Kyle Piddington on 11/10/20. |
| 30570 |
+// |
| 30571 |
+ |
| 30572 |
+#ifndef mtl_glslang_mtl_utils_h |
| 30573 |
+#define mtl_glslang_mtl_utils_h |
| 30574 |
+#include "libANGLE/Context.h" |
| 30575 |
+#include "libANGLE/renderer/ProgramImpl.h" |
| 30576 |
+#include "libANGLE/renderer/glslang_wrapper_utils.h" |
| 30577 |
+#include "libANGLE/renderer/metal/mtl_common.h" |
| 30578 |
+ |
| 30579 |
+namespace rx |
| 30580 |
+{ |
| 30581 |
+namespace mtl |
| 30582 |
+{ |
| 30583 |
+struct SamplerBinding |
| 30584 |
+{ |
| 30585 |
+ uint32_t textureBinding = 0; |
| 30586 |
+ uint32_t samplerBinding = 0; |
| 30587 |
+}; |
| 30588 |
+ |
| 30589 |
+struct TranslatedShaderInfo |
| 30590 |
+{ |
| 30591 |
+ void reset(); |
| 30592 |
+ // Translated Metal source code |
| 30593 |
+ std::string metalShaderSource; |
| 30594 |
+ // Metal library compiled from source code above. Used by ProgramMtl. |
| 30595 |
+ AutoObjCPtr<id<MTLLibrary>> metalLibrary; |
| 30596 |
+ std::array<SamplerBinding, kMaxGLSamplerBindings> actualSamplerBindings; |
| 30597 |
+ std::array<uint32_t, kMaxGLUBOBindings> actualUBOBindings; |
| 30598 |
+ std::array<uint32_t, kMaxShaderXFBs> actualXFBBindings; |
| 30599 |
+ bool hasUBOArgumentBuffer; |
| 30600 |
+}; |
| 30601 |
+void MSLGetShaderSource(const gl::ProgramState &programState, |
| 30602 |
+ const gl::ProgramLinkedResources &resources, |
| 30603 |
+ gl::ShaderMap<std::string> *shaderSourcesOut, |
| 30604 |
+ ShaderMapInterfaceVariableInfoMap *variableInfoMapOut); |
| 30605 |
+ |
| 30606 |
+angle::Result GlslangGetMSL(const gl::Context *glContext, |
| 30607 |
+ const gl::ProgramState &programState, |
| 30608 |
+ const gl::Caps &glCaps, |
| 30609 |
+ const gl::ShaderMap<std::string> &shaderSources, |
| 30610 |
+ const ShaderMapInterfaceVariableInfoMap &variableInfoMap, |
| 30611 |
+ gl::ShaderMap<TranslatedShaderInfo> *mslShaderInfoOut, |
| 30612 |
+ gl::ShaderMap<std::string> *mslCodeOut, |
| 30613 |
+ size_t xfbBufferCount); |
| 30614 |
+ |
| 30615 |
+// Get equivalent shadow compare mode that is used in translated msl shader. |
| 30616 |
+uint MslGetShaderShadowCompareMode(GLenum mode, GLenum func); |
| 30617 |
+ |
| 30618 |
+} // namespace mtl |
| 30619 |
+} // namespace rx |
| 30620 |
+ |
| 30621 |
+#endif /* mtl_glslang_mtl_utils_h */ |
| 30622 |
diff --git a/src/libANGLE/renderer/metal/mtl_glslang_mtl_utils.mm b/src/libANGLE/renderer/metal/mtl_glslang_mtl_utils.mm |
| 30623 |
new file mode 100644 |
| 30624 |
index 0000000..35f5bef |
| 30625 |
--- /dev/null |
| 30626 |
+++ b/src/libANGLE/renderer/metal/mtl_glslang_mtl_utils.mm |
| 30627 |
@@ -0,0 +1,241 @@ |
| 30628 |
+// |
| 30629 |
+// mgl_glslang_mtl_utils.m |
| 30630 |
+// ANGLE (static) |
| 30631 |
+// |
| 30632 |
+// Created by Kyle Piddington on 11/10/20. |
| 30633 |
+// |
| 30634 |
+ |
| 30635 |
+#import <Foundation/Foundation.h> |
| 30636 |
+ |
| 30637 |
+#include "compiler/translator/TranslatorMetalDirect.h" |
| 30638 |
+#include "libANGLE/renderer/metal/ShaderMtl.h" |
| 30639 |
+#include "libANGLE/renderer/metal/mtl_glslang_mtl_utils.h" |
| 30640 |
+ |
| 30641 |
+namespace rx |
| 30642 |
+{ |
| 30643 |
+namespace mtl |
| 30644 |
+{ |
| 30645 |
+ |
| 30646 |
+void TranslatedShaderInfo::reset() |
| 30647 |
+{ |
| 30648 |
+ metalShaderSource.clear(); |
| 30649 |
+ metalLibrary = nil; |
| 30650 |
+ hasUBOArgumentBuffer = false; |
| 30651 |
+ for (mtl::SamplerBinding &binding : actualSamplerBindings) |
| 30652 |
+ { |
| 30653 |
+ binding.textureBinding = mtl::kMaxShaderSamplers; |
| 30654 |
+ } |
| 30655 |
+ |
| 30656 |
+ for (uint32_t &binding : actualUBOBindings) |
| 30657 |
+ { |
| 30658 |
+ binding = mtl::kMaxShaderBuffers; |
| 30659 |
+ } |
| 30660 |
+ |
| 30661 |
+ for (uint32_t &binding : actualXFBBindings) |
| 30662 |
+ { |
| 30663 |
+ binding = mtl::kMaxShaderBuffers; |
| 30664 |
+ } |
| 30665 |
+} |
| 30666 |
+ |
| 30667 |
+// Original mapping of front end from sampler name to multiple sampler slots (in form of |
| 30668 |
+// slot:count pair) |
| 30669 |
+using OriginalSamplerBindingMap = |
| 30670 |
+ std::unordered_map<std::string, std::vector<std::pair<uint32_t, uint32_t>>>; |
| 30671 |
+ |
| 30672 |
+bool MappedSamplerNameNeedsUserDefinedPrefix(const std::string &originalName) |
| 30673 |
+{ |
| 30674 |
+ return originalName.find('.') == std::string::npos; |
| 30675 |
+} |
| 30676 |
+ |
| 30677 |
+static std::string MSLGetMappedSamplerName(const std::string &originalName) |
| 30678 |
+{ |
| 30679 |
+ std::string samplerName = originalName; |
| 30680 |
+ |
| 30681 |
+ // Samplers in structs are extracted. |
| 30682 |
+ std::replace(samplerName.begin(), samplerName.end(), '.', '_'); |
| 30683 |
+ |
| 30684 |
+ // Remove array elements |
| 30685 |
+ auto out = samplerName.begin(); |
| 30686 |
+ for (auto in = samplerName.begin(); in != samplerName.end(); in++) |
| 30687 |
+ { |
| 30688 |
+ if (*in == '[') |
| 30689 |
+ { |
| 30690 |
+ while (*in != ']') |
| 30691 |
+ { |
| 30692 |
+ in++; |
| 30693 |
+ ASSERT(in != samplerName.end()); |
| 30694 |
+ } |
| 30695 |
+ } |
| 30696 |
+ else |
| 30697 |
+ { |
| 30698 |
+ *out++ = *in; |
| 30699 |
+ } |
| 30700 |
+ } |
| 30701 |
+ |
| 30702 |
+ samplerName.erase(out, samplerName.end()); |
| 30703 |
+ |
| 30704 |
+ if (MappedSamplerNameNeedsUserDefinedPrefix(originalName)) |
| 30705 |
+ { |
| 30706 |
+ samplerName = sh::kUserDefinedNamePrefix + samplerName; |
| 30707 |
+ } |
| 30708 |
+ |
| 30709 |
+ return samplerName; |
| 30710 |
+} |
| 30711 |
+ |
| 30712 |
+void MSLGetShaderSource(const gl::ProgramState &programState, |
| 30713 |
+ const gl::ProgramLinkedResources &resources, |
| 30714 |
+ gl::ShaderMap<std::string> *shaderSourcesOut, |
| 30715 |
+ ShaderMapInterfaceVariableInfoMap *variableInfoMapOut) |
| 30716 |
+{ |
| 30717 |
+ for (const gl::ShaderType shaderType : gl::AllShaderTypes()) |
| 30718 |
+ { |
| 30719 |
+ gl::Shader *glShader = programState.getAttachedShader(shaderType); |
| 30720 |
+ (*shaderSourcesOut)[shaderType] = glShader ? glShader->getTranslatedSource() : ""; |
| 30721 |
+ } |
| 30722 |
+} |
| 30723 |
+ |
| 30724 |
+void GetAssignedSamplerBindings(const sh::TranslatorMetalReflection *reflection, |
| 30725 |
+ const OriginalSamplerBindingMap &originalBindings, |
| 30726 |
+ std::unordered_set<std::string> &structSamplers, |
| 30727 |
+ std::array<SamplerBinding, mtl::kMaxGLSamplerBindings> *bindings) |
| 30728 |
+{ |
| 30729 |
+ for (auto &sampler : reflection->getSamplerBindings()) |
| 30730 |
+ { |
| 30731 |
+ const std::string &name = sampler.first; |
| 30732 |
+ const uint32_t actualSamplerSlot = (uint32_t)reflection->getSamplerBinding(name); |
| 30733 |
+ const uint32_t actualTextureSlot = (uint32_t)reflection->getTextureBinding(name); |
| 30734 |
+ |
| 30735 |
+ // Assign sequential index for subsequent array elements |
| 30736 |
+ const bool structSampler = structSamplers.find(name) != structSamplers.end(); |
| 30737 |
+ const std::string mappedName = |
| 30738 |
+ structSampler ? name : MSLGetMappedSamplerName(sh::kUserDefinedNamePrefix + name); |
| 30739 |
+ auto original = originalBindings.find(mappedName); |
| 30740 |
+ if (original != originalBindings.end()) |
| 30741 |
+ { |
| 30742 |
+ const std::vector<std::pair<uint32_t, uint32_t>> &resOrignalBindings = |
| 30743 |
+ originalBindings.at(mappedName); |
| 30744 |
+ uint32_t currentTextureSlot = actualTextureSlot; |
| 30745 |
+ uint32_t currentSamplerSlot = actualSamplerSlot; |
| 30746 |
+ for (const std::pair<uint32_t, uint32_t> &originalBindingRange : resOrignalBindings) |
| 30747 |
+ { |
| 30748 |
+ SamplerBinding &actualBinding = bindings->at(originalBindingRange.first); |
| 30749 |
+ actualBinding.textureBinding = currentTextureSlot; |
| 30750 |
+ actualBinding.samplerBinding = currentSamplerSlot; |
| 30751 |
+ |
| 30752 |
+ currentTextureSlot += originalBindingRange.second; |
| 30753 |
+ currentSamplerSlot += originalBindingRange.second; |
| 30754 |
+ } |
| 30755 |
+ } |
| 30756 |
+ } |
| 30757 |
+} |
| 30758 |
+ |
| 30759 |
+sh::TranslatorMetalReflection *getReflectionFromShader(gl::Shader *shader) |
| 30760 |
+{ |
| 30761 |
+ ShaderMtl *shaderInstance = static_cast<ShaderMtl *>(shader->getImplementation()); |
| 30762 |
+ return shaderInstance->getTranslatorMetalReflection(); |
| 30763 |
+} |
| 30764 |
+ |
| 30765 |
+sh::TranslatorMetalReflection *getReflectionFromCompiler(gl::Compiler *compiler, |
| 30766 |
+ gl::ShaderType type) |
| 30767 |
+{ |
| 30768 |
+ auto compilerInstance = compiler->getInstance(type); |
| 30769 |
+ sh::TShHandleBase *base = static_cast<sh::TShHandleBase *>(compilerInstance.getHandle()); |
| 30770 |
+ auto translatorMetalDirect = base->getAsTranslatorMetalDirect(); |
| 30771 |
+ compiler->putInstance(std::move(compilerInstance)); |
| 30772 |
+ return translatorMetalDirect->getTranslatorMetalReflection(); |
| 30773 |
+} |
| 30774 |
+ |
| 30775 |
+angle::Result GlslangGetMSL(const gl::Context *glContext, |
| 30776 |
+ const gl::ProgramState &programState, |
| 30777 |
+ const gl::Caps &glCaps, |
| 30778 |
+ const gl::ShaderMap<std::string> &shaderSources, |
| 30779 |
+ const ShaderMapInterfaceVariableInfoMap &variableInfoMap, |
| 30780 |
+ gl::ShaderMap<TranslatedShaderInfo> *mslShaderInfoOut, |
| 30781 |
+ gl::ShaderMap<std::string> *mslCodeOut, |
| 30782 |
+ size_t xfbBufferCount) |
| 30783 |
+{ |
| 30784 |
+ // Retrieve original uniform buffer bindings generated by front end. We will need to do a remap. |
| 30785 |
+ std::unordered_map<std::string, uint32_t> uboOriginalBindings; |
| 30786 |
+ const std::vector<gl::InterfaceBlock> &blocks = programState.getUniformBlocks(); |
| 30787 |
+ for (uint32_t bufferIdx = 0; bufferIdx < blocks.size(); ++bufferIdx) |
| 30788 |
+ { |
| 30789 |
+ const gl::InterfaceBlock &block = blocks[bufferIdx]; |
| 30790 |
+ if (!uboOriginalBindings.count(block.mappedName)) |
| 30791 |
+ { |
| 30792 |
+ uboOriginalBindings[block.mappedName] = bufferIdx; |
| 30793 |
+ } |
| 30794 |
+ } |
| 30795 |
+ // Retrieve original sampler bindings produced by front end. |
| 30796 |
+ OriginalSamplerBindingMap originalSamplerBindings; |
| 30797 |
+ const std::vector<gl::SamplerBinding> &samplerBindings = programState.getSamplerBindings(); |
| 30798 |
+ const std::vector<gl::LinkedUniform> &uniforms = programState.getUniforms(); |
| 30799 |
+ |
| 30800 |
+ std::unordered_set<std::string> structSamplers = {}; |
| 30801 |
+ |
| 30802 |
+ for (uint32_t textureIndex = 0; textureIndex < samplerBindings.size(); ++textureIndex) |
| 30803 |
+ { |
| 30804 |
+ const gl::SamplerBinding &samplerBinding = samplerBindings[textureIndex]; |
| 30805 |
+ uint32_t uniformIndex = programState.getUniformIndexFromSamplerIndex(textureIndex); |
| 30806 |
+ const gl::LinkedUniform &samplerUniform = uniforms[uniformIndex]; |
| 30807 |
+ bool isSamplerInStruct = samplerUniform.name.find('.') != std::string::npos; |
| 30808 |
+ std::string mappedSamplerName = isSamplerInStruct |
| 30809 |
+ ? MSLGetMappedSamplerName(samplerUniform.name) |
| 30810 |
+ : MSLGetMappedSamplerName(samplerUniform.mappedName); |
| 30811 |
+ // These need to be prefixed later seperately |
| 30812 |
+ if (isSamplerInStruct) |
| 30813 |
+ structSamplers.insert(mappedSamplerName); |
| 30814 |
+ originalSamplerBindings[mappedSamplerName].push_back( |
| 30815 |
+ {textureIndex, static_cast<uint32_t>(samplerBinding.boundTextureUnits.size())}); |
| 30816 |
+ } |
| 30817 |
+ for (gl::ShaderType type : {gl::ShaderType::Vertex, gl::ShaderType::Fragment}) |
| 30818 |
+ { |
| 30819 |
+ (*mslCodeOut)[type] = shaderSources[type]; |
| 30820 |
+ (*mslShaderInfoOut)[type].metalShaderSource = shaderSources[type]; |
| 30821 |
+ gl::Shader *shader = programState.getAttachedShader(type); |
| 30822 |
+ sh::TranslatorMetalReflection *reflection = getReflectionFromShader(shader); |
| 30823 |
+ // Retrieve automatic texture slot assignments |
| 30824 |
+ if (originalSamplerBindings.size() > 0) |
| 30825 |
+ { |
| 30826 |
+ GetAssignedSamplerBindings(reflection, originalSamplerBindings, structSamplers, |
| 30827 |
+ &mslShaderInfoOut->at(type).actualSamplerBindings); |
| 30828 |
+ } |
| 30829 |
+ reflection->reset(); |
| 30830 |
+ } |
| 30831 |
+ return angle::Result::Continue; |
| 30832 |
+} |
| 30833 |
+ |
| 30834 |
+uint MslGetShaderShadowCompareMode(GLenum mode, GLenum func) |
| 30835 |
+{ |
| 30836 |
+ // See SpirvToMslCompiler::emit_header() |
| 30837 |
+ if (mode == GL_NONE) |
| 30838 |
+ { |
| 30839 |
+ return 0; |
| 30840 |
+ } |
| 30841 |
+ else |
| 30842 |
+ { |
| 30843 |
+ switch (func) |
| 30844 |
+ { |
| 30845 |
+ case GL_LESS: |
| 30846 |
+ return 1; |
| 30847 |
+ case GL_LEQUAL: |
| 30848 |
+ return 2; |
| 30849 |
+ case GL_GREATER: |
| 30850 |
+ return 3; |
| 30851 |
+ case GL_GEQUAL: |
| 30852 |
+ return 4; |
| 30853 |
+ case GL_NEVER: |
| 30854 |
+ return 5; |
| 30855 |
+ case GL_ALWAYS: |
| 30856 |
+ return 6; |
| 30857 |
+ case GL_EQUAL: |
| 30858 |
+ return 7; |
| 30859 |
+ case GL_NOTEQUAL: |
| 30860 |
+ return 8; |
| 30861 |
+ default: |
| 30862 |
+ UNREACHABLE(); |
| 30863 |
+ return 1; |
| 30864 |
+ } |
| 30865 |
+ } |
| 30866 |
+} |
| 30867 |
+} // namespace mtl |
| 30868 |
+} // namespace rx |
| 30869 |
diff --git a/src/libANGLE/renderer/metal/mtl_glslang_utils.h b/src/libANGLE/renderer/metal/mtl_glslang_utils.h |
| 30870 |
index 13c97ee..c02446a 100644 |
| 30871 |
--- a/src/libANGLE/renderer/metal/mtl_glslang_utils.h |
| 30872 |
+++ b/src/libANGLE/renderer/metal/mtl_glslang_utils.h |
| 30873 |
@@ -14,33 +14,11 @@ |
| 30874 |
#include "libANGLE/renderer/ProgramImpl.h" |
| 30875 |
#include "libANGLE/renderer/glslang_wrapper_utils.h" |
| 30876 |
#include "libANGLE/renderer/metal/mtl_common.h" |
| 30877 |
- |
| 30878 |
+#include "libANGLE/renderer/metal/mtl_glslang_mtl_utils.h" |
| 30879 |
namespace rx |
| 30880 |
{ |
| 30881 |
namespace mtl |
| 30882 |
{ |
| 30883 |
- |
| 30884 |
-struct SamplerBinding |
| 30885 |
-{ |
| 30886 |
- uint32_t textureBinding = 0; |
| 30887 |
- uint32_t samplerBinding = 0; |
| 30888 |
-}; |
| 30889 |
- |
| 30890 |
-struct TranslatedShaderInfo |
| 30891 |
-{ |
| 30892 |
- void reset(); |
| 30893 |
- |
| 30894 |
- // Translated Metal source code |
| 30895 |
- std::string metalShaderSource; |
| 30896 |
- // Metal library compiled from source code above. Used by ProgramMtl. |
| 30897 |
- AutoObjCPtr<id<MTLLibrary>> metalLibrary; |
| 30898 |
- |
| 30899 |
- std::array<SamplerBinding, kMaxGLSamplerBindings> actualSamplerBindings; |
| 30900 |
- std::array<uint32_t, kMaxGLUBOBindings> actualUBOBindings; |
| 30901 |
- std::array<uint32_t, kMaxShaderXFBs> actualXFBBindings; |
| 30902 |
- bool hasUBOArgumentBuffer; |
| 30903 |
-}; |
| 30904 |
- |
| 30905 |
// - shaderSourcesOut is result GLSL code per shader stage when XFB emulation is turned off. |
| 30906 |
// - xfbOnlyShaderSourceOut will contain vertex shader's GLSL code when XFB emulation is turned on. |
| 30907 |
void GlslangGetShaderSource(const gl::ProgramState &programState, |
| 30908 |
@@ -57,6 +35,13 @@ angle::Result GlslangGetShaderSpirvCode(ErrorHandler *context, |
| 30909 |
const ShaderMapInterfaceVariableInfoMap &variableInfoMap, |
| 30910 |
gl::ShaderMap<std::vector<uint32_t>> *shaderCodeOut); |
| 30911 |
|
| 30912 |
+angle::Result MSLGetShaderSpirvCode(ErrorHandler *context, |
| 30913 |
+ const gl::ShaderBitSet &linkedShaderStages, |
| 30914 |
+ const gl::Caps &glCaps, |
| 30915 |
+ const gl::ShaderMap<std::string> &shaderSources, |
| 30916 |
+ const ShaderMapInterfaceVariableInfoMap &variableInfoMap, |
| 30917 |
+ gl::ShaderMap<std::vector<uint32_t>> *shaderCodeOut); |
| 30918 |
+ |
| 30919 |
// Translate from SPIR-V code to Metal shader source code. |
| 30920 |
// - spirvShaderCode is SPIRV code per shader stage when XFB emulation is turned off. |
| 30921 |
// - xfbOnlySpirvCode is vertex shader's SPIRV code when XFB emulation is turned on. |
| 30922 |
@@ -70,6 +55,23 @@ angle::Result SpirvCodeToMsl(Context *context, |
| 30923 |
gl::ShaderMap<TranslatedShaderInfo> *mslShaderInfoOut, |
| 30924 |
TranslatedShaderInfo *mslXfbOnlyShaderInfoOut /** nullable */); |
| 30925 |
|
| 30926 |
+void MSLGetShaderSource(const gl::ProgramState &programState, |
| 30927 |
+ const gl::ProgramLinkedResources &resources, |
| 30928 |
+ gl::ShaderMap<std::string> *shaderSourcesOut, |
| 30929 |
+ ShaderMapInterfaceVariableInfoMap *variableInfoMapOut); |
| 30930 |
+ |
| 30931 |
+angle::Result GlslangGetMSL(Context *context, |
| 30932 |
+ const gl::ShaderBitSet &linkedShaderStages, |
| 30933 |
+ const gl::Caps &glCaps, |
| 30934 |
+ const gl::ShaderMap<std::string> &shaderSources, |
| 30935 |
+ const ShaderMapInterfaceVariableInfoMap &variableInfoMap, |
| 30936 |
+ gl::ShaderMap<TranslatedShaderInfo> *mslShaderInfoOut, |
| 30937 |
+ gl::ShaderMap<std::string> *mslCodeOut, |
| 30938 |
+ size_t xfbBufferCount); |
| 30939 |
+ |
| 30940 |
+// Get equivalent shadow compare mode that is used in translated msl shader. |
| 30941 |
+uint MslGetShaderShadowCompareMode(GLenum mode, GLenum func); |
| 30942 |
+ |
| 30943 |
} // namespace mtl |
| 30944 |
} // namespace rx |
| 30945 |
|
| 30946 |
diff --git a/src/libANGLE/renderer/metal/mtl_glslang_utils.mm b/src/libANGLE/renderer/metal/mtl_glslang_utils.mm |
| 30947 |
index caa0e56..4cf717a 100644 |
| 30948 |
--- a/src/libANGLE/renderer/metal/mtl_glslang_utils.mm |
| 30949 |
+++ b/src/libANGLE/renderer/metal/mtl_glslang_utils.mm |
| 30950 |
@@ -13,6 +13,7 @@ |
| 30951 |
#include <spirv_msl.hpp> |
| 30952 |
|
| 30953 |
#include "common/apple_platform_utils.h" |
| 30954 |
+#include "compiler/translator/TranslatorMetal.h" |
| 30955 |
#include "libANGLE/renderer/glslang_wrapper_utils.h" |
| 30956 |
#include "libANGLE/renderer/metal/DisplayMtl.h" |
| 30957 |
|
| 30958 |
@@ -22,12 +23,13 @@ |
| 30959 |
{ |
| 30960 |
namespace |
| 30961 |
{ |
| 30962 |
- |
| 30963 |
constexpr uint32_t kGlslangTextureDescSet = 0; |
| 30964 |
constexpr uint32_t kGlslangDefaultUniformAndXfbDescSet = 1; |
| 30965 |
constexpr uint32_t kGlslangDriverUniformsDescSet = 2; |
| 30966 |
constexpr uint32_t kGlslangShaderResourceDescSet = 3; |
| 30967 |
|
| 30968 |
+constexpr char kShadowSamplerCompareModesVarName[] = "ANGLEShadowCompareModes"; |
| 30969 |
+ |
| 30970 |
// Original mapping of front end from sampler name to multiple sampler slots (in form of |
| 30971 |
// slot:count pair) |
| 30972 |
using OriginalSamplerBindingMap = |
| 30973 |
@@ -56,9 +58,13 @@ void ResetGlslangProgramInterfaceInfo(GlslangProgramInterfaceInfo *programInterf |
| 30974 |
static_assert(kDriverUniformsBindingIndex != 0, "kDriverUniformsBindingIndex must not be 0"); |
| 30975 |
} |
| 30976 |
|
| 30977 |
+ |
| 30978 |
GlslangSourceOptions CreateSourceOptions() |
| 30979 |
{ |
| 30980 |
GlslangSourceOptions options; |
| 30981 |
+ options.emulateTransformFeedback = true; |
| 30982 |
+ // We can early out in the MSL once transform feedback is written |
| 30983 |
+ options.transformFeedbackEarlyReturn = true; |
| 30984 |
return options; |
| 30985 |
} |
| 30986 |
|
| 30987 |
@@ -79,8 +85,8 @@ GlslangSourceOptions CreateSourceOptions() |
| 30988 |
void BindBuffers(spirv_cross::CompilerMSL *compiler, |
| 30989 |
const spirv_cross::SmallVector<spirv_cross::Resource> &resources, |
| 30990 |
gl::ShaderType shaderType, |
| 30991 |
- const std::unordered_map<std::string, uint32_t> &uboOriginalBindings, |
| 30992 |
- const std::unordered_map<uint32_t, uint32_t> &xfbOriginalBindings, |
| 30993 |
+ const angle::HashMap<std::string, uint32_t> &uboOriginalBindings, |
| 30994 |
+ const angle::HashMap<uint32_t, uint32_t> &xfbOriginalBindings, |
| 30995 |
std::array<uint32_t, kMaxGLUBOBindings> *uboBindingsRemapOut, |
| 30996 |
std::array<uint32_t, kMaxShaderXFBs> *xfbBindingRemapOut, |
| 30997 |
bool *uboArgumentBufferUsed) |
| 30998 |
@@ -253,30 +259,50 @@ void GetAssignedSamplerBindings(const spirv_cross::CompilerMSL &compilerMsl, |
| 30999 |
} |
| 31000 |
} |
| 31001 |
|
| 31002 |
-std::string PostProcessTranslatedMsl(const std::string &translatedSource) |
| 31003 |
+std::string PostProcessTranslatedMsl(bool hasDepthSampler, const std::string &translatedSource) |
| 31004 |
{ |
| 31005 |
+ std::string source; |
| 31006 |
+ if (hasDepthSampler) |
| 31007 |
+ { |
| 31008 |
+ // Add ANGLEShadowCompareModes variable to main(), We need to add here because it is the |
| 31009 |
+ // only way without modifying spirv-cross. |
| 31010 |
+ std::regex mainDeclareRegex( |
| 31011 |
+ R"(((vertex|fragment|kernel)\s+[_a-zA-Z0-9<>]+\s+main[^\(]*\())"); |
| 31012 |
+ std::string mainDeclareReplaceStr = std::string("$1constant uniform<uint> *") + |
| 31013 |
+ kShadowSamplerCompareModesVarName + "[[buffer(" + |
| 31014 |
+ Str(kShadowSamplerCompareModesBindingIndex) + ")]], "; |
| 31015 |
+ source = std::regex_replace(translatedSource, mainDeclareRegex, mainDeclareReplaceStr); |
| 31016 |
+ } |
| 31017 |
+ else |
| 31018 |
+ { |
| 31019 |
+ source = translatedSource; |
| 31020 |
+ } |
| 31021 |
+ |
| 31022 |
// Add function_constant attribute to gl_SampleMask. |
| 31023 |
// Even though this varying is only used when ANGLECoverageMaskEnabled is true, |
| 31024 |
// the spirv-cross doesn't assign function_constant attribute to it. Thus it won't be dead-code |
| 31025 |
// removed when ANGLECoverageMaskEnabled=false. |
| 31026 |
std::string sampleMaskReplaceStr = std::string("[[sample_mask, function_constant(") + |
| 31027 |
- sh::mtl::kCoverageMaskEnabledConstName + ")]]"; |
| 31028 |
+ sh::TranslatorMetal::GetCoverageMaskEnabledConstName() + |
| 31029 |
+ ")]]"; |
| 31030 |
|
| 31031 |
// This replaces "gl_SampleMask [[sample_mask]]" |
| 31032 |
// with "gl_SampleMask [[sample_mask, function_constant(ANGLECoverageMaskEnabled)]]" |
| 31033 |
std::regex sampleMaskDeclareRegex(R"(\[\s*\[\s*sample_mask\s*\]\s*\])"); |
| 31034 |
- return std::regex_replace(translatedSource, sampleMaskDeclareRegex, sampleMaskReplaceStr); |
| 31035 |
+ return std::regex_replace(source, sampleMaskDeclareRegex, sampleMaskReplaceStr); |
| 31036 |
} |
| 31037 |
|
| 31038 |
// Customized spirv-cross compiler |
| 31039 |
class SpirvToMslCompiler : public spirv_cross::CompilerMSL |
| 31040 |
{ |
| 31041 |
public: |
| 31042 |
- SpirvToMslCompiler(std::vector<uint32_t> &&spriv) : spirv_cross::CompilerMSL(spriv) {} |
| 31043 |
+ SpirvToMslCompiler(Context *context, std::vector<uint32_t> &&spriv) |
| 31044 |
+ : spirv_cross::CompilerMSL(spriv), mContext(context) |
| 31045 |
+ {} |
| 31046 |
|
| 31047 |
void compileEx(gl::ShaderType shaderType, |
| 31048 |
- const std::unordered_map<std::string, uint32_t> &uboOriginalBindings, |
| 31049 |
- const std::unordered_map<uint32_t, uint32_t> &xfbOriginalBindings, |
| 31050 |
+ const angle::HashMap<std::string, uint32_t> &uboOriginalBindings, |
| 31051 |
+ const angle::HashMap<uint32_t, uint32_t> &xfbOriginalBindings, |
| 31052 |
const OriginalSamplerBindingMap &originalSamplerBindings, |
| 31053 |
TranslatedShaderInfo *mslShaderInfoOut) |
| 31054 |
{ |
| 31055 |
@@ -328,8 +354,7 @@ void compileEx(gl::ShaderType shaderType, |
| 31056 |
// Force discrete slot bindings for textures, default uniforms & driver uniforms |
| 31057 |
// instead of using argument buffer. |
| 31058 |
spirv_cross::CompilerMSL::add_discrete_descriptor_set(kGlslangTextureDescSet); |
| 31059 |
- spirv_cross::CompilerMSL::add_discrete_descriptor_set( |
| 31060 |
- kGlslangDefaultUniformAndXfbDescSet); |
| 31061 |
+ spirv_cross::CompilerMSL::add_discrete_descriptor_set(kGlslangDefaultUniformAndXfbDescSet); |
| 31062 |
spirv_cross::CompilerMSL::add_discrete_descriptor_set(kGlslangDriverUniformsDescSet); |
| 31063 |
} |
| 31064 |
else |
| 31065 |
@@ -340,21 +365,732 @@ void compileEx(gl::ShaderType shaderType, |
| 31066 |
|
| 31067 |
spirv_cross::CompilerMSL::set_msl_options(compOpt); |
| 31068 |
|
| 31069 |
+ addBuiltInResources(); |
| 31070 |
+ analyzeShaderVariables(); |
| 31071 |
+ |
| 31072 |
// Actual compilation |
| 31073 |
mslShaderInfoOut->metalShaderSource = |
| 31074 |
- PostProcessTranslatedMsl(spirv_cross::CompilerMSL::compile()); |
| 31075 |
+ PostProcessTranslatedMsl(mHasDepthSampler, spirv_cross::CompilerMSL::compile()); |
| 31076 |
|
| 31077 |
// Retrieve automatic texture slot assignments |
| 31078 |
GetAssignedSamplerBindings(*this, originalSamplerBindings, |
| 31079 |
&mslShaderInfoOut->actualSamplerBindings); |
| 31080 |
} |
| 31081 |
+ |
| 31082 |
+ private: |
| 31083 |
+ // Override CompilerMSL |
| 31084 |
+ void emit_header() override |
| 31085 |
+ { |
| 31086 |
+ spirv_cross::CompilerMSL::emit_header(); |
| 31087 |
+ if (!mHasDepthSampler) |
| 31088 |
+ { |
| 31089 |
+ return; |
| 31090 |
+ } |
| 31091 |
+ // Work around code for these issues: |
| 31092 |
+ // - spriv_cross always translates shadow texture's sampling to sample_compare() and doesn't |
| 31093 |
+ // take into account GL_TEXTURE_COMPARE_MODE=GL_NONE. |
| 31094 |
+ // - on macOS, explicit level of detail parameter is not supported in sample_compare(). |
| 31095 |
+ // - on devices prior to iOS GPU family 3, changing sampler's compare mode outside shader is |
| 31096 |
+ // not supported. |
| 31097 |
+ if (!mContext->getDisplay()->getFeatures().allowRuntimeSamplerCompareMode.enabled) |
| 31098 |
+ { |
| 31099 |
+ statement("#define ANGLE_MTL_NO_SAMPLER_RUNTIME_COMPARE_MODE"); |
| 31100 |
+ } |
| 31101 |
+ |
| 31102 |
+ statement("enum class ANGLECompareMode : uint"); |
| 31103 |
+ statement("{"); |
| 31104 |
+ statement(" None = 0,"); |
| 31105 |
+ statement(" Less,"); |
| 31106 |
+ statement(" LessEqual,"); |
| 31107 |
+ statement(" Greater,"); |
| 31108 |
+ statement(" GreaterEqual,"); |
| 31109 |
+ statement(" Never,"); |
| 31110 |
+ statement(" Always,"); |
| 31111 |
+ statement(" Equal,"); |
| 31112 |
+ statement(" NotEqual,"); |
| 31113 |
+ statement("};"); |
| 31114 |
+ statement(""); |
| 31115 |
+ |
| 31116 |
+ statement("template <typename T, typename UniformOrUInt>"); |
| 31117 |
+ statement("inline T ANGLEcompare(T depth, T dref, UniformOrUInt compareMode)"); |
| 31118 |
+ statement("{"); |
| 31119 |
+ statement(" ANGLECompareMode mode = static_cast<ANGLECompareMode>(compareMode);"); |
| 31120 |
+ statement(" switch (mode)"); |
| 31121 |
+ statement(" {"); |
| 31122 |
+ statement(" case ANGLECompareMode::Less:"); |
| 31123 |
+ statement(" return dref < depth;"); |
| 31124 |
+ statement(" case ANGLECompareMode::LessEqual:"); |
| 31125 |
+ statement(" return dref <= depth;"); |
| 31126 |
+ statement(" case ANGLECompareMode::Greater:"); |
| 31127 |
+ statement(" return dref > depth;"); |
| 31128 |
+ statement(" case ANGLECompareMode::GreaterEqual:"); |
| 31129 |
+ statement(" return dref >= depth;"); |
| 31130 |
+ statement(" case ANGLECompareMode::Never:"); |
| 31131 |
+ statement(" return 0;"); |
| 31132 |
+ statement(" case ANGLECompareMode::Always:"); |
| 31133 |
+ statement(" return 1;"); |
| 31134 |
+ statement(" case ANGLECompareMode::Equal:"); |
| 31135 |
+ statement(" return dref == depth;"); |
| 31136 |
+ statement(" case ANGLECompareMode::NotEqual:"); |
| 31137 |
+ statement(" return dref != depth;"); |
| 31138 |
+ statement(" default:"); |
| 31139 |
+ statement(" return 1;"); |
| 31140 |
+ statement(" }"); |
| 31141 |
+ statement("}"); |
| 31142 |
+ statement(""); |
| 31143 |
+ |
| 31144 |
+ statement("// Wrapper functions for shadow texture functions"); |
| 31145 |
+ // 2D PCF sampling |
| 31146 |
+ statement("template <typename T, typename Opt, typename UniformOrUInt>"); |
| 31147 |
+ statement("inline T ANGLEtexturePCF(depth2d<T> texture, sampler s, float2 coord, float " |
| 31148 |
+ "compare_value, Opt options, int2 offset, UniformOrUInt shadowCompareMode)"); |
| 31149 |
+ statement("{"); |
| 31150 |
+ statement("#if defined(__METAL_MACOS__)"); |
| 31151 |
+ statement(" float2 dims = float2(texture.get_width(), texture.get_height());"); |
| 31152 |
+ statement(" float2 imgCoord = coord * dims;"); |
| 31153 |
+ statement(" float2 texelSize = 1.0 / dims;"); |
| 31154 |
+ statement(" float2 weight = fract(imgCoord);"); |
| 31155 |
+ statement(" float tl = ANGLEcompare(texture.sample(s, coord, options, offset), " |
| 31156 |
+ "compare_value, shadowCompareMode);"); |
| 31157 |
+ statement(" float tr = ANGLEcompare(texture.sample(s, coord + float2(texelSize.x, 0.0), " |
| 31158 |
+ "options, offset), compare_value, shadowCompareMode);"); |
| 31159 |
+ statement(" float bl = ANGLEcompare(texture.sample(s, coord + float2(0.0, texelSize.y), " |
| 31160 |
+ "options, offset), compare_value, shadowCompareMode);"); |
| 31161 |
+ statement(" float br = ANGLEcompare(texture.sample(s, coord + texelSize, options, " |
| 31162 |
+ "offset), compare_value, shadowCompareMode);"); |
| 31163 |
+ statement(" float top = mix(tl, tr, weight.x);"); |
| 31164 |
+ statement(" float bottom = mix(bl, br, weight.x);"); |
| 31165 |
+ statement(" return mix(top, bottom, weight.y);"); |
| 31166 |
+ statement("#else // if defined(__METAL_MACOS__)"); |
| 31167 |
+ statement(" return ANGLEcompare(texture.sample(s, coord, options, offset), " |
| 31168 |
+ "compare_value, shadowCompareMode);"); |
| 31169 |
+ statement("#endif // if defined(__METAL_MACOS__)"); |
| 31170 |
+ statement("}"); |
| 31171 |
+ statement(""); |
| 31172 |
+ |
| 31173 |
+ // Cube PCF sampling |
| 31174 |
+ statement("template <typename T, typename Opt, typename UniformOrUInt>"); |
| 31175 |
+ statement("inline T ANGLEtexturePCF(depthcube<T> texture, sampler s, float3 coord, float " |
| 31176 |
+ "compare_value, Opt options, UniformOrUInt shadowCompareMode)"); |
| 31177 |
+ statement("{"); |
| 31178 |
+ statement(" // NOTE(hqle): to implement"); |
| 31179 |
+ statement(" return ANGLEcompare(texture.sample(s, coord, options), compare_value, " |
| 31180 |
+ "shadowCompareMode);"); |
| 31181 |
+ statement("}"); |
| 31182 |
+ statement(""); |
| 31183 |
+ |
| 31184 |
+ // 2D array PCF sampling |
| 31185 |
+ statement("template <typename T, typename Opt, typename UniformOrUInt>"); |
| 31186 |
+ statement( |
| 31187 |
+ "inline T ANGLEtexturePCF(depth2d_array<T> texture, sampler s, float2 coord, uint " |
| 31188 |
+ "array, float compare_value, Opt options, int2 offset, UniformOrUInt " |
| 31189 |
+ "shadowCompareMode)"); |
| 31190 |
+ statement("{"); |
| 31191 |
+ statement("#if defined(__METAL_MACOS__)"); |
| 31192 |
+ statement(" float2 dims = float2(texture.get_width(), texture.get_height());"); |
| 31193 |
+ statement(" float2 imgCoord = coord * dims;"); |
| 31194 |
+ statement(" float2 texelSize = 1.0 / dims;"); |
| 31195 |
+ statement(" float2 weight = fract(imgCoord);"); |
| 31196 |
+ statement(" float tl = ANGLEcompare(texture.sample(s, coord, array, options, offset), " |
| 31197 |
+ "compare_value, shadowCompareMode);"); |
| 31198 |
+ statement(" float tr = ANGLEcompare(texture.sample(s, coord + float2(texelSize.x, 0.0), " |
| 31199 |
+ "array, options, offset), compare_value, shadowCompareMode);"); |
| 31200 |
+ statement(" float bl = ANGLEcompare(texture.sample(s, coord + float2(0.0, texelSize.y), " |
| 31201 |
+ "array, options, offset), compare_value, shadowCompareMode);"); |
| 31202 |
+ statement(" float br = ANGLEcompare(texture.sample(s, coord + texelSize, array, " |
| 31203 |
+ "options, offset), compare_value, shadowCompareMode);"); |
| 31204 |
+ statement(" float top = mix(tl, tr, weight.x);"); |
| 31205 |
+ statement(" float bottom = mix(bl, br, weight.x);"); |
| 31206 |
+ statement(" return mix(top, bottom, weight.y);"); |
| 31207 |
+ statement("#else // if defined(__METAL_MACOS__)"); |
| 31208 |
+ statement(" return ANGLEcompare(texture.sample(s, coord, array, options, offset), " |
| 31209 |
+ "compare_value, shadowCompareMode);"); |
| 31210 |
+ statement("#endif // if defined(__METAL_MACOS__)"); |
| 31211 |
+ statement("}"); |
| 31212 |
+ statement(""); |
| 31213 |
+ |
| 31214 |
+ // 2D texture's sample_compare() wrapper |
| 31215 |
+ statement("template <typename T, typename Opt, typename UniformOrUInt>"); |
| 31216 |
+ statement("inline T ANGLEtextureCompare(depth2d<T> texture, sampler s, float2 coord, float " |
| 31217 |
+ "compare_value, Opt options, int2 offset, UniformOrUInt shadowCompareMode)"); |
| 31218 |
+ statement("{"); |
| 31219 |
+ statement( |
| 31220 |
+ "#if defined(__METAL_MACOS__) || defined(ANGLE_MTL_NO_SAMPLER_RUNTIME_COMPARE_MODE)"); |
| 31221 |
+ statement(" return ANGLEtexturePCF(texture, s, coord, compare_value, options, offset, " |
| 31222 |
+ "shadowCompareMode);"); |
| 31223 |
+ statement("#else"); |
| 31224 |
+ statement(" return texture.sample_compare(s, coord, compare_value, options, offset);"); |
| 31225 |
+ statement("#endif"); |
| 31226 |
+ statement("}"); |
| 31227 |
+ statement(""); |
| 31228 |
+ |
| 31229 |
+ statement("template <typename T, typename Opt, typename UniformOrUInt>"); |
| 31230 |
+ statement("inline T ANGLEtextureCompare(depth2d<T> texture, sampler s, float2 coord, float " |
| 31231 |
+ "compare_value, Opt options, UniformOrUInt shadowCompareMode)"); |
| 31232 |
+ statement("{"); |
| 31233 |
+ statement(" return ANGLEtextureCompare(texture, s, coord, compare_value, options, " |
| 31234 |
+ "int2(0), shadowCompareMode);"); |
| 31235 |
+ statement("}"); |
| 31236 |
+ statement(""); |
| 31237 |
+ |
| 31238 |
+ statement("template <typename T, typename UniformOrUInt>"); |
| 31239 |
+ statement("inline T ANGLEtextureCompare(depth2d<T> texture, sampler s, float2 coord, float " |
| 31240 |
+ "compare_value, int2 offset, UniformOrUInt shadowCompareMode)"); |
| 31241 |
+ statement("{"); |
| 31242 |
+ statement("#if defined(ANGLE_MTL_NO_SAMPLER_RUNTIME_COMPARE_MODE)"); |
| 31243 |
+ statement(" return ANGLEtexturePCF(texture, s, coord, compare_value, level(0), offset, " |
| 31244 |
+ "shadowCompareMode);"); |
| 31245 |
+ statement("#else"); |
| 31246 |
+ statement(" return texture.sample_compare(s, coord, compare_value, offset);"); |
| 31247 |
+ statement("#endif"); |
| 31248 |
+ statement("}"); |
| 31249 |
+ statement(""); |
| 31250 |
+ |
| 31251 |
+ // Cube texture's sample_compare() wrapper |
| 31252 |
+ statement("template <typename T, typename Opt, typename UniformOrUInt>"); |
| 31253 |
+ statement( |
| 31254 |
+ "inline T ANGLEtextureCompare(depthcube<T> texture, sampler s, float3 coord, float " |
| 31255 |
+ "compare_value, Opt options, UniformOrUInt shadowCompareMode)"); |
| 31256 |
+ statement("{"); |
| 31257 |
+ statement( |
| 31258 |
+ "#if defined(__METAL_MACOS__) || defined(ANGLE_MTL_NO_SAMPLER_RUNTIME_COMPARE_MODE)"); |
| 31259 |
+ statement(" return ANGLEtexturePCF(texture, s, coord, compare_value, options, " |
| 31260 |
+ "shadowCompareMode);"); |
| 31261 |
+ statement("#else"); |
| 31262 |
+ statement(" return texture.sample_compare(s, coord, compare_value, options);"); |
| 31263 |
+ statement("#endif"); |
| 31264 |
+ statement("}"); |
| 31265 |
+ statement(""); |
| 31266 |
+ |
| 31267 |
+ statement("template <typename T, typename UniformOrUInt>"); |
| 31268 |
+ statement( |
| 31269 |
+ "inline T ANGLEtextureCompare(depthcube<T> texture, sampler s, float3 coord, float " |
| 31270 |
+ "compare_value, UniformOrUInt shadowCompareMode)"); |
| 31271 |
+ statement("{"); |
| 31272 |
+ statement("#if defined(ANGLE_MTL_NO_SAMPLER_RUNTIME_COMPARE_MODE)"); |
| 31273 |
+ statement(" return ANGLEtexturePCF(texture, s, coord, compare_value, level(0), " |
| 31274 |
+ "shadowCompareMode);"); |
| 31275 |
+ statement("#else"); |
| 31276 |
+ statement(" return texture.sample_compare(s, coord, compare_value);"); |
| 31277 |
+ statement("#endif"); |
| 31278 |
+ statement("}"); |
| 31279 |
+ statement(""); |
| 31280 |
+ |
| 31281 |
+ // 2D array texture's sample_compare() wrapper |
| 31282 |
+ statement("template <typename T, typename Opt, typename UniformOrUInt>"); |
| 31283 |
+ statement("inline T ANGLEtextureCompare(depth2d_array<T> texture, sampler s, float2 coord, " |
| 31284 |
+ "uint array, float compare_value, Opt options, int2 offset, UniformOrUInt " |
| 31285 |
+ "shadowCompareMode)"); |
| 31286 |
+ statement("{"); |
| 31287 |
+ statement( |
| 31288 |
+ "#if defined(__METAL_MACOS__) || defined(ANGLE_MTL_NO_SAMPLER_RUNTIME_COMPARE_MODE)"); |
| 31289 |
+ statement(" return ANGLEtexturePCF(texture, s, coord, array, compare_value, options, " |
| 31290 |
+ "offset, shadowCompareMode);"); |
| 31291 |
+ statement("#else"); |
| 31292 |
+ statement( |
| 31293 |
+ " return texture.sample_compare(s, coord, array, compare_value, options, offset);"); |
| 31294 |
+ statement("#endif"); |
| 31295 |
+ statement("}"); |
| 31296 |
+ statement(""); |
| 31297 |
+ |
| 31298 |
+ statement("template <typename T, typename Opt, typename UniformOrUInt>"); |
| 31299 |
+ statement("inline T ANGLEtextureCompare(depth2d_array<T> texture, sampler s, float2 coord, " |
| 31300 |
+ "uint array, float compare_value, Opt options, UniformOrUInt shadowCompareMode)"); |
| 31301 |
+ statement("{"); |
| 31302 |
+ statement(" return ANGLEtextureCompare(texture, s, coord, array, compare_value, " |
| 31303 |
+ "options, int2(0), shadowCompareMode);"); |
| 31304 |
+ statement("}"); |
| 31305 |
+ statement(""); |
| 31306 |
+ |
| 31307 |
+ statement("template <typename T, typename UniformOrUInt>"); |
| 31308 |
+ statement("inline T ANGLEtextureCompare(depth2d_array<T> texture, sampler s, float2 coord, " |
| 31309 |
+ "uint array, float compare_value, int2 offset, UniformOrUInt " |
| 31310 |
+ "shadowCompareMode)"); |
| 31311 |
+ statement("{"); |
| 31312 |
+ statement("#if defined(ANGLE_MTL_NO_SAMPLER_RUNTIME_COMPARE_MODE)"); |
| 31313 |
+ statement(" return ANGLEtexturePCF(texture, s, coord, array, compare_value, level(0), " |
| 31314 |
+ "offset, shadowCompareMode);"); |
| 31315 |
+ statement("#else"); |
| 31316 |
+ statement(" return texture.sample_compare(s, coord, array, compare_value, offset);"); |
| 31317 |
+ statement("#endif"); |
| 31318 |
+ statement("}"); |
| 31319 |
+ statement(""); |
| 31320 |
+ |
| 31321 |
+ // 2D texture's generic sampling function |
| 31322 |
+ statement("// Wrapper functions for shadow texture functions"); |
| 31323 |
+ statement("template <typename T, typename UniformOrUInt>"); |
| 31324 |
+ statement("inline T ANGLEtexture(depth2d<T> texture, sampler s, float2 coord, int2 offset, " |
| 31325 |
+ "float compare_value, UniformOrUInt shadowCompareMode)"); |
| 31326 |
+ statement("{"); |
| 31327 |
+ statement(" if (shadowCompareMode)"); |
| 31328 |
+ statement(" {"); |
| 31329 |
+ statement(" return ANGLEtextureCompare(texture, s, coord, compare_value, offset, " |
| 31330 |
+ "shadowCompareMode);"); |
| 31331 |
+ statement(" }"); |
| 31332 |
+ statement(" else"); |
| 31333 |
+ statement(" {"); |
| 31334 |
+ statement(" return texture.sample(s, coord, offset);"); |
| 31335 |
+ statement(" }"); |
| 31336 |
+ statement("}"); |
| 31337 |
+ statement(""); |
| 31338 |
+ |
| 31339 |
+ statement("template <typename T, typename UniformOrUInt>"); |
| 31340 |
+ statement("inline T ANGLEtexture(depth2d<T> texture, sampler s, float2 coord, float " |
| 31341 |
+ "compare_value, UniformOrUInt shadowCompareMode)"); |
| 31342 |
+ statement("{"); |
| 31343 |
+ statement(" return ANGLEtexture(texture, s, coord, int2(0), compare_value, " |
| 31344 |
+ "shadowCompareMode);"); |
| 31345 |
+ statement("}"); |
| 31346 |
+ statement(""); |
| 31347 |
+ |
| 31348 |
+ statement("template <typename T, typename Opt, typename UniformOrUInt>"); |
| 31349 |
+ statement("inline T ANGLEtexture(depth2d<T> texture, sampler s, float2 coord, Opt options, " |
| 31350 |
+ "int2 offset, float compare_value, UniformOrUInt shadowCompareMode)"); |
| 31351 |
+ statement("{"); |
| 31352 |
+ statement(" if (shadowCompareMode)"); |
| 31353 |
+ statement(" {"); |
| 31354 |
+ statement(" return ANGLEtextureCompare(texture, s, coord, compare_value, options, " |
| 31355 |
+ "offset, shadowCompareMode);"); |
| 31356 |
+ statement(" }"); |
| 31357 |
+ statement(" else"); |
| 31358 |
+ statement(" {"); |
| 31359 |
+ statement(" return texture.sample(s, coord, options, offset);"); |
| 31360 |
+ statement(" }"); |
| 31361 |
+ statement("}"); |
| 31362 |
+ statement(""); |
| 31363 |
+ |
| 31364 |
+ statement("template <typename T, typename Opt, typename UniformOrUInt>"); |
| 31365 |
+ statement("inline T ANGLEtexture(depth2d<T> texture, sampler s, float2 coord, Opt options, " |
| 31366 |
+ "float compare_value, UniformOrUInt shadowCompareMode)"); |
| 31367 |
+ statement("{"); |
| 31368 |
+ statement(" return ANGLEtexture(texture, s, coord, options, int2(0), compare_value, " |
| 31369 |
+ "shadowCompareMode);"); |
| 31370 |
+ statement("}"); |
| 31371 |
+ statement(""); |
| 31372 |
+ |
| 31373 |
+ // Cube texture's generic sampling function |
| 31374 |
+ statement("template <typename T, typename UniformOrUInt>"); |
| 31375 |
+ statement("inline T ANGLEtexture(depthcube<T> texture, sampler s, float3 coord, float " |
| 31376 |
+ "compare_value, UniformOrUInt shadowCompareMode)"); |
| 31377 |
+ statement("{"); |
| 31378 |
+ statement(" if (shadowCompareMode)"); |
| 31379 |
+ statement(" {"); |
| 31380 |
+ statement(" return ANGLEtextureCompare(texture, s, coord, compare_value, " |
| 31381 |
+ "shadowCompareMode);"); |
| 31382 |
+ statement(" }"); |
| 31383 |
+ statement(" else"); |
| 31384 |
+ statement(" {"); |
| 31385 |
+ statement(" return texture.sample(s, coord);"); |
| 31386 |
+ statement(" }"); |
| 31387 |
+ statement("}"); |
| 31388 |
+ statement(""); |
| 31389 |
+ |
| 31390 |
+ statement("template <typename T, typename Opt, typename UniformOrUInt>"); |
| 31391 |
+ statement("inline T ANGLEtexture(depthcube<T> texture, sampler s, float2 coord, Opt " |
| 31392 |
+ "options, float compare_value, UniformOrUInt shadowCompareMode)"); |
| 31393 |
+ statement("{"); |
| 31394 |
+ statement(" if (shadowCompareMode)"); |
| 31395 |
+ statement(" {"); |
| 31396 |
+ statement(" return ANGLEtextureCompare(texture, s, coord, compare_value, options, " |
| 31397 |
+ "shadowCompareMode);"); |
| 31398 |
+ statement(" }"); |
| 31399 |
+ statement(" else"); |
| 31400 |
+ statement(" {"); |
| 31401 |
+ statement(" return texture.sample(s, coord, options);"); |
| 31402 |
+ statement(" }"); |
| 31403 |
+ statement("}"); |
| 31404 |
+ statement(""); |
| 31405 |
+ |
| 31406 |
+ // 2D array texture's generic sampling function |
| 31407 |
+ statement("template <typename T, typename UniformOrUInt>"); |
| 31408 |
+ statement("inline T ANGLEtexture(depth2d_array<T> texture, sampler s, float2 coord, uint " |
| 31409 |
+ "array, int2 offset, " |
| 31410 |
+ "float compare_value, UniformOrUInt shadowCompareMode)"); |
| 31411 |
+ statement("{"); |
| 31412 |
+ statement(" if (shadowCompareMode)"); |
| 31413 |
+ statement(" {"); |
| 31414 |
+ statement(" return ANGLEtextureCompare(texture, s, coord, array, compare_value, " |
| 31415 |
+ "offset, shadowCompareMode);"); |
| 31416 |
+ statement(" }"); |
| 31417 |
+ statement(" else"); |
| 31418 |
+ statement(" {"); |
| 31419 |
+ statement(" return texture.sample(s, coord, array, offset);"); |
| 31420 |
+ statement(" }"); |
| 31421 |
+ statement("}"); |
| 31422 |
+ statement(""); |
| 31423 |
+ |
| 31424 |
+ statement("template <typename T, typename UniformOrUInt>"); |
| 31425 |
+ statement("inline T ANGLEtexture(depth2d_array<T> texture, sampler s, float2 coord, uint " |
| 31426 |
+ "array, float compare_value, UniformOrUInt shadowCompareMode)"); |
| 31427 |
+ statement("{"); |
| 31428 |
+ statement(" return ANGLEtexture(texture, s, coord, array, int2(0), compare_value, " |
| 31429 |
+ "shadowCompareMode);"); |
| 31430 |
+ statement("}"); |
| 31431 |
+ statement(""); |
| 31432 |
+ |
| 31433 |
+ statement("template <typename T, typename Opt, typename UniformOrUInt>"); |
| 31434 |
+ statement("inline T ANGLEtexture(depth2d_array<T> texture, sampler s, float2 coord, uint " |
| 31435 |
+ "array, Opt options, int2 offset, " |
| 31436 |
+ "float compare_value, UniformOrUInt shadowCompareMode)"); |
| 31437 |
+ statement("{"); |
| 31438 |
+ statement(" if (shadowCompareMode)"); |
| 31439 |
+ statement(" {"); |
| 31440 |
+ statement(" return ANGLEtextureCompare(texture, s, coord, array, compare_value, " |
| 31441 |
+ "options, offset, shadowCompareMode);"); |
| 31442 |
+ statement(" }"); |
| 31443 |
+ statement(" else"); |
| 31444 |
+ statement(" {"); |
| 31445 |
+ statement(" return texture.sample(s, coord, array, options, offset);"); |
| 31446 |
+ statement(" }"); |
| 31447 |
+ statement("}"); |
| 31448 |
+ statement(""); |
| 31449 |
+ |
| 31450 |
+ statement("template <typename T, typename Opt, typename UniformOrUInt>"); |
| 31451 |
+ statement("inline T ANGLEtexture(depth2d_array<T> texture, sampler s, float2 coord, uint " |
| 31452 |
+ "array, Opt options, float compare_value, UniformOrUInt shadowCompareMode)"); |
| 31453 |
+ statement("{"); |
| 31454 |
+ statement(" return ANGLEtexture(texture, s, coord, array, options, int2(0), " |
| 31455 |
+ "compare_value, shadowCompareMode);"); |
| 31456 |
+ statement("}"); |
| 31457 |
+ statement(""); |
| 31458 |
+ } |
| 31459 |
+ |
| 31460 |
+ std::string to_function_name(spirv_cross::VariableID img, |
| 31461 |
+ const spirv_cross::SPIRType &imgType, |
| 31462 |
+ bool isFetch, |
| 31463 |
+ bool isGather, |
| 31464 |
+ bool isProj, |
| 31465 |
+ bool hasArrayOffsets, |
| 31466 |
+ bool hasOffset, |
| 31467 |
+ bool hasGrad, |
| 31468 |
+ bool hasDref, |
| 31469 |
+ uint32_t lod, |
| 31470 |
+ uint32_t minLod) override |
| 31471 |
+ { |
| 31472 |
+ if (!hasDref) |
| 31473 |
+ { |
| 31474 |
+ return spirv_cross::CompilerMSL::to_function_name(img, imgType, isFetch, isGather, |
| 31475 |
+ isProj, hasArrayOffsets, hasOffset, |
| 31476 |
+ hasGrad, hasDref, lod, minLod); |
| 31477 |
+ } |
| 31478 |
+ |
| 31479 |
+ // Use custom ANGLEtexture function instead of using built-in sample_compare() |
| 31480 |
+ return "ANGLEtexture"; |
| 31481 |
+ } |
| 31482 |
+ |
| 31483 |
+ std::string to_function_args(spirv_cross::VariableID img, |
| 31484 |
+ const spirv_cross::SPIRType &imgType, |
| 31485 |
+ bool isFetch, |
| 31486 |
+ bool isGather, |
| 31487 |
+ bool isProj, |
| 31488 |
+ uint32_t coord, |
| 31489 |
+ uint32_t coordComponents, |
| 31490 |
+ uint32_t dref, |
| 31491 |
+ uint32_t gradX, |
| 31492 |
+ uint32_t gradY, |
| 31493 |
+ uint32_t lod, |
| 31494 |
+ uint32_t coffset, |
| 31495 |
+ uint32_t offset, |
| 31496 |
+ uint32_t bias, |
| 31497 |
+ uint32_t comp, |
| 31498 |
+ uint32_t sample, |
| 31499 |
+ uint32_t minlod, |
| 31500 |
+ bool *pForward) override |
| 31501 |
+ { |
| 31502 |
+ bool forward; |
| 31503 |
+ std::string argsWithoutDref = spirv_cross::CompilerMSL::to_function_args( |
| 31504 |
+ img, imgType, isFetch, isGather, isProj, coord, coordComponents, 0, gradX, gradY, lod, |
| 31505 |
+ coffset, offset, bias, comp, sample, minlod, &forward); |
| 31506 |
+ |
| 31507 |
+ if (!dref) |
| 31508 |
+ { |
| 31509 |
+ if (pForward) |
| 31510 |
+ { |
| 31511 |
+ *pForward = forward; |
| 31512 |
+ } |
| 31513 |
+ return argsWithoutDref; |
| 31514 |
+ } |
| 31515 |
+ // Convert to arguments to ANGLEtexture. |
| 31516 |
+ std::string args = to_expression(img); |
| 31517 |
+ args += ", "; |
| 31518 |
+ args += argsWithoutDref; |
| 31519 |
+ args += ", "; |
| 31520 |
+ |
| 31521 |
+ forward = forward && should_forward(dref); |
| 31522 |
+ const spirv_cross::SPIRType &drefType = expression_type(dref); |
| 31523 |
+ std::string drefExpr; |
| 31524 |
+ uint32_t altCoordComponent = 0; |
| 31525 |
+ switch (imgType.image.dim) |
| 31526 |
+ { |
| 31527 |
+ case spv::Dim2D: |
| 31528 |
+ altCoordComponent = 2; |
| 31529 |
+ break; |
| 31530 |
+ case spv::Dim3D: |
| 31531 |
+ case spv::DimCube: |
| 31532 |
+ altCoordComponent = 3; |
| 31533 |
+ break; |
| 31534 |
+ default: |
| 31535 |
+ UNREACHABLE(); |
| 31536 |
+ break; |
| 31537 |
+ } |
| 31538 |
+ if (isProj) |
| 31539 |
+ drefExpr = spirv_cross::join(to_enclosed_expression(dref), " / ", |
| 31540 |
+ to_extract_component_expression(coord, altCoordComponent)); |
| 31541 |
+ else |
| 31542 |
+ drefExpr = to_expression(dref); |
| 31543 |
+ |
| 31544 |
+ if (drefType.basetype == spirv_cross::SPIRType::Half) |
| 31545 |
+ drefExpr = convert_to_f32(drefExpr, 1); |
| 31546 |
+ |
| 31547 |
+ args += drefExpr; |
| 31548 |
+ args += ", "; |
| 31549 |
+ args += toShadowCompareModeExpression(img); |
| 31550 |
+ |
| 31551 |
+ if (pForward) |
| 31552 |
+ { |
| 31553 |
+ *pForward = forward; |
| 31554 |
+ } |
| 31555 |
+ |
| 31556 |
+ return args; |
| 31557 |
+ } |
| 31558 |
+ |
| 31559 |
+ // Override function prototype emitter to insert shadow compare mode flag to come |
| 31560 |
+ // together with the shadow sampler. NOTE(hqle): This is just 90% copy of spirv_msl's code. |
| 31561 |
+ // The better way is modifying and creating a PR on spirv-cross repo directly. But this should |
| 31562 |
+ // be a work around solution for now. |
| 31563 |
+ void emit_function_prototype(spirv_cross::SPIRFunction &func, |
| 31564 |
+ const spirv_cross::Bitset &) override |
| 31565 |
+ { |
| 31566 |
+ // Turn off clang-format to easier compare with original code |
| 31567 |
+ // clang-format off |
| 31568 |
+ using namespace spirv_cross; |
| 31569 |
+ using namespace spv; |
| 31570 |
+ using namespace std; |
| 31571 |
+ |
| 31572 |
+ if (func.self != ir.default_entry_point) |
| 31573 |
+ add_function_overload(func); |
| 31574 |
+ |
| 31575 |
+ local_variable_names = resource_names; |
| 31576 |
+ string decl; |
| 31577 |
+ |
| 31578 |
+ processing_entry_point = func.self == ir.default_entry_point; |
| 31579 |
+ |
| 31580 |
+ // Metal helper functions must be static force-inline otherwise they will cause problems when linked together in a single Metallib. |
| 31581 |
+ if (!processing_entry_point) |
| 31582 |
+ statement("static inline __attribute__((always_inline))"); |
| 31583 |
+ |
| 31584 |
+ auto &type = get<SPIRType>(func.return_type); |
| 31585 |
+ |
| 31586 |
+ if (!type.array.empty() && msl_options.force_native_arrays) |
| 31587 |
+ { |
| 31588 |
+ // We cannot return native arrays in MSL, so "return" through an out variable. |
| 31589 |
+ decl += "void"; |
| 31590 |
+ } |
| 31591 |
+ else |
| 31592 |
+ { |
| 31593 |
+ decl += func_type_decl(type); |
| 31594 |
+ } |
| 31595 |
+ |
| 31596 |
+ decl += " "; |
| 31597 |
+ decl += to_name(func.self); |
| 31598 |
+ decl += "("; |
| 31599 |
+ |
| 31600 |
+ if (!type.array.empty() && msl_options.force_native_arrays) |
| 31601 |
+ { |
| 31602 |
+ // Fake arrays returns by writing to an out array instead. |
| 31603 |
+ decl += "thread "; |
| 31604 |
+ decl += type_to_glsl(type); |
| 31605 |
+ decl += " (&SPIRV_Cross_return_value)"; |
| 31606 |
+ decl += type_to_array_glsl(type); |
| 31607 |
+ if (!func.arguments.empty()) |
| 31608 |
+ decl += ", "; |
| 31609 |
+ } |
| 31610 |
+ |
| 31611 |
+ if (processing_entry_point) |
| 31612 |
+ { |
| 31613 |
+ if (msl_options.argument_buffers) |
| 31614 |
+ decl += entry_point_args_argument_buffer(!func.arguments.empty()); |
| 31615 |
+ else |
| 31616 |
+ decl += entry_point_args_classic(!func.arguments.empty()); |
| 31617 |
+ |
| 31618 |
+ // If entry point function has variables that require early declaration, |
| 31619 |
+ // ensure they each have an empty initializer, creating one if needed. |
| 31620 |
+ // This is done at this late stage because the initialization expression |
| 31621 |
+ // is cleared after each compilation pass. |
| 31622 |
+ for (auto var_id : vars_needing_early_declaration) |
| 31623 |
+ { |
| 31624 |
+ auto &ed_var = get<SPIRVariable>(var_id); |
| 31625 |
+ ID &initializer = ed_var.initializer; |
| 31626 |
+ if (!initializer) |
| 31627 |
+ initializer = ir.increase_bound_by(1); |
| 31628 |
+ |
| 31629 |
+ // Do not override proper initializers. |
| 31630 |
+ if (ir.ids[initializer].get_type() == TypeNone || ir.ids[initializer].get_type() == TypeExpression) |
| 31631 |
+ set<SPIRExpression>(ed_var.initializer, "{}", ed_var.basetype, true); |
| 31632 |
+ } |
| 31633 |
+ } |
| 31634 |
+ |
| 31635 |
+ for (auto &arg : func.arguments) |
| 31636 |
+ { |
| 31637 |
+ uint32_t name_id = arg.id; |
| 31638 |
+ |
| 31639 |
+ auto *var = maybe_get<SPIRVariable>(arg.id); |
| 31640 |
+ if (var) |
| 31641 |
+ { |
| 31642 |
+ // If we need to modify the name of the variable, make sure we modify the original variable. |
| 31643 |
+ // Our alias is just a shadow variable. |
| 31644 |
+ if (arg.alias_global_variable && var->basevariable) |
| 31645 |
+ name_id = var->basevariable; |
| 31646 |
+ |
| 31647 |
+ var->parameter = &arg; // Hold a pointer to the parameter so we can invalidate the readonly field if needed. |
| 31648 |
+ } |
| 31649 |
+ |
| 31650 |
+ add_local_variable_name(name_id); |
| 31651 |
+ |
| 31652 |
+ decl += argument_decl(arg); |
| 31653 |
+ |
| 31654 |
+ bool is_dynamic_img_sampler = has_extended_decoration(arg.id, SPIRVCrossDecorationDynamicImageSampler); |
| 31655 |
+ |
| 31656 |
+ auto &arg_type = get<SPIRType>(arg.type); |
| 31657 |
+ if (arg_type.basetype == SPIRType::SampledImage && !is_dynamic_img_sampler) |
| 31658 |
+ { |
| 31659 |
+ // Manufacture automatic plane args for multiplanar texture |
| 31660 |
+ uint32_t planes = 1; |
| 31661 |
+ if (auto *constexpr_sampler = find_constexpr_sampler(name_id)) |
| 31662 |
+ if (constexpr_sampler->ycbcr_conversion_enable) |
| 31663 |
+ planes = constexpr_sampler->planes; |
| 31664 |
+ for (uint32_t i = 1; i < planes; i++) |
| 31665 |
+ decl += join(", ", argument_decl(arg), plane_name_suffix, i); |
| 31666 |
+ |
| 31667 |
+ // Manufacture automatic sampler arg for SampledImage texture |
| 31668 |
+ if (arg_type.image.dim != DimBuffer) |
| 31669 |
+ decl += join(", thread const ", sampler_type(arg_type), " ", to_sampler_expression(arg.id)); |
| 31670 |
+ } |
| 31671 |
+ |
| 31672 |
+ // Manufacture automatic swizzle arg. |
| 31673 |
+ if (msl_options.swizzle_texture_samples && has_sampled_images && is_sampled_image_type(arg_type) && |
| 31674 |
+ !is_dynamic_img_sampler) |
| 31675 |
+ { |
| 31676 |
+ bool arg_is_array = !arg_type.array.empty(); |
| 31677 |
+ decl += join(", constant uint", arg_is_array ? "* " : "& ", to_swizzle_expression(arg.id)); |
| 31678 |
+ } |
| 31679 |
+ |
| 31680 |
+ if (buffers_requiring_array_length.count(name_id)) |
| 31681 |
+ { |
| 31682 |
+ bool arg_is_array = !arg_type.array.empty(); |
| 31683 |
+ decl += join(", constant uint", arg_is_array ? "* " : "& ", to_buffer_size_expression(name_id)); |
| 31684 |
+ } |
| 31685 |
+ |
| 31686 |
+ if (is_sampled_image_type(arg_type) && arg_type.image.depth) |
| 31687 |
+ { |
| 31688 |
+ bool arg_is_array = !arg_type.array.empty(); |
| 31689 |
+ // Insert shadow compare mode flag to the argument sequence: |
| 31690 |
+ decl += join(", constant uniform<uint>", arg_is_array ? "* " : "& ", |
| 31691 |
+ toShadowCompareModeExpression(arg.id)); |
| 31692 |
+ } |
| 31693 |
+ |
| 31694 |
+ if (&arg != &func.arguments.back()) |
| 31695 |
+ decl += ", "; |
| 31696 |
+ } |
| 31697 |
+ |
| 31698 |
+ decl += ")"; |
| 31699 |
+ statement(decl); |
| 31700 |
+ |
| 31701 |
+ // clang-format on |
| 31702 |
+ } |
| 31703 |
+ |
| 31704 |
+ // Override function call arguments passing generator to insert shadow compare mode flag to come |
| 31705 |
+ // together with the shadow sampler |
| 31706 |
+ std::string to_func_call_arg(const spirv_cross::SPIRFunction::Parameter &arg, |
| 31707 |
+ uint32_t id) override |
| 31708 |
+ { |
| 31709 |
+ std::string arg_str = spirv_cross::CompilerMSL::to_func_call_arg(arg, id); |
| 31710 |
+ |
| 31711 |
+ const spirv_cross::SPIRType &type = expression_type(id); |
| 31712 |
+ |
| 31713 |
+ if (is_sampled_image_type(type) && type.image.depth) |
| 31714 |
+ { |
| 31715 |
+ // Insert shadow compare mode flag to the argument sequence: |
| 31716 |
+ // Need to check the base variable in case we need to apply a qualified alias. |
| 31717 |
+ uint32_t var_id = 0; |
| 31718 |
+ auto *var = maybe_get<spirv_cross::SPIRVariable>(id); |
| 31719 |
+ if (var) |
| 31720 |
+ var_id = var->basevariable; |
| 31721 |
+ |
| 31722 |
+ arg_str += ", " + toShadowCompareModeExpression(var_id ? var_id : id); |
| 31723 |
+ } |
| 31724 |
+ return arg_str; |
| 31725 |
+ } |
| 31726 |
+ |
| 31727 |
+ // Additional functions |
| 31728 |
+ void addBuiltInResources() |
| 31729 |
+ { |
| 31730 |
+ uint32_t varId = build_constant_uint_array_pointer(); |
| 31731 |
+ set_name(varId, kShadowSamplerCompareModesVarName); |
| 31732 |
+ // This should never match anything. |
| 31733 |
+ set_decoration(varId, spv::DecorationDescriptorSet, kShadowSamplerCompareModesBindingIndex); |
| 31734 |
+ set_decoration(varId, spv::DecorationBinding, 0); |
| 31735 |
+ set_extended_decoration(varId, spirv_cross::SPIRVCrossDecorationResourceIndexPrimary, 0); |
| 31736 |
+ mANGLEShadowCompareModesVarId = varId; |
| 31737 |
+ } |
| 31738 |
+ |
| 31739 |
+ void analyzeShaderVariables() |
| 31740 |
+ { |
| 31741 |
+ ir.for_each_typed_id<spirv_cross::SPIRVariable>([this](uint32_t, |
| 31742 |
+ spirv_cross::SPIRVariable &var) { |
| 31743 |
+ const spirv_cross::SPIRType &type = get_variable_data_type(var); |
| 31744 |
+ uint32_t varId = var.self; |
| 31745 |
+ |
| 31746 |
+ if (var.storage == spv::StorageClassUniformConstant && !is_hidden_variable(var)) |
| 31747 |
+ { |
| 31748 |
+ if (is_sampled_image_type(type) && type.image.depth) |
| 31749 |
+ { |
| 31750 |
+ mHasDepthSampler = true; |
| 31751 |
+ |
| 31752 |
+ auto &entry_func = this->get<spirv_cross::SPIRFunction>(ir.default_entry_point); |
| 31753 |
+ entry_func.fixup_hooks_in.push_back([this, &type, &var, varId]() { |
| 31754 |
+ bool isArrayType = !type.array.empty(); |
| 31755 |
+ |
| 31756 |
+ statement("constant uniform<uint>", isArrayType ? "* " : "& ", |
| 31757 |
+ toShadowCompareModeExpression(varId), |
| 31758 |
+ isArrayType ? " = &" : " = ", |
| 31759 |
+ to_name(mANGLEShadowCompareModesVarId), "[", |
| 31760 |
+ spirv_cross::convert_to_string( |
| 31761 |
+ get_metal_resource_index(var, spirv_cross::SPIRType::Image)), |
| 31762 |
+ "];"); |
| 31763 |
+ }); |
| 31764 |
+ } |
| 31765 |
+ } |
| 31766 |
+ }); |
| 31767 |
+ } |
| 31768 |
+ |
| 31769 |
+ std::string toShadowCompareModeExpression(uint32_t id) |
| 31770 |
+ { |
| 31771 |
+ constexpr char kCompareModeSuffix[] = "_CompMode"; |
| 31772 |
+ auto *combined = maybe_get<spirv_cross::SPIRCombinedImageSampler>(id); |
| 31773 |
+ |
| 31774 |
+ std::string expr = to_expression(combined ? combined->image : spirv_cross::VariableID(id)); |
| 31775 |
+ auto index = expr.find_first_of('['); |
| 31776 |
+ |
| 31777 |
+ if (index == std::string::npos) |
| 31778 |
+ return expr + kCompareModeSuffix; |
| 31779 |
+ else |
| 31780 |
+ { |
| 31781 |
+ auto imageExpr = expr.substr(0, index); |
| 31782 |
+ auto arrayExpr = expr.substr(index); |
| 31783 |
+ return imageExpr + kCompareModeSuffix + arrayExpr; |
| 31784 |
+ } |
| 31785 |
+ } |
| 31786 |
+ |
| 31787 |
+ Context *mContext; |
| 31788 |
+ uint32_t mANGLEShadowCompareModesVarId = 0; |
| 31789 |
+ bool mHasDepthSampler = false; |
| 31790 |
}; |
| 31791 |
|
| 31792 |
-angle::Result ConvertSpirvToMsl( |
| 31793 |
- Context *context, |
| 31794 |
+angle::Result ConvertSpirvToMsl(Context *context, |
| 31795 |
gl::ShaderType shaderType, |
| 31796 |
- const std::unordered_map<std::string, uint32_t> &uboOriginalBindings, |
| 31797 |
- const std::unordered_map<uint32_t, uint32_t> &xfbOriginalBindings, |
| 31798 |
+ const angle::HashMap<std::string, uint32_t> &uboOriginalBindings, |
| 31799 |
+ const angle::HashMap<uint32_t, uint32_t> &xfbOriginalBindings, |
| 31800 |
const OriginalSamplerBindingMap &originalSamplerBindings, |
| 31801 |
std::vector<uint32_t> *sprivCode, |
| 31802 |
TranslatedShaderInfo *translatedShaderInfoOut) |
| 31803 |
@@ -364,7 +1100,7 @@ void compileEx(gl::ShaderType shaderType, |
| 31804 |
return angle::Result::Continue; |
| 31805 |
} |
| 31806 |
|
| 31807 |
- SpirvToMslCompiler compilerMsl(std::move(*sprivCode)); |
| 31808 |
+ SpirvToMslCompiler compilerMsl(context, std::move(*sprivCode)); |
| 31809 |
|
| 31810 |
// NOTE(hqle): spirv-cross uses exceptions to report error, what should we do here |
| 31811 |
// in case of error? |
| 31812 |
@@ -431,12 +1167,13 @@ void GlslangGetShaderSource(const gl::ProgramState &programState, |
| 31813 |
options, programState, &xfbOnlyInterfaceInfo, xfbOnlyShaderSourceOut, |
| 31814 |
&xfbOnlyVariableMaps[gl::ShaderType::Vertex]); |
| 31815 |
|
| 31816 |
- GlslangAssignLocations(options, programState.getExecutable(), gl::ShaderType::Vertex, |
| 31817 |
- &xfbOnlyInterfaceInfo, &xfbOnlyVariableMaps); |
| 31818 |
+ GlslangAssignLocations(options, programState.getExecutable(), gl::ShaderType::Vertex, &xfbOnlyInterfaceInfo, |
| 31819 |
+ &xfbOnlyVariableMaps); |
| 31820 |
*xfbOnlyVSVariableInfoMapOut = std::move(xfbOnlyVariableMaps[gl::ShaderType::Vertex]); |
| 31821 |
} |
| 31822 |
} |
| 31823 |
|
| 31824 |
+ |
| 31825 |
angle::Result GlslangGetShaderSpirvCode(ErrorHandler *context, |
| 31826 |
const gl::ShaderBitSet &linkedShaderStages, |
| 31827 |
const gl::Caps &glCaps, |
| 31828 |
@@ -478,7 +1215,7 @@ void GlslangGetShaderSource(const gl::ProgramState &programState, |
| 31829 |
TranslatedShaderInfo *mslXfbOnlyShaderInfoOut /** nullable */) |
| 31830 |
{ |
| 31831 |
// Retrieve original uniform buffer bindings generated by front end. We will need to do a remap. |
| 31832 |
- std::unordered_map<std::string, uint32_t> uboOriginalBindings; |
| 31833 |
+ angle::HashMap<std::string, uint32_t> uboOriginalBindings; |
| 31834 |
const std::vector<gl::InterfaceBlock> &blocks = programState.getUniformBlocks(); |
| 31835 |
for (uint32_t bufferIdx = 0; bufferIdx < blocks.size(); ++bufferIdx) |
| 31836 |
{ |
| 31837 |
@@ -489,7 +1226,7 @@ void GlslangGetShaderSource(const gl::ProgramState &programState, |
| 31838 |
} |
| 31839 |
} |
| 31840 |
// Retrieve original XFB buffers bindings produced by front end. |
| 31841 |
- std::unordered_map<uint32_t, uint32_t> xfbOriginalBindings; |
| 31842 |
+ angle::HashMap<uint32_t, uint32_t> xfbOriginalBindings; |
| 31843 |
for (uint32_t bufferIdx = 0; bufferIdx < kMaxShaderXFBs; ++bufferIdx) |
| 31844 |
{ |
| 31845 |
std::string bufferName = rx::GetXfbBufferName(bufferIdx); |
| 31846 |
@@ -533,6 +1270,5 @@ void GlslangGetShaderSource(const gl::ProgramState &programState, |
| 31847 |
|
| 31848 |
return angle::Result::Continue; |
| 31849 |
} |
| 31850 |
- |
| 31851 |
} // namespace mtl |
| 31852 |
} // namespace rx |
| 31853 |
diff --git a/src/libANGLE/renderer/metal/mtl_occlusion_query_pool.h b/src/libANGLE/renderer/metal/mtl_occlusion_query_pool.h |
| 31854 |
index 87dc217..f857034 100644 |
| 31855 |
--- a/src/libANGLE/renderer/metal/mtl_occlusion_query_pool.h |
| 31856 |
+++ b/src/libANGLE/renderer/metal/mtl_occlusion_query_pool.h |
| 31857 |
@@ -1,5 +1,5 @@ |
| 31858 |
// |
| 31859 |
-// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 31860 |
+// Copyright (c) 2020 The ANGLE Project Authors. All rights reserved. |
| 31861 |
// Use of this source code is governed by a BSD-style license that can be |
| 31862 |
// found in the LICENSE file. |
| 31863 |
// |
| 31864 |
diff --git a/src/libANGLE/renderer/metal/mtl_occlusion_query_pool.mm b/src/libANGLE/renderer/metal/mtl_occlusion_query_pool.mm |
| 31865 |
index 368dbf4..7cc8990 100644 |
| 31866 |
--- a/src/libANGLE/renderer/metal/mtl_occlusion_query_pool.mm |
| 31867 |
+++ b/src/libANGLE/renderer/metal/mtl_occlusion_query_pool.mm |
| 31868 |
@@ -1,5 +1,5 @@ |
| 31869 |
// |
| 31870 |
-// Copyright 2020 The ANGLE Project Authors. All rights reserved. |
| 31871 |
+// Copyright (c) 2020 The ANGLE Project Authors. All rights reserved. |
| 31872 |
// Use of this source code is governed by a BSD-style license that can be |
| 31873 |
// found in the LICENSE file. |
| 31874 |
// |
| 31875 |
@@ -52,8 +52,7 @@ |
| 31876 |
{ |
| 31877 |
// First allocation |
| 31878 |
ANGLE_TRY(Buffer::MakeBufferWithResOpt(contextMtl, MTLResourceStorageModePrivate, |
| 31879 |
- kOcclusionQueryResultSize, nullptr, |
| 31880 |
- &mRenderPassResultsPool)); |
| 31881 |
+ kOcclusionQueryResultSize, nullptr, &mRenderPassResultsPool)); |
| 31882 |
mRenderPassResultsPool->get().label = @"OcclusionQueryPool"; |
| 31883 |
} |
| 31884 |
else if (currentOffset + kOcclusionQueryResultSize > mRenderPassResultsPool->size()) |
| 31885 |
@@ -88,6 +87,12 @@ |
| 31886 |
if (currentOffset == 0) |
| 31887 |
{ |
| 31888 |
mResetFirstQuery = clearOldValue; |
| 31889 |
+ if (!clearOldValue && !contextMtl->getDisplay()->getFeatures().allowBufferReadWrite.enabled) |
| 31890 |
+ { |
| 31891 |
+ // If old value of first query needs to be retained and device doesn't support buffer |
| 31892 |
+ // read-write, we need an additional offset to store the old value of the query. |
| 31893 |
+ return allocateQueryOffset(contextMtl, query, false); |
| 31894 |
+ } |
| 31895 |
} |
| 31896 |
|
| 31897 |
return angle::Result::Continue; |
| 31898 |
@@ -113,9 +118,33 @@ |
| 31899 |
} |
| 31900 |
|
| 31901 |
RenderUtils &utils = contextMtl->getDisplay()->getUtils(); |
| 31902 |
+ BlitCommandEncoder *blitEncoder = nullptr; |
| 31903 |
+ // Combine the values stored in the offsets allocated for first query |
| 31904 |
+ if (mAllocatedQueries[0]) |
| 31905 |
+ { |
| 31906 |
+ const BufferRef &dstBuf = mAllocatedQueries[0]->getVisibilityResultBuffer(); |
| 31907 |
+ const VisibilityBufferOffsetsMtl &allocatedOffsets = |
| 31908 |
+ mAllocatedQueries[0]->getAllocatedVisibilityOffsets(); |
| 31909 |
+ if (!mResetFirstQuery && |
| 31910 |
+ !contextMtl->getDisplay()->getFeatures().allowBufferReadWrite.enabled) |
| 31911 |
+ { |
| 31912 |
+ // If we cannot read and write to the same buffer in shader. We need to copy the old |
| 31913 |
+ // value of first query to first offset allocated for it. |
| 31914 |
+ blitEncoder = contextMtl->getBlitCommandEncoder(); |
| 31915 |
+ blitEncoder->copyBuffer(dstBuf, 0, mRenderPassResultsPool, allocatedOffsets.front(), |
| 31916 |
+ kOcclusionQueryResultSize); |
| 31917 |
+ utils.combineVisibilityResult(contextMtl, false, allocatedOffsets, |
| 31918 |
+ mRenderPassResultsPool, dstBuf); |
| 31919 |
+ } |
| 31920 |
+ else |
| 31921 |
+ { |
| 31922 |
+ utils.combineVisibilityResult(contextMtl, !mResetFirstQuery, allocatedOffsets, |
| 31923 |
+ mRenderPassResultsPool, dstBuf); |
| 31924 |
+ } |
| 31925 |
+ } |
| 31926 |
|
| 31927 |
// Combine the values stored in the offsets allocated for each of the remaining queries |
| 31928 |
- for (size_t i = 0; i < mAllocatedQueries.size(); ++i) |
| 31929 |
+ for (size_t i = 1; i < mAllocatedQueries.size(); ++i) |
| 31930 |
{ |
| 31931 |
QueryMtl *query = mAllocatedQueries[i]; |
| 31932 |
if (!query) |
| 31933 |
@@ -126,12 +155,12 @@ |
| 31934 |
const BufferRef &dstBuf = mAllocatedQueries[i]->getVisibilityResultBuffer(); |
| 31935 |
const VisibilityBufferOffsetsMtl &allocatedOffsets = |
| 31936 |
mAllocatedQueries[i]->getAllocatedVisibilityOffsets(); |
| 31937 |
- utils.combineVisibilityResult(contextMtl, /** keepOldValue */ i == 0 && !mResetFirstQuery, |
| 31938 |
- allocatedOffsets, mRenderPassResultsPool, dstBuf); |
| 31939 |
+ utils.combineVisibilityResult(contextMtl, false, allocatedOffsets, mRenderPassResultsPool, |
| 31940 |
+ dstBuf); |
| 31941 |
} |
| 31942 |
|
| 31943 |
// Request synchronization and cleanup |
| 31944 |
- BlitCommandEncoder *blitEncoder = contextMtl->getBlitCommandEncoder(); |
| 31945 |
+ blitEncoder = contextMtl->getBlitCommandEncoder(); |
| 31946 |
for (size_t i = 0; i < mAllocatedQueries.size(); ++i) |
| 31947 |
{ |
| 31948 |
QueryMtl *query = mAllocatedQueries[i]; |
| 31949 |
diff --git a/src/libANGLE/renderer/metal/mtl_render_utils.h b/src/libANGLE/renderer/metal/mtl_render_utils.h |
| 31950 |
index 6b967de..d0a4837 100644 |
| 31951 |
--- a/src/libANGLE/renderer/metal/mtl_render_utils.h |
| 31952 |
+++ b/src/libANGLE/renderer/metal/mtl_render_utils.h |
| 31953 |
@@ -6,6 +6,8 @@ |
| 31954 |
// mtl_render_utils.h: |
| 31955 |
// Defines the class interface for RenderUtils, which contains many utility functions and shaders |
| 31956 |
// for converting, blitting, copying as well as generating data, and many more. |
| 31957 |
+// NOTE(hqle): Consider splitting this class into multiple classes each doing different utilities. |
| 31958 |
+// This class has become too big. |
| 31959 |
// |
| 31960 |
|
| 31961 |
#ifndef LIBANGLE_RENDERER_METAL_MTL_RENDER_UTILS_H_ |
| 31962 |
@@ -89,6 +91,8 @@ struct ColorBlitParams : public BlitParams |
| 31963 |
struct DepthStencilBlitParams : public BlitParams |
| 31964 |
{ |
| 31965 |
TextureRef srcStencil; |
| 31966 |
+ uint32_t srcStencilLevel = 0; |
| 31967 |
+ uint32_t srcStencilLayer = 0; |
| 31968 |
}; |
| 31969 |
|
| 31970 |
// Stencil blit via an intermediate buffer. NOTE: source depth texture parameter is ignored. |
| 31971 |
@@ -309,21 +313,17 @@ class IndexGeneratorUtils final : angle::NonCopyable |
| 31972 |
public: |
| 31973 |
void onDestroy(); |
| 31974 |
|
| 31975 |
- // Convert index buffer. |
| 31976 |
angle::Result convertIndexBufferGPU(ContextMtl *contextMtl, |
| 31977 |
const IndexConversionParams ¶ms); |
| 31978 |
- // Generate triangle fan index buffer for glDrawArrays(). |
| 31979 |
angle::Result generateTriFanBufferFromArrays(ContextMtl *contextMtl, |
| 31980 |
const TriFanOrLineLoopFromArrayParams ¶ms); |
| 31981 |
// Generate triangle fan index buffer for glDrawElements(). |
| 31982 |
angle::Result generateTriFanBufferFromElementsArray(ContextMtl *contextMtl, |
| 31983 |
- const IndexGenerationParams ¶ms); |
| 31984 |
+ const IndexGenerationParams ¶ms, |
| 31985 |
+ uint32_t *indicesGenerated); |
| 31986 |
|
| 31987 |
- // Generate line loop index buffer for glDrawArrays(). |
| 31988 |
angle::Result generateLineLoopBufferFromArrays(ContextMtl *contextMtl, |
| 31989 |
const TriFanOrLineLoopFromArrayParams ¶ms); |
| 31990 |
- // Generate line loop's last segment index buffer for glDrawArrays(). |
| 31991 |
- // This is used when primitive restart is not enabled. |
| 31992 |
angle::Result generateLineLoopLastSegment(ContextMtl *contextMtl, |
| 31993 |
uint32_t firstVertex, |
| 31994 |
uint32_t lastVertex, |
| 31995 |
@@ -340,6 +340,18 @@ class IndexGeneratorUtils final : angle::NonCopyable |
| 31996 |
angle::Result generateLineLoopLastSegmentFromElementsArray(ContextMtl *contextMtl, |
| 31997 |
const IndexGenerationParams ¶ms); |
| 31998 |
|
| 31999 |
+ angle::Result generatePrimitiveRestartPointsBuffer(ContextMtl *contextMtl, |
| 32000 |
+ const IndexGenerationParams ¶ms, |
| 32001 |
+ size_t *indicesGenerated); |
| 32002 |
+ |
| 32003 |
+ angle::Result generatePrimitiveRestartLinesBuffer(ContextMtl *contextMtl, |
| 32004 |
+ const IndexGenerationParams ¶ms, |
| 32005 |
+ size_t *indicesGenerated); |
| 32006 |
+ |
| 32007 |
+ angle::Result generatePrimitiveRestartTrianglesBuffer(ContextMtl *contextMtl, |
| 32008 |
+ const IndexGenerationParams ¶ms, |
| 32009 |
+ size_t *indicesGenerated); |
| 32010 |
+ |
| 32011 |
private: |
| 32012 |
// Index generator compute pipelines: |
| 32013 |
// - First dimension: index type. |
| 32014 |
@@ -348,7 +360,6 @@ class IndexGeneratorUtils final : angle::NonCopyable |
| 32015 |
std::array<std::array<AutoObjCPtr<id<MTLComputePipelineState>>, 2>, |
| 32016 |
angle::EnumSize<gl::DrawElementsType>()>; |
| 32017 |
|
| 32018 |
- // Get compute pipeline to convert index between buffers. |
| 32019 |
AutoObjCPtr<id<MTLComputePipelineState>> getIndexConversionPipeline( |
| 32020 |
ContextMtl *contextMtl, |
| 32021 |
gl::DrawElementsType srcType, |
| 32022 |
@@ -375,7 +386,8 @@ class IndexGeneratorUtils final : angle::NonCopyable |
| 32023 |
// Must be multiples of kIndexBufferOffsetAlignment |
| 32024 |
uint32_t dstOffset); |
| 32025 |
angle::Result generateTriFanBufferFromElementsArrayCPU(ContextMtl *contextMtl, |
| 32026 |
- const IndexGenerationParams ¶ms); |
| 32027 |
+ const IndexGenerationParams ¶ms, |
| 32028 |
+ uint32_t *indicesGenerated); |
| 32029 |
|
| 32030 |
angle::Result generateLineLoopBufferFromElementsArrayGPU( |
| 32031 |
ContextMtl *contextMtl, |
| 32032 |
@@ -393,6 +405,11 @@ class IndexGeneratorUtils final : angle::NonCopyable |
| 32033 |
ContextMtl *contextMtl, |
| 32034 |
const IndexGenerationParams ¶ms); |
| 32035 |
|
| 32036 |
+ angle::Result generatePrimitiveRestartBuffer(ContextMtl *contextMtl, |
| 32037 |
+ unsigned numVerticesPerPrimitive, |
| 32038 |
+ const IndexGenerationParams ¶ms, |
| 32039 |
+ size_t *indicesGenerated); |
| 32040 |
+ |
| 32041 |
IndexConversionPipelineArray mIndexConversionPipelineCaches; |
| 32042 |
|
| 32043 |
IndexConversionPipelineArray mTriFanFromElemArrayGeneratorPipelineCaches; |
| 32044 |
@@ -429,7 +446,7 @@ class MipmapUtils final : angle::NonCopyable |
| 32045 |
public: |
| 32046 |
void onDestroy(); |
| 32047 |
|
| 32048 |
- // Compute based mipmap generation. Only possible for 3D texture for now. |
| 32049 |
+ // Compute based mipmap generation. |
| 32050 |
angle::Result generateMipmapCS(ContextMtl *contextMtl, |
| 32051 |
const TextureRef &srcTexture, |
| 32052 |
bool sRGBMipmap, |
| 32053 |
@@ -437,9 +454,15 @@ class MipmapUtils final : angle::NonCopyable |
| 32054 |
|
| 32055 |
private: |
| 32056 |
void ensure3DMipGeneratorPipelineInitialized(ContextMtl *contextMtl); |
| 32057 |
+ void ensure2DMipGeneratorPipelineInitialized(ContextMtl *contextMtl); |
| 32058 |
+ void ensure2DArrayMipGeneratorPipelineInitialized(ContextMtl *contextMtl); |
| 32059 |
+ void ensureCubeMipGeneratorPipelineInitialized(ContextMtl *contextMtl); |
| 32060 |
|
| 32061 |
// Mipmaps generating compute pipeline: |
| 32062 |
AutoObjCPtr<id<MTLComputePipelineState>> m3DMipGeneratorPipeline; |
| 32063 |
+ AutoObjCPtr<id<MTLComputePipelineState>> m2DMipGeneratorPipeline; |
| 32064 |
+ AutoObjCPtr<id<MTLComputePipelineState>> m2DArrayMipGeneratorPipeline; |
| 32065 |
+ AutoObjCPtr<id<MTLComputePipelineState>> mCubeMipGeneratorPipeline; |
| 32066 |
}; |
| 32067 |
|
| 32068 |
// Util class for handling pixels copy between buffers and textures |
| 32069 |
@@ -543,6 +566,21 @@ class VertexFormatConversionUtils final : angle::NonCopyable |
| 32070 |
RenderPipelineCache mComponentsExpandRenderPipelineCache; |
| 32071 |
}; |
| 32072 |
|
| 32073 |
+// Util class for handling transform feedback |
| 32074 |
+ class TransformFeedbackUtils |
| 32075 |
+{ |
| 32076 |
+ public: |
| 32077 |
+ void onDestroy(); |
| 32078 |
+ AutoObjCPtr<id<MTLRenderPipelineState>> getTransformFeedbackRenderPipeline( |
| 32079 |
+ ContextMtl *contextMtl, |
| 32080 |
+ RenderCommandEncoder *cmdEncoder, |
| 32081 |
+ mtl::RenderPipelineDesc &pipelineDesc); |
| 32082 |
+ |
| 32083 |
+ private: |
| 32084 |
+ AutoObjCPtr<id<MTLLibrary>> createMslXfbLibrary(ContextMtl *contextMtl, |
| 32085 |
+ const std::string &translatedMsl); |
| 32086 |
+}; |
| 32087 |
+ |
| 32088 |
// RenderUtils: container class of various util classes above |
| 32089 |
class RenderUtils : public Context, angle::NonCopyable |
| 32090 |
{ |
| 32091 |
@@ -587,7 +625,8 @@ class RenderUtils : public Context, angle::NonCopyable |
| 32092 |
angle::Result generateTriFanBufferFromArrays(ContextMtl *contextMtl, |
| 32093 |
const TriFanOrLineLoopFromArrayParams ¶ms); |
| 32094 |
angle::Result generateTriFanBufferFromElementsArray(ContextMtl *contextMtl, |
| 32095 |
- const IndexGenerationParams ¶ms); |
| 32096 |
+ const IndexGenerationParams ¶ms, |
| 32097 |
+ uint32_t *indicesGenerated); |
| 32098 |
|
| 32099 |
angle::Result generateLineLoopBufferFromArrays(ContextMtl *contextMtl, |
| 32100 |
const TriFanOrLineLoopFromArrayParams ¶ms); |
| 32101 |
@@ -639,6 +678,19 @@ class RenderUtils : public Context, angle::NonCopyable |
| 32102 |
RenderCommandEncoder *renderEncoder, |
| 32103 |
const angle::Format &srcAngleFormat, |
| 32104 |
const VertexFormatConvertParams ¶ms); |
| 32105 |
+ angle::Result createTransformFeedbackPSO(const gl::Context *context, |
| 32106 |
+ RenderCommandEncoder *renderEncoder, |
| 32107 |
+ mtl::RenderPipelineDesc &pipelineDesc); |
| 32108 |
+ |
| 32109 |
+ angle::Result generatePrimitiveRestartPointsBuffer(ContextMtl *contextMtl, |
| 32110 |
+ const IndexGenerationParams ¶ms, |
| 32111 |
+ size_t *indicesGenerated); |
| 32112 |
+ angle::Result generatePrimitiveRestartLinesBuffer(ContextMtl *contextMtl, |
| 32113 |
+ const IndexGenerationParams ¶ms, |
| 32114 |
+ size_t *indicesGenerated); |
| 32115 |
+ angle::Result generatePrimitiveRestartTrianglesBuffer(ContextMtl *contextMtl, |
| 32116 |
+ const IndexGenerationParams ¶ms, |
| 32117 |
+ size_t *indicesGenerated); |
| 32118 |
|
| 32119 |
private: |
| 32120 |
// override ErrorHandler |
| 32121 |
@@ -646,7 +698,7 @@ class RenderUtils : public Context, angle::NonCopyable |
| 32122 |
const char *file, |
| 32123 |
const char *function, |
| 32124 |
unsigned int line) override; |
| 32125 |
- void handleError(NSError *_Nullable error, |
| 32126 |
+ void handleError(NSError *error, |
| 32127 |
const char *file, |
| 32128 |
const char *function, |
| 32129 |
unsigned int line) override; |
| 32130 |
@@ -662,6 +714,7 @@ class RenderUtils : public Context, angle::NonCopyable |
| 32131 |
MipmapUtils mMipmapUtils; |
| 32132 |
std::array<CopyPixelsUtils, angle::EnumSize<PixelType>()> mCopyPixelsUtils; |
| 32133 |
VertexFormatConversionUtils mVertexFormatUtils; |
| 32134 |
+ TransformFeedbackUtils mTransformFeedbackUtils; |
| 32135 |
}; |
| 32136 |
|
| 32137 |
} // namespace mtl |
| 32138 |
diff --git a/src/libANGLE/renderer/metal/mtl_render_utils.mm b/src/libANGLE/renderer/metal/mtl_render_utils.mm |
| 32139 |
index d224801..32b33ca 100644 |
| 32140 |
--- a/src/libANGLE/renderer/metal/mtl_render_utils.mm |
| 32141 |
+++ b/src/libANGLE/renderer/metal/mtl_render_utils.mm |
| 32142 |
@@ -15,6 +15,7 @@ |
| 32143 |
#include "libANGLE/renderer/metal/BufferMtl.h" |
| 32144 |
#include "libANGLE/renderer/metal/ContextMtl.h" |
| 32145 |
#include "libANGLE/renderer/metal/DisplayMtl.h" |
| 32146 |
+#include "libANGLE/renderer/metal/ProgramMtl.h" |
| 32147 |
#include "libANGLE/renderer/metal/QueryMtl.h" |
| 32148 |
#include "libANGLE/renderer/metal/mtl_common.h" |
| 32149 |
#include "libANGLE/renderer/metal/mtl_utils.h" |
| 32150 |
@@ -54,10 +55,12 @@ |
| 32151 |
float srcTexCoords[3][2]; |
| 32152 |
int srcLevel = 0; |
| 32153 |
int srcLayer = 0; |
| 32154 |
+ int srcLevel2 = 0; |
| 32155 |
+ int srcLayer2 = 0; |
| 32156 |
uint8_t dstFlipX = 0; |
| 32157 |
uint8_t dstFlipY = 0; |
| 32158 |
uint8_t dstLuminance = 0; // dest texture is luminace |
| 32159 |
- uint8_t padding[13]; |
| 32160 |
+ uint8_t padding[9]; |
| 32161 |
}; |
| 32162 |
|
| 32163 |
struct BlitStencilToBufferParamsUniform |
| 32164 |
@@ -90,7 +93,7 @@ |
| 32165 |
uint8_t padding[7]; |
| 32166 |
}; |
| 32167 |
|
| 32168 |
-// See libANGLE/renderer/metal/shaders/visibility.metal |
| 32169 |
+// See libANGLE/renderer/metal/shaders/misc.metal |
| 32170 |
struct CombineVisibilityResultUniform |
| 32171 |
{ |
| 32172 |
uint32_t startOffset; |
| 32173 |
@@ -99,12 +102,11 @@ |
| 32174 |
}; |
| 32175 |
|
| 32176 |
// See libANGLE/renderer/metal/shaders/gen_mipmap.metal |
| 32177 |
-struct GenerateMipmapUniform |
| 32178 |
+struct Generate3DMipmapUniform |
| 32179 |
{ |
| 32180 |
uint32_t srcLevel; |
| 32181 |
uint32_t numMipmapsToGenerate; |
| 32182 |
- uint8_t sRGB; |
| 32183 |
- uint8_t padding[7]; |
| 32184 |
+ uint32_t padding[2]; |
| 32185 |
}; |
| 32186 |
|
| 32187 |
// See libANGLE/renderer/metal/shaders/copy_buffer.metal |
| 32188 |
@@ -156,19 +158,36 @@ |
| 32189 |
// exiting block. |
| 32190 |
struct ScopedDisableOcclusionQuery |
| 32191 |
{ |
| 32192 |
- ScopedDisableOcclusionQuery(ContextMtl *contextMtl, angle::Result *resultOut) |
| 32193 |
- : mContextMtl(contextMtl), mResultOut(resultOut) |
| 32194 |
+ ScopedDisableOcclusionQuery(ContextMtl *contextMtl, |
| 32195 |
+ RenderCommandEncoder *encoder, |
| 32196 |
+ angle::Result *resultOut) |
| 32197 |
+ : mContextMtl(contextMtl), mEncoder(encoder), mResultOut(resultOut) |
| 32198 |
+ { |
| 32199 |
+#ifndef NDEBUG |
| 32200 |
+ if (contextMtl->hasActiveOcclusionQuery()) |
| 32201 |
{ |
| 32202 |
+ encoder->pushDebugGroup(@"Disabled OcclusionQuery"); |
| 32203 |
+ } |
| 32204 |
+#endif |
| 32205 |
// temporarily disable occlusion query |
| 32206 |
contextMtl->disableActiveOcclusionQueryInRenderPass(); |
| 32207 |
} |
| 32208 |
~ScopedDisableOcclusionQuery() |
| 32209 |
{ |
| 32210 |
*mResultOut = mContextMtl->restartActiveOcclusionQueryInRenderPass(); |
| 32211 |
+#ifndef NDEBUG |
| 32212 |
+ if (mContextMtl->hasActiveOcclusionQuery()) |
| 32213 |
+ { |
| 32214 |
+ mEncoder->popDebugGroup(); |
| 32215 |
+ } |
| 32216 |
+#else |
| 32217 |
+ ANGLE_UNUSED_VARIABLE(mEncoder); |
| 32218 |
+#endif |
| 32219 |
} |
| 32220 |
|
| 32221 |
private: |
| 32222 |
ContextMtl *mContextMtl; |
| 32223 |
+ RenderCommandEncoder *mEncoder; |
| 32224 |
|
| 32225 |
angle::Result *mResultOut; |
| 32226 |
}; |
| 32227 |
@@ -219,66 +238,43 @@ void GetBlitTexCoords(uint32_t srcWidth, |
| 32228 |
bool primitiveRestartEnabled, |
| 32229 |
const T *indices, |
| 32230 |
const BufferRef &dstBuffer, |
| 32231 |
- uint32_t dstOffset) |
| 32232 |
+ uint32_t dstOffset, |
| 32233 |
+ uint32_t *indicesGenerated) |
| 32234 |
{ |
| 32235 |
ASSERT(count > 2); |
| 32236 |
- |
| 32237 |
- uint32_t genIndicesCount; |
| 32238 |
- ANGLE_TRY(mtl::GetTriangleFanIndicesCount(contextMtl, count, &genIndicesCount)); |
| 32239 |
- |
| 32240 |
constexpr T kSrcPrimitiveRestartIndex = std::numeric_limits<T>::max(); |
| 32241 |
- const uint32_t kDstPrimitiveRestartIndex = std::numeric_limits<uint32_t>::max(); |
| 32242 |
- |
| 32243 |
+ GLsizei dstTriangle = 0; |
| 32244 |
uint32_t *dstPtr = reinterpret_cast<uint32_t *>(dstBuffer->map(contextMtl) + dstOffset); |
| 32245 |
- T triFirstIdx = 0; // Vertex index of trianlge's 1st vertex |
| 32246 |
- T srcPrevIdx = 0; // Vertex index of trianlge's 2nd vertex |
| 32247 |
+ T triFirstIdx, srcPrevIdx; |
| 32248 |
memcpy(&triFirstIdx, indices, sizeof(triFirstIdx)); |
| 32249 |
+ memcpy(&srcPrevIdx, indices + 1, sizeof(srcPrevIdx)); |
| 32250 |
|
| 32251 |
if (primitiveRestartEnabled) |
| 32252 |
{ |
| 32253 |
- // triFirstIdxLoc: Location of current triangle's fist vertex in source buffer. |
| 32254 |
GLsizei triFirstIdxLoc = 0; |
| 32255 |
while (triFirstIdx == kSrcPrimitiveRestartIndex) |
| 32256 |
{ |
| 32257 |
- memcpy(&dstPtr[triFirstIdxLoc++], &kDstPrimitiveRestartIndex, |
| 32258 |
- sizeof(kDstPrimitiveRestartIndex)); |
| 32259 |
+ ++triFirstIdxLoc; |
| 32260 |
memcpy(&triFirstIdx, indices + triFirstIdxLoc, sizeof(triFirstIdx)); |
| 32261 |
} |
| 32262 |
|
| 32263 |
- if (triFirstIdxLoc + 2 >= count) |
| 32264 |
- { |
| 32265 |
- // Not enough indices. |
| 32266 |
- for (GLsizei i = triFirstIdxLoc; i < count; ++i) |
| 32267 |
- { |
| 32268 |
- memcpy(&dstPtr[i], &kDstPrimitiveRestartIndex, sizeof(kDstPrimitiveRestartIndex)); |
| 32269 |
- } |
| 32270 |
- } |
| 32271 |
- else if (triFirstIdxLoc + 1 < count) |
| 32272 |
- { |
| 32273 |
- memcpy(&srcPrevIdx, indices + triFirstIdxLoc + 1, sizeof(srcPrevIdx)); |
| 32274 |
- } |
| 32275 |
- |
| 32276 |
for (GLsizei i = triFirstIdxLoc + 2; i < count; ++i) |
| 32277 |
{ |
| 32278 |
uint32_t triIndices[3]; |
| 32279 |
- |
| 32280 |
T srcIdx; |
| 32281 |
memcpy(&srcIdx, indices + i, sizeof(srcIdx)); |
| 32282 |
+ bool completeTriangle = true; |
| 32283 |
if (srcPrevIdx == kSrcPrimitiveRestartIndex || srcIdx == kSrcPrimitiveRestartIndex) |
| 32284 |
{ |
| 32285 |
- // Incomplete triangle. |
| 32286 |
- triIndices[0] = kDstPrimitiveRestartIndex; |
| 32287 |
- triIndices[1] = kDstPrimitiveRestartIndex; |
| 32288 |
- triIndices[2] = kDstPrimitiveRestartIndex; |
| 32289 |
+ // Incomplete triangle. Move to next triangle and set triFirstIndex |
| 32290 |
triFirstIdx = srcIdx; |
| 32291 |
triFirstIdxLoc = i; |
| 32292 |
+ completeTriangle = false; |
| 32293 |
} |
| 32294 |
else if (i < triFirstIdxLoc + 2) |
| 32295 |
{ |
| 32296 |
- // Incomplete triangle |
| 32297 |
- triIndices[0] = kDstPrimitiveRestartIndex; |
| 32298 |
- triIndices[1] = kDstPrimitiveRestartIndex; |
| 32299 |
- triIndices[2] = kDstPrimitiveRestartIndex; |
| 32300 |
+ // Incomplete triangle, move to next triangle |
| 32301 |
+ completeTriangle = false; |
| 32302 |
} |
| 32303 |
else |
| 32304 |
{ |
| 32305 |
@@ -286,15 +282,16 @@ void GetBlitTexCoords(uint32_t srcWidth, |
| 32306 |
triIndices[1] = srcPrevIdx; |
| 32307 |
triIndices[2] = srcIdx; |
| 32308 |
} |
| 32309 |
+ if (completeTriangle) |
| 32310 |
+ { |
| 32311 |
+ memcpy(dstPtr + 3 * dstTriangle, triIndices, sizeof(triIndices)); |
| 32312 |
+ ++dstTriangle; |
| 32313 |
+ } |
| 32314 |
srcPrevIdx = srcIdx; |
| 32315 |
- |
| 32316 |
- memcpy(dstPtr + 3 * (i - 2), triIndices, sizeof(triIndices)); |
| 32317 |
} |
| 32318 |
} |
| 32319 |
else |
| 32320 |
{ |
| 32321 |
- memcpy(&srcPrevIdx, indices + 1, sizeof(srcPrevIdx)); |
| 32322 |
- |
| 32323 |
for (GLsizei i = 2; i < count; ++i) |
| 32324 |
{ |
| 32325 |
T srcIdx; |
| 32326 |
@@ -306,14 +303,68 @@ void GetBlitTexCoords(uint32_t srcWidth, |
| 32327 |
triIndices[2] = srcIdx; |
| 32328 |
srcPrevIdx = srcIdx; |
| 32329 |
|
| 32330 |
- memcpy(dstPtr + 3 * (i - 2), triIndices, sizeof(triIndices)); |
| 32331 |
+ memcpy(dstPtr + 3 * dstTriangle, triIndices, sizeof(triIndices)); |
| 32332 |
+ ++dstTriangle; |
| 32333 |
} |
| 32334 |
} |
| 32335 |
- dstBuffer->unmapAndFlushSubset(contextMtl, dstOffset, genIndicesCount * sizeof(uint32_t)); |
| 32336 |
+ if (indicesGenerated) |
| 32337 |
+ *indicesGenerated = dstTriangle * 3; |
| 32338 |
+ dstBuffer->unmap(contextMtl); |
| 32339 |
|
| 32340 |
return angle::Result::Continue; |
| 32341 |
} |
| 32342 |
|
| 32343 |
+template <typename T> |
| 32344 |
+angle::Result GenPrimitiveRestartBuffer(ContextMtl *contextMtl, |
| 32345 |
+ GLsizei count, |
| 32346 |
+ GLsizei indicesPerPrimitive, |
| 32347 |
+ const T *indices, |
| 32348 |
+ const BufferRef &dstBuffer, |
| 32349 |
+ uint32_t dstOffset, |
| 32350 |
+ size_t *indicesGenerated) |
| 32351 |
+{ |
| 32352 |
+ constexpr T kSrcPrimitiveRestartIndex = std::numeric_limits<T>::max(); |
| 32353 |
+ uint32_t *dstPtr = reinterpret_cast<uint32_t *>(dstBuffer->map(contextMtl) + dstOffset); |
| 32354 |
+ GLsizei readValueLoc = 0; |
| 32355 |
+ T readValue = 0; |
| 32356 |
+ uint32_t dstIdx = 0; |
| 32357 |
+ memcpy(&readValue, indices, sizeof(readValue)); |
| 32358 |
+ while (readValue == kSrcPrimitiveRestartIndex) |
| 32359 |
+ { |
| 32360 |
+ |
| 32361 |
+ ++readValueLoc; |
| 32362 |
+ memcpy(&readValue, indices + readValueLoc, sizeof(readValue)); |
| 32363 |
+ } |
| 32364 |
+ while (readValueLoc + indicesPerPrimitive <= count) |
| 32365 |
+ { |
| 32366 |
+ |
| 32367 |
+ uint32_t primIndicies[3]; |
| 32368 |
+ bool foundPrimitive = true; |
| 32369 |
+ for (int k = 0; k < indicesPerPrimitive; ++k) |
| 32370 |
+ { |
| 32371 |
+ memcpy(&readValue, indices + readValueLoc, sizeof(readValue)); |
| 32372 |
+ ++readValueLoc; |
| 32373 |
+ if (readValue == kSrcPrimitiveRestartIndex) |
| 32374 |
+ { |
| 32375 |
+ foundPrimitive = false; |
| 32376 |
+ break; |
| 32377 |
+ } |
| 32378 |
+ else |
| 32379 |
+ { |
| 32380 |
+ primIndicies[k] = (uint32_t)readValue; |
| 32381 |
+ } |
| 32382 |
+ } |
| 32383 |
+ if (foundPrimitive) |
| 32384 |
+ { |
| 32385 |
+ memcpy(&dstPtr[dstIdx], primIndicies, (indicesPerPrimitive) * sizeof(uint32_t)); |
| 32386 |
+ dstIdx += indicesPerPrimitive; |
| 32387 |
+ } |
| 32388 |
+ } |
| 32389 |
+ if (indicesGenerated) |
| 32390 |
+ *indicesGenerated = dstIdx; |
| 32391 |
+ return angle::Result::Continue; |
| 32392 |
+} |
| 32393 |
+ |
| 32394 |
template <typename T> |
| 32395 |
angle::Result GenLineLoopFromClientElements(ContextMtl *contextMtl, |
| 32396 |
GLsizei count, |
| 32397 |
@@ -328,14 +379,11 @@ void GetBlitTexCoords(uint32_t srcWidth, |
| 32398 |
const uint32_t kDstPrimitiveRestartIndex = std::numeric_limits<uint32_t>::max(); |
| 32399 |
|
| 32400 |
uint32_t *dstPtr = reinterpret_cast<uint32_t *>(dstBuffer->map(contextMtl) + dstOffset); |
| 32401 |
- // lineLoopFirstIdx: value of of current line loop's first vertex index. Can change when |
| 32402 |
- // encounter a primitive restart index. |
| 32403 |
T lineLoopFirstIdx; |
| 32404 |
memcpy(&lineLoopFirstIdx, indices, sizeof(lineLoopFirstIdx)); |
| 32405 |
|
| 32406 |
if (primitiveRestartEnabled) |
| 32407 |
{ |
| 32408 |
- // lineLoopFirstIdxLoc: location of current line loop's first vertex in the source buffer. |
| 32409 |
GLsizei lineLoopFirstIdxLoc = 0; |
| 32410 |
while (lineLoopFirstIdx == kSrcPrimitiveRestartIndex) |
| 32411 |
{ |
| 32412 |
@@ -344,15 +392,12 @@ void GetBlitTexCoords(uint32_t srcWidth, |
| 32413 |
memcpy(&lineLoopFirstIdx, indices + lineLoopFirstIdxLoc, sizeof(lineLoopFirstIdx)); |
| 32414 |
} |
| 32415 |
|
| 32416 |
- // dstIdx : value of index to be written to dest buffer |
| 32417 |
uint32_t dstIdx = lineLoopFirstIdx; |
| 32418 |
memcpy(&dstPtr[lineLoopFirstIdxLoc], &dstIdx, sizeof(dstIdx)); |
| 32419 |
- // dstWritten: number of indices written to dest buffer |
| 32420 |
uint32_t dstWritten = lineLoopFirstIdxLoc + 1; |
| 32421 |
|
| 32422 |
for (GLsizei i = lineLoopFirstIdxLoc + 1; i < count; ++i) |
| 32423 |
{ |
| 32424 |
- // srcIdx : value of index from source buffer |
| 32425 |
T srcIdx; |
| 32426 |
memcpy(&srcIdx, indices + i, sizeof(srcIdx)); |
| 32427 |
if (srcIdx == kSrcPrimitiveRestartIndex) |
| 32428 |
@@ -400,7 +445,7 @@ void GetBlitTexCoords(uint32_t srcWidth, |
| 32429 |
|
| 32430 |
*indicesGenerated = count + 1; |
| 32431 |
} |
| 32432 |
- dstBuffer->unmapAndFlushSubset(contextMtl, dstOffset, (*indicesGenerated) * sizeof(uint32_t)); |
| 32433 |
+ dstBuffer->unmap(contextMtl); |
| 32434 |
|
| 32435 |
return angle::Result::Continue; |
| 32436 |
} |
| 32437 |
@@ -472,7 +517,7 @@ void EnsureComputePipelineInitialized(DisplayMtl *display, |
| 32438 |
ANGLE_MTL_OBJC_SCOPE |
| 32439 |
{ |
| 32440 |
id<MTLDevice> metalDevice = display->getMetalDevice(); |
| 32441 |
- id<MTLLibrary> shaderLib = display->getDefaultShadersLib(); |
| 32442 |
+ auto shaderLib = display->getDefaultShadersLib(); |
| 32443 |
NSError *err = nil; |
| 32444 |
id<MTLFunction> shader = [shaderLib newFunctionWithName:functionName]; |
| 32445 |
|
| 32446 |
@@ -512,7 +557,7 @@ void EnsureSpecializedComputePipelineInitialized( |
| 32447 |
ANGLE_MTL_OBJC_SCOPE |
| 32448 |
{ |
| 32449 |
id<MTLDevice> metalDevice = display->getMetalDevice(); |
| 32450 |
- id<MTLLibrary> shaderLib = display->getDefaultShadersLib(); |
| 32451 |
+ auto shaderLib = display->getDefaultShadersLib(); |
| 32452 |
NSError *err = nil; |
| 32453 |
|
| 32454 |
id<MTLFunction> shader = [shaderLib newFunctionWithName:functionName |
| 32455 |
@@ -538,6 +583,7 @@ void EnsureSpecializedComputePipelineInitialized( |
| 32456 |
ANGLE_INLINE |
| 32457 |
void EnsureVertexShaderOnlyPipelineCacheInitialized(Context *context, |
| 32458 |
NSString *vertexFunctionName, |
| 32459 |
+ id<MTLLibrary> shaderLib, |
| 32460 |
RenderPipelineCache *pipelineCacheOut) |
| 32461 |
{ |
| 32462 |
RenderPipelineCache &pipelineCache = *pipelineCacheOut; |
| 32463 |
@@ -549,8 +595,6 @@ void EnsureVertexShaderOnlyPipelineCacheInitialized(Context *context, |
| 32464 |
|
| 32465 |
ANGLE_MTL_OBJC_SCOPE |
| 32466 |
{ |
| 32467 |
- DisplayMtl *display = context->getDisplay(); |
| 32468 |
- id<MTLLibrary> shaderLib = display->getDefaultShadersLib(); |
| 32469 |
id<MTLFunction> shader = [shaderLib newFunctionWithName:vertexFunctionName]; |
| 32470 |
|
| 32471 |
ASSERT([shader ANGLE_MTL_AUTORELEASE]); |
| 32472 |
@@ -570,7 +614,9 @@ void EnsureSpecializedVertexShaderOnlyPipelineCacheInitialized( |
| 32473 |
if (!funcConstants) |
| 32474 |
{ |
| 32475 |
// Non specialized constants provided, use default creation function. |
| 32476 |
- EnsureVertexShaderOnlyPipelineCacheInitialized(context, vertexFunctionName, |
| 32477 |
+ DisplayMtl *display = context->getDisplay(); |
| 32478 |
+ auto shaderLib = display->getDefaultShadersLib(); |
| 32479 |
+ EnsureVertexShaderOnlyPipelineCacheInitialized(context, vertexFunctionName, shaderLib, |
| 32480 |
pipelineCacheOut); |
| 32481 |
return; |
| 32482 |
} |
| 32483 |
@@ -585,7 +631,7 @@ void EnsureSpecializedVertexShaderOnlyPipelineCacheInitialized( |
| 32484 |
ANGLE_MTL_OBJC_SCOPE |
| 32485 |
{ |
| 32486 |
DisplayMtl *display = context->getDisplay(); |
| 32487 |
- id<MTLLibrary> shaderLib = display->getDefaultShadersLib(); |
| 32488 |
+ auto shaderLib = display->getDefaultShadersLib(); |
| 32489 |
NSError *err = nil; |
| 32490 |
|
| 32491 |
id<MTLFunction> shader = [shaderLib newFunctionWithName:vertexFunctionName |
| 32492 |
@@ -615,6 +661,22 @@ RenderPipelineDesc GetComputingVertexShaderOnlyRenderPipelineDesc(RenderCommandE |
| 32493 |
return pipelineDesc; |
| 32494 |
} |
| 32495 |
|
| 32496 |
+// Get pipeline descriptor for render pipeline that contains vertex shader acting as transform |
| 32497 |
+// feedback. |
| 32498 |
+ANGLE_INLINE |
| 32499 |
+RenderPipelineDesc GetTransformFeedbackRenderPipelineDesc(RenderCommandEncoder *cmdEncoder, |
| 32500 |
+ mtl::RenderPipelineDesc &pipelineDesc) |
| 32501 |
+{ |
| 32502 |
+ RenderPipelineDesc xfbPipelineDesc = RenderPipelineDesc(pipelineDesc); |
| 32503 |
+ const RenderPassDesc &renderPassDesc = cmdEncoder->renderPassDesc(); |
| 32504 |
+ |
| 32505 |
+ renderPassDesc.populateRenderPipelineOutputDesc(&pipelineDesc.outputDescriptor); |
| 32506 |
+ xfbPipelineDesc.rasterizationType = RenderPipelineRasterization::Disabled; |
| 32507 |
+ xfbPipelineDesc.inputPrimitiveTopology = kPrimitiveTopologyClassPoint; |
| 32508 |
+ |
| 32509 |
+ return xfbPipelineDesc; |
| 32510 |
+} |
| 32511 |
+ |
| 32512 |
template <typename T> |
| 32513 |
void ClearRenderPipelineCacheArray(T *pipelineCacheArray) |
| 32514 |
{ |
| 32515 |
@@ -712,9 +774,15 @@ void SetupBlitWithDrawUniformData(RenderCommandEncoder *cmdEncoder, |
| 32516 |
uniformParams.srcLayer = params.srcLayer; |
| 32517 |
if (isColorBlit) |
| 32518 |
{ |
| 32519 |
- const ColorBlitParams *colorParams = static_cast<const ColorBlitParams *>(¶ms); |
| 32520 |
+ const auto colorParams = static_cast<const ColorBlitParams *>(¶ms); |
| 32521 |
uniformParams.dstLuminance = colorParams->dstLuminance ? 1 : 0; |
| 32522 |
} |
| 32523 |
+ else |
| 32524 |
+ { |
| 32525 |
+ const auto dsParams = static_cast<const DepthStencilBlitParams *>(¶ms); |
| 32526 |
+ uniformParams.srcLevel2 = dsParams->srcStencilLevel; |
| 32527 |
+ uniformParams.srcLayer2 = dsParams->srcStencilLayer; |
| 32528 |
+ } |
| 32529 |
|
| 32530 |
// Compute source texCoords |
| 32531 |
uint32_t srcWidth = 0, srcHeight = 0; |
| 32532 |
@@ -727,8 +795,8 @@ void SetupBlitWithDrawUniformData(RenderCommandEncoder *cmdEncoder, |
| 32533 |
{ |
| 32534 |
const DepthStencilBlitParams *dsParams = |
| 32535 |
static_cast<const DepthStencilBlitParams *>(¶ms); |
| 32536 |
- srcWidth = dsParams->srcStencil->width(dsParams->srcLevel); |
| 32537 |
- srcHeight = dsParams->srcStencil->height(dsParams->srcLevel); |
| 32538 |
+ srcWidth = dsParams->srcStencil->width(mtl::MipmapNativeLevel(dsParams->srcStencilLevel)); |
| 32539 |
+ srcHeight = dsParams->srcStencil->height(mtl::MipmapNativeLevel(dsParams->srcStencilLevel)); |
| 32540 |
} |
| 32541 |
else |
| 32542 |
{ |
| 32543 |
@@ -739,8 +807,8 @@ void SetupBlitWithDrawUniformData(RenderCommandEncoder *cmdEncoder, |
| 32544 |
GetBlitTexCoords(srcWidth, srcHeight, params.srcRect, params.srcYFlipped, params.unpackFlipX, |
| 32545 |
params.unpackFlipY, &u0, &v0, &u1, &v1); |
| 32546 |
|
| 32547 |
- float du = u1 - u0; |
| 32548 |
- float dv = v1 - v0; |
| 32549 |
+ auto du = u1 - u0; |
| 32550 |
+ auto dv = v1 - v0; |
| 32551 |
|
| 32552 |
// lower left |
| 32553 |
uniformParams.srcTexCoords[0][0] = u0; |
| 32554 |
@@ -844,19 +912,21 @@ ANGLE_INLINE void SetPipelineState(ComputeCommandEncoder *encoder, |
| 32555 |
// StencilBlitViaBufferParams implementation |
| 32556 |
StencilBlitViaBufferParams::StencilBlitViaBufferParams() {} |
| 32557 |
|
| 32558 |
-StencilBlitViaBufferParams::StencilBlitViaBufferParams(const DepthStencilBlitParams &srcIn) |
| 32559 |
+StencilBlitViaBufferParams::StencilBlitViaBufferParams(const DepthStencilBlitParams &srcParams) |
| 32560 |
{ |
| 32561 |
- dstTextureSize = srcIn.dstTextureSize; |
| 32562 |
- dstRect = srcIn.dstRect; |
| 32563 |
- dstScissorRect = srcIn.dstScissorRect; |
| 32564 |
- dstFlipY = srcIn.dstFlipY; |
| 32565 |
- dstFlipX = srcIn.dstFlipX; |
| 32566 |
- srcRect = srcIn.srcRect; |
| 32567 |
- srcYFlipped = srcIn.srcYFlipped; |
| 32568 |
- unpackFlipX = srcIn.unpackFlipX; |
| 32569 |
- unpackFlipY = srcIn.unpackFlipY; |
| 32570 |
+ dstTextureSize = srcParams.dstTextureSize; |
| 32571 |
+ dstRect = srcParams.dstRect; |
| 32572 |
+ dstScissorRect = srcParams.dstScissorRect; |
| 32573 |
+ dstFlipY = srcParams.dstFlipY; |
| 32574 |
+ dstFlipX = srcParams.dstFlipX; |
| 32575 |
+ srcRect = srcParams.srcRect; |
| 32576 |
+ srcYFlipped = srcParams.srcYFlipped; |
| 32577 |
+ unpackFlipX = srcParams.unpackFlipX; |
| 32578 |
+ unpackFlipY = srcParams.unpackFlipY; |
| 32579 |
|
| 32580 |
- srcStencil = srcIn.srcStencil; |
| 32581 |
+ srcStencil = srcParams.srcStencil; |
| 32582 |
+ srcStencilLevel = srcParams.srcStencilLevel; |
| 32583 |
+ srcStencilLayer = srcParams.srcStencilLayer; |
| 32584 |
} |
| 32585 |
|
| 32586 |
// RenderUtils implementation |
| 32587 |
@@ -903,6 +973,7 @@ ANGLE_INLINE void SetPipelineState(ComputeCommandEncoder *encoder, |
| 32588 |
} |
| 32589 |
} |
| 32590 |
|
| 32591 |
+ |
| 32592 |
// override ErrorHandler |
| 32593 |
void RenderUtils::handleError(GLenum glErrorCode, |
| 32594 |
const char *file, |
| 32595 |
@@ -1016,9 +1087,10 @@ ANGLE_INLINE void SetPipelineState(ComputeCommandEncoder *encoder, |
| 32596 |
} |
| 32597 |
angle::Result RenderUtils::generateTriFanBufferFromElementsArray( |
| 32598 |
ContextMtl *contextMtl, |
| 32599 |
- const IndexGenerationParams ¶ms) |
| 32600 |
+ const IndexGenerationParams ¶ms, |
| 32601 |
+ uint32_t *indicesGenerated) |
| 32602 |
{ |
| 32603 |
- return mIndexUtils.generateTriFanBufferFromElementsArray(contextMtl, params); |
| 32604 |
+ return mIndexUtils.generateTriFanBufferFromElementsArray(contextMtl, params, indicesGenerated); |
| 32605 |
} |
| 32606 |
|
| 32607 |
angle::Result RenderUtils::generateLineLoopBufferFromArrays( |
| 32608 |
@@ -1050,6 +1122,26 @@ ANGLE_INLINE void SetPipelineState(ComputeCommandEncoder *encoder, |
| 32609 |
{ |
| 32610 |
return mIndexUtils.generateLineLoopLastSegmentFromElementsArray(contextMtl, params); |
| 32611 |
} |
| 32612 |
+angle::Result RenderUtils::generatePrimitiveRestartPointsBuffer(ContextMtl *contextMtl, |
| 32613 |
+ const IndexGenerationParams ¶ms, |
| 32614 |
+ size_t *indicesGenerated) |
| 32615 |
+{ |
| 32616 |
+ return mIndexUtils.generatePrimitiveRestartPointsBuffer(contextMtl, params, indicesGenerated); |
| 32617 |
+} |
| 32618 |
+angle::Result RenderUtils::generatePrimitiveRestartLinesBuffer(ContextMtl *contextMtl, |
| 32619 |
+ const IndexGenerationParams ¶ms, |
| 32620 |
+ size_t *indicesGenerated) |
| 32621 |
+{ |
| 32622 |
+ return mIndexUtils.generatePrimitiveRestartLinesBuffer(contextMtl, params, indicesGenerated); |
| 32623 |
+} |
| 32624 |
+angle::Result RenderUtils::generatePrimitiveRestartTrianglesBuffer( |
| 32625 |
+ ContextMtl *contextMtl, |
| 32626 |
+ const IndexGenerationParams ¶ms, |
| 32627 |
+ size_t *indicesGenerated) |
| 32628 |
+{ |
| 32629 |
+ return mIndexUtils.generatePrimitiveRestartTrianglesBuffer(contextMtl, params, |
| 32630 |
+ indicesGenerated); |
| 32631 |
+} |
| 32632 |
|
| 32633 |
void RenderUtils::combineVisibilityResult( |
| 32634 |
ContextMtl *contextMtl, |
| 32635 |
@@ -1121,6 +1213,21 @@ ANGLE_INLINE void SetPipelineState(ComputeCommandEncoder *encoder, |
| 32636 |
params); |
| 32637 |
} |
| 32638 |
|
| 32639 |
+angle::Result RenderUtils::createTransformFeedbackPSO(const gl::Context *context, |
| 32640 |
+ RenderCommandEncoder *renderEncoder, |
| 32641 |
+ mtl::RenderPipelineDesc &pipelineDesc) |
| 32642 |
+{ |
| 32643 |
+ ContextMtl *contextMtl = mtl::GetImpl(context); |
| 32644 |
+ // Create and cache the PSO |
| 32645 |
+ auto pso = mTransformFeedbackUtils.getTransformFeedbackRenderPipeline(contextMtl, renderEncoder, |
| 32646 |
+ pipelineDesc); |
| 32647 |
+ if (pso) |
| 32648 |
+ { |
| 32649 |
+ return angle::Result::Continue; |
| 32650 |
+ } |
| 32651 |
+ return angle::Result::Stop; |
| 32652 |
+} |
| 32653 |
+ |
| 32654 |
// ClearUtils implementation |
| 32655 |
ClearUtils::ClearUtils(const std::string &fragmentShaderName) |
| 32656 |
: mFragmentShaderName(fragmentShaderName) |
| 32657 |
@@ -1287,11 +1394,11 @@ ANGLE_INLINE void SetPipelineState(ComputeCommandEncoder *encoder, |
| 32658 |
{ |
| 32659 |
overridedParams.clearColor.reset(); |
| 32660 |
} |
| 32661 |
- if (!renderPassDesc.depthAttachment.texture) |
| 32662 |
+ if (!renderPassDesc.depthAttachment.texture()) |
| 32663 |
{ |
| 32664 |
overridedParams.clearDepth.reset(); |
| 32665 |
} |
| 32666 |
- if (!renderPassDesc.stencilAttachment.texture) |
| 32667 |
+ if (!renderPassDesc.stencilAttachment.texture()) |
| 32668 |
{ |
| 32669 |
overridedParams.clearStencil.reset(); |
| 32670 |
} |
| 32671 |
@@ -1307,7 +1414,7 @@ ANGLE_INLINE void SetPipelineState(ComputeCommandEncoder *encoder, |
| 32672 |
angle::Result result; |
| 32673 |
{ |
| 32674 |
// Need to disable occlusion query, otherwise clearing will affect the occlusion counting |
| 32675 |
- ScopedDisableOcclusionQuery disableOcclusionQuery(contextMtl, &result); |
| 32676 |
+ ScopedDisableOcclusionQuery disableOcclusionQuery(contextMtl, cmdEncoder, &result); |
| 32677 |
// Draw the screen aligned triangle |
| 32678 |
cmdEncoder->draw(MTLPrimitiveTypeTriangle, 0, 3); |
| 32679 |
} |
| 32680 |
@@ -1481,7 +1588,7 @@ ANGLE_INLINE void SetPipelineState(ComputeCommandEncoder *encoder, |
| 32681 |
angle::Result result; |
| 32682 |
{ |
| 32683 |
// Need to disable occlusion query, otherwise blitting will affect the occlusion counting |
| 32684 |
- ScopedDisableOcclusionQuery disableOcclusionQuery(contextMtl, &result); |
| 32685 |
+ ScopedDisableOcclusionQuery disableOcclusionQuery(contextMtl, cmdEncoder, &result); |
| 32686 |
// Draw the screen aligned triangle |
| 32687 |
cmdEncoder->draw(MTLPrimitiveTypeTriangle, 0, 3); |
| 32688 |
} |
| 32689 |
@@ -1703,7 +1810,7 @@ ANGLE_INLINE void SetPipelineState(ComputeCommandEncoder *encoder, |
| 32690 |
angle::Result result; |
| 32691 |
{ |
| 32692 |
// Need to disable occlusion query, otherwise blitting will affect the occlusion counting |
| 32693 |
- ScopedDisableOcclusionQuery disableOcclusionQuery(contextMtl, &result); |
| 32694 |
+ ScopedDisableOcclusionQuery disableOcclusionQuery(contextMtl, cmdEncoder, &result); |
| 32695 |
// Draw the screen aligned triangle |
| 32696 |
cmdEncoder->draw(MTLPrimitiveTypeTriangle, 0, 3); |
| 32697 |
} |
| 32698 |
@@ -2002,7 +2109,8 @@ ANGLE_INLINE void SetPipelineState(ComputeCommandEncoder *encoder, |
| 32699 |
|
| 32700 |
angle::Result IndexGeneratorUtils::generateTriFanBufferFromElementsArray( |
| 32701 |
ContextMtl *contextMtl, |
| 32702 |
- const IndexGenerationParams ¶ms) |
| 32703 |
+ const IndexGenerationParams ¶ms, |
| 32704 |
+ uint32_t *indicesGenerated) |
| 32705 |
{ |
| 32706 |
const gl::VertexArray *vertexArray = contextMtl->getState().getVertexArray(); |
| 32707 |
const gl::Buffer *elementBuffer = vertexArray->getElementArrayBuffer(); |
| 32708 |
@@ -2013,13 +2121,14 @@ ANGLE_INLINE void SetPipelineState(ComputeCommandEncoder *encoder, |
| 32709 |
ANGLE_CHECK(contextMtl, srcOffset <= std::numeric_limits<uint32_t>::max(), |
| 32710 |
"Index offset is too large", GL_INVALID_VALUE); |
| 32711 |
if (params.primitiveRestartEnabled || |
| 32712 |
- (!contextMtl->getDisplay()->getFeatures().hasCheapRenderPass.enabled && |
| 32713 |
+ (!contextMtl->getDisplay()->getFeatures().breakRenderPassIsCheap.enabled && |
| 32714 |
contextMtl->getRenderCommandEncoder())) |
| 32715 |
{ |
| 32716 |
IndexGenerationParams cpuPathParams = params; |
| 32717 |
cpuPathParams.indices = |
| 32718 |
elementBufferMtl->getClientShadowCopyData(contextMtl) + srcOffset; |
| 32719 |
- return generateTriFanBufferFromElementsArrayCPU(contextMtl, cpuPathParams); |
| 32720 |
+ return generateTriFanBufferFromElementsArrayCPU(contextMtl, cpuPathParams, |
| 32721 |
+ indicesGenerated); |
| 32722 |
} |
| 32723 |
else |
| 32724 |
{ |
| 32725 |
@@ -2030,7 +2139,7 @@ ANGLE_INLINE void SetPipelineState(ComputeCommandEncoder *encoder, |
| 32726 |
} |
| 32727 |
else |
| 32728 |
{ |
| 32729 |
- return generateTriFanBufferFromElementsArrayCPU(contextMtl, params); |
| 32730 |
+ return generateTriFanBufferFromElementsArrayCPU(contextMtl, params, indicesGenerated); |
| 32731 |
} |
| 32732 |
} |
| 32733 |
|
| 32734 |
@@ -2074,22 +2183,23 @@ ANGLE_INLINE void SetPipelineState(ComputeCommandEncoder *encoder, |
| 32735 |
|
| 32736 |
angle::Result IndexGeneratorUtils::generateTriFanBufferFromElementsArrayCPU( |
| 32737 |
ContextMtl *contextMtl, |
| 32738 |
- const IndexGenerationParams ¶ms) |
| 32739 |
+ const IndexGenerationParams ¶ms, |
| 32740 |
+ uint32_t *genIndices) |
| 32741 |
{ |
| 32742 |
switch (params.srcType) |
| 32743 |
{ |
| 32744 |
case gl::DrawElementsType::UnsignedByte: |
| 32745 |
return GenTriFanFromClientElements( |
| 32746 |
contextMtl, params.indexCount, params.primitiveRestartEnabled, |
| 32747 |
- static_cast<const uint8_t *>(params.indices), params.dstBuffer, params.dstOffset); |
| 32748 |
+ static_cast<const uint8_t *>(params.indices), params.dstBuffer, params.dstOffset, genIndices); |
| 32749 |
case gl::DrawElementsType::UnsignedShort: |
| 32750 |
return GenTriFanFromClientElements( |
| 32751 |
contextMtl, params.indexCount, params.primitiveRestartEnabled, |
| 32752 |
- static_cast<const uint16_t *>(params.indices), params.dstBuffer, params.dstOffset); |
| 32753 |
+ static_cast<const uint16_t *>(params.indices), params.dstBuffer, params.dstOffset, genIndices); |
| 32754 |
case gl::DrawElementsType::UnsignedInt: |
| 32755 |
return GenTriFanFromClientElements( |
| 32756 |
contextMtl, params.indexCount, params.primitiveRestartEnabled, |
| 32757 |
- static_cast<const uint32_t *>(params.indices), params.dstBuffer, params.dstOffset); |
| 32758 |
+ static_cast<const uint32_t *>(params.indices), params.dstBuffer, params.dstOffset, genIndices); |
| 32759 |
default: |
| 32760 |
UNREACHABLE(); |
| 32761 |
} |
| 32762 |
@@ -2301,6 +2411,56 @@ ANGLE_INLINE void SetPipelineState(ComputeCommandEncoder *encoder, |
| 32763 |
return generateLineLoopLastSegment(contextMtl, first, last, params.dstBuffer, params.dstOffset); |
| 32764 |
} |
| 32765 |
|
| 32766 |
+angle::Result IndexGeneratorUtils::generatePrimitiveRestartBuffer( |
| 32767 |
+ ContextMtl *contextMtl, |
| 32768 |
+ unsigned numVerticesPerPrimitive, |
| 32769 |
+ const IndexGenerationParams ¶ms, |
| 32770 |
+ size_t *indicesGenerated) |
| 32771 |
+{ |
| 32772 |
+ switch (params.srcType) |
| 32773 |
+ { |
| 32774 |
+ case gl::DrawElementsType::UnsignedByte: |
| 32775 |
+ return GenPrimitiveRestartBuffer(contextMtl, params.indexCount, numVerticesPerPrimitive, |
| 32776 |
+ static_cast<const uint8_t *>(params.indices), |
| 32777 |
+ params.dstBuffer, params.dstOffset, indicesGenerated); |
| 32778 |
+ case gl::DrawElementsType::UnsignedShort: |
| 32779 |
+ return GenPrimitiveRestartBuffer(contextMtl, params.indexCount, numVerticesPerPrimitive, |
| 32780 |
+ static_cast<const uint16_t *>(params.indices), |
| 32781 |
+ params.dstBuffer, params.dstOffset, indicesGenerated); |
| 32782 |
+ case gl::DrawElementsType::UnsignedInt: |
| 32783 |
+ return GenPrimitiveRestartBuffer(contextMtl, params.indexCount, numVerticesPerPrimitive, |
| 32784 |
+ static_cast<const uint32_t *>(params.indices), |
| 32785 |
+ params.dstBuffer, params.dstOffset, indicesGenerated); |
| 32786 |
+ default: |
| 32787 |
+ UNREACHABLE(); |
| 32788 |
+ return angle::Result::Stop; |
| 32789 |
+ } |
| 32790 |
+} |
| 32791 |
+ |
| 32792 |
+angle::Result IndexGeneratorUtils::generatePrimitiveRestartTrianglesBuffer( |
| 32793 |
+ ContextMtl *contextMtl, |
| 32794 |
+ const IndexGenerationParams ¶ms, |
| 32795 |
+ size_t *indicesGenerated) |
| 32796 |
+{ |
| 32797 |
+ return generatePrimitiveRestartBuffer(contextMtl, 3, params, indicesGenerated); |
| 32798 |
+} |
| 32799 |
+ |
| 32800 |
+angle::Result IndexGeneratorUtils::generatePrimitiveRestartLinesBuffer( |
| 32801 |
+ ContextMtl *contextMtl, |
| 32802 |
+ const IndexGenerationParams ¶ms, |
| 32803 |
+ size_t *indicesGenerated) |
| 32804 |
+{ |
| 32805 |
+ return generatePrimitiveRestartBuffer(contextMtl, 2, params, indicesGenerated); |
| 32806 |
+} |
| 32807 |
+ |
| 32808 |
+angle::Result IndexGeneratorUtils::generatePrimitiveRestartPointsBuffer( |
| 32809 |
+ ContextMtl *contextMtl, |
| 32810 |
+ const IndexGenerationParams ¶ms, |
| 32811 |
+ size_t *indicesGenerated) |
| 32812 |
+{ |
| 32813 |
+ return generatePrimitiveRestartBuffer(contextMtl, 1, params, indicesGenerated); |
| 32814 |
+} |
| 32815 |
+ |
| 32816 |
// VisibilityResultUtils implementation |
| 32817 |
void VisibilityResultUtils::onDestroy() |
| 32818 |
{ |
| 32819 |
@@ -2376,6 +2536,9 @@ ANGLE_INLINE void SetPipelineState(ComputeCommandEncoder *encoder, |
| 32820 |
void MipmapUtils::onDestroy() |
| 32821 |
{ |
| 32822 |
m3DMipGeneratorPipeline = nil; |
| 32823 |
+ m2DMipGeneratorPipeline = nil; |
| 32824 |
+ m2DArrayMipGeneratorPipeline = nil; |
| 32825 |
+ mCubeMipGeneratorPipeline = nil; |
| 32826 |
} |
| 32827 |
|
| 32828 |
void MipmapUtils::ensure3DMipGeneratorPipelineInitialized(ContextMtl *contextMtl) |
| 32829 |
@@ -2384,66 +2547,78 @@ ANGLE_INLINE void SetPipelineState(ComputeCommandEncoder *encoder, |
| 32830 |
&m3DMipGeneratorPipeline); |
| 32831 |
} |
| 32832 |
|
| 32833 |
+void MipmapUtils::ensure2DMipGeneratorPipelineInitialized(ContextMtl *contextMtl) |
| 32834 |
+{ |
| 32835 |
+ EnsureComputePipelineInitialized(contextMtl->getDisplay(), @"generate2DMipmaps", |
| 32836 |
+ &m2DMipGeneratorPipeline); |
| 32837 |
+} |
| 32838 |
+ |
| 32839 |
+void MipmapUtils::ensure2DArrayMipGeneratorPipelineInitialized(ContextMtl *contextMtl) |
| 32840 |
+{ |
| 32841 |
+ EnsureComputePipelineInitialized(contextMtl->getDisplay(), @"generate2DArrayMipmaps", |
| 32842 |
+ &m2DArrayMipGeneratorPipeline); |
| 32843 |
+} |
| 32844 |
+ |
| 32845 |
+void MipmapUtils::ensureCubeMipGeneratorPipelineInitialized(ContextMtl *contextMtl) |
| 32846 |
+{ |
| 32847 |
+ EnsureComputePipelineInitialized(contextMtl->getDisplay(), @"generateCubeMipmaps", |
| 32848 |
+ &mCubeMipGeneratorPipeline); |
| 32849 |
+} |
| 32850 |
+ |
| 32851 |
angle::Result MipmapUtils::generateMipmapCS(ContextMtl *contextMtl, |
| 32852 |
const TextureRef &srcTexture, |
| 32853 |
bool sRGBMipmap, |
| 32854 |
- NativeTexLevelArray *mipmapOutputViews) |
| 32855 |
+ NativeTexLevelArray * mipmapOutputViews) |
| 32856 |
{ |
| 32857 |
- // Only support 3D texture for now. |
| 32858 |
- ASSERT(srcTexture->textureType() == MTLTextureType3D); |
| 32859 |
+ ComputeCommandEncoder *cmdEncoder = contextMtl->getComputeCommandEncoder(); |
| 32860 |
+ ASSERT(cmdEncoder); |
| 32861 |
|
| 32862 |
MTLSize threadGroupSize; |
| 32863 |
uint32_t slices = 1; |
| 32864 |
- id<MTLComputePipelineState> computePipeline = nil; |
| 32865 |
- |
| 32866 |
+ switch (srcTexture->textureType()) |
| 32867 |
+ { |
| 32868 |
+ case MTLTextureType2D: |
| 32869 |
+ ensure2DMipGeneratorPipelineInitialized(contextMtl); |
| 32870 |
+ cmdEncoder->setComputePipelineState(m2DMipGeneratorPipeline); |
| 32871 |
+ threadGroupSize = MTLSizeMake(kGenerateMipThreadGroupSizePerDim, |
| 32872 |
+ kGenerateMipThreadGroupSizePerDim, 1); |
| 32873 |
+ break; |
| 32874 |
+ case MTLTextureType2DArray: |
| 32875 |
+ ensure2DArrayMipGeneratorPipelineInitialized(contextMtl); |
| 32876 |
+ cmdEncoder->setComputePipelineState(m2DArrayMipGeneratorPipeline); |
| 32877 |
+ slices = srcTexture->arrayLength(); |
| 32878 |
+ threadGroupSize = MTLSizeMake(kGenerateMipThreadGroupSizePerDim, |
| 32879 |
+ kGenerateMipThreadGroupSizePerDim, 1); |
| 32880 |
+ break; |
| 32881 |
+ case MTLTextureTypeCube: |
| 32882 |
+ ensureCubeMipGeneratorPipelineInitialized(contextMtl); |
| 32883 |
+ cmdEncoder->setComputePipelineState(mCubeMipGeneratorPipeline); |
| 32884 |
+ slices = 6; |
| 32885 |
+ threadGroupSize = MTLSizeMake(kGenerateMipThreadGroupSizePerDim, |
| 32886 |
+ kGenerateMipThreadGroupSizePerDim, 1); |
| 32887 |
+ break; |
| 32888 |
+ case MTLTextureType3D: |
| 32889 |
ensure3DMipGeneratorPipelineInitialized(contextMtl); |
| 32890 |
- computePipeline = m3DMipGeneratorPipeline; |
| 32891 |
+ cmdEncoder->setComputePipelineState(m3DMipGeneratorPipeline); |
| 32892 |
threadGroupSize = |
| 32893 |
MTLSizeMake(kGenerateMipThreadGroupSizePerDim, kGenerateMipThreadGroupSizePerDim, |
| 32894 |
kGenerateMipThreadGroupSizePerDim); |
| 32895 |
- |
| 32896 |
- // The compute shader supports up to 4 mipmaps generated per pass. |
| 32897 |
- // See shaders/gen_mipmap.metal |
| 32898 |
- uint32_t maxMipsPerBatch = 4; |
| 32899 |
- |
| 32900 |
- if (threadGroupSize.width * threadGroupSize.height * threadGroupSize.depth > |
| 32901 |
- computePipeline.maxTotalThreadsPerThreadgroup || |
| 32902 |
- ANGLE_UNLIKELY( |
| 32903 |
- !contextMtl->getDisplay()->getFeatures().allowGenMultipleMipsPerPass.enabled)) |
| 32904 |
- { |
| 32905 |
- // Multiple mipmaps generation is not supported due to hardware's thread group size limits. |
| 32906 |
- // Fallback to generate one mip per pass and reduce thread group size. |
| 32907 |
- if (ANGLE_UNLIKELY(threadGroupSize.width * threadGroupSize.height > |
| 32908 |
- computePipeline.maxTotalThreadsPerThreadgroup)) |
| 32909 |
- { |
| 32910 |
- // Even with reduced thread group size, we cannot proceed. |
| 32911 |
- // HACK: use blit command encoder to generate mipmaps if it is not possible |
| 32912 |
- // to use compute shader due to hardware limits. |
| 32913 |
- BlitCommandEncoder *blitEncoder = contextMtl->getBlitCommandEncoder(); |
| 32914 |
- blitEncoder->generateMipmapsForTexture(srcTexture); |
| 32915 |
- return angle::Result::Continue; |
| 32916 |
- } |
| 32917 |
- |
| 32918 |
- threadGroupSize.depth = 1; |
| 32919 |
- maxMipsPerBatch = 1; |
| 32920 |
+ break; |
| 32921 |
+ default: |
| 32922 |
+ UNREACHABLE(); |
| 32923 |
} |
| 32924 |
|
| 32925 |
- ComputeCommandEncoder *cmdEncoder = contextMtl->getComputeCommandEncoder(); |
| 32926 |
- ASSERT(cmdEncoder); |
| 32927 |
- cmdEncoder->setComputePipelineState(computePipeline); |
| 32928 |
- |
| 32929 |
- GenerateMipmapUniform options; |
| 32930 |
+ Generate3DMipmapUniform options; |
| 32931 |
+ uint32_t maxMipsPerBatch = 4; |
| 32932 |
|
| 32933 |
uint32_t remainMips = srcTexture->mipmapLevels() - 1; |
| 32934 |
- MipmapNativeLevel batchSrcLevel = kZeroNativeMipLevel; |
| 32935 |
- options.srcLevel = batchSrcLevel.get(); |
| 32936 |
- options.sRGB = sRGBMipmap; |
| 32937 |
+ options.srcLevel = 0; |
| 32938 |
|
| 32939 |
cmdEncoder->setTexture(srcTexture, 0); |
| 32940 |
cmdEncoder->markResourceBeingWrittenByGPU(srcTexture); |
| 32941 |
while (remainMips) |
| 32942 |
{ |
| 32943 |
- const TextureRef &firstMipView = mipmapOutputViews->at(batchSrcLevel + 1); |
| 32944 |
+ const TextureRef &firstMipView = mipmapOutputViews->at(mtl::MipmapNativeLevel(options.srcLevel + 1)); |
| 32945 |
gl::Extents size = firstMipView->sizeAt0(); |
| 32946 |
bool isPow2 = gl::isPow2(size.width) && gl::isPow2(size.height) && gl::isPow2(size.depth); |
| 32947 |
|
| 32948 |
@@ -2461,20 +2636,18 @@ ANGLE_INLINE void SetPipelineState(ComputeCommandEncoder *encoder, |
| 32949 |
|
| 32950 |
for (uint32_t i = 1; i <= options.numMipmapsToGenerate; ++i) |
| 32951 |
{ |
| 32952 |
- cmdEncoder->setTexture(mipmapOutputViews->at(batchSrcLevel + i), i); |
| 32953 |
+ cmdEncoder->setTexture(mipmapOutputViews->at(mtl::MipmapNativeLevel(options.srcLevel + i)), i); |
| 32954 |
} |
| 32955 |
|
| 32956 |
uint32_t threadsPerZ = std::max(slices, firstMipView->depthAt0()); |
| 32957 |
|
| 32958 |
- DispatchCompute( |
| 32959 |
- contextMtl, cmdEncoder, |
| 32960 |
+ DispatchCompute(contextMtl, cmdEncoder, |
| 32961 |
/** allowNonUniform */ false, |
| 32962 |
MTLSizeMake(firstMipView->widthAt0(), firstMipView->heightAt0(), threadsPerZ), |
| 32963 |
threadGroupSize); |
| 32964 |
|
| 32965 |
remainMips -= options.numMipmapsToGenerate; |
| 32966 |
- batchSrcLevel = batchSrcLevel + options.numMipmapsToGenerate; |
| 32967 |
- options.srcLevel = batchSrcLevel.get(); |
| 32968 |
+ options.srcLevel += options.numMipmapsToGenerate; |
| 32969 |
} |
| 32970 |
|
| 32971 |
return angle::Result::Continue; |
| 32972 |
@@ -2504,8 +2677,7 @@ ANGLE_INLINE void SetPipelineState(ComputeCommandEncoder *encoder, |
| 32973 |
int shaderTextureType = GetShaderTextureType(texture); |
| 32974 |
int index2 = mtl_shader::kTextureTypeCount * (bufferWrite ? 1 : 0) + shaderTextureType; |
| 32975 |
|
| 32976 |
- AutoObjCPtr<id<MTLComputePipelineState>> &cache = |
| 32977 |
- mPixelsCopyPipelineCaches[formatIDValue][index2]; |
| 32978 |
+ auto &cache = mPixelsCopyPipelineCaches[formatIDValue][index2]; |
| 32979 |
|
| 32980 |
if (!cache) |
| 32981 |
{ |
| 32982 |
@@ -2783,7 +2955,10 @@ ANGLE_INLINE void SetPipelineState(ComputeCommandEncoder *encoder, |
| 32983 |
VertexFormatConversionUtils::getComponentsExpandRenderPipeline(ContextMtl *contextMtl, |
| 32984 |
RenderCommandEncoder *cmdEncoder) |
| 32985 |
{ |
| 32986 |
+ DisplayMtl *display = contextMtl->getDisplay(); |
| 32987 |
+ auto shaderLib = display->getDefaultShadersLib(); |
| 32988 |
EnsureVertexShaderOnlyPipelineCacheInitialized(contextMtl, @"expandVertexFormatComponentsVS", |
| 32989 |
+ shaderLib, |
| 32990 |
&mComponentsExpandRenderPipelineCache); |
| 32991 |
|
| 32992 |
RenderPipelineDesc pipelineDesc = GetComputingVertexShaderOnlyRenderPipelineDesc(cmdEncoder); |
| 32993 |
@@ -2797,8 +2972,7 @@ ANGLE_INLINE void SetPipelineState(ComputeCommandEncoder *encoder, |
| 32994 |
{ |
| 32995 |
int formatIDValue = static_cast<int>(srcAngleFormat.id); |
| 32996 |
|
| 32997 |
- AutoObjCPtr<id<MTLComputePipelineState>> &cache = |
| 32998 |
- mConvertToFloatCompPipelineCaches[formatIDValue]; |
| 32999 |
+ auto &cache = mConvertToFloatCompPipelineCaches[formatIDValue]; |
| 33000 |
|
| 33001 |
if (!cache) |
| 33002 |
{ |
| 33003 |
@@ -2849,5 +3023,53 @@ ANGLE_INLINE void SetPipelineState(ComputeCommandEncoder *encoder, |
| 33004 |
return cache.getRenderPipelineState(contextMtl, pipelineDesc); |
| 33005 |
} |
| 33006 |
|
| 33007 |
+AutoObjCPtr<id<MTLLibrary>> TransformFeedbackUtils::createMslXfbLibrary( |
| 33008 |
+ ContextMtl *contextMtl, |
| 33009 |
+ const std::string &translatedMsl) |
| 33010 |
+{ |
| 33011 |
+ ANGLE_MTL_OBJC_SCOPE |
| 33012 |
+ { |
| 33013 |
+ DisplayMtl *display = contextMtl->getDisplay(); |
| 33014 |
+ id<MTLDevice> mtlDevice = display->getMetalDevice(); |
| 33015 |
+ |
| 33016 |
+ // Convert to actual binary shader |
| 33017 |
+ mtl::AutoObjCPtr<NSError *> err = nil; |
| 33018 |
+ mtl::AutoObjCPtr<id<MTLLibrary>> mtlShaderLib = |
| 33019 |
+ mtl::CreateShaderLibrary(mtlDevice, translatedMsl, &err); |
| 33020 |
+ if (err && !mtlShaderLib) |
| 33021 |
+ { |
| 33022 |
+ NSLog(@"%@", err.get()); |
| 33023 |
+ assert(0); |
| 33024 |
+ } |
| 33025 |
+ return mtlShaderLib; |
| 33026 |
+ } |
| 33027 |
+} |
| 33028 |
+ |
| 33029 |
+AutoObjCPtr<id<MTLRenderPipelineState>> TransformFeedbackUtils::getTransformFeedbackRenderPipeline( |
| 33030 |
+ ContextMtl *contextMtl, |
| 33031 |
+ RenderCommandEncoder *cmdEncoder, |
| 33032 |
+ mtl::RenderPipelineDesc &pipelineDesc) |
| 33033 |
+{ |
| 33034 |
+ const ProgramMtl *programMtl = mtl::GetImpl(contextMtl->getState().getProgram()); |
| 33035 |
+ RenderPipelineCache &cache = *programMtl->mMetalXfbRenderPipelineCache; |
| 33036 |
+ |
| 33037 |
+ if (!cache.getVertexShader()) |
| 33038 |
+ { |
| 33039 |
+ // Pipeline cache not intialized, do it now: |
| 33040 |
+ ANGLE_MTL_OBJC_SCOPE |
| 33041 |
+ { |
| 33042 |
+ auto shaderLib = createMslXfbLibrary(contextMtl, programMtl->getXfbMslSource()); |
| 33043 |
+ // Non specialized constants provided, use default creation function. |
| 33044 |
+ EnsureVertexShaderOnlyPipelineCacheInitialized(contextMtl, SHADER_ENTRY_NAME, shaderLib, |
| 33045 |
+ &cache); |
| 33046 |
+ } |
| 33047 |
+ } |
| 33048 |
+ |
| 33049 |
+ RenderPipelineDesc xfbPipelineDesc = |
| 33050 |
+ GetTransformFeedbackRenderPipelineDesc(cmdEncoder, pipelineDesc); |
| 33051 |
+ |
| 33052 |
+ return cache.getRenderPipelineState(contextMtl, xfbPipelineDesc); |
| 33053 |
+} |
| 33054 |
+ |
| 33055 |
} // namespace mtl |
| 33056 |
} // namespace rx |
| 33057 |
diff --git a/src/libANGLE/renderer/metal/mtl_resources.h b/src/libANGLE/renderer/metal/mtl_resources.h |
| 33058 |
index f220650..2e3334d 100644 |
| 33059 |
--- a/src/libANGLE/renderer/metal/mtl_resources.h |
| 33060 |
+++ b/src/libANGLE/renderer/metal/mtl_resources.h |
| 33061 |
@@ -63,7 +63,6 @@ class Resource : angle::NonCopyable |
| 33062 |
bool isCPUReadMemNeedSync() const { return mUsageRef->cpuReadMemNeedSync; } |
| 33063 |
void resetCPUReadMemNeedSync() { mUsageRef->cpuReadMemNeedSync = false; } |
| 33064 |
|
| 33065 |
- // These functions are useful for BufferMtl to know whether it should update the shadow copy |
| 33066 |
bool isCPUReadMemDirty() const { return mUsageRef->cpuReadMemDirty; } |
| 33067 |
void resetCPUReadMemDirty() { mUsageRef->cpuReadMemDirty = false; } |
| 33068 |
|
| 33069 |
@@ -81,7 +80,7 @@ class Resource : angle::NonCopyable |
| 33070 |
uint64_t cmdBufferQueueSerial = 0; |
| 33071 |
|
| 33072 |
// This flag means the resource was issued to be modified by GPU, if CPU wants to read |
| 33073 |
- // its content, explicit synchronization call must be invoked. |
| 33074 |
+ // its content, explicit synchornization call must be invoked. |
| 33075 |
bool cpuReadMemNeedSync = false; |
| 33076 |
|
| 33077 |
// This flag is useful for BufferMtl to know whether it should update the shadow copy |
| 33078 |
@@ -110,6 +109,13 @@ class Texture final : public Resource, |
| 33079 |
bool allowFormatView, |
| 33080 |
TextureRef *refOut); |
| 33081 |
|
| 33082 |
+ // On macOS, memory will still be allocated for this texture. |
| 33083 |
+ static angle::Result MakeMemoryLess2DTexture(ContextMtl *context, |
| 33084 |
+ const Format &format, |
| 33085 |
+ uint32_t width, |
| 33086 |
+ uint32_t height, |
| 33087 |
+ TextureRef *refOut); |
| 33088 |
+ |
| 33089 |
static angle::Result MakeCubeTexture(ContextMtl *context, |
| 33090 |
const Format &format, |
| 33091 |
uint32_t size, |
| 33092 |
@@ -147,10 +153,21 @@ class Texture final : public Resource, |
| 33093 |
bool allowFormatView, |
| 33094 |
TextureRef *refOut); |
| 33095 |
|
| 33096 |
+ static angle::Result MakeIOSurfaceTexture(ContextMtl *context, |
| 33097 |
+ const Format &format, |
| 33098 |
+ uint32_t width, |
| 33099 |
+ uint32_t height, |
| 33100 |
+ IOSurfaceRef ref, |
| 33101 |
+ uint32_t plane, |
| 33102 |
+ TextureRef *refOut); |
| 33103 |
+ |
| 33104 |
static TextureRef MakeFromMetal(id<MTLTexture> metalTexture); |
| 33105 |
|
| 33106 |
// Allow CPU to read & write data directly to this texture? |
| 33107 |
bool isCPUAccessible() const; |
| 33108 |
+ // Allow shaders to read/sample this texture? |
| 33109 |
+ // Texture created with renderTargetOnly flag won't be readable |
| 33110 |
+ bool isShaderReadable() const; |
| 33111 |
|
| 33112 |
bool supportFormatView() const; |
| 33113 |
|
| 33114 |
@@ -218,16 +235,29 @@ class Texture final : public Resource, |
| 33115 |
MTLColorWriteMask getColorWritableMask() const { return *mColorWritableMask; } |
| 33116 |
void setColorWritableMask(MTLColorWriteMask mask) { *mColorWritableMask = mask; } |
| 33117 |
|
| 33118 |
- // Get linear color space view. Only usable for sRGB textures. |
| 33119 |
- TextureRef getLinearColorView(); |
| 33120 |
+ // Get reading copy. Used for reading non-readable texture or reading stencil value from |
| 33121 |
+ // packed depth & stencil texture. |
| 33122 |
+ // NOTE: this only copies 1 depth slice of the 3D texture. |
| 33123 |
+ // The texels will be copied to region(0, 0, 0, areaToCopy.size) of the returned texture. |
| 33124 |
+ // The returned pointer will be retained by the original texture object. |
| 33125 |
+ // Calling getReadableCopy() will overwrite previously returned texture. |
| 33126 |
+ TextureRef getReadableCopy(ContextMtl *context, |
| 33127 |
+ mtl::BlitCommandEncoder *encoder, |
| 33128 |
+ const uint32_t levelToCopy, |
| 33129 |
+ const uint32_t sliceToCopy, |
| 33130 |
+ const MTLRegion &areaToCopy); |
| 33131 |
+ |
| 33132 |
+ void releaseReadableCopy(); |
| 33133 |
|
| 33134 |
// Get stencil view |
| 33135 |
TextureRef getStencilView(); |
| 33136 |
+ //Get linear color |
| 33137 |
+ TextureRef getLinearColorView(); |
| 33138 |
|
| 33139 |
// Change the wrapped metal object. Special case for swapchain image |
| 33140 |
void set(id<MTLTexture> metalTexture); |
| 33141 |
|
| 33142 |
- // sync content between CPU and GPU |
| 33143 |
+ // Explicitly sync content between CPU and GPU |
| 33144 |
void syncContent(ContextMtl *context, mtl::BlitCommandEncoder *encoder); |
| 33145 |
|
| 33146 |
private: |
| 33147 |
@@ -241,12 +271,41 @@ class Texture final : public Resource, |
| 33148 |
bool allowFormatView, |
| 33149 |
TextureRef *refOut); |
| 33150 |
|
| 33151 |
+ static angle::Result MakeTexture(ContextMtl *context, |
| 33152 |
+ const Format &mtlFormat, |
| 33153 |
+ MTLTextureDescriptor *desc, |
| 33154 |
+ uint32_t mips, |
| 33155 |
+ bool renderTargetOnly, |
| 33156 |
+ bool allowFormatView, |
| 33157 |
+ bool memoryLess, |
| 33158 |
+ TextureRef *refOut); |
| 33159 |
+ |
| 33160 |
+ static angle::Result MakeTexture(ContextMtl *context, |
| 33161 |
+ const Format &mtlFormat, |
| 33162 |
+ MTLTextureDescriptor *desc, |
| 33163 |
+ IOSurfaceRef surfaceRef, |
| 33164 |
+ NSUInteger slice, |
| 33165 |
+ bool renderTargetOnly, |
| 33166 |
+ TextureRef *refOut); |
| 33167 |
+ |
| 33168 |
Texture(id<MTLTexture> metalTexture); |
| 33169 |
Texture(ContextMtl *context, |
| 33170 |
MTLTextureDescriptor *desc, |
| 33171 |
uint32_t mips, |
| 33172 |
bool renderTargetOnly, |
| 33173 |
bool allowFormatView); |
| 33174 |
+ Texture(ContextMtl *context, |
| 33175 |
+ MTLTextureDescriptor *desc, |
| 33176 |
+ uint32_t mips, |
| 33177 |
+ bool renderTargetOnly, |
| 33178 |
+ bool allowFormatView, |
| 33179 |
+ bool memoryLess); |
| 33180 |
+ |
| 33181 |
+ Texture(ContextMtl *context, |
| 33182 |
+ MTLTextureDescriptor *desc, |
| 33183 |
+ IOSurfaceRef iosurface, |
| 33184 |
+ NSUInteger plane, |
| 33185 |
+ bool renderTargetOnly); |
| 33186 |
|
| 33187 |
// Create a texture view |
| 33188 |
Texture(Texture *original, MTLPixelFormat format); |
| 33189 |
@@ -264,9 +323,14 @@ class Texture final : public Resource, |
| 33190 |
TextureRef mLinearColorView; |
| 33191 |
|
| 33192 |
TextureRef mStencilView; |
| 33193 |
+ //Readable copy of texture |
| 33194 |
+ TextureRef mReadCopy; |
| 33195 |
+ |
| 33196 |
}; |
| 33197 |
|
| 33198 |
-class Buffer final : public Resource, public WrappedObject<id<MTLBuffer>> |
| 33199 |
+class Buffer final : public Resource, |
| 33200 |
+ public WrappedObject<id<MTLBuffer>>, |
| 33201 |
+ public std::enable_shared_from_this<Buffer> |
| 33202 |
{ |
| 33203 |
public: |
| 33204 |
static angle::Result MakeBuffer(ContextMtl *context, |
| 33205 |
diff --git a/src/libANGLE/renderer/metal/mtl_resources.mm b/src/libANGLE/renderer/metal/mtl_resources.mm |
| 33206 |
index 9bee475..d0475ae 100644 |
| 33207 |
--- a/src/libANGLE/renderer/metal/mtl_resources.mm |
| 33208 |
+++ b/src/libANGLE/renderer/metal/mtl_resources.mm |
| 33209 |
@@ -34,20 +34,22 @@ inline NSUInteger GetMipSize(NSUInteger baseSize, const MipmapNativeLevel level) |
| 33210 |
// Asynchronously synchronize the content of a resource between GPU memory and its CPU cache. |
| 33211 |
// NOTE: This operation doesn't finish immediately upon function's return. |
| 33212 |
template <class T> |
| 33213 |
-void InvokeCPUMemSync(ContextMtl *context, mtl::BlitCommandEncoder *blitEncoder, T *resource) |
| 33214 |
+void SyncContent(ContextMtl *context, |
| 33215 |
+ mtl::BlitCommandEncoder *blitEncoder, |
| 33216 |
+ const std::shared_ptr<T> &resource) |
| 33217 |
{ |
| 33218 |
#if TARGET_OS_OSX || TARGET_OS_MACCATALYST |
| 33219 |
if (blitEncoder) |
| 33220 |
{ |
| 33221 |
blitEncoder->synchronizeResource(resource); |
| 33222 |
+ |
| 33223 |
resource->resetCPUReadMemNeedSync(); |
| 33224 |
} |
| 33225 |
#endif |
| 33226 |
} |
| 33227 |
-// Ensure that a resource's CPU cache will be synchronized after GPU finishes its modifications on |
| 33228 |
-// the resource. |
| 33229 |
+ |
| 33230 |
template <class T> |
| 33231 |
-void EnsureCPUMemWillBeSynced(ContextMtl *context, T *resource) |
| 33232 |
+void EnsureContentSynced(ContextMtl *context, const std::shared_ptr<T> &resource) |
| 33233 |
{ |
| 33234 |
#if TARGET_OS_OSX || TARGET_OS_MACCATALYST |
| 33235 |
// Make sure GPU & CPU contents are synchronized. |
| 33236 |
@@ -56,7 +58,7 @@ void EnsureCPUMemWillBeSynced(ContextMtl *context, T *resource) |
| 33237 |
if (resource->get().storageMode == MTLStorageModeManaged && resource->isCPUReadMemNeedSync()) |
| 33238 |
{ |
| 33239 |
mtl::BlitCommandEncoder *blitEncoder = context->getBlitCommandEncoder(); |
| 33240 |
- InvokeCPUMemSync(context, blitEncoder, resource); |
| 33241 |
+ SyncContent(context, blitEncoder, resource); |
| 33242 |
} |
| 33243 |
#endif |
| 33244 |
} |
| 33245 |
@@ -122,6 +124,24 @@ void EnsureCPUMemWillBeSynced(ContextMtl *context, T *resource) |
| 33246 |
} // ANGLE_MTL_OBJC_SCOPE |
| 33247 |
} |
| 33248 |
|
| 33249 |
+/** static */ |
| 33250 |
+angle::Result Texture::MakeMemoryLess2DTexture(ContextMtl *context, |
| 33251 |
+ const Format &format, |
| 33252 |
+ uint32_t width, |
| 33253 |
+ uint32_t height, |
| 33254 |
+ TextureRef *refOut) |
| 33255 |
+{ |
| 33256 |
+ ANGLE_MTL_OBJC_SCOPE |
| 33257 |
+ { |
| 33258 |
+ MTLTextureDescriptor *desc = |
| 33259 |
+ [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:format.metalFormat |
| 33260 |
+ width:width |
| 33261 |
+ height:height |
| 33262 |
+ mipmapped:NO]; |
| 33263 |
+ |
| 33264 |
+ return MakeTexture(context, format, desc, 1, true, false, true, refOut); |
| 33265 |
+ } // ANGLE_MTL_OBJC_SCOPE |
| 33266 |
+} |
| 33267 |
/** static */ |
| 33268 |
angle::Result Texture::MakeCubeTexture(ContextMtl *context, |
| 33269 |
const Format &format, |
| 33270 |
@@ -223,6 +243,23 @@ void EnsureCPUMemWillBeSynced(ContextMtl *context, T *resource) |
| 33271 |
return MakeTexture(context, format, desc, mips, renderTargetOnly, allowFormatView, refOut); |
| 33272 |
} // ANGLE_MTL_OBJC_SCOPE |
| 33273 |
} |
| 33274 |
+angle::Result Texture::MakeIOSurfaceTexture(ContextMtl *context, |
| 33275 |
+ const Format &format, |
| 33276 |
+ uint32_t width, |
| 33277 |
+ uint32_t height, |
| 33278 |
+ IOSurfaceRef ref, |
| 33279 |
+ uint32_t plane, |
| 33280 |
+ TextureRef *refOut) |
| 33281 |
+{ |
| 33282 |
+ MTLTextureDescriptor *desc = [[MTLTextureDescriptor new] ANGLE_MTL_AUTORELEASE]; |
| 33283 |
+ desc.textureType = MTLTextureType2D; |
| 33284 |
+ desc.pixelFormat = format.metalFormat; |
| 33285 |
+ desc.width = width; |
| 33286 |
+ desc.height = height; |
| 33287 |
+ desc.mipmapLevelCount = 1; |
| 33288 |
+ desc.sampleCount = 1; |
| 33289 |
+ return MakeTexture(context, format, desc, ref, plane, NO, refOut); |
| 33290 |
+} |
| 33291 |
|
| 33292 |
/** static */ |
| 33293 |
angle::Result Texture::MakeTexture(ContextMtl *context, |
| 33294 |
@@ -233,7 +270,42 @@ void EnsureCPUMemWillBeSynced(ContextMtl *context, T *resource) |
| 33295 |
bool allowFormatView, |
| 33296 |
TextureRef *refOut) |
| 33297 |
{ |
| 33298 |
- refOut->reset(new Texture(context, desc, mips, renderTargetOnly, allowFormatView)); |
| 33299 |
+ return MakeTexture(context, mtlFormat, desc, mips, renderTargetOnly, allowFormatView, false, |
| 33300 |
+ refOut); |
| 33301 |
+} |
| 33302 |
+ |
| 33303 |
+angle::Result Texture::MakeTexture(ContextMtl *context, |
| 33304 |
+ const Format &mtlFormat, |
| 33305 |
+ MTLTextureDescriptor *desc, |
| 33306 |
+ uint32_t mips, |
| 33307 |
+ bool renderTargetOnly, |
| 33308 |
+ bool allowFormatView, |
| 33309 |
+ bool memoryLess, |
| 33310 |
+ TextureRef *refOut) |
| 33311 |
+{ |
| 33312 |
+ refOut->reset(new Texture(context, desc, mips, renderTargetOnly, allowFormatView, memoryLess)); |
| 33313 |
+ |
| 33314 |
+ if (!refOut || !refOut->get()) |
| 33315 |
+ { |
| 33316 |
+ ANGLE_MTL_CHECK(context, false, GL_OUT_OF_MEMORY); |
| 33317 |
+ } |
| 33318 |
+ if (!mtlFormat.hasDepthAndStencilBits()) |
| 33319 |
+ { |
| 33320 |
+ refOut->get()->setColorWritableMask(GetEmulatedColorWriteMask(mtlFormat)); |
| 33321 |
+ } |
| 33322 |
+ |
| 33323 |
+ return angle::Result::Continue; |
| 33324 |
+} |
| 33325 |
+ |
| 33326 |
+angle::Result Texture::MakeTexture(ContextMtl *context, |
| 33327 |
+ const Format &mtlFormat, |
| 33328 |
+ MTLTextureDescriptor *desc, |
| 33329 |
+ IOSurfaceRef surfaceRef, |
| 33330 |
+ NSUInteger slice, |
| 33331 |
+ bool renderTargetOnly, |
| 33332 |
+ TextureRef *refOut) |
| 33333 |
+{ |
| 33334 |
+ refOut->reset(new Texture(context, desc, surfaceRef, slice, renderTargetOnly)); |
| 33335 |
|
| 33336 |
if (!(*refOut) || !(*refOut)->get()) |
| 33337 |
{ |
| 33338 |
@@ -264,6 +336,15 @@ void EnsureCPUMemWillBeSynced(ContextMtl *context, T *resource) |
| 33339 |
uint32_t mips, |
| 33340 |
bool renderTargetOnly, |
| 33341 |
bool allowFormatView) |
| 33342 |
+ : Texture(context, desc, mips, renderTargetOnly, allowFormatView, false) |
| 33343 |
+{} |
| 33344 |
+ |
| 33345 |
+Texture::Texture(ContextMtl *context, |
| 33346 |
+ MTLTextureDescriptor *desc, |
| 33347 |
+ uint32_t mips, |
| 33348 |
+ bool renderTargetOnly, |
| 33349 |
+ bool allowFormatView, |
| 33350 |
+ bool memoryLess) |
| 33351 |
: mColorWritableMask(std::make_shared<MTLColorWriteMask>(MTLColorWriteMaskAll)) |
| 33352 |
{ |
| 33353 |
ANGLE_MTL_OBJC_SCOPE |
| 33354 |
@@ -283,7 +364,15 @@ void EnsureCPUMemWillBeSynced(ContextMtl *context, T *resource) |
| 33355 |
desc.usage |= MTLTextureUsageRenderTarget; |
| 33356 |
} |
| 33357 |
|
| 33358 |
- if (context->getNativeFormatCaps(desc.pixelFormat).depthRenderable || |
| 33359 |
+ if (memoryLess) |
| 33360 |
+ { |
| 33361 |
+#if (TARGET_OS_IOS || TARGET_OS_TV) && !TARGET_OS_MACCATALYST |
| 33362 |
+ desc.resourceOptions = MTLResourceStorageModeMemoryless; |
| 33363 |
+#else |
| 33364 |
+ desc.resourceOptions = MTLResourceStorageModePrivate; |
| 33365 |
+#endif |
| 33366 |
+ } |
| 33367 |
+ else if (context->getNativeFormatCaps(desc.pixelFormat).depthRenderable || |
| 33368 |
desc.textureType == MTLTextureType2DMultisample) |
| 33369 |
{ |
| 33370 |
// Metal doesn't support host access to depth stencil texture's data |
| 33371 |
@@ -310,6 +399,46 @@ void EnsureCPUMemWillBeSynced(ContextMtl *context, T *resource) |
| 33372 |
} |
| 33373 |
} |
| 33374 |
|
| 33375 |
+Texture::Texture(ContextMtl *context, |
| 33376 |
+ MTLTextureDescriptor *desc, |
| 33377 |
+ IOSurfaceRef iosurface, |
| 33378 |
+ NSUInteger plane, |
| 33379 |
+ bool renderTargetOnly) |
| 33380 |
+ : mColorWritableMask(std::make_shared<MTLColorWriteMask>(MTLColorWriteMaskAll)) |
| 33381 |
+{ |
| 33382 |
+ ANGLE_MTL_OBJC_SCOPE |
| 33383 |
+ { |
| 33384 |
+ id<MTLDevice> metalDevice = context->getMetalDevice(); |
| 33385 |
+ |
| 33386 |
+ // Every texture will support being rendered for now |
| 33387 |
+ desc.usage = MTLTextureUsagePixelFormatView; |
| 33388 |
+ |
| 33389 |
+ if (context->getNativeFormatCaps(desc.pixelFormat).isRenderable()) |
| 33390 |
+ { |
| 33391 |
+ desc.usage |= MTLTextureUsageRenderTarget; |
| 33392 |
+ } |
| 33393 |
+ |
| 33394 |
+#if (TARGET_OS_IOS || TARGET_OS_TV) && !TARGET_OS_MACCATALYST |
| 33395 |
+ desc.resourceOptions = MTLResourceStorageModeShared; |
| 33396 |
+#else |
| 33397 |
+ desc.resourceOptions = MTLResourceStorageModeManaged; |
| 33398 |
+#endif |
| 33399 |
+ |
| 33400 |
+ if (!renderTargetOnly) |
| 33401 |
+ { |
| 33402 |
+ desc.usage = desc.usage | MTLTextureUsageShaderRead; |
| 33403 |
+ if (context->getNativeFormatCaps(desc.pixelFormat).writable) |
| 33404 |
+ { |
| 33405 |
+ desc.usage = desc.usage | MTLTextureUsageShaderWrite; |
| 33406 |
+ } |
| 33407 |
+ } |
| 33408 |
+ id<MTLTexture> iosurfTexture = [metalDevice newTextureWithDescriptor:desc |
| 33409 |
+ iosurface:iosurface |
| 33410 |
+ plane:plane]; |
| 33411 |
+ set([iosurfTexture ANGLE_MTL_AUTORELEASE]); |
| 33412 |
+ } |
| 33413 |
+} |
| 33414 |
+ |
| 33415 |
Texture::Texture(Texture *original, MTLPixelFormat format) |
| 33416 |
: Resource(original), |
| 33417 |
mColorWritableMask(original->mColorWritableMask) // Share color write mask property |
| 33418 |
@@ -341,7 +470,7 @@ void EnsureCPUMemWillBeSynced(ContextMtl *context, T *resource) |
| 33419 |
: Resource(original), |
| 33420 |
mColorWritableMask(original->mColorWritableMask) // Share color write mask property |
| 33421 |
{ |
| 33422 |
-#if ANGLE_MTL_SWIZZLE_AVAILABLE |
| 33423 |
+#if defined(__IPHONE_13_0) || defined(__MAC_10_15) |
| 33424 |
ANGLE_MTL_OBJC_SCOPE |
| 33425 |
{ |
| 33426 |
auto view = [original->get() |
| 33427 |
@@ -360,12 +489,12 @@ void EnsureCPUMemWillBeSynced(ContextMtl *context, T *resource) |
| 33428 |
|
| 33429 |
void Texture::syncContent(ContextMtl *context, mtl::BlitCommandEncoder *blitEncoder) |
| 33430 |
{ |
| 33431 |
- InvokeCPUMemSync(context, blitEncoder, this); |
| 33432 |
+ SyncContent(context, blitEncoder, shared_from_this()); |
| 33433 |
} |
| 33434 |
|
| 33435 |
void Texture::syncContentIfNeeded(ContextMtl *context) |
| 33436 |
{ |
| 33437 |
- EnsureCPUMemWillBeSynced(context, this); |
| 33438 |
+ EnsureContentSynced(context, shared_from_this()); |
| 33439 |
} |
| 33440 |
|
| 33441 |
bool Texture::isCPUAccessible() const |
| 33442 |
@@ -379,6 +508,11 @@ void EnsureCPUMemWillBeSynced(ContextMtl *context, T *resource) |
| 33443 |
return get().storageMode == MTLStorageModeShared; |
| 33444 |
} |
| 33445 |
|
| 33446 |
+bool Texture::isShaderReadable() const |
| 33447 |
+{ |
| 33448 |
+ return get().usage & MTLTextureUsageShaderRead; |
| 33449 |
+} |
| 33450 |
+ |
| 33451 |
bool Texture::supportFormatView() const |
| 33452 |
{ |
| 33453 |
return get().usage & MTLTextureUsagePixelFormatView; |
| 33454 |
@@ -514,12 +648,14 @@ void EnsureCPUMemWillBeSynced(ContextMtl *context, T *resource) |
| 33455 |
ASSERT(supportFormatView()); |
| 33456 |
return TextureRef(new Texture(this, format)); |
| 33457 |
} |
| 33458 |
+ |
| 33459 |
TextureRef Texture::createViewWithCompatibleFormat(MTLPixelFormat format) |
| 33460 |
{ |
| 33461 |
- // No need for ASSERT(supportFormatView()); |
| 33462 |
return TextureRef(new Texture(this, format)); |
| 33463 |
} |
| 33464 |
|
| 33465 |
+ |
| 33466 |
+ |
| 33467 |
TextureRef Texture::createSwizzleView(const TextureSwizzleChannels &swizzle) |
| 33468 |
{ |
| 33469 |
#if ANGLE_MTL_SWIZZLE_AVAILABLE |
| 33470 |
@@ -652,6 +788,48 @@ void EnsureCPUMemWillBeSynced(ContextMtl *context, T *resource) |
| 33471 |
return mLinearColorView; |
| 33472 |
} |
| 33473 |
|
| 33474 |
+TextureRef Texture::getReadableCopy(ContextMtl *context, |
| 33475 |
+ mtl::BlitCommandEncoder *encoder, |
| 33476 |
+ const uint32_t levelToCopy, |
| 33477 |
+ const uint32_t sliceToCopy, |
| 33478 |
+ const MTLRegion &areaToCopy) |
| 33479 |
+{ |
| 33480 |
+ gl::Extents firstLevelSize = size(kZeroNativeMipLevel); |
| 33481 |
+ if (!mReadCopy || mReadCopy->get().width < static_cast<size_t>(firstLevelSize.width) || |
| 33482 |
+ mReadCopy->get().height < static_cast<size_t>(firstLevelSize.height)) |
| 33483 |
+ { |
| 33484 |
+ // Create a texture that big enough to store the first level data and any smaller level |
| 33485 |
+ ANGLE_MTL_OBJC_SCOPE |
| 33486 |
+ { |
| 33487 |
+ auto desc = [[MTLTextureDescriptor new] ANGLE_MTL_AUTORELEASE]; |
| 33488 |
+ desc.textureType = get().textureType; |
| 33489 |
+ desc.pixelFormat = get().pixelFormat; |
| 33490 |
+ desc.width = firstLevelSize.width; |
| 33491 |
+ desc.height = firstLevelSize.height; |
| 33492 |
+ desc.depth = 1; |
| 33493 |
+ desc.arrayLength = 1; |
| 33494 |
+ desc.resourceOptions = MTLResourceStorageModePrivate; |
| 33495 |
+ desc.sampleCount = get().sampleCount; |
| 33496 |
+ desc.usage = MTLTextureUsageShaderRead | MTLTextureUsagePixelFormatView; |
| 33497 |
+ |
| 33498 |
+ id<MTLTexture> mtlTexture = [context->getMetalDevice() newTextureWithDescriptor:desc]; |
| 33499 |
+ mReadCopy.reset(new Texture(mtlTexture)); |
| 33500 |
+ } // ANGLE_MTL_OBJC_SCOPE |
| 33501 |
+ } |
| 33502 |
+ |
| 33503 |
+ ASSERT(encoder); |
| 33504 |
+ |
| 33505 |
+ encoder->copyTexture(shared_from_this(), sliceToCopy, levelToCopy, mReadCopy, 0, |
| 33506 |
+ 0, 1, 1); |
| 33507 |
+ |
| 33508 |
+ return mReadCopy; |
| 33509 |
+} |
| 33510 |
+ |
| 33511 |
+void Texture::releaseReadableCopy() |
| 33512 |
+{ |
| 33513 |
+ mReadCopy = nullptr; |
| 33514 |
+} |
| 33515 |
+ |
| 33516 |
TextureRef Texture::getStencilView() |
| 33517 |
{ |
| 33518 |
if (mStencilView) |
| 33519 |
@@ -799,7 +977,7 @@ void EnsureCPUMemWillBeSynced(ContextMtl *context, T *resource) |
| 33520 |
|
| 33521 |
void Buffer::syncContent(ContextMtl *context, mtl::BlitCommandEncoder *blitEncoder) |
| 33522 |
{ |
| 33523 |
- InvokeCPUMemSync(context, blitEncoder, this); |
| 33524 |
+ SyncContent(context, blitEncoder, shared_from_this()); |
| 33525 |
} |
| 33526 |
|
| 33527 |
const uint8_t *Buffer::mapReadOnly(ContextMtl *context) |
| 33528 |
@@ -820,7 +998,7 @@ void EnsureCPUMemWillBeSynced(ContextMtl *context, T *resource) |
| 33529 |
{ |
| 33530 |
CommandQueue &cmdQueue = context->cmdQueue(); |
| 33531 |
|
| 33532 |
- EnsureCPUMemWillBeSynced(context, this); |
| 33533 |
+ EnsureContentSynced(context, shared_from_this()); |
| 33534 |
|
| 33535 |
if (this->isBeingUsedByGPU(context)) |
| 33536 |
{ |
| 33537 |
diff --git a/src/libANGLE/renderer/metal/mtl_state_cache.h b/src/libANGLE/renderer/metal/mtl_state_cache.h |
| 33538 |
index 768c369..e6bf71d 100644 |
| 33539 |
--- a/src/libANGLE/renderer/metal/mtl_state_cache.h |
| 33540 |
+++ b/src/libANGLE/renderer/metal/mtl_state_cache.h |
| 33541 |
@@ -22,6 +22,11 @@ |
| 33542 |
|
| 33543 |
static inline bool operator==(const MTLClearColor &lhs, const MTLClearColor &rhs); |
| 33544 |
|
| 33545 |
+namespace angle |
| 33546 |
+{ |
| 33547 |
+struct FeaturesMtl; |
| 33548 |
+} |
| 33549 |
+ |
| 33550 |
namespace rx |
| 33551 |
{ |
| 33552 |
class ContextMtl; |
| 33553 |
@@ -223,7 +228,8 @@ struct RenderPipelineOutputDesc |
| 33554 |
}; |
| 33555 |
|
| 33556 |
// Some SDK levels don't declare MTLPrimitiveTopologyClass. Needs to do compile time check here: |
| 33557 |
-#if !(TARGET_OS_OSX || TARGET_OS_MACCATALYST) && ANGLE_IOS_DEPLOY_TARGET < __IPHONE_12_0 |
| 33558 |
+#if !(TARGET_OS_OSX || TARGET_OS_MACCATALYST) && \ |
| 33559 |
+ (!defined(__IPHONE_12_0) || ANGLE_IOS_DEPLOY_TARGET < __IPHONE_12_0) |
| 33560 |
# define ANGLE_MTL_PRIMITIVE_TOPOLOGY_CLASS_AVAILABLE 0 |
| 33561 |
using PrimitiveTopologyClass = uint32_t; |
| 33562 |
constexpr PrimitiveTopologyClass kPrimitiveTopologyClassTriangle = 0; |
| 33563 |
@@ -267,9 +273,7 @@ struct alignas(4) RenderPipelineDesc |
| 33564 |
RenderPipelineDesc &operator=(const RenderPipelineDesc &src); |
| 33565 |
|
| 33566 |
bool operator==(const RenderPipelineDesc &rhs) const; |
| 33567 |
- |
| 33568 |
size_t hash() const; |
| 33569 |
- |
| 33570 |
bool rasterizationEnabled() const; |
| 33571 |
|
| 33572 |
VertexDesc vertexDescriptor; |
| 33573 |
@@ -288,6 +292,27 @@ struct alignas(4) RenderPipelineDesc |
| 33574 |
bool emulateCoverageMask : 1; |
| 33575 |
}; |
| 33576 |
|
| 33577 |
+struct RenderPassAttachmentTextureTargetDesc |
| 33578 |
+{ |
| 33579 |
+ TextureRef getTextureRef() const { return texture.lock(); } |
| 33580 |
+ TextureRef getImplicitMSTextureRef() const { return implicitMSTexture.lock(); } |
| 33581 |
+ bool hasImplicitMSTexture() const { return !implicitMSTexture.expired(); } |
| 33582 |
+ uint32_t getRenderSamples() const |
| 33583 |
+ { |
| 33584 |
+ TextureRef tex = getTextureRef(); |
| 33585 |
+ TextureRef msTex = getImplicitMSTextureRef(); |
| 33586 |
+ return msTex ? msTex->samples() : (tex ? tex->samples() : 1); |
| 33587 |
+ } |
| 33588 |
+ |
| 33589 |
+ TextureWeakRef texture; |
| 33590 |
+ // Implicit multisample texture that will be rendered into and discarded at the end of |
| 33591 |
+ // a render pass. Its result will be resolved into normal texture above. |
| 33592 |
+ TextureWeakRef implicitMSTexture; |
| 33593 |
+ MipmapNativeLevel level = kZeroNativeMipLevel; |
| 33594 |
+ uint32_t sliceOrDepth = 0; |
| 33595 |
+ bool blendable = true; |
| 33596 |
+}; |
| 33597 |
+ |
| 33598 |
struct RenderPassAttachmentDesc |
| 33599 |
{ |
| 33600 |
RenderPassAttachmentDesc(); |
| 33601 |
@@ -297,18 +322,34 @@ struct RenderPassAttachmentDesc |
| 33602 |
bool equalIgnoreLoadStoreOptions(const RenderPassAttachmentDesc &other) const; |
| 33603 |
bool operator==(const RenderPassAttachmentDesc &other) const; |
| 33604 |
|
| 33605 |
- ANGLE_INLINE bool hasImplicitMSTexture() const { return implicitMSTexture.get(); } |
| 33606 |
- |
| 33607 |
- TextureRef texture; |
| 33608 |
- // Implicit multisample texture that will be rendered into and discarded at the end of |
| 33609 |
- // a render pass. Its result will be resolved into normal texture above. |
| 33610 |
- TextureRef implicitMSTexture; |
| 33611 |
- MipmapNativeLevel level; |
| 33612 |
- uint32_t sliceOrDepth; |
| 33613 |
- |
| 33614 |
- // This attachment is blendable or not. |
| 33615 |
- bool blendable; |
| 33616 |
+ ANGLE_INLINE TextureRef texture() const |
| 33617 |
+ { |
| 33618 |
+ return renderTarget ? renderTarget->getTextureRef() : nullptr; |
| 33619 |
+ } |
| 33620 |
+ ANGLE_INLINE TextureRef implicitMSTexture() const |
| 33621 |
+ { |
| 33622 |
+ return renderTarget ? renderTarget->getImplicitMSTextureRef() : nullptr; |
| 33623 |
+ } |
| 33624 |
+ ANGLE_INLINE bool hasImplicitMSTexture() const |
| 33625 |
+ { |
| 33626 |
+ return renderTarget ? renderTarget->hasImplicitMSTexture() : false; |
| 33627 |
+ } |
| 33628 |
+ ANGLE_INLINE uint32_t renderSamples() const |
| 33629 |
+ { |
| 33630 |
+ return renderTarget ? renderTarget->getRenderSamples() : 1; |
| 33631 |
+ } |
| 33632 |
+ ANGLE_INLINE MipmapNativeLevel level() const |
| 33633 |
+ { |
| 33634 |
+ return renderTarget ? renderTarget->level : kZeroNativeMipLevel; |
| 33635 |
+ } |
| 33636 |
+ ANGLE_INLINE uint32_t sliceOrDepth() const |
| 33637 |
+ { |
| 33638 |
+ return renderTarget ? renderTarget->sliceOrDepth : 0; |
| 33639 |
+ } |
| 33640 |
+ ANGLE_INLINE bool blendable() const { return renderTarget ? renderTarget->blendable : false; } |
| 33641 |
|
| 33642 |
+ // This is shared pointer to avoid crashing when texture deleted after bound to a frame buffer. |
| 33643 |
+ std::shared_ptr<RenderPassAttachmentTextureTargetDesc> renderTarget; |
| 33644 |
MTLLoadAction loadAction; |
| 33645 |
MTLStoreAction storeAction; |
| 33646 |
MTLStoreActionOptions storeActionOptions; |
| 33647 |
@@ -354,6 +395,11 @@ struct RenderPassStencilAttachmentDesc : public RenderPassAttachmentDesc |
| 33648 |
uint32_t clearStencil = 0; |
| 33649 |
}; |
| 33650 |
|
| 33651 |
+// |
| 33652 |
+// This is C++ equivalent of Objective-C MTLRenderPassDescriptor. |
| 33653 |
+// We could use MTLRenderPassDescriptor directly, however, using C++ struct has benefits of fast |
| 33654 |
+// copy, stack allocation, inlined comparing function, etc. |
| 33655 |
+// |
| 33656 |
struct RenderPassDesc |
| 33657 |
{ |
| 33658 |
RenderPassColorAttachmentDesc colorAttachments[kMaxRenderTargets]; |
| 33659 |
@@ -417,7 +463,6 @@ class RenderPipelineCacheSpecializeShaderFactory |
| 33660 |
{ |
| 33661 |
public: |
| 33662 |
virtual ~RenderPipelineCacheSpecializeShaderFactory() = default; |
| 33663 |
- |
| 33664 |
// Get specialized shader for the render pipeline cache. |
| 33665 |
virtual angle::Result getSpecializedShader(Context *context, |
| 33666 |
gl::ShaderType shaderType, |
| 33667 |
@@ -429,7 +474,7 @@ class RenderPipelineCacheSpecializeShaderFactory |
| 33668 |
const RenderPipelineDesc &renderPipelineDesc) = 0; |
| 33669 |
}; |
| 33670 |
|
| 33671 |
-// Render pipeline state cache per shader program. |
| 33672 |
+// render pipeline state cache per shader program |
| 33673 |
class RenderPipelineCache final : angle::NonCopyable |
| 33674 |
{ |
| 33675 |
public: |
| 33676 |
@@ -459,6 +504,7 @@ class RenderPipelineCache final : angle::NonCopyable |
| 33677 |
AutoObjCPtr<id<MTLFunction>> mVertexShader; |
| 33678 |
// Non-specialized fragment shader |
| 33679 |
AutoObjCPtr<id<MTLFunction>> mFragmentShader; |
| 33680 |
+ // On shader with emulated rasterization discard, one without |
| 33681 |
|
| 33682 |
private: |
| 33683 |
void clearPipelineStates(); |
| 33684 |
@@ -477,14 +523,13 @@ class RenderPipelineCache final : angle::NonCopyable |
| 33685 |
// One table with default attrib and one table without. |
| 33686 |
std::unordered_map<RenderPipelineDesc, AutoObjCPtr<id<MTLRenderPipelineState>>> |
| 33687 |
mRenderPipelineStates[2]; |
| 33688 |
- |
| 33689 |
RenderPipelineCacheSpecializeShaderFactory *mSpecializedShaderFactory; |
| 33690 |
}; |
| 33691 |
|
| 33692 |
class StateCache final : angle::NonCopyable |
| 33693 |
{ |
| 33694 |
public: |
| 33695 |
- StateCache(); |
| 33696 |
+ StateCache(const angle::FeaturesMtl &features); |
| 33697 |
~StateCache(); |
| 33698 |
|
| 33699 |
// Null depth stencil state has depth/stecil read & write disabled. |
| 33700 |
@@ -502,6 +547,8 @@ class StateCache final : angle::NonCopyable |
| 33701 |
void clear(); |
| 33702 |
|
| 33703 |
private: |
| 33704 |
+ const angle::FeaturesMtl &mFeatures; |
| 33705 |
+ |
| 33706 |
AutoObjCPtr<id<MTLDepthStencilState>> mNullDepthStencilState = nil; |
| 33707 |
std::unordered_map<DepthStencilDesc, AutoObjCPtr<id<MTLDepthStencilState>>> mDepthStencilStates; |
| 33708 |
std::unordered_map<SamplerDesc, AutoObjCPtr<id<MTLSamplerState>>> mSamplerStates; |
| 33709 |
diff --git a/src/libANGLE/renderer/metal/mtl_state_cache.mm b/src/libANGLE/renderer/metal/mtl_state_cache.mm |
| 33710 |
index 1cf237a..45c719d 100644 |
| 33711 |
--- a/src/libANGLE/renderer/metal/mtl_state_cache.mm |
| 33712 |
+++ b/src/libANGLE/renderer/metal/mtl_state_cache.mm |
| 33713 |
@@ -17,6 +17,7 @@ |
| 33714 |
#include "libANGLE/renderer/metal/ContextMtl.h" |
| 33715 |
#include "libANGLE/renderer/metal/mtl_resources.h" |
| 33716 |
#include "libANGLE/renderer/metal/mtl_utils.h" |
| 33717 |
+#include "platform/FeaturesMtl.h" |
| 33718 |
|
| 33719 |
#define ANGLE_OBJC_CP_PROPERTY(DST, SRC, PROPERTY) \ |
| 33720 |
(DST).PROPERTY = static_cast<__typeof__((DST).PROPERTY)>(ToObjC((SRC).PROPERTY)) |
| 33721 |
@@ -182,10 +183,10 @@ inline T ToObjC(const T p) |
| 33722 |
return textureRef ? textureRef->get() : nil; |
| 33723 |
} |
| 33724 |
|
| 33725 |
-void BaseRenderPassAttachmentDescToObjC(const RenderPassAttachmentDesc &src, |
| 33726 |
- MTLRenderPassAttachmentDescriptor *dst) |
| 33727 |
+void BaseRenderPassAttachmentDescToObjC(MTLRenderPassAttachmentDescriptor *dst, |
| 33728 |
+ const RenderPassAttachmentDesc &src) |
| 33729 |
{ |
| 33730 |
- const TextureRef &implicitMsTexture = src.implicitMSTexture; |
| 33731 |
+ auto implicitMsTexture = src.implicitMSTexture(); |
| 33732 |
|
| 33733 |
if (implicitMsTexture) |
| 33734 |
{ |
| 33735 |
@@ -193,31 +194,31 @@ void BaseRenderPassAttachmentDescToObjC(const RenderPassAttachmentDesc &src, |
| 33736 |
dst.level = 0; |
| 33737 |
dst.slice = 0; |
| 33738 |
dst.depthPlane = 0; |
| 33739 |
- dst.resolveTexture = ToObjC(src.texture); |
| 33740 |
- dst.resolveLevel = src.level.get(); |
| 33741 |
+ dst.resolveTexture = ToObjC(src.texture()); |
| 33742 |
+ dst.resolveLevel = src.level().get(); |
| 33743 |
if (dst.resolveTexture.textureType == MTLTextureType3D) |
| 33744 |
{ |
| 33745 |
- dst.resolveDepthPlane = src.sliceOrDepth; |
| 33746 |
+ dst.resolveDepthPlane = src.sliceOrDepth(); |
| 33747 |
dst.resolveSlice = 0; |
| 33748 |
} |
| 33749 |
else |
| 33750 |
{ |
| 33751 |
- dst.resolveSlice = src.sliceOrDepth; |
| 33752 |
+ dst.resolveSlice = src.sliceOrDepth(); |
| 33753 |
dst.resolveDepthPlane = 0; |
| 33754 |
} |
| 33755 |
} |
| 33756 |
else |
| 33757 |
{ |
| 33758 |
- dst.texture = ToObjC(src.texture); |
| 33759 |
- dst.level = src.level.get(); |
| 33760 |
+ dst.texture = ToObjC(src.texture()); |
| 33761 |
+ dst.level = src.level().get(); |
| 33762 |
if (dst.texture.textureType == MTLTextureType3D) |
| 33763 |
{ |
| 33764 |
- dst.depthPlane = src.sliceOrDepth; |
| 33765 |
+ dst.depthPlane = src.sliceOrDepth(); |
| 33766 |
dst.slice = 0; |
| 33767 |
} |
| 33768 |
else |
| 33769 |
{ |
| 33770 |
- dst.slice = src.sliceOrDepth; |
| 33771 |
+ dst.slice = src.sliceOrDepth(); |
| 33772 |
dst.depthPlane = 0; |
| 33773 |
} |
| 33774 |
dst.resolveTexture = nil; |
| 33775 |
@@ -231,26 +232,26 @@ void BaseRenderPassAttachmentDescToObjC(const RenderPassAttachmentDesc &src, |
| 33776 |
ANGLE_OBJC_CP_PROPERTY(dst, src, storeActionOptions); |
| 33777 |
} |
| 33778 |
|
| 33779 |
-void ToObjC(const RenderPassColorAttachmentDesc &desc, |
| 33780 |
- MTLRenderPassColorAttachmentDescriptor *objCDesc) |
| 33781 |
+void ToObjC(MTLRenderPassColorAttachmentDescriptor *objCDesc, |
| 33782 |
+ const RenderPassColorAttachmentDesc &desc) |
| 33783 |
{ |
| 33784 |
- BaseRenderPassAttachmentDescToObjC(desc, objCDesc); |
| 33785 |
+ BaseRenderPassAttachmentDescToObjC(objCDesc, desc); |
| 33786 |
|
| 33787 |
ANGLE_OBJC_CP_PROPERTY(objCDesc, desc, clearColor); |
| 33788 |
} |
| 33789 |
|
| 33790 |
-void ToObjC(const RenderPassDepthAttachmentDesc &desc, |
| 33791 |
- MTLRenderPassDepthAttachmentDescriptor *objCDesc) |
| 33792 |
+void ToObjC(MTLRenderPassDepthAttachmentDescriptor *objCDesc, |
| 33793 |
+ const RenderPassDepthAttachmentDesc &desc) |
| 33794 |
{ |
| 33795 |
- BaseRenderPassAttachmentDescToObjC(desc, objCDesc); |
| 33796 |
+ BaseRenderPassAttachmentDescToObjC(objCDesc, desc); |
| 33797 |
|
| 33798 |
ANGLE_OBJC_CP_PROPERTY(objCDesc, desc, clearDepth); |
| 33799 |
} |
| 33800 |
|
| 33801 |
-void ToObjC(const RenderPassStencilAttachmentDesc &desc, |
| 33802 |
- MTLRenderPassStencilAttachmentDescriptor *objCDesc) |
| 33803 |
+void ToObjC(MTLRenderPassStencilAttachmentDescriptor *objCDesc, |
| 33804 |
+ const RenderPassStencilAttachmentDesc &desc) |
| 33805 |
{ |
| 33806 |
- BaseRenderPassAttachmentDescToObjC(desc, objCDesc); |
| 33807 |
+ BaseRenderPassAttachmentDescToObjC(objCDesc, desc); |
| 33808 |
|
| 33809 |
ANGLE_OBJC_CP_PROPERTY(objCDesc, desc, clearStencil); |
| 33810 |
} |
| 33811 |
@@ -696,11 +697,7 @@ void ToObjC(const RenderPassStencilAttachmentDesc &desc, |
| 33812 |
|
| 33813 |
void RenderPassAttachmentDesc::reset() |
| 33814 |
{ |
| 33815 |
- texture.reset(); |
| 33816 |
- implicitMSTexture.reset(); |
| 33817 |
- level = mtl::kZeroNativeMipLevel; |
| 33818 |
- sliceOrDepth = 0; |
| 33819 |
- blendable = false; |
| 33820 |
+ renderTarget = nullptr; |
| 33821 |
loadAction = MTLLoadActionLoad; |
| 33822 |
storeAction = MTLStoreActionStore; |
| 33823 |
storeActionOptions = MTLStoreActionOptionNone; |
| 33824 |
@@ -709,8 +706,9 @@ void ToObjC(const RenderPassStencilAttachmentDesc &desc, |
| 33825 |
bool RenderPassAttachmentDesc::equalIgnoreLoadStoreOptions( |
| 33826 |
const RenderPassAttachmentDesc &other) const |
| 33827 |
{ |
| 33828 |
- return texture == other.texture && implicitMSTexture == other.implicitMSTexture && |
| 33829 |
- level == other.level && sliceOrDepth == other.sliceOrDepth; |
| 33830 |
+ return renderTarget == other.renderTarget || |
| 33831 |
+ (texture() == other.texture() && level() == other.level() && |
| 33832 |
+ sliceOrDepth() == other.sliceOrDepth()); |
| 33833 |
} |
| 33834 |
|
| 33835 |
bool RenderPassAttachmentDesc::operator==(const RenderPassAttachmentDesc &other) const |
| 33836 |
@@ -723,6 +721,30 @@ void ToObjC(const RenderPassStencilAttachmentDesc &desc, |
| 33837 |
return loadAction == other.loadAction && storeAction == other.storeAction && |
| 33838 |
storeActionOptions == other.storeActionOptions; |
| 33839 |
} |
| 33840 |
+// Convert to Metal object |
| 33841 |
+void RenderPassDesc::convertToMetalDesc(MTLRenderPassDescriptor *objCDesc) const |
| 33842 |
+{ |
| 33843 |
+ ANGLE_MTL_OBJC_SCOPE |
| 33844 |
+ { |
| 33845 |
+ for (uint32_t i = 0; i < numColorAttachments; ++i) |
| 33846 |
+ { |
| 33847 |
+ ToObjC(objCDesc.colorAttachments[i], colorAttachments[i]); |
| 33848 |
+ } |
| 33849 |
+ for (uint32_t i = numColorAttachments; i < kMaxRenderTargets; ++i) |
| 33850 |
+ { |
| 33851 |
+ // Inactive render target |
| 33852 |
+ objCDesc.colorAttachments[i].texture = nil; |
| 33853 |
+ objCDesc.colorAttachments[i].level = 0; |
| 33854 |
+ objCDesc.colorAttachments[i].slice = 0; |
| 33855 |
+ objCDesc.colorAttachments[i].depthPlane = 0; |
| 33856 |
+ objCDesc.colorAttachments[i].loadAction = MTLLoadActionDontCare; |
| 33857 |
+ objCDesc.colorAttachments[i].storeAction = MTLStoreActionDontCare; |
| 33858 |
+ } |
| 33859 |
+ |
| 33860 |
+ ToObjC(objCDesc.depthAttachment, depthAttachment); |
| 33861 |
+ ToObjC(objCDesc.stencilAttachment, stencilAttachment); |
| 33862 |
+ } |
| 33863 |
+} |
| 33864 |
|
| 33865 |
void RenderPassDesc::populateRenderPipelineOutputDesc(RenderPipelineOutputDesc *outDesc) const |
| 33866 |
{ |
| 33867 |
@@ -742,19 +764,19 @@ void ToObjC(const RenderPassStencilAttachmentDesc &desc, |
| 33868 |
void RenderPassDesc::populateRenderPipelineOutputDesc(const BlendDesc &blendState, |
| 33869 |
RenderPipelineOutputDesc *outDesc) const |
| 33870 |
{ |
| 33871 |
- RenderPipelineOutputDesc &outputDescriptor = *outDesc; |
| 33872 |
+ auto &outputDescriptor = *outDesc; |
| 33873 |
outputDescriptor.numColorAttachments = this->numColorAttachments; |
| 33874 |
outputDescriptor.sampleCount = this->sampleCount; |
| 33875 |
for (uint32_t i = 0; i < this->numColorAttachments; ++i) |
| 33876 |
{ |
| 33877 |
auto &renderPassColorAttachment = this->colorAttachments[i]; |
| 33878 |
- auto texture = renderPassColorAttachment.texture; |
| 33879 |
+ auto texture = renderPassColorAttachment.texture(); |
| 33880 |
|
| 33881 |
if (texture) |
| 33882 |
{ |
| 33883 |
// Copy parameters from blend state |
| 33884 |
outputDescriptor.colorAttachments[i].update(blendState); |
| 33885 |
- if (!renderPassColorAttachment.blendable) |
| 33886 |
+ if (!renderPassColorAttachment.blendable()) |
| 33887 |
{ |
| 33888 |
// Disable blending if the attachment's render target doesn't support blending. |
| 33889 |
outputDescriptor.colorAttachments[i].blendingEnabled = false; |
| 33890 |
@@ -781,11 +803,11 @@ void ToObjC(const RenderPassStencilAttachmentDesc &desc, |
| 33891 |
outputDescriptor.colorAttachments[i].reset(); |
| 33892 |
} |
| 33893 |
|
| 33894 |
- auto depthTexture = this->depthAttachment.texture; |
| 33895 |
+ auto depthTexture = this->depthAttachment.texture(); |
| 33896 |
outputDescriptor.depthAttachmentPixelFormat = |
| 33897 |
depthTexture ? depthTexture->pixelFormat() : MTLPixelFormatInvalid; |
| 33898 |
|
| 33899 |
- auto stencilTexture = this->stencilAttachment.texture; |
| 33900 |
+ auto stencilTexture = this->stencilAttachment.texture(); |
| 33901 |
outputDescriptor.stencilAttachmentPixelFormat = |
| 33902 |
stencilTexture ? stencilTexture->pixelFormat() : MTLPixelFormatInvalid; |
| 33903 |
} |
| 33904 |
@@ -831,42 +853,21 @@ void ToObjC(const RenderPassStencilAttachmentDesc &desc, |
| 33905 |
return depthAttachment == other.depthAttachment && stencilAttachment == other.stencilAttachment; |
| 33906 |
} |
| 33907 |
|
| 33908 |
-// Convert to Metal object |
| 33909 |
-void RenderPassDesc::convertToMetalDesc(MTLRenderPassDescriptor *objCDesc) const |
| 33910 |
-{ |
| 33911 |
- ANGLE_MTL_OBJC_SCOPE |
| 33912 |
- { |
| 33913 |
- for (uint32_t i = 0; i < numColorAttachments; ++i) |
| 33914 |
- { |
| 33915 |
- ToObjC(colorAttachments[i], objCDesc.colorAttachments[i]); |
| 33916 |
- } |
| 33917 |
- for (uint32_t i = numColorAttachments; i < kMaxRenderTargets; ++i) |
| 33918 |
- { |
| 33919 |
- // Inactive render target |
| 33920 |
- objCDesc.colorAttachments[i].texture = nil; |
| 33921 |
- objCDesc.colorAttachments[i].level = 0; |
| 33922 |
- objCDesc.colorAttachments[i].slice = 0; |
| 33923 |
- objCDesc.colorAttachments[i].depthPlane = 0; |
| 33924 |
- objCDesc.colorAttachments[i].loadAction = MTLLoadActionDontCare; |
| 33925 |
- objCDesc.colorAttachments[i].storeAction = MTLStoreActionDontCare; |
| 33926 |
- } |
| 33927 |
- |
| 33928 |
- ToObjC(depthAttachment, objCDesc.depthAttachment); |
| 33929 |
- ToObjC(stencilAttachment, objCDesc.stencilAttachment); |
| 33930 |
- } |
| 33931 |
-} |
| 33932 |
- |
| 33933 |
// RenderPipelineCache implementation |
| 33934 |
-RenderPipelineCache::RenderPipelineCache() : RenderPipelineCache(nullptr) {} |
| 33935 |
+RenderPipelineCache::RenderPipelineCache() : RenderPipelineCache(nullptr) { |
| 33936 |
+} |
| 33937 |
|
| 33938 |
RenderPipelineCache::RenderPipelineCache( |
| 33939 |
RenderPipelineCacheSpecializeShaderFactory *specializedShaderFactory) |
| 33940 |
: mSpecializedShaderFactory(specializedShaderFactory) |
| 33941 |
-{} |
| 33942 |
+{ |
| 33943 |
+ |
| 33944 |
+} |
| 33945 |
|
| 33946 |
RenderPipelineCache::~RenderPipelineCache() {} |
| 33947 |
|
| 33948 |
-void RenderPipelineCache::setVertexShader(Context *context, id<MTLFunction> shader) |
| 33949 |
+void RenderPipelineCache::setVertexShader(Context *context, |
| 33950 |
+ id<MTLFunction> shader) |
| 33951 |
{ |
| 33952 |
mVertexShader.retainAssign(shader); |
| 33953 |
|
| 33954 |
@@ -879,7 +880,8 @@ void ToObjC(const RenderPassStencilAttachmentDesc &desc, |
| 33955 |
recreatePipelineStates(context); |
| 33956 |
} |
| 33957 |
|
| 33958 |
-void RenderPipelineCache::setFragmentShader(Context *context, id<MTLFunction> shader) |
| 33959 |
+void RenderPipelineCache::setFragmentShader(Context *context, |
| 33960 |
+ id<MTLFunction> shader) |
| 33961 |
{ |
| 33962 |
mFragmentShader.retainAssign(shader); |
| 33963 |
|
| 33964 |
@@ -929,10 +931,6 @@ void ToObjC(const RenderPassStencilAttachmentDesc &desc, |
| 33965 |
{ |
| 33966 |
AutoObjCPtr<id<MTLRenderPipelineState>> newState = |
| 33967 |
createRenderPipelineState(context, desc, insertDefaultAttribLayout); |
| 33968 |
- if (!newState) |
| 33969 |
- { |
| 33970 |
- return nil; |
| 33971 |
- } |
| 33972 |
|
| 33973 |
int tableIdx = insertDefaultAttribLayout ? 1 : 0; |
| 33974 |
auto re = mRenderPipelineStates[tableIdx].insert(std::make_pair(desc, newState)); |
| 33975 |
@@ -944,6 +942,7 @@ void ToObjC(const RenderPassStencilAttachmentDesc &desc, |
| 33976 |
return re.first->second; |
| 33977 |
} |
| 33978 |
|
| 33979 |
+ |
| 33980 |
AutoObjCPtr<id<MTLRenderPipelineState>> RenderPipelineCache::createRenderPipelineState( |
| 33981 |
Context *context, |
| 33982 |
const RenderPipelineDesc &originalDesc, |
| 33983 |
@@ -959,7 +958,6 @@ void ToObjC(const RenderPassStencilAttachmentDesc &desc, |
| 33984 |
desc.emulateCoverageMask = false; |
| 33985 |
desc.alphaToCoverageEnabled = false; |
| 33986 |
} |
| 33987 |
- |
| 33988 |
// Choose shader variant |
| 33989 |
id<MTLFunction> vertShader = nil; |
| 33990 |
id<MTLFunction> fragShader = nil; |
| 33991 |
@@ -1004,7 +1002,25 @@ void ToObjC(const RenderPassStencilAttachmentDesc &desc, |
| 33992 |
|
| 33993 |
// Convert to Objective-C desc: |
| 33994 |
AutoObjCObj<MTLRenderPipelineDescriptor> objCDesc = ToObjC(vertShader, fragShader, desc); |
| 33995 |
- |
| 33996 |
+ // Validate Render Pipeline State: |
| 33997 |
+ if (DeviceHasMaximumRenderTargetSize(metalDevice)) |
| 33998 |
+ { |
| 33999 |
+ NSUInteger maxSize = GetMaxRenderTargetSizeForDeviceInBytes(metalDevice); |
| 34000 |
+ NSUInteger renderTargetSize = |
| 34001 |
+ ComputeTotalSizeUsedForMTLRenderPipelineDescriptor(objCDesc, context, metalDevice); |
| 34002 |
+ if (renderTargetSize > maxSize) |
| 34003 |
+ { |
| 34004 |
+ NSString *errorString = |
| 34005 |
+ [NSString stringWithFormat:@"This set of render targets requires %lu bytes of " |
| 34006 |
+ @"pixel storage. This device supports %lu bytes.", |
| 34007 |
+ renderTargetSize, maxSize]; |
| 34008 |
+ NSError *err = [NSError errorWithDomain:@"MTLValidationError" |
| 34009 |
+ code:-1 |
| 34010 |
+ userInfo:@{NSLocalizedDescriptionKey : errorString}]; |
| 34011 |
+ context->handleError(err, __FILE__, ANGLE_FUNCTION, __LINE__); |
| 34012 |
+ return nil; |
| 34013 |
+ } |
| 34014 |
+ } |
| 34015 |
// Special attribute slot for default attribute |
| 34016 |
if (insertDefaultAttribLayout) |
| 34017 |
{ |
| 34018 |
@@ -1032,6 +1048,7 @@ void ToObjC(const RenderPassStencilAttachmentDesc &desc, |
| 34019 |
} |
| 34020 |
} |
| 34021 |
|
| 34022 |
+ |
| 34023 |
void RenderPipelineCache::recreatePipelineStates(Context *context) |
| 34024 |
{ |
| 34025 |
for (int hasDefaultAttrib = 0; hasDefaultAttrib <= 1; ++hasDefaultAttrib) |
| 34026 |
@@ -1062,7 +1079,7 @@ void ToObjC(const RenderPassStencilAttachmentDesc &desc, |
| 34027 |
} |
| 34028 |
|
| 34029 |
// StateCache implementation |
| 34030 |
-StateCache::StateCache() {} |
| 34031 |
+StateCache::StateCache(const angle::FeaturesMtl &features) : mFeatures(features) {} |
| 34032 |
|
| 34033 |
StateCache::~StateCache() {} |
| 34034 |
|
| 34035 |
@@ -1113,6 +1130,11 @@ void ToObjC(const RenderPassStencilAttachmentDesc &desc, |
| 34036 |
if (ite == mSamplerStates.end()) |
| 34037 |
{ |
| 34038 |
AutoObjCObj<MTLSamplerDescriptor> objCDesc = ToObjC(desc); |
| 34039 |
+ if (!mFeatures.allowRuntimeSamplerCompareMode.enabled) |
| 34040 |
+ { |
| 34041 |
+ // Runtime sampler compare mode is not supported, fallback to never. |
| 34042 |
+ objCDesc.get().compareFunction = MTLCompareFunctionNever; |
| 34043 |
+ } |
| 34044 |
AutoObjCPtr<id<MTLSamplerState>> newState = |
| 34045 |
[[metalDevice newSamplerStateWithDescriptor:objCDesc] ANGLE_MTL_AUTORELEASE]; |
| 34046 |
|
| 34047 |
diff --git a/src/libANGLE/renderer/metal/mtl_utils.h b/src/libANGLE/renderer/metal/mtl_utils.h |
| 34048 |
index a84ac73..805729e 100644 |
| 34049 |
--- a/src/libANGLE/renderer/metal/mtl_utils.h |
| 34050 |
+++ b/src/libANGLE/renderer/metal/mtl_utils.h |
| 34051 |
@@ -135,15 +135,30 @@ MTLTextureSwizzle GetTextureSwizzle(GLenum swizzle); |
| 34052 |
|
| 34053 |
// Get color write mask for a specified format. Some formats such as RGB565 doesn't have alpha |
| 34054 |
// channel but is emulated by a RGBA8 format, we need to disable alpha write for this format. |
| 34055 |
-// - isFormatEmulated: if the format is emulated, this pointer will store a true value. |
| 34056 |
-MTLColorWriteMask GetEmulatedColorWriteMask(const mtl::Format &mtlFormat, bool *isFormatEmulated); |
| 34057 |
+// - emulatedChannelsOut: if the format is emulated, this pointer will store a true value. |
| 34058 |
+MTLColorWriteMask GetEmulatedColorWriteMask(const mtl::Format &mtlFormat, |
| 34059 |
+ bool *emulatedChannelsOut); |
| 34060 |
MTLColorWriteMask GetEmulatedColorWriteMask(const mtl::Format &mtlFormat); |
| 34061 |
bool IsFormatEmulated(const mtl::Format &mtlFormat); |
| 307 |
|
34062 |
|
| 308 |
SOFT_LINK_FRAMEWORK_HEADER(OpenGLES) |
34063 |
+NSUInteger GetMaxRenderTargetSizeForDeviceInBytes(id<MTLDevice> device); |
|
|
34064 |
+NSUInteger GetMaxNumberOfRenderTargetsForDevice(id<MTLDevice> device); |
| 34065 |
+bool DeviceHasMaximumRenderTargetSize(id<MTLDevice> device); |
| 34066 |
+ |
| 34067 |
// Useful to set clear color for texture originally having no alpha in GL, but backend's format |
| 34068 |
// has alpha channel. |
| 34069 |
MTLClearColor EmulatedAlphaClearColor(MTLClearColor color, MTLColorWriteMask colorMask); |
| 309 |
|
34070 |
|
| 310 |
diff --git a/src/libANGLE/renderer/gl/eagl/FunctionsEAGL.mm b/src/libANGLE/renderer/gl/eagl/FunctionsEAGL.mm |
34071 |
+ |
| 311 |
index 7779792..076d072 100644 |
34072 |
+NSUInteger ComputeTotalSizeUsedForMTLRenderPassDescriptor(const MTLRenderPassDescriptor *descriptor, |
| 312 |
--- a/src/libANGLE/renderer/gl/eagl/FunctionsEAGL.mm |
34073 |
+ const Context *context, |
| 313 |
+++ b/src/libANGLE/renderer/gl/eagl/FunctionsEAGL.mm |
34074 |
+ id<MTLDevice> device); |
| 314 |
@@ -14,7 +14,7 @@ |
34075 |
+ |
| 315 |
# import <OpenGLES/EAGLDrawable.h> |
34076 |
+NSUInteger ComputeTotalSizeUsedForMTLRenderPipelineDescriptor( |
| 316 |
# import <OpenGLES/EAGLIOSurface.h> |
34077 |
+ const MTLRenderPipelineDescriptor *descriptor, |
|
|
34078 |
+ const Context *context, |
| 34079 |
+ id<MTLDevice> device); |
| 34080 |
+ |
| 34081 |
gl::Box MTLRegionToGLBox(const MTLRegion &mtlRegion); |
| 317 |
|
34082 |
|
| 318 |
-# include "libANGLE/renderer/gl/apple/SoftLinking.h" |
34083 |
MipmapNativeLevel GetNativeMipLevel(GLuint level, GLuint base); |
| 319 |
+# include "common/apple/SoftLinking.h" |
34084 |
diff --git a/src/libANGLE/renderer/metal/mtl_utils.mm b/src/libANGLE/renderer/metal/mtl_utils.mm |
|
|
34085 |
index 076e609..009af5a 100644 |
| 34086 |
--- a/src/libANGLE/renderer/metal/mtl_utils.mm |
| 34087 |
+++ b/src/libANGLE/renderer/metal/mtl_utils.mm |
| 34088 |
@@ -10,9 +10,11 @@ |
| 320 |
|
34089 |
|
| 321 |
SOFT_LINK_FRAMEWORK_SOURCE(OpenGLES) |
34090 |
#include "libANGLE/renderer/metal/mtl_utils.h" |
| 322 |
|
34091 |
|
| 323 |
diff --git a/src/libANGLE/renderer/gl/eagl/IOSurfaceSurfaceEAGL.mm b/src/libANGLE/renderer/gl/eagl/IOSurfaceSurfaceEAGL.mm |
34092 |
+#include <Availability.h> |
| 324 |
index f16c3e7..45e6d0f 100644 |
34093 |
#include <TargetConditionals.h> |
| 325 |
--- a/src/libANGLE/renderer/gl/eagl/IOSurfaceSurfaceEAGL.mm |
|
|
| 326 |
+++ b/src/libANGLE/renderer/gl/eagl/IOSurfaceSurfaceEAGL.mm |
| 327 |
@@ -206,7 +206,9 @@ egl::Error IOSurfaceSurfaceEAGL::bindTexImage(const gl::Context *context, |
| 328 |
// TODO(kbr): possibly more state to be set here, including setting any |
| 329 |
// pixel unpack buffer to 0 when using ES 3.0 contexts. |
| 330 |
gl::PixelUnpackState defaultUnpackState; |
| 331 |
- stateManager->setPixelUnpackState(defaultUnpackState); |
| 332 |
+ if (IsError(stateManager->setPixelUnpackState(context, defaultUnpackState))) { |
| 333 |
+ return egl::EglBadState() << "Failed to set pixel unpack state."; |
| 334 |
+ } |
| 335 |
textureData = IOSurfaceGetBaseAddress(mIOSurface); |
| 336 |
} |
| 337 |
|
| 338 |
@@ -238,7 +240,9 @@ egl::Error IOSurfaceSurfaceEAGL::releaseTexImage(const gl::Context *context, EGL |
| 339 |
gl::PixelPackState state; |
| 340 |
state.rowLength = mRowStrideInPixels; |
| 341 |
state.alignment = 1; |
| 342 |
- stateManager->setPixelPackState(state); |
| 343 |
+ if (IsError(stateManager->setPixelPackState(context, state))) { |
| 344 |
+ return egl::EglBadState() << "Failed to set pixel unpack state."; |
| 345 |
+ } |
| 346 |
// TODO(kbr): possibly more state to be set here, including setting any |
| 347 |
// pixel pack buffer to 0 when using ES 3.0 contexts. |
| 348 |
const auto &format = kIOSurfaceFormats[mFormatIndex]; |
| 349 |
diff --git a/src/libANGLE/renderer/gl/renderergl_utils.cpp b/src/libANGLE/renderer/gl/renderergl_utils.cpp |
| 350 |
index 99772c4..11f47e6 100644 |
| 351 |
--- a/src/libANGLE/renderer/gl/renderergl_utils.cpp |
| 352 |
+++ b/src/libANGLE/renderer/gl/renderergl_utils.cpp |
| 353 |
@@ -1358,7 +1358,7 @@ void GenerateCaps(const FunctionsGL *functions, |
| 354 |
|
34094 |
|
| 355 |
#if defined(ANGLE_PLATFORM_MACOS) || defined(ANGLE_PLATFORM_MACCATALYST) |
34095 |
#include "common/MemoryBuffer.h" |
| 356 |
angle::SystemInfo info; |
34096 |
+#include "common/system_utils.h" |
| 357 |
- if (angle::GetSystemInfo(&info) && !info.isiOSAppOnMac) |
34097 |
#include "gpu_info_util/SystemInfo.h" |
| 358 |
+ if (angle::GetSystemInfo(&info) && !info.needsEAGLOnMac) |
34098 |
#include "libANGLE/renderer/metal/ContextMtl.h" |
|
|
34099 |
#include "libANGLE/renderer/metal/DisplayMtl.h" |
| 34100 |
@@ -24,6 +26,8 @@ |
| 34101 |
namespace mtl |
| 34102 |
{ |
| 34103 |
|
| 34104 |
+constexpr char kANGLEPrintMSLEnv[] = "ANGLE_METAL_PRINT_MSL_ENABLE"; |
| 34105 |
+ |
| 34106 |
namespace |
| 34107 |
{ |
| 34108 |
|
| 34109 |
@@ -103,24 +107,43 @@ GLint GetSliceOrDepth(const ImageNativeIndex &index) |
| 34110 |
const ImageNativeIndex &index) |
| 34111 |
{ |
| 34112 |
ASSERT(texture && texture->valid()); |
| 34113 |
- // Only one slice can be initialized at a time. |
| 34114 |
- ASSERT(!index.isLayered() || index.getType() == gl::TextureType::_3D); |
| 34115 |
ContextMtl *contextMtl = mtl::GetImpl(context); |
| 34116 |
|
| 34117 |
+ const angle::Format &actualAngleFormat = textureObjFormat.actualAngleFormat(); |
| 34118 |
const gl::InternalFormat &intendedInternalFormat = textureObjFormat.intendedInternalFormat(); |
| 34119 |
|
| 34120 |
// This function is called in many places to initialize the content of a texture. |
| 34121 |
- // So it's better we do the initial check here instead of let the callers do it themselves: |
| 34122 |
- if (!textureObjFormat.valid() || intendedInternalFormat.compressed) |
| 34123 |
+ // So it's better we do the sanity check here instead of let the callers do it themselves: |
| 34124 |
+ if (!textureObjFormat.valid() || actualAngleFormat.isBlock || actualAngleFormat.depthBits > 0 || |
| 34125 |
+ actualAngleFormat.stencilBits > 0) |
| 359 |
{ |
34126 |
{ |
| 360 |
VendorID vendor = GetVendorID(functions); |
34127 |
+ // If dst format is compressed, ignore. |
| 361 |
if ((IsAMD(vendor) || IsIntel(vendor)) && *maxSupportedESVersion >= gl::Version(3, 0)) |
34128 |
return angle::Result::Continue; |
|
|
34129 |
} |
| 34130 |
|
| 34131 |
gl::Extents size = texture->size(index); |
| 34132 |
|
| 34133 |
- // Intiialize the content to black |
| 34134 |
- GLint layer, startDepth; |
| 34135 |
- GetSliceAndDepth(index, &layer, &startDepth); |
| 34136 |
+ // Intialize the content to black |
| 34137 |
+ GLint layer = 0; |
| 34138 |
+ GLint startDepth = 0; |
| 34139 |
+ if (index.hasLayer()) |
| 34140 |
+ { |
| 34141 |
+ switch (index.getType()) |
| 34142 |
+ { |
| 34143 |
+ case gl::TextureType::CubeMap: |
| 34144 |
+ layer = index.cubeMapFaceIndex(); |
| 34145 |
+ break; |
| 34146 |
+ case gl::TextureType::_2DArray: |
| 34147 |
+ layer = index.getLayerIndex(); |
| 34148 |
+ break; |
| 34149 |
+ case gl::TextureType::_3D: |
| 34150 |
+ startDepth = index.getLayerIndex(); |
| 34151 |
+ break; |
| 34152 |
+ default: |
| 34153 |
+ UNREACHABLE(); |
| 34154 |
+ break; |
| 34155 |
+ } |
| 34156 |
+ } |
| 34157 |
|
| 34158 |
if (texture->isCPUAccessible() && index.getType() != gl::TextureType::_2DMultisample && |
| 34159 |
index.getType() != gl::TextureType::_2DMultisampleArray) |
| 34160 |
@@ -136,6 +159,13 @@ GLint GetSliceOrDepth(const ImageNativeIndex &index) |
| 34161 |
} |
| 34162 |
else |
| 34163 |
{ |
| 34164 |
+ if (!textureObjFormat.valid() || intendedInternalFormat.compressed || |
| 34165 |
+ intendedInternalFormat.depthBits > 0 || intendedInternalFormat.stencilBits > 0) |
| 34166 |
+ { |
| 34167 |
+ // If source format is compressed, ignore. |
| 34168 |
+ return angle::Result::Continue; |
| 34169 |
+ } |
| 34170 |
+ |
| 34171 |
const angle::Format &srcFormat = angle::Format::Get( |
| 34172 |
intendedInternalFormat.alphaBits > 0 ? angle::FormatID::R8G8B8A8_UNORM |
| 34173 |
: angle::FormatID::R8G8B8_UNORM); |
| 34174 |
@@ -165,7 +195,7 @@ GLint GetSliceOrDepth(const ImageNativeIndex &index) |
| 34175 |
conversionRow.data(), dstRowPitch); |
| 34176 |
} |
| 34177 |
} |
| 34178 |
- } |
| 34179 |
+ } // if (texture->isCPUAccessible()) |
| 34180 |
else |
| 34181 |
{ |
| 34182 |
ANGLE_TRY(InitializeTextureContentsGPU(context, texture, textureObjFormat, index, |
| 34183 |
@@ -210,7 +240,7 @@ GLint GetSliceOrDepth(const ImageNativeIndex &index) |
| 34184 |
RenderTargetMtl tempRtt; |
| 34185 |
tempRtt.set(texture, index.getNativeLevel(), sliceOrDepth, textureObjFormat); |
| 34186 |
|
| 34187 |
- int clearAlpha = 0; |
| 34188 |
+ float clearAlpha = 0; |
| 34189 |
if (!textureObjFormat.intendedAngleFormat().alphaBits) |
| 34190 |
{ |
| 34191 |
// if intended format doesn't have alpha, set it to 1.0. |
| 34192 |
@@ -240,11 +270,11 @@ GLint GetSliceOrDepth(const ImageNativeIndex &index) |
| 34193 |
ClearColorValue clearColor; |
| 34194 |
if (angleFormat.isSint()) |
| 34195 |
{ |
| 34196 |
- clearColor.setAsInt(0, 0, 0, clearAlpha); |
| 34197 |
+ clearColor.setAsInt(0, 0, 0, (int)clearAlpha); |
| 34198 |
} |
| 34199 |
else if (angleFormat.isUint()) |
| 34200 |
{ |
| 34201 |
- clearColor.setAsUInt(0, 0, 0, clearAlpha); |
| 34202 |
+ clearColor.setAsUInt(0, 0, 0, (int)clearAlpha); |
| 34203 |
} |
| 34204 |
else |
| 34205 |
{ |
| 34206 |
@@ -283,17 +313,17 @@ GLint GetSliceOrDepth(const ImageNativeIndex &index) |
| 34207 |
rpDesc.sampleCount = texture->samples(); |
| 34208 |
if (angleFormat.depthBits) |
| 34209 |
{ |
| 34210 |
- rpDesc.depthAttachment.texture = texture; |
| 34211 |
- rpDesc.depthAttachment.level = level; |
| 34212 |
- rpDesc.depthAttachment.sliceOrDepth = layer; |
| 34213 |
+ rpDesc.depthAttachment.renderTarget->texture = texture; |
| 34214 |
+ rpDesc.depthAttachment.renderTarget->level = level; |
| 34215 |
+ rpDesc.depthAttachment.renderTarget->sliceOrDepth = layer; |
| 34216 |
rpDesc.depthAttachment.loadAction = MTLLoadActionClear; |
| 34217 |
rpDesc.depthAttachment.clearDepth = 1.0; |
| 34218 |
} |
| 34219 |
if (angleFormat.stencilBits) |
| 34220 |
{ |
| 34221 |
- rpDesc.stencilAttachment.texture = texture; |
| 34222 |
- rpDesc.stencilAttachment.level = level; |
| 34223 |
- rpDesc.stencilAttachment.sliceOrDepth = layer; |
| 34224 |
+ rpDesc.stencilAttachment.renderTarget->texture = texture; |
| 34225 |
+ rpDesc.stencilAttachment.renderTarget->level = level; |
| 34226 |
+ rpDesc.stencilAttachment.renderTarget->sliceOrDepth = layer; |
| 34227 |
rpDesc.stencilAttachment.loadAction = MTLLoadActionClear; |
| 34228 |
} |
| 34229 |
|
| 34230 |
@@ -456,6 +486,30 @@ uint32_t GetDeviceVendorId(id<MTLDevice> metalDevice) |
| 34231 |
return CreateShaderLibrary(metalDevice, source.c_str(), source.size(), error); |
| 34232 |
} |
| 34233 |
|
| 34234 |
+#if 0 |
| 34235 |
+static MTLLanguageVersion GetHighestSupportedMSLVersion() |
| 34236 |
+{ |
| 34237 |
+ // https://developer.apple.com/documentation/metal/mtllanguageversion?language=objc |
| 34238 |
+ if (ANGLE_APPLE_AVAILABLE_XCI(11.0, 14.0, 14.0)) |
| 34239 |
+ return MTLLanguageVersion2_3; |
| 34240 |
+ if (ANGLE_APPLE_AVAILABLE_XCI(10.15, 13.0, 13.0)) |
| 34241 |
+ return MTLLanguageVersion2_2; |
| 34242 |
+ if (ANGLE_APPLE_AVAILABLE_XCI(10.15, 13.0, 12.0)) |
| 34243 |
+ return MTLLanguageVersion2_1; |
| 34244 |
+ if (ANGLE_APPLE_AVAILABLE_XCI(10.13, 13.0, 11.0)) |
| 34245 |
+ return MTLLanguageVersion2_0; |
| 34246 |
+ if (ANGLE_APPLE_AVAILABLE_XCI(10.12, 13.0, 10.0)) |
| 34247 |
+ return MTLLanguageVersion1_2; |
| 34248 |
+ if (ANGLE_APPLE_AVAILABLE_XCI(10.11, 13.0, 9.0)) |
| 34249 |
+ return MTLLanguageVersion1_1; |
| 34250 |
+# if TARGET_OS_IOS |
| 34251 |
+ if (ANGLE_APPLE_AVAILABLE_I(9.0)) |
| 34252 |
+ return MTLLanguageVersion1_0; |
| 34253 |
+# endif |
| 34254 |
+ return MTLLanguageVersion1_1; |
| 34255 |
+} |
| 34256 |
+#endif |
| 34257 |
+ |
| 34258 |
AutoObjCPtr<id<MTLLibrary>> CreateShaderLibrary(id<MTLDevice> metalDevice, |
| 34259 |
const char *source, |
| 34260 |
size_t sourceLen, |
| 34261 |
@@ -469,8 +523,25 @@ uint32_t GetDeviceVendorId(id<MTLDevice> metalDevice) |
| 34262 |
encoding:NSUTF8StringEncoding |
| 34263 |
freeWhenDone:NO]; |
| 34264 |
auto options = [[[MTLCompileOptions alloc] init] ANGLE_MTL_AUTORELEASE]; |
| 34265 |
+ // Mark all positions in VS with attribute invariant as non-optimizable |
| 34266 |
+#if (defined(__MAC_11_0) && __MAC_OS_X_VERSION_MAX_ALLOWED >= __MAC_11_0) || \ |
| 34267 |
+ (defined(__IPHONE_14_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_14_0) || \ |
| 34268 |
+ (defined(__TVOS_14_0) && __TV_OS_VERSION_MAX_ALLOWED >= __TVOS_14_0) |
| 34269 |
+ options.preserveInvariance = true; |
| 34270 |
+#else |
| 34271 |
+ // No preserveInvariance available compiling from source, so just disable fastmath. |
| 34272 |
+ options.fastMathEnabled = false; |
| 34273 |
+#endif |
| 34274 |
+ // TODO(jcunningham): workaround for intel driver not preserving invariance on all shaders |
| 34275 |
+ if ([metalDevice.name rangeOfString:@"Intel"].location != NSNotFound) |
| 34276 |
+ { |
| 34277 |
+ options.fastMathEnabled = false; |
| 34278 |
+ } |
| 34279 |
auto library = [metalDevice newLibraryWithSource:nsSource options:options error:&nsError]; |
| 34280 |
- |
| 34281 |
+ if (angle::GetEnvironmentVar(kANGLEPrintMSLEnv)[0] == '1') |
| 34282 |
+ { |
| 34283 |
+ NSLog(@"%@\n", nsSource); |
| 34284 |
+ } |
| 34285 |
[nsSource ANGLE_MTL_AUTORELEASE]; |
| 34286 |
|
| 34287 |
*errorOut = std::move(nsError); |
| 34288 |
@@ -772,15 +843,15 @@ MTLTextureSwizzle GetTextureSwizzle(GLenum swizzle) |
| 34289 |
} |
| 34290 |
#endif |
| 34291 |
|
| 34292 |
-MTLColorWriteMask GetEmulatedColorWriteMask(const mtl::Format &mtlFormat, bool *isEmulatedOut) |
| 34293 |
+MTLColorWriteMask GetEmulatedColorWriteMask(const mtl::Format &mtlFormat, bool *emulatedChannelsOut) |
| 34294 |
{ |
| 34295 |
const angle::Format &intendedFormat = mtlFormat.intendedAngleFormat(); |
| 34296 |
const angle::Format &actualFormat = mtlFormat.actualAngleFormat(); |
| 34297 |
- bool isFormatEmulated = false; |
| 34298 |
+ bool emulatedChannels = false; |
| 34299 |
MTLColorWriteMask colorWritableMask = MTLColorWriteMaskAll; |
| 34300 |
if (intendedFormat.alphaBits == 0 && actualFormat.alphaBits) |
| 34301 |
{ |
| 34302 |
- isFormatEmulated = true; |
| 34303 |
+ emulatedChannels = true; |
| 34304 |
// Disable alpha write to this texture |
| 34305 |
colorWritableMask = colorWritableMask & (~MTLColorWriteMaskAlpha); |
| 34306 |
} |
| 34307 |
@@ -788,41 +859,41 @@ MTLColorWriteMask GetEmulatedColorWriteMask(const mtl::Format &mtlFormat, bool * |
| 34308 |
{ |
| 34309 |
if (intendedFormat.redBits == 0 && actualFormat.redBits) |
| 34310 |
{ |
| 34311 |
- isFormatEmulated = true; |
| 34312 |
+ emulatedChannels = true; |
| 34313 |
// Disable red write to this texture |
| 34314 |
colorWritableMask = colorWritableMask & (~MTLColorWriteMaskRed); |
| 34315 |
} |
| 34316 |
if (intendedFormat.greenBits == 0 && actualFormat.greenBits) |
| 34317 |
{ |
| 34318 |
- isFormatEmulated = true; |
| 34319 |
+ emulatedChannels = true; |
| 34320 |
// Disable green write to this texture |
| 34321 |
colorWritableMask = colorWritableMask & (~MTLColorWriteMaskGreen); |
| 34322 |
} |
| 34323 |
if (intendedFormat.blueBits == 0 && actualFormat.blueBits) |
| 34324 |
{ |
| 34325 |
- isFormatEmulated = true; |
| 34326 |
+ emulatedChannels = true; |
| 34327 |
// Disable blue write to this texture |
| 34328 |
colorWritableMask = colorWritableMask & (~MTLColorWriteMaskBlue); |
| 34329 |
} |
| 34330 |
} |
| 34331 |
|
| 34332 |
- *isEmulatedOut = isFormatEmulated; |
| 34333 |
+ *emulatedChannelsOut = emulatedChannels; |
| 34334 |
|
| 34335 |
return colorWritableMask; |
| 34336 |
} |
| 34337 |
|
| 34338 |
MTLColorWriteMask GetEmulatedColorWriteMask(const mtl::Format &mtlFormat) |
| 34339 |
{ |
| 34340 |
- // Ignore isFormatEmulated boolean value |
| 34341 |
- bool isFormatEmulated; |
| 34342 |
- return GetEmulatedColorWriteMask(mtlFormat, &isFormatEmulated); |
| 34343 |
+ // Ignore emulatedChannels boolean value |
| 34344 |
+ bool emulatedChannels; |
| 34345 |
+ return GetEmulatedColorWriteMask(mtlFormat, &emulatedChannels); |
| 34346 |
} |
| 34347 |
|
| 34348 |
bool IsFormatEmulated(const mtl::Format &mtlFormat) |
| 34349 |
{ |
| 34350 |
- bool isFormatEmulated; |
| 34351 |
- (void)GetEmulatedColorWriteMask(mtlFormat, &isFormatEmulated); |
| 34352 |
- return isFormatEmulated; |
| 34353 |
+ bool emulatedChannels; |
| 34354 |
+ (void)GetEmulatedColorWriteMask(mtlFormat, &emulatedChannels); |
| 34355 |
+ return emulatedChannels; |
| 34356 |
} |
| 34357 |
|
| 34358 |
MTLClearColor EmulatedAlphaClearColor(MTLClearColor color, MTLColorWriteMask colorMask) |
| 34359 |
@@ -837,6 +908,151 @@ MTLClearColor EmulatedAlphaClearColor(MTLClearColor color, MTLColorWriteMask col |
| 34360 |
return re; |
| 34361 |
} |
| 34362 |
|
| 34363 |
+NSUInteger GetMaxRenderTargetSizeForDeviceInBytes(id<MTLDevice> device) |
| 34364 |
+{ |
| 34365 |
+ if ([device supportsFamily:MTLGPUFamilyApple4]) |
| 34366 |
+ { |
| 34367 |
+ return 64; |
| 34368 |
+ } |
| 34369 |
+ else if ([device supportsFamily:MTLGPUFamilyApple2]) |
| 34370 |
+ { |
| 34371 |
+ return 32; |
| 34372 |
+ } |
| 34373 |
+ else |
| 34374 |
+ { |
| 34375 |
+ return 16; |
| 34376 |
+ } |
| 34377 |
+} |
| 34378 |
+ |
| 34379 |
+NSUInteger GetMaxNumberOfRenderTargetsForDevice(id<MTLDevice> device) |
| 34380 |
+{ |
| 34381 |
+ if ([device supportsFamily:MTLGPUFamilyApple2] || [device supportsFamily:MTLGPUFamilyMac1]) |
| 34382 |
+ { |
| 34383 |
+ return 8; |
| 34384 |
+ } |
| 34385 |
+ else |
| 34386 |
+ { |
| 34387 |
+ return 4; |
| 34388 |
+ } |
| 34389 |
+} |
| 34390 |
+ |
| 34391 |
+bool DeviceHasMaximumRenderTargetSize(id<MTLDevice> device) |
| 34392 |
+{ |
| 34393 |
+ return [device supportsFamily:MTLGPUFamilyApple1]; |
| 34394 |
+} |
| 34395 |
+ |
| 34396 |
+static NSUInteger getNextLocationForFormat(const FormatCaps &caps, |
| 34397 |
+ bool isMSAA, |
| 34398 |
+ NSUInteger currentRenderTargetSize) |
| 34399 |
+{ |
| 34400 |
+ assert(!caps.compressed); |
| 34401 |
+ uint8_t alignment = caps.alignment; |
| 34402 |
+ NSUInteger pixelBytes = caps.pixelBytes; |
| 34403 |
+ NSUInteger pixelBytesMSAA = caps.pixelBytesMSAA; |
| 34404 |
+ pixelBytes = isMSAA ? pixelBytesMSAA : pixelBytes; |
| 34405 |
+ |
| 34406 |
+ currentRenderTargetSize = (currentRenderTargetSize + (alignment - 1)) & ~(alignment - 1); |
| 34407 |
+ currentRenderTargetSize += pixelBytes; |
| 34408 |
+ return currentRenderTargetSize; |
| 34409 |
+} |
| 34410 |
+ |
| 34411 |
+NSUInteger ComputeTotalSizeUsedForMTLRenderPassDescriptor(const MTLRenderPassDescriptor *descriptor, |
| 34412 |
+ const Context *context, |
| 34413 |
+ id<MTLDevice> device) |
| 34414 |
+{ |
| 34415 |
+ NSUInteger currentRenderTargetSize = 0; |
| 34416 |
+ |
| 34417 |
+ for (NSUInteger i = 0; i < GetMaxNumberOfRenderTargetsForDevice(device); i++) |
| 34418 |
+ { |
| 34419 |
+ MTLPixelFormat pixelFormat = descriptor.colorAttachments[i].texture.pixelFormat; |
| 34420 |
+ bool isMsaa = descriptor.colorAttachments[i].texture.sampleCount > 1; |
| 34421 |
+ if (pixelFormat != MTLPixelFormatInvalid) |
| 34422 |
+ { |
| 34423 |
+ const FormatCaps &caps = context->getDisplay()->getNativeFormatCaps(pixelFormat); |
| 34424 |
+ currentRenderTargetSize = |
| 34425 |
+ getNextLocationForFormat(caps, isMsaa, currentRenderTargetSize); |
| 34426 |
+ } |
| 34427 |
+ } |
| 34428 |
+ if (descriptor.depthAttachment.texture.pixelFormat == |
| 34429 |
+ descriptor.stencilAttachment.texture.pixelFormat) |
| 34430 |
+ { |
| 34431 |
+ bool isMsaa = descriptor.depthAttachment.texture.sampleCount > 1; |
| 34432 |
+ if (descriptor.depthAttachment.texture.pixelFormat != MTLPixelFormatInvalid) |
| 34433 |
+ { |
| 34434 |
+ const FormatCaps &caps = context->getDisplay()->getNativeFormatCaps( |
| 34435 |
+ descriptor.depthAttachment.texture.pixelFormat); |
| 34436 |
+ currentRenderTargetSize = |
| 34437 |
+ getNextLocationForFormat(caps, isMsaa, currentRenderTargetSize); |
| 34438 |
+ } |
| 34439 |
+ } |
| 34440 |
+ else |
| 34441 |
+ { |
| 34442 |
+ if (descriptor.depthAttachment.texture.pixelFormat != MTLPixelFormatInvalid) |
| 34443 |
+ { |
| 34444 |
+ bool isMsaa = descriptor.depthAttachment.texture.sampleCount > 1; |
| 34445 |
+ const FormatCaps &caps = context->getDisplay()->getNativeFormatCaps( |
| 34446 |
+ descriptor.depthAttachment.texture.pixelFormat); |
| 34447 |
+ currentRenderTargetSize = |
| 34448 |
+ getNextLocationForFormat(caps, isMsaa, currentRenderTargetSize); |
| 34449 |
+ } |
| 34450 |
+ if (descriptor.stencilAttachment.texture.pixelFormat != MTLPixelFormatInvalid) |
| 34451 |
+ { |
| 34452 |
+ bool isMsaa = descriptor.stencilAttachment.texture.sampleCount > 1; |
| 34453 |
+ const FormatCaps &caps = context->getDisplay()->getNativeFormatCaps( |
| 34454 |
+ descriptor.stencilAttachment.texture.pixelFormat); |
| 34455 |
+ currentRenderTargetSize = |
| 34456 |
+ getNextLocationForFormat(caps, isMsaa, currentRenderTargetSize); |
| 34457 |
+ } |
| 34458 |
+ } |
| 34459 |
+ return currentRenderTargetSize; |
| 34460 |
+} |
| 34461 |
+NSUInteger ComputeTotalSizeUsedForMTLRenderPipelineDescriptor( |
| 34462 |
+ const MTLRenderPipelineDescriptor *descriptor, |
| 34463 |
+ const Context *context, |
| 34464 |
+ id<MTLDevice> device) |
| 34465 |
+{ |
| 34466 |
+ NSUInteger currentRenderTargetSize = 0; |
| 34467 |
+ bool isMsaa = descriptor.sampleCount > 1; |
| 34468 |
+ for (NSUInteger i = 0; i < GetMaxNumberOfRenderTargetsForDevice(device); i++) |
| 34469 |
+ { |
| 34470 |
+ MTLRenderPipelineColorAttachmentDescriptor *color = descriptor.colorAttachments[i]; |
| 34471 |
+ if (color.pixelFormat != MTLPixelFormatInvalid) |
| 34472 |
+ { |
| 34473 |
+ const FormatCaps &caps = context->getDisplay()->getNativeFormatCaps(color.pixelFormat); |
| 34474 |
+ currentRenderTargetSize = |
| 34475 |
+ getNextLocationForFormat(caps, isMsaa, currentRenderTargetSize); |
| 34476 |
+ } |
| 34477 |
+ } |
| 34478 |
+ if (descriptor.depthAttachmentPixelFormat == descriptor.stencilAttachmentPixelFormat) |
| 34479 |
+ { |
| 34480 |
+ if (descriptor.depthAttachmentPixelFormat != MTLPixelFormatInvalid) |
| 34481 |
+ { |
| 34482 |
+ const FormatCaps &caps = |
| 34483 |
+ context->getDisplay()->getNativeFormatCaps(descriptor.depthAttachmentPixelFormat); |
| 34484 |
+ currentRenderTargetSize = |
| 34485 |
+ getNextLocationForFormat(caps, isMsaa, currentRenderTargetSize); |
| 34486 |
+ } |
| 34487 |
+ } |
| 34488 |
+ else |
| 34489 |
+ { |
| 34490 |
+ if (descriptor.depthAttachmentPixelFormat != MTLPixelFormatInvalid) |
| 34491 |
+ { |
| 34492 |
+ const FormatCaps &caps = |
| 34493 |
+ context->getDisplay()->getNativeFormatCaps(descriptor.depthAttachmentPixelFormat); |
| 34494 |
+ currentRenderTargetSize = |
| 34495 |
+ getNextLocationForFormat(caps, isMsaa, currentRenderTargetSize); |
| 34496 |
+ } |
| 34497 |
+ if (descriptor.stencilAttachmentPixelFormat != MTLPixelFormatInvalid) |
| 34498 |
+ { |
| 34499 |
+ const FormatCaps &caps = |
| 34500 |
+ context->getDisplay()->getNativeFormatCaps(descriptor.stencilAttachmentPixelFormat); |
| 34501 |
+ currentRenderTargetSize = |
| 34502 |
+ getNextLocationForFormat(caps, isMsaa, currentRenderTargetSize); |
| 34503 |
+ } |
| 34504 |
+ } |
| 34505 |
+ return currentRenderTargetSize; |
| 34506 |
+} |
| 34507 |
+ |
| 34508 |
gl::Box MTLRegionToGLBox(const MTLRegion &mtlRegion) |
| 34509 |
{ |
| 34510 |
return gl::Box(static_cast<int>(mtlRegion.origin.x), static_cast<int>(mtlRegion.origin.y), |
| 34511 |
diff --git a/src/libANGLE/renderer/metal/shaders/blit.metal b/src/libANGLE/renderer/metal/shaders/blit.metal |
| 34512 |
index 4272c4f..2a9bb5d 100644 |
| 34513 |
--- a/src/libANGLE/renderer/metal/shaders/blit.metal |
| 34514 |
+++ b/src/libANGLE/renderer/metal/shaders/blit.metal |
| 34515 |
@@ -334,7 +334,7 @@ kernel void blitStencilToBufferCS(ushort2 gIndices [[thread_position_in_grid]], |
| 34516 |
} |
| 34517 |
|
| 34518 |
// Fragment's stencil output is only available since Metal 2.1 |
| 34519 |
-@@#if __METAL_VERSION__ >= 210 |
| 34520 |
+#if __METAL_VERSION__ >= 210 |
| 34521 |
|
| 34522 |
struct FragmentStencilOut |
| 34523 |
{ |
| 34524 |
@@ -397,4 +397,4 @@ fragment FragmentDepthStencilOut blitDepthStencilFS( |
| 34525 |
srcStencilTextureCube, input.texCoords, options.srcLevel, options.srcLayer); |
| 34526 |
return re; |
| 34527 |
} |
| 34528 |
-@@#endif // __METAL_VERSION__ >= 210 |
| 34529 |
+#endif // __METAL_VERSION__ >= 210 |
| 34530 |
diff --git a/src/libANGLE/renderer/metal/shaders/common.h b/src/libANGLE/renderer/metal/shaders/common.h |
| 34531 |
index 68c7745..e6673b5 100644 |
| 34532 |
--- a/src/libANGLE/renderer/metal/shaders/common.h |
| 34533 |
+++ b/src/libANGLE/renderer/metal/shaders/common.h |
| 34534 |
@@ -10,8 +10,8 @@ |
| 34535 |
|
| 34536 |
// clang-format off |
| 34537 |
#ifndef SKIP_STD_HEADERS |
| 34538 |
-@@# include <simd/simd.h> |
| 34539 |
-@@# include <metal_stdlib> |
| 34540 |
+# include <simd/simd.h> |
| 34541 |
+# include <metal_stdlib> |
| 34542 |
#endif |
| 34543 |
|
| 34544 |
#include "constants.h" |
| 34545 |
diff --git a/src/libANGLE/renderer/metal/shaders/copy_buffer.metal b/src/libANGLE/renderer/metal/shaders/copy_buffer.metal |
| 34546 |
index df7c4c9..1b408d8 100644 |
| 34547 |
--- a/src/libANGLE/renderer/metal/shaders/copy_buffer.metal |
| 34548 |
+++ b/src/libANGLE/renderer/metal/shaders/copy_buffer.metal |
| 34549 |
@@ -4,22 +4,22 @@ |
| 34550 |
// found in the LICENSE file. |
| 34551 |
// |
| 34552 |
// copy_buffer.metal: implements compute shader that copy formatted data from buffer to texture, |
| 34553 |
-// and from texture to buffer. |
| 34554 |
+// from texture to buffer and from buffer to buffer. |
| 34555 |
// NOTE(hqle): This file is a bit hard to read but there are a lot of repeated works, and it would |
| 34556 |
// be a pain to implement without the use of macros. |
| 34557 |
// |
| 34558 |
|
| 34559 |
-@@#include <metal_pack> |
| 34560 |
+#include <metal_pack> |
| 34561 |
|
| 34562 |
#include "common.h" |
| 34563 |
#include "format_autogen.h" |
| 34564 |
|
| 34565 |
using namespace rx::mtl_shader; |
| 34566 |
|
| 34567 |
-constant int kCopyFormatType [[function_constant(10)]]; |
| 34568 |
+constant int kCopyFormatType [[function_constant(1)]]; |
| 34569 |
|
| 34570 |
/* -------- copy pixel data between buffer and texture ---------*/ |
| 34571 |
-constant int kCopyTextureType [[function_constant(20)]]; |
| 34572 |
+constant int kCopyTextureType [[function_constant(2)]]; |
| 34573 |
constant bool kCopyTextureType2D = kCopyTextureType == kTextureType2D; |
| 34574 |
constant bool kCopyTextureType2DArray = kCopyTextureType == kTextureType2DArray; |
| 34575 |
constant bool kCopyTextureType2DMS = kCopyTextureType == kTextureType2DMultisample; |
| 34576 |
diff --git a/src/libANGLE/renderer/metal/shaders/format_autogen.h b/src/libANGLE/renderer/metal/shaders/format_autogen.h |
| 34577 |
index a17ead3..b991e48 100644 |
| 34578 |
--- a/src/libANGLE/renderer/metal/shaders/format_autogen.h |
| 34579 |
+++ b/src/libANGLE/renderer/metal/shaders/format_autogen.h |
| 34580 |
@@ -245,5 +245,5 @@ enum |
| 34581 |
|
| 34582 |
} |
| 34583 |
|
| 34584 |
-} // namespace mtl_shader |
| 34585 |
-} // namespace rx |
| 34586 |
+} |
| 34587 |
+} |
| 34588 |
diff --git a/src/libANGLE/renderer/metal/shaders/gen_indices.metal b/src/libANGLE/renderer/metal/shaders/gen_indices.metal |
| 34589 |
index 2d8353b..eed61ea 100644 |
| 34590 |
--- a/src/libANGLE/renderer/metal/shaders/gen_indices.metal |
| 34591 |
+++ b/src/libANGLE/renderer/metal/shaders/gen_indices.metal |
| 34592 |
@@ -56,10 +56,10 @@ inline uint getIndexUnalignedU32(constant uchar *input, uint offset, uint idx) |
| 34593 |
return input0 | (input1 << 8) | (input2 << 16) | (input3 << 24); |
| 34594 |
} |
| 34595 |
|
| 34596 |
-kernel void convertIndexU8ToU16(uint idx[[thread_position_in_grid]], |
| 34597 |
- constant IndexConversionParams &options[[buffer(0)]], |
| 34598 |
- constant uchar *input[[buffer(1)]], |
| 34599 |
- device ushort *output[[buffer(2)]]) |
| 34600 |
+kernel void convertIndexU8ToU16(uint idx [[thread_position_in_grid]], |
| 34601 |
+ constant IndexConversionParams &options [[buffer(0)]], |
| 34602 |
+ constant uchar *input [[buffer(1)]], |
| 34603 |
+ device ushort *output [[buffer(2)]]) |
| 34604 |
{ |
| 34605 |
ANGLE_IDX_CONVERSION_GUARD(idx, options); |
| 34606 |
|
| 34607 |
@@ -75,12 +75,13 @@ kernel void convertIndexU8ToU16(uint idx[[thread_position_in_grid]], |
| 34608 |
} |
| 34609 |
} |
| 34610 |
|
| 34611 |
-kernel void convertIndexU16( |
| 34612 |
- uint idx[[thread_position_in_grid]], |
| 34613 |
- constant IndexConversionParams &options[[buffer(0)]], |
| 34614 |
- constant uchar *input[[ buffer(1), function_constant(kSourceBufferUnaligned) ]], |
| 34615 |
- constant ushort *inputAligned[[ buffer(1), function_constant(kSourceBufferAligned) ]], |
| 34616 |
- device ushort *output[[buffer(2)]]) |
| 34617 |
+kernel void convertIndexU16(uint idx [[thread_position_in_grid]], |
| 34618 |
+ constant IndexConversionParams &options [[buffer(0)]], |
| 34619 |
+ constant uchar *input |
| 34620 |
+ [[buffer(1), function_constant(kSourceBufferUnaligned)]], |
| 34621 |
+ constant ushort *inputAligned |
| 34622 |
+ [[buffer(1), function_constant(kSourceBufferAligned)]], |
| 34623 |
+ device ushort *output [[buffer(2)]]) |
| 34624 |
{ |
| 34625 |
ANGLE_IDX_CONVERSION_GUARD(idx, options); |
| 34626 |
|
| 34627 |
@@ -96,12 +97,13 @@ kernel void convertIndexU16( |
| 34628 |
output[idx] = value; |
| 34629 |
} |
| 34630 |
|
| 34631 |
-kernel void convertIndexU32( |
| 34632 |
- uint idx[[thread_position_in_grid]], |
| 34633 |
- constant IndexConversionParams &options[[buffer(0)]], |
| 34634 |
- constant uchar *input[[ buffer(1), function_constant(kSourceBufferUnaligned) ]], |
| 34635 |
- constant uint *inputAligned[[ buffer(1), function_constant(kSourceBufferAligned) ]], |
| 34636 |
- device uint *output[[buffer(2)]]) |
| 34637 |
+kernel void convertIndexU32(uint idx [[thread_position_in_grid]], |
| 34638 |
+ constant IndexConversionParams &options [[buffer(0)]], |
| 34639 |
+ constant uchar *input |
| 34640 |
+ [[buffer(1), function_constant(kSourceBufferUnaligned)]], |
| 34641 |
+ constant uint *inputAligned |
| 34642 |
+ [[buffer(1), function_constant(kSourceBufferAligned)]], |
| 34643 |
+ device uint *output [[buffer(2)]]) |
| 34644 |
{ |
| 34645 |
ANGLE_IDX_CONVERSION_GUARD(idx, options); |
| 34646 |
|
| 34647 |
@@ -140,9 +142,9 @@ kernel void genTriFanIndicesFromArray(uint idx [[thread_position_in_grid]], |
| 34648 |
|
| 34649 |
inline uint getIndexU32(uint offset, |
| 34650 |
uint idx, |
| 34651 |
- constant uchar *inputU8[[function_constant(kUseSourceBufferU8)]], |
| 34652 |
- constant ushort *inputU16[[function_constant(kUseSourceBufferU16)]], |
| 34653 |
- constant uint *inputU32[[function_constant(kUseSourceBufferU32)]]) |
| 34654 |
+ constant uchar *inputU8 [[function_constant(kUseSourceBufferU8)]], |
| 34655 |
+ constant ushort *inputU16 [[function_constant(kUseSourceBufferU16)]], |
| 34656 |
+ constant uint *inputU32 [[function_constant(kUseSourceBufferU32)]]) |
| 34657 |
{ |
| 34658 |
if (kUseSourceBufferU8) |
| 34659 |
{ |
| 34660 |
@@ -170,13 +172,15 @@ inline uint getIndexU32(uint offset, |
| 34661 |
// NOTE(hqle): triangle fan indices generation doesn't support primitive restart. |
| 34662 |
// Generate triangle fan indices from an indices buffer. indexCount options indicates number |
| 34663 |
// of indices starting from the 3rd. |
| 34664 |
-kernel void genTriFanIndicesFromElements( |
| 34665 |
- uint idx[[thread_position_in_grid]], |
| 34666 |
- constant IndexConversionParams &options[[buffer(0)]], |
| 34667 |
- constant uchar *inputU8[[ buffer(1), function_constant(kUseSourceBufferU8) ]], |
| 34668 |
- constant ushort *inputU16[[ buffer(1), function_constant(kUseSourceBufferU16) ]], |
| 34669 |
- constant uint *inputU32[[ buffer(1), function_constant(kUseSourceBufferU32) ]], |
| 34670 |
- device uint *output[[buffer(2)]]) |
| 34671 |
+kernel void genTriFanIndicesFromElements(uint idx [[thread_position_in_grid]], |
| 34672 |
+ constant IndexConversionParams &options [[buffer(0)]], |
| 34673 |
+ constant uchar *inputU8 |
| 34674 |
+ [[buffer(1), function_constant(kUseSourceBufferU8)]], |
| 34675 |
+ constant ushort *inputU16 |
| 34676 |
+ [[buffer(1), function_constant(kUseSourceBufferU16)]], |
| 34677 |
+ constant uint *inputU32 |
| 34678 |
+ [[buffer(1), function_constant(kUseSourceBufferU32)]], |
| 34679 |
+ device uint *output [[buffer(2)]]) |
| 34680 |
{ |
| 34681 |
ANGLE_IDX_CONVERSION_GUARD(idx, options); |
| 34682 |
|
| 34683 |
diff --git a/src/libANGLE/renderer/metal/shaders/gen_mipmap.metal b/src/libANGLE/renderer/metal/shaders/gen_mipmap.metal |
| 34684 |
index b3a3675..f2338b2 100644 |
| 34685 |
--- a/src/libANGLE/renderer/metal/shaders/gen_mipmap.metal |
| 34686 |
+++ b/src/libANGLE/renderer/metal/shaders/gen_mipmap.metal |
| 34687 |
@@ -23,8 +23,6 @@ using namespace rx::mtl_shader; |
| 34688 |
|
| 34689 |
#define TEXEL_LOAD(index) float4(sR[index], sG[index], sB[index], sA[index]) |
| 34690 |
|
| 34691 |
-#define TO_LINEAR(texel) (options.sRGB ? sRGBtoLinear(texel) : texel) |
| 34692 |
- |
| 34693 |
#define OUT_OF_BOUND_CHECK(edgeValue, targetValue, condition) \ |
| 34694 |
(condition) ? (edgeValue) : (targetValue) |
| 34695 |
|
| 34696 |
@@ -32,7 +30,6 @@ struct GenMipParams |
| 34697 |
{ |
| 34698 |
uint srcLevel; |
| 34699 |
uint numMipLevelsToGen; |
| 34700 |
- bool sRGB; |
| 34701 |
}; |
| 34702 |
|
| 34703 |
// NOTE(hqle): For numMipLevelsToGen > 1, this function assumes the texture is power of two. If it |
| 34704 |
@@ -83,10 +80,6 @@ kernel void generate3DMipmaps(uint lIndex [[thread_index_in_threadgroup]], |
| 34705 |
// ---- Second mip level -------- |
| 34706 |
|
| 34707 |
// Write to shared memory |
| 34708 |
- if (options.sRGB) |
| 34709 |
- { |
| 34710 |
- texel1 = linearToSRGB(texel1); |
| 34711 |
- } |
| 34712 |
TEXEL_STORE(lIndex, texel1); |
| 34713 |
|
| 34714 |
threadgroup_barrier(mem_flags::mem_threadgroup); |
| 34715 |
@@ -119,7 +112,7 @@ kernel void generate3DMipmaps(uint lIndex [[thread_index_in_threadgroup]], |
| 34716 |
|
| 34717 |
texel1 = (texel1 + texel2 + texel3 + texel4 + texel5 + texel6 + texel7 + texel8) / 8.0; |
| 34718 |
|
| 34719 |
- dstMip2.write(TO_LINEAR(texel1), gIndices >> 1); |
| 34720 |
+ dstMip2.write(texel1, gIndices >> 1); |
| 34721 |
|
| 34722 |
// Write to shared memory |
| 34723 |
TEXEL_STORE(lIndex, texel1); |
| 34724 |
@@ -165,7 +158,7 @@ kernel void generate3DMipmaps(uint lIndex [[thread_index_in_threadgroup]], |
| 34725 |
|
| 34726 |
texel1 = (texel1 + texel2 + texel3 + texel4 + texel5 + texel6 + texel7 + texel8) / 8.0; |
| 34727 |
|
| 34728 |
- dstMip3.write(TO_LINEAR(texel1), gIndices >> 2); |
| 34729 |
+ dstMip3.write(texel1, gIndices >> 2); |
| 34730 |
|
| 34731 |
// Write to shared memory |
| 34732 |
TEXEL_STORE(lIndex, texel1); |
| 34733 |
@@ -211,6 +204,348 @@ kernel void generate3DMipmaps(uint lIndex [[thread_index_in_threadgroup]], |
| 34734 |
|
| 34735 |
texel1 = (texel1 + texel2 + texel3 + texel4 + texel5 + texel6 + texel7 + texel8) / 8.0; |
| 34736 |
|
| 34737 |
- dstMip4.write(TO_LINEAR(texel1), gIndices >> 3); |
| 34738 |
+ dstMip4.write(texel1, gIndices >> 3); |
| 34739 |
+ } |
| 34740 |
+} |
| 34741 |
+ |
| 34742 |
+kernel void generate2DMipmaps(uint lIndex [[thread_index_in_threadgroup]], |
| 34743 |
+ ushort2 gIndices [[thread_position_in_grid]], |
| 34744 |
+ texture2d<float> srcTexture [[texture(0)]], |
| 34745 |
+ texture2d<float, access::write> dstMip1 [[texture(1)]], |
| 34746 |
+ texture2d<float, access::write> dstMip2 [[texture(2)]], |
| 34747 |
+ texture2d<float, access::write> dstMip3 [[texture(3)]], |
| 34748 |
+ texture2d<float, access::write> dstMip4 [[texture(4)]], |
| 34749 |
+ constant GenMipParams &options [[buffer(0)]]) |
| 34750 |
+{ |
| 34751 |
+ uint firstMipLevel = options.srcLevel + 1; |
| 34752 |
+ ushort2 mipSize = |
| 34753 |
+ ushort2(srcTexture.get_width(firstMipLevel), srcTexture.get_height(firstMipLevel)); |
| 34754 |
+ bool validThread = gIndices.x < mipSize.x && gIndices.y < mipSize.y; |
| 34755 |
+ |
| 34756 |
+ constexpr sampler textureSampler(mag_filter::linear, min_filter::linear, mip_filter::linear); |
| 34757 |
+ |
| 34758 |
+ // NOTE(hqle): Use simd_group function whenever available. That could avoid barrier use. |
| 34759 |
+ |
| 34760 |
+ // Use struct of array style to avoid bank conflict. |
| 34761 |
+ threadgroup float sR[kThreadGroupXY]; |
| 34762 |
+ threadgroup float sG[kThreadGroupXY]; |
| 34763 |
+ threadgroup float sB[kThreadGroupXY]; |
| 34764 |
+ threadgroup float sA[kThreadGroupXY]; |
| 34765 |
+ |
| 34766 |
+ // ----- First mip level ------- |
| 34767 |
+ float4 texel1; |
| 34768 |
+ if (validThread) |
| 34769 |
+ { |
| 34770 |
+ float2 texCoords = (float2(gIndices) + float2(0.5, 0.5)) / float2(mipSize); |
| 34771 |
+ texel1 = srcTexture.sample(textureSampler, texCoords, level(options.srcLevel)); |
| 34772 |
+ |
| 34773 |
+ // Write to texture |
| 34774 |
+ dstMip1.write(texel1, gIndices); |
| 34775 |
+ } |
| 34776 |
+ else |
| 34777 |
+ { |
| 34778 |
+ // This will invalidate all subsequent checks |
| 34779 |
+ lIndex = 0xffffffff; |
| 34780 |
+ } |
| 34781 |
+ |
| 34782 |
+ if (options.numMipLevelsToGen == 1) |
| 34783 |
+ { |
| 34784 |
+ return; |
| 34785 |
+ } |
| 34786 |
+ |
| 34787 |
+ // ---- Second mip level -------- |
| 34788 |
+ |
| 34789 |
+ // Write to shared memory |
| 34790 |
+ TEXEL_STORE(lIndex, texel1); |
| 34791 |
+ |
| 34792 |
+ threadgroup_barrier(mem_flags::mem_threadgroup); |
| 34793 |
+ |
| 34794 |
+ // Index must be even |
| 34795 |
+ if ((lIndex & 0x09) == 0) // (lIndex & b001001) == 0 |
| 34796 |
+ { |
| 34797 |
+ bool2 atEdge = gIndices == (mipSize - ushort2(1)); |
| 34798 |
+ |
| 34799 |
+ // (x+1, y) |
| 34800 |
+ // If the width of mip is 1, texel2 will equal to texel1: |
| 34801 |
+ float4 texel2 = OUT_OF_BOUND_CHECK(texel1, TEXEL_LOAD(lIndex + 1), atEdge.x); |
| 34802 |
+ // (x, y+1) |
| 34803 |
+ float4 texel3 = OUT_OF_BOUND_CHECK(texel1, TEXEL_LOAD(lIndex + kThreadGroupX), atEdge.y); |
| 34804 |
+ // (x+1, y+1) |
| 34805 |
+ float4 texel4 = OUT_OF_BOUND_CHECK(texel2, TEXEL_LOAD(lIndex + (kThreadGroupX + 1)), |
| 34806 |
+ atEdge.x | atEdge.y); |
| 34807 |
+ |
| 34808 |
+ texel1 = (texel1 + texel2 + texel3 + texel4) / 4.0; |
| 34809 |
+ |
| 34810 |
+ dstMip2.write(texel1, gIndices >> 1); |
| 34811 |
+ |
| 34812 |
+ // Write to shared memory |
| 34813 |
+ TEXEL_STORE(lIndex, texel1); |
| 34814 |
+ } |
| 34815 |
+ |
| 34816 |
+ if (options.numMipLevelsToGen == 2) |
| 34817 |
+ { |
| 34818 |
+ return; |
| 34819 |
+ } |
| 34820 |
+ |
| 34821 |
+ // ---- 3rd mip level -------- |
| 34822 |
+ threadgroup_barrier(mem_flags::mem_threadgroup); |
| 34823 |
+ |
| 34824 |
+ // Index must be multiple of 4 |
| 34825 |
+ if ((lIndex & 0x1b) == 0) // (lIndex & b011011) == 0 |
| 34826 |
+ { |
| 34827 |
+ mipSize = max(mipSize >> 1, ushort2(1)); |
| 34828 |
+ bool2 atEdge = (gIndices >> 1) == (mipSize - ushort2(1)); |
| 34829 |
+ |
| 34830 |
+ // (x+1, y) |
| 34831 |
+ // If the width of mip is 1, texel2 will equal to texel1: |
| 34832 |
+ float4 texel2 = OUT_OF_BOUND_CHECK(texel1, TEXEL_LOAD(lIndex + 2), atEdge.x); |
| 34833 |
+ // (x, y+1) |
| 34834 |
+ float4 texel3 = |
| 34835 |
+ OUT_OF_BOUND_CHECK(texel1, TEXEL_LOAD(lIndex + 2 * kThreadGroupX), atEdge.y); |
| 34836 |
+ // (x+1, y+1) |
| 34837 |
+ float4 texel4 = OUT_OF_BOUND_CHECK(texel2, TEXEL_LOAD(lIndex + (2 * kThreadGroupX + 2)), |
| 34838 |
+ atEdge.x | atEdge.y); |
| 34839 |
+ |
| 34840 |
+ texel1 = (texel1 + texel2 + texel3 + texel4) / 4.0; |
| 34841 |
+ |
| 34842 |
+ dstMip3.write(texel1, gIndices >> 2); |
| 34843 |
+ |
| 34844 |
+ // Write to shared memory |
| 34845 |
+ TEXEL_STORE(lIndex, texel1); |
| 34846 |
+ } |
| 34847 |
+ |
| 34848 |
+ if (options.numMipLevelsToGen == 3) |
| 34849 |
+ { |
| 34850 |
+ return; |
| 34851 |
+ } |
| 34852 |
+ |
| 34853 |
+ // ---- 4th mip level -------- |
| 34854 |
+ threadgroup_barrier(mem_flags::mem_threadgroup); |
| 34855 |
+ |
| 34856 |
+ // Index must be multiple of 8 |
| 34857 |
+ if ((lIndex & 0x3f) == 0) // (lIndex & b111111) == 0 |
| 34858 |
+ { |
| 34859 |
+ mipSize = max(mipSize >> 1, ushort2(1)); |
| 34860 |
+ bool2 atEdge = (gIndices >> 2) == (mipSize - ushort2(1)); |
| 34861 |
+ |
| 34862 |
+ // (x+1, y) |
| 34863 |
+ // If the width of mip is 1, texel2 will equal to texel1: |
| 34864 |
+ float4 texel2 = OUT_OF_BOUND_CHECK(texel1, TEXEL_LOAD(lIndex + 4), atEdge.x); |
| 34865 |
+ // (x, y+1) |
| 34866 |
+ float4 texel3 = |
| 34867 |
+ OUT_OF_BOUND_CHECK(texel1, TEXEL_LOAD(lIndex + 4 * kThreadGroupX), atEdge.y); |
| 34868 |
+ // (x+1, y+1) |
| 34869 |
+ float4 texel4 = OUT_OF_BOUND_CHECK(texel2, TEXEL_LOAD(lIndex + (4 * kThreadGroupX + 4)), |
| 34870 |
+ atEdge.x | atEdge.y); |
| 34871 |
+ |
| 34872 |
+ texel1 = (texel1 + texel2 + texel3 + texel4) / 4.0; |
| 34873 |
+ |
| 34874 |
+ dstMip4.write(texel1, gIndices >> 3); |
| 34875 |
+ } |
| 34876 |
+} |
| 34877 |
+ |
| 34878 |
+template <typename TextureTypeR, typename TextureTypeW> |
| 34879 |
+static __attribute__((always_inline)) void generateCubeOr2DArray2ndAndMoreMipmaps( |
| 34880 |
+ uint lIndex, |
| 34881 |
+ ushort3 gIndices, |
| 34882 |
+ TextureTypeR srcTexture, |
| 34883 |
+ TextureTypeW dstMip2, |
| 34884 |
+ TextureTypeW dstMip3, |
| 34885 |
+ TextureTypeW dstMip4, |
| 34886 |
+ ushort2 mip1Size, |
| 34887 |
+ float4 mip1Texel, |
| 34888 |
+ threadgroup float *sR, |
| 34889 |
+ threadgroup float *sG, |
| 34890 |
+ threadgroup float *sB, |
| 34891 |
+ threadgroup float *sA, |
| 34892 |
+ constant GenMipParams &options) |
| 34893 |
+{ |
| 34894 |
+ ushort2 mipSize = mip1Size; |
| 34895 |
+ float4 texel1 = mip1Texel; |
| 34896 |
+ |
| 34897 |
+ // ---- Second mip level -------- |
| 34898 |
+ |
| 34899 |
+ // Write to shared memory |
| 34900 |
+ TEXEL_STORE(lIndex, texel1); |
| 34901 |
+ |
| 34902 |
+ threadgroup_barrier(mem_flags::mem_threadgroup); |
| 34903 |
+ |
| 34904 |
+ // Index must be even |
| 34905 |
+ if ((lIndex & 0x09) == 0) // (lIndex & b001001) == 0 |
| 34906 |
+ { |
| 34907 |
+ bool2 atEdge = gIndices.xy == (mipSize - ushort2(1)); |
| 34908 |
+ |
| 34909 |
+ // (x+1, y) |
| 34910 |
+ // If the width of mip is 1, texel2 will equal to texel1: |
| 34911 |
+ float4 texel2 = OUT_OF_BOUND_CHECK(texel1, TEXEL_LOAD(lIndex + 1), atEdge.x); |
| 34912 |
+ // (x, y+1) |
| 34913 |
+ float4 texel3 = OUT_OF_BOUND_CHECK(texel1, TEXEL_LOAD(lIndex + kThreadGroupX), atEdge.y); |
| 34914 |
+ // (x+1, y+1) |
| 34915 |
+ float4 texel4 = OUT_OF_BOUND_CHECK(texel2, TEXEL_LOAD(lIndex + (kThreadGroupX + 1)), |
| 34916 |
+ atEdge.x | atEdge.y); |
| 34917 |
+ |
| 34918 |
+ texel1 = (texel1 + texel2 + texel3 + texel4) / 4.0; |
| 34919 |
+ |
| 34920 |
+ dstMip2.write(texel1, gIndices.xy >> 1, gIndices.z); |
| 34921 |
+ |
| 34922 |
+ // Write to shared memory |
| 34923 |
+ TEXEL_STORE(lIndex, texel1); |
| 34924 |
+ } |
| 34925 |
+ |
| 34926 |
+ if (options.numMipLevelsToGen == 2) |
| 34927 |
+ { |
| 34928 |
+ return; |
| 34929 |
+ } |
| 34930 |
+ |
| 34931 |
+ // ---- 3rd mip level -------- |
| 34932 |
+ threadgroup_barrier(mem_flags::mem_threadgroup); |
| 34933 |
+ |
| 34934 |
+ // Index must be multiple of 4 |
| 34935 |
+ if ((lIndex & 0x1b) == 0) // (lIndex & b011011) == 0 |
| 34936 |
+ { |
| 34937 |
+ mipSize = max(mipSize >> 1, ushort2(1)); |
| 34938 |
+ bool2 atEdge = (gIndices.xy >> 1) == (mipSize - ushort2(1)); |
| 34939 |
+ |
| 34940 |
+ // (x+1, y) |
| 34941 |
+ // If the width of mip is 1, texel2 will equal to texel1: |
| 34942 |
+ float4 texel2 = OUT_OF_BOUND_CHECK(texel1, TEXEL_LOAD(lIndex + 2), atEdge.x); |
| 34943 |
+ // (x, y+1) |
| 34944 |
+ float4 texel3 = |
| 34945 |
+ OUT_OF_BOUND_CHECK(texel1, TEXEL_LOAD(lIndex + 2 * kThreadGroupX), atEdge.y); |
| 34946 |
+ // (x+1, y+1) |
| 34947 |
+ float4 texel4 = OUT_OF_BOUND_CHECK(texel2, TEXEL_LOAD(lIndex + (2 * kThreadGroupX + 2)), |
| 34948 |
+ atEdge.x | atEdge.y); |
| 34949 |
+ |
| 34950 |
+ texel1 = (texel1 + texel2 + texel3 + texel4) / 4.0; |
| 34951 |
+ |
| 34952 |
+ dstMip3.write(texel1, gIndices.xy >> 2, gIndices.z); |
| 34953 |
+ |
| 34954 |
+ // Write to shared memory |
| 34955 |
+ TEXEL_STORE(lIndex, texel1); |
| 34956 |
} |
| 34957 |
+ |
| 34958 |
+ if (options.numMipLevelsToGen == 3) |
| 34959 |
+ { |
| 34960 |
+ return; |
| 34961 |
+ } |
| 34962 |
+ |
| 34963 |
+ // ---- 4th mip level -------- |
| 34964 |
+ threadgroup_barrier(mem_flags::mem_threadgroup); |
| 34965 |
+ |
| 34966 |
+ // Index must be multiple of 8 |
| 34967 |
+ if ((lIndex & 0x3f) == 0) // (lIndex & b111111) == 0 |
| 34968 |
+ { |
| 34969 |
+ mipSize = max(mipSize >> 1, ushort2(1)); |
| 34970 |
+ bool2 atEdge = (gIndices.xy >> 2) == (mipSize - ushort2(1)); |
| 34971 |
+ |
| 34972 |
+ // (x+1, y) |
| 34973 |
+ // If the width of mip is 1, texel2 will equal to texel1: |
| 34974 |
+ float4 texel2 = OUT_OF_BOUND_CHECK(texel1, TEXEL_LOAD(lIndex + 4), atEdge.x); |
| 34975 |
+ // (x, y+1) |
| 34976 |
+ float4 texel3 = |
| 34977 |
+ OUT_OF_BOUND_CHECK(texel1, TEXEL_LOAD(lIndex + 4 * kThreadGroupX), atEdge.y); |
| 34978 |
+ // (x+1, y+1) |
| 34979 |
+ float4 texel4 = OUT_OF_BOUND_CHECK(texel2, TEXEL_LOAD(lIndex + (4 * kThreadGroupX + 4)), |
| 34980 |
+ atEdge.x | atEdge.y); |
| 34981 |
+ |
| 34982 |
+ texel1 = (texel1 + texel2 + texel3 + texel4) / 4.0; |
| 34983 |
+ |
| 34984 |
+ dstMip4.write(texel1, gIndices.xy >> 3, gIndices.z); |
| 34985 |
+ } |
| 34986 |
+} |
| 34987 |
+ |
| 34988 |
+kernel void generateCubeMipmaps(uint lIndex [[thread_index_in_threadgroup]], |
| 34989 |
+ ushort3 gIndices [[thread_position_in_grid]], |
| 34990 |
+ texturecube<float> srcTexture [[texture(0)]], |
| 34991 |
+ texturecube<float, access::write> dstMip1 [[texture(1)]], |
| 34992 |
+ texturecube<float, access::write> dstMip2 [[texture(2)]], |
| 34993 |
+ texturecube<float, access::write> dstMip3 [[texture(3)]], |
| 34994 |
+ texturecube<float, access::write> dstMip4 [[texture(4)]], |
| 34995 |
+ constant GenMipParams &options [[buffer(0)]]) |
| 34996 |
+{ |
| 34997 |
+ uint firstMipLevel = options.srcLevel + 1; |
| 34998 |
+ ushort2 mip1Size = |
| 34999 |
+ ushort2(srcTexture.get_width(firstMipLevel), srcTexture.get_height(firstMipLevel)); |
| 35000 |
+ bool validThread = gIndices.x < mip1Size.x && gIndices.y < mip1Size.y; |
| 35001 |
+ |
| 35002 |
+ constexpr sampler textureSampler(mag_filter::linear, min_filter::linear, mip_filter::linear); |
| 35003 |
+ |
| 35004 |
+ // ----- First mip level ------- |
| 35005 |
+ float4 mip1Texel; |
| 35006 |
+ if (validThread) |
| 35007 |
+ { |
| 35008 |
+ float2 texCoords = (float2(gIndices.xy) + float2(0.5, 0.5)) / float2(mip1Size); |
| 35009 |
+ mip1Texel = srcTexture.sample(textureSampler, cubeTexcoords(texCoords, int(gIndices.z)), |
| 35010 |
+ level(options.srcLevel)); |
| 35011 |
+ |
| 35012 |
+ // Write to texture |
| 35013 |
+ dstMip1.write(mip1Texel, gIndices.xy, gIndices.z); |
| 35014 |
+ } |
| 35015 |
+ else |
| 35016 |
+ { |
| 35017 |
+ // This will invalidate all subsequent checks |
| 35018 |
+ lIndex = 0xffffffff; |
| 35019 |
+ } |
| 35020 |
+ |
| 35021 |
+ if (options.numMipLevelsToGen == 1) |
| 35022 |
+ { |
| 35023 |
+ return; |
| 35024 |
+ } |
| 35025 |
+ |
| 35026 |
+ // Use struct of array style to avoid bank conflict. |
| 35027 |
+ threadgroup float sR[kThreadGroupXY]; |
| 35028 |
+ threadgroup float sG[kThreadGroupXY]; |
| 35029 |
+ threadgroup float sB[kThreadGroupXY]; |
| 35030 |
+ threadgroup float sA[kThreadGroupXY]; |
| 35031 |
+ |
| 35032 |
+ generateCubeOr2DArray2ndAndMoreMipmaps(lIndex, gIndices, srcTexture, dstMip2, dstMip3, dstMip4, |
| 35033 |
+ mip1Size, mip1Texel, sR, sG, sB, sA, options); |
| 35034 |
+} |
| 35035 |
+ |
| 35036 |
+kernel void generate2DArrayMipmaps(uint lIndex [[thread_index_in_threadgroup]], |
| 35037 |
+ ushort3 gIndices [[thread_position_in_grid]], |
| 35038 |
+ texture2d_array<float> srcTexture [[texture(0)]], |
| 35039 |
+ texture2d_array<float, access::write> dstMip1 [[texture(1)]], |
| 35040 |
+ texture2d_array<float, access::write> dstMip2 [[texture(2)]], |
| 35041 |
+ texture2d_array<float, access::write> dstMip3 [[texture(3)]], |
| 35042 |
+ texture2d_array<float, access::write> dstMip4 [[texture(4)]], |
| 35043 |
+ constant GenMipParams &options [[buffer(0)]]) |
| 35044 |
+{ |
| 35045 |
+ uint firstMipLevel = options.srcLevel + 1; |
| 35046 |
+ ushort2 mip1Size = |
| 35047 |
+ ushort2(srcTexture.get_width(firstMipLevel), srcTexture.get_height(firstMipLevel)); |
| 35048 |
+ bool validThread = gIndices.x < mip1Size.x && gIndices.y < mip1Size.y; |
| 35049 |
+ |
| 35050 |
+ constexpr sampler textureSampler(mag_filter::linear, min_filter::linear, mip_filter::linear); |
| 35051 |
+ |
| 35052 |
+ // ----- First mip level ------- |
| 35053 |
+ float4 mip1Texel; |
| 35054 |
+ if (validThread) |
| 35055 |
+ { |
| 35056 |
+ float2 texCoords = (float2(gIndices.xy) + float2(0.5, 0.5)) / float2(mip1Size); |
| 35057 |
+ mip1Texel = |
| 35058 |
+ srcTexture.sample(textureSampler, texCoords, gIndices.z, level(options.srcLevel)); |
| 35059 |
+ |
| 35060 |
+ // Write to texture |
| 35061 |
+ dstMip1.write(mip1Texel, gIndices.xy, gIndices.z); |
| 35062 |
+ } |
| 35063 |
+ else |
| 35064 |
+ { |
| 35065 |
+ // This will invalidate all subsequent checks |
| 35066 |
+ lIndex = 0xffffffff; |
| 35067 |
+ } |
| 35068 |
+ |
| 35069 |
+ if (options.numMipLevelsToGen == 1) |
| 35070 |
+ { |
| 35071 |
+ return; |
| 35072 |
+ } |
| 35073 |
+ |
| 35074 |
+ // Use struct of array style to avoid bank conflict. |
| 35075 |
+ threadgroup float sR[kThreadGroupXY]; |
| 35076 |
+ threadgroup float sG[kThreadGroupXY]; |
| 35077 |
+ threadgroup float sB[kThreadGroupXY]; |
| 35078 |
+ threadgroup float sA[kThreadGroupXY]; |
| 35079 |
+ |
| 35080 |
+ generateCubeOr2DArray2ndAndMoreMipmaps(lIndex, gIndices, srcTexture, dstMip2, dstMip3, dstMip4, |
| 35081 |
+ mip1Size, mip1Texel, sR, sG, sB, sA, options); |
| 35082 |
} |
| 35083 |
diff --git a/src/libANGLE/renderer/metal/shaders/visibility.metal b/src/libANGLE/renderer/metal/shaders/visibility.metal |
| 35084 |
index 905c196..ad5860f 100644 |
| 35085 |
--- a/src/libANGLE/renderer/metal/shaders/visibility.metal |
| 35086 |
+++ b/src/libANGLE/renderer/metal/shaders/visibility.metal |
| 35087 |
@@ -6,7 +6,7 @@ |
| 35088 |
|
| 35089 |
#include "common.h" |
| 35090 |
|
| 35091 |
-constant bool kCombineWithExistingResult [[function_constant(1000)]]; |
| 35092 |
+constant bool kCombineWithExistingResult [[function_constant(1)]]; |
| 35093 |
|
| 35094 |
// Combine the visibility result of current render pass with previous value from previous render |
| 35095 |
// pass |
| 35096 |
diff --git a/src/libGLESv2/entry_points_egl.cpp b/src/libGLESv2/entry_points_egl.cpp |
| 35097 |
index 755bd61..7d5ac58 100644 |
| 35098 |
--- a/src/libGLESv2/entry_points_egl.cpp |
| 35099 |
+++ b/src/libGLESv2/entry_points_egl.cpp |
| 35100 |
@@ -428,8 +428,6 @@ EGLBoolean EGLAPIENTRY EGL_DestroyContext(EGLDisplay dpy, EGLContext ctx) |
| 35101 |
|
| 35102 |
if (contextWasCurrent) |
| 35103 |
{ |
| 35104 |
- ANGLE_EGL_TRY_RETURN(thread, display->makeCurrent(context, nullptr, nullptr, nullptr), |
| 35105 |
- "eglDestroyContext", GetContextIfValid(display, context), EGL_FALSE); |
| 35106 |
SetContextCurrent(thread, nullptr); |
| 35107 |
} |
| 35108 |
|
| 35109 |
@@ -466,8 +464,8 @@ EGLBoolean EGLAPIENTRY EGL_MakeCurrent(EGLDisplay dpy, |
| 35110 |
// Only call makeCurrent if the context or surfaces have changed. |
| 35111 |
if (previousDraw != drawSurface || previousRead != readSurface || previousContext != context) |
| 35112 |
{ |
| 35113 |
- ANGLE_EGL_TRY_RETURN( |
| 35114 |
- thread, display->makeCurrent(previousContext, drawSurface, readSurface, context), |
| 35115 |
+ ANGLE_EGL_TRY_RETURN(thread, |
| 35116 |
+ display->makeCurrent(thread, drawSurface, readSurface, context), |
| 35117 |
"eglMakeCurrent", GetContextIfValid(display, context), EGL_FALSE); |
| 35118 |
|
| 35119 |
SetContextCurrent(thread, context); |
| 35120 |
@@ -818,8 +816,8 @@ EGLBoolean EGLAPIENTRY EGL_ReleaseThread(void) |
| 35121 |
if (previousDraw != EGL_NO_SURFACE || previousRead != EGL_NO_SURFACE || |
| 35122 |
previousContext != EGL_NO_CONTEXT) |
| 35123 |
{ |
| 35124 |
- ANGLE_EGL_TRY_RETURN( |
| 35125 |
- thread, previousDisplay->makeCurrent(previousContext, nullptr, nullptr, nullptr), |
| 35126 |
+ ANGLE_EGL_TRY_RETURN(thread, |
| 35127 |
+ previousDisplay->makeCurrent(thread, nullptr, nullptr, nullptr), |
| 35128 |
"eglReleaseThread", nullptr, EGL_FALSE); |
| 35129 |
} |
| 35130 |
ANGLE_EGL_TRY_RETURN(thread, previousDisplay->releaseThread(), "eglReleaseThread", |
| 35131 |
diff --git a/src/tests/deqp_support/deqp_egl_test_expectations.txt b/src/tests/deqp_support/deqp_egl_TestExpectations |
| 35132 |
similarity index 100% |
| 35133 |
rename from src/tests/deqp_support/deqp_egl_test_expectations.txt |
| 35134 |
rename to src/tests/deqp_support/deqp_egl_TestExpectations |
| 35135 |
diff --git a/src/tests/deqp_support/deqp_gles2_test_expectations.txt b/src/tests/deqp_support/deqp_gles2_TestExpectations |
| 35136 |
similarity index 100% |
| 35137 |
rename from src/tests/deqp_support/deqp_gles2_test_expectations.txt |
| 35138 |
rename to src/tests/deqp_support/deqp_gles2_TestExpectations |
| 35139 |
diff --git a/src/tests/deqp_support/deqp_gles31_test_expectations.txt b/src/tests/deqp_support/deqp_gles31_TestExpectations |
| 35140 |
similarity index 100% |
| 35141 |
rename from src/tests/deqp_support/deqp_gles31_test_expectations.txt |
| 35142 |
rename to src/tests/deqp_support/deqp_gles31_TestExpectations |
| 35143 |
diff --git a/src/tests/deqp_support/deqp_gles31_rotate_test_expectations.txt b/src/tests/deqp_support/deqp_gles31_rotate_TestExpectations |
| 35144 |
similarity index 100% |
| 35145 |
rename from src/tests/deqp_support/deqp_gles31_rotate_test_expectations.txt |
| 35146 |
rename to src/tests/deqp_support/deqp_gles31_rotate_TestExpectations |
| 35147 |
diff --git a/src/tests/deqp_support/deqp_gles3_test_expectations.txt b/src/tests/deqp_support/deqp_gles3_TestExpectations |
| 35148 |
similarity index 100% |
| 35149 |
rename from src/tests/deqp_support/deqp_gles3_test_expectations.txt |
| 35150 |
rename to src/tests/deqp_support/deqp_gles3_TestExpectations |
| 35151 |
diff --git a/src/tests/deqp_support/deqp_gles3_rotate_test_expectations.txt b/src/tests/deqp_support/deqp_gles3_rotate_TestExpectations |
| 35152 |
similarity index 100% |
| 35153 |
rename from src/tests/deqp_support/deqp_gles3_rotate_test_expectations.txt |
| 35154 |
rename to src/tests/deqp_support/deqp_gles3_rotate_TestExpectations |
| 35155 |
diff --git a/src/tests/deqp_support/deqp_khr_gles2_test_expectations.txt b/src/tests/deqp_support/deqp_khr_gles2_TestExpectations |
| 35156 |
similarity index 100% |
| 35157 |
rename from src/tests/deqp_support/deqp_khr_gles2_test_expectations.txt |
| 35158 |
rename to src/tests/deqp_support/deqp_khr_gles2_TestExpectations |
| 35159 |
diff --git a/src/tests/deqp_support/deqp_khr_gles31_test_expectations.txt b/src/tests/deqp_support/deqp_khr_gles31_TestExpectations |
| 35160 |
similarity index 100% |
| 35161 |
rename from src/tests/deqp_support/deqp_khr_gles31_test_expectations.txt |
| 35162 |
rename to src/tests/deqp_support/deqp_khr_gles31_TestExpectations |
| 35163 |
diff --git a/src/tests/deqp_support/deqp_khr_gles3_test_expectations.txt b/src/tests/deqp_support/deqp_khr_gles3_TestExpectations |
| 35164 |
similarity index 100% |
| 35165 |
rename from src/tests/deqp_support/deqp_khr_gles3_test_expectations.txt |
| 35166 |
rename to src/tests/deqp_support/deqp_khr_gles3_TestExpectations |