Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
skip to main content
research-article
Open access

Staged metaprogramming for shader system development

Published: 08 November 2019 Publication History

Abstract

The shader system for a modern game engine comprises much more than just compilation of source code to executable kernels. Shaders must also be exposed to art tools, interfaced with engine code, and specialized for performance. Engines typically address each of these tasks in an ad hoc fashion, without a unifying abstraction. The alternative of developing a more powerful compiler framework is prohibitive for most engines.
In this paper, we identify staged metaprogramming as a unifying abstraction and implementation strategy to develop a powerful shader system with modest effort. By using a multi-stage language to perform metaprogramming at compile time, engine-specific code can consume, analyze, transform, and generate shader code that will execute at runtime. Staged metaprogramming reduces the effort required to implement a shader system that provides earlier error detection, avoids repeat declarations of shader parameters, and explores opportunities to improve performance.
To demonstrate the value of this approach, we design and implement a shader system, called Selos, built using staged metaprogramming. In our system, shader and application code are written in the same language and can share types and functions. We implement a design space exploration framework for Selos that investigates static versus dynamic composition of shader features, exploring the impact of shader specialization in a deferred renderer. Staged metaprogramming allows Selos to provide compelling features with a simple implementation.

Supplementary Material

ZIP File (a202-seitz.zip)
Supplemental files.

References

