mirror of
https://git.triforceproject.com/triforce/source
synced 2026-11-19 16:20:01 -04:00
Triforce v0.2.0
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
117
gpu/third_party/suyu/GPL-2.0-or-later.txt
vendored
Normal file
117
gpu/third_party/suyu/GPL-2.0-or-later.txt
vendored
Normal file
@@ -0,0 +1,117 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
|
||||
Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and modification follow.
|
||||
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
one line to give the program's name and an idea of what it does. Copyright (C) yyyy name of author
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
signature of Ty Coon, 1 April 1989 Ty Coon, President of Vice
|
||||
232
gpu/third_party/suyu/GPL-3.0-or-later.txt
vendored
Normal file
232
gpu/third_party/suyu/GPL-3.0-or-later.txt
vendored
Normal file
@@ -0,0 +1,232 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright © 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
|
||||
Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
“This License” refers to version 3 of the GNU General Public License.
|
||||
|
||||
“Copyright” also means copyright-like laws that apply to other kinds of works, such as semiconductor masks.
|
||||
|
||||
“The Program” refers to any copyrightable work licensed under this License. Each licensee is addressed as “you”. “Licensees” and “recipients” may be individuals or organizations.
|
||||
|
||||
To “modify” a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a “modified version” of the earlier work or a work “based on” the earlier work.
|
||||
|
||||
A “covered work” means either the unmodified Program or a work based on the Program.
|
||||
|
||||
To “propagate” a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well.
|
||||
|
||||
To “convey” a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays “Appropriate Legal Notices” to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
The “source code” for a work means the preferred form of the work for making modifications to it. “Object code” means any non-source form of a work.
|
||||
|
||||
A “Standard Interface” means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language.
|
||||
|
||||
The “System Libraries” of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A “Major Component”, in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The “Corresponding Source” for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to “keep intact all notices”.
|
||||
|
||||
c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an “aggregate” if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work.
|
||||
|
||||
A “User Product” is either (1) a “consumer product”, which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, “normally used” refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product.
|
||||
|
||||
“Installation Information” for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
“Additional permissions” are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered “further restrictions” within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License.
|
||||
|
||||
An “entity transaction” is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
A “contributor” is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's “contributor version”.
|
||||
|
||||
A contributor's “essential patent claims” are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, “control” includes the right to grant patent sublicenses in a manner consistent with the requirements of this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a “patent license” is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To “grant” such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. “Knowingly relying” means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it.
|
||||
|
||||
A patent license is “discriminatory” if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License “or any later version” applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the “copyright” line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an “about box”.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school, if any, to sign a “copyright disclaimer” for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read <http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
||||
120
gpu/third_party/suyu/common/alignment.h
vendored
Normal file
120
gpu/third_party/suyu/common/alignment.h
vendored
Normal file
@@ -0,0 +1,120 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2026 suyu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: 2014 Jannik Vogel <email@jannikvogel.de>
|
||||
// SPDX-License-Identifier: CC0-1.0
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <bit>
|
||||
#include <cstddef>
|
||||
#include <new>
|
||||
#include <type_traits>
|
||||
|
||||
namespace Common {
|
||||
|
||||
template <typename T>
|
||||
requires std::is_integral_v<T>
|
||||
[[nodiscard]] constexpr T AlignUp(T value_, size_t size) {
|
||||
using U = typename std::make_unsigned_t<T>;
|
||||
auto value{static_cast<U>(value_)};
|
||||
auto mod{static_cast<T>(value % size)};
|
||||
value -= mod;
|
||||
return static_cast<T>(mod == T{0} ? value : value + size);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
requires std::is_unsigned_v<T>
|
||||
[[nodiscard]] constexpr T AlignUpLog2(T value, size_t align_log2) {
|
||||
return static_cast<T>((value + ((1ULL << align_log2) - 1)) >> align_log2 << align_log2);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
requires std::is_integral_v<T>
|
||||
[[nodiscard]] constexpr T AlignDown(T value_, size_t size) {
|
||||
using U = typename std::make_unsigned_t<T>;
|
||||
const auto value{static_cast<U>(value_)};
|
||||
return static_cast<T>(value - value % size);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
requires std::is_unsigned_v<T>
|
||||
[[nodiscard]] constexpr bool IsWordAligned(T value) {
|
||||
return (value & 0b11) == 0;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
requires std::is_integral_v<T>
|
||||
[[nodiscard]] constexpr bool IsAligned(T value, size_t alignment) noexcept {
|
||||
using U = typename std::make_unsigned_t<T>;
|
||||
const U mask = U(alignment - 1);
|
||||
return (value & mask) == 0;
|
||||
}
|
||||
|
||||
template <typename T, typename U>
|
||||
requires std::is_integral_v<T>
|
||||
[[nodiscard]] constexpr T DivideUp(T x, U y) {
|
||||
return (x + (y - 1)) / y;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
requires std::is_integral_v<T>
|
||||
[[nodiscard]] constexpr T LeastSignificantOneBit(T x) {
|
||||
return x & ~(x - 1);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
requires std::is_integral_v<T>
|
||||
[[nodiscard]] constexpr T ResetLeastSignificantOneBit(T x) {
|
||||
return x & (x - 1);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
requires std::is_integral_v<T>
|
||||
[[nodiscard]] constexpr bool IsPowerOfTwo(T x) {
|
||||
return x > 0 && ResetLeastSignificantOneBit(x) == 0;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
requires std::is_integral_v<T>
|
||||
[[nodiscard]] constexpr T FloorPowerOfTwo(T x) {
|
||||
return T{1} << (sizeof(T) * 8 - std::countl_zero(x) - 1);
|
||||
}
|
||||
|
||||
template <typename T, size_t Align = 16>
|
||||
class AlignmentAllocator {
|
||||
public:
|
||||
using value_type = T;
|
||||
using size_type = size_t;
|
||||
using difference_type = ptrdiff_t;
|
||||
|
||||
using propagate_on_container_copy_assignment = std::true_type;
|
||||
using propagate_on_container_move_assignment = std::true_type;
|
||||
using propagate_on_container_swap = std::true_type;
|
||||
using is_always_equal = std::false_type;
|
||||
|
||||
constexpr AlignmentAllocator() noexcept = default;
|
||||
|
||||
template <typename T2>
|
||||
constexpr AlignmentAllocator(const AlignmentAllocator<T2, Align>&) noexcept {}
|
||||
|
||||
[[nodiscard]] T* allocate(size_type n) {
|
||||
return static_cast<T*>(::operator new(n * sizeof(T), std::align_val_t{Align}));
|
||||
}
|
||||
|
||||
void deallocate(T* p, size_type n) {
|
||||
::operator delete(p, n * sizeof(T), std::align_val_t{Align});
|
||||
}
|
||||
|
||||
template <typename T2>
|
||||
struct rebind {
|
||||
using other = AlignmentAllocator<T2, Align>;
|
||||
};
|
||||
|
||||
template <typename T2, size_t Align2>
|
||||
constexpr bool operator==(const AlignmentAllocator<T2, Align2>&) const noexcept {
|
||||
return std::is_same_v<T, T2> && Align == Align2;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace Common
|
||||
40
gpu/third_party/suyu/common/assert.h
vendored
Normal file
40
gpu/third_party/suyu/common/assert.h
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
// Rexcomp replacement for suyu's common/assert.h: same macros; a failed assertion prints and carries on, as suyu's
|
||||
// soft asserts do in release builds.
|
||||
#pragma once
|
||||
#include <cstdio>
|
||||
|
||||
namespace Common {
|
||||
inline void AssertFail(const char* file, int line, const char* what) {
|
||||
std::fprintf(stderr, "[shader] assertion failed at %s:%d: %s\n", file, line, what);
|
||||
}
|
||||
} // namespace Common
|
||||
|
||||
// each assertion reports its first 3 failures
|
||||
#define ASSERT_MSG(_a_, ...) \
|
||||
do { \
|
||||
if (!(_a_)) [[unlikely]] { \
|
||||
static int assert_reports_; \
|
||||
if (assert_reports_++ < 3) ::Common::AssertFail(__FILE__, __LINE__, #_a_); \
|
||||
} \
|
||||
} while (0)
|
||||
#define ASSERT(_a_) ASSERT_MSG(_a_, "")
|
||||
#define UNREACHABLE_MSG(...) \
|
||||
do { \
|
||||
::Common::AssertFail(__FILE__, __LINE__, "unreachable"); \
|
||||
__builtin_unreachable(); \
|
||||
} while (0)
|
||||
#define UNREACHABLE() UNREACHABLE_MSG("")
|
||||
#define DEBUG_ASSERT(_a_) ((void)0)
|
||||
#define DEBUG_ASSERT_MSG(_a_, ...) ((void)0)
|
||||
#define UNIMPLEMENTED() ASSERT(false && "Unimplemented!")
|
||||
#define UNIMPLEMENTED_MSG(...) ASSERT_MSG(false, __VA_ARGS__)
|
||||
#define UNIMPLEMENTED_IF(cond) ASSERT((!(cond)) && "Unimplemented!")
|
||||
#define UNIMPLEMENTED_IF_MSG(cond, ...) ASSERT_MSG(!(cond), __VA_ARGS__)
|
||||
#define ASSERT_OR_EXECUTE(_a_, _b_) \
|
||||
do { \
|
||||
ASSERT(_a_); \
|
||||
if (!(_a_)) [[unlikely]] { \
|
||||
_b_ \
|
||||
} \
|
||||
} while (0)
|
||||
#define ASSERT_OR_EXECUTE_MSG(_a_, _b_, ...) ASSERT_OR_EXECUTE(_a_, _b_)
|
||||
175
gpu/third_party/suyu/common/bit_field.h
vendored
Normal file
175
gpu/third_party/suyu/common/bit_field.h
vendored
Normal file
@@ -0,0 +1,175 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2026 suyu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: 2014 Tony Wasserka
|
||||
// SPDX-FileCopyrightText: 2014 Dolphin Emulator Project
|
||||
// SPDX-License-Identifier: BSD-3-Clause AND GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <limits>
|
||||
#include <type_traits>
|
||||
#include <climits>
|
||||
#include "common/swap.h"
|
||||
|
||||
/*
|
||||
* Abstract bitfield class
|
||||
*
|
||||
* Allows endianness-independent access to individual bitfields within some raw
|
||||
* integer value. The assembly generated by this class is identical to the
|
||||
* usage of raw bitfields, so it's a perfectly fine replacement.
|
||||
*
|
||||
* For BitField<X,Y,Z>, X is the distance of the bitfield to the LSB of the
|
||||
* raw value, Y is the length in bits of the bitfield. Z is an integer type
|
||||
* which determines the sign of the bitfield. Z must have the same size as the
|
||||
* raw integer.
|
||||
*
|
||||
*
|
||||
* General usage:
|
||||
*
|
||||
* Create a new union with the raw integer value as a member.
|
||||
* Then for each bitfield you want to expose, add a BitField member
|
||||
* in the union. The template parameters are the bit offset and the number
|
||||
* of desired bits.
|
||||
*
|
||||
* Changes in the bitfield members will then get reflected in the raw integer
|
||||
* value and vice-versa.
|
||||
*
|
||||
*
|
||||
* Sample usage:
|
||||
*
|
||||
* union SomeRegister
|
||||
* {
|
||||
* u32 hex;
|
||||
*
|
||||
* BitField<0,7,u32> first_seven_bits; // unsigned
|
||||
* BitField<7,8,u32> next_eight_bits; // unsigned
|
||||
* BitField<3,15,s32> some_signed_fields; // signed
|
||||
* };
|
||||
*
|
||||
* This is equivalent to the little-endian specific code:
|
||||
*
|
||||
* union SomeRegister
|
||||
* {
|
||||
* u32 hex;
|
||||
*
|
||||
* struct
|
||||
* {
|
||||
* u32 first_seven_bits : 7;
|
||||
* u32 next_eight_bits : 8;
|
||||
* };
|
||||
* struct
|
||||
* {
|
||||
* u32 : 3; // padding
|
||||
* s32 some_signed_fields : 15;
|
||||
* };
|
||||
* };
|
||||
*
|
||||
*
|
||||
* Caveats:
|
||||
*
|
||||
* 1)
|
||||
* BitField provides automatic casting from and to the storage type where
|
||||
* appropriate. However, when using non-typesafe functions like printf, an
|
||||
* explicit cast must be performed on the BitField object to make sure it gets
|
||||
* passed correctly, e.g.:
|
||||
* printf("Value: %d", (s32)some_register.some_signed_fields);
|
||||
*
|
||||
* 2)
|
||||
* Not really a caveat, but potentially irritating: This class is used in some
|
||||
* packed structures that do not guarantee proper alignment. Therefore we have
|
||||
* to use #pragma pack here not to pack the members of the class, but instead
|
||||
* to break GCC's assumption that the members of the class are aligned on
|
||||
* sizeof(StorageType).
|
||||
* TODO(neobrain): Confirm that this is a proper fix and not just masking
|
||||
* symptoms.
|
||||
*/
|
||||
#pragma pack(1)
|
||||
template <std::size_t Position, std::size_t Bits, typename T, typename EndianTag = LETag>
|
||||
requires std::is_trivially_copyable_v<T>
|
||||
struct BitField {
|
||||
private:
|
||||
// UnderlyingType is T for non-enum types and the underlying type of T if
|
||||
// T is an enumeration. Note that T is wrapped within an enable_if in the
|
||||
// former case to workaround compile errors which arise when using
|
||||
// std::underlying_type<T>::type directly.
|
||||
using UnderlyingType = typename std::conditional_t<std::is_enum_v<T>, std::underlying_type<T>, std::enable_if<true, T>>::type;
|
||||
// We store the value as the unsigned type to avoid undefined behaviour on value shifting
|
||||
using StorageType = std::make_unsigned_t<UnderlyingType>;
|
||||
using StorageTypeWithEndian = typename AddEndian<StorageType, EndianTag>::type;
|
||||
public:
|
||||
/// Constants to allow limited introspection of fields if needed
|
||||
static constexpr std::size_t position = Position;
|
||||
static constexpr std::size_t bits = Bits;
|
||||
static constexpr StorageType mask = (StorageType(~0) >> (CHAR_BIT * sizeof(T) - bits)) << position;
|
||||
|
||||
/**
|
||||
* Formats a value by masking and shifting it according to the field parameters. A value
|
||||
* containing several bitfields can be assembled by formatting each of their values and ORing
|
||||
* the results together.
|
||||
*/
|
||||
[[nodiscard]] static constexpr StorageType FormatValue(const T& value) {
|
||||
return (StorageType(value) << position) & mask;
|
||||
}
|
||||
|
||||
/// @brief Extracts a value from the passed storage. In most situations prefer use the member functions
|
||||
/// (such as Value() or operator T), but this can be used to extract a value from a bitfield
|
||||
/// union in a constexpr context.
|
||||
[[nodiscard]] static constexpr T ExtractValue(const StorageType& storage) {
|
||||
if constexpr (std::numeric_limits<UnderlyingType>::is_signed) {
|
||||
std::size_t shift = CHAR_BIT * sizeof(T) - bits;
|
||||
return T(UnderlyingType(storage << (shift - position)) >> shift);
|
||||
} else {
|
||||
return T((storage & mask) >> position);
|
||||
}
|
||||
}
|
||||
|
||||
// This constructor and assignment operator might be considered ambiguous:
|
||||
// Would they initialize the storage or just the bitfield?
|
||||
// Hence, delete them. Use the Assign method to set bitfield values!
|
||||
BitField(T val) = delete;
|
||||
BitField& operator=(T val) = delete;
|
||||
|
||||
constexpr BitField() noexcept = default;
|
||||
|
||||
constexpr BitField(const BitField&) noexcept = default;
|
||||
constexpr BitField& operator=(const BitField&) noexcept = default;
|
||||
|
||||
constexpr BitField(BitField&&) noexcept = default;
|
||||
constexpr BitField& operator=(BitField&&) noexcept = default;
|
||||
|
||||
constexpr void Assign(const T value) {
|
||||
storage = StorageType((storage & ~mask) | FormatValue(value));
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr T Value() const {
|
||||
return ExtractValue(storage);
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr operator T() const {
|
||||
return Value();
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr explicit operator bool() const {
|
||||
return Value() != 0;
|
||||
}
|
||||
|
||||
private:
|
||||
StorageTypeWithEndian storage;
|
||||
|
||||
static_assert(bits + position <= CHAR_BIT * sizeof(T), "Bitfield out of range");
|
||||
// And, you know, just in case people specify something stupid like bits=position=0x80000000
|
||||
static_assert(position < CHAR_BIT * sizeof(T), "Invalid position");
|
||||
static_assert(bits <= CHAR_BIT * sizeof(T), "Invalid number of bits");
|
||||
static_assert(bits > 0, "Invalid number of bits");
|
||||
};
|
||||
#pragma pack()
|
||||
|
||||
template <std::size_t Position, std::size_t Bits, typename T>
|
||||
using BitFieldBE = BitField<Position, Bits, T, BETag>;
|
||||
|
||||
template <std::size_t Position, std::size_t Bits, typename T, typename EndianTag = LETag>
|
||||
inline auto format_as(BitField<Position, Bits, T, EndianTag> bitfield) {
|
||||
return bitfield.Value();
|
||||
}
|
||||
57
gpu/third_party/suyu/common/bit_util.h
vendored
Normal file
57
gpu/third_party/suyu/common/bit_util.h
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2026 suyu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <bit>
|
||||
#include <climits>
|
||||
#include <cstddef>
|
||||
#include <type_traits>
|
||||
|
||||
#include "common/common_types.h"
|
||||
|
||||
namespace Common {
|
||||
|
||||
/// Gets the size of a specified type T in bits.
|
||||
template <typename T>
|
||||
requires std::is_integral_v<T>
|
||||
[[nodiscard]] constexpr std::size_t BitSize() {
|
||||
return std::size_t(sizeof(T) * CHAR_BIT);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
requires std::is_integral_v<T>
|
||||
[[nodiscard]] constexpr u32 MostSignificantBit(const T value) {
|
||||
return u32(sizeof(T) * CHAR_BIT - 1 - std::countl_zero(value));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
requires std::is_integral_v<T>
|
||||
[[nodiscard]] constexpr T Log2Floor(const T value) {
|
||||
return T(MostSignificantBit<T>(value));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
requires std::is_integral_v<T>
|
||||
[[nodiscard]] constexpr T Log2Ceil(const T value) {
|
||||
const T log2_f = Log2Floor<T>(value);
|
||||
return T(log2_f + T((value ^ (T(1ULL) << log2_f)) != T(0ULL)));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
requires std::is_integral_v<T>
|
||||
[[nodiscard]] T NextPow2(T value) {
|
||||
return T(1ULL << (sizeof(T) * CHAR_BIT - std::countl_zero(value - 1U)));
|
||||
}
|
||||
|
||||
template <size_t bit_index, typename T>
|
||||
requires std::is_integral_v<T>
|
||||
[[nodiscard]] constexpr bool Bit(const T value) {
|
||||
static_assert(bit_index < BitSize<T>(), "bit_index must be smaller than size of T");
|
||||
return ((value >> bit_index) & T(1)) == T(1);
|
||||
}
|
||||
|
||||
} // namespace Common
|
||||
111
gpu/third_party/suyu/common/common_funcs.h
vendored
Normal file
111
gpu/third_party/suyu/common/common_funcs.h
vendored
Normal file
@@ -0,0 +1,111 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2026 suyu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2019 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <iterator>
|
||||
#include <utility>
|
||||
#include <cstdlib> // for exit
|
||||
#include "common/common_types.h"
|
||||
|
||||
#ifndef __cpp_lib_to_underlying
|
||||
namespace std {
|
||||
// https://en.cppreference.com/cpp/utility/to_underlying
|
||||
template<class T>
|
||||
requires std::is_enum_v<T>
|
||||
constexpr std::underlying_type_t<T> to_underlying(T e) noexcept {
|
||||
return std::underlying_type_t<T>(e);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/// Textually concatenates two tokens. The double-expansion is required by the C preprocessor.
|
||||
#define CONCAT2(x, y) DO_CONCAT2(x, y)
|
||||
#define DO_CONCAT2(x, y) x##y
|
||||
|
||||
/// Helper macros to insert unused bytes or words to properly align structs. These values will be
|
||||
/// zero-initialized.
|
||||
#define INSERT_PADDING_BYTES(num_bytes) \
|
||||
[[maybe_unused]] std::array<u8, num_bytes> CONCAT2(pad, __LINE__) {}
|
||||
#define INSERT_PADDING_WORDS(num_words) \
|
||||
[[maybe_unused]] std::array<u32, num_words> CONCAT2(pad, __LINE__) {}
|
||||
|
||||
/// These are similar to the INSERT_PADDING_* macros but do not zero-initialize the contents.
|
||||
/// This keeps the structure trivial to construct.
|
||||
#define INSERT_PADDING_BYTES_NOINIT(num_bytes) \
|
||||
[[maybe_unused]] std::array<u8, num_bytes> CONCAT2(pad, __LINE__)
|
||||
#define INSERT_PADDING_WORDS_NOINIT(num_words) \
|
||||
[[maybe_unused]] std::array<u32, num_words> CONCAT2(pad, __LINE__)
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# define locale_t _locale_t // Locale Cross-Compatibility
|
||||
#endif // _MSC_VER
|
||||
|
||||
#define DECLARE_ENUM_FLAG_OPERATORS(type) \
|
||||
[[nodiscard]] constexpr type operator|(type a, type b) noexcept { \
|
||||
return type(std::to_underlying(a) | std::to_underlying(b)); \
|
||||
} \
|
||||
[[nodiscard]] constexpr type operator&(type a, type b) noexcept { \
|
||||
return type(std::to_underlying(a) & std::to_underlying(b)); \
|
||||
} \
|
||||
[[nodiscard]] constexpr type operator^(type a, type b) noexcept { \
|
||||
return type(std::to_underlying(a) ^ std::to_underlying(b)); \
|
||||
} \
|
||||
[[nodiscard]] constexpr type operator<<(type a, type b) noexcept { \
|
||||
return type(std::to_underlying(a) << std::to_underlying(b)); \
|
||||
} \
|
||||
[[nodiscard]] constexpr type operator>>(type a, type b) noexcept { \
|
||||
return type(std::to_underlying(a) >> std::to_underlying(b)); \
|
||||
} \
|
||||
constexpr type operator|=(type& a, type b) noexcept { \
|
||||
return a = a | b; \
|
||||
} \
|
||||
constexpr type operator&=(type& a, type b) noexcept { \
|
||||
return a = a & b; \
|
||||
} \
|
||||
constexpr type operator^=(type& a, type b) noexcept { \
|
||||
return a = a ^ b; \
|
||||
} \
|
||||
constexpr type operator<<=(type& a, type b) noexcept { \
|
||||
return a = a << b; \
|
||||
} \
|
||||
constexpr type operator>>=(type& a, type b) noexcept { \
|
||||
return a = a >> b; \
|
||||
} \
|
||||
[[nodiscard]] constexpr type operator~(type key) noexcept { \
|
||||
return type(~std::to_underlying(key)); \
|
||||
} \
|
||||
[[nodiscard]] constexpr bool True(type key) noexcept { \
|
||||
return std::to_underlying(key) != 0; \
|
||||
} \
|
||||
[[nodiscard]] constexpr bool False(type key) noexcept { \
|
||||
return std::to_underlying(key) == 0; \
|
||||
}
|
||||
|
||||
#define YUZU_NON_COPYABLE(cls) \
|
||||
cls(const cls&) = delete; \
|
||||
cls& operator=(const cls&) = delete
|
||||
|
||||
#define YUZU_NON_MOVEABLE(cls) \
|
||||
cls(cls&&) = delete; \
|
||||
cls& operator=(cls&&) = delete
|
||||
|
||||
// suyu-branded aliases
|
||||
#define SUYU_NON_COPYABLE(cls) YUZU_NON_COPYABLE(cls)
|
||||
#define SUYU_NON_MOVEABLE(cls) YUZU_NON_MOVEABLE(cls)
|
||||
|
||||
namespace Common {
|
||||
|
||||
[[nodiscard]] constexpr u32 MakeMagic(char a, char b, char c, char d) {
|
||||
return u32(a) | u32(b) << 8 | u32(c) << 16 | u32(d) << 24;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr u64 MakeMagic(char a, char b, char c, char d, char e, char f, char g, char h) {
|
||||
return u64(a) << 0 | u64(b) << 8 | u64(c) << 16 | u64(d) << 24 | u64(e) << 32 | u64(f) << 40 | u64(g) << 48 | u64(h) << 56;
|
||||
}
|
||||
|
||||
} // namespace Common
|
||||
14
gpu/third_party/suyu/common/common_precompiled_headers.h
vendored
Normal file
14
gpu/third_party/suyu/common/common_precompiled_headers.h
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
// SPDX-FileCopyrightText: 2022 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <chrono>
|
||||
#include <memory>
|
||||
|
||||
#include <fmt/format.h>
|
||||
|
||||
#include "common/assert.h"
|
||||
#include "common/common_types.h"
|
||||
56
gpu/third_party/suyu/common/common_types.h
vendored
Normal file
56
gpu/third_party/suyu/common/common_types.h
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2025 suyu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: 2012 Gekko Emulator
|
||||
// SPDX-FileContributor: ShizZy <shizzy247@gmail.com>
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
/**
|
||||
* Copyright (C) 2005-2012 Gekko Emulator
|
||||
*
|
||||
* @file common_types.h
|
||||
* @author ShizZy <shizzy247@gmail.com>
|
||||
* @date 2012-02-11
|
||||
* @brief Common types used throughout the project
|
||||
*
|
||||
* @section LICENSE
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details at
|
||||
* http://www.gnu.org/copyleft/gpl.html
|
||||
*
|
||||
* Official project repository can be found at:
|
||||
* http://code.google.com/p/gekko-gc-emu/
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
|
||||
using u8 = std::uint8_t; ///< 8-bit unsigned byte
|
||||
using u16 = std::uint16_t; ///< 16-bit unsigned short
|
||||
using u32 = std::uint32_t; ///< 32-bit unsigned word
|
||||
using u64 = std::uint64_t; ///< 64-bit unsigned int
|
||||
|
||||
using s8 = std::int8_t; ///< 8-bit signed byte
|
||||
using s16 = std::int16_t; ///< 16-bit signed short
|
||||
using s32 = std::int32_t; ///< 32-bit signed word
|
||||
using s64 = std::int64_t; ///< 64-bit signed int
|
||||
|
||||
using f32 = float; ///< 32-bit floating point
|
||||
using f64 = double; ///< 64-bit floating point
|
||||
|
||||
using VAddr = u64; ///< Represents a pointer in the userspace virtual address space.
|
||||
using DAddr = u64; ///< Represents a pointer in the device specific virtual address space.
|
||||
using PAddr = u64; ///< Represents a pointer in the ARM11 physical address space.
|
||||
using GPUVAddr = u64; ///< Represents a pointer in the GPU virtual address space.
|
||||
|
||||
using u128 = std::array<std::uint64_t, 2>;
|
||||
static_assert(sizeof(u128) == 16, "u128 must be 128 bits wide");
|
||||
25
gpu/third_party/suyu/common/div_ceil.h
vendored
Normal file
25
gpu/third_party/suyu/common/div_ceil.h
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <type_traits>
|
||||
|
||||
namespace Common {
|
||||
|
||||
/// Ceiled integer division.
|
||||
template <typename N, typename D>
|
||||
requires std::is_integral_v<N> && std::is_unsigned_v<D>
|
||||
[[nodiscard]] constexpr N DivCeil(N number, D divisor) {
|
||||
return static_cast<N>((static_cast<D>(number) + divisor - 1) / divisor);
|
||||
}
|
||||
|
||||
/// Ceiled integer division with logarithmic divisor in base 2
|
||||
template <typename N, typename D>
|
||||
requires std::is_integral_v<N> && std::is_unsigned_v<D>
|
||||
[[nodiscard]] constexpr N DivCeilLog2(N value, D alignment_log2) {
|
||||
return static_cast<N>((static_cast<D>(value) + (D(1) << alignment_log2) - 1) >> alignment_log2);
|
||||
}
|
||||
|
||||
} // namespace Common
|
||||
15
gpu/third_party/suyu/common/logging.h
vendored
Normal file
15
gpu/third_party/suyu/common/logging.h
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
// Rexcomp replacement for suyu's common/logging.h: log lines go nowhere unless GPU_SHADER_LOG is defined.
|
||||
#pragma once
|
||||
#include <fmt/format.h> // suyu code reaches fmt through this header
|
||||
#ifdef GPU_SHADER_LOG
|
||||
#include <cstdio>
|
||||
#define LOG_GENERIC_(level, cls, ...) std::fprintf(stderr, "[shader %s] %s\n", level, fmt::format(__VA_ARGS__).c_str())
|
||||
#else
|
||||
#define LOG_GENERIC_(level, cls, ...) ((void)0)
|
||||
#endif
|
||||
#define LOG_TRACE(cls, ...) ((void)0)
|
||||
#define LOG_DEBUG(cls, ...) ((void)0)
|
||||
#define LOG_INFO(cls, ...) LOG_GENERIC_("info", cls, __VA_ARGS__)
|
||||
#define LOG_WARNING(cls, ...) LOG_GENERIC_("warning", cls, __VA_ARGS__)
|
||||
#define LOG_ERROR(cls, ...) LOG_GENERIC_("error", cls, __VA_ARGS__)
|
||||
#define LOG_CRITICAL(cls, ...) LOG_GENERIC_("critical", cls, __VA_ARGS__)
|
||||
100
gpu/third_party/suyu/common/math_util.h
vendored
Normal file
100
gpu/third_party/suyu/common/math_util.h
vendored
Normal file
@@ -0,0 +1,100 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2026 suyu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: 2013 Dolphin Emulator Project
|
||||
// SPDX-FileCopyrightText: 2014 Citra Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdlib>
|
||||
#include <type_traits>
|
||||
|
||||
namespace Common {
|
||||
|
||||
template <class T>
|
||||
struct Rectangle {
|
||||
T left{};
|
||||
T top{};
|
||||
T right{};
|
||||
T bottom{};
|
||||
|
||||
constexpr Rectangle() = default;
|
||||
|
||||
constexpr Rectangle(T width, T height) : right(width), bottom(height) {}
|
||||
|
||||
constexpr Rectangle(T left_, T top_, T right_, T bottom_)
|
||||
: left(left_), top(top_), right(right_), bottom(bottom_) {}
|
||||
|
||||
[[nodiscard]] constexpr T Left() const {
|
||||
return left;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr T Top() const {
|
||||
return top;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr T Right() const {
|
||||
return right;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr T Bottom() const {
|
||||
return bottom;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr bool IsEmpty() const {
|
||||
return (GetWidth() <= 0) || (GetHeight() <= 0);
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr T GetWidth() const {
|
||||
if constexpr (std::is_floating_point_v<T>) {
|
||||
return std::abs(right - left);
|
||||
} else {
|
||||
return static_cast<T>(std::abs(static_cast<std::make_signed_t<T>>(right - left)));
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr T GetHeight() const {
|
||||
if constexpr (std::is_floating_point_v<T>) {
|
||||
return std::abs(bottom - top);
|
||||
} else {
|
||||
return static_cast<T>(std::abs(static_cast<std::make_signed_t<T>>(bottom - top)));
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr Rectangle<T> TranslateX(const T x) const {
|
||||
return Rectangle{left + x, top, right + x, bottom};
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr Rectangle<T> TranslateY(const T y) const {
|
||||
return Rectangle{left, top + y, right, bottom + y};
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr Rectangle<T> Scale(const float s) const {
|
||||
return Rectangle{left, top, static_cast<T>(static_cast<float>(left + GetWidth()) * s),
|
||||
static_cast<T>(static_cast<float>(top + GetHeight()) * s)};
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr bool operator==(const Rectangle<T>& rhs) const {
|
||||
return (left == rhs.left) && (top == rhs.top) && (right == rhs.right) &&
|
||||
(bottom == rhs.bottom);
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr bool operator!=(const Rectangle<T>& rhs) const {
|
||||
return !operator==(rhs);
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr bool Intersect(const Rectangle<T>& with, Rectangle<T>* result) const {
|
||||
result->left = (std::max)(left, with.left);
|
||||
result->top = (std::max)(top, with.top);
|
||||
result->right = (std::min)(right, with.right);
|
||||
result->bottom = (std::min)(bottom, with.bottom);
|
||||
return !result->IsEmpty();
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
Rectangle(T, T, T, T) -> Rectangle<T>;
|
||||
|
||||
} // namespace Common
|
||||
28
gpu/third_party/suyu/common/settings.h
vendored
Normal file
28
gpu/third_party/suyu/common/settings.h
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
// Rexcomp replacement for suyu's common/settings.h: only the values shader_recompiler reads, at suyu's defaults.
|
||||
#pragma once
|
||||
#include "common/common_types.h"
|
||||
|
||||
namespace Settings {
|
||||
enum class AstcRecompression : u32 { Uncompressed = 0, Bc1 = 1, Bc3 = 2 };
|
||||
template <typename T>
|
||||
struct Setting {
|
||||
T value;
|
||||
T GetValue() const { return value; }
|
||||
operator T() const { return value; }
|
||||
};
|
||||
struct ResolutionScalingInfo {
|
||||
u32 up_scale{1};
|
||||
u32 down_shift{0};
|
||||
f32 up_factor{1.0f};
|
||||
f32 down_factor{1.0f};
|
||||
bool active{false};
|
||||
};
|
||||
struct Values {
|
||||
Setting<bool> disable_shader_loop_safety_checks{false};
|
||||
Setting<bool> renderer_debug{false};
|
||||
Setting<bool> rescale_hack{false};
|
||||
ResolutionScalingInfo resolution_info{};
|
||||
Setting<AstcRecompression> astc_recompression{AstcRecompression::Uncompressed};
|
||||
};
|
||||
inline Values values;
|
||||
} // namespace Settings
|
||||
664
gpu/third_party/suyu/common/swap.h
vendored
Normal file
664
gpu/third_party/suyu/common/swap.h
vendored
Normal file
@@ -0,0 +1,664 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2026 suyu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: 2012 PPSSPP Project
|
||||
// SPDX-FileCopyrightText: 2012 Dolphin Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
// Official git repository and contact information can be found at
|
||||
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <type_traits>
|
||||
#include <bit>
|
||||
#include "common/common_types.h"
|
||||
|
||||
namespace Common {
|
||||
|
||||
#if defined(__Bitrig__) || defined(__OpenBSD__)
|
||||
// We'll redefine swap16, swap32, swap64 as inline functions
|
||||
// but OpenBSD is like "wow I bring my own stuff"
|
||||
// It would be nice if we could use them without C++ namespace shenanigans
|
||||
// But alas :)
|
||||
#undef swap16
|
||||
#undef swap32
|
||||
#undef swap64
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
[[nodiscard]] inline u16 swap16(u16 data) noexcept {
|
||||
return _byteswap_ushort(data);
|
||||
}
|
||||
[[nodiscard]] inline u32 swap32(u32 data) noexcept {
|
||||
return _byteswap_ulong(data);
|
||||
}
|
||||
[[nodiscard]] inline u64 swap64(u64 data) noexcept {
|
||||
return _byteswap_uint64(data);
|
||||
}
|
||||
#elif defined(__clang__) || defined(__GNUC__)
|
||||
[[nodiscard]] inline u16 swap16(u16 data) noexcept {
|
||||
return __builtin_bswap16(data);
|
||||
}
|
||||
[[nodiscard]] inline u32 swap32(u32 data) noexcept {
|
||||
return __builtin_bswap32(data);
|
||||
}
|
||||
[[nodiscard]] inline u64 swap64(u64 data) noexcept {
|
||||
return __builtin_bswap64(data);
|
||||
}
|
||||
#else
|
||||
// Generic implementation - compiler will optimise these into their respective
|
||||
// __builtin_byteswapXX() and such; if not, the compiler is stupid and we probably
|
||||
// have bigger problems to worry about :)
|
||||
[[nodiscard]] inline u16 swap16(u16 data) noexcept {
|
||||
return (data >> 8) | (data << 8);
|
||||
}
|
||||
[[nodiscard]] inline u32 swap32(u32 data) noexcept {
|
||||
return ((data & 0xFF000000U) >> 24) | ((data & 0x00FF0000U) >> 8) |
|
||||
((data & 0x0000FF00U) << 8) | ((data & 0x000000FFU) << 24);
|
||||
}
|
||||
[[nodiscard]] inline u64 swap64(u64 data) noexcept {
|
||||
return ((data & 0xFF00000000000000ULL) >> 56) | ((data & 0x00FF000000000000ULL) >> 40) |
|
||||
((data & 0x0000FF0000000000ULL) >> 24) | ((data & 0x000000FF00000000ULL) >> 8) |
|
||||
((data & 0x00000000FF000000ULL) << 8) | ((data & 0x0000000000FF0000ULL) << 24) |
|
||||
((data & 0x000000000000FF00ULL) << 40) | ((data & 0x00000000000000FFULL) << 56);
|
||||
}
|
||||
#endif
|
||||
|
||||
[[nodiscard]] inline float swapf(float f) noexcept {
|
||||
static_assert(sizeof(u32) == sizeof(float), "float must be the same size as uint32_t.");
|
||||
u32 value;
|
||||
std::memcpy(&value, &f, sizeof(u32));
|
||||
value = swap32(value);
|
||||
std::memcpy(&f, &value, sizeof(u32));
|
||||
return f;
|
||||
}
|
||||
|
||||
[[nodiscard]] inline double swapd(double f) noexcept {
|
||||
static_assert(sizeof(u64) == sizeof(double), "double must be the same size as uint64_t.");
|
||||
u64 value;
|
||||
std::memcpy(&value, &f, sizeof(u64));
|
||||
value = swap64(value);
|
||||
std::memcpy(&f, &value, sizeof(u64));
|
||||
return f;
|
||||
}
|
||||
|
||||
} // Namespace Common
|
||||
|
||||
template <typename T, typename F>
|
||||
struct SwapStructT {
|
||||
using SwappedT = SwapStructT;
|
||||
|
||||
protected:
|
||||
T value;
|
||||
|
||||
static T swap(T v) {
|
||||
return F::swap(v);
|
||||
}
|
||||
|
||||
public:
|
||||
T swap() const {
|
||||
return swap(value);
|
||||
}
|
||||
SwapStructT() = default;
|
||||
SwapStructT(const T& v) : value(swap(v)) {}
|
||||
|
||||
template <typename S>
|
||||
SwappedT& operator=(const S& source) {
|
||||
value = swap(T(source));
|
||||
return *this;
|
||||
}
|
||||
|
||||
operator s8() const {
|
||||
return s8(swap());
|
||||
}
|
||||
operator u8() const {
|
||||
return u8(swap());
|
||||
}
|
||||
operator s16() const {
|
||||
return s16(swap());
|
||||
}
|
||||
operator u16() const {
|
||||
return u16(swap());
|
||||
}
|
||||
operator s32() const {
|
||||
return s32(swap());
|
||||
}
|
||||
operator u32() const {
|
||||
return u32(swap());
|
||||
}
|
||||
operator s64() const {
|
||||
return s64(swap());
|
||||
}
|
||||
operator u64() const {
|
||||
return u64(swap());
|
||||
}
|
||||
operator float() const {
|
||||
return float(swap());
|
||||
}
|
||||
operator double() const {
|
||||
return double(swap());
|
||||
}
|
||||
|
||||
// +v
|
||||
SwappedT operator+() const {
|
||||
return +swap();
|
||||
}
|
||||
// -v
|
||||
SwappedT operator-() const {
|
||||
return -swap();
|
||||
}
|
||||
|
||||
// v / 5
|
||||
SwappedT operator/(const SwappedT& i) const {
|
||||
return swap() / i.swap();
|
||||
}
|
||||
template <typename S>
|
||||
SwappedT operator/(const S& i) const {
|
||||
return swap() / i;
|
||||
}
|
||||
|
||||
// v * 5
|
||||
SwappedT operator*(const SwappedT& i) const {
|
||||
return swap() * i.swap();
|
||||
}
|
||||
template <typename S>
|
||||
SwappedT operator*(const S& i) const {
|
||||
return swap() * i;
|
||||
}
|
||||
|
||||
// v + 5
|
||||
SwappedT operator+(const SwappedT& i) const {
|
||||
return swap() + i.swap();
|
||||
}
|
||||
template <typename S>
|
||||
SwappedT operator+(const S& i) const {
|
||||
return swap() + T(i);
|
||||
}
|
||||
// v - 5
|
||||
SwappedT operator-(const SwappedT& i) const {
|
||||
return swap() - i.swap();
|
||||
}
|
||||
template <typename S>
|
||||
SwappedT operator-(const S& i) const {
|
||||
return swap() - T(i);
|
||||
}
|
||||
|
||||
// v += 5
|
||||
SwappedT& operator+=(const SwappedT& i) {
|
||||
value = swap(swap() + i.swap());
|
||||
return *this;
|
||||
}
|
||||
template <typename S>
|
||||
SwappedT& operator+=(const S& i) {
|
||||
value = swap(swap() + T(i));
|
||||
return *this;
|
||||
}
|
||||
// v -= 5
|
||||
SwappedT& operator-=(const SwappedT& i) {
|
||||
value = swap(swap() - i.swap());
|
||||
return *this;
|
||||
}
|
||||
template <typename S>
|
||||
SwappedT& operator-=(const S& i) {
|
||||
value = swap(swap() - T(i));
|
||||
return *this;
|
||||
}
|
||||
|
||||
// ++v
|
||||
SwappedT& operator++() {
|
||||
value = swap(swap() + 1);
|
||||
return *this;
|
||||
}
|
||||
// --v
|
||||
SwappedT& operator--() {
|
||||
value = swap(swap() - 1);
|
||||
return *this;
|
||||
}
|
||||
|
||||
// v++
|
||||
SwappedT operator++(int) {
|
||||
SwappedT old = *this;
|
||||
value = swap(swap() + 1);
|
||||
return old;
|
||||
}
|
||||
// v--
|
||||
SwappedT operator--(int) {
|
||||
SwappedT old = *this;
|
||||
value = swap(swap() - 1);
|
||||
return old;
|
||||
}
|
||||
// Comparison
|
||||
// v == i
|
||||
bool operator==(const SwappedT& i) const {
|
||||
return swap() == i.swap();
|
||||
}
|
||||
template <typename S>
|
||||
bool operator==(const S& i) const {
|
||||
return swap() == i;
|
||||
}
|
||||
|
||||
// v != i
|
||||
bool operator!=(const SwappedT& i) const {
|
||||
return swap() != i.swap();
|
||||
}
|
||||
template <typename S>
|
||||
bool operator!=(const S& i) const {
|
||||
return swap() != i;
|
||||
}
|
||||
|
||||
// v > i
|
||||
bool operator>(const SwappedT& i) const {
|
||||
return swap() > i.swap();
|
||||
}
|
||||
template <typename S>
|
||||
bool operator>(const S& i) const {
|
||||
return swap() > i;
|
||||
}
|
||||
|
||||
// v < i
|
||||
bool operator<(const SwappedT& i) const {
|
||||
return swap() < i.swap();
|
||||
}
|
||||
template <typename S>
|
||||
bool operator<(const S& i) const {
|
||||
return swap() < i;
|
||||
}
|
||||
|
||||
// v >= i
|
||||
bool operator>=(const SwappedT& i) const {
|
||||
return swap() >= i.swap();
|
||||
}
|
||||
template <typename S>
|
||||
bool operator>=(const S& i) const {
|
||||
return swap() >= i;
|
||||
}
|
||||
|
||||
// v <= i
|
||||
bool operator<=(const SwappedT& i) const {
|
||||
return swap() <= i.swap();
|
||||
}
|
||||
template <typename S>
|
||||
bool operator<=(const S& i) const {
|
||||
return swap() <= i;
|
||||
}
|
||||
|
||||
// logical
|
||||
SwappedT operator!() const {
|
||||
return !swap();
|
||||
}
|
||||
|
||||
// bitmath
|
||||
SwappedT operator~() const {
|
||||
return ~swap();
|
||||
}
|
||||
|
||||
SwappedT operator&(const SwappedT& b) const {
|
||||
return swap() & b.swap();
|
||||
}
|
||||
template <typename S>
|
||||
SwappedT operator&(const S& b) const {
|
||||
return swap() & b;
|
||||
}
|
||||
SwappedT& operator&=(const SwappedT& b) {
|
||||
value = swap(swap() & b.swap());
|
||||
return *this;
|
||||
}
|
||||
template <typename S>
|
||||
SwappedT& operator&=(const S b) {
|
||||
value = swap(swap() & b);
|
||||
return *this;
|
||||
}
|
||||
|
||||
SwappedT operator|(const SwappedT& b) const {
|
||||
return swap() | b.swap();
|
||||
}
|
||||
template <typename S>
|
||||
SwappedT operator|(const S& b) const {
|
||||
return swap() | b;
|
||||
}
|
||||
SwappedT& operator|=(const SwappedT& b) {
|
||||
value = swap(swap() | b.swap());
|
||||
return *this;
|
||||
}
|
||||
template <typename S>
|
||||
SwappedT& operator|=(const S& b) {
|
||||
value = swap(swap() | b);
|
||||
return *this;
|
||||
}
|
||||
|
||||
SwappedT operator^(const SwappedT& b) const {
|
||||
return swap() ^ b.swap();
|
||||
}
|
||||
template <typename S>
|
||||
SwappedT operator^(const S& b) const {
|
||||
return swap() ^ b;
|
||||
}
|
||||
SwappedT& operator^=(const SwappedT& b) {
|
||||
value = swap(swap() ^ b.swap());
|
||||
return *this;
|
||||
}
|
||||
template <typename S>
|
||||
SwappedT& operator^=(const S& b) {
|
||||
value = swap(swap() ^ b);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename S>
|
||||
SwappedT operator<<(const S& b) const {
|
||||
return swap() << b;
|
||||
}
|
||||
template <typename S>
|
||||
SwappedT& operator<<=(const S& b) const {
|
||||
value = swap(swap() << b);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename S>
|
||||
SwappedT operator>>(const S& b) const {
|
||||
return swap() >> b;
|
||||
}
|
||||
template <typename S>
|
||||
SwappedT& operator>>=(const S& b) const {
|
||||
value = swap(swap() >> b);
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Member
|
||||
/** todo **/
|
||||
|
||||
// Arithmetic
|
||||
template <typename S, typename T2, typename F2>
|
||||
friend S operator+(const S& p, const SwappedT v);
|
||||
|
||||
template <typename S, typename T2, typename F2>
|
||||
friend S operator-(const S& p, const SwappedT v);
|
||||
|
||||
template <typename S, typename T2, typename F2>
|
||||
friend S operator/(const S& p, const SwappedT v);
|
||||
|
||||
template <typename S, typename T2, typename F2>
|
||||
friend S operator*(const S& p, const SwappedT v);
|
||||
|
||||
template <typename S, typename T2, typename F2>
|
||||
friend S operator%(const S& p, const SwappedT v);
|
||||
|
||||
// Arithmetic + assignments
|
||||
template <typename S, typename T2, typename F2>
|
||||
friend S operator+=(const S& p, const SwappedT v);
|
||||
|
||||
template <typename S, typename T2, typename F2>
|
||||
friend S operator-=(const S& p, const SwappedT v);
|
||||
|
||||
// Bitmath
|
||||
template <typename S, typename T2, typename F2>
|
||||
friend S operator&(const S& p, const SwappedT v);
|
||||
|
||||
// Comparison
|
||||
template <typename S, typename T2, typename F2>
|
||||
friend bool operator<(const S& p, const SwappedT v);
|
||||
|
||||
template <typename S, typename T2, typename F2>
|
||||
friend bool operator>(const S& p, const SwappedT v);
|
||||
|
||||
template <typename S, typename T2, typename F2>
|
||||
friend bool operator<=(const S& p, const SwappedT v);
|
||||
|
||||
template <typename S, typename T2, typename F2>
|
||||
friend bool operator>=(const S& p, const SwappedT v);
|
||||
|
||||
template <typename S, typename T2, typename F2>
|
||||
friend bool operator!=(const S& p, const SwappedT v);
|
||||
|
||||
template <typename S, typename T2, typename F2>
|
||||
friend bool operator==(const S& p, const SwappedT v);
|
||||
};
|
||||
|
||||
// Arithmetic
|
||||
template <typename S, typename T, typename F>
|
||||
S operator+(const S& i, const SwapStructT<T, F> v) {
|
||||
return i + v.swap();
|
||||
}
|
||||
|
||||
template <typename S, typename T, typename F>
|
||||
S operator-(const S& i, const SwapStructT<T, F> v) {
|
||||
return i - v.swap();
|
||||
}
|
||||
|
||||
template <typename S, typename T, typename F>
|
||||
S operator/(const S& i, const SwapStructT<T, F> v) {
|
||||
return i / v.swap();
|
||||
}
|
||||
|
||||
template <typename S, typename T, typename F>
|
||||
S operator*(const S& i, const SwapStructT<T, F> v) {
|
||||
return i * v.swap();
|
||||
}
|
||||
|
||||
template <typename S, typename T, typename F>
|
||||
S operator%(const S& i, const SwapStructT<T, F> v) {
|
||||
return i % v.swap();
|
||||
}
|
||||
|
||||
// Arithmetic + assignments
|
||||
template <typename S, typename T, typename F>
|
||||
S& operator+=(S& i, const SwapStructT<T, F> v) {
|
||||
i += v.swap();
|
||||
return i;
|
||||
}
|
||||
|
||||
template <typename S, typename T, typename F>
|
||||
S& operator-=(S& i, const SwapStructT<T, F> v) {
|
||||
i -= v.swap();
|
||||
return i;
|
||||
}
|
||||
|
||||
// Logical
|
||||
template <typename S, typename T, typename F>
|
||||
S operator&(const S& i, const SwapStructT<T, F> v) {
|
||||
return i & v.swap();
|
||||
}
|
||||
|
||||
// Comparison
|
||||
template <typename S, typename T, typename F>
|
||||
bool operator<(const S& p, const SwapStructT<T, F> v) {
|
||||
return p < v.swap();
|
||||
}
|
||||
template <typename S, typename T, typename F>
|
||||
bool operator>(const S& p, const SwapStructT<T, F> v) {
|
||||
return p > v.swap();
|
||||
}
|
||||
template <typename S, typename T, typename F>
|
||||
bool operator<=(const S& p, const SwapStructT<T, F> v) {
|
||||
return p <= v.swap();
|
||||
}
|
||||
template <typename S, typename T, typename F>
|
||||
bool operator>=(const S& p, const SwapStructT<T, F> v) {
|
||||
return p >= v.swap();
|
||||
}
|
||||
template <typename S, typename T, typename F>
|
||||
bool operator!=(const S& p, const SwapStructT<T, F> v) {
|
||||
return p != v.swap();
|
||||
}
|
||||
template <typename S, typename T, typename F>
|
||||
bool operator==(const S& p, const SwapStructT<T, F> v) {
|
||||
return p == v.swap();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
struct Swap64T {
|
||||
static T swap(T x) {
|
||||
return T(Common::swap64(x));
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct Swap32T {
|
||||
static T swap(T x) {
|
||||
return T(Common::swap32(x));
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct Swap16T {
|
||||
static T swap(T x) {
|
||||
return T(Common::swap16(x));
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct SwapFloatT {
|
||||
static T swap(T x) {
|
||||
return T(Common::swapf(x));
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct SwapDoubleT {
|
||||
static T swap(T x) {
|
||||
return T(Common::swapd(x));
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct SwapEnumT {
|
||||
static_assert(std::is_enum_v<T>);
|
||||
using base = std::underlying_type_t<T>;
|
||||
|
||||
public:
|
||||
SwapEnumT() = default;
|
||||
SwapEnumT(const T& v) : value(swap(v)) {}
|
||||
|
||||
SwapEnumT& operator=(const T& v) {
|
||||
value = swap(v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
operator T() const {
|
||||
return swap(value);
|
||||
}
|
||||
|
||||
explicit operator base() const {
|
||||
return base(swap(value));
|
||||
}
|
||||
|
||||
protected:
|
||||
T value{};
|
||||
using swap_t = std::conditional_t<
|
||||
std::is_same_v<base, u16>, Swap16T<u16>, std::conditional_t<
|
||||
std::is_same_v<base, s16>, Swap16T<s16>, std::conditional_t<
|
||||
std::is_same_v<base, u32>, Swap32T<u32>, std::conditional_t<
|
||||
std::is_same_v<base, s32>, Swap32T<s32>, std::conditional_t<
|
||||
std::is_same_v<base, u64>, Swap64T<u64>, std::conditional_t<
|
||||
std::is_same_v<base, s64>, Swap64T<s64>, void>>>>>>;
|
||||
static T swap(T x) {
|
||||
return T(swap_t::swap(base(x)));
|
||||
}
|
||||
};
|
||||
|
||||
struct SwapTag {}; // Use the different endianness from the system
|
||||
struct KeepTag {}; // Use the same endianness as the system
|
||||
|
||||
template <typename T, typename Tag>
|
||||
struct AddEndian;
|
||||
|
||||
// KeepTag specializations
|
||||
|
||||
template <typename T>
|
||||
struct AddEndian<T, KeepTag> {
|
||||
using type = T;
|
||||
};
|
||||
|
||||
// SwapTag specializations
|
||||
|
||||
template <>
|
||||
struct AddEndian<u8, SwapTag> {
|
||||
using type = u8;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct AddEndian<u16, SwapTag> {
|
||||
using type = SwapStructT<u16, Swap16T<u16>>;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct AddEndian<u32, SwapTag> {
|
||||
using type = SwapStructT<u32, Swap32T<u32>>;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct AddEndian<u64, SwapTag> {
|
||||
using type = SwapStructT<u64, Swap64T<u64>>;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct AddEndian<s8, SwapTag> {
|
||||
using type = s8;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct AddEndian<s16, SwapTag> {
|
||||
using type = SwapStructT<s16, Swap16T<s16>>;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct AddEndian<s32, SwapTag> {
|
||||
using type = SwapStructT<s32, Swap32T<s32>>;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct AddEndian<s64, SwapTag> {
|
||||
using type = SwapStructT<s64, Swap64T<s64>>;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct AddEndian<float, SwapTag> {
|
||||
using type = SwapStructT<float, SwapFloatT<float>>;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct AddEndian<double, SwapTag> {
|
||||
using type = SwapStructT<double, SwapDoubleT<double>>;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct AddEndian<T, SwapTag> {
|
||||
static_assert(std::is_enum_v<T>);
|
||||
using type = SwapEnumT<T>;
|
||||
};
|
||||
|
||||
// Alias LETag/BETag as KeepTag/SwapTag depending on the system
|
||||
using LETag = std::conditional_t<std::endian::native == std::endian::little, KeepTag, SwapTag>;
|
||||
using BETag = std::conditional_t<std::endian::native == std::endian::big, KeepTag, SwapTag>;
|
||||
|
||||
// Aliases for LE types
|
||||
using u16_le = AddEndian<u16, LETag>::type;
|
||||
using u32_le = AddEndian<u32, LETag>::type;
|
||||
using u64_le = AddEndian<u64, LETag>::type;
|
||||
|
||||
using s16_le = AddEndian<s16, LETag>::type;
|
||||
using s32_le = AddEndian<s32, LETag>::type;
|
||||
using s64_le = AddEndian<s64, LETag>::type;
|
||||
|
||||
template <typename T>
|
||||
using enum_le = std::enable_if_t<std::is_enum_v<T>, typename AddEndian<T, LETag>::type>;
|
||||
|
||||
using float_le = AddEndian<float, LETag>::type;
|
||||
using double_le = AddEndian<double, LETag>::type;
|
||||
|
||||
// Aliases for BE types
|
||||
using u16_be = AddEndian<u16, BETag>::type;
|
||||
using u32_be = AddEndian<u32, BETag>::type;
|
||||
using u64_be = AddEndian<u64, BETag>::type;
|
||||
|
||||
using s16_be = AddEndian<s16, BETag>::type;
|
||||
using s32_be = AddEndian<s32, BETag>::type;
|
||||
using s64_be = AddEndian<s64, BETag>::type;
|
||||
|
||||
template <typename T>
|
||||
using enum_be = std::enable_if_t<std::is_enum_v<T>, typename AddEndian<T, BETag>::type>;
|
||||
|
||||
using float_be = AddEndian<float, BETag>::type;
|
||||
using double_be = AddEndian<double, BETag>::type;
|
||||
264
gpu/third_party/suyu/shader_recompiler/CMakeLists.txt
vendored
Normal file
264
gpu/third_party/suyu/shader_recompiler/CMakeLists.txt
vendored
Normal file
@@ -0,0 +1,264 @@
|
||||
# SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
# SPDX-FileCopyrightText: 2018 yuzu Emulator Project
|
||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
add_library(shader_recompiler STATIC
|
||||
backend/bindings.h
|
||||
backend/glasm/emit_glasm.cpp
|
||||
backend/glasm/emit_glasm.h
|
||||
backend/glasm/emit_glasm_barriers.cpp
|
||||
backend/glasm/emit_glasm_bitwise_conversion.cpp
|
||||
backend/glasm/emit_glasm_composite.cpp
|
||||
backend/glasm/emit_glasm_context_get_set.cpp
|
||||
backend/glasm/emit_glasm_control_flow.cpp
|
||||
backend/glasm/emit_glasm_convert.cpp
|
||||
backend/glasm/emit_glasm_floating_point.cpp
|
||||
backend/glasm/emit_glasm_image.cpp
|
||||
backend/glasm/emit_glasm_instructions.h
|
||||
backend/glasm/emit_glasm_integer.cpp
|
||||
backend/glasm/emit_glasm_logical.cpp
|
||||
backend/glasm/emit_glasm_memory.cpp
|
||||
backend/glasm/emit_glasm_not_implemented.cpp
|
||||
backend/glasm/emit_glasm_select.cpp
|
||||
backend/glasm/emit_glasm_shared_memory.cpp
|
||||
backend/glasm/emit_glasm_special.cpp
|
||||
backend/glasm/emit_glasm_undefined.cpp
|
||||
backend/glasm/emit_glasm_warp.cpp
|
||||
backend/glasm/glasm_emit_context.cpp
|
||||
backend/glasm/glasm_emit_context.h
|
||||
backend/glasm/reg_alloc.cpp
|
||||
backend/glasm/reg_alloc.h
|
||||
backend/glsl/emit_glsl.cpp
|
||||
backend/glsl/emit_glsl.h
|
||||
backend/glsl/emit_glsl_atomic.cpp
|
||||
backend/glsl/emit_glsl_barriers.cpp
|
||||
backend/glsl/emit_glsl_bitwise_conversion.cpp
|
||||
backend/glsl/emit_glsl_composite.cpp
|
||||
backend/glsl/emit_glsl_context_get_set.cpp
|
||||
backend/glsl/emit_glsl_control_flow.cpp
|
||||
backend/glsl/emit_glsl_convert.cpp
|
||||
backend/glsl/emit_glsl_floating_point.cpp
|
||||
backend/glsl/emit_glsl_image.cpp
|
||||
backend/glsl/emit_glsl_instructions.h
|
||||
backend/glsl/emit_glsl_integer.cpp
|
||||
backend/glsl/emit_glsl_logical.cpp
|
||||
backend/glsl/emit_glsl_memory.cpp
|
||||
backend/glsl/emit_glsl_not_implemented.cpp
|
||||
backend/glsl/emit_glsl_select.cpp
|
||||
backend/glsl/emit_glsl_shared_memory.cpp
|
||||
backend/glsl/emit_glsl_special.cpp
|
||||
backend/glsl/emit_glsl_undefined.cpp
|
||||
backend/glsl/emit_glsl_warp.cpp
|
||||
backend/glsl/glsl_emit_context.cpp
|
||||
backend/glsl/glsl_emit_context.h
|
||||
backend/glsl/var_alloc.cpp
|
||||
backend/glsl/var_alloc.h
|
||||
backend/spirv/emit_spirv.cpp
|
||||
backend/spirv/emit_spirv.h
|
||||
backend/spirv/emit_spirv_atomic.cpp
|
||||
backend/spirv/emit_spirv_barriers.cpp
|
||||
backend/spirv/emit_spirv_bitwise_conversion.cpp
|
||||
backend/spirv/emit_spirv_composite.cpp
|
||||
backend/spirv/emit_spirv_context_get_set.cpp
|
||||
backend/spirv/emit_spirv_control_flow.cpp
|
||||
backend/spirv/emit_spirv_convert.cpp
|
||||
backend/spirv/emit_spirv_floating_point.cpp
|
||||
backend/spirv/emit_spirv_image.cpp
|
||||
backend/spirv/emit_spirv_image_atomic.cpp
|
||||
backend/spirv/emit_spirv_instructions.h
|
||||
backend/spirv/emit_spirv_integer.cpp
|
||||
backend/spirv/emit_spirv_logical.cpp
|
||||
backend/spirv/emit_spirv_memory.cpp
|
||||
backend/spirv/emit_spirv_select.cpp
|
||||
backend/spirv/emit_spirv_shared_memory.cpp
|
||||
backend/spirv/emit_spirv_special.cpp
|
||||
backend/spirv/emit_spirv_undefined.cpp
|
||||
backend/spirv/emit_spirv_warp.cpp
|
||||
backend/spirv/spirv_emit_context.cpp
|
||||
backend/spirv/spirv_emit_context.h
|
||||
environment.h
|
||||
exception.h
|
||||
frontend/ir/abstract_syntax_list.h
|
||||
frontend/ir/attribute.h
|
||||
frontend/ir/basic_block.cpp
|
||||
frontend/ir/basic_block.h
|
||||
frontend/ir/breadth_first_search.h
|
||||
frontend/ir/condition.cpp
|
||||
frontend/ir/condition.h
|
||||
frontend/ir/flow_test.h
|
||||
frontend/ir/ir_emitter.cpp
|
||||
frontend/ir/ir_emitter.h
|
||||
frontend/ir/microinstruction.cpp
|
||||
frontend/ir/modifiers.h
|
||||
frontend/ir/opcodes.cpp
|
||||
frontend/ir/opcodes.h
|
||||
frontend/ir/opcodes.inc
|
||||
frontend/ir/patch.cpp
|
||||
frontend/ir/patch.h
|
||||
frontend/ir/post_order.cpp
|
||||
frontend/ir/post_order.h
|
||||
frontend/ir/pred.h
|
||||
frontend/ir/program.cpp
|
||||
frontend/ir/program.h
|
||||
frontend/ir/reg.h
|
||||
frontend/ir/type.cpp
|
||||
frontend/ir/type.h
|
||||
frontend/ir/value.cpp
|
||||
frontend/ir/value.h
|
||||
frontend/maxwell/control_flow.cpp
|
||||
frontend/maxwell/control_flow.h
|
||||
frontend/maxwell/decode.cpp
|
||||
frontend/maxwell/decode.h
|
||||
frontend/maxwell/indirect_branch_table_track.cpp
|
||||
frontend/maxwell/indirect_branch_table_track.h
|
||||
frontend/maxwell/instruction.h
|
||||
frontend/maxwell/location.h
|
||||
frontend/maxwell/maxwell.inc
|
||||
frontend/maxwell/opcodes.cpp
|
||||
frontend/maxwell/opcodes.h
|
||||
frontend/maxwell/structured_control_flow.cpp
|
||||
frontend/maxwell/structured_control_flow.h
|
||||
frontend/maxwell/translate/impl/atomic_operations_global_memory.cpp
|
||||
frontend/maxwell/translate/impl/atomic_operations_shared_memory.cpp
|
||||
frontend/maxwell/translate/impl/attribute_memory_to_physical.cpp
|
||||
frontend/maxwell/translate/impl/barrier_operations.cpp
|
||||
frontend/maxwell/translate/impl/bitfield_extract.cpp
|
||||
frontend/maxwell/translate/impl/bitfield_insert.cpp
|
||||
frontend/maxwell/translate/impl/branch_indirect.cpp
|
||||
frontend/maxwell/translate/impl/common_encoding.h
|
||||
frontend/maxwell/translate/impl/common_funcs.cpp
|
||||
frontend/maxwell/translate/impl/common_funcs.h
|
||||
frontend/maxwell/translate/impl/condition_code_set.cpp
|
||||
frontend/maxwell/translate/impl/double_add.cpp
|
||||
frontend/maxwell/translate/impl/double_compare_and_set.cpp
|
||||
frontend/maxwell/translate/impl/double_fused_multiply_add.cpp
|
||||
frontend/maxwell/translate/impl/double_min_max.cpp
|
||||
frontend/maxwell/translate/impl/double_multiply.cpp
|
||||
frontend/maxwell/translate/impl/double_set_predicate.cpp
|
||||
frontend/maxwell/translate/impl/exit_program.cpp
|
||||
frontend/maxwell/translate/impl/find_leading_one.cpp
|
||||
frontend/maxwell/translate/impl/floating_point_add.cpp
|
||||
frontend/maxwell/translate/impl/floating_point_compare.cpp
|
||||
frontend/maxwell/translate/impl/floating_point_compare_and_set.cpp
|
||||
frontend/maxwell/translate/impl/floating_point_conversion_floating_point.cpp
|
||||
frontend/maxwell/translate/impl/floating_point_conversion_integer.cpp
|
||||
frontend/maxwell/translate/impl/floating_point_fused_multiply_add.cpp
|
||||
frontend/maxwell/translate/impl/floating_point_min_max.cpp
|
||||
frontend/maxwell/translate/impl/floating_point_multi_function.cpp
|
||||
frontend/maxwell/translate/impl/floating_point_multiply.cpp
|
||||
frontend/maxwell/translate/impl/floating_point_range_reduction.cpp
|
||||
frontend/maxwell/translate/impl/floating_point_set_predicate.cpp
|
||||
frontend/maxwell/translate/impl/floating_point_swizzled_add.cpp
|
||||
frontend/maxwell/translate/impl/half_floating_point_add.cpp
|
||||
frontend/maxwell/translate/impl/half_floating_point_fused_multiply_add.cpp
|
||||
frontend/maxwell/translate/impl/half_floating_point_helper.cpp
|
||||
frontend/maxwell/translate/impl/half_floating_point_helper.h
|
||||
frontend/maxwell/translate/impl/half_floating_point_multiply.cpp
|
||||
frontend/maxwell/translate/impl/half_floating_point_set.cpp
|
||||
frontend/maxwell/translate/impl/half_floating_point_set_predicate.cpp
|
||||
frontend/maxwell/translate/impl/impl.cpp
|
||||
frontend/maxwell/translate/impl/impl.h
|
||||
frontend/maxwell/translate/impl/integer_add.cpp
|
||||
frontend/maxwell/translate/impl/integer_add_three_input.cpp
|
||||
frontend/maxwell/translate/impl/integer_compare.cpp
|
||||
frontend/maxwell/translate/impl/integer_compare_and_set.cpp
|
||||
frontend/maxwell/translate/impl/integer_floating_point_conversion.cpp
|
||||
frontend/maxwell/translate/impl/integer_funnel_shift.cpp
|
||||
frontend/maxwell/translate/impl/integer_minimum_maximum.cpp
|
||||
frontend/maxwell/translate/impl/integer_popcount.cpp
|
||||
frontend/maxwell/translate/impl/integer_scaled_add.cpp
|
||||
frontend/maxwell/translate/impl/integer_set_predicate.cpp
|
||||
frontend/maxwell/translate/impl/integer_shift_left.cpp
|
||||
frontend/maxwell/translate/impl/integer_shift_right.cpp
|
||||
frontend/maxwell/translate/impl/integer_short_multiply_add.cpp
|
||||
frontend/maxwell/translate/impl/integer_to_integer_conversion.cpp
|
||||
frontend/maxwell/translate/impl/internal_stage_buffer_entry_read.cpp
|
||||
frontend/maxwell/translate/impl/load_constant.cpp
|
||||
frontend/maxwell/translate/impl/load_constant.h
|
||||
frontend/maxwell/translate/impl/load_effective_address.cpp
|
||||
frontend/maxwell/translate/impl/load_store_attribute.cpp
|
||||
frontend/maxwell/translate/impl/load_store_local_shared.cpp
|
||||
frontend/maxwell/translate/impl/load_store_memory.cpp
|
||||
frontend/maxwell/translate/impl/logic_operation.cpp
|
||||
frontend/maxwell/translate/impl/logic_operation_three_input.cpp
|
||||
frontend/maxwell/translate/impl/move_predicate_to_register.cpp
|
||||
frontend/maxwell/translate/impl/move_register.cpp
|
||||
frontend/maxwell/translate/impl/move_register_to_predicate.cpp
|
||||
frontend/maxwell/translate/impl/move_special_register.cpp
|
||||
frontend/maxwell/translate/impl/not_implemented.cpp
|
||||
frontend/maxwell/translate/impl/output_geometry.cpp
|
||||
frontend/maxwell/translate/impl/pixel_load.cpp
|
||||
frontend/maxwell/translate/impl/predicate_set_predicate.cpp
|
||||
frontend/maxwell/translate/impl/predicate_set_register.cpp
|
||||
frontend/maxwell/translate/impl/select_source_with_predicate.cpp
|
||||
frontend/maxwell/translate/impl/surface_atomic_operations.cpp
|
||||
frontend/maxwell/translate/impl/surface_load_store.cpp
|
||||
frontend/maxwell/translate/impl/texture_fetch.cpp
|
||||
frontend/maxwell/translate/impl/texture_fetch_swizzled.cpp
|
||||
frontend/maxwell/translate/impl/texture_gather.cpp
|
||||
frontend/maxwell/translate/impl/texture_gather_swizzled.cpp
|
||||
frontend/maxwell/translate/impl/texture_gradient.cpp
|
||||
frontend/maxwell/translate/impl/texture_load.cpp
|
||||
frontend/maxwell/translate/impl/texture_load_swizzled.cpp
|
||||
frontend/maxwell/translate/impl/texture_mipmap_level.cpp
|
||||
frontend/maxwell/translate/impl/texture_query.cpp
|
||||
frontend/maxwell/translate/impl/video_helper.cpp
|
||||
frontend/maxwell/translate/impl/video_helper.h
|
||||
frontend/maxwell/translate/impl/video_minimum_maximum.cpp
|
||||
frontend/maxwell/translate/impl/video_multiply_add.cpp
|
||||
frontend/maxwell/translate/impl/video_set_predicate.cpp
|
||||
frontend/maxwell/translate/impl/vote.cpp
|
||||
frontend/maxwell/translate/impl/warp_shuffle.cpp
|
||||
frontend/maxwell/translate/translate.cpp
|
||||
frontend/maxwell/translate/translate.h
|
||||
frontend/maxwell/translate_program.cpp
|
||||
frontend/maxwell/translate_program.h
|
||||
host_translate_info.h
|
||||
ir_opt/collect_shader_info_pass.cpp
|
||||
ir_opt/conditional_barrier_pass.cpp
|
||||
ir_opt/constant_propagation_pass.cpp
|
||||
ir_opt/dead_code_elimination_pass.cpp
|
||||
ir_opt/dual_vertex_pass.cpp
|
||||
ir_opt/global_memory_to_storage_buffer_pass.cpp
|
||||
ir_opt/identity_removal_pass.cpp
|
||||
ir_opt/layer_pass.cpp
|
||||
ir_opt/lower_fp16_to_fp32.cpp
|
||||
ir_opt/lower_fp64_to_fp32.cpp
|
||||
ir_opt/lower_int64_to_int32.cpp
|
||||
ir_opt/passes.h
|
||||
ir_opt/position_pass.cpp
|
||||
ir_opt/rescaling_pass.cpp
|
||||
ir_opt/ssa_rewrite_pass.cpp
|
||||
ir_opt/texture_pass.cpp
|
||||
ir_opt/vendor_workaround_pass.cpp
|
||||
ir_opt/verification_pass.cpp
|
||||
object_pool.h
|
||||
profile.h
|
||||
program_header.h
|
||||
runtime_info.h
|
||||
shader_info.h
|
||||
varying_state.h
|
||||
|
||||
)
|
||||
|
||||
target_link_libraries(shader_recompiler PUBLIC common fmt::fmt sirit::sirit)
|
||||
|
||||
if (MSVC)
|
||||
target_compile_options(shader_recompiler PRIVATE
|
||||
/we4242 # 'identifier': conversion from 'type1' to 'type2', possible loss of data
|
||||
/we4254 # 'operator': conversion from 'type1:field_bits' to 'type2:field_bits', possible loss of data
|
||||
/we4800 # Implicit conversion from 'type' to bool. Possible information loss
|
||||
)
|
||||
else()
|
||||
target_compile_options(shader_recompiler PRIVATE
|
||||
$<$<COMPILE_LANGUAGE:C,CXX>:-Werror=conversion>
|
||||
# Bracket depth determines maximum size of a fold expression in Clang since 9c9974c3ccb6.
|
||||
# And this in turns limits the size of a std::array.
|
||||
$<$<CXX_COMPILER_ID:Clang>:-fbracket-depth=1024>
|
||||
$<$<CXX_COMPILER_ID:AppleClang>:-fbracket-depth=1024>
|
||||
)
|
||||
endif()
|
||||
|
||||
create_target_directory_groups(shader_recompiler)
|
||||
20
gpu/third_party/suyu/shader_recompiler/backend/bindings.h
vendored
Normal file
20
gpu/third_party/suyu/shader_recompiler/backend/bindings.h
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/common_types.h"
|
||||
|
||||
namespace Shader::Backend {
|
||||
|
||||
struct Bindings {
|
||||
u32 unified{};
|
||||
u32 uniform_buffer{};
|
||||
u32 storage_buffer{};
|
||||
u32 texture{};
|
||||
u32 image{};
|
||||
u32 texture_scaling_index{};
|
||||
u32 image_scaling_index{};
|
||||
};
|
||||
|
||||
} // namespace Shader::Backend
|
||||
252
gpu/third_party/suyu/shader_recompiler/backend/glsl/emit_glsl.cpp
vendored
Normal file
252
gpu/third_party/suyu/shader_recompiler/backend/glsl/emit_glsl.cpp
vendored
Normal file
@@ -0,0 +1,252 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
#include <type_traits>
|
||||
|
||||
#include "common/div_ceil.h"
|
||||
#include "common/settings.h"
|
||||
#include "shader_recompiler/backend/glsl/emit_glsl.h"
|
||||
#include "shader_recompiler/backend/glsl/emit_glsl_instructions.h"
|
||||
#include "shader_recompiler/backend/glsl/glsl_emit_context.h"
|
||||
#include "shader_recompiler/frontend/ir/ir_emitter.h"
|
||||
|
||||
namespace Shader::Backend::GLSL {
|
||||
namespace {
|
||||
template <class Func>
|
||||
struct FuncTraits {};
|
||||
|
||||
template <class ReturnType_, class... Args>
|
||||
struct FuncTraits<ReturnType_ (*)(Args...)> {
|
||||
using ReturnType = ReturnType_;
|
||||
|
||||
static constexpr size_t NUM_ARGS = sizeof...(Args);
|
||||
|
||||
template <size_t I>
|
||||
using ArgType = std::tuple_element_t<I, std::tuple<Args...>>;
|
||||
};
|
||||
|
||||
template <auto func, typename... Args>
|
||||
void SetDefinition(EmitContext& ctx, IR::Inst* inst, Args... args) {
|
||||
inst->SetDefinition<Id>(func(ctx, std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
template <typename ArgType>
|
||||
auto Arg(EmitContext& ctx, const IR::Value& arg) {
|
||||
if constexpr (std::is_same_v<ArgType, std::string_view>) {
|
||||
return ctx.var_alloc.Consume(arg);
|
||||
} else if constexpr (std::is_same_v<ArgType, const IR::Value&>) {
|
||||
return arg;
|
||||
} else if constexpr (std::is_same_v<ArgType, u32>) {
|
||||
return arg.U32();
|
||||
} else if constexpr (std::is_same_v<ArgType, IR::Attribute>) {
|
||||
return arg.Attribute();
|
||||
} else if constexpr (std::is_same_v<ArgType, IR::Patch>) {
|
||||
return arg.Patch();
|
||||
} else if constexpr (std::is_same_v<ArgType, IR::Reg>) {
|
||||
return arg.Reg();
|
||||
}
|
||||
}
|
||||
|
||||
template <auto func, bool is_first_arg_inst, size_t... I>
|
||||
void Invoke(EmitContext& ctx, IR::Inst* inst, std::index_sequence<I...>) {
|
||||
using Traits = FuncTraits<decltype(func)>;
|
||||
if constexpr (std::is_same_v<typename Traits::ReturnType, Id>) {
|
||||
if constexpr (is_first_arg_inst) {
|
||||
SetDefinition<func>(
|
||||
ctx, inst, *inst,
|
||||
Arg<typename Traits::template ArgType<I + 2>>(ctx, inst->Arg(I))...);
|
||||
} else {
|
||||
SetDefinition<func>(
|
||||
ctx, inst, Arg<typename Traits::template ArgType<I + 1>>(ctx, inst->Arg(I))...);
|
||||
}
|
||||
} else {
|
||||
if constexpr (is_first_arg_inst) {
|
||||
func(ctx, *inst, Arg<typename Traits::template ArgType<I + 2>>(ctx, inst->Arg(I))...);
|
||||
} else {
|
||||
func(ctx, Arg<typename Traits::template ArgType<I + 1>>(ctx, inst->Arg(I))...);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <auto func>
|
||||
void Invoke(EmitContext& ctx, IR::Inst* inst) {
|
||||
using Traits = FuncTraits<decltype(func)>;
|
||||
static_assert(Traits::NUM_ARGS >= 1, "Insufficient arguments");
|
||||
if constexpr (Traits::NUM_ARGS == 1) {
|
||||
Invoke<func, false>(ctx, inst, std::make_index_sequence<0>{});
|
||||
} else {
|
||||
using FirstArgType = typename Traits::template ArgType<1>;
|
||||
static constexpr bool is_first_arg_inst = std::is_same_v<FirstArgType, IR::Inst&>;
|
||||
using Indices = std::make_index_sequence<Traits::NUM_ARGS - (is_first_arg_inst ? 2 : 1)>;
|
||||
Invoke<func, is_first_arg_inst>(ctx, inst, Indices{});
|
||||
}
|
||||
}
|
||||
|
||||
void EmitInst(EmitContext& ctx, IR::Inst* inst) {
|
||||
switch (inst->GetOpcode()) {
|
||||
#define OPCODE(name, result_type, ...) \
|
||||
case IR::Opcode::name: \
|
||||
return Invoke<&Emit##name>(ctx, inst);
|
||||
#include "shader_recompiler/frontend/ir/opcodes.inc"
|
||||
#undef OPCODE
|
||||
}
|
||||
throw LogicError("Invalid opcode {}", inst->GetOpcode());
|
||||
}
|
||||
|
||||
bool IsReference(IR::Inst& inst) {
|
||||
return inst.GetOpcode() == IR::Opcode::Reference;
|
||||
}
|
||||
|
||||
void PrecolorInst(IR::Inst& phi) {
|
||||
// Insert phi moves before references to avoid overwriting other phis
|
||||
const size_t num_args{phi.NumArgs()};
|
||||
for (size_t i = 0; i < num_args; ++i) {
|
||||
IR::Block& phi_block{*phi.PhiBlock(i)};
|
||||
auto it{std::find_if_not(phi_block.rbegin(), phi_block.rend(), IsReference).base()};
|
||||
IR::IREmitter ir{phi_block, it};
|
||||
const IR::Value arg{phi.Arg(i)};
|
||||
if (arg.IsImmediate()) {
|
||||
ir.PhiMove(phi, arg);
|
||||
} else {
|
||||
ir.PhiMove(phi, IR::Value{arg.InstRecursive()});
|
||||
}
|
||||
}
|
||||
for (size_t i = 0; i < num_args; ++i) {
|
||||
IR::IREmitter{*phi.PhiBlock(i)}.Reference(IR::Value{&phi});
|
||||
}
|
||||
}
|
||||
|
||||
void Precolor(const IR::Program& program) {
|
||||
for (IR::Block* const block : program.blocks) {
|
||||
for (IR::Inst& phi : block->Instructions()) {
|
||||
if (!IR::IsPhi(phi)) {
|
||||
break;
|
||||
}
|
||||
PrecolorInst(phi);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EmitCode(EmitContext& ctx, const IR::Program& program) {
|
||||
for (const IR::AbstractSyntaxNode& node : program.syntax_list) {
|
||||
switch (node.type) {
|
||||
case IR::AbstractSyntaxNode::Type::Block:
|
||||
for (IR::Inst& inst : node.data.block->Instructions()) {
|
||||
EmitInst(ctx, &inst);
|
||||
}
|
||||
break;
|
||||
case IR::AbstractSyntaxNode::Type::If:
|
||||
ctx.Add("if({}){{", ctx.var_alloc.Consume(node.data.if_node.cond));
|
||||
break;
|
||||
case IR::AbstractSyntaxNode::Type::EndIf:
|
||||
ctx.Add("}}");
|
||||
break;
|
||||
case IR::AbstractSyntaxNode::Type::Break:
|
||||
if (node.data.break_node.cond.IsImmediate()) {
|
||||
if (node.data.break_node.cond.U1()) {
|
||||
ctx.Add("break;");
|
||||
}
|
||||
} else {
|
||||
ctx.Add("if({}){{break;}}", ctx.var_alloc.Consume(node.data.break_node.cond));
|
||||
}
|
||||
break;
|
||||
case IR::AbstractSyntaxNode::Type::Return:
|
||||
case IR::AbstractSyntaxNode::Type::Unreachable:
|
||||
ctx.Add("return;");
|
||||
break;
|
||||
case IR::AbstractSyntaxNode::Type::Loop:
|
||||
ctx.Add("for(;;){{");
|
||||
break;
|
||||
case IR::AbstractSyntaxNode::Type::Repeat:
|
||||
if (Settings::values.disable_shader_loop_safety_checks) {
|
||||
ctx.Add("if(!{}){{break;}}}}", ctx.var_alloc.Consume(node.data.repeat.cond));
|
||||
} else {
|
||||
ctx.Add("if(--loop{}<0 || !{}){{break;}}}}", ctx.num_safety_loop_vars++,
|
||||
ctx.var_alloc.Consume(node.data.repeat.cond));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw NotImplementedException("AbstractSyntaxNode Type {}", node.type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string GlslVersionSpecifier(const EmitContext& ctx) {
|
||||
if (ctx.uses_y_direction) {
|
||||
return " compatibility";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
bool IsPreciseType(GlslVarType type) {
|
||||
switch (type) {
|
||||
case GlslVarType::PrecF32:
|
||||
case GlslVarType::PrecF64:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void DefineVariables(const EmitContext& ctx, std::string& header) {
|
||||
for (u32 i = 0; i < static_cast<u32>(GlslVarType::Void); ++i) {
|
||||
const auto type{static_cast<GlslVarType>(i)};
|
||||
const auto& tracker{ctx.var_alloc.GetUseTracker(type)};
|
||||
const auto type_name{ctx.var_alloc.GetGlslType(type)};
|
||||
const bool has_precise_bug{ctx.stage == Stage::Fragment && ctx.profile.has_gl_precise_bug};
|
||||
const auto precise{!has_precise_bug && IsPreciseType(type) ? "precise " : ""};
|
||||
// Temps/return types that are never used are stored at index 0
|
||||
if (tracker.uses_temp) {
|
||||
header += fmt::format("{}{} t{}={}(0);", precise, type_name,
|
||||
ctx.var_alloc.Representation(0, type), type_name);
|
||||
}
|
||||
for (u32 index = 0; index < tracker.num_used; ++index) {
|
||||
header += fmt::format("{}{} {}={}(0);", precise, type_name,
|
||||
ctx.var_alloc.Representation(index, type), type_name);
|
||||
}
|
||||
}
|
||||
for (u32 i = 0; i < ctx.num_safety_loop_vars; ++i) {
|
||||
header += fmt::format("int loop{}=0x2000;", i);
|
||||
}
|
||||
}
|
||||
} // Anonymous namespace
|
||||
|
||||
std::string EmitGLSL(const Profile& profile, const RuntimeInfo& runtime_info, IR::Program& program,
|
||||
Bindings& bindings) {
|
||||
EmitContext ctx{program, bindings, profile, runtime_info};
|
||||
Precolor(program);
|
||||
EmitCode(ctx, program);
|
||||
const std::string version{fmt::format("#version 460{}\n", GlslVersionSpecifier(ctx))};
|
||||
ctx.header.insert(0, version);
|
||||
if (program.shared_memory_size > 0) {
|
||||
const auto requested_size{program.shared_memory_size};
|
||||
const auto max_size{profile.gl_max_compute_smem_size};
|
||||
const bool needs_clamp{requested_size > max_size};
|
||||
if (needs_clamp) {
|
||||
LOG_WARNING(Shader_GLSL, "Requested shared memory size ({}) exceeds device limit ({})",
|
||||
requested_size, max_size);
|
||||
}
|
||||
const auto smem_size{needs_clamp ? max_size : requested_size};
|
||||
ctx.header += fmt::format("shared uint smem[{}];", Common::DivCeil(smem_size, 4U));
|
||||
}
|
||||
ctx.header += "void main(){\n";
|
||||
if (program.local_memory_size > 0) {
|
||||
ctx.header += fmt::format("uint lmem[{}];", Common::DivCeil(program.local_memory_size, 4U));
|
||||
}
|
||||
DefineVariables(ctx, ctx.header);
|
||||
if (ctx.uses_cc_carry) {
|
||||
ctx.header += "uint carry;";
|
||||
}
|
||||
if (program.info.uses_subgroup_shuffles) {
|
||||
ctx.header += "bool shfl_in_bounds;";
|
||||
ctx.header += "uint shfl_result;";
|
||||
}
|
||||
ctx.code.insert(0, ctx.header);
|
||||
ctx.code += '}';
|
||||
return ctx.code;
|
||||
}
|
||||
|
||||
} // namespace Shader::Backend::GLSL
|
||||
23
gpu/third_party/suyu/shader_recompiler/backend/glsl/emit_glsl.h
vendored
Normal file
23
gpu/third_party/suyu/shader_recompiler/backend/glsl/emit_glsl.h
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "shader_recompiler/backend/bindings.h"
|
||||
#include "shader_recompiler/frontend/ir/program.h"
|
||||
#include "shader_recompiler/profile.h"
|
||||
#include "shader_recompiler/runtime_info.h"
|
||||
|
||||
namespace Shader::Backend::GLSL {
|
||||
|
||||
[[nodiscard]] std::string EmitGLSL(const Profile& profile, const RuntimeInfo& runtime_info,
|
||||
IR::Program& program, Bindings& bindings);
|
||||
|
||||
[[nodiscard]] inline std::string EmitGLSL(const Profile& profile, IR::Program& program) {
|
||||
Bindings binding;
|
||||
return EmitGLSL(profile, {}, program, binding);
|
||||
}
|
||||
|
||||
} // namespace Shader::Backend::GLSL
|
||||
559
gpu/third_party/suyu/shader_recompiler/backend/glsl/emit_glsl_atomic.cpp
vendored
Normal file
559
gpu/third_party/suyu/shader_recompiler/backend/glsl/emit_glsl_atomic.cpp
vendored
Normal file
@@ -0,0 +1,559 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <string_view>
|
||||
|
||||
#include "shader_recompiler/backend/glsl/emit_glsl_instructions.h"
|
||||
#include "shader_recompiler/backend/glsl/glsl_emit_context.h"
|
||||
#include "shader_recompiler/frontend/ir/value.h"
|
||||
|
||||
namespace Shader::Backend::GLSL {
|
||||
namespace {
|
||||
constexpr char cas_loop[]{
|
||||
"for (;;){{uint old={};{}=atomicCompSwap({},old,{}({},{}));if({}==old){{break;}}}}"};
|
||||
|
||||
void SharedCasFunction(EmitContext& ctx, IR::Inst& inst, std::string_view offset,
|
||||
std::string_view value, std::string_view function) {
|
||||
const auto ret{ctx.var_alloc.Define(inst, GlslVarType::U32)};
|
||||
const std::string smem{fmt::format("smem[{}>>2]", offset)};
|
||||
ctx.Add(cas_loop, smem, ret, smem, function, smem, value, ret);
|
||||
}
|
||||
|
||||
void SsboCasFunction(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value, std::string_view function) {
|
||||
const auto ret{ctx.var_alloc.Define(inst, GlslVarType::U32)};
|
||||
const std::string ssbo{fmt::format("{}_ssbo{}[{}>>2]", ctx.stage_name, binding.U32(),
|
||||
ctx.var_alloc.Consume(offset))};
|
||||
ctx.Add(cas_loop, ssbo, ret, ssbo, function, ssbo, value, ret);
|
||||
}
|
||||
|
||||
void SsboCasFunctionF32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value,
|
||||
std::string_view function) {
|
||||
const std::string ssbo{fmt::format("{}_ssbo{}[{}>>2]", ctx.stage_name, binding.U32(),
|
||||
ctx.var_alloc.Consume(offset))};
|
||||
const auto ret{ctx.var_alloc.Define(inst, GlslVarType::U32)};
|
||||
ctx.Add(cas_loop, ssbo, ret, ssbo, function, ssbo, value, ret);
|
||||
ctx.AddF32("{}=utof({});", inst, ret);
|
||||
}
|
||||
} // Anonymous namespace
|
||||
|
||||
void EmitSharedAtomicIAdd32(EmitContext& ctx, IR::Inst& inst, std::string_view pointer_offset,
|
||||
std::string_view value) {
|
||||
ctx.AddU32("{}=atomicAdd(smem[{}>>2],{});", inst, pointer_offset, value);
|
||||
}
|
||||
|
||||
void EmitSharedAtomicSMin32(EmitContext& ctx, IR::Inst& inst, std::string_view pointer_offset,
|
||||
std::string_view value) {
|
||||
const std::string u32_value{fmt::format("uint({})", value)};
|
||||
SharedCasFunction(ctx, inst, pointer_offset, u32_value, "CasMinS32");
|
||||
}
|
||||
|
||||
void EmitSharedAtomicUMin32(EmitContext& ctx, IR::Inst& inst, std::string_view pointer_offset,
|
||||
std::string_view value) {
|
||||
ctx.AddU32("{}=atomicMin(smem[{}>>2],{});", inst, pointer_offset, value);
|
||||
}
|
||||
|
||||
void EmitSharedAtomicSMax32(EmitContext& ctx, IR::Inst& inst, std::string_view pointer_offset,
|
||||
std::string_view value) {
|
||||
const std::string u32_value{fmt::format("uint({})", value)};
|
||||
SharedCasFunction(ctx, inst, pointer_offset, u32_value, "CasMaxS32");
|
||||
}
|
||||
|
||||
void EmitSharedAtomicUMax32(EmitContext& ctx, IR::Inst& inst, std::string_view pointer_offset,
|
||||
std::string_view value) {
|
||||
ctx.AddU32("{}=atomicMax(smem[{}>>2],{});", inst, pointer_offset, value);
|
||||
}
|
||||
|
||||
void EmitSharedAtomicInc32(EmitContext& ctx, IR::Inst& inst, std::string_view pointer_offset,
|
||||
std::string_view value) {
|
||||
SharedCasFunction(ctx, inst, pointer_offset, value, "CasIncrement");
|
||||
}
|
||||
|
||||
void EmitSharedAtomicDec32(EmitContext& ctx, IR::Inst& inst, std::string_view pointer_offset,
|
||||
std::string_view value) {
|
||||
SharedCasFunction(ctx, inst, pointer_offset, value, "CasDecrement");
|
||||
}
|
||||
|
||||
void EmitSharedAtomicAnd32(EmitContext& ctx, IR::Inst& inst, std::string_view pointer_offset,
|
||||
std::string_view value) {
|
||||
ctx.AddU32("{}=atomicAnd(smem[{}>>2],{});", inst, pointer_offset, value);
|
||||
}
|
||||
|
||||
void EmitSharedAtomicOr32(EmitContext& ctx, IR::Inst& inst, std::string_view pointer_offset,
|
||||
std::string_view value) {
|
||||
ctx.AddU32("{}=atomicOr(smem[{}>>2],{});", inst, pointer_offset, value);
|
||||
}
|
||||
|
||||
void EmitSharedAtomicXor32(EmitContext& ctx, IR::Inst& inst, std::string_view pointer_offset,
|
||||
std::string_view value) {
|
||||
ctx.AddU32("{}=atomicXor(smem[{}>>2],{});", inst, pointer_offset, value);
|
||||
}
|
||||
|
||||
void EmitSharedAtomicExchange32(EmitContext& ctx, IR::Inst& inst, std::string_view pointer_offset,
|
||||
std::string_view value) {
|
||||
ctx.AddU32("{}=atomicExchange(smem[{}>>2],{});", inst, pointer_offset, value);
|
||||
}
|
||||
|
||||
void EmitSharedAtomicExchange64(EmitContext& ctx, IR::Inst& inst, std::string_view pointer_offset,
|
||||
std::string_view value) {
|
||||
LOG_WARNING(Shader_GLSL, "Int64 atomics not supported, fallback to non-atomic");
|
||||
ctx.AddU64("{}=packUint2x32(uvec2(smem[{}>>2],smem[({}+4)>>2]));", inst, pointer_offset,
|
||||
pointer_offset);
|
||||
ctx.Add("smem[{}>>2]=unpackUint2x32({}).x;smem[({}+4)>>2]=unpackUint2x32({}).y;",
|
||||
pointer_offset, value, pointer_offset, value);
|
||||
}
|
||||
|
||||
void EmitSharedAtomicExchange32x2(EmitContext& ctx, IR::Inst& inst, std::string_view pointer_offset,
|
||||
std::string_view value) {
|
||||
LOG_WARNING(Shader_GLSL, "Int64 atomics not supported, fallback to non-atomic");
|
||||
ctx.AddU32x2("{}=uvec2(smem[{}>>2],smem[({}+4)>>2]);", inst, pointer_offset, pointer_offset);
|
||||
ctx.Add("smem[{}>>2]={}.x;smem[({}+4)>>2]={}.y;", pointer_offset, value, pointer_offset, value);
|
||||
}
|
||||
|
||||
void EmitStorageAtomicIAdd32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
ctx.AddU32("{}=atomicAdd({}_ssbo{}[{}>>2],{});", inst, ctx.stage_name, binding.U32(),
|
||||
ctx.var_alloc.Consume(offset), value);
|
||||
}
|
||||
|
||||
void EmitStorageAtomicSMin32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
const std::string u32_value{fmt::format("uint({})", value)};
|
||||
SsboCasFunction(ctx, inst, binding, offset, u32_value, "CasMinS32");
|
||||
}
|
||||
|
||||
void EmitStorageAtomicUMin32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
ctx.AddU32("{}=atomicMin({}_ssbo{}[{}>>2],{});", inst, ctx.stage_name, binding.U32(),
|
||||
ctx.var_alloc.Consume(offset), value);
|
||||
}
|
||||
|
||||
void EmitStorageAtomicSMax32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
const std::string u32_value{fmt::format("uint({})", value)};
|
||||
SsboCasFunction(ctx, inst, binding, offset, u32_value, "CasMaxS32");
|
||||
}
|
||||
|
||||
void EmitStorageAtomicUMax32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
ctx.AddU32("{}=atomicMax({}_ssbo{}[{}>>2],{});", inst, ctx.stage_name, binding.U32(),
|
||||
ctx.var_alloc.Consume(offset), value);
|
||||
}
|
||||
|
||||
void EmitStorageAtomicInc32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
SsboCasFunction(ctx, inst, binding, offset, value, "CasIncrement");
|
||||
}
|
||||
|
||||
void EmitStorageAtomicDec32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
SsboCasFunction(ctx, inst, binding, offset, value, "CasDecrement");
|
||||
}
|
||||
|
||||
void EmitStorageAtomicAnd32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
ctx.AddU32("{}=atomicAnd({}_ssbo{}[{}>>2],{});", inst, ctx.stage_name, binding.U32(),
|
||||
ctx.var_alloc.Consume(offset), value);
|
||||
}
|
||||
|
||||
void EmitStorageAtomicOr32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
ctx.AddU32("{}=atomicOr({}_ssbo{}[{}>>2],{});", inst, ctx.stage_name, binding.U32(),
|
||||
ctx.var_alloc.Consume(offset), value);
|
||||
}
|
||||
|
||||
void EmitStorageAtomicXor32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
ctx.AddU32("{}=atomicXor({}_ssbo{}[{}>>2],{});", inst, ctx.stage_name, binding.U32(),
|
||||
ctx.var_alloc.Consume(offset), value);
|
||||
}
|
||||
|
||||
void EmitStorageAtomicExchange32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
ctx.AddU32("{}=atomicExchange({}_ssbo{}[{}>>2],{});", inst, ctx.stage_name, binding.U32(),
|
||||
ctx.var_alloc.Consume(offset), value);
|
||||
}
|
||||
|
||||
void EmitStorageAtomicIAdd64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
LOG_WARNING(Shader_GLSL, "Int64 atomics not supported, fallback to non-atomic");
|
||||
ctx.AddU64("{}=packUint2x32(uvec2({}_ssbo{}[{}>>2],{}_ssbo{}[({}>>2)+1]));", inst,
|
||||
ctx.stage_name, binding.U32(), ctx.var_alloc.Consume(offset), ctx.stage_name,
|
||||
binding.U32(), ctx.var_alloc.Consume(offset));
|
||||
ctx.Add("{}_ssbo{}[{}>>2]+=unpackUint2x32({}).x;{}_ssbo{}[({}>>2)+1]+=unpackUint2x32({}).y;",
|
||||
ctx.stage_name, binding.U32(), ctx.var_alloc.Consume(offset), value, ctx.stage_name,
|
||||
binding.U32(), ctx.var_alloc.Consume(offset), value);
|
||||
}
|
||||
|
||||
void EmitStorageAtomicSMin64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
LOG_WARNING(Shader_GLSL, "Int64 atomics not supported, fallback to non-atomic");
|
||||
ctx.AddU64("{}=packInt2x32(ivec2({}_ssbo{}[{}>>2],{}_ssbo{}[({}>>2)+1]));", inst,
|
||||
ctx.stage_name, binding.U32(), ctx.var_alloc.Consume(offset), ctx.stage_name,
|
||||
binding.U32(), ctx.var_alloc.Consume(offset));
|
||||
ctx.Add("for(int i=0;i<2;++i){{ "
|
||||
"{}_ssbo{}[({}>>2)+i]=uint(min(int({}_ssbo{}[({}>>2)+i]),unpackInt2x32(int64_t({}))[i])"
|
||||
");}}",
|
||||
ctx.stage_name, binding.U32(), ctx.var_alloc.Consume(offset), ctx.stage_name,
|
||||
binding.U32(), ctx.var_alloc.Consume(offset), value);
|
||||
}
|
||||
|
||||
void EmitStorageAtomicUMin64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
LOG_WARNING(Shader_GLSL, "Int64 atomics not supported, fallback to non-atomic");
|
||||
ctx.AddU64("{}=packUint2x32(uvec2({}_ssbo{}[{}>>2],{}_ssbo{}[({}>>2)+1]));", inst,
|
||||
ctx.stage_name, binding.U32(), ctx.var_alloc.Consume(offset), ctx.stage_name,
|
||||
binding.U32(), ctx.var_alloc.Consume(offset));
|
||||
ctx.Add("for(int i=0;i<2;++i){{ "
|
||||
"{}_ssbo{}[({}>>2)+i]=min({}_ssbo{}[({}>>2)+i],unpackUint2x32(uint64_t({}))[i]);}}",
|
||||
ctx.stage_name, binding.U32(), ctx.var_alloc.Consume(offset), ctx.stage_name,
|
||||
binding.U32(), ctx.var_alloc.Consume(offset), value);
|
||||
}
|
||||
|
||||
void EmitStorageAtomicSMax64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
LOG_WARNING(Shader_GLSL, "Int64 atomics not supported, fallback to non-atomic");
|
||||
ctx.AddU64("{}=packInt2x32(ivec2({}_ssbo{}[{}>>2],{}_ssbo{}[({}>>2)+1]));", inst,
|
||||
ctx.stage_name, binding.U32(), ctx.var_alloc.Consume(offset), ctx.stage_name,
|
||||
binding.U32(), ctx.var_alloc.Consume(offset));
|
||||
ctx.Add("for(int i=0;i<2;++i){{ "
|
||||
"{}_ssbo{}[({}>>2)+i]=uint(max(int({}_ssbo{}[({}>>2)+i]),unpackInt2x32(int64_t({}))[i])"
|
||||
");}}",
|
||||
ctx.stage_name, binding.U32(), ctx.var_alloc.Consume(offset), ctx.stage_name,
|
||||
binding.U32(), ctx.var_alloc.Consume(offset), value);
|
||||
}
|
||||
|
||||
void EmitStorageAtomicUMax64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
LOG_WARNING(Shader_GLSL, "Int64 atomics not supported, fallback to non-atomic");
|
||||
ctx.AddU64("{}=packUint2x32(uvec2({}_ssbo{}[{}>>2],{}_ssbo{}[({}>>2)+1]));", inst,
|
||||
ctx.stage_name, binding.U32(), ctx.var_alloc.Consume(offset), ctx.stage_name,
|
||||
binding.U32(), ctx.var_alloc.Consume(offset));
|
||||
ctx.Add("for(int "
|
||||
"i=0;i<2;++i){{{}_ssbo{}[({}>>2)+i]=max({}_ssbo{}[({}>>2)+i],unpackUint2x32(uint64_t({}"
|
||||
"))[i]);}}",
|
||||
ctx.stage_name, binding.U32(), ctx.var_alloc.Consume(offset), ctx.stage_name,
|
||||
binding.U32(), ctx.var_alloc.Consume(offset), value);
|
||||
}
|
||||
|
||||
void EmitStorageAtomicAnd64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
ctx.AddU64(
|
||||
"{}=packUint2x32(uvec2(atomicAnd({}_ssbo{}[{}>>2],unpackUint2x32({}).x),atomicAnd({}_"
|
||||
"ssbo{}[({}>>2)+1],unpackUint2x32({}).y)));",
|
||||
inst, ctx.stage_name, binding.U32(), ctx.var_alloc.Consume(offset), value, ctx.stage_name,
|
||||
binding.U32(), ctx.var_alloc.Consume(offset), value);
|
||||
}
|
||||
|
||||
void EmitStorageAtomicOr64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
ctx.AddU64("{}=packUint2x32(uvec2(atomicOr({}_ssbo{}[{}>>2],unpackUint2x32({}).x),atomicOr({}_"
|
||||
"ssbo{}[({}>>2)+1],unpackUint2x32({}).y)));",
|
||||
inst, ctx.stage_name, binding.U32(), ctx.var_alloc.Consume(offset), value,
|
||||
ctx.stage_name, binding.U32(), ctx.var_alloc.Consume(offset), value);
|
||||
}
|
||||
|
||||
void EmitStorageAtomicXor64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
ctx.AddU64(
|
||||
"{}=packUint2x32(uvec2(atomicXor({}_ssbo{}[{}>>2],unpackUint2x32({}).x),atomicXor({}_"
|
||||
"ssbo{}[({}>>2)+1],unpackUint2x32({}).y)));",
|
||||
inst, ctx.stage_name, binding.U32(), ctx.var_alloc.Consume(offset), value, ctx.stage_name,
|
||||
binding.U32(), ctx.var_alloc.Consume(offset), value);
|
||||
}
|
||||
|
||||
void EmitStorageAtomicExchange64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
ctx.AddU64("{}=packUint2x32(uvec2(atomicExchange({}_ssbo{}[{}>>2],unpackUint2x32({}).x),"
|
||||
"atomicExchange({}_ssbo{}[({}>>2)+1],unpackUint2x32({}).y)));",
|
||||
inst, ctx.stage_name, binding.U32(), ctx.var_alloc.Consume(offset), value,
|
||||
ctx.stage_name, binding.U32(), ctx.var_alloc.Consume(offset), value);
|
||||
}
|
||||
|
||||
void EmitStorageAtomicIAdd32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
LOG_WARNING(Shader_GLSL, "Int64 atomics not supported, fallback to non-atomic");
|
||||
ctx.AddU32x2("{}=uvec2({}_ssbo{}[{}>>2],{}_ssbo{}[({}>>2)+1]);", inst, ctx.stage_name,
|
||||
binding.U32(), ctx.var_alloc.Consume(offset), ctx.stage_name, binding.U32(),
|
||||
ctx.var_alloc.Consume(offset));
|
||||
ctx.Add("{}_ssbo{}[{}>>2]+={}.x;{}_ssbo{}[({}>>2)+1]+={}.y;", ctx.stage_name, binding.U32(),
|
||||
ctx.var_alloc.Consume(offset), value, ctx.stage_name, binding.U32(),
|
||||
ctx.var_alloc.Consume(offset), value);
|
||||
}
|
||||
|
||||
void EmitStorageAtomicSMin32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
LOG_WARNING(Shader_GLSL, "Int64 atomics not supported, fallback to non-atomic");
|
||||
ctx.AddU32x2("{}=ivec2({}_ssbo{}[{}>>2],{}_ssbo{}[({}>>2)+1]);", inst, ctx.stage_name,
|
||||
binding.U32(), ctx.var_alloc.Consume(offset), ctx.stage_name, binding.U32(),
|
||||
ctx.var_alloc.Consume(offset));
|
||||
ctx.Add("for(int "
|
||||
"i=0;i<2;++i){{{}_ssbo{}[({}>>2)+i]=uint(min(int({}_ssbo{}[({}>>2)+i]),int({}[i])));}}",
|
||||
ctx.stage_name, binding.U32(), ctx.var_alloc.Consume(offset), ctx.stage_name,
|
||||
binding.U32(), ctx.var_alloc.Consume(offset), value);
|
||||
}
|
||||
|
||||
void EmitStorageAtomicUMin32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
LOG_WARNING(Shader_GLSL, "Int64 atomics not supported, fallback to non-atomic");
|
||||
ctx.AddU32x2("{}=uvec2({}_ssbo{}[{}>>2],{}_ssbo{}[({}>>2)+1]);", inst, ctx.stage_name,
|
||||
binding.U32(), ctx.var_alloc.Consume(offset), ctx.stage_name, binding.U32(),
|
||||
ctx.var_alloc.Consume(offset));
|
||||
ctx.Add("for(int i=0;i<2;++i){{ "
|
||||
"{}_ssbo{}[({}>>2)+i]=min({}_ssbo{}[({}>>2)+i],{}[i]);}}",
|
||||
ctx.stage_name, binding.U32(), ctx.var_alloc.Consume(offset), ctx.stage_name,
|
||||
binding.U32(), ctx.var_alloc.Consume(offset), value);
|
||||
}
|
||||
|
||||
void EmitStorageAtomicSMax32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
LOG_WARNING(Shader_GLSL, "Int64 atomics not supported, fallback to non-atomic");
|
||||
ctx.AddU32x2("{}=ivec2({}_ssbo{}[{}>>2],{}_ssbo{}[({}>>2)+1]);", inst, ctx.stage_name,
|
||||
binding.U32(), ctx.var_alloc.Consume(offset), ctx.stage_name, binding.U32(),
|
||||
ctx.var_alloc.Consume(offset));
|
||||
ctx.Add("for(int "
|
||||
"i=0;i<2;++i){{{}_ssbo{}[({}>>2)+i]=uint(max(int({}_ssbo{}[({}>>2)+i]),int({}[i])));}}",
|
||||
ctx.stage_name, binding.U32(), ctx.var_alloc.Consume(offset), ctx.stage_name,
|
||||
binding.U32(), ctx.var_alloc.Consume(offset), value);
|
||||
}
|
||||
|
||||
void EmitStorageAtomicUMax32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
LOG_WARNING(Shader_GLSL, "Int64 atomics not supported, fallback to non-atomic");
|
||||
ctx.AddU32x2("{}=uvec2({}_ssbo{}[{}>>2],{}_ssbo{}[({}>>2)+1]);", inst, ctx.stage_name,
|
||||
binding.U32(), ctx.var_alloc.Consume(offset), ctx.stage_name, binding.U32(),
|
||||
ctx.var_alloc.Consume(offset));
|
||||
ctx.Add("for(int i=0;i<2;++i){{{}_ssbo{}[({}>>2)+i]=max({}_ssbo{}[({}>>2)+i],{}[i]);}}",
|
||||
ctx.stage_name, binding.U32(), ctx.var_alloc.Consume(offset), ctx.stage_name,
|
||||
binding.U32(), ctx.var_alloc.Consume(offset), value);
|
||||
}
|
||||
|
||||
void EmitStorageAtomicAnd32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
LOG_WARNING(Shader_GLSL, "Int64 atomics not supported, fallback to 32x2");
|
||||
ctx.AddU32x2("{}=uvec2(atomicAnd({}_ssbo{}[{}>>2],{}.x),atomicAnd({}_ssbo{}[({}>>2)+1],{}.y));",
|
||||
inst, ctx.stage_name, binding.U32(), ctx.var_alloc.Consume(offset), value,
|
||||
ctx.stage_name, binding.U32(), ctx.var_alloc.Consume(offset), value);
|
||||
}
|
||||
|
||||
void EmitStorageAtomicOr32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
LOG_WARNING(Shader_GLSL, "Int64 atomics not supported, fallback to 32x2");
|
||||
ctx.AddU32x2("{}=uvec2(atomicOr({}_ssbo{}[{}>>2],{}.x),atomicOr({}_ssbo{}[({}>>2)+1],{}.y));",
|
||||
inst, ctx.stage_name, binding.U32(), ctx.var_alloc.Consume(offset), value,
|
||||
ctx.stage_name, binding.U32(), ctx.var_alloc.Consume(offset), value);
|
||||
}
|
||||
|
||||
void EmitStorageAtomicXor32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
LOG_WARNING(Shader_GLSL, "Int64 atomics not supported, fallback to 32x2");
|
||||
ctx.AddU32x2("{}=uvec2(atomicXor({}_ssbo{}[{}>>2],{}.x),atomicXor({}_ssbo{}[({}>>2)+1],{}.y));",
|
||||
inst, ctx.stage_name, binding.U32(), ctx.var_alloc.Consume(offset), value,
|
||||
ctx.stage_name, binding.U32(), ctx.var_alloc.Consume(offset), value);
|
||||
}
|
||||
|
||||
void EmitStorageAtomicExchange32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
LOG_WARNING(Shader_GLSL, "Int64 atomics not supported, fallback to 32x2");
|
||||
ctx.AddU32x2("{}=uvec2(atomicExchange({}_ssbo{}[{}>>2],{}.x),atomicExchange({}_ssbo{}[({}>>2)+"
|
||||
"1],{}.y));",
|
||||
inst, ctx.stage_name, binding.U32(), ctx.var_alloc.Consume(offset), value,
|
||||
ctx.stage_name, binding.U32(), ctx.var_alloc.Consume(offset), value);
|
||||
}
|
||||
|
||||
void EmitStorageAtomicAddF32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
SsboCasFunctionF32(ctx, inst, binding, offset, value, "CasFloatAdd");
|
||||
}
|
||||
|
||||
void EmitStorageAtomicAddF16x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
SsboCasFunction(ctx, inst, binding, offset, value, "CasFloatAdd16x2");
|
||||
}
|
||||
|
||||
void EmitStorageAtomicAddF32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
SsboCasFunction(ctx, inst, binding, offset, value, "CasFloatAdd32x2");
|
||||
}
|
||||
|
||||
void EmitStorageAtomicMinF16x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
SsboCasFunction(ctx, inst, binding, offset, value, "CasFloatMin16x2");
|
||||
}
|
||||
|
||||
void EmitStorageAtomicMinF32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
SsboCasFunction(ctx, inst, binding, offset, value, "CasFloatMin32x2");
|
||||
}
|
||||
|
||||
void EmitStorageAtomicMaxF16x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
SsboCasFunction(ctx, inst, binding, offset, value, "CasFloatMax16x2");
|
||||
}
|
||||
|
||||
void EmitStorageAtomicMaxF32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
SsboCasFunction(ctx, inst, binding, offset, value, "CasFloatMax32x2");
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicIAdd32(EmitContext&) {
|
||||
throw NotImplementedException("GLSL Instruction");
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicSMin32(EmitContext&) {
|
||||
throw NotImplementedException("GLSL Instruction");
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicUMin32(EmitContext&) {
|
||||
throw NotImplementedException("GLSL Instruction");
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicSMax32(EmitContext&) {
|
||||
throw NotImplementedException("GLSL Instruction");
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicUMax32(EmitContext&) {
|
||||
throw NotImplementedException("GLSL Instruction");
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicInc32(EmitContext&) {
|
||||
throw NotImplementedException("GLSL Instruction");
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicDec32(EmitContext&) {
|
||||
throw NotImplementedException("GLSL Instruction");
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicAnd32(EmitContext&) {
|
||||
throw NotImplementedException("GLSL Instruction");
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicOr32(EmitContext&) {
|
||||
throw NotImplementedException("GLSL Instruction");
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicXor32(EmitContext&) {
|
||||
throw NotImplementedException("GLSL Instruction");
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicExchange32(EmitContext&) {
|
||||
throw NotImplementedException("GLSL Instruction");
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicIAdd64(EmitContext&) {
|
||||
throw NotImplementedException("GLSL Instruction");
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicSMin64(EmitContext&) {
|
||||
throw NotImplementedException("GLSL Instruction");
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicUMin64(EmitContext&) {
|
||||
throw NotImplementedException("GLSL Instruction");
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicSMax64(EmitContext&) {
|
||||
throw NotImplementedException("GLSL Instruction");
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicUMax64(EmitContext&) {
|
||||
throw NotImplementedException("GLSL Instruction");
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicInc64(EmitContext&) {
|
||||
throw NotImplementedException("GLSL Instruction");
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicDec64(EmitContext&) {
|
||||
throw NotImplementedException("GLSL Instruction");
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicAnd64(EmitContext&) {
|
||||
throw NotImplementedException("GLSL Instruction");
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicOr64(EmitContext&) {
|
||||
throw NotImplementedException("GLSL Instruction");
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicXor64(EmitContext&) {
|
||||
throw NotImplementedException("GLSL Instruction");
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicExchange64(EmitContext&) {
|
||||
throw NotImplementedException("GLSL Instruction");
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicIAdd32x2(EmitContext&) {
|
||||
throw NotImplementedException("GLSL Instruction");
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicSMin32x2(EmitContext&) {
|
||||
throw NotImplementedException("GLSL Instruction");
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicUMin32x2(EmitContext&) {
|
||||
throw NotImplementedException("GLSL Instruction");
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicSMax32x2(EmitContext&) {
|
||||
throw NotImplementedException("GLSL Instruction");
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicUMax32x2(EmitContext&) {
|
||||
throw NotImplementedException("GLSL Instruction");
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicInc32x2(EmitContext&) {
|
||||
throw NotImplementedException("GLSL Instruction");
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicDec32x2(EmitContext&) {
|
||||
throw NotImplementedException("GLSL Instruction");
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicAnd32x2(EmitContext&) {
|
||||
throw NotImplementedException("GLSL Instruction");
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicOr32x2(EmitContext&) {
|
||||
throw NotImplementedException("GLSL Instruction");
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicXor32x2(EmitContext&) {
|
||||
throw NotImplementedException("GLSL Instruction");
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicExchange32x2(EmitContext&) {
|
||||
throw NotImplementedException("GLSL Instruction");
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicAddF32(EmitContext&) {
|
||||
throw NotImplementedException("GLSL Instruction");
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicAddF16x2(EmitContext&) {
|
||||
throw NotImplementedException("GLSL Instruction");
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicAddF32x2(EmitContext&) {
|
||||
throw NotImplementedException("GLSL Instruction");
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicMinF16x2(EmitContext&) {
|
||||
throw NotImplementedException("GLSL Instruction");
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicMinF32x2(EmitContext&) {
|
||||
throw NotImplementedException("GLSL Instruction");
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicMaxF16x2(EmitContext&) {
|
||||
throw NotImplementedException("GLSL Instruction");
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicMaxF32x2(EmitContext&) {
|
||||
throw NotImplementedException("GLSL Instruction");
|
||||
}
|
||||
} // namespace Shader::Backend::GLSL
|
||||
19
gpu/third_party/suyu/shader_recompiler/backend/glsl/emit_glsl_barriers.cpp
vendored
Normal file
19
gpu/third_party/suyu/shader_recompiler/backend/glsl/emit_glsl_barriers.cpp
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "shader_recompiler/backend/glsl/emit_glsl_instructions.h"
|
||||
#include "shader_recompiler/backend/glsl/glsl_emit_context.h"
|
||||
|
||||
namespace Shader::Backend::GLSL {
|
||||
void EmitBarrier(EmitContext& ctx) {
|
||||
ctx.Add("barrier();");
|
||||
}
|
||||
|
||||
void EmitWorkgroupMemoryBarrier(EmitContext& ctx) {
|
||||
ctx.Add("groupMemoryBarrier();");
|
||||
}
|
||||
|
||||
void EmitDeviceMemoryBarrier(EmitContext& ctx) {
|
||||
ctx.Add("memoryBarrier();");
|
||||
}
|
||||
} // namespace Shader::Backend::GLSL
|
||||
95
gpu/third_party/suyu/shader_recompiler/backend/glsl/emit_glsl_bitwise_conversion.cpp
vendored
Normal file
95
gpu/third_party/suyu/shader_recompiler/backend/glsl/emit_glsl_bitwise_conversion.cpp
vendored
Normal file
@@ -0,0 +1,95 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <string_view>
|
||||
|
||||
#include "shader_recompiler/backend/glsl/emit_glsl_instructions.h"
|
||||
#include "shader_recompiler/backend/glsl/glsl_emit_context.h"
|
||||
#include "shader_recompiler/frontend/ir/value.h"
|
||||
#include "shader_recompiler/profile.h"
|
||||
|
||||
namespace Shader::Backend::GLSL {
|
||||
namespace {
|
||||
void Alias(IR::Inst& inst, const IR::Value& value) {
|
||||
if (value.IsImmediate()) {
|
||||
return;
|
||||
}
|
||||
IR::Inst& value_inst{*value.InstRecursive()};
|
||||
value_inst.DestructiveAddUsage(inst.UseCount());
|
||||
value_inst.DestructiveRemoveUsage();
|
||||
inst.SetDefinition(value_inst.Definition<Id>());
|
||||
}
|
||||
} // Anonymous namespace
|
||||
|
||||
void EmitIdentity(EmitContext&, IR::Inst& inst, const IR::Value& value) {
|
||||
Alias(inst, value);
|
||||
}
|
||||
|
||||
void EmitConditionRef(EmitContext& ctx, IR::Inst& inst, const IR::Value& value) {
|
||||
// Fake one usage to get a real variable out of the condition
|
||||
inst.DestructiveAddUsage(1);
|
||||
const auto ret{ctx.var_alloc.Define(inst, GlslVarType::U1)};
|
||||
const auto input{ctx.var_alloc.Consume(value)};
|
||||
const auto suffix{ctx.profile.has_gl_bool_ref_bug ? "?true:false" : ""};
|
||||
if (ret != input) {
|
||||
ctx.Add("{}={}{};", ret, input, suffix);
|
||||
}
|
||||
}
|
||||
|
||||
void EmitBitCastU16F16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBitCastU32F32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddU32("{}=ftou({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitBitCastU64F64(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddU64("{}=doubleBitsToUint64({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitBitCastF16U16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBitCastF32U32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddF32("{}=utof({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitBitCastF64U64(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddF64("{}=uint64BitsToDouble({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitPackUint2x32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddU64("{}=packUint2x32({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitUnpackUint2x32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddU32x2("{}=unpackUint2x32({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitPackFloat2x16(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddU32("{}=packFloat2x16({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitUnpackFloat2x16(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddF16x2("{}=unpackFloat2x16({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitPackHalf2x16(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddU32("{}=packHalf2x16({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitUnpackHalf2x16(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddF32x2("{}=unpackHalf2x16({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitPackDouble2x32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddF64("{}=packDouble2x32({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitUnpackDouble2x32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddU32x2("{}=unpackDouble2x32({});", inst, value);
|
||||
}
|
||||
|
||||
} // namespace Shader::Backend::GLSL
|
||||
218
gpu/third_party/suyu/shader_recompiler/backend/glsl/emit_glsl_composite.cpp
vendored
Normal file
218
gpu/third_party/suyu/shader_recompiler/backend/glsl/emit_glsl_composite.cpp
vendored
Normal file
@@ -0,0 +1,218 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <string_view>
|
||||
|
||||
#include "shader_recompiler/backend/glsl/emit_glsl_instructions.h"
|
||||
#include "shader_recompiler/backend/glsl/glsl_emit_context.h"
|
||||
#include "shader_recompiler/frontend/ir/value.h"
|
||||
|
||||
namespace Shader::Backend::GLSL {
|
||||
namespace {
|
||||
constexpr std::string_view SWIZZLE{"xyzw"};
|
||||
void CompositeInsert(EmitContext& ctx, std::string_view result, std::string_view composite,
|
||||
std::string_view object, u32 index) {
|
||||
if (result == composite) {
|
||||
// The result is aliased with the composite
|
||||
ctx.Add("{}.{}={};", composite, SWIZZLE[index], object);
|
||||
} else {
|
||||
ctx.Add("{}={};{}.{}={};", result, composite, result, SWIZZLE[index], object);
|
||||
}
|
||||
}
|
||||
} // Anonymous namespace
|
||||
|
||||
void EmitCompositeConstructU32x2(EmitContext& ctx, IR::Inst& inst, std::string_view e1,
|
||||
std::string_view e2) {
|
||||
ctx.AddU32x2("{}=uvec2({},{});", inst, e1, e2);
|
||||
}
|
||||
|
||||
void EmitCompositeConstructU32x3(EmitContext& ctx, IR::Inst& inst, std::string_view e1,
|
||||
std::string_view e2, std::string_view e3) {
|
||||
ctx.AddU32x3("{}=uvec3({},{},{});", inst, e1, e2, e3);
|
||||
}
|
||||
|
||||
void EmitCompositeConstructU32x4(EmitContext& ctx, IR::Inst& inst, std::string_view e1,
|
||||
std::string_view e2, std::string_view e3, std::string_view e4) {
|
||||
ctx.AddU32x4("{}=uvec4({},{},{},{});", inst, e1, e2, e3, e4);
|
||||
}
|
||||
|
||||
void EmitCompositeExtractU32x2(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
|
||||
u32 index) {
|
||||
ctx.AddU32("{}={}.{};", inst, composite, SWIZZLE[index]);
|
||||
}
|
||||
|
||||
void EmitCompositeExtractU32x3(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
|
||||
u32 index) {
|
||||
ctx.AddU32("{}={}.{};", inst, composite, SWIZZLE[index]);
|
||||
}
|
||||
|
||||
void EmitCompositeExtractU32x4(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
|
||||
u32 index) {
|
||||
ctx.AddU32("{}={}.{};", inst, composite, SWIZZLE[index]);
|
||||
}
|
||||
|
||||
void EmitCompositeInsertU32x2(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
|
||||
std::string_view object, u32 index) {
|
||||
const auto ret{ctx.var_alloc.Define(inst, GlslVarType::U32x2)};
|
||||
CompositeInsert(ctx, ret, composite, object, index);
|
||||
}
|
||||
|
||||
void EmitCompositeInsertU32x3(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
|
||||
std::string_view object, u32 index) {
|
||||
const auto ret{ctx.var_alloc.Define(inst, GlslVarType::U32x3)};
|
||||
CompositeInsert(ctx, ret, composite, object, index);
|
||||
}
|
||||
|
||||
void EmitCompositeInsertU32x4(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
|
||||
std::string_view object, u32 index) {
|
||||
const auto ret{ctx.var_alloc.Define(inst, GlslVarType::U32x4)};
|
||||
CompositeInsert(ctx, ret, composite, object, index);
|
||||
}
|
||||
|
||||
void EmitCompositeConstructF16x2([[maybe_unused]] EmitContext& ctx,
|
||||
[[maybe_unused]] std::string_view e1,
|
||||
[[maybe_unused]] std::string_view e2) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitCompositeConstructF16x3([[maybe_unused]] EmitContext& ctx,
|
||||
[[maybe_unused]] std::string_view e1,
|
||||
[[maybe_unused]] std::string_view e2,
|
||||
[[maybe_unused]] std::string_view e3) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitCompositeConstructF16x4([[maybe_unused]] EmitContext& ctx,
|
||||
[[maybe_unused]] std::string_view e1,
|
||||
[[maybe_unused]] std::string_view e2,
|
||||
[[maybe_unused]] std::string_view e3,
|
||||
[[maybe_unused]] std::string_view e4) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitCompositeExtractF16x2([[maybe_unused]] EmitContext& ctx,
|
||||
[[maybe_unused]] std::string_view composite,
|
||||
[[maybe_unused]] u32 index) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitCompositeExtractF16x3([[maybe_unused]] EmitContext& ctx,
|
||||
[[maybe_unused]] std::string_view composite,
|
||||
[[maybe_unused]] u32 index) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitCompositeExtractF16x4([[maybe_unused]] EmitContext& ctx,
|
||||
[[maybe_unused]] std::string_view composite,
|
||||
[[maybe_unused]] u32 index) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitCompositeInsertF16x2([[maybe_unused]] EmitContext& ctx,
|
||||
[[maybe_unused]] std::string_view composite,
|
||||
[[maybe_unused]] std::string_view object,
|
||||
[[maybe_unused]] u32 index) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitCompositeInsertF16x3([[maybe_unused]] EmitContext& ctx,
|
||||
[[maybe_unused]] std::string_view composite,
|
||||
[[maybe_unused]] std::string_view object,
|
||||
[[maybe_unused]] u32 index) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitCompositeInsertF16x4([[maybe_unused]] EmitContext& ctx,
|
||||
[[maybe_unused]] std::string_view composite,
|
||||
[[maybe_unused]] std::string_view object,
|
||||
[[maybe_unused]] u32 index) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitCompositeConstructF32x2(EmitContext& ctx, IR::Inst& inst, std::string_view e1,
|
||||
std::string_view e2) {
|
||||
ctx.AddF32x2("{}=vec2({},{});", inst, e1, e2);
|
||||
}
|
||||
|
||||
void EmitCompositeConstructF32x3(EmitContext& ctx, IR::Inst& inst, std::string_view e1,
|
||||
std::string_view e2, std::string_view e3) {
|
||||
ctx.AddF32x3("{}=vec3({},{},{});", inst, e1, e2, e3);
|
||||
}
|
||||
|
||||
void EmitCompositeConstructF32x4(EmitContext& ctx, IR::Inst& inst, std::string_view e1,
|
||||
std::string_view e2, std::string_view e3, std::string_view e4) {
|
||||
ctx.AddF32x4("{}=vec4({},{},{},{});", inst, e1, e2, e3, e4);
|
||||
}
|
||||
|
||||
void EmitCompositeExtractF32x2(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
|
||||
u32 index) {
|
||||
ctx.AddF32("{}={}.{};", inst, composite, SWIZZLE[index]);
|
||||
}
|
||||
|
||||
void EmitCompositeExtractF32x3(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
|
||||
u32 index) {
|
||||
ctx.AddF32("{}={}.{};", inst, composite, SWIZZLE[index]);
|
||||
}
|
||||
|
||||
void EmitCompositeExtractF32x4(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
|
||||
u32 index) {
|
||||
ctx.AddF32("{}={}.{};", inst, composite, SWIZZLE[index]);
|
||||
}
|
||||
|
||||
void EmitCompositeInsertF32x2(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
|
||||
std::string_view object, u32 index) {
|
||||
const auto ret{ctx.var_alloc.Define(inst, GlslVarType::F32x2)};
|
||||
CompositeInsert(ctx, ret, composite, object, index);
|
||||
}
|
||||
|
||||
void EmitCompositeInsertF32x3(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
|
||||
std::string_view object, u32 index) {
|
||||
const auto ret{ctx.var_alloc.Define(inst, GlslVarType::F32x3)};
|
||||
CompositeInsert(ctx, ret, composite, object, index);
|
||||
}
|
||||
|
||||
void EmitCompositeInsertF32x4(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
|
||||
std::string_view object, u32 index) {
|
||||
const auto ret{ctx.var_alloc.Define(inst, GlslVarType::F32x4)};
|
||||
CompositeInsert(ctx, ret, composite, object, index);
|
||||
}
|
||||
|
||||
void EmitCompositeConstructF64x2([[maybe_unused]] EmitContext& ctx) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitCompositeConstructF64x3([[maybe_unused]] EmitContext& ctx) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitCompositeConstructF64x4([[maybe_unused]] EmitContext& ctx) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitCompositeExtractF64x2([[maybe_unused]] EmitContext& ctx) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitCompositeExtractF64x3([[maybe_unused]] EmitContext& ctx) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitCompositeExtractF64x4([[maybe_unused]] EmitContext& ctx) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitCompositeInsertF64x2(EmitContext& ctx, std::string_view composite, std::string_view object,
|
||||
u32 index) {
|
||||
ctx.Add("{}.{}={};", composite, SWIZZLE[index], object);
|
||||
}
|
||||
|
||||
void EmitCompositeInsertF64x3(EmitContext& ctx, std::string_view composite, std::string_view object,
|
||||
u32 index) {
|
||||
ctx.Add("{}.{}={};", composite, SWIZZLE[index], object);
|
||||
}
|
||||
|
||||
void EmitCompositeInsertF64x4(EmitContext& ctx, std::string_view composite, std::string_view object,
|
||||
u32 index) {
|
||||
ctx.Add("{}.{}={};", composite, SWIZZLE[index], object);
|
||||
}
|
||||
} // namespace Shader::Backend::GLSL
|
||||
476
gpu/third_party/suyu/shader_recompiler/backend/glsl/emit_glsl_context_get_set.cpp
vendored
Normal file
476
gpu/third_party/suyu/shader_recompiler/backend/glsl/emit_glsl_context_get_set.cpp
vendored
Normal file
@@ -0,0 +1,476 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <string_view>
|
||||
|
||||
#include "shader_recompiler/backend/glsl/emit_glsl_instructions.h"
|
||||
#include "shader_recompiler/backend/glsl/glsl_emit_context.h"
|
||||
#include "shader_recompiler/frontend/ir/value.h"
|
||||
#include "shader_recompiler/profile.h"
|
||||
#include "shader_recompiler/runtime_info.h"
|
||||
|
||||
namespace Shader::Backend::GLSL {
|
||||
namespace {
|
||||
constexpr char SWIZZLE[]{"xyzw"};
|
||||
|
||||
u32 CbufIndex(u32 offset) {
|
||||
return (offset / 4) % 4;
|
||||
}
|
||||
|
||||
char OffsetSwizzle(u32 offset) {
|
||||
return SWIZZLE[CbufIndex(offset)];
|
||||
}
|
||||
|
||||
bool IsInputArray(Stage stage) {
|
||||
return stage == Stage::Geometry || stage == Stage::TessellationControl ||
|
||||
stage == Stage::TessellationEval;
|
||||
}
|
||||
|
||||
std::string InputVertexIndex(EmitContext& ctx, std::string_view vertex) {
|
||||
return IsInputArray(ctx.stage) ? fmt::format("[{}]", vertex) : "";
|
||||
}
|
||||
|
||||
std::string_view OutputVertexIndex(EmitContext& ctx) {
|
||||
return ctx.stage == Stage::TessellationControl ? "[gl_InvocationID]" : "";
|
||||
}
|
||||
|
||||
std::string ChooseCbuf(EmitContext& ctx, const IR::Value& binding, std::string_view index) {
|
||||
if (binding.IsImmediate()) {
|
||||
return fmt::format("{}_cbuf{}[{}]", ctx.stage_name, binding.U32(), index);
|
||||
} else {
|
||||
const auto binding_var{ctx.var_alloc.Consume(binding)};
|
||||
return fmt::format("GetCbufIndirect({},{})", binding_var, index);
|
||||
}
|
||||
}
|
||||
|
||||
void GetCbuf(EmitContext& ctx, std::string_view ret, const IR::Value& binding,
|
||||
const IR::Value& offset, u32 num_bits, std::string_view cast = {},
|
||||
std::string_view bit_offset = {}) {
|
||||
const bool is_immediate{offset.IsImmediate()};
|
||||
const bool component_indexing_bug{!is_immediate && ctx.profile.has_gl_component_indexing_bug};
|
||||
if (is_immediate) {
|
||||
const s32 signed_offset{static_cast<s32>(offset.U32())};
|
||||
static constexpr u32 cbuf_size{0x10000};
|
||||
if (signed_offset < 0 || offset.U32() > cbuf_size) {
|
||||
LOG_WARNING(Shader_GLSL, "Immediate constant buffer offset is out of bounds");
|
||||
ctx.Add("{}=0u;", ret);
|
||||
return;
|
||||
}
|
||||
}
|
||||
const auto offset_var{ctx.var_alloc.Consume(offset)};
|
||||
const auto index{is_immediate ? fmt::format("{}", offset.U32() / 16)
|
||||
: fmt::format("{}>>4", offset_var)};
|
||||
const auto swizzle{is_immediate ? fmt::format(".{}", OffsetSwizzle(offset.U32()))
|
||||
: fmt::format("[({}>>2)%4]", offset_var)};
|
||||
|
||||
const auto cbuf{ChooseCbuf(ctx, binding, index)};
|
||||
const auto cbuf_cast{fmt::format("{}({}{{}})", cast, cbuf)};
|
||||
const auto extraction{num_bits == 32 ? cbuf_cast
|
||||
: fmt::format("bitfieldExtract({},int({}),{})", cbuf_cast,
|
||||
bit_offset, num_bits)};
|
||||
if (!component_indexing_bug) {
|
||||
const auto result{fmt::format(fmt::runtime(extraction), swizzle)};
|
||||
ctx.Add("{}={};", ret, result);
|
||||
return;
|
||||
}
|
||||
const auto cbuf_offset{fmt::format("{}>>2", offset_var)};
|
||||
for (u32 i = 0; i < 4; ++i) {
|
||||
const auto swizzle_string{fmt::format(".{}", "xyzw"[i])};
|
||||
const auto result{fmt::format(fmt::runtime(extraction), swizzle_string)};
|
||||
ctx.Add("if(({}&3)=={}){}={};", cbuf_offset, i, ret, result);
|
||||
}
|
||||
}
|
||||
|
||||
void GetCbuf8(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, const IR::Value& offset,
|
||||
std::string_view cast) {
|
||||
const auto ret{ctx.var_alloc.Define(inst, GlslVarType::U32)};
|
||||
if (offset.IsImmediate()) {
|
||||
const auto bit_offset{fmt::format("{}", (offset.U32() % 4) * 8)};
|
||||
GetCbuf(ctx, ret, binding, offset, 8, cast, bit_offset);
|
||||
} else {
|
||||
const auto offset_var{ctx.var_alloc.Consume(offset)};
|
||||
const auto bit_offset{fmt::format("({}%4)*8", offset_var)};
|
||||
GetCbuf(ctx, ret, binding, offset, 8, cast, bit_offset);
|
||||
}
|
||||
}
|
||||
|
||||
void GetCbuf16(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, const IR::Value& offset,
|
||||
std::string_view cast) {
|
||||
const auto ret{ctx.var_alloc.Define(inst, GlslVarType::U32)};
|
||||
if (offset.IsImmediate()) {
|
||||
const auto bit_offset{fmt::format("{}", ((offset.U32() / 2) % 2) * 16)};
|
||||
GetCbuf(ctx, ret, binding, offset, 16, cast, bit_offset);
|
||||
} else {
|
||||
const auto offset_var{ctx.var_alloc.Consume(offset)};
|
||||
const auto bit_offset{fmt::format("(({}>>1)%2)*16", offset_var)};
|
||||
GetCbuf(ctx, ret, binding, offset, 16, cast, bit_offset);
|
||||
}
|
||||
}
|
||||
} // Anonymous namespace
|
||||
|
||||
void EmitGetCbufU8(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset) {
|
||||
const auto cast{ctx.profile.has_gl_cbuf_ftou_bug ? "" : "ftou"};
|
||||
GetCbuf8(ctx, inst, binding, offset, cast);
|
||||
}
|
||||
|
||||
void EmitGetCbufS8(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset) {
|
||||
const auto cast{ctx.profile.has_gl_cbuf_ftou_bug ? "int" : "ftoi"};
|
||||
GetCbuf8(ctx, inst, binding, offset, cast);
|
||||
}
|
||||
|
||||
void EmitGetCbufU16(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset) {
|
||||
const auto cast{ctx.profile.has_gl_cbuf_ftou_bug ? "" : "ftou"};
|
||||
GetCbuf16(ctx, inst, binding, offset, cast);
|
||||
}
|
||||
|
||||
void EmitGetCbufS16(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset) {
|
||||
const auto cast{ctx.profile.has_gl_cbuf_ftou_bug ? "int" : "ftoi"};
|
||||
GetCbuf16(ctx, inst, binding, offset, cast);
|
||||
}
|
||||
|
||||
void EmitGetCbufU32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset) {
|
||||
const auto ret{ctx.var_alloc.Define(inst, GlslVarType::U32)};
|
||||
const auto cast{ctx.profile.has_gl_cbuf_ftou_bug ? "" : "ftou"};
|
||||
GetCbuf(ctx, ret, binding, offset, 32, cast);
|
||||
}
|
||||
|
||||
void EmitGetCbufF32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset) {
|
||||
const auto ret{ctx.var_alloc.Define(inst, GlslVarType::F32)};
|
||||
const auto cast{ctx.profile.has_gl_cbuf_ftou_bug ? "utof" : ""};
|
||||
GetCbuf(ctx, ret, binding, offset, 32, cast);
|
||||
}
|
||||
|
||||
void EmitGetCbufU32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset) {
|
||||
const auto cast{ctx.profile.has_gl_cbuf_ftou_bug ? "" : "ftou"};
|
||||
if (offset.IsImmediate()) {
|
||||
const auto cbuf{fmt::format("{}_cbuf{}", ctx.stage_name, binding.U32())};
|
||||
static constexpr u32 cbuf_size{0x10000};
|
||||
const u32 u32_offset{offset.U32()};
|
||||
const s32 signed_offset{static_cast<s32>(offset.U32())};
|
||||
if (signed_offset < 0 || u32_offset > cbuf_size) {
|
||||
LOG_WARNING(Shader_GLSL, "Immediate constant buffer offset is out of bounds");
|
||||
ctx.AddU32x2("{}=uvec2(0u);", inst);
|
||||
return;
|
||||
}
|
||||
if (u32_offset % 2 == 0) {
|
||||
ctx.AddU32x2("{}={}({}[{}].{}{});", inst, cast, cbuf, u32_offset / 16,
|
||||
OffsetSwizzle(u32_offset), OffsetSwizzle(u32_offset + 4));
|
||||
} else {
|
||||
ctx.AddU32x2("{}=uvec2({}({}[{}].{}),{}({}[{}].{}));", inst, cast, cbuf,
|
||||
u32_offset / 16, OffsetSwizzle(u32_offset), cast, cbuf,
|
||||
(u32_offset + 4) / 16, OffsetSwizzle(u32_offset + 4));
|
||||
}
|
||||
return;
|
||||
}
|
||||
const auto offset_var{ctx.var_alloc.Consume(offset)};
|
||||
const auto cbuf{ChooseCbuf(ctx, binding, fmt::format("{}>>4", offset_var))};
|
||||
if (!ctx.profile.has_gl_component_indexing_bug) {
|
||||
ctx.AddU32x2("{}=uvec2({}({}[({}>>2)%4]),{}({}[(({}+4)>>2)%4]));", inst, cast, cbuf,
|
||||
offset_var, cast, cbuf, offset_var);
|
||||
return;
|
||||
}
|
||||
const auto ret{ctx.var_alloc.Define(inst, GlslVarType::U32x2)};
|
||||
const auto cbuf_offset{fmt::format("{}>>2", offset_var)};
|
||||
for (u32 swizzle = 0; swizzle < 4; ++swizzle) {
|
||||
ctx.Add("if(({}&3)=={}){}=uvec2({}({}.{}),{}({}.{}));", cbuf_offset, swizzle, ret, cast,
|
||||
cbuf, "xyzw"[swizzle], cast, cbuf, "xyzw"[(swizzle + 1) % 4]);
|
||||
}
|
||||
}
|
||||
|
||||
void EmitGetAttribute(EmitContext& ctx, IR::Inst& inst, IR::Attribute attr,
|
||||
std::string_view vertex) {
|
||||
const u32 element{static_cast<u32>(attr) % 4};
|
||||
const char swizzle{"xyzw"[element]};
|
||||
if (IR::IsGeneric(attr)) {
|
||||
const u32 index{IR::GenericAttributeIndex(attr)};
|
||||
if (!ctx.runtime_info.previous_stage_stores.Generic(index, element)) {
|
||||
if (element == 3) {
|
||||
ctx.AddF32("{}=1.f;", inst, attr);
|
||||
} else {
|
||||
ctx.AddF32("{}=0.f;", inst, attr);
|
||||
}
|
||||
return;
|
||||
}
|
||||
ctx.AddF32("{}=in_attr{}{}.{};", inst, index, InputVertexIndex(ctx, vertex), swizzle);
|
||||
return;
|
||||
}
|
||||
switch (attr) {
|
||||
case IR::Attribute::PrimitiveId:
|
||||
ctx.AddF32("{}=itof(gl_PrimitiveID);", inst);
|
||||
break;
|
||||
case IR::Attribute::Layer:
|
||||
ctx.AddF32("{}=itof(gl_Layer);", inst);
|
||||
break;
|
||||
case IR::Attribute::PositionX:
|
||||
case IR::Attribute::PositionY:
|
||||
case IR::Attribute::PositionZ:
|
||||
case IR::Attribute::PositionW: {
|
||||
const bool is_array{IsInputArray(ctx.stage)};
|
||||
const auto input_decorator{is_array ? fmt::format("gl_in[{}].", vertex) : ""};
|
||||
ctx.AddF32("{}={}{}.{};", inst, input_decorator, ctx.position_name, swizzle);
|
||||
break;
|
||||
}
|
||||
case IR::Attribute::PointSpriteS:
|
||||
case IR::Attribute::PointSpriteT:
|
||||
ctx.AddF32("{}=gl_PointCoord.{};", inst, swizzle);
|
||||
break;
|
||||
case IR::Attribute::TessellationEvaluationPointU:
|
||||
case IR::Attribute::TessellationEvaluationPointV:
|
||||
ctx.AddF32("{}=gl_TessCoord.{};", inst, swizzle);
|
||||
break;
|
||||
case IR::Attribute::InstanceId:
|
||||
ctx.AddF32("{}=itof(gl_InstanceID);", inst);
|
||||
break;
|
||||
case IR::Attribute::VertexId:
|
||||
ctx.AddF32("{}=itof(gl_VertexID);", inst);
|
||||
break;
|
||||
case IR::Attribute::FrontFace:
|
||||
ctx.AddF32("{}=itof(gl_FrontFacing?-1:0);", inst);
|
||||
break;
|
||||
case IR::Attribute::BaseInstance:
|
||||
ctx.AddF32("{}=itof(gl_BaseInstance);", inst);
|
||||
break;
|
||||
case IR::Attribute::BaseVertex:
|
||||
ctx.AddF32("{}=itof(gl_BaseVertex);", inst);
|
||||
break;
|
||||
case IR::Attribute::DrawID:
|
||||
ctx.AddF32("{}=itof(gl_DrawID);", inst);
|
||||
break;
|
||||
default:
|
||||
throw NotImplementedException("Get attribute {}", attr);
|
||||
}
|
||||
}
|
||||
|
||||
void EmitGetAttributeU32(EmitContext& ctx, IR::Inst& inst, IR::Attribute attr, std::string_view) {
|
||||
switch (attr) {
|
||||
case IR::Attribute::PrimitiveId:
|
||||
ctx.AddU32("{}=uint(gl_PrimitiveID);", inst);
|
||||
break;
|
||||
case IR::Attribute::InstanceId:
|
||||
ctx.AddU32("{}=uint(gl_InstanceID);", inst);
|
||||
break;
|
||||
case IR::Attribute::VertexId:
|
||||
ctx.AddU32("{}=uint(gl_VertexID);", inst);
|
||||
break;
|
||||
case IR::Attribute::BaseInstance:
|
||||
ctx.AddU32("{}=uint(gl_BaseInstance);", inst);
|
||||
break;
|
||||
case IR::Attribute::BaseVertex:
|
||||
ctx.AddU32("{}=uint(gl_BaseVertex);", inst);
|
||||
break;
|
||||
case IR::Attribute::DrawID:
|
||||
ctx.AddU32("{}=uint(gl_DrawID);", inst);
|
||||
break;
|
||||
default:
|
||||
throw NotImplementedException("Get U32 attribute {}", attr);
|
||||
}
|
||||
}
|
||||
|
||||
void EmitSetAttribute(EmitContext& ctx, IR::Attribute attr, std::string_view value,
|
||||
[[maybe_unused]] std::string_view vertex) {
|
||||
if (IR::IsGeneric(attr)) {
|
||||
const u32 index{IR::GenericAttributeIndex(attr)};
|
||||
const u32 attr_element{IR::GenericAttributeElement(attr)};
|
||||
const GenericElementInfo& info{ctx.output_generics.at(index).at(attr_element)};
|
||||
const auto output_decorator{OutputVertexIndex(ctx)};
|
||||
if (info.num_components == 1) {
|
||||
ctx.Add("{}{}={};", info.name, output_decorator, value);
|
||||
} else {
|
||||
const u32 index_element{attr_element - info.first_element};
|
||||
ctx.Add("{}{}.{}={};", info.name, output_decorator, "xyzw"[index_element], value);
|
||||
}
|
||||
return;
|
||||
}
|
||||
const u32 element{static_cast<u32>(attr) % 4};
|
||||
const char swizzle{"xyzw"[element]};
|
||||
switch (attr) {
|
||||
case IR::Attribute::Layer:
|
||||
if (ctx.stage != Stage::Geometry &&
|
||||
!ctx.profile.support_viewport_index_layer_non_geometry) {
|
||||
LOG_WARNING(Shader_GLSL, "Shader stores viewport layer but device does not support "
|
||||
"viewport layer extension");
|
||||
break;
|
||||
}
|
||||
ctx.Add("gl_Layer=ftoi({});", value);
|
||||
break;
|
||||
case IR::Attribute::ViewportIndex:
|
||||
if (ctx.stage != Stage::Geometry &&
|
||||
!ctx.profile.support_viewport_index_layer_non_geometry) {
|
||||
LOG_WARNING(Shader_GLSL, "Shader stores viewport index but device does not support "
|
||||
"viewport layer extension");
|
||||
break;
|
||||
}
|
||||
ctx.Add("gl_ViewportIndex=ftoi({});", value);
|
||||
break;
|
||||
case IR::Attribute::ViewportMask:
|
||||
if (ctx.stage != Stage::Geometry && !ctx.profile.support_viewport_mask) {
|
||||
LOG_WARNING(
|
||||
Shader_GLSL,
|
||||
"Shader stores viewport mask but device does not support viewport mask extension");
|
||||
break;
|
||||
}
|
||||
ctx.Add("gl_ViewportMask[0]=ftoi({});", value);
|
||||
break;
|
||||
case IR::Attribute::PointSize:
|
||||
ctx.Add("gl_PointSize={};", value);
|
||||
break;
|
||||
case IR::Attribute::PositionX:
|
||||
case IR::Attribute::PositionY:
|
||||
case IR::Attribute::PositionZ:
|
||||
case IR::Attribute::PositionW:
|
||||
ctx.Add("gl_Position.{}={};", swizzle, value);
|
||||
break;
|
||||
case IR::Attribute::ClipDistance0:
|
||||
case IR::Attribute::ClipDistance1:
|
||||
case IR::Attribute::ClipDistance2:
|
||||
case IR::Attribute::ClipDistance3:
|
||||
case IR::Attribute::ClipDistance4:
|
||||
case IR::Attribute::ClipDistance5:
|
||||
case IR::Attribute::ClipDistance6:
|
||||
case IR::Attribute::ClipDistance7: {
|
||||
const u32 index{static_cast<u32>(attr) - static_cast<u32>(IR::Attribute::ClipDistance0)};
|
||||
ctx.Add("gl_ClipDistance[{}]={};", index, value);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw NotImplementedException("Set attribute {}", attr);
|
||||
}
|
||||
}
|
||||
|
||||
void EmitGetAttributeIndexed(EmitContext& ctx, IR::Inst& inst, std::string_view offset,
|
||||
std::string_view vertex) {
|
||||
const bool is_array{ctx.stage == Stage::Geometry};
|
||||
const auto vertex_arg{is_array ? fmt::format(",{}", vertex) : ""};
|
||||
ctx.AddF32("{}=IndexedAttrLoad(int({}){});", inst, offset, vertex_arg);
|
||||
}
|
||||
|
||||
void EmitSetAttributeIndexed([[maybe_unused]] EmitContext& ctx,
|
||||
[[maybe_unused]] std::string_view offset,
|
||||
[[maybe_unused]] std::string_view value,
|
||||
[[maybe_unused]] std::string_view vertex) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitGetPatch(EmitContext& ctx, IR::Inst& inst, IR::Patch patch) {
|
||||
if (!IR::IsGeneric(patch)) {
|
||||
throw NotImplementedException("Non-generic patch load");
|
||||
}
|
||||
const u32 index{IR::GenericPatchIndex(patch)};
|
||||
const u32 element{IR::GenericPatchElement(patch)};
|
||||
const char swizzle{"xyzw"[element]};
|
||||
ctx.AddF32("{}=patch{}.{};", inst, index, swizzle);
|
||||
}
|
||||
|
||||
void EmitSetPatch(EmitContext& ctx, IR::Patch patch, std::string_view value) {
|
||||
if (IR::IsGeneric(patch)) {
|
||||
const u32 index{IR::GenericPatchIndex(patch)};
|
||||
const u32 element{IR::GenericPatchElement(patch)};
|
||||
ctx.Add("patch{}.{}={};", index, "xyzw"[element], value);
|
||||
return;
|
||||
}
|
||||
switch (patch) {
|
||||
case IR::Patch::TessellationLodLeft:
|
||||
case IR::Patch::TessellationLodRight:
|
||||
case IR::Patch::TessellationLodTop:
|
||||
case IR::Patch::TessellationLodBottom: {
|
||||
const u32 index{static_cast<u32>(patch) - u32(IR::Patch::TessellationLodLeft)};
|
||||
ctx.Add("gl_TessLevelOuter[{}]={};", index, value);
|
||||
break;
|
||||
}
|
||||
case IR::Patch::TessellationLodInteriorU:
|
||||
ctx.Add("gl_TessLevelInner[0]={};", value);
|
||||
break;
|
||||
case IR::Patch::TessellationLodInteriorV:
|
||||
ctx.Add("gl_TessLevelInner[1]={};", value);
|
||||
break;
|
||||
default:
|
||||
throw NotImplementedException("Patch {}", patch);
|
||||
}
|
||||
}
|
||||
|
||||
void EmitSetFragColor(EmitContext& ctx, u32 index, u32 component, std::string_view value) {
|
||||
const char swizzle{"xyzw"[component]};
|
||||
ctx.Add("frag_color{}.{}={};", index, swizzle, value);
|
||||
}
|
||||
|
||||
void EmitSetSampleMask(EmitContext& ctx, std::string_view value) {
|
||||
ctx.Add("gl_SampleMask[0]=int({});", value);
|
||||
}
|
||||
|
||||
void EmitSetFragDepth(EmitContext& ctx, std::string_view value) {
|
||||
ctx.Add("gl_FragDepth={};", value);
|
||||
}
|
||||
|
||||
void EmitLocalInvocationId(EmitContext& ctx, IR::Inst& inst) {
|
||||
ctx.AddU32x3("{}=gl_LocalInvocationID;", inst);
|
||||
}
|
||||
|
||||
void EmitWorkgroupId(EmitContext& ctx, IR::Inst& inst) {
|
||||
ctx.AddU32x3("{}=gl_WorkGroupID;", inst);
|
||||
}
|
||||
|
||||
void EmitInvocationId(EmitContext& ctx, IR::Inst& inst) {
|
||||
ctx.AddU32("{}=uint(gl_InvocationID);", inst);
|
||||
}
|
||||
|
||||
void EmitInvocationInfo(EmitContext& ctx, IR::Inst& inst) {
|
||||
switch (ctx.stage) {
|
||||
case Stage::TessellationControl:
|
||||
case Stage::TessellationEval:
|
||||
ctx.AddU32("{}=uint(gl_PatchVerticesIn)<<16;", inst);
|
||||
break;
|
||||
case Stage::Geometry:
|
||||
ctx.AddU32("{}=uint({}<<16);", inst,
|
||||
InputTopologyVertices::vertices(ctx.runtime_info.input_topology));
|
||||
break;
|
||||
default:
|
||||
LOG_WARNING(Shader, "(STUBBED) called");
|
||||
ctx.AddU32("{}=uint(0x00ff0000);", inst);
|
||||
}
|
||||
}
|
||||
|
||||
void EmitSampleId(EmitContext& ctx, IR::Inst& inst) {
|
||||
ctx.AddU32("{}=uint(gl_SampleID);", inst);
|
||||
}
|
||||
|
||||
void EmitIsHelperInvocation(EmitContext& ctx, IR::Inst& inst) {
|
||||
ctx.AddU1("{}=gl_HelperInvocation;", inst);
|
||||
}
|
||||
|
||||
void EmitSR_WScaleFactorXY(EmitContext& ctx, IR::Inst& inst) {
|
||||
LOG_WARNING(Shader, "(STUBBED) called");
|
||||
}
|
||||
|
||||
void EmitSR_WScaleFactorZ(EmitContext& ctx, IR::Inst& inst) {
|
||||
LOG_WARNING(Shader, "(STUBBED) called");
|
||||
}
|
||||
|
||||
void EmitYDirection(EmitContext& ctx, IR::Inst& inst) {
|
||||
ctx.uses_y_direction = true;
|
||||
ctx.AddF32("{}=gl_FrontMaterial.ambient.a;", inst);
|
||||
}
|
||||
|
||||
void EmitResolutionDownFactor(EmitContext& ctx, IR::Inst& inst) {
|
||||
ctx.AddF32("{}=scaling.z;", inst);
|
||||
}
|
||||
|
||||
void EmitRenderArea(EmitContext& ctx, IR::Inst& inst) {
|
||||
ctx.AddF32x4("{}=render_area;", inst);
|
||||
}
|
||||
|
||||
void EmitLoadLocal(EmitContext& ctx, IR::Inst& inst, std::string_view word_offset) {
|
||||
ctx.AddU32("{}=lmem[{}];", inst, word_offset);
|
||||
}
|
||||
|
||||
void EmitWriteLocal(EmitContext& ctx, std::string_view word_offset, std::string_view value) {
|
||||
ctx.Add("lmem[{}]={};", word_offset, value);
|
||||
}
|
||||
|
||||
} // namespace Shader::Backend::GLSL
|
||||
18
gpu/third_party/suyu/shader_recompiler/backend/glsl/emit_glsl_control_flow.cpp
vendored
Normal file
18
gpu/third_party/suyu/shader_recompiler/backend/glsl/emit_glsl_control_flow.cpp
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "shader_recompiler/backend/glsl/emit_glsl_instructions.h"
|
||||
#include "shader_recompiler/backend/glsl/glsl_emit_context.h"
|
||||
#include "shader_recompiler/exception.h"
|
||||
|
||||
namespace Shader::Backend::GLSL {
|
||||
|
||||
void EmitJoin(EmitContext&) {
|
||||
throw NotImplementedException("Join shouldn't be emitted");
|
||||
}
|
||||
|
||||
void EmitDemoteToHelperInvocation(EmitContext& ctx) {
|
||||
ctx.Add("discard;");
|
||||
}
|
||||
|
||||
} // namespace Shader::Backend::GLSL
|
||||
259
gpu/third_party/suyu/shader_recompiler/backend/glsl/emit_glsl_convert.cpp
vendored
Normal file
259
gpu/third_party/suyu/shader_recompiler/backend/glsl/emit_glsl_convert.cpp
vendored
Normal file
@@ -0,0 +1,259 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <string_view>
|
||||
|
||||
#include "shader_recompiler/backend/glsl/emit_glsl_instructions.h"
|
||||
#include "shader_recompiler/backend/glsl/glsl_emit_context.h"
|
||||
#include "shader_recompiler/frontend/ir/value.h"
|
||||
|
||||
namespace Shader::Backend::GLSL {
|
||||
void EmitConvertS16F16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertS16F32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddU32("{}=(int({})&0xffff)|(bitfieldExtract(int({}),31,1)<<15);", inst, value, value);
|
||||
}
|
||||
|
||||
void EmitConvertS16F64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertS32F16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertS32F32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddU32("{}=int({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitConvertS32F64(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddU32("{}=int({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitConvertS64F16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertS64F32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddU64("{}=int64_t({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitConvertS64F64(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddU64("{}=int64_t({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitConvertU16F16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertU16F32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertU16F64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertU32F16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertU16U32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertU32U16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertU8U32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertU32U8([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertS32S8([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertS32S16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertU32F32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddU32("{}=uint({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitConvertU32F64(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddU32("{}=uint({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitConvertU64F16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertU64F32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddU64("{}=uint64_t({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitConvertU64F64(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddU64("{}=uint64_t({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitConvertU64U32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddU64("{}=uint64_t({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitConvertU32U64(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddU32("{}=uint({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitConvertF16F32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertF32F16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertF32F64(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddF32("{}=float({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitConvertF64F32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddF64("{}=double({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitConvertF16S8([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertF16S16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertF16S32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertF16S64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertF16U8([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertF16U16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertF16U32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertF16U64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertF32S8([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertF32S16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertF32S32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddF32("{}=float(int({}));", inst, value);
|
||||
}
|
||||
|
||||
void EmitConvertF32S64(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddF32("{}=float(int64_t({}));", inst, value);
|
||||
}
|
||||
|
||||
void EmitConvertF32U8([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertF32U16(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddF32("{}=float({}&0xffff);", inst, value);
|
||||
}
|
||||
|
||||
void EmitConvertF32U32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddF32("{}=float({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitConvertF32U64(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddF32("{}=float({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitConvertF64S8([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertF64S16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertF64S32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddF64("{}=double(int({}));", inst, value);
|
||||
}
|
||||
|
||||
void EmitConvertF64S64(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddF64("{}=double(int64_t({}));", inst, value);
|
||||
}
|
||||
|
||||
void EmitConvertF64U8([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertF64U16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertF64U32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddF64("{}=double({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitConvertF64U64(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddF64("{}=double({});", inst, value);
|
||||
}
|
||||
|
||||
} // namespace Shader::Backend::GLSL
|
||||
455
gpu/third_party/suyu/shader_recompiler/backend/glsl/emit_glsl_floating_point.cpp
vendored
Normal file
455
gpu/third_party/suyu/shader_recompiler/backend/glsl/emit_glsl_floating_point.cpp
vendored
Normal file
@@ -0,0 +1,455 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <string_view>
|
||||
|
||||
#include "shader_recompiler/backend/glsl/emit_glsl_instructions.h"
|
||||
#include "shader_recompiler/backend/glsl/glsl_emit_context.h"
|
||||
#include "shader_recompiler/frontend/ir/modifiers.h"
|
||||
#include "shader_recompiler/frontend/ir/value.h"
|
||||
|
||||
namespace Shader::Backend::GLSL {
|
||||
namespace {
|
||||
void Compare(EmitContext& ctx, IR::Inst& inst, std::string_view lhs, std::string_view rhs,
|
||||
std::string_view op, bool ordered) {
|
||||
const auto nan_op{ordered ? "&&!" : "||"};
|
||||
ctx.AddU1("{}={}{}{}"
|
||||
"{}isnan({}){}isnan({});",
|
||||
inst, lhs, op, rhs, nan_op, lhs, nan_op, rhs);
|
||||
}
|
||||
|
||||
bool IsPrecise(const IR::Inst& inst) {
|
||||
return inst.Flags<IR::FpControl>().no_contraction;
|
||||
}
|
||||
} // Anonymous namespace
|
||||
|
||||
void EmitFPAbs16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitFPAbs32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddF32("{}=abs({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitFPAbs64(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddF64("{}=abs({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitFPAdd16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view a, [[maybe_unused]] std::string_view b) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitFPAdd32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
|
||||
if (IsPrecise(inst)) {
|
||||
ctx.AddPrecF32("{}={}+{};", inst, a, b);
|
||||
} else {
|
||||
ctx.AddF32("{}={}+{};", inst, a, b);
|
||||
}
|
||||
}
|
||||
|
||||
void EmitFPAdd64(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
|
||||
if (IsPrecise(inst)) {
|
||||
ctx.AddPrecF64("{}={}+{};", inst, a, b);
|
||||
} else {
|
||||
ctx.AddF64("{}={}+{};", inst, a, b);
|
||||
}
|
||||
}
|
||||
|
||||
void EmitFPFma16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view a, [[maybe_unused]] std::string_view b,
|
||||
[[maybe_unused]] std::string_view c) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitFPFma32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b,
|
||||
std::string_view c) {
|
||||
if (IsPrecise(inst)) {
|
||||
ctx.AddPrecF32("{}=fma({},{},{});", inst, a, b, c);
|
||||
} else {
|
||||
ctx.AddF32("{}=fma({},{},{});", inst, a, b, c);
|
||||
}
|
||||
}
|
||||
|
||||
void EmitFPFma64(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b,
|
||||
std::string_view c) {
|
||||
if (IsPrecise(inst)) {
|
||||
ctx.AddPrecF64("{}=fma({},{},{});", inst, a, b, c);
|
||||
} else {
|
||||
ctx.AddF64("{}=fma({},{},{});", inst, a, b, c);
|
||||
}
|
||||
}
|
||||
|
||||
void EmitFPMax32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
|
||||
ctx.AddF32("{}=max({},{});", inst, a, b);
|
||||
}
|
||||
|
||||
void EmitFPMax64(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
|
||||
ctx.AddF64("{}=max({},{});", inst, a, b);
|
||||
}
|
||||
|
||||
void EmitFPMin32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
|
||||
ctx.AddF32("{}=min({},{});", inst, a, b);
|
||||
}
|
||||
|
||||
void EmitFPMin64(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
|
||||
ctx.AddF64("{}=min({},{});", inst, a, b);
|
||||
}
|
||||
|
||||
void EmitFPMul16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view a, [[maybe_unused]] std::string_view b) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitFPMul32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
|
||||
if (IsPrecise(inst)) {
|
||||
ctx.AddPrecF32("{}={}*{};", inst, a, b);
|
||||
} else {
|
||||
ctx.AddF32("{}={}*{};", inst, a, b);
|
||||
}
|
||||
}
|
||||
|
||||
void EmitFPMul64(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
|
||||
if (IsPrecise(inst)) {
|
||||
ctx.AddPrecF64("{}={}*{};", inst, a, b);
|
||||
} else {
|
||||
ctx.AddF64("{}={}*{};", inst, a, b);
|
||||
}
|
||||
}
|
||||
|
||||
void EmitFPNeg16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitFPNeg32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddF32("{}=0.f-({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitFPNeg64(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddF64("{}=double(0.)-({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitFPSin(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddF32("{}=sin({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitFPCos(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddF32("{}=cos({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitFPExp2(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddF32("{}=exp2({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitFPLog2(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddF32("{}=log2({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitFPRecip32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddF32("{}=(1.0f)/{};", inst, value);
|
||||
}
|
||||
|
||||
void EmitFPRecip64(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddF64("{}=1.0/{};", inst, value);
|
||||
}
|
||||
|
||||
void EmitFPRecipSqrt32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
ctx.AddF32("{}=inversesqrt({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitFPRecipSqrt64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitFPSqrt(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddF32("{}=sqrt({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitFPSaturate16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitFPSaturate32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddF32("{}=min(max({},0.0),1.0);", inst, value);
|
||||
}
|
||||
|
||||
void EmitFPSaturate64(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddF64("{}=min(max({},0.0),1.0);", inst, value);
|
||||
}
|
||||
|
||||
void EmitFPClamp16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value,
|
||||
[[maybe_unused]] std::string_view min_value,
|
||||
[[maybe_unused]] std::string_view max_value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitFPClamp32(EmitContext& ctx, IR::Inst& inst, std::string_view value,
|
||||
std::string_view min_value, std::string_view max_value) {
|
||||
// GLSL's clamp does not produce desirable results
|
||||
ctx.AddF32("{}=min(max({},float({})),float({}));", inst, value, min_value, max_value);
|
||||
}
|
||||
|
||||
void EmitFPClamp64(EmitContext& ctx, IR::Inst& inst, std::string_view value,
|
||||
std::string_view min_value, std::string_view max_value) {
|
||||
// GLSL's clamp does not produce desirable results
|
||||
ctx.AddF64("{}=min(max({},double({})),double({}));", inst, value, min_value, max_value);
|
||||
}
|
||||
|
||||
void EmitFPRoundEven16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitFPRoundEven32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddF32("{}=roundEven({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitFPRoundEven64(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddF64("{}=roundEven({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitFPFloor16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitFPFloor32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddF32("{}=floor({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitFPFloor64(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddF64("{}=floor({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitFPCeil16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitFPCeil32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddF32("{}=ceil({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitFPCeil64(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddF64("{}=ceil({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitFPTrunc16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitFPTrunc32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddF32("{}=trunc({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitFPTrunc64(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddF64("{}=trunc({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitFPOrdEqual16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view lhs,
|
||||
[[maybe_unused]] std::string_view rhs) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitFPOrdEqual32(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs) {
|
||||
Compare(ctx, inst, lhs, rhs, "==", true);
|
||||
}
|
||||
|
||||
void EmitFPOrdEqual64(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs) {
|
||||
Compare(ctx, inst, lhs, rhs, "==", true);
|
||||
}
|
||||
|
||||
void EmitFPUnordEqual16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view lhs,
|
||||
[[maybe_unused]] std::string_view rhs) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitFPUnordEqual32(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs) {
|
||||
Compare(ctx, inst, lhs, rhs, "==", false);
|
||||
}
|
||||
|
||||
void EmitFPUnordEqual64(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs) {
|
||||
Compare(ctx, inst, lhs, rhs, "==", false);
|
||||
}
|
||||
|
||||
void EmitFPOrdNotEqual16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view lhs,
|
||||
[[maybe_unused]] std::string_view rhs) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitFPOrdNotEqual32(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs) {
|
||||
Compare(ctx, inst, lhs, rhs, "!=", true);
|
||||
}
|
||||
|
||||
void EmitFPOrdNotEqual64(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs) {
|
||||
Compare(ctx, inst, lhs, rhs, "!=", true);
|
||||
}
|
||||
|
||||
void EmitFPUnordNotEqual16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view lhs,
|
||||
[[maybe_unused]] std::string_view rhs) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitFPUnordNotEqual32(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs) {
|
||||
Compare(ctx, inst, lhs, rhs, "!=", false);
|
||||
}
|
||||
|
||||
void EmitFPUnordNotEqual64(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs) {
|
||||
Compare(ctx, inst, lhs, rhs, "!=", false);
|
||||
}
|
||||
|
||||
void EmitFPOrdLessThan16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view lhs,
|
||||
[[maybe_unused]] std::string_view rhs) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitFPOrdLessThan32(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs) {
|
||||
Compare(ctx, inst, lhs, rhs, "<", true);
|
||||
}
|
||||
|
||||
void EmitFPOrdLessThan64(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs) {
|
||||
Compare(ctx, inst, lhs, rhs, "<", true);
|
||||
}
|
||||
|
||||
void EmitFPUnordLessThan16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view lhs,
|
||||
[[maybe_unused]] std::string_view rhs) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitFPUnordLessThan32(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs) {
|
||||
Compare(ctx, inst, lhs, rhs, "<", false);
|
||||
}
|
||||
|
||||
void EmitFPUnordLessThan64(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs) {
|
||||
Compare(ctx, inst, lhs, rhs, "<", false);
|
||||
}
|
||||
|
||||
void EmitFPOrdGreaterThan16([[maybe_unused]] EmitContext& ctx,
|
||||
[[maybe_unused]] std::string_view lhs,
|
||||
[[maybe_unused]] std::string_view rhs) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitFPOrdGreaterThan32(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs) {
|
||||
Compare(ctx, inst, lhs, rhs, ">", true);
|
||||
}
|
||||
|
||||
void EmitFPOrdGreaterThan64(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs) {
|
||||
Compare(ctx, inst, lhs, rhs, ">", true);
|
||||
}
|
||||
|
||||
void EmitFPUnordGreaterThan16([[maybe_unused]] EmitContext& ctx,
|
||||
[[maybe_unused]] std::string_view lhs,
|
||||
[[maybe_unused]] std::string_view rhs) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitFPUnordGreaterThan32(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs) {
|
||||
Compare(ctx, inst, lhs, rhs, ">", false);
|
||||
}
|
||||
|
||||
void EmitFPUnordGreaterThan64(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs) {
|
||||
Compare(ctx, inst, lhs, rhs, ">", false);
|
||||
}
|
||||
|
||||
void EmitFPOrdLessThanEqual16([[maybe_unused]] EmitContext& ctx,
|
||||
[[maybe_unused]] std::string_view lhs,
|
||||
[[maybe_unused]] std::string_view rhs) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitFPOrdLessThanEqual32(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs) {
|
||||
Compare(ctx, inst, lhs, rhs, "<=", true);
|
||||
}
|
||||
|
||||
void EmitFPOrdLessThanEqual64(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs) {
|
||||
Compare(ctx, inst, lhs, rhs, "<=", true);
|
||||
}
|
||||
|
||||
void EmitFPUnordLessThanEqual16([[maybe_unused]] EmitContext& ctx,
|
||||
[[maybe_unused]] std::string_view lhs,
|
||||
[[maybe_unused]] std::string_view rhs) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitFPUnordLessThanEqual32(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs) {
|
||||
Compare(ctx, inst, lhs, rhs, "<=", false);
|
||||
}
|
||||
|
||||
void EmitFPUnordLessThanEqual64(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs) {
|
||||
Compare(ctx, inst, lhs, rhs, "<=", false);
|
||||
}
|
||||
|
||||
void EmitFPOrdGreaterThanEqual16([[maybe_unused]] EmitContext& ctx,
|
||||
[[maybe_unused]] std::string_view lhs,
|
||||
[[maybe_unused]] std::string_view rhs) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitFPOrdGreaterThanEqual32(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs) {
|
||||
Compare(ctx, inst, lhs, rhs, ">=", true);
|
||||
}
|
||||
|
||||
void EmitFPOrdGreaterThanEqual64(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs) {
|
||||
Compare(ctx, inst, lhs, rhs, ">=", true);
|
||||
}
|
||||
|
||||
void EmitFPUnordGreaterThanEqual16([[maybe_unused]] EmitContext& ctx,
|
||||
[[maybe_unused]] std::string_view lhs,
|
||||
[[maybe_unused]] std::string_view rhs) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitFPUnordGreaterThanEqual32(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs) {
|
||||
Compare(ctx, inst, lhs, rhs, ">=", false);
|
||||
}
|
||||
|
||||
void EmitFPUnordGreaterThanEqual64(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs) {
|
||||
Compare(ctx, inst, lhs, rhs, ">=", false);
|
||||
}
|
||||
|
||||
void EmitFPIsNan16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitFPIsNan32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddU1("{}=isnan({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitFPIsNan64(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddU1("{}=isnan({});", inst, value);
|
||||
}
|
||||
|
||||
} // namespace Shader::Backend::GLSL
|
||||
869
gpu/third_party/suyu/shader_recompiler/backend/glsl/emit_glsl_image.cpp
vendored
Normal file
869
gpu/third_party/suyu/shader_recompiler/backend/glsl/emit_glsl_image.cpp
vendored
Normal file
@@ -0,0 +1,869 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <string_view>
|
||||
|
||||
#include "shader_recompiler/backend/glsl/emit_glsl_instructions.h"
|
||||
#include "shader_recompiler/backend/glsl/glsl_emit_context.h"
|
||||
#include "shader_recompiler/frontend/ir/modifiers.h"
|
||||
#include "shader_recompiler/frontend/ir/value.h"
|
||||
#include "shader_recompiler/profile.h"
|
||||
|
||||
namespace Shader::Backend::GLSL {
|
||||
namespace {
|
||||
std::string Texture(EmitContext& ctx, const IR::TextureInstInfo& info, const IR::Value& index) {
|
||||
const auto def{info.type == TextureType::Buffer ? ctx.texture_buffers.at(info.descriptor_index)
|
||||
: ctx.textures.at(info.descriptor_index)};
|
||||
const auto index_offset{def.count > 1 ? fmt::format("[{}]", ctx.var_alloc.Consume(index)) : ""};
|
||||
return fmt::format("tex{}{}", def.binding, index_offset);
|
||||
}
|
||||
|
||||
std::string Image(EmitContext& ctx, const IR::TextureInstInfo& info, const IR::Value& index) {
|
||||
const auto def{info.type == TextureType::Buffer ? ctx.image_buffers.at(info.descriptor_index)
|
||||
: ctx.images.at(info.descriptor_index)};
|
||||
const auto index_offset{def.count > 1 ? fmt::format("[{}]", ctx.var_alloc.Consume(index)) : ""};
|
||||
return fmt::format("img{}{}", def.binding, index_offset);
|
||||
}
|
||||
|
||||
bool IsTextureMsaa(EmitContext& ctx, const IR::TextureInstInfo& info) {
|
||||
if (info.type == TextureType::Buffer) {
|
||||
return false;
|
||||
}
|
||||
return ctx.info.texture_descriptors.at(info.descriptor_index).is_multisample;
|
||||
}
|
||||
|
||||
std::string CastToIntVec(std::string_view value, const IR::TextureInstInfo& info) {
|
||||
switch (info.type) {
|
||||
case TextureType::Color1D:
|
||||
case TextureType::Buffer:
|
||||
return fmt::format("int({})", value);
|
||||
case TextureType::ColorArray1D:
|
||||
case TextureType::Color2D:
|
||||
case TextureType::ColorArray2D:
|
||||
return fmt::format("ivec2({})", value);
|
||||
case TextureType::Color3D:
|
||||
case TextureType::ColorCube:
|
||||
return fmt::format("ivec3({})", value);
|
||||
case TextureType::ColorArrayCube:
|
||||
return fmt::format("ivec4({})", value);
|
||||
default:
|
||||
throw NotImplementedException("Integer cast for TextureType {}", info.type.Value());
|
||||
}
|
||||
}
|
||||
|
||||
std::string CoordsCastToInt(std::string_view value, const IR::TextureInstInfo& info) {
|
||||
switch (info.type) {
|
||||
case TextureType::Color1D:
|
||||
case TextureType::Buffer:
|
||||
return fmt::format("int({})", value);
|
||||
case TextureType::ColorArray1D:
|
||||
case TextureType::Color2D:
|
||||
return fmt::format("ivec2({})", value);
|
||||
case TextureType::ColorArray2D:
|
||||
case TextureType::Color3D:
|
||||
case TextureType::ColorCube:
|
||||
return fmt::format("ivec3({})", value);
|
||||
case TextureType::ColorArrayCube:
|
||||
return fmt::format("ivec4({})", value);
|
||||
default:
|
||||
throw NotImplementedException("TexelFetchCast type {}", info.type.Value());
|
||||
}
|
||||
}
|
||||
|
||||
bool NeedsShadowLodExt(TextureType type) {
|
||||
switch (type) {
|
||||
case TextureType::ColorArray2D:
|
||||
case TextureType::ColorCube:
|
||||
case TextureType::ColorArrayCube:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
std::string GetOffsetVec(EmitContext& ctx, const IR::Value& offset) {
|
||||
if (offset.IsImmediate()) {
|
||||
return fmt::format("int({})", offset.U32());
|
||||
}
|
||||
IR::Inst* const inst{offset.InstRecursive()};
|
||||
if (inst->AreAllArgsImmediates()) {
|
||||
switch (inst->GetOpcode()) {
|
||||
case IR::Opcode::CompositeConstructU32x2:
|
||||
return fmt::format("ivec2({},{})", inst->Arg(0).U32(), inst->Arg(1).U32());
|
||||
case IR::Opcode::CompositeConstructU32x3:
|
||||
return fmt::format("ivec3({},{},{})", inst->Arg(0).U32(), inst->Arg(1).U32(),
|
||||
inst->Arg(2).U32());
|
||||
case IR::Opcode::CompositeConstructU32x4:
|
||||
return fmt::format("ivec4({},{},{},{})", inst->Arg(0).U32(), inst->Arg(1).U32(),
|
||||
inst->Arg(2).U32(), inst->Arg(3).U32());
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
const bool has_var_aoffi{ctx.profile.support_gl_variable_aoffi};
|
||||
if (!has_var_aoffi) {
|
||||
LOG_WARNING(Shader_GLSL, "Device does not support variable texture offsets, STUBBING");
|
||||
}
|
||||
const auto offset_str{has_var_aoffi ? ctx.var_alloc.Consume(offset) : "0"};
|
||||
switch (offset.Type()) {
|
||||
case IR::Type::U32:
|
||||
return fmt::format("int({})", offset_str);
|
||||
case IR::Type::U32x2:
|
||||
return fmt::format("ivec2({})", offset_str);
|
||||
case IR::Type::U32x3:
|
||||
return fmt::format("ivec3({})", offset_str);
|
||||
case IR::Type::U32x4:
|
||||
return fmt::format("ivec4({})", offset_str);
|
||||
default:
|
||||
throw NotImplementedException("Offset type {}", offset.Type());
|
||||
}
|
||||
}
|
||||
|
||||
std::string PtpOffsets(const IR::Value& offset, const IR::Value& offset2) {
|
||||
const std::array values{offset.InstRecursive(), offset2.InstRecursive()};
|
||||
if (!values[0]->AreAllArgsImmediates() || !values[1]->AreAllArgsImmediates()) {
|
||||
LOG_WARNING(Shader_GLSL, "Not all arguments in PTP are immediate, STUBBING");
|
||||
return "ivec2[](ivec2(0), ivec2(1), ivec2(2), ivec2(3))";
|
||||
}
|
||||
const IR::Opcode opcode{values[0]->GetOpcode()};
|
||||
if (opcode != values[1]->GetOpcode() || opcode != IR::Opcode::CompositeConstructU32x4) {
|
||||
throw LogicError("Invalid PTP arguments");
|
||||
}
|
||||
auto read{[&](unsigned int a, unsigned int b) { return values[a]->Arg(b).U32(); }};
|
||||
|
||||
return fmt::format("ivec2[](ivec2({},{}),ivec2({},{}),ivec2({},{}),ivec2({},{}))", read(0, 0),
|
||||
read(0, 1), read(0, 2), read(0, 3), read(1, 0), read(1, 1), read(1, 2),
|
||||
read(1, 3));
|
||||
}
|
||||
|
||||
IR::Inst* PrepareSparse(IR::Inst& inst) {
|
||||
const auto sparse_inst{inst.GetAssociatedPseudoOperation(IR::Opcode::GetSparseFromOp)};
|
||||
if (sparse_inst) {
|
||||
sparse_inst->Invalidate();
|
||||
}
|
||||
return sparse_inst;
|
||||
}
|
||||
|
||||
std::string ImageGatherSubpixelOffset(const IR::TextureInstInfo& info, std::string_view texture,
|
||||
std::string_view coords) {
|
||||
switch (info.type) {
|
||||
case TextureType::Color2D:
|
||||
case TextureType::Color2DRect:
|
||||
return fmt::format("{}+vec2(0.001953125)/vec2(textureSize({}, 0))", coords, texture);
|
||||
case TextureType::ColorArray2D:
|
||||
case TextureType::ColorCube:
|
||||
return fmt::format("vec3({0}.xy+vec2(0.001953125)/vec2(textureSize({1}, 0)),{0}.z)", coords,
|
||||
texture);
|
||||
default:
|
||||
return std::string{coords};
|
||||
}
|
||||
}
|
||||
} // Anonymous namespace
|
||||
|
||||
void EmitImageSampleImplicitLod(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords, std::string_view bias_lc,
|
||||
const IR::Value& offset) {
|
||||
const auto info{inst.Flags<IR::TextureInstInfo>()};
|
||||
if (info.has_lod_clamp) {
|
||||
throw NotImplementedException("EmitImageSampleImplicitLod Lod clamp samples");
|
||||
}
|
||||
const auto texture{Texture(ctx, info, index)};
|
||||
const auto bias{info.has_bias ? fmt::format(",{}", bias_lc) : ""};
|
||||
const auto texel{ctx.var_alloc.Define(inst, GlslVarType::F32x4)};
|
||||
const auto sparse_inst{PrepareSparse(inst)};
|
||||
const bool supports_sparse{ctx.profile.support_gl_sparse_textures};
|
||||
if (sparse_inst && !supports_sparse) {
|
||||
LOG_WARNING(Shader_GLSL, "Device does not support sparse texture queries. STUBBING");
|
||||
ctx.AddU1("{}=true;", *sparse_inst);
|
||||
}
|
||||
if (!sparse_inst || !supports_sparse) {
|
||||
if (!offset.IsEmpty()) {
|
||||
const auto offset_str{GetOffsetVec(ctx, offset)};
|
||||
if (ctx.stage == Stage::Fragment) {
|
||||
ctx.Add("{}=textureOffset({},{},{}{});", texel, texture, coords, offset_str, bias);
|
||||
} else {
|
||||
ctx.Add("{}=textureLodOffset({},{},0.0,{});", texel, texture, coords, offset_str);
|
||||
}
|
||||
} else {
|
||||
if (ctx.stage == Stage::Fragment) {
|
||||
ctx.Add("{}=texture({},{}{});", texel, texture, coords, bias);
|
||||
} else {
|
||||
ctx.Add("{}=textureLod({},{},0.0);", texel, texture, coords);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!offset.IsEmpty()) {
|
||||
ctx.AddU1("{}=sparseTexelsResidentARB(sparseTextureOffsetARB({},{},{},{}{}));",
|
||||
*sparse_inst, texture, coords, GetOffsetVec(ctx, offset), texel, bias);
|
||||
} else {
|
||||
ctx.AddU1("{}=sparseTexelsResidentARB(sparseTextureARB({},{},{}{}));", *sparse_inst,
|
||||
texture, coords, texel, bias);
|
||||
}
|
||||
}
|
||||
|
||||
void EmitImageSampleExplicitLod(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords, std::string_view lod_lc,
|
||||
const IR::Value& offset) {
|
||||
const auto info{inst.Flags<IR::TextureInstInfo>()};
|
||||
if (info.has_bias) {
|
||||
throw NotImplementedException("EmitImageSampleExplicitLod Bias texture samples");
|
||||
}
|
||||
if (info.has_lod_clamp) {
|
||||
throw NotImplementedException("EmitImageSampleExplicitLod Lod clamp samples");
|
||||
}
|
||||
const auto texture{Texture(ctx, info, index)};
|
||||
const auto texel{ctx.var_alloc.Define(inst, GlslVarType::F32x4)};
|
||||
const auto sparse_inst{PrepareSparse(inst)};
|
||||
const bool supports_sparse{ctx.profile.support_gl_sparse_textures};
|
||||
if (sparse_inst && !supports_sparse) {
|
||||
LOG_WARNING(Shader_GLSL, "Device does not support sparse texture queries. STUBBING");
|
||||
ctx.AddU1("{}=true;", *sparse_inst);
|
||||
}
|
||||
if (!sparse_inst || !supports_sparse) {
|
||||
if (!offset.IsEmpty()) {
|
||||
ctx.Add("{}=textureLodOffset({},{},{},{});", texel, texture, coords, lod_lc,
|
||||
GetOffsetVec(ctx, offset));
|
||||
} else {
|
||||
ctx.Add("{}=textureLod({},{},{});", texel, texture, coords, lod_lc);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!offset.IsEmpty()) {
|
||||
ctx.AddU1("{}=sparseTexelsResidentARB(sparseTexelFetchOffsetARB({},{},int({}),{},{}));",
|
||||
*sparse_inst, texture, CastToIntVec(coords, info), lod_lc,
|
||||
GetOffsetVec(ctx, offset), texel);
|
||||
} else {
|
||||
ctx.AddU1("{}=sparseTexelsResidentARB(sparseTextureLodARB({},{},{},{}));", *sparse_inst,
|
||||
texture, coords, lod_lc, texel);
|
||||
}
|
||||
}
|
||||
|
||||
void EmitImageSampleDrefImplicitLod(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords, std::string_view dref,
|
||||
std::string_view bias_lc, const IR::Value& offset) {
|
||||
const auto info{inst.Flags<IR::TextureInstInfo>()};
|
||||
const auto sparse_inst{PrepareSparse(inst)};
|
||||
if (sparse_inst) {
|
||||
throw NotImplementedException("EmitImageSampleDrefImplicitLod Sparse texture samples");
|
||||
}
|
||||
if (info.has_bias) {
|
||||
throw NotImplementedException("EmitImageSampleDrefImplicitLod Bias texture samples");
|
||||
}
|
||||
if (info.has_lod_clamp) {
|
||||
throw NotImplementedException("EmitImageSampleDrefImplicitLod Lod clamp samples");
|
||||
}
|
||||
const auto texture{Texture(ctx, info, index)};
|
||||
const auto bias{info.has_bias ? fmt::format(",{}", bias_lc) : ""};
|
||||
const bool needs_shadow_ext{NeedsShadowLodExt(info.type)};
|
||||
const auto cast{needs_shadow_ext ? "vec4" : "vec3"};
|
||||
const bool use_grad{!ctx.profile.support_gl_texture_shadow_lod &&
|
||||
ctx.stage != Stage::Fragment && needs_shadow_ext};
|
||||
if (use_grad) {
|
||||
LOG_WARNING(Shader_GLSL,
|
||||
"Device lacks GL_EXT_texture_shadow_lod. Using textureGrad fallback");
|
||||
if (info.type == TextureType::ColorArrayCube) {
|
||||
LOG_WARNING(Shader_GLSL, "textureGrad does not support ColorArrayCube. Stubbing");
|
||||
ctx.AddF32("{}=0.0f;", inst);
|
||||
return;
|
||||
}
|
||||
const auto d_cast{info.type == TextureType::ColorArray2D ? "vec2" : "vec3"};
|
||||
ctx.AddF32("{}=textureGrad({},{}({},{}),{}(0),{}(0));", inst, texture, cast, coords, dref,
|
||||
d_cast, d_cast);
|
||||
return;
|
||||
}
|
||||
if (!offset.IsEmpty()) {
|
||||
const auto offset_str{GetOffsetVec(ctx, offset)};
|
||||
if (ctx.stage == Stage::Fragment) {
|
||||
ctx.AddF32("{}=textureOffset({},{}({},{}),{}{});", inst, texture, cast, coords, dref,
|
||||
offset_str, bias);
|
||||
} else {
|
||||
ctx.AddF32("{}=textureLodOffset({},{}({},{}),0.0,{});", inst, texture, cast, coords,
|
||||
dref, offset_str);
|
||||
}
|
||||
} else {
|
||||
if (ctx.stage == Stage::Fragment) {
|
||||
if (info.type == TextureType::ColorArrayCube) {
|
||||
ctx.AddF32("{}=texture({},vec4({}),{});", inst, texture, coords, dref);
|
||||
} else {
|
||||
ctx.AddF32("{}=texture({},{}({},{}){});", inst, texture, cast, coords, dref, bias);
|
||||
}
|
||||
} else {
|
||||
ctx.AddF32("{}=textureLod({},{}({},{}),0.0);", inst, texture, cast, coords, dref);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EmitImageSampleDrefExplicitLod(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords, std::string_view dref,
|
||||
std::string_view lod_lc, const IR::Value& offset) {
|
||||
const auto info{inst.Flags<IR::TextureInstInfo>()};
|
||||
const auto sparse_inst{PrepareSparse(inst)};
|
||||
if (sparse_inst) {
|
||||
throw NotImplementedException("EmitImageSampleDrefExplicitLod Sparse texture samples");
|
||||
}
|
||||
if (info.has_bias) {
|
||||
throw NotImplementedException("EmitImageSampleDrefExplicitLod Bias texture samples");
|
||||
}
|
||||
if (info.has_lod_clamp) {
|
||||
throw NotImplementedException("EmitImageSampleDrefExplicitLod Lod clamp samples");
|
||||
}
|
||||
const auto texture{Texture(ctx, info, index)};
|
||||
const bool needs_shadow_ext{NeedsShadowLodExt(info.type)};
|
||||
const bool use_grad{!ctx.profile.support_gl_texture_shadow_lod && needs_shadow_ext};
|
||||
const auto cast{needs_shadow_ext ? "vec4" : "vec3"};
|
||||
if (use_grad) {
|
||||
LOG_WARNING(Shader_GLSL,
|
||||
"Device lacks GL_EXT_texture_shadow_lod. Using textureGrad fallback");
|
||||
if (info.type == TextureType::ColorArrayCube) {
|
||||
LOG_WARNING(Shader_GLSL, "textureGrad does not support ColorArrayCube. Stubbing");
|
||||
ctx.AddF32("{}=0.0f;", inst);
|
||||
return;
|
||||
}
|
||||
const auto d_cast{info.type == TextureType::ColorArray2D ? "vec2" : "vec3"};
|
||||
ctx.AddF32("{}=textureGrad({},{}({},{}),{}(0),{}(0));", inst, texture, cast, coords, dref,
|
||||
d_cast, d_cast);
|
||||
return;
|
||||
}
|
||||
if (!offset.IsEmpty()) {
|
||||
const auto offset_str{GetOffsetVec(ctx, offset)};
|
||||
if (info.type == TextureType::ColorArrayCube) {
|
||||
ctx.AddF32("{}=textureLodOffset({},{},{},{},{});", inst, texture, coords, dref, lod_lc,
|
||||
offset_str);
|
||||
} else {
|
||||
ctx.AddF32("{}=textureLodOffset({},{}({},{}),{},{});", inst, texture, cast, coords,
|
||||
dref, lod_lc, offset_str);
|
||||
}
|
||||
} else {
|
||||
if (info.type == TextureType::ColorArrayCube) {
|
||||
ctx.AddF32("{}=textureLod({},{},{},{});", inst, texture, coords, dref, lod_lc);
|
||||
} else {
|
||||
ctx.AddF32("{}=textureLod({},{}({},{}),{});", inst, texture, cast, coords, dref,
|
||||
lod_lc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EmitImageGather(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords, const IR::Value& offset, const IR::Value& offset2) {
|
||||
const auto info{inst.Flags<IR::TextureInstInfo>()};
|
||||
const auto texture{Texture(ctx, info, index)};
|
||||
const auto texel{ctx.var_alloc.Define(inst, GlslVarType::F32x4)};
|
||||
const auto sparse_inst{PrepareSparse(inst)};
|
||||
const bool supports_sparse{ctx.profile.support_gl_sparse_textures};
|
||||
if (sparse_inst && !supports_sparse) {
|
||||
LOG_WARNING(Shader_GLSL, "Device does not support sparse texture queries. STUBBING");
|
||||
ctx.AddU1("{}=true;", *sparse_inst);
|
||||
}
|
||||
std::string coords_with_subpixel_offset;
|
||||
if (ctx.profile.need_gather_subpixel_offset) {
|
||||
// Apply a subpixel offset of 1/512 the texel size of the texture to ensure same rounding on
|
||||
// AMD hardware as on Maxwell or other Nvidia architectures.
|
||||
coords_with_subpixel_offset = ImageGatherSubpixelOffset(info, texture, coords);
|
||||
coords = coords_with_subpixel_offset;
|
||||
}
|
||||
if (!sparse_inst || !supports_sparse) {
|
||||
if (offset.IsEmpty()) {
|
||||
ctx.Add("{}=textureGather({},{},int({}));", texel, texture, coords,
|
||||
info.gather_component);
|
||||
return;
|
||||
}
|
||||
if (offset2.IsEmpty()) {
|
||||
ctx.Add("{}=textureGatherOffset({},{},{},int({}));", texel, texture, coords,
|
||||
GetOffsetVec(ctx, offset), info.gather_component);
|
||||
return;
|
||||
}
|
||||
// PTP
|
||||
const auto offsets{PtpOffsets(offset, offset2)};
|
||||
ctx.Add("{}=textureGatherOffsets({},{},{},int({}));", texel, texture, coords, offsets,
|
||||
info.gather_component);
|
||||
return;
|
||||
}
|
||||
if (offset.IsEmpty()) {
|
||||
ctx.AddU1("{}=sparseTexelsResidentARB(sparseTextureGatherARB({},{},{},int({})));",
|
||||
*sparse_inst, texture, coords, texel, info.gather_component);
|
||||
return;
|
||||
}
|
||||
if (offset2.IsEmpty()) {
|
||||
ctx.AddU1("{}=sparseTexelsResidentARB(sparseTextureGatherOffsetARB({},{},{},{},int({})));",
|
||||
*sparse_inst, texture, CastToIntVec(coords, info), GetOffsetVec(ctx, offset),
|
||||
texel, info.gather_component);
|
||||
return;
|
||||
}
|
||||
// PTP
|
||||
const auto offsets{PtpOffsets(offset, offset2)};
|
||||
ctx.AddU1("{}=sparseTexelsResidentARB(sparseTextureGatherOffsetARB({},{},{},{},int({})));",
|
||||
*sparse_inst, texture, CastToIntVec(coords, info), offsets, texel,
|
||||
info.gather_component);
|
||||
}
|
||||
|
||||
void EmitImageGatherDref(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords, const IR::Value& offset, const IR::Value& offset2,
|
||||
std::string_view dref) {
|
||||
const auto info{inst.Flags<IR::TextureInstInfo>()};
|
||||
const auto texture{Texture(ctx, info, index)};
|
||||
const auto texel{ctx.var_alloc.Define(inst, GlslVarType::F32x4)};
|
||||
const auto sparse_inst{PrepareSparse(inst)};
|
||||
const bool supports_sparse{ctx.profile.support_gl_sparse_textures};
|
||||
if (sparse_inst && !supports_sparse) {
|
||||
LOG_WARNING(Shader_GLSL, "Device does not support sparse texture queries. STUBBING");
|
||||
ctx.AddU1("{}=true;", *sparse_inst);
|
||||
}
|
||||
std::string coords_with_subpixel_offset;
|
||||
if (ctx.profile.need_gather_subpixel_offset) {
|
||||
// Apply a subpixel offset of 1/512 the texel size of the texture to ensure same rounding on
|
||||
// AMD hardware as on Maxwell or other Nvidia architectures.
|
||||
coords_with_subpixel_offset = ImageGatherSubpixelOffset(info, texture, coords);
|
||||
coords = coords_with_subpixel_offset;
|
||||
}
|
||||
if (!sparse_inst || !supports_sparse) {
|
||||
if (offset.IsEmpty()) {
|
||||
ctx.Add("{}=textureGather({},{},{});", texel, texture, coords, dref);
|
||||
return;
|
||||
}
|
||||
if (offset2.IsEmpty()) {
|
||||
ctx.Add("{}=textureGatherOffset({},{},{},{});", texel, texture, coords, dref,
|
||||
GetOffsetVec(ctx, offset));
|
||||
return;
|
||||
}
|
||||
// PTP
|
||||
const auto offsets{PtpOffsets(offset, offset2)};
|
||||
ctx.Add("{}=textureGatherOffsets({},{},{},{});", texel, texture, coords, dref, offsets);
|
||||
return;
|
||||
}
|
||||
if (offset.IsEmpty()) {
|
||||
ctx.AddU1("{}=sparseTexelsResidentARB(sparseTextureGatherARB({},{},{},{}));", *sparse_inst,
|
||||
texture, coords, dref, texel);
|
||||
return;
|
||||
}
|
||||
if (offset2.IsEmpty()) {
|
||||
ctx.AddU1("{}=sparseTexelsResidentARB(sparseTextureGatherOffsetARB({},{},{},,{},{}));",
|
||||
*sparse_inst, texture, CastToIntVec(coords, info), dref,
|
||||
GetOffsetVec(ctx, offset), texel);
|
||||
return;
|
||||
}
|
||||
// PTP
|
||||
const auto offsets{PtpOffsets(offset, offset2)};
|
||||
ctx.AddU1("{}=sparseTexelsResidentARB(sparseTextureGatherOffsetARB({},{},{},,{},{}));",
|
||||
*sparse_inst, texture, CastToIntVec(coords, info), dref, offsets, texel);
|
||||
}
|
||||
|
||||
void EmitImageFetch(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords, const IR::Value& offset, std::string_view lod,
|
||||
std::string_view ms) {
|
||||
const auto info{inst.Flags<IR::TextureInstInfo>()};
|
||||
if (info.has_bias) {
|
||||
throw NotImplementedException("EmitImageFetch Bias texture samples");
|
||||
}
|
||||
if (info.has_lod_clamp) {
|
||||
throw NotImplementedException("EmitImageFetch Lod clamp samples");
|
||||
}
|
||||
const auto texture{Texture(ctx, info, index)};
|
||||
const auto sparse_inst{PrepareSparse(inst)};
|
||||
const auto texel{ctx.var_alloc.Define(inst, GlslVarType::F32x4)};
|
||||
const bool supports_sparse{ctx.profile.support_gl_sparse_textures};
|
||||
if (sparse_inst && !supports_sparse) {
|
||||
LOG_WARNING(Shader_GLSL, "Device does not support sparse texture queries. STUBBING");
|
||||
ctx.AddU1("{}=true;", *sparse_inst);
|
||||
}
|
||||
if (!sparse_inst || !supports_sparse) {
|
||||
const auto int_coords{CoordsCastToInt(coords, info)};
|
||||
if (!ms.empty()) {
|
||||
ctx.Add("{}=texelFetch({},{},int({}));", texel, texture, int_coords, ms);
|
||||
} else if (!offset.IsEmpty()) {
|
||||
ctx.Add("{}=texelFetchOffset({},{},int({}),{});", texel, texture, int_coords, lod,
|
||||
GetOffsetVec(ctx, offset));
|
||||
} else {
|
||||
if (info.type == TextureType::Buffer) {
|
||||
ctx.Add("{}=texelFetch({},int({}));", texel, texture, coords);
|
||||
} else {
|
||||
ctx.Add("{}=texelFetch({},{},int({}));", texel, texture, int_coords, lod);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!ms.empty()) {
|
||||
throw NotImplementedException("EmitImageFetch Sparse MSAA samples");
|
||||
}
|
||||
if (!offset.IsEmpty()) {
|
||||
ctx.AddU1("{}=sparseTexelsResidentARB(sparseTexelFetchOffsetARB({},{},int({}),{},{}));",
|
||||
*sparse_inst, texture, CastToIntVec(coords, info), lod, GetOffsetVec(ctx, offset),
|
||||
texel);
|
||||
} else {
|
||||
ctx.AddU1("{}=sparseTexelsResidentARB(sparseTexelFetchARB({},{},int({}),{}));",
|
||||
*sparse_inst, texture, CastToIntVec(coords, info), lod, texel);
|
||||
}
|
||||
}
|
||||
|
||||
void EmitImageQueryDimensions(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view lod, const IR::Value& skip_mips_val) {
|
||||
const auto info{inst.Flags<IR::TextureInstInfo>()};
|
||||
const auto texture{Texture(ctx, info, index)};
|
||||
const bool is_msaa{IsTextureMsaa(ctx, info)};
|
||||
const bool skip_mips{skip_mips_val.U1()};
|
||||
const auto mips{skip_mips ? "0u" : fmt::format("uint(textureQueryLevels({}))", texture)};
|
||||
if (is_msaa && !skip_mips) {
|
||||
throw NotImplementedException("EmitImageQueryDimensions MSAA QueryLevels");
|
||||
}
|
||||
if (info.type == TextureType::Buffer && !skip_mips) {
|
||||
throw NotImplementedException("EmitImageQueryDimensions TextureType::Buffer QueryLevels");
|
||||
}
|
||||
const bool uses_lod{!is_msaa && info.type != TextureType::Buffer};
|
||||
const auto lod_str{uses_lod ? fmt::format(",int({})", lod) : ""};
|
||||
switch (info.type) {
|
||||
case TextureType::Color1D:
|
||||
return ctx.AddU32x4("{}=uvec4(uint(textureSize({}{})),0u,0u,{});", inst, texture, lod_str,
|
||||
mips);
|
||||
case TextureType::ColorArray1D:
|
||||
case TextureType::Color2D:
|
||||
case TextureType::ColorCube:
|
||||
case TextureType::Color2DRect:
|
||||
return ctx.AddU32x4("{}=uvec4(uvec2(textureSize({}{})),0u,{});", inst, texture, lod_str,
|
||||
mips);
|
||||
case TextureType::ColorArray2D:
|
||||
case TextureType::Color3D:
|
||||
case TextureType::ColorArrayCube:
|
||||
return ctx.AddU32x4("{}=uvec4(uvec3(textureSize({}{})),{});", inst, texture, lod_str, mips);
|
||||
case TextureType::Buffer:
|
||||
return ctx.AddU32x4("{}=uvec4(uint(textureSize({})),0u,0u,{});", inst, texture, mips);
|
||||
}
|
||||
throw LogicError("Unspecified image type {}", info.type.Value());
|
||||
}
|
||||
|
||||
void EmitImageQueryLod(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords) {
|
||||
const auto info{inst.Flags<IR::TextureInstInfo>()};
|
||||
const auto texture{Texture(ctx, info, index)};
|
||||
return ctx.AddF32x4("{}=vec4(textureQueryLod({},{}),0.0,0.0);", inst, texture, coords);
|
||||
}
|
||||
|
||||
void EmitImageGradient(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords, const IR::Value& derivatives,
|
||||
const IR::Value& offset, [[maybe_unused]] const IR::Value& lod_clamp) {
|
||||
const auto info{inst.Flags<IR::TextureInstInfo>()};
|
||||
if (info.has_lod_clamp) {
|
||||
throw NotImplementedException("EmitImageGradient Lod clamp samples");
|
||||
}
|
||||
const auto sparse_inst{PrepareSparse(inst)};
|
||||
if (sparse_inst) {
|
||||
throw NotImplementedException("EmitImageGradient Sparse");
|
||||
}
|
||||
if (!offset.IsEmpty() && info.num_derivatives <= 2) {
|
||||
throw NotImplementedException("EmitImageGradient offset");
|
||||
}
|
||||
const auto texture{Texture(ctx, info, index)};
|
||||
const auto texel{ctx.var_alloc.Define(inst, GlslVarType::F32x4)};
|
||||
const bool multi_component{info.num_derivatives > 1 || info.has_lod_clamp};
|
||||
const auto derivatives_vec{ctx.var_alloc.Consume(derivatives)};
|
||||
if (multi_component) {
|
||||
if (info.num_derivatives >= 3) {
|
||||
const auto offset_vec{ctx.var_alloc.Consume(offset)};
|
||||
ctx.Add("{}=textureGrad({},{},vec3({}.xz, {}.x),vec3({}.yw, {}.y));", texel, texture,
|
||||
coords, derivatives_vec, offset_vec, derivatives_vec, offset_vec);
|
||||
return;
|
||||
}
|
||||
ctx.Add("{}=textureGrad({},{},vec2({}.xz),vec2({}.yz));", texel, texture, coords,
|
||||
derivatives_vec, derivatives_vec);
|
||||
} else {
|
||||
ctx.Add("{}=textureGrad({},{},float({}.x),float({}.y));", texel, texture, coords,
|
||||
derivatives_vec, derivatives_vec);
|
||||
}
|
||||
}
|
||||
|
||||
void EmitImageRead(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords) {
|
||||
const auto info{inst.Flags<IR::TextureInstInfo>()};
|
||||
const auto sparse_inst{PrepareSparse(inst)};
|
||||
if (sparse_inst) {
|
||||
throw NotImplementedException("EmitImageRead Sparse");
|
||||
}
|
||||
const auto image{Image(ctx, info, index)};
|
||||
ctx.AddU32x4("{}=uvec4(imageLoad({},{}));", inst, image, CoordsCastToInt(coords, info));
|
||||
}
|
||||
|
||||
void EmitImageWrite(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords, std::string_view color) {
|
||||
const auto info{inst.Flags<IR::TextureInstInfo>()};
|
||||
const auto image{Image(ctx, info, index)};
|
||||
ctx.Add("imageStore({},{},{});", image, CoordsCastToInt(coords, info), color);
|
||||
}
|
||||
|
||||
void EmitImageAtomicIAdd32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords, std::string_view value) {
|
||||
const auto info{inst.Flags<IR::TextureInstInfo>()};
|
||||
const auto image{Image(ctx, info, index)};
|
||||
ctx.AddU32("{}=imageAtomicAdd({},{},{});", inst, image, CoordsCastToInt(coords, info), value);
|
||||
}
|
||||
|
||||
void EmitImageAtomicSMin32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords, std::string_view value) {
|
||||
const auto info{inst.Flags<IR::TextureInstInfo>()};
|
||||
const auto image{Image(ctx, info, index)};
|
||||
ctx.AddU32("{}=imageAtomicMin({},{},int({}));", inst, image, CoordsCastToInt(coords, info),
|
||||
value);
|
||||
}
|
||||
|
||||
void EmitImageAtomicUMin32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords, std::string_view value) {
|
||||
const auto info{inst.Flags<IR::TextureInstInfo>()};
|
||||
const auto image{Image(ctx, info, index)};
|
||||
ctx.AddU32("{}=imageAtomicMin({},{},uint({}));", inst, image, CoordsCastToInt(coords, info),
|
||||
value);
|
||||
}
|
||||
|
||||
void EmitImageAtomicSMax32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords, std::string_view value) {
|
||||
const auto info{inst.Flags<IR::TextureInstInfo>()};
|
||||
const auto image{Image(ctx, info, index)};
|
||||
ctx.AddU32("{}=imageAtomicMax({},{},int({}));", inst, image, CoordsCastToInt(coords, info),
|
||||
value);
|
||||
}
|
||||
|
||||
void EmitImageAtomicUMax32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords, std::string_view value) {
|
||||
const auto info{inst.Flags<IR::TextureInstInfo>()};
|
||||
const auto image{Image(ctx, info, index)};
|
||||
ctx.AddU32("{}=imageAtomicMax({},{},uint({}));", inst, image, CoordsCastToInt(coords, info),
|
||||
value);
|
||||
}
|
||||
|
||||
void EmitImageAtomicInc32(EmitContext&, IR::Inst&, const IR::Value&, std::string_view,
|
||||
std::string_view) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitImageAtomicDec32(EmitContext&, IR::Inst&, const IR::Value&, std::string_view,
|
||||
std::string_view) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitImageAtomicAnd32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords, std::string_view value) {
|
||||
const auto info{inst.Flags<IR::TextureInstInfo>()};
|
||||
const auto image{Image(ctx, info, index)};
|
||||
ctx.AddU32("{}=imageAtomicAnd({},{},{});", inst, image, CoordsCastToInt(coords, info), value);
|
||||
}
|
||||
|
||||
void EmitImageAtomicOr32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords, std::string_view value) {
|
||||
const auto info{inst.Flags<IR::TextureInstInfo>()};
|
||||
const auto image{Image(ctx, info, index)};
|
||||
ctx.AddU32("{}=imageAtomicOr({},{},{});", inst, image, CoordsCastToInt(coords, info), value);
|
||||
}
|
||||
|
||||
void EmitImageAtomicXor32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords, std::string_view value) {
|
||||
const auto info{inst.Flags<IR::TextureInstInfo>()};
|
||||
const auto image{Image(ctx, info, index)};
|
||||
ctx.AddU32("{}=imageAtomicXor({},{},{});", inst, image, CoordsCastToInt(coords, info), value);
|
||||
}
|
||||
|
||||
void EmitImageAtomicExchange32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords, std::string_view value) {
|
||||
const auto info{inst.Flags<IR::TextureInstInfo>()};
|
||||
const auto image{Image(ctx, info, index)};
|
||||
ctx.AddU32("{}=imageAtomicExchange({},{},{});", inst, image, CoordsCastToInt(coords, info),
|
||||
value);
|
||||
}
|
||||
|
||||
void EmitIsTextureScaled(EmitContext& ctx, IR::Inst& inst, const IR::Value& index) {
|
||||
if (!index.IsImmediate()) {
|
||||
throw NotImplementedException("Non-constant texture rescaling");
|
||||
}
|
||||
const u32 image_index{index.U32()};
|
||||
ctx.AddU1("{}=(ftou(scaling.x)&{})!=0;", inst, 1u << image_index);
|
||||
}
|
||||
|
||||
void EmitIsImageScaled(EmitContext& ctx, IR::Inst& inst, const IR::Value& index) {
|
||||
if (!index.IsImmediate()) {
|
||||
throw NotImplementedException("Non-constant texture rescaling");
|
||||
}
|
||||
const u32 image_index{index.U32()};
|
||||
ctx.AddU1("{}=(ftou(scaling.y)&{})!=0;", inst, 1u << image_index);
|
||||
}
|
||||
|
||||
void EmitBindlessImageSampleImplicitLod(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBindlessImageSampleExplicitLod(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBindlessImageSampleDrefImplicitLod(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBindlessImageSampleDrefExplicitLod(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBindlessImageGather(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBindlessImageGatherDref(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBindlessImageFetch(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBindlessImageQueryDimensions(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBindlessImageQueryLod(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBindlessImageGradient(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBindlessImageRead(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBindlessImageWrite(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBoundImageSampleImplicitLod(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBoundImageSampleExplicitLod(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBoundImageSampleDrefImplicitLod(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBoundImageSampleDrefExplicitLod(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBoundImageGather(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBoundImageGatherDref(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBoundImageFetch(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBoundImageQueryDimensions(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBoundImageQueryLod(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBoundImageGradient(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBoundImageRead(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBoundImageWrite(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBindlessImageAtomicIAdd32(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBindlessImageAtomicSMin32(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBindlessImageAtomicUMin32(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBindlessImageAtomicSMax32(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBindlessImageAtomicUMax32(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBindlessImageAtomicInc32(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBindlessImageAtomicDec32(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBindlessImageAtomicAnd32(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBindlessImageAtomicOr32(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBindlessImageAtomicXor32(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBindlessImageAtomicExchange32(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBoundImageAtomicIAdd32(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBoundImageAtomicSMin32(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBoundImageAtomicUMin32(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBoundImageAtomicSMax32(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBoundImageAtomicUMax32(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBoundImageAtomicInc32(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBoundImageAtomicDec32(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBoundImageAtomicAnd32(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBoundImageAtomicOr32(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBoundImageAtomicXor32(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBoundImageAtomicExchange32(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
} // namespace Shader::Backend::GLSL
|
||||
753
gpu/third_party/suyu/shader_recompiler/backend/glsl/emit_glsl_instructions.h
vendored
Normal file
753
gpu/third_party/suyu/shader_recompiler/backend/glsl/emit_glsl_instructions.h
vendored
Normal file
@@ -0,0 +1,753 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2025 suyu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string_view>
|
||||
|
||||
#include "common/common_types.h"
|
||||
|
||||
namespace Shader::IR {
|
||||
enum class Attribute : u64;
|
||||
enum class Patch : u64;
|
||||
class Inst;
|
||||
class Value;
|
||||
} // namespace Shader::IR
|
||||
|
||||
namespace Shader::Backend::GLSL {
|
||||
class EmitContext;
|
||||
|
||||
#define NotImplemented() throw NotImplementedException("GLSL instruction {}", __func__)
|
||||
|
||||
// Microinstruction emitters
|
||||
void EmitPhi(EmitContext& ctx, IR::Inst& inst);
|
||||
void EmitVoid(EmitContext& ctx);
|
||||
void EmitIdentity(EmitContext& ctx, IR::Inst& inst, const IR::Value& value);
|
||||
void EmitConditionRef(EmitContext& ctx, IR::Inst& inst, const IR::Value& value);
|
||||
void EmitReference(EmitContext& ctx, const IR::Value& value);
|
||||
void EmitPhiMove(EmitContext& ctx, const IR::Value& phi, const IR::Value& value);
|
||||
void EmitJoin(EmitContext& ctx);
|
||||
void EmitDemoteToHelperInvocation(EmitContext& ctx);
|
||||
void EmitBarrier(EmitContext& ctx);
|
||||
void EmitWorkgroupMemoryBarrier(EmitContext& ctx);
|
||||
void EmitDeviceMemoryBarrier(EmitContext& ctx);
|
||||
void EmitPrologue(EmitContext& ctx);
|
||||
void EmitEpilogue(EmitContext& ctx);
|
||||
void EmitEmitVertex(EmitContext& ctx, const IR::Value& stream);
|
||||
void EmitEndPrimitive(EmitContext& ctx, const IR::Value& stream);
|
||||
void EmitGetRegister(EmitContext& ctx);
|
||||
void EmitSetRegister(EmitContext& ctx);
|
||||
void EmitGetPred(EmitContext& ctx);
|
||||
void EmitSetPred(EmitContext& ctx);
|
||||
void EmitSetGotoVariable(EmitContext& ctx);
|
||||
void EmitGetGotoVariable(EmitContext& ctx);
|
||||
void EmitSetIndirectBranchVariable(EmitContext& ctx);
|
||||
void EmitGetIndirectBranchVariable(EmitContext& ctx);
|
||||
void EmitGetCbufU8(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset);
|
||||
void EmitGetCbufS8(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset);
|
||||
void EmitGetCbufU16(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset);
|
||||
void EmitGetCbufS16(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset);
|
||||
void EmitGetCbufU32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset);
|
||||
void EmitGetCbufF32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset);
|
||||
void EmitGetCbufU32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset);
|
||||
void EmitGetAttribute(EmitContext& ctx, IR::Inst& inst, IR::Attribute attr,
|
||||
std::string_view vertex);
|
||||
void EmitGetAttributeU32(EmitContext& ctx, IR::Inst& inst, IR::Attribute attr,
|
||||
std::string_view vertex);
|
||||
void EmitSetAttribute(EmitContext& ctx, IR::Attribute attr, std::string_view value,
|
||||
std::string_view vertex);
|
||||
void EmitGetAttributeIndexed(EmitContext& ctx, IR::Inst& inst, std::string_view offset,
|
||||
std::string_view vertex);
|
||||
void EmitSetAttributeIndexed(EmitContext& ctx, std::string_view offset, std::string_view value,
|
||||
std::string_view vertex);
|
||||
void EmitGetPatch(EmitContext& ctx, IR::Inst& inst, IR::Patch patch);
|
||||
void EmitSetPatch(EmitContext& ctx, IR::Patch patch, std::string_view value);
|
||||
void EmitSetFragColor(EmitContext& ctx, u32 index, u32 component, std::string_view value);
|
||||
void EmitSetSampleMask(EmitContext& ctx, std::string_view value);
|
||||
void EmitSetFragDepth(EmitContext& ctx, std::string_view value);
|
||||
void EmitGetZFlag(EmitContext& ctx);
|
||||
void EmitGetSFlag(EmitContext& ctx);
|
||||
void EmitGetCFlag(EmitContext& ctx);
|
||||
void EmitGetOFlag(EmitContext& ctx);
|
||||
void EmitSetZFlag(EmitContext& ctx);
|
||||
void EmitSetSFlag(EmitContext& ctx);
|
||||
void EmitSetCFlag(EmitContext& ctx);
|
||||
void EmitSetOFlag(EmitContext& ctx);
|
||||
void EmitWorkgroupId(EmitContext& ctx, IR::Inst& inst);
|
||||
void EmitLocalInvocationId(EmitContext& ctx, IR::Inst& inst);
|
||||
void EmitInvocationId(EmitContext& ctx, IR::Inst& inst);
|
||||
void EmitInvocationInfo(EmitContext& ctx, IR::Inst& inst);
|
||||
void EmitSampleId(EmitContext& ctx, IR::Inst& inst);
|
||||
void EmitIsHelperInvocation(EmitContext& ctx, IR::Inst& inst);
|
||||
void EmitSR_WScaleFactorXY(EmitContext& ctx, IR::Inst& inst);
|
||||
void EmitSR_WScaleFactorZ(EmitContext& ctx, IR::Inst& inst);
|
||||
void EmitYDirection(EmitContext& ctx, IR::Inst& inst);
|
||||
void EmitResolutionDownFactor(EmitContext& ctx, IR::Inst& inst);
|
||||
void EmitRenderArea(EmitContext& ctx, IR::Inst& inst);
|
||||
void EmitLoadLocal(EmitContext& ctx, IR::Inst& inst, std::string_view word_offset);
|
||||
void EmitWriteLocal(EmitContext& ctx, std::string_view word_offset, std::string_view value);
|
||||
void EmitUndefU1(EmitContext& ctx, IR::Inst& inst);
|
||||
void EmitUndefU8(EmitContext& ctx, IR::Inst& inst);
|
||||
void EmitUndefU16(EmitContext& ctx, IR::Inst& inst);
|
||||
void EmitUndefU32(EmitContext& ctx, IR::Inst& inst);
|
||||
void EmitUndefU64(EmitContext& ctx, IR::Inst& inst);
|
||||
void EmitLoadGlobalU8(EmitContext& ctx);
|
||||
void EmitLoadGlobalS8(EmitContext& ctx);
|
||||
void EmitLoadGlobalU16(EmitContext& ctx);
|
||||
void EmitLoadGlobalS16(EmitContext& ctx);
|
||||
void EmitLoadGlobal32(EmitContext& ctx, IR::Inst& inst, std::string_view address);
|
||||
void EmitLoadGlobal64(EmitContext& ctx, IR::Inst& inst, std::string_view address);
|
||||
void EmitLoadGlobal128(EmitContext& ctx, IR::Inst& inst, std::string_view address);
|
||||
void EmitWriteGlobalU8(EmitContext& ctx);
|
||||
void EmitWriteGlobalS8(EmitContext& ctx);
|
||||
void EmitWriteGlobalU16(EmitContext& ctx);
|
||||
void EmitWriteGlobalS16(EmitContext& ctx);
|
||||
void EmitWriteGlobal32(EmitContext& ctx, std::string_view address, std::string_view value);
|
||||
void EmitWriteGlobal64(EmitContext& ctx, std::string_view address, std::string_view value);
|
||||
void EmitWriteGlobal128(EmitContext& ctx, std::string_view address, std::string_view value);
|
||||
void EmitLoadStorageU8(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset);
|
||||
void EmitLoadStorageS8(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset);
|
||||
void EmitLoadStorageU16(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset);
|
||||
void EmitLoadStorageS16(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset);
|
||||
void EmitLoadStorage32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset);
|
||||
void EmitLoadStorage64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset);
|
||||
void EmitLoadStorage128(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset);
|
||||
void EmitWriteStorageU8(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset,
|
||||
std::string_view value);
|
||||
void EmitWriteStorageS8(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset,
|
||||
std::string_view value);
|
||||
void EmitWriteStorageU16(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset,
|
||||
std::string_view value);
|
||||
void EmitWriteStorageS16(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset,
|
||||
std::string_view value);
|
||||
void EmitWriteStorage32(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset,
|
||||
std::string_view value);
|
||||
void EmitWriteStorage64(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset,
|
||||
std::string_view value);
|
||||
void EmitWriteStorage128(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset,
|
||||
std::string_view value);
|
||||
void EmitLoadSharedU8(EmitContext& ctx, IR::Inst& inst, std::string_view offset);
|
||||
void EmitLoadSharedS8(EmitContext& ctx, IR::Inst& inst, std::string_view offset);
|
||||
void EmitLoadSharedU16(EmitContext& ctx, IR::Inst& inst, std::string_view offset);
|
||||
void EmitLoadSharedS16(EmitContext& ctx, IR::Inst& inst, std::string_view offset);
|
||||
void EmitLoadSharedU32(EmitContext& ctx, IR::Inst& inst, std::string_view offset);
|
||||
void EmitLoadSharedU64(EmitContext& ctx, IR::Inst& inst, std::string_view offset);
|
||||
void EmitLoadSharedU128(EmitContext& ctx, IR::Inst& inst, std::string_view offset);
|
||||
void EmitWriteSharedU8(EmitContext& ctx, std::string_view offset, std::string_view value);
|
||||
void EmitWriteSharedU16(EmitContext& ctx, std::string_view offset, std::string_view value);
|
||||
void EmitWriteSharedU32(EmitContext& ctx, std::string_view offset, std::string_view value);
|
||||
void EmitWriteSharedU64(EmitContext& ctx, std::string_view offset, std::string_view value);
|
||||
void EmitWriteSharedU128(EmitContext& ctx, std::string_view offset, std::string_view value);
|
||||
void EmitCompositeConstructU32x2(EmitContext& ctx, IR::Inst& inst, std::string_view e1,
|
||||
std::string_view e2);
|
||||
void EmitCompositeConstructU32x3(EmitContext& ctx, IR::Inst& inst, std::string_view e1,
|
||||
std::string_view e2, std::string_view e3);
|
||||
void EmitCompositeConstructU32x4(EmitContext& ctx, IR::Inst& inst, std::string_view e1,
|
||||
std::string_view e2, std::string_view e3, std::string_view e4);
|
||||
void EmitCompositeExtractU32x2(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
|
||||
u32 index);
|
||||
void EmitCompositeExtractU32x3(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
|
||||
u32 index);
|
||||
void EmitCompositeExtractU32x4(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
|
||||
u32 index);
|
||||
void EmitCompositeInsertU32x2(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
|
||||
std::string_view object, u32 index);
|
||||
void EmitCompositeInsertU32x3(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
|
||||
std::string_view object, u32 index);
|
||||
void EmitCompositeInsertU32x4(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
|
||||
std::string_view object, u32 index);
|
||||
void EmitCompositeConstructF16x2(EmitContext& ctx, std::string_view e1, std::string_view e2);
|
||||
void EmitCompositeConstructF16x3(EmitContext& ctx, std::string_view e1, std::string_view e2,
|
||||
std::string_view e3);
|
||||
void EmitCompositeConstructF16x4(EmitContext& ctx, std::string_view e1, std::string_view e2,
|
||||
std::string_view e3, std::string_view e4);
|
||||
void EmitCompositeExtractF16x2(EmitContext& ctx, std::string_view composite, u32 index);
|
||||
void EmitCompositeExtractF16x3(EmitContext& ctx, std::string_view composite, u32 index);
|
||||
void EmitCompositeExtractF16x4(EmitContext& ctx, std::string_view composite, u32 index);
|
||||
void EmitCompositeInsertF16x2(EmitContext& ctx, std::string_view composite, std::string_view object,
|
||||
u32 index);
|
||||
void EmitCompositeInsertF16x3(EmitContext& ctx, std::string_view composite, std::string_view object,
|
||||
u32 index);
|
||||
void EmitCompositeInsertF16x4(EmitContext& ctx, std::string_view composite, std::string_view object,
|
||||
u32 index);
|
||||
void EmitCompositeConstructF32x2(EmitContext& ctx, IR::Inst& inst, std::string_view e1,
|
||||
std::string_view e2);
|
||||
void EmitCompositeConstructF32x3(EmitContext& ctx, IR::Inst& inst, std::string_view e1,
|
||||
std::string_view e2, std::string_view e3);
|
||||
void EmitCompositeConstructF32x4(EmitContext& ctx, IR::Inst& inst, std::string_view e1,
|
||||
std::string_view e2, std::string_view e3, std::string_view e4);
|
||||
void EmitCompositeExtractF32x2(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
|
||||
u32 index);
|
||||
void EmitCompositeExtractF32x3(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
|
||||
u32 index);
|
||||
void EmitCompositeExtractF32x4(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
|
||||
u32 index);
|
||||
void EmitCompositeInsertF32x2(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
|
||||
std::string_view object, u32 index);
|
||||
void EmitCompositeInsertF32x3(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
|
||||
std::string_view object, u32 index);
|
||||
void EmitCompositeInsertF32x4(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
|
||||
std::string_view object, u32 index);
|
||||
void EmitCompositeConstructF64x2(EmitContext& ctx);
|
||||
void EmitCompositeConstructF64x3(EmitContext& ctx);
|
||||
void EmitCompositeConstructF64x4(EmitContext& ctx);
|
||||
void EmitCompositeExtractF64x2(EmitContext& ctx);
|
||||
void EmitCompositeExtractF64x3(EmitContext& ctx);
|
||||
void EmitCompositeExtractF64x4(EmitContext& ctx);
|
||||
void EmitCompositeInsertF64x2(EmitContext& ctx, std::string_view composite, std::string_view object,
|
||||
u32 index);
|
||||
void EmitCompositeInsertF64x3(EmitContext& ctx, std::string_view composite, std::string_view object,
|
||||
u32 index);
|
||||
void EmitCompositeInsertF64x4(EmitContext& ctx, std::string_view composite, std::string_view object,
|
||||
u32 index);
|
||||
void EmitSelectU1(EmitContext& ctx, IR::Inst& inst, std::string_view cond,
|
||||
std::string_view true_value, std::string_view false_value);
|
||||
void EmitSelectU8(EmitContext& ctx, std::string_view cond, std::string_view true_value,
|
||||
std::string_view false_value);
|
||||
void EmitSelectU16(EmitContext& ctx, std::string_view cond, std::string_view true_value,
|
||||
std::string_view false_value);
|
||||
void EmitSelectU32(EmitContext& ctx, IR::Inst& inst, std::string_view cond,
|
||||
std::string_view true_value, std::string_view false_value);
|
||||
void EmitSelectU64(EmitContext& ctx, IR::Inst& inst, std::string_view cond,
|
||||
std::string_view true_value, std::string_view false_value);
|
||||
void EmitSelectF16(EmitContext& ctx, std::string_view cond, std::string_view true_value,
|
||||
std::string_view false_value);
|
||||
void EmitSelectF32(EmitContext& ctx, IR::Inst& inst, std::string_view cond,
|
||||
std::string_view true_value, std::string_view false_value);
|
||||
void EmitSelectF64(EmitContext& ctx, IR::Inst& inst, std::string_view cond,
|
||||
std::string_view true_value, std::string_view false_value);
|
||||
void EmitBitCastU16F16(EmitContext& ctx, IR::Inst& inst);
|
||||
void EmitBitCastU32F32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitBitCastU64F64(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitBitCastF16U16(EmitContext& ctx, IR::Inst& inst);
|
||||
void EmitBitCastF32U32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitBitCastF64U64(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitPackUint2x32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitUnpackUint2x32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitPackFloat2x16(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitUnpackFloat2x16(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitPackHalf2x16(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitUnpackHalf2x16(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitPackDouble2x32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitUnpackDouble2x32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitGetZeroFromOp(EmitContext& ctx);
|
||||
void EmitGetSignFromOp(EmitContext& ctx);
|
||||
void EmitGetCarryFromOp(EmitContext& ctx);
|
||||
void EmitGetOverflowFromOp(EmitContext& ctx);
|
||||
void EmitGetSparseFromOp(EmitContext& ctx);
|
||||
void EmitGetInBoundsFromOp(EmitContext& ctx);
|
||||
void EmitFPAbs16(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFPAbs32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFPAbs64(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFPAdd16(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b);
|
||||
void EmitFPAdd32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b);
|
||||
void EmitFPAdd64(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b);
|
||||
void EmitFPFma16(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b,
|
||||
std::string_view c);
|
||||
void EmitFPFma32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b,
|
||||
std::string_view c);
|
||||
void EmitFPFma64(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b,
|
||||
std::string_view c);
|
||||
void EmitFPMax32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b);
|
||||
void EmitFPMax64(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b);
|
||||
void EmitFPMin32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b);
|
||||
void EmitFPMin64(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b);
|
||||
void EmitFPMul16(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b);
|
||||
void EmitFPMul32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b);
|
||||
void EmitFPMul64(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b);
|
||||
void EmitFPNeg16(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFPNeg32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFPNeg64(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFPSin(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFPCos(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFPExp2(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFPLog2(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFPRecip32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFPRecip64(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFPRecipSqrt32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFPRecipSqrt64(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFPSqrt(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFPSaturate16(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFPSaturate32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFPSaturate64(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFPClamp16(EmitContext& ctx, IR::Inst& inst, std::string_view value,
|
||||
std::string_view min_value, std::string_view max_value);
|
||||
void EmitFPClamp32(EmitContext& ctx, IR::Inst& inst, std::string_view value,
|
||||
std::string_view min_value, std::string_view max_value);
|
||||
void EmitFPClamp64(EmitContext& ctx, IR::Inst& inst, std::string_view value,
|
||||
std::string_view min_value, std::string_view max_value);
|
||||
void EmitFPRoundEven16(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFPRoundEven32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFPRoundEven64(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFPFloor16(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFPFloor32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFPFloor64(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFPCeil16(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFPCeil32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFPCeil64(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFPTrunc16(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFPTrunc32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFPTrunc64(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFPOrdEqual16(EmitContext& ctx, std::string_view lhs, std::string_view rhs);
|
||||
void EmitFPOrdEqual32(EmitContext& ctx, IR::Inst& inst, std::string_view lhs, std::string_view rhs);
|
||||
void EmitFPOrdEqual64(EmitContext& ctx, IR::Inst& inst, std::string_view lhs, std::string_view rhs);
|
||||
void EmitFPUnordEqual16(EmitContext& ctx, std::string_view lhs, std::string_view rhs);
|
||||
void EmitFPUnordEqual32(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs);
|
||||
void EmitFPUnordEqual64(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs);
|
||||
void EmitFPOrdNotEqual16(EmitContext& ctx, std::string_view lhs, std::string_view rhs);
|
||||
void EmitFPOrdNotEqual32(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs);
|
||||
void EmitFPOrdNotEqual64(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs);
|
||||
void EmitFPUnordNotEqual16(EmitContext& ctx, std::string_view lhs, std::string_view rhs);
|
||||
void EmitFPUnordNotEqual32(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs);
|
||||
void EmitFPUnordNotEqual64(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs);
|
||||
void EmitFPOrdLessThan16(EmitContext& ctx, std::string_view lhs, std::string_view rhs);
|
||||
void EmitFPOrdLessThan32(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs);
|
||||
void EmitFPOrdLessThan64(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs);
|
||||
void EmitFPUnordLessThan16(EmitContext& ctx, std::string_view lhs, std::string_view rhs);
|
||||
void EmitFPUnordLessThan32(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs);
|
||||
void EmitFPUnordLessThan64(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs);
|
||||
void EmitFPOrdGreaterThan16(EmitContext& ctx, std::string_view lhs, std::string_view rhs);
|
||||
void EmitFPOrdGreaterThan32(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs);
|
||||
void EmitFPOrdGreaterThan64(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs);
|
||||
void EmitFPUnordGreaterThan16(EmitContext& ctx, std::string_view lhs, std::string_view rhs);
|
||||
void EmitFPUnordGreaterThan32(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs);
|
||||
void EmitFPUnordGreaterThan64(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs);
|
||||
void EmitFPOrdLessThanEqual16(EmitContext& ctx, std::string_view lhs, std::string_view rhs);
|
||||
void EmitFPOrdLessThanEqual32(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs);
|
||||
void EmitFPOrdLessThanEqual64(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs);
|
||||
void EmitFPUnordLessThanEqual16(EmitContext& ctx, std::string_view lhs, std::string_view rhs);
|
||||
void EmitFPUnordLessThanEqual32(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs);
|
||||
void EmitFPUnordLessThanEqual64(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs);
|
||||
void EmitFPOrdGreaterThanEqual16(EmitContext& ctx, std::string_view lhs, std::string_view rhs);
|
||||
void EmitFPOrdGreaterThanEqual32(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs);
|
||||
void EmitFPOrdGreaterThanEqual64(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs);
|
||||
void EmitFPUnordGreaterThanEqual16(EmitContext& ctx, std::string_view lhs, std::string_view rhs);
|
||||
void EmitFPUnordGreaterThanEqual32(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs);
|
||||
void EmitFPUnordGreaterThanEqual64(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs);
|
||||
void EmitFPIsNan16(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFPIsNan32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFPIsNan64(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitIAdd32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b);
|
||||
void EmitIAdd64(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b);
|
||||
void EmitISub32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b);
|
||||
void EmitISub64(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b);
|
||||
void EmitIMul32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b);
|
||||
void EmitSDiv32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b);
|
||||
void EmitUDiv32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b);
|
||||
void EmitINeg32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitINeg64(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitIAbs32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitIAbs64(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitShiftLeftLogical32(EmitContext& ctx, IR::Inst& inst, std::string_view base,
|
||||
std::string_view shift);
|
||||
void EmitShiftLeftLogical64(EmitContext& ctx, IR::Inst& inst, std::string_view base,
|
||||
std::string_view shift);
|
||||
void EmitShiftRightLogical32(EmitContext& ctx, IR::Inst& inst, std::string_view base,
|
||||
std::string_view shift);
|
||||
void EmitShiftRightLogical64(EmitContext& ctx, IR::Inst& inst, std::string_view base,
|
||||
std::string_view shift);
|
||||
void EmitShiftRightArithmetic32(EmitContext& ctx, IR::Inst& inst, std::string_view base,
|
||||
std::string_view shift);
|
||||
void EmitShiftRightArithmetic64(EmitContext& ctx, IR::Inst& inst, std::string_view base,
|
||||
std::string_view shift);
|
||||
void EmitBitwiseAnd32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b);
|
||||
void EmitBitwiseOr32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b);
|
||||
void EmitBitwiseXor32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b);
|
||||
void EmitBitFieldInsert(EmitContext& ctx, IR::Inst& inst, std::string_view base,
|
||||
std::string_view insert, std::string_view offset, std::string_view count);
|
||||
void EmitBitFieldSExtract(EmitContext& ctx, IR::Inst& inst, std::string_view base,
|
||||
std::string_view offset, std::string_view count);
|
||||
void EmitBitFieldUExtract(EmitContext& ctx, IR::Inst& inst, std::string_view base,
|
||||
std::string_view offset, std::string_view count);
|
||||
void EmitBitReverse32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitBitCount32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitBitwiseNot32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFindSMsb32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFindUMsb32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitSMin32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b);
|
||||
void EmitUMin32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b);
|
||||
void EmitSMax32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b);
|
||||
void EmitUMax32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b);
|
||||
void EmitSClamp32(EmitContext& ctx, IR::Inst& inst, std::string_view value, std::string_view min,
|
||||
std::string_view max);
|
||||
void EmitUClamp32(EmitContext& ctx, IR::Inst& inst, std::string_view value, std::string_view min,
|
||||
std::string_view max);
|
||||
void EmitSLessThan(EmitContext& ctx, IR::Inst& inst, std::string_view lhs, std::string_view rhs);
|
||||
void EmitULessThan(EmitContext& ctx, IR::Inst& inst, std::string_view lhs, std::string_view rhs);
|
||||
void EmitIEqual(EmitContext& ctx, IR::Inst& inst, std::string_view lhs, std::string_view rhs);
|
||||
void EmitSLessThanEqual(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs);
|
||||
void EmitULessThanEqual(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs);
|
||||
void EmitSGreaterThan(EmitContext& ctx, IR::Inst& inst, std::string_view lhs, std::string_view rhs);
|
||||
void EmitUGreaterThan(EmitContext& ctx, IR::Inst& inst, std::string_view lhs, std::string_view rhs);
|
||||
void EmitINotEqual(EmitContext& ctx, IR::Inst& inst, std::string_view lhs, std::string_view rhs);
|
||||
void EmitSGreaterThanEqual(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs);
|
||||
void EmitUGreaterThanEqual(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs);
|
||||
void EmitSharedAtomicIAdd32(EmitContext& ctx, IR::Inst& inst, std::string_view pointer_offset,
|
||||
std::string_view value);
|
||||
void EmitSharedAtomicSMin32(EmitContext& ctx, IR::Inst& inst, std::string_view pointer_offset,
|
||||
std::string_view value);
|
||||
void EmitSharedAtomicUMin32(EmitContext& ctx, IR::Inst& inst, std::string_view pointer_offset,
|
||||
std::string_view value);
|
||||
void EmitSharedAtomicSMax32(EmitContext& ctx, IR::Inst& inst, std::string_view pointer_offset,
|
||||
std::string_view value);
|
||||
void EmitSharedAtomicUMax32(EmitContext& ctx, IR::Inst& inst, std::string_view pointer_offset,
|
||||
std::string_view value);
|
||||
void EmitSharedAtomicInc32(EmitContext& ctx, IR::Inst& inst, std::string_view pointer_offset,
|
||||
std::string_view value);
|
||||
void EmitSharedAtomicDec32(EmitContext& ctx, IR::Inst& inst, std::string_view pointer_offset,
|
||||
std::string_view value);
|
||||
void EmitSharedAtomicAnd32(EmitContext& ctx, IR::Inst& inst, std::string_view pointer_offset,
|
||||
std::string_view value);
|
||||
void EmitSharedAtomicOr32(EmitContext& ctx, IR::Inst& inst, std::string_view pointer_offset,
|
||||
std::string_view value);
|
||||
void EmitSharedAtomicXor32(EmitContext& ctx, IR::Inst& inst, std::string_view pointer_offset,
|
||||
std::string_view value);
|
||||
void EmitSharedAtomicExchange32(EmitContext& ctx, IR::Inst& inst, std::string_view pointer_offset,
|
||||
std::string_view value);
|
||||
void EmitSharedAtomicExchange64(EmitContext& ctx, IR::Inst& inst, std::string_view pointer_offset,
|
||||
std::string_view value);
|
||||
void EmitSharedAtomicExchange32x2(EmitContext& ctx, IR::Inst& inst, std::string_view pointer_offset,
|
||||
std::string_view value);
|
||||
void EmitStorageAtomicIAdd32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicSMin32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicUMin32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicSMax32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicUMax32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicInc32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicDec32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicAnd32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicOr32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicXor32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicExchange32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicIAdd64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicSMin64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicUMin64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicSMax64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicUMax64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicAnd64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicOr64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicXor64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicExchange64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicIAdd32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicSMin32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicUMin32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicSMax32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicUMax32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicAnd32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicOr32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicXor32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicExchange32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicAddF32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicAddF16x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicAddF32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicMinF16x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicMinF32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicMaxF16x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicMaxF32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitGlobalAtomicIAdd32(EmitContext& ctx);
|
||||
void EmitGlobalAtomicSMin32(EmitContext& ctx);
|
||||
void EmitGlobalAtomicUMin32(EmitContext& ctx);
|
||||
void EmitGlobalAtomicSMax32(EmitContext& ctx);
|
||||
void EmitGlobalAtomicUMax32(EmitContext& ctx);
|
||||
void EmitGlobalAtomicInc32(EmitContext& ctx);
|
||||
void EmitGlobalAtomicDec32(EmitContext& ctx);
|
||||
void EmitGlobalAtomicAnd32(EmitContext& ctx);
|
||||
void EmitGlobalAtomicOr32(EmitContext& ctx);
|
||||
void EmitGlobalAtomicXor32(EmitContext& ctx);
|
||||
void EmitGlobalAtomicExchange32(EmitContext& ctx);
|
||||
void EmitGlobalAtomicIAdd64(EmitContext& ctx);
|
||||
void EmitGlobalAtomicSMin64(EmitContext& ctx);
|
||||
void EmitGlobalAtomicUMin64(EmitContext& ctx);
|
||||
void EmitGlobalAtomicSMax64(EmitContext& ctx);
|
||||
void EmitGlobalAtomicUMax64(EmitContext& ctx);
|
||||
void EmitGlobalAtomicInc64(EmitContext& ctx);
|
||||
void EmitGlobalAtomicDec64(EmitContext& ctx);
|
||||
void EmitGlobalAtomicAnd64(EmitContext& ctx);
|
||||
void EmitGlobalAtomicOr64(EmitContext& ctx);
|
||||
void EmitGlobalAtomicXor64(EmitContext& ctx);
|
||||
void EmitGlobalAtomicExchange64(EmitContext& ctx);
|
||||
void EmitGlobalAtomicIAdd32x2(EmitContext& ctx);
|
||||
void EmitGlobalAtomicSMin32x2(EmitContext& ctx);
|
||||
void EmitGlobalAtomicUMin32x2(EmitContext& ctx);
|
||||
void EmitGlobalAtomicSMax32x2(EmitContext& ctx);
|
||||
void EmitGlobalAtomicUMax32x2(EmitContext& ctx);
|
||||
void EmitGlobalAtomicInc32x2(EmitContext& ctx);
|
||||
void EmitGlobalAtomicDec32x2(EmitContext& ctx);
|
||||
void EmitGlobalAtomicAnd32x2(EmitContext& ctx);
|
||||
void EmitGlobalAtomicOr32x2(EmitContext& ctx);
|
||||
void EmitGlobalAtomicXor32x2(EmitContext& ctx);
|
||||
void EmitGlobalAtomicExchange32x2(EmitContext& ctx);
|
||||
void EmitGlobalAtomicAddF32(EmitContext& ctx);
|
||||
void EmitGlobalAtomicAddF16x2(EmitContext& ctx);
|
||||
void EmitGlobalAtomicAddF32x2(EmitContext& ctx);
|
||||
void EmitGlobalAtomicMinF16x2(EmitContext& ctx);
|
||||
void EmitGlobalAtomicMinF32x2(EmitContext& ctx);
|
||||
void EmitGlobalAtomicMaxF16x2(EmitContext& ctx);
|
||||
void EmitGlobalAtomicMaxF32x2(EmitContext& ctx);
|
||||
void EmitLogicalOr(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b);
|
||||
void EmitLogicalAnd(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b);
|
||||
void EmitLogicalXor(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b);
|
||||
void EmitLogicalNot(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertS16F16(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertS16F32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertS16F64(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertS32F16(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertS32F32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertS32F64(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertS64F16(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertS64F32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertS64F64(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertU16F16(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertU16F32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertU16F64(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertU32F16(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertU32F32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertU32F64(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertU64F16(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertU64F32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertU64F64(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertU64U32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertU32U64(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertF16F32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertF32F16(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertF32F64(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertF64F32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertF16S8(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertF16S16(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertF16S32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertF16S64(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertF16U8(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertF16U16(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertF16U32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertF16U64(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertF32S8(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertF32S16(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertF32S32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertF32S64(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertF32U8(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertF32U16(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertF32U32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertF32U64(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertF64S8(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertF64S16(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertF64S32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertF64S64(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertF64U8(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertF64U16(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertF64U32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertF64U64(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertU16U32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertU32U16(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertU8U32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertU32U8(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertS32S8(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertS32S16(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitBindlessImageSampleImplicitLod(EmitContext&);
|
||||
void EmitBindlessImageSampleExplicitLod(EmitContext&);
|
||||
void EmitBindlessImageSampleDrefImplicitLod(EmitContext&);
|
||||
void EmitBindlessImageSampleDrefExplicitLod(EmitContext&);
|
||||
void EmitBindlessImageGather(EmitContext&);
|
||||
void EmitBindlessImageGatherDref(EmitContext&);
|
||||
void EmitBindlessImageFetch(EmitContext&);
|
||||
void EmitBindlessImageQueryDimensions(EmitContext&);
|
||||
void EmitBindlessImageQueryLod(EmitContext&);
|
||||
void EmitBindlessImageGradient(EmitContext&);
|
||||
void EmitBindlessImageRead(EmitContext&);
|
||||
void EmitBindlessImageWrite(EmitContext&);
|
||||
void EmitBoundImageSampleImplicitLod(EmitContext&);
|
||||
void EmitBoundImageSampleExplicitLod(EmitContext&);
|
||||
void EmitBoundImageSampleDrefImplicitLod(EmitContext&);
|
||||
void EmitBoundImageSampleDrefExplicitLod(EmitContext&);
|
||||
void EmitBoundImageGather(EmitContext&);
|
||||
void EmitBoundImageGatherDref(EmitContext&);
|
||||
void EmitBoundImageFetch(EmitContext&);
|
||||
void EmitBoundImageQueryDimensions(EmitContext&);
|
||||
void EmitBoundImageQueryLod(EmitContext&);
|
||||
void EmitBoundImageGradient(EmitContext&);
|
||||
void EmitBoundImageRead(EmitContext&);
|
||||
void EmitBoundImageWrite(EmitContext&);
|
||||
void EmitImageSampleImplicitLod(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords, std::string_view bias_lc,
|
||||
const IR::Value& offset);
|
||||
void EmitImageSampleExplicitLod(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords, std::string_view lod_lc,
|
||||
const IR::Value& offset);
|
||||
void EmitImageSampleDrefImplicitLod(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords, std::string_view dref,
|
||||
std::string_view bias_lc, const IR::Value& offset);
|
||||
void EmitImageSampleDrefExplicitLod(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords, std::string_view dref,
|
||||
std::string_view lod_lc, const IR::Value& offset);
|
||||
void EmitImageGather(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords, const IR::Value& offset, const IR::Value& offset2);
|
||||
void EmitImageGatherDref(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords, const IR::Value& offset, const IR::Value& offset2,
|
||||
std::string_view dref);
|
||||
void EmitImageFetch(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords, const IR::Value& offset, std::string_view lod,
|
||||
std::string_view ms);
|
||||
void EmitImageQueryDimensions(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view lod, const IR::Value& skip_mips);
|
||||
void EmitImageQueryLod(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords);
|
||||
void EmitImageGradient(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords, const IR::Value& derivatives,
|
||||
const IR::Value& offset, const IR::Value& lod_clamp);
|
||||
void EmitImageRead(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords);
|
||||
void EmitImageWrite(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords, std::string_view color);
|
||||
void EmitIsTextureScaled(EmitContext& ctx, IR::Inst& inst, const IR::Value& index);
|
||||
void EmitIsImageScaled(EmitContext& ctx, IR::Inst& inst, const IR::Value& index);
|
||||
void EmitBindlessImageAtomicIAdd32(EmitContext&);
|
||||
void EmitBindlessImageAtomicSMin32(EmitContext&);
|
||||
void EmitBindlessImageAtomicUMin32(EmitContext&);
|
||||
void EmitBindlessImageAtomicSMax32(EmitContext&);
|
||||
void EmitBindlessImageAtomicUMax32(EmitContext&);
|
||||
void EmitBindlessImageAtomicInc32(EmitContext&);
|
||||
void EmitBindlessImageAtomicDec32(EmitContext&);
|
||||
void EmitBindlessImageAtomicAnd32(EmitContext&);
|
||||
void EmitBindlessImageAtomicOr32(EmitContext&);
|
||||
void EmitBindlessImageAtomicXor32(EmitContext&);
|
||||
void EmitBindlessImageAtomicExchange32(EmitContext&);
|
||||
void EmitBoundImageAtomicIAdd32(EmitContext&);
|
||||
void EmitBoundImageAtomicSMin32(EmitContext&);
|
||||
void EmitBoundImageAtomicUMin32(EmitContext&);
|
||||
void EmitBoundImageAtomicSMax32(EmitContext&);
|
||||
void EmitBoundImageAtomicUMax32(EmitContext&);
|
||||
void EmitBoundImageAtomicInc32(EmitContext&);
|
||||
void EmitBoundImageAtomicDec32(EmitContext&);
|
||||
void EmitBoundImageAtomicAnd32(EmitContext&);
|
||||
void EmitBoundImageAtomicOr32(EmitContext&);
|
||||
void EmitBoundImageAtomicXor32(EmitContext&);
|
||||
void EmitBoundImageAtomicExchange32(EmitContext&);
|
||||
void EmitImageAtomicIAdd32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords, std::string_view value);
|
||||
void EmitImageAtomicSMin32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords, std::string_view value);
|
||||
void EmitImageAtomicUMin32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords, std::string_view value);
|
||||
void EmitImageAtomicSMax32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords, std::string_view value);
|
||||
void EmitImageAtomicUMax32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords, std::string_view value);
|
||||
void EmitImageAtomicInc32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords, std::string_view value);
|
||||
void EmitImageAtomicDec32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords, std::string_view value);
|
||||
void EmitImageAtomicAnd32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords, std::string_view value);
|
||||
void EmitImageAtomicOr32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords, std::string_view value);
|
||||
void EmitImageAtomicXor32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords, std::string_view value);
|
||||
void EmitImageAtomicExchange32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords, std::string_view value);
|
||||
void EmitLaneId(EmitContext& ctx, IR::Inst& inst);
|
||||
void EmitVoteAll(EmitContext& ctx, IR::Inst& inst, std::string_view pred);
|
||||
void EmitVoteAny(EmitContext& ctx, IR::Inst& inst, std::string_view pred);
|
||||
void EmitVoteEqual(EmitContext& ctx, IR::Inst& inst, std::string_view pred);
|
||||
void EmitSubgroupBallot(EmitContext& ctx, IR::Inst& inst, std::string_view pred);
|
||||
void EmitSubgroupEqMask(EmitContext& ctx, IR::Inst& inst);
|
||||
void EmitSubgroupLtMask(EmitContext& ctx, IR::Inst& inst);
|
||||
void EmitSubgroupLeMask(EmitContext& ctx, IR::Inst& inst);
|
||||
void EmitSubgroupGtMask(EmitContext& ctx, IR::Inst& inst);
|
||||
void EmitSubgroupGeMask(EmitContext& ctx, IR::Inst& inst);
|
||||
void EmitShuffleIndex(EmitContext& ctx, IR::Inst& inst, std::string_view value,
|
||||
std::string_view index, std::string_view clamp,
|
||||
std::string_view segmentation_mask);
|
||||
void EmitShuffleUp(EmitContext& ctx, IR::Inst& inst, std::string_view value, std::string_view index,
|
||||
std::string_view clamp, std::string_view segmentation_mask);
|
||||
void EmitShuffleDown(EmitContext& ctx, IR::Inst& inst, std::string_view value,
|
||||
std::string_view index, std::string_view clamp,
|
||||
std::string_view segmentation_mask);
|
||||
void EmitShuffleButterfly(EmitContext& ctx, IR::Inst& inst, std::string_view value,
|
||||
std::string_view index, std::string_view clamp,
|
||||
std::string_view segmentation_mask);
|
||||
void EmitFSwizzleAdd(EmitContext& ctx, IR::Inst& inst, std::string_view op_a, std::string_view op_b,
|
||||
std::string_view swizzle);
|
||||
void EmitDPdxFine(EmitContext& ctx, IR::Inst& inst, std::string_view op_a);
|
||||
void EmitDPdyFine(EmitContext& ctx, IR::Inst& inst, std::string_view op_a);
|
||||
void EmitDPdxCoarse(EmitContext& ctx, IR::Inst& inst, std::string_view op_a);
|
||||
void EmitDPdyCoarse(EmitContext& ctx, IR::Inst& inst, std::string_view op_a);
|
||||
|
||||
} // namespace Shader::Backend::GLSL
|
||||
266
gpu/third_party/suyu/shader_recompiler/backend/glsl/emit_glsl_integer.cpp
vendored
Normal file
266
gpu/third_party/suyu/shader_recompiler/backend/glsl/emit_glsl_integer.cpp
vendored
Normal file
@@ -0,0 +1,266 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2025 suyu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "shader_recompiler/backend/glsl/emit_glsl_instructions.h"
|
||||
#include "shader_recompiler/backend/glsl/glsl_emit_context.h"
|
||||
#include "shader_recompiler/frontend/ir/value.h"
|
||||
|
||||
namespace Shader::Backend::GLSL {
|
||||
namespace {
|
||||
void SetZeroFlag(EmitContext& ctx, IR::Inst& inst, std::string_view result) {
|
||||
IR::Inst* const zero{inst.GetAssociatedPseudoOperation(IR::Opcode::GetZeroFromOp)};
|
||||
if (!zero) {
|
||||
return;
|
||||
}
|
||||
ctx.AddU1("{}={}==0;", *zero, result);
|
||||
zero->Invalidate();
|
||||
}
|
||||
|
||||
void SetSignFlag(EmitContext& ctx, IR::Inst& inst, std::string_view result) {
|
||||
IR::Inst* const sign{inst.GetAssociatedPseudoOperation(IR::Opcode::GetSignFromOp)};
|
||||
if (!sign) {
|
||||
return;
|
||||
}
|
||||
ctx.AddU1("{}=int({})<0;", *sign, result);
|
||||
sign->Invalidate();
|
||||
}
|
||||
|
||||
void BitwiseLogicalOp(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b,
|
||||
char lop) {
|
||||
const auto result{ctx.var_alloc.Define(inst, GlslVarType::U32)};
|
||||
ctx.Add("{}={}{}{};", result, a, lop, b);
|
||||
SetZeroFlag(ctx, inst, result);
|
||||
SetSignFlag(ctx, inst, result);
|
||||
}
|
||||
} // Anonymous namespace
|
||||
|
||||
void EmitIAdd32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
|
||||
// Compute the overflow CC first as it requires the original operand values,
|
||||
// which may be overwritten by the result of the addition
|
||||
if (IR::Inst * overflow{inst.GetAssociatedPseudoOperation(IR::Opcode::GetOverflowFromOp)}) {
|
||||
// https://stackoverflow.com/questions/55468823/how-to-detect-integer-overflow-in-c
|
||||
constexpr u32 s32_max{static_cast<u32>((std::numeric_limits<s32>::max)())};
|
||||
const auto sub_a{fmt::format("{}u-{}", s32_max, a)};
|
||||
const auto positive_result{fmt::format("int({})>int({})", b, sub_a)};
|
||||
const auto negative_result{fmt::format("int({})<int({})", b, sub_a)};
|
||||
ctx.AddU1("{}=int({})>=0?{}:{};", *overflow, a, positive_result, negative_result);
|
||||
overflow->Invalidate();
|
||||
}
|
||||
const auto result{ctx.var_alloc.Define(inst, GlslVarType::U32)};
|
||||
if (IR::Inst* const carry{inst.GetAssociatedPseudoOperation(IR::Opcode::GetCarryFromOp)}) {
|
||||
ctx.uses_cc_carry = true;
|
||||
ctx.Add("{}=uaddCarry({},{},carry);", result, a, b);
|
||||
ctx.AddU1("{}=carry!=0;", *carry);
|
||||
carry->Invalidate();
|
||||
} else {
|
||||
ctx.Add("{}={}+{};", result, a, b);
|
||||
}
|
||||
SetZeroFlag(ctx, inst, result);
|
||||
SetSignFlag(ctx, inst, result);
|
||||
}
|
||||
|
||||
void EmitIAdd64(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
|
||||
ctx.AddU64("{}={}+{};", inst, a, b);
|
||||
}
|
||||
|
||||
void EmitISub32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
|
||||
ctx.AddU32("{}={}-{};", inst, a, b);
|
||||
}
|
||||
|
||||
void EmitISub64(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
|
||||
ctx.AddU64("{}={}-{};", inst, a, b);
|
||||
}
|
||||
|
||||
void EmitIMul32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
|
||||
ctx.AddU32("{}=uint({}*{});", inst, a, b);
|
||||
}
|
||||
|
||||
void EmitSDiv32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
|
||||
ctx.AddU32("{}=uint(int({})/int({}));", inst, a, b);
|
||||
}
|
||||
|
||||
void EmitUDiv32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
|
||||
ctx.AddU32("{}={}/{};", inst, a, b);
|
||||
}
|
||||
|
||||
void EmitINeg32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddU32("{}=uint(int(0)-int({}));", inst, value);
|
||||
}
|
||||
|
||||
void EmitINeg64(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddU64("{}=uint64_t(int64_t(0)-int64_t({}));", inst, value);
|
||||
}
|
||||
|
||||
void EmitIAbs32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddU32("{}=abs(int({}));", inst, value);
|
||||
}
|
||||
|
||||
void EmitIAbs64(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
// TODO: Uhm, are you sure? This may crash on some drivers!
|
||||
ctx.AddU32("{}=abs(int64_t({}));", inst, value);
|
||||
}
|
||||
|
||||
void EmitShiftLeftLogical32(EmitContext& ctx, IR::Inst& inst, std::string_view base,
|
||||
std::string_view shift) {
|
||||
ctx.AddU32("{}={}<<{};", inst, base, shift);
|
||||
}
|
||||
|
||||
void EmitShiftLeftLogical64(EmitContext& ctx, IR::Inst& inst, std::string_view base,
|
||||
std::string_view shift) {
|
||||
ctx.AddU64("{}={}<<{};", inst, base, shift);
|
||||
}
|
||||
|
||||
void EmitShiftRightLogical32(EmitContext& ctx, IR::Inst& inst, std::string_view base,
|
||||
std::string_view shift) {
|
||||
ctx.AddU32("{}={}>>{};", inst, base, shift);
|
||||
}
|
||||
|
||||
void EmitShiftRightLogical64(EmitContext& ctx, IR::Inst& inst, std::string_view base,
|
||||
std::string_view shift) {
|
||||
ctx.AddU64("{}={}>>{};", inst, base, shift);
|
||||
}
|
||||
|
||||
void EmitShiftRightArithmetic32(EmitContext& ctx, IR::Inst& inst, std::string_view base,
|
||||
std::string_view shift) {
|
||||
ctx.AddU32("{}=int({})>>{};", inst, base, shift);
|
||||
}
|
||||
|
||||
void EmitShiftRightArithmetic64(EmitContext& ctx, IR::Inst& inst, std::string_view base,
|
||||
std::string_view shift) {
|
||||
ctx.AddU64("{}=int64_t({})>>{};", inst, base, shift);
|
||||
}
|
||||
|
||||
void EmitBitwiseAnd32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
|
||||
BitwiseLogicalOp(ctx, inst, a, b, '&');
|
||||
}
|
||||
|
||||
void EmitBitwiseOr32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
|
||||
BitwiseLogicalOp(ctx, inst, a, b, '|');
|
||||
}
|
||||
|
||||
void EmitBitwiseXor32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
|
||||
BitwiseLogicalOp(ctx, inst, a, b, '^');
|
||||
}
|
||||
|
||||
void EmitBitFieldInsert(EmitContext& ctx, IR::Inst& inst, std::string_view base,
|
||||
std::string_view insert, std::string_view offset, std::string_view count) {
|
||||
ctx.AddU32("{}=bitfieldInsert({},{},int({}),int({}));", inst, base, insert, offset, count);
|
||||
}
|
||||
|
||||
void EmitBitFieldSExtract(EmitContext& ctx, IR::Inst& inst, std::string_view base,
|
||||
std::string_view offset, std::string_view count) {
|
||||
const auto result{ctx.var_alloc.Define(inst, GlslVarType::U32)};
|
||||
ctx.Add("{}=uint(bitfieldExtract(int({}),int({}),int({})));", result, base, offset, count);
|
||||
SetZeroFlag(ctx, inst, result);
|
||||
SetSignFlag(ctx, inst, result);
|
||||
}
|
||||
|
||||
void EmitBitFieldUExtract(EmitContext& ctx, IR::Inst& inst, std::string_view base,
|
||||
std::string_view offset, std::string_view count) {
|
||||
const auto result{ctx.var_alloc.Define(inst, GlslVarType::U32)};
|
||||
ctx.Add("{}=uint(bitfieldExtract(uint({}),int({}),int({})));", result, base, offset, count);
|
||||
SetZeroFlag(ctx, inst, result);
|
||||
SetSignFlag(ctx, inst, result);
|
||||
}
|
||||
|
||||
void EmitBitReverse32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddU32("{}=bitfieldReverse({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitBitCount32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddU32("{}=bitCount({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitBitwiseNot32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddU32("{}=~{};", inst, value);
|
||||
}
|
||||
|
||||
void EmitFindSMsb32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddU32("{}=findMSB(int({}));", inst, value);
|
||||
}
|
||||
|
||||
void EmitFindUMsb32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddU32("{}=findMSB(uint({}));", inst, value);
|
||||
}
|
||||
|
||||
void EmitSMin32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
|
||||
ctx.AddU32("{}=min(int({}),int({}));", inst, a, b);
|
||||
}
|
||||
|
||||
void EmitUMin32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
|
||||
ctx.AddU32("{}=min(uint({}),uint({}));", inst, a, b);
|
||||
}
|
||||
|
||||
void EmitSMax32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
|
||||
ctx.AddU32("{}=max(int({}),int({}));", inst, a, b);
|
||||
}
|
||||
|
||||
void EmitUMax32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
|
||||
ctx.AddU32("{}=max(uint({}),uint({}));", inst, a, b);
|
||||
}
|
||||
|
||||
void EmitSClamp32(EmitContext& ctx, IR::Inst& inst, std::string_view value, std::string_view min,
|
||||
std::string_view max) {
|
||||
const auto result{ctx.var_alloc.Define(inst, GlslVarType::U32)};
|
||||
ctx.Add("{}=clamp(int({}),int({}),int({}));", result, value, min, max);
|
||||
SetZeroFlag(ctx, inst, result);
|
||||
SetSignFlag(ctx, inst, result);
|
||||
}
|
||||
|
||||
void EmitUClamp32(EmitContext& ctx, IR::Inst& inst, std::string_view value, std::string_view min,
|
||||
std::string_view max) {
|
||||
const auto result{ctx.var_alloc.Define(inst, GlslVarType::U32)};
|
||||
ctx.Add("{}=clamp(uint({}),uint({}),uint({}));", result, value, min, max);
|
||||
SetZeroFlag(ctx, inst, result);
|
||||
SetSignFlag(ctx, inst, result);
|
||||
}
|
||||
|
||||
void EmitSLessThan(EmitContext& ctx, IR::Inst& inst, std::string_view lhs, std::string_view rhs) {
|
||||
ctx.AddU1("{}=int({})<int({});", inst, lhs, rhs);
|
||||
}
|
||||
|
||||
void EmitULessThan(EmitContext& ctx, IR::Inst& inst, std::string_view lhs, std::string_view rhs) {
|
||||
ctx.AddU1("{}=uint({})<uint({});", inst, lhs, rhs);
|
||||
}
|
||||
|
||||
void EmitIEqual(EmitContext& ctx, IR::Inst& inst, std::string_view lhs, std::string_view rhs) {
|
||||
ctx.AddU1("{}={}=={};", inst, lhs, rhs);
|
||||
}
|
||||
|
||||
void EmitSLessThanEqual(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs) {
|
||||
ctx.AddU1("{}=int({})<=int({});", inst, lhs, rhs);
|
||||
}
|
||||
|
||||
void EmitULessThanEqual(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs) {
|
||||
ctx.AddU1("{}=uint({})<=uint({});", inst, lhs, rhs);
|
||||
}
|
||||
|
||||
void EmitSGreaterThan(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs) {
|
||||
ctx.AddU1("{}=int({})>int({});", inst, lhs, rhs);
|
||||
}
|
||||
|
||||
void EmitUGreaterThan(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs) {
|
||||
ctx.AddU1("{}=uint({})>uint({});", inst, lhs, rhs);
|
||||
}
|
||||
|
||||
void EmitINotEqual(EmitContext& ctx, IR::Inst& inst, std::string_view lhs, std::string_view rhs) {
|
||||
ctx.AddU1("{}={}!={};", inst, lhs, rhs);
|
||||
}
|
||||
|
||||
void EmitSGreaterThanEqual(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs) {
|
||||
ctx.AddU1("{}=int({})>=int({});", inst, lhs, rhs);
|
||||
}
|
||||
|
||||
void EmitUGreaterThanEqual(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs) {
|
||||
ctx.AddU1("{}=uint({})>=uint({});", inst, lhs, rhs);
|
||||
}
|
||||
} // namespace Shader::Backend::GLSL
|
||||
25
gpu/third_party/suyu/shader_recompiler/backend/glsl/emit_glsl_logical.cpp
vendored
Normal file
25
gpu/third_party/suyu/shader_recompiler/backend/glsl/emit_glsl_logical.cpp
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "shader_recompiler/backend/glsl/emit_glsl_instructions.h"
|
||||
#include "shader_recompiler/backend/glsl/glsl_emit_context.h"
|
||||
#include "shader_recompiler/frontend/ir/value.h"
|
||||
|
||||
namespace Shader::Backend::GLSL {
|
||||
|
||||
void EmitLogicalOr(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
|
||||
ctx.AddU1("{}={}||{};", inst, a, b);
|
||||
}
|
||||
|
||||
void EmitLogicalAnd(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
|
||||
ctx.AddU1("{}={}&&{};", inst, a, b);
|
||||
}
|
||||
|
||||
void EmitLogicalXor(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
|
||||
ctx.AddU1("{}={}^^{};", inst, a, b);
|
||||
}
|
||||
|
||||
void EmitLogicalNot(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddU1("{}=!{};", inst, value);
|
||||
}
|
||||
} // namespace Shader::Backend::GLSL
|
||||
201
gpu/third_party/suyu/shader_recompiler/backend/glsl/emit_glsl_memory.cpp
vendored
Normal file
201
gpu/third_party/suyu/shader_recompiler/backend/glsl/emit_glsl_memory.cpp
vendored
Normal file
@@ -0,0 +1,201 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <string_view>
|
||||
|
||||
#include "shader_recompiler/backend/glsl/emit_glsl_instructions.h"
|
||||
#include "shader_recompiler/backend/glsl/glsl_emit_context.h"
|
||||
#include "shader_recompiler/frontend/ir/value.h"
|
||||
#include "shader_recompiler/profile.h"
|
||||
|
||||
namespace Shader::Backend::GLSL {
|
||||
namespace {
|
||||
constexpr char cas_loop[]{"for(;;){{uint old_value={};uint "
|
||||
"cas_result=atomicCompSwap({},old_value,bitfieldInsert({},{},{},{}));"
|
||||
"if(cas_result==old_value){{break;}}}}"};
|
||||
|
||||
void SsboWriteCas(EmitContext& ctx, const IR::Value& binding, std::string_view offset_var,
|
||||
std::string_view value, std::string_view bit_offset, u32 num_bits) {
|
||||
const auto ssbo{fmt::format("{}_ssbo{}[{}>>2]", ctx.stage_name, binding.U32(), offset_var)};
|
||||
ctx.Add(cas_loop, ssbo, ssbo, ssbo, value, bit_offset, num_bits);
|
||||
}
|
||||
} // Anonymous namespace
|
||||
|
||||
void EmitLoadGlobalU8(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitLoadGlobalS8(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitLoadGlobalU16(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitLoadGlobalS16(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitLoadGlobal32(EmitContext& ctx, IR::Inst& inst, std::string_view address) {
|
||||
if (ctx.profile.support_int64) {
|
||||
return ctx.AddU32("{}=LoadGlobal32({});", inst, address);
|
||||
}
|
||||
LOG_WARNING(Shader_GLSL, "Int64 not supported, ignoring memory operation");
|
||||
ctx.AddU32("{}=0u;", inst);
|
||||
}
|
||||
|
||||
void EmitLoadGlobal64(EmitContext& ctx, IR::Inst& inst, std::string_view address) {
|
||||
if (ctx.profile.support_int64) {
|
||||
return ctx.AddU32x2("{}=LoadGlobal64({});", inst, address);
|
||||
}
|
||||
LOG_WARNING(Shader_GLSL, "Int64 not supported, ignoring memory operation");
|
||||
ctx.AddU32x2("{}=uvec2(0);", inst);
|
||||
}
|
||||
|
||||
void EmitLoadGlobal128(EmitContext& ctx, IR::Inst& inst, std::string_view address) {
|
||||
if (ctx.profile.support_int64) {
|
||||
return ctx.AddU32x4("{}=LoadGlobal128({});", inst, address);
|
||||
}
|
||||
LOG_WARNING(Shader_GLSL, "Int64 not supported, ignoring memory operation");
|
||||
ctx.AddU32x4("{}=uvec4(0);", inst);
|
||||
}
|
||||
|
||||
void EmitWriteGlobalU8(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitWriteGlobalS8(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitWriteGlobalU16(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitWriteGlobalS16(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitWriteGlobal32(EmitContext& ctx, std::string_view address, std::string_view value) {
|
||||
if (ctx.profile.support_int64) {
|
||||
return ctx.Add("WriteGlobal32({},{});", address, value);
|
||||
}
|
||||
LOG_WARNING(Shader_GLSL, "Int64 not supported, ignoring memory operation");
|
||||
}
|
||||
|
||||
void EmitWriteGlobal64(EmitContext& ctx, std::string_view address, std::string_view value) {
|
||||
if (ctx.profile.support_int64) {
|
||||
return ctx.Add("WriteGlobal64({},{});", address, value);
|
||||
}
|
||||
LOG_WARNING(Shader_GLSL, "Int64 not supported, ignoring memory operation");
|
||||
}
|
||||
|
||||
void EmitWriteGlobal128(EmitContext& ctx, std::string_view address, std::string_view value) {
|
||||
if (ctx.profile.support_int64) {
|
||||
return ctx.Add("WriteGlobal128({},{});", address, value);
|
||||
}
|
||||
LOG_WARNING(Shader_GLSL, "Int64 not supported, ignoring memory operation");
|
||||
}
|
||||
|
||||
void EmitLoadStorageU8(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset) {
|
||||
const auto offset_var{ctx.var_alloc.Consume(offset)};
|
||||
ctx.AddU32("{}=bitfieldExtract({}_ssbo{}[{}>>2],int({}%4)*8,8);", inst, ctx.stage_name,
|
||||
binding.U32(), offset_var, offset_var);
|
||||
}
|
||||
|
||||
void EmitLoadStorageS8(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset) {
|
||||
const auto offset_var{ctx.var_alloc.Consume(offset)};
|
||||
ctx.AddU32("{}=bitfieldExtract(int({}_ssbo{}[{}>>2]),int({}%4)*8,8);", inst, ctx.stage_name,
|
||||
binding.U32(), offset_var, offset_var);
|
||||
}
|
||||
|
||||
void EmitLoadStorageU16(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset) {
|
||||
const auto offset_var{ctx.var_alloc.Consume(offset)};
|
||||
ctx.AddU32("{}=bitfieldExtract({}_ssbo{}[{}>>2],int(({}>>1)%2)*16,16);", inst, ctx.stage_name,
|
||||
binding.U32(), offset_var, offset_var);
|
||||
}
|
||||
|
||||
void EmitLoadStorageS16(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset) {
|
||||
const auto offset_var{ctx.var_alloc.Consume(offset)};
|
||||
ctx.AddU32("{}=bitfieldExtract(int({}_ssbo{}[{}>>2]),int(({}>>1)%2)*16,16);", inst,
|
||||
ctx.stage_name, binding.U32(), offset_var, offset_var);
|
||||
}
|
||||
|
||||
void EmitLoadStorage32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset) {
|
||||
const auto offset_var{ctx.var_alloc.Consume(offset)};
|
||||
ctx.AddU32("{}={}_ssbo{}[{}>>2];", inst, ctx.stage_name, binding.U32(), offset_var);
|
||||
}
|
||||
|
||||
void EmitLoadStorage64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset) {
|
||||
const auto offset_var{ctx.var_alloc.Consume(offset)};
|
||||
ctx.AddU32x2("{}=uvec2({}_ssbo{}[{}>>2],{}_ssbo{}[({}+4)>>2]);", inst, ctx.stage_name,
|
||||
binding.U32(), offset_var, ctx.stage_name, binding.U32(), offset_var);
|
||||
}
|
||||
|
||||
void EmitLoadStorage128(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset) {
|
||||
const auto offset_var{ctx.var_alloc.Consume(offset)};
|
||||
ctx.AddU32x4("{}=uvec4({}_ssbo{}[{}>>2],{}_ssbo{}[({}+4)>>2],{}_ssbo{}[({}+8)>>2],{}_ssbo{}[({}"
|
||||
"+12)>>2]);",
|
||||
inst, ctx.stage_name, binding.U32(), offset_var, ctx.stage_name, binding.U32(),
|
||||
offset_var, ctx.stage_name, binding.U32(), offset_var, ctx.stage_name,
|
||||
binding.U32(), offset_var);
|
||||
}
|
||||
|
||||
void EmitWriteStorageU8(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset,
|
||||
std::string_view value) {
|
||||
const auto offset_var{ctx.var_alloc.Consume(offset)};
|
||||
const auto bit_offset{fmt::format("int({}%4)*8", offset_var)};
|
||||
SsboWriteCas(ctx, binding, offset_var, value, bit_offset, 8);
|
||||
}
|
||||
|
||||
void EmitWriteStorageS8(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset,
|
||||
std::string_view value) {
|
||||
const auto offset_var{ctx.var_alloc.Consume(offset)};
|
||||
const auto bit_offset{fmt::format("int({}%4)*8", offset_var)};
|
||||
SsboWriteCas(ctx, binding, offset_var, value, bit_offset, 8);
|
||||
}
|
||||
|
||||
void EmitWriteStorageU16(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset,
|
||||
std::string_view value) {
|
||||
const auto offset_var{ctx.var_alloc.Consume(offset)};
|
||||
const auto bit_offset{fmt::format("int(({}>>1)%2)*16", offset_var)};
|
||||
SsboWriteCas(ctx, binding, offset_var, value, bit_offset, 16);
|
||||
}
|
||||
|
||||
void EmitWriteStorageS16(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset,
|
||||
std::string_view value) {
|
||||
const auto offset_var{ctx.var_alloc.Consume(offset)};
|
||||
const auto bit_offset{fmt::format("int(({}>>1)%2)*16", offset_var)};
|
||||
SsboWriteCas(ctx, binding, offset_var, value, bit_offset, 16);
|
||||
}
|
||||
|
||||
void EmitWriteStorage32(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset,
|
||||
std::string_view value) {
|
||||
const auto offset_var{ctx.var_alloc.Consume(offset)};
|
||||
ctx.Add("{}_ssbo{}[{}>>2]={};", ctx.stage_name, binding.U32(), offset_var, value);
|
||||
}
|
||||
|
||||
void EmitWriteStorage64(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset,
|
||||
std::string_view value) {
|
||||
const auto offset_var{ctx.var_alloc.Consume(offset)};
|
||||
ctx.Add("{}_ssbo{}[{}>>2]={}.x;", ctx.stage_name, binding.U32(), offset_var, value);
|
||||
ctx.Add("{}_ssbo{}[({}+4)>>2]={}.y;", ctx.stage_name, binding.U32(), offset_var, value);
|
||||
}
|
||||
|
||||
void EmitWriteStorage128(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset,
|
||||
std::string_view value) {
|
||||
const auto offset_var{ctx.var_alloc.Consume(offset)};
|
||||
ctx.Add("{}_ssbo{}[{}>>2]={}.x;", ctx.stage_name, binding.U32(), offset_var, value);
|
||||
ctx.Add("{}_ssbo{}[({}+4)>>2]={}.y;", ctx.stage_name, binding.U32(), offset_var, value);
|
||||
ctx.Add("{}_ssbo{}[({}+8)>>2]={}.z;", ctx.stage_name, binding.U32(), offset_var, value);
|
||||
ctx.Add("{}_ssbo{}[({}+12)>>2]={}.w;", ctx.stage_name, binding.U32(), offset_var, value);
|
||||
}
|
||||
} // namespace Shader::Backend::GLSL
|
||||
100
gpu/third_party/suyu/shader_recompiler/backend/glsl/emit_glsl_not_implemented.cpp
vendored
Normal file
100
gpu/third_party/suyu/shader_recompiler/backend/glsl/emit_glsl_not_implemented.cpp
vendored
Normal file
@@ -0,0 +1,100 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <string_view>
|
||||
|
||||
#include "shader_recompiler/backend/glsl/emit_glsl_instructions.h"
|
||||
#include "shader_recompiler/backend/glsl/glsl_emit_context.h"
|
||||
#include "shader_recompiler/frontend/ir/value.h"
|
||||
|
||||
namespace Shader::Backend::GLSL {
|
||||
|
||||
void EmitGetRegister(EmitContext& ctx) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitSetRegister(EmitContext& ctx) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitGetPred(EmitContext& ctx) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitSetPred(EmitContext& ctx) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitSetGotoVariable(EmitContext& ctx) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitGetGotoVariable(EmitContext& ctx) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitSetIndirectBranchVariable(EmitContext& ctx) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitGetIndirectBranchVariable(EmitContext& ctx) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitGetZFlag(EmitContext& ctx) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitGetSFlag(EmitContext& ctx) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitGetCFlag(EmitContext& ctx) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitGetOFlag(EmitContext& ctx) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitSetZFlag(EmitContext& ctx) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitSetSFlag(EmitContext& ctx) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitSetCFlag(EmitContext& ctx) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitSetOFlag(EmitContext& ctx) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitGetZeroFromOp(EmitContext& ctx) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitGetSignFromOp(EmitContext& ctx) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitGetCarryFromOp(EmitContext& ctx) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitGetOverflowFromOp(EmitContext& ctx) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitGetSparseFromOp(EmitContext& ctx) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitGetInBoundsFromOp(EmitContext& ctx) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
} // namespace Shader::Backend::GLSL
|
||||
54
gpu/third_party/suyu/shader_recompiler/backend/glsl/emit_glsl_select.cpp
vendored
Normal file
54
gpu/third_party/suyu/shader_recompiler/backend/glsl/emit_glsl_select.cpp
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <string_view>
|
||||
|
||||
#include "shader_recompiler/backend/glsl/emit_glsl_instructions.h"
|
||||
#include "shader_recompiler/backend/glsl/glsl_emit_context.h"
|
||||
#include "shader_recompiler/frontend/ir/value.h"
|
||||
|
||||
namespace Shader::Backend::GLSL {
|
||||
void EmitSelectU1(EmitContext& ctx, IR::Inst& inst, std::string_view cond,
|
||||
std::string_view true_value, std::string_view false_value) {
|
||||
ctx.AddU1("{}={}?{}:{};", inst, cond, true_value, false_value);
|
||||
}
|
||||
|
||||
void EmitSelectU8([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view cond,
|
||||
[[maybe_unused]] std::string_view true_value,
|
||||
[[maybe_unused]] std::string_view false_value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitSelectU16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view cond,
|
||||
[[maybe_unused]] std::string_view true_value,
|
||||
[[maybe_unused]] std::string_view false_value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitSelectU32(EmitContext& ctx, IR::Inst& inst, std::string_view cond,
|
||||
std::string_view true_value, std::string_view false_value) {
|
||||
ctx.AddU32("{}={}?{}:{};", inst, cond, true_value, false_value);
|
||||
}
|
||||
|
||||
void EmitSelectU64(EmitContext& ctx, IR::Inst& inst, std::string_view cond,
|
||||
std::string_view true_value, std::string_view false_value) {
|
||||
ctx.AddU64("{}={}?{}:{};", inst, cond, true_value, false_value);
|
||||
}
|
||||
|
||||
void EmitSelectF16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view cond,
|
||||
[[maybe_unused]] std::string_view true_value,
|
||||
[[maybe_unused]] std::string_view false_value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitSelectF32(EmitContext& ctx, IR::Inst& inst, std::string_view cond,
|
||||
std::string_view true_value, std::string_view false_value) {
|
||||
ctx.AddF32("{}={}?{}:{};", inst, cond, true_value, false_value);
|
||||
}
|
||||
|
||||
void EmitSelectF64(EmitContext& ctx, IR::Inst& inst, std::string_view cond,
|
||||
std::string_view true_value, std::string_view false_value) {
|
||||
ctx.AddF64("{}={}?{}:{};", inst, cond, true_value, false_value);
|
||||
}
|
||||
|
||||
} // namespace Shader::Backend::GLSL
|
||||
76
gpu/third_party/suyu/shader_recompiler/backend/glsl/emit_glsl_shared_memory.cpp
vendored
Normal file
76
gpu/third_party/suyu/shader_recompiler/backend/glsl/emit_glsl_shared_memory.cpp
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "shader_recompiler/backend/glsl/emit_glsl_instructions.h"
|
||||
#include "shader_recompiler/backend/glsl/glsl_emit_context.h"
|
||||
#include "shader_recompiler/frontend/ir/value.h"
|
||||
|
||||
namespace Shader::Backend::GLSL {
|
||||
namespace {
|
||||
constexpr char cas_loop[]{"for(;;){{uint old_value={};uint "
|
||||
"cas_result=atomicCompSwap({},old_value,bitfieldInsert({},{},{},{}));"
|
||||
"if(cas_result==old_value){{break;}}}}"};
|
||||
|
||||
void SharedWriteCas(EmitContext& ctx, std::string_view offset, std::string_view value,
|
||||
std::string_view bit_offset, u32 num_bits) {
|
||||
const auto smem{fmt::format("smem[{}>>2]", offset)};
|
||||
ctx.Add(cas_loop, smem, smem, smem, value, bit_offset, num_bits);
|
||||
}
|
||||
} // Anonymous namespace
|
||||
|
||||
void EmitLoadSharedU8(EmitContext& ctx, IR::Inst& inst, std::string_view offset) {
|
||||
ctx.AddU32("{}=bitfieldExtract(smem[{}>>2],int({}%4)*8,8);", inst, offset, offset);
|
||||
}
|
||||
|
||||
void EmitLoadSharedS8(EmitContext& ctx, IR::Inst& inst, std::string_view offset) {
|
||||
ctx.AddU32("{}=bitfieldExtract(int(smem[{}>>2]),int({}%4)*8,8);", inst, offset, offset);
|
||||
}
|
||||
|
||||
void EmitLoadSharedU16(EmitContext& ctx, IR::Inst& inst, std::string_view offset) {
|
||||
ctx.AddU32("{}=bitfieldExtract(smem[{}>>2],int(({}>>1)%2)*16,16);", inst, offset, offset);
|
||||
}
|
||||
|
||||
void EmitLoadSharedS16(EmitContext& ctx, IR::Inst& inst, std::string_view offset) {
|
||||
ctx.AddU32("{}=bitfieldExtract(int(smem[{}>>2]),int(({}>>1)%2)*16,16);", inst, offset, offset);
|
||||
}
|
||||
|
||||
void EmitLoadSharedU32(EmitContext& ctx, IR::Inst& inst, std::string_view offset) {
|
||||
ctx.AddU32("{}=smem[{}>>2];", inst, offset);
|
||||
}
|
||||
|
||||
void EmitLoadSharedU64(EmitContext& ctx, IR::Inst& inst, std::string_view offset) {
|
||||
ctx.AddU32x2("{}=uvec2(smem[{}>>2],smem[({}+4)>>2]);", inst, offset, offset);
|
||||
}
|
||||
|
||||
void EmitLoadSharedU128(EmitContext& ctx, IR::Inst& inst, std::string_view offset) {
|
||||
ctx.AddU32x4("{}=uvec4(smem[{}>>2],smem[({}+4)>>2],smem[({}+8)>>2],smem[({}+12)>>2]);", inst,
|
||||
offset, offset, offset, offset);
|
||||
}
|
||||
|
||||
void EmitWriteSharedU8(EmitContext& ctx, std::string_view offset, std::string_view value) {
|
||||
const auto bit_offset{fmt::format("int({}%4)*8", offset)};
|
||||
SharedWriteCas(ctx, offset, value, bit_offset, 8);
|
||||
}
|
||||
|
||||
void EmitWriteSharedU16(EmitContext& ctx, std::string_view offset, std::string_view value) {
|
||||
const auto bit_offset{fmt::format("int(({}>>1)%2)*16", offset)};
|
||||
SharedWriteCas(ctx, offset, value, bit_offset, 16);
|
||||
}
|
||||
|
||||
void EmitWriteSharedU32(EmitContext& ctx, std::string_view offset, std::string_view value) {
|
||||
ctx.Add("smem[{}>>2]={};", offset, value);
|
||||
}
|
||||
|
||||
void EmitWriteSharedU64(EmitContext& ctx, std::string_view offset, std::string_view value) {
|
||||
ctx.Add("smem[{}>>2]={}.x;", offset, value);
|
||||
ctx.Add("smem[({}+4)>>2]={}.y;", offset, value);
|
||||
}
|
||||
|
||||
void EmitWriteSharedU128(EmitContext& ctx, std::string_view offset, std::string_view value) {
|
||||
ctx.Add("smem[{}>>2]={}.x;", offset, value);
|
||||
ctx.Add("smem[({}+4)>>2]={}.y;", offset, value);
|
||||
ctx.Add("smem[({}+8)>>2]={}.z;", offset, value);
|
||||
ctx.Add("smem[({}+12)>>2]={}.w;", offset, value);
|
||||
}
|
||||
|
||||
} // namespace Shader::Backend::GLSL
|
||||
110
gpu/third_party/suyu/shader_recompiler/backend/glsl/emit_glsl_special.cpp
vendored
Normal file
110
gpu/third_party/suyu/shader_recompiler/backend/glsl/emit_glsl_special.cpp
vendored
Normal file
@@ -0,0 +1,110 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "shader_recompiler/backend/glsl/emit_glsl_instructions.h"
|
||||
#include "shader_recompiler/backend/glsl/glsl_emit_context.h"
|
||||
#include "shader_recompiler/frontend/ir/program.h"
|
||||
#include "shader_recompiler/frontend/ir/value.h"
|
||||
#include "shader_recompiler/profile.h"
|
||||
|
||||
namespace Shader::Backend::GLSL {
|
||||
namespace {
|
||||
std::string_view OutputVertexIndex(EmitContext& ctx) {
|
||||
return ctx.stage == Stage::TessellationControl ? "[gl_InvocationID]" : "";
|
||||
}
|
||||
|
||||
void InitializeOutputVaryings(EmitContext& ctx) {
|
||||
if (ctx.uses_geometry_passthrough) {
|
||||
return;
|
||||
}
|
||||
if (ctx.stage == Stage::VertexB || ctx.stage == Stage::Geometry) {
|
||||
ctx.Add("gl_Position=vec4(0,0,0,1);");
|
||||
}
|
||||
for (size_t index = 0; index < IR::NUM_GENERICS; ++index) {
|
||||
if (!ctx.info.stores.Generic(index)) {
|
||||
continue;
|
||||
}
|
||||
const auto& info_array{ctx.output_generics.at(index)};
|
||||
const auto output_decorator{OutputVertexIndex(ctx)};
|
||||
size_t element{};
|
||||
while (element < info_array.size()) {
|
||||
const auto& info{info_array.at(element)};
|
||||
const auto varying_name{fmt::format("{}{}", info.name, output_decorator)};
|
||||
switch (info.num_components) {
|
||||
case 1: {
|
||||
const char value{element == 3 ? '1' : '0'};
|
||||
ctx.Add("{}={}.f;", varying_name, value);
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
case 3:
|
||||
if (element + info.num_components < 4) {
|
||||
ctx.Add("{}=vec{}(0);", varying_name, info.num_components);
|
||||
} else {
|
||||
// last element is the w component, must be initialized to 1
|
||||
const auto zeros{info.num_components == 3 ? "0,0," : "0,"};
|
||||
ctx.Add("{}=vec{}({}1);", varying_name, info.num_components, zeros);
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
ctx.Add("{}=vec4(0,0,0,1);", varying_name);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
element += info.num_components;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // Anonymous namespace
|
||||
|
||||
void EmitPhi(EmitContext& ctx, IR::Inst& phi) {
|
||||
const size_t num_args{phi.NumArgs()};
|
||||
for (size_t i = 0; i < num_args; ++i) {
|
||||
ctx.var_alloc.Consume(phi.Arg(i));
|
||||
}
|
||||
if (!phi.Definition<Id>().is_valid) {
|
||||
// The phi node wasn't forward defined
|
||||
ctx.var_alloc.PhiDefine(phi, phi.Type());
|
||||
}
|
||||
}
|
||||
|
||||
void EmitVoid(EmitContext&) {}
|
||||
|
||||
void EmitReference(EmitContext& ctx, const IR::Value& value) {
|
||||
ctx.var_alloc.Consume(value);
|
||||
}
|
||||
|
||||
void EmitPhiMove(EmitContext& ctx, const IR::Value& phi_value, const IR::Value& value) {
|
||||
IR::Inst& phi{*phi_value.InstRecursive()};
|
||||
const auto phi_type{phi.Type()};
|
||||
if (!phi.Definition<Id>().is_valid) {
|
||||
// The phi node wasn't forward defined
|
||||
ctx.var_alloc.PhiDefine(phi, phi_type);
|
||||
}
|
||||
const auto phi_reg{ctx.var_alloc.Consume(IR::Value{&phi})};
|
||||
const auto val_reg{ctx.var_alloc.Consume(value)};
|
||||
if (phi_reg == val_reg) {
|
||||
return;
|
||||
}
|
||||
const bool needs_workaround{ctx.profile.has_gl_bool_ref_bug && phi_type == IR::Type::U1};
|
||||
const auto suffix{needs_workaround ? "?true:false" : ""};
|
||||
ctx.Add("{}={}{};", phi_reg, val_reg, suffix);
|
||||
}
|
||||
|
||||
void EmitPrologue(EmitContext& ctx) {
|
||||
InitializeOutputVaryings(ctx);
|
||||
}
|
||||
|
||||
void EmitEpilogue(EmitContext&) {}
|
||||
|
||||
void EmitEmitVertex(EmitContext& ctx, const IR::Value& stream) {
|
||||
ctx.Add("EmitStreamVertex(int({}));", ctx.var_alloc.Consume(stream));
|
||||
InitializeOutputVaryings(ctx);
|
||||
}
|
||||
|
||||
void EmitEndPrimitive(EmitContext& ctx, const IR::Value& stream) {
|
||||
ctx.Add("EndStreamPrimitive(int({}));", ctx.var_alloc.Consume(stream));
|
||||
}
|
||||
|
||||
} // namespace Shader::Backend::GLSL
|
||||
29
gpu/third_party/suyu/shader_recompiler/backend/glsl/emit_glsl_undefined.cpp
vendored
Normal file
29
gpu/third_party/suyu/shader_recompiler/backend/glsl/emit_glsl_undefined.cpp
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "shader_recompiler/backend/glsl/emit_glsl_instructions.h"
|
||||
#include "shader_recompiler/backend/glsl/glsl_emit_context.h"
|
||||
|
||||
namespace Shader::Backend::GLSL {
|
||||
|
||||
void EmitUndefU1(EmitContext& ctx, IR::Inst& inst) {
|
||||
ctx.AddU1("{}=false;", inst);
|
||||
}
|
||||
|
||||
void EmitUndefU8(EmitContext& ctx, IR::Inst& inst) {
|
||||
ctx.AddU32("{}=0u;", inst);
|
||||
}
|
||||
|
||||
void EmitUndefU16(EmitContext& ctx, IR::Inst& inst) {
|
||||
ctx.AddU32("{}=0u;", inst);
|
||||
}
|
||||
|
||||
void EmitUndefU32(EmitContext& ctx, IR::Inst& inst) {
|
||||
ctx.AddU32("{}=0u;", inst);
|
||||
}
|
||||
|
||||
void EmitUndefU64(EmitContext& ctx, IR::Inst& inst) {
|
||||
ctx.AddU64("{}=0u;", inst);
|
||||
}
|
||||
|
||||
} // namespace Shader::Backend::GLSL
|
||||
246
gpu/third_party/suyu/shader_recompiler/backend/glsl/emit_glsl_warp.cpp
vendored
Normal file
246
gpu/third_party/suyu/shader_recompiler/backend/glsl/emit_glsl_warp.cpp
vendored
Normal file
@@ -0,0 +1,246 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <string_view>
|
||||
|
||||
#include "shader_recompiler/backend/glsl/emit_glsl_instructions.h"
|
||||
#include "shader_recompiler/backend/glsl/glsl_emit_context.h"
|
||||
#include "shader_recompiler/frontend/ir/value.h"
|
||||
#include "shader_recompiler/profile.h"
|
||||
|
||||
namespace Shader::Backend::GLSL {
|
||||
namespace {
|
||||
constexpr char THREAD_ID[]{"gl_SubGroupInvocationARB"};
|
||||
|
||||
void SetInBoundsFlag(EmitContext& ctx, IR::Inst& inst) {
|
||||
IR::Inst* const in_bounds{inst.GetAssociatedPseudoOperation(IR::Opcode::GetInBoundsFromOp)};
|
||||
if (!in_bounds) {
|
||||
return;
|
||||
}
|
||||
ctx.AddU1("{}=shfl_in_bounds;", *in_bounds);
|
||||
in_bounds->Invalidate();
|
||||
}
|
||||
|
||||
std::string ComputeMinThreadId(std::string_view thread_id, std::string_view segmentation_mask) {
|
||||
return fmt::format("({}&{})", thread_id, segmentation_mask);
|
||||
}
|
||||
|
||||
std::string ComputeMaxThreadId(std::string_view min_thread_id, std::string_view clamp,
|
||||
std::string_view not_seg_mask) {
|
||||
return fmt::format("({})|({}&{})", min_thread_id, clamp, not_seg_mask);
|
||||
}
|
||||
|
||||
std::string GetMaxThreadId(std::string_view thread_id, std::string_view clamp,
|
||||
std::string_view segmentation_mask) {
|
||||
const auto not_seg_mask{fmt::format("(~{})", segmentation_mask)};
|
||||
const auto min_thread_id{ComputeMinThreadId(thread_id, segmentation_mask)};
|
||||
return ComputeMaxThreadId(min_thread_id, clamp, not_seg_mask);
|
||||
}
|
||||
|
||||
void UseShuffleNv(EmitContext& ctx, IR::Inst& inst, std::string_view shfl_op,
|
||||
std::string_view value, std::string_view index,
|
||||
[[maybe_unused]] std::string_view clamp, std::string_view segmentation_mask) {
|
||||
const auto width{fmt::format("32u>>(bitCount({}&31u))", segmentation_mask)};
|
||||
ctx.AddU32("{}={}({},{},{},shfl_in_bounds);", inst, shfl_op, value, index, width);
|
||||
SetInBoundsFlag(ctx, inst);
|
||||
}
|
||||
|
||||
std::string_view BallotIndex(EmitContext& ctx) {
|
||||
if (!ctx.profile.warp_size_potentially_larger_than_guest) {
|
||||
return ".x";
|
||||
}
|
||||
return "[gl_SubGroupInvocationARB>>5]";
|
||||
}
|
||||
|
||||
std::string GetMask(EmitContext& ctx, std::string_view mask) {
|
||||
const auto ballot_index{BallotIndex(ctx)};
|
||||
return fmt::format("uint(uvec2({}){})", mask, ballot_index);
|
||||
}
|
||||
} // Anonymous namespace
|
||||
|
||||
void EmitLaneId(EmitContext& ctx, IR::Inst& inst) {
|
||||
ctx.AddU32("{}={}&31u;", inst, THREAD_ID);
|
||||
}
|
||||
|
||||
void EmitVoteAll(EmitContext& ctx, IR::Inst& inst, std::string_view pred) {
|
||||
if (!ctx.profile.warp_size_potentially_larger_than_guest) {
|
||||
ctx.AddU1("{}=allInvocationsEqualARB({});", inst, pred);
|
||||
return;
|
||||
}
|
||||
const auto ballot_index{BallotIndex(ctx)};
|
||||
const auto active_mask{fmt::format("uvec2(ballotARB(true)){}", ballot_index)};
|
||||
const auto ballot{fmt::format("uvec2(ballotARB({})){}", pred, ballot_index)};
|
||||
ctx.AddU1("{}=({}&{})=={};", inst, ballot, active_mask, active_mask);
|
||||
}
|
||||
|
||||
void EmitVoteAny(EmitContext& ctx, IR::Inst& inst, std::string_view pred) {
|
||||
if (!ctx.profile.warp_size_potentially_larger_than_guest) {
|
||||
ctx.AddU1("{}=anyInvocationARB({});", inst, pred);
|
||||
return;
|
||||
}
|
||||
const auto ballot_index{BallotIndex(ctx)};
|
||||
const auto active_mask{fmt::format("uvec2(ballotARB(true)){}", ballot_index)};
|
||||
const auto ballot{fmt::format("uvec2(ballotARB({})){}", pred, ballot_index)};
|
||||
ctx.AddU1("{}=({}&{})!=0u;", inst, ballot, active_mask, active_mask);
|
||||
}
|
||||
|
||||
void EmitVoteEqual(EmitContext& ctx, IR::Inst& inst, std::string_view pred) {
|
||||
if (!ctx.profile.warp_size_potentially_larger_than_guest) {
|
||||
ctx.AddU1("{}=allInvocationsEqualARB({});", inst, pred);
|
||||
return;
|
||||
}
|
||||
const auto ballot_index{BallotIndex(ctx)};
|
||||
const auto active_mask{fmt::format("uvec2(ballotARB(true)){}", ballot_index)};
|
||||
const auto ballot{fmt::format("uvec2(ballotARB({})){}", pred, ballot_index)};
|
||||
const auto value{fmt::format("({}^{})", ballot, active_mask)};
|
||||
ctx.AddU1("{}=({}==0)||({}=={});", inst, value, value, active_mask);
|
||||
}
|
||||
|
||||
void EmitSubgroupBallot(EmitContext& ctx, IR::Inst& inst, std::string_view pred) {
|
||||
const auto ballot_index{BallotIndex(ctx)};
|
||||
ctx.AddU32("{}=uvec2(ballotARB({})){};", inst, pred, ballot_index);
|
||||
}
|
||||
|
||||
void EmitSubgroupEqMask(EmitContext& ctx, IR::Inst& inst) {
|
||||
ctx.AddU32("{}={};", inst, GetMask(ctx, "gl_SubGroupEqMaskARB"));
|
||||
}
|
||||
|
||||
void EmitSubgroupLtMask(EmitContext& ctx, IR::Inst& inst) {
|
||||
ctx.AddU32("{}={};", inst, GetMask(ctx, "gl_SubGroupLtMaskARB"));
|
||||
}
|
||||
|
||||
void EmitSubgroupLeMask(EmitContext& ctx, IR::Inst& inst) {
|
||||
ctx.AddU32("{}={};", inst, GetMask(ctx, "gl_SubGroupLeMaskARB"));
|
||||
}
|
||||
|
||||
void EmitSubgroupGtMask(EmitContext& ctx, IR::Inst& inst) {
|
||||
ctx.AddU32("{}={};", inst, GetMask(ctx, "gl_SubGroupGtMaskARB"));
|
||||
}
|
||||
|
||||
void EmitSubgroupGeMask(EmitContext& ctx, IR::Inst& inst) {
|
||||
ctx.AddU32("{}={};", inst, GetMask(ctx, "gl_SubGroupGeMaskARB"));
|
||||
}
|
||||
|
||||
void EmitShuffleIndex(EmitContext& ctx, IR::Inst& inst, std::string_view value,
|
||||
std::string_view index, std::string_view clamp, std::string_view seg_mask) {
|
||||
if (ctx.profile.support_gl_warp_intrinsics) {
|
||||
UseShuffleNv(ctx, inst, "shuffleNV", value, index, clamp, seg_mask);
|
||||
return;
|
||||
}
|
||||
const bool big_warp{ctx.profile.warp_size_potentially_larger_than_guest};
|
||||
const auto is_upper_partition{"int(gl_SubGroupInvocationARB)>=32"};
|
||||
const auto upper_index{fmt::format("{}?{}+32:{}", is_upper_partition, index, index)};
|
||||
const auto upper_clamp{fmt::format("{}?{}+32:{}", is_upper_partition, clamp, clamp)};
|
||||
|
||||
const auto not_seg_mask{fmt::format("(~{})", seg_mask)};
|
||||
const auto min_thread_id{ComputeMinThreadId(THREAD_ID, seg_mask)};
|
||||
const auto max_thread_id{
|
||||
ComputeMaxThreadId(min_thread_id, big_warp ? upper_clamp : clamp, not_seg_mask)};
|
||||
|
||||
const auto lhs{fmt::format("({}&{})", big_warp ? upper_index : index, not_seg_mask)};
|
||||
const auto src_thread_id{fmt::format("({})|({})", lhs, min_thread_id)};
|
||||
ctx.Add("shfl_in_bounds=int({})<=int({});", src_thread_id, max_thread_id);
|
||||
SetInBoundsFlag(ctx, inst);
|
||||
ctx.Add("shfl_result=readInvocationARB({},{});", value, src_thread_id);
|
||||
ctx.AddU32("{}=shfl_in_bounds?shfl_result:{};", inst, value);
|
||||
}
|
||||
|
||||
void EmitShuffleUp(EmitContext& ctx, IR::Inst& inst, std::string_view value, std::string_view index,
|
||||
std::string_view clamp, std::string_view seg_mask) {
|
||||
if (ctx.profile.support_gl_warp_intrinsics) {
|
||||
UseShuffleNv(ctx, inst, "shuffleUpNV", value, index, clamp, seg_mask);
|
||||
return;
|
||||
}
|
||||
const bool big_warp{ctx.profile.warp_size_potentially_larger_than_guest};
|
||||
const auto is_upper_partition{"int(gl_SubGroupInvocationARB)>=32"};
|
||||
const auto upper_clamp{fmt::format("{}?{}+32:{}", is_upper_partition, clamp, clamp)};
|
||||
|
||||
const auto max_thread_id{GetMaxThreadId(THREAD_ID, big_warp ? upper_clamp : clamp, seg_mask)};
|
||||
const auto src_thread_id{fmt::format("({}-{})", THREAD_ID, index)};
|
||||
ctx.Add("shfl_in_bounds=int({})>=int({});", src_thread_id, max_thread_id);
|
||||
SetInBoundsFlag(ctx, inst);
|
||||
ctx.Add("shfl_result=readInvocationARB({},{});", value, src_thread_id);
|
||||
ctx.AddU32("{}=shfl_in_bounds?shfl_result:{};", inst, value);
|
||||
}
|
||||
|
||||
void EmitShuffleDown(EmitContext& ctx, IR::Inst& inst, std::string_view value,
|
||||
std::string_view index, std::string_view clamp, std::string_view seg_mask) {
|
||||
if (ctx.profile.support_gl_warp_intrinsics) {
|
||||
UseShuffleNv(ctx, inst, "shuffleDownNV", value, index, clamp, seg_mask);
|
||||
return;
|
||||
}
|
||||
const bool big_warp{ctx.profile.warp_size_potentially_larger_than_guest};
|
||||
const auto is_upper_partition{"int(gl_SubGroupInvocationARB)>=32"};
|
||||
const auto upper_clamp{fmt::format("{}?{}+32:{}", is_upper_partition, clamp, clamp)};
|
||||
|
||||
const auto max_thread_id{GetMaxThreadId(THREAD_ID, big_warp ? upper_clamp : clamp, seg_mask)};
|
||||
const auto src_thread_id{fmt::format("({}+{})", THREAD_ID, index)};
|
||||
ctx.Add("shfl_in_bounds=int({})<=int({});", src_thread_id, max_thread_id);
|
||||
SetInBoundsFlag(ctx, inst);
|
||||
ctx.Add("shfl_result=readInvocationARB({},{});", value, src_thread_id);
|
||||
ctx.AddU32("{}=shfl_in_bounds?shfl_result:{};", inst, value);
|
||||
}
|
||||
|
||||
void EmitShuffleButterfly(EmitContext& ctx, IR::Inst& inst, std::string_view value,
|
||||
std::string_view index, std::string_view clamp,
|
||||
std::string_view seg_mask) {
|
||||
if (ctx.profile.support_gl_warp_intrinsics) {
|
||||
UseShuffleNv(ctx, inst, "shuffleXorNV", value, index, clamp, seg_mask);
|
||||
return;
|
||||
}
|
||||
const bool big_warp{ctx.profile.warp_size_potentially_larger_than_guest};
|
||||
const auto is_upper_partition{"int(gl_SubGroupInvocationARB)>=32"};
|
||||
const auto upper_clamp{fmt::format("{}?{}+32:{}", is_upper_partition, clamp, clamp)};
|
||||
|
||||
const auto max_thread_id{GetMaxThreadId(THREAD_ID, big_warp ? upper_clamp : clamp, seg_mask)};
|
||||
const auto src_thread_id{fmt::format("({}^{})", THREAD_ID, index)};
|
||||
ctx.Add("shfl_in_bounds=int({})<=int({});", src_thread_id, max_thread_id);
|
||||
SetInBoundsFlag(ctx, inst);
|
||||
ctx.Add("shfl_result=readInvocationARB({},{});", value, src_thread_id);
|
||||
ctx.AddU32("{}=shfl_in_bounds?shfl_result:{};", inst, value);
|
||||
}
|
||||
|
||||
void EmitFSwizzleAdd(EmitContext& ctx, IR::Inst& inst, std::string_view op_a, std::string_view op_b,
|
||||
std::string_view swizzle) {
|
||||
const auto mask{fmt::format("({}>>((gl_SubGroupInvocationARB&3)<<1))&3", swizzle)};
|
||||
const std::string modifier_a = fmt::format("FSWZ_A[{}]", mask);
|
||||
const std::string modifier_b = fmt::format("FSWZ_B[{}]", mask);
|
||||
ctx.AddF32("{}=({}*{})+({}*{});", inst, op_a, modifier_a, op_b, modifier_b);
|
||||
}
|
||||
|
||||
void EmitDPdxFine(EmitContext& ctx, IR::Inst& inst, std::string_view op_a) {
|
||||
if (ctx.profile.support_gl_derivative_control) {
|
||||
ctx.AddF32("{}=dFdxFine({});", inst, op_a);
|
||||
} else {
|
||||
LOG_WARNING(Shader_GLSL, "Device does not support dFdxFine, fallback to dFdx");
|
||||
ctx.AddF32("{}=dFdx({});", inst, op_a);
|
||||
}
|
||||
}
|
||||
|
||||
void EmitDPdyFine(EmitContext& ctx, IR::Inst& inst, std::string_view op_a) {
|
||||
if (ctx.profile.support_gl_derivative_control) {
|
||||
ctx.AddF32("{}=dFdyFine({});", inst, op_a);
|
||||
} else {
|
||||
LOG_WARNING(Shader_GLSL, "Device does not support dFdyFine, fallback to dFdy");
|
||||
ctx.AddF32("{}=dFdy({});", inst, op_a);
|
||||
}
|
||||
}
|
||||
|
||||
void EmitDPdxCoarse(EmitContext& ctx, IR::Inst& inst, std::string_view op_a) {
|
||||
if (ctx.profile.support_gl_derivative_control) {
|
||||
ctx.AddF32("{}=dFdxCoarse({});", inst, op_a);
|
||||
} else {
|
||||
LOG_WARNING(Shader_GLSL, "Device does not support dFdxCoarse, fallback to dFdx");
|
||||
ctx.AddF32("{}=dFdx({});", inst, op_a);
|
||||
}
|
||||
}
|
||||
|
||||
void EmitDPdyCoarse(EmitContext& ctx, IR::Inst& inst, std::string_view op_a) {
|
||||
if (ctx.profile.support_gl_derivative_control) {
|
||||
ctx.AddF32("{}=dFdyCoarse({});", inst, op_a);
|
||||
} else {
|
||||
LOG_WARNING(Shader_GLSL, "Device does not support dFdyCoarse, fallback to dFdy");
|
||||
ctx.AddF32("{}=dFdy({});", inst, op_a);
|
||||
}
|
||||
}
|
||||
} // namespace Shader::Backend::GLSL
|
||||
714
gpu/third_party/suyu/shader_recompiler/backend/glsl/glsl_emit_context.cpp
vendored
Normal file
714
gpu/third_party/suyu/shader_recompiler/backend/glsl/glsl_emit_context.cpp
vendored
Normal file
@@ -0,0 +1,714 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2026 suyu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "common/div_ceil.h"
|
||||
#include "shader_recompiler/backend/bindings.h"
|
||||
#include "shader_recompiler/backend/glsl/glsl_emit_context.h"
|
||||
#include "shader_recompiler/frontend/ir/program.h"
|
||||
#include "shader_recompiler/profile.h"
|
||||
#include "shader_recompiler/runtime_info.h"
|
||||
|
||||
namespace Shader::Backend::GLSL {
|
||||
namespace {
|
||||
u32 CbufIndex(size_t offset) {
|
||||
return (offset / 4) % 4;
|
||||
}
|
||||
|
||||
char Swizzle(size_t offset) {
|
||||
return "xyzw"[CbufIndex(offset)];
|
||||
}
|
||||
|
||||
std::string_view InterpDecorator(Interpolation interp) {
|
||||
switch (interp) {
|
||||
case Interpolation::Smooth:
|
||||
return "";
|
||||
case Interpolation::Flat:
|
||||
return "flat ";
|
||||
case Interpolation::NoPerspective:
|
||||
return "noperspective ";
|
||||
}
|
||||
throw InvalidArgument("Invalid interpolation {}", interp);
|
||||
}
|
||||
|
||||
std::string_view InputArrayDecorator(Stage stage) {
|
||||
switch (stage) {
|
||||
case Stage::Geometry:
|
||||
case Stage::TessellationControl:
|
||||
case Stage::TessellationEval:
|
||||
return "[]";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
bool StoresPerVertexAttributes(Stage stage) {
|
||||
switch (stage) {
|
||||
case Stage::VertexA:
|
||||
case Stage::VertexB:
|
||||
case Stage::Geometry:
|
||||
case Stage::TessellationEval:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
std::string OutputDecorator(Stage stage, u32 size) {
|
||||
switch (stage) {
|
||||
case Stage::TessellationControl:
|
||||
return fmt::format("[{}]", size);
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
std::string_view DepthSamplerType(TextureType type) {
|
||||
switch (type) {
|
||||
case TextureType::Color1D:
|
||||
return "sampler1DShadow";
|
||||
case TextureType::ColorArray1D:
|
||||
return "sampler1DArrayShadow";
|
||||
case TextureType::Color2D:
|
||||
return "sampler2DShadow";
|
||||
case TextureType::ColorArray2D:
|
||||
return "sampler2DArrayShadow";
|
||||
case TextureType::ColorCube:
|
||||
return "samplerCubeShadow";
|
||||
case TextureType::ColorArrayCube:
|
||||
return "samplerCubeArrayShadow";
|
||||
default:
|
||||
throw NotImplementedException("Texture type: {}", type);
|
||||
}
|
||||
}
|
||||
|
||||
std::string_view ColorSamplerType(TextureType type, bool is_multisample = false) {
|
||||
if (is_multisample) {
|
||||
ASSERT(type == TextureType::Color2D || type == TextureType::ColorArray2D);
|
||||
}
|
||||
switch (type) {
|
||||
case TextureType::Color1D:
|
||||
return "sampler1D";
|
||||
case TextureType::ColorArray1D:
|
||||
return "sampler1DArray";
|
||||
case TextureType::Color2D:
|
||||
case TextureType::Color2DRect:
|
||||
return is_multisample ? "sampler2DMS" : "sampler2D";
|
||||
case TextureType::ColorArray2D:
|
||||
return is_multisample ? "sampler2DMSArray" : "sampler2DArray";
|
||||
case TextureType::Color3D:
|
||||
return "sampler3D";
|
||||
case TextureType::ColorCube:
|
||||
return "samplerCube";
|
||||
case TextureType::ColorArrayCube:
|
||||
return "samplerCubeArray";
|
||||
case TextureType::Buffer:
|
||||
return "samplerBuffer";
|
||||
default:
|
||||
throw NotImplementedException("Texture type: {}", type);
|
||||
}
|
||||
}
|
||||
|
||||
std::string_view ImageType(TextureType type) {
|
||||
switch (type) {
|
||||
case TextureType::Color1D:
|
||||
return "uimage1D";
|
||||
case TextureType::ColorArray1D:
|
||||
return "uimage1DArray";
|
||||
case TextureType::Color2D:
|
||||
return "uimage2D";
|
||||
case TextureType::ColorArray2D:
|
||||
return "uimage2DArray";
|
||||
case TextureType::Color3D:
|
||||
return "uimage3D";
|
||||
case TextureType::ColorCube:
|
||||
return "uimageCube";
|
||||
case TextureType::ColorArrayCube:
|
||||
return "uimageCubeArray";
|
||||
case TextureType::Buffer:
|
||||
return "uimageBuffer";
|
||||
default:
|
||||
throw NotImplementedException("Image type: {}", type);
|
||||
}
|
||||
}
|
||||
|
||||
std::string_view ImageFormatString(ImageFormat format) {
|
||||
switch (format) {
|
||||
case ImageFormat::Typeless:
|
||||
return "";
|
||||
case ImageFormat::R8_UINT:
|
||||
return ",r8ui";
|
||||
case ImageFormat::R8_SINT:
|
||||
return ",r8i";
|
||||
case ImageFormat::R16_UINT:
|
||||
return ",r16ui";
|
||||
case ImageFormat::R16_SINT:
|
||||
return ",r16i";
|
||||
case ImageFormat::R32_UINT:
|
||||
return ",r32ui";
|
||||
case ImageFormat::R32G32_UINT:
|
||||
return ",rg32ui";
|
||||
case ImageFormat::R32G32B32A32_UINT:
|
||||
return ",rgba32ui";
|
||||
default:
|
||||
throw NotImplementedException("Image format: {}", format);
|
||||
}
|
||||
}
|
||||
|
||||
std::string_view ImageAccessQualifier(bool is_written, bool is_read) {
|
||||
if (is_written && !is_read) {
|
||||
return "writeonly ";
|
||||
}
|
||||
if (is_read && !is_written) {
|
||||
return "readonly ";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string_view GetTessMode(TessPrimitive primitive) {
|
||||
switch (primitive) {
|
||||
case TessPrimitive::Triangles:
|
||||
return "triangles";
|
||||
case TessPrimitive::Quads:
|
||||
return "quads";
|
||||
case TessPrimitive::Isolines:
|
||||
return "isolines";
|
||||
}
|
||||
throw InvalidArgument("Invalid tessellation primitive {}", primitive);
|
||||
}
|
||||
|
||||
std::string_view GetTessSpacing(TessSpacing spacing) {
|
||||
switch (spacing) {
|
||||
case TessSpacing::Equal:
|
||||
return "equal_spacing";
|
||||
case TessSpacing::FractionalOdd:
|
||||
return "fractional_odd_spacing";
|
||||
case TessSpacing::FractionalEven:
|
||||
return "fractional_even_spacing";
|
||||
}
|
||||
throw InvalidArgument("Invalid tessellation spacing {}", spacing);
|
||||
}
|
||||
|
||||
std::string_view InputPrimitive(InputTopology topology) {
|
||||
switch (topology) {
|
||||
case InputTopology::Points:
|
||||
return "points";
|
||||
case InputTopology::Lines:
|
||||
return "lines";
|
||||
case InputTopology::LinesAdjacency:
|
||||
return "lines_adjacency";
|
||||
case InputTopology::Triangles:
|
||||
return "triangles";
|
||||
case InputTopology::TrianglesAdjacency:
|
||||
return "triangles_adjacency";
|
||||
}
|
||||
throw InvalidArgument("Invalid input topology {}", topology);
|
||||
}
|
||||
|
||||
std::string_view OutputPrimitive(OutputTopology topology) {
|
||||
switch (topology) {
|
||||
case OutputTopology::PointList:
|
||||
return "points";
|
||||
case OutputTopology::LineStrip:
|
||||
return "line_strip";
|
||||
case OutputTopology::TriangleStrip:
|
||||
return "triangle_strip";
|
||||
}
|
||||
throw InvalidArgument("Invalid output topology {}", topology);
|
||||
}
|
||||
|
||||
void SetupOutPerVertex(EmitContext& ctx, std::string& header) {
|
||||
if (!StoresPerVertexAttributes(ctx.stage)) {
|
||||
return;
|
||||
}
|
||||
if (ctx.uses_geometry_passthrough) {
|
||||
return;
|
||||
}
|
||||
header += "out gl_PerVertex{vec4 gl_Position;";
|
||||
if (ctx.info.stores[IR::Attribute::PointSize]) {
|
||||
header += "float gl_PointSize;";
|
||||
}
|
||||
if (ctx.info.stores.ClipDistances()) {
|
||||
header += "float gl_ClipDistance[];";
|
||||
}
|
||||
if (ctx.info.stores[IR::Attribute::ViewportIndex] &&
|
||||
ctx.profile.support_viewport_index_layer_non_geometry && ctx.stage != Stage::Geometry) {
|
||||
header += "int gl_ViewportIndex;";
|
||||
}
|
||||
header += "};";
|
||||
if (ctx.info.stores[IR::Attribute::ViewportIndex] && ctx.stage == Stage::Geometry) {
|
||||
header += "out int gl_ViewportIndex;";
|
||||
}
|
||||
}
|
||||
|
||||
void SetupInPerVertex(EmitContext& ctx, std::string& header) {
|
||||
// Currently only required for TessellationControl to adhere to
|
||||
// ARB_separate_shader_objects requirements
|
||||
if (ctx.stage != Stage::TessellationControl) {
|
||||
return;
|
||||
}
|
||||
const bool loads_position{ctx.info.loads.AnyComponent(IR::Attribute::PositionX)};
|
||||
const bool loads_point_size{ctx.info.loads[IR::Attribute::PointSize]};
|
||||
const bool loads_clip_distance{ctx.info.loads.ClipDistances()};
|
||||
const bool loads_per_vertex{loads_position || loads_point_size || loads_clip_distance};
|
||||
if (!loads_per_vertex) {
|
||||
return;
|
||||
}
|
||||
header += "in gl_PerVertex{";
|
||||
if (loads_position) {
|
||||
header += "vec4 gl_Position;";
|
||||
}
|
||||
if (loads_point_size) {
|
||||
header += "float gl_PointSize;";
|
||||
}
|
||||
if (loads_clip_distance) {
|
||||
header += "float gl_ClipDistance[];";
|
||||
}
|
||||
header += "}gl_in[gl_MaxPatchVertices];";
|
||||
}
|
||||
} // Anonymous namespace
|
||||
|
||||
EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile& profile_,
|
||||
const RuntimeInfo& runtime_info_)
|
||||
: info{program.info}, profile{profile_}, runtime_info{runtime_info_}, stage{program.stage},
|
||||
uses_geometry_passthrough{program.is_geometry_passthrough &&
|
||||
profile.support_geometry_shader_passthrough} {
|
||||
if (profile.need_fastmath_off) {
|
||||
header += "#pragma optionNV(fastmath off)\n";
|
||||
}
|
||||
SetupExtensions();
|
||||
switch (program.stage) {
|
||||
case Stage::VertexA:
|
||||
case Stage::VertexB:
|
||||
stage_name = "vs";
|
||||
break;
|
||||
case Stage::TessellationControl:
|
||||
stage_name = "tcs";
|
||||
header += fmt::format("layout(vertices={})out;", program.invocations);
|
||||
break;
|
||||
case Stage::TessellationEval:
|
||||
stage_name = "tes";
|
||||
header += fmt::format("layout({},{},{})in;", GetTessMode(runtime_info.tess_primitive),
|
||||
GetTessSpacing(runtime_info.tess_spacing),
|
||||
runtime_info.tess_clockwise ? "cw" : "ccw");
|
||||
break;
|
||||
case Stage::Geometry:
|
||||
stage_name = "gs";
|
||||
header += fmt::format("layout({})in;", InputPrimitive(runtime_info.input_topology));
|
||||
if (uses_geometry_passthrough) {
|
||||
// Passthru REQUIRES the layout to be defined with a corresponding name, for our sanity
|
||||
// we will just use `gl_in[]`, if you don't the driver will complain with:
|
||||
// 0(56) : error C7593: Builtin block member gl_Position not found in redeclaration of in gl_PerVertex
|
||||
header += "layout(passthrough)in gl_PerVertex{vec4 gl_Position;}gl_in[];";
|
||||
break;
|
||||
} else if (program.is_geometry_passthrough && !profile.support_geometry_shader_passthrough) {
|
||||
LOG_WARNING(Shader_GLSL, "Passthrough geometry program used but not supported");
|
||||
}
|
||||
header += fmt::format(
|
||||
"layout({},max_vertices={})out;in gl_PerVertex{{vec4 gl_Position;}}gl_in[];",
|
||||
OutputPrimitive(program.output_topology), program.output_vertices);
|
||||
break;
|
||||
case Stage::Fragment:
|
||||
stage_name = "fs";
|
||||
position_name = "gl_FragCoord";
|
||||
if (runtime_info.force_early_z) {
|
||||
header += "layout(early_fragment_tests)in;";
|
||||
}
|
||||
break;
|
||||
case Stage::Compute:
|
||||
stage_name = "cs";
|
||||
const u32 local_x{(std::max)(program.workgroup_size[0], 1u)};
|
||||
const u32 local_y{(std::max)(program.workgroup_size[1], 1u)};
|
||||
const u32 local_z{(std::max)(program.workgroup_size[2], 1u)};
|
||||
header += fmt::format("layout(local_size_x={},local_size_y={},local_size_z={}) in;",
|
||||
local_x, local_y, local_z);
|
||||
break;
|
||||
}
|
||||
SetupOutPerVertex(*this, header);
|
||||
SetupInPerVertex(*this, header);
|
||||
|
||||
for (size_t index = 0; index < IR::NUM_GENERICS; ++index) {
|
||||
if (!info.loads.Generic(index) || !runtime_info.previous_stage_stores.Generic(index)) {
|
||||
continue;
|
||||
}
|
||||
const auto qualifier{uses_geometry_passthrough ? "passthrough"
|
||||
: fmt::format("location={}", index)};
|
||||
header += fmt::format("layout({}){}in vec4 in_attr{}{};", qualifier,
|
||||
InterpDecorator(info.interpolation[index]), index,
|
||||
InputArrayDecorator(stage));
|
||||
}
|
||||
for (size_t index = 0; index < info.uses_patches.size(); ++index) {
|
||||
if (!info.uses_patches[index]) {
|
||||
continue;
|
||||
}
|
||||
const auto qualifier{stage == Stage::TessellationControl ? "out" : "in"};
|
||||
header += fmt::format("layout(location={})patch {} vec4 patch{};", index, qualifier, index);
|
||||
}
|
||||
if (stage == Stage::Fragment) {
|
||||
for (size_t index = 0; index < info.stores_frag_color.size(); ++index) {
|
||||
if (!info.stores_frag_color[index] && !profile.need_declared_frag_colors) {
|
||||
continue;
|
||||
}
|
||||
header += fmt::format("layout(location={})out vec4 frag_color{};", index, index);
|
||||
}
|
||||
}
|
||||
for (size_t index = 0; index < IR::NUM_GENERICS; ++index) {
|
||||
if (info.stores.Generic(index)) {
|
||||
DefineGenericOutput(index, program.invocations);
|
||||
}
|
||||
}
|
||||
if (info.uses_rescaling_uniform) {
|
||||
header += "layout(location=0) uniform vec4 scaling;";
|
||||
}
|
||||
if (info.uses_render_area) {
|
||||
header += "layout(location=1) uniform vec4 render_area;";
|
||||
}
|
||||
DefineConstantBuffers(bindings);
|
||||
DefineConstantBufferIndirect();
|
||||
DefineStorageBuffers(bindings);
|
||||
SetupImages(bindings);
|
||||
SetupTextures(bindings);
|
||||
DefineHelperFunctions();
|
||||
DefineConstants();
|
||||
}
|
||||
|
||||
void EmitContext::SetupExtensions() {
|
||||
header += "#extension GL_ARB_separate_shader_objects : enable\n";
|
||||
if (info.uses_shadow_lod && profile.support_gl_texture_shadow_lod) {
|
||||
header += "#extension GL_EXT_texture_shadow_lod : enable\n";
|
||||
}
|
||||
if (info.uses_int64 && profile.support_int64) {
|
||||
header += "#extension GL_ARB_gpu_shader_int64 : enable\n";
|
||||
}
|
||||
if (info.uses_int64_bit_atomics) {
|
||||
header += "#extension GL_NV_shader_atomic_int64 : enable\n";
|
||||
}
|
||||
if (info.uses_atomic_f32_add) {
|
||||
header += "#extension GL_NV_shader_atomic_float : enable\n";
|
||||
}
|
||||
if (info.uses_atomic_f16x2_add || info.uses_atomic_f16x2_min || info.uses_atomic_f16x2_max) {
|
||||
header += "#extension GL_NV_shader_atomic_fp16_vector : enable\n";
|
||||
}
|
||||
if (info.uses_fp16) {
|
||||
if (profile.support_gl_nv_gpu_shader_5) {
|
||||
header += "#extension GL_NV_gpu_shader5 : enable\n";
|
||||
}
|
||||
if (profile.support_gl_amd_gpu_shader_half_float) {
|
||||
header += "#extension GL_AMD_gpu_shader_half_float : enable\n";
|
||||
}
|
||||
}
|
||||
if (info.uses_subgroup_invocation_id || info.uses_subgroup_mask || info.uses_subgroup_vote ||
|
||||
info.uses_subgroup_shuffles || info.uses_fswzadd) {
|
||||
header += "#extension GL_ARB_shader_ballot : enable\n"
|
||||
"#extension GL_ARB_shader_group_vote : enable\n";
|
||||
if (!info.uses_int64 && profile.support_int64) {
|
||||
header += "#extension GL_ARB_gpu_shader_int64 : enable\n";
|
||||
}
|
||||
if (profile.support_gl_warp_intrinsics) {
|
||||
header += "#extension GL_NV_shader_thread_shuffle : enable\n";
|
||||
}
|
||||
}
|
||||
if ((info.stores[IR::Attribute::ViewportIndex] || info.stores[IR::Attribute::Layer]) &&
|
||||
profile.support_viewport_index_layer_non_geometry && stage != Stage::Geometry) {
|
||||
header += "#extension GL_ARB_shader_viewport_layer_array : enable\n";
|
||||
}
|
||||
if (info.uses_sparse_residency && profile.support_gl_sparse_textures) {
|
||||
header += "#extension GL_ARB_sparse_texture2 : enable\n";
|
||||
}
|
||||
if (info.stores[IR::Attribute::ViewportMask] && profile.support_viewport_mask) {
|
||||
header += "#extension GL_NV_viewport_array2 : enable\n";
|
||||
}
|
||||
if (info.uses_typeless_image_reads) {
|
||||
header += "#extension GL_EXT_shader_image_load_formatted : enable\n";
|
||||
}
|
||||
if (info.uses_derivatives && profile.support_gl_derivative_control) {
|
||||
header += "#extension GL_ARB_derivative_control : enable\n";
|
||||
}
|
||||
if (uses_geometry_passthrough) {
|
||||
header += "#extension GL_NV_geometry_shader_passthrough : enable\n";
|
||||
}
|
||||
}
|
||||
|
||||
void EmitContext::DefineConstantBuffers(Bindings& bindings) {
|
||||
if (info.constant_buffer_descriptors.empty()) {
|
||||
return;
|
||||
}
|
||||
for (const auto& desc : info.constant_buffer_descriptors) {
|
||||
const auto cbuf_type{profile.has_gl_cbuf_ftou_bug ? "uvec4" : "vec4"};
|
||||
const u32 cbuf_used_size{Common::DivCeil(info.constant_buffer_used_sizes[desc.index], 16U)};
|
||||
const u32 cbuf_binding_size{info.uses_global_memory ? 0x1000U : cbuf_used_size};
|
||||
header += fmt::format("layout(std140,binding={}) uniform {}_cbuf_{}{{{} {}_cbuf{}[{}];}};",
|
||||
bindings.uniform_buffer, stage_name, desc.index, cbuf_type,
|
||||
stage_name, desc.index, cbuf_binding_size);
|
||||
bindings.uniform_buffer += desc.count;
|
||||
}
|
||||
}
|
||||
|
||||
void EmitContext::DefineConstantBufferIndirect() {
|
||||
if (!info.uses_cbuf_indirect) {
|
||||
return;
|
||||
}
|
||||
|
||||
header += profile.has_gl_cbuf_ftou_bug ? "uvec4 " : "vec4 ";
|
||||
header += "GetCbufIndirect(uint binding, uint offset){"
|
||||
"switch(binding){"
|
||||
"default:";
|
||||
|
||||
for (const auto& desc : info.constant_buffer_descriptors) {
|
||||
header +=
|
||||
fmt::format("case {}:return {}_cbuf{}[offset];", desc.index, stage_name, desc.index);
|
||||
}
|
||||
|
||||
header += "}}";
|
||||
}
|
||||
|
||||
void EmitContext::DefineStorageBuffers(Bindings& bindings) {
|
||||
if (info.storage_buffers_descriptors.empty()) {
|
||||
return;
|
||||
}
|
||||
u32 index{};
|
||||
for (const auto& desc : info.storage_buffers_descriptors) {
|
||||
header += fmt::format("layout(std430,binding={}) buffer {}_ssbo_{}{{uint {}_ssbo{}[];}};",
|
||||
bindings.storage_buffer, stage_name, bindings.storage_buffer,
|
||||
stage_name, index);
|
||||
bindings.storage_buffer += desc.count;
|
||||
index += desc.count;
|
||||
}
|
||||
}
|
||||
|
||||
void EmitContext::DefineGenericOutput(size_t index, u32 invocations) {
|
||||
static constexpr std::string_view swizzle{"xyzw"};
|
||||
const size_t base_index{static_cast<size_t>(IR::Attribute::Generic0X) + index * 4};
|
||||
u32 element{0};
|
||||
while (element < 4) {
|
||||
std::string definition{fmt::format("layout(location={}", index)};
|
||||
const u32 remainder{4 - element};
|
||||
const TransformFeedbackVarying* xfb_varying{};
|
||||
const size_t xfb_varying_index{base_index + element};
|
||||
if (xfb_varying_index < runtime_info.xfb_count) {
|
||||
xfb_varying = &runtime_info.xfb_varyings[xfb_varying_index];
|
||||
xfb_varying = xfb_varying->components > 0 ? xfb_varying : nullptr;
|
||||
}
|
||||
const u32 num_components{xfb_varying ? xfb_varying->components : remainder};
|
||||
if (element > 0) {
|
||||
definition += fmt::format(",component={}", element);
|
||||
}
|
||||
if (xfb_varying) {
|
||||
definition +=
|
||||
fmt::format(",xfb_buffer={},xfb_stride={},xfb_offset={}", xfb_varying->buffer,
|
||||
xfb_varying->stride, xfb_varying->offset);
|
||||
}
|
||||
std::string name{fmt::format("out_attr{}", index)};
|
||||
if (num_components < 4 || element > 0) {
|
||||
name += fmt::format("_{}", swizzle.substr(element, num_components));
|
||||
}
|
||||
const auto type{num_components == 1 ? "float" : fmt::format("vec{}", num_components)};
|
||||
definition += fmt::format(")out {} {}{};", type, name, OutputDecorator(stage, invocations));
|
||||
header += definition;
|
||||
|
||||
const GenericElementInfo element_info{
|
||||
.name = name,
|
||||
.first_element = element,
|
||||
.num_components = num_components,
|
||||
};
|
||||
std::fill_n(output_generics[index].begin() + element, num_components, element_info);
|
||||
element += num_components;
|
||||
}
|
||||
}
|
||||
|
||||
void EmitContext::DefineHelperFunctions() {
|
||||
header += "\n#define ftoi floatBitsToInt\n#define ftou floatBitsToUint\n"
|
||||
"#define itof intBitsToFloat\n#define utof uintBitsToFloat\n";
|
||||
if (info.uses_global_increment || info.uses_shared_increment) {
|
||||
header += "uint CasIncrement(uint op_a,uint op_b){return op_a>=op_b?0u:(op_a+1u);}";
|
||||
}
|
||||
if (info.uses_global_decrement || info.uses_shared_decrement) {
|
||||
header += "uint CasDecrement(uint op_a,uint op_b){"
|
||||
"return op_a==0||op_a>op_b?op_b:(op_a-1u);}";
|
||||
}
|
||||
if (info.uses_atomic_f32_add) {
|
||||
header += "uint CasFloatAdd(uint op_a,float op_b){"
|
||||
"return ftou(utof(op_a)+op_b);}";
|
||||
}
|
||||
if (info.uses_atomic_f32x2_add) {
|
||||
header += "uint CasFloatAdd32x2(uint op_a,vec2 op_b){"
|
||||
"return packHalf2x16(unpackHalf2x16(op_a)+op_b);}";
|
||||
}
|
||||
if (info.uses_atomic_f32x2_min) {
|
||||
header += "uint CasFloatMin32x2(uint op_a,vec2 op_b){return "
|
||||
"packHalf2x16(min(unpackHalf2x16(op_a),op_b));}";
|
||||
}
|
||||
if (info.uses_atomic_f32x2_max) {
|
||||
header += "uint CasFloatMax32x2(uint op_a,vec2 op_b){return "
|
||||
"packHalf2x16(max(unpackHalf2x16(op_a),op_b));}";
|
||||
}
|
||||
if (info.uses_atomic_f16x2_add) {
|
||||
header += "uint CasFloatAdd16x2(uint op_a,f16vec2 op_b){return "
|
||||
"packFloat2x16(unpackFloat2x16(op_a)+op_b);}";
|
||||
}
|
||||
if (info.uses_atomic_f16x2_min) {
|
||||
header += "uint CasFloatMin16x2(uint op_a,f16vec2 op_b){return "
|
||||
"packFloat2x16(min(unpackFloat2x16(op_a),op_b));}";
|
||||
}
|
||||
if (info.uses_atomic_f16x2_max) {
|
||||
header += "uint CasFloatMax16x2(uint op_a,f16vec2 op_b){return "
|
||||
"packFloat2x16(max(unpackFloat2x16(op_a),op_b));}";
|
||||
}
|
||||
if (info.uses_atomic_s32_min) {
|
||||
header += "uint CasMinS32(uint op_a,uint op_b){return uint(min(int(op_a),int(op_b)));}";
|
||||
}
|
||||
if (info.uses_atomic_s32_max) {
|
||||
header += "uint CasMaxS32(uint op_a,uint op_b){return uint(max(int(op_a),int(op_b)));}";
|
||||
}
|
||||
if (info.uses_global_memory && profile.support_int64) {
|
||||
header += DefineGlobalMemoryFunctions();
|
||||
}
|
||||
if (info.loads_indexed_attributes) {
|
||||
const bool is_array{stage == Stage::Geometry};
|
||||
const auto vertex_arg{is_array ? ",uint vertex" : ""};
|
||||
std::string func{
|
||||
fmt::format("float IndexedAttrLoad(int offset{}){{int base_index=offset>>2;uint "
|
||||
"masked_index=uint(base_index)&3u;switch(base_index>>2){{",
|
||||
vertex_arg)};
|
||||
if (info.loads.AnyComponent(IR::Attribute::PositionX)) {
|
||||
const auto position_idx{is_array ? "gl_in[vertex]." : ""};
|
||||
func += fmt::format("case {}:return {}{}[masked_index];",
|
||||
static_cast<u32>(IR::Attribute::PositionX) >> 2, position_idx,
|
||||
position_name);
|
||||
}
|
||||
const u32 base_attribute_value = static_cast<u32>(IR::Attribute::Generic0X) >> 2;
|
||||
for (u32 index = 0; index < IR::NUM_GENERICS; ++index) {
|
||||
if (!info.loads.Generic(index)) {
|
||||
continue;
|
||||
}
|
||||
const auto vertex_idx{is_array ? "[vertex]" : ""};
|
||||
func += fmt::format("case {}:return in_attr{}{}[masked_index];",
|
||||
base_attribute_value + index, index, vertex_idx);
|
||||
}
|
||||
func += "default: return 0.0;}}";
|
||||
header += func;
|
||||
}
|
||||
if (info.stores_indexed_attributes) {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
|
||||
std::string EmitContext::DefineGlobalMemoryFunctions() {
|
||||
const auto define_body{[&](std::string& func, size_t index, std::string_view return_statement) {
|
||||
const auto& ssbo{info.storage_buffers_descriptors[index]};
|
||||
const u32 size_cbuf_offset{ssbo.cbuf_offset + 8};
|
||||
const auto ssbo_addr{fmt::format("ssbo_addr{}", index)};
|
||||
const auto cbuf{fmt::format("{}_cbuf{}", stage_name, ssbo.cbuf_index)};
|
||||
std::array<std::string, 2> addr_xy;
|
||||
std::array<std::string, 2> size_xy;
|
||||
for (size_t i = 0; i < addr_xy.size(); ++i) {
|
||||
const auto addr_loc{ssbo.cbuf_offset + 4 * i};
|
||||
const auto size_loc{size_cbuf_offset + 4 * i};
|
||||
addr_xy[i] = fmt::format("ftou({}[{}].{})", cbuf, addr_loc / 16, Swizzle(addr_loc));
|
||||
size_xy[i] = fmt::format("ftou({}[{}].{})", cbuf, size_loc / 16, Swizzle(size_loc));
|
||||
}
|
||||
const u32 ssbo_align_mask{~(static_cast<u32>(profile.min_ssbo_alignment) - 1U)};
|
||||
const auto aligned_low_addr{fmt::format("{}&{}", addr_xy[0], ssbo_align_mask)};
|
||||
const auto aligned_addr{fmt::format("uvec2({},{})", aligned_low_addr, addr_xy[1])};
|
||||
const auto addr_pack{fmt::format("packUint2x32({})", aligned_addr)};
|
||||
const auto addr_statement{fmt::format("uint64_t {}={};", ssbo_addr, addr_pack)};
|
||||
func += addr_statement;
|
||||
|
||||
const auto size_vec{fmt::format("uvec2({},{})", size_xy[0], size_xy[1])};
|
||||
const auto comp_lhs{fmt::format("(addr>={})", ssbo_addr)};
|
||||
const auto comp_rhs{fmt::format("(addr<({}+uint64_t({})))", ssbo_addr, size_vec)};
|
||||
const auto comparison{fmt::format("if({}&&{}){{", comp_lhs, comp_rhs)};
|
||||
func += comparison;
|
||||
|
||||
const auto ssbo_name{fmt::format("{}_ssbo{}", stage_name, index)};
|
||||
func += fmt::format(fmt::runtime(return_statement), ssbo_name, ssbo_addr);
|
||||
}};
|
||||
std::string write_func{"void WriteGlobal32(uint64_t addr,uint data){"};
|
||||
std::string write_func_64{"void WriteGlobal64(uint64_t addr,uvec2 data){"};
|
||||
std::string write_func_128{"void WriteGlobal128(uint64_t addr,uvec4 data){"};
|
||||
std::string load_func{"uint LoadGlobal32(uint64_t addr){"};
|
||||
std::string load_func_64{"uvec2 LoadGlobal64(uint64_t addr){"};
|
||||
std::string load_func_128{"uvec4 LoadGlobal128(uint64_t addr){"};
|
||||
const size_t num_buffers{info.storage_buffers_descriptors.size()};
|
||||
for (size_t index = 0; index < num_buffers; ++index) {
|
||||
if (!info.nvn_buffer_used[index]) {
|
||||
continue;
|
||||
}
|
||||
define_body(write_func, index, "{0}[uint(addr-{1})>>2]=data;return;}}");
|
||||
define_body(write_func_64, index,
|
||||
"{0}[uint(addr-{1})>>2]=data.x;{0}[uint(addr-{1}+4)>>2]=data.y;return;}}");
|
||||
define_body(write_func_128, index,
|
||||
"{0}[uint(addr-{1})>>2]=data.x;{0}[uint(addr-{1}+4)>>2]=data.y;{0}[uint("
|
||||
"addr-{1}+8)>>2]=data.z;{0}[uint(addr-{1}+12)>>2]=data.w;return;}}");
|
||||
define_body(load_func, index, "return {0}[uint(addr-{1})>>2];}}");
|
||||
define_body(load_func_64, index,
|
||||
"return uvec2({0}[uint(addr-{1})>>2],{0}[uint(addr-{1}+4)>>2]);}}");
|
||||
define_body(load_func_128, index,
|
||||
"return uvec4({0}[uint(addr-{1})>>2],{0}[uint(addr-{1}+4)>>2],{0}["
|
||||
"uint(addr-{1}+8)>>2],{0}[uint(addr-{1}+12)>>2]);}}");
|
||||
}
|
||||
write_func += '}';
|
||||
write_func_64 += '}';
|
||||
write_func_128 += '}';
|
||||
load_func += "return 0u;}";
|
||||
load_func_64 += "return uvec2(0);}";
|
||||
load_func_128 += "return uvec4(0);}";
|
||||
return write_func + write_func_64 + write_func_128 + load_func + load_func_64 + load_func_128;
|
||||
}
|
||||
|
||||
void EmitContext::SetupImages(Bindings& bindings) {
|
||||
image_buffers.reserve(info.image_buffer_descriptors.size());
|
||||
for (const auto& desc : info.image_buffer_descriptors) {
|
||||
image_buffers.push_back({bindings.image, desc.count});
|
||||
const auto format{ImageFormatString(desc.format)};
|
||||
const auto qualifier{ImageAccessQualifier(desc.is_written, desc.is_read)};
|
||||
const auto array_decorator{desc.count > 1 ? fmt::format("[{}]", desc.count) : ""};
|
||||
header += fmt::format("layout(binding={}{}) uniform {}uimageBuffer img{}{};",
|
||||
bindings.image, format, qualifier, bindings.image, array_decorator);
|
||||
bindings.image += desc.count;
|
||||
}
|
||||
images.reserve(info.image_descriptors.size());
|
||||
for (const auto& desc : info.image_descriptors) {
|
||||
images.push_back({bindings.image, desc.count});
|
||||
const auto format{ImageFormatString(desc.format)};
|
||||
const auto image_type{ImageType(desc.type)};
|
||||
const auto qualifier{ImageAccessQualifier(desc.is_written, desc.is_read)};
|
||||
const auto array_decorator{desc.count > 1 ? fmt::format("[{}]", desc.count) : ""};
|
||||
header += fmt::format("layout(binding={}{})uniform {}{} img{}{};", bindings.image, format,
|
||||
qualifier, image_type, bindings.image, array_decorator);
|
||||
bindings.image += desc.count;
|
||||
}
|
||||
}
|
||||
|
||||
void EmitContext::SetupTextures(Bindings& bindings) {
|
||||
texture_buffers.reserve(info.texture_buffer_descriptors.size());
|
||||
for (const auto& desc : info.texture_buffer_descriptors) {
|
||||
texture_buffers.push_back({bindings.texture, desc.count});
|
||||
const auto sampler_type{ColorSamplerType(TextureType::Buffer)};
|
||||
const auto array_decorator{desc.count > 1 ? fmt::format("[{}]", desc.count) : ""};
|
||||
header += fmt::format("layout(binding={}) uniform {} tex{}{};", bindings.texture,
|
||||
sampler_type, bindings.texture, array_decorator);
|
||||
bindings.texture += desc.count;
|
||||
}
|
||||
textures.reserve(info.texture_descriptors.size());
|
||||
for (const auto& desc : info.texture_descriptors) {
|
||||
textures.push_back({bindings.texture, desc.count});
|
||||
const auto sampler_type{desc.is_depth ? DepthSamplerType(desc.type)
|
||||
: ColorSamplerType(desc.type, desc.is_multisample)};
|
||||
const auto array_decorator{desc.count > 1 ? fmt::format("[{}]", desc.count) : ""};
|
||||
header += fmt::format("layout(binding={}) uniform {} tex{}{};", bindings.texture,
|
||||
sampler_type, bindings.texture, array_decorator);
|
||||
bindings.texture += desc.count;
|
||||
}
|
||||
}
|
||||
|
||||
void EmitContext::DefineConstants() {
|
||||
if (info.uses_fswzadd) {
|
||||
header += "const float FSWZ_A[]=float[4](-1.f,1.f,-1.f,0.f);"
|
||||
"const float FSWZ_B[]=float[4](-1.f,-1.f,1.f,-1.f);";
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Shader::Backend::GLSL
|
||||
174
gpu/third_party/suyu/shader_recompiler/backend/glsl/glsl_emit_context.h
vendored
Normal file
174
gpu/third_party/suyu/shader_recompiler/backend/glsl/glsl_emit_context.h
vendored
Normal file
@@ -0,0 +1,174 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <fmt/ranges.h>
|
||||
|
||||
#include "shader_recompiler/backend/glsl/var_alloc.h"
|
||||
#include "shader_recompiler/stage.h"
|
||||
|
||||
namespace Shader {
|
||||
struct Info;
|
||||
struct Profile;
|
||||
struct RuntimeInfo;
|
||||
} // namespace Shader
|
||||
|
||||
namespace Shader::Backend {
|
||||
struct Bindings;
|
||||
}
|
||||
|
||||
namespace Shader::IR {
|
||||
class Inst;
|
||||
struct Program;
|
||||
} // namespace Shader::IR
|
||||
|
||||
namespace Shader::Backend::GLSL {
|
||||
|
||||
struct GenericElementInfo {
|
||||
std::string name;
|
||||
u32 first_element{};
|
||||
u32 num_components{};
|
||||
};
|
||||
|
||||
struct TextureImageDefinition {
|
||||
u32 binding;
|
||||
u32 count;
|
||||
};
|
||||
|
||||
class EmitContext {
|
||||
public:
|
||||
explicit EmitContext(IR::Program& program, Bindings& bindings, const Profile& profile_,
|
||||
const RuntimeInfo& runtime_info_);
|
||||
|
||||
template <GlslVarType type, typename... Args>
|
||||
void Add(const char* format_str, IR::Inst& inst, Args&&... args) {
|
||||
const auto var_def{var_alloc.AddDefine(inst, type)};
|
||||
if (var_def.empty()) {
|
||||
// skip assignment.
|
||||
code += fmt::format(fmt::runtime(format_str + 3), std::forward<Args>(args)...);
|
||||
} else {
|
||||
code += fmt::format(fmt::runtime(format_str), var_def, std::forward<Args>(args)...);
|
||||
}
|
||||
// TODO: Remove this
|
||||
code += '\n';
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void AddU1(const char* format_str, IR::Inst& inst, Args&&... args) {
|
||||
Add<GlslVarType::U1>(format_str, inst, args...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void AddF16x2(const char* format_str, IR::Inst& inst, Args&&... args) {
|
||||
Add<GlslVarType::F16x2>(format_str, inst, args...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void AddU32(const char* format_str, IR::Inst& inst, Args&&... args) {
|
||||
Add<GlslVarType::U32>(format_str, inst, args...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void AddF32(const char* format_str, IR::Inst& inst, Args&&... args) {
|
||||
Add<GlslVarType::F32>(format_str, inst, args...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void AddU64(const char* format_str, IR::Inst& inst, Args&&... args) {
|
||||
Add<GlslVarType::U64>(format_str, inst, args...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void AddF64(const char* format_str, IR::Inst& inst, Args&&... args) {
|
||||
Add<GlslVarType::F64>(format_str, inst, args...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void AddU32x2(const char* format_str, IR::Inst& inst, Args&&... args) {
|
||||
Add<GlslVarType::U32x2>(format_str, inst, args...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void AddF32x2(const char* format_str, IR::Inst& inst, Args&&... args) {
|
||||
Add<GlslVarType::F32x2>(format_str, inst, args...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void AddU32x3(const char* format_str, IR::Inst& inst, Args&&... args) {
|
||||
Add<GlslVarType::U32x3>(format_str, inst, args...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void AddF32x3(const char* format_str, IR::Inst& inst, Args&&... args) {
|
||||
Add<GlslVarType::F32x3>(format_str, inst, args...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void AddU32x4(const char* format_str, IR::Inst& inst, Args&&... args) {
|
||||
Add<GlslVarType::U32x4>(format_str, inst, args...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void AddF32x4(const char* format_str, IR::Inst& inst, Args&&... args) {
|
||||
Add<GlslVarType::F32x4>(format_str, inst, args...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void AddPrecF32(const char* format_str, IR::Inst& inst, Args&&... args) {
|
||||
Add<GlslVarType::PrecF32>(format_str, inst, args...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void AddPrecF64(const char* format_str, IR::Inst& inst, Args&&... args) {
|
||||
Add<GlslVarType::PrecF64>(format_str, inst, args...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void Add(const char* format_str, Args&&... args) {
|
||||
code += fmt::format(fmt::runtime(format_str), std::forward<Args>(args)...);
|
||||
// TODO: Remove this
|
||||
code += '\n';
|
||||
}
|
||||
|
||||
std::string header;
|
||||
std::string code;
|
||||
VarAlloc var_alloc;
|
||||
const Info& info;
|
||||
const Profile& profile;
|
||||
const RuntimeInfo& runtime_info;
|
||||
|
||||
Stage stage{};
|
||||
std::string_view stage_name = "invalid";
|
||||
std::string_view position_name = "gl_Position";
|
||||
|
||||
std::vector<TextureImageDefinition> texture_buffers;
|
||||
std::vector<TextureImageDefinition> image_buffers;
|
||||
std::vector<TextureImageDefinition> textures;
|
||||
std::vector<TextureImageDefinition> images;
|
||||
std::array<std::array<GenericElementInfo, 4>, 32> output_generics{};
|
||||
|
||||
u32 num_safety_loop_vars{};
|
||||
|
||||
bool uses_y_direction{};
|
||||
bool uses_cc_carry{};
|
||||
bool uses_geometry_passthrough{};
|
||||
|
||||
private:
|
||||
void SetupExtensions();
|
||||
void DefineConstantBuffers(Bindings& bindings);
|
||||
void DefineConstantBufferIndirect();
|
||||
void DefineStorageBuffers(Bindings& bindings);
|
||||
void DefineGenericOutput(size_t index, u32 invocations);
|
||||
void DefineHelperFunctions();
|
||||
void DefineConstants();
|
||||
std::string DefineGlobalMemoryFunctions();
|
||||
void SetupImages(Bindings& bindings);
|
||||
void SetupTextures(Bindings& bindings);
|
||||
};
|
||||
|
||||
} // namespace Shader::Backend::GLSL
|
||||
309
gpu/third_party/suyu/shader_recompiler/backend/glsl/var_alloc.cpp
vendored
Normal file
309
gpu/third_party/suyu/shader_recompiler/backend/glsl/var_alloc.cpp
vendored
Normal file
@@ -0,0 +1,309 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2025 suyu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
#include <fmt/ranges.h>
|
||||
|
||||
#include "shader_recompiler/backend/glsl/var_alloc.h"
|
||||
#include "shader_recompiler/exception.h"
|
||||
#include "shader_recompiler/frontend/ir/value.h"
|
||||
|
||||
namespace Shader::Backend::GLSL {
|
||||
namespace {
|
||||
std::string TypePrefix(GlslVarType type) {
|
||||
switch (type) {
|
||||
case GlslVarType::U1:
|
||||
return "b_";
|
||||
case GlslVarType::F16x2:
|
||||
return "f16x2_";
|
||||
case GlslVarType::U32:
|
||||
return "u_";
|
||||
case GlslVarType::F32:
|
||||
return "f_";
|
||||
case GlslVarType::U64:
|
||||
return "u64_";
|
||||
case GlslVarType::F64:
|
||||
return "d_";
|
||||
case GlslVarType::U32x2:
|
||||
return "u2_";
|
||||
case GlslVarType::F32x2:
|
||||
return "f2_";
|
||||
case GlslVarType::U32x3:
|
||||
return "u3_";
|
||||
case GlslVarType::F32x3:
|
||||
return "f3_";
|
||||
case GlslVarType::U32x4:
|
||||
return "u4_";
|
||||
case GlslVarType::F32x4:
|
||||
return "f4_";
|
||||
case GlslVarType::PrecF32:
|
||||
return "pf_";
|
||||
case GlslVarType::PrecF64:
|
||||
return "pd_";
|
||||
case GlslVarType::Void:
|
||||
return "";
|
||||
default:
|
||||
throw NotImplementedException("Type {}", type);
|
||||
}
|
||||
}
|
||||
|
||||
std::string FormatFloat(std::string_view value, IR::Type type) {
|
||||
// TODO: Confirm FP64 nan/inf
|
||||
if (type == IR::Type::F32) {
|
||||
if (value == "nan") {
|
||||
return "utof(0x7fc00000)";
|
||||
}
|
||||
if (value == "inf") {
|
||||
return "utof(0x7f800000)";
|
||||
}
|
||||
if (value == "-inf") {
|
||||
return "utof(0xff800000)";
|
||||
}
|
||||
}
|
||||
if (value.find_first_of('e') != std::string_view::npos) {
|
||||
// scientific notation
|
||||
const auto cast{type == IR::Type::F32 ? "float" : "double"};
|
||||
return fmt::format("{}({})", cast, value);
|
||||
}
|
||||
const bool needs_dot{value.find_first_of('.') == std::string_view::npos};
|
||||
const bool needs_suffix{!value.ends_with('f')};
|
||||
const auto suffix{type == IR::Type::F32 ? "f" : "lf"};
|
||||
return fmt::format("{}{}{}", value, needs_dot ? "." : "", needs_suffix ? suffix : "");
|
||||
}
|
||||
|
||||
std::string MakeImm(const IR::Value& value) {
|
||||
switch (value.Type()) {
|
||||
case IR::Type::U1:
|
||||
return fmt::format("{}", value.U1() ? "true" : "false");
|
||||
case IR::Type::U32:
|
||||
return fmt::format("{}u", value.U32());
|
||||
case IR::Type::F32:
|
||||
return FormatFloat(fmt::format("{}", value.F32()), IR::Type::F32);
|
||||
case IR::Type::U64:
|
||||
return fmt::format("{}ul", value.U64());
|
||||
case IR::Type::F64:
|
||||
return FormatFloat(fmt::format("{}", value.F64()), IR::Type::F64);
|
||||
case IR::Type::Void:
|
||||
return "";
|
||||
default:
|
||||
throw NotImplementedException("Immediate type {}", value.Type());
|
||||
}
|
||||
}
|
||||
} // Anonymous namespace
|
||||
|
||||
std::string VarAlloc::Representation(u32 index, GlslVarType type) const {
|
||||
const auto prefix{TypePrefix(type)};
|
||||
return fmt::format("{}{}", prefix, index);
|
||||
}
|
||||
|
||||
std::string VarAlloc::Representation(Id id) const {
|
||||
return Representation(id.index, id.type);
|
||||
}
|
||||
|
||||
std::string VarAlloc::Define(IR::Inst& inst, GlslVarType type) {
|
||||
if (inst.HasUses()) {
|
||||
inst.SetDefinition<Id>(Alloc(type));
|
||||
return Representation(inst.Definition<Id>());
|
||||
} else {
|
||||
Id id{};
|
||||
id.type.Assign(type);
|
||||
GetUseTracker(type).uses_temp = true;
|
||||
inst.SetDefinition<Id>(id);
|
||||
return 't' + Representation(inst.Definition<Id>());
|
||||
}
|
||||
}
|
||||
|
||||
std::string VarAlloc::Define(IR::Inst& inst, IR::Type type) {
|
||||
return Define(inst, RegType(type));
|
||||
}
|
||||
|
||||
std::string VarAlloc::PhiDefine(IR::Inst& inst, IR::Type type) {
|
||||
return AddDefine(inst, RegType(type));
|
||||
}
|
||||
|
||||
std::string VarAlloc::AddDefine(IR::Inst& inst, GlslVarType type) {
|
||||
if (inst.HasUses()) {
|
||||
inst.SetDefinition<Id>(Alloc(type));
|
||||
return Representation(inst.Definition<Id>());
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
std::string VarAlloc::Consume(const IR::Value& value) {
|
||||
return value.IsImmediate() ? MakeImm(value) : ConsumeInst(*value.InstRecursive());
|
||||
}
|
||||
|
||||
std::string VarAlloc::ConsumeInst(IR::Inst& inst) {
|
||||
inst.DestructiveRemoveUsage();
|
||||
if (!inst.HasUses()) {
|
||||
Free(inst.Definition<Id>());
|
||||
}
|
||||
return Representation(inst.Definition<Id>());
|
||||
}
|
||||
|
||||
std::string VarAlloc::GetGlslType(IR::Type type) const {
|
||||
return GetGlslType(RegType(type));
|
||||
}
|
||||
|
||||
Id VarAlloc::Alloc(GlslVarType type) {
|
||||
auto& use_tracker{GetUseTracker(type)};
|
||||
const auto num_vars{use_tracker.var_use.size()};
|
||||
for (size_t var = 0; var < num_vars; ++var) {
|
||||
if (use_tracker.var_use[var]) {
|
||||
continue;
|
||||
}
|
||||
use_tracker.num_used = (std::max)(use_tracker.num_used, var + 1);
|
||||
use_tracker.var_use[var] = true;
|
||||
Id ret{};
|
||||
ret.is_valid.Assign(1);
|
||||
ret.type.Assign(type);
|
||||
ret.index.Assign(static_cast<u32>(var));
|
||||
return ret;
|
||||
}
|
||||
// Allocate a new variable
|
||||
use_tracker.var_use.push_back(true);
|
||||
Id ret{};
|
||||
ret.is_valid.Assign(1);
|
||||
ret.type.Assign(type);
|
||||
ret.index.Assign(static_cast<u32>(use_tracker.num_used));
|
||||
++use_tracker.num_used;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void VarAlloc::Free(Id id) {
|
||||
if (id.is_valid == 0) {
|
||||
throw LogicError("Freeing invalid variable");
|
||||
}
|
||||
auto& use_tracker{GetUseTracker(id.type)};
|
||||
use_tracker.var_use[id.index] = false;
|
||||
}
|
||||
|
||||
GlslVarType VarAlloc::RegType(IR::Type type) const {
|
||||
switch (type) {
|
||||
case IR::Type::U1:
|
||||
return GlslVarType::U1;
|
||||
case IR::Type::U32:
|
||||
return GlslVarType::U32;
|
||||
case IR::Type::F32:
|
||||
return GlslVarType::F32;
|
||||
case IR::Type::U64:
|
||||
return GlslVarType::U64;
|
||||
case IR::Type::F64:
|
||||
return GlslVarType::F64;
|
||||
default:
|
||||
throw NotImplementedException("IR type {}", type);
|
||||
}
|
||||
}
|
||||
|
||||
std::string VarAlloc::GetGlslType(GlslVarType type) const {
|
||||
switch (type) {
|
||||
case GlslVarType::U1:
|
||||
return "bool";
|
||||
case GlslVarType::F16x2:
|
||||
return "f16vec2";
|
||||
case GlslVarType::U32:
|
||||
return "uint";
|
||||
case GlslVarType::F32:
|
||||
case GlslVarType::PrecF32:
|
||||
return "float";
|
||||
case GlslVarType::U64:
|
||||
return "uint64_t";
|
||||
case GlslVarType::F64:
|
||||
case GlslVarType::PrecF64:
|
||||
return "double";
|
||||
case GlslVarType::U32x2:
|
||||
return "uvec2";
|
||||
case GlslVarType::F32x2:
|
||||
return "vec2";
|
||||
case GlslVarType::U32x3:
|
||||
return "uvec3";
|
||||
case GlslVarType::F32x3:
|
||||
return "vec3";
|
||||
case GlslVarType::U32x4:
|
||||
return "uvec4";
|
||||
case GlslVarType::F32x4:
|
||||
return "vec4";
|
||||
case GlslVarType::Void:
|
||||
return "";
|
||||
default:
|
||||
throw NotImplementedException("Type {}", type);
|
||||
}
|
||||
}
|
||||
|
||||
VarAlloc::UseTracker& VarAlloc::GetUseTracker(GlslVarType type) {
|
||||
switch (type) {
|
||||
case GlslVarType::U1:
|
||||
return var_bool;
|
||||
case GlslVarType::F16x2:
|
||||
return var_f16x2;
|
||||
case GlslVarType::U32:
|
||||
return var_u32;
|
||||
case GlslVarType::F32:
|
||||
return var_f32;
|
||||
case GlslVarType::U64:
|
||||
return var_u64;
|
||||
case GlslVarType::F64:
|
||||
return var_f64;
|
||||
case GlslVarType::U32x2:
|
||||
return var_u32x2;
|
||||
case GlslVarType::F32x2:
|
||||
return var_f32x2;
|
||||
case GlslVarType::U32x3:
|
||||
return var_u32x3;
|
||||
case GlslVarType::F32x3:
|
||||
return var_f32x3;
|
||||
case GlslVarType::U32x4:
|
||||
return var_u32x4;
|
||||
case GlslVarType::F32x4:
|
||||
return var_f32x4;
|
||||
case GlslVarType::PrecF32:
|
||||
return var_precf32;
|
||||
case GlslVarType::PrecF64:
|
||||
return var_precf64;
|
||||
default:
|
||||
throw NotImplementedException("Type {}", type);
|
||||
}
|
||||
}
|
||||
|
||||
const VarAlloc::UseTracker& VarAlloc::GetUseTracker(GlslVarType type) const {
|
||||
switch (type) {
|
||||
case GlslVarType::U1:
|
||||
return var_bool;
|
||||
case GlslVarType::F16x2:
|
||||
return var_f16x2;
|
||||
case GlslVarType::U32:
|
||||
return var_u32;
|
||||
case GlslVarType::F32:
|
||||
return var_f32;
|
||||
case GlslVarType::U64:
|
||||
return var_u64;
|
||||
case GlslVarType::F64:
|
||||
return var_f64;
|
||||
case GlslVarType::U32x2:
|
||||
return var_u32x2;
|
||||
case GlslVarType::F32x2:
|
||||
return var_f32x2;
|
||||
case GlslVarType::U32x3:
|
||||
return var_u32x3;
|
||||
case GlslVarType::F32x3:
|
||||
return var_f32x3;
|
||||
case GlslVarType::U32x4:
|
||||
return var_u32x4;
|
||||
case GlslVarType::F32x4:
|
||||
return var_f32x4;
|
||||
case GlslVarType::PrecF32:
|
||||
return var_precf32;
|
||||
case GlslVarType::PrecF64:
|
||||
return var_precf64;
|
||||
default:
|
||||
throw NotImplementedException("Type {}", type);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Shader::Backend::GLSL
|
||||
104
gpu/third_party/suyu/shader_recompiler/backend/glsl/var_alloc.h
vendored
Normal file
104
gpu/third_party/suyu/shader_recompiler/backend/glsl/var_alloc.h
vendored
Normal file
@@ -0,0 +1,104 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <bitset>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "common/bit_field.h"
|
||||
#include "common/common_types.h"
|
||||
|
||||
namespace Shader::IR {
|
||||
class Inst;
|
||||
class Value;
|
||||
enum class Type;
|
||||
} // namespace Shader::IR
|
||||
|
||||
namespace Shader::Backend::GLSL {
|
||||
enum class GlslVarType : u32 {
|
||||
U1,
|
||||
F16x2,
|
||||
U32,
|
||||
F32,
|
||||
U64,
|
||||
F64,
|
||||
U32x2,
|
||||
F32x2,
|
||||
U32x3,
|
||||
F32x3,
|
||||
U32x4,
|
||||
F32x4,
|
||||
PrecF32,
|
||||
PrecF64,
|
||||
Void,
|
||||
};
|
||||
|
||||
struct Id {
|
||||
union {
|
||||
u32 raw;
|
||||
BitField<0, 1, u32> is_valid;
|
||||
BitField<1, 4, GlslVarType> type;
|
||||
BitField<6, 26, u32> index;
|
||||
};
|
||||
|
||||
bool operator==(Id rhs) const noexcept {
|
||||
return raw == rhs.raw;
|
||||
}
|
||||
bool operator!=(Id rhs) const noexcept {
|
||||
return !operator==(rhs);
|
||||
}
|
||||
};
|
||||
static_assert(sizeof(Id) == sizeof(u32));
|
||||
|
||||
class VarAlloc {
|
||||
public:
|
||||
struct UseTracker {
|
||||
bool uses_temp{};
|
||||
size_t num_used{};
|
||||
std::vector<bool> var_use;
|
||||
};
|
||||
|
||||
/// Used for explicit usages of variables, may revert to temporaries
|
||||
std::string Define(IR::Inst& inst, GlslVarType type);
|
||||
std::string Define(IR::Inst& inst, IR::Type type);
|
||||
|
||||
/// Used to assign variables used by the IR. May return a blank string if
|
||||
/// the instruction's result is unused in the IR.
|
||||
std::string AddDefine(IR::Inst& inst, GlslVarType type);
|
||||
std::string PhiDefine(IR::Inst& inst, IR::Type type);
|
||||
|
||||
std::string Consume(const IR::Value& value);
|
||||
std::string ConsumeInst(IR::Inst& inst);
|
||||
|
||||
std::string GetGlslType(GlslVarType type) const;
|
||||
std::string GetGlslType(IR::Type type) const;
|
||||
|
||||
const UseTracker& GetUseTracker(GlslVarType type) const;
|
||||
std::string Representation(u32 index, GlslVarType type) const;
|
||||
|
||||
private:
|
||||
GlslVarType RegType(IR::Type type) const;
|
||||
Id Alloc(GlslVarType type);
|
||||
void Free(Id id);
|
||||
UseTracker& GetUseTracker(GlslVarType type);
|
||||
std::string Representation(Id id) const;
|
||||
|
||||
UseTracker var_bool{};
|
||||
UseTracker var_f16x2{};
|
||||
UseTracker var_u32{};
|
||||
UseTracker var_u32x2{};
|
||||
UseTracker var_u32x3{};
|
||||
UseTracker var_u32x4{};
|
||||
UseTracker var_f32{};
|
||||
UseTracker var_f32x2{};
|
||||
UseTracker var_f32x3{};
|
||||
UseTracker var_f32x4{};
|
||||
UseTracker var_u64{};
|
||||
UseTracker var_f64{};
|
||||
UseTracker var_precf32{};
|
||||
UseTracker var_precf64{};
|
||||
};
|
||||
|
||||
} // namespace Shader::Backend::GLSL
|
||||
565
gpu/third_party/suyu/shader_recompiler/backend/wgsl/emit_wgsl.cpp
vendored
Normal file
565
gpu/third_party/suyu/shader_recompiler/backend/wgsl/emit_wgsl.cpp
vendored
Normal file
@@ -0,0 +1,565 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
#include <type_traits>
|
||||
|
||||
#include "common/div_ceil.h"
|
||||
#include "common/settings.h"
|
||||
#include "shader_recompiler/backend/wgsl/emit_wgsl.h"
|
||||
#include "shader_recompiler/backend/wgsl/emit_wgsl_instructions.h"
|
||||
#include "shader_recompiler/backend/wgsl/wgsl_emit_context.h"
|
||||
#include "shader_recompiler/frontend/ir/ir_emitter.h"
|
||||
|
||||
namespace Shader::Backend::WGSL {
|
||||
namespace {
|
||||
template <class Func>
|
||||
struct FuncTraits {};
|
||||
|
||||
template <class ReturnType_, class... Args>
|
||||
struct FuncTraits<ReturnType_ (*)(Args...)> {
|
||||
using ReturnType = ReturnType_;
|
||||
|
||||
static constexpr size_t NUM_ARGS = sizeof...(Args);
|
||||
|
||||
template <size_t I>
|
||||
using ArgType = std::tuple_element_t<I, std::tuple<Args...>>;
|
||||
};
|
||||
|
||||
template <auto func, typename... Args>
|
||||
void SetDefinition(EmitContext& ctx, IR::Inst* inst, Args... args) {
|
||||
inst->SetDefinition<Id>(func(ctx, std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
template <typename ArgType>
|
||||
auto Arg(EmitContext& ctx, const IR::Value& arg) {
|
||||
if constexpr (std::is_same_v<ArgType, std::string_view>) {
|
||||
return ctx.var_alloc.Consume(arg);
|
||||
} else if constexpr (std::is_same_v<ArgType, const IR::Value&>) {
|
||||
return arg;
|
||||
} else if constexpr (std::is_same_v<ArgType, u32>) {
|
||||
return arg.U32();
|
||||
} else if constexpr (std::is_same_v<ArgType, IR::Attribute>) {
|
||||
return arg.Attribute();
|
||||
} else if constexpr (std::is_same_v<ArgType, IR::Patch>) {
|
||||
return arg.Patch();
|
||||
} else if constexpr (std::is_same_v<ArgType, IR::Reg>) {
|
||||
return arg.Reg();
|
||||
}
|
||||
}
|
||||
|
||||
template <auto func, bool is_first_arg_inst, size_t... I>
|
||||
void Invoke(EmitContext& ctx, IR::Inst* inst, std::index_sequence<I...>) {
|
||||
using Traits = FuncTraits<decltype(func)>;
|
||||
constexpr size_t off = is_first_arg_inst ? 2 : 1;
|
||||
constexpr size_t N = sizeof...(I);
|
||||
// The operands are consumed last to first, in a defined order: Consume has side effects (a value's last use
|
||||
// releases its variable for reuse) and this backend was written and checked where function arguments are
|
||||
// evaluated right to left (the MSVC ABI). Compiled for wasm, which evaluates them left to right, comparisons
|
||||
// came out as "x > x" and constants changed. (A braced list is evaluated in order.)
|
||||
std::tuple<decltype(Arg<typename Traits::template ArgType<N - 1 - I + off>>(ctx, inst->Arg(N - 1 - I)))...> rev{
|
||||
Arg<typename Traits::template ArgType<N - 1 - I + off>>(ctx, inst->Arg(N - 1 - I))...};
|
||||
(void)rev;
|
||||
if constexpr (std::is_same_v<typename Traits::ReturnType, Id>) {
|
||||
if constexpr (is_first_arg_inst) {
|
||||
SetDefinition<func>(ctx, inst, *inst, std::get<N - 1 - I>(rev)...);
|
||||
} else {
|
||||
SetDefinition<func>(ctx, inst, std::get<N - 1 - I>(rev)...);
|
||||
}
|
||||
} else {
|
||||
if constexpr (is_first_arg_inst) {
|
||||
func(ctx, *inst, std::get<N - 1 - I>(rev)...);
|
||||
} else {
|
||||
func(ctx, std::get<N - 1 - I>(rev)...);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <auto func>
|
||||
void Invoke(EmitContext& ctx, IR::Inst* inst) {
|
||||
using Traits = FuncTraits<decltype(func)>;
|
||||
static_assert(Traits::NUM_ARGS >= 1, "Insufficient arguments");
|
||||
if constexpr (Traits::NUM_ARGS == 1) {
|
||||
Invoke<func, false>(ctx, inst, std::make_index_sequence<0>{});
|
||||
} else {
|
||||
using FirstArgType = typename Traits::template ArgType<1>;
|
||||
static constexpr bool is_first_arg_inst = std::is_same_v<FirstArgType, IR::Inst&>;
|
||||
using Indices = std::make_index_sequence<Traits::NUM_ARGS - (is_first_arg_inst ? 2 : 1)>;
|
||||
Invoke<func, is_first_arg_inst>(ctx, inst, Indices{});
|
||||
}
|
||||
}
|
||||
|
||||
void EmitInst(EmitContext& ctx, IR::Inst* inst) {
|
||||
switch (inst->GetOpcode()) {
|
||||
#define OPCODE(name, result_type, ...) \
|
||||
case IR::Opcode::name: \
|
||||
return Invoke<&Emit##name>(ctx, inst);
|
||||
#include "shader_recompiler/frontend/ir/opcodes.inc"
|
||||
#undef OPCODE
|
||||
}
|
||||
throw LogicError("Invalid opcode {}", inst->GetOpcode());
|
||||
}
|
||||
|
||||
bool IsReference(IR::Inst& inst) {
|
||||
return inst.GetOpcode() == IR::Opcode::Reference;
|
||||
}
|
||||
|
||||
void PrecolorInst(IR::Inst& phi) {
|
||||
// Insert phi moves before references to avoid overwriting other phis
|
||||
const size_t num_args{phi.NumArgs()};
|
||||
for (size_t i = 0; i < num_args; ++i) {
|
||||
IR::Block& phi_block{*phi.PhiBlock(i)};
|
||||
auto it{std::find_if_not(phi_block.rbegin(), phi_block.rend(), IsReference).base()};
|
||||
IR::IREmitter ir{phi_block, it};
|
||||
const IR::Value arg{phi.Arg(i)};
|
||||
if (arg.IsImmediate()) {
|
||||
ir.PhiMove(phi, arg);
|
||||
} else {
|
||||
ir.PhiMove(phi, IR::Value{arg.InstRecursive()});
|
||||
}
|
||||
}
|
||||
for (size_t i = 0; i < num_args; ++i) {
|
||||
IR::IREmitter{*phi.PhiBlock(i)}.Reference(IR::Value{&phi});
|
||||
}
|
||||
}
|
||||
|
||||
void Precolor(const IR::Program& program) {
|
||||
for (IR::Block* const block : program.blocks) {
|
||||
for (IR::Inst& phi : block->Instructions()) {
|
||||
if (!IR::IsPhi(phi)) {
|
||||
break;
|
||||
}
|
||||
PrecolorInst(phi);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EmitCode(EmitContext& ctx, const IR::Program& program) {
|
||||
for (const IR::AbstractSyntaxNode& node : program.syntax_list) {
|
||||
switch (node.type) {
|
||||
case IR::AbstractSyntaxNode::Type::Block:
|
||||
for (IR::Inst& inst : node.data.block->Instructions()) {
|
||||
EmitInst(ctx, &inst);
|
||||
}
|
||||
break;
|
||||
case IR::AbstractSyntaxNode::Type::If:
|
||||
ctx.Add("if ({}) {{", ctx.var_alloc.Consume(node.data.if_node.cond));
|
||||
break;
|
||||
case IR::AbstractSyntaxNode::Type::EndIf:
|
||||
ctx.Add("}}");
|
||||
break;
|
||||
case IR::AbstractSyntaxNode::Type::Break:
|
||||
if (node.data.break_node.cond.IsImmediate()) {
|
||||
if (node.data.break_node.cond.U1()) {
|
||||
ctx.Add("break;");
|
||||
}
|
||||
} else {
|
||||
ctx.Add("if ({}) {{ break; }}", ctx.var_alloc.Consume(node.data.break_node.cond));
|
||||
}
|
||||
break;
|
||||
case IR::AbstractSyntaxNode::Type::Return:
|
||||
case IR::AbstractSyntaxNode::Type::Unreachable:
|
||||
ctx.Add("return;");
|
||||
break;
|
||||
case IR::AbstractSyntaxNode::Type::Loop:
|
||||
ctx.Add("loop {{");
|
||||
break;
|
||||
case IR::AbstractSyntaxNode::Type::Repeat:
|
||||
if (Settings::values.disable_shader_loop_safety_checks) {
|
||||
ctx.Add("if (!{}) {{ break; }} }}", ctx.var_alloc.Consume(node.data.repeat.cond));
|
||||
} else {
|
||||
const u32 n{ctx.num_safety_loop_vars++};
|
||||
ctx.Add("loop{} = loop{} - 1; if (loop{} < 0 || !{}) {{ break; }} }}", n, n, n,
|
||||
ctx.var_alloc.Consume(node.data.repeat.cond));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw NotImplementedException("AbstractSyntaxNode Type {}", node.type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DefineVariables(const EmitContext& ctx, std::string& header) {
|
||||
for (u32 i = 0; i < static_cast<u32>(WgslVarType::Void); ++i) {
|
||||
const auto type{static_cast<WgslVarType>(i)};
|
||||
const auto& tracker{ctx.var_alloc.GetUseTracker(type)};
|
||||
if (!tracker.uses_temp && tracker.num_used == 0) {
|
||||
continue;
|
||||
}
|
||||
const auto type_name{ctx.var_alloc.GetWgslType(type)};
|
||||
// Temps/return types that are never used are stored at index 0
|
||||
if (tracker.uses_temp) {
|
||||
header += fmt::format("var t{}: {};\n", ctx.var_alloc.Representation(0, type), type_name);
|
||||
}
|
||||
for (u32 index = 0; index < tracker.num_used; ++index) {
|
||||
header += fmt::format("var {}: {};\n", ctx.var_alloc.Representation(index, type), type_name);
|
||||
}
|
||||
}
|
||||
for (u32 i = 0; i < ctx.num_safety_loop_vars; ++i) {
|
||||
header += fmt::format("var loop{}: i32 = 0x2000;\n", i);
|
||||
}
|
||||
}
|
||||
|
||||
std::string_view AttributeTypeName(AttributeType type) {
|
||||
switch (type) {
|
||||
case AttributeType::SignedInt:
|
||||
case AttributeType::SignedScaled:
|
||||
return "vec4<i32>";
|
||||
case AttributeType::UnsignedInt:
|
||||
case AttributeType::UnsignedScaled:
|
||||
return "vec4<u32>";
|
||||
default:
|
||||
return "vec4<f32>";
|
||||
}
|
||||
}
|
||||
|
||||
bool IsIntegerAttribute(AttributeType type) {
|
||||
return type == AttributeType::SignedInt || type == AttributeType::UnsignedInt;
|
||||
}
|
||||
|
||||
std::string_view InterpolationAttribute(Interpolation interp) {
|
||||
switch (interp) {
|
||||
case Interpolation::Flat:
|
||||
return "@interpolate(flat) ";
|
||||
case Interpolation::NoPerspective:
|
||||
return "@interpolate(linear) ";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/// A pulled vertex attribute (Options::VertexPull): its bytes read from the stream's storage binding and converted
|
||||
/// as the vertex fetch would (Maxwell's attribute format word: offset 7-20, size 21-26, type 27-29, bgra 31).
|
||||
std::string PulledAttribute(const EmitContext& ctx, size_t i, const Options::VertexPull& p) {
|
||||
const u32 a{p.attribute}, offset{(a >> 7) & 0x3fff}, size{(a >> 21) & 0x3f}, type{(a >> 27) & 7};
|
||||
const bool bgra{(a >> 31) != 0};
|
||||
int bits[4]{};
|
||||
switch (size) {
|
||||
case 0x01: bits[0] = bits[1] = bits[2] = bits[3] = 32; break;
|
||||
case 0x02: bits[0] = bits[1] = bits[2] = 32; break;
|
||||
case 0x03: bits[0] = bits[1] = bits[2] = bits[3] = 16; break;
|
||||
case 0x04: bits[0] = bits[1] = 32; break;
|
||||
case 0x05: bits[0] = bits[1] = bits[2] = 16; break;
|
||||
case 0x0A: case 0x33: bits[0] = bits[1] = bits[2] = bits[3] = 8; break;
|
||||
case 0x0F: bits[0] = bits[1] = 16; break;
|
||||
case 0x12: bits[0] = 32; break;
|
||||
case 0x13: bits[0] = bits[1] = bits[2] = 8; break;
|
||||
case 0x18: case 0x32: bits[0] = bits[1] = 8; break;
|
||||
case 0x1B: bits[0] = 16; break;
|
||||
case 0x1D: case 0x34: bits[0] = 8; break;
|
||||
default: break; // packed (0x30, 0x31): below
|
||||
}
|
||||
const char k{"xyz"[p.stream % 3]};
|
||||
const auto element{p.instanced ? std::string{"(input.instance_index + vs_pull.w)"}
|
||||
: std::string{"u32(i32(input.vertex_index) + bitcast<i32>(rescale_(3u).z))"}};
|
||||
const auto base{fmt::format("(vs_pull.{} + {} * {}u + {}u)", k, element, p.stride, offset)};
|
||||
const bool integer{type == 3 || type == 4}, scaled{type == 5 || type == 6};
|
||||
const bool is_signed{type == 1 || type == 3 || type == 6};
|
||||
std::string out{fmt::format(" {{\n let o = {};\n", base)};
|
||||
std::string comps[4];
|
||||
if (size == 0x30 || size == 0x31) {
|
||||
out += fmt::format(" let w = vb{}_32(o);\n", p.stream);
|
||||
if (size == 0x31) {
|
||||
out += fmt::format(" in_attr{} = vec4<f32>(uf11_(w & 0x7ffu), uf11_((w >> 11u) & 0x7ffu), uf10_(w >> 22u), 1.0);\n }}\n", i);
|
||||
return out;
|
||||
}
|
||||
const char* u{"vec4<u32>(w & 0x3ffu, (w >> 10u) & 0x3ffu, (w >> 20u) & 0x3ffu, w >> 30u)"};
|
||||
const char* s{"vec4<i32>(i32(w << 22u) >> 22u, i32(w << 12u) >> 22u, i32(w << 2u) >> 22u, i32(w) >> 30u)"};
|
||||
std::string v;
|
||||
switch (type) {
|
||||
case 1: v = fmt::format("max(vec4<f32>({}) / vec4<f32>(511.0, 511.0, 511.0, 1.0), vec4<f32>(-1.0))", s); break;
|
||||
case 2: v = fmt::format("vec4<f32>({}) / vec4<f32>(1023.0, 1023.0, 1023.0, 3.0)", u); break;
|
||||
case 3: v = fmt::format("bitcast<vec4<f32>>({})", s); break;
|
||||
case 4: v = fmt::format("bitcast<vec4<f32>>({})", u); break;
|
||||
case 5: v = fmt::format("vec4<f32>({})", u); break;
|
||||
case 6: v = fmt::format("vec4<f32>({})", s); break;
|
||||
default: v = "vec4<f32>(0.0, 0.0, 0.0, 1.0)"; break;
|
||||
}
|
||||
out += fmt::format(" in_attr{} = {};\n }}\n", i, v);
|
||||
return out;
|
||||
}
|
||||
u32 at{0};
|
||||
for (int c = 0; c < 4; ++c) {
|
||||
if (!bits[c]) {
|
||||
comps[c] = integer ? (c == 3 ? "1u" : "0u") : (c == 3 ? "1.0" : "0.0");
|
||||
continue;
|
||||
}
|
||||
const int n{bits[c]};
|
||||
const auto raw{fmt::format("vb{}_{}(o + {}u)", p.stream, n, at)};
|
||||
at += n / 8;
|
||||
const auto sext{n == 32 ? fmt::format("i32({})", raw)
|
||||
: fmt::format("(i32({} << {}u) >> {}u)", raw, 32 - n, 32 - n)};
|
||||
if (integer) {
|
||||
comps[c] = is_signed ? fmt::format("u32({})", sext) : raw;
|
||||
} else if (scaled) {
|
||||
comps[c] = is_signed ? fmt::format("f32({})", sext) : fmt::format("f32({})", raw);
|
||||
} else if (type == 7) { // float
|
||||
comps[c] = n == 32 ? fmt::format("bitcast<f32>({})", raw)
|
||||
: n == 16 ? fmt::format("unpack2x16float({}).x", raw)
|
||||
: fmt::format("f32({})", raw);
|
||||
} else if (type == 2) { // unorm
|
||||
comps[c] = fmt::format("(f32({}) / {}.0)", raw, n == 32 ? 4294967295.0 : (double)((1u << n) - 1));
|
||||
} else { // snorm
|
||||
comps[c] = fmt::format("max(f32({}) / {}.0, -1.0)", sext, (1u << (n - 1)) - 1);
|
||||
}
|
||||
}
|
||||
if (bgra) std::swap(comps[0], comps[2]);
|
||||
if (size == 0x32) std::swap(comps[0], comps[1]);
|
||||
out += integer ? fmt::format(" in_attr{} = bitcast<vec4<f32>>(vec4<u32>({}, {}, {}, {}));\n }}\n", i, comps[0],
|
||||
comps[1], comps[2], comps[3])
|
||||
: fmt::format(" in_attr{} = vec4<f32>({}, {}, {}, {});\n }}\n", i, comps[0], comps[1], comps[2],
|
||||
comps[3]);
|
||||
return out;
|
||||
}
|
||||
|
||||
/// The WGSL entry point: copies the stage's inputs into the private variables the body reads, runs it, and returns
|
||||
/// the private variables it wrote as the stage's outputs.
|
||||
std::string EntryPoint(const EmitContext& ctx, const IR::Program& program, const Options& options) {
|
||||
const Info& info{ctx.info};
|
||||
std::string out;
|
||||
switch (ctx.stage) {
|
||||
case Stage::VertexA:
|
||||
case Stage::VertexB: {
|
||||
out += "struct VsIn {\n @builtin(vertex_index) vertex_index: u32,\n"
|
||||
" @builtin(instance_index) instance_index: u32,\n";
|
||||
for (size_t i = 0; i < IR::NUM_GENERICS; ++i) {
|
||||
if (info.loads.Generic(i) && !options.vertex_pull[i].enabled) {
|
||||
out += fmt::format(" @location({}) a{}: {},\n", i, i,
|
||||
options.vertex_unpack[i] != VertexUnpack::None
|
||||
? std::string_view{"u32"}
|
||||
: AttributeTypeName(ctx.runtime_info.generic_input_types[i]));
|
||||
}
|
||||
}
|
||||
out += "};\nstruct VsOut {\n @builtin(position) position: vec4<f32>,\n";
|
||||
for (size_t i = 0; i < IR::NUM_GENERICS; ++i) {
|
||||
if (info.stores.Generic(i)) {
|
||||
out += fmt::format(" @location({}) {}o{}: vec4<f32>,\n", i,
|
||||
InterpolationAttribute(options.output_interpolation[i]), i);
|
||||
}
|
||||
}
|
||||
// unsigned 11/10-bit floats (5-bit exponent, no sign)
|
||||
out += "};\nfn uf11_(v: u32) -> f32 { let e = v >> 6u; let m = f32(v & 63u);"
|
||||
" if (e == 0u) { return m * exp2(-20.0); } if (e == 31u) { return 65504.0; }"
|
||||
" return (1.0 + m / 64.0) * exp2(f32(e) - 15.0); }\n"
|
||||
"fn uf10_(v: u32) -> f32 { let e = v >> 5u; let m = f32(v & 31u);"
|
||||
" if (e == 0u) { return m * exp2(-19.0); } if (e == 31u) { return 65504.0; }"
|
||||
" return (1.0 + m / 32.0) * exp2(f32(e) - 15.0); }\n"
|
||||
"@vertex\nfn main(input: VsIn) -> VsOut {\n"
|
||||
" gl_VertexID = i32(input.vertex_index) + bitcast<i32>(rescale_(3u).z);\n"
|
||||
" gl_InstanceID = i32(input.instance_index) + bitcast<i32>(rescale_(3u).w);\n";
|
||||
for (size_t i = 0; i < IR::NUM_GENERICS; ++i) {
|
||||
if (info.loads.Generic(i) && options.vertex_pull[i].enabled) {
|
||||
out += PulledAttribute(ctx, i, options.vertex_pull[i]);
|
||||
} else if (info.loads.Generic(i) && options.vertex_unpack[i] != VertexUnpack::None) {
|
||||
// fields of a packed word: x = bits 0-9, y 10-19, z 20-29, w 30-31 (10/11-bit floats: 0-10,
|
||||
// 11-21, 22-31)
|
||||
const auto v{fmt::format("input.a{}", i)};
|
||||
const auto u{fmt::format("vec4<u32>({0}&0x3ffu,({0}>>10u)&0x3ffu,({0}>>20u)&0x3ffu,{0}>>30u)", v)};
|
||||
const auto s{fmt::format("vec4<i32>(i32({0}<<22u)>>22u,i32({0}<<12u)>>22u,i32({0}<<2u)>>22u,"
|
||||
"i32({0})>>30u)", v)};
|
||||
std::string value;
|
||||
switch (options.vertex_unpack[i]) {
|
||||
case VertexUnpack::A2B10G10R10_SNORM:
|
||||
value = fmt::format("max(vec4<f32>({})/vec4<f32>(511.0,511.0,511.0,1.0),vec4<f32>(-1.0))", s);
|
||||
break;
|
||||
case VertexUnpack::A2B10G10R10_UINT:
|
||||
value = fmt::format("bitcast<vec4<f32>>({})", u);
|
||||
break;
|
||||
case VertexUnpack::A2B10G10R10_SINT:
|
||||
value = fmt::format("bitcast<vec4<f32>>({})", s);
|
||||
break;
|
||||
case VertexUnpack::A2B10G10R10_USCALED:
|
||||
value = fmt::format("vec4<f32>({})", u);
|
||||
break;
|
||||
case VertexUnpack::A2B10G10R10_SSCALED:
|
||||
value = fmt::format("vec4<f32>({})", s);
|
||||
break;
|
||||
case VertexUnpack::B10G11R11_FLOAT:
|
||||
value = fmt::format("vec4<f32>(uf11_({0}&0x7ffu),uf11_(({0}>>11u)&0x7ffu),uf10_({0}>>22u),1.0)", v);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
out += fmt::format(" in_attr{} = {};\n", i, value);
|
||||
} else if (info.loads.Generic(i)) {
|
||||
const AttributeType type{ctx.runtime_info.generic_input_types[i]};
|
||||
out += IsIntegerAttribute(type) ? fmt::format(" in_attr{} = bitcast<vec4<f32>>(input.a{});\n", i, i)
|
||||
: type == AttributeType::SignedScaled || type == AttributeType::UnsignedScaled
|
||||
? fmt::format(" in_attr{} = vec4<f32>(input.a{});\n", i, i)
|
||||
: fmt::format(" in_attr{} = input.a{};\n", i, i);
|
||||
}
|
||||
}
|
||||
out += " gl_Position = vec4<f32>(0.0f, 0.0f, 0.0f, 1.0f);\n shader_main();\n var output: VsOut;\n"
|
||||
" let p = gl_Position;\n let t = rescale_(2u);\n let z = rescale_(3u);\n"
|
||||
" output.position = vec4<f32>(t.x * p.x + t.y * p.w, t.z * p.y + t.w * p.w, z.x * p.z + z.y * p.w,"
|
||||
" p.w);\n"
|
||||
// a 16-bit depth target: the depth on its step, as pixel shaders write it (d16q_); vertices outside
|
||||
// the depth range keep theirs (the visible part of the primitive keeps its slope)
|
||||
" if (render_area().z != 0.0f && p.w > 0.0f) {\n"
|
||||
" let d = output.position.z / p.w;\n"
|
||||
" if (d >= 0.0f && d <= 1.0f) { output.position.z = d16q_(d) * p.w; }\n"
|
||||
" }\n";
|
||||
// RX_DEBUG_VS_NONFINITE=1 (debugging): a position with an infinite or NaN component goes to the screen's
|
||||
// centre; =2: all of it NaN (a bit test: compilers may fold x != x)
|
||||
if (static const char* nonfinite = std::getenv("RX_DEBUG_VS_NONFINITE"); nonfinite)
|
||||
out += fmt::format(" if (any((bitcast<vec4<u32>>(p) & vec4<u32>(0x7f800000u)) == vec4<u32>(0x7f800000u))) {{"
|
||||
" output.position = {}; }}\n",
|
||||
*nonfinite == '2' ? "bitcast<vec4<f32>>(vec4<u32>(0x7fc00000u))"
|
||||
: "vec4<f32>(0.0f, 0.0f, 0.5f, 1.0f)");
|
||||
for (size_t i = 0; i < IR::NUM_GENERICS; ++i) {
|
||||
if (info.stores.Generic(i)) {
|
||||
out += fmt::format(" output.o{} = out_attr{};\n", i, i);
|
||||
}
|
||||
}
|
||||
out += " return output;\n}\n";
|
||||
if (ctx.vs_compute) { // (vs_as_compute_next: the same body as a compute entry, outputs dropped)
|
||||
const auto swap = [&out](std::string_view from, std::string_view to) {
|
||||
const size_t at{out.find(from)};
|
||||
if (at == std::string::npos) throw NotImplementedException("vertex program as compute: {}", from);
|
||||
out.replace(at, from.size(), to);
|
||||
};
|
||||
if (out.find("@location(", 0) < out.find("};\nstruct VsOut")) {
|
||||
throw NotImplementedException("vertex program as compute: attributes not pulled");
|
||||
}
|
||||
swap("struct VsIn {\n @builtin(vertex_index) vertex_index: u32,\n"
|
||||
" @builtin(instance_index) instance_index: u32,\n",
|
||||
"struct VsIn {\n vertex_index: u32,\n instance_index: u32,\n");
|
||||
swap("@vertex\nfn main(input: VsIn) -> VsOut {\n",
|
||||
"@compute @workgroup_size(1)\nfn main(@builtin(global_invocation_id) gid_: vec3<u32>) {\n"
|
||||
" let input = VsIn(gid_.x, gid_.y);\n");
|
||||
swap(" return output;\n}\n", "}\n");
|
||||
}
|
||||
break;
|
||||
}
|
||||
case Stage::Fragment: {
|
||||
out += "struct FsIn {\n @builtin(position) frag_coord: vec4<f32>,\n"
|
||||
" @builtin(front_facing) front_facing: bool,\n";
|
||||
if (info.uses_sample_id) {
|
||||
out += " @builtin(sample_index) sample_index: u32,\n";
|
||||
}
|
||||
for (size_t i = 0; i < IR::NUM_GENERICS; ++i) {
|
||||
if (info.loads.Generic(i) && ctx.runtime_info.previous_stage_stores.Generic(i)) {
|
||||
out += fmt::format(" @location({}) {}a{}: vec4<f32>,\n", i,
|
||||
InterpolationAttribute(info.interpolation[i]), i);
|
||||
}
|
||||
}
|
||||
out += "};\n";
|
||||
bool any_output{info.stores_frag_depth};
|
||||
std::string outs{"struct FsOut {\n"};
|
||||
for (size_t i = 0; i < info.stores_frag_color.size(); ++i) {
|
||||
if (info.stores_frag_color[i]) {
|
||||
outs += fmt::format(" @location({}) c{}: {},\n", i, i,
|
||||
AttributeTypeName(ctx.runtime_info.color_output_types[i]));
|
||||
any_output = true;
|
||||
}
|
||||
}
|
||||
if (info.stores_frag_depth) {
|
||||
outs += " @builtin(frag_depth) depth: f32,\n";
|
||||
}
|
||||
outs += "};\n";
|
||||
if (any_output) {
|
||||
out += outs;
|
||||
}
|
||||
// (force_early_z: depth and stencil tests before the shader runs, so the fragments they reject make no stores:
|
||||
// the GPU's early-Z for a program that asks for it)
|
||||
const char* early = "";
|
||||
if (ctx.runtime_info.force_early_z && !info.stores_frag_depth) {
|
||||
static const char* attr = getenv("RX_EARLY_Z_ATTR") ? getenv("RX_EARLY_Z_ATTR") : "@early_depth_test(force)";
|
||||
early = attr;
|
||||
}
|
||||
out += fmt::format("@fragment {}\nfn main(input: FsIn){} {{\n", early, any_output ? " -> FsOut" : "");
|
||||
out += " gl_FragCoord = input.frag_coord;\n gl_FrontFacing = input.front_facing;\n";
|
||||
if (info.uses_sample_id) {
|
||||
out += " gl_SampleID = i32(input.sample_index);\n";
|
||||
}
|
||||
for (size_t i = 0; i < IR::NUM_GENERICS; ++i) {
|
||||
if (info.loads.Generic(i) && ctx.runtime_info.previous_stage_stores.Generic(i)) {
|
||||
out += fmt::format(" in_attr{} = input.a{};\n", i, i);
|
||||
}
|
||||
}
|
||||
out += " gl_FragDepth = input.frag_coord.z;\n shader_main();\n";
|
||||
if (any_output) {
|
||||
out += " var output: FsOut;\n";
|
||||
// render_area().w: bit i = colour target i has a UNORM format kept as float (16-bit UNORM targets
|
||||
// cannot be render attachments in WebGPU), bit 8 + i the same for SNORM: clamped as the hardware's
|
||||
// store would
|
||||
out += " let ntc_ = u32(render_area().w);\n";
|
||||
for (size_t i = 0; i < info.stores_frag_color.size(); ++i) {
|
||||
if (info.stores_frag_color[i]) {
|
||||
const auto type{ctx.runtime_info.color_output_types[i]};
|
||||
out += IsIntegerAttribute(type)
|
||||
? fmt::format(" output.c{} = bitcast<{}>(frag_color{});\n", i, AttributeTypeName(type), i)
|
||||
: fmt::format(" output.c{0} = frag_color{0};\n"
|
||||
" if ((ntc_ & {1}u) != 0u) {{ output.c{0} = clamp(output.c{0}, vec4<f32>(0.0), vec4<f32>(1.0)); }}\n"
|
||||
" if ((ntc_ & {2}u) != 0u) {{ output.c{0} = clamp(output.c{0}, vec4<f32>(-1.0), vec4<f32>(1.0)); }}\n",
|
||||
i, 1u << i, 0x100u << i);
|
||||
}
|
||||
}
|
||||
if (info.stores_frag_depth) {
|
||||
out += " output.depth = select(gl_FragDepth, d16q_(gl_FragDepth), render_area().z != 0.0f);\n";
|
||||
}
|
||||
out += " return output;\n";
|
||||
}
|
||||
out += "}\n";
|
||||
break;
|
||||
}
|
||||
case Stage::Compute:
|
||||
out += fmt::format("@compute @workgroup_size({}, {}, {})\n"
|
||||
"fn main(@builtin(local_invocation_id) lid: vec3<u32>, "
|
||||
"@builtin(workgroup_id) wid: vec3<u32>) {{\n"
|
||||
" gl_LocalInvocationID = lid;\n gl_WorkGroupID = wid;\n shader_main();\n}}\n",
|
||||
(std::max)(program.workgroup_size[0], 1u), (std::max)(program.workgroup_size[1], 1u),
|
||||
(std::max)(program.workgroup_size[2], 1u));
|
||||
break;
|
||||
default:
|
||||
throw NotImplementedException("WebGPU has no {} shaders", ctx.stage);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
} // Anonymous namespace
|
||||
|
||||
std::string EmitWGSL(const Profile& profile, const RuntimeInfo& runtime_info, IR::Program& program,
|
||||
Bindings& bindings, const Options& options) {
|
||||
EmitContext ctx{program, bindings, profile, runtime_info};
|
||||
u32 pulled_streams{0};
|
||||
for (const auto& p : options.vertex_pull) {
|
||||
if (p.enabled) {
|
||||
pulled_streams = (std::max)(pulled_streams, static_cast<u32>(p.stream) + 1);
|
||||
}
|
||||
}
|
||||
if (pulled_streams > 0 && (program.stage == Stage::VertexA || program.stage == Stage::VertexB)) {
|
||||
ctx.header += fmt::format("@group({}) @binding({}) var<uniform> vs_pull: vec4<u32>;\n", ctx.group,
|
||||
bindings.unified++);
|
||||
for (u32 k = 0; k < pulled_streams; ++k) {
|
||||
ctx.header += fmt::format(
|
||||
"@group({0}) @binding({1}) var<storage, read> vs_vb{2}: array<u32>;\n"
|
||||
"fn vb{2}_8(o: u32) -> u32 {{ return (vs_vb{2}[o >> 2u] >> ((o & 3u) * 8u)) & 0xffu; }}\n"
|
||||
"fn vb{2}_16(o: u32) -> u32 {{ return vb{2}_8(o) | (vb{2}_8(o + 1u) << 8u); }}\n"
|
||||
"fn vb{2}_32(o: u32) -> u32 {{ return vb{2}_16(o) | (vb{2}_16(o + 2u) << 16u); }}\n",
|
||||
ctx.group, bindings.unified++, k);
|
||||
}
|
||||
}
|
||||
Precolor(program);
|
||||
EmitCode(ctx, program);
|
||||
if (program.shared_memory_size > 0) {
|
||||
ctx.header += fmt::format("var<workgroup> smem: array<{}, {}>;\n", ctx.atomic_smem ? "atomic<u32>" : "u32",
|
||||
Common::DivCeil(program.shared_memory_size, 4U));
|
||||
}
|
||||
std::string body{"fn shader_main() {\n"};
|
||||
if (program.local_memory_size > 0) {
|
||||
body += fmt::format("var lmem: array<u32, {}>;\n", Common::DivCeil(program.local_memory_size, 4U));
|
||||
}
|
||||
DefineVariables(ctx, body);
|
||||
if (ctx.uses_cc_carry) {
|
||||
body += "var carry: u32;\n";
|
||||
}
|
||||
if (program.info.uses_subgroup_shuffles) {
|
||||
body += "var shfl_in_bounds: bool;\nvar shfl_result: u32;\n";
|
||||
}
|
||||
return ctx.header + body + ctx.code + "}\n" + EntryPoint(ctx, program, options);
|
||||
}
|
||||
|
||||
} // namespace Shader::Backend::WGSL
|
||||
76
gpu/third_party/suyu/shader_recompiler/backend/wgsl/emit_wgsl.h
vendored
Normal file
76
gpu/third_party/suyu/shader_recompiler/backend/wgsl/emit_wgsl.h
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
//
|
||||
// WGSL backend (Rexcomp): one stage of a WebGPU pipeline as a WGSL module with a `main` entry point.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <string>
|
||||
|
||||
#include "shader_recompiler/backend/bindings.h"
|
||||
#include "shader_recompiler/frontend/ir/program.h"
|
||||
#include "shader_recompiler/profile.h"
|
||||
#include "shader_recompiler/runtime_info.h"
|
||||
#include "shader_recompiler/shader_info.h"
|
||||
|
||||
namespace Shader::Backend::WGSL {
|
||||
|
||||
/// Vertex attributes in formats WebGPU's vertex fetch lacks: read as one u32 and unpacked in the vertex stage.
|
||||
enum class VertexUnpack : u8 {
|
||||
None,
|
||||
A2B10G10R10_SNORM,
|
||||
A2B10G10R10_UINT, ///< (the generic is an unsigned integer)
|
||||
A2B10G10R10_SINT, ///< (signed integer)
|
||||
A2B10G10R10_USCALED, ///< (floats of the unsigned values)
|
||||
A2B10G10R10_SSCALED, ///< (floats of the signed values)
|
||||
B10G11R11_FLOAT,
|
||||
};
|
||||
|
||||
/// What one stage needs to know about its neighbours in the pipeline.
|
||||
struct Options {
|
||||
/// Vertex stages: the interpolation the fragment stage declares for each generic (WebGPU requires both sides
|
||||
/// of a location to agree).
|
||||
std::array<Interpolation, 32> output_interpolation{};
|
||||
/// Vertex stages: attributes fetched packed (see VertexUnpack).
|
||||
std::array<VertexUnpack, 32> vertex_unpack{};
|
||||
/// Vertex stages: attributes the vertex stage reads from memory itself ("vertex pulling": layouts WebGPU's vertex
|
||||
/// fetch cannot describe, like strides that are not multiples of 4). Each names one of up to 3 pulled streams,
|
||||
/// bound after every other resource as `var<storage, read> vs_vb<k>: array<u32>`, preceded by
|
||||
/// `var<uniform> vs_pull: vec4<u32>` (x, y, z: where stream 0, 1, 2 starts in its binding, in bytes; w: added to
|
||||
/// the instance index of instanced streams).
|
||||
struct VertexPull {
|
||||
bool enabled{};
|
||||
u8 stream{};
|
||||
bool instanced{};
|
||||
u32 attribute{}; ///< the Maxwell attribute format word (offset, size, type, bgra)
|
||||
u32 stride{};
|
||||
};
|
||||
std::array<VertexPull, 32> vertex_pull{};
|
||||
};
|
||||
|
||||
/// Storage buffers bound to one same range (the browser forbids two writable bindings of one range): for the next
|
||||
/// EmitWGSL on this thread, ssbo_alias_next[j] = i + 1 makes descriptor j use descriptor i's binding (j is not
|
||||
/// declared). Reset by the emission.
|
||||
extern thread_local std::array<u8, 64> ssbo_alias_next;
|
||||
/// ...and where descriptor j's data starts in descriptor i's binding, in words (overlapping ranges merged into one)
|
||||
extern thread_local std::array<u32, 64> ssbo_alias_words_next;
|
||||
/// For the next EmitWGSL of a vertex program on this thread: emit it as a compute program instead (one invocation per
|
||||
/// vertex: x the vertex index, y the instance), with its storage writes, which WebGPU's vertex stage cannot make
|
||||
/// (TOTK's Ultrahand reads the object under the reticle in a one-point draw whose vertex program stores it). Its outputs
|
||||
/// are dropped. Only for vertex programs whose attributes are all pulled (vertex_pull) or none. Reset by the emission.
|
||||
extern thread_local bool vs_as_compute_next;
|
||||
/// (mkw-recomp) The storage texture format of each image descriptor (WGSL's name: "rgba16float"...) for the next
|
||||
/// EmitWGSL on this thread: a formatted image store or load takes its format from the bound image, which WGSL must
|
||||
/// declare. Empty: the descriptor's own (typeless: r32uint). Reset by the emission.
|
||||
extern thread_local std::array<std::string, 16> image_formats_next;
|
||||
|
||||
[[nodiscard]] std::string EmitWGSL(const Profile& profile, const RuntimeInfo& runtime_info,
|
||||
IR::Program& program, Bindings& bindings, const Options& options = {});
|
||||
|
||||
[[nodiscard]] inline std::string EmitWGSL(const Profile& profile, IR::Program& program) {
|
||||
Bindings binding;
|
||||
return EmitWGSL(profile, {}, program, binding);
|
||||
}
|
||||
|
||||
} // namespace Shader::Backend::WGSL
|
||||
449
gpu/third_party/suyu/shader_recompiler/backend/wgsl/emit_wgsl_atomic.cpp
vendored
Normal file
449
gpu/third_party/suyu/shader_recompiler/backend/wgsl/emit_wgsl_atomic.cpp
vendored
Normal file
@@ -0,0 +1,449 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <string_view>
|
||||
|
||||
#include "shader_recompiler/backend/wgsl/emit_wgsl_instructions.h"
|
||||
#include "shader_recompiler/backend/wgsl/wgsl_emit_context.h"
|
||||
#include "shader_recompiler/frontend/ir/value.h"
|
||||
|
||||
namespace Shader::Backend::WGSL {
|
||||
namespace {
|
||||
// WGSL atomics on atomic<u32> memory (EmitContext::atomic_ssbo / atomic_smem). The result is assigned after the
|
||||
// operation, as it may share a variable with an operand.
|
||||
void Native(EmitContext& ctx, IR::Inst& inst, std::string_view ptr, std::string_view function,
|
||||
std::string_view value) {
|
||||
const std::string op{fmt::format("{}({},{})", function, ptr, value)};
|
||||
const auto ret{ctx.var_alloc.Define(inst, WgslVarType::U32)};
|
||||
ctx.Add("{}={};", ret, op);
|
||||
}
|
||||
|
||||
/// An operation WGSL has no atomic for: a compare-exchange loop over function(old, value) -> new.
|
||||
void CasLoop(EmitContext& ctx, IR::Inst& inst, std::string_view ptr, std::string_view function,
|
||||
std::string_view value) {
|
||||
const std::string p{ptr}, v{value};
|
||||
const auto ret{ctx.var_alloc.Define(inst, WgslVarType::U32)};
|
||||
ctx.Add("loop {{let old_=atomicLoad({});let r_=atomicCompareExchangeWeak({},old_,{}(old_,{}));"
|
||||
"if (r_.exchanged) {{{}=old_;break;}}}}",
|
||||
p, p, function, v, ret);
|
||||
}
|
||||
|
||||
std::string Smem(EmitContext&, std::string_view offset) {
|
||||
return fmt::format("&smem[{}>>2]", offset);
|
||||
}
|
||||
|
||||
std::string Ssbo(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset) {
|
||||
return ctx.SsboPtr(binding.U32(), fmt::format("{}>>2", ctx.var_alloc.Consume(offset)));
|
||||
}
|
||||
} // Anonymous namespace
|
||||
|
||||
void EmitSharedAtomicIAdd32(EmitContext& ctx, IR::Inst& inst, std::string_view pointer_offset,
|
||||
std::string_view value) {
|
||||
Native(ctx, inst, Smem(ctx, pointer_offset), "atomicAdd", value);
|
||||
}
|
||||
|
||||
void EmitSharedAtomicSMin32(EmitContext& ctx, IR::Inst& inst, std::string_view pointer_offset,
|
||||
std::string_view value) {
|
||||
CasLoop(ctx, inst, Smem(ctx, pointer_offset), "CasMinS32", fmt::format("u32({})", value));
|
||||
}
|
||||
|
||||
void EmitSharedAtomicUMin32(EmitContext& ctx, IR::Inst& inst, std::string_view pointer_offset,
|
||||
std::string_view value) {
|
||||
Native(ctx, inst, Smem(ctx, pointer_offset), "atomicMin", value);
|
||||
}
|
||||
|
||||
void EmitSharedAtomicSMax32(EmitContext& ctx, IR::Inst& inst, std::string_view pointer_offset,
|
||||
std::string_view value) {
|
||||
CasLoop(ctx, inst, Smem(ctx, pointer_offset), "CasMaxS32", fmt::format("u32({})", value));
|
||||
}
|
||||
|
||||
void EmitSharedAtomicUMax32(EmitContext& ctx, IR::Inst& inst, std::string_view pointer_offset,
|
||||
std::string_view value) {
|
||||
Native(ctx, inst, Smem(ctx, pointer_offset), "atomicMax", value);
|
||||
}
|
||||
|
||||
void EmitSharedAtomicInc32(EmitContext& ctx, IR::Inst& inst, std::string_view pointer_offset,
|
||||
std::string_view value) {
|
||||
CasLoop(ctx, inst, Smem(ctx, pointer_offset), "CasIncrement", value);
|
||||
}
|
||||
|
||||
void EmitSharedAtomicDec32(EmitContext& ctx, IR::Inst& inst, std::string_view pointer_offset,
|
||||
std::string_view value) {
|
||||
CasLoop(ctx, inst, Smem(ctx, pointer_offset), "CasDecrement", value);
|
||||
}
|
||||
|
||||
void EmitSharedAtomicAnd32(EmitContext& ctx, IR::Inst& inst, std::string_view pointer_offset,
|
||||
std::string_view value) {
|
||||
Native(ctx, inst, Smem(ctx, pointer_offset), "atomicAnd", value);
|
||||
}
|
||||
|
||||
void EmitSharedAtomicOr32(EmitContext& ctx, IR::Inst& inst, std::string_view pointer_offset,
|
||||
std::string_view value) {
|
||||
Native(ctx, inst, Smem(ctx, pointer_offset), "atomicOr", value);
|
||||
}
|
||||
|
||||
void EmitSharedAtomicXor32(EmitContext& ctx, IR::Inst& inst, std::string_view pointer_offset,
|
||||
std::string_view value) {
|
||||
Native(ctx, inst, Smem(ctx, pointer_offset), "atomicXor", value);
|
||||
}
|
||||
|
||||
void EmitSharedAtomicExchange32(EmitContext& ctx, IR::Inst& inst, std::string_view pointer_offset,
|
||||
std::string_view value) {
|
||||
Native(ctx, inst, Smem(ctx, pointer_offset), "atomicExchange", value);
|
||||
}
|
||||
|
||||
void EmitSharedAtomicExchange64(EmitContext& ctx, IR::Inst& inst, std::string_view pointer_offset,
|
||||
std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitSharedAtomicExchange32x2(EmitContext& ctx, IR::Inst& inst, std::string_view pointer_offset,
|
||||
std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitStorageAtomicIAdd32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
Native(ctx, inst, Ssbo(ctx, binding, offset), "atomicAdd", value);
|
||||
}
|
||||
|
||||
void EmitStorageAtomicSMin32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
CasLoop(ctx, inst, Ssbo(ctx, binding, offset), "CasMinS32", fmt::format("u32({})", value));
|
||||
}
|
||||
|
||||
void EmitStorageAtomicUMin32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
Native(ctx, inst, Ssbo(ctx, binding, offset), "atomicMin", value);
|
||||
}
|
||||
|
||||
void EmitStorageAtomicSMax32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
CasLoop(ctx, inst, Ssbo(ctx, binding, offset), "CasMaxS32", fmt::format("u32({})", value));
|
||||
}
|
||||
|
||||
void EmitStorageAtomicUMax32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
Native(ctx, inst, Ssbo(ctx, binding, offset), "atomicMax", value);
|
||||
}
|
||||
|
||||
void EmitStorageAtomicInc32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
CasLoop(ctx, inst, Ssbo(ctx, binding, offset), "CasIncrement", value);
|
||||
}
|
||||
|
||||
void EmitStorageAtomicDec32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
CasLoop(ctx, inst, Ssbo(ctx, binding, offset), "CasDecrement", value);
|
||||
}
|
||||
|
||||
void EmitStorageAtomicAnd32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
Native(ctx, inst, Ssbo(ctx, binding, offset), "atomicAnd", value);
|
||||
}
|
||||
|
||||
void EmitStorageAtomicOr32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
Native(ctx, inst, Ssbo(ctx, binding, offset), "atomicOr", value);
|
||||
}
|
||||
|
||||
void EmitStorageAtomicXor32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
Native(ctx, inst, Ssbo(ctx, binding, offset), "atomicXor", value);
|
||||
}
|
||||
|
||||
void EmitStorageAtomicExchange32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
Native(ctx, inst, Ssbo(ctx, binding, offset), "atomicExchange", value);
|
||||
}
|
||||
|
||||
void EmitStorageAtomicIAdd64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitStorageAtomicSMin64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitStorageAtomicUMin64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitStorageAtomicSMax64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitStorageAtomicUMax64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitStorageAtomicAnd64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitStorageAtomicOr64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitStorageAtomicXor64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitStorageAtomicExchange64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitStorageAtomicIAdd32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitStorageAtomicSMin32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitStorageAtomicUMin32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitStorageAtomicSMax32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitStorageAtomicUMax32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitStorageAtomicAnd32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitStorageAtomicOr32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitStorageAtomicXor32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitStorageAtomicExchange32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitStorageAtomicAddF32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
const std::string ptr{Ssbo(ctx, binding, offset)}, v{value};
|
||||
const auto ret{ctx.var_alloc.Define(inst, WgslVarType::U32)};
|
||||
ctx.Add("loop {{let old_=atomicLoad({});let r_=atomicCompareExchangeWeak({},old_,CasFloatAdd(old_,{}));"
|
||||
"if (r_.exchanged) {{{}=old_;break;}}}}",
|
||||
ptr, ptr, v, ret);
|
||||
ctx.AddF32("{}=bitcast<f32>({});", inst, ret);
|
||||
}
|
||||
|
||||
void EmitStorageAtomicAddF16x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
CasLoop(ctx, inst, Ssbo(ctx, binding, offset), "CasFloatAdd16x2", value);
|
||||
}
|
||||
|
||||
void EmitStorageAtomicAddF32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitStorageAtomicMinF16x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
CasLoop(ctx, inst, Ssbo(ctx, binding, offset), "CasFloatMin16x2", value);
|
||||
}
|
||||
|
||||
void EmitStorageAtomicMinF32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitStorageAtomicMaxF16x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
CasLoop(ctx, inst, Ssbo(ctx, binding, offset), "CasFloatMax16x2", value);
|
||||
}
|
||||
|
||||
void EmitStorageAtomicMaxF32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicIAdd32(EmitContext&) {
|
||||
throw NotImplementedException("GLSL Instruction");
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicSMin32(EmitContext&) {
|
||||
throw NotImplementedException("GLSL Instruction");
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicUMin32(EmitContext&) {
|
||||
throw NotImplementedException("GLSL Instruction");
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicSMax32(EmitContext&) {
|
||||
throw NotImplementedException("GLSL Instruction");
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicUMax32(EmitContext&) {
|
||||
throw NotImplementedException("GLSL Instruction");
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicInc32(EmitContext&) {
|
||||
throw NotImplementedException("GLSL Instruction");
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicDec32(EmitContext&) {
|
||||
throw NotImplementedException("GLSL Instruction");
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicAnd32(EmitContext&) {
|
||||
throw NotImplementedException("GLSL Instruction");
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicOr32(EmitContext&) {
|
||||
throw NotImplementedException("GLSL Instruction");
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicXor32(EmitContext&) {
|
||||
throw NotImplementedException("GLSL Instruction");
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicExchange32(EmitContext&) {
|
||||
throw NotImplementedException("GLSL Instruction");
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicIAdd64(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicSMin64(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicUMin64(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicSMax64(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicUMax64(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicInc64(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicDec64(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicAnd64(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicOr64(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicXor64(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicExchange64(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicIAdd32x2(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicSMin32x2(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicUMin32x2(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicSMax32x2(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicUMax32x2(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicInc32x2(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicDec32x2(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicAnd32x2(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicOr32x2(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicXor32x2(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicExchange32x2(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicAddF32(EmitContext&) {
|
||||
throw NotImplementedException("GLSL Instruction");
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicAddF16x2(EmitContext&) {
|
||||
throw NotImplementedException("GLSL Instruction");
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicAddF32x2(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicMinF16x2(EmitContext&) {
|
||||
throw NotImplementedException("GLSL Instruction");
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicMinF32x2(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicMaxF16x2(EmitContext&) {
|
||||
throw NotImplementedException("GLSL Instruction");
|
||||
}
|
||||
|
||||
void EmitGlobalAtomicMaxF32x2(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
} // namespace Shader::Backend::WGSL
|
||||
19
gpu/third_party/suyu/shader_recompiler/backend/wgsl/emit_wgsl_barriers.cpp
vendored
Normal file
19
gpu/third_party/suyu/shader_recompiler/backend/wgsl/emit_wgsl_barriers.cpp
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "shader_recompiler/backend/wgsl/emit_wgsl_instructions.h"
|
||||
#include "shader_recompiler/backend/wgsl/wgsl_emit_context.h"
|
||||
|
||||
namespace Shader::Backend::WGSL {
|
||||
void EmitBarrier(EmitContext& ctx) {
|
||||
ctx.Add("workgroupBarrier();");
|
||||
}
|
||||
|
||||
void EmitWorkgroupMemoryBarrier(EmitContext& ctx) {
|
||||
ctx.Add("workgroupBarrier();");
|
||||
}
|
||||
|
||||
void EmitDeviceMemoryBarrier(EmitContext& ctx) {
|
||||
ctx.Add("storageBarrier();");
|
||||
}
|
||||
} // namespace Shader::Backend::WGSL
|
||||
95
gpu/third_party/suyu/shader_recompiler/backend/wgsl/emit_wgsl_bitwise_conversion.cpp
vendored
Normal file
95
gpu/third_party/suyu/shader_recompiler/backend/wgsl/emit_wgsl_bitwise_conversion.cpp
vendored
Normal file
@@ -0,0 +1,95 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <string_view>
|
||||
|
||||
#include "shader_recompiler/backend/wgsl/emit_wgsl_instructions.h"
|
||||
#include "shader_recompiler/backend/wgsl/wgsl_emit_context.h"
|
||||
#include "shader_recompiler/frontend/ir/value.h"
|
||||
#include "shader_recompiler/profile.h"
|
||||
|
||||
namespace Shader::Backend::WGSL {
|
||||
namespace {
|
||||
void Alias(IR::Inst& inst, const IR::Value& value) {
|
||||
if (value.IsImmediate()) {
|
||||
return;
|
||||
}
|
||||
IR::Inst& value_inst{*value.InstRecursive()};
|
||||
value_inst.DestructiveAddUsage(inst.UseCount());
|
||||
value_inst.DestructiveRemoveUsage();
|
||||
inst.SetDefinition(value_inst.Definition<Id>());
|
||||
}
|
||||
} // Anonymous namespace
|
||||
|
||||
void EmitIdentity(EmitContext&, IR::Inst& inst, const IR::Value& value) {
|
||||
Alias(inst, value);
|
||||
}
|
||||
|
||||
void EmitConditionRef(EmitContext& ctx, IR::Inst& inst, const IR::Value& value) {
|
||||
// Fake one usage to get a real variable out of the condition
|
||||
inst.DestructiveAddUsage(1);
|
||||
const auto ret{ctx.var_alloc.Define(inst, WgslVarType::U1)};
|
||||
const auto input{ctx.var_alloc.Consume(value)};
|
||||
const auto suffix{ctx.profile.has_gl_bool_ref_bug ? "?true:false" : ""};
|
||||
if (ret != input) {
|
||||
ctx.Add("{}={}{};", ret, input, suffix);
|
||||
}
|
||||
}
|
||||
|
||||
void EmitBitCastU16F16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBitCastU32F32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddU32("{}=bitcast<u32>({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitBitCastU64F64(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBitCastF16U16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBitCastF32U32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddF32("{}=bitcast<f32>({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitBitCastF64U64(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitPackUint2x32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddU64("{}={};", inst, value); // u64 is vec2<u32>
|
||||
}
|
||||
|
||||
void EmitUnpackUint2x32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddU32x2("{}={};", inst, value);
|
||||
}
|
||||
|
||||
void EmitPackFloat2x16(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddU32("{}=pack2x16float({});", inst, value); // f16x2 is vec2<f32>
|
||||
}
|
||||
|
||||
void EmitUnpackFloat2x16(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddF16x2("{}=unpack2x16float({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitPackHalf2x16(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddU32("{}=pack2x16float({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitUnpackHalf2x16(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddF32x2("{}=unpack2x16float({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitPackDouble2x32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitUnpackDouble2x32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
} // namespace Shader::Backend::WGSL
|
||||
218
gpu/third_party/suyu/shader_recompiler/backend/wgsl/emit_wgsl_composite.cpp
vendored
Normal file
218
gpu/third_party/suyu/shader_recompiler/backend/wgsl/emit_wgsl_composite.cpp
vendored
Normal file
@@ -0,0 +1,218 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <string_view>
|
||||
|
||||
#include "shader_recompiler/backend/wgsl/emit_wgsl_instructions.h"
|
||||
#include "shader_recompiler/backend/wgsl/wgsl_emit_context.h"
|
||||
#include "shader_recompiler/frontend/ir/value.h"
|
||||
|
||||
namespace Shader::Backend::WGSL {
|
||||
namespace {
|
||||
constexpr std::string_view SWIZZLE{"xyzw"};
|
||||
void CompositeInsert(EmitContext& ctx, std::string_view result, std::string_view composite,
|
||||
std::string_view object, u32 index) {
|
||||
if (result == composite) {
|
||||
// The result is aliased with the composite
|
||||
ctx.Add("{}.{}={};", composite, SWIZZLE[index], object);
|
||||
} else {
|
||||
ctx.Add("{}={};{}.{}={};", result, composite, result, SWIZZLE[index], object);
|
||||
}
|
||||
}
|
||||
} // Anonymous namespace
|
||||
|
||||
void EmitCompositeConstructU32x2(EmitContext& ctx, IR::Inst& inst, std::string_view e1,
|
||||
std::string_view e2) {
|
||||
ctx.AddU32x2("{}=vec2<u32>({},{});", inst, e1, e2);
|
||||
}
|
||||
|
||||
void EmitCompositeConstructU32x3(EmitContext& ctx, IR::Inst& inst, std::string_view e1,
|
||||
std::string_view e2, std::string_view e3) {
|
||||
ctx.AddU32x3("{}=vec3<u32>({},{},{});", inst, e1, e2, e3);
|
||||
}
|
||||
|
||||
void EmitCompositeConstructU32x4(EmitContext& ctx, IR::Inst& inst, std::string_view e1,
|
||||
std::string_view e2, std::string_view e3, std::string_view e4) {
|
||||
ctx.AddU32x4("{}=vec4<u32>({},{},{},{});", inst, e1, e2, e3, e4);
|
||||
}
|
||||
|
||||
void EmitCompositeExtractU32x2(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
|
||||
u32 index) {
|
||||
ctx.AddU32("{}={}.{};", inst, composite, SWIZZLE[index]);
|
||||
}
|
||||
|
||||
void EmitCompositeExtractU32x3(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
|
||||
u32 index) {
|
||||
ctx.AddU32("{}={}.{};", inst, composite, SWIZZLE[index]);
|
||||
}
|
||||
|
||||
void EmitCompositeExtractU32x4(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
|
||||
u32 index) {
|
||||
ctx.AddU32("{}={}.{};", inst, composite, SWIZZLE[index]);
|
||||
}
|
||||
|
||||
void EmitCompositeInsertU32x2(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
|
||||
std::string_view object, u32 index) {
|
||||
const auto ret{ctx.var_alloc.Define(inst, WgslVarType::U32x2)};
|
||||
CompositeInsert(ctx, ret, composite, object, index);
|
||||
}
|
||||
|
||||
void EmitCompositeInsertU32x3(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
|
||||
std::string_view object, u32 index) {
|
||||
const auto ret{ctx.var_alloc.Define(inst, WgslVarType::U32x3)};
|
||||
CompositeInsert(ctx, ret, composite, object, index);
|
||||
}
|
||||
|
||||
void EmitCompositeInsertU32x4(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
|
||||
std::string_view object, u32 index) {
|
||||
const auto ret{ctx.var_alloc.Define(inst, WgslVarType::U32x4)};
|
||||
CompositeInsert(ctx, ret, composite, object, index);
|
||||
}
|
||||
|
||||
void EmitCompositeConstructF16x2([[maybe_unused]] EmitContext& ctx,
|
||||
[[maybe_unused]] std::string_view e1,
|
||||
[[maybe_unused]] std::string_view e2) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitCompositeConstructF16x3([[maybe_unused]] EmitContext& ctx,
|
||||
[[maybe_unused]] std::string_view e1,
|
||||
[[maybe_unused]] std::string_view e2,
|
||||
[[maybe_unused]] std::string_view e3) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitCompositeConstructF16x4([[maybe_unused]] EmitContext& ctx,
|
||||
[[maybe_unused]] std::string_view e1,
|
||||
[[maybe_unused]] std::string_view e2,
|
||||
[[maybe_unused]] std::string_view e3,
|
||||
[[maybe_unused]] std::string_view e4) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitCompositeExtractF16x2([[maybe_unused]] EmitContext& ctx,
|
||||
[[maybe_unused]] std::string_view composite,
|
||||
[[maybe_unused]] u32 index) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitCompositeExtractF16x3([[maybe_unused]] EmitContext& ctx,
|
||||
[[maybe_unused]] std::string_view composite,
|
||||
[[maybe_unused]] u32 index) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitCompositeExtractF16x4([[maybe_unused]] EmitContext& ctx,
|
||||
[[maybe_unused]] std::string_view composite,
|
||||
[[maybe_unused]] u32 index) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitCompositeInsertF16x2([[maybe_unused]] EmitContext& ctx,
|
||||
[[maybe_unused]] std::string_view composite,
|
||||
[[maybe_unused]] std::string_view object,
|
||||
[[maybe_unused]] u32 index) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitCompositeInsertF16x3([[maybe_unused]] EmitContext& ctx,
|
||||
[[maybe_unused]] std::string_view composite,
|
||||
[[maybe_unused]] std::string_view object,
|
||||
[[maybe_unused]] u32 index) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitCompositeInsertF16x4([[maybe_unused]] EmitContext& ctx,
|
||||
[[maybe_unused]] std::string_view composite,
|
||||
[[maybe_unused]] std::string_view object,
|
||||
[[maybe_unused]] u32 index) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitCompositeConstructF32x2(EmitContext& ctx, IR::Inst& inst, std::string_view e1,
|
||||
std::string_view e2) {
|
||||
ctx.AddF32x2("{}=vec2<f32>({},{});", inst, e1, e2);
|
||||
}
|
||||
|
||||
void EmitCompositeConstructF32x3(EmitContext& ctx, IR::Inst& inst, std::string_view e1,
|
||||
std::string_view e2, std::string_view e3) {
|
||||
ctx.AddF32x3("{}=vec3<f32>({},{},{});", inst, e1, e2, e3);
|
||||
}
|
||||
|
||||
void EmitCompositeConstructF32x4(EmitContext& ctx, IR::Inst& inst, std::string_view e1,
|
||||
std::string_view e2, std::string_view e3, std::string_view e4) {
|
||||
ctx.AddF32x4("{}=vec4<f32>({},{},{},{});", inst, e1, e2, e3, e4);
|
||||
}
|
||||
|
||||
void EmitCompositeExtractF32x2(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
|
||||
u32 index) {
|
||||
ctx.AddF32("{}={}.{};", inst, composite, SWIZZLE[index]);
|
||||
}
|
||||
|
||||
void EmitCompositeExtractF32x3(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
|
||||
u32 index) {
|
||||
ctx.AddF32("{}={}.{};", inst, composite, SWIZZLE[index]);
|
||||
}
|
||||
|
||||
void EmitCompositeExtractF32x4(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
|
||||
u32 index) {
|
||||
ctx.AddF32("{}={}.{};", inst, composite, SWIZZLE[index]);
|
||||
}
|
||||
|
||||
void EmitCompositeInsertF32x2(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
|
||||
std::string_view object, u32 index) {
|
||||
const auto ret{ctx.var_alloc.Define(inst, WgslVarType::F32x2)};
|
||||
CompositeInsert(ctx, ret, composite, object, index);
|
||||
}
|
||||
|
||||
void EmitCompositeInsertF32x3(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
|
||||
std::string_view object, u32 index) {
|
||||
const auto ret{ctx.var_alloc.Define(inst, WgslVarType::F32x3)};
|
||||
CompositeInsert(ctx, ret, composite, object, index);
|
||||
}
|
||||
|
||||
void EmitCompositeInsertF32x4(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
|
||||
std::string_view object, u32 index) {
|
||||
const auto ret{ctx.var_alloc.Define(inst, WgslVarType::F32x4)};
|
||||
CompositeInsert(ctx, ret, composite, object, index);
|
||||
}
|
||||
|
||||
void EmitCompositeConstructF64x2([[maybe_unused]] EmitContext& ctx) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitCompositeConstructF64x3([[maybe_unused]] EmitContext& ctx) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitCompositeConstructF64x4([[maybe_unused]] EmitContext& ctx) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitCompositeExtractF64x2([[maybe_unused]] EmitContext& ctx) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitCompositeExtractF64x3([[maybe_unused]] EmitContext& ctx) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitCompositeExtractF64x4([[maybe_unused]] EmitContext& ctx) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitCompositeInsertF64x2(EmitContext& ctx, std::string_view composite, std::string_view object,
|
||||
u32 index) {
|
||||
ctx.Add("{}.{}={};", composite, SWIZZLE[index], object);
|
||||
}
|
||||
|
||||
void EmitCompositeInsertF64x3(EmitContext& ctx, std::string_view composite, std::string_view object,
|
||||
u32 index) {
|
||||
ctx.Add("{}.{}={};", composite, SWIZZLE[index], object);
|
||||
}
|
||||
|
||||
void EmitCompositeInsertF64x4(EmitContext& ctx, std::string_view composite, std::string_view object,
|
||||
u32 index) {
|
||||
ctx.Add("{}.{}={};", composite, SWIZZLE[index], object);
|
||||
}
|
||||
} // namespace Shader::Backend::WGSL
|
||||
479
gpu/third_party/suyu/shader_recompiler/backend/wgsl/emit_wgsl_context_get_set.cpp
vendored
Normal file
479
gpu/third_party/suyu/shader_recompiler/backend/wgsl/emit_wgsl_context_get_set.cpp
vendored
Normal file
@@ -0,0 +1,479 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <string_view>
|
||||
|
||||
#include "shader_recompiler/backend/wgsl/emit_wgsl_instructions.h"
|
||||
#include "shader_recompiler/backend/wgsl/wgsl_emit_context.h"
|
||||
#include "shader_recompiler/frontend/ir/value.h"
|
||||
#include "shader_recompiler/profile.h"
|
||||
#include "shader_recompiler/runtime_info.h"
|
||||
|
||||
namespace Shader::Backend::WGSL {
|
||||
namespace {
|
||||
constexpr char SWIZZLE[]{"xyzw"};
|
||||
|
||||
u32 CbufIndex(u32 offset) {
|
||||
return (offset / 4) % 4;
|
||||
}
|
||||
|
||||
char OffsetSwizzle(u32 offset) {
|
||||
return SWIZZLE[CbufIndex(offset)];
|
||||
}
|
||||
|
||||
bool IsInputArray(Stage stage) {
|
||||
return stage == Stage::Geometry || stage == Stage::TessellationControl ||
|
||||
stage == Stage::TessellationEval;
|
||||
}
|
||||
|
||||
std::string InputVertexIndex(EmitContext& ctx, std::string_view vertex) {
|
||||
return IsInputArray(ctx.stage) ? fmt::format("[{}]", vertex) : "";
|
||||
}
|
||||
|
||||
std::string_view OutputVertexIndex(EmitContext& ctx) {
|
||||
return ctx.stage == Stage::TessellationControl ? "[gl_InvocationID]" : "";
|
||||
}
|
||||
|
||||
/// dynamic: the index is computed at run time (a storage-bound buffer then reads 0 past its bound size: CbufAt)
|
||||
std::string ChooseCbuf(EmitContext& ctx, const IR::Value& binding, std::string_view index, bool dynamic = false) {
|
||||
if (binding.IsImmediate()) {
|
||||
if (ctx.cbuf_in_ub[binding.U32() % 18]) {
|
||||
return fmt::format("{}[{}u+({})]", ctx.ub_name, ctx.ub_cbuf_base[binding.U32() % 18], index);
|
||||
}
|
||||
if (dynamic && !CbufClamp()) return fmt::format("{}_cbuf{}_at(u32({}))", ctx.stage_name, binding.U32(), index);
|
||||
return fmt::format("{}_cbuf{}[{}]", ctx.stage_name, binding.U32(), index);
|
||||
} else {
|
||||
const auto binding_var{ctx.var_alloc.Consume(binding)};
|
||||
return fmt::format("GetCbufIndirect({},{})", binding_var, index);
|
||||
}
|
||||
}
|
||||
|
||||
void GetCbuf(EmitContext& ctx, std::string_view ret, const IR::Value& binding,
|
||||
const IR::Value& offset, u32 num_bits, std::string_view cast = {},
|
||||
std::string_view bit_offset = {}) {
|
||||
const bool is_immediate{offset.IsImmediate()};
|
||||
const bool component_indexing_bug{!is_immediate && ctx.profile.has_gl_component_indexing_bug};
|
||||
if (is_immediate) {
|
||||
const s32 signed_offset{static_cast<s32>(offset.U32())};
|
||||
static constexpr u32 cbuf_size{0x10000};
|
||||
if (signed_offset < 0 || offset.U32() > cbuf_size) {
|
||||
LOG_WARNING(Shader_WGSL, "Immediate constant buffer offset is out of bounds");
|
||||
ctx.Add("{}={};", ret, cast == "bitcast<f32>" ? "0.0f" : "0u");
|
||||
return;
|
||||
}
|
||||
}
|
||||
const auto offset_var{ctx.var_alloc.Consume(offset)};
|
||||
const auto index{is_immediate ? fmt::format("{}", offset.U32() / 16)
|
||||
: fmt::format("{}>>4", offset_var)};
|
||||
const auto swizzle{is_immediate ? fmt::format(".{}", OffsetSwizzle(offset.U32()))
|
||||
: fmt::format("[({}>>2)%4]", offset_var)};
|
||||
|
||||
const auto cbuf{ChooseCbuf(ctx, binding, index, !is_immediate)};
|
||||
const auto cbuf_cast{fmt::format("{}({}{{}})", cast, cbuf)};
|
||||
const auto extraction{num_bits == 32 ? cbuf_cast
|
||||
: fmt::format("u32(extractBits({},u32({}),{}u))", cbuf_cast,
|
||||
bit_offset, num_bits)};
|
||||
if (!component_indexing_bug) {
|
||||
const auto result{fmt::format(fmt::runtime(extraction), swizzle)};
|
||||
ctx.Add("{}={};", ret, result);
|
||||
return;
|
||||
}
|
||||
const auto cbuf_offset{fmt::format("{}>>2", offset_var)};
|
||||
for (u32 i = 0; i < 4; ++i) {
|
||||
const auto swizzle_string{fmt::format(".{}", "xyzw"[i])};
|
||||
const auto result{fmt::format(fmt::runtime(extraction), swizzle_string)};
|
||||
ctx.Add("if(({}&3)=={}){}={};", cbuf_offset, i, ret, result);
|
||||
}
|
||||
}
|
||||
|
||||
void GetCbuf8(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, const IR::Value& offset,
|
||||
std::string_view cast) {
|
||||
const auto ret{ctx.var_alloc.Define(inst, WgslVarType::U32)};
|
||||
if (offset.IsImmediate()) {
|
||||
const auto bit_offset{fmt::format("{}", (offset.U32() % 4) * 8)};
|
||||
GetCbuf(ctx, ret, binding, offset, 8, cast, bit_offset);
|
||||
} else {
|
||||
const auto offset_var{ctx.var_alloc.Consume(offset)};
|
||||
const auto bit_offset{fmt::format("({}%4)*8", offset_var)};
|
||||
GetCbuf(ctx, ret, binding, offset, 8, cast, bit_offset);
|
||||
}
|
||||
}
|
||||
|
||||
void GetCbuf16(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, const IR::Value& offset,
|
||||
std::string_view cast) {
|
||||
const auto ret{ctx.var_alloc.Define(inst, WgslVarType::U32)};
|
||||
if (offset.IsImmediate()) {
|
||||
const auto bit_offset{fmt::format("{}", ((offset.U32() / 2) % 2) * 16)};
|
||||
GetCbuf(ctx, ret, binding, offset, 16, cast, bit_offset);
|
||||
} else {
|
||||
const auto offset_var{ctx.var_alloc.Consume(offset)};
|
||||
const auto bit_offset{fmt::format("(({}>>1)%2)*16", offset_var)};
|
||||
GetCbuf(ctx, ret, binding, offset, 16, cast, bit_offset);
|
||||
}
|
||||
}
|
||||
} // Anonymous namespace
|
||||
|
||||
void EmitGetCbufU8(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset) {
|
||||
const auto cast{""};
|
||||
GetCbuf8(ctx, inst, binding, offset, cast);
|
||||
}
|
||||
|
||||
void EmitGetCbufS8(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset) {
|
||||
const auto cast{"bitcast<i32>"};
|
||||
GetCbuf8(ctx, inst, binding, offset, cast);
|
||||
}
|
||||
|
||||
void EmitGetCbufU16(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset) {
|
||||
const auto cast{""};
|
||||
GetCbuf16(ctx, inst, binding, offset, cast);
|
||||
}
|
||||
|
||||
void EmitGetCbufS16(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset) {
|
||||
const auto cast{"bitcast<i32>"};
|
||||
GetCbuf16(ctx, inst, binding, offset, cast);
|
||||
}
|
||||
|
||||
void EmitGetCbufU32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset) {
|
||||
const auto ret{ctx.var_alloc.Define(inst, WgslVarType::U32)};
|
||||
GetCbuf(ctx, ret, binding, offset, 32, "");
|
||||
}
|
||||
|
||||
void EmitGetCbufF32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset) {
|
||||
const auto ret{ctx.var_alloc.Define(inst, WgslVarType::F32)};
|
||||
GetCbuf(ctx, ret, binding, offset, 32, "bitcast<f32>");
|
||||
}
|
||||
|
||||
void EmitGetCbufU32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset) {
|
||||
const auto cast{""};
|
||||
if (offset.IsImmediate()) {
|
||||
static constexpr u32 cbuf_size{0x10000};
|
||||
const u32 u32_offset{offset.U32()};
|
||||
const s32 signed_offset{static_cast<s32>(offset.U32())};
|
||||
if (signed_offset < 0 || u32_offset > cbuf_size) {
|
||||
LOG_WARNING(Shader_WGSL, "Immediate constant buffer offset is out of bounds");
|
||||
ctx.AddU32x2("{}=vec2<u32>(0u);", inst);
|
||||
return;
|
||||
}
|
||||
const auto first{ChooseCbuf(ctx, binding, fmt::format("{}", u32_offset / 16))};
|
||||
if (u32_offset % 16 <= 8 && u32_offset % 4 == 0) {
|
||||
ctx.AddU32x2("{}={}({}.{}{});", inst, cast, first, OffsetSwizzle(u32_offset),
|
||||
OffsetSwizzle(u32_offset + 4));
|
||||
} else {
|
||||
const auto second{ChooseCbuf(ctx, binding, fmt::format("{}", (u32_offset + 4) / 16))};
|
||||
ctx.AddU32x2("{}=vec2<u32>({}({}.{}),{}({}.{}));", inst, cast, first, OffsetSwizzle(u32_offset), cast,
|
||||
second, OffsetSwizzle(u32_offset + 4));
|
||||
}
|
||||
return;
|
||||
}
|
||||
const auto offset_var{ctx.var_alloc.Consume(offset)};
|
||||
const auto cbuf{ChooseCbuf(ctx, binding, fmt::format("{}>>4", offset_var), true)};
|
||||
if (!ctx.profile.has_gl_component_indexing_bug) {
|
||||
ctx.AddU32x2("{}=vec2<u32>({}({}[({}>>2)%4]),{}({}[(({}+4)>>2)%4]));", inst, cast, cbuf,
|
||||
offset_var, cast, cbuf, offset_var);
|
||||
return;
|
||||
}
|
||||
const auto ret{ctx.var_alloc.Define(inst, WgslVarType::U32x2)};
|
||||
const auto cbuf_offset{fmt::format("{}>>2", offset_var)};
|
||||
for (u32 swizzle = 0; swizzle < 4; ++swizzle) {
|
||||
ctx.Add("if(({}&3)=={}){}=vec2<u32>({}({}.{}),{}({}.{}));", cbuf_offset, swizzle, ret, cast,
|
||||
cbuf, "xyzw"[swizzle], cast, cbuf, "xyzw"[(swizzle + 1) % 4]);
|
||||
}
|
||||
}
|
||||
|
||||
void EmitGetAttribute(EmitContext& ctx, IR::Inst& inst, IR::Attribute attr,
|
||||
std::string_view vertex) {
|
||||
const u32 element{static_cast<u32>(attr) % 4};
|
||||
const char swizzle{"xyzw"[element]};
|
||||
if (IR::IsGeneric(attr)) {
|
||||
const u32 index{IR::GenericAttributeIndex(attr)};
|
||||
if (!ctx.runtime_info.previous_stage_stores.Generic(index, element)) {
|
||||
if (element == 3) {
|
||||
ctx.AddF32("{}=1.f;", inst, attr);
|
||||
} else {
|
||||
ctx.AddF32("{}=0.f;", inst, attr);
|
||||
}
|
||||
return;
|
||||
}
|
||||
ctx.AddF32("{}=in_attr{}{}.{};", inst, index, InputVertexIndex(ctx, vertex), swizzle);
|
||||
return;
|
||||
}
|
||||
switch (attr) {
|
||||
case IR::Attribute::PrimitiveId:
|
||||
ctx.AddF32("{}=bitcast<f32>(gl_PrimitiveID);", inst);
|
||||
break;
|
||||
case IR::Attribute::Layer:
|
||||
ctx.AddF32("{}=bitcast<f32>(gl_Layer);", inst);
|
||||
break;
|
||||
case IR::Attribute::PositionX:
|
||||
case IR::Attribute::PositionY:
|
||||
case IR::Attribute::PositionZ:
|
||||
case IR::Attribute::PositionW: {
|
||||
const bool is_array{IsInputArray(ctx.stage)};
|
||||
const auto input_decorator{is_array ? fmt::format("gl_in[{}].", vertex) : ""};
|
||||
ctx.AddF32("{}={}{}.{};", inst, input_decorator, ctx.position_name, swizzle);
|
||||
break;
|
||||
}
|
||||
case IR::Attribute::PointSpriteS:
|
||||
case IR::Attribute::PointSpriteT:
|
||||
ctx.AddF32("{}=gl_PointCoord.{};", inst, swizzle);
|
||||
break;
|
||||
case IR::Attribute::TessellationEvaluationPointU:
|
||||
case IR::Attribute::TessellationEvaluationPointV:
|
||||
ctx.AddF32("{}=gl_TessCoord.{};", inst, swizzle);
|
||||
break;
|
||||
case IR::Attribute::InstanceId:
|
||||
ctx.AddF32("{}=bitcast<f32>(gl_InstanceID);", inst);
|
||||
break;
|
||||
case IR::Attribute::VertexId:
|
||||
ctx.AddF32("{}=bitcast<f32>(gl_VertexID);", inst);
|
||||
break;
|
||||
case IR::Attribute::FrontFace:
|
||||
ctx.AddF32("{}=bitcast<f32>(select(0i,-1i,gl_FrontFacing));", inst);
|
||||
break;
|
||||
case IR::Attribute::BaseInstance:
|
||||
ctx.AddF32("{}=bitcast<f32>(gl_BaseInstance);", inst);
|
||||
break;
|
||||
case IR::Attribute::BaseVertex:
|
||||
ctx.AddF32("{}=bitcast<f32>(gl_BaseVertex);", inst);
|
||||
break;
|
||||
case IR::Attribute::DrawID:
|
||||
ctx.AddF32("{}=bitcast<f32>(gl_DrawID);", inst);
|
||||
break;
|
||||
default:
|
||||
throw NotImplementedException("Get attribute {}", attr);
|
||||
}
|
||||
}
|
||||
|
||||
void EmitGetAttributeU32(EmitContext& ctx, IR::Inst& inst, IR::Attribute attr, std::string_view) {
|
||||
switch (attr) {
|
||||
case IR::Attribute::PrimitiveId:
|
||||
ctx.AddU32("{}=u32(gl_PrimitiveID);", inst);
|
||||
break;
|
||||
case IR::Attribute::InstanceId:
|
||||
ctx.AddU32("{}=u32(gl_InstanceID);", inst);
|
||||
break;
|
||||
case IR::Attribute::VertexId:
|
||||
ctx.AddU32("{}=u32(gl_VertexID);", inst);
|
||||
break;
|
||||
case IR::Attribute::BaseInstance:
|
||||
ctx.AddU32("{}=u32(gl_BaseInstance);", inst);
|
||||
break;
|
||||
case IR::Attribute::BaseVertex:
|
||||
ctx.AddU32("{}=u32(gl_BaseVertex);", inst);
|
||||
break;
|
||||
case IR::Attribute::DrawID:
|
||||
ctx.AddU32("{}=u32(gl_DrawID);", inst);
|
||||
break;
|
||||
default:
|
||||
throw NotImplementedException("Get U32 attribute {}", attr);
|
||||
}
|
||||
}
|
||||
|
||||
void EmitSetAttribute(EmitContext& ctx, IR::Attribute attr, std::string_view value,
|
||||
[[maybe_unused]] std::string_view vertex) {
|
||||
if (IR::IsGeneric(attr)) {
|
||||
const u32 index{IR::GenericAttributeIndex(attr)};
|
||||
const u32 attr_element{IR::GenericAttributeElement(attr)};
|
||||
const GenericElementInfo& info{ctx.output_generics.at(index).at(attr_element)};
|
||||
const auto output_decorator{OutputVertexIndex(ctx)};
|
||||
if (info.num_components == 1) {
|
||||
ctx.Add("{}{}={};", info.name, output_decorator, value);
|
||||
} else {
|
||||
const u32 index_element{attr_element - info.first_element};
|
||||
ctx.Add("{}{}.{}={};", info.name, output_decorator, "xyzw"[index_element], value);
|
||||
}
|
||||
return;
|
||||
}
|
||||
const u32 element{static_cast<u32>(attr) % 4};
|
||||
const char swizzle{"xyzw"[element]};
|
||||
switch (attr) {
|
||||
case IR::Attribute::Layer:
|
||||
if (ctx.stage != Stage::Geometry &&
|
||||
!ctx.profile.support_viewport_index_layer_non_geometry) {
|
||||
LOG_WARNING(Shader_WGSL, "Shader stores viewport layer but device does not support "
|
||||
"viewport layer extension");
|
||||
break;
|
||||
}
|
||||
ctx.Add("gl_Layer=bitcast<i32>({});", value);
|
||||
break;
|
||||
case IR::Attribute::ViewportIndex:
|
||||
if (ctx.stage != Stage::Geometry &&
|
||||
!ctx.profile.support_viewport_index_layer_non_geometry) {
|
||||
LOG_WARNING(Shader_WGSL, "Shader stores viewport index but device does not support "
|
||||
"viewport layer extension");
|
||||
break;
|
||||
}
|
||||
ctx.Add("gl_ViewportIndex=bitcast<i32>({});", value);
|
||||
break;
|
||||
case IR::Attribute::ViewportMask:
|
||||
if (ctx.stage != Stage::Geometry && !ctx.profile.support_viewport_mask) {
|
||||
LOG_WARNING(
|
||||
Shader_WGSL,
|
||||
"Shader stores viewport mask but device does not support viewport mask extension");
|
||||
break;
|
||||
}
|
||||
ctx.Add("gl_ViewportMask[0]=bitcast<i32>({});", value);
|
||||
break;
|
||||
case IR::Attribute::PointSize:
|
||||
ctx.Add("gl_PointSize={};", value);
|
||||
break;
|
||||
case IR::Attribute::PositionX:
|
||||
case IR::Attribute::PositionY:
|
||||
case IR::Attribute::PositionZ:
|
||||
case IR::Attribute::PositionW:
|
||||
ctx.Add("gl_Position.{}={};", swizzle, value);
|
||||
break;
|
||||
case IR::Attribute::ClipDistance0:
|
||||
case IR::Attribute::ClipDistance1:
|
||||
case IR::Attribute::ClipDistance2:
|
||||
case IR::Attribute::ClipDistance3:
|
||||
case IR::Attribute::ClipDistance4:
|
||||
case IR::Attribute::ClipDistance5:
|
||||
case IR::Attribute::ClipDistance6:
|
||||
case IR::Attribute::ClipDistance7: {
|
||||
const u32 index{static_cast<u32>(attr) - static_cast<u32>(IR::Attribute::ClipDistance0)};
|
||||
ctx.Add("gl_ClipDistance[{}]={};", index, value);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw NotImplementedException("Set attribute {}", attr);
|
||||
}
|
||||
}
|
||||
|
||||
void EmitGetAttributeIndexed(EmitContext& ctx, IR::Inst& inst, std::string_view offset,
|
||||
std::string_view vertex) {
|
||||
const bool is_array{ctx.stage == Stage::Geometry};
|
||||
const auto vertex_arg{is_array ? fmt::format(",{}", vertex) : ""};
|
||||
ctx.AddF32("{}=IndexedAttrLoad(i32({}){});", inst, offset, vertex_arg);
|
||||
}
|
||||
|
||||
void EmitSetAttributeIndexed([[maybe_unused]] EmitContext& ctx,
|
||||
[[maybe_unused]] std::string_view offset,
|
||||
[[maybe_unused]] std::string_view value,
|
||||
[[maybe_unused]] std::string_view vertex) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitGetPatch(EmitContext& ctx, IR::Inst& inst, IR::Patch patch) {
|
||||
if (!IR::IsGeneric(patch)) {
|
||||
throw NotImplementedException("Non-generic patch load");
|
||||
}
|
||||
const u32 index{IR::GenericPatchIndex(patch)};
|
||||
const u32 element{IR::GenericPatchElement(patch)};
|
||||
const char swizzle{"xyzw"[element]};
|
||||
ctx.AddF32("{}=patch{}.{};", inst, index, swizzle);
|
||||
}
|
||||
|
||||
void EmitSetPatch(EmitContext& ctx, IR::Patch patch, std::string_view value) {
|
||||
if (IR::IsGeneric(patch)) {
|
||||
const u32 index{IR::GenericPatchIndex(patch)};
|
||||
const u32 element{IR::GenericPatchElement(patch)};
|
||||
ctx.Add("patch{}.{}={};", index, "xyzw"[element], value);
|
||||
return;
|
||||
}
|
||||
switch (patch) {
|
||||
case IR::Patch::TessellationLodLeft:
|
||||
case IR::Patch::TessellationLodRight:
|
||||
case IR::Patch::TessellationLodTop:
|
||||
case IR::Patch::TessellationLodBottom: {
|
||||
const u32 index{static_cast<u32>(patch) - u32(IR::Patch::TessellationLodLeft)};
|
||||
ctx.Add("gl_TessLevelOuter[{}]={};", index, value);
|
||||
break;
|
||||
}
|
||||
case IR::Patch::TessellationLodInteriorU:
|
||||
ctx.Add("gl_TessLevelInner[0]={};", value);
|
||||
break;
|
||||
case IR::Patch::TessellationLodInteriorV:
|
||||
ctx.Add("gl_TessLevelInner[1]={};", value);
|
||||
break;
|
||||
default:
|
||||
throw NotImplementedException("Patch {}", patch);
|
||||
}
|
||||
}
|
||||
|
||||
void EmitSetFragColor(EmitContext& ctx, u32 index, u32 component, std::string_view value) {
|
||||
const char swizzle{"xyzw"[component]};
|
||||
ctx.Add("frag_color{}.{}={};", index, swizzle, value);
|
||||
}
|
||||
|
||||
void EmitSetSampleMask(EmitContext& ctx, std::string_view value) {
|
||||
ctx.Add("gl_SampleMask[0]=i32({});", value);
|
||||
}
|
||||
|
||||
void EmitSetFragDepth(EmitContext& ctx, std::string_view value) {
|
||||
ctx.Add("gl_FragDepth={};", value);
|
||||
}
|
||||
|
||||
void EmitLocalInvocationId(EmitContext& ctx, IR::Inst& inst) {
|
||||
ctx.AddU32x3("{}=gl_LocalInvocationID;", inst);
|
||||
}
|
||||
|
||||
void EmitWorkgroupId(EmitContext& ctx, IR::Inst& inst) {
|
||||
ctx.AddU32x3("{}=gl_WorkGroupID;", inst);
|
||||
}
|
||||
|
||||
void EmitInvocationId(EmitContext& ctx, IR::Inst& inst) {
|
||||
ctx.AddU32("{}=u32(gl_InvocationID);", inst);
|
||||
}
|
||||
|
||||
void EmitInvocationInfo(EmitContext& ctx, IR::Inst& inst) {
|
||||
switch (ctx.stage) {
|
||||
case Stage::TessellationControl:
|
||||
case Stage::TessellationEval:
|
||||
ctx.AddU32("{}=u32(gl_PatchVerticesIn)<<16;", inst);
|
||||
break;
|
||||
case Stage::Geometry:
|
||||
ctx.AddU32("{}=u32({}<<16);", inst,
|
||||
InputTopologyVertices::vertices(ctx.runtime_info.input_topology));
|
||||
break;
|
||||
default:
|
||||
LOG_WARNING(Shader, "(STUBBED) called");
|
||||
ctx.AddU32("{}=u32(0x00ff0000);", inst);
|
||||
}
|
||||
}
|
||||
|
||||
void EmitSampleId(EmitContext& ctx, IR::Inst& inst) {
|
||||
ctx.AddU32("{}=u32(gl_SampleID);", inst);
|
||||
}
|
||||
|
||||
void EmitIsHelperInvocation(EmitContext& ctx, IR::Inst& inst) {
|
||||
ctx.AddU1("{}=gl_HelperInvocation;", inst);
|
||||
}
|
||||
|
||||
void EmitSR_WScaleFactorXY(EmitContext& ctx, IR::Inst& inst) {
|
||||
LOG_WARNING(Shader, "(STUBBED) called");
|
||||
}
|
||||
|
||||
void EmitSR_WScaleFactorZ(EmitContext& ctx, IR::Inst& inst) {
|
||||
LOG_WARNING(Shader, "(STUBBED) called");
|
||||
}
|
||||
|
||||
void EmitYDirection(EmitContext& ctx, IR::Inst& inst) {
|
||||
ctx.uses_y_direction = true;
|
||||
ctx.AddF32("{}=1.0f;", inst); // the renderer flips Y in the viewport
|
||||
}
|
||||
|
||||
void EmitResolutionDownFactor(EmitContext& ctx, IR::Inst& inst) {
|
||||
ctx.AddF32("{}=scaling().z;", inst);
|
||||
}
|
||||
|
||||
void EmitRenderArea(EmitContext& ctx, IR::Inst& inst) {
|
||||
ctx.AddF32x4("{}=render_area();", inst);
|
||||
}
|
||||
|
||||
void EmitLoadLocal(EmitContext& ctx, IR::Inst& inst, std::string_view word_offset) {
|
||||
ctx.AddU32("{}=lmem[{}];", inst, word_offset);
|
||||
}
|
||||
|
||||
void EmitWriteLocal(EmitContext& ctx, std::string_view word_offset, std::string_view value) {
|
||||
ctx.Add("lmem[{}]={};", word_offset, value);
|
||||
}
|
||||
|
||||
} // namespace Shader::Backend::WGSL
|
||||
18
gpu/third_party/suyu/shader_recompiler/backend/wgsl/emit_wgsl_control_flow.cpp
vendored
Normal file
18
gpu/third_party/suyu/shader_recompiler/backend/wgsl/emit_wgsl_control_flow.cpp
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "shader_recompiler/backend/wgsl/emit_wgsl_instructions.h"
|
||||
#include "shader_recompiler/backend/wgsl/wgsl_emit_context.h"
|
||||
#include "shader_recompiler/exception.h"
|
||||
|
||||
namespace Shader::Backend::WGSL {
|
||||
|
||||
void EmitJoin(EmitContext&) {
|
||||
throw NotImplementedException("Join shouldn't be emitted");
|
||||
}
|
||||
|
||||
void EmitDemoteToHelperInvocation(EmitContext& ctx) {
|
||||
ctx.Add("discard;");
|
||||
}
|
||||
|
||||
} // namespace Shader::Backend::WGSL
|
||||
259
gpu/third_party/suyu/shader_recompiler/backend/wgsl/emit_wgsl_convert.cpp
vendored
Normal file
259
gpu/third_party/suyu/shader_recompiler/backend/wgsl/emit_wgsl_convert.cpp
vendored
Normal file
@@ -0,0 +1,259 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <string_view>
|
||||
|
||||
#include "shader_recompiler/backend/wgsl/emit_wgsl_instructions.h"
|
||||
#include "shader_recompiler/backend/wgsl/wgsl_emit_context.h"
|
||||
#include "shader_recompiler/frontend/ir/value.h"
|
||||
|
||||
namespace Shader::Backend::WGSL {
|
||||
void EmitConvertS16F16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertS16F32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddU32("{}=u32((i32({})&0xffff)|(extractBits(i32({}),31u,1u)<<15u));", inst, value, value);
|
||||
}
|
||||
|
||||
void EmitConvertS16F64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertS32F16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertS32F32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddU32("{}=u32(i32({}));", inst, value);
|
||||
}
|
||||
|
||||
void EmitConvertS32F64(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddU32("{}=u32(i32({}));", inst, value);
|
||||
}
|
||||
|
||||
void EmitConvertS64F16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertS64F32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddU64("{}=vec2<u32>(u32(i32({})),select(0u,0xffffffffu,{}<0.0f));", inst, value, value);
|
||||
}
|
||||
|
||||
void EmitConvertS64F64(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddU64("{}=vec2<u32>(u32(i32({})),select(0u,0xffffffffu,{}<0.0f));", inst, value, value);
|
||||
}
|
||||
|
||||
void EmitConvertU16F16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertU16F32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertU16F64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertU32F16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertU16U32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertU32U16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertU8U32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertU32U8([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertS32S8([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertS32S16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertU32F32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddU32("{}=u32({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitConvertU32F64(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddU32("{}=u32({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitConvertU64F16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertU64F32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddU64("{}=vec2<u32>(u32({}),0u);", inst, value);
|
||||
}
|
||||
|
||||
void EmitConvertU64F64(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddU64("{}=vec2<u32>(u32({}),0u);", inst, value);
|
||||
}
|
||||
|
||||
void EmitConvertU64U32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddU64("{}=vec2<u32>(u32({}),0u);", inst, value);
|
||||
}
|
||||
|
||||
void EmitConvertU32U64(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddU32("{}={}.x;", inst, value);
|
||||
}
|
||||
|
||||
void EmitConvertF16F32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertF32F16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertF32F64(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddF32("{}=f32({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitConvertF64F32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertF16S8([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertF16S16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertF16S32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertF16S64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertF16U8([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertF16U16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertF16U32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertF16U64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertF32S8([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertF32S16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertF32S32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddF32("{}=f32(i32({}));", inst, value);
|
||||
}
|
||||
|
||||
void EmitConvertF32S64(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddF32("{}=f32(i32({}.x));", inst, value);
|
||||
}
|
||||
|
||||
void EmitConvertF32U8([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertF32U16(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddF32("{}=f32({}&0xffffu);", inst, value);
|
||||
}
|
||||
|
||||
void EmitConvertF32U32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddF32("{}=f32({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitConvertF32U64(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddF32("{}=f32({}.x);", inst, value);
|
||||
}
|
||||
|
||||
void EmitConvertF64S8([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertF64S16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertF64S32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertF64S64(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertF64U8([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertF64U16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertF64U32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitConvertF64U64(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
} // namespace Shader::Backend::WGSL
|
||||
489
gpu/third_party/suyu/shader_recompiler/backend/wgsl/emit_wgsl_floating_point.cpp
vendored
Normal file
489
gpu/third_party/suyu/shader_recompiler/backend/wgsl/emit_wgsl_floating_point.cpp
vendored
Normal file
@@ -0,0 +1,489 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <cctype>
|
||||
#include <cmath>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
#include "shader_recompiler/backend/wgsl/emit_wgsl_instructions.h"
|
||||
#include "shader_recompiler/backend/wgsl/wgsl_emit_context.h"
|
||||
#include "shader_recompiler/frontend/ir/modifiers.h"
|
||||
#include "shader_recompiler/frontend/ir/value.h"
|
||||
|
||||
namespace Shader::Backend::WGSL {
|
||||
namespace {
|
||||
/// A literal operand wrapped in rt_(): WGSL would fold the call at shader creation and reject a domain error.
|
||||
std::string Rt(std::string_view v) {
|
||||
const bool literal{!v.empty() && (std::isdigit(static_cast<unsigned char>(v[0])) || v[0] == '-' || v[0] == '.')};
|
||||
return literal ? fmt::format("rt_({})", v) : std::string{v};
|
||||
}
|
||||
|
||||
void Compare(EmitContext& ctx, IR::Inst& inst, std::string_view lhs, std::string_view rhs,
|
||||
std::string_view op, bool ordered) {
|
||||
const auto nan_op{ordered ? "&&!" : "||"};
|
||||
ctx.AddU1("{}={}{}{}"
|
||||
"{}isnan_({}){}isnan_({});",
|
||||
inst, lhs, op, rhs, nan_op, lhs, nan_op, rhs);
|
||||
}
|
||||
|
||||
bool IsPrecise(const IR::Inst& inst) {
|
||||
return inst.Flags<IR::FpControl>().no_contraction;
|
||||
}
|
||||
|
||||
/// A float literal operand of magnitude below 1e-6 (an epsilon guarding a division or a logarithm).
|
||||
bool IsEpsilon(std::string_view v) {
|
||||
if (v.size() < 2 || v.back() != 'f') return false;
|
||||
const char c{v[0]};
|
||||
if (!std::isdigit(static_cast<unsigned char>(c)) && c != '-' && c != '.') return false;
|
||||
try {
|
||||
const float f{std::stof(std::string{v.substr(0, v.size() - 1)})};
|
||||
return f != 0.0f && std::fabs(f) < 1e-6f;
|
||||
} catch (...) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} // Anonymous namespace
|
||||
|
||||
void EmitFPAbs16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitFPAbs32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddF32("{}=abs({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitFPAbs64(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddF64("{}=abs({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitFPAdd16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view a, [[maybe_unused]] std::string_view b) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitFPAdd32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
|
||||
// x + epsilon: x is made opaque, so that the host compiler cannot fold the epsilon into an earlier constant
|
||||
if (IsEpsilon(b) && !IsEpsilon(a)) {
|
||||
ctx.AddF32("{}=opq_({})+{};", inst, a, b);
|
||||
return;
|
||||
}
|
||||
if (IsEpsilon(a) && !IsEpsilon(b)) {
|
||||
ctx.AddF32("{}={}+opq_({});", inst, a, b);
|
||||
return;
|
||||
}
|
||||
if (IsPrecise(inst)) {
|
||||
ctx.AddPrecF32("{}={}+{};", inst, a, b);
|
||||
} else {
|
||||
ctx.AddF32("{}={}+{};", inst, a, b);
|
||||
}
|
||||
}
|
||||
|
||||
void EmitFPAdd64(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
|
||||
if (IsPrecise(inst)) {
|
||||
ctx.AddPrecF64("{}={}+{};", inst, a, b);
|
||||
} else {
|
||||
ctx.AddF64("{}={}+{};", inst, a, b);
|
||||
}
|
||||
}
|
||||
|
||||
void EmitFPFma16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view a, [[maybe_unused]] std::string_view b,
|
||||
[[maybe_unused]] std::string_view c) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitFPFma32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b,
|
||||
std::string_view c) {
|
||||
if (IsPrecise(inst)) {
|
||||
ctx.AddPrecF32("{}=fma({},{},{});", inst, a, b, c);
|
||||
} else {
|
||||
ctx.AddF32("{}=fma({},{},{});", inst, a, b, c);
|
||||
}
|
||||
}
|
||||
|
||||
void EmitFPFma64(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b,
|
||||
std::string_view c) {
|
||||
if (IsPrecise(inst)) {
|
||||
ctx.AddPrecF64("{}=fma({},{},{});", inst, a, b, c);
|
||||
} else {
|
||||
ctx.AddF64("{}=fma({},{},{});", inst, a, b, c);
|
||||
}
|
||||
}
|
||||
|
||||
void EmitFPMax32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
|
||||
ctx.AddF32("{}=max({},{});", inst, a, b);
|
||||
}
|
||||
|
||||
void EmitFPMax64(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
|
||||
ctx.AddF64("{}=max({},{});", inst, a, b);
|
||||
}
|
||||
|
||||
void EmitFPMin32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
|
||||
ctx.AddF32("{}=min({},{});", inst, a, b);
|
||||
}
|
||||
|
||||
void EmitFPMin64(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
|
||||
ctx.AddF64("{}=min({},{});", inst, a, b);
|
||||
}
|
||||
|
||||
void EmitFPMul16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view a, [[maybe_unused]] std::string_view b) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitFPMul32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
|
||||
if (IsPrecise(inst)) {
|
||||
ctx.AddPrecF32("{}={}*{};", inst, a, b);
|
||||
} else {
|
||||
ctx.AddF32("{}={}*{};", inst, a, b);
|
||||
}
|
||||
}
|
||||
|
||||
void EmitFPMul64(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
|
||||
if (IsPrecise(inst)) {
|
||||
ctx.AddPrecF64("{}={}*{};", inst, a, b);
|
||||
} else {
|
||||
ctx.AddF64("{}={}*{};", inst, a, b);
|
||||
}
|
||||
}
|
||||
|
||||
void EmitFPNeg16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitFPNeg32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddF32("{}=0.f-({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitFPNeg64(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddF64("{}=double(0.)-({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitFPSin(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddF32("{}=sin({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitFPCos(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddF32("{}=cos({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitFPExp2(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
// Maxwell's EX2 takes its input through RRO (a fixed-point range reduction) where NaN becomes 0: pow(0, 0)
|
||||
// compiled as exp2(0 * log2(0)) is 1 there, NaN on PC GPUs (TOTK sky islands: white blobs in the lighting)
|
||||
ctx.AddF32("{}=exp2(lodok_({}));", inst, Rt(value));
|
||||
}
|
||||
|
||||
void EmitFPLog2(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddF32("{}=log2({});", inst, Rt(value));
|
||||
}
|
||||
|
||||
void EmitFPRecip32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddF32("{}=(1.0f)/{};", inst, Rt(value));
|
||||
}
|
||||
|
||||
void EmitFPRecip64(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddF64("{}=1.0/{};", inst, value);
|
||||
}
|
||||
|
||||
void EmitFPRecipSqrt32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
ctx.AddF32("{}=inverseSqrt({});", inst, Rt(value));
|
||||
}
|
||||
|
||||
void EmitFPRecipSqrt64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitFPSqrt(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddF32("{}=sqrt({});", inst, Rt(value));
|
||||
}
|
||||
|
||||
void EmitFPSaturate16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitFPSaturate32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
// Maxwell's .SAT makes NaN 0 (the frontend's FMZ emulation relies on it); WGSL's max(NaN, 0) may be NaN
|
||||
ctx.AddF32("{0}=select(min(max({1},0.0),1.0),0.0,isnan_({1}));", inst, value);
|
||||
}
|
||||
|
||||
void EmitFPSaturate64(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddF64("{}=min(max({},0.0),1.0);", inst, value);
|
||||
}
|
||||
|
||||
void EmitFPClamp16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value,
|
||||
[[maybe_unused]] std::string_view min_value,
|
||||
[[maybe_unused]] std::string_view max_value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitFPClamp32(EmitContext& ctx, IR::Inst& inst, std::string_view value,
|
||||
std::string_view min_value, std::string_view max_value) {
|
||||
// GLSL's clamp does not produce desirable results
|
||||
ctx.AddF32("{}=min(max({},f32({})),f32({}));", inst, value, min_value, max_value);
|
||||
}
|
||||
|
||||
void EmitFPClamp64(EmitContext& ctx, IR::Inst& inst, std::string_view value,
|
||||
std::string_view min_value, std::string_view max_value) {
|
||||
// GLSL's clamp does not produce desirable results
|
||||
ctx.AddF64("{}=min(max({},double({})),double({}));", inst, value, min_value, max_value);
|
||||
}
|
||||
|
||||
void EmitFPRoundEven16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitFPRoundEven32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddF32("{}=round({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitFPRoundEven64(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddF64("{}=round({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitFPFloor16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitFPFloor32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddF32("{}=floor({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitFPFloor64(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddF64("{}=floor({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitFPCeil16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitFPCeil32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddF32("{}=ceil({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitFPCeil64(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddF64("{}=ceil({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitFPTrunc16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitFPTrunc32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddF32("{}=trunc({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitFPTrunc64(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddF64("{}=trunc({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitFPOrdEqual16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view lhs,
|
||||
[[maybe_unused]] std::string_view rhs) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitFPOrdEqual32(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs) {
|
||||
Compare(ctx, inst, lhs, rhs, "==", true);
|
||||
}
|
||||
|
||||
void EmitFPOrdEqual64(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs) {
|
||||
Compare(ctx, inst, lhs, rhs, "==", true);
|
||||
}
|
||||
|
||||
void EmitFPUnordEqual16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view lhs,
|
||||
[[maybe_unused]] std::string_view rhs) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitFPUnordEqual32(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs) {
|
||||
Compare(ctx, inst, lhs, rhs, "==", false);
|
||||
}
|
||||
|
||||
void EmitFPUnordEqual64(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs) {
|
||||
Compare(ctx, inst, lhs, rhs, "==", false);
|
||||
}
|
||||
|
||||
void EmitFPOrdNotEqual16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view lhs,
|
||||
[[maybe_unused]] std::string_view rhs) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitFPOrdNotEqual32(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs) {
|
||||
Compare(ctx, inst, lhs, rhs, "!=", true);
|
||||
}
|
||||
|
||||
void EmitFPOrdNotEqual64(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs) {
|
||||
Compare(ctx, inst, lhs, rhs, "!=", true);
|
||||
}
|
||||
|
||||
void EmitFPUnordNotEqual16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view lhs,
|
||||
[[maybe_unused]] std::string_view rhs) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitFPUnordNotEqual32(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs) {
|
||||
Compare(ctx, inst, lhs, rhs, "!=", false);
|
||||
}
|
||||
|
||||
void EmitFPUnordNotEqual64(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs) {
|
||||
Compare(ctx, inst, lhs, rhs, "!=", false);
|
||||
}
|
||||
|
||||
void EmitFPOrdLessThan16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view lhs,
|
||||
[[maybe_unused]] std::string_view rhs) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitFPOrdLessThan32(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs) {
|
||||
Compare(ctx, inst, lhs, rhs, "<", true);
|
||||
}
|
||||
|
||||
void EmitFPOrdLessThan64(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs) {
|
||||
Compare(ctx, inst, lhs, rhs, "<", true);
|
||||
}
|
||||
|
||||
void EmitFPUnordLessThan16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view lhs,
|
||||
[[maybe_unused]] std::string_view rhs) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitFPUnordLessThan32(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs) {
|
||||
Compare(ctx, inst, lhs, rhs, "<", false);
|
||||
}
|
||||
|
||||
void EmitFPUnordLessThan64(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs) {
|
||||
Compare(ctx, inst, lhs, rhs, "<", false);
|
||||
}
|
||||
|
||||
void EmitFPOrdGreaterThan16([[maybe_unused]] EmitContext& ctx,
|
||||
[[maybe_unused]] std::string_view lhs,
|
||||
[[maybe_unused]] std::string_view rhs) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitFPOrdGreaterThan32(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs) {
|
||||
Compare(ctx, inst, lhs, rhs, ">", true);
|
||||
}
|
||||
|
||||
void EmitFPOrdGreaterThan64(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs) {
|
||||
Compare(ctx, inst, lhs, rhs, ">", true);
|
||||
}
|
||||
|
||||
void EmitFPUnordGreaterThan16([[maybe_unused]] EmitContext& ctx,
|
||||
[[maybe_unused]] std::string_view lhs,
|
||||
[[maybe_unused]] std::string_view rhs) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitFPUnordGreaterThan32(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs) {
|
||||
Compare(ctx, inst, lhs, rhs, ">", false);
|
||||
}
|
||||
|
||||
void EmitFPUnordGreaterThan64(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs) {
|
||||
Compare(ctx, inst, lhs, rhs, ">", false);
|
||||
}
|
||||
|
||||
void EmitFPOrdLessThanEqual16([[maybe_unused]] EmitContext& ctx,
|
||||
[[maybe_unused]] std::string_view lhs,
|
||||
[[maybe_unused]] std::string_view rhs) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitFPOrdLessThanEqual32(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs) {
|
||||
Compare(ctx, inst, lhs, rhs, "<=", true);
|
||||
}
|
||||
|
||||
void EmitFPOrdLessThanEqual64(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs) {
|
||||
Compare(ctx, inst, lhs, rhs, "<=", true);
|
||||
}
|
||||
|
||||
void EmitFPUnordLessThanEqual16([[maybe_unused]] EmitContext& ctx,
|
||||
[[maybe_unused]] std::string_view lhs,
|
||||
[[maybe_unused]] std::string_view rhs) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitFPUnordLessThanEqual32(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs) {
|
||||
Compare(ctx, inst, lhs, rhs, "<=", false);
|
||||
}
|
||||
|
||||
void EmitFPUnordLessThanEqual64(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs) {
|
||||
Compare(ctx, inst, lhs, rhs, "<=", false);
|
||||
}
|
||||
|
||||
void EmitFPOrdGreaterThanEqual16([[maybe_unused]] EmitContext& ctx,
|
||||
[[maybe_unused]] std::string_view lhs,
|
||||
[[maybe_unused]] std::string_view rhs) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitFPOrdGreaterThanEqual32(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs) {
|
||||
Compare(ctx, inst, lhs, rhs, ">=", true);
|
||||
}
|
||||
|
||||
void EmitFPOrdGreaterThanEqual64(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs) {
|
||||
Compare(ctx, inst, lhs, rhs, ">=", true);
|
||||
}
|
||||
|
||||
void EmitFPUnordGreaterThanEqual16([[maybe_unused]] EmitContext& ctx,
|
||||
[[maybe_unused]] std::string_view lhs,
|
||||
[[maybe_unused]] std::string_view rhs) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitFPUnordGreaterThanEqual32(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs) {
|
||||
Compare(ctx, inst, lhs, rhs, ">=", false);
|
||||
}
|
||||
|
||||
void EmitFPUnordGreaterThanEqual64(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs) {
|
||||
Compare(ctx, inst, lhs, rhs, ">=", false);
|
||||
}
|
||||
|
||||
void EmitFPIsNan16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitFPIsNan32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddU1("{}=isnan_({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitFPIsNan64(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddU1("{}=isnan_({});", inst, value);
|
||||
}
|
||||
|
||||
} // namespace Shader::Backend::WGSL
|
||||
644
gpu/third_party/suyu/shader_recompiler/backend/wgsl/emit_wgsl_image.cpp
vendored
Normal file
644
gpu/third_party/suyu/shader_recompiler/backend/wgsl/emit_wgsl_image.cpp
vendored
Normal file
@@ -0,0 +1,644 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
//
|
||||
// WGSL backend (Rexcomp): texture and image instructions, rewritten for WGSL's separate texture/sampler model.
|
||||
|
||||
#include <cstdlib>
|
||||
#include <string_view>
|
||||
|
||||
#include "shader_recompiler/backend/wgsl/emit_wgsl_instructions.h"
|
||||
#include "shader_recompiler/backend/wgsl/wgsl_emit_context.h"
|
||||
#include "shader_recompiler/frontend/ir/modifiers.h"
|
||||
#include "shader_recompiler/frontend/ir/value.h"
|
||||
#include "shader_recompiler/profile.h"
|
||||
|
||||
namespace Shader::Backend::WGSL {
|
||||
namespace {
|
||||
const TextureImageDefinition& TextureDef(EmitContext& ctx, const IR::TextureInstInfo& info) {
|
||||
if (info.type == TextureType::Buffer) {
|
||||
throw NotImplementedException("WGSL texture buffers");
|
||||
}
|
||||
return ctx.textures.at(info.descriptor_index);
|
||||
}
|
||||
|
||||
/// "texN,sampN": the texture and its sampler
|
||||
std::string TexSamp(EmitContext& ctx, const IR::TextureInstInfo& info) {
|
||||
const auto& def{TextureDef(ctx, info)};
|
||||
return fmt::format("tex{},samp{}", def.binding, def.textures_sampler_binding());
|
||||
}
|
||||
|
||||
std::string Tex(EmitContext& ctx, const IR::TextureInstInfo& info) {
|
||||
return fmt::format("tex{}", TextureDef(ctx, info).binding);
|
||||
}
|
||||
|
||||
std::string Swizzled(EmitContext& ctx, const IR::TextureInstInfo& info, const std::string& expression) {
|
||||
return fmt::format("swizzle{}({})", TextureDef(ctx, info).binding, expression);
|
||||
}
|
||||
|
||||
/// The normalized coordinates a border test looks at (xyz; axes the texture type has not are inside), or "" when
|
||||
/// the type has no border (cubes, unnormalized coordinates).
|
||||
std::string BorderCoords(const IR::TextureInstInfo& info, std::string_view c) {
|
||||
switch (info.type) {
|
||||
case TextureType::Color1D: return fmt::format("vec3<f32>(f32({}),0.5,0.5)", c);
|
||||
case TextureType::Color2D:
|
||||
case TextureType::ColorArray2D: return fmt::format("vec3<f32>({}.xy,0.5)", c);
|
||||
case TextureType::Color3D: return fmt::format("vec3<f32>({}.xyz)", c);
|
||||
default: return "";
|
||||
}
|
||||
}
|
||||
|
||||
/// A sampled color with the sampler's border color outside [0, 1] on its border axes.
|
||||
std::string Bordered(EmitContext& ctx, const IR::TextureInstInfo& info, std::string_view coords,
|
||||
const std::string& expression) {
|
||||
const auto bc{BorderCoords(info, coords)};
|
||||
if (bc.empty()) {
|
||||
return expression;
|
||||
}
|
||||
return fmt::format("border{}({},{})", TextureDef(ctx, info).binding, bc, expression);
|
||||
}
|
||||
|
||||
/// A depth comparison's reference, clamped to [0, 1] as the console compares it. WebGPU (Vulkan) clamps it only for a
|
||||
/// UNORM depth texture: against a float one a point just past a shadow cascade's far plane compared 1.0x <= 1.0 and
|
||||
/// fell into shadow. TOTK's moonlight cascades end within view: dark bands across the ground at night, moving with the
|
||||
/// camera (gone with the clamp, 2026-10-28). RX_NO_DREF_CLAMP=1: the reference as computed (debugging).
|
||||
/// Against an array texture (TOTK's shadow cascades: D16 arrays) the reference is also rounded to 16 bits, as Maxwell
|
||||
/// compares at the texture's precision: a driver that compares the full float (AMD's) left a lit face failing its own
|
||||
/// compare by a fraction of a step, shadowed (totk-pc-recomp 6029719 / MacNativeGames 6283599, MIT).
|
||||
/// RX_NO_D16_DREF=1: not rounded.
|
||||
std::string Dref(std::string_view dref, bool array = false) {
|
||||
static const bool no_clamp{std::getenv("RX_NO_DREF_CLAMP") != nullptr};
|
||||
static const bool no_d16{std::getenv("RX_NO_D16_DREF") != nullptr};
|
||||
if (no_clamp) return std::string{dref};
|
||||
if (array && !no_d16) return fmt::format("(floor(clamp({},0.0,1.0)*65535.0+0.5)/65535.0)", dref);
|
||||
return fmt::format("clamp({},0.0,1.0)", dref);
|
||||
}
|
||||
|
||||
/// The same for a depth comparison: outside, the reference is compared with the border depth.
|
||||
std::string BorderedCompare(EmitContext& ctx, const IR::TextureInstInfo& info, std::string_view coords,
|
||||
std::string_view dref, const std::string& expression) {
|
||||
const auto bc{BorderCoords(info, coords)};
|
||||
if (bc.empty()) {
|
||||
return expression;
|
||||
}
|
||||
return fmt::format("bordercmp{}({},{},{})", TextureDef(ctx, info).binding, bc, dref, expression);
|
||||
}
|
||||
|
||||
std::string Image(EmitContext& ctx, const IR::TextureInstInfo& info) {
|
||||
if (info.type == TextureType::Buffer) {
|
||||
throw NotImplementedException("WGSL image buffers");
|
||||
}
|
||||
return fmt::format("img{}", ctx.images.at(info.descriptor_index).binding);
|
||||
}
|
||||
|
||||
bool IsArray(const IR::TextureInstInfo& info) {
|
||||
return info.type == TextureType::ColorArray2D || info.type == TextureType::ColorArrayCube;
|
||||
}
|
||||
|
||||
/// Sampling coordinates, with the array layer as WGSL's separate argument.
|
||||
std::string SampleCoords(const IR::TextureInstInfo& info, std::string_view c) {
|
||||
switch (info.type) {
|
||||
case TextureType::Color1D:
|
||||
case TextureType::Color2D:
|
||||
case TextureType::Color2DRect:
|
||||
case TextureType::Color3D:
|
||||
case TextureType::ColorCube:
|
||||
return std::string{c};
|
||||
case TextureType::ColorArray2D:
|
||||
return fmt::format("{}.xy,i32({}.z)", c, c);
|
||||
case TextureType::ColorArrayCube:
|
||||
return fmt::format("{}.xyz,i32({}.w)", c, c);
|
||||
default:
|
||||
throw NotImplementedException("WGSL sampling of texture type {}", info.type.Value());
|
||||
}
|
||||
}
|
||||
|
||||
/// Integer coordinates for textureLoad/textureStore (u32 inputs), with the array layer separate; `offset` (an
|
||||
/// i32 vector expression or empty) is added to the texel coordinates.
|
||||
std::string LoadCoords(const IR::TextureInstInfo& info, std::string_view c, std::string_view offset = {}) {
|
||||
const auto add{offset.empty() ? std::string{} : fmt::format("+{}", offset)};
|
||||
switch (info.type) {
|
||||
case TextureType::Color1D:
|
||||
return fmt::format("i32({}){}", c, add);
|
||||
case TextureType::Color2D:
|
||||
case TextureType::Color2DRect:
|
||||
return fmt::format("vec2<i32>({}){}", c, add);
|
||||
case TextureType::ColorArray2D:
|
||||
return fmt::format("vec2<i32>({}.xy){},i32({}.z)", c, add, c);
|
||||
case TextureType::Color3D:
|
||||
return fmt::format("vec3<i32>({}){}", c, add);
|
||||
default:
|
||||
throw NotImplementedException("WGSL texel loads of texture type {}", info.type.Value());
|
||||
}
|
||||
}
|
||||
|
||||
bool OffsetAllowed(const IR::TextureInstInfo& info) {
|
||||
switch (info.type) {
|
||||
case TextureType::Color2D:
|
||||
case TextureType::Color2DRect:
|
||||
case TextureType::ColorArray2D:
|
||||
case TextureType::Color3D:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// A texel offset as a WGSL constant expression (WGSL requires one), or "" when there is none or it is not constant.
|
||||
std::string ConstOffset(const IR::Value& offset) {
|
||||
if (offset.IsEmpty()) {
|
||||
return "";
|
||||
}
|
||||
if (offset.IsImmediate()) {
|
||||
return fmt::format("{}", static_cast<s32>(offset.U32()));
|
||||
}
|
||||
IR::Inst* const inst{offset.InstRecursive()};
|
||||
if (inst->AreAllArgsImmediates()) {
|
||||
switch (inst->GetOpcode()) {
|
||||
case IR::Opcode::CompositeConstructU32x2:
|
||||
return fmt::format("vec2<i32>({},{})", static_cast<s32>(inst->Arg(0).U32()),
|
||||
static_cast<s32>(inst->Arg(1).U32()));
|
||||
case IR::Opcode::CompositeConstructU32x3:
|
||||
return fmt::format("vec3<i32>({},{},{})", static_cast<s32>(inst->Arg(0).U32()),
|
||||
static_cast<s32>(inst->Arg(1).U32()), static_cast<s32>(inst->Arg(2).U32()));
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
LOG_WARNING(Shader_WGSL, "Variable texture offset dropped (WGSL offsets are constants)");
|
||||
return "";
|
||||
}
|
||||
|
||||
/// ",offset" for a sampling call, when the texture type takes one
|
||||
std::string SampleOffsetArg(const IR::TextureInstInfo& info, const IR::Value& offset) {
|
||||
const auto o{ConstOffset(offset)};
|
||||
if (o.empty() && !offset.IsEmpty()) return "/*VAROFFSET*/";
|
||||
return o.empty() || !OffsetAllowed(info) ? "" : "," + o;
|
||||
}
|
||||
|
||||
/// A texel offset as an i32 vector expression for textureLoad (variable offsets are fine here).
|
||||
std::string LoadOffset(EmitContext& ctx, const IR::TextureInstInfo& info, const IR::Value& offset) {
|
||||
if (offset.IsEmpty()) {
|
||||
return "";
|
||||
}
|
||||
const auto o{ConstOffset(offset)};
|
||||
if (!o.empty()) {
|
||||
return o;
|
||||
}
|
||||
const auto v{ctx.var_alloc.Consume(offset)};
|
||||
switch (info.type) {
|
||||
case TextureType::Color1D:
|
||||
return fmt::format("i32({})", v);
|
||||
case TextureType::Color3D:
|
||||
return fmt::format("vec3<i32>({})", v);
|
||||
default:
|
||||
return fmt::format("vec2<i32>({})", v);
|
||||
}
|
||||
}
|
||||
|
||||
IR::Inst* PrepareSparse(EmitContext& ctx, IR::Inst& inst) {
|
||||
IR::Inst* const sparse_inst{inst.GetAssociatedPseudoOperation(IR::Opcode::GetSparseFromOp)};
|
||||
if (sparse_inst) {
|
||||
// WebGPU has no sparse residency: every texel is resident
|
||||
ctx.AddU1("{}=true;", *sparse_inst);
|
||||
sparse_inst->Invalidate();
|
||||
}
|
||||
return sparse_inst;
|
||||
}
|
||||
} // Anonymous namespace
|
||||
|
||||
void EmitImageSampleImplicitLod(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords, std::string_view bias_lc,
|
||||
const IR::Value& offset) {
|
||||
const auto info{inst.Flags<IR::TextureInstInfo>()};
|
||||
if (info.has_lod_clamp) {
|
||||
throw NotImplementedException("EmitImageSampleImplicitLod Lod clamp samples");
|
||||
}
|
||||
(void)index;
|
||||
PrepareSparse(ctx, inst);
|
||||
const auto ts{TexSamp(ctx, info)};
|
||||
const auto c{SampleCoords(info, coords)};
|
||||
const auto o{SampleOffsetArg(info, offset)};
|
||||
// the sampler's LOD bias (lodbiasN, from the uniform block) is added: WebGPU samplers have none
|
||||
const auto lb{fmt::format("lodbias{}()", TextureDef(ctx, info).binding)};
|
||||
if (ctx.stage != Stage::Fragment) {
|
||||
ctx.AddF32x4("{}={};", inst, Bordered(ctx, info, coords, Swizzled(ctx, info, fmt::format("textureSampleLevel({},{},{}{})", ts, c, lb, o))));
|
||||
} else if (info.has_bias) {
|
||||
ctx.AddF32x4("{}={};", inst, Bordered(ctx, info, coords, Swizzled(ctx, info, fmt::format("textureSampleBias({},{},lodok_({}+{}){})", ts, c, bias_lc, lb, o))));
|
||||
} else if (info.type == TextureType::Color1D) {
|
||||
ctx.AddF32x4("{}={};", inst, Bordered(ctx, info, coords, Swizzled(ctx, info, fmt::format("textureSample({},{}{})", ts, c, o))));
|
||||
} else {
|
||||
ctx.AddF32x4("{}={};", inst, Bordered(ctx, info, coords, Swizzled(ctx, info, fmt::format("textureSampleBias({},{},{}{})", ts, c, lb, o))));
|
||||
}
|
||||
}
|
||||
|
||||
void EmitImageSampleExplicitLod(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords, std::string_view lod_lc,
|
||||
const IR::Value& offset) {
|
||||
const auto info{inst.Flags<IR::TextureInstInfo>()};
|
||||
if (info.has_bias) {
|
||||
throw NotImplementedException("EmitImageSampleExplicitLod Bias texture samples");
|
||||
}
|
||||
if (info.has_lod_clamp) {
|
||||
throw NotImplementedException("EmitImageSampleExplicitLod Lod clamp samples");
|
||||
}
|
||||
(void)index;
|
||||
PrepareSparse(ctx, inst);
|
||||
ctx.AddF32x4("{}={};", inst, Bordered(ctx, info, coords, Swizzled(ctx, info, fmt::format("textureSampleLevel({},{},lodok_({}+lodbias{}()){})",
|
||||
TexSamp(ctx, info), SampleCoords(info, coords), lod_lc, TextureDef(ctx, info).binding,
|
||||
SampleOffsetArg(info, offset)))));
|
||||
}
|
||||
|
||||
void EmitImageSampleDrefImplicitLod(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords, std::string_view dref,
|
||||
std::string_view bias_lc, const IR::Value& offset) {
|
||||
const auto info{inst.Flags<IR::TextureInstInfo>()};
|
||||
if (info.has_lod_clamp) {
|
||||
throw NotImplementedException("EmitImageSampleDrefImplicitLod Lod clamp samples");
|
||||
}
|
||||
(void)index;
|
||||
(void)bias_lc;
|
||||
PrepareSparse(ctx, inst);
|
||||
const auto fn{ctx.stage == Stage::Fragment ? "textureSampleCompare" : "textureSampleCompareLevel"};
|
||||
const auto d{Dref(dref, IsArray(info))};
|
||||
ctx.AddF32("{}={};", inst, BorderedCompare(ctx, info, coords, d, fmt::format("{}({},{},{}{})", fn,
|
||||
TexSamp(ctx, info), SampleCoords(info, coords), d, SampleOffsetArg(info, offset))));
|
||||
}
|
||||
|
||||
void EmitImageSampleDrefExplicitLod(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords, std::string_view dref,
|
||||
std::string_view lod_lc, const IR::Value& offset) {
|
||||
const auto info{inst.Flags<IR::TextureInstInfo>()};
|
||||
if (info.has_lod_clamp) {
|
||||
throw NotImplementedException("EmitImageSampleDrefExplicitLod Lod clamp samples");
|
||||
}
|
||||
(void)index;
|
||||
(void)lod_lc; // WGSL compares at level 0 only
|
||||
PrepareSparse(ctx, inst);
|
||||
const auto d{Dref(dref, IsArray(info))};
|
||||
ctx.AddF32("{}={};", inst, BorderedCompare(ctx, info, coords, d, fmt::format("textureSampleCompareLevel({},{},{}{})",
|
||||
TexSamp(ctx, info), SampleCoords(info, coords), d, SampleOffsetArg(info, offset))));
|
||||
}
|
||||
|
||||
void EmitImageGather(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords, const IR::Value& offset, const IR::Value& offset2) {
|
||||
const auto info{inst.Flags<IR::TextureInstInfo>()};
|
||||
(void)index;
|
||||
if (!offset2.IsEmpty()) ctx.Add("/*PTP*/"); // per-texel offsets (PTP): WGSL has none; the first offset is used
|
||||
PrepareSparse(ctx, inst);
|
||||
const bool depth{ctx.info.texture_descriptors.at(info.descriptor_index).is_depth};
|
||||
const auto component{depth ? std::string{} : fmt::format("{},", info.gather_component)};
|
||||
// A gather at a texel's center sits on the edge between two footprints: the game uses .w of such a gather as a
|
||||
// point fetch (TOTK's half-resolution lighting upsample), so 1/256 of a texel decides the footprint the way
|
||||
// Maxwell's rounding does instead of the interpolation error of the coordinate
|
||||
std::string c{coords};
|
||||
static const bool no_nudge{std::getenv("RX_NO_GATHER_NUDGE") != nullptr}; // (debugging)
|
||||
if (no_nudge) {
|
||||
} else if (info.type == TextureType::Color2D || info.type == TextureType::Color2DRect) {
|
||||
c = fmt::format("({}+vec2<f32>(0.00390625)/vec2<f32>(textureDimensions({},0)))", coords, Tex(ctx, info));
|
||||
} else if (info.type == TextureType::ColorArray2D) {
|
||||
c = fmt::format("vec3<f32>({0}.xy+vec2<f32>(0.00390625)/vec2<f32>(textureDimensions({1},0)),{0}.z)", coords,
|
||||
Tex(ctx, info));
|
||||
}
|
||||
ctx.AddF32x4("{}=textureGather({}{},{}{});", inst, component, TexSamp(ctx, info), SampleCoords(info, c),
|
||||
SampleOffsetArg(info, offset));
|
||||
}
|
||||
|
||||
void EmitImageGatherDref(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords, const IR::Value& offset, const IR::Value& offset2,
|
||||
std::string_view dref) {
|
||||
const auto info{inst.Flags<IR::TextureInstInfo>()};
|
||||
(void)index;
|
||||
(void)offset2;
|
||||
PrepareSparse(ctx, inst);
|
||||
ctx.AddF32x4("{}=textureGatherCompare({},{},{}{});", inst, TexSamp(ctx, info), SampleCoords(info, coords),
|
||||
Dref(dref, IsArray(info)), SampleOffsetArg(info, offset));
|
||||
}
|
||||
|
||||
void EmitImageFetch(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords, const IR::Value& offset, std::string_view lod,
|
||||
std::string_view ms) {
|
||||
const auto info{inst.Flags<IR::TextureInstInfo>()};
|
||||
if (info.has_bias) {
|
||||
throw NotImplementedException("EmitImageFetch Bias texture samples");
|
||||
}
|
||||
if (info.has_lod_clamp) {
|
||||
throw NotImplementedException("EmitImageFetch Lod clamp samples");
|
||||
}
|
||||
(void)index;
|
||||
PrepareSparse(ctx, inst);
|
||||
const auto o{LoadOffset(ctx, info, offset)};
|
||||
const auto c{LoadCoords(info, coords, o)};
|
||||
const bool depth{ctx.info.texture_descriptors.at(info.descriptor_index).is_depth};
|
||||
const auto level{!ms.empty() ? fmt::format("i32({})", ms) : fmt::format("i32({})", lod)};
|
||||
if (depth) {
|
||||
ctx.AddF32x4("{}={};", inst, Swizzled(ctx, info, fmt::format("vec4<f32>(textureLoad({},{},{}),0.0f,0.0f,1.0f)", Tex(ctx, info), c, level)));
|
||||
} else {
|
||||
ctx.AddF32x4("{}={};", inst, Swizzled(ctx, info, fmt::format("textureLoad({},{},{})", Tex(ctx, info), c, level)));
|
||||
}
|
||||
}
|
||||
|
||||
void EmitImageQueryDimensions(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view lod, const IR::Value& skip_mips_val) {
|
||||
const auto info{inst.Flags<IR::TextureInstInfo>()};
|
||||
(void)index;
|
||||
const auto t{Tex(ctx, info)};
|
||||
const bool is_msaa{ctx.info.texture_descriptors.at(info.descriptor_index).is_multisample};
|
||||
const auto mips{skip_mips_val.U1() || is_msaa ? std::string{"0u"} : fmt::format("textureNumLevels({})", t)};
|
||||
const auto dims{is_msaa ? fmt::format("textureDimensions({})", t)
|
||||
: fmt::format("textureDimensions({},u32({}))", t, lod)};
|
||||
switch (info.type) {
|
||||
case TextureType::Color1D:
|
||||
return ctx.AddU32x4("{}=vec4<u32>({},0u,0u,{});", inst, dims, mips);
|
||||
case TextureType::Color2D:
|
||||
case TextureType::Color2DRect:
|
||||
case TextureType::ColorCube:
|
||||
return ctx.AddU32x4("{}=vec4<u32>({},0u,{});", inst, dims, mips);
|
||||
case TextureType::ColorArray2D:
|
||||
case TextureType::ColorArrayCube:
|
||||
return ctx.AddU32x4("{}=vec4<u32>({},textureNumLayers({}),{});", inst, dims, t, mips);
|
||||
case TextureType::Color3D:
|
||||
return ctx.AddU32x4("{}=vec4<u32>({},{});", inst, dims, mips);
|
||||
default:
|
||||
throw NotImplementedException("WGSL dimension query of texture type {}", info.type.Value());
|
||||
}
|
||||
}
|
||||
|
||||
void EmitImageQueryLod(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords) {
|
||||
const auto info{inst.Flags<IR::TextureInstInfo>()};
|
||||
(void)index;
|
||||
if (ctx.stage != Stage::Fragment || (info.type != TextureType::Color2D && info.type != TextureType::ColorArray2D)) {
|
||||
ctx.AddF32x4("{}=vec4<f32>(0.0f);", inst);
|
||||
return;
|
||||
}
|
||||
// WGSL has no textureQueryLod: the level from the screen-space derivatives of the texel coordinates
|
||||
const auto t{Tex(ctx, info)};
|
||||
ctx.AddF32x4("{}=vec4<f32>(vec2<f32>(max(0.5f*log2(max(dot(dpdx({}.xy*vec2<f32>(textureDimensions({},0u))),"
|
||||
"dpdx({}.xy*vec2<f32>(textureDimensions({},0u)))),dot(dpdy({}.xy*vec2<f32>(textureDimensions({},0u))),"
|
||||
"dpdy({}.xy*vec2<f32>(textureDimensions({},0u)))))),0.0f)),0.0f,0.0f);",
|
||||
inst, coords, t, coords, t, coords, t, coords, t);
|
||||
}
|
||||
|
||||
void EmitImageGradient(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords, const IR::Value& derivatives,
|
||||
const IR::Value& offset, [[maybe_unused]] const IR::Value& lod_clamp) {
|
||||
const auto info{inst.Flags<IR::TextureInstInfo>()};
|
||||
if (info.has_lod_clamp) {
|
||||
throw NotImplementedException("EmitImageGradient Lod clamp samples");
|
||||
}
|
||||
(void)index;
|
||||
PrepareSparse(ctx, inst);
|
||||
const auto d{ctx.var_alloc.Consume(derivatives)};
|
||||
const auto ts{TexSamp(ctx, info)};
|
||||
const auto c{SampleCoords(info, coords)};
|
||||
if (info.num_derivatives >= 3) {
|
||||
const auto o{ctx.var_alloc.Consume(offset)};
|
||||
ctx.AddF32x4("{}={};", inst, Swizzled(ctx, info, fmt::format("textureSampleGrad({},{},vec3<f32>({}.xz,{}.x),vec3<f32>({}.yw,{}.y))", ts, c, d, o, d, o)));
|
||||
return;
|
||||
}
|
||||
if (info.num_derivatives == 2) {
|
||||
// (the LOD bias as scaled derivatives)
|
||||
ctx.AddF32x4("{}={};", inst, Bordered(ctx, info, coords, Swizzled(ctx, info, fmt::format("textureSampleGrad({},{},{}.xz*exp2(lodbias{}()),{}.yw*exp2(lodbias{}()){})", ts, c, d,
|
||||
TextureDef(ctx, info).binding, d, TextureDef(ctx, info).binding, SampleOffsetArg(info, offset)))));
|
||||
return;
|
||||
}
|
||||
throw NotImplementedException("WGSL 1D gradient samples");
|
||||
}
|
||||
|
||||
void EmitImageRead(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords) {
|
||||
const auto info{inst.Flags<IR::TextureInstInfo>()};
|
||||
(void)index;
|
||||
PrepareSparse(ctx, inst);
|
||||
// (mkw-recomp) a float or signed image's texels as the program's 32-bit words
|
||||
const u32 kind = ctx.images.at(info.descriptor_index).kind;
|
||||
if (kind == 0) ctx.AddU32x4("{}=textureLoad({},{});", inst, Image(ctx, info), LoadCoords(info, coords));
|
||||
else ctx.AddU32x4("{}=bitcast<vec4<u32>>(textureLoad({},{}));", inst, Image(ctx, info), LoadCoords(info, coords));
|
||||
}
|
||||
|
||||
void EmitImageWrite(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords, std::string_view color) {
|
||||
const auto info{inst.Flags<IR::TextureInstInfo>()};
|
||||
(void)index;
|
||||
const u32 kind = ctx.images.at(info.descriptor_index).kind;
|
||||
ctx.Add("textureStore({},{},{});", Image(ctx, info), LoadCoords(info, coords),
|
||||
kind == 0 ? std::string(color) : fmt::format("bitcast<vec4<{}>>({})", kind == 1 ? "f32" : "i32", color));
|
||||
}
|
||||
|
||||
#define IMAGE_ATOMIC(name) \
|
||||
void EmitImageAtomic##name(EmitContext&, IR::Inst&, const IR::Value&, std::string_view, \
|
||||
std::string_view) { \
|
||||
throw NotImplementedException("WGSL image atomics"); \
|
||||
}
|
||||
IMAGE_ATOMIC(IAdd32)
|
||||
IMAGE_ATOMIC(SMin32)
|
||||
IMAGE_ATOMIC(UMin32)
|
||||
IMAGE_ATOMIC(SMax32)
|
||||
IMAGE_ATOMIC(UMax32)
|
||||
IMAGE_ATOMIC(Inc32)
|
||||
IMAGE_ATOMIC(Dec32)
|
||||
IMAGE_ATOMIC(And32)
|
||||
IMAGE_ATOMIC(Or32)
|
||||
IMAGE_ATOMIC(Xor32)
|
||||
IMAGE_ATOMIC(Exchange32)
|
||||
#undef IMAGE_ATOMIC
|
||||
|
||||
void EmitIsTextureScaled(EmitContext& ctx, IR::Inst& inst, const IR::Value& index) {
|
||||
if (!index.IsImmediate()) {
|
||||
throw NotImplementedException("Non-constant texture rescaling");
|
||||
}
|
||||
ctx.AddU1("{}=(bitcast<u32>(scaling().x)&{}u)!=0u;", inst, 1u << index.U32());
|
||||
}
|
||||
|
||||
void EmitIsImageScaled(EmitContext& ctx, IR::Inst& inst, const IR::Value& index) {
|
||||
if (!index.IsImmediate()) {
|
||||
throw NotImplementedException("Non-constant texture rescaling");
|
||||
}
|
||||
ctx.AddU1("{}=(bitcast<u32>(scaling().y)&{}u)!=0u;", inst, 1u << index.U32());
|
||||
}
|
||||
|
||||
void EmitBindlessImageSampleImplicitLod(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBindlessImageSampleExplicitLod(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBindlessImageSampleDrefImplicitLod(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBindlessImageSampleDrefExplicitLod(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBindlessImageGather(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBindlessImageGatherDref(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBindlessImageFetch(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBindlessImageQueryDimensions(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBindlessImageQueryLod(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBindlessImageGradient(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBindlessImageRead(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBindlessImageWrite(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBoundImageSampleImplicitLod(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBoundImageSampleExplicitLod(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBoundImageSampleDrefImplicitLod(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBoundImageSampleDrefExplicitLod(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBoundImageGather(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBoundImageGatherDref(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBoundImageFetch(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBoundImageQueryDimensions(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBoundImageQueryLod(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBoundImageGradient(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBoundImageRead(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBoundImageWrite(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBindlessImageAtomicIAdd32(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBindlessImageAtomicSMin32(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBindlessImageAtomicUMin32(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBindlessImageAtomicSMax32(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBindlessImageAtomicUMax32(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBindlessImageAtomicInc32(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBindlessImageAtomicDec32(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBindlessImageAtomicAnd32(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBindlessImageAtomicOr32(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBindlessImageAtomicXor32(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBindlessImageAtomicExchange32(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBoundImageAtomicIAdd32(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBoundImageAtomicSMin32(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBoundImageAtomicUMin32(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBoundImageAtomicSMax32(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBoundImageAtomicUMax32(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBoundImageAtomicInc32(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBoundImageAtomicDec32(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBoundImageAtomicAnd32(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBoundImageAtomicOr32(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBoundImageAtomicXor32(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitBoundImageAtomicExchange32(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
} // namespace Shader::Backend::WGSL
|
||||
753
gpu/third_party/suyu/shader_recompiler/backend/wgsl/emit_wgsl_instructions.h
vendored
Normal file
753
gpu/third_party/suyu/shader_recompiler/backend/wgsl/emit_wgsl_instructions.h
vendored
Normal file
@@ -0,0 +1,753 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2025 suyu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string_view>
|
||||
|
||||
#include "common/common_types.h"
|
||||
|
||||
namespace Shader::IR {
|
||||
enum class Attribute : u64;
|
||||
enum class Patch : u64;
|
||||
class Inst;
|
||||
class Value;
|
||||
} // namespace Shader::IR
|
||||
|
||||
namespace Shader::Backend::WGSL {
|
||||
class EmitContext;
|
||||
|
||||
#define NotImplemented() throw NotImplementedException("GLSL instruction {}", __func__)
|
||||
|
||||
// Microinstruction emitters
|
||||
void EmitPhi(EmitContext& ctx, IR::Inst& inst);
|
||||
void EmitVoid(EmitContext& ctx);
|
||||
void EmitIdentity(EmitContext& ctx, IR::Inst& inst, const IR::Value& value);
|
||||
void EmitConditionRef(EmitContext& ctx, IR::Inst& inst, const IR::Value& value);
|
||||
void EmitReference(EmitContext& ctx, const IR::Value& value);
|
||||
void EmitPhiMove(EmitContext& ctx, const IR::Value& phi, const IR::Value& value);
|
||||
void EmitJoin(EmitContext& ctx);
|
||||
void EmitDemoteToHelperInvocation(EmitContext& ctx);
|
||||
void EmitBarrier(EmitContext& ctx);
|
||||
void EmitWorkgroupMemoryBarrier(EmitContext& ctx);
|
||||
void EmitDeviceMemoryBarrier(EmitContext& ctx);
|
||||
void EmitPrologue(EmitContext& ctx);
|
||||
void EmitEpilogue(EmitContext& ctx);
|
||||
void EmitEmitVertex(EmitContext& ctx, const IR::Value& stream);
|
||||
void EmitEndPrimitive(EmitContext& ctx, const IR::Value& stream);
|
||||
void EmitGetRegister(EmitContext& ctx);
|
||||
void EmitSetRegister(EmitContext& ctx);
|
||||
void EmitGetPred(EmitContext& ctx);
|
||||
void EmitSetPred(EmitContext& ctx);
|
||||
void EmitSetGotoVariable(EmitContext& ctx);
|
||||
void EmitGetGotoVariable(EmitContext& ctx);
|
||||
void EmitSetIndirectBranchVariable(EmitContext& ctx);
|
||||
void EmitGetIndirectBranchVariable(EmitContext& ctx);
|
||||
void EmitGetCbufU8(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset);
|
||||
void EmitGetCbufS8(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset);
|
||||
void EmitGetCbufU16(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset);
|
||||
void EmitGetCbufS16(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset);
|
||||
void EmitGetCbufU32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset);
|
||||
void EmitGetCbufF32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset);
|
||||
void EmitGetCbufU32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset);
|
||||
void EmitGetAttribute(EmitContext& ctx, IR::Inst& inst, IR::Attribute attr,
|
||||
std::string_view vertex);
|
||||
void EmitGetAttributeU32(EmitContext& ctx, IR::Inst& inst, IR::Attribute attr,
|
||||
std::string_view vertex);
|
||||
void EmitSetAttribute(EmitContext& ctx, IR::Attribute attr, std::string_view value,
|
||||
std::string_view vertex);
|
||||
void EmitGetAttributeIndexed(EmitContext& ctx, IR::Inst& inst, std::string_view offset,
|
||||
std::string_view vertex);
|
||||
void EmitSetAttributeIndexed(EmitContext& ctx, std::string_view offset, std::string_view value,
|
||||
std::string_view vertex);
|
||||
void EmitGetPatch(EmitContext& ctx, IR::Inst& inst, IR::Patch patch);
|
||||
void EmitSetPatch(EmitContext& ctx, IR::Patch patch, std::string_view value);
|
||||
void EmitSetFragColor(EmitContext& ctx, u32 index, u32 component, std::string_view value);
|
||||
void EmitSetSampleMask(EmitContext& ctx, std::string_view value);
|
||||
void EmitSetFragDepth(EmitContext& ctx, std::string_view value);
|
||||
void EmitGetZFlag(EmitContext& ctx);
|
||||
void EmitGetSFlag(EmitContext& ctx);
|
||||
void EmitGetCFlag(EmitContext& ctx);
|
||||
void EmitGetOFlag(EmitContext& ctx);
|
||||
void EmitSetZFlag(EmitContext& ctx);
|
||||
void EmitSetSFlag(EmitContext& ctx);
|
||||
void EmitSetCFlag(EmitContext& ctx);
|
||||
void EmitSetOFlag(EmitContext& ctx);
|
||||
void EmitWorkgroupId(EmitContext& ctx, IR::Inst& inst);
|
||||
void EmitLocalInvocationId(EmitContext& ctx, IR::Inst& inst);
|
||||
void EmitInvocationId(EmitContext& ctx, IR::Inst& inst);
|
||||
void EmitInvocationInfo(EmitContext& ctx, IR::Inst& inst);
|
||||
void EmitSampleId(EmitContext& ctx, IR::Inst& inst);
|
||||
void EmitIsHelperInvocation(EmitContext& ctx, IR::Inst& inst);
|
||||
void EmitSR_WScaleFactorXY(EmitContext& ctx, IR::Inst& inst);
|
||||
void EmitSR_WScaleFactorZ(EmitContext& ctx, IR::Inst& inst);
|
||||
void EmitYDirection(EmitContext& ctx, IR::Inst& inst);
|
||||
void EmitResolutionDownFactor(EmitContext& ctx, IR::Inst& inst);
|
||||
void EmitRenderArea(EmitContext& ctx, IR::Inst& inst);
|
||||
void EmitLoadLocal(EmitContext& ctx, IR::Inst& inst, std::string_view word_offset);
|
||||
void EmitWriteLocal(EmitContext& ctx, std::string_view word_offset, std::string_view value);
|
||||
void EmitUndefU1(EmitContext& ctx, IR::Inst& inst);
|
||||
void EmitUndefU8(EmitContext& ctx, IR::Inst& inst);
|
||||
void EmitUndefU16(EmitContext& ctx, IR::Inst& inst);
|
||||
void EmitUndefU32(EmitContext& ctx, IR::Inst& inst);
|
||||
void EmitUndefU64(EmitContext& ctx, IR::Inst& inst);
|
||||
void EmitLoadGlobalU8(EmitContext& ctx);
|
||||
void EmitLoadGlobalS8(EmitContext& ctx);
|
||||
void EmitLoadGlobalU16(EmitContext& ctx);
|
||||
void EmitLoadGlobalS16(EmitContext& ctx);
|
||||
void EmitLoadGlobal32(EmitContext& ctx, IR::Inst& inst, std::string_view address);
|
||||
void EmitLoadGlobal64(EmitContext& ctx, IR::Inst& inst, std::string_view address);
|
||||
void EmitLoadGlobal128(EmitContext& ctx, IR::Inst& inst, std::string_view address);
|
||||
void EmitWriteGlobalU8(EmitContext& ctx);
|
||||
void EmitWriteGlobalS8(EmitContext& ctx);
|
||||
void EmitWriteGlobalU16(EmitContext& ctx);
|
||||
void EmitWriteGlobalS16(EmitContext& ctx);
|
||||
void EmitWriteGlobal32(EmitContext& ctx, std::string_view address, std::string_view value);
|
||||
void EmitWriteGlobal64(EmitContext& ctx, std::string_view address, std::string_view value);
|
||||
void EmitWriteGlobal128(EmitContext& ctx, std::string_view address, std::string_view value);
|
||||
void EmitLoadStorageU8(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset);
|
||||
void EmitLoadStorageS8(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset);
|
||||
void EmitLoadStorageU16(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset);
|
||||
void EmitLoadStorageS16(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset);
|
||||
void EmitLoadStorage32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset);
|
||||
void EmitLoadStorage64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset);
|
||||
void EmitLoadStorage128(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset);
|
||||
void EmitWriteStorageU8(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset,
|
||||
std::string_view value);
|
||||
void EmitWriteStorageS8(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset,
|
||||
std::string_view value);
|
||||
void EmitWriteStorageU16(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset,
|
||||
std::string_view value);
|
||||
void EmitWriteStorageS16(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset,
|
||||
std::string_view value);
|
||||
void EmitWriteStorage32(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset,
|
||||
std::string_view value);
|
||||
void EmitWriteStorage64(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset,
|
||||
std::string_view value);
|
||||
void EmitWriteStorage128(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset,
|
||||
std::string_view value);
|
||||
void EmitLoadSharedU8(EmitContext& ctx, IR::Inst& inst, std::string_view offset);
|
||||
void EmitLoadSharedS8(EmitContext& ctx, IR::Inst& inst, std::string_view offset);
|
||||
void EmitLoadSharedU16(EmitContext& ctx, IR::Inst& inst, std::string_view offset);
|
||||
void EmitLoadSharedS16(EmitContext& ctx, IR::Inst& inst, std::string_view offset);
|
||||
void EmitLoadSharedU32(EmitContext& ctx, IR::Inst& inst, std::string_view offset);
|
||||
void EmitLoadSharedU64(EmitContext& ctx, IR::Inst& inst, std::string_view offset);
|
||||
void EmitLoadSharedU128(EmitContext& ctx, IR::Inst& inst, std::string_view offset);
|
||||
void EmitWriteSharedU8(EmitContext& ctx, std::string_view offset, std::string_view value);
|
||||
void EmitWriteSharedU16(EmitContext& ctx, std::string_view offset, std::string_view value);
|
||||
void EmitWriteSharedU32(EmitContext& ctx, std::string_view offset, std::string_view value);
|
||||
void EmitWriteSharedU64(EmitContext& ctx, std::string_view offset, std::string_view value);
|
||||
void EmitWriteSharedU128(EmitContext& ctx, std::string_view offset, std::string_view value);
|
||||
void EmitCompositeConstructU32x2(EmitContext& ctx, IR::Inst& inst, std::string_view e1,
|
||||
std::string_view e2);
|
||||
void EmitCompositeConstructU32x3(EmitContext& ctx, IR::Inst& inst, std::string_view e1,
|
||||
std::string_view e2, std::string_view e3);
|
||||
void EmitCompositeConstructU32x4(EmitContext& ctx, IR::Inst& inst, std::string_view e1,
|
||||
std::string_view e2, std::string_view e3, std::string_view e4);
|
||||
void EmitCompositeExtractU32x2(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
|
||||
u32 index);
|
||||
void EmitCompositeExtractU32x3(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
|
||||
u32 index);
|
||||
void EmitCompositeExtractU32x4(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
|
||||
u32 index);
|
||||
void EmitCompositeInsertU32x2(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
|
||||
std::string_view object, u32 index);
|
||||
void EmitCompositeInsertU32x3(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
|
||||
std::string_view object, u32 index);
|
||||
void EmitCompositeInsertU32x4(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
|
||||
std::string_view object, u32 index);
|
||||
void EmitCompositeConstructF16x2(EmitContext& ctx, std::string_view e1, std::string_view e2);
|
||||
void EmitCompositeConstructF16x3(EmitContext& ctx, std::string_view e1, std::string_view e2,
|
||||
std::string_view e3);
|
||||
void EmitCompositeConstructF16x4(EmitContext& ctx, std::string_view e1, std::string_view e2,
|
||||
std::string_view e3, std::string_view e4);
|
||||
void EmitCompositeExtractF16x2(EmitContext& ctx, std::string_view composite, u32 index);
|
||||
void EmitCompositeExtractF16x3(EmitContext& ctx, std::string_view composite, u32 index);
|
||||
void EmitCompositeExtractF16x4(EmitContext& ctx, std::string_view composite, u32 index);
|
||||
void EmitCompositeInsertF16x2(EmitContext& ctx, std::string_view composite, std::string_view object,
|
||||
u32 index);
|
||||
void EmitCompositeInsertF16x3(EmitContext& ctx, std::string_view composite, std::string_view object,
|
||||
u32 index);
|
||||
void EmitCompositeInsertF16x4(EmitContext& ctx, std::string_view composite, std::string_view object,
|
||||
u32 index);
|
||||
void EmitCompositeConstructF32x2(EmitContext& ctx, IR::Inst& inst, std::string_view e1,
|
||||
std::string_view e2);
|
||||
void EmitCompositeConstructF32x3(EmitContext& ctx, IR::Inst& inst, std::string_view e1,
|
||||
std::string_view e2, std::string_view e3);
|
||||
void EmitCompositeConstructF32x4(EmitContext& ctx, IR::Inst& inst, std::string_view e1,
|
||||
std::string_view e2, std::string_view e3, std::string_view e4);
|
||||
void EmitCompositeExtractF32x2(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
|
||||
u32 index);
|
||||
void EmitCompositeExtractF32x3(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
|
||||
u32 index);
|
||||
void EmitCompositeExtractF32x4(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
|
||||
u32 index);
|
||||
void EmitCompositeInsertF32x2(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
|
||||
std::string_view object, u32 index);
|
||||
void EmitCompositeInsertF32x3(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
|
||||
std::string_view object, u32 index);
|
||||
void EmitCompositeInsertF32x4(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
|
||||
std::string_view object, u32 index);
|
||||
void EmitCompositeConstructF64x2(EmitContext& ctx);
|
||||
void EmitCompositeConstructF64x3(EmitContext& ctx);
|
||||
void EmitCompositeConstructF64x4(EmitContext& ctx);
|
||||
void EmitCompositeExtractF64x2(EmitContext& ctx);
|
||||
void EmitCompositeExtractF64x3(EmitContext& ctx);
|
||||
void EmitCompositeExtractF64x4(EmitContext& ctx);
|
||||
void EmitCompositeInsertF64x2(EmitContext& ctx, std::string_view composite, std::string_view object,
|
||||
u32 index);
|
||||
void EmitCompositeInsertF64x3(EmitContext& ctx, std::string_view composite, std::string_view object,
|
||||
u32 index);
|
||||
void EmitCompositeInsertF64x4(EmitContext& ctx, std::string_view composite, std::string_view object,
|
||||
u32 index);
|
||||
void EmitSelectU1(EmitContext& ctx, IR::Inst& inst, std::string_view cond,
|
||||
std::string_view true_value, std::string_view false_value);
|
||||
void EmitSelectU8(EmitContext& ctx, std::string_view cond, std::string_view true_value,
|
||||
std::string_view false_value);
|
||||
void EmitSelectU16(EmitContext& ctx, std::string_view cond, std::string_view true_value,
|
||||
std::string_view false_value);
|
||||
void EmitSelectU32(EmitContext& ctx, IR::Inst& inst, std::string_view cond,
|
||||
std::string_view true_value, std::string_view false_value);
|
||||
void EmitSelectU64(EmitContext& ctx, IR::Inst& inst, std::string_view cond,
|
||||
std::string_view true_value, std::string_view false_value);
|
||||
void EmitSelectF16(EmitContext& ctx, std::string_view cond, std::string_view true_value,
|
||||
std::string_view false_value);
|
||||
void EmitSelectF32(EmitContext& ctx, IR::Inst& inst, std::string_view cond,
|
||||
std::string_view true_value, std::string_view false_value);
|
||||
void EmitSelectF64(EmitContext& ctx, IR::Inst& inst, std::string_view cond,
|
||||
std::string_view true_value, std::string_view false_value);
|
||||
void EmitBitCastU16F16(EmitContext& ctx, IR::Inst& inst);
|
||||
void EmitBitCastU32F32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitBitCastU64F64(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitBitCastF16U16(EmitContext& ctx, IR::Inst& inst);
|
||||
void EmitBitCastF32U32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitBitCastF64U64(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitPackUint2x32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitUnpackUint2x32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitPackFloat2x16(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitUnpackFloat2x16(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitPackHalf2x16(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitUnpackHalf2x16(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitPackDouble2x32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitUnpackDouble2x32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitGetZeroFromOp(EmitContext& ctx);
|
||||
void EmitGetSignFromOp(EmitContext& ctx);
|
||||
void EmitGetCarryFromOp(EmitContext& ctx);
|
||||
void EmitGetOverflowFromOp(EmitContext& ctx);
|
||||
void EmitGetSparseFromOp(EmitContext& ctx);
|
||||
void EmitGetInBoundsFromOp(EmitContext& ctx);
|
||||
void EmitFPAbs16(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFPAbs32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFPAbs64(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFPAdd16(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b);
|
||||
void EmitFPAdd32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b);
|
||||
void EmitFPAdd64(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b);
|
||||
void EmitFPFma16(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b,
|
||||
std::string_view c);
|
||||
void EmitFPFma32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b,
|
||||
std::string_view c);
|
||||
void EmitFPFma64(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b,
|
||||
std::string_view c);
|
||||
void EmitFPMax32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b);
|
||||
void EmitFPMax64(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b);
|
||||
void EmitFPMin32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b);
|
||||
void EmitFPMin64(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b);
|
||||
void EmitFPMul16(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b);
|
||||
void EmitFPMul32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b);
|
||||
void EmitFPMul64(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b);
|
||||
void EmitFPNeg16(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFPNeg32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFPNeg64(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFPSin(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFPCos(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFPExp2(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFPLog2(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFPRecip32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFPRecip64(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFPRecipSqrt32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFPRecipSqrt64(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFPSqrt(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFPSaturate16(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFPSaturate32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFPSaturate64(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFPClamp16(EmitContext& ctx, IR::Inst& inst, std::string_view value,
|
||||
std::string_view min_value, std::string_view max_value);
|
||||
void EmitFPClamp32(EmitContext& ctx, IR::Inst& inst, std::string_view value,
|
||||
std::string_view min_value, std::string_view max_value);
|
||||
void EmitFPClamp64(EmitContext& ctx, IR::Inst& inst, std::string_view value,
|
||||
std::string_view min_value, std::string_view max_value);
|
||||
void EmitFPRoundEven16(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFPRoundEven32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFPRoundEven64(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFPFloor16(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFPFloor32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFPFloor64(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFPCeil16(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFPCeil32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFPCeil64(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFPTrunc16(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFPTrunc32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFPTrunc64(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFPOrdEqual16(EmitContext& ctx, std::string_view lhs, std::string_view rhs);
|
||||
void EmitFPOrdEqual32(EmitContext& ctx, IR::Inst& inst, std::string_view lhs, std::string_view rhs);
|
||||
void EmitFPOrdEqual64(EmitContext& ctx, IR::Inst& inst, std::string_view lhs, std::string_view rhs);
|
||||
void EmitFPUnordEqual16(EmitContext& ctx, std::string_view lhs, std::string_view rhs);
|
||||
void EmitFPUnordEqual32(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs);
|
||||
void EmitFPUnordEqual64(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs);
|
||||
void EmitFPOrdNotEqual16(EmitContext& ctx, std::string_view lhs, std::string_view rhs);
|
||||
void EmitFPOrdNotEqual32(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs);
|
||||
void EmitFPOrdNotEqual64(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs);
|
||||
void EmitFPUnordNotEqual16(EmitContext& ctx, std::string_view lhs, std::string_view rhs);
|
||||
void EmitFPUnordNotEqual32(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs);
|
||||
void EmitFPUnordNotEqual64(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs);
|
||||
void EmitFPOrdLessThan16(EmitContext& ctx, std::string_view lhs, std::string_view rhs);
|
||||
void EmitFPOrdLessThan32(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs);
|
||||
void EmitFPOrdLessThan64(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs);
|
||||
void EmitFPUnordLessThan16(EmitContext& ctx, std::string_view lhs, std::string_view rhs);
|
||||
void EmitFPUnordLessThan32(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs);
|
||||
void EmitFPUnordLessThan64(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs);
|
||||
void EmitFPOrdGreaterThan16(EmitContext& ctx, std::string_view lhs, std::string_view rhs);
|
||||
void EmitFPOrdGreaterThan32(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs);
|
||||
void EmitFPOrdGreaterThan64(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs);
|
||||
void EmitFPUnordGreaterThan16(EmitContext& ctx, std::string_view lhs, std::string_view rhs);
|
||||
void EmitFPUnordGreaterThan32(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs);
|
||||
void EmitFPUnordGreaterThan64(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs);
|
||||
void EmitFPOrdLessThanEqual16(EmitContext& ctx, std::string_view lhs, std::string_view rhs);
|
||||
void EmitFPOrdLessThanEqual32(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs);
|
||||
void EmitFPOrdLessThanEqual64(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs);
|
||||
void EmitFPUnordLessThanEqual16(EmitContext& ctx, std::string_view lhs, std::string_view rhs);
|
||||
void EmitFPUnordLessThanEqual32(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs);
|
||||
void EmitFPUnordLessThanEqual64(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs);
|
||||
void EmitFPOrdGreaterThanEqual16(EmitContext& ctx, std::string_view lhs, std::string_view rhs);
|
||||
void EmitFPOrdGreaterThanEqual32(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs);
|
||||
void EmitFPOrdGreaterThanEqual64(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs);
|
||||
void EmitFPUnordGreaterThanEqual16(EmitContext& ctx, std::string_view lhs, std::string_view rhs);
|
||||
void EmitFPUnordGreaterThanEqual32(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs);
|
||||
void EmitFPUnordGreaterThanEqual64(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs);
|
||||
void EmitFPIsNan16(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFPIsNan32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFPIsNan64(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitIAdd32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b);
|
||||
void EmitIAdd64(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b);
|
||||
void EmitISub32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b);
|
||||
void EmitISub64(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b);
|
||||
void EmitIMul32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b);
|
||||
void EmitSDiv32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b);
|
||||
void EmitUDiv32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b);
|
||||
void EmitINeg32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitINeg64(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitIAbs32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitIAbs64(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitShiftLeftLogical32(EmitContext& ctx, IR::Inst& inst, std::string_view base,
|
||||
std::string_view shift);
|
||||
void EmitShiftLeftLogical64(EmitContext& ctx, IR::Inst& inst, std::string_view base,
|
||||
std::string_view shift);
|
||||
void EmitShiftRightLogical32(EmitContext& ctx, IR::Inst& inst, std::string_view base,
|
||||
std::string_view shift);
|
||||
void EmitShiftRightLogical64(EmitContext& ctx, IR::Inst& inst, std::string_view base,
|
||||
std::string_view shift);
|
||||
void EmitShiftRightArithmetic32(EmitContext& ctx, IR::Inst& inst, std::string_view base,
|
||||
std::string_view shift);
|
||||
void EmitShiftRightArithmetic64(EmitContext& ctx, IR::Inst& inst, std::string_view base,
|
||||
std::string_view shift);
|
||||
void EmitBitwiseAnd32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b);
|
||||
void EmitBitwiseOr32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b);
|
||||
void EmitBitwiseXor32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b);
|
||||
void EmitBitFieldInsert(EmitContext& ctx, IR::Inst& inst, std::string_view base,
|
||||
std::string_view insert, std::string_view offset, std::string_view count);
|
||||
void EmitBitFieldSExtract(EmitContext& ctx, IR::Inst& inst, std::string_view base,
|
||||
std::string_view offset, std::string_view count);
|
||||
void EmitBitFieldUExtract(EmitContext& ctx, IR::Inst& inst, std::string_view base,
|
||||
std::string_view offset, std::string_view count);
|
||||
void EmitBitReverse32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitBitCount32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitBitwiseNot32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFindSMsb32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitFindUMsb32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitSMin32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b);
|
||||
void EmitUMin32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b);
|
||||
void EmitSMax32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b);
|
||||
void EmitUMax32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b);
|
||||
void EmitSClamp32(EmitContext& ctx, IR::Inst& inst, std::string_view value, std::string_view min,
|
||||
std::string_view max);
|
||||
void EmitUClamp32(EmitContext& ctx, IR::Inst& inst, std::string_view value, std::string_view min,
|
||||
std::string_view max);
|
||||
void EmitSLessThan(EmitContext& ctx, IR::Inst& inst, std::string_view lhs, std::string_view rhs);
|
||||
void EmitULessThan(EmitContext& ctx, IR::Inst& inst, std::string_view lhs, std::string_view rhs);
|
||||
void EmitIEqual(EmitContext& ctx, IR::Inst& inst, std::string_view lhs, std::string_view rhs);
|
||||
void EmitSLessThanEqual(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs);
|
||||
void EmitULessThanEqual(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs);
|
||||
void EmitSGreaterThan(EmitContext& ctx, IR::Inst& inst, std::string_view lhs, std::string_view rhs);
|
||||
void EmitUGreaterThan(EmitContext& ctx, IR::Inst& inst, std::string_view lhs, std::string_view rhs);
|
||||
void EmitINotEqual(EmitContext& ctx, IR::Inst& inst, std::string_view lhs, std::string_view rhs);
|
||||
void EmitSGreaterThanEqual(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs);
|
||||
void EmitUGreaterThanEqual(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs);
|
||||
void EmitSharedAtomicIAdd32(EmitContext& ctx, IR::Inst& inst, std::string_view pointer_offset,
|
||||
std::string_view value);
|
||||
void EmitSharedAtomicSMin32(EmitContext& ctx, IR::Inst& inst, std::string_view pointer_offset,
|
||||
std::string_view value);
|
||||
void EmitSharedAtomicUMin32(EmitContext& ctx, IR::Inst& inst, std::string_view pointer_offset,
|
||||
std::string_view value);
|
||||
void EmitSharedAtomicSMax32(EmitContext& ctx, IR::Inst& inst, std::string_view pointer_offset,
|
||||
std::string_view value);
|
||||
void EmitSharedAtomicUMax32(EmitContext& ctx, IR::Inst& inst, std::string_view pointer_offset,
|
||||
std::string_view value);
|
||||
void EmitSharedAtomicInc32(EmitContext& ctx, IR::Inst& inst, std::string_view pointer_offset,
|
||||
std::string_view value);
|
||||
void EmitSharedAtomicDec32(EmitContext& ctx, IR::Inst& inst, std::string_view pointer_offset,
|
||||
std::string_view value);
|
||||
void EmitSharedAtomicAnd32(EmitContext& ctx, IR::Inst& inst, std::string_view pointer_offset,
|
||||
std::string_view value);
|
||||
void EmitSharedAtomicOr32(EmitContext& ctx, IR::Inst& inst, std::string_view pointer_offset,
|
||||
std::string_view value);
|
||||
void EmitSharedAtomicXor32(EmitContext& ctx, IR::Inst& inst, std::string_view pointer_offset,
|
||||
std::string_view value);
|
||||
void EmitSharedAtomicExchange32(EmitContext& ctx, IR::Inst& inst, std::string_view pointer_offset,
|
||||
std::string_view value);
|
||||
void EmitSharedAtomicExchange64(EmitContext& ctx, IR::Inst& inst, std::string_view pointer_offset,
|
||||
std::string_view value);
|
||||
void EmitSharedAtomicExchange32x2(EmitContext& ctx, IR::Inst& inst, std::string_view pointer_offset,
|
||||
std::string_view value);
|
||||
void EmitStorageAtomicIAdd32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicSMin32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicUMin32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicSMax32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicUMax32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicInc32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicDec32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicAnd32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicOr32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicXor32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicExchange32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicIAdd64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicSMin64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicUMin64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicSMax64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicUMax64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicAnd64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicOr64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicXor64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicExchange64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicIAdd32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicSMin32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicUMin32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicSMax32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicUMax32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicAnd32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicOr32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicXor32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicExchange32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicAddF32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicAddF16x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicAddF32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicMinF16x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicMinF32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicMaxF16x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitStorageAtomicMaxF32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset, std::string_view value);
|
||||
void EmitGlobalAtomicIAdd32(EmitContext& ctx);
|
||||
void EmitGlobalAtomicSMin32(EmitContext& ctx);
|
||||
void EmitGlobalAtomicUMin32(EmitContext& ctx);
|
||||
void EmitGlobalAtomicSMax32(EmitContext& ctx);
|
||||
void EmitGlobalAtomicUMax32(EmitContext& ctx);
|
||||
void EmitGlobalAtomicInc32(EmitContext& ctx);
|
||||
void EmitGlobalAtomicDec32(EmitContext& ctx);
|
||||
void EmitGlobalAtomicAnd32(EmitContext& ctx);
|
||||
void EmitGlobalAtomicOr32(EmitContext& ctx);
|
||||
void EmitGlobalAtomicXor32(EmitContext& ctx);
|
||||
void EmitGlobalAtomicExchange32(EmitContext& ctx);
|
||||
void EmitGlobalAtomicIAdd64(EmitContext& ctx);
|
||||
void EmitGlobalAtomicSMin64(EmitContext& ctx);
|
||||
void EmitGlobalAtomicUMin64(EmitContext& ctx);
|
||||
void EmitGlobalAtomicSMax64(EmitContext& ctx);
|
||||
void EmitGlobalAtomicUMax64(EmitContext& ctx);
|
||||
void EmitGlobalAtomicInc64(EmitContext& ctx);
|
||||
void EmitGlobalAtomicDec64(EmitContext& ctx);
|
||||
void EmitGlobalAtomicAnd64(EmitContext& ctx);
|
||||
void EmitGlobalAtomicOr64(EmitContext& ctx);
|
||||
void EmitGlobalAtomicXor64(EmitContext& ctx);
|
||||
void EmitGlobalAtomicExchange64(EmitContext& ctx);
|
||||
void EmitGlobalAtomicIAdd32x2(EmitContext& ctx);
|
||||
void EmitGlobalAtomicSMin32x2(EmitContext& ctx);
|
||||
void EmitGlobalAtomicUMin32x2(EmitContext& ctx);
|
||||
void EmitGlobalAtomicSMax32x2(EmitContext& ctx);
|
||||
void EmitGlobalAtomicUMax32x2(EmitContext& ctx);
|
||||
void EmitGlobalAtomicInc32x2(EmitContext& ctx);
|
||||
void EmitGlobalAtomicDec32x2(EmitContext& ctx);
|
||||
void EmitGlobalAtomicAnd32x2(EmitContext& ctx);
|
||||
void EmitGlobalAtomicOr32x2(EmitContext& ctx);
|
||||
void EmitGlobalAtomicXor32x2(EmitContext& ctx);
|
||||
void EmitGlobalAtomicExchange32x2(EmitContext& ctx);
|
||||
void EmitGlobalAtomicAddF32(EmitContext& ctx);
|
||||
void EmitGlobalAtomicAddF16x2(EmitContext& ctx);
|
||||
void EmitGlobalAtomicAddF32x2(EmitContext& ctx);
|
||||
void EmitGlobalAtomicMinF16x2(EmitContext& ctx);
|
||||
void EmitGlobalAtomicMinF32x2(EmitContext& ctx);
|
||||
void EmitGlobalAtomicMaxF16x2(EmitContext& ctx);
|
||||
void EmitGlobalAtomicMaxF32x2(EmitContext& ctx);
|
||||
void EmitLogicalOr(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b);
|
||||
void EmitLogicalAnd(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b);
|
||||
void EmitLogicalXor(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b);
|
||||
void EmitLogicalNot(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertS16F16(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertS16F32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertS16F64(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertS32F16(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertS32F32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertS32F64(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertS64F16(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertS64F32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertS64F64(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertU16F16(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertU16F32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertU16F64(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertU32F16(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertU32F32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertU32F64(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertU64F16(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertU64F32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertU64F64(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertU64U32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertU32U64(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertF16F32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertF32F16(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertF32F64(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertF64F32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertF16S8(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertF16S16(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertF16S32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertF16S64(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertF16U8(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertF16U16(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertF16U32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertF16U64(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertF32S8(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertF32S16(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertF32S32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertF32S64(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertF32U8(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertF32U16(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertF32U32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertF32U64(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertF64S8(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertF64S16(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertF64S32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertF64S64(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertF64U8(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertF64U16(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertF64U32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertF64U64(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertU16U32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertU32U16(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertU8U32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertU32U8(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertS32S8(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitConvertS32S16(EmitContext& ctx, IR::Inst& inst, std::string_view value);
|
||||
void EmitBindlessImageSampleImplicitLod(EmitContext&);
|
||||
void EmitBindlessImageSampleExplicitLod(EmitContext&);
|
||||
void EmitBindlessImageSampleDrefImplicitLod(EmitContext&);
|
||||
void EmitBindlessImageSampleDrefExplicitLod(EmitContext&);
|
||||
void EmitBindlessImageGather(EmitContext&);
|
||||
void EmitBindlessImageGatherDref(EmitContext&);
|
||||
void EmitBindlessImageFetch(EmitContext&);
|
||||
void EmitBindlessImageQueryDimensions(EmitContext&);
|
||||
void EmitBindlessImageQueryLod(EmitContext&);
|
||||
void EmitBindlessImageGradient(EmitContext&);
|
||||
void EmitBindlessImageRead(EmitContext&);
|
||||
void EmitBindlessImageWrite(EmitContext&);
|
||||
void EmitBoundImageSampleImplicitLod(EmitContext&);
|
||||
void EmitBoundImageSampleExplicitLod(EmitContext&);
|
||||
void EmitBoundImageSampleDrefImplicitLod(EmitContext&);
|
||||
void EmitBoundImageSampleDrefExplicitLod(EmitContext&);
|
||||
void EmitBoundImageGather(EmitContext&);
|
||||
void EmitBoundImageGatherDref(EmitContext&);
|
||||
void EmitBoundImageFetch(EmitContext&);
|
||||
void EmitBoundImageQueryDimensions(EmitContext&);
|
||||
void EmitBoundImageQueryLod(EmitContext&);
|
||||
void EmitBoundImageGradient(EmitContext&);
|
||||
void EmitBoundImageRead(EmitContext&);
|
||||
void EmitBoundImageWrite(EmitContext&);
|
||||
void EmitImageSampleImplicitLod(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords, std::string_view bias_lc,
|
||||
const IR::Value& offset);
|
||||
void EmitImageSampleExplicitLod(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords, std::string_view lod_lc,
|
||||
const IR::Value& offset);
|
||||
void EmitImageSampleDrefImplicitLod(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords, std::string_view dref,
|
||||
std::string_view bias_lc, const IR::Value& offset);
|
||||
void EmitImageSampleDrefExplicitLod(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords, std::string_view dref,
|
||||
std::string_view lod_lc, const IR::Value& offset);
|
||||
void EmitImageGather(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords, const IR::Value& offset, const IR::Value& offset2);
|
||||
void EmitImageGatherDref(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords, const IR::Value& offset, const IR::Value& offset2,
|
||||
std::string_view dref);
|
||||
void EmitImageFetch(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords, const IR::Value& offset, std::string_view lod,
|
||||
std::string_view ms);
|
||||
void EmitImageQueryDimensions(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view lod, const IR::Value& skip_mips);
|
||||
void EmitImageQueryLod(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords);
|
||||
void EmitImageGradient(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords, const IR::Value& derivatives,
|
||||
const IR::Value& offset, const IR::Value& lod_clamp);
|
||||
void EmitImageRead(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords);
|
||||
void EmitImageWrite(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords, std::string_view color);
|
||||
void EmitIsTextureScaled(EmitContext& ctx, IR::Inst& inst, const IR::Value& index);
|
||||
void EmitIsImageScaled(EmitContext& ctx, IR::Inst& inst, const IR::Value& index);
|
||||
void EmitBindlessImageAtomicIAdd32(EmitContext&);
|
||||
void EmitBindlessImageAtomicSMin32(EmitContext&);
|
||||
void EmitBindlessImageAtomicUMin32(EmitContext&);
|
||||
void EmitBindlessImageAtomicSMax32(EmitContext&);
|
||||
void EmitBindlessImageAtomicUMax32(EmitContext&);
|
||||
void EmitBindlessImageAtomicInc32(EmitContext&);
|
||||
void EmitBindlessImageAtomicDec32(EmitContext&);
|
||||
void EmitBindlessImageAtomicAnd32(EmitContext&);
|
||||
void EmitBindlessImageAtomicOr32(EmitContext&);
|
||||
void EmitBindlessImageAtomicXor32(EmitContext&);
|
||||
void EmitBindlessImageAtomicExchange32(EmitContext&);
|
||||
void EmitBoundImageAtomicIAdd32(EmitContext&);
|
||||
void EmitBoundImageAtomicSMin32(EmitContext&);
|
||||
void EmitBoundImageAtomicUMin32(EmitContext&);
|
||||
void EmitBoundImageAtomicSMax32(EmitContext&);
|
||||
void EmitBoundImageAtomicUMax32(EmitContext&);
|
||||
void EmitBoundImageAtomicInc32(EmitContext&);
|
||||
void EmitBoundImageAtomicDec32(EmitContext&);
|
||||
void EmitBoundImageAtomicAnd32(EmitContext&);
|
||||
void EmitBoundImageAtomicOr32(EmitContext&);
|
||||
void EmitBoundImageAtomicXor32(EmitContext&);
|
||||
void EmitBoundImageAtomicExchange32(EmitContext&);
|
||||
void EmitImageAtomicIAdd32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords, std::string_view value);
|
||||
void EmitImageAtomicSMin32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords, std::string_view value);
|
||||
void EmitImageAtomicUMin32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords, std::string_view value);
|
||||
void EmitImageAtomicSMax32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords, std::string_view value);
|
||||
void EmitImageAtomicUMax32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords, std::string_view value);
|
||||
void EmitImageAtomicInc32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords, std::string_view value);
|
||||
void EmitImageAtomicDec32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords, std::string_view value);
|
||||
void EmitImageAtomicAnd32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords, std::string_view value);
|
||||
void EmitImageAtomicOr32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords, std::string_view value);
|
||||
void EmitImageAtomicXor32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords, std::string_view value);
|
||||
void EmitImageAtomicExchange32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||
std::string_view coords, std::string_view value);
|
||||
void EmitLaneId(EmitContext& ctx, IR::Inst& inst);
|
||||
void EmitVoteAll(EmitContext& ctx, IR::Inst& inst, std::string_view pred);
|
||||
void EmitVoteAny(EmitContext& ctx, IR::Inst& inst, std::string_view pred);
|
||||
void EmitVoteEqual(EmitContext& ctx, IR::Inst& inst, std::string_view pred);
|
||||
void EmitSubgroupBallot(EmitContext& ctx, IR::Inst& inst, std::string_view pred);
|
||||
void EmitSubgroupEqMask(EmitContext& ctx, IR::Inst& inst);
|
||||
void EmitSubgroupLtMask(EmitContext& ctx, IR::Inst& inst);
|
||||
void EmitSubgroupLeMask(EmitContext& ctx, IR::Inst& inst);
|
||||
void EmitSubgroupGtMask(EmitContext& ctx, IR::Inst& inst);
|
||||
void EmitSubgroupGeMask(EmitContext& ctx, IR::Inst& inst);
|
||||
void EmitShuffleIndex(EmitContext& ctx, IR::Inst& inst, std::string_view value,
|
||||
std::string_view index, std::string_view clamp,
|
||||
std::string_view segmentation_mask);
|
||||
void EmitShuffleUp(EmitContext& ctx, IR::Inst& inst, std::string_view value, std::string_view index,
|
||||
std::string_view clamp, std::string_view segmentation_mask);
|
||||
void EmitShuffleDown(EmitContext& ctx, IR::Inst& inst, std::string_view value,
|
||||
std::string_view index, std::string_view clamp,
|
||||
std::string_view segmentation_mask);
|
||||
void EmitShuffleButterfly(EmitContext& ctx, IR::Inst& inst, std::string_view value,
|
||||
std::string_view index, std::string_view clamp,
|
||||
std::string_view segmentation_mask);
|
||||
void EmitFSwizzleAdd(EmitContext& ctx, IR::Inst& inst, std::string_view op_a, std::string_view op_b,
|
||||
std::string_view swizzle);
|
||||
void EmitDPdxFine(EmitContext& ctx, IR::Inst& inst, std::string_view op_a);
|
||||
void EmitDPdyFine(EmitContext& ctx, IR::Inst& inst, std::string_view op_a);
|
||||
void EmitDPdxCoarse(EmitContext& ctx, IR::Inst& inst, std::string_view op_a);
|
||||
void EmitDPdyCoarse(EmitContext& ctx, IR::Inst& inst, std::string_view op_a);
|
||||
|
||||
} // namespace Shader::Backend::WGSL
|
||||
268
gpu/third_party/suyu/shader_recompiler/backend/wgsl/emit_wgsl_integer.cpp
vendored
Normal file
268
gpu/third_party/suyu/shader_recompiler/backend/wgsl/emit_wgsl_integer.cpp
vendored
Normal file
@@ -0,0 +1,268 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2025 suyu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "shader_recompiler/backend/wgsl/emit_wgsl_instructions.h"
|
||||
#include "shader_recompiler/backend/wgsl/wgsl_emit_context.h"
|
||||
#include "shader_recompiler/frontend/ir/value.h"
|
||||
|
||||
namespace Shader::Backend::WGSL {
|
||||
namespace {
|
||||
void SetZeroFlag(EmitContext& ctx, IR::Inst& inst, std::string_view result) {
|
||||
IR::Inst* const zero{inst.GetAssociatedPseudoOperation(IR::Opcode::GetZeroFromOp)};
|
||||
if (!zero) {
|
||||
return;
|
||||
}
|
||||
ctx.AddU1("{}={}==0;", *zero, result);
|
||||
zero->Invalidate();
|
||||
}
|
||||
|
||||
void SetSignFlag(EmitContext& ctx, IR::Inst& inst, std::string_view result) {
|
||||
IR::Inst* const sign{inst.GetAssociatedPseudoOperation(IR::Opcode::GetSignFromOp)};
|
||||
if (!sign) {
|
||||
return;
|
||||
}
|
||||
ctx.AddU1("{}=i32({})<0;", *sign, result);
|
||||
sign->Invalidate();
|
||||
}
|
||||
|
||||
void BitwiseLogicalOp(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b,
|
||||
char lop) {
|
||||
const auto result{ctx.var_alloc.Define(inst, WgslVarType::U32)};
|
||||
ctx.Add("{}={}{}{};", result, a, lop, b);
|
||||
SetZeroFlag(ctx, inst, result);
|
||||
SetSignFlag(ctx, inst, result);
|
||||
}
|
||||
} // Anonymous namespace
|
||||
|
||||
void EmitIAdd32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
|
||||
// Compute the overflow CC first as it requires the original operand values,
|
||||
// which may be overwritten by the result of the addition
|
||||
if (IR::Inst * overflow{inst.GetAssociatedPseudoOperation(IR::Opcode::GetOverflowFromOp)}) {
|
||||
// https://stackoverflow.com/questions/55468823/how-to-detect-integer-overflow-in-c
|
||||
constexpr u32 s32_max{static_cast<u32>((std::numeric_limits<s32>::max)())};
|
||||
const auto sub_a{fmt::format("{}u-{}", s32_max, a)};
|
||||
const auto positive_result{fmt::format("i32({})>i32({})", b, sub_a)};
|
||||
const auto negative_result{fmt::format("i32({})<i32({})", b, sub_a)};
|
||||
ctx.AddU1("{}=select({},{},i32({})>=0);", *overflow, negative_result, positive_result, a);
|
||||
overflow->Invalidate();
|
||||
}
|
||||
const auto result{ctx.var_alloc.Define(inst, WgslVarType::U32)};
|
||||
if (IR::Inst* const carry{inst.GetAssociatedPseudoOperation(IR::Opcode::GetCarryFromOp)}) {
|
||||
ctx.uses_cc_carry = true;
|
||||
// the carry first: the result may share a variable with an operand
|
||||
ctx.Add("carry=select(0u,1u,({}+{})<{});", a, b, a);
|
||||
ctx.Add("{}={}+{};", result, a, b);
|
||||
ctx.AddU1("{}=carry!=0;", *carry);
|
||||
carry->Invalidate();
|
||||
} else {
|
||||
ctx.Add("{}={}+{};", result, a, b);
|
||||
}
|
||||
SetZeroFlag(ctx, inst, result);
|
||||
SetSignFlag(ctx, inst, result);
|
||||
}
|
||||
|
||||
void EmitIAdd64(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
|
||||
ctx.AddU64("{}=add64({},{});", inst, a, b);
|
||||
}
|
||||
|
||||
void EmitISub32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
|
||||
ctx.AddU32("{}={}-{};", inst, a, b);
|
||||
}
|
||||
|
||||
void EmitISub64(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
|
||||
ctx.AddU64("{}=sub64({},{});", inst, a, b);
|
||||
}
|
||||
|
||||
void EmitIMul32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
|
||||
ctx.AddU32("{}=u32({}*{});", inst, a, b);
|
||||
}
|
||||
|
||||
void EmitSDiv32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
|
||||
ctx.AddU32("{}=u32(i32({})/i32({}));", inst, a, b);
|
||||
}
|
||||
|
||||
void EmitUDiv32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
|
||||
ctx.AddU32("{}={}/{};", inst, a, b);
|
||||
}
|
||||
|
||||
void EmitINeg32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddU32("{}=u32(i32(0)-i32({}));", inst, value);
|
||||
}
|
||||
|
||||
void EmitINeg64(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddU64("{}=sub64(vec2<u32>(0u),{});", inst, value);
|
||||
}
|
||||
|
||||
void EmitIAbs32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddU32("{}=u32(abs(i32({})));", inst, value);
|
||||
}
|
||||
|
||||
void EmitIAbs64(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
// TODO: Uhm, are you sure? This may crash on some drivers!
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitShiftLeftLogical32(EmitContext& ctx, IR::Inst& inst, std::string_view base,
|
||||
std::string_view shift) {
|
||||
ctx.AddU32("{}={}<<{};", inst, base, shift);
|
||||
}
|
||||
|
||||
void EmitShiftLeftLogical64(EmitContext& ctx, IR::Inst& inst, std::string_view base,
|
||||
std::string_view shift) {
|
||||
ctx.AddU64("{}=shl64({},{});", inst, base, shift);
|
||||
}
|
||||
|
||||
void EmitShiftRightLogical32(EmitContext& ctx, IR::Inst& inst, std::string_view base,
|
||||
std::string_view shift) {
|
||||
ctx.AddU32("{}={}>>{};", inst, base, shift);
|
||||
}
|
||||
|
||||
void EmitShiftRightLogical64(EmitContext& ctx, IR::Inst& inst, std::string_view base,
|
||||
std::string_view shift) {
|
||||
ctx.AddU64("{}=shr64({},{});", inst, base, shift);
|
||||
}
|
||||
|
||||
void EmitShiftRightArithmetic32(EmitContext& ctx, IR::Inst& inst, std::string_view base,
|
||||
std::string_view shift) {
|
||||
ctx.AddU32("{}=u32(i32({})>>{});", inst, base, shift);
|
||||
}
|
||||
|
||||
void EmitShiftRightArithmetic64(EmitContext& ctx, IR::Inst& inst, std::string_view base,
|
||||
std::string_view shift) {
|
||||
ctx.AddU64("{}=sar64({},{});", inst, base, shift);
|
||||
}
|
||||
|
||||
void EmitBitwiseAnd32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
|
||||
BitwiseLogicalOp(ctx, inst, a, b, '&');
|
||||
}
|
||||
|
||||
void EmitBitwiseOr32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
|
||||
BitwiseLogicalOp(ctx, inst, a, b, '|');
|
||||
}
|
||||
|
||||
void EmitBitwiseXor32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
|
||||
BitwiseLogicalOp(ctx, inst, a, b, '^');
|
||||
}
|
||||
|
||||
void EmitBitFieldInsert(EmitContext& ctx, IR::Inst& inst, std::string_view base,
|
||||
std::string_view insert, std::string_view offset, std::string_view count) {
|
||||
ctx.AddU32("{}=insertBits({},{},u32({}),u32({}));", inst, base, insert, offset, count);
|
||||
}
|
||||
|
||||
void EmitBitFieldSExtract(EmitContext& ctx, IR::Inst& inst, std::string_view base,
|
||||
std::string_view offset, std::string_view count) {
|
||||
const auto result{ctx.var_alloc.Define(inst, WgslVarType::U32)};
|
||||
ctx.Add("{}=u32(extractBits(i32({}),u32({}),u32({})));", result, base, offset, count);
|
||||
SetZeroFlag(ctx, inst, result);
|
||||
SetSignFlag(ctx, inst, result);
|
||||
}
|
||||
|
||||
void EmitBitFieldUExtract(EmitContext& ctx, IR::Inst& inst, std::string_view base,
|
||||
std::string_view offset, std::string_view count) {
|
||||
const auto result{ctx.var_alloc.Define(inst, WgslVarType::U32)};
|
||||
ctx.Add("{}=extractBits(u32({}),u32({}),u32({}));", result, base, offset, count);
|
||||
SetZeroFlag(ctx, inst, result);
|
||||
SetSignFlag(ctx, inst, result);
|
||||
}
|
||||
|
||||
void EmitBitReverse32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddU32("{}=reverseBits({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitBitCount32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddU32("{}=countOneBits({});", inst, value);
|
||||
}
|
||||
|
||||
void EmitBitwiseNot32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddU32("{}=~{};", inst, value);
|
||||
}
|
||||
|
||||
void EmitFindSMsb32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddU32("{}=u32(firstLeadingBit(i32({})));", inst, value);
|
||||
}
|
||||
|
||||
void EmitFindUMsb32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddU32("{}=firstLeadingBit(u32({}));", inst, value);
|
||||
}
|
||||
|
||||
void EmitSMin32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
|
||||
ctx.AddU32("{}=u32(min(i32({}),i32({})));", inst, a, b);
|
||||
}
|
||||
|
||||
void EmitUMin32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
|
||||
ctx.AddU32("{}=min(u32({}),u32({}));", inst, a, b);
|
||||
}
|
||||
|
||||
void EmitSMax32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
|
||||
ctx.AddU32("{}=u32(max(i32({}),i32({})));", inst, a, b);
|
||||
}
|
||||
|
||||
void EmitUMax32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
|
||||
ctx.AddU32("{}=max(u32({}),u32({}));", inst, a, b);
|
||||
}
|
||||
|
||||
void EmitSClamp32(EmitContext& ctx, IR::Inst& inst, std::string_view value, std::string_view min,
|
||||
std::string_view max) {
|
||||
const auto result{ctx.var_alloc.Define(inst, WgslVarType::U32)};
|
||||
ctx.Add("{}=u32(clamp(i32({}),i32({}),i32({})));", result, value, min, max);
|
||||
SetZeroFlag(ctx, inst, result);
|
||||
SetSignFlag(ctx, inst, result);
|
||||
}
|
||||
|
||||
void EmitUClamp32(EmitContext& ctx, IR::Inst& inst, std::string_view value, std::string_view min,
|
||||
std::string_view max) {
|
||||
const auto result{ctx.var_alloc.Define(inst, WgslVarType::U32)};
|
||||
ctx.Add("{}=clamp(u32({}),u32({}),u32({}));", result, value, min, max);
|
||||
SetZeroFlag(ctx, inst, result);
|
||||
SetSignFlag(ctx, inst, result);
|
||||
}
|
||||
|
||||
void EmitSLessThan(EmitContext& ctx, IR::Inst& inst, std::string_view lhs, std::string_view rhs) {
|
||||
ctx.AddU1("{}=i32({})<i32({});", inst, lhs, rhs);
|
||||
}
|
||||
|
||||
void EmitULessThan(EmitContext& ctx, IR::Inst& inst, std::string_view lhs, std::string_view rhs) {
|
||||
ctx.AddU1("{}=u32({})<u32({});", inst, lhs, rhs);
|
||||
}
|
||||
|
||||
void EmitIEqual(EmitContext& ctx, IR::Inst& inst, std::string_view lhs, std::string_view rhs) {
|
||||
ctx.AddU1("{}={}=={};", inst, lhs, rhs);
|
||||
}
|
||||
|
||||
void EmitSLessThanEqual(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs) {
|
||||
ctx.AddU1("{}=i32({})<=i32({});", inst, lhs, rhs);
|
||||
}
|
||||
|
||||
void EmitULessThanEqual(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs) {
|
||||
ctx.AddU1("{}=u32({})<=u32({});", inst, lhs, rhs);
|
||||
}
|
||||
|
||||
void EmitSGreaterThan(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs) {
|
||||
ctx.AddU1("{}=i32({})>i32({});", inst, lhs, rhs);
|
||||
}
|
||||
|
||||
void EmitUGreaterThan(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs) {
|
||||
ctx.AddU1("{}=u32({})>u32({});", inst, lhs, rhs);
|
||||
}
|
||||
|
||||
void EmitINotEqual(EmitContext& ctx, IR::Inst& inst, std::string_view lhs, std::string_view rhs) {
|
||||
ctx.AddU1("{}={}!={};", inst, lhs, rhs);
|
||||
}
|
||||
|
||||
void EmitSGreaterThanEqual(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs) {
|
||||
ctx.AddU1("{}=i32({})>=i32({});", inst, lhs, rhs);
|
||||
}
|
||||
|
||||
void EmitUGreaterThanEqual(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
|
||||
std::string_view rhs) {
|
||||
ctx.AddU1("{}=u32({})>=u32({});", inst, lhs, rhs);
|
||||
}
|
||||
} // namespace Shader::Backend::WGSL
|
||||
25
gpu/third_party/suyu/shader_recompiler/backend/wgsl/emit_wgsl_logical.cpp
vendored
Normal file
25
gpu/third_party/suyu/shader_recompiler/backend/wgsl/emit_wgsl_logical.cpp
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "shader_recompiler/backend/wgsl/emit_wgsl_instructions.h"
|
||||
#include "shader_recompiler/backend/wgsl/wgsl_emit_context.h"
|
||||
#include "shader_recompiler/frontend/ir/value.h"
|
||||
|
||||
namespace Shader::Backend::WGSL {
|
||||
|
||||
void EmitLogicalOr(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
|
||||
ctx.AddU1("{}={}||{};", inst, a, b);
|
||||
}
|
||||
|
||||
void EmitLogicalAnd(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
|
||||
ctx.AddU1("{}={}&&{};", inst, a, b);
|
||||
}
|
||||
|
||||
void EmitLogicalXor(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
|
||||
ctx.AddU1("{}={}!={};", inst, a, b);
|
||||
}
|
||||
|
||||
void EmitLogicalNot(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddU1("{}=!{};", inst, value);
|
||||
}
|
||||
} // namespace Shader::Backend::WGSL
|
||||
223
gpu/third_party/suyu/shader_recompiler/backend/wgsl/emit_wgsl_memory.cpp
vendored
Normal file
223
gpu/third_party/suyu/shader_recompiler/backend/wgsl/emit_wgsl_memory.cpp
vendored
Normal file
@@ -0,0 +1,223 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <string_view>
|
||||
|
||||
#include "shader_recompiler/backend/wgsl/emit_wgsl_instructions.h"
|
||||
#include "shader_recompiler/backend/wgsl/wgsl_emit_context.h"
|
||||
#include "shader_recompiler/frontend/ir/value.h"
|
||||
#include "shader_recompiler/profile.h"
|
||||
|
||||
namespace Shader::Backend::WGSL {
|
||||
namespace {
|
||||
// a byte or a short: read-modify-write of its word
|
||||
void SsboWriteCas(EmitContext& ctx, const IR::Value& binding, std::string_view offset_var,
|
||||
std::string_view value, std::string_view bit_offset, u32 num_bits) {
|
||||
const auto word{fmt::format("{}>>2", offset_var)};
|
||||
const auto merged{fmt::format("insertBits({},{},u32({}),{}u)", ctx.SsboLoad(binding.U32(), word), value,
|
||||
bit_offset, num_bits)};
|
||||
ctx.Add("{}", ctx.SsboStore(binding.U32(), word, merged));
|
||||
}
|
||||
|
||||
std::string Word(std::string_view offset_var, u32 plus = 0) {
|
||||
return plus ? fmt::format("({}+{})>>2", offset_var, plus) : fmt::format("{}>>2", offset_var);
|
||||
}
|
||||
} // Anonymous namespace
|
||||
|
||||
void EmitLoadGlobalU8(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitLoadGlobalS8(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitLoadGlobalU16(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitLoadGlobalS16(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitLoadGlobal32(EmitContext& ctx, IR::Inst& inst, std::string_view address) {
|
||||
if (ctx.profile.support_int64) {
|
||||
return ctx.AddU32("{}=LoadGlobal32({});", inst, address);
|
||||
}
|
||||
LOG_WARNING(Shader_WGSL, "Int64 not supported, ignoring memory operation");
|
||||
ctx.AddU32("{}=0u;", inst);
|
||||
}
|
||||
|
||||
void EmitLoadGlobal64(EmitContext& ctx, IR::Inst& inst, std::string_view address) {
|
||||
if (ctx.profile.support_int64) {
|
||||
return ctx.AddU32x2("{}=LoadGlobal64({});", inst, address);
|
||||
}
|
||||
LOG_WARNING(Shader_WGSL, "Int64 not supported, ignoring memory operation");
|
||||
ctx.AddU32x2("{}=vec2<u32>(0);", inst);
|
||||
}
|
||||
|
||||
void EmitLoadGlobal128(EmitContext& ctx, IR::Inst& inst, std::string_view address) {
|
||||
if (ctx.profile.support_int64) {
|
||||
return ctx.AddU32x4("{}=LoadGlobal128({});", inst, address);
|
||||
}
|
||||
LOG_WARNING(Shader_WGSL, "Int64 not supported, ignoring memory operation");
|
||||
ctx.AddU32x4("{}=vec4<u32>(0);", inst);
|
||||
}
|
||||
|
||||
void EmitWriteGlobalU8(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitWriteGlobalS8(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitWriteGlobalU16(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitWriteGlobalS16(EmitContext&) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitWriteGlobal32(EmitContext& ctx, std::string_view address, std::string_view value) {
|
||||
if (ctx.profile.support_int64) {
|
||||
return ctx.Add("WriteGlobal32({},{});", address, value);
|
||||
}
|
||||
LOG_WARNING(Shader_WGSL, "Int64 not supported, ignoring memory operation");
|
||||
}
|
||||
|
||||
void EmitWriteGlobal64(EmitContext& ctx, std::string_view address, std::string_view value) {
|
||||
if (ctx.profile.support_int64) {
|
||||
return ctx.Add("WriteGlobal64({},{});", address, value);
|
||||
}
|
||||
LOG_WARNING(Shader_WGSL, "Int64 not supported, ignoring memory operation");
|
||||
}
|
||||
|
||||
void EmitWriteGlobal128(EmitContext& ctx, std::string_view address, std::string_view value) {
|
||||
if (ctx.profile.support_int64) {
|
||||
return ctx.Add("WriteGlobal128({},{});", address, value);
|
||||
}
|
||||
LOG_WARNING(Shader_WGSL, "Int64 not supported, ignoring memory operation");
|
||||
}
|
||||
|
||||
void EmitLoadStorageU8(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset) {
|
||||
const auto offset_var{ctx.var_alloc.Consume(offset)};
|
||||
ctx.AddU32("{}=extractBits({},u32({}%4)*8u,8u);", inst, ctx.SsboLoad(binding.U32(), Word(offset_var)),
|
||||
offset_var);
|
||||
}
|
||||
|
||||
void EmitLoadStorageS8(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset) {
|
||||
const auto offset_var{ctx.var_alloc.Consume(offset)};
|
||||
ctx.AddU32("{}=u32(extractBits(i32({}),u32({}%4)*8u,8u));", inst, ctx.SsboLoad(binding.U32(), Word(offset_var)),
|
||||
offset_var);
|
||||
}
|
||||
|
||||
void EmitLoadStorageU16(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset) {
|
||||
const auto offset_var{ctx.var_alloc.Consume(offset)};
|
||||
ctx.AddU32("{}=extractBits({},u32(({}>>1)%2)*16u,16u);", inst, ctx.SsboLoad(binding.U32(), Word(offset_var)),
|
||||
offset_var);
|
||||
}
|
||||
|
||||
void EmitLoadStorageS16(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset) {
|
||||
const auto offset_var{ctx.var_alloc.Consume(offset)};
|
||||
ctx.AddU32("{}=u32(extractBits(i32({}),u32(({}>>1)%2)*16u,16u));", inst,
|
||||
ctx.SsboLoad(binding.U32(), Word(offset_var)), offset_var);
|
||||
}
|
||||
|
||||
void EmitLoadStorage32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset) {
|
||||
const auto offset_var{ctx.var_alloc.Consume(offset)};
|
||||
ctx.AddU32("{}={};", inst, ctx.SsboLoad(binding.U32(), Word(offset_var)));
|
||||
}
|
||||
|
||||
void EmitLoadStorage64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset) {
|
||||
const auto offset_var{ctx.var_alloc.Consume(offset)};
|
||||
ctx.AddU32x2("{}=vec2<u32>({},{});", inst, ctx.SsboLoad(binding.U32(), Word(offset_var)),
|
||||
ctx.SsboLoad(binding.U32(), Word(offset_var, 4)));
|
||||
}
|
||||
|
||||
void EmitLoadStorage128(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
const IR::Value& offset) {
|
||||
const auto offset_var{ctx.var_alloc.Consume(offset)};
|
||||
ctx.AddU32x4("{}=vec4<u32>({},{},{},{});", inst, ctx.SsboLoad(binding.U32(), Word(offset_var)),
|
||||
ctx.SsboLoad(binding.U32(), Word(offset_var, 4)), ctx.SsboLoad(binding.U32(), Word(offset_var, 8)),
|
||||
ctx.SsboLoad(binding.U32(), Word(offset_var, 12)));
|
||||
}
|
||||
|
||||
void EmitWriteStorageU8(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset,
|
||||
std::string_view value) {
|
||||
if ((ctx.stage == Stage::VertexA || ctx.stage == Stage::VertexB) && !ctx.vs_compute) {
|
||||
return; // WebGPU has no writable storage in vertex shaders
|
||||
}
|
||||
const auto offset_var{ctx.var_alloc.Consume(offset)};
|
||||
const auto bit_offset{fmt::format("i32({}%4)*8", offset_var)};
|
||||
SsboWriteCas(ctx, binding, offset_var, value, bit_offset, 8);
|
||||
}
|
||||
|
||||
void EmitWriteStorageS8(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset,
|
||||
std::string_view value) {
|
||||
if ((ctx.stage == Stage::VertexA || ctx.stage == Stage::VertexB) && !ctx.vs_compute) {
|
||||
return; // WebGPU has no writable storage in vertex shaders
|
||||
}
|
||||
const auto offset_var{ctx.var_alloc.Consume(offset)};
|
||||
const auto bit_offset{fmt::format("i32({}%4)*8", offset_var)};
|
||||
SsboWriteCas(ctx, binding, offset_var, value, bit_offset, 8);
|
||||
}
|
||||
|
||||
void EmitWriteStorageU16(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset,
|
||||
std::string_view value) {
|
||||
if ((ctx.stage == Stage::VertexA || ctx.stage == Stage::VertexB) && !ctx.vs_compute) {
|
||||
return; // WebGPU has no writable storage in vertex shaders
|
||||
}
|
||||
const auto offset_var{ctx.var_alloc.Consume(offset)};
|
||||
const auto bit_offset{fmt::format("i32(({}>>1)%2)*16", offset_var)};
|
||||
SsboWriteCas(ctx, binding, offset_var, value, bit_offset, 16);
|
||||
}
|
||||
|
||||
void EmitWriteStorageS16(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset,
|
||||
std::string_view value) {
|
||||
if ((ctx.stage == Stage::VertexA || ctx.stage == Stage::VertexB) && !ctx.vs_compute) {
|
||||
return; // WebGPU has no writable storage in vertex shaders
|
||||
}
|
||||
const auto offset_var{ctx.var_alloc.Consume(offset)};
|
||||
const auto bit_offset{fmt::format("i32(({}>>1)%2)*16", offset_var)};
|
||||
SsboWriteCas(ctx, binding, offset_var, value, bit_offset, 16);
|
||||
}
|
||||
|
||||
void EmitWriteStorage32(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset,
|
||||
std::string_view value) {
|
||||
if ((ctx.stage == Stage::VertexA || ctx.stage == Stage::VertexB) && !ctx.vs_compute) {
|
||||
return; // WebGPU has no writable storage in vertex shaders
|
||||
}
|
||||
const auto offset_var{ctx.var_alloc.Consume(offset)};
|
||||
ctx.Add("{}", ctx.SsboStore(binding.U32(), Word(offset_var), value));
|
||||
}
|
||||
|
||||
void EmitWriteStorage64(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset,
|
||||
std::string_view value) {
|
||||
if ((ctx.stage == Stage::VertexA || ctx.stage == Stage::VertexB) && !ctx.vs_compute) {
|
||||
return; // WebGPU has no writable storage in vertex shaders
|
||||
}
|
||||
const auto offset_var{ctx.var_alloc.Consume(offset)};
|
||||
ctx.Add("{}", ctx.SsboStore(binding.U32(), Word(offset_var), fmt::format("{}.x", value)));
|
||||
ctx.Add("{}", ctx.SsboStore(binding.U32(), Word(offset_var, 4), fmt::format("{}.y", value)));
|
||||
}
|
||||
|
||||
void EmitWriteStorage128(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset,
|
||||
std::string_view value) {
|
||||
if ((ctx.stage == Stage::VertexA || ctx.stage == Stage::VertexB) && !ctx.vs_compute) {
|
||||
return; // WebGPU has no writable storage in vertex shaders
|
||||
}
|
||||
const auto offset_var{ctx.var_alloc.Consume(offset)};
|
||||
ctx.Add("{}", ctx.SsboStore(binding.U32(), Word(offset_var), fmt::format("{}.x", value)));
|
||||
ctx.Add("{}", ctx.SsboStore(binding.U32(), Word(offset_var, 4), fmt::format("{}.y", value)));
|
||||
ctx.Add("{}", ctx.SsboStore(binding.U32(), Word(offset_var, 8), fmt::format("{}.z", value)));
|
||||
ctx.Add("{}", ctx.SsboStore(binding.U32(), Word(offset_var, 12), fmt::format("{}.w", value)));
|
||||
}
|
||||
} // namespace Shader::Backend::WGSL
|
||||
100
gpu/third_party/suyu/shader_recompiler/backend/wgsl/emit_wgsl_not_implemented.cpp
vendored
Normal file
100
gpu/third_party/suyu/shader_recompiler/backend/wgsl/emit_wgsl_not_implemented.cpp
vendored
Normal file
@@ -0,0 +1,100 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <string_view>
|
||||
|
||||
#include "shader_recompiler/backend/wgsl/emit_wgsl_instructions.h"
|
||||
#include "shader_recompiler/backend/wgsl/wgsl_emit_context.h"
|
||||
#include "shader_recompiler/frontend/ir/value.h"
|
||||
|
||||
namespace Shader::Backend::WGSL {
|
||||
|
||||
void EmitGetRegister(EmitContext& ctx) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitSetRegister(EmitContext& ctx) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitGetPred(EmitContext& ctx) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitSetPred(EmitContext& ctx) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitSetGotoVariable(EmitContext& ctx) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitGetGotoVariable(EmitContext& ctx) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitSetIndirectBranchVariable(EmitContext& ctx) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitGetIndirectBranchVariable(EmitContext& ctx) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitGetZFlag(EmitContext& ctx) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitGetSFlag(EmitContext& ctx) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitGetCFlag(EmitContext& ctx) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitGetOFlag(EmitContext& ctx) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitSetZFlag(EmitContext& ctx) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitSetSFlag(EmitContext& ctx) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitSetCFlag(EmitContext& ctx) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitSetOFlag(EmitContext& ctx) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitGetZeroFromOp(EmitContext& ctx) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitGetSignFromOp(EmitContext& ctx) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitGetCarryFromOp(EmitContext& ctx) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitGetOverflowFromOp(EmitContext& ctx) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitGetSparseFromOp(EmitContext& ctx) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitGetInBoundsFromOp(EmitContext& ctx) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
} // namespace Shader::Backend::WGSL
|
||||
54
gpu/third_party/suyu/shader_recompiler/backend/wgsl/emit_wgsl_select.cpp
vendored
Normal file
54
gpu/third_party/suyu/shader_recompiler/backend/wgsl/emit_wgsl_select.cpp
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <string_view>
|
||||
|
||||
#include "shader_recompiler/backend/wgsl/emit_wgsl_instructions.h"
|
||||
#include "shader_recompiler/backend/wgsl/wgsl_emit_context.h"
|
||||
#include "shader_recompiler/frontend/ir/value.h"
|
||||
|
||||
namespace Shader::Backend::WGSL {
|
||||
void EmitSelectU1(EmitContext& ctx, IR::Inst& inst, std::string_view cond,
|
||||
std::string_view true_value, std::string_view false_value) {
|
||||
ctx.AddU1("{}=select({},{},{});", inst, false_value, true_value, cond);
|
||||
}
|
||||
|
||||
void EmitSelectU8([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view cond,
|
||||
[[maybe_unused]] std::string_view true_value,
|
||||
[[maybe_unused]] std::string_view false_value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitSelectU16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view cond,
|
||||
[[maybe_unused]] std::string_view true_value,
|
||||
[[maybe_unused]] std::string_view false_value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitSelectU32(EmitContext& ctx, IR::Inst& inst, std::string_view cond,
|
||||
std::string_view true_value, std::string_view false_value) {
|
||||
ctx.AddU32("{}=select({},{},{});", inst, false_value, true_value, cond);
|
||||
}
|
||||
|
||||
void EmitSelectU64(EmitContext& ctx, IR::Inst& inst, std::string_view cond,
|
||||
std::string_view true_value, std::string_view false_value) {
|
||||
ctx.AddU64("{}=select({},{},{});", inst, false_value, true_value, cond);
|
||||
}
|
||||
|
||||
void EmitSelectF16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view cond,
|
||||
[[maybe_unused]] std::string_view true_value,
|
||||
[[maybe_unused]] std::string_view false_value) {
|
||||
NotImplemented();
|
||||
}
|
||||
|
||||
void EmitSelectF32(EmitContext& ctx, IR::Inst& inst, std::string_view cond,
|
||||
std::string_view true_value, std::string_view false_value) {
|
||||
ctx.AddF32("{}=select({},{},{});", inst, false_value, true_value, cond);
|
||||
}
|
||||
|
||||
void EmitSelectF64(EmitContext& ctx, IR::Inst& inst, std::string_view cond,
|
||||
std::string_view true_value, std::string_view false_value) {
|
||||
ctx.AddF64("{}=select({},{},{});", inst, false_value, true_value, cond);
|
||||
}
|
||||
|
||||
} // namespace Shader::Backend::WGSL
|
||||
78
gpu/third_party/suyu/shader_recompiler/backend/wgsl/emit_wgsl_shared_memory.cpp
vendored
Normal file
78
gpu/third_party/suyu/shader_recompiler/backend/wgsl/emit_wgsl_shared_memory.cpp
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "shader_recompiler/backend/wgsl/emit_wgsl_instructions.h"
|
||||
#include "shader_recompiler/backend/wgsl/wgsl_emit_context.h"
|
||||
#include "shader_recompiler/frontend/ir/value.h"
|
||||
|
||||
namespace Shader::Backend::WGSL {
|
||||
namespace {
|
||||
// a byte or a short: read-modify-write of its word
|
||||
void SharedWriteCas(EmitContext& ctx, std::string_view offset, std::string_view value,
|
||||
std::string_view bit_offset, u32 num_bits) {
|
||||
const auto word{fmt::format("{}>>2", offset)};
|
||||
ctx.Add("{}", ctx.SmemStore(word, fmt::format("insertBits({},{},u32({}),{}u)", ctx.SmemLoad(word), value,
|
||||
bit_offset, num_bits)));
|
||||
}
|
||||
|
||||
std::string Word(std::string_view offset, u32 plus = 0) {
|
||||
return plus ? fmt::format("({}+{})>>2", offset, plus) : fmt::format("{}>>2", offset);
|
||||
}
|
||||
} // Anonymous namespace
|
||||
|
||||
void EmitLoadSharedU8(EmitContext& ctx, IR::Inst& inst, std::string_view offset) {
|
||||
ctx.AddU32("{}=extractBits({},u32({}%4)*8u,8u);", inst, ctx.SmemLoad(Word(offset)), offset);
|
||||
}
|
||||
|
||||
void EmitLoadSharedS8(EmitContext& ctx, IR::Inst& inst, std::string_view offset) {
|
||||
ctx.AddU32("{}=u32(extractBits(i32({}),u32({}%4)*8u,8u));", inst, ctx.SmemLoad(Word(offset)), offset);
|
||||
}
|
||||
|
||||
void EmitLoadSharedU16(EmitContext& ctx, IR::Inst& inst, std::string_view offset) {
|
||||
ctx.AddU32("{}=extractBits({},u32(({}>>1)%2)*16u,16u);", inst, ctx.SmemLoad(Word(offset)), offset);
|
||||
}
|
||||
|
||||
void EmitLoadSharedS16(EmitContext& ctx, IR::Inst& inst, std::string_view offset) {
|
||||
ctx.AddU32("{}=u32(extractBits(i32({}),u32(({}>>1)%2)*16u,16u));", inst, ctx.SmemLoad(Word(offset)), offset);
|
||||
}
|
||||
|
||||
void EmitLoadSharedU32(EmitContext& ctx, IR::Inst& inst, std::string_view offset) {
|
||||
ctx.AddU32("{}={};", inst, ctx.SmemLoad(Word(offset)));
|
||||
}
|
||||
|
||||
void EmitLoadSharedU64(EmitContext& ctx, IR::Inst& inst, std::string_view offset) {
|
||||
ctx.AddU32x2("{}=vec2<u32>({},{});", inst, ctx.SmemLoad(Word(offset)), ctx.SmemLoad(Word(offset, 4)));
|
||||
}
|
||||
|
||||
void EmitLoadSharedU128(EmitContext& ctx, IR::Inst& inst, std::string_view offset) {
|
||||
ctx.AddU32x4("{}=vec4<u32>({},{},{},{});", inst, ctx.SmemLoad(Word(offset)), ctx.SmemLoad(Word(offset, 4)),
|
||||
ctx.SmemLoad(Word(offset, 8)), ctx.SmemLoad(Word(offset, 12)));
|
||||
}
|
||||
|
||||
void EmitWriteSharedU8(EmitContext& ctx, std::string_view offset, std::string_view value) {
|
||||
const auto bit_offset{fmt::format("i32({}%4)*8", offset)};
|
||||
SharedWriteCas(ctx, offset, value, bit_offset, 8);
|
||||
}
|
||||
|
||||
void EmitWriteSharedU16(EmitContext& ctx, std::string_view offset, std::string_view value) {
|
||||
const auto bit_offset{fmt::format("i32(({}>>1)%2)*16", offset)};
|
||||
SharedWriteCas(ctx, offset, value, bit_offset, 16);
|
||||
}
|
||||
|
||||
void EmitWriteSharedU32(EmitContext& ctx, std::string_view offset, std::string_view value) {
|
||||
ctx.Add("{}", ctx.SmemStore(Word(offset), value));
|
||||
}
|
||||
|
||||
void EmitWriteSharedU64(EmitContext& ctx, std::string_view offset, std::string_view value) {
|
||||
ctx.Add("{}", ctx.SmemStore(Word(offset), fmt::format("{}.x", value)));
|
||||
ctx.Add("{}", ctx.SmemStore(Word(offset, 4), fmt::format("{}.y", value)));
|
||||
}
|
||||
|
||||
void EmitWriteSharedU128(EmitContext& ctx, std::string_view offset, std::string_view value) {
|
||||
ctx.Add("{}", ctx.SmemStore(Word(offset), fmt::format("{}.x", value)));
|
||||
ctx.Add("{}", ctx.SmemStore(Word(offset, 4), fmt::format("{}.y", value)));
|
||||
ctx.Add("{}", ctx.SmemStore(Word(offset, 8), fmt::format("{}.z", value)));
|
||||
ctx.Add("{}", ctx.SmemStore(Word(offset, 12), fmt::format("{}.w", value)));
|
||||
}
|
||||
|
||||
} // namespace Shader::Backend::WGSL
|
||||
109
gpu/third_party/suyu/shader_recompiler/backend/wgsl/emit_wgsl_special.cpp
vendored
Normal file
109
gpu/third_party/suyu/shader_recompiler/backend/wgsl/emit_wgsl_special.cpp
vendored
Normal file
@@ -0,0 +1,109 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "shader_recompiler/backend/wgsl/emit_wgsl_instructions.h"
|
||||
#include "shader_recompiler/backend/wgsl/wgsl_emit_context.h"
|
||||
#include "shader_recompiler/frontend/ir/program.h"
|
||||
#include "shader_recompiler/frontend/ir/value.h"
|
||||
#include "shader_recompiler/profile.h"
|
||||
|
||||
namespace Shader::Backend::WGSL {
|
||||
namespace {
|
||||
std::string_view OutputVertexIndex(EmitContext& ctx) {
|
||||
return ctx.stage == Stage::TessellationControl ? "[gl_InvocationID]" : "";
|
||||
}
|
||||
|
||||
void InitializeOutputVaryings(EmitContext& ctx) {
|
||||
if (ctx.uses_geometry_passthrough) {
|
||||
return;
|
||||
}
|
||||
if (ctx.stage == Stage::VertexB || ctx.stage == Stage::Geometry) {
|
||||
ctx.Add("gl_Position=vec4<f32>(0,0,0,1);");
|
||||
}
|
||||
for (size_t index = 0; index < IR::NUM_GENERICS; ++index) {
|
||||
if (!ctx.info.stores.Generic(index)) {
|
||||
continue;
|
||||
}
|
||||
const auto& info_array{ctx.output_generics.at(index)};
|
||||
const auto output_decorator{OutputVertexIndex(ctx)};
|
||||
size_t element{};
|
||||
while (element < info_array.size()) {
|
||||
const auto& info{info_array.at(element)};
|
||||
const auto varying_name{fmt::format("{}{}", info.name, output_decorator)};
|
||||
switch (info.num_components) {
|
||||
case 1: {
|
||||
ctx.Add("{}={}f;", varying_name, element == 3 ? "1.0" : "0.0");
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
case 3:
|
||||
if (element + info.num_components < 4) {
|
||||
ctx.Add("{}=vec{}<f32>(0);", varying_name, info.num_components);
|
||||
} else {
|
||||
// last element is the w component, must be initialized to 1
|
||||
const auto zeros{info.num_components == 3 ? "0,0," : "0,"};
|
||||
ctx.Add("{}=vec{}<f32>({}1);", varying_name, info.num_components, zeros);
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
ctx.Add("{}=vec4<f32>(0,0,0,1);", varying_name);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
element += info.num_components;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // Anonymous namespace
|
||||
|
||||
void EmitPhi(EmitContext& ctx, IR::Inst& phi) {
|
||||
const size_t num_args{phi.NumArgs()};
|
||||
for (size_t i = 0; i < num_args; ++i) {
|
||||
ctx.var_alloc.Consume(phi.Arg(i));
|
||||
}
|
||||
if (!phi.Definition<Id>().is_valid) {
|
||||
// The phi node wasn't forward defined
|
||||
ctx.var_alloc.PhiDefine(phi, phi.Type());
|
||||
}
|
||||
}
|
||||
|
||||
void EmitVoid(EmitContext&) {}
|
||||
|
||||
void EmitReference(EmitContext& ctx, const IR::Value& value) {
|
||||
ctx.var_alloc.Consume(value);
|
||||
}
|
||||
|
||||
void EmitPhiMove(EmitContext& ctx, const IR::Value& phi_value, const IR::Value& value) {
|
||||
IR::Inst& phi{*phi_value.InstRecursive()};
|
||||
const auto phi_type{phi.Type()};
|
||||
if (!phi.Definition<Id>().is_valid) {
|
||||
// The phi node wasn't forward defined
|
||||
ctx.var_alloc.PhiDefine(phi, phi_type);
|
||||
}
|
||||
const auto phi_reg{ctx.var_alloc.Consume(IR::Value{&phi})};
|
||||
const auto val_reg{ctx.var_alloc.Consume(value)};
|
||||
if (phi_reg == val_reg) {
|
||||
return;
|
||||
}
|
||||
const bool needs_workaround{ctx.profile.has_gl_bool_ref_bug && phi_type == IR::Type::U1};
|
||||
const auto suffix{needs_workaround ? "?true:false" : ""};
|
||||
ctx.Add("{}={}{};", phi_reg, val_reg, suffix);
|
||||
}
|
||||
|
||||
void EmitPrologue(EmitContext& ctx) {
|
||||
InitializeOutputVaryings(ctx);
|
||||
}
|
||||
|
||||
void EmitEpilogue(EmitContext&) {}
|
||||
|
||||
void EmitEmitVertex(EmitContext& ctx, const IR::Value& stream) {
|
||||
ctx.Add("EmitStreamVertex(i32({}));", ctx.var_alloc.Consume(stream));
|
||||
InitializeOutputVaryings(ctx);
|
||||
}
|
||||
|
||||
void EmitEndPrimitive(EmitContext& ctx, const IR::Value& stream) {
|
||||
ctx.Add("EndStreamPrimitive(i32({}));", ctx.var_alloc.Consume(stream));
|
||||
}
|
||||
|
||||
} // namespace Shader::Backend::WGSL
|
||||
29
gpu/third_party/suyu/shader_recompiler/backend/wgsl/emit_wgsl_undefined.cpp
vendored
Normal file
29
gpu/third_party/suyu/shader_recompiler/backend/wgsl/emit_wgsl_undefined.cpp
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "shader_recompiler/backend/wgsl/emit_wgsl_instructions.h"
|
||||
#include "shader_recompiler/backend/wgsl/wgsl_emit_context.h"
|
||||
|
||||
namespace Shader::Backend::WGSL {
|
||||
|
||||
void EmitUndefU1(EmitContext& ctx, IR::Inst& inst) {
|
||||
ctx.AddU1("{}=false;", inst);
|
||||
}
|
||||
|
||||
void EmitUndefU8(EmitContext& ctx, IR::Inst& inst) {
|
||||
ctx.AddU32("{}=0u;", inst);
|
||||
}
|
||||
|
||||
void EmitUndefU16(EmitContext& ctx, IR::Inst& inst) {
|
||||
ctx.AddU32("{}=0u;", inst);
|
||||
}
|
||||
|
||||
void EmitUndefU32(EmitContext& ctx, IR::Inst& inst) {
|
||||
ctx.AddU32("{}=0u;", inst);
|
||||
}
|
||||
|
||||
void EmitUndefU64(EmitContext& ctx, IR::Inst& inst) {
|
||||
ctx.AddU64("{}=vec2<u32>(0u);", inst);
|
||||
}
|
||||
|
||||
} // namespace Shader::Backend::WGSL
|
||||
203
gpu/third_party/suyu/shader_recompiler/backend/wgsl/emit_wgsl_warp.cpp
vendored
Normal file
203
gpu/third_party/suyu/shader_recompiler/backend/wgsl/emit_wgsl_warp.cpp
vendored
Normal file
@@ -0,0 +1,203 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <string_view>
|
||||
|
||||
#include "shader_recompiler/backend/wgsl/emit_wgsl_instructions.h"
|
||||
#include "shader_recompiler/backend/wgsl/wgsl_emit_context.h"
|
||||
#include "shader_recompiler/frontend/ir/value.h"
|
||||
#include "shader_recompiler/profile.h"
|
||||
|
||||
namespace Shader::Backend::WGSL {
|
||||
namespace {
|
||||
constexpr char THREAD_ID[]{"gl_SubGroupInvocationARB"};
|
||||
|
||||
void SetInBoundsFlag(EmitContext& ctx, IR::Inst& inst) {
|
||||
IR::Inst* const in_bounds{inst.GetAssociatedPseudoOperation(IR::Opcode::GetInBoundsFromOp)};
|
||||
if (!in_bounds) {
|
||||
return;
|
||||
}
|
||||
ctx.AddU1("{}=shfl_in_bounds;", *in_bounds);
|
||||
in_bounds->Invalidate();
|
||||
}
|
||||
|
||||
std::string ComputeMinThreadId(std::string_view thread_id, std::string_view segmentation_mask) {
|
||||
return fmt::format("({}&{})", thread_id, segmentation_mask);
|
||||
}
|
||||
|
||||
std::string ComputeMaxThreadId(std::string_view min_thread_id, std::string_view clamp,
|
||||
std::string_view not_seg_mask) {
|
||||
return fmt::format("({})|({}&{})", min_thread_id, clamp, not_seg_mask);
|
||||
}
|
||||
|
||||
std::string GetMaxThreadId(std::string_view thread_id, std::string_view clamp,
|
||||
std::string_view segmentation_mask) {
|
||||
const auto not_seg_mask{fmt::format("(~{})", segmentation_mask)};
|
||||
const auto min_thread_id{ComputeMinThreadId(thread_id, segmentation_mask)};
|
||||
return ComputeMaxThreadId(min_thread_id, clamp, not_seg_mask);
|
||||
}
|
||||
|
||||
void UseShuffleNv(EmitContext& ctx, IR::Inst& inst, std::string_view shfl_op,
|
||||
std::string_view value, std::string_view index,
|
||||
[[maybe_unused]] std::string_view clamp, std::string_view segmentation_mask) {
|
||||
const auto width{fmt::format("32u>>(countOneBits({}&31u))", segmentation_mask)};
|
||||
ctx.AddU32("{}={}({},{},{},shfl_in_bounds);", inst, shfl_op, value, index, width);
|
||||
SetInBoundsFlag(ctx, inst);
|
||||
}
|
||||
|
||||
std::string_view BallotIndex(EmitContext& ctx) {
|
||||
if (!ctx.profile.warp_size_potentially_larger_than_guest) {
|
||||
return ".x";
|
||||
}
|
||||
return "[gl_SubGroupInvocationARB>>5]";
|
||||
}
|
||||
|
||||
std::string GetMask(EmitContext& ctx, std::string_view mask) {
|
||||
const auto ballot_index{BallotIndex(ctx)};
|
||||
return fmt::format("u32(vec2<u32>({}){})", mask, ballot_index);
|
||||
}
|
||||
} // Anonymous namespace
|
||||
|
||||
void EmitLaneId(EmitContext& ctx, IR::Inst& inst) {
|
||||
ctx.AddU32("{}={}&31u;", inst, THREAD_ID);
|
||||
}
|
||||
|
||||
void EmitVoteAll(EmitContext& ctx, IR::Inst& inst, std::string_view pred) {
|
||||
ctx.AddU1("{}={};", inst, pred);
|
||||
}
|
||||
|
||||
void EmitVoteAny(EmitContext& ctx, IR::Inst& inst, std::string_view pred) {
|
||||
ctx.AddU1("{}={};", inst, pred);
|
||||
}
|
||||
|
||||
void EmitVoteEqual(EmitContext& ctx, IR::Inst& inst, std::string_view pred) {
|
||||
ctx.AddU1("{}=true;", inst);
|
||||
}
|
||||
|
||||
void EmitSubgroupBallot(EmitContext& ctx, IR::Inst& inst, std::string_view pred) {
|
||||
ctx.AddU32("{}=select(0u,1u,{});", inst, pred);
|
||||
}
|
||||
|
||||
void EmitSubgroupEqMask(EmitContext& ctx, IR::Inst& inst) {
|
||||
ctx.AddU32("{}=1u;", inst);
|
||||
}
|
||||
|
||||
void EmitSubgroupLtMask(EmitContext& ctx, IR::Inst& inst) {
|
||||
ctx.AddU32("{}=0u;", inst);
|
||||
}
|
||||
|
||||
void EmitSubgroupLeMask(EmitContext& ctx, IR::Inst& inst) {
|
||||
ctx.AddU32("{}=1u;", inst);
|
||||
}
|
||||
|
||||
void EmitSubgroupGtMask(EmitContext& ctx, IR::Inst& inst) {
|
||||
ctx.AddU32("{}=0u;", inst);
|
||||
}
|
||||
|
||||
void EmitSubgroupGeMask(EmitContext& ctx, IR::Inst& inst) {
|
||||
ctx.AddU32("{}=1u;", inst);
|
||||
}
|
||||
|
||||
void EmitShuffleIndex(EmitContext& ctx, IR::Inst& inst, std::string_view value,
|
||||
std::string_view index, std::string_view clamp, std::string_view seg_mask) {
|
||||
if (ctx.profile.support_gl_warp_intrinsics) {
|
||||
UseShuffleNv(ctx, inst, "shuffleNV", value, index, clamp, seg_mask);
|
||||
return;
|
||||
}
|
||||
const bool big_warp{ctx.profile.warp_size_potentially_larger_than_guest};
|
||||
const auto is_upper_partition{"i32(gl_SubGroupInvocationARB)>=32"};
|
||||
const auto upper_index{fmt::format("select({},{}+32u,{})", index, index, is_upper_partition)};
|
||||
const auto upper_clamp{fmt::format("select({},{}+32u,{})", clamp, clamp, is_upper_partition)};
|
||||
|
||||
const auto not_seg_mask{fmt::format("(~{})", seg_mask)};
|
||||
const auto min_thread_id{ComputeMinThreadId(THREAD_ID, seg_mask)};
|
||||
const auto max_thread_id{
|
||||
ComputeMaxThreadId(min_thread_id, big_warp ? upper_clamp : clamp, not_seg_mask)};
|
||||
|
||||
const auto lhs{fmt::format("({}&{})", big_warp ? upper_index : index, not_seg_mask)};
|
||||
const auto src_thread_id{fmt::format("({})|({})", lhs, min_thread_id)};
|
||||
ctx.Add("shfl_in_bounds=i32({})<=i32({});", src_thread_id, max_thread_id);
|
||||
SetInBoundsFlag(ctx, inst);
|
||||
ctx.Add("shfl_result={};", value);
|
||||
ctx.AddU32("{}=select({},shfl_result,shfl_in_bounds);", inst, value);
|
||||
}
|
||||
|
||||
void EmitShuffleUp(EmitContext& ctx, IR::Inst& inst, std::string_view value, std::string_view index,
|
||||
std::string_view clamp, std::string_view seg_mask) {
|
||||
if (ctx.profile.support_gl_warp_intrinsics) {
|
||||
UseShuffleNv(ctx, inst, "shuffleUpNV", value, index, clamp, seg_mask);
|
||||
return;
|
||||
}
|
||||
const bool big_warp{ctx.profile.warp_size_potentially_larger_than_guest};
|
||||
const auto is_upper_partition{"i32(gl_SubGroupInvocationARB)>=32"};
|
||||
const auto upper_clamp{fmt::format("select({},{}+32u,{})", clamp, clamp, is_upper_partition)};
|
||||
|
||||
const auto max_thread_id{GetMaxThreadId(THREAD_ID, big_warp ? upper_clamp : clamp, seg_mask)};
|
||||
const auto src_thread_id{fmt::format("({}-{})", THREAD_ID, index)};
|
||||
ctx.Add("shfl_in_bounds=i32({})>=i32({});", src_thread_id, max_thread_id);
|
||||
SetInBoundsFlag(ctx, inst);
|
||||
ctx.Add("shfl_result={};", value);
|
||||
ctx.AddU32("{}=select({},shfl_result,shfl_in_bounds);", inst, value);
|
||||
}
|
||||
|
||||
void EmitShuffleDown(EmitContext& ctx, IR::Inst& inst, std::string_view value,
|
||||
std::string_view index, std::string_view clamp, std::string_view seg_mask) {
|
||||
if (ctx.profile.support_gl_warp_intrinsics) {
|
||||
UseShuffleNv(ctx, inst, "shuffleDownNV", value, index, clamp, seg_mask);
|
||||
return;
|
||||
}
|
||||
const bool big_warp{ctx.profile.warp_size_potentially_larger_than_guest};
|
||||
const auto is_upper_partition{"i32(gl_SubGroupInvocationARB)>=32"};
|
||||
const auto upper_clamp{fmt::format("select({},{}+32u,{})", clamp, clamp, is_upper_partition)};
|
||||
|
||||
const auto max_thread_id{GetMaxThreadId(THREAD_ID, big_warp ? upper_clamp : clamp, seg_mask)};
|
||||
const auto src_thread_id{fmt::format("({}+{})", THREAD_ID, index)};
|
||||
ctx.Add("shfl_in_bounds=i32({})<=i32({});", src_thread_id, max_thread_id);
|
||||
SetInBoundsFlag(ctx, inst);
|
||||
ctx.Add("shfl_result={};", value);
|
||||
ctx.AddU32("{}=select({},shfl_result,shfl_in_bounds);", inst, value);
|
||||
}
|
||||
|
||||
void EmitShuffleButterfly(EmitContext& ctx, IR::Inst& inst, std::string_view value,
|
||||
std::string_view index, std::string_view clamp,
|
||||
std::string_view seg_mask) {
|
||||
if (ctx.profile.support_gl_warp_intrinsics) {
|
||||
UseShuffleNv(ctx, inst, "shuffleXorNV", value, index, clamp, seg_mask);
|
||||
return;
|
||||
}
|
||||
const bool big_warp{ctx.profile.warp_size_potentially_larger_than_guest};
|
||||
const auto is_upper_partition{"i32(gl_SubGroupInvocationARB)>=32"};
|
||||
const auto upper_clamp{fmt::format("select({},{}+32u,{})", clamp, clamp, is_upper_partition)};
|
||||
|
||||
const auto max_thread_id{GetMaxThreadId(THREAD_ID, big_warp ? upper_clamp : clamp, seg_mask)};
|
||||
const auto src_thread_id{fmt::format("({}^{})", THREAD_ID, index)};
|
||||
ctx.Add("shfl_in_bounds=i32({})<=i32({});", src_thread_id, max_thread_id);
|
||||
SetInBoundsFlag(ctx, inst);
|
||||
ctx.Add("shfl_result={};", value);
|
||||
ctx.AddU32("{}=select({},shfl_result,shfl_in_bounds);", inst, value);
|
||||
}
|
||||
|
||||
void EmitFSwizzleAdd(EmitContext& ctx, IR::Inst& inst, std::string_view op_a, std::string_view op_b,
|
||||
std::string_view swizzle) {
|
||||
const auto mask{fmt::format("({}>>((gl_SubGroupInvocationARB&3)<<1))&3", swizzle)};
|
||||
const std::string modifier_a = fmt::format("FSWZ_A[{}]", mask);
|
||||
const std::string modifier_b = fmt::format("FSWZ_B[{}]", mask);
|
||||
ctx.AddF32("{}=({}*{})+({}*{});", inst, op_a, modifier_a, op_b, modifier_b);
|
||||
}
|
||||
|
||||
void EmitDPdxFine(EmitContext& ctx, IR::Inst& inst, std::string_view op_a) {
|
||||
ctx.AddF32("{}=dpdxFine({});", inst, op_a);
|
||||
}
|
||||
|
||||
void EmitDPdyFine(EmitContext& ctx, IR::Inst& inst, std::string_view op_a) {
|
||||
ctx.AddF32("{}=dpdyFine({});", inst, op_a);
|
||||
}
|
||||
|
||||
void EmitDPdxCoarse(EmitContext& ctx, IR::Inst& inst, std::string_view op_a) {
|
||||
ctx.AddF32("{}=dpdxCoarse({});", inst, op_a);
|
||||
}
|
||||
|
||||
void EmitDPdyCoarse(EmitContext& ctx, IR::Inst& inst, std::string_view op_a) {
|
||||
ctx.AddF32("{}=dpdyCoarse({});", inst, op_a);
|
||||
}
|
||||
} // namespace Shader::Backend::WGSL
|
||||
301
gpu/third_party/suyu/shader_recompiler/backend/wgsl/var_alloc.cpp
vendored
Normal file
301
gpu/third_party/suyu/shader_recompiler/backend/wgsl/var_alloc.cpp
vendored
Normal file
@@ -0,0 +1,301 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2025 suyu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
#include <fmt/ranges.h>
|
||||
|
||||
#include "shader_recompiler/backend/wgsl/var_alloc.h"
|
||||
#include "shader_recompiler/exception.h"
|
||||
#include "shader_recompiler/frontend/ir/value.h"
|
||||
|
||||
namespace Shader::Backend::WGSL {
|
||||
namespace {
|
||||
std::string TypePrefix(WgslVarType type) {
|
||||
switch (type) {
|
||||
case WgslVarType::U1:
|
||||
return "b_";
|
||||
case WgslVarType::F16x2:
|
||||
return "f16x2_";
|
||||
case WgslVarType::U32:
|
||||
return "u_";
|
||||
case WgslVarType::F32:
|
||||
return "f_";
|
||||
case WgslVarType::U64:
|
||||
return "u64_";
|
||||
case WgslVarType::F64:
|
||||
return "d_";
|
||||
case WgslVarType::U32x2:
|
||||
return "u2_";
|
||||
case WgslVarType::F32x2:
|
||||
return "f2_";
|
||||
case WgslVarType::U32x3:
|
||||
return "u3_";
|
||||
case WgslVarType::F32x3:
|
||||
return "f3_";
|
||||
case WgslVarType::U32x4:
|
||||
return "u4_";
|
||||
case WgslVarType::F32x4:
|
||||
return "f4_";
|
||||
case WgslVarType::PrecF32:
|
||||
return "pf_";
|
||||
case WgslVarType::PrecF64:
|
||||
return "pd_";
|
||||
case WgslVarType::Void:
|
||||
return "";
|
||||
default:
|
||||
throw NotImplementedException("Type {}", type);
|
||||
}
|
||||
}
|
||||
|
||||
std::string FormatFloat(std::string_view value, IR::Type type) {
|
||||
if (type != IR::Type::F32) {
|
||||
throw NotImplementedException("WGSL has no 64-bit floats");
|
||||
}
|
||||
// WGSL const-evaluates bitcasts of literals and rejects non-finite results: read them from private variables
|
||||
if (value == "nan") {
|
||||
return "bitcast<f32>(F32_NAN_)";
|
||||
}
|
||||
if (value == "inf") {
|
||||
return "bitcast<f32>(F32_INF_)";
|
||||
}
|
||||
if (value == "-inf") {
|
||||
return "bitcast<f32>(F32_NINF_)";
|
||||
}
|
||||
const bool scientific{value.find_first_of('e') != std::string_view::npos};
|
||||
const bool needs_dot{!scientific && value.find_first_of('.') == std::string_view::npos};
|
||||
return fmt::format("{}{}f", value, needs_dot ? ".0" : "");
|
||||
}
|
||||
|
||||
std::string MakeImm(const IR::Value& value) {
|
||||
switch (value.Type()) {
|
||||
case IR::Type::U1:
|
||||
return value.U1() ? "true" : "false";
|
||||
case IR::Type::U32:
|
||||
return fmt::format("{}u", value.U32());
|
||||
case IR::Type::F32:
|
||||
return FormatFloat(fmt::format("{}", value.F32()), IR::Type::F32);
|
||||
case IR::Type::U64:
|
||||
return fmt::format("vec2<u32>({}u, {}u)", static_cast<u32>(value.U64()),
|
||||
static_cast<u32>(value.U64() >> 32));
|
||||
case IR::Type::Void:
|
||||
return "";
|
||||
default:
|
||||
throw NotImplementedException("Immediate type {}", value.Type());
|
||||
}
|
||||
}
|
||||
} // Anonymous namespace
|
||||
|
||||
std::string VarAlloc::Representation(u32 index, WgslVarType type) const {
|
||||
const auto prefix{TypePrefix(type)};
|
||||
return fmt::format("{}{}", prefix, index);
|
||||
}
|
||||
|
||||
std::string VarAlloc::Representation(Id id) const {
|
||||
return Representation(id.index, id.type);
|
||||
}
|
||||
|
||||
std::string VarAlloc::Define(IR::Inst& inst, WgslVarType type) {
|
||||
if (inst.HasUses()) {
|
||||
inst.SetDefinition<Id>(Alloc(type));
|
||||
return Representation(inst.Definition<Id>());
|
||||
} else {
|
||||
Id id{};
|
||||
id.type.Assign(type);
|
||||
GetUseTracker(type).uses_temp = true;
|
||||
inst.SetDefinition<Id>(id);
|
||||
return 't' + Representation(inst.Definition<Id>());
|
||||
}
|
||||
}
|
||||
|
||||
std::string VarAlloc::Define(IR::Inst& inst, IR::Type type) {
|
||||
return Define(inst, RegType(type));
|
||||
}
|
||||
|
||||
std::string VarAlloc::PhiDefine(IR::Inst& inst, IR::Type type) {
|
||||
return AddDefine(inst, RegType(type));
|
||||
}
|
||||
|
||||
std::string VarAlloc::AddDefine(IR::Inst& inst, WgslVarType type) {
|
||||
if (inst.HasUses()) {
|
||||
inst.SetDefinition<Id>(Alloc(type));
|
||||
return Representation(inst.Definition<Id>());
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
std::string VarAlloc::Consume(const IR::Value& value) {
|
||||
return value.IsImmediate() ? MakeImm(value) : ConsumeInst(*value.InstRecursive());
|
||||
}
|
||||
|
||||
std::string VarAlloc::ConsumeInst(IR::Inst& inst) {
|
||||
inst.DestructiveRemoveUsage();
|
||||
if (!inst.HasUses()) {
|
||||
Free(inst.Definition<Id>());
|
||||
}
|
||||
return Representation(inst.Definition<Id>());
|
||||
}
|
||||
|
||||
std::string VarAlloc::GetWgslType(IR::Type type) const {
|
||||
return GetWgslType(RegType(type));
|
||||
}
|
||||
|
||||
Id VarAlloc::Alloc(WgslVarType type) {
|
||||
auto& use_tracker{GetUseTracker(type)};
|
||||
const auto num_vars{use_tracker.var_use.size()};
|
||||
for (size_t var = 0; var < num_vars; ++var) {
|
||||
if (use_tracker.var_use[var]) {
|
||||
continue;
|
||||
}
|
||||
use_tracker.num_used = (std::max)(use_tracker.num_used, var + 1);
|
||||
use_tracker.var_use[var] = true;
|
||||
Id ret{};
|
||||
ret.is_valid.Assign(1);
|
||||
ret.type.Assign(type);
|
||||
ret.index.Assign(static_cast<u32>(var));
|
||||
return ret;
|
||||
}
|
||||
// Allocate a new variable
|
||||
use_tracker.var_use.push_back(true);
|
||||
Id ret{};
|
||||
ret.is_valid.Assign(1);
|
||||
ret.type.Assign(type);
|
||||
ret.index.Assign(static_cast<u32>(use_tracker.num_used));
|
||||
++use_tracker.num_used;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void VarAlloc::Free(Id id) {
|
||||
if (id.is_valid == 0) {
|
||||
throw LogicError("Freeing invalid variable");
|
||||
}
|
||||
auto& use_tracker{GetUseTracker(id.type)};
|
||||
use_tracker.var_use[id.index] = false;
|
||||
}
|
||||
|
||||
WgslVarType VarAlloc::RegType(IR::Type type) const {
|
||||
switch (type) {
|
||||
case IR::Type::U1:
|
||||
return WgslVarType::U1;
|
||||
case IR::Type::U32:
|
||||
return WgslVarType::U32;
|
||||
case IR::Type::F32:
|
||||
return WgslVarType::F32;
|
||||
case IR::Type::U64:
|
||||
return WgslVarType::U64;
|
||||
case IR::Type::F64:
|
||||
return WgslVarType::F64;
|
||||
default:
|
||||
throw NotImplementedException("IR type {}", type);
|
||||
}
|
||||
}
|
||||
|
||||
std::string VarAlloc::GetWgslType(WgslVarType type) const {
|
||||
switch (type) {
|
||||
case WgslVarType::U1:
|
||||
return "bool";
|
||||
case WgslVarType::F16x2: // no f16 in core WebGPU: half pairs are carried as f32 pairs
|
||||
case WgslVarType::F32x2:
|
||||
return "vec2<f32>";
|
||||
case WgslVarType::U32:
|
||||
return "u32";
|
||||
case WgslVarType::F32:
|
||||
case WgslVarType::PrecF32:
|
||||
return "f32";
|
||||
case WgslVarType::U64: // no 64-bit integers either: low and high words
|
||||
case WgslVarType::U32x2:
|
||||
return "vec2<u32>";
|
||||
case WgslVarType::U32x3:
|
||||
return "vec3<u32>";
|
||||
case WgslVarType::F32x3:
|
||||
return "vec3<f32>";
|
||||
case WgslVarType::U32x4:
|
||||
return "vec4<u32>";
|
||||
case WgslVarType::F32x4:
|
||||
return "vec4<f32>";
|
||||
case WgslVarType::F64:
|
||||
case WgslVarType::PrecF64:
|
||||
throw NotImplementedException("WGSL has no 64-bit floats");
|
||||
case WgslVarType::Void:
|
||||
return "";
|
||||
default:
|
||||
throw NotImplementedException("Type {}", type);
|
||||
}
|
||||
}
|
||||
|
||||
VarAlloc::UseTracker& VarAlloc::GetUseTracker(WgslVarType type) {
|
||||
switch (type) {
|
||||
case WgslVarType::U1:
|
||||
return var_bool;
|
||||
case WgslVarType::F16x2:
|
||||
return var_f16x2;
|
||||
case WgslVarType::U32:
|
||||
return var_u32;
|
||||
case WgslVarType::F32:
|
||||
return var_f32;
|
||||
case WgslVarType::U64:
|
||||
return var_u64;
|
||||
case WgslVarType::F64:
|
||||
return var_f64;
|
||||
case WgslVarType::U32x2:
|
||||
return var_u32x2;
|
||||
case WgslVarType::F32x2:
|
||||
return var_f32x2;
|
||||
case WgslVarType::U32x3:
|
||||
return var_u32x3;
|
||||
case WgslVarType::F32x3:
|
||||
return var_f32x3;
|
||||
case WgslVarType::U32x4:
|
||||
return var_u32x4;
|
||||
case WgslVarType::F32x4:
|
||||
return var_f32x4;
|
||||
case WgslVarType::PrecF32:
|
||||
return var_precf32;
|
||||
case WgslVarType::PrecF64:
|
||||
return var_precf64;
|
||||
default:
|
||||
throw NotImplementedException("Type {}", type);
|
||||
}
|
||||
}
|
||||
|
||||
const VarAlloc::UseTracker& VarAlloc::GetUseTracker(WgslVarType type) const {
|
||||
switch (type) {
|
||||
case WgslVarType::U1:
|
||||
return var_bool;
|
||||
case WgslVarType::F16x2:
|
||||
return var_f16x2;
|
||||
case WgslVarType::U32:
|
||||
return var_u32;
|
||||
case WgslVarType::F32:
|
||||
return var_f32;
|
||||
case WgslVarType::U64:
|
||||
return var_u64;
|
||||
case WgslVarType::F64:
|
||||
return var_f64;
|
||||
case WgslVarType::U32x2:
|
||||
return var_u32x2;
|
||||
case WgslVarType::F32x2:
|
||||
return var_f32x2;
|
||||
case WgslVarType::U32x3:
|
||||
return var_u32x3;
|
||||
case WgslVarType::F32x3:
|
||||
return var_f32x3;
|
||||
case WgslVarType::U32x4:
|
||||
return var_u32x4;
|
||||
case WgslVarType::F32x4:
|
||||
return var_f32x4;
|
||||
case WgslVarType::PrecF32:
|
||||
return var_precf32;
|
||||
case WgslVarType::PrecF64:
|
||||
return var_precf64;
|
||||
default:
|
||||
throw NotImplementedException("Type {}", type);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Shader::Backend::WGSL
|
||||
104
gpu/third_party/suyu/shader_recompiler/backend/wgsl/var_alloc.h
vendored
Normal file
104
gpu/third_party/suyu/shader_recompiler/backend/wgsl/var_alloc.h
vendored
Normal file
@@ -0,0 +1,104 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <bitset>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "common/bit_field.h"
|
||||
#include "common/common_types.h"
|
||||
|
||||
namespace Shader::IR {
|
||||
class Inst;
|
||||
class Value;
|
||||
enum class Type;
|
||||
} // namespace Shader::IR
|
||||
|
||||
namespace Shader::Backend::WGSL {
|
||||
enum class WgslVarType : u32 {
|
||||
U1,
|
||||
F16x2,
|
||||
U32,
|
||||
F32,
|
||||
U64,
|
||||
F64,
|
||||
U32x2,
|
||||
F32x2,
|
||||
U32x3,
|
||||
F32x3,
|
||||
U32x4,
|
||||
F32x4,
|
||||
PrecF32,
|
||||
PrecF64,
|
||||
Void,
|
||||
};
|
||||
|
||||
struct Id {
|
||||
union {
|
||||
u32 raw;
|
||||
BitField<0, 1, u32> is_valid;
|
||||
BitField<1, 4, WgslVarType> type;
|
||||
BitField<6, 26, u32> index;
|
||||
};
|
||||
|
||||
bool operator==(Id rhs) const noexcept {
|
||||
return raw == rhs.raw;
|
||||
}
|
||||
bool operator!=(Id rhs) const noexcept {
|
||||
return !operator==(rhs);
|
||||
}
|
||||
};
|
||||
static_assert(sizeof(Id) == sizeof(u32));
|
||||
|
||||
class VarAlloc {
|
||||
public:
|
||||
struct UseTracker {
|
||||
bool uses_temp{};
|
||||
size_t num_used{};
|
||||
std::vector<bool> var_use;
|
||||
};
|
||||
|
||||
/// Used for explicit usages of variables, may revert to temporaries
|
||||
std::string Define(IR::Inst& inst, WgslVarType type);
|
||||
std::string Define(IR::Inst& inst, IR::Type type);
|
||||
|
||||
/// Used to assign variables used by the IR. May return a blank string if
|
||||
/// the instruction's result is unused in the IR.
|
||||
std::string AddDefine(IR::Inst& inst, WgslVarType type);
|
||||
std::string PhiDefine(IR::Inst& inst, IR::Type type);
|
||||
|
||||
std::string Consume(const IR::Value& value);
|
||||
std::string ConsumeInst(IR::Inst& inst);
|
||||
|
||||
std::string GetWgslType(WgslVarType type) const;
|
||||
std::string GetWgslType(IR::Type type) const;
|
||||
|
||||
const UseTracker& GetUseTracker(WgslVarType type) const;
|
||||
std::string Representation(u32 index, WgslVarType type) const;
|
||||
|
||||
private:
|
||||
WgslVarType RegType(IR::Type type) const;
|
||||
Id Alloc(WgslVarType type);
|
||||
void Free(Id id);
|
||||
UseTracker& GetUseTracker(WgslVarType type);
|
||||
std::string Representation(Id id) const;
|
||||
|
||||
UseTracker var_bool{};
|
||||
UseTracker var_f16x2{};
|
||||
UseTracker var_u32{};
|
||||
UseTracker var_u32x2{};
|
||||
UseTracker var_u32x3{};
|
||||
UseTracker var_u32x4{};
|
||||
UseTracker var_f32{};
|
||||
UseTracker var_f32x2{};
|
||||
UseTracker var_f32x3{};
|
||||
UseTracker var_f32x4{};
|
||||
UseTracker var_u64{};
|
||||
UseTracker var_f64{};
|
||||
UseTracker var_precf32{};
|
||||
UseTracker var_precf64{};
|
||||
};
|
||||
|
||||
} // namespace Shader::Backend::WGSL
|
||||
482
gpu/third_party/suyu/shader_recompiler/backend/wgsl/wgsl_emit_context.cpp
vendored
Normal file
482
gpu/third_party/suyu/shader_recompiler/backend/wgsl/wgsl_emit_context.cpp
vendored
Normal file
@@ -0,0 +1,482 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
//
|
||||
// WGSL backend (Rexcomp): derived from suyu's GLSL backend context. Module-scope declarations for one shader stage
|
||||
// of a WebGPU pipeline.
|
||||
//
|
||||
// Layout:
|
||||
// - every resource of a stage is in one bind group: vertex 0, fragment 1, compute 0; binding numbers come from
|
||||
// Bindings::unified in declaration order (the uniform block, constant buffers indexed at run time, storage
|
||||
// buffers, textures (each a texture then its sampler), images)
|
||||
// - binding 0, the stage's uniform block <stage>_ub: array<vec4<u32>, N>, which the renderer binds at a dynamic
|
||||
// offset per draw: [0] resolution scaling, [1] render area, [2] (ax, bx, ay, by), [3] (az, bz, vertex id
|
||||
// offset, instance id offset): the viewport transform the vertex stage applies (WebGPU has no negative or
|
||||
// out-of-target viewports), [4 + t] the component swizzle of texture t (WebGPU views have none), then the
|
||||
// constant buffers (raw words; floats are bitcast), each at its base in declaration order
|
||||
// - constant buffers indexed at run time: var<storage, read> <stage>_cbuf<i>: array<vec4<u32>> of the bound size
|
||||
// - storage buffers: var<storage, read|read_write> <stage>_ssbo<i>: array<u32>
|
||||
// - GLSL's built-ins (gl_Position, gl_FragCoord, ...) and the stage's inputs/outputs (in_attr<i>, out_attr<i>,
|
||||
// frag_color<i>) are module-scope private variables with the GLSL names, so the instruction emitters read
|
||||
// like the GLSL backend's; the entry point (emit_wgsl.cpp) copies them from/to the WGSL built-ins and locations.
|
||||
|
||||
#include "common/div_ceil.h"
|
||||
#include "shader_recompiler/backend/bindings.h"
|
||||
#include "shader_recompiler/backend/wgsl/wgsl_emit_context.h"
|
||||
#include "shader_recompiler/frontend/ir/program.h"
|
||||
#include "shader_recompiler/profile.h"
|
||||
#include "shader_recompiler/runtime_info.h"
|
||||
|
||||
namespace Shader::Backend::WGSL {
|
||||
namespace {
|
||||
std::string_view ColorTextureType(TextureType type, bool is_multisample) {
|
||||
switch (type) {
|
||||
case TextureType::Color1D:
|
||||
return "texture_1d<f32>";
|
||||
case TextureType::Color2D:
|
||||
case TextureType::Color2DRect:
|
||||
return is_multisample ? "texture_multisampled_2d<f32>" : "texture_2d<f32>";
|
||||
case TextureType::ColorArray2D:
|
||||
return "texture_2d_array<f32>";
|
||||
case TextureType::Color3D:
|
||||
return "texture_3d<f32>";
|
||||
case TextureType::ColorCube:
|
||||
return "texture_cube<f32>";
|
||||
case TextureType::ColorArrayCube:
|
||||
return "texture_cube_array<f32>";
|
||||
default:
|
||||
throw NotImplementedException("WGSL texture type {}", type);
|
||||
}
|
||||
}
|
||||
|
||||
std::string_view DepthTextureType(TextureType type) {
|
||||
switch (type) {
|
||||
case TextureType::Color2D:
|
||||
case TextureType::Color2DRect:
|
||||
return "texture_depth_2d";
|
||||
case TextureType::ColorArray2D:
|
||||
return "texture_depth_2d_array";
|
||||
case TextureType::ColorCube:
|
||||
return "texture_depth_cube";
|
||||
case TextureType::ColorArrayCube:
|
||||
return "texture_depth_cube_array";
|
||||
default:
|
||||
throw NotImplementedException("WGSL depth texture type {}", type);
|
||||
}
|
||||
}
|
||||
|
||||
std::string_view StorageTextureType(TextureType type) {
|
||||
switch (type) {
|
||||
case TextureType::Color1D:
|
||||
return "texture_storage_1d";
|
||||
case TextureType::Color2D:
|
||||
return "texture_storage_2d";
|
||||
case TextureType::ColorArray2D:
|
||||
return "texture_storage_2d_array";
|
||||
case TextureType::Color3D:
|
||||
return "texture_storage_3d";
|
||||
default:
|
||||
throw NotImplementedException("WGSL storage texture type {}", type);
|
||||
}
|
||||
}
|
||||
|
||||
std::string_view StorageFormat(ImageFormat format) {
|
||||
switch (format) {
|
||||
case ImageFormat::Typeless:
|
||||
case ImageFormat::R32_UINT:
|
||||
return "r32uint";
|
||||
case ImageFormat::R32G32_UINT:
|
||||
return "rg32uint";
|
||||
case ImageFormat::R32G32B32A32_UINT:
|
||||
return "rgba32uint";
|
||||
default:
|
||||
throw NotImplementedException("WGSL storage texture format {}", format);
|
||||
}
|
||||
}
|
||||
} // Anonymous namespace
|
||||
|
||||
thread_local std::array<u8, 64> ssbo_alias_next{};
|
||||
thread_local std::array<u32, 64> ssbo_alias_words_next{};
|
||||
thread_local bool vs_as_compute_next{};
|
||||
thread_local std::array<std::string, 16> image_formats_next{};
|
||||
|
||||
EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile& profile_,
|
||||
const RuntimeInfo& runtime_info_)
|
||||
: info{program.info}, profile{profile_}, runtime_info{runtime_info_}, stage{program.stage} {
|
||||
ssbo_alias = ssbo_alias_next;
|
||||
ssbo_alias_next = {};
|
||||
ssbo_alias_words = ssbo_alias_words_next;
|
||||
ssbo_alias_words_next = {};
|
||||
vs_compute = vs_as_compute_next && (stage == Stage::VertexA || stage == Stage::VertexB);
|
||||
vs_as_compute_next = false;
|
||||
image_formats = image_formats_next;
|
||||
image_formats_next = {};
|
||||
for (IR::Block* const block : program.blocks) {
|
||||
for (IR::Inst& inst : block->Instructions()) {
|
||||
const std::string_view name{IR::NameOf(inst.GetOpcode())};
|
||||
if (name.starts_with("StorageAtomic") && inst.Arg(0).IsImmediate() && inst.Arg(0).U32() < 64) {
|
||||
atomic_ssbo.set(MapSsbo(inst.Arg(0).U32()));
|
||||
} else if (name.starts_with("SharedAtomic")) {
|
||||
atomic_smem = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
switch (program.stage) {
|
||||
case Stage::VertexA:
|
||||
case Stage::VertexB:
|
||||
stage_name = "vs";
|
||||
group = 0;
|
||||
break;
|
||||
case Stage::Fragment:
|
||||
stage_name = "fs";
|
||||
position_name = "gl_FragCoord";
|
||||
group = 1;
|
||||
break;
|
||||
case Stage::Compute:
|
||||
stage_name = "cs";
|
||||
group = 0;
|
||||
break;
|
||||
default:
|
||||
throw NotImplementedException("WebGPU has no {} shaders", program.stage);
|
||||
}
|
||||
header += "diagnostic(off, derivative_uniformity);\n";
|
||||
DefineBuiltins();
|
||||
for (size_t index = 0; index < IR::NUM_GENERICS; ++index) {
|
||||
if (info.loads.Generic(index)) {
|
||||
header += fmt::format("var<private> in_attr{}: vec4<f32>;\n", index);
|
||||
}
|
||||
if (info.stores.Generic(index)) {
|
||||
header += fmt::format("var<private> out_attr{}: vec4<f32>;\n", index);
|
||||
const GenericElementInfo element_info{
|
||||
.name = fmt::format("out_attr{}", index),
|
||||
.first_element = 0,
|
||||
.num_components = 4,
|
||||
};
|
||||
output_generics[index].fill(element_info);
|
||||
}
|
||||
}
|
||||
if (stage == Stage::Fragment) {
|
||||
for (size_t index = 0; index < info.stores_frag_color.size(); ++index) {
|
||||
if (info.stores_frag_color[index]) {
|
||||
header += fmt::format("var<private> frag_color{}: vec4<f32>;\n", index);
|
||||
}
|
||||
}
|
||||
}
|
||||
// binding 0: the uniform block (see the layout above)
|
||||
ub_name = fmt::format("{}_ub", stage_name);
|
||||
ub_size = 4 + 2 * static_cast<u32>(info.texture_descriptors.size());
|
||||
if (!(info.uses_global_memory || info.uses_cbuf_indirect)) {
|
||||
// in declaration order, while they fit (the renderer lays the block out the same way)
|
||||
for (const auto& desc : info.constant_buffer_descriptors) {
|
||||
const u32 size{(std::max)(Common::DivCeil(info.constant_buffer_used_sizes[desc.index], 16U), 1U)};
|
||||
if (runtime_info.cbuf_ub_limit && desc.index >= 3 &&
|
||||
info.constant_buffer_used_sizes[desc.index] > runtime_info.cbuf_ub_limit) {
|
||||
continue; // (bound in place: copying it for every draw costs more)
|
||||
}
|
||||
if (ub_size + size > 0x1000) {
|
||||
continue;
|
||||
}
|
||||
cbuf_in_ub[desc.index] = true;
|
||||
ub_cbuf_base[desc.index] = ub_size;
|
||||
ub_size += size;
|
||||
}
|
||||
}
|
||||
header += fmt::format("@group({}) @binding({}) var<uniform> {}: array<vec4<u32>, {}>;\n", group,
|
||||
bindings.unified++, ub_name, ub_size);
|
||||
header += fmt::format("fn rescale_(i: u32) -> vec4<f32> {{ return bitcast<vec4<f32>>({}[i]); }}\n", ub_name);
|
||||
// Depth for a 16-bit target, on its step: the nearest step (halves up) plus a quarter, so that rounding and
|
||||
// truncating conversions agree and a value one draw writes passes another draw's EQUAL test (TOTK keeps
|
||||
// material numbers in a D16 target as 0.5 + id/510: even numbers fall halfway between two steps). On when
|
||||
// render_area().z is not 0 (the renderer sets it for draws into a 16-bit depth target).
|
||||
header += "fn d16q_(d: f32) -> f32 { return min((floor(clamp(d, 0.0, 1.0) * 65535.0 + 0.5) + 0.25) / 65535.0, 1.0); }\n";
|
||||
header += "fn scaling() -> vec4<f32> { return rescale_(0u); }\n"
|
||||
"fn render_area() -> vec4<f32> { return rescale_(1u); }\n";
|
||||
// opq_(x) == x, but the host compiler cannot see it (the uniform block's lane [0].w is always 0): it keeps an
|
||||
// addition of a tiny epsilon from being reassociated away, e.g. (1 - a) + 1e-10 into (1 + 1e-10) - a = 1 - a,
|
||||
// which then divides by zero where the guest's compiler kept the epsilon
|
||||
header += fmt::format("fn opq_(x: f32) -> f32 {{ return bitcast<f32>(bitcast<u32>(x) | {}[0u].w); }}\n", ub_name);
|
||||
DefineConstantBuffers(bindings);
|
||||
DefineConstantBufferIndirect();
|
||||
DefineStorageBuffers(bindings);
|
||||
SetupTextures(bindings);
|
||||
SetupImages(bindings);
|
||||
DefineHelperFunctions();
|
||||
DefineConstants();
|
||||
}
|
||||
|
||||
void EmitContext::DefineBuiltins() {
|
||||
header += "var<private> gl_Position: vec4<f32>;\n"
|
||||
"var<private> gl_FragCoord: vec4<f32>;\n"
|
||||
"var<private> gl_VertexID: i32;\n"
|
||||
"var<private> gl_InstanceID: i32;\n"
|
||||
"var<private> gl_BaseVertex: i32;\n"
|
||||
"var<private> gl_BaseInstance: i32;\n"
|
||||
"var<private> gl_DrawID: i32;\n"
|
||||
"var<private> gl_FrontFacing: bool;\n"
|
||||
"var<private> gl_FragDepth: f32;\n"
|
||||
"var<private> gl_PointSize: f32;\n"
|
||||
"var<private> gl_PointCoord: vec2<f32>;\n"
|
||||
"var<private> gl_ClipDistance: array<f32, 8>;\n"
|
||||
"var<private> gl_Layer: i32;\n"
|
||||
"var<private> gl_ViewportIndex: i32;\n"
|
||||
"var<private> gl_PrimitiveID: i32;\n"
|
||||
"var<private> gl_SampleID: i32;\n"
|
||||
"var<private> gl_SampleMask: array<i32, 1>;\n"
|
||||
"var<private> gl_HelperInvocation: bool;\n"
|
||||
"var<private> gl_LocalInvocationID: vec3<u32>;\n"
|
||||
"var<private> gl_WorkGroupID: vec3<u32>;\n"
|
||||
"var<private> gl_SubGroupInvocationARB: u32;\n"
|
||||
"var<private> discarded_: bool;\n"
|
||||
"var<private> F32_INF_: u32 = 0x7f800000u;\n"
|
||||
"var<private> F32_NINF_: u32 = 0xff800000u;\n"
|
||||
"var<private> F32_NAN_: u32 = 0x7fc00000u;\n"
|
||||
// a call is never a const-expression: literal arguments of log2, sqrt, ... are not folded (and so
|
||||
// not rejected) at shader creation
|
||||
"fn rt_(x: f32) -> f32 { return x; }\n";
|
||||
}
|
||||
|
||||
void EmitContext::DefineConstantBuffers(Bindings& bindings) {
|
||||
for (const auto& desc : info.constant_buffer_descriptors) {
|
||||
if (cbuf_in_ub[desc.index]) {
|
||||
continue;
|
||||
}
|
||||
// not in the uniform block (indexed at run time, or no room): a read-only storage buffer of the bound size
|
||||
header += fmt::format("@group({}) @binding({}) var<storage, read> {}_cbuf{}: array<vec4<u32>>;\n", group,
|
||||
bindings.unified, stage_name, desc.index);
|
||||
// reads at a run-time offset (CbufAt): past the bound size the hardware reads 0, where WebGPU's bounds checks
|
||||
// would give the buffer's last vec4 (TOTK's particle programs index their emitter's tables so: long spikes)
|
||||
if (!CbufClamp()) {
|
||||
header += fmt::format("fn {0}_cbuf{1}_at(i: u32) -> vec4<u32> {{ if (i < arrayLength(&{0}_cbuf{1})) {{ "
|
||||
"return {0}_cbuf{1}[i]; }} return vec4<u32>(0u); }}\n",
|
||||
stage_name, desc.index);
|
||||
}
|
||||
cbuf_bindings.push_back({bindings.unified, desc.index});
|
||||
bindings.unified += desc.count;
|
||||
}
|
||||
}
|
||||
|
||||
void EmitContext::DefineConstantBufferIndirect() {
|
||||
if (!info.uses_cbuf_indirect) {
|
||||
return;
|
||||
}
|
||||
header += "fn GetCbufIndirect(binding: u32, offset: u32) -> vec4<u32> {\n switch (binding) {\n";
|
||||
for (const auto& desc : info.constant_buffer_descriptors) {
|
||||
header += fmt::format(fmt::runtime(CbufClamp() ? " case {0}u: {{ return {1}_cbuf{0}[offset]; }}\n"
|
||||
: " case {0}u: {{ return {1}_cbuf{0}_at(offset); }}\n"),
|
||||
desc.index, stage_name);
|
||||
}
|
||||
header += " default: { return vec4<u32>(0u); }\n }\n}\n";
|
||||
}
|
||||
|
||||
void EmitContext::DefineStorageBuffers(Bindings& bindings) {
|
||||
u32 index{};
|
||||
for (const auto& desc : info.storage_buffers_descriptors) {
|
||||
if (index < 64 && ssbo_alias[index]) { // (uses another descriptor's binding)
|
||||
bindings.unified += desc.count;
|
||||
index += desc.count;
|
||||
continue;
|
||||
}
|
||||
// WebGPU forbids writable storage buffers in vertex shaders
|
||||
// compute: every storage buffer read_write (they may share one GPU buffer, and WebGPU forbids a buffer in
|
||||
// one dispatch as both read-only and writable storage)
|
||||
const bool writable{stage == Stage::Compute ||
|
||||
(desc.is_written && ((stage != Stage::VertexA && stage != Stage::VertexB) || vs_compute))};
|
||||
const bool atomic{index < 64 && atomic_ssbo[index]};
|
||||
header += fmt::format("@group({}) @binding({}) var<storage, {}> {}_ssbo{}: array<{}>;\n", group,
|
||||
bindings.unified, writable || atomic ? "read_write" : "read", stage_name, index,
|
||||
atomic ? "atomic<u32>" : "u32");
|
||||
ssbo_bindings.push_back({bindings.unified, index});
|
||||
bindings.unified += desc.count;
|
||||
index += desc.count;
|
||||
}
|
||||
}
|
||||
|
||||
void EmitContext::SetupTextures(Bindings& bindings) {
|
||||
if (!info.texture_buffer_descriptors.empty()) {
|
||||
throw NotImplementedException("WGSL texture buffers");
|
||||
}
|
||||
textures.reserve(info.texture_descriptors.size());
|
||||
// Browsers allow 16 samplers a stage (wgpu more): from the 17th texture on, a texture samples with the sampler of
|
||||
// the last earlier texture of its kind that has one (gpu/render/rx_draw.cpp binds the same way)
|
||||
u32 last_own[2] = {0, 0}; // the last texture with a sampler of its own, by is_depth (binding + 1; 0: none)
|
||||
for (const auto& desc : info.texture_descriptors) {
|
||||
if (desc.count > 1) {
|
||||
throw NotImplementedException("WGSL texture arrays");
|
||||
}
|
||||
const u32 binding{bindings.unified};
|
||||
u32 shared{0};
|
||||
#ifdef __EMSCRIPTEN__
|
||||
if (textures.size() >= 16) shared = last_own[desc.is_depth ? 1 : 0]; // (binding + 1)
|
||||
#endif
|
||||
textures.push_back({binding, desc.count, shared});
|
||||
if (!shared) last_own[desc.is_depth ? 1 : 0] = binding + 1;
|
||||
const auto type{desc.is_depth ? DepthTextureType(desc.type)
|
||||
: ColorTextureType(desc.type, desc.is_multisample)};
|
||||
header += fmt::format("@group({}) @binding({}) var tex{}: {};\n", group, binding, binding, type);
|
||||
if (!shared)
|
||||
header += fmt::format("@group({}) @binding({}) var samp{}: {};\n", group, binding + 1, binding,
|
||||
desc.is_depth ? "sampler_comparison" : "sampler");
|
||||
// WebGPU texture views have no component swizzle and samplers no border color or LOD bias: per texture,
|
||||
// two slots of the uniform block: [0] the TIC's component mapping (0-7 each; x bits 3-5: the axes whose
|
||||
// wrap mode is border, y bits 3-5: the sampler's depth compare function, z bits 8-31: the sampler's LOD bias
|
||||
// in 1/256), [1] the border color
|
||||
const u32 swizzle_index{4 + 2 * static_cast<u32>(textures.size() - 1)};
|
||||
header += fmt::format("fn swizzle{}(v: vec4<f32>) -> vec4<f32> {{\n"
|
||||
" let s = {}[{}u] & vec4<u32>(7u);\n"
|
||||
" let c = array<f32,8>(0.0,0.0,v.x,v.y,v.z,v.w,1.0,1.0);\n"
|
||||
" return vec4<f32>(c[s.x],c[s.y],c[s.z],c[s.w]);\n}}\n",
|
||||
binding, ub_name, swizzle_index);
|
||||
header += fmt::format("fn lodbias{}() -> f32 {{ return f32(bitcast<i32>({}[{}u].z) >> 8u) / 256.0; }}\n",
|
||||
binding, ub_name, swizzle_index);
|
||||
header += fmt::format(
|
||||
"fn outside{0}(c: vec3<f32>) -> bool {{\n"
|
||||
" let m = ({1}[{2}u].x >> 3u) & 7u;\n"
|
||||
" return ((m & 1u) != 0u && (c.x < 0.0 || c.x > 1.0)) || ((m & 2u) != 0u && (c.y < 0.0 || c.y > 1.0)) ||"
|
||||
" ((m & 4u) != 0u && (c.z < 0.0 || c.z > 1.0));\n}}\n"
|
||||
"fn border{0}(c: vec3<f32>, v: vec4<f32>) -> vec4<f32> {{\n"
|
||||
" return select(v, bitcast<vec4<f32>>({1}[{3}u]), outside{0}(c));\n}}\n"
|
||||
"fn bordercmp{0}(c: vec3<f32>, dref: f32, v: f32) -> f32 {{\n"
|
||||
" if (!outside{0}(c)) {{ return v; }}\n"
|
||||
" let b = bitcast<f32>({1}[{3}u].x);\n"
|
||||
" switch (({1}[{2}u].y >> 3u) & 7u) {{\n"
|
||||
" case 0u: {{ return 0.0; }}\n"
|
||||
" case 1u: {{ return select(0.0, 1.0, dref < b); }}\n"
|
||||
" case 2u: {{ return select(0.0, 1.0, dref == b); }}\n"
|
||||
" case 3u: {{ return select(0.0, 1.0, dref <= b); }}\n"
|
||||
" case 4u: {{ return select(0.0, 1.0, dref > b); }}\n"
|
||||
" case 5u: {{ return select(0.0, 1.0, dref != b); }}\n"
|
||||
" case 6u: {{ return select(0.0, 1.0, dref >= b); }}\n"
|
||||
" default: {{ return 1.0; }}\n"
|
||||
" }}\n}}\n",
|
||||
binding, ub_name, swizzle_index, swizzle_index + 1);
|
||||
texture_bindings.push_back({binding, static_cast<u32>(textures.size() - 1)});
|
||||
bindings.unified += 2;
|
||||
}
|
||||
}
|
||||
|
||||
void EmitContext::SetupImages(Bindings& bindings) {
|
||||
if (!info.image_buffer_descriptors.empty()) {
|
||||
throw NotImplementedException("WGSL image buffers");
|
||||
}
|
||||
images.reserve(info.image_descriptors.size());
|
||||
for (const auto& desc : info.image_descriptors) {
|
||||
if (desc.count > 1) {
|
||||
throw NotImplementedException("WGSL image arrays");
|
||||
}
|
||||
// (mkw-recomp) the bound image's format when the renderer gives it; the access the program needs
|
||||
const size_t index = images.size();
|
||||
const std::string format = index < image_formats.size() && !image_formats[index].empty()
|
||||
? image_formats[index] : std::string(StorageFormat(desc.format));
|
||||
const u32 kind = format.ends_with("uint") ? 0U : format.ends_with("sint") ? 2U : 1U;
|
||||
images.push_back({bindings.unified, desc.count, 0, kind});
|
||||
header += fmt::format("@group({}) @binding({}) var img{}: {}<{}, {}>;\n", group, bindings.unified,
|
||||
bindings.unified, StorageTextureType(desc.type), format,
|
||||
desc.is_written ? (desc.is_read ? "read_write" : "write") : "read");
|
||||
bindings.unified += 1;
|
||||
}
|
||||
}
|
||||
|
||||
void EmitContext::DefineHelperFunctions() {
|
||||
header += "fn add64(a: vec2<u32>, b: vec2<u32>) -> vec2<u32> {"
|
||||
" let lo = a.x + b.x; return vec2<u32>(lo, a.y + b.y + select(0u, 1u, lo < a.x)); }\n"
|
||||
"fn sub64(a: vec2<u32>, b: vec2<u32>) -> vec2<u32> {"
|
||||
" return vec2<u32>(a.x - b.x, a.y - b.y - select(0u, 1u, a.x < b.x)); }\n"
|
||||
"fn shl64(a: vec2<u32>, s: u32) -> vec2<u32> {"
|
||||
" if (s == 0u) { return a; } if (s >= 32u) { return vec2<u32>(0u, a.x << (s - 32u)); }"
|
||||
" return vec2<u32>(a.x << s, (a.y << s) | (a.x >> (32u - s))); }\n"
|
||||
"fn shr64(a: vec2<u32>, s: u32) -> vec2<u32> {"
|
||||
" if (s == 0u) { return a; } if (s >= 32u) { return vec2<u32>(a.y >> (s - 32u), 0u); }"
|
||||
" return vec2<u32>((a.x >> s) | (a.y << (32u - s)), a.y >> s); }\n"
|
||||
"fn sar64(a: vec2<u32>, s: u32) -> vec2<u32> {"
|
||||
" let hi = i32(a.y); if (s == 0u) { return a; }"
|
||||
" if (s >= 32u) { return vec2<u32>(u32(hi >> (s - 32u)), u32(hi >> 31u)); }"
|
||||
" return vec2<u32>((a.x >> s) | (a.y << (32u - s)), u32(hi >> s)); }\n";
|
||||
header += "fn isnan_(x: f32) -> bool { return (bitcast<u32>(x) & 0x7fffffffu) > 0x7f800000u; }\n"
|
||||
"fn isinf_(x: f32) -> bool { return (bitcast<u32>(x) & 0x7fffffffu) == 0x7f800000u; }\n"
|
||||
"fn isnan2_(x: vec2<f32>) -> vec2<bool> { return vec2<bool>(isnan_(x.x), isnan_(x.y)); }\n"
|
||||
// a NaN level of detail or bias picks level 0 on Maxwell (its fixed-point conversion); on PC GPUs the
|
||||
// sample itself becomes NaN (TOTK: white blobs from an environment cube sampled at a NaN roughness LOD)
|
||||
"fn lodok_(x: f32) -> f32 { return select(x, 0.0, isnan_(x)); }\n";
|
||||
if (info.uses_global_increment || info.uses_shared_increment) {
|
||||
header += "fn CasIncrement(op_a: u32, op_b: u32) -> u32 { return select(op_a + 1u, 0u, op_a >= op_b); }\n";
|
||||
}
|
||||
if (info.uses_global_decrement || info.uses_shared_decrement) {
|
||||
header += "fn CasDecrement(op_a: u32, op_b: u32) -> u32 {"
|
||||
" return select(op_a - 1u, op_b, op_a == 0u || op_a > op_b); }\n";
|
||||
}
|
||||
if (info.uses_atomic_f32_add) {
|
||||
header += "fn CasFloatAdd(op_a: u32, op_b: f32) -> u32 { return bitcast<u32>(bitcast<f32>(op_a) + op_b); }\n";
|
||||
}
|
||||
if (info.uses_atomic_s32_min) {
|
||||
header += "fn CasMinS32(op_a: u32, op_b: u32) -> u32 { return u32(min(i32(op_a), i32(op_b))); }\n";
|
||||
}
|
||||
if (info.uses_atomic_s32_max) {
|
||||
header += "fn CasMaxS32(op_a: u32, op_b: u32) -> u32 { return u32(max(i32(op_a), i32(op_b))); }\n";
|
||||
}
|
||||
if (info.uses_global_memory) {
|
||||
throw NotImplementedException("WGSL global memory (64-bit addresses)");
|
||||
}
|
||||
if (info.loads_indexed_attributes) {
|
||||
std::string func{"fn IndexedAttrLoad(offset: i32) -> f32 {\n"
|
||||
" let base_index = offset >> 2u;\n let masked_index = u32(base_index) & 3u;\n"
|
||||
" switch (base_index >> 2u) {\n"};
|
||||
if (info.loads.AnyComponent(IR::Attribute::PositionX)) {
|
||||
func += fmt::format(" case {}: {{ return {}[masked_index]; }}\n",
|
||||
static_cast<u32>(IR::Attribute::PositionX) >> 2, position_name);
|
||||
}
|
||||
const u32 base_attribute_value = static_cast<u32>(IR::Attribute::Generic0X) >> 2;
|
||||
for (u32 index = 0; index < IR::NUM_GENERICS; ++index) {
|
||||
if (info.loads.Generic(index)) {
|
||||
func += fmt::format(" case {}: {{ return in_attr{}[masked_index]; }}\n",
|
||||
base_attribute_value + index, index);
|
||||
}
|
||||
}
|
||||
func += " default: { return 0.0f; }\n }\n}\n";
|
||||
header += func;
|
||||
}
|
||||
}
|
||||
|
||||
void EmitContext::DefineConstants() {
|
||||
if (info.uses_fswzadd) {
|
||||
header += "var<private> FSWZ_A: array<f32, 4> = array<f32, 4>(-1.0f, 1.0f, -1.0f, 0.0f);\n"
|
||||
"var<private> FSWZ_B: array<f32, 4> = array<f32, 4>(-1.0f, -1.0f, 1.0f, -1.0f);\n";
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Shader::Backend::WGSL
|
||||
|
||||
namespace Shader::Backend::WGSL {
|
||||
std::string EmitContext::SsboPtr(u32 binding, std::string_view word) const {
|
||||
const std::string w{SsboWord(binding, word)};
|
||||
word = w;
|
||||
binding = MapSsbo(binding);
|
||||
return fmt::format("&{}_ssbo{}[{}]", stage_name, binding, word);
|
||||
}
|
||||
|
||||
std::string EmitContext::SsboLoad(u32 binding, std::string_view word) const {
|
||||
const std::string w{SsboWord(binding, word)};
|
||||
word = w;
|
||||
binding = MapSsbo(binding);
|
||||
if (binding < 64 && atomic_ssbo[binding]) {
|
||||
return fmt::format("atomicLoad(&{}_ssbo{}[{}])", stage_name, binding, word);
|
||||
}
|
||||
return fmt::format("{}_ssbo{}[{}]", stage_name, binding, word);
|
||||
}
|
||||
|
||||
std::string EmitContext::SsboStore(u32 binding, std::string_view word, std::string_view value) const {
|
||||
const std::string w{SsboWord(binding, word)};
|
||||
word = w;
|
||||
binding = MapSsbo(binding);
|
||||
if (binding < 64 && atomic_ssbo[binding]) {
|
||||
return fmt::format("atomicStore(&{}_ssbo{}[{}],{});", stage_name, binding, word, value);
|
||||
}
|
||||
return fmt::format("{}_ssbo{}[{}]={};", stage_name, binding, word, value);
|
||||
}
|
||||
|
||||
std::string EmitContext::SmemLoad(std::string_view word) const {
|
||||
return atomic_smem ? fmt::format("atomicLoad(&smem[{}])", word) : fmt::format("smem[{}]", word);
|
||||
}
|
||||
|
||||
std::string EmitContext::SmemStore(std::string_view word, std::string_view value) const {
|
||||
return atomic_smem ? fmt::format("atomicStore(&smem[{}],{});", word, value) : fmt::format("smem[{}]={};", word, value);
|
||||
}
|
||||
} // namespace Shader::Backend::WGSL
|
||||
223
gpu/third_party/suyu/shader_recompiler/backend/wgsl/wgsl_emit_context.h
vendored
Normal file
223
gpu/third_party/suyu/shader_recompiler/backend/wgsl/wgsl_emit_context.h
vendored
Normal file
@@ -0,0 +1,223 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <bitset>
|
||||
#include <cstdlib>
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <fmt/ranges.h>
|
||||
|
||||
#include "shader_recompiler/backend/wgsl/var_alloc.h"
|
||||
#include "shader_recompiler/stage.h"
|
||||
|
||||
namespace Shader {
|
||||
struct Info;
|
||||
struct Profile;
|
||||
struct RuntimeInfo;
|
||||
} // namespace Shader
|
||||
|
||||
namespace Shader::Backend {
|
||||
struct Bindings;
|
||||
}
|
||||
|
||||
namespace Shader::IR {
|
||||
class Inst;
|
||||
struct Program;
|
||||
} // namespace Shader::IR
|
||||
|
||||
namespace Shader::Backend::WGSL {
|
||||
|
||||
/// RX_CBUF_CLAMP=1: constant buffer reads at run-time offsets past the bound size get WebGPU's clamped read (the old
|
||||
/// translation) instead of the hardware's 0 (<stage>_cbuf<n>_at).
|
||||
inline bool CbufClamp() {
|
||||
static const bool clamp = std::getenv("RX_CBUF_CLAMP") != nullptr;
|
||||
return clamp;
|
||||
}
|
||||
|
||||
struct GenericElementInfo {
|
||||
std::string name;
|
||||
u32 first_element{};
|
||||
u32 num_components{};
|
||||
};
|
||||
|
||||
struct TextureImageDefinition {
|
||||
u32 binding;
|
||||
u32 count;
|
||||
u32 sampler_plus1 = 0; // the texture whose sampler it samples with, binding + 1 (0: its own; shared: web)
|
||||
u32 kind = 0; // (mkw-recomp, images: the declared format's texel type: 0 u32, 1 f32, 2 i32)
|
||||
u32 textures_sampler_binding() const { return sampler_plus1 ? sampler_plus1 - 1 : binding; }
|
||||
};
|
||||
|
||||
/// A resource of the stage's bind group: its binding number and the descriptor index it serves.
|
||||
struct ResourceBinding {
|
||||
u32 binding;
|
||||
u32 index;
|
||||
};
|
||||
|
||||
class EmitContext {
|
||||
public:
|
||||
explicit EmitContext(IR::Program& program, Bindings& bindings, const Profile& profile_,
|
||||
const RuntimeInfo& runtime_info_);
|
||||
|
||||
template <WgslVarType type, typename... Args>
|
||||
void Add(const char* format_str, IR::Inst& inst, Args&&... args) {
|
||||
const auto var_def{var_alloc.AddDefine(inst, type)};
|
||||
if (var_def.empty()) {
|
||||
// the result is unused: WGSL needs a phony assignment to evaluate an expression for its effects
|
||||
code += "_=";
|
||||
code += fmt::format(fmt::runtime(format_str + 3), std::forward<Args>(args)...);
|
||||
} else {
|
||||
code += fmt::format(fmt::runtime(format_str), var_def, std::forward<Args>(args)...);
|
||||
}
|
||||
// TODO: Remove this
|
||||
code += '\n';
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void AddU1(const char* format_str, IR::Inst& inst, Args&&... args) {
|
||||
Add<WgslVarType::U1>(format_str, inst, args...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void AddF16x2(const char* format_str, IR::Inst& inst, Args&&... args) {
|
||||
Add<WgslVarType::F16x2>(format_str, inst, args...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void AddU32(const char* format_str, IR::Inst& inst, Args&&... args) {
|
||||
Add<WgslVarType::U32>(format_str, inst, args...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void AddF32(const char* format_str, IR::Inst& inst, Args&&... args) {
|
||||
Add<WgslVarType::F32>(format_str, inst, args...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void AddU64(const char* format_str, IR::Inst& inst, Args&&... args) {
|
||||
Add<WgslVarType::U64>(format_str, inst, args...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void AddF64(const char* format_str, IR::Inst& inst, Args&&... args) {
|
||||
Add<WgslVarType::F64>(format_str, inst, args...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void AddU32x2(const char* format_str, IR::Inst& inst, Args&&... args) {
|
||||
Add<WgslVarType::U32x2>(format_str, inst, args...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void AddF32x2(const char* format_str, IR::Inst& inst, Args&&... args) {
|
||||
Add<WgslVarType::F32x2>(format_str, inst, args...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void AddU32x3(const char* format_str, IR::Inst& inst, Args&&... args) {
|
||||
Add<WgslVarType::U32x3>(format_str, inst, args...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void AddF32x3(const char* format_str, IR::Inst& inst, Args&&... args) {
|
||||
Add<WgslVarType::F32x3>(format_str, inst, args...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void AddU32x4(const char* format_str, IR::Inst& inst, Args&&... args) {
|
||||
Add<WgslVarType::U32x4>(format_str, inst, args...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void AddF32x4(const char* format_str, IR::Inst& inst, Args&&... args) {
|
||||
Add<WgslVarType::F32x4>(format_str, inst, args...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void AddPrecF32(const char* format_str, IR::Inst& inst, Args&&... args) {
|
||||
Add<WgslVarType::PrecF32>(format_str, inst, args...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void AddPrecF64(const char* format_str, IR::Inst& inst, Args&&... args) {
|
||||
Add<WgslVarType::PrecF64>(format_str, inst, args...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void Add(const char* format_str, Args&&... args) {
|
||||
code += fmt::format(fmt::runtime(format_str), std::forward<Args>(args)...);
|
||||
// TODO: Remove this
|
||||
code += '\n';
|
||||
}
|
||||
|
||||
std::string header;
|
||||
std::string code;
|
||||
VarAlloc var_alloc;
|
||||
const Info& info;
|
||||
const Profile& profile;
|
||||
const RuntimeInfo& runtime_info;
|
||||
|
||||
Stage stage{};
|
||||
std::string_view stage_name = "invalid";
|
||||
std::string_view position_name = "gl_Position";
|
||||
u32 group{}; ///< the bind group of this stage's resources
|
||||
|
||||
/// The stage's uniform block (binding 0, bound at a dynamic offset per draw): its name, size in vec4s, and
|
||||
/// which constant buffers are in it and where (the others are storage buffers: indexed at run time, or no
|
||||
/// room left in the 64 KB a uniform binding may have).
|
||||
std::string ub_name;
|
||||
u32 ub_size{};
|
||||
std::array<bool, 18> cbuf_in_ub{};
|
||||
std::array<u32, 18> ub_cbuf_base{};
|
||||
|
||||
std::vector<ResourceBinding> cbuf_bindings;
|
||||
std::vector<ResourceBinding> ssbo_bindings;
|
||||
// Storage buffers (by index) and shared memory an atomic operation touches: declared array<atomic<u32>> and
|
||||
// read and written through atomicLoad / atomicStore (WGSL atomics need atomic-typed memory)
|
||||
std::bitset<64> atomic_ssbo;
|
||||
std::array<u8, 64> ssbo_alias{}; // (see ssbo_alias_next)
|
||||
bool vs_compute{}; // (see vs_as_compute_next)
|
||||
std::array<std::string, 16> image_formats{}; // (see image_formats_next)
|
||||
std::array<u32, 64> ssbo_alias_words{};
|
||||
std::string SsboWord(u32 binding, std::string_view word) const {
|
||||
return binding < 64 && ssbo_alias[binding] && ssbo_alias_words[binding]
|
||||
? fmt::format("(({}) + {}u)", word, ssbo_alias_words[binding]) : std::string(word);
|
||||
}
|
||||
u32 MapSsbo(u32 binding) const { return binding < 64 && ssbo_alias[binding] ? ssbo_alias[binding] - 1u : binding; }
|
||||
bool atomic_smem{};
|
||||
std::string SsboLoad(u32 binding, std::string_view word) const;
|
||||
std::string SsboStore(u32 binding, std::string_view word, std::string_view value) const;
|
||||
std::string SsboPtr(u32 binding, std::string_view word) const;
|
||||
std::string SmemLoad(std::string_view word) const;
|
||||
std::string SmemStore(std::string_view word, std::string_view value) const;
|
||||
std::vector<ResourceBinding> texture_bindings;
|
||||
|
||||
std::vector<TextureImageDefinition> texture_buffers;
|
||||
std::vector<TextureImageDefinition> image_buffers;
|
||||
std::vector<TextureImageDefinition> textures;
|
||||
std::vector<TextureImageDefinition> images;
|
||||
std::array<std::array<GenericElementInfo, 4>, 32> output_generics{};
|
||||
|
||||
u32 num_safety_loop_vars{};
|
||||
|
||||
bool uses_y_direction{};
|
||||
bool uses_cc_carry{};
|
||||
bool uses_geometry_passthrough{};
|
||||
|
||||
private:
|
||||
void DefineBuiltins();
|
||||
void DefineConstantBuffers(Bindings& bindings);
|
||||
void DefineConstantBufferIndirect();
|
||||
void DefineStorageBuffers(Bindings& bindings);
|
||||
void DefineHelperFunctions();
|
||||
void DefineConstants();
|
||||
void SetupImages(Bindings& bindings);
|
||||
void SetupTextures(Bindings& bindings);
|
||||
};
|
||||
|
||||
} // namespace Shader::Backend::WGSL
|
||||
138
gpu/third_party/suyu/shader_recompiler/environment.h
vendored
Normal file
138
gpu/third_party/suyu/shader_recompiler/environment.h
vendored
Normal file
@@ -0,0 +1,138 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2026 suyu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <ankerl/unordered_dense.h>
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "shader_recompiler/program_header.h"
|
||||
#include "shader_recompiler/shader_info.h"
|
||||
#include "shader_recompiler/stage.h"
|
||||
#include "shader_recompiler/frontend/ir/value.h"
|
||||
|
||||
namespace Shader::IR {
|
||||
class Inst;
|
||||
}
|
||||
|
||||
namespace Shader {
|
||||
|
||||
struct CbufWordKey {
|
||||
u32 index;
|
||||
u32 offset;
|
||||
constexpr bool operator==(const CbufWordKey& o) const noexcept {
|
||||
return index == o.index && offset == o.offset;
|
||||
}
|
||||
};
|
||||
|
||||
struct CbufWordKeyHash {
|
||||
constexpr size_t operator()(const CbufWordKey& k) const noexcept {
|
||||
return (size_t(k.index) << 32) ^ k.offset;
|
||||
}
|
||||
};
|
||||
|
||||
struct HandleKey {
|
||||
u32 index, offset, shift_left;
|
||||
u32 sec_index, sec_offset, sec_shift_left;
|
||||
u32 count;
|
||||
bool has_secondary;
|
||||
constexpr bool operator==(const HandleKey& o) const noexcept {
|
||||
return std::tie(index, offset, shift_left, sec_index, sec_offset, sec_shift_left, count, has_secondary)
|
||||
== std::tie(o.index, o.offset, o.shift_left, o.sec_index, o.sec_offset, o.sec_shift_left, o.count, o.has_secondary);
|
||||
}
|
||||
};
|
||||
struct HandleKeyHash {
|
||||
constexpr size_t operator()(const HandleKey& k) const noexcept {
|
||||
size_t h = (size_t(k.index) << 32) ^ k.offset;
|
||||
h ^= (size_t(k.shift_left) << 1);
|
||||
h ^= (size_t(k.sec_index) << 33) ^ (size_t(k.sec_offset) << 2);
|
||||
h ^= (size_t(k.sec_shift_left) << 3);
|
||||
h ^= (size_t(k.count) << 7);
|
||||
return h ^ (k.has_secondary ? 0x9e3779b97f4a7c15ULL : 0ULL);
|
||||
}
|
||||
};
|
||||
|
||||
struct ConstBufferAddr {
|
||||
u32 index;
|
||||
u32 offset;
|
||||
u32 shift_left;
|
||||
u32 secondary_index;
|
||||
u32 secondary_offset;
|
||||
u32 secondary_shift_left;
|
||||
IR::U32 dynamic_offset;
|
||||
u32 count;
|
||||
bool has_secondary;
|
||||
};
|
||||
|
||||
class Environment {
|
||||
public:
|
||||
virtual ~Environment() = default;
|
||||
|
||||
[[nodiscard]] virtual u64 ReadInstruction(u32 address) = 0;
|
||||
|
||||
/// (mkw-recomp, from Eglantine) an indirect branch's target, from the native program's address to the
|
||||
/// translated one's: Ampere programs are lowered to Maxwell (frontend/ampere) before the Maxwell frontend
|
||||
[[nodiscard]] virtual u32 TranslateProgramAddress(u32 address) const { return address; }
|
||||
|
||||
[[nodiscard]] virtual u32 ReadCbufValue(u32 cbuf_index, u32 cbuf_offset) = 0;
|
||||
|
||||
[[nodiscard]] virtual TextureType ReadTextureType(u32 raw_handle) = 0;
|
||||
|
||||
[[nodiscard]] virtual TexturePixelFormat ReadTexturePixelFormat(u32 raw_handle) = 0;
|
||||
|
||||
[[nodiscard]] virtual bool IsTexturePixelFormatInteger(u32 raw_handle) = 0;
|
||||
|
||||
[[nodiscard]] virtual u32 ReadViewportTransformState() = 0;
|
||||
|
||||
[[nodiscard]] virtual u32 TextureBoundBuffer() const = 0;
|
||||
|
||||
[[nodiscard]] virtual u32 LocalMemorySize() const = 0;
|
||||
|
||||
[[nodiscard]] virtual u32 SharedMemorySize() const = 0;
|
||||
|
||||
[[nodiscard]] virtual std::array<u32, 3> WorkgroupSize() const = 0;
|
||||
|
||||
[[nodiscard]] virtual bool HasHLEMacroState() const = 0;
|
||||
|
||||
[[nodiscard]] virtual std::optional<ReplaceConstant> GetReplaceConstBuffer(u32 bank,
|
||||
u32 offset) = 0;
|
||||
|
||||
virtual void Dump(u64 pipeline_hash, u64 shader_hash) = 0;
|
||||
|
||||
[[nodiscard]] const ProgramHeader& SPH() const noexcept {
|
||||
return sph;
|
||||
}
|
||||
|
||||
[[nodiscard]] const std::array<u32, 8>& GpPassthroughMask() const noexcept {
|
||||
return gp_passthrough_mask;
|
||||
}
|
||||
|
||||
[[nodiscard]] Stage ShaderStage() const noexcept {
|
||||
return stage;
|
||||
}
|
||||
|
||||
[[nodiscard]] u32 StartAddress() const noexcept {
|
||||
return start_address;
|
||||
}
|
||||
|
||||
[[nodiscard]] bool IsProprietaryDriver() const noexcept {
|
||||
return is_proprietary_driver;
|
||||
}
|
||||
|
||||
protected:
|
||||
ProgramHeader sph{};
|
||||
std::array<u32, 8> gp_passthrough_mask{};
|
||||
Stage stage{};
|
||||
u32 start_address{};
|
||||
bool is_proprietary_driver{};
|
||||
public:
|
||||
ankerl::unordered_dense::map<CbufWordKey, u32, CbufWordKeyHash> cbuf_word_cache;
|
||||
ankerl::unordered_dense::map<HandleKey, u32, HandleKeyHash> handle_cache;
|
||||
ankerl::unordered_dense::map<const IR::Inst*, ConstBufferAddr> track_cache;
|
||||
};
|
||||
|
||||
} // namespace Shader
|
||||
67
gpu/third_party/suyu/shader_recompiler/exception.h
vendored
Normal file
67
gpu/third_party/suyu/shader_recompiler/exception.h
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2026 suyu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <exception>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "common/logging.h"
|
||||
|
||||
namespace Shader {
|
||||
|
||||
class Exception : public std::exception {
|
||||
public:
|
||||
explicit Exception(std::string message) noexcept : err_message{std::move(message)} {}
|
||||
|
||||
[[nodiscard]] const char* what() const noexcept override {
|
||||
return err_message.c_str();
|
||||
}
|
||||
|
||||
void Prepend(std::string_view prepend) {
|
||||
err_message.insert(0, prepend);
|
||||
}
|
||||
|
||||
void Append(std::string_view append) {
|
||||
err_message += append;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string err_message;
|
||||
};
|
||||
|
||||
class LogicError : public Exception {
|
||||
public:
|
||||
template <typename... Args>
|
||||
explicit LogicError(const char* message, Args&&... args)
|
||||
: Exception{fmt::format(fmt::runtime(message), std::forward<Args>(args)...)} {}
|
||||
};
|
||||
|
||||
class RuntimeError : public Exception {
|
||||
public:
|
||||
template <typename... Args>
|
||||
explicit RuntimeError(const char* message, Args&&... args)
|
||||
: Exception{fmt::format(fmt::runtime(message), std::forward<Args>(args)...)} {}
|
||||
};
|
||||
|
||||
class NotImplementedException : public Exception {
|
||||
public:
|
||||
template <typename... Args>
|
||||
explicit NotImplementedException(const char* message, Args&&... args)
|
||||
: Exception{fmt::format(fmt::runtime(message), std::forward<Args>(args)...)} {
|
||||
Append(" is not implemented");
|
||||
}
|
||||
};
|
||||
|
||||
class InvalidArgument : public Exception {
|
||||
public:
|
||||
template <typename... Args>
|
||||
explicit InvalidArgument(const char* message, Args&&... args)
|
||||
: Exception{fmt::format(fmt::runtime(message), std::forward<Args>(args)...)} {}
|
||||
};
|
||||
|
||||
} // namespace Shader
|
||||
2289
gpu/third_party/suyu/shader_recompiler/frontend/ampere/lower_to_maxwell.h
vendored
Normal file
2289
gpu/third_party/suyu/shader_recompiler/frontend/ampere/lower_to_maxwell.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
29
gpu/third_party/suyu/shader_recompiler/frontend/ampere/program_address_map.h
vendored
Normal file
29
gpu/third_party/suyu/shader_recompiler/frontend/ampere/program_address_map.h
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#pragma once
|
||||
#include <optional>
|
||||
#include <span>
|
||||
#include <vector>
|
||||
#include "common/common_types.h"
|
||||
|
||||
namespace Shader::Ampere {
|
||||
constexpr u64 NativeAddressMapMagic = 0x50414d4e4544454eULL;
|
||||
inline bool HasNativeAddressMap(std::span<const u64> code) {
|
||||
return code.size() >= 2 && code.back() == NativeAddressMapMagic;
|
||||
}
|
||||
inline void AppendNativeAddressMap(std::vector<u64>& code, std::span<const u32> offsets) {
|
||||
if (offsets.empty()) return;
|
||||
for (u32 index : offsets) code.push_back(0x50U + index * 8 + ((index + 1) / 3) * 8);
|
||||
code.push_back(offsets.size());
|
||||
code.push_back(NativeAddressMapMagic);
|
||||
}
|
||||
inline std::optional<u32> NativeProgramAddress(std::span<const u64> code, u32 address) {
|
||||
if (!HasNativeAddressMap(code) || address % 16) return {};
|
||||
const u64 count = code[code.size() - 2];
|
||||
if (!count || count > 65536 || count + 2 > code.size() || address / 16 >= count) return {};
|
||||
const size_t start = code.size() - static_cast<size_t>(count) - 2;
|
||||
const u64 target = code[start + address / 16];
|
||||
if (target < 0x50 || target >= start * 8 || target % 8 || target % 32 == 0) return {};
|
||||
return static_cast<u32>(target);
|
||||
}
|
||||
} // namespace Shader::Ampere
|
||||
54
gpu/third_party/suyu/shader_recompiler/frontend/ampere/program_capture.h
vendored
Normal file
54
gpu/third_party/suyu/shader_recompiler/frontend/ampere/program_capture.h
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#pragma once
|
||||
|
||||
#include "shader_recompiler/frontend/ampere/lower_to_maxwell.h"
|
||||
|
||||
namespace Shader::Ampere {
|
||||
class ProgramCaptureState {
|
||||
public:
|
||||
enum class Result { Continue, Complete, InvalidTarget };
|
||||
static constexpr u32 MaximumInstructions = 65536;
|
||||
|
||||
Result Observe(const Instruction& instruction, u32 index) {
|
||||
const u32 opcode = instruction.Bits(0, 12);
|
||||
if (opcode == 0x944 || opcode == 0x947 || opcode == 0x945) {
|
||||
const u64 raw = instruction.words[1] | (u64{instruction.words[2] & 0x3ffff} << 32);
|
||||
const s64 relative = opcode == 0x945 ? static_cast<s32>(instruction.words[1])
|
||||
: static_cast<s64>(raw << 14) >> 14;
|
||||
const s64 target = s64{index} * 16 + 16 + relative;
|
||||
if (target < 0 || target % 16 || target >= MaximumInstructions * 16)
|
||||
return Result::InvalidTarget;
|
||||
// CALL.REL.NOINC (bit 86) pushes no return address: the compiler uses it as a jump
|
||||
// (the lowering treats it as one), so it never pairs with a RET.
|
||||
const bool noinc_call = opcode == 0x944 && (instruction.words[2] & 0x400000) != 0;
|
||||
if (opcode == 0x944 && !noinc_call) {
|
||||
last_call_target = std::max(last_call_target, static_cast<u32>(target / 16));
|
||||
} else {
|
||||
last_forward_target = std::max(last_forward_target, static_cast<u32>(target / 16));
|
||||
}
|
||||
// The compiler ends every program with an unconditional branch to itself; with a jump
|
||||
// table (whose targets live in a constant buffer) that is the only reliable end.
|
||||
if (opcode == 0x947 && computed_branch && instruction.Bits(12, 4) == 7 &&
|
||||
target == s64{index} * 16)
|
||||
return Result::Complete;
|
||||
}
|
||||
if (opcode == 0x949 || opcode == 0x958) computed_branch = true;
|
||||
if (computed_branch) return Result::Continue;
|
||||
if (opcode == 0x94d && instruction.Bits(12, 4) == 7 && index >= last_forward_target) {
|
||||
if (!last_call_target) return Result::Complete;
|
||||
main_exited = true;
|
||||
}
|
||||
if (opcode == 0x950 && instruction.Bits(12, 4) == 7 && main_exited &&
|
||||
index >= last_call_target && index >= last_forward_target)
|
||||
return Result::Complete;
|
||||
return Result::Continue;
|
||||
}
|
||||
|
||||
private:
|
||||
u32 last_call_target{};
|
||||
u32 last_forward_target{};
|
||||
bool main_exited{};
|
||||
bool computed_branch{};
|
||||
};
|
||||
} // namespace Shader::Ampere
|
||||
85
gpu/third_party/suyu/shader_recompiler/frontend/ampere/program_override.h
vendored
Normal file
85
gpu/third_party/suyu/shader_recompiler/frontend/ampere/program_override.h
vendored
Normal file
@@ -0,0 +1,85 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#pragma once
|
||||
|
||||
#include <cstring>
|
||||
#include "shader_recompiler/frontend/ampere/lower_to_maxwell.h"
|
||||
|
||||
namespace Shader::Ampere {
|
||||
|
||||
inline u64 NativeProgramKey(std::span<const Instruction> source) {
|
||||
u64 hash = 14695981039346656037ULL;
|
||||
for (const auto& instruction : source) {
|
||||
for (u32 word : instruction.words) {
|
||||
for (u32 byte = 0; byte < 4; ++byte) hash = (hash ^ ((word >> (byte * 8)) & 255)) * 1099511628211ULL;
|
||||
}
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
// Private iteration format: version, lengths, texture bank, exact original
|
||||
// instructions, then the newly generated canonical instructions. Source bytes
|
||||
// are compared directly; the filename hash is only an index.
|
||||
inline std::vector<u8> EncodeProgramOverride(std::span<const Instruction> source,
|
||||
const LoweredProgram& program) {
|
||||
if (!program || program.source_size != source.size_bytes() || program.source_instruction_offsets.size() != source.size()) return {};
|
||||
const std::array<u32, 6> header{0x4e454445, 0x3230564f,
|
||||
static_cast<u32>(source.size_bytes()), static_cast<u32>(program.instructions.size()),
|
||||
program.required_texture_buffer, static_cast<u32>(program.source_instruction_offsets.size())};
|
||||
std::vector<u8> bytes(sizeof(header) + source.size_bytes() + program.instructions.size() * 8 + program.source_instruction_offsets.size() * 4);
|
||||
std::memcpy(bytes.data(), header.data(), sizeof(header));
|
||||
std::memcpy(bytes.data() + sizeof(header), source.data(), source.size_bytes());
|
||||
std::memcpy(bytes.data() + sizeof(header) + source.size_bytes(), program.instructions.data(), program.instructions.size() * 8);
|
||||
std::memcpy(bytes.data() + sizeof(header) + source.size_bytes() + program.instructions.size() * 8,
|
||||
program.source_instruction_offsets.data(), program.source_instruction_offsets.size() * 4);
|
||||
return bytes;
|
||||
}
|
||||
|
||||
inline u32 ProgramOverrideSourceSize(std::span<const u8> bytes) {
|
||||
std::array<u32, 6> header{};
|
||||
if (bytes.size() < sizeof(header)) return 0;
|
||||
std::memcpy(header.data(), bytes.data(), sizeof(header));
|
||||
const bool mapped = header[1] == 0x3230564f;
|
||||
if (header[0] != 0x4e454445 || (!mapped && header[1] != 0x3130564f) ||
|
||||
(mapped ? header[5] != header[2] / 16 : header[5] != 0) ||
|
||||
header[2] == 0 || header[2] % sizeof(Instruction) || header[2] > 1048576 ||
|
||||
header[3] == 0 || header[3] > 1048576 || (header[4] != ~0U && header[4] >= 18)) return 0;
|
||||
if (bytes.size() != sizeof(header) + size_t{header[2]} + size_t{header[3]} * 8 + size_t{header[5]} * 4) return 0;
|
||||
return header[2];
|
||||
}
|
||||
|
||||
inline LoweredProgram DecodeProgramOverride(std::span<const u8> bytes,
|
||||
std::span<const Instruction> source) {
|
||||
LoweredProgram result;
|
||||
const auto fail = [&result](std::string_view message) {
|
||||
result.instructions.clear();
|
||||
result.source_instruction_offsets.clear();
|
||||
result.error = message;
|
||||
return result;
|
||||
};
|
||||
std::array<u32, 6> header{};
|
||||
if (!ProgramOverrideSourceSize(bytes)) return fail("invalid native override header or length");
|
||||
std::memcpy(header.data(), bytes.data(), sizeof(header));
|
||||
if (header[2] != source.size_bytes()) return fail("native override source length mismatch");
|
||||
if (std::memcmp(bytes.data() + sizeof(header), source.data(), source.size_bytes()))
|
||||
return fail("native override source mismatch");
|
||||
result.instructions.resize(header[3]);
|
||||
std::memcpy(result.instructions.data(), bytes.data() + sizeof(header) + source.size_bytes(), header[3] * 8);
|
||||
if (header[5]) {
|
||||
result.source_instruction_offsets.resize(header[5]);
|
||||
std::memcpy(result.source_instruction_offsets.data(),
|
||||
bytes.data() + sizeof(header) + source.size_bytes() + size_t{header[3]} * 8,
|
||||
size_t{header[5]} * 4);
|
||||
u32 previous = 0;
|
||||
for (u32 offset : result.source_instruction_offsets) {
|
||||
if (offset >= result.instructions.size() || offset < previous)
|
||||
return fail("native override address map mismatch");
|
||||
previous = offset;
|
||||
}
|
||||
}
|
||||
result.source_size = header[2];
|
||||
result.required_texture_buffer = header[4];
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace Shader::Ampere
|
||||
57
gpu/third_party/suyu/shader_recompiler/frontend/ir/abstract_syntax_list.h
vendored
Normal file
57
gpu/third_party/suyu/shader_recompiler/frontend/ir/abstract_syntax_list.h
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "shader_recompiler/frontend/ir/value.h"
|
||||
|
||||
namespace Shader::IR {
|
||||
|
||||
class Block;
|
||||
|
||||
struct AbstractSyntaxNode {
|
||||
enum class Type {
|
||||
Block,
|
||||
If,
|
||||
EndIf,
|
||||
Loop,
|
||||
Repeat,
|
||||
Break,
|
||||
Return,
|
||||
Unreachable,
|
||||
};
|
||||
union Data {
|
||||
Block* block;
|
||||
struct {
|
||||
U1 cond;
|
||||
Block* body;
|
||||
Block* merge;
|
||||
} if_node;
|
||||
struct {
|
||||
Block* merge;
|
||||
} end_if;
|
||||
struct {
|
||||
Block* body;
|
||||
Block* continue_block;
|
||||
Block* merge;
|
||||
} loop;
|
||||
struct {
|
||||
U1 cond;
|
||||
Block* loop_header;
|
||||
Block* merge;
|
||||
} repeat;
|
||||
struct {
|
||||
U1 cond;
|
||||
Block* merge;
|
||||
Block* skip;
|
||||
} break_node;
|
||||
};
|
||||
|
||||
Data data{};
|
||||
Type type{};
|
||||
};
|
||||
using AbstractSyntaxList = std::vector<AbstractSyntaxNode>;
|
||||
|
||||
} // namespace Shader::IR
|
||||
459
gpu/third_party/suyu/shader_recompiler/frontend/ir/attribute.cpp
vendored
Normal file
459
gpu/third_party/suyu/shader_recompiler/frontend/ir/attribute.cpp
vendored
Normal file
@@ -0,0 +1,459 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <fmt/format.h>
|
||||
|
||||
#include "shader_recompiler/exception.h"
|
||||
#include "shader_recompiler/frontend/ir/attribute.h"
|
||||
|
||||
namespace Shader::IR {
|
||||
|
||||
bool IsGeneric(Attribute attribute) noexcept {
|
||||
return attribute >= Attribute::Generic0X && attribute <= Attribute::Generic31X;
|
||||
}
|
||||
|
||||
u32 GenericAttributeIndex(Attribute attribute) {
|
||||
if (!IsGeneric(attribute)) {
|
||||
throw InvalidArgument("Attribute is not generic {}", attribute);
|
||||
}
|
||||
return (static_cast<u32>(attribute) - static_cast<u32>(Attribute::Generic0X)) / 4u;
|
||||
}
|
||||
|
||||
u32 GenericAttributeElement(Attribute attribute) {
|
||||
if (!IsGeneric(attribute)) {
|
||||
throw InvalidArgument("Attribute is not generic {}", attribute);
|
||||
}
|
||||
return static_cast<u32>(attribute) % 4;
|
||||
}
|
||||
|
||||
std::string NameOf(Attribute attribute) {
|
||||
switch (attribute) {
|
||||
case Attribute::PrimitiveId:
|
||||
return "PrimitiveId";
|
||||
case Attribute::Layer:
|
||||
return "Layer";
|
||||
case Attribute::ViewportIndex:
|
||||
return "ViewportIndex";
|
||||
case Attribute::PointSize:
|
||||
return "PointSize";
|
||||
case Attribute::PositionX:
|
||||
return "Position.X";
|
||||
case Attribute::PositionY:
|
||||
return "Position.Y";
|
||||
case Attribute::PositionZ:
|
||||
return "Position.Z";
|
||||
case Attribute::PositionW:
|
||||
return "Position.W";
|
||||
case Attribute::Generic0X:
|
||||
return "Generic[0].X";
|
||||
case Attribute::Generic0Y:
|
||||
return "Generic[0].Y";
|
||||
case Attribute::Generic0Z:
|
||||
return "Generic[0].Z";
|
||||
case Attribute::Generic0W:
|
||||
return "Generic[0].W";
|
||||
case Attribute::Generic1X:
|
||||
return "Generic[1].X";
|
||||
case Attribute::Generic1Y:
|
||||
return "Generic[1].Y";
|
||||
case Attribute::Generic1Z:
|
||||
return "Generic[1].Z";
|
||||
case Attribute::Generic1W:
|
||||
return "Generic[1].W";
|
||||
case Attribute::Generic2X:
|
||||
return "Generic[2].X";
|
||||
case Attribute::Generic2Y:
|
||||
return "Generic[2].Y";
|
||||
case Attribute::Generic2Z:
|
||||
return "Generic[2].Z";
|
||||
case Attribute::Generic2W:
|
||||
return "Generic[2].W";
|
||||
case Attribute::Generic3X:
|
||||
return "Generic[3].X";
|
||||
case Attribute::Generic3Y:
|
||||
return "Generic[3].Y";
|
||||
case Attribute::Generic3Z:
|
||||
return "Generic[3].Z";
|
||||
case Attribute::Generic3W:
|
||||
return "Generic[3].W";
|
||||
case Attribute::Generic4X:
|
||||
return "Generic[4].X";
|
||||
case Attribute::Generic4Y:
|
||||
return "Generic[4].Y";
|
||||
case Attribute::Generic4Z:
|
||||
return "Generic[4].Z";
|
||||
case Attribute::Generic4W:
|
||||
return "Generic[4].W";
|
||||
case Attribute::Generic5X:
|
||||
return "Generic[5].X";
|
||||
case Attribute::Generic5Y:
|
||||
return "Generic[5].Y";
|
||||
case Attribute::Generic5Z:
|
||||
return "Generic[5].Z";
|
||||
case Attribute::Generic5W:
|
||||
return "Generic[5].W";
|
||||
case Attribute::Generic6X:
|
||||
return "Generic[6].X";
|
||||
case Attribute::Generic6Y:
|
||||
return "Generic[6].Y";
|
||||
case Attribute::Generic6Z:
|
||||
return "Generic[6].Z";
|
||||
case Attribute::Generic6W:
|
||||
return "Generic[6].W";
|
||||
case Attribute::Generic7X:
|
||||
return "Generic[7].X";
|
||||
case Attribute::Generic7Y:
|
||||
return "Generic[7].Y";
|
||||
case Attribute::Generic7Z:
|
||||
return "Generic[7].Z";
|
||||
case Attribute::Generic7W:
|
||||
return "Generic[7].W";
|
||||
case Attribute::Generic8X:
|
||||
return "Generic[8].X";
|
||||
case Attribute::Generic8Y:
|
||||
return "Generic[8].Y";
|
||||
case Attribute::Generic8Z:
|
||||
return "Generic[8].Z";
|
||||
case Attribute::Generic8W:
|
||||
return "Generic[8].W";
|
||||
case Attribute::Generic9X:
|
||||
return "Generic[9].X";
|
||||
case Attribute::Generic9Y:
|
||||
return "Generic[9].Y";
|
||||
case Attribute::Generic9Z:
|
||||
return "Generic[9].Z";
|
||||
case Attribute::Generic9W:
|
||||
return "Generic[9].W";
|
||||
case Attribute::Generic10X:
|
||||
return "Generic[10].X";
|
||||
case Attribute::Generic10Y:
|
||||
return "Generic[10].Y";
|
||||
case Attribute::Generic10Z:
|
||||
return "Generic[10].Z";
|
||||
case Attribute::Generic10W:
|
||||
return "Generic[10].W";
|
||||
case Attribute::Generic11X:
|
||||
return "Generic[11].X";
|
||||
case Attribute::Generic11Y:
|
||||
return "Generic[11].Y";
|
||||
case Attribute::Generic11Z:
|
||||
return "Generic[11].Z";
|
||||
case Attribute::Generic11W:
|
||||
return "Generic[11].W";
|
||||
case Attribute::Generic12X:
|
||||
return "Generic[12].X";
|
||||
case Attribute::Generic12Y:
|
||||
return "Generic[12].Y";
|
||||
case Attribute::Generic12Z:
|
||||
return "Generic[12].Z";
|
||||
case Attribute::Generic12W:
|
||||
return "Generic[12].W";
|
||||
case Attribute::Generic13X:
|
||||
return "Generic[13].X";
|
||||
case Attribute::Generic13Y:
|
||||
return "Generic[13].Y";
|
||||
case Attribute::Generic13Z:
|
||||
return "Generic[13].Z";
|
||||
case Attribute::Generic13W:
|
||||
return "Generic[13].W";
|
||||
case Attribute::Generic14X:
|
||||
return "Generic[14].X";
|
||||
case Attribute::Generic14Y:
|
||||
return "Generic[14].Y";
|
||||
case Attribute::Generic14Z:
|
||||
return "Generic[14].Z";
|
||||
case Attribute::Generic14W:
|
||||
return "Generic[14].W";
|
||||
case Attribute::Generic15X:
|
||||
return "Generic[15].X";
|
||||
case Attribute::Generic15Y:
|
||||
return "Generic[15].Y";
|
||||
case Attribute::Generic15Z:
|
||||
return "Generic[15].Z";
|
||||
case Attribute::Generic15W:
|
||||
return "Generic[15].W";
|
||||
case Attribute::Generic16X:
|
||||
return "Generic[16].X";
|
||||
case Attribute::Generic16Y:
|
||||
return "Generic[16].Y";
|
||||
case Attribute::Generic16Z:
|
||||
return "Generic[16].Z";
|
||||
case Attribute::Generic16W:
|
||||
return "Generic[16].W";
|
||||
case Attribute::Generic17X:
|
||||
return "Generic[17].X";
|
||||
case Attribute::Generic17Y:
|
||||
return "Generic[17].Y";
|
||||
case Attribute::Generic17Z:
|
||||
return "Generic[17].Z";
|
||||
case Attribute::Generic17W:
|
||||
return "Generic[17].W";
|
||||
case Attribute::Generic18X:
|
||||
return "Generic[18].X";
|
||||
case Attribute::Generic18Y:
|
||||
return "Generic[18].Y";
|
||||
case Attribute::Generic18Z:
|
||||
return "Generic[18].Z";
|
||||
case Attribute::Generic18W:
|
||||
return "Generic[18].W";
|
||||
case Attribute::Generic19X:
|
||||
return "Generic[19].X";
|
||||
case Attribute::Generic19Y:
|
||||
return "Generic[19].Y";
|
||||
case Attribute::Generic19Z:
|
||||
return "Generic[19].Z";
|
||||
case Attribute::Generic19W:
|
||||
return "Generic[19].W";
|
||||
case Attribute::Generic20X:
|
||||
return "Generic[20].X";
|
||||
case Attribute::Generic20Y:
|
||||
return "Generic[20].Y";
|
||||
case Attribute::Generic20Z:
|
||||
return "Generic[20].Z";
|
||||
case Attribute::Generic20W:
|
||||
return "Generic[20].W";
|
||||
case Attribute::Generic21X:
|
||||
return "Generic[21].X";
|
||||
case Attribute::Generic21Y:
|
||||
return "Generic[21].Y";
|
||||
case Attribute::Generic21Z:
|
||||
return "Generic[21].Z";
|
||||
case Attribute::Generic21W:
|
||||
return "Generic[21].W";
|
||||
case Attribute::Generic22X:
|
||||
return "Generic[22].X";
|
||||
case Attribute::Generic22Y:
|
||||
return "Generic[22].Y";
|
||||
case Attribute::Generic22Z:
|
||||
return "Generic[22].Z";
|
||||
case Attribute::Generic22W:
|
||||
return "Generic[22].W";
|
||||
case Attribute::Generic23X:
|
||||
return "Generic[23].X";
|
||||
case Attribute::Generic23Y:
|
||||
return "Generic[23].Y";
|
||||
case Attribute::Generic23Z:
|
||||
return "Generic[23].Z";
|
||||
case Attribute::Generic23W:
|
||||
return "Generic[23].W";
|
||||
case Attribute::Generic24X:
|
||||
return "Generic[24].X";
|
||||
case Attribute::Generic24Y:
|
||||
return "Generic[24].Y";
|
||||
case Attribute::Generic24Z:
|
||||
return "Generic[24].Z";
|
||||
case Attribute::Generic24W:
|
||||
return "Generic[24].W";
|
||||
case Attribute::Generic25X:
|
||||
return "Generic[25].X";
|
||||
case Attribute::Generic25Y:
|
||||
return "Generic[25].Y";
|
||||
case Attribute::Generic25Z:
|
||||
return "Generic[25].Z";
|
||||
case Attribute::Generic25W:
|
||||
return "Generic[25].W";
|
||||
case Attribute::Generic26X:
|
||||
return "Generic[26].X";
|
||||
case Attribute::Generic26Y:
|
||||
return "Generic[26].Y";
|
||||
case Attribute::Generic26Z:
|
||||
return "Generic[26].Z";
|
||||
case Attribute::Generic26W:
|
||||
return "Generic[26].W";
|
||||
case Attribute::Generic27X:
|
||||
return "Generic[27].X";
|
||||
case Attribute::Generic27Y:
|
||||
return "Generic[27].Y";
|
||||
case Attribute::Generic27Z:
|
||||
return "Generic[27].Z";
|
||||
case Attribute::Generic27W:
|
||||
return "Generic[27].W";
|
||||
case Attribute::Generic28X:
|
||||
return "Generic[28].X";
|
||||
case Attribute::Generic28Y:
|
||||
return "Generic[28].Y";
|
||||
case Attribute::Generic28Z:
|
||||
return "Generic[28].Z";
|
||||
case Attribute::Generic28W:
|
||||
return "Generic[28].W";
|
||||
case Attribute::Generic29X:
|
||||
return "Generic[29].X";
|
||||
case Attribute::Generic29Y:
|
||||
return "Generic[29].Y";
|
||||
case Attribute::Generic29Z:
|
||||
return "Generic[29].Z";
|
||||
case Attribute::Generic29W:
|
||||
return "Generic[29].W";
|
||||
case Attribute::Generic30X:
|
||||
return "Generic[30].X";
|
||||
case Attribute::Generic30Y:
|
||||
return "Generic[30].Y";
|
||||
case Attribute::Generic30Z:
|
||||
return "Generic[30].Z";
|
||||
case Attribute::Generic30W:
|
||||
return "Generic[30].W";
|
||||
case Attribute::Generic31X:
|
||||
return "Generic[31].X";
|
||||
case Attribute::Generic31Y:
|
||||
return "Generic[31].Y";
|
||||
case Attribute::Generic31Z:
|
||||
return "Generic[31].Z";
|
||||
case Attribute::Generic31W:
|
||||
return "Generic[31].W";
|
||||
case Attribute::ColorFrontDiffuseR:
|
||||
return "ColorFrontDiffuse.R";
|
||||
case Attribute::ColorFrontDiffuseG:
|
||||
return "ColorFrontDiffuse.G";
|
||||
case Attribute::ColorFrontDiffuseB:
|
||||
return "ColorFrontDiffuse.B";
|
||||
case Attribute::ColorFrontDiffuseA:
|
||||
return "ColorFrontDiffuse.A";
|
||||
case Attribute::ColorFrontSpecularR:
|
||||
return "ColorFrontSpecular.R";
|
||||
case Attribute::ColorFrontSpecularG:
|
||||
return "ColorFrontSpecular.G";
|
||||
case Attribute::ColorFrontSpecularB:
|
||||
return "ColorFrontSpecular.B";
|
||||
case Attribute::ColorFrontSpecularA:
|
||||
return "ColorFrontSpecular.A";
|
||||
case Attribute::ColorBackDiffuseR:
|
||||
return "ColorBackDiffuse.R";
|
||||
case Attribute::ColorBackDiffuseG:
|
||||
return "ColorBackDiffuse.G";
|
||||
case Attribute::ColorBackDiffuseB:
|
||||
return "ColorBackDiffuse.B";
|
||||
case Attribute::ColorBackDiffuseA:
|
||||
return "ColorBackDiffuse.A";
|
||||
case Attribute::ColorBackSpecularR:
|
||||
return "ColorBackSpecular.R";
|
||||
case Attribute::ColorBackSpecularG:
|
||||
return "ColorBackSpecular.G";
|
||||
case Attribute::ColorBackSpecularB:
|
||||
return "ColorBackSpecular.B";
|
||||
case Attribute::ColorBackSpecularA:
|
||||
return "ColorBackSpecular.A";
|
||||
case Attribute::ClipDistance0:
|
||||
return "ClipDistance[0]";
|
||||
case Attribute::ClipDistance1:
|
||||
return "ClipDistance[1]";
|
||||
case Attribute::ClipDistance2:
|
||||
return "ClipDistance[2]";
|
||||
case Attribute::ClipDistance3:
|
||||
return "ClipDistance[3]";
|
||||
case Attribute::ClipDistance4:
|
||||
return "ClipDistance[4]";
|
||||
case Attribute::ClipDistance5:
|
||||
return "ClipDistance[5]";
|
||||
case Attribute::ClipDistance6:
|
||||
return "ClipDistance[6]";
|
||||
case Attribute::ClipDistance7:
|
||||
return "ClipDistance[7]";
|
||||
case Attribute::PointSpriteS:
|
||||
return "PointSprite.S";
|
||||
case Attribute::PointSpriteT:
|
||||
return "PointSprite.T";
|
||||
case Attribute::FogCoordinate:
|
||||
return "FogCoordinate";
|
||||
case Attribute::TessellationEvaluationPointU:
|
||||
return "TessellationEvaluationPoint.U";
|
||||
case Attribute::TessellationEvaluationPointV:
|
||||
return "TessellationEvaluationPoint.V";
|
||||
case Attribute::InstanceId:
|
||||
return "InstanceId";
|
||||
case Attribute::VertexId:
|
||||
return "VertexId";
|
||||
case Attribute::FixedFncTexture0S:
|
||||
return "FixedFncTexture[0].S";
|
||||
case Attribute::FixedFncTexture0T:
|
||||
return "FixedFncTexture[0].T";
|
||||
case Attribute::FixedFncTexture0R:
|
||||
return "FixedFncTexture[0].R";
|
||||
case Attribute::FixedFncTexture0Q:
|
||||
return "FixedFncTexture[0].Q";
|
||||
case Attribute::FixedFncTexture1S:
|
||||
return "FixedFncTexture[1].S";
|
||||
case Attribute::FixedFncTexture1T:
|
||||
return "FixedFncTexture[1].T";
|
||||
case Attribute::FixedFncTexture1R:
|
||||
return "FixedFncTexture[1].R";
|
||||
case Attribute::FixedFncTexture1Q:
|
||||
return "FixedFncTexture[1].Q";
|
||||
case Attribute::FixedFncTexture2S:
|
||||
return "FixedFncTexture[2].S";
|
||||
case Attribute::FixedFncTexture2T:
|
||||
return "FixedFncTexture[2].T";
|
||||
case Attribute::FixedFncTexture2R:
|
||||
return "FixedFncTexture[2].R";
|
||||
case Attribute::FixedFncTexture2Q:
|
||||
return "FixedFncTexture[2].Q";
|
||||
case Attribute::FixedFncTexture3S:
|
||||
return "FixedFncTexture[3].S";
|
||||
case Attribute::FixedFncTexture3T:
|
||||
return "FixedFncTexture[3].T";
|
||||
case Attribute::FixedFncTexture3R:
|
||||
return "FixedFncTexture[3].R";
|
||||
case Attribute::FixedFncTexture3Q:
|
||||
return "FixedFncTexture[3].Q";
|
||||
case Attribute::FixedFncTexture4S:
|
||||
return "FixedFncTexture[4].S";
|
||||
case Attribute::FixedFncTexture4T:
|
||||
return "FixedFncTexture[4].T";
|
||||
case Attribute::FixedFncTexture4R:
|
||||
return "FixedFncTexture[4].R";
|
||||
case Attribute::FixedFncTexture4Q:
|
||||
return "FixedFncTexture[4].Q";
|
||||
case Attribute::FixedFncTexture5S:
|
||||
return "FixedFncTexture[5].S";
|
||||
case Attribute::FixedFncTexture5T:
|
||||
return "FixedFncTexture[5].T";
|
||||
case Attribute::FixedFncTexture5R:
|
||||
return "FixedFncTexture[5].R";
|
||||
case Attribute::FixedFncTexture5Q:
|
||||
return "FixedFncTexture[5].Q";
|
||||
case Attribute::FixedFncTexture6S:
|
||||
return "FixedFncTexture[6].S";
|
||||
case Attribute::FixedFncTexture6T:
|
||||
return "FixedFncTexture[6].T";
|
||||
case Attribute::FixedFncTexture6R:
|
||||
return "FixedFncTexture[6].R";
|
||||
case Attribute::FixedFncTexture6Q:
|
||||
return "FixedFncTexture[6].Q";
|
||||
case Attribute::FixedFncTexture7S:
|
||||
return "FixedFncTexture[7].S";
|
||||
case Attribute::FixedFncTexture7T:
|
||||
return "FixedFncTexture[7].T";
|
||||
case Attribute::FixedFncTexture7R:
|
||||
return "FixedFncTexture[7].R";
|
||||
case Attribute::FixedFncTexture7Q:
|
||||
return "FixedFncTexture[7].Q";
|
||||
case Attribute::FixedFncTexture8S:
|
||||
return "FixedFncTexture[8].S";
|
||||
case Attribute::FixedFncTexture8T:
|
||||
return "FixedFncTexture[8].T";
|
||||
case Attribute::FixedFncTexture8R:
|
||||
return "FixedFncTexture[8].R";
|
||||
case Attribute::FixedFncTexture8Q:
|
||||
return "FixedFncTexture[8].Q";
|
||||
case Attribute::FixedFncTexture9S:
|
||||
return "FixedFncTexture[9].S";
|
||||
case Attribute::FixedFncTexture9T:
|
||||
return "FixedFncTexture[9].T";
|
||||
case Attribute::FixedFncTexture9R:
|
||||
return "FixedFncTexture[9].R";
|
||||
case Attribute::FixedFncTexture9Q:
|
||||
return "FixedFncTexture[9].Q";
|
||||
case Attribute::ViewportMask:
|
||||
return "ViewportMask";
|
||||
case Attribute::FrontFace:
|
||||
return "FrontFace";
|
||||
case Attribute::BaseInstance:
|
||||
return "BaseInstance";
|
||||
case Attribute::BaseVertex:
|
||||
return "BaseVertex";
|
||||
case Attribute::DrawID:
|
||||
return "DrawID";
|
||||
}
|
||||
return fmt::format("<reserved attribute {}>", static_cast<int>(attribute));
|
||||
}
|
||||
|
||||
} // namespace Shader::IR
|
||||
288
gpu/third_party/suyu/shader_recompiler/frontend/ir/attribute.h
vendored
Normal file
288
gpu/third_party/suyu/shader_recompiler/frontend/ir/attribute.h
vendored
Normal file
@@ -0,0 +1,288 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2026 suyu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <fmt/ranges.h>
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "shader_recompiler/exception.h"
|
||||
|
||||
namespace Shader::IR {
|
||||
|
||||
enum class Attribute : u64 {
|
||||
#define SRIR_ATTRIBUTE_LIST \
|
||||
SRIR_ATTRIBUTE_ELEM(PrimitiveId, 24) \
|
||||
SRIR_ATTRIBUTE_ELEM(Layer, 25) \
|
||||
SRIR_ATTRIBUTE_ELEM(ViewportIndex, 26) \
|
||||
SRIR_ATTRIBUTE_ELEM(PointSize, 27) \
|
||||
SRIR_ATTRIBUTE_ELEM(PositionX, 28) \
|
||||
SRIR_ATTRIBUTE_ELEM(PositionY, 29) \
|
||||
SRIR_ATTRIBUTE_ELEM(PositionZ, 30) \
|
||||
SRIR_ATTRIBUTE_ELEM(PositionW, 31) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic0X, 32) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic0Y, 33) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic0Z, 34) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic0W, 35) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic1X, 36) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic1Y, 37) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic1Z, 38) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic1W, 39) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic2X, 40) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic2Y, 41) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic2Z, 42) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic2W, 43) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic3X, 44) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic3Y, 45) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic3Z, 46) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic3W, 47) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic4X, 48) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic4Y, 49) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic4Z, 50) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic4W, 51) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic5X, 52) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic5Y, 53) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic5Z, 54) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic5W, 55) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic6X, 56) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic6Y, 57) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic6Z, 58) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic6W, 59) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic7X, 60) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic7Y, 61) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic7Z, 62) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic7W, 63) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic8X, 64) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic8Y, 65) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic8Z, 66) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic8W, 67) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic9X, 68) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic9Y, 69) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic9Z, 70) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic9W, 71) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic10X, 72) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic10Y, 73) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic10Z, 74) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic10W, 75) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic11X, 76) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic11Y, 77) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic11Z, 78) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic11W, 79) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic12X, 80) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic12Y, 81) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic12Z, 82) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic12W, 83) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic13X, 84) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic13Y, 85) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic13Z, 86) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic13W, 87) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic14X, 88) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic14Y, 89) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic14Z, 90) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic14W, 91) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic15X, 92) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic15Y, 93) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic15Z, 94) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic15W, 95) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic16X, 96) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic16Y, 97) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic16Z, 98) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic16W, 99) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic17X, 100) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic17Y, 101) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic17Z, 102) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic17W, 103) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic18X, 104) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic18Y, 105) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic18Z, 106) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic18W, 107) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic19X, 108) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic19Y, 109) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic19Z, 110) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic19W, 111) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic20X, 112) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic20Y, 113) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic20Z, 114) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic20W, 115) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic21X, 116) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic21Y, 117) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic21Z, 118) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic21W, 119) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic22X, 120) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic22Y, 121) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic22Z, 122) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic22W, 123) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic23X, 124) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic23Y, 125) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic23Z, 126) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic23W, 127) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic24X, 128) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic24Y, 129) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic24Z, 130) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic24W, 131) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic25X, 132) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic25Y, 133) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic25Z, 134) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic25W, 135) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic26X, 136) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic26Y, 137) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic26Z, 138) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic26W, 139) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic27X, 140) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic27Y, 141) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic27Z, 142) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic27W, 143) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic28X, 144) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic28Y, 145) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic28Z, 146) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic28W, 147) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic29X, 148) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic29Y, 149) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic29Z, 150) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic29W, 151) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic30X, 152) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic30Y, 153) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic30Z, 154) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic30W, 155) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic31X, 156) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic31Y, 157) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic31Z, 158) \
|
||||
SRIR_ATTRIBUTE_ELEM(Generic31W, 159) \
|
||||
SRIR_ATTRIBUTE_ELEM(ColorFrontDiffuseR, 160) \
|
||||
SRIR_ATTRIBUTE_ELEM(ColorFrontDiffuseG, 161) \
|
||||
SRIR_ATTRIBUTE_ELEM(ColorFrontDiffuseB, 162) \
|
||||
SRIR_ATTRIBUTE_ELEM(ColorFrontDiffuseA, 163) \
|
||||
SRIR_ATTRIBUTE_ELEM(ColorFrontSpecularR, 164) \
|
||||
SRIR_ATTRIBUTE_ELEM(ColorFrontSpecularG, 165) \
|
||||
SRIR_ATTRIBUTE_ELEM(ColorFrontSpecularB, 166) \
|
||||
SRIR_ATTRIBUTE_ELEM(ColorFrontSpecularA, 167) \
|
||||
SRIR_ATTRIBUTE_ELEM(ColorBackDiffuseR, 168) \
|
||||
SRIR_ATTRIBUTE_ELEM(ColorBackDiffuseG, 169) \
|
||||
SRIR_ATTRIBUTE_ELEM(ColorBackDiffuseB, 170) \
|
||||
SRIR_ATTRIBUTE_ELEM(ColorBackDiffuseA, 171) \
|
||||
SRIR_ATTRIBUTE_ELEM(ColorBackSpecularR, 172) \
|
||||
SRIR_ATTRIBUTE_ELEM(ColorBackSpecularG, 173) \
|
||||
SRIR_ATTRIBUTE_ELEM(ColorBackSpecularB, 174) \
|
||||
SRIR_ATTRIBUTE_ELEM(ColorBackSpecularA, 175) \
|
||||
SRIR_ATTRIBUTE_ELEM(ClipDistance0, 176) \
|
||||
SRIR_ATTRIBUTE_ELEM(ClipDistance1, 177) \
|
||||
SRIR_ATTRIBUTE_ELEM(ClipDistance2, 178) \
|
||||
SRIR_ATTRIBUTE_ELEM(ClipDistance3, 179) \
|
||||
SRIR_ATTRIBUTE_ELEM(ClipDistance4, 180) \
|
||||
SRIR_ATTRIBUTE_ELEM(ClipDistance5, 181) \
|
||||
SRIR_ATTRIBUTE_ELEM(ClipDistance6, 182) \
|
||||
SRIR_ATTRIBUTE_ELEM(ClipDistance7, 183) \
|
||||
SRIR_ATTRIBUTE_ELEM(PointSpriteS, 184) \
|
||||
SRIR_ATTRIBUTE_ELEM(PointSpriteT, 185) \
|
||||
SRIR_ATTRIBUTE_ELEM(FogCoordinate, 186) \
|
||||
SRIR_ATTRIBUTE_ELEM(TessellationEvaluationPointU, 188) \
|
||||
SRIR_ATTRIBUTE_ELEM(TessellationEvaluationPointV, 189) \
|
||||
SRIR_ATTRIBUTE_ELEM(InstanceId, 190) \
|
||||
SRIR_ATTRIBUTE_ELEM(VertexId, 191) \
|
||||
SRIR_ATTRIBUTE_ELEM(FixedFncTexture0S, 192) \
|
||||
SRIR_ATTRIBUTE_ELEM(FixedFncTexture0T, 193) \
|
||||
SRIR_ATTRIBUTE_ELEM(FixedFncTexture0R, 194) \
|
||||
SRIR_ATTRIBUTE_ELEM(FixedFncTexture0Q, 195) \
|
||||
SRIR_ATTRIBUTE_ELEM(FixedFncTexture1S, 196) \
|
||||
SRIR_ATTRIBUTE_ELEM(FixedFncTexture1T, 197) \
|
||||
SRIR_ATTRIBUTE_ELEM(FixedFncTexture1R, 198) \
|
||||
SRIR_ATTRIBUTE_ELEM(FixedFncTexture1Q, 199) \
|
||||
SRIR_ATTRIBUTE_ELEM(FixedFncTexture2S, 200) \
|
||||
SRIR_ATTRIBUTE_ELEM(FixedFncTexture2T, 201) \
|
||||
SRIR_ATTRIBUTE_ELEM(FixedFncTexture2R, 202) \
|
||||
SRIR_ATTRIBUTE_ELEM(FixedFncTexture2Q, 203) \
|
||||
SRIR_ATTRIBUTE_ELEM(FixedFncTexture3S, 204) \
|
||||
SRIR_ATTRIBUTE_ELEM(FixedFncTexture3T, 205) \
|
||||
SRIR_ATTRIBUTE_ELEM(FixedFncTexture3R, 206) \
|
||||
SRIR_ATTRIBUTE_ELEM(FixedFncTexture3Q, 207) \
|
||||
SRIR_ATTRIBUTE_ELEM(FixedFncTexture4S, 208) \
|
||||
SRIR_ATTRIBUTE_ELEM(FixedFncTexture4T, 209) \
|
||||
SRIR_ATTRIBUTE_ELEM(FixedFncTexture4R, 210) \
|
||||
SRIR_ATTRIBUTE_ELEM(FixedFncTexture4Q, 211) \
|
||||
SRIR_ATTRIBUTE_ELEM(FixedFncTexture5S, 212) \
|
||||
SRIR_ATTRIBUTE_ELEM(FixedFncTexture5T, 213) \
|
||||
SRIR_ATTRIBUTE_ELEM(FixedFncTexture5R, 214) \
|
||||
SRIR_ATTRIBUTE_ELEM(FixedFncTexture5Q, 215) \
|
||||
SRIR_ATTRIBUTE_ELEM(FixedFncTexture6S, 216) \
|
||||
SRIR_ATTRIBUTE_ELEM(FixedFncTexture6T, 217) \
|
||||
SRIR_ATTRIBUTE_ELEM(FixedFncTexture6R, 218) \
|
||||
SRIR_ATTRIBUTE_ELEM(FixedFncTexture6Q, 219) \
|
||||
SRIR_ATTRIBUTE_ELEM(FixedFncTexture7S, 220) \
|
||||
SRIR_ATTRIBUTE_ELEM(FixedFncTexture7T, 221) \
|
||||
SRIR_ATTRIBUTE_ELEM(FixedFncTexture7R, 222) \
|
||||
SRIR_ATTRIBUTE_ELEM(FixedFncTexture7Q, 223) \
|
||||
SRIR_ATTRIBUTE_ELEM(FixedFncTexture8S, 224) \
|
||||
SRIR_ATTRIBUTE_ELEM(FixedFncTexture8T, 225) \
|
||||
SRIR_ATTRIBUTE_ELEM(FixedFncTexture8R, 226) \
|
||||
SRIR_ATTRIBUTE_ELEM(FixedFncTexture8Q, 227) \
|
||||
SRIR_ATTRIBUTE_ELEM(FixedFncTexture9S, 228) \
|
||||
SRIR_ATTRIBUTE_ELEM(FixedFncTexture9T, 229) \
|
||||
SRIR_ATTRIBUTE_ELEM(FixedFncTexture9R, 230) \
|
||||
SRIR_ATTRIBUTE_ELEM(FixedFncTexture9Q, 231) \
|
||||
SRIR_ATTRIBUTE_ELEM(ViewportMask, 232) \
|
||||
SRIR_ATTRIBUTE_ELEM(FrontFace, 255) \
|
||||
/* Implementation attributes */ \
|
||||
SRIR_ATTRIBUTE_ELEM(BaseInstance, 256) \
|
||||
SRIR_ATTRIBUTE_ELEM(BaseVertex, 257) \
|
||||
SRIR_ATTRIBUTE_ELEM(DrawID, 258)
|
||||
#define SRIR_ATTRIBUTE_ELEM(n, v) n = v,
|
||||
SRIR_ATTRIBUTE_LIST
|
||||
#undef SRIR_ATTRIBUTE_ELEM
|
||||
};
|
||||
|
||||
constexpr size_t NUM_GENERICS = 32;
|
||||
constexpr size_t NUM_FIXEDFNCTEXTURE = 10;
|
||||
|
||||
[[nodiscard]] inline bool IsGeneric(Attribute attribute) noexcept {
|
||||
return attribute >= Attribute::Generic0X && attribute <= Attribute::Generic31X;
|
||||
}
|
||||
|
||||
[[nodiscard]] inline bool IsLegacyAttribute(Attribute attribute) noexcept {
|
||||
return (attribute >= Attribute::ColorFrontDiffuseR &&
|
||||
attribute <= Attribute::ColorBackSpecularA) ||
|
||||
attribute == Attribute::FogCoordinate ||
|
||||
(attribute >= Attribute::FixedFncTexture0S &&
|
||||
attribute <= Attribute::FixedFncTexture9Q);
|
||||
}
|
||||
|
||||
[[nodiscard]] inline u32 GenericAttributeIndex(Attribute attribute) {
|
||||
if (!IsGeneric(attribute))
|
||||
throw InvalidArgument("Attribute is not generic {}", attribute);
|
||||
return (u32(attribute) - u32(Attribute::Generic0X)) / 4u;
|
||||
}
|
||||
|
||||
[[nodiscard]] inline u32 GenericAttributeElement(Attribute attribute) {
|
||||
if (!IsGeneric(attribute))
|
||||
throw InvalidArgument("Attribute is not generic {}", attribute);
|
||||
return u32(attribute) % 4;
|
||||
}
|
||||
|
||||
[[nodiscard]] inline std::string NameOf(Attribute attribute) {
|
||||
switch (attribute) {
|
||||
#define SRIR_ATTRIBUTE_ELEM(n, v) case Attribute::n: return #n;
|
||||
SRIR_ATTRIBUTE_LIST
|
||||
#undef SRIR_ATTRIBUTE_ELEM
|
||||
default:
|
||||
return fmt::format("<reserved attribute {}>", int(attribute));
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr IR::Attribute operator+(IR::Attribute attribute, size_t value) noexcept {
|
||||
return IR::Attribute(size_t(attribute) + value);
|
||||
}
|
||||
|
||||
} // namespace Shader::IR
|
||||
|
||||
template <>
|
||||
struct fmt::formatter<Shader::IR::Attribute> {
|
||||
constexpr auto parse(format_parse_context& ctx) {
|
||||
return ctx.begin();
|
||||
}
|
||||
template <typename FormatContext>
|
||||
auto format(const Shader::IR::Attribute& attribute, FormatContext& ctx) const {
|
||||
return fmt::format_to(ctx.out(), "{}", Shader::IR::NameOf(attribute));
|
||||
}
|
||||
};
|
||||
154
gpu/third_party/suyu/shader_recompiler/frontend/ir/basic_block.cpp
vendored
Normal file
154
gpu/third_party/suyu/shader_recompiler/frontend/ir/basic_block.cpp
vendored
Normal file
@@ -0,0 +1,154 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2026 suyu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <algorithm>
|
||||
#include <initializer_list>
|
||||
#include <map>
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "shader_recompiler/frontend/ir/basic_block.h"
|
||||
#include "shader_recompiler/frontend/ir/value.h"
|
||||
|
||||
namespace Shader::IR {
|
||||
|
||||
Block::Block(ObjectPool<Inst>& inst_pool_) : inst_pool{&inst_pool_} {}
|
||||
|
||||
Block::~Block() = default;
|
||||
|
||||
void Block::AppendNewInst(Opcode op, std::initializer_list<Value> args) {
|
||||
PrependNewInst(instructions.end(), op, args);
|
||||
}
|
||||
|
||||
Block::iterator Block::PrependNewInst(iterator insertion_point, const Inst& base_inst) {
|
||||
Inst* const inst{inst_pool->Create(base_inst)};
|
||||
return instructions.insert(insertion_point, *inst);
|
||||
}
|
||||
|
||||
Block::iterator Block::PrependNewInst(iterator insertion_point, Opcode op,
|
||||
std::initializer_list<Value> args, u32 flags) {
|
||||
Inst* const inst{inst_pool->Create(op, flags)};
|
||||
const auto result_it{instructions.insert(insertion_point, *inst)};
|
||||
|
||||
if (inst->NumArgs() != args.size()) {
|
||||
throw InvalidArgument("Invalid number of arguments {} in {}", args.size(), op);
|
||||
}
|
||||
std::ranges::for_each(args, [inst, index = size_t{0}](const Value& arg) mutable {
|
||||
inst->SetArg(index, arg);
|
||||
++index;
|
||||
});
|
||||
return result_it;
|
||||
}
|
||||
|
||||
void Block::AddBranch(Block* block) {
|
||||
if (std::ranges::find(imm_successors, block) != imm_successors.end()) {
|
||||
throw LogicError("Successor already inserted");
|
||||
}
|
||||
if (std::ranges::find(block->imm_predecessors, this) != block->imm_predecessors.end()) {
|
||||
throw LogicError("Predecessor already inserted");
|
||||
}
|
||||
imm_successors.push_back(block);
|
||||
block->imm_predecessors.push_back(this);
|
||||
}
|
||||
|
||||
static std::string BlockToIndex(const std::map<const Block*, size_t>& block_to_index,
|
||||
Block* block) {
|
||||
if (const auto it{block_to_index.find(block)}; it != block_to_index.end()) {
|
||||
return fmt::format("{{Block ${}}}", it->second);
|
||||
}
|
||||
return fmt::format("$<unknown block {:016x}>", reinterpret_cast<u64>(block));
|
||||
}
|
||||
|
||||
static size_t InstIndex(std::map<const Inst*, size_t>& inst_to_index, size_t& inst_index,
|
||||
const Inst* inst) {
|
||||
const auto [it, is_inserted]{inst_to_index.emplace(inst, inst_index + 1)};
|
||||
if (is_inserted) {
|
||||
++inst_index;
|
||||
}
|
||||
return it->second;
|
||||
}
|
||||
|
||||
static std::string ArgToIndex(std::map<const Inst*, size_t>& inst_to_index, size_t& inst_index,
|
||||
const Value& arg) {
|
||||
if (arg.IsEmpty()) {
|
||||
return "<null>";
|
||||
}
|
||||
if (!arg.IsImmediate() || arg.IsIdentity()) {
|
||||
return fmt::format("%{}", InstIndex(inst_to_index, inst_index, arg.Inst()));
|
||||
}
|
||||
switch (arg.Type()) {
|
||||
case Type::U1:
|
||||
return fmt::format("#{}", arg.U1() ? "true" : "false");
|
||||
case Type::U8:
|
||||
return fmt::format("#{}", arg.U8());
|
||||
case Type::U16:
|
||||
return fmt::format("#{}", arg.U16());
|
||||
case Type::U32:
|
||||
return fmt::format("#{}", arg.U32());
|
||||
case Type::U64:
|
||||
return fmt::format("#{}", arg.U64());
|
||||
case Type::F32:
|
||||
return fmt::format("#{}", arg.F32());
|
||||
case Type::Reg:
|
||||
return fmt::format("{}", arg.Reg());
|
||||
case Type::Pred:
|
||||
return fmt::format("{}", arg.Pred());
|
||||
case Type::Attribute:
|
||||
return fmt::format("{}", arg.Attribute());
|
||||
default:
|
||||
return "<unknown immediate type>";
|
||||
}
|
||||
}
|
||||
|
||||
std::string DumpBlock(const Block& block) {
|
||||
size_t inst_index{0};
|
||||
std::map<const Inst*, size_t> inst_to_index;
|
||||
return DumpBlock(block, {}, inst_to_index, inst_index);
|
||||
}
|
||||
|
||||
std::string DumpBlock(const Block& block, const std::map<const Block*, size_t>& block_to_index,
|
||||
std::map<const Inst*, size_t>& inst_to_index, size_t& inst_index) {
|
||||
std::string ret{"Block"};
|
||||
if (const auto it{block_to_index.find(&block)}; it != block_to_index.end()) {
|
||||
ret += fmt::format(" ${}", it->second);
|
||||
}
|
||||
ret += '\n';
|
||||
for (const Inst& inst : block) {
|
||||
const Opcode op{inst.GetOpcode()};
|
||||
ret += fmt::format("[{:016x}] ", reinterpret_cast<u64>(&inst));
|
||||
if (TypeOf(op) != Type::Void) {
|
||||
ret += fmt::format("%{:<5} = {}", InstIndex(inst_to_index, inst_index, &inst), op);
|
||||
} else {
|
||||
ret += fmt::format(" {}", op); // '%00000 = ' -> 1 + 5 + 3 = 9 spaces
|
||||
}
|
||||
const size_t arg_count{inst.NumArgs()};
|
||||
for (size_t arg_index = 0; arg_index < arg_count; ++arg_index) {
|
||||
const Value arg{inst.Arg(arg_index)};
|
||||
const std::string arg_str{ArgToIndex(inst_to_index, inst_index, arg)};
|
||||
ret += arg_index != 0 ? ", " : " ";
|
||||
if (op == Opcode::Phi) {
|
||||
ret += fmt::format("[ {}, {} ]", arg_str,
|
||||
BlockToIndex(block_to_index, inst.PhiBlock(arg_index)));
|
||||
} else {
|
||||
ret += arg_str;
|
||||
}
|
||||
if (op != Opcode::Phi) {
|
||||
const Type actual_type{arg.Type()};
|
||||
const Type expected_type{ArgTypeOf(op, arg_index)};
|
||||
if (!AreTypesCompatible(actual_type, expected_type)) {
|
||||
ret += fmt::format("<type error: {} != {}>", actual_type, expected_type);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (TypeOf(op) != Type::Void) {
|
||||
ret += fmt::format(" (uses: {})\n", inst.UseCount());
|
||||
} else {
|
||||
ret += '\n';
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
} // namespace Shader::IR
|
||||
204
gpu/third_party/suyu/shader_recompiler/frontend/ir/basic_block.h
vendored
Normal file
204
gpu/third_party/suyu/shader_recompiler/frontend/ir/basic_block.h
vendored
Normal file
@@ -0,0 +1,204 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2025 suyu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <initializer_list>
|
||||
#include <map>
|
||||
#include <span>
|
||||
#include <vector>
|
||||
#include <bit>
|
||||
#include <numeric>
|
||||
#include <boost/intrusive/list.hpp>
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "shader_recompiler/frontend/ir/condition.h"
|
||||
#include "shader_recompiler/frontend/ir/value.h"
|
||||
#include "shader_recompiler/object_pool.h"
|
||||
|
||||
namespace Shader::IR {
|
||||
|
||||
class Block {
|
||||
public:
|
||||
using InstructionList = boost::intrusive::list<Inst>;
|
||||
using size_type = InstructionList::size_type;
|
||||
using iterator = InstructionList::iterator;
|
||||
using const_iterator = InstructionList::const_iterator;
|
||||
using reverse_iterator = InstructionList::reverse_iterator;
|
||||
using const_reverse_iterator = InstructionList::const_reverse_iterator;
|
||||
|
||||
explicit Block(ObjectPool<Inst>& inst_pool_);
|
||||
~Block();
|
||||
|
||||
Block(const Block&) = delete;
|
||||
Block& operator=(const Block&) = delete;
|
||||
|
||||
Block(Block&&) = default;
|
||||
Block& operator=(Block&&) = default;
|
||||
|
||||
/// Appends a new instruction to the end of this basic block.
|
||||
void AppendNewInst(Opcode op, std::initializer_list<Value> args);
|
||||
|
||||
/// Prepends a copy of an instruction to this basic block before the insertion point.
|
||||
iterator PrependNewInst(iterator insertion_point, const Inst& base_inst);
|
||||
|
||||
/// Prepends a new instruction to this basic block before the insertion point.
|
||||
iterator PrependNewInst(iterator insertion_point, Opcode op,
|
||||
std::initializer_list<Value> args = {}, u32 flags = 0);
|
||||
|
||||
/// Adds a new branch to this basic block.
|
||||
void AddBranch(Block* block);
|
||||
|
||||
/// Gets a mutable reference to the instruction list for this basic block.
|
||||
[[nodiscard]] InstructionList& Instructions() noexcept {
|
||||
return instructions;
|
||||
}
|
||||
/// Gets an immutable reference to the instruction list for this basic block.
|
||||
[[nodiscard]] const InstructionList& Instructions() const noexcept {
|
||||
return instructions;
|
||||
}
|
||||
|
||||
/// Gets an immutable span to the immediate predecessors.
|
||||
[[nodiscard]] std::span<Block* const> ImmPredecessors() const noexcept {
|
||||
return imm_predecessors;
|
||||
}
|
||||
/// Gets an immutable span to the immediate successors.
|
||||
[[nodiscard]] std::span<Block* const> ImmSuccessors() const noexcept {
|
||||
return imm_successors;
|
||||
}
|
||||
|
||||
/// Intrusively store the host definition of this instruction.
|
||||
template <typename DefinitionType>
|
||||
void SetDefinition(DefinitionType def) {
|
||||
definition = std::bit_cast<u32>(def);
|
||||
}
|
||||
|
||||
/// Return the intrusively stored host definition of this instruction.
|
||||
template <typename DefinitionType>
|
||||
[[nodiscard]] DefinitionType Definition() const noexcept {
|
||||
return std::bit_cast<DefinitionType>(definition);
|
||||
}
|
||||
|
||||
void SetSsaRegValue(IR::Reg reg, const Value& value) noexcept {
|
||||
ssa_reg_values[RegIndex(reg)] = value;
|
||||
}
|
||||
const Value& SsaRegValue(IR::Reg reg) const noexcept {
|
||||
return ssa_reg_values[RegIndex(reg)];
|
||||
}
|
||||
|
||||
void SsaSeal() noexcept {
|
||||
is_ssa_sealed = true;
|
||||
}
|
||||
[[nodiscard]] bool IsSsaSealed() const noexcept {
|
||||
return is_ssa_sealed;
|
||||
}
|
||||
|
||||
[[nodiscard]] bool empty() const {
|
||||
return instructions.empty();
|
||||
}
|
||||
[[nodiscard]] size_type size() const {
|
||||
return instructions.size();
|
||||
}
|
||||
|
||||
[[nodiscard]] Inst& front() {
|
||||
return instructions.front();
|
||||
}
|
||||
[[nodiscard]] const Inst& front() const {
|
||||
return instructions.front();
|
||||
}
|
||||
|
||||
[[nodiscard]] Inst& back() {
|
||||
return instructions.back();
|
||||
}
|
||||
[[nodiscard]] const Inst& back() const {
|
||||
return instructions.back();
|
||||
}
|
||||
|
||||
[[nodiscard]] iterator begin() {
|
||||
return instructions.begin();
|
||||
}
|
||||
[[nodiscard]] const_iterator begin() const {
|
||||
return instructions.begin();
|
||||
}
|
||||
[[nodiscard]] iterator end() {
|
||||
return instructions.end();
|
||||
}
|
||||
[[nodiscard]] const_iterator end() const {
|
||||
return instructions.end();
|
||||
}
|
||||
|
||||
[[nodiscard]] reverse_iterator rbegin() {
|
||||
return instructions.rbegin();
|
||||
}
|
||||
[[nodiscard]] const_reverse_iterator rbegin() const {
|
||||
return instructions.rbegin();
|
||||
}
|
||||
[[nodiscard]] reverse_iterator rend() {
|
||||
return instructions.rend();
|
||||
}
|
||||
[[nodiscard]] const_reverse_iterator rend() const {
|
||||
return instructions.rend();
|
||||
}
|
||||
|
||||
[[nodiscard]] const_iterator cbegin() const {
|
||||
return instructions.cbegin();
|
||||
}
|
||||
[[nodiscard]] const_iterator cend() const {
|
||||
return instructions.cend();
|
||||
}
|
||||
|
||||
[[nodiscard]] const_reverse_iterator crbegin() const {
|
||||
return instructions.crbegin();
|
||||
}
|
||||
[[nodiscard]] const_reverse_iterator crend() const {
|
||||
return instructions.crend();
|
||||
}
|
||||
|
||||
// Set the order of the block, it can be set pre order, the user decides
|
||||
void SetOrder(u32 new_order) {
|
||||
order = new_order;
|
||||
}
|
||||
|
||||
// Get the order of the block.
|
||||
// The higher, the closer is the block to the end.
|
||||
[[nodiscard]] u32 GetOrder() const {
|
||||
return order;
|
||||
}
|
||||
|
||||
private:
|
||||
/// Memory pool for instruction list
|
||||
ObjectPool<Inst>* inst_pool;
|
||||
|
||||
/// List of instructions in this block
|
||||
InstructionList instructions;
|
||||
|
||||
/// Block immediate predecessors
|
||||
std::vector<Block*> imm_predecessors;
|
||||
/// Block immediate successors
|
||||
std::vector<Block*> imm_successors;
|
||||
|
||||
/// Intrusively store the value of a register in the block.
|
||||
std::array<Value, NUM_REGS> ssa_reg_values;
|
||||
/// Intrusively store if the block is sealed in the SSA pass.
|
||||
bool is_ssa_sealed{false};
|
||||
|
||||
/// Intrusively stored host definition of this block.
|
||||
u32 definition{};
|
||||
|
||||
/// Order of the block.
|
||||
u32 order{};
|
||||
};
|
||||
|
||||
using BlockList = std::vector<Block*>;
|
||||
|
||||
[[nodiscard]] std::string DumpBlock(const Block& block);
|
||||
|
||||
[[nodiscard]] std::string DumpBlock(const Block& block,
|
||||
const std::map<const Block*, size_t>& block_to_index,
|
||||
std::map<const Inst*, size_t>& inst_to_index,
|
||||
size_t& inst_index);
|
||||
|
||||
} // namespace Shader::IR
|
||||
55
gpu/third_party/suyu/shader_recompiler/frontend/ir/breadth_first_search.h
vendored
Normal file
55
gpu/third_party/suyu/shader_recompiler/frontend/ir/breadth_first_search.h
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <optional>
|
||||
#include <type_traits>
|
||||
#include <queue>
|
||||
|
||||
#include <boost/container/small_vector.hpp>
|
||||
|
||||
#include "shader_recompiler/frontend/ir/value.h"
|
||||
|
||||
namespace Shader::IR {
|
||||
|
||||
template <typename Pred>
|
||||
auto BreadthFirstSearch(const Value& value, Pred&& pred)
|
||||
-> std::invoke_result_t<Pred, const Inst*> {
|
||||
if (value.IsImmediate()) {
|
||||
// Nothing to do with immediates
|
||||
return std::nullopt;
|
||||
}
|
||||
// Breadth-first search visiting the right most arguments first
|
||||
// Small vector has been determined from shaders in Super Smash Bros. Ultimate
|
||||
boost::container::small_vector<const Inst*, 2> visited;
|
||||
std::queue<const Inst*> queue;
|
||||
queue.push(value.InstRecursive());
|
||||
|
||||
while (!queue.empty()) {
|
||||
// Pop one instruction from the queue
|
||||
const Inst* const inst{queue.front()};
|
||||
queue.pop();
|
||||
if (const std::optional result = pred(inst)) {
|
||||
// This is the instruction we were looking for
|
||||
return result;
|
||||
}
|
||||
// Visit the right most arguments first
|
||||
for (size_t arg = inst->NumArgs(); arg--;) {
|
||||
const Value arg_value{inst->Arg(arg)};
|
||||
if (arg_value.IsImmediate()) {
|
||||
continue;
|
||||
}
|
||||
// Queue instruction if it hasn't been visited
|
||||
const Inst* const arg_inst{arg_value.InstRecursive()};
|
||||
if (std::ranges::find(visited, arg_inst) == visited.end()) {
|
||||
visited.push_back(arg_inst);
|
||||
queue.push(arg_inst);
|
||||
}
|
||||
}
|
||||
}
|
||||
// SSA tree has been traversed and the result hasn't been found
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
} // namespace Shader::IR
|
||||
28
gpu/third_party/suyu/shader_recompiler/frontend/ir/condition.cpp
vendored
Normal file
28
gpu/third_party/suyu/shader_recompiler/frontend/ir/condition.cpp
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <fmt/ranges.h>
|
||||
|
||||
#include "shader_recompiler/frontend/ir/condition.h"
|
||||
|
||||
namespace Shader::IR {
|
||||
|
||||
std::string NameOf(Condition condition) {
|
||||
std::string ret;
|
||||
if (condition.GetFlowTest() != FlowTest::T) {
|
||||
ret = fmt::to_string(condition.GetFlowTest());
|
||||
}
|
||||
const auto [pred, negated]{condition.GetPred()};
|
||||
if (!ret.empty()) {
|
||||
ret += '&';
|
||||
}
|
||||
if (negated) {
|
||||
ret += '!';
|
||||
}
|
||||
ret += fmt::to_string(pred);
|
||||
return ret;
|
||||
}
|
||||
|
||||
} // namespace Shader::IR
|
||||
58
gpu/third_party/suyu/shader_recompiler/frontend/ir/condition.h
vendored
Normal file
58
gpu/third_party/suyu/shader_recompiler/frontend/ir/condition.h
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <fmt/ranges.h>
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "shader_recompiler/frontend/ir/flow_test.h"
|
||||
#include "shader_recompiler/frontend/ir/pred.h"
|
||||
|
||||
namespace Shader::IR {
|
||||
|
||||
class Condition {
|
||||
public:
|
||||
Condition() noexcept = default;
|
||||
|
||||
explicit Condition(FlowTest flow_test_, Pred pred_, bool pred_negated_ = false) noexcept
|
||||
: flow_test{static_cast<u16>(flow_test_)}, pred{static_cast<u8>(pred_)},
|
||||
pred_negated{pred_negated_ ? u8{1} : u8{0}} {}
|
||||
|
||||
explicit Condition(Pred pred_, bool pred_negated_ = false) noexcept
|
||||
: Condition(FlowTest::T, pred_, pred_negated_) {}
|
||||
|
||||
explicit Condition(bool value) : Condition(Pred::PT, !value) {}
|
||||
|
||||
auto operator<=>(const Condition&) const noexcept = default;
|
||||
|
||||
[[nodiscard]] IR::FlowTest GetFlowTest() const noexcept {
|
||||
return static_cast<IR::FlowTest>(flow_test);
|
||||
}
|
||||
|
||||
[[nodiscard]] std::pair<IR::Pred, bool> GetPred() const noexcept {
|
||||
return {static_cast<IR::Pred>(pred), pred_negated != 0};
|
||||
}
|
||||
|
||||
private:
|
||||
u16 flow_test;
|
||||
u8 pred;
|
||||
u8 pred_negated;
|
||||
};
|
||||
|
||||
std::string NameOf(Condition condition);
|
||||
|
||||
} // namespace Shader::IR
|
||||
|
||||
template <>
|
||||
struct fmt::formatter<Shader::IR::Condition> {
|
||||
constexpr auto parse(format_parse_context& ctx) {
|
||||
return ctx.begin();
|
||||
}
|
||||
template <typename FormatContext>
|
||||
auto format(const Shader::IR::Condition& cond, FormatContext& ctx) const {
|
||||
return fmt::format_to(ctx.out(), "{}", Shader::IR::NameOf(cond));
|
||||
}
|
||||
};
|
||||
82
gpu/third_party/suyu/shader_recompiler/frontend/ir/flow_test.cpp
vendored
Normal file
82
gpu/third_party/suyu/shader_recompiler/frontend/ir/flow_test.cpp
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <fmt/format.h>
|
||||
|
||||
#include "shader_recompiler/frontend/ir/flow_test.h"
|
||||
|
||||
namespace Shader::IR {
|
||||
|
||||
std::string NameOf(FlowTest flow_test) {
|
||||
switch (flow_test) {
|
||||
case FlowTest::F:
|
||||
return "F";
|
||||
case FlowTest::LT:
|
||||
return "LT";
|
||||
case FlowTest::EQ:
|
||||
return "EQ";
|
||||
case FlowTest::LE:
|
||||
return "LE";
|
||||
case FlowTest::GT:
|
||||
return "GT";
|
||||
case FlowTest::NE:
|
||||
return "NE";
|
||||
case FlowTest::GE:
|
||||
return "GE";
|
||||
case FlowTest::NUM:
|
||||
return "NUM";
|
||||
case FlowTest::NaN:
|
||||
return "NAN";
|
||||
case FlowTest::LTU:
|
||||
return "LTU";
|
||||
case FlowTest::EQU:
|
||||
return "EQU";
|
||||
case FlowTest::LEU:
|
||||
return "LEU";
|
||||
case FlowTest::GTU:
|
||||
return "GTU";
|
||||
case FlowTest::NEU:
|
||||
return "NEU";
|
||||
case FlowTest::GEU:
|
||||
return "GEU";
|
||||
case FlowTest::T:
|
||||
return "T";
|
||||
case FlowTest::OFF:
|
||||
return "OFF";
|
||||
case FlowTest::LO:
|
||||
return "LO";
|
||||
case FlowTest::SFF:
|
||||
return "SFF";
|
||||
case FlowTest::LS:
|
||||
return "LS";
|
||||
case FlowTest::HI:
|
||||
return "HI";
|
||||
case FlowTest::SFT:
|
||||
return "SFT";
|
||||
case FlowTest::HS:
|
||||
return "HS";
|
||||
case FlowTest::OFT:
|
||||
return "OFT";
|
||||
case FlowTest::CSM_TA:
|
||||
return "CSM_TA";
|
||||
case FlowTest::CSM_TR:
|
||||
return "CSM_TR";
|
||||
case FlowTest::CSM_MX:
|
||||
return "CSM_MX";
|
||||
case FlowTest::FCSM_TA:
|
||||
return "FCSM_TA";
|
||||
case FlowTest::FCSM_TR:
|
||||
return "FCSM_TR";
|
||||
case FlowTest::FCSM_MX:
|
||||
return "FCSM_MX";
|
||||
case FlowTest::RLE:
|
||||
return "RLE";
|
||||
case FlowTest::RGT:
|
||||
return "RGT";
|
||||
}
|
||||
return fmt::format("<invalid flow test {}>", static_cast<int>(flow_test));
|
||||
}
|
||||
|
||||
} // namespace Shader::IR
|
||||
77
gpu/third_party/suyu/shader_recompiler/frontend/ir/flow_test.h
vendored
Normal file
77
gpu/third_party/suyu/shader_recompiler/frontend/ir/flow_test.h
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2025 suyu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <fmt/ranges.h>
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "shader_recompiler/exception.h"
|
||||
|
||||
namespace Shader::IR {
|
||||
|
||||
enum class FlowTest : u64 {
|
||||
#define SRIR_FLOW_TEST_LIST \
|
||||
SRIR_FLOW_TEST_ELEM(F) \
|
||||
SRIR_FLOW_TEST_ELEM(LT) \
|
||||
SRIR_FLOW_TEST_ELEM(EQ) \
|
||||
SRIR_FLOW_TEST_ELEM(LE) \
|
||||
SRIR_FLOW_TEST_ELEM(GT) \
|
||||
SRIR_FLOW_TEST_ELEM(NE) \
|
||||
SRIR_FLOW_TEST_ELEM(GE) \
|
||||
SRIR_FLOW_TEST_ELEM(NUM) \
|
||||
SRIR_FLOW_TEST_ELEM(NaN) \
|
||||
SRIR_FLOW_TEST_ELEM(LTU) \
|
||||
SRIR_FLOW_TEST_ELEM(EQU) \
|
||||
SRIR_FLOW_TEST_ELEM(LEU) \
|
||||
SRIR_FLOW_TEST_ELEM(GTU) \
|
||||
SRIR_FLOW_TEST_ELEM(NEU) \
|
||||
SRIR_FLOW_TEST_ELEM(GEU) \
|
||||
SRIR_FLOW_TEST_ELEM(T) \
|
||||
SRIR_FLOW_TEST_ELEM(OFF) \
|
||||
SRIR_FLOW_TEST_ELEM(LO) \
|
||||
SRIR_FLOW_TEST_ELEM(SFF) \
|
||||
SRIR_FLOW_TEST_ELEM(LS) \
|
||||
SRIR_FLOW_TEST_ELEM(HI) \
|
||||
SRIR_FLOW_TEST_ELEM(SFT) \
|
||||
SRIR_FLOW_TEST_ELEM(HS) \
|
||||
SRIR_FLOW_TEST_ELEM(OFT) \
|
||||
SRIR_FLOW_TEST_ELEM(CSM_TA) \
|
||||
SRIR_FLOW_TEST_ELEM(CSM_TR) \
|
||||
SRIR_FLOW_TEST_ELEM(CSM_MX) \
|
||||
SRIR_FLOW_TEST_ELEM(FCSM_TA) \
|
||||
SRIR_FLOW_TEST_ELEM(FCSM_TR) \
|
||||
SRIR_FLOW_TEST_ELEM(FCSM_MX) \
|
||||
SRIR_FLOW_TEST_ELEM(RLE) \
|
||||
SRIR_FLOW_TEST_ELEM(RGT)
|
||||
#define SRIR_FLOW_TEST_ELEM(n) n,
|
||||
SRIR_FLOW_TEST_LIST
|
||||
#undef SRIR_FLOW_TEST_ELEM
|
||||
};
|
||||
|
||||
[[nodiscard]] inline std::string NameOf(FlowTest flow_test) {
|
||||
switch (flow_test) {
|
||||
#define SRIR_FLOW_TEST_ELEM(n) case FlowTest::n: return #n;
|
||||
SRIR_FLOW_TEST_LIST
|
||||
#undef SRIR_FLOW_TEST_ELEM
|
||||
default:
|
||||
return fmt::format("<invalid flow test {}>", int(flow_test));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Shader::IR
|
||||
|
||||
template <>
|
||||
struct fmt::formatter<Shader::IR::FlowTest> {
|
||||
constexpr auto parse(format_parse_context& ctx) {
|
||||
return ctx.begin();
|
||||
}
|
||||
template <typename FormatContext>
|
||||
auto format(const Shader::IR::FlowTest& flow_test, FormatContext& ctx) const {
|
||||
return fmt::format_to(ctx.out(), "{}", Shader::IR::NameOf(flow_test));
|
||||
}
|
||||
};
|
||||
2123
gpu/third_party/suyu/shader_recompiler/frontend/ir/ir_emitter.cpp
vendored
Normal file
2123
gpu/third_party/suyu/shader_recompiler/frontend/ir/ir_emitter.cpp
vendored
Normal file
File diff suppressed because it is too large
Load Diff
435
gpu/third_party/suyu/shader_recompiler/frontend/ir/ir_emitter.h
vendored
Normal file
435
gpu/third_party/suyu/shader_recompiler/frontend/ir/ir_emitter.h
vendored
Normal file
@@ -0,0 +1,435 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2025 suyu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstring>
|
||||
#include <type_traits>
|
||||
|
||||
#include "shader_recompiler/frontend/ir/attribute.h"
|
||||
#include "shader_recompiler/frontend/ir/basic_block.h"
|
||||
#include "shader_recompiler/frontend/ir/modifiers.h"
|
||||
#include "shader_recompiler/frontend/ir/value.h"
|
||||
|
||||
namespace Shader::IR {
|
||||
|
||||
class IREmitter {
|
||||
public:
|
||||
explicit IREmitter(Block& block_) : block{&block_}, insertion_point{block->end()} {}
|
||||
explicit IREmitter(Block& block_, Block::iterator insertion_point_)
|
||||
: block{&block_}, insertion_point{insertion_point_} {}
|
||||
|
||||
Block* block;
|
||||
|
||||
[[nodiscard]] U1 Imm1(bool value) const;
|
||||
[[nodiscard]] U8 Imm8(u8 value) const;
|
||||
[[nodiscard]] U16 Imm16(u16 value) const;
|
||||
[[nodiscard]] U32 Imm32(u32 value) const;
|
||||
[[nodiscard]] U32 Imm32(s32 value) const;
|
||||
[[nodiscard]] F32 Imm32(f32 value) const;
|
||||
[[nodiscard]] U64 Imm64(u64 value) const;
|
||||
[[nodiscard]] U64 Imm64(s64 value) const;
|
||||
[[nodiscard]] F64 Imm64(f64 value) const;
|
||||
|
||||
U1 ConditionRef(const U1& value);
|
||||
void Reference(const Value& value);
|
||||
|
||||
void PhiMove(IR::Inst& phi, const Value& value);
|
||||
|
||||
void Prologue();
|
||||
void Epilogue();
|
||||
void DemoteToHelperInvocation();
|
||||
void EmitVertex(const U32& stream);
|
||||
void EndPrimitive(const U32& stream);
|
||||
|
||||
[[nodiscard]] U32 GetReg(IR::Reg reg);
|
||||
void SetReg(IR::Reg reg, const U32& value);
|
||||
|
||||
[[nodiscard]] U1 GetPred(IR::Pred pred, bool is_negated = false);
|
||||
void SetPred(IR::Pred pred, const U1& value);
|
||||
|
||||
[[nodiscard]] U1 GetGotoVariable(u32 id);
|
||||
void SetGotoVariable(u32 id, const U1& value);
|
||||
|
||||
[[nodiscard]] U32 GetIndirectBranchVariable();
|
||||
void SetIndirectBranchVariable(const U32& value);
|
||||
|
||||
[[nodiscard]] U32 GetCbuf(const U32& binding, const U32& byte_offset);
|
||||
[[nodiscard]] Value GetCbuf(const U32& binding, const U32& byte_offset, size_t bitsize,
|
||||
bool is_signed);
|
||||
[[nodiscard]] F32 GetFloatCbuf(const U32& binding, const U32& byte_offset);
|
||||
|
||||
[[nodiscard]] U1 GetZFlag();
|
||||
[[nodiscard]] U1 GetSFlag();
|
||||
[[nodiscard]] U1 GetCFlag();
|
||||
[[nodiscard]] U1 GetOFlag();
|
||||
|
||||
void SetZFlag(const U1& value);
|
||||
void SetSFlag(const U1& value);
|
||||
void SetCFlag(const U1& value);
|
||||
void SetOFlag(const U1& value);
|
||||
|
||||
[[nodiscard]] U1 Condition(IR::Condition cond);
|
||||
[[nodiscard]] U1 GetFlowTestResult(FlowTest test);
|
||||
|
||||
[[nodiscard]] F32 GetAttribute(IR::Attribute attribute);
|
||||
[[nodiscard]] F32 GetAttribute(IR::Attribute attribute, const U32& vertex);
|
||||
[[nodiscard]] U32 GetAttributeU32(IR::Attribute attribute);
|
||||
[[nodiscard]] U32 GetAttributeU32(IR::Attribute attribute, const U32& vertex);
|
||||
void SetAttribute(IR::Attribute attribute, const F32& value, const U32& vertex);
|
||||
|
||||
[[nodiscard]] F32 GetAttributeIndexed(const U32& phys_address);
|
||||
[[nodiscard]] F32 GetAttributeIndexed(const U32& phys_address, const U32& vertex);
|
||||
void SetAttributeIndexed(const U32& phys_address, const F32& value, const U32& vertex);
|
||||
|
||||
[[nodiscard]] F32 GetPatch(Patch patch);
|
||||
void SetPatch(Patch patch, const F32& value);
|
||||
|
||||
void SetFragColor(u32 index, u32 component, const F32& value);
|
||||
void SetSampleMask(const U32& value);
|
||||
void SetFragDepth(const F32& value);
|
||||
|
||||
[[nodiscard]] U32 WorkgroupIdX();
|
||||
[[nodiscard]] U32 WorkgroupIdY();
|
||||
[[nodiscard]] U32 WorkgroupIdZ();
|
||||
|
||||
[[nodiscard]] Value LocalInvocationId();
|
||||
[[nodiscard]] U32 LocalInvocationIdX();
|
||||
[[nodiscard]] U32 LocalInvocationIdY();
|
||||
[[nodiscard]] U32 LocalInvocationIdZ();
|
||||
|
||||
[[nodiscard]] U32 InvocationId();
|
||||
[[nodiscard]] U32 InvocationInfo();
|
||||
[[nodiscard]] U32 SampleId();
|
||||
[[nodiscard]] U1 IsHelperInvocation();
|
||||
[[nodiscard]] U32 SR_WScaleFactorXY();
|
||||
[[nodiscard]] U32 SR_WScaleFactorZ();
|
||||
[[nodiscard]] F32 YDirection();
|
||||
|
||||
[[nodiscard]] F32 ResolutionDownFactor();
|
||||
|
||||
[[nodiscard]] F32 RenderAreaWidth();
|
||||
[[nodiscard]] F32 RenderAreaHeight();
|
||||
|
||||
[[nodiscard]] U32 LaneId();
|
||||
|
||||
[[nodiscard]] U32 LoadGlobalU8(const U64& address);
|
||||
[[nodiscard]] U32 LoadGlobalS8(const U64& address);
|
||||
[[nodiscard]] U32 LoadGlobalU16(const U64& address);
|
||||
[[nodiscard]] U32 LoadGlobalS16(const U64& address);
|
||||
[[nodiscard]] U32 LoadGlobal32(const U64& address);
|
||||
[[nodiscard]] Value LoadGlobal64(const U64& address);
|
||||
[[nodiscard]] Value LoadGlobal128(const U64& address);
|
||||
|
||||
void WriteGlobalU8(const U64& address, const U32& value);
|
||||
void WriteGlobalS8(const U64& address, const U32& value);
|
||||
void WriteGlobalU16(const U64& address, const U32& value);
|
||||
void WriteGlobalS16(const U64& address, const U32& value);
|
||||
void WriteGlobal32(const U64& address, const U32& value);
|
||||
void WriteGlobal64(const U64& address, const IR::Value& vector);
|
||||
void WriteGlobal128(const U64& address, const IR::Value& vector);
|
||||
|
||||
[[nodiscard]] U32 LoadLocal(const U32& word_offset);
|
||||
void WriteLocal(const U32& word_offset, const U32& value);
|
||||
|
||||
[[nodiscard]] Value LoadShared(int bit_size, bool is_signed, const U32& offset);
|
||||
void WriteShared(int bit_size, const U32& offset, const Value& value);
|
||||
|
||||
[[nodiscard]] U1 GetZeroFromOp(const Value& op);
|
||||
[[nodiscard]] U1 GetSignFromOp(const Value& op);
|
||||
[[nodiscard]] U1 GetCarryFromOp(const Value& op);
|
||||
[[nodiscard]] U1 GetOverflowFromOp(const Value& op);
|
||||
[[nodiscard]] U1 GetSparseFromOp(const Value& op);
|
||||
[[nodiscard]] U1 GetInBoundsFromOp(const Value& op);
|
||||
|
||||
[[nodiscard]] Value CompositeConstruct(const Value& e1, const Value& e2);
|
||||
[[nodiscard]] Value CompositeConstruct(const Value& e1, const Value& e2, const Value& e3);
|
||||
[[nodiscard]] Value CompositeConstruct(const Value& e1, const Value& e2, const Value& e3,
|
||||
const Value& e4);
|
||||
[[nodiscard]] Value CompositeExtract(const Value& vector, size_t element);
|
||||
[[nodiscard]] Value CompositeInsert(const Value& vector, const Value& object, size_t element);
|
||||
|
||||
[[nodiscard]] Value Select(const U1& condition, const Value& true_value,
|
||||
const Value& false_value);
|
||||
|
||||
void Barrier();
|
||||
void WorkgroupMemoryBarrier();
|
||||
void DeviceMemoryBarrier();
|
||||
|
||||
template <typename Dest, typename Source>
|
||||
[[nodiscard]] Dest BitCast(const Source& value);
|
||||
|
||||
[[nodiscard]] U64 PackUint2x32(const Value& vector);
|
||||
[[nodiscard]] Value UnpackUint2x32(const U64& value);
|
||||
|
||||
[[nodiscard]] U32 PackFloat2x16(const Value& vector);
|
||||
[[nodiscard]] Value UnpackFloat2x16(const U32& value);
|
||||
|
||||
[[nodiscard]] U32 PackHalf2x16(const Value& vector);
|
||||
[[nodiscard]] Value UnpackHalf2x16(const U32& value);
|
||||
|
||||
[[nodiscard]] F64 PackDouble2x32(const Value& vector);
|
||||
[[nodiscard]] Value UnpackDouble2x32(const F64& value);
|
||||
|
||||
[[nodiscard]] F16F32F64 FPAdd(const F16F32F64& a, const F16F32F64& b, FpControl control = {});
|
||||
[[nodiscard]] F16F32F64 FPMul(const F16F32F64& a, const F16F32F64& b, FpControl control = {});
|
||||
[[nodiscard]] F16F32F64 FPFma(const F16F32F64& a, const F16F32F64& b, const F16F32F64& c,
|
||||
FpControl control = {});
|
||||
|
||||
[[nodiscard]] F16F32F64 FPAbs(const F16F32F64& value);
|
||||
[[nodiscard]] F16F32F64 FPNeg(const F16F32F64& value);
|
||||
[[nodiscard]] F16F32F64 FPAbsNeg(const F16F32F64& value, bool abs, bool neg);
|
||||
|
||||
[[nodiscard]] F32 FPCos(const F32& value);
|
||||
[[nodiscard]] F32 FPSin(const F32& value);
|
||||
[[nodiscard]] F32 FPExp2(const F32& value);
|
||||
[[nodiscard]] F32 FPLog2(const F32& value);
|
||||
[[nodiscard]] F32F64 FPRecip(const F32F64& value);
|
||||
[[nodiscard]] F32F64 FPRecipSqrt(const F32F64& value);
|
||||
[[nodiscard]] F32 FPSqrt(const F32& value);
|
||||
[[nodiscard]] F16F32F64 FPSaturate(const F16F32F64& value);
|
||||
[[nodiscard]] F16F32F64 FPClamp(const F16F32F64& value, const F16F32F64& min_value,
|
||||
const F16F32F64& max_value);
|
||||
[[nodiscard]] F16F32F64 FPRoundEven(const F16F32F64& value, FpControl control = {});
|
||||
[[nodiscard]] F16F32F64 FPFloor(const F16F32F64& value, FpControl control = {});
|
||||
[[nodiscard]] F16F32F64 FPCeil(const F16F32F64& value, FpControl control = {});
|
||||
[[nodiscard]] F16F32F64 FPTrunc(const F16F32F64& value, FpControl control = {});
|
||||
|
||||
[[nodiscard]] U1 FPEqual(const F16F32F64& lhs, const F16F32F64& rhs, FpControl control = {},
|
||||
bool ordered = true);
|
||||
[[nodiscard]] U1 FPNotEqual(const F16F32F64& lhs, const F16F32F64& rhs, FpControl control = {},
|
||||
bool ordered = true);
|
||||
[[nodiscard]] U1 FPLessThan(const F16F32F64& lhs, const F16F32F64& rhs, FpControl control = {},
|
||||
bool ordered = true);
|
||||
[[nodiscard]] U1 FPGreaterThan(const F16F32F64& lhs, const F16F32F64& rhs,
|
||||
FpControl control = {}, bool ordered = true);
|
||||
[[nodiscard]] U1 FPLessThanEqual(const F16F32F64& lhs, const F16F32F64& rhs,
|
||||
FpControl control = {}, bool ordered = true);
|
||||
[[nodiscard]] U1 FPGreaterThanEqual(const F16F32F64& lhs, const F16F32F64& rhs,
|
||||
FpControl control = {}, bool ordered = true);
|
||||
[[nodiscard]] U1 FPIsNan(const F16F32F64& value);
|
||||
[[nodiscard]] U1 FPOrdered(const F16F32F64& lhs, const F16F32F64& rhs);
|
||||
[[nodiscard]] U1 FPUnordered(const F16F32F64& lhs, const F16F32F64& rhs);
|
||||
[[nodiscard]] F32F64 FPMax(const F32F64& lhs, const F32F64& rhs, FpControl control = {});
|
||||
[[nodiscard]] F32F64 FPMin(const F32F64& lhs, const F32F64& rhs, FpControl control = {});
|
||||
|
||||
[[nodiscard]] U32U64 IAdd(const U32U64& a, const U32U64& b);
|
||||
[[nodiscard]] U32U64 ISub(const U32U64& a, const U32U64& b);
|
||||
[[nodiscard]] U32 IMul(const U32& a, const U32& b);
|
||||
[[nodiscard]] U32 IDiv(const U32& a, const U32& b, bool is_signed = false);
|
||||
[[nodiscard]] U32U64 INeg(const U32U64& value);
|
||||
[[nodiscard]] U32U64 IAbs(const U32U64& value);
|
||||
[[nodiscard]] U32U64 ShiftLeftLogical(const U32U64& base, const U32& shift);
|
||||
[[nodiscard]] U32U64 ShiftRightLogical(const U32U64& base, const U32& shift);
|
||||
[[nodiscard]] U32U64 ShiftRightArithmetic(const U32U64& base, const U32& shift);
|
||||
[[nodiscard]] U32 BitwiseAnd(const U32& a, const U32& b);
|
||||
[[nodiscard]] U32 BitwiseOr(const U32& a, const U32& b);
|
||||
[[nodiscard]] U32 BitwiseXor(const U32& a, const U32& b);
|
||||
[[nodiscard]] U32 BitFieldInsert(const U32& base, const U32& insert, const U32& offset,
|
||||
const U32& count);
|
||||
[[nodiscard]] U32 BitFieldExtract(const U32& base, const U32& offset, const U32& count,
|
||||
bool is_signed = false);
|
||||
[[nodiscard]] U32 BitReverse(const U32& value);
|
||||
[[nodiscard]] U32 BitCount(const U32& value);
|
||||
[[nodiscard]] U32 BitwiseNot(const U32& value);
|
||||
|
||||
[[nodiscard]] U32 FindSMsb(const U32& value);
|
||||
[[nodiscard]] U32 FindUMsb(const U32& value);
|
||||
[[nodiscard]] U32 SMin(const U32& a, const U32& b);
|
||||
[[nodiscard]] U32 UMin(const U32& a, const U32& b);
|
||||
[[nodiscard]] U32 IMin(const U32& a, const U32& b, bool is_signed);
|
||||
[[nodiscard]] U32 SMax(const U32& a, const U32& b);
|
||||
[[nodiscard]] U32 UMax(const U32& a, const U32& b);
|
||||
[[nodiscard]] U32 IMax(const U32& a, const U32& b, bool is_signed);
|
||||
[[nodiscard]] U32 SClamp(const U32& value, const U32& min, const U32& max);
|
||||
[[nodiscard]] U32 UClamp(const U32& value, const U32& min, const U32& max);
|
||||
|
||||
[[nodiscard]] U1 ILessThan(const U32& lhs, const U32& rhs, bool is_signed);
|
||||
[[nodiscard]] U1 IEqual(const U32U64& lhs, const U32U64& rhs);
|
||||
[[nodiscard]] U1 ILessThanEqual(const U32& lhs, const U32& rhs, bool is_signed);
|
||||
[[nodiscard]] U1 IGreaterThan(const U32& lhs, const U32& rhs, bool is_signed);
|
||||
[[nodiscard]] U1 INotEqual(const U32& lhs, const U32& rhs);
|
||||
[[nodiscard]] U1 IGreaterThanEqual(const U32& lhs, const U32& rhs, bool is_signed);
|
||||
|
||||
[[nodiscard]] U32 SharedAtomicIAdd(const U32& pointer_offset, const U32& value);
|
||||
[[nodiscard]] U32 SharedAtomicSMin(const U32& pointer_offset, const U32& value);
|
||||
[[nodiscard]] U32 SharedAtomicUMin(const U32& pointer_offset, const U32& value);
|
||||
[[nodiscard]] U32 SharedAtomicIMin(const U32& pointer_offset, const U32& value, bool is_signed);
|
||||
[[nodiscard]] U32 SharedAtomicSMax(const U32& pointer_offset, const U32& value);
|
||||
[[nodiscard]] U32 SharedAtomicUMax(const U32& pointer_offset, const U32& value);
|
||||
[[nodiscard]] U32 SharedAtomicIMax(const U32& pointer_offset, const U32& value, bool is_signed);
|
||||
[[nodiscard]] U32 SharedAtomicInc(const U32& pointer_offset, const U32& value);
|
||||
[[nodiscard]] U32 SharedAtomicDec(const U32& pointer_offset, const U32& value);
|
||||
[[nodiscard]] U32 SharedAtomicAnd(const U32& pointer_offset, const U32& value);
|
||||
[[nodiscard]] U32 SharedAtomicOr(const U32& pointer_offset, const U32& value);
|
||||
[[nodiscard]] U32 SharedAtomicXor(const U32& pointer_offset, const U32& value);
|
||||
[[nodiscard]] U32U64 SharedAtomicExchange(const U32& pointer_offset, const U32U64& value);
|
||||
|
||||
[[nodiscard]] U32U64 GlobalAtomicIAdd(const U64& pointer_offset, const U32U64& value);
|
||||
[[nodiscard]] U32U64 GlobalAtomicSMin(const U64& pointer_offset, const U32U64& value);
|
||||
[[nodiscard]] U32U64 GlobalAtomicUMin(const U64& pointer_offset, const U32U64& value);
|
||||
[[nodiscard]] U32U64 GlobalAtomicIMin(const U64& pointer_offset, const U32U64& value,
|
||||
bool is_signed);
|
||||
[[nodiscard]] U32U64 GlobalAtomicSMax(const U64& pointer_offset, const U32U64& value);
|
||||
[[nodiscard]] U32U64 GlobalAtomicUMax(const U64& pointer_offset, const U32U64& value);
|
||||
[[nodiscard]] U32U64 GlobalAtomicIMax(const U64& pointer_offset, const U32U64& value,
|
||||
bool is_signed);
|
||||
[[nodiscard]] U32 GlobalAtomicInc(const U64& pointer_offset, const U32& value);
|
||||
[[nodiscard]] U32 GlobalAtomicDec(const U64& pointer_offset, const U32& value);
|
||||
[[nodiscard]] U32U64 GlobalAtomicAnd(const U64& pointer_offset, const U32U64& value);
|
||||
[[nodiscard]] U32U64 GlobalAtomicOr(const U64& pointer_offset, const U32U64& value);
|
||||
[[nodiscard]] U32U64 GlobalAtomicXor(const U64& pointer_offset, const U32U64& value);
|
||||
[[nodiscard]] U32U64 GlobalAtomicExchange(const U64& pointer_offset, const U32U64& value);
|
||||
|
||||
[[nodiscard]] F32 GlobalAtomicF32Add(const U64& pointer_offset, const Value& value,
|
||||
const FpControl control = {});
|
||||
[[nodiscard]] Value GlobalAtomicF16x2Add(const U64& pointer_offset, const Value& value,
|
||||
const FpControl control = {});
|
||||
[[nodiscard]] Value GlobalAtomicF16x2Min(const U64& pointer_offset, const Value& value,
|
||||
const FpControl control = {});
|
||||
[[nodiscard]] Value GlobalAtomicF16x2Max(const U64& pointer_offset, const Value& value,
|
||||
const FpControl control = {});
|
||||
|
||||
[[nodiscard]] U1 LogicalOr(const U1& a, const U1& b);
|
||||
[[nodiscard]] U1 LogicalAnd(const U1& a, const U1& b);
|
||||
[[nodiscard]] U1 LogicalXor(const U1& a, const U1& b);
|
||||
[[nodiscard]] U1 LogicalNot(const U1& value);
|
||||
|
||||
[[nodiscard]] U32U64 ConvertFToS(size_t bitsize, const F16F32F64& value);
|
||||
[[nodiscard]] U32U64 ConvertFToU(size_t bitsize, const F16F32F64& value);
|
||||
[[nodiscard]] U32U64 ConvertFToI(size_t bitsize, bool is_signed, const F16F32F64& value);
|
||||
[[nodiscard]] F16F32F64 ConvertSToF(size_t dest_bitsize, size_t src_bitsize, const Value& value,
|
||||
FpControl control = {});
|
||||
[[nodiscard]] F16F32F64 ConvertUToF(size_t dest_bitsize, size_t src_bitsize, const Value& value,
|
||||
FpControl control = {});
|
||||
[[nodiscard]] F16F32F64 ConvertIToF(size_t dest_bitsize, size_t src_bitsize, bool is_signed,
|
||||
const Value& value, FpControl control = {});
|
||||
|
||||
[[nodiscard]] U8U16U32U64 UConvert(size_t result_bitsize, const U8U16U32U64& value);
|
||||
[[nodiscard]] U8U16U32U64 SConvert(size_t result_bitsize, const U8U16U32U64& value);
|
||||
[[nodiscard]] F16F32F64 FPConvert(size_t result_bitsize, const F16F32F64& value,
|
||||
FpControl control = {});
|
||||
|
||||
[[nodiscard]] Value ImageSampleImplicitLod(const Value& handle, const Value& coords,
|
||||
const F32& bias, const Value& offset,
|
||||
const F32& lod_clamp, TextureInstInfo info);
|
||||
[[nodiscard]] Value ImageSampleExplicitLod(const Value& handle, const Value& coords,
|
||||
const F32& lod, const Value& offset,
|
||||
TextureInstInfo info);
|
||||
[[nodiscard]] F32 ImageSampleDrefImplicitLod(const Value& handle, const Value& coords,
|
||||
const F32& dref, const F32& bias,
|
||||
const Value& offset, const F32& lod_clamp,
|
||||
TextureInstInfo info);
|
||||
[[nodiscard]] F32 ImageSampleDrefExplicitLod(const Value& handle, const Value& coords,
|
||||
const F32& dref, const F32& lod,
|
||||
const Value& offset, TextureInstInfo info);
|
||||
[[nodiscard]] Value ImageQueryDimension(const Value& handle, const IR::U32& lod,
|
||||
const IR::U1& skip_mips);
|
||||
[[nodiscard]] Value ImageQueryDimension(const Value& handle, const IR::U32& lod,
|
||||
const IR::U1& skip_mips, TextureInstInfo info);
|
||||
|
||||
[[nodiscard]] Value ImageQueryLod(const Value& handle, const Value& coords,
|
||||
TextureInstInfo info);
|
||||
[[nodiscard]] Value ImageGather(const Value& handle, const Value& coords, const Value& offset,
|
||||
const Value& offset2, TextureInstInfo info);
|
||||
[[nodiscard]] Value ImageGatherDref(const Value& handle, const Value& coords,
|
||||
const Value& offset, const Value& offset2, const F32& dref,
|
||||
TextureInstInfo info);
|
||||
[[nodiscard]] Value ImageFetch(const Value& handle, const Value& coords, const Value& offset,
|
||||
const U32& lod, const U32& multisampling, TextureInstInfo info);
|
||||
[[nodiscard]] Value ImageGradient(const Value& handle, const Value& coords,
|
||||
const Value& derivatives, const Value& offset,
|
||||
const F32& lod_clamp, TextureInstInfo info);
|
||||
[[nodiscard]] Value ImageRead(const Value& handle, const Value& coords, TextureInstInfo info);
|
||||
void ImageWrite(const Value& handle, const Value& coords, const Value& color,
|
||||
TextureInstInfo info);
|
||||
|
||||
[[nodiscard]] Value ImageAtomicIAdd(const Value& handle, const Value& coords,
|
||||
const Value& value, TextureInstInfo info);
|
||||
[[nodiscard]] Value ImageAtomicSMin(const Value& handle, const Value& coords,
|
||||
const Value& value, TextureInstInfo info);
|
||||
[[nodiscard]] Value ImageAtomicUMin(const Value& handle, const Value& coords,
|
||||
const Value& value, TextureInstInfo info);
|
||||
[[nodiscard]] Value ImageAtomicIMin(const Value& handle, const Value& coords,
|
||||
const Value& value, bool is_signed, TextureInstInfo info);
|
||||
[[nodiscard]] Value ImageAtomicSMax(const Value& handle, const Value& coords,
|
||||
const Value& value, TextureInstInfo info);
|
||||
[[nodiscard]] Value ImageAtomicUMax(const Value& handle, const Value& coords,
|
||||
const Value& value, TextureInstInfo info);
|
||||
[[nodiscard]] Value ImageAtomicIMax(const Value& handle, const Value& coords,
|
||||
const Value& value, bool is_signed, TextureInstInfo info);
|
||||
[[nodiscard]] Value ImageAtomicInc(const Value& handle, const Value& coords, const Value& value,
|
||||
TextureInstInfo info);
|
||||
[[nodiscard]] Value ImageAtomicDec(const Value& handle, const Value& coords, const Value& value,
|
||||
TextureInstInfo info);
|
||||
[[nodiscard]] Value ImageAtomicAnd(const Value& handle, const Value& coords, const Value& value,
|
||||
TextureInstInfo info);
|
||||
[[nodiscard]] Value ImageAtomicOr(const Value& handle, const Value& coords, const Value& value,
|
||||
TextureInstInfo info);
|
||||
[[nodiscard]] Value ImageAtomicXor(const Value& handle, const Value& coords, const Value& value,
|
||||
TextureInstInfo info);
|
||||
[[nodiscard]] Value ImageAtomicExchange(const Value& handle, const Value& coords,
|
||||
const Value& value, TextureInstInfo info);
|
||||
|
||||
[[nodiscard]] U1 IsTextureScaled(const U32& index);
|
||||
[[nodiscard]] U1 IsImageScaled(const U32& index);
|
||||
|
||||
[[nodiscard]] U1 VoteAll(const U1& value);
|
||||
[[nodiscard]] U1 VoteAny(const U1& value);
|
||||
[[nodiscard]] U1 VoteEqual(const U1& value);
|
||||
[[nodiscard]] U32 SubgroupBallot(const U1& value);
|
||||
[[nodiscard]] U32 SubgroupEqMask();
|
||||
[[nodiscard]] U32 SubgroupLtMask();
|
||||
[[nodiscard]] U32 SubgroupLeMask();
|
||||
[[nodiscard]] U32 SubgroupGtMask();
|
||||
[[nodiscard]] U32 SubgroupGeMask();
|
||||
[[nodiscard]] U32 ShuffleIndex(const IR::U32& value, const IR::U32& index, const IR::U32& clamp,
|
||||
const IR::U32& seg_mask);
|
||||
[[nodiscard]] U32 ShuffleUp(const IR::U32& value, const IR::U32& index, const IR::U32& clamp,
|
||||
const IR::U32& seg_mask);
|
||||
[[nodiscard]] U32 ShuffleDown(const IR::U32& value, const IR::U32& index, const IR::U32& clamp,
|
||||
const IR::U32& seg_mask);
|
||||
[[nodiscard]] U32 ShuffleButterfly(const IR::U32& value, const IR::U32& index,
|
||||
const IR::U32& clamp, const IR::U32& seg_mask);
|
||||
[[nodiscard]] F32 FSwizzleAdd(const F32& a, const F32& b, const U32& swizzle,
|
||||
FpControl control = {});
|
||||
|
||||
[[nodiscard]] F32 DPdxFine(const F32& a);
|
||||
|
||||
[[nodiscard]] F32 DPdyFine(const F32& a);
|
||||
|
||||
[[nodiscard]] F32 DPdxCoarse(const F32& a);
|
||||
|
||||
[[nodiscard]] F32 DPdyCoarse(const F32& a);
|
||||
|
||||
private:
|
||||
IR::Block::iterator insertion_point;
|
||||
|
||||
template <typename T = Value, typename... Args>
|
||||
T Inst(Opcode op, Args... args) {
|
||||
auto it{block->PrependNewInst(insertion_point, op, {Value{args}...})};
|
||||
return T{Value{&*it}};
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
requires(sizeof(T) <= sizeof(u32) && std::is_trivially_copyable_v<T>)
|
||||
struct Flags {
|
||||
Flags() = default;
|
||||
Flags(T proxy_) : proxy{proxy_} {}
|
||||
|
||||
T proxy;
|
||||
};
|
||||
|
||||
template <typename T = Value, typename FlagType, typename... Args>
|
||||
T Inst(Opcode op, Flags<FlagType> flags, Args... args) {
|
||||
u32 raw_flags{};
|
||||
std::memcpy(&raw_flags, &flags.proxy, sizeof(flags.proxy));
|
||||
auto it{block->PrependNewInst(insertion_point, op, {Value{args}...}, raw_flags)};
|
||||
return T{Value{&*it}};
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace Shader::IR
|
||||
455
gpu/third_party/suyu/shader_recompiler/frontend/ir/microinstruction.cpp
vendored
Normal file
455
gpu/third_party/suyu/shader_recompiler/frontend/ir/microinstruction.cpp
vendored
Normal file
@@ -0,0 +1,455 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <algorithm>
|
||||
#include <memory>
|
||||
|
||||
#include "shader_recompiler/exception.h"
|
||||
#include "shader_recompiler/frontend/ir/basic_block.h"
|
||||
#include "shader_recompiler/frontend/ir/type.h"
|
||||
#include "shader_recompiler/frontend/ir/value.h"
|
||||
|
||||
namespace Shader::IR {
|
||||
namespace {
|
||||
void CheckPseudoInstruction(IR::Inst* inst, IR::Opcode opcode) {
|
||||
if (inst && inst->GetOpcode() != opcode) {
|
||||
throw LogicError("Invalid pseudo-instruction");
|
||||
}
|
||||
}
|
||||
|
||||
void SetPseudoInstruction(IR::Inst*& dest_inst, IR::Inst* pseudo_inst) {
|
||||
if (dest_inst) {
|
||||
throw LogicError("Only one of each type of pseudo-op allowed");
|
||||
}
|
||||
dest_inst = pseudo_inst;
|
||||
}
|
||||
|
||||
void RemovePseudoInstruction(IR::Inst*& inst, IR::Opcode expected_opcode) {
|
||||
if (inst->GetOpcode() != expected_opcode) {
|
||||
throw LogicError("Undoing use of invalid pseudo-op");
|
||||
}
|
||||
inst = nullptr;
|
||||
}
|
||||
|
||||
void AllocAssociatedInsts(std::unique_ptr<AssociatedInsts>& associated_insts) {
|
||||
if (!associated_insts) {
|
||||
associated_insts = std::make_unique<AssociatedInsts>();
|
||||
}
|
||||
}
|
||||
} // Anonymous namespace
|
||||
|
||||
Inst::Inst(IR::Opcode op_, u32 flags_) noexcept : op{op_}, flags{flags_} {
|
||||
if (op == Opcode::Phi) {
|
||||
std::construct_at(&phi_args);
|
||||
} else {
|
||||
std::construct_at(&args);
|
||||
}
|
||||
}
|
||||
|
||||
Inst::Inst(const Inst& base) : op{base.op}, flags{base.flags} {
|
||||
if (base.op == Opcode::Phi) {
|
||||
throw NotImplementedException("Copying phi node");
|
||||
}
|
||||
std::construct_at(&args);
|
||||
const size_t num_args{base.NumArgs()};
|
||||
for (size_t index = 0; index < num_args; ++index) {
|
||||
SetArg(index, base.Arg(index));
|
||||
}
|
||||
}
|
||||
|
||||
Inst::~Inst() {
|
||||
if (op == Opcode::Phi) {
|
||||
std::destroy_at(&phi_args);
|
||||
} else {
|
||||
std::destroy_at(&args);
|
||||
}
|
||||
}
|
||||
|
||||
bool Inst::MayHaveSideEffects() const noexcept {
|
||||
switch (op) {
|
||||
case Opcode::ConditionRef:
|
||||
case Opcode::Reference:
|
||||
case Opcode::PhiMove:
|
||||
case Opcode::Prologue:
|
||||
case Opcode::Epilogue:
|
||||
case Opcode::Join:
|
||||
case Opcode::DemoteToHelperInvocation:
|
||||
case Opcode::Barrier:
|
||||
case Opcode::WorkgroupMemoryBarrier:
|
||||
case Opcode::DeviceMemoryBarrier:
|
||||
case Opcode::EmitVertex:
|
||||
case Opcode::EndPrimitive:
|
||||
case Opcode::SetAttribute:
|
||||
case Opcode::SetAttributeIndexed:
|
||||
case Opcode::SetPatch:
|
||||
case Opcode::SetFragColor:
|
||||
case Opcode::SetSampleMask:
|
||||
case Opcode::SetFragDepth:
|
||||
case Opcode::WriteGlobalU8:
|
||||
case Opcode::WriteGlobalS8:
|
||||
case Opcode::WriteGlobalU16:
|
||||
case Opcode::WriteGlobalS16:
|
||||
case Opcode::WriteGlobal32:
|
||||
case Opcode::WriteGlobal64:
|
||||
case Opcode::WriteGlobal128:
|
||||
case Opcode::WriteStorageU8:
|
||||
case Opcode::WriteStorageS8:
|
||||
case Opcode::WriteStorageU16:
|
||||
case Opcode::WriteStorageS16:
|
||||
case Opcode::WriteStorage32:
|
||||
case Opcode::WriteStorage64:
|
||||
case Opcode::WriteStorage128:
|
||||
case Opcode::WriteLocal:
|
||||
case Opcode::WriteSharedU8:
|
||||
case Opcode::WriteSharedU16:
|
||||
case Opcode::WriteSharedU32:
|
||||
case Opcode::WriteSharedU64:
|
||||
case Opcode::WriteSharedU128:
|
||||
case Opcode::SharedAtomicIAdd32:
|
||||
case Opcode::SharedAtomicSMin32:
|
||||
case Opcode::SharedAtomicUMin32:
|
||||
case Opcode::SharedAtomicSMax32:
|
||||
case Opcode::SharedAtomicUMax32:
|
||||
case Opcode::SharedAtomicInc32:
|
||||
case Opcode::SharedAtomicDec32:
|
||||
case Opcode::SharedAtomicAnd32:
|
||||
case Opcode::SharedAtomicOr32:
|
||||
case Opcode::SharedAtomicXor32:
|
||||
case Opcode::SharedAtomicExchange32:
|
||||
case Opcode::SharedAtomicExchange64:
|
||||
case Opcode::SharedAtomicExchange32x2:
|
||||
case Opcode::GlobalAtomicIAdd32:
|
||||
case Opcode::GlobalAtomicSMin32:
|
||||
case Opcode::GlobalAtomicUMin32:
|
||||
case Opcode::GlobalAtomicSMax32:
|
||||
case Opcode::GlobalAtomicUMax32:
|
||||
case Opcode::GlobalAtomicInc32:
|
||||
case Opcode::GlobalAtomicDec32:
|
||||
case Opcode::GlobalAtomicAnd32:
|
||||
case Opcode::GlobalAtomicOr32:
|
||||
case Opcode::GlobalAtomicXor32:
|
||||
case Opcode::GlobalAtomicExchange32:
|
||||
case Opcode::GlobalAtomicIAdd64:
|
||||
case Opcode::GlobalAtomicSMin64:
|
||||
case Opcode::GlobalAtomicUMin64:
|
||||
case Opcode::GlobalAtomicSMax64:
|
||||
case Opcode::GlobalAtomicUMax64:
|
||||
case Opcode::GlobalAtomicAnd64:
|
||||
case Opcode::GlobalAtomicOr64:
|
||||
case Opcode::GlobalAtomicXor64:
|
||||
case Opcode::GlobalAtomicExchange64:
|
||||
case Opcode::GlobalAtomicIAdd32x2:
|
||||
case Opcode::GlobalAtomicSMin32x2:
|
||||
case Opcode::GlobalAtomicUMin32x2:
|
||||
case Opcode::GlobalAtomicSMax32x2:
|
||||
case Opcode::GlobalAtomicUMax32x2:
|
||||
case Opcode::GlobalAtomicAnd32x2:
|
||||
case Opcode::GlobalAtomicOr32x2:
|
||||
case Opcode::GlobalAtomicXor32x2:
|
||||
case Opcode::GlobalAtomicExchange32x2:
|
||||
case Opcode::GlobalAtomicAddF32:
|
||||
case Opcode::GlobalAtomicAddF16x2:
|
||||
case Opcode::GlobalAtomicAddF32x2:
|
||||
case Opcode::GlobalAtomicMinF16x2:
|
||||
case Opcode::GlobalAtomicMinF32x2:
|
||||
case Opcode::GlobalAtomicMaxF16x2:
|
||||
case Opcode::GlobalAtomicMaxF32x2:
|
||||
case Opcode::StorageAtomicIAdd32:
|
||||
case Opcode::StorageAtomicSMin32:
|
||||
case Opcode::StorageAtomicUMin32:
|
||||
case Opcode::StorageAtomicSMax32:
|
||||
case Opcode::StorageAtomicUMax32:
|
||||
case Opcode::StorageAtomicInc32:
|
||||
case Opcode::StorageAtomicDec32:
|
||||
case Opcode::StorageAtomicAnd32:
|
||||
case Opcode::StorageAtomicOr32:
|
||||
case Opcode::StorageAtomicXor32:
|
||||
case Opcode::StorageAtomicExchange32:
|
||||
case Opcode::StorageAtomicIAdd64:
|
||||
case Opcode::StorageAtomicSMin64:
|
||||
case Opcode::StorageAtomicUMin64:
|
||||
case Opcode::StorageAtomicSMax64:
|
||||
case Opcode::StorageAtomicUMax64:
|
||||
case Opcode::StorageAtomicAnd64:
|
||||
case Opcode::StorageAtomicOr64:
|
||||
case Opcode::StorageAtomicXor64:
|
||||
case Opcode::StorageAtomicExchange64:
|
||||
case Opcode::StorageAtomicIAdd32x2:
|
||||
case Opcode::StorageAtomicSMin32x2:
|
||||
case Opcode::StorageAtomicUMin32x2:
|
||||
case Opcode::StorageAtomicSMax32x2:
|
||||
case Opcode::StorageAtomicUMax32x2:
|
||||
case Opcode::StorageAtomicAnd32x2:
|
||||
case Opcode::StorageAtomicOr32x2:
|
||||
case Opcode::StorageAtomicXor32x2:
|
||||
case Opcode::StorageAtomicExchange32x2:
|
||||
case Opcode::StorageAtomicAddF32:
|
||||
case Opcode::StorageAtomicAddF16x2:
|
||||
case Opcode::StorageAtomicAddF32x2:
|
||||
case Opcode::StorageAtomicMinF16x2:
|
||||
case Opcode::StorageAtomicMinF32x2:
|
||||
case Opcode::StorageAtomicMaxF16x2:
|
||||
case Opcode::StorageAtomicMaxF32x2:
|
||||
case Opcode::BindlessImageWrite:
|
||||
case Opcode::BoundImageWrite:
|
||||
case Opcode::ImageWrite:
|
||||
case IR::Opcode::BindlessImageAtomicIAdd32:
|
||||
case IR::Opcode::BindlessImageAtomicSMin32:
|
||||
case IR::Opcode::BindlessImageAtomicUMin32:
|
||||
case IR::Opcode::BindlessImageAtomicSMax32:
|
||||
case IR::Opcode::BindlessImageAtomicUMax32:
|
||||
case IR::Opcode::BindlessImageAtomicInc32:
|
||||
case IR::Opcode::BindlessImageAtomicDec32:
|
||||
case IR::Opcode::BindlessImageAtomicAnd32:
|
||||
case IR::Opcode::BindlessImageAtomicOr32:
|
||||
case IR::Opcode::BindlessImageAtomicXor32:
|
||||
case IR::Opcode::BindlessImageAtomicExchange32:
|
||||
case IR::Opcode::BoundImageAtomicIAdd32:
|
||||
case IR::Opcode::BoundImageAtomicSMin32:
|
||||
case IR::Opcode::BoundImageAtomicUMin32:
|
||||
case IR::Opcode::BoundImageAtomicSMax32:
|
||||
case IR::Opcode::BoundImageAtomicUMax32:
|
||||
case IR::Opcode::BoundImageAtomicInc32:
|
||||
case IR::Opcode::BoundImageAtomicDec32:
|
||||
case IR::Opcode::BoundImageAtomicAnd32:
|
||||
case IR::Opcode::BoundImageAtomicOr32:
|
||||
case IR::Opcode::BoundImageAtomicXor32:
|
||||
case IR::Opcode::BoundImageAtomicExchange32:
|
||||
case IR::Opcode::ImageAtomicIAdd32:
|
||||
case IR::Opcode::ImageAtomicSMin32:
|
||||
case IR::Opcode::ImageAtomicUMin32:
|
||||
case IR::Opcode::ImageAtomicSMax32:
|
||||
case IR::Opcode::ImageAtomicUMax32:
|
||||
case IR::Opcode::ImageAtomicInc32:
|
||||
case IR::Opcode::ImageAtomicDec32:
|
||||
case IR::Opcode::ImageAtomicAnd32:
|
||||
case IR::Opcode::ImageAtomicOr32:
|
||||
case IR::Opcode::ImageAtomicXor32:
|
||||
case IR::Opcode::ImageAtomicExchange32:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool Inst::IsPseudoInstruction() const noexcept {
|
||||
switch (op) {
|
||||
case Opcode::GetZeroFromOp:
|
||||
case Opcode::GetSignFromOp:
|
||||
case Opcode::GetCarryFromOp:
|
||||
case Opcode::GetOverflowFromOp:
|
||||
case Opcode::GetSparseFromOp:
|
||||
case Opcode::GetInBoundsFromOp:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool Inst::AreAllArgsImmediates() const {
|
||||
if (op == Opcode::Phi) {
|
||||
throw LogicError("Testing for all arguments are immediates on phi instruction");
|
||||
}
|
||||
return std::all_of(args.begin(), args.begin() + NumArgs(),
|
||||
[](const IR::Value& value) { return value.IsImmediate(); });
|
||||
}
|
||||
|
||||
Inst* Inst::GetAssociatedPseudoOperation(IR::Opcode opcode) {
|
||||
if (!associated_insts) {
|
||||
return nullptr;
|
||||
}
|
||||
switch (opcode) {
|
||||
case Opcode::GetZeroFromOp:
|
||||
CheckPseudoInstruction(associated_insts->zero_inst, Opcode::GetZeroFromOp);
|
||||
return associated_insts->zero_inst;
|
||||
case Opcode::GetSignFromOp:
|
||||
CheckPseudoInstruction(associated_insts->sign_inst, Opcode::GetSignFromOp);
|
||||
return associated_insts->sign_inst;
|
||||
case Opcode::GetCarryFromOp:
|
||||
CheckPseudoInstruction(associated_insts->carry_inst, Opcode::GetCarryFromOp);
|
||||
return associated_insts->carry_inst;
|
||||
case Opcode::GetOverflowFromOp:
|
||||
CheckPseudoInstruction(associated_insts->overflow_inst, Opcode::GetOverflowFromOp);
|
||||
return associated_insts->overflow_inst;
|
||||
case Opcode::GetSparseFromOp:
|
||||
CheckPseudoInstruction(associated_insts->sparse_inst, Opcode::GetSparseFromOp);
|
||||
return associated_insts->sparse_inst;
|
||||
case Opcode::GetInBoundsFromOp:
|
||||
CheckPseudoInstruction(associated_insts->in_bounds_inst, Opcode::GetInBoundsFromOp);
|
||||
return associated_insts->in_bounds_inst;
|
||||
default:
|
||||
throw InvalidArgument("{} is not a pseudo-instruction", opcode);
|
||||
}
|
||||
}
|
||||
|
||||
IR::Type Inst::Type() const {
|
||||
if (op == IR::Opcode::Phi) {
|
||||
// The type of a phi node is stored in its flags
|
||||
return Flags<IR::Type>();
|
||||
}
|
||||
return TypeOf(op);
|
||||
}
|
||||
|
||||
void Inst::SetArg(size_t index, Value value) {
|
||||
if (index >= NumArgs()) {
|
||||
throw InvalidArgument("Out of bounds argument index {} in opcode {}", index, op);
|
||||
}
|
||||
const IR::Value arg{Arg(index)};
|
||||
if (!arg.IsImmediate()) {
|
||||
UndoUse(arg);
|
||||
}
|
||||
if (!value.IsImmediate()) {
|
||||
Use(value);
|
||||
}
|
||||
if (op == Opcode::Phi) {
|
||||
phi_args[index].second = value;
|
||||
} else {
|
||||
args[index] = value;
|
||||
}
|
||||
}
|
||||
|
||||
Block* Inst::PhiBlock(size_t index) const {
|
||||
if (op != Opcode::Phi) {
|
||||
throw LogicError("{} is not a Phi instruction", op);
|
||||
}
|
||||
if (index >= phi_args.size()) {
|
||||
throw InvalidArgument("Out of bounds argument index {} in phi instruction");
|
||||
}
|
||||
return phi_args[index].first;
|
||||
}
|
||||
|
||||
void Inst::AddPhiOperand(Block* predecessor, const Value& value) {
|
||||
if (!value.IsImmediate()) {
|
||||
Use(value);
|
||||
}
|
||||
phi_args.emplace_back(predecessor, value);
|
||||
}
|
||||
|
||||
void Inst::OrderPhiArgs() {
|
||||
if (op != Opcode::Phi) {
|
||||
throw LogicError("{} is not a Phi instruction", op);
|
||||
}
|
||||
std::sort(phi_args.begin(), phi_args.end(),
|
||||
[](const std::pair<Block*, Value>& a, const std::pair<Block*, Value>& b) {
|
||||
return a.first->GetOrder() < b.first->GetOrder();
|
||||
});
|
||||
}
|
||||
|
||||
void Inst::Invalidate() {
|
||||
ClearArgs();
|
||||
ReplaceOpcode(Opcode::Void);
|
||||
}
|
||||
|
||||
void Inst::ClearArgs() {
|
||||
if (op == Opcode::Phi) {
|
||||
for (auto& pair : phi_args) {
|
||||
IR::Value& value{pair.second};
|
||||
if (!value.IsImmediate()) {
|
||||
UndoUse(value);
|
||||
}
|
||||
}
|
||||
phi_args.clear();
|
||||
} else {
|
||||
for (auto& value : args) {
|
||||
if (!value.IsImmediate()) {
|
||||
UndoUse(value);
|
||||
}
|
||||
}
|
||||
// Reset arguments to null
|
||||
// std::memset was measured to be faster on MSVC than std::ranges:fill
|
||||
std::memset(reinterpret_cast<char*>(&args), 0, sizeof(args));
|
||||
}
|
||||
}
|
||||
|
||||
void Inst::ReplaceUsesWith(Value replacement) {
|
||||
Invalidate();
|
||||
ReplaceOpcode(Opcode::Identity);
|
||||
if (!replacement.IsImmediate()) {
|
||||
Use(replacement);
|
||||
}
|
||||
args[0] = replacement;
|
||||
}
|
||||
|
||||
void Inst::ReplaceOpcode(IR::Opcode opcode) {
|
||||
if (opcode == IR::Opcode::Phi) {
|
||||
throw LogicError("Cannot transition into Phi");
|
||||
}
|
||||
if (op == Opcode::Phi) {
|
||||
// Transition out of phi arguments into non-phi
|
||||
std::destroy_at(&phi_args);
|
||||
std::construct_at(&args);
|
||||
}
|
||||
op = opcode;
|
||||
}
|
||||
|
||||
void Inst::Use(const Value& value) {
|
||||
Inst* const inst{value.Inst()};
|
||||
++inst->use_count;
|
||||
|
||||
std::unique_ptr<AssociatedInsts>& assoc_inst{inst->associated_insts};
|
||||
switch (op) {
|
||||
case Opcode::GetZeroFromOp:
|
||||
AllocAssociatedInsts(assoc_inst);
|
||||
SetPseudoInstruction(assoc_inst->zero_inst, this);
|
||||
break;
|
||||
case Opcode::GetSignFromOp:
|
||||
AllocAssociatedInsts(assoc_inst);
|
||||
SetPseudoInstruction(assoc_inst->sign_inst, this);
|
||||
break;
|
||||
case Opcode::GetCarryFromOp:
|
||||
AllocAssociatedInsts(assoc_inst);
|
||||
SetPseudoInstruction(assoc_inst->carry_inst, this);
|
||||
break;
|
||||
case Opcode::GetOverflowFromOp:
|
||||
AllocAssociatedInsts(assoc_inst);
|
||||
SetPseudoInstruction(assoc_inst->overflow_inst, this);
|
||||
break;
|
||||
case Opcode::GetSparseFromOp:
|
||||
AllocAssociatedInsts(assoc_inst);
|
||||
SetPseudoInstruction(assoc_inst->sparse_inst, this);
|
||||
break;
|
||||
case Opcode::GetInBoundsFromOp:
|
||||
AllocAssociatedInsts(assoc_inst);
|
||||
SetPseudoInstruction(assoc_inst->in_bounds_inst, this);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Inst::UndoUse(const Value& value) {
|
||||
Inst* const inst{value.Inst()};
|
||||
--inst->use_count;
|
||||
|
||||
std::unique_ptr<AssociatedInsts>& assoc_inst{inst->associated_insts};
|
||||
switch (op) {
|
||||
case Opcode::GetZeroFromOp:
|
||||
AllocAssociatedInsts(assoc_inst);
|
||||
RemovePseudoInstruction(assoc_inst->zero_inst, Opcode::GetZeroFromOp);
|
||||
break;
|
||||
case Opcode::GetSignFromOp:
|
||||
AllocAssociatedInsts(assoc_inst);
|
||||
RemovePseudoInstruction(assoc_inst->sign_inst, Opcode::GetSignFromOp);
|
||||
break;
|
||||
case Opcode::GetCarryFromOp:
|
||||
AllocAssociatedInsts(assoc_inst);
|
||||
RemovePseudoInstruction(assoc_inst->carry_inst, Opcode::GetCarryFromOp);
|
||||
break;
|
||||
case Opcode::GetOverflowFromOp:
|
||||
AllocAssociatedInsts(assoc_inst);
|
||||
RemovePseudoInstruction(assoc_inst->overflow_inst, Opcode::GetOverflowFromOp);
|
||||
break;
|
||||
case Opcode::GetSparseFromOp:
|
||||
AllocAssociatedInsts(assoc_inst);
|
||||
RemovePseudoInstruction(assoc_inst->sparse_inst, Opcode::GetSparseFromOp);
|
||||
break;
|
||||
case Opcode::GetInBoundsFromOp:
|
||||
AllocAssociatedInsts(assoc_inst);
|
||||
RemovePseudoInstruction(assoc_inst->in_bounds_inst, Opcode::GetInBoundsFromOp);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Shader::IR
|
||||
56
gpu/third_party/suyu/shader_recompiler/frontend/ir/modifiers.h
vendored
Normal file
56
gpu/third_party/suyu/shader_recompiler/frontend/ir/modifiers.h
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2026 suyu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/bit_field.h"
|
||||
#include "common/common_types.h"
|
||||
#include "shader_recompiler/shader_info.h"
|
||||
|
||||
namespace Shader::IR {
|
||||
|
||||
enum class FmzMode : u8 {
|
||||
DontCare, // Not specified for this instruction
|
||||
FTZ, // Flush denorms to zero, NAN is propagated (D3D11, NVN, GL, VK)
|
||||
FMZ, // Flush denorms to zero, x * 0 == 0 (D3D9)
|
||||
None, // Denorms are not flushed, NAN is propagated (nouveau)
|
||||
};
|
||||
|
||||
enum class FpRounding : u8 {
|
||||
DontCare, // Not specified for this instruction
|
||||
RN, // Round to nearest even,
|
||||
RM, // Round towards negative infinity
|
||||
RP, // Round towards positive infinity
|
||||
RZ, // Round towards zero
|
||||
};
|
||||
|
||||
struct FpControl {
|
||||
bool no_contraction{false};
|
||||
FpRounding rounding{FpRounding::DontCare};
|
||||
FmzMode fmz_mode{FmzMode::DontCare};
|
||||
};
|
||||
static_assert(sizeof(FpControl) <= sizeof(u32));
|
||||
|
||||
union TextureInstInfo {
|
||||
u32 raw;
|
||||
BitField<0, 16, u32> descriptor_index;
|
||||
BitField<16, 3, TextureType> type;
|
||||
BitField<19, 1, u32> is_depth;
|
||||
BitField<20, 1, u32> has_bias;
|
||||
BitField<21, 1, u32> has_lod_clamp;
|
||||
BitField<22, 1, u32> relaxed_precision;
|
||||
BitField<23, 2, u32> gather_component;
|
||||
BitField<25, 2, u32> num_derivatives;
|
||||
BitField<27, 3, ImageFormat> image_format;
|
||||
BitField<30, 1, u32> ndv_is_active;
|
||||
/// Only meaningful for the sampled-texture family (ImageSampleImplicitLod, ImageFetch,
|
||||
/// ImageGather, etc.); unused/zero for storage-image opcodes, which carry their own
|
||||
/// is_integer via ImageDescriptor/ImageBufferDescriptor instead.
|
||||
BitField<31, 1, u32> is_integer;
|
||||
};
|
||||
static_assert(sizeof(TextureInstInfo) <= sizeof(u32));
|
||||
|
||||
} // namespace Shader::IR
|
||||
36
gpu/third_party/suyu/shader_recompiler/frontend/ir/opcodes.cpp
vendored
Normal file
36
gpu/third_party/suyu/shader_recompiler/frontend/ir/opcodes.cpp
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2026 suyu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "shader_recompiler/frontend/ir/opcodes.h"
|
||||
|
||||
namespace Shader::IR {
|
||||
|
||||
namespace Detail {
|
||||
|
||||
OpcodeMeta META_TABLE[532] = {
|
||||
#define OPCODE(name_token, type_token, ...) \
|
||||
{ \
|
||||
.name{#name_token}, \
|
||||
.type = type_token, \
|
||||
.arg_types{__VA_ARGS__}, \
|
||||
},
|
||||
#include "opcodes.inc"
|
||||
#undef OPCODE
|
||||
};
|
||||
|
||||
u8 NUM_ARGS[532] = {
|
||||
#define OPCODE(name_token, type_token, ...) u8(CalculateNumArgsOf(Opcode::name_token)),
|
||||
#include "opcodes.inc"
|
||||
#undef OPCODE
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
std::string_view NameOf(Opcode op) {
|
||||
return Detail::META_TABLE[static_cast<size_t>(op)].name;
|
||||
}
|
||||
|
||||
} // namespace Shader::IR
|
||||
97
gpu/third_party/suyu/shader_recompiler/frontend/ir/opcodes.h
vendored
Normal file
97
gpu/third_party/suyu/shader_recompiler/frontend/ir/opcodes.h
vendored
Normal file
@@ -0,0 +1,97 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2026 suyu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
|
||||
#include <fmt/ranges.h>
|
||||
|
||||
#include <ranges>
|
||||
#include "shader_recompiler/frontend/ir/type.h"
|
||||
|
||||
namespace Shader::IR {
|
||||
|
||||
enum class Opcode {
|
||||
#define OPCODE(name, ...) name,
|
||||
#include "opcodes.inc"
|
||||
#undef OPCODE
|
||||
};
|
||||
|
||||
namespace Detail {
|
||||
struct OpcodeMeta {
|
||||
std::string_view name;
|
||||
Type type;
|
||||
std::array<Type, 5> arg_types;
|
||||
};
|
||||
|
||||
// using enum Type;
|
||||
static constexpr Type Void{Type::Void};
|
||||
static constexpr Type Opaque{Type::Opaque};
|
||||
static constexpr Type Reg{Type::Reg};
|
||||
static constexpr Type Pred{Type::Pred};
|
||||
static constexpr Type Attribute{Type::Attribute};
|
||||
static constexpr Type Patch{Type::Patch};
|
||||
static constexpr Type U1{Type::U1};
|
||||
static constexpr Type U8{Type::U8};
|
||||
static constexpr Type U16{Type::U16};
|
||||
static constexpr Type U32{Type::U32};
|
||||
static constexpr Type U64{Type::U64};
|
||||
static constexpr Type F16{Type::F16};
|
||||
static constexpr Type F32{Type::F32};
|
||||
static constexpr Type F64{Type::F64};
|
||||
static constexpr Type U32x2{Type::U32x2};
|
||||
static constexpr Type U32x3{Type::U32x3};
|
||||
static constexpr Type U32x4{Type::U32x4};
|
||||
static constexpr Type F16x2{Type::F16x2};
|
||||
static constexpr Type F16x3{Type::F16x3};
|
||||
static constexpr Type F16x4{Type::F16x4};
|
||||
static constexpr Type F32x2{Type::F32x2};
|
||||
static constexpr Type F32x3{Type::F32x3};
|
||||
static constexpr Type F32x4{Type::F32x4};
|
||||
static constexpr Type F64x2{Type::F64x2};
|
||||
static constexpr Type F64x3{Type::F64x3};
|
||||
static constexpr Type F64x4{Type::F64x4};
|
||||
|
||||
extern OpcodeMeta META_TABLE[532];
|
||||
constexpr size_t CalculateNumArgsOf(Opcode op) noexcept {
|
||||
const auto& arg_types = META_TABLE[size_t(op)].arg_types;
|
||||
return size_t(std::distance(arg_types.begin(), std::ranges::find(arg_types, Type::Void)));
|
||||
}
|
||||
extern u8 NUM_ARGS[532];
|
||||
} // namespace Detail
|
||||
|
||||
/// Get return type of an opcode
|
||||
[[nodiscard]] inline Type TypeOf(Opcode op) noexcept {
|
||||
return Detail::META_TABLE[size_t(op)].type;
|
||||
}
|
||||
|
||||
/// Get the number of arguments an opcode accepts
|
||||
[[nodiscard]] inline size_t NumArgsOf(Opcode op) noexcept {
|
||||
return size_t(Detail::NUM_ARGS[size_t(op)]);
|
||||
}
|
||||
|
||||
/// Get the required type of an argument of an opcode
|
||||
[[nodiscard]] inline Type ArgTypeOf(Opcode op, size_t arg_index) noexcept {
|
||||
return Detail::META_TABLE[size_t(op)].arg_types[arg_index];
|
||||
}
|
||||
|
||||
/// Get the name of an opcode
|
||||
[[nodiscard]] std::string_view NameOf(Opcode op);
|
||||
|
||||
} // namespace Shader::IR
|
||||
|
||||
template <>
|
||||
struct fmt::formatter<Shader::IR::Opcode> {
|
||||
constexpr auto parse(format_parse_context& ctx) {
|
||||
return ctx.begin();
|
||||
}
|
||||
template <typename FormatContext>
|
||||
auto format(const Shader::IR::Opcode& op, FormatContext& ctx) const {
|
||||
return fmt::format_to(ctx.out(), "{}", Shader::IR::NameOf(op));
|
||||
}
|
||||
};
|
||||
586
gpu/third_party/suyu/shader_recompiler/frontend/ir/opcodes.inc
vendored
Normal file
586
gpu/third_party/suyu/shader_recompiler/frontend/ir/opcodes.inc
vendored
Normal file
@@ -0,0 +1,586 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
// opcode name, return type, arg1 type, arg2 type, arg3 type, arg4 type, arg4 type, ...
|
||||
OPCODE(Phi, Opaque, )
|
||||
OPCODE(Identity, Opaque, Opaque, )
|
||||
OPCODE(Void, Void, )
|
||||
OPCODE(ConditionRef, U1, U1, )
|
||||
OPCODE(Reference, Void, Opaque, )
|
||||
OPCODE(PhiMove, Void, Opaque, Opaque, )
|
||||
|
||||
// Special operations
|
||||
OPCODE(Prologue, Void, )
|
||||
OPCODE(Epilogue, Void, )
|
||||
OPCODE(Join, Void, )
|
||||
OPCODE(DemoteToHelperInvocation, Void, )
|
||||
OPCODE(EmitVertex, Void, U32, )
|
||||
OPCODE(EndPrimitive, Void, U32, )
|
||||
|
||||
// Barriers
|
||||
OPCODE(Barrier, Void, )
|
||||
OPCODE(WorkgroupMemoryBarrier, Void, )
|
||||
OPCODE(DeviceMemoryBarrier, Void, )
|
||||
|
||||
// Context getters/setters
|
||||
OPCODE(GetRegister, U32, Reg, )
|
||||
OPCODE(SetRegister, Void, Reg, U32, )
|
||||
OPCODE(GetPred, U1, Pred, )
|
||||
OPCODE(SetPred, Void, Pred, U1, )
|
||||
OPCODE(GetGotoVariable, U1, U32, )
|
||||
OPCODE(SetGotoVariable, Void, U32, U1, )
|
||||
OPCODE(GetIndirectBranchVariable, U32, )
|
||||
OPCODE(SetIndirectBranchVariable, Void, U32, )
|
||||
OPCODE(GetCbufU8, U32, U32, U32, )
|
||||
OPCODE(GetCbufS8, U32, U32, U32, )
|
||||
OPCODE(GetCbufU16, U32, U32, U32, )
|
||||
OPCODE(GetCbufS16, U32, U32, U32, )
|
||||
OPCODE(GetCbufU32, U32, U32, U32, )
|
||||
OPCODE(GetCbufF32, F32, U32, U32, )
|
||||
OPCODE(GetCbufU32x2, U32x2, U32, U32, )
|
||||
OPCODE(GetAttribute, F32, Attribute, U32, )
|
||||
OPCODE(GetAttributeU32, U32, Attribute, U32, )
|
||||
OPCODE(SetAttribute, Void, Attribute, F32, U32, )
|
||||
OPCODE(GetAttributeIndexed, F32, U32, U32, )
|
||||
OPCODE(SetAttributeIndexed, Void, U32, F32, U32, )
|
||||
OPCODE(GetPatch, F32, Patch, )
|
||||
OPCODE(SetPatch, Void, Patch, F32, )
|
||||
OPCODE(SetFragColor, Void, U32, U32, F32, )
|
||||
OPCODE(SetSampleMask, Void, U32, )
|
||||
OPCODE(SetFragDepth, Void, F32, )
|
||||
OPCODE(GetZFlag, U1, Void, )
|
||||
OPCODE(GetSFlag, U1, Void, )
|
||||
OPCODE(GetCFlag, U1, Void, )
|
||||
OPCODE(GetOFlag, U1, Void, )
|
||||
OPCODE(SetZFlag, Void, U1, )
|
||||
OPCODE(SetSFlag, Void, U1, )
|
||||
OPCODE(SetCFlag, Void, U1, )
|
||||
OPCODE(SetOFlag, Void, U1, )
|
||||
OPCODE(WorkgroupId, U32x3, )
|
||||
OPCODE(LocalInvocationId, U32x3, )
|
||||
OPCODE(InvocationId, U32, )
|
||||
OPCODE(InvocationInfo, U32, )
|
||||
OPCODE(SampleId, U32, )
|
||||
OPCODE(IsHelperInvocation, U1, )
|
||||
OPCODE(SR_WScaleFactorXY, U32, )
|
||||
OPCODE(SR_WScaleFactorZ, U32, )
|
||||
OPCODE(YDirection, F32, )
|
||||
OPCODE(ResolutionDownFactor, F32, )
|
||||
OPCODE(RenderArea, F32x4, )
|
||||
|
||||
// Undefined
|
||||
OPCODE(UndefU1, U1, )
|
||||
OPCODE(UndefU8, U8, )
|
||||
OPCODE(UndefU16, U16, )
|
||||
OPCODE(UndefU32, U32, )
|
||||
OPCODE(UndefU64, U64, )
|
||||
|
||||
// Memory operations
|
||||
OPCODE(LoadGlobalU8, U32, Opaque, )
|
||||
OPCODE(LoadGlobalS8, U32, Opaque, )
|
||||
OPCODE(LoadGlobalU16, U32, Opaque, )
|
||||
OPCODE(LoadGlobalS16, U32, Opaque, )
|
||||
OPCODE(LoadGlobal32, U32, Opaque, )
|
||||
OPCODE(LoadGlobal64, U32x2, Opaque, )
|
||||
OPCODE(LoadGlobal128, U32x4, Opaque, )
|
||||
OPCODE(WriteGlobalU8, Void, Opaque, U32, )
|
||||
OPCODE(WriteGlobalS8, Void, Opaque, U32, )
|
||||
OPCODE(WriteGlobalU16, Void, Opaque, U32, )
|
||||
OPCODE(WriteGlobalS16, Void, Opaque, U32, )
|
||||
OPCODE(WriteGlobal32, Void, Opaque, U32, )
|
||||
OPCODE(WriteGlobal64, Void, Opaque, U32x2, )
|
||||
OPCODE(WriteGlobal128, Void, Opaque, U32x4, )
|
||||
|
||||
// Storage buffer operations
|
||||
OPCODE(LoadStorageU8, U32, U32, U32, )
|
||||
OPCODE(LoadStorageS8, U32, U32, U32, )
|
||||
OPCODE(LoadStorageU16, U32, U32, U32, )
|
||||
OPCODE(LoadStorageS16, U32, U32, U32, )
|
||||
OPCODE(LoadStorage32, U32, U32, U32, )
|
||||
OPCODE(LoadStorage64, U32x2, U32, U32, )
|
||||
OPCODE(LoadStorage128, U32x4, U32, U32, )
|
||||
OPCODE(WriteStorageU8, Void, U32, U32, U32, )
|
||||
OPCODE(WriteStorageS8, Void, U32, U32, U32, )
|
||||
OPCODE(WriteStorageU16, Void, U32, U32, U32, )
|
||||
OPCODE(WriteStorageS16, Void, U32, U32, U32, )
|
||||
OPCODE(WriteStorage32, Void, U32, U32, U32, )
|
||||
OPCODE(WriteStorage64, Void, U32, U32, U32x2, )
|
||||
OPCODE(WriteStorage128, Void, U32, U32, U32x4, )
|
||||
|
||||
// Local memory operations
|
||||
OPCODE(LoadLocal, U32, U32, )
|
||||
OPCODE(WriteLocal, Void, U32, U32, )
|
||||
|
||||
// Shared memory operations
|
||||
OPCODE(LoadSharedU8, U32, U32, )
|
||||
OPCODE(LoadSharedS8, U32, U32, )
|
||||
OPCODE(LoadSharedU16, U32, U32, )
|
||||
OPCODE(LoadSharedS16, U32, U32, )
|
||||
OPCODE(LoadSharedU32, U32, U32, )
|
||||
OPCODE(LoadSharedU64, U32x2, U32, )
|
||||
OPCODE(LoadSharedU128, U32x4, U32, )
|
||||
OPCODE(WriteSharedU8, Void, U32, U32, )
|
||||
OPCODE(WriteSharedU16, Void, U32, U32, )
|
||||
OPCODE(WriteSharedU32, Void, U32, U32, )
|
||||
OPCODE(WriteSharedU64, Void, U32, U32x2, )
|
||||
OPCODE(WriteSharedU128, Void, U32, U32x4, )
|
||||
|
||||
// Vector utility
|
||||
OPCODE(CompositeConstructU32x2, U32x2, U32, U32, )
|
||||
OPCODE(CompositeConstructU32x3, U32x3, U32, U32, U32, )
|
||||
OPCODE(CompositeConstructU32x4, U32x4, U32, U32, U32, U32, )
|
||||
OPCODE(CompositeExtractU32x2, U32, U32x2, U32, )
|
||||
OPCODE(CompositeExtractU32x3, U32, U32x3, U32, )
|
||||
OPCODE(CompositeExtractU32x4, U32, U32x4, U32, )
|
||||
OPCODE(CompositeInsertU32x2, U32x2, U32x2, U32, U32, )
|
||||
OPCODE(CompositeInsertU32x3, U32x3, U32x3, U32, U32, )
|
||||
OPCODE(CompositeInsertU32x4, U32x4, U32x4, U32, U32, )
|
||||
OPCODE(CompositeConstructF16x2, F16x2, F16, F16, )
|
||||
OPCODE(CompositeConstructF16x3, F16x3, F16, F16, F16, )
|
||||
OPCODE(CompositeConstructF16x4, F16x4, F16, F16, F16, F16, )
|
||||
OPCODE(CompositeExtractF16x2, F16, F16x2, U32, )
|
||||
OPCODE(CompositeExtractF16x3, F16, F16x3, U32, )
|
||||
OPCODE(CompositeExtractF16x4, F16, F16x4, U32, )
|
||||
OPCODE(CompositeInsertF16x2, F16x2, F16x2, F16, U32, )
|
||||
OPCODE(CompositeInsertF16x3, F16x3, F16x3, F16, U32, )
|
||||
OPCODE(CompositeInsertF16x4, F16x4, F16x4, F16, U32, )
|
||||
OPCODE(CompositeConstructF32x2, F32x2, F32, F32, )
|
||||
OPCODE(CompositeConstructF32x3, F32x3, F32, F32, F32, )
|
||||
OPCODE(CompositeConstructF32x4, F32x4, F32, F32, F32, F32, )
|
||||
OPCODE(CompositeExtractF32x2, F32, F32x2, U32, )
|
||||
OPCODE(CompositeExtractF32x3, F32, F32x3, U32, )
|
||||
OPCODE(CompositeExtractF32x4, F32, F32x4, U32, )
|
||||
OPCODE(CompositeInsertF32x2, F32x2, F32x2, F32, U32, )
|
||||
OPCODE(CompositeInsertF32x3, F32x3, F32x3, F32, U32, )
|
||||
OPCODE(CompositeInsertF32x4, F32x4, F32x4, F32, U32, )
|
||||
OPCODE(CompositeConstructF64x2, F64x2, F64, F64, )
|
||||
OPCODE(CompositeConstructF64x3, F64x3, F64, F64, F64, )
|
||||
OPCODE(CompositeConstructF64x4, F64x4, F64, F64, F64, F64, )
|
||||
OPCODE(CompositeExtractF64x2, F64, F64x2, U32, )
|
||||
OPCODE(CompositeExtractF64x3, F64, F64x3, U32, )
|
||||
OPCODE(CompositeExtractF64x4, F64, F64x4, U32, )
|
||||
OPCODE(CompositeInsertF64x2, F64x2, F64x2, F64, U32, )
|
||||
OPCODE(CompositeInsertF64x3, F64x3, F64x3, F64, U32, )
|
||||
OPCODE(CompositeInsertF64x4, F64x4, F64x4, F64, U32, )
|
||||
|
||||
// Select operations
|
||||
OPCODE(SelectU1, U1, U1, U1, U1, )
|
||||
OPCODE(SelectU8, U8, U1, U8, U8, )
|
||||
OPCODE(SelectU16, U16, U1, U16, U16, )
|
||||
OPCODE(SelectU32, U32, U1, U32, U32, )
|
||||
OPCODE(SelectU64, U64, U1, U64, U64, )
|
||||
OPCODE(SelectF16, F16, U1, F16, F16, )
|
||||
OPCODE(SelectF32, F32, U1, F32, F32, )
|
||||
OPCODE(SelectF64, F64, U1, F64, F64, )
|
||||
|
||||
// Bitwise conversions
|
||||
OPCODE(BitCastU16F16, U16, F16, )
|
||||
OPCODE(BitCastU32F32, U32, F32, )
|
||||
OPCODE(BitCastU64F64, U64, F64, )
|
||||
OPCODE(BitCastF16U16, F16, U16, )
|
||||
OPCODE(BitCastF32U32, F32, U32, )
|
||||
OPCODE(BitCastF64U64, F64, U64, )
|
||||
OPCODE(PackUint2x32, U64, U32x2, )
|
||||
OPCODE(UnpackUint2x32, U32x2, U64, )
|
||||
OPCODE(PackFloat2x16, U32, F16x2, )
|
||||
OPCODE(UnpackFloat2x16, F16x2, U32, )
|
||||
OPCODE(PackHalf2x16, U32, F32x2, )
|
||||
OPCODE(UnpackHalf2x16, F32x2, U32, )
|
||||
OPCODE(PackDouble2x32, F64, U32x2, )
|
||||
OPCODE(UnpackDouble2x32, U32x2, F64, )
|
||||
|
||||
// Pseudo-operation, handled specially at final emit
|
||||
OPCODE(GetZeroFromOp, U1, Opaque, )
|
||||
OPCODE(GetSignFromOp, U1, Opaque, )
|
||||
OPCODE(GetCarryFromOp, U1, Opaque, )
|
||||
OPCODE(GetOverflowFromOp, U1, Opaque, )
|
||||
OPCODE(GetSparseFromOp, U1, Opaque, )
|
||||
OPCODE(GetInBoundsFromOp, U1, Opaque, )
|
||||
|
||||
// Floating-point operations
|
||||
OPCODE(FPAbs16, F16, F16, )
|
||||
OPCODE(FPAbs32, F32, F32, )
|
||||
OPCODE(FPAbs64, F64, F64, )
|
||||
OPCODE(FPAdd16, F16, F16, F16, )
|
||||
OPCODE(FPAdd32, F32, F32, F32, )
|
||||
OPCODE(FPAdd64, F64, F64, F64, )
|
||||
OPCODE(FPFma16, F16, F16, F16, F16, )
|
||||
OPCODE(FPFma32, F32, F32, F32, F32, )
|
||||
OPCODE(FPFma64, F64, F64, F64, F64, )
|
||||
OPCODE(FPMax32, F32, F32, F32, )
|
||||
OPCODE(FPMax64, F64, F64, F64, )
|
||||
OPCODE(FPMin32, F32, F32, F32, )
|
||||
OPCODE(FPMin64, F64, F64, F64, )
|
||||
OPCODE(FPMul16, F16, F16, F16, )
|
||||
OPCODE(FPMul32, F32, F32, F32, )
|
||||
OPCODE(FPMul64, F64, F64, F64, )
|
||||
OPCODE(FPNeg16, F16, F16, )
|
||||
OPCODE(FPNeg32, F32, F32, )
|
||||
OPCODE(FPNeg64, F64, F64, )
|
||||
OPCODE(FPRecip32, F32, F32, )
|
||||
OPCODE(FPRecip64, F64, F64, )
|
||||
OPCODE(FPRecipSqrt32, F32, F32, )
|
||||
OPCODE(FPRecipSqrt64, F64, F64, )
|
||||
OPCODE(FPSqrt, F32, F32, )
|
||||
OPCODE(FPSin, F32, F32, )
|
||||
OPCODE(FPExp2, F32, F32, )
|
||||
OPCODE(FPCos, F32, F32, )
|
||||
OPCODE(FPLog2, F32, F32, )
|
||||
OPCODE(FPSaturate16, F16, F16, )
|
||||
OPCODE(FPSaturate32, F32, F32, )
|
||||
OPCODE(FPSaturate64, F64, F64, )
|
||||
OPCODE(FPClamp16, F16, F16, F16, F16, )
|
||||
OPCODE(FPClamp32, F32, F32, F32, F32, )
|
||||
OPCODE(FPClamp64, F64, F64, F64, F64, )
|
||||
OPCODE(FPRoundEven16, F16, F16, )
|
||||
OPCODE(FPRoundEven32, F32, F32, )
|
||||
OPCODE(FPRoundEven64, F64, F64, )
|
||||
OPCODE(FPFloor16, F16, F16, )
|
||||
OPCODE(FPFloor32, F32, F32, )
|
||||
OPCODE(FPFloor64, F64, F64, )
|
||||
OPCODE(FPCeil16, F16, F16, )
|
||||
OPCODE(FPCeil32, F32, F32, )
|
||||
OPCODE(FPCeil64, F64, F64, )
|
||||
OPCODE(FPTrunc16, F16, F16, )
|
||||
OPCODE(FPTrunc32, F32, F32, )
|
||||
OPCODE(FPTrunc64, F64, F64, )
|
||||
|
||||
OPCODE(FPOrdEqual16, U1, F16, F16, )
|
||||
OPCODE(FPOrdEqual32, U1, F32, F32, )
|
||||
OPCODE(FPOrdEqual64, U1, F64, F64, )
|
||||
OPCODE(FPUnordEqual16, U1, F16, F16, )
|
||||
OPCODE(FPUnordEqual32, U1, F32, F32, )
|
||||
OPCODE(FPUnordEqual64, U1, F64, F64, )
|
||||
OPCODE(FPOrdNotEqual16, U1, F16, F16, )
|
||||
OPCODE(FPOrdNotEqual32, U1, F32, F32, )
|
||||
OPCODE(FPOrdNotEqual64, U1, F64, F64, )
|
||||
OPCODE(FPUnordNotEqual16, U1, F16, F16, )
|
||||
OPCODE(FPUnordNotEqual32, U1, F32, F32, )
|
||||
OPCODE(FPUnordNotEqual64, U1, F64, F64, )
|
||||
OPCODE(FPOrdLessThan16, U1, F16, F16, )
|
||||
OPCODE(FPOrdLessThan32, U1, F32, F32, )
|
||||
OPCODE(FPOrdLessThan64, U1, F64, F64, )
|
||||
OPCODE(FPUnordLessThan16, U1, F16, F16, )
|
||||
OPCODE(FPUnordLessThan32, U1, F32, F32, )
|
||||
OPCODE(FPUnordLessThan64, U1, F64, F64, )
|
||||
OPCODE(FPOrdGreaterThan16, U1, F16, F16, )
|
||||
OPCODE(FPOrdGreaterThan32, U1, F32, F32, )
|
||||
OPCODE(FPOrdGreaterThan64, U1, F64, F64, )
|
||||
OPCODE(FPUnordGreaterThan16, U1, F16, F16, )
|
||||
OPCODE(FPUnordGreaterThan32, U1, F32, F32, )
|
||||
OPCODE(FPUnordGreaterThan64, U1, F64, F64, )
|
||||
OPCODE(FPOrdLessThanEqual16, U1, F16, F16, )
|
||||
OPCODE(FPOrdLessThanEqual32, U1, F32, F32, )
|
||||
OPCODE(FPOrdLessThanEqual64, U1, F64, F64, )
|
||||
OPCODE(FPUnordLessThanEqual16, U1, F16, F16, )
|
||||
OPCODE(FPUnordLessThanEqual32, U1, F32, F32, )
|
||||
OPCODE(FPUnordLessThanEqual64, U1, F64, F64, )
|
||||
OPCODE(FPOrdGreaterThanEqual16, U1, F16, F16, )
|
||||
OPCODE(FPOrdGreaterThanEqual32, U1, F32, F32, )
|
||||
OPCODE(FPOrdGreaterThanEqual64, U1, F64, F64, )
|
||||
OPCODE(FPUnordGreaterThanEqual16, U1, F16, F16, )
|
||||
OPCODE(FPUnordGreaterThanEqual32, U1, F32, F32, )
|
||||
OPCODE(FPUnordGreaterThanEqual64, U1, F64, F64, )
|
||||
OPCODE(FPIsNan16, U1, F16, )
|
||||
OPCODE(FPIsNan32, U1, F32, )
|
||||
OPCODE(FPIsNan64, U1, F64, )
|
||||
|
||||
// Integer operations
|
||||
OPCODE(IAdd32, U32, U32, U32, )
|
||||
OPCODE(IAdd64, U64, U64, U64, )
|
||||
OPCODE(ISub32, U32, U32, U32, )
|
||||
OPCODE(ISub64, U64, U64, U64, )
|
||||
OPCODE(IMul32, U32, U32, U32, )
|
||||
OPCODE(SDiv32, U32, U32, U32, )
|
||||
OPCODE(UDiv32, U32, U32, U32, )
|
||||
OPCODE(INeg32, U32, U32, )
|
||||
OPCODE(INeg64, U64, U64, )
|
||||
OPCODE(IAbs32, U32, U32, )
|
||||
OPCODE(IAbs64, U64, U64, )
|
||||
OPCODE(ShiftLeftLogical32, U32, U32, U32, )
|
||||
OPCODE(ShiftLeftLogical64, U64, U64, U32, )
|
||||
OPCODE(ShiftRightLogical32, U32, U32, U32, )
|
||||
OPCODE(ShiftRightLogical64, U64, U64, U32, )
|
||||
OPCODE(ShiftRightArithmetic32, U32, U32, U32, )
|
||||
OPCODE(ShiftRightArithmetic64, U64, U64, U32, )
|
||||
OPCODE(BitwiseAnd32, U32, U32, U32, )
|
||||
OPCODE(BitwiseOr32, U32, U32, U32, )
|
||||
OPCODE(BitwiseXor32, U32, U32, U32, )
|
||||
OPCODE(BitFieldInsert, U32, U32, U32, U32, U32, )
|
||||
OPCODE(BitFieldSExtract, U32, U32, U32, U32, )
|
||||
OPCODE(BitFieldUExtract, U32, U32, U32, U32, )
|
||||
OPCODE(BitReverse32, U32, U32, )
|
||||
OPCODE(BitCount32, U32, U32, )
|
||||
OPCODE(BitwiseNot32, U32, U32, )
|
||||
|
||||
OPCODE(FindSMsb32, U32, U32, )
|
||||
OPCODE(FindUMsb32, U32, U32, )
|
||||
OPCODE(SMin32, U32, U32, U32, )
|
||||
OPCODE(UMin32, U32, U32, U32, )
|
||||
OPCODE(SMax32, U32, U32, U32, )
|
||||
OPCODE(UMax32, U32, U32, U32, )
|
||||
OPCODE(SClamp32, U32, U32, U32, U32, )
|
||||
OPCODE(UClamp32, U32, U32, U32, U32, )
|
||||
OPCODE(SLessThan, U1, U32, U32, )
|
||||
OPCODE(ULessThan, U1, U32, U32, )
|
||||
OPCODE(IEqual, U1, U32, U32, )
|
||||
OPCODE(SLessThanEqual, U1, U32, U32, )
|
||||
OPCODE(ULessThanEqual, U1, U32, U32, )
|
||||
OPCODE(SGreaterThan, U1, U32, U32, )
|
||||
OPCODE(UGreaterThan, U1, U32, U32, )
|
||||
OPCODE(INotEqual, U1, U32, U32, )
|
||||
OPCODE(SGreaterThanEqual, U1, U32, U32, )
|
||||
OPCODE(UGreaterThanEqual, U1, U32, U32, )
|
||||
|
||||
// Atomic operations
|
||||
OPCODE(SharedAtomicIAdd32, U32, U32, U32, )
|
||||
OPCODE(SharedAtomicSMin32, U32, U32, U32, )
|
||||
OPCODE(SharedAtomicUMin32, U32, U32, U32, )
|
||||
OPCODE(SharedAtomicSMax32, U32, U32, U32, )
|
||||
OPCODE(SharedAtomicUMax32, U32, U32, U32, )
|
||||
OPCODE(SharedAtomicInc32, U32, U32, U32, )
|
||||
OPCODE(SharedAtomicDec32, U32, U32, U32, )
|
||||
OPCODE(SharedAtomicAnd32, U32, U32, U32, )
|
||||
OPCODE(SharedAtomicOr32, U32, U32, U32, )
|
||||
OPCODE(SharedAtomicXor32, U32, U32, U32, )
|
||||
OPCODE(SharedAtomicExchange32, U32, U32, U32, )
|
||||
OPCODE(SharedAtomicExchange64, U64, U32, U64, )
|
||||
OPCODE(SharedAtomicExchange32x2, U32x2, U32, U32x2, )
|
||||
|
||||
OPCODE(GlobalAtomicIAdd32, U32, U64, U32, )
|
||||
OPCODE(GlobalAtomicSMin32, U32, U64, U32, )
|
||||
OPCODE(GlobalAtomicUMin32, U32, U64, U32, )
|
||||
OPCODE(GlobalAtomicSMax32, U32, U64, U32, )
|
||||
OPCODE(GlobalAtomicUMax32, U32, U64, U32, )
|
||||
OPCODE(GlobalAtomicInc32, U32, U64, U32, )
|
||||
OPCODE(GlobalAtomicDec32, U32, U64, U32, )
|
||||
OPCODE(GlobalAtomicAnd32, U32, U64, U32, )
|
||||
OPCODE(GlobalAtomicOr32, U32, U64, U32, )
|
||||
OPCODE(GlobalAtomicXor32, U32, U64, U32, )
|
||||
OPCODE(GlobalAtomicExchange32, U32, U64, U32, )
|
||||
OPCODE(GlobalAtomicIAdd64, U64, U64, U64, )
|
||||
OPCODE(GlobalAtomicSMin64, U64, U64, U64, )
|
||||
OPCODE(GlobalAtomicUMin64, U64, U64, U64, )
|
||||
OPCODE(GlobalAtomicSMax64, U64, U64, U64, )
|
||||
OPCODE(GlobalAtomicUMax64, U64, U64, U64, )
|
||||
OPCODE(GlobalAtomicAnd64, U64, U64, U64, )
|
||||
OPCODE(GlobalAtomicOr64, U64, U64, U64, )
|
||||
OPCODE(GlobalAtomicXor64, U64, U64, U64, )
|
||||
OPCODE(GlobalAtomicExchange64, U64, U64, U64, )
|
||||
OPCODE(GlobalAtomicIAdd32x2, U32x2, U32x2, U32x2, )
|
||||
OPCODE(GlobalAtomicSMin32x2, U32x2, U32x2, U32x2, )
|
||||
OPCODE(GlobalAtomicUMin32x2, U32x2, U32x2, U32x2, )
|
||||
OPCODE(GlobalAtomicSMax32x2, U32x2, U32x2, U32x2, )
|
||||
OPCODE(GlobalAtomicUMax32x2, U32x2, U32x2, U32x2, )
|
||||
OPCODE(GlobalAtomicAnd32x2, U32x2, U32x2, U32x2, )
|
||||
OPCODE(GlobalAtomicOr32x2, U32x2, U32x2, U32x2, )
|
||||
OPCODE(GlobalAtomicXor32x2, U32x2, U32x2, U32x2, )
|
||||
OPCODE(GlobalAtomicExchange32x2, U32x2, U32x2, U32x2, )
|
||||
OPCODE(GlobalAtomicAddF32, F32, U64, F32, )
|
||||
OPCODE(GlobalAtomicAddF16x2, U32, U64, F16x2, )
|
||||
OPCODE(GlobalAtomicAddF32x2, U32, U64, F32x2, )
|
||||
OPCODE(GlobalAtomicMinF16x2, U32, U64, F16x2, )
|
||||
OPCODE(GlobalAtomicMinF32x2, U32, U64, F32x2, )
|
||||
OPCODE(GlobalAtomicMaxF16x2, U32, U64, F16x2, )
|
||||
OPCODE(GlobalAtomicMaxF32x2, U32, U64, F32x2, )
|
||||
|
||||
OPCODE(StorageAtomicIAdd32, U32, U32, U32, U32, )
|
||||
OPCODE(StorageAtomicSMin32, U32, U32, U32, U32, )
|
||||
OPCODE(StorageAtomicUMin32, U32, U32, U32, U32, )
|
||||
OPCODE(StorageAtomicSMax32, U32, U32, U32, U32, )
|
||||
OPCODE(StorageAtomicUMax32, U32, U32, U32, U32, )
|
||||
OPCODE(StorageAtomicInc32, U32, U32, U32, U32, )
|
||||
OPCODE(StorageAtomicDec32, U32, U32, U32, U32, )
|
||||
OPCODE(StorageAtomicAnd32, U32, U32, U32, U32, )
|
||||
OPCODE(StorageAtomicOr32, U32, U32, U32, U32, )
|
||||
OPCODE(StorageAtomicXor32, U32, U32, U32, U32, )
|
||||
OPCODE(StorageAtomicExchange32, U32, U32, U32, U32, )
|
||||
OPCODE(StorageAtomicIAdd64, U64, U32, U32, U64, )
|
||||
OPCODE(StorageAtomicSMin64, U64, U32, U32, U64, )
|
||||
OPCODE(StorageAtomicUMin64, U64, U32, U32, U64, )
|
||||
OPCODE(StorageAtomicSMax64, U64, U32, U32, U64, )
|
||||
OPCODE(StorageAtomicUMax64, U64, U32, U32, U64, )
|
||||
OPCODE(StorageAtomicAnd64, U64, U32, U32, U64, )
|
||||
OPCODE(StorageAtomicOr64, U64, U32, U32, U64, )
|
||||
OPCODE(StorageAtomicXor64, U64, U32, U32, U64, )
|
||||
OPCODE(StorageAtomicExchange64, U64, U32, U32, U64, )
|
||||
OPCODE(StorageAtomicIAdd32x2, U32x2, U32, U32, U32x2, )
|
||||
OPCODE(StorageAtomicSMin32x2, U32x2, U32, U32, U32x2, )
|
||||
OPCODE(StorageAtomicUMin32x2, U32x2, U32, U32, U32x2, )
|
||||
OPCODE(StorageAtomicSMax32x2, U32x2, U32, U32, U32x2, )
|
||||
OPCODE(StorageAtomicUMax32x2, U32x2, U32, U32, U32x2, )
|
||||
OPCODE(StorageAtomicAnd32x2, U32x2, U32, U32, U32x2, )
|
||||
OPCODE(StorageAtomicOr32x2, U32x2, U32, U32, U32x2, )
|
||||
OPCODE(StorageAtomicXor32x2, U32x2, U32, U32, U32x2, )
|
||||
OPCODE(StorageAtomicExchange32x2, U32x2, U32, U32, U32x2, )
|
||||
OPCODE(StorageAtomicAddF32, F32, U32, U32, F32, )
|
||||
OPCODE(StorageAtomicAddF16x2, U32, U32, U32, F16x2, )
|
||||
OPCODE(StorageAtomicAddF32x2, U32, U32, U32, F32x2, )
|
||||
OPCODE(StorageAtomicMinF16x2, U32, U32, U32, F16x2, )
|
||||
OPCODE(StorageAtomicMinF32x2, U32, U32, U32, F32x2, )
|
||||
OPCODE(StorageAtomicMaxF16x2, U32, U32, U32, F16x2, )
|
||||
OPCODE(StorageAtomicMaxF32x2, U32, U32, U32, F32x2, )
|
||||
|
||||
// Logical operations
|
||||
OPCODE(LogicalOr, U1, U1, U1, )
|
||||
OPCODE(LogicalAnd, U1, U1, U1, )
|
||||
OPCODE(LogicalXor, U1, U1, U1, )
|
||||
OPCODE(LogicalNot, U1, U1, )
|
||||
|
||||
// Conversion operations
|
||||
OPCODE(ConvertS16F16, U32, F16, )
|
||||
OPCODE(ConvertS16F32, U32, F32, )
|
||||
OPCODE(ConvertS16F64, U32, F64, )
|
||||
OPCODE(ConvertS32F16, U32, F16, )
|
||||
OPCODE(ConvertS32F32, U32, F32, )
|
||||
OPCODE(ConvertS32F64, U32, F64, )
|
||||
OPCODE(ConvertS64F16, U64, F16, )
|
||||
OPCODE(ConvertS64F32, U64, F32, )
|
||||
OPCODE(ConvertS64F64, U64, F64, )
|
||||
OPCODE(ConvertU16F16, U32, F16, )
|
||||
OPCODE(ConvertU16F32, U32, F32, )
|
||||
OPCODE(ConvertU16F64, U32, F64, )
|
||||
OPCODE(ConvertU32F16, U32, F16, )
|
||||
OPCODE(ConvertU32F32, U32, F32, )
|
||||
OPCODE(ConvertU32F64, U32, F64, )
|
||||
OPCODE(ConvertU64F16, U64, F16, )
|
||||
OPCODE(ConvertU64F32, U64, F32, )
|
||||
OPCODE(ConvertU64F64, U64, F64, )
|
||||
OPCODE(ConvertU64U32, U64, U32, )
|
||||
OPCODE(ConvertU32U64, U32, U64, )
|
||||
OPCODE(ConvertF16F32, F16, F32, )
|
||||
OPCODE(ConvertF32F16, F32, F16, )
|
||||
OPCODE(ConvertF32F64, F32, F64, )
|
||||
OPCODE(ConvertF64F32, F64, F32, )
|
||||
OPCODE(ConvertF16S8, F16, U32, )
|
||||
OPCODE(ConvertF16S16, F16, U32, )
|
||||
OPCODE(ConvertF16S32, F16, U32, )
|
||||
OPCODE(ConvertF16S64, F16, U64, )
|
||||
OPCODE(ConvertF16U8, F16, U32, )
|
||||
OPCODE(ConvertF16U16, F16, U32, )
|
||||
OPCODE(ConvertF16U32, F16, U32, )
|
||||
OPCODE(ConvertF16U64, F16, U64, )
|
||||
OPCODE(ConvertF32S8, F32, U32, )
|
||||
OPCODE(ConvertF32S16, F32, U32, )
|
||||
OPCODE(ConvertF32S32, F32, U32, )
|
||||
OPCODE(ConvertF32S64, F32, U64, )
|
||||
OPCODE(ConvertF32U8, F32, U32, )
|
||||
OPCODE(ConvertF32U16, F32, U32, )
|
||||
OPCODE(ConvertF32U32, F32, U32, )
|
||||
OPCODE(ConvertF32U64, F32, U64, )
|
||||
OPCODE(ConvertF64S8, F64, U32, )
|
||||
OPCODE(ConvertF64S16, F64, U32, )
|
||||
OPCODE(ConvertF64S32, F64, U32, )
|
||||
OPCODE(ConvertF64S64, F64, U64, )
|
||||
OPCODE(ConvertF64U8, F64, U32, )
|
||||
OPCODE(ConvertF64U16, F64, U32, )
|
||||
OPCODE(ConvertF64U32, F64, U32, )
|
||||
OPCODE(ConvertF64U64, F64, U64, )
|
||||
OPCODE(ConvertU16U32, U16, U32, )
|
||||
OPCODE(ConvertU32U16, U32, U16, )
|
||||
OPCODE(ConvertU8U32, U8, U32, )
|
||||
OPCODE(ConvertU32U8, U32, U8, )
|
||||
OPCODE(ConvertS32S8, U32, U8, )
|
||||
OPCODE(ConvertS32S16, U32, U16, )
|
||||
|
||||
// Image operations
|
||||
OPCODE(BindlessImageSampleImplicitLod, F32x4, U32, Opaque, Opaque, Opaque, )
|
||||
OPCODE(BindlessImageSampleExplicitLod, F32x4, U32, Opaque, Opaque, Opaque, )
|
||||
OPCODE(BindlessImageSampleDrefImplicitLod, F32, U32, Opaque, F32, Opaque, Opaque, )
|
||||
OPCODE(BindlessImageSampleDrefExplicitLod, F32, U32, Opaque, F32, Opaque, Opaque, )
|
||||
OPCODE(BindlessImageGather, F32x4, U32, Opaque, Opaque, Opaque, )
|
||||
OPCODE(BindlessImageGatherDref, F32x4, U32, Opaque, Opaque, Opaque, F32, )
|
||||
OPCODE(BindlessImageFetch, F32x4, U32, Opaque, Opaque, U32, Opaque, )
|
||||
OPCODE(BindlessImageQueryDimensions, U32x4, U32, U32, U1, )
|
||||
OPCODE(BindlessImageQueryLod, F32x4, U32, Opaque, )
|
||||
OPCODE(BindlessImageGradient, F32x4, U32, Opaque, Opaque, Opaque, Opaque, )
|
||||
OPCODE(BindlessImageRead, U32x4, U32, Opaque, )
|
||||
OPCODE(BindlessImageWrite, Void, U32, Opaque, U32x4, )
|
||||
|
||||
OPCODE(BoundImageSampleImplicitLod, F32x4, U32, Opaque, Opaque, Opaque, )
|
||||
OPCODE(BoundImageSampleExplicitLod, F32x4, U32, Opaque, Opaque, Opaque, )
|
||||
OPCODE(BoundImageSampleDrefImplicitLod, F32, U32, Opaque, F32, Opaque, Opaque, )
|
||||
OPCODE(BoundImageSampleDrefExplicitLod, F32, U32, Opaque, F32, Opaque, Opaque, )
|
||||
OPCODE(BoundImageGather, F32x4, U32, Opaque, Opaque, Opaque, )
|
||||
OPCODE(BoundImageGatherDref, F32x4, U32, Opaque, Opaque, Opaque, F32, )
|
||||
OPCODE(BoundImageFetch, F32x4, U32, Opaque, Opaque, U32, Opaque, )
|
||||
OPCODE(BoundImageQueryDimensions, U32x4, U32, U32, U1, )
|
||||
OPCODE(BoundImageQueryLod, F32x4, U32, Opaque, )
|
||||
OPCODE(BoundImageGradient, F32x4, U32, Opaque, Opaque, Opaque, Opaque, )
|
||||
OPCODE(BoundImageRead, U32x4, U32, Opaque, )
|
||||
OPCODE(BoundImageWrite, Void, U32, Opaque, U32x4, )
|
||||
|
||||
OPCODE(ImageSampleImplicitLod, F32x4, Opaque, Opaque, Opaque, Opaque, )
|
||||
OPCODE(ImageSampleExplicitLod, F32x4, Opaque, Opaque, Opaque, Opaque, )
|
||||
OPCODE(ImageSampleDrefImplicitLod, F32, Opaque, Opaque, F32, Opaque, Opaque, )
|
||||
OPCODE(ImageSampleDrefExplicitLod, F32, Opaque, Opaque, F32, Opaque, Opaque, )
|
||||
OPCODE(ImageGather, F32x4, Opaque, Opaque, Opaque, Opaque, )
|
||||
OPCODE(ImageGatherDref, F32x4, Opaque, Opaque, Opaque, Opaque, F32, )
|
||||
OPCODE(ImageFetch, F32x4, Opaque, Opaque, Opaque, U32, Opaque, )
|
||||
OPCODE(ImageQueryDimensions, U32x4, Opaque, U32, U1, )
|
||||
OPCODE(ImageQueryLod, F32x4, Opaque, Opaque, )
|
||||
OPCODE(ImageGradient, F32x4, Opaque, Opaque, Opaque, Opaque, Opaque, )
|
||||
OPCODE(ImageRead, U32x4, Opaque, Opaque, )
|
||||
OPCODE(ImageWrite, Void, Opaque, Opaque, U32x4, )
|
||||
|
||||
OPCODE(IsTextureScaled, U1, U32, )
|
||||
OPCODE(IsImageScaled, U1, U32, )
|
||||
|
||||
// Atomic Image operations
|
||||
|
||||
OPCODE(BindlessImageAtomicIAdd32, U32, U32, Opaque, U32, )
|
||||
OPCODE(BindlessImageAtomicSMin32, U32, U32, Opaque, U32, )
|
||||
OPCODE(BindlessImageAtomicUMin32, U32, U32, Opaque, U32, )
|
||||
OPCODE(BindlessImageAtomicSMax32, U32, U32, Opaque, U32, )
|
||||
OPCODE(BindlessImageAtomicUMax32, U32, U32, Opaque, U32, )
|
||||
OPCODE(BindlessImageAtomicInc32, U32, U32, Opaque, U32, )
|
||||
OPCODE(BindlessImageAtomicDec32, U32, U32, Opaque, U32, )
|
||||
OPCODE(BindlessImageAtomicAnd32, U32, U32, Opaque, U32, )
|
||||
OPCODE(BindlessImageAtomicOr32, U32, U32, Opaque, U32, )
|
||||
OPCODE(BindlessImageAtomicXor32, U32, U32, Opaque, U32, )
|
||||
OPCODE(BindlessImageAtomicExchange32, U32, U32, Opaque, U32, )
|
||||
|
||||
OPCODE(BoundImageAtomicIAdd32, U32, U32, Opaque, U32, )
|
||||
OPCODE(BoundImageAtomicSMin32, U32, U32, Opaque, U32, )
|
||||
OPCODE(BoundImageAtomicUMin32, U32, U32, Opaque, U32, )
|
||||
OPCODE(BoundImageAtomicSMax32, U32, U32, Opaque, U32, )
|
||||
OPCODE(BoundImageAtomicUMax32, U32, U32, Opaque, U32, )
|
||||
OPCODE(BoundImageAtomicInc32, U32, U32, Opaque, U32, )
|
||||
OPCODE(BoundImageAtomicDec32, U32, U32, Opaque, U32, )
|
||||
OPCODE(BoundImageAtomicAnd32, U32, U32, Opaque, U32, )
|
||||
OPCODE(BoundImageAtomicOr32, U32, U32, Opaque, U32, )
|
||||
OPCODE(BoundImageAtomicXor32, U32, U32, Opaque, U32, )
|
||||
OPCODE(BoundImageAtomicExchange32, U32, U32, Opaque, U32, )
|
||||
|
||||
OPCODE(ImageAtomicIAdd32, U32, Opaque, Opaque, U32, )
|
||||
OPCODE(ImageAtomicSMin32, U32, Opaque, Opaque, U32, )
|
||||
OPCODE(ImageAtomicUMin32, U32, Opaque, Opaque, U32, )
|
||||
OPCODE(ImageAtomicSMax32, U32, Opaque, Opaque, U32, )
|
||||
OPCODE(ImageAtomicUMax32, U32, Opaque, Opaque, U32, )
|
||||
OPCODE(ImageAtomicInc32, U32, Opaque, Opaque, U32, )
|
||||
OPCODE(ImageAtomicDec32, U32, Opaque, Opaque, U32, )
|
||||
OPCODE(ImageAtomicAnd32, U32, Opaque, Opaque, U32, )
|
||||
OPCODE(ImageAtomicOr32, U32, Opaque, Opaque, U32, )
|
||||
OPCODE(ImageAtomicXor32, U32, Opaque, Opaque, U32, )
|
||||
OPCODE(ImageAtomicExchange32, U32, Opaque, Opaque, U32, )
|
||||
|
||||
// Warp operations
|
||||
OPCODE(LaneId, U32, )
|
||||
OPCODE(VoteAll, U1, U1, )
|
||||
OPCODE(VoteAny, U1, U1, )
|
||||
OPCODE(VoteEqual, U1, U1, )
|
||||
OPCODE(SubgroupBallot, U32, U1, )
|
||||
OPCODE(SubgroupEqMask, U32, )
|
||||
OPCODE(SubgroupLtMask, U32, )
|
||||
OPCODE(SubgroupLeMask, U32, )
|
||||
OPCODE(SubgroupGtMask, U32, )
|
||||
OPCODE(SubgroupGeMask, U32, )
|
||||
OPCODE(ShuffleIndex, U32, U32, U32, U32, U32, )
|
||||
OPCODE(ShuffleUp, U32, U32, U32, U32, U32, )
|
||||
OPCODE(ShuffleDown, U32, U32, U32, U32, U32, )
|
||||
OPCODE(ShuffleButterfly, U32, U32, U32, U32, U32, )
|
||||
OPCODE(FSwizzleAdd, F32, F32, F32, U32, )
|
||||
OPCODE(DPdxFine, F32, F32, )
|
||||
OPCODE(DPdyFine, F32, F32, )
|
||||
OPCODE(DPdxCoarse, F32, F32, )
|
||||
OPCODE(DPdyCoarse, F32, F32, )
|
||||
27
gpu/third_party/suyu/shader_recompiler/frontend/ir/patch.cpp
vendored
Normal file
27
gpu/third_party/suyu/shader_recompiler/frontend/ir/patch.cpp
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "shader_recompiler/exception.h"
|
||||
#include "shader_recompiler/frontend/ir/patch.h"
|
||||
|
||||
namespace Shader::IR {
|
||||
|
||||
bool IsGeneric(Patch patch) noexcept {
|
||||
return patch >= Patch::Component0 && patch <= Patch::Component119;
|
||||
}
|
||||
|
||||
u32 GenericPatchIndex(Patch patch) {
|
||||
if (!IsGeneric(patch)) {
|
||||
throw InvalidArgument("Patch {} is not generic", patch);
|
||||
}
|
||||
return (static_cast<u32>(patch) - static_cast<u32>(Patch::Component0)) / 4;
|
||||
}
|
||||
|
||||
u32 GenericPatchElement(Patch patch) {
|
||||
if (!IsGeneric(patch)) {
|
||||
throw InvalidArgument("Patch {} is not generic", patch);
|
||||
}
|
||||
return (static_cast<u32>(patch) - static_cast<u32>(Patch::Component0)) % 4;
|
||||
}
|
||||
|
||||
} // namespace Shader::IR
|
||||
146
gpu/third_party/suyu/shader_recompiler/frontend/ir/patch.h
vendored
Normal file
146
gpu/third_party/suyu/shader_recompiler/frontend/ir/patch.h
vendored
Normal file
@@ -0,0 +1,146 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/common_types.h"
|
||||
|
||||
namespace Shader::IR {
|
||||
|
||||
enum class Patch : u64 {
|
||||
TessellationLodLeft,
|
||||
TessellationLodTop,
|
||||
TessellationLodRight,
|
||||
TessellationLodBottom,
|
||||
TessellationLodInteriorU,
|
||||
TessellationLodInteriorV,
|
||||
Component0,
|
||||
Component1,
|
||||
Component2,
|
||||
Component3,
|
||||
Component4,
|
||||
Component5,
|
||||
Component6,
|
||||
Component7,
|
||||
Component8,
|
||||
Component9,
|
||||
Component10,
|
||||
Component11,
|
||||
Component12,
|
||||
Component13,
|
||||
Component14,
|
||||
Component15,
|
||||
Component16,
|
||||
Component17,
|
||||
Component18,
|
||||
Component19,
|
||||
Component20,
|
||||
Component21,
|
||||
Component22,
|
||||
Component23,
|
||||
Component24,
|
||||
Component25,
|
||||
Component26,
|
||||
Component27,
|
||||
Component28,
|
||||
Component29,
|
||||
Component30,
|
||||
Component31,
|
||||
Component32,
|
||||
Component33,
|
||||
Component34,
|
||||
Component35,
|
||||
Component36,
|
||||
Component37,
|
||||
Component38,
|
||||
Component39,
|
||||
Component40,
|
||||
Component41,
|
||||
Component42,
|
||||
Component43,
|
||||
Component44,
|
||||
Component45,
|
||||
Component46,
|
||||
Component47,
|
||||
Component48,
|
||||
Component49,
|
||||
Component50,
|
||||
Component51,
|
||||
Component52,
|
||||
Component53,
|
||||
Component54,
|
||||
Component55,
|
||||
Component56,
|
||||
Component57,
|
||||
Component58,
|
||||
Component59,
|
||||
Component60,
|
||||
Component61,
|
||||
Component62,
|
||||
Component63,
|
||||
Component64,
|
||||
Component65,
|
||||
Component66,
|
||||
Component67,
|
||||
Component68,
|
||||
Component69,
|
||||
Component70,
|
||||
Component71,
|
||||
Component72,
|
||||
Component73,
|
||||
Component74,
|
||||
Component75,
|
||||
Component76,
|
||||
Component77,
|
||||
Component78,
|
||||
Component79,
|
||||
Component80,
|
||||
Component81,
|
||||
Component82,
|
||||
Component83,
|
||||
Component84,
|
||||
Component85,
|
||||
Component86,
|
||||
Component87,
|
||||
Component88,
|
||||
Component89,
|
||||
Component90,
|
||||
Component91,
|
||||
Component92,
|
||||
Component93,
|
||||
Component94,
|
||||
Component95,
|
||||
Component96,
|
||||
Component97,
|
||||
Component98,
|
||||
Component99,
|
||||
Component100,
|
||||
Component101,
|
||||
Component102,
|
||||
Component103,
|
||||
Component104,
|
||||
Component105,
|
||||
Component106,
|
||||
Component107,
|
||||
Component108,
|
||||
Component109,
|
||||
Component110,
|
||||
Component111,
|
||||
Component112,
|
||||
Component113,
|
||||
Component114,
|
||||
Component115,
|
||||
Component116,
|
||||
Component117,
|
||||
Component118,
|
||||
Component119,
|
||||
};
|
||||
static_assert(static_cast<u64>(Patch::Component119) == 125);
|
||||
|
||||
[[nodiscard]] bool IsGeneric(Patch patch) noexcept;
|
||||
|
||||
[[nodiscard]] u32 GenericPatchIndex(Patch patch);
|
||||
|
||||
[[nodiscard]] u32 GenericPatchElement(Patch patch);
|
||||
|
||||
} // namespace Shader::IR
|
||||
45
gpu/third_party/suyu/shader_recompiler/frontend/ir/post_order.cpp
vendored
Normal file
45
gpu/third_party/suyu/shader_recompiler/frontend/ir/post_order.cpp
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include <boost/container/flat_set.hpp>
|
||||
#include <boost/container/small_vector.hpp>
|
||||
|
||||
#include "shader_recompiler/frontend/ir/basic_block.h"
|
||||
#include "shader_recompiler/frontend/ir/post_order.h"
|
||||
|
||||
namespace Shader::IR {
|
||||
|
||||
BlockList PostOrder(const AbstractSyntaxNode& root) {
|
||||
boost::container::small_vector<Block*, 16> block_stack;
|
||||
boost::container::flat_set<Block*> visited;
|
||||
BlockList post_order_blocks;
|
||||
|
||||
if (root.type != AbstractSyntaxNode::Type::Block) {
|
||||
throw LogicError("First node in abstract syntax list root is not a block");
|
||||
}
|
||||
Block* const first_block{root.data.block};
|
||||
visited.insert(first_block);
|
||||
block_stack.push_back(first_block);
|
||||
|
||||
while (!block_stack.empty()) {
|
||||
Block* const block{block_stack.back()};
|
||||
const auto visit{[&](Block* branch) {
|
||||
if (!visited.insert(branch).second) {
|
||||
return false;
|
||||
}
|
||||
// Calling push_back twice is faster than insert on MSVC
|
||||
block_stack.push_back(block);
|
||||
block_stack.push_back(branch);
|
||||
return true;
|
||||
}};
|
||||
block_stack.pop_back();
|
||||
if (std::ranges::none_of(block->ImmSuccessors(), visit)) {
|
||||
post_order_blocks.push_back(block);
|
||||
}
|
||||
}
|
||||
return post_order_blocks;
|
||||
}
|
||||
|
||||
} // namespace Shader::IR
|
||||
13
gpu/third_party/suyu/shader_recompiler/frontend/ir/post_order.h
vendored
Normal file
13
gpu/third_party/suyu/shader_recompiler/frontend/ir/post_order.h
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "shader_recompiler/frontend/ir/abstract_syntax_list.h"
|
||||
#include "shader_recompiler/frontend/ir/basic_block.h"
|
||||
|
||||
namespace Shader::IR {
|
||||
|
||||
BlockList PostOrder(const AbstractSyntaxNode& root);
|
||||
|
||||
} // namespace Shader::IR
|
||||
43
gpu/third_party/suyu/shader_recompiler/frontend/ir/pred.h
vendored
Normal file
43
gpu/third_party/suyu/shader_recompiler/frontend/ir/pred.h
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <fmt/ranges.h>
|
||||
|
||||
namespace Shader::IR {
|
||||
|
||||
enum class Pred : u64 {
|
||||
P0,
|
||||
P1,
|
||||
P2,
|
||||
P3,
|
||||
P4,
|
||||
P5,
|
||||
P6,
|
||||
PT,
|
||||
};
|
||||
|
||||
constexpr size_t NUM_USER_PREDS = 7;
|
||||
constexpr size_t NUM_PREDS = 8;
|
||||
|
||||
[[nodiscard]] constexpr size_t PredIndex(Pred pred) noexcept {
|
||||
return static_cast<size_t>(pred);
|
||||
}
|
||||
|
||||
} // namespace Shader::IR
|
||||
|
||||
template <>
|
||||
struct fmt::formatter<Shader::IR::Pred> {
|
||||
constexpr auto parse(format_parse_context& ctx) {
|
||||
return ctx.begin();
|
||||
}
|
||||
template <typename FormatContext>
|
||||
auto format(const Shader::IR::Pred& pred, FormatContext& ctx) const {
|
||||
if (pred == Shader::IR::Pred::PT) {
|
||||
return fmt::format_to(ctx.out(), "PT");
|
||||
} else {
|
||||
return fmt::format_to(ctx.out(), "P{}", static_cast<int>(pred));
|
||||
}
|
||||
}
|
||||
};
|
||||
31
gpu/third_party/suyu/shader_recompiler/frontend/ir/program.cpp
vendored
Normal file
31
gpu/third_party/suyu/shader_recompiler/frontend/ir/program.cpp
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include <fmt/ranges.h>
|
||||
|
||||
#include "shader_recompiler/frontend/ir/basic_block.h"
|
||||
#include "shader_recompiler/frontend/ir/program.h"
|
||||
#include "shader_recompiler/frontend/ir/value.h"
|
||||
|
||||
namespace Shader::IR {
|
||||
|
||||
std::string DumpProgram(const Program& program) {
|
||||
size_t index{0};
|
||||
std::map<const IR::Inst*, size_t> inst_to_index;
|
||||
std::map<const IR::Block*, size_t> block_to_index;
|
||||
|
||||
for (const IR::Block* const block : program.blocks) {
|
||||
block_to_index.emplace(block, index);
|
||||
++index;
|
||||
}
|
||||
std::string ret;
|
||||
for (const auto& block : program.blocks) {
|
||||
ret += IR::DumpBlock(*block, block_to_index, inst_to_index, index) + '\n';
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
} // namespace Shader::IR
|
||||
34
gpu/third_party/suyu/shader_recompiler/frontend/ir/program.h
vendored
Normal file
34
gpu/third_party/suyu/shader_recompiler/frontend/ir/program.h
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <string>
|
||||
|
||||
#include "shader_recompiler/frontend/ir/abstract_syntax_list.h"
|
||||
#include "shader_recompiler/frontend/ir/basic_block.h"
|
||||
#include "shader_recompiler/program_header.h"
|
||||
#include "shader_recompiler/shader_info.h"
|
||||
#include "shader_recompiler/stage.h"
|
||||
|
||||
namespace Shader::IR {
|
||||
|
||||
struct Program {
|
||||
AbstractSyntaxList syntax_list;
|
||||
BlockList blocks;
|
||||
BlockList post_order_blocks;
|
||||
Info info;
|
||||
Stage stage{};
|
||||
std::array<u32, 3> workgroup_size{};
|
||||
OutputTopology output_topology{};
|
||||
u32 output_vertices{};
|
||||
u32 invocations{};
|
||||
u32 local_memory_size{};
|
||||
u32 shared_memory_size{};
|
||||
bool is_geometry_passthrough{};
|
||||
};
|
||||
|
||||
[[nodiscard]] std::string DumpProgram(const Program& program);
|
||||
|
||||
} // namespace Shader::IR
|
||||
331
gpu/third_party/suyu/shader_recompiler/frontend/ir/reg.h
vendored
Normal file
331
gpu/third_party/suyu/shader_recompiler/frontend/ir/reg.h
vendored
Normal file
@@ -0,0 +1,331 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <fmt/ranges.h>
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "shader_recompiler/exception.h"
|
||||
|
||||
namespace Shader::IR {
|
||||
|
||||
enum class Reg : u64 {
|
||||
R0,
|
||||
R1,
|
||||
R2,
|
||||
R3,
|
||||
R4,
|
||||
R5,
|
||||
R6,
|
||||
R7,
|
||||
R8,
|
||||
R9,
|
||||
R10,
|
||||
R11,
|
||||
R12,
|
||||
R13,
|
||||
R14,
|
||||
R15,
|
||||
R16,
|
||||
R17,
|
||||
R18,
|
||||
R19,
|
||||
R20,
|
||||
R21,
|
||||
R22,
|
||||
R23,
|
||||
R24,
|
||||
R25,
|
||||
R26,
|
||||
R27,
|
||||
R28,
|
||||
R29,
|
||||
R30,
|
||||
R31,
|
||||
R32,
|
||||
R33,
|
||||
R34,
|
||||
R35,
|
||||
R36,
|
||||
R37,
|
||||
R38,
|
||||
R39,
|
||||
R40,
|
||||
R41,
|
||||
R42,
|
||||
R43,
|
||||
R44,
|
||||
R45,
|
||||
R46,
|
||||
R47,
|
||||
R48,
|
||||
R49,
|
||||
R50,
|
||||
R51,
|
||||
R52,
|
||||
R53,
|
||||
R54,
|
||||
R55,
|
||||
R56,
|
||||
R57,
|
||||
R58,
|
||||
R59,
|
||||
R60,
|
||||
R61,
|
||||
R62,
|
||||
R63,
|
||||
R64,
|
||||
R65,
|
||||
R66,
|
||||
R67,
|
||||
R68,
|
||||
R69,
|
||||
R70,
|
||||
R71,
|
||||
R72,
|
||||
R73,
|
||||
R74,
|
||||
R75,
|
||||
R76,
|
||||
R77,
|
||||
R78,
|
||||
R79,
|
||||
R80,
|
||||
R81,
|
||||
R82,
|
||||
R83,
|
||||
R84,
|
||||
R85,
|
||||
R86,
|
||||
R87,
|
||||
R88,
|
||||
R89,
|
||||
R90,
|
||||
R91,
|
||||
R92,
|
||||
R93,
|
||||
R94,
|
||||
R95,
|
||||
R96,
|
||||
R97,
|
||||
R98,
|
||||
R99,
|
||||
R100,
|
||||
R101,
|
||||
R102,
|
||||
R103,
|
||||
R104,
|
||||
R105,
|
||||
R106,
|
||||
R107,
|
||||
R108,
|
||||
R109,
|
||||
R110,
|
||||
R111,
|
||||
R112,
|
||||
R113,
|
||||
R114,
|
||||
R115,
|
||||
R116,
|
||||
R117,
|
||||
R118,
|
||||
R119,
|
||||
R120,
|
||||
R121,
|
||||
R122,
|
||||
R123,
|
||||
R124,
|
||||
R125,
|
||||
R126,
|
||||
R127,
|
||||
R128,
|
||||
R129,
|
||||
R130,
|
||||
R131,
|
||||
R132,
|
||||
R133,
|
||||
R134,
|
||||
R135,
|
||||
R136,
|
||||
R137,
|
||||
R138,
|
||||
R139,
|
||||
R140,
|
||||
R141,
|
||||
R142,
|
||||
R143,
|
||||
R144,
|
||||
R145,
|
||||
R146,
|
||||
R147,
|
||||
R148,
|
||||
R149,
|
||||
R150,
|
||||
R151,
|
||||
R152,
|
||||
R153,
|
||||
R154,
|
||||
R155,
|
||||
R156,
|
||||
R157,
|
||||
R158,
|
||||
R159,
|
||||
R160,
|
||||
R161,
|
||||
R162,
|
||||
R163,
|
||||
R164,
|
||||
R165,
|
||||
R166,
|
||||
R167,
|
||||
R168,
|
||||
R169,
|
||||
R170,
|
||||
R171,
|
||||
R172,
|
||||
R173,
|
||||
R174,
|
||||
R175,
|
||||
R176,
|
||||
R177,
|
||||
R178,
|
||||
R179,
|
||||
R180,
|
||||
R181,
|
||||
R182,
|
||||
R183,
|
||||
R184,
|
||||
R185,
|
||||
R186,
|
||||
R187,
|
||||
R188,
|
||||
R189,
|
||||
R190,
|
||||
R191,
|
||||
R192,
|
||||
R193,
|
||||
R194,
|
||||
R195,
|
||||
R196,
|
||||
R197,
|
||||
R198,
|
||||
R199,
|
||||
R200,
|
||||
R201,
|
||||
R202,
|
||||
R203,
|
||||
R204,
|
||||
R205,
|
||||
R206,
|
||||
R207,
|
||||
R208,
|
||||
R209,
|
||||
R210,
|
||||
R211,
|
||||
R212,
|
||||
R213,
|
||||
R214,
|
||||
R215,
|
||||
R216,
|
||||
R217,
|
||||
R218,
|
||||
R219,
|
||||
R220,
|
||||
R221,
|
||||
R222,
|
||||
R223,
|
||||
R224,
|
||||
R225,
|
||||
R226,
|
||||
R227,
|
||||
R228,
|
||||
R229,
|
||||
R230,
|
||||
R231,
|
||||
R232,
|
||||
R233,
|
||||
R234,
|
||||
R235,
|
||||
R236,
|
||||
R237,
|
||||
R238,
|
||||
R239,
|
||||
R240,
|
||||
R241,
|
||||
R242,
|
||||
R243,
|
||||
R244,
|
||||
R245,
|
||||
R246,
|
||||
R247,
|
||||
R248,
|
||||
R249,
|
||||
R250,
|
||||
R251,
|
||||
R252,
|
||||
R253,
|
||||
R254,
|
||||
RZ,
|
||||
};
|
||||
static_assert(static_cast<int>(Reg::RZ) == 255);
|
||||
|
||||
constexpr size_t NUM_USER_REGS = 255;
|
||||
constexpr size_t NUM_REGS = 256;
|
||||
|
||||
[[nodiscard]] constexpr Reg operator+(Reg reg, int num) {
|
||||
if (reg == Reg::RZ) {
|
||||
// Adding or subtracting registers from RZ yields RZ
|
||||
return Reg::RZ;
|
||||
}
|
||||
const int result{static_cast<int>(reg) + num};
|
||||
if (result >= static_cast<int>(Reg::RZ)) {
|
||||
throw LogicError("Overflow on register arithmetic");
|
||||
}
|
||||
if (result < 0) {
|
||||
throw LogicError("Underflow on register arithmetic");
|
||||
}
|
||||
return static_cast<Reg>(result);
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr Reg operator-(Reg reg, int num) {
|
||||
return reg + (-num);
|
||||
}
|
||||
|
||||
constexpr Reg operator++(Reg& reg) {
|
||||
reg = reg + 1;
|
||||
return reg;
|
||||
}
|
||||
|
||||
constexpr Reg operator++(Reg& reg, int) {
|
||||
const Reg copy{reg};
|
||||
reg = reg + 1;
|
||||
return copy;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr size_t RegIndex(Reg reg) noexcept {
|
||||
return static_cast<size_t>(reg);
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr bool IsAligned(Reg reg, size_t align) {
|
||||
return RegIndex(reg) % align == 0 || reg == Reg::RZ;
|
||||
}
|
||||
|
||||
} // namespace Shader::IR
|
||||
|
||||
template <>
|
||||
struct fmt::formatter<Shader::IR::Reg> {
|
||||
constexpr auto parse(format_parse_context& ctx) {
|
||||
return ctx.begin();
|
||||
}
|
||||
template <typename FormatContext>
|
||||
auto format(const Shader::IR::Reg& reg, FormatContext& ctx) const {
|
||||
if (reg == Shader::IR::Reg::RZ) {
|
||||
return fmt::format_to(ctx.out(), "RZ");
|
||||
} else if (static_cast<int>(reg) >= 0 && static_cast<int>(reg) < 255) {
|
||||
return fmt::format_to(ctx.out(), "R{}", static_cast<int>(reg));
|
||||
} else {
|
||||
throw Shader::LogicError("Invalid register with raw value {}", static_cast<int>(reg));
|
||||
}
|
||||
}
|
||||
};
|
||||
37
gpu/third_party/suyu/shader_recompiler/frontend/ir/type.cpp
vendored
Normal file
37
gpu/third_party/suyu/shader_recompiler/frontend/ir/type.cpp
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <array>
|
||||
#include <string>
|
||||
|
||||
#include "shader_recompiler/frontend/ir/type.h"
|
||||
|
||||
namespace Shader::IR {
|
||||
|
||||
std::string NameOf(Type type) {
|
||||
static constexpr std::array names{
|
||||
"Opaque", "Label", "Reg", "Pred", "Attribute", "U1", "U8", "U16", "U32",
|
||||
"U64", "F16", "F32", "F64", "U32x2", "U32x3", "U32x4", "F16x2", "F16x3",
|
||||
"F16x4", "F32x2", "F32x3", "F32x4", "F64x2", "F64x3", "F64x4",
|
||||
};
|
||||
const size_t bits{static_cast<size_t>(type)};
|
||||
if (bits == 0) {
|
||||
return "Void";
|
||||
}
|
||||
std::string result;
|
||||
for (size_t i = 0; i < names.size(); i++) {
|
||||
if ((bits & (size_t{1} << i)) != 0) {
|
||||
if (!result.empty()) {
|
||||
result += '|';
|
||||
}
|
||||
result += names[i];
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool AreTypesCompatible(Type lhs, Type rhs) noexcept {
|
||||
return lhs == rhs || lhs == Type::Opaque || rhs == Type::Opaque;
|
||||
}
|
||||
|
||||
} // namespace Shader::IR
|
||||
60
gpu/third_party/suyu/shader_recompiler/frontend/ir/type.h
vendored
Normal file
60
gpu/third_party/suyu/shader_recompiler/frontend/ir/type.h
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <fmt/ranges.h>
|
||||
|
||||
#include "common/common_funcs.h"
|
||||
#include "shader_recompiler/exception.h"
|
||||
|
||||
namespace Shader::IR {
|
||||
|
||||
enum class Type {
|
||||
Void = 0,
|
||||
Opaque = 1 << 0,
|
||||
Reg = 1 << 1,
|
||||
Pred = 1 << 2,
|
||||
Attribute = 1 << 3,
|
||||
Patch = 1 << 4,
|
||||
U1 = 1 << 5,
|
||||
U8 = 1 << 6,
|
||||
U16 = 1 << 7,
|
||||
U32 = 1 << 8,
|
||||
U64 = 1 << 9,
|
||||
F16 = 1 << 10,
|
||||
F32 = 1 << 11,
|
||||
F64 = 1 << 12,
|
||||
U32x2 = 1 << 13,
|
||||
U32x3 = 1 << 14,
|
||||
U32x4 = 1 << 15,
|
||||
F16x2 = 1 << 16,
|
||||
F16x3 = 1 << 17,
|
||||
F16x4 = 1 << 18,
|
||||
F32x2 = 1 << 19,
|
||||
F32x3 = 1 << 20,
|
||||
F32x4 = 1 << 21,
|
||||
F64x2 = 1 << 22,
|
||||
F64x3 = 1 << 23,
|
||||
F64x4 = 1 << 24,
|
||||
};
|
||||
DECLARE_ENUM_FLAG_OPERATORS(Type)
|
||||
|
||||
[[nodiscard]] std::string NameOf(Type type);
|
||||
|
||||
[[nodiscard]] bool AreTypesCompatible(Type lhs, Type rhs) noexcept;
|
||||
|
||||
} // namespace Shader::IR
|
||||
|
||||
template <>
|
||||
struct fmt::formatter<Shader::IR::Type> {
|
||||
constexpr auto parse(format_parse_context& ctx) {
|
||||
return ctx.begin();
|
||||
}
|
||||
template <typename FormatContext>
|
||||
auto format(const Shader::IR::Type& type, FormatContext& ctx) const {
|
||||
return fmt::format_to(ctx.out(), "{}", NameOf(type));
|
||||
}
|
||||
};
|
||||
97
gpu/third_party/suyu/shader_recompiler/frontend/ir/value.cpp
vendored
Normal file
97
gpu/third_party/suyu/shader_recompiler/frontend/ir/value.cpp
vendored
Normal file
@@ -0,0 +1,97 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "shader_recompiler/frontend/ir/value.h"
|
||||
|
||||
namespace Shader::IR {
|
||||
|
||||
Value::Value(IR::Inst* value) noexcept : type{Type::Opaque}, inst{value} {}
|
||||
|
||||
Value::Value(IR::Reg value) noexcept : type{Type::Reg}, reg{value} {}
|
||||
|
||||
Value::Value(IR::Pred value) noexcept : type{Type::Pred}, pred{value} {}
|
||||
|
||||
Value::Value(IR::Attribute value) noexcept : type{Type::Attribute}, attribute{value} {}
|
||||
|
||||
Value::Value(IR::Patch value) noexcept : type{Type::Patch}, patch{value} {}
|
||||
|
||||
Value::Value(bool value) noexcept : type{Type::U1}, imm_u1{value} {}
|
||||
|
||||
Value::Value(u8 value) noexcept : type{Type::U8}, imm_u8{value} {}
|
||||
|
||||
Value::Value(u16 value) noexcept : type{Type::U16}, imm_u16{value} {}
|
||||
|
||||
Value::Value(u32 value) noexcept : type{Type::U32}, imm_u32{value} {}
|
||||
|
||||
Value::Value(f32 value) noexcept : type{Type::F32}, imm_f32{value} {}
|
||||
|
||||
Value::Value(u64 value) noexcept : type{Type::U64}, imm_u64{value} {}
|
||||
|
||||
Value::Value(f64 value) noexcept : type{Type::F64}, imm_f64{value} {}
|
||||
|
||||
IR::Type Value::Type() const noexcept {
|
||||
if (IsPhi()) {
|
||||
// The type of a phi node is stored in its flags
|
||||
return inst->Flags<IR::Type>();
|
||||
}
|
||||
if (IsIdentity()) {
|
||||
return inst->Arg(0).Type();
|
||||
}
|
||||
if (type == Type::Opaque) {
|
||||
return inst->Type();
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
bool Value::operator==(const Value& other) const {
|
||||
if (type != other.type) {
|
||||
return false;
|
||||
}
|
||||
switch (type) {
|
||||
case Type::Void:
|
||||
return true;
|
||||
case Type::Opaque:
|
||||
return inst == other.inst;
|
||||
case Type::Reg:
|
||||
return reg == other.reg;
|
||||
case Type::Pred:
|
||||
return pred == other.pred;
|
||||
case Type::Attribute:
|
||||
return attribute == other.attribute;
|
||||
case Type::Patch:
|
||||
return patch == other.patch;
|
||||
case Type::U1:
|
||||
return imm_u1 == other.imm_u1;
|
||||
case Type::U8:
|
||||
return imm_u8 == other.imm_u8;
|
||||
case Type::U16:
|
||||
case Type::F16:
|
||||
return imm_u16 == other.imm_u16;
|
||||
case Type::U32:
|
||||
case Type::F32:
|
||||
return imm_u32 == other.imm_u32;
|
||||
case Type::U64:
|
||||
case Type::F64:
|
||||
return imm_u64 == other.imm_u64;
|
||||
case Type::U32x2:
|
||||
case Type::U32x3:
|
||||
case Type::U32x4:
|
||||
case Type::F16x2:
|
||||
case Type::F16x3:
|
||||
case Type::F16x4:
|
||||
case Type::F32x2:
|
||||
case Type::F32x3:
|
||||
case Type::F32x4:
|
||||
case Type::F64x2:
|
||||
case Type::F64x3:
|
||||
case Type::F64x4:
|
||||
break;
|
||||
}
|
||||
throw LogicError("Invalid type {}", type);
|
||||
}
|
||||
|
||||
bool Value::operator!=(const Value& other) const {
|
||||
return !operator==(other);
|
||||
}
|
||||
|
||||
} // namespace Shader::IR
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user