-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6cdc3a0
commit 6926769
Showing
36 changed files
with
1,255 additions
and
213 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "screen-13" | ||
version = "0.7.1" | ||
version = "0.8.0" | ||
authors = ["John Wells <[email protected]>"] | ||
edition = "2021" | ||
license = "MIT OR Apache-2.0" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
[package] | ||
name = "screen-13-hot" | ||
version = "0.1.0" | ||
authors = ["John Wells <[email protected]>"] | ||
edition = "2021" | ||
license = "MIT OR Apache-2.0" | ||
readme = "README.md" | ||
repository = "https://github.com/attackgoat/screen-13" | ||
homepage = "https://github.com/attackgoat/screen-13/contrib/screen-13-hot" | ||
keywords = ["gamedev", "vulkan"] | ||
categories = ["game-development", "multimedia::images", "rendering::engine"] | ||
description = "Hot-reloading shader pipelines for Screen-13" | ||
|
||
[dependencies] | ||
anyhow = "1.0" | ||
derive_builder = "0.12" | ||
lazy_static = "1.4" | ||
notify = "5.0" | ||
screen-13 = { path = "../.."} | ||
shader-prepper = "0.3.0-pre.3" | ||
shaderc = "0.8" | ||
|
||
[dev-dependencies] | ||
pretty_env_logger = "0.4" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Screen 13 Hot | ||
|
||
Hot-reloading shader pipelines for _Screen 13_. Supports compute, graphic, and ray-trace shader | ||
pipelines. | ||
|
||
Based on shaderc. Feel free to submit PRs for other compilers. | ||
|
||
## Quick Start | ||
|
||
See the [example code](examples/README.md), | ||
|
||
## Basic usage | ||
|
||
See the [GLSL](examples/glsl.rs) and [HLSL](examples/hlsl.rs) examples for usage - the hot pipelines | ||
are drop-in replacements for the regular shader pipelines offered by _Screen 13_. | ||
|
||
After creating a pipeline two functions are available, `hot` or `cold`. The result of each may be | ||
bound to a render graph for any sort of regular use. | ||
|
||
- `hot()`: Returns the pipeline instance which includes any changes found on disk. | ||
- `cold()`: Returns the most recent successful compilation without watching for changes. | ||
|
||
## Advanced usage | ||
|
||
There are a few options available when creating a `HotShader` instance, which is a wrapper around | ||
regular `Shader` instances. These options allow you to set compilation settings such as optimization | ||
level and warnings-as-errors, among other things. | ||
|
||
## More infomation | ||
|
||
Run `cargo doc --open` to view detailed API documentation and find available compilation options. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# _Screen 13 Hot_ Example Code | ||
|
||
## Getting Started | ||
|
||
Hot-reloading shader pipelines are drop-in replacements for regular shader pipelines. Reference the | ||
below code to get started. | ||
|
||
See the [README](../README.md) for more information. | ||
|
||
## Example Code | ||
|
||
Example | Instructions | Preview | ||
--- | --- | :---: | ||
[glsl.rs](glsl.rs) | <pre>cargo run --example glsl</pre> | <image alt="Preview" src="../.github/img/noise.png" height=149 width=176> | ||
[hlsl.rs](hlsl.rs) | <pre>cargo run --example hlsl</pre> | <image alt="Preview" src="../.github/img/noise.png" height=149 width=176> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use { | ||
lazy_static::lazy_static, screen_13::prelude::*, screen_13_hot::prelude::*, std::path::PathBuf, | ||
}; | ||
|
||
lazy_static! { | ||
static ref CARGO_MANIFEST_DIR: PathBuf = PathBuf::from(env!("CARGO_MANIFEST_DIR")); | ||
} | ||
|
||
/// This program draws a noise signal to the swapchain - make changes to fill_image.comp or the | ||
/// noise.glsl file it includes to see those changes update while the program is still running. | ||
/// | ||
/// Run with RUST_LOG=info to get notification of shader compilations. | ||
fn main() -> Result<(), DisplayError> { | ||
pretty_env_logger::init(); | ||
|
||
let event_loop = EventLoop::new().build()?; | ||
|
||
// Create a compute pipeline - the same as normal except for "Hot" prefixes and we provide the | ||
// shader source code path instead of the shader source code bytes | ||
let mut pipeline = HotComputePipeline::create( | ||
&event_loop.device, | ||
ComputePipelineInfo::default(), | ||
HotShader::new_compute(CARGO_MANIFEST_DIR.join("examples/res/fill_image.comp")), | ||
)?; | ||
|
||
let mut frame_index: u32 = 0; | ||
|
||
event_loop.run(|frame| { | ||
frame | ||
.render_graph | ||
.begin_pass("make some noise") | ||
.bind_pipeline(pipeline.hot()) | ||
.write_descriptor(0, frame.swapchain_image) | ||
.record_compute(move |compute, _| { | ||
compute.push_constants(&frame_index.to_ne_bytes()).dispatch( | ||
frame.width, | ||
frame.height, | ||
1, | ||
); | ||
}); | ||
|
||
frame_index += 1; | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
use { | ||
lazy_static::lazy_static, screen_13::prelude::*, screen_13_hot::prelude::*, std::path::PathBuf, | ||
}; | ||
|
||
lazy_static! { | ||
static ref CARGO_MANIFEST_DIR: PathBuf = PathBuf::from(env!("CARGO_MANIFEST_DIR")); | ||
} | ||
|
||
/// This program draws a noise signal to the swapchain - make changes to fill_image.hlsl or the | ||
/// noise.hlsl file it includes to see those changes update while the program is still running. | ||
/// | ||
/// Run with RUST_LOG=info to get notification of shader compilations. | ||
fn main() -> Result<(), DisplayError> { | ||
pretty_env_logger::init(); | ||
|
||
let event_loop = EventLoop::new().build()?; | ||
|
||
// Create a graphic pipeline - the same as normal except for "Hot" prefixes and we provide the | ||
// shader source code path instead of the shader source code bytes | ||
let fill_image_path = CARGO_MANIFEST_DIR.join("examples/res/fill_image.hlsl"); | ||
let mut pipeline = HotGraphicPipeline::create( | ||
&event_loop.device, | ||
GraphicPipelineInfo::default(), | ||
[ | ||
HotShader::new_vertex(&fill_image_path).entry_name("vertex_main".to_string()), | ||
HotShader::new_fragment(&fill_image_path).entry_name("fragment_main".to_string()), | ||
], | ||
)?; | ||
|
||
let mut frame_index: u32 = 0; | ||
|
||
event_loop.run(|frame| { | ||
frame | ||
.render_graph | ||
.begin_pass("make some noise") | ||
.bind_pipeline(pipeline.hot()) | ||
.clear_color(0, frame.swapchain_image) | ||
.store_color(0, frame.swapchain_image) | ||
.record_subpass(move |subpass, _| { | ||
subpass | ||
.push_constants_offset(0, &frame_index.to_ne_bytes()) | ||
.push_constants_offset(4, &frame.width.to_ne_bytes()) | ||
.push_constants_offset(8, &frame.height.to_ne_bytes()) | ||
.draw(3, 1, 0, 0); | ||
}); | ||
|
||
frame_index += 1; | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#version 460 core | ||
|
||
#include "noise.glsl" | ||
|
||
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in; | ||
|
||
layout(push_constant) uniform PushConstants { | ||
layout(offset = 0) uint frame_index; | ||
} push_const; | ||
|
||
layout(set = 0, binding = 0, rgba32f) restrict writeonly uniform image2D image; | ||
|
||
void main() { | ||
uvec3 data = uvec3(gl_GlobalInvocationID.xy, push_const.frame_index); | ||
vec4 color = vec4(hash(data), 1.0); | ||
|
||
imageStore(image, ivec2(gl_GlobalInvocationID.xy), color); | ||
} |
Oops, something went wrong.