Skip to content

An instruction-level simulator for GPU shaders, written in C99.

License

Notifications You must be signed in to change notification settings

JohanSmet/shader_sim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ShaderSim

ShaderSim is an instruction-level simulator for GPU 'shaders'. The primary intention is to help debug/validate a shader and to visualize and help understand the execution of the shader. More attention has been given to the clarity and maintainability of the code, run-time performance comes secondary in this respect.

At the moment only (a subset of) of SPIR-V has been implemented. Support for other, compiled, shader formats (HLSL, Metal) might be added in the future.

Why ?

The short answer is that it seemed like a fun way to spend some free time.

A slightly longer answer would be it's a combination of events. I was playing around with using SPIR-V shaders in OpenGL, and having some trouble figuring out what was going on in the shaders. At the same time I was watching bitwise building computer systems from scratch. So I thought it would be fun to try and write a SPIR-V simulator. I decided to use this opportunity to brush up on my C. It had been a while since I wrote anything in pure C.

The decision to do include a browser based front-end came about in the same way. Thought a UI could be useful, didn't feel like using Qt or WxWindows (been there, done that). So why experiment with Emscripten and WebAssembly. Another thing I can scratch of my bucket list ;-)

It's definitely not ground breaking and might not be useful to many people. But I had a lot of fun and learned quite a bit while doing this.

Structure

The core of ShaderSim is implemented as a C11 library, with minimal external dependencies. The majority of the code should be compatible with C99, the only C11 feature in use are static_asserts.

There's a command-line front-end that can be used to verify expected outputs from given inputs. The parameters of the execution are specified through a JSON file.

A browser-based front-end can be used to step through the shader instruction by instruction and inspect the state of the internal registers and the outputs. This front-end runs entirely on the client-side of the browser, no communication with an external server is required once the program is loaded. You can test it out now by following this link.

License

This project is licensed under the 3-clause BSD License. See LICENSE for the full text.

Acknowledgements

The browser front-end would not have been possible without the excellent Emscripten project.

The unit tests were written using the µnit framework.

More information

About

An instruction-level simulator for GPU shaders, written in C99.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published