### Render Shader Presets Source: https://github.com/snowflakepowered/librashader/blob/master/CLI.md Examples of rendering shader presets to an output image, including frame selection for animated presets. ```bash $ librashader-cli render -i image.png -p crt-royale.slangp -r opengl3 -o out.png ``` ```bash $ librashader-cli render -i image.png -p MBZ__0__SMOOTH-ADV.slangp -f 120 -r opengl3 -o out.png ``` -------------------------------- ### Install librashader-cli Source: https://github.com/snowflakepowered/librashader/blob/master/CLI.md Installs the CLI tool using the Cargo package manager. ```bash $ cargo install librashader-cli ``` -------------------------------- ### Install FreeType via vcpkg Source: https://github.com/snowflakepowered/librashader/blob/master/test/capi-tests/imgui/misc/freetype/README.md Command to install FreeType binaries on Windows using the vcpkg package manager. ```bash vcpkg install freetype --triplet=x64-windows ``` ```bash vcpkg integrate install ``` -------------------------------- ### Shader reflection JSON output Source: https://github.com/snowflakepowered/librashader/blob/master/CLI.md Example of the JSON structure returned by the reflection command, detailing UBO, push constant, and parameter offsets. ```json { "ubo": { "binding": 0, "size": 96, "stage_mask": "VERTEX | FRAGMENT" }, "push_constant": { "binding": null, "size": 96, "stage_mask": "VERTEX | FRAGMENT" }, "meta": { "param": { "ysize": { "offset": { "ubo": null, "push": 80 }, "size": 1, "id": "ysize" }, "xsize": { "offset": { "ubo": null, "push": 76 }, "size": 1, "id": "xsize" }, "invert_aspect": { "offset": { "ubo": null, "push": 68 }, "size": 1, "id": "invert_aspect" }, "x_tilt": { "offset": { "ubo": null, "push": 28 }, "size": 1, "id": "x_tilt" }, "y_tilt": { "offset": { "ubo": null, "push": 32 }, "size": 1, "id": "y_tilt" }, "R": { "offset": { "ubo": null, "push": 16 }, "size": 1, "id": "R" }, "d": { "offset": { "ubo": null, "push": 12 }, "size": 1, "id": "d" }, "vertical_scanlines": { "offset": { "ubo": null, "push": 72 }, "size": 1, "id": "vertical_scanlines" }, "SHARPER": { "offset": { "ubo": null, "push": 48 }, "size": 1, "id": "SHARPER" }, "interlace_detect": { "offset": { "ubo": null, "push": 60 }, "size": 1, "id": "interlace_detect" }, "CURVATURE": { "offset": { "ubo": null, "push": 56 }, "size": 1, "id": "CURVATURE" }, "overscan_x": { "offset": { "ubo": null, "push": 36 }, "size": 1, "id": "overscan_x" }, "overscan_y": { "offset": { "ubo": null, "push": 40 }, "size": 1, "id": "overscan_y" }, "cornersize": { "offset": { "ubo": null, "push": 20 }, "size": 1, "id": "cornersize" }, "cornersmooth": { "offset": { "ubo": null, "push": 24 }, "size": 1, "id": "cornersmooth" }, "CRTgamma": { "offset": { "ubo": null, "push": 4 }, "size": 1, "id": "CRTgamma" }, "scanline_weight": { "offset": { "ubo": null, "push": 52 }, "size": 1, "id": "scanline_weight" }, "lum": { "offset": { "ubo": null, "push": 64 }, "size": 1, "id": "lum" }, "DOTMASK": { "offset": { "ubo": null, "push": 44 }, "size": 1, "id": "DOTMASK" }, "monitorgamma": { "offset": { "ubo": null, "push": 8 }, "size": 1, "id": "monitorgamma" } }, "unique": { ``` -------------------------------- ### Initialize and Render with wgpu Runtime Source: https://context7.com/snowflakepowered/librashader/llms.txt Demonstrates cross-platform shader rendering using the wgpu runtime. Some WGSL features may be unsupported. ```rust use librashader::presets::ShaderPreset; use librashader::runtime::wgpu::{ FilterChain, FilterChainOptions, FrameOptions, WgpuOutputView }; use librashader::runtime::Viewport; use wgpu::{Device, Queue, TextureView}; let preset = ShaderPreset::try_parse("shaders/scalefx.slangp")?; let options = FilterChainOptions { force_no_mipmaps: false, }; let mut filter_chain = FilterChain::load_from_preset( preset, &device, &queue, Some(&options) )?; // Render frame let output_view = WgpuOutputView::new(&output_texture_view, output_size); let viewport = Viewport { x: 0.0, y: 0.0, output: output_view, mvp: None, }; filter_chain.frame( &device, &input_texture_view, &viewport, &mut encoder, frame_count, Some(&FrameOptions::default()) )?; ``` -------------------------------- ### Build project via command line Source: https://github.com/snowflakepowered/librashader/blob/master/test/capi-tests/imgui/examples/example_glfw_vulkan/CMakeLists.txt Standard commands to initialize the build directory and generate project files using CMake. ```bash mkdir build cd build cmake -g "Visual Studio 14 2015" .. ``` -------------------------------- ### CLI Usage Source: https://github.com/snowflakepowered/librashader/blob/master/README.md Command-line interface help output for rendering, comparing, and inspecting shader presets. ```text Usage: librashader-cli Commands: render Render a shader preset against an image compare Compare two runtimes and get a similarity score between the two runtimes rendering the same frame parse Parse a preset and get a JSON representation of the data pack Create a serialized preset pack from a shader preset preprocess Get the raw GLSL output of a preprocessed shader transpile Transpile a shader in a given preset to the given format reflect Reflect the shader relative to a preset, giving information about semantics used in a slang shader help Print this message or the help of the given subcommand(s) Options: -h, --help Print help -V, --version Print version ``` -------------------------------- ### View CLI Help Source: https://github.com/snowflakepowered/librashader/blob/master/CLI.md Displays the available commands and options for the librashader CLI. ```text Helpers and utilities to reflect and debug 'slang' shaders and presets Usage: librashader-cli Commands: render Render a shader preset against an image compare Compare two runtimes and get a similarity score between the two runtimes rendering the same frame parse Parse a preset and get a JSON representation of the data pack Create a serialized preset pack from a shader preset preprocess Get the raw GLSL output of a preprocessed shader transpile Transpile a shader in a given preset to the given format reflect Reflect the shader relative to a preset, giving information about semantics used in a slang shader help Print this message or the help of the given subcommand(s) Options: -h, --help Print help -V, --version Print version ``` -------------------------------- ### Get Shader Pass Reflection Info Source: https://context7.com/snowflakepowered/librashader/llms.txt The `reflect` command retrieves reflection information for a specific shader pass within a preset. The `-b naga` option can be used for reflection via the Naga backend. ```bash librashader-cli reflect -p preset.slangp -i 0 ``` ```bash librashader-cli reflect -p preset.slangp -i 0 -b naga ``` -------------------------------- ### View Render Command Help Source: https://github.com/snowflakepowered/librashader/blob/master/CLI.md Displays detailed usage information and options for the render command. ```text Render a shader preset against an image Usage: librashader-cli render [OPTIONS] --preset --image --out --runtime Options: -p, --preset The path to the shader preset to load -w, --wildcards ... Additional wildcard options, comma separated with equals signs. The PRESET and PRESET_DIR wildcards are always added to the preset parsing context. For example, CONTENT-DIR=MyVerticalGames,GAME=mspacman -f, --frame The frame to render. The renderer will run up to the number of frames specified here to ensure feedback and history. [default: 0] -d, --dimensions The dimensions of the image. This is given in either explicit dimensions `WIDTHxHEIGHT`, or a percentage of the input image in `SCALE%`. --params ... Parameters to pass to the shader preset, comma separated with equals signs. For example, crt_gamma=2.5,halation_weight=0.001 --passes-enabled Set the number of passes enabled for the preset -i, --image The path to the input image --frame-direction The direction of rendering. -1 indicates that the frames are played in reverse order [default: 1] --rotation The rotation of the output. 0 = 0deg, 1 = 90deg, 2 = 180deg, 3 = 270deg [default: 0] --total-subframes The total number of subframes ran. Default is 1 [default: 1] --current-subframe The current sub frame. Default is 1 [default: 1] --aspect-ratio The aspect ratio of the source. The default is 0, which will infer the ratio from the input --frames-per-second Frames per second of the source. The default is 1 --frametime-delta The time between the previous and current frame. The default is 0 -o, --out The path to the output image If `-`, writes the image in PNG format to stdout. -r, --runtime The runtime to use to render the shader preset [possible values: opengl3, opengl4, vulkan, wgpu, d3d9, d3d11, d3d12, metal] -h, --help Print help (see a summary with '-h') ``` -------------------------------- ### Preprocess GLSL Source of a .slang Shader Source: https://github.com/snowflakepowered/librashader/blob/master/CLI.md Use the `preprocess` command to get the raw GLSL output of a preprocessed shader. Specify the shader path and the desired output type (fragment, vertex, params, passformat, json). ```bash $ librashader-cli preprocess -s crt-geom.slang -o fragment ``` ```bash $ librashader-cli preprocess -s crt-geom.slang -o params | jq 'first(.[])' ``` -------------------------------- ### Initialize and Render with Metal Runtime Source: https://context7.com/snowflakepowered/librashader/llms.txt Demonstrates loading a shader preset and rendering a frame using the Metal runtime. Note that the Metal runtime is not thread-safe. ```rust use librashader::presets::ShaderPreset; use librashader::runtime::mtl::{ FilterChain, FilterChainOptions, FrameOptions, MetalTextureRef }; use librashader::runtime::Viewport; use objc2_metal::{MTLCommandQueue, MTLTexture}; let preset = ShaderPreset::try_parse("shaders/crt-geom.slangp")?; let options = FilterChainOptions { force_no_mipmaps: false, }; let mut filter_chain = unsafe { FilterChain::load_from_preset(preset, command_queue.clone(), Some(&options))? }; // Deferred creation let mut filter_chain = unsafe { FilterChain::load_from_preset_deferred( preset, command_queue.clone(), command_buffer, Some(&options) )? }; // Render frame let viewport = Viewport { x: 0.0, y: 0.0, output: MetalTextureRef::new(&output_texture), mvp: None, }; unsafe { filter_chain.frame( MetalTextureRef::new(&input_texture), &viewport, command_buffer, frame_count, Some(&FrameOptions::default()) )?; } ``` -------------------------------- ### Initialize and Render with Vulkan Filter Chain Source: https://context7.com/snowflakepowered/librashader/llms.txt Supports both standard and deferred creation for asynchronous GPU initialization. Input images must use VK_SHADER_READ_ONLY_OPTIMAL layout, and output images must use VK_COLOR_ATTACHMENT_OPTIMAL. ```c #define LIBRA_RUNTIME_VULKAN #include "librashader_ld.h" // Setup Vulkan device info libra_device_vk_t vulkan = { .physical_device = physical_device, .instance = instance, .device = device, .queue = graphics_queue, .entry = vkGetInstanceProcAddr }; filter_chain_vk_opt_t options = { .version = LIBRASHADER_CURRENT_VERSION, .frames_in_flight = 3, .force_no_mipmaps = false, .use_dynamic_rendering = true, .disable_cache = false }; libra_vk_filter_chain_t chain = NULL; libra_vk_filter_chain_create(&preset, vulkan, &options, &chain); // Or deferred creation for async GPU init libra_vk_filter_chain_create_deferred( &preset, vulkan, command_buffer, &options, &chain ); // Submit command_buffer and wait before calling frame // Render frame - input must be VK_SHADER_READ_ONLY_OPTIMAL libra_image_vk_t input = { .handle = source_image, .format = VK_FORMAT_R8G8B8A8_UNORM, .width = 256, .height = 224 }; // Output must be VK_COLOR_ATTACHMENT_OPTIMAL libra_image_vk_t output = { .handle = target_image, .format = VK_FORMAT_R8G8B8A8_UNORM, .width = 1920, .height = 1080 }; frame_vk_opt_t frame_options = { .version = LIBRASHADER_CURRENT_VERSION, .clear_history = false, .frame_direction = 1, .rotation = 0 }; libra_vk_filter_chain_frame( &chain, command_buffer, frame_count, input, output, NULL, NULL, &frame_options ); libra_vk_filter_chain_free(&chain); ``` -------------------------------- ### Build Commands Source: https://github.com/snowflakepowered/librashader/blob/master/README.md Commands for adding the crate to a project and building the C-compatible dynamic library. ```bash cargo add librashader ``` ```bash cargo run -p librashader-build-script -- --profile optimized ``` -------------------------------- ### Manage Shader Presets with C API Source: https://context7.com/snowflakepowered/librashader/llms.txt Shows how to load, configure, and inspect shader presets using the C API dynamic loader. ```c #include "librashader_ld.h" // Initialize librashader - loads library from search path if (libra_instance_abi_version() == 0) { // Library not loaded return -1; } // Load a shader preset libra_shader_preset_t preset = NULL; libra_error_t error = libra_preset_create("shaders/crt-geom.slangp", &preset); if (error) { libra_error_print(error); libra_error_free(&error); return -1; } // Load with wildcard context libra_preset_ctx_t context = NULL; libra_preset_ctx_create(&context); libra_preset_ctx_set_core_name(&context, "mgba"); libra_preset_ctx_set_content_dir(&context, "/roms/gba"); libra_preset_ctx_set_runtime(&context, LIBRA_PRESET_CTX_RUNTIME_VULKAN); libra_shader_preset_t preset = NULL; libra_preset_create_with_context("shaders/mega-bezel.slangp", &context, &preset); // context is invalidated after this call // Get and modify parameters float value; libra_preset_get_param(&preset, "crt_gamma", &value); libra_preset_set_param(&preset, "crt_gamma", 2.4f); // Get runtime parameter list libra_preset_param_list_t params; libra_preset_get_runtime_params(&preset, ¶ms); for (uint64_t i = 0; i < params.length; i++) { printf("Param: %s, default: %f\n", params.parameters[i].name, params.parameters[i].initial); } libra_preset_free_runtime_params(params); // Cleanup libra_preset_free(&preset); ``` -------------------------------- ### Load and Parse Shader Presets in Rust Source: https://context7.com/snowflakepowered/librashader/llms.txt Demonstrates loading shader presets using standard and wildcard contexts, and accessing preset metadata and parameters. ```rust use librashader::presets::ShaderPreset; use librashader::presets::context::WildcardContext; use std::path::Path; // Basic preset loading let preset = ShaderPreset::try_parse("shaders/crt-royale.slangp") .expect("Failed to parse preset"); // Loading with wildcard context for dynamic path resolution let mut context = WildcardContext::new(); context.set_core_name("mgba"); context.set_content_dir("/roms/gba"); let preset = ShaderPreset::try_parse_with_context( "shaders/mega-bezel.slangp", context ).expect("Failed to parse preset with context"); // Access preset information println!("Shader count: {}", preset.passes.len()); println!("Texture count: {}", preset.textures.len()); // Get shader parameters for runtime adjustment for (name, param) in &preset.parameters { println!("Parameter: {} = {} (range: {} to {})", name, param.value, param.minimum, param.maximum); } ``` -------------------------------- ### librashader-cli Overview Source: https://github.com/snowflakepowered/librashader/blob/master/CLI.md Provides a general overview of the librashader-cli tool, its purpose, and available commands. ```APIDOC ## librashader-cli Overview ### Description Helpers and utilities to reflect and debug 'slang' shaders and presets. ### Usage librashader-cli ### Commands - render: Render a shader preset against an image - compare: Compare two runtimes and get a similarity score between the two runtimes rendering the same frame - parse: Parse a preset and get a JSON representation of the data - pack: Create a serialized preset pack from a shader preset - preprocess: Get the raw GLSL output of a preprocessed shader - transpile: Transpile a shader in a given preset to the given format - reflect: Reflect the shader relative to a preset, giving information about semantics used in a slang shader - help: Print this message or the help of the given subcommand(s) ### Options - -h, --help: Print help - -V, --version: Print version ``` -------------------------------- ### Render Shader Preset with Parameters Source: https://context7.com/snowflakepowered/librashader/llms.txt Use the `render` command to apply a shader preset to an input image, specifying parameters for customization. Ensure the preset and parameters are correctly formatted. ```bash librashader-cli render \ -i input.png \ -p shaders/crt-geom.slangp \ -r opengl4 \ --params crt_gamma=2.5,CURVATURE=1.0 \ -o output.png ``` -------------------------------- ### Compare Runtime Shader Outputs Source: https://context7.com/snowflakepowered/librashader/llms.txt Use the `compare` command to generate a difference image between the outputs of two different rendering backends (e.g., OpenGL and Vulkan) for the same shader and input. ```bash librashader-cli compare \ -i input.png \ -p shaders/crt-geom.slangp \ -l opengl4 \ -r vulkan \ -o diff.png ``` -------------------------------- ### Implement OpenGL Filter Chain in Rust Source: https://context7.com/snowflakepowered/librashader/llms.txt Shows how to initialize an OpenGL filter chain from a preset and render frames using the glow context. ```rust use librashader::presets::ShaderPreset; use librashader::runtime::gl::{FilterChain, FilterChainOptions, FrameOptions, GLImage}; use librashader::runtime::{Size, Viewport}; use std::sync::Arc; use glow::Context; // Create filter chain from preset let preset = ShaderPreset::try_parse("shaders/crt-geom.slangp")?; let options = FilterChainOptions { glsl_version: 330, use_dsa: true, // Enable Direct State Access for OpenGL 4.6+ force_no_mipmaps: false, disable_cache: false, }; let gl_context: Arc = /* your glow context */; let mut filter_chain = unsafe { FilterChain::load_from_preset(preset, gl_context, Some(&options))? }; // Render a frame let input_image = GLImage { handle: input_texture_id, format: gl::RGBA8, width: 256, height: 224, }; let output_image = GLImage { handle: output_texture_id, format: gl::RGBA8, width: 1920, height: 1080, }; let viewport = Viewport { x: 0.0, y: 0.0, output: &output_image, mvp: None, // Use default MVP matrix }; let frame_options = FrameOptions { clear_history: false, frame_direction: 1, rotation: 0, total_subframes: 1, current_subframe: 1, }; unsafe { filter_chain.frame(&input_image, &viewport, frame_count, Some(&frame_options))?; } ``` -------------------------------- ### CLI Command: parse Source: https://github.com/snowflakepowered/librashader/blob/master/CLI.md Parses a shader preset file and returns its data in JSON format. ```APIDOC ## CLI Command: parse ### Description Parses a shader preset file and outputs a JSON representation of the preset data. Paths are resolved relative to the preset file location. ### Method CLI Command ### Endpoint librashader-cli parse ### Parameters #### Options - **--preset, -p** (string) - Required - The path to the shader preset to load. - **--wildcards, -w** (string) - Optional - Additional wildcard options, comma separated with equals signs (e.g., CONTENT-DIR=MyVerticalGames,GAME=mspacman). ### Request Example $ librashader-cli parse -p crt-geom.slangp ### Response #### Success Response (200) - **shader_count** (integer) - Total number of shaders in the preset. - **shaders** (array) - List of shader objects containing path, alias, filter, wrap_mode, and scaling configuration. #### Response Example { "shader_count": 12, "shaders": [ { "id": 0, "path": "/tmp/shaders_slang/crt/shaders/crt-royale/src/crt-royale-first-pass-linearize-crt-gamma-bob-fields.slang", "alias": "ORIG_LINEARIZED", "filter": "Nearest", "wrap_mode": "ClampToBorder", "frame_count_mod": 0, "srgb_framebuffer": true, "float_framebuffer": false, "mipmap_input": false, "scaling": { "valid": true, "x": { "scale_type": "Input", "factor": { "Float": 1.0 } }, "y": { "scale_type": "Input", "factor": { "Float": 1.0 } } } } ] } ``` -------------------------------- ### Render Shader Preset with Wildcards Source: https://context7.com/snowflakepowered/librashader/llms.txt The `render` command supports wildcards in the preset path for dynamic resolution of content directories and core types. This is useful for managing multiple game configurations. ```bash librashader-cli render \ -i input.png \ -p shaders/mega-bezel.slangp \ -w CONTENT-DIR=VerticalGames,CORE=mgba \ -r vulkan \ -o output.png ``` -------------------------------- ### Serialize a preset pack via CLI Source: https://github.com/snowflakepowered/librashader/blob/master/CLI.md Command-line interface usage for packing shader presets into JSON or MessagePack formats. ```bash Create a serialized preset pack from a shader preset Usage: librashader-cli pack [OPTIONS] --preset --out --format Options: -p, --preset The path to the shader preset to load -w, --wildcards ... Additional wildcard options, comma separated with equals signs. The PRESET and PRESET_DIR wildcards are always added to the preset parsing context. For example, CONTENT-DIR=MyVerticalGames,GAME=mspacman -o, --out The path to write the output If `-`, writes the output to stdout -f, --format The file format to output [possible values: json, msgpack] -d, --features Enable the defines for certain shader features. [possible values: originalaspect-uniforms, frametime-uniforms] -h, --help Print help (see a summary with '-h') ``` -------------------------------- ### SPIR-V Entry Point Export Source: https://github.com/snowflakepowered/librashader/blob/master/test/extreme_basic_split.structured.spirt.html Exports the function F1 as the main entry point for fragment execution. ```spirv export { spv.OpEntryPoint(spv.ExecutionModel.Fragment, Name: "main"): [F1](#F1), } ``` -------------------------------- ### Load a shader preset using librashader_ld.h Source: https://github.com/snowflakepowered/librashader/blob/master/include/README.md Uses the dynamic loader header to initialize an instance and create an OpenGL filter chain from a preset path. ```c++ #include "librashader_ld.h" libra_gl_filter_chain_t load_gl_filter_chain(libra_gl_loader_t opengl, const char *preset_path) { libra_instance_t librashader = librashader_load_instance(); if (!librashader.instance_loaded) { std::cout << "Could not load librashader\n"; return NULL; } libra_shader_preset_t preset; libra_error_t error = librashader.preset_create(preset_path, &preset); if (error != NULL) { std::cout << "Could not load preset\n"; return NULL; } libra_gl_filter_chain_t chain; if (librashader.gl_filter_chain_create(&preset, opengl, NULL, &chain) { std::cout << "Could not create OpenGL filter chain\n"; } return chain; } ``` -------------------------------- ### Transpile .slang to Target Shader Format Source: https://github.com/snowflakepowered/librashader/blob/master/CLI.md Use the `transpile` command to convert a .slang shader to a target format like GLSL, HLSL, WGSL, MSL, or SPIR-V. Specify the shader path, stage, format, and optionally the version and features. ```bash $ librashader-cli transpile -s crt-geom.slang -o fragment -f hlsl -v 60 ``` -------------------------------- ### Pack Shader Preset to Single File Source: https://context7.com/snowflakepowered/librashader/llms.txt The `pack` command bundles a shader preset and its dependencies into a single file, using MessagePack format by default. This is useful for distribution. ```bash librashader-cli pack \ -p shaders/crt-royale.slangp \ -f msgpack \ -o preset.pack ``` -------------------------------- ### Initialize and Render with OpenGL Filter Chain Source: https://context7.com/snowflakepowered/librashader/llms.txt Requires a GL function loader callback and specific options for GLSL version and DSA usage. The preset object is invalidated upon successful chain creation. ```c #define LIBRA_RUNTIME_OPENGL #include "librashader_ld.h" // GL function loader callback const void* gl_loader(const char* name) { return (const void*)glfwGetProcAddress(name); } // Create filter chain libra_gl_filter_chain_t chain = NULL; filter_chain_gl_opt_t options = { .version = LIBRASHADER_CURRENT_VERSION, .glsl_version = 330, .use_dsa = true, .force_no_mipmaps = false, .disable_cache = false }; libra_error_t error = libra_gl_filter_chain_create( &preset, gl_loader, &options, &chain ); // preset is invalidated after this call // Render a frame libra_image_gl_t input = { .handle = input_texture, .format = GL_RGBA8, .width = 256, .height = 224 }; libra_image_gl_t output = { .handle = output_texture, .format = GL_RGBA8, .width = 1920, .height = 1080 }; libra_viewport_t viewport = { .x = 0, .y = 0, .width = 1920, .height = 1080 }; frame_gl_opt_t frame_options = { .version = LIBRASHADER_CURRENT_VERSION, .clear_history = false, .frame_direction = 1, .rotation = 0, .total_subframes = 1, .current_subframe = 1 }; libra_gl_filter_chain_frame( &chain, frame_count, input, output, &viewport, NULL, &frame_options ); // Set shader parameters at runtime libra_gl_filter_chain_set_param(&chain, "crt_gamma", 2.5f); // Get active pass count uint32_t pass_count; libra_gl_filter_chain_get_active_pass_count(&chain, &pass_count); // Cleanup libra_gl_filter_chain_free(&chain); ``` -------------------------------- ### Librashader CLI Parse Command Usage Source: https://github.com/snowflakepowered/librashader/blob/master/CLI.md This describes the command-line interface for parsing shader presets. Use the --preset option to specify the shader file and --wildcards for additional options. ```bash librashader-cli parse [OPTIONS] --preset Options: -p, --preset The path to the shader preset to load -w, --wildcards ... Additional wildcard options, comma separated with equals signs. The PRESET and PRESET_DIR wildcards are always added to the preset parsing context. For example, CONTENT-DIR=MyVerticalGames,GAME=mspacman -h, --help Print help (see a summary with '-h') ``` -------------------------------- ### SPIR-V Fragment Entry Point 'main' (F1) Source: https://github.com/snowflakepowered/librashader/blob/master/test/extreme_basic_split.spirt.html The main entry point for a fragment shader. It loads data, calls another function (F0), and stores the result to the output variable. This function orchestrates shader execution. ```spirv #[spv.ExecutionMode.OriginUpperLeft] [func F1](#F1)() { [](#F1.AA.0)[](#F1.AA.1) _ = [](#F1.AA.2)spv.OpLoad(Pointer: &[GV1](#GV1)): [T0](#T0) _ = [](#F1.AA.3)spv.OpLoad(Pointer: &[GV2](#GV2)): spv.OpTypeSampler branch [L0](#F1.L0) [label L0](#F1.L0): [](#F1.AA.4)[](#F1.AA.5)[](#F1.AA.6) call [F0](#F0)() [v0](#F1.v0) = [](#F1.AA.7)spv.OpLoad(Pointer: &[GV3](#GV3)): f32×4 [](#F1.AA.8) spv.OpStore(Pointer: &[GV0](#GV0), Object: [v0](#F1.v0)) return } ``` -------------------------------- ### Render Shader to Image via CLI Source: https://context7.com/snowflakepowered/librashader/llms.txt Use the librashader-cli tool to apply shader presets to images with support for custom dimensions, frame selection, and various graphics backends. ```bash # Install CLI tool cargo install librashader-cli # Apply shader preset to an image librashader-cli render \ -i input.png \ -p shaders/crt-royale.slangp \ -r opengl3 \ -o output.png # Render specific frame (for animated presets) librashader-cli render \ -i input.png \ -p shaders/mega-bezel.slangp \ -f 120 \ -r vulkan \ -o output.png # Custom output dimensions librashader-cli render \ -i input.png \ -p shaders/crt-geom.slangp \ -r d3d11 \ -d 1920x1080 \ -o output.png # Scale relative to input librashader-cli render \ -i input.png \ -p shaders/scalefx.slangp \ -r wgpu \ -d 400% \ -o output.png ``` -------------------------------- ### Transpile Shader to Target Format Source: https://context7.com/snowflakepowered/librashader/llms.txt Use the `transpile` command to convert a slang shader into various target formats like HLSL, GLSL, SPIR-V, WGSL, or MSL. Specify the output format and version as needed. ```bash librashader-cli transpile -s shader.slang -o fragment -f hlsl -v 60 ``` ```bash librashader-cli transpile -s shader.slang -o vertex -f glsl -v 330 ``` ```bash librashader-cli transpile -s shader.slang -o fragment -f spirv ``` ```bash librashader-cli transpile -s shader.slang -o fragment -f wgsl ``` ```bash librashader-cli transpile -s shader.slang -o fragment -f msl -v 3_1 ``` -------------------------------- ### Build C API with Stable Feature Source: https://github.com/snowflakepowered/librashader/blob/master/README.md Use this command to build the C API of librashader with the `--stable` flag, which enables the `stable` feature for stable Rust compatibility. Note that C headers will not be regenerated when using this feature. ```bash cargo +stable run -p librashader-build-script -- --profile optimized --stable ``` -------------------------------- ### librashader-cli pack Source: https://github.com/snowflakepowered/librashader/blob/master/CLI.md Serializes a shader preset into a single file (JSON or MessagePack). This format is useful for caching or environments without filesystem access. ```APIDOC ## POST /api/pack ### Description Creates a serialized preset pack from a shader preset. ### Method POST ### Endpoint /api/pack ### Parameters #### Query Parameters - **preset** (string) - Required - The path to the shader preset to load. - **out** (string) - Required - The path to write the output. Use '-' for stdout. - **format** (string) - Required - The file format to output. Possible values: json, msgpack. - **wildcards** (array of strings) - Optional - Additional wildcard options, comma separated with equals signs (e.g., CONTENT-DIR=MyVerticalGames,GAME=mspacman). - **features** (array of strings) - Optional - Enable the defines for certain shader features. Possible values: originalaspect-uniforms, frametime-uniforms. ### Request Example ```json { "preset": "/path/to/shader.slangp", "out": "output.pack", "format": "json", "wildcards": ["CONTENT-DIR=MyGames", "GAME=doom"], "features": ["originalaspect-uniforms"] } ``` ### Response #### Success Response (200) - **data** (string) - The serialized preset pack content. ``` -------------------------------- ### Reflect shader pass via CLI Source: https://github.com/snowflakepowered/librashader/blob/master/CLI.md Execute the reflection command by specifying the shader preset path and the target pass index. ```bash $ librashader-cli reflect -p crt-geom.slangp -i 0 ``` -------------------------------- ### Enable FreeType in imconfig.h Source: https://github.com/snowflakepowered/librashader/blob/master/test/capi-tests/imgui/misc/freetype/README.md Preprocessor directive required to enable FreeType support within the Dear ImGui configuration. ```cpp #define IMGUI_ENABLE_FREETYPE ``` -------------------------------- ### Initialize and Render with Direct3D 11 Filter Chain Source: https://context7.com/snowflakepowered/librashader/llms.txt Supports deferred creation using a device context. The frame rendering function accepts ID3D11ShaderResourceView and ID3D11RenderTargetView pointers. ```c #define LIBRA_RUNTIME_D3D11 #include "librashader_ld.h" filter_chain_d3d11_opt_t options = { .version = LIBRASHADER_CURRENT_VERSION, .force_no_mipmaps = false, .disable_cache = false }; libra_d3d11_filter_chain_t chain = NULL; libra_d3d11_filter_chain_create(&preset, device, &options, &chain); // Deferred creation with device context libra_d3d11_filter_chain_create_deferred( &preset, device, deferred_context, &options, &chain ); // Render frame libra_viewport_t viewport = { .x = 0, .y = 0, .width = 1920, .height = 1080 }; frame_d3d11_opt_t frame_options = { .version = LIBRASHADER_CURRENT_VERSION, .clear_history = false, .frame_direction = 1, .rotation = 0 }; libra_d3d11_filter_chain_frame( &chain, immediate_context, // or NULL for immediate context frame_count, input_srv, // ID3D11ShaderResourceView* output_rtv, // ID3D11RenderTargetView* &viewport, NULL, // MVP matrix (NULL for default) &frame_options ); libra_d3d11_filter_chain_free(&chain); ``` -------------------------------- ### Define shader uniform and texture mappings Source: https://github.com/snowflakepowered/librashader/blob/master/CLI.md Configuration structure for shader uniform offsets and texture bindings. ```json "MVP": { "offset": { "ubo": 0, "push": null }, "size": 16, "id": "MVP" }, "Output": { "offset": { "ubo": 64, "push": null }, "size": 4, "id": "OutputSize" }, "FrameCount": { "offset": { "ubo": null, "push": 0 }, "size": 1, "id": "FrameCount" } }, "texture": { "Source": { "binding": 2 } }, "texture_size": { "Source": { "offset": { "ubo": 80, "push": null }, "stage_mask": "VERTEX | FRAGMENT", "id": "SourceSize" } } } } ``` -------------------------------- ### SPIR-V Function F1: Fragment Entry Point Source: https://github.com/snowflakepowered/librashader/blob/master/test/extreme_basic_split.structured.spirt.html Sets the origin to upper left, loads variables, calls function F0, and stores the result to the output color variable. This function serves as the fragment shader entry point. ```spirv [](#F1)#\[spv.ExecutionMode.OriginUpperLeft\] [func F1](#F1)[](#F1.start)() { [](#F1.AA.0)[](#F1.AA.1) \_ = [](#F1.AA.2)spv.OpLoad(Pointer: &[GV1](#GV1)): [T0](#T0) \_ = [](#F1.AA.3)spv.OpLoad(Pointer: &[GV2](#GV2)): spv.OpTypeSampler [](#F1.AA.4)[](#F1.AA.5) call [F0](#F0) () [v0](#F1.v0) = [](#F1.AA.6)spv.OpLoad(Pointer: &[GV3](#GV3)): f32×4 [](#F1.AA.7) spv.OpStore(Pointer: &[GV0](#GV0), Object: [v0](#F1.v0)) } ``` -------------------------------- ### Parse Shader Preset with Wildcards Source: https://context7.com/snowflakepowered/librashader/llms.txt The `parse` command can also handle presets with wildcards by providing them via the `-w` flag, similar to the `render` command. ```bash librashader-cli parse \ -p shaders/mega-bezel.slangp \ -w CONTENT-DIR=MyGames ``` -------------------------------- ### Preprocessed Shader Parameters (JSON) Source: https://github.com/snowflakepowered/librashader/blob/master/CLI.md The `preprocess` command with the `json` output option provides meta information inferred from `#pragma` declarations in the source code. ```json { "CRTgamma": { "id": "CRTgamma", "description": "CRTGeom Target Gamma", "initial": 2.4, "minimum": 0.1, "maximum": 5.0, "step": 0.1 } } ``` -------------------------------- ### Direct3D 12 Filter Chain Implementation Source: https://context7.com/snowflakepowered/librashader/llms.txt Sets up a D3D12 filter chain, noting that input resources must be in the PIXEL_SHADER_RESOURCE state. ```rust use librashader::presets::ShaderPreset; use librashader::runtime::d3d12::{ FilterChain, FilterChainOptions, FrameOptions, D3D12InputImage, D3D12OutputView }; use librashader::runtime::Viewport; use windows::Win32::Graphics::Direct3D12::*; let preset = ShaderPreset::try_parse("shaders/mega-bezel.slangp")?; let options = FilterChainOptions { force_hlsl_pipeline: false, // Use SPIRV-to-DXIL by default force_no_mipmaps: false, disable_cache: false, }; let mut filter_chain = unsafe { FilterChain::load_from_preset(preset, &device, Some(&options))? }; // Deferred creation let mut filter_chain = unsafe { FilterChain::load_from_preset_deferred( preset, &device, &command_list, Some(&options) )? }; // Render frame - input must be in PIXEL_SHADER_RESOURCE state let input = D3D12InputImage { resource: source_resource.clone(), descriptor: source_srv_descriptor, size: Size::new(256, 224), format: DXGI_FORMAT_R8G8B8A8_UNORM, }; // Output must be in RENDER_TARGET state let output = D3D12OutputView { descriptor: output_rtv_descriptor, size: Size::new(1920, 1080), format: DXGI_FORMAT_R8G8B8A8_UNORM, }; let viewport = Viewport { x: 0.0, y: 0.0, output: &output, mvp: None, }; unsafe { filter_chain.frame( &command_list, &input, &viewport, frame_count, Some(&FrameOptions::default()) )?; } // Output remains in RENDER_TARGET state - caller must transition ```