[1]
Johan Andersson. 2011. DirectX 11 Rendering in Battlefield 3. Game Developers Conference 2011. http://www.dice.se/news/directx-11-rendering-battlefield-3/
[2]
Alan Bawden and Jonathan Rees. 1988. Syntactic Closures. In Proceedings of the 1988 ACM Conference on LISP and Functional Programming (LFP '88). 86--95.
[3]
Sean Baxter. 2019. Circle. https://github.com/seanbaxter/circle
[4]
Nir Benty, Kai-Hwa Yao, Tim Foley, Matthew Oakes, Conor Lavelle, and Chris Wyman. 2018. The Falcor Rendering Framework. https://github.com/NVIDIAGameWorks/Falcor https://github.com/NVIDIAGameWorks/Falcor.
[5]
David Blythe. 2006. The Direct3D 10 System. ACM Transactions on Graphics 25, 3 (July 2006), 724--734.
[6]
Cristiano Calcagno, Walid Taha, Liwen Huang, and Xavier Leroy. 2003. Implementing Multi-stage Languages Using ASTs, Gensym, and Reflection. In Proceedings of the 2nd International Conference on Generative Programming and Component Engineering (GPCE '03). 57--76.
[7]
Shigeru Chiba. 1995. A Metaobject Protocol for C++. In Proceedings of the Tenth Annual Conference on Object-oriented Programming Systems, Languages, and Applications (OOPSLA '95). 285--299.
[8]
Matus Chochlik, Axel Naumann, and David Sankel. 2018. Static reflection. C++ Standards Committee Papers. http://wg21.link/p0194
[9]
Petrik Clarberg and Jacob Munkberg. 2014. Deep Shading Buffers on Commodity GPUs. ACM Transactions on Graphics 33, 6, Article 227 (Nov. 2014), 12 pages.
[10]
Robert L. Cook. 1984. Shade Trees. In Computer Graphics (Proceedings of SIGGRAPH 84). 223--231.
[11]
Russ Cox, Tom Bergan, Austin T. Clements, Frans Kaashoek, and Eddie Kohler. 2008. Xoc, an Extension-oriented Compiler for Systems Programming. In Proceedings of the 13th International Conference on Architectural Support for Programming Languages and Operating Systems (ASPLOS XIII). 244--254.
[12]
Zachary DeVito, James Hegarty, Alex Aiken, Pat Hanrahan, and Jan Vitek. 2013. Terra: A Multi-Stage Language for High-Performance Computing. In Proceedings of the 34th ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI '13). 105--116.
[13]
Ramy El Garawany. 2016. Advances in Real-time Rendering, Part I: Deferred Lighting in Uncharted 4. In ACM SIGGRAPH 2016 Courses (SIGGRAPH '16). http://advances.realtimerendering.com/s2016/index.html
[14]
Conal Elliott. 2004. Programming Graphics Processors Functionally. In Proceedings of the 2004 ACM SIGPLAN Workshop on Haskell (Haskell '04). 45--56.
[15]
Dawson R. Engler, Wilson C. Hsieh, and M. Frans Kaashoek. 1996. 'C: A Language for High-level, Efficient, and Machine-independent Dynamic Code Generation. In Proceedings of the 23rd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL '96). 131--144.
[16]
Epic Games. 2017. Unreal Engine Sun Temple, Open Research Content Archive (ORCA). https://developer.nvidia.com/ue4-sun-temple
[17]
Epic Games, Inc. 2019. Unreal Engine 4 Documentation. https://docs.unrealengine.com/en-us/
[18]
Matthew Flatt. 2002. Composable and Compilable Macros: You Want It When?. In Proceedings of the Seventh ACM SIGPLAN International Conference on Functional Programming (ICFP '02). 72--83.
[19]
Tim Foley and Pat Hanrahan. 2011. Spark: Modular, Composable Shaders for Graphics Hardware. ACM Transactions on Graphics 30, 4 (July 2011), 107:1--107:12.
[20]
Yoshihiko Futamura. 1982. Partial Computation of Programs. In RIMS Symposium on Software Science and Engineering, Kyoto, Japan, 1982, Proceedings. 1--35.
[21]
Romain Guy and Mathias Agopian. 2019. Filament. https://github.com/google/filament https://github.com/google/filament.
[22]
Pat Hanrahan and Jim Lawson. 1990. A Language for Shading and Lighting Calculations. In Computer Graphics (Proceedings of SIGGRAPH 90). 289--298.
[23]
Yong He, Kayvon Fatahalian, and Tim Foley. 2018. Slang: Language Mechanisms for Extensible Real-time Shading Systems. ACM Transactions on Graphics 37, 4, Article 141 (July 2018), 13 pages.
[24]
Yong He, Tim Foley, and Kayvon Fatahalian. 2016. A System for Rapid Exploration of Shader Optimization Choices. ACM Transactions on Graphics 35, 4, Article 112 (July 2016), 12 pages.
[25]
Roberto Ierusalimschy, Luiz Henrique de Figueiredo, and Waldemar Celes Filho. 1996. Lua---An Extensible Extension Language. Software: Practice and Experience 26, 6 (June 1996), 635--652. <635::AID-SPE26>3.0.CO;2-P
[26]
John Kessenich and Boaz Ouriel. 2018. SPIR-V Specification (Version 1.00). https://www.khronos.org/registry/spir-v/specs/1.0/SPIRV.pdf.
[27]
Khronos Group. 2016. Vulkan 1.0.12 - A Specification. https://www.khronos.org/registry/vulkan/specs/1.0/pdf/vkspec.pdf.
[28]
Calle Lejdfors and Lennart Ohlsson. 2004. PyFX - An active effect framework. In Proceedings of SIGRAD 2004. Linköping University Electronic Press, 17--24. http://www.ep.liu.se/ecp/article.asp?issue=013&article=006
[29]
Ronan Marchalot. 2018. Cluster Forward Rendering and Anti-Aliasing in 'Detroit: Become Human'. Game Developers Conference 2018. https://www.gdcvault.com/play/1025420/Cluster-Forward-Rendering-and-Anti
[30]
Stephen McAuley. 2018. Advances in Real-time Rendering in Games, Part I: The Challenges of Rendering an Open World in Far Cry 5. In ACM SIGGRAPH 2018 Courses (SIGGRAPH '18). ACM. http://advances.realtimerendering.com/s2018/index.htm
[31]
John McCarthy. 1960. Recursive Functions of Symbolic Expressions and Their Computation by Machine, Part I. Commun. ACM 3, 4 (April 1960), 184--195.
[32]
Michael D. McCool, Zheng Qin, and Tiberiu S. Popa. 2002. Shader Metaprogramming. In Proceedings of the ACM SIGGRAPH/EUROGRAPHICS Conference on Graphics Hardware (HWWS '02). 57--68. http://dl.acm.org/citation.cfm?id=569046.569055
[33]
Morgan McGuire, George Stathis, Hanspeter Pfister, and Shriram Krishnamurthi. 2006. Abstract Shade Trees. In Proceedings of the 2006 Symposium on Interactive 3D Graphics and Games (I3D '06). 79--86.
[34]
Microsoft. 2010. Effect Format (Direct3D 11). (2010). https://msdn.microsoft.com/en-us/library/windows/desktop/ff476118(v=vs.85).aspx.
[35]
Microsoft. 2017. Direct3D 12 Programming Guide. https://docs.microsoft.com/en-us/windows/desktop/direct3d12/directx-12-programming-guide
[36]
Microsoft. 2019. DirectX Shader Compiler. https://github.com/Microsoft/DirectXShaderCompiler https://github.com/Microsoft/DirectXShaderCompiler.
[37]
NVIDIA Corporation. 2007. NVIDIA CUDA Compute Unified Device Architecture Programming Guide. (Jan. 2007). http://developer.nvidia.com/cuda.
[38]
NVIDIA Corporation. 2010. Introduction to CgFX. (2010). http://http.developer.nvidia.com/CgTutorial/cg_tutorial_chapter01.html.
[39]
Arsène Pérard-Gayot, Richard Membarth, Roland Leißa, Sebastian Hack, and Philipp Slusallek. 2019. Rodent: Generating Renderers without Writing a Generator. In ACM Transactions on Graphics (TOG), Vol. 38. 40:1--40:12.
[40]
Aras Pranckevičius. 2013. HLSL to GLSL shader language translator. https://github.com/aras-p/hlsl2glslfork
[41]
Aras Pranckevičius. 2016. Personal Communication.
[42]
Kekoa Proudfoot, William R. Mark, Svetoslav Tzvetkov, and Pat Hanrahan. 2001. A Real-Time Procedural Shading System for Programmable Graphics Hardware. In Proceedings of SIGGRAPH 2001. 159--170.
[43]
Rust Project Developers. 2015. The Rust Programming Language. https://doc.rustlang.org/book/.
[44]
Adrian Sampson, Kathryn S. McKinley, and Todd Mytkowicz. 2017. Static Stages for Heterogeneous Programming. Proceedings of the ACM on Programming Languages 1, OOPSLA, Article 71 (Oct. 2017), 27 pages.
[45]
Mark Segal, Kurt Akeley, Chris Frazier, Jon Leech, and Pat Brown. 2015. The OpenGL© Graphics System: A Specification (Version 4.5 (Core Profile) - May 28, 2015). https://www.opengl.org/registry/doc/glspec45.core.pdf.
[46]
Tiago Sousa and Jean Geffroy. 2016. Advances in Real-time Rendering, Part II: The Devil is in the Details: idTech 666. In ACM SIGGRAPH 2016 Courses (SIGGRAPH '16). http://advances.realtimerendering.com/s2016/index.html
[47]
Gerald Jay Sussman and Guy L. Steele, Jr. 1998. Scheme: A Interpreter for Extended Lambda Calculus. Higher-Order and Symbolic Computation 11, 4 (Dec. 1998), 405--439.
[48]
Herb Sutter. 2018. Metaclasses: Generative C++. C++ Standards Committee Papers. https://wg21.link/P0707
[49]
Walid Taha and Tim Sheard. 2000. MetaML and multi-stage programming with explicit annotations. Theoretical Computer Science 248, 1--2 (Oct. 2000), 211--242.
[50]
Walid Mohamed Taha. 1999. Multistage Programming: Its Theory and Applications. Ph.D. Dissertation. Oregon Graduate Institute of Science and Technology.
[51]
Natalya Tatarchuk and Chris Tchou. 2017. Destiny Shader Pipeline. Game Developers Conference 2017. http://advances.realtimerendering.com/destiny/gdc_2017/
[52]
Unity Technologies. 2019. Unity User Manual (2019.1). https://docs.unity3d.com/Manual/index.html
[53]
Daveed Vandevoorde and Louis Dionne. 2017. Exploring the design space of metaprogramming and reflection. C++ Standards Committee Papers. https://wg21.link/P0633

Cited By

View all
  • (2024)RenderKernel: High-level programming for real-time rendering systemsVisual Informatics10.1016/j.visinf.2024.09.0048:3(82-95)Online publication date: Sep-2024
  • (2024)The consolidation of game software engineering: A systematic literature review of software engineering for industry-scale computer gamesInformation and Software Technology10.1016/j.infsof.2023.107330165(107330)Online publication date: Jan-2024
  • (2023)SLANG.D: Fast, Modular and Differentiable Shader ProgrammingACM Transactions on Graphics10.1145/361835342:6(1-28)Online publication date: 5-Dec-2023
  • Show More Cited By

Recommendations

Comments

Information & Contributors

Information

Published In

cover image ACM Transactions on Graphics
ACM Transactions on Graphics  Volume 38, Issue 6
December 2019
1292 pages
ISSN:0730-0301
EISSN:1557-7368
DOI:10.1145/3355089
Issue’s Table of Contents
Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than the author(s) must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected].

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

Published: 08 November 2019
Published in TOG Volume 38, Issue 6

Permissions

Request permissions for this article.

Check for updates

Author Tags

  1. computer graphics
  2. metaprogramming
  3. multi-stage languages
  4. shaders
  5. shading languages

Qualifiers

  • Research-article

Funding Sources

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • Downloads (Last 12 months)208
  • Downloads (Last 6 weeks)21
Reflects downloads up to 04 Oct 2024

Other Metrics

Citations

Cited By

View all
  • (2024)RenderKernel: High-level programming for real-time rendering systemsVisual Informatics10.1016/j.visinf.2024.09.0048:3(82-95)Online publication date: Sep-2024
  • (2024)The consolidation of game software engineering: A systematic literature review of software engineering for industry-scale computer gamesInformation and Software Technology10.1016/j.infsof.2023.107330165(107330)Online publication date: Jan-2024
  • (2023)SLANG.D: Fast, Modular and Differentiable Shader ProgrammingACM Transactions on Graphics10.1145/361835342:6(1-28)Online publication date: 5-Dec-2023
  • (2022)LuisaRenderACM Transactions on Graphics10.1145/3550454.355546341:6(1-19)Online publication date: 30-Nov-2022
  • (2022)Supporting Unified Shader Specialization by Co-opting C++ FeaturesProceedings of the ACM on Computer Graphics and Interactive Techniques10.1145/35438665:3(1-17)Online publication date: 27-Jul-2022

View Options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Get Access

Login options

Full Access

Media

Figures

Other

Tables

Share

Share

Share this Publication link

Share on social media