selos

A shader system built using staged metaprogramming

https://github.com/kseitz/selos

Science Score: 67.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 4 DOI reference(s) in README
  • Academic publication links
    Links to: acm.org
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (10.8%) to scientific vocabulary
Last synced: 6 months ago · JSON representation ·

Repository

A shader system built using staged metaprogramming

Basic Info
  • Host: GitHub
  • Owner: kseitz
  • License: other
  • Language: Lua
  • Default Branch: master
  • Size: 4.71 MB
Statistics
  • Stars: 14
  • Watchers: 2
  • Forks: 3
  • Open Issues: 0
  • Releases: 0
Created over 6 years ago · Last pushed over 3 years ago
Metadata Files
Readme License Citation

README.md

Selos

This repository contains source code supporting the SIGGRAPH Asia 2019 paper:

Staged Metaprogramming for Shader System Development\ Kerry A. Seitz, Jr., T. Foley, Serban D. Porumbescu, and John D. Owens\ ACM Transactions on Graphics (TOG) — SIGGRAPH Asia 2019\ Volume 38 Issue 6, November 2019\ Article No. 202

DOI: https://doi.org/10.1145/3355089.3356554\ BibTeX: selos.bib\ ACM Paper: https://dl.acm.org/citation.cfm?id=3356554\ Author Preprint: https://escholarship.org/uc/item/2f8448n2\ Slides (pptx): Selos-SIGGRAPHAsia2019.pptx\ Slides (pdf): Selos-SIGGRAPHAsia2019.pdf\ Code: https://github.com/kseitz/selos

Getting Started

Note: This code is currently tested only on 64-bit Windows. All pre-built binaries are built for 64-bit Windows only.

Required Software

1) Microsoft Visual Studio 2013: https://visualstudio.microsoft.com/vs/older-downloads/

Note: Also known as Microsoft Visual Studio 12.0

2) Terra and its prerequisites: terralang.org

Direct link to download: terra-Windows-x86_64-332a506.zip

Note 1: Our code currently works with Terra release 2016-03-25: https://github.com/zdevito/terra/releases/tag/release-2016-03-25

Note 2: The pre-build binaries are sufficient. However, if you choose to build Terra from source:

  • Be sure to check out the commit corresponding to the release specified above 332a506

  • We recommend building LLVM and Clang in x64 Release mode for easiest compatibility with Terra. Make sure you get the version of LLVM and Clang that Terra specifies. Also, LLVM's CMAKE_INSTALL_PREFIX path may default to a privileged location, so you may need to manually modify that CMake argument for proper installation. Instructions for building LLVM and Clang can be found here: llvm.org/docs/GettingStarted.html

  • You do not need to manually build LuaJIT. The Terra build process will build it automatically.

3) SDL 2.0: libsdl.org

Direct link to download: SDL2-devel-2.0.8-VC.zip

Note 1: Download the "Development Libraries" for SDL2 in order to obtain both the binaries and the required headers.

Note 2: The SDL2 binary download should be sufficient, but you can build from source if desired.

Note 3: This code was tested using SDL 2.0.8, which can be downloaded at libsdl.org/release (specifically SDL2-devel-2.0.8-VC.zip)

4) UE4 Sun Temple scene (version 1): https://escholarship.org/uc/item/2f8448n2#supplemental

Direct link to download (~800 MB): SunTemple_v1.zip

Note: This code was tested with version 1 of the UE4 Sun Temple scene. The performance analysis in the paper also uses version 1. However, this version is no longer available from the ORCA: Open Research Content Archive website, so please download it from the links provided above.

Installing

1) Clone the Selos repository. We'll call the directory into which you cloned the repository: $SELOS

Shell # Make sure to clone with --recursive git clone --recursive https://github.com/kseitz/selos.git

Note: If you didn't clone with the --recursive flag, then you need to manually clone the submodules:

Shell cd $SELOS git submodule update --init --recursive

2) Copy your SDL download to $SELOS/external/SDL2

Note: You should have the following SDL files:

Shell $SELOS/external/SDL2/include/SDL.h $SELOS/external/SDL2/include/SDL_opengl.h $SELOS/external/SDL2/lib/x64/SDL2.dll

3) Copy your UE Sun Temple (version 1) download to $SELOS/examples/assets/models

Note: You should have the following Sun Temple file and folder:

Shell $SELOS/examples/assets/models/SunTemple_v1/SunTemple.fbx $SELOS/examples/assets/models/SunTemple_v1/Textures/

4) Add the following directories to your PATH environment variable:

Shell $SELOS/external/built/bin/x64 $SELOS/external/SDL2/lib/x64

Note: We also recommend adding the path to terra.exe to your PATH environment variable.

Running the Deferred Renderer

Note: The default window size is 1920 x 1080. You can change the window size by editing the MAX_WINDOW_WIDTH and MAX_WINDOW_HEIGHT variables in $SELOS/examples/deferredRenderer/constants.t.

1) Compile the shaders and the runtime application:

Shell cd $SELOS/examples/deferredRenderer terra compile.t

2) Run the application:

Shell cd $SELOS/examples/deferredRenderer/build runGame-OpenGL.exe

Note: By default, compile.t generates GLSL shaders and compiles the runtime application to use the OpenGL implementation. To generate HLSL shaders and compile the application to use the Direct3D 11 implementation, use the --d3d11 argument:

Shell cd $SELOS/examples/deferredRenderer terra compile.t --d3d11

Shell cd $SELOS/examples/deferredRenderer/build runGame-D3D11.exe

You can also compile the shaders and the runtime application separately:

Shell cd $SELOS/examples/deferredRenderer terra compileShaders.t terra compileRuntime.t

This functionality is useful if, for example, you want to hot reload shaders while the application is running. You can modify the logic of a shader, run terra compileShaders.t, and then click the Reload Shader Cache GUI button. However, if the interface to a shader changes (e.g., if you add or remove a parameter), then the application must be recompiled.

Both compileShaders.t and compileRuntime.t also support the --d3d11 argument.

Running the Specialization Design Space Exploration

To run the specialization design space exploration case study as presented in the paper, use the -a argument when launching the runtime application:

Shell cd $SELOS/examples/deferredRenderer/build runGame-OpenGL.exe -a

or

Shell cd $SELOS/examples/deferredRenderer/build runGame-D3D11.exe -a

Note This will take a long time to complete. You can adjust some testing parameters in $SELOS/examples/deferredRenderer/constants.t to decrease testing time at the cost of accuracy.

Results are written to $SELOS/examples/deferredRenderer/build/output/{D3D11,OpenGL}/, including partial results as the test is running.

You can also run individual parts of the test by specifying how many features you want to allow to be specialized. Use the -sN argument for this purpose, where N is the number of features to specialize (0 <= N <= 6). For example, if you want to allow only 3 features to be specialized at a time:

Shell cd $SELOS/examples/deferredRenderer/build runGame-OpenGL.exe -s3

or

Shell cd $SELOS/examples/deferredRenderer/build runGame-D3D11.exe -s3

Using the GLSL/HLSL Backends with Other Projects

DISCLAIMER: The below information has not been updated recently. Thus, it may not be completely consistent with the current implementation. For example, Selos supports compute shaders, but the documentation below only discusses vertex and fragment shaders. However, the information should still be a useful starting point for anyone interested in using the GLSL and HLSL backends for Terra separate from Selos. Please feel free to post an issue on the Selos GitHub repo if you would like further assistance.

Note: Below is some brief documentation for how to use the GLSL and HLSL Terra backends. This documentation will be useful if you want to use the backends with external projects. The Selos Shader Intermediate Representation (SIR) handles interfacing with the backends, so you will likely not need to read this documentation if you are using the SIR for your code.

The GLSL and HLSL backends can be used directly through the functions returned by the files $SELOS/src/terraToGLSL.t and $SELOS/src/terraToHLSL.t (respectively). These functions take a single table as an input, and each entry in the table should be a Lua array (e.g., created from terralib.newlist()). The entires required, as well as the format for each array's entries, are detailed below:

Note: inputsList is for vertex shader inputs; outputsList is for fragment shader outputs; and varyingsList is for vertex shader outputs and fragment shader inputs.

These functions return a table with two string entires named vertexSourceCode and fragmentSourceCode for the vertex and fragment, respectively, GLSL/HLSL for the shader.

We provide GLSL/HLSL builtin types and functions in $SELOS/src/builtin.t. The backends will automatically replace uses of these builtins with the corresponding GLSL/HLSL builtins (if applicable).

Some system-provided inputs and outputs (e.g., equivalents to gl_FragCoord and gl_Position) are also specified in $SELOS/src/builtin.t in the Builtin.systemInputs and Builtin.systemOutputs tables, respectively. See the bottom of this file to see which inputs/outputs we provide and how they are named.

Owner

  • Name: Kerry A. Seitz, Jr.
  • Login: kseitz
  • Kind: user

I work on computer graphics, shading systems, and shader compilers. I received my Ph.D. in Computer Science from UC Davis.

Citation (CITATION.cff)

cff-version: 1.2.0
message: "If you use this software, please cite the associated technical paper from the preferred-citation."
title: "Staged Metaprogramming for Shader System Development"
authors:
  - given-names: "Kerry A."
    family-names: "Seitz"
    name-suffix: "Jr."
    email: "kaseitz@ucdavis.edu"
    affiliation: "University of California, Davis"
    orcid: "https://orcid.org/0000-0003-2424-9495"
  - given-names: "T."
    family-names: "Foley"
    email: "tfoley@nvidia.com"
    affiliation: "NVIDIA"
    orcid: "https://orcid.org/0000-0002-2381-3544"
  - given-names: "Serban D."
    family-names: "Porumbescu"
    email: "sdporumbescu@ucdavis.edu"
    affiliation: "University of California, Davis"
    orcid: "https://orcid.org/0000-0003-1523-9199"
  - given-names: "John D."
    family-names: "Owens"
    email: "jowens@ece.ucdavis.edu"
    affiliation: "University of California, Davis"
    orcid: "https://orcid.org/0000-0001-6582-8237"
repository-code: "https://github.com/kseitz/selos"
preferred-citation:
  type: article
  title: "Staged Metaprogramming for Shader System Development"
  authors:
    - given-names: "Kerry A."
      family-names: "Seitz"
      name-suffix: "Jr."
      email: "kaseitz@ucdavis.edu"
      affiliation: "University of California, Davis"
      orcid: "https://orcid.org/0000-0003-2424-9495"
    - given-names: "T."
      family-names: "Foley"
      email: "tfoley@nvidia.com"
      affiliation: "NVIDIA"
      orcid: "https://orcid.org/0000-0002-2381-3544"
    - given-names: "Serban D."
      family-names: "Porumbescu"
      email: "sdporumbescu@ucdavis.edu"
      affiliation: "University of California, Davis"
      orcid: "https://orcid.org/0000-0003-1523-9199"
    - given-names: "John D."
      family-names: "Owens"
      email: "jowens@ece.ucdavis.edu"
      affiliation: "University of California, Davis"
      orcid: "https://orcid.org/0000-0001-6582-8237"
  journal: "ACM Transactions on Graphics"
  year: 2019
  volume: 38
  issue: 6
  start: "202:1"
  end: "202:15"
  month: 11
  doi: 10.1145/3355089.3356554

GitHub Events

Total
Last Year