Skip to content

Commit

Permalink
wrap readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Snektron committed Sep 25, 2023
1 parent 14259cc commit 1e4e90f
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,7 @@ For some times (such as those from Google Games Platform) no default is known. U

### Shader compilation

vulkan-zig provides functionality to help compile shaders to SPIR-V using glslc.
It can be used from build.zig as follows:
vulkan-zig provides functionality to help compile shaders to SPIR-V using glslc. It can be used from build.zig as follows:

```zig
const vkgen = @import("vulkan_zig");
Expand All @@ -300,22 +299,15 @@ pub fn build(b: *Builder) void {
const shader_comp = vkgen.ShaderCompileStep.create(
builder,
&[_][]const u8{"glslc", "--target-env=vulkan1.2"},
"-o",
"-o",
);
shader_comp.add("shader_frag", "path/to/shader.frag", .{});
shader_comp.add("shader_vert", "path/to/shader.vert", .{});
exe.addModule("shaders", shader_comp.getModule());
}
```

Upon compilation, glslc is invoked to compile each shader, and the result is
placed within `zig-cache`. All shaders which are compiled using a particular
`ShaderCompileStep` are imported in a single Zig file using `@embedFile`, and
this file can be added to an executable as a module using `addModule`. To
slightly improve compile times, shader compilation is cached; as long as a
shader's source and its compile commands stay the same, the shader is not
recompiled. The SPIR-V code for any particular shader is aligned to that of a
32-bit integer as follows, as required by vkCreateShaderModule:
Upon compilation, glslc is invoked to compile each shader, and the result is placed within `zig-cache`. All shaders which are compiled using a particular `ShaderCompileStep` are imported in a single Zig file using `@embedFile`, and this file can be added to an executable as a module using `addModule`. To slightly improve compile times, shader compilation is cached; as long as a shader's source and its compile commands stay the same, the shader is not recompiled. The SPIR-V code for any particular shader is aligned to that of a 32-bit integer as follows, as required by vkCreateShaderModule:

```zig
pub const ${name} align(@alignOf(u32)) = @embedFile("${path}").*;
Expand Down

0 comments on commit 1e4e90f

Please sign in to comment.