npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rollup-plugin-glsl-optimize

v1.0.4

Published

Import GLSL source files as strings. Pre-processed, validated and optimized with Khronos Group SPIRV-Tools. Supports glslify.

Downloads

91

Readme

rollup-plugin-glsl-optimize

NPM Package Changelog Node Version Types Maintainability
Dependencies Dev Dependencies Coverage Status Node.js CI

Import GLSL source files as strings. Pre-processed, validated and optimized with Khronos Group SPIRV-Tools.

Primary use-case is processing WebGL2 / GLSL ES 300 shaders.

import frag from './shaders/myShader.frag';
console.log(frag);

Features

GLSL Optimizer

For WebGL2 / GLSL ES >= 300

With optimize: true (default) shaders will be compiled to SPIR-V (opengl semantics) and optimized for performance using the Khronos SPIR-V Tools Optimizer before being cross-compiled back to GLSL.

Shader Preprocessor

Shaders are preprocessed and validated using the Khronos Glslang Validator.

Macros are run at build time with support for C-style #include directives: *

#version 300 es
#include "postProcessingShared.glsl"
#include "dofCircle.glsl"

void main() {
  outColor = CircleDof(UVAndScreenPos, Color, ColorCoc);
}

* Via the GL_GOOGLE_include_directive extension. But an #extension directive is not required nor recommended in your final inlined code.

Supports glslify

Specify glslify: true to process shader sources with glslify (a node.js-style module system for GLSL).

And install glslify in your devDependencies with npm i -D glslify

Installation

npm i rollup-plugin-glsl-optimize -D

Khronos tools

This plugin uses the Khronos Glslang Validator, Khronos SPIRV-Tools Optimizer and Khronos SPIRV Cross compiler.

Binaries are automatically installed for:

  • Windows 64bit (MSVC 2017)
  • MacOS x86_64 (clang)
  • Ubuntu Trusty / Debian Buster amd64 (clang)

Paths can be manually provided / overridden with the GLSLANG_VALIDATOR, GLSLANG_OPTIMIZER, GLSLANG_CROSS environment variables.

Usage

// rollup.config.js
import {default as glslOptimize} from 'rollup-plugin-glsl-optimize';

export default {
    // ...
    plugins: [
        glslOptimize(),
    ]
};

Shader stages

The following shader stages are supported by the Khronos tools and recognized by file extension:

| Shader Stage | File Extensions | | ------------ | ------------------------------------- | | Vertex | .vs, .vert, .vs.glsl, .vert.glsl | | Fragment | .fs, .frag, .fs.glsl, .frag.glsl | | Geometry* | .geom, .geom.glsl | | Compute* | .comp, .comp.glsl | | Tess Control* | .tesc, .tesc.glsl | | Tess Eval* | .tese, .tese.glsl |

* Unsupported in WebGL2

Options

  • include : PathFilter (default table above) File extensions within rollup to include. Though this option can be reconfigured, shader stage detection still operates based on the table above.
  • exclude : PathFilter (default undefined) File extensions within rollup to exclude.
  • includePaths : string[] (default undefined) Additional search paths for #include directive (source file directory is always searched)

Features

  • optimize : boolean (default true) Optimize via SPIR-V as described in the Optimization section [requires WebGL2 / GLSL ES >= 300]. When disabled simply runs the preprocessor [all supported GLSL versions].
  • compress : boolean (default true) Strip all whitespace in the sources

Debugging

  • sourceMap : boolean (default true) Emit source maps. These contain the final preprocessed/optimized GLSL source (but not stripped of whitespace) to aid debugging.
  • emitLineDirectives : boolean (default false) Emit #line NN "original.file" directives for debugging - useful with #include. Note this requires the GL_GOOGLE_cpp_style_line_directive extension so the shader will fail to run in drivers that lack support.

Preprocessor

  • optimizerPreserveUnusedBindings : boolean (default true) Ensure that the optimizer preserves all declared bindings, even when those bindings are unused.
  • preamble : string (default undefined) Prepended to the shader source (after the #version directive, before the preprocessor runs)

glslify

  • glslify : boolean (default false) Process sources using glslify prior to all preprocessing, validation and optimization.
  • glslifyOptions (default undefined) When glslify enabled, pass these additional options to glslify.compile().

Advanced Options

  • optimizerDebugSkipOptimizer : boolean (default false) When optimize enabled, skip the SPIR-V optimizer - compiles to SPIR-V then cross-compiles back to GLSL immediately.
  • suppressLineExtensionDirective : boolean (default false) When emitLineDirectives enabled, suppress the GL_GOOGLE_cpp_style_line_directive directive.
  • extraValidatorParams, extraOptimizerParams, extraCrossParams : string[] (default undefined) Additional parameters for the Khronos Glslang Validator here, the Khronos SPIR-V Optimizer here, and the Khronos SPIR-V Cross compiler here.
  • glslangValidatorPath, glslangOptimizerPath, glslangCrossPath : string (default undefined) Provide / override binary tool paths.
    It's recommended to instead use the environment variables GLSLANG_VALIDATOR, GLSLANG_OPTIMIZER, GLSLANG_CROSS where needed. They always take precedence if set.

Changelog

Available in CHANGES.md.

Caveats & Known Issues

  • This plugin handles glsl and glslify by itself. Use with conflicting plugins (e.g. rollup-plugin-glsl, rollup-plugin-glslify) will cause unpredictable results.
  • Optimizer: lowp precision qualifier - emitted as mediump
    SPIR-V has a single RelaxedPrecision decoration for 16-32bit precision. However most implementations actually treat mediump and lowp equivalently, hence the lack of need for it in SPIR-V.

License

Released under the MIT license.
Strip whitespace function adapted from code by Vincent Wochnik (rollup-plugin-glsl).

Khronos tool binaries (built by the upstream projects) are distributed and installed with this plugin under the terms of the Apache License Version 2.0. See the corresponding LICENSE files installed in the bin folder and the binary releases.