src/compiler/translator/msl/EmitMetal.cpp


Log

Author Commit Date CI Message
Shahbaz Youssefi f48fcb46 2025-06-19T07:11:48 Revert "Metal: Wraparound int arithmetic for add, sub" This reverts commit 2f6f0514563d81e439e04ba09eee9e8a1d6ca8d1. Reason for revert: Leads to MSL compiler errors: > error: non-const reference cannot bind to vector element Bug: angleproject:382215759 Original change's description: > Metal: Wraparound int arithmetic for add, sub > > Implement wraparound int arithmetic for > int, ivec +, -, +=, -=, ++, --. > > All of the added tests pass also without the changes. > > Bug: angleproject:382215759 > Change-Id: I7605582ab2931e63010c34fba474797f7edd19f9 > Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/6578729 > Auto-Submit: Kimmo Kinnunen <kkinnunen@apple.com> > Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> > Reviewed-by: Geoff Lang <geofflang@chromium.org> > Commit-Queue: Kimmo Kinnunen <kkinnunen@apple.com> Bug: angleproject:382215759 Bug: chromium:425746892 Change-Id: I831d96c6ee7b8bcdeaa08fbf32d430def87a3c30 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/6656001 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org>
Kimmo Kinnunen 94ee620d 2025-05-22T10:07:05 Metal: Allow optimization of simple loops Reimplement the feature to avoid undefined behavior of infinite loops. Add EnsureLoopForwardProgress rewrite pass that inserts a volatile variable access to all loops that it cannot analyze as being finite. Detect loops of form `for (; i <op> x; ++i)` as being finite. The <op> can be any of <,<=,>,>=,==, != operator. The i can be int or uint. The ++i can be -- or ++, -=1, +=1. This assumes that backends using the feature emit signed int arithmetic with defined wraparound semantics. Uses volatile write instead of asm("") due to asm not forcing the behavior in some compiler versions. The volatile variable access is defined in C++ as forward progress, and by inheritance this works in MSL. Later commits may remove injectAsmStatementIntoLoopBodies if ensureLoopForwardProgress is appropriate for all use-cases. Bug: angleproject:418918522 Change-Id: Ic9c29f57044b792195386483208632354d24c854 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/6575051 Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Auto-Submit: Kimmo Kinnunen <kkinnunen@apple.com> Reviewed-by: Geoff Lang <geofflang@chromium.org> Commit-Queue: Kimmo Kinnunen <kkinnunen@apple.com>
Kimmo Kinnunen 2f6f0514 2025-05-22T15:59:19 Metal: Wraparound int arithmetic for add, sub Implement wraparound int arithmetic for int, ivec +, -, +=, -=, ++, --. All of the added tests pass also without the changes. Bug: angleproject:382215759 Change-Id: I7605582ab2931e63010c34fba474797f7edd19f9 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/6578729 Auto-Submit: Kimmo Kinnunen <kkinnunen@apple.com> Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Geoff Lang <geofflang@chromium.org> Commit-Queue: Kimmo Kinnunen <kkinnunen@apple.com>
Kimmo Kinnunen 8e9dc1a6 2024-11-19T11:08:31 Validate anonymous struct names with namespace Consider GLSL: struct { vec4 e; } g; struct sbbf { vec4 f; }; The struct name validation would fail if user chosen struct name would clash with a symbol name that ANGLE internally gave to an anonymous struct. Fix by importing Name abstraction from MSL backend. A symbol name is a pair (namespace, string). Move operator<<(std::ostream &os, const ImmutableString &str) to sh namespace because that is more natural for operator overloading name resolution. MSVC works with this. Bug: angleproject:379758201 Change-Id: Icc9b02aa8cb532e1d925e2fba4c45468f01b9144 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/6035029 Reviewed-by: Geoff Lang <geofflang@chromium.org> Auto-Submit: Kimmo Kinnunen <kkinnunen@apple.com> Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Kimmo Kinnunen <kkinnunen@apple.com>
Alexey Knyazev 0f7371ae 2024-10-07T00:00:00 Metal: Remove ANGLE_tensor macro Its replacement is never used. Fixed: angleproject:372053408 Change-Id: I1d54efcc1a1ecac1d0c6dae5ff7524b501297fe0 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5912904 Reviewed-by: Kimmo Kinnunen <kkinnunen@apple.com> Reviewed-by: Geoff Lang <geofflang@chromium.org> Commit-Queue: Alexey Knyazev <lexa.knyazev@gmail.com>
Shahbaz Youssefi b16d105f 2024-10-03T10:25:32 Remove Desktop GL front-end support For Desktop GL applications, please use Zink! Bug: angleproject:370937467 Change-Id: Ie734634bb62a2e98c80e1b32d8b3d34624da3c04 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5905428 Reviewed-by: Geoff Lang <geofflang@chromium.org>
Alexey Knyazev 95664631 2024-09-19T00:00:00 Metal: Fix OES_texture_3D texture function wrappers * Removed redundant variadic macros and templates for GL_OES_texture_3D functions. * Added missing texture3D function variants. * Emit texture3DProj variant with bias only when the GLSL function call has that parameter. Fixed all failures in KHR-GLES2.texture_3d.* tests. Bug: angleproject:368059227 Change-Id: I9c0b209988563710824c38d0535997e351bbd6bd Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5875725 Reviewed-by: Geoff Lang <geofflang@chromium.org> Commit-Queue: Alexey Knyazev <lexa.knyazev@gmail.com>
Alexey Knyazev e6c22c93 2024-09-19T00:00:00 Metal: Remove invalid ESSL 1.00 texture functions * 1D textures are not supported in GLSL ES * 2D textures do not support sampling with 3-component coordinates * Metal backend does not support rectangle texture type * Cubemap textures do not support sampling with projection Bug: angleproject:368059227 Change-Id: Iec33f4293d995b9f244274338d444604ffd23249 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5872915 Reviewed-by: Geoff Lang <geofflang@chromium.org> Commit-Queue: Alexey Knyazev <lexa.knyazev@gmail.com>
Alexey Knyazev b7d4c5d1 2024-07-04T00:00:00 Metal: Disable fast math if isinf or isnan are used Fixed: angleproject:42266714 Fixed: angleproject:42267063 Change-Id: Ibf6508ffc7d458a6b91b9218b2b488b6aa5b1001 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5678416 Reviewed-by: Geoff Lang <geofflang@chromium.org> Commit-Queue: Alexey Knyazev <lexa.knyazev@gmail.com>
Shahbaz Youssefi d193d51b 2024-06-17T22:46:08 Replace issue ids post migration to new issue tracker This change replaces anglebug.com/NNNN links. Bug: None Change-Id: I8ac3aec8d2a8a844b3d7b99fc0a6b2be8da31761 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5637912 Reviewed-by: Geoff Lang <geofflang@chromium.org> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
Kimmo Kinnunen 18fa02be 2024-03-12T10:23:55 Rewrite exprs using separated decl variables Rewrite expressions that use the rewritten struct declaration variables. Declaration that specfies a struct and defines multiple variables will get its variable declarations separated. The type of the variable changes when a struct specifier is removed for the second and rest of the variable declarations. The type of the variable changes also when a anonymous struct is named. The expressions that used the separated variables used the old struct as their types. Fix by using TIntermRebuild. Upon creating a new symbol node referencing the new type, the rebuilder will instantiate also all the needed intermediate nodes, which then get the correct struct type. For consistency, fix the case of anonymous struct -> named struct transform naming the variables similar to named struct separation. Consider base case: struct S { .. } a, b; -> struct S { .. } a; S b; Compare against case: struct { .. } a, b; Before, inconsistency: struct s1 { .. }; s1 a; s1 b; After, fixed: struct s1 { .. } a; s1 b; Bug: angleproject:8590 Change-Id: Iffb0ef4441d6021e076b04485b808b26a7fa4dcb Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5365201 Auto-Submit: Kimmo Kinnunen <kkinnunen@apple.com> Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Kimmo Kinnunen <kkinnunen@apple.com> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
Kimmo Kinnunen 197beb4d 2024-02-13T15:47:32 Metal: Crash if for loop body is optimized away Loops might have their bodies optimized away. For case like `for(;;) if(false);` the constant pruning happens at parse phase. The else branch (e.e. no else branch, nullptr) would be selected as the body. Some code treated the body as optional, some code treated it as required. Define it as required, and remove all conditional code related to the loop body. Bug: angleproject:8532 Change-Id: Ic35f1bf78e63ceb2cee7b96ba99e788efc282e6f Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5291554 Auto-Submit: Kimmo Kinnunen <kkinnunen@apple.com> Commit-Queue: Kimmo Kinnunen <kkinnunen@apple.com> Reviewed-by: Kenneth Russell <kbr@chromium.org>
Geoff Lang 9318a143 2024-01-11T15:58:44 Add __asm__("") statements to loop bodies in MSL. This prevents erasure of infinite loops during optimization passes. Bug: chromium:1513738 Change-Id: I84a305b5e7fd824531d9e3ebae5496ddec030bac Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5191166 Commit-Queue: Geoff Lang <geofflang@chromium.org> Reviewed-by: Alexey Knyazev <lexa.knyazev@gmail.com>
Alexey Knyazev 7d30cf9f 2024-01-22T00:00:00 Metal: Simplify sign function translation Check whether a float or an integer variant is needed and emit only what is necessary. Fixed: angleproject:8502 Change-Id: I7061a5faa7cf09519b30e64ff90c42bbe392908a Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5234350 Reviewed-by: Kenneth Russell <kbr@chromium.org> Commit-Queue: Alexey Knyazev <lexa.knyazev@gmail.com>
Alexey Knyazev 2431d4df 2024-01-18T00:00:00 Metal: Skip array index clamp for constant values Do not wrap constant array indices with ANGLE_int_clamp when their values could be statically validated. Fixed: angleproject:8488 Change-Id: I3ad183475e1847cb7db1a07df3598c7d39767d7e Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5220233 Reviewed-by: Geoff Lang <geofflang@chromium.org> Commit-Queue: Alexey Knyazev <lexa.knyazev@gmail.com> Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org>
Alexey Knyazev fc742305 2024-01-18T00:00:00 Metal: Simplify geometry functions translation Check whether a vector or a scalar variant is needed and emit only what is necessary. Reduced the generated MSL for: - atan/atan2 - length - distance - dot - normalize - faceforward - reflect - refract Fixed: angleproject:8487 Fixed: angleproject:8489 Change-Id: I3be39e55997062136aae2782269a65c0c738d6cf Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5217532 Reviewed-by: Geoff Lang <geofflang@chromium.org> Reviewed-by: Kenneth Russell <kbr@chromium.org> Commit-Queue: Alexey Knyazev <lexa.knyazev@gmail.com>
Alexey Knyazev a6b9a744 2023-12-21T00:00:00 Metal: Implement vertex attribute aliasing When vertex attribute aliasing is supported, the external vertex input struct is filled post-link to account for potentially aliased attributes. Fixed the following tests: dEQP-GLES2.functional.attribute_location.bind_aliasing .cond_float .cond_vec2 .cond_vec3 .cond_vec4 .cond_mat2 .cond_mat2_offset_1 .cond_mat3 .cond_mat3_offset_1 .cond_mat4 .cond_mat4_offset_1 dEQP-GLES3.functional.attribute_location.bind_aliasing .cond_float .cond_vec2 .cond_vec3 .cond_vec4 .cond_mat2 .cond_mat2_offset_1 .cond_mat3 .cond_mat3_offset_1 .cond_mat4 .cond_mat4_offset_1 .max_cond_float .max_cond_vec2 .max_cond_vec3 .max_cond_vec4 .max_cond_mat2 .max_cond_mat3 .max_cond_mat4 Fixed: angleproject:6297 Change-Id: Ifa6b82e0d7d4e12115ec19e342cfb82ab4389f5a Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5148210 Reviewed-by: Kenneth Russell <kbr@chromium.org> Commit-Queue: Alexey Knyazev <lexa.knyazev@gmail.com>
Alexey Knyazev e172c104 2023-12-07T00:00:00 Metal: Fix temporary array initialization Ensure that temporary array declarations have literal initializers to bypass Metal compiler issues. Fixed the following tests on Apple silicon: dEQP-GLES2.functional.shaders.indexing.tmp_array .float_const_write_dynamic_loop_read_fragment .float_const_write_dynamic_loop_read_vertex .float_const_write_dynamic_read_fragment .float_const_write_dynamic_read_vertex Fixed: angleproject:7058 Change-Id: Id4a360b0a5a15da43ce4626c6dfe03556cc9d0f0 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5115898 Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
Alexey Knyazev 6d9f0aee 2023-11-30T00:00:00 Metal: Ensure helper invocations when derivatives are used Set sample coverage mask to ensure that fragment shader helper invocations are performed when derivatives are used. Fixed the following tests on Apple silicon: dEQP-GLES2.functional.texture.mipmap .2d.projected.nearest_linear_repeat .2d.projected.linear_linear_repeat .cube.projected.linear_nearest .cube.projected.linear_linear dEQP-GLES3.functional.texture.mipmap .2d.projected.nearest_nearest_mirror .2d.projected.linear_nearest_clamp .2d.projected.linear_nearest_repeat .2d.projected.linear_nearest_mirror .2d.projected.nearest_linear_repeat .2d.projected.linear_linear_clamp .2d.projected.linear_linear_repeat .3d.projected.nearest_nearest_mirror .3d.projected.linear_nearest_clamp .3d.projected.linear_nearest_repeat .3d.projected.nearest_linear_clamp .3d.projected.nearest_linear_mirror .3d.projected.linear_linear_clamp .3d.projected.linear_linear_repeat Fixed: angleproject:8443 Fixed: angleproject:7023 Change-Id: I13fc52532b94de098dcf3e9f5f02d48a6c8913c7 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5089131 Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Geoff Lang <geofflang@chromium.org> Commit-Queue: Alexey Knyazev <lexa.knyazev@gmail.com>
Alexey Knyazev 5d70a41c 2023-11-30T00:00:00 Metal: Use a separate struct for last fragment data Used a separate MSL struct type for reading from framebuffer attachments to not fetch unnecessary draw buffers and to be able to set a sample mask. Removed TranslatorMSL::isSampleMaskAllowed() Ensured that the lastFragmentOut variable is not added when PLS does not use framebuffer fetch. Fixed: angleproject:8442 Change-Id: Ia3320fc6063277479b5aa9b7fea34457465add75 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5079450 Reviewed-by: Geoff Lang <geofflang@chromium.org> Commit-Queue: Alexey Knyazev <lexa.knyazev@gmail.com>
Alexey Knyazev d696b40f 2023-11-23T00:00:00 Metal: Use precise tanh for highp result types When fast math is enabled, default tanh does not pass dEQP precision tests. Explicitly request precise tanh when the result type has high precision. Bug: angleproject:8287 Change-Id: I07c8c2638b5f0a51feacbeadb78382152a95b03c Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5057298 Reviewed-by: Geoff Lang <geofflang@chromium.org> Commit-Queue: Alexey Knyazev <lexa.knyazev@gmail.com>
Geoff Lang f441e3ee 2023-11-01T15:22:55 Metal: Fix missing mix(float,float,bool) overload ANGLE has an ANGLE_mix_bool overload when the last parameter is a bool but it is not needed when the other parameters are scalar. Bug: chromium:1493243 Change-Id: I6ea904ed63055b49cf3eaded475eafa607ca5976 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/4995278 Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Geoff Lang <geofflang@chromium.org>
Alexey Knyazev 777a46bf 2023-09-29T00:00:00 Metal: Fix power function translation GLSL definition of pow(x, y) excludes negative x, so it must be translated to metal::powr, not metal::pow. Fixed: angleproject:8366 Change-Id: Idaa66da73a149119e2a74beddc9a49e187d3e7af Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/4901995 Commit-Queue: Alexey Knyazev <lexa.knyazev@gmail.com> Reviewed-by: Kenneth Russell <kbr@chromium.org>
Kenneth Russell 8ba04f1c 2023-08-05T00:48:35 Metal: disable fastmath less often. Stop disabling fastmath if atan is used in the shader. Application developers will surely prefer the significant performance improvement of the fastmath optimizations over corner-case differences in precision. Make disabling fastmath more precise: only if it's forcibly disabled as a driver bug workaround, or if the shader uses invariance and preserveInvariance is not available. Suppress the test: dEQP-GLES[23].functional.shaders.invariance.lowp.loop_2 which fails when fastmath is enabled for shaders using atan and invariance. Fixed: chromium:1320111 Change-Id: I6e33b14b1d05faedc15373f24af3e22a4074a35b Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/4754018 Reviewed-by: Geoff Lang <geofflang@chromium.org> Auto-Submit: Kenneth Russell <kbr@chromium.org> Commit-Queue: Geoff Lang <geofflang@chromium.org>
Shahbaz Youssefi 9b63700b 2023-07-11T10:25:40 Translator: Reorganize files This change makes the translator files more organized by: - Grouping files that are specific to a certain output under their own directory, - Moving transformations under tree_ops - Removing Direct from metal translation now that that SPIR-V Cross path is removed Bug: angleproject:6394 Change-Id: Iaf5bb8d5604b84748dece029821b1f77b2813967 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/4678780 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Geoff Lang <geofflang@chromium.org>