Skip to content

Commit

Permalink
Add motion texture with new Rg8 formats in blade-graphics
Browse files Browse the repository at this point in the history
  • Loading branch information
kvark committed Nov 20, 2023
1 parent 3531250 commit 8c85a15
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 5 deletions.
3 changes: 1 addition & 2 deletions blade-graphics/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ naga = { workspace = true, features = ["spv-out"] }
slab = { workspace = true }

[target.'cfg(any(gles, target_arch = "wasm32"))'.dependencies]
# Version contains `glGetProgramResource`
glow = "0.12.2"
glow = "0.13"
naga = { workspace = true, features = ["glsl-out"] }

[target.'cfg(all(gles, not(target_arch = "wasm32")))'.dependencies]
Expand Down
2 changes: 2 additions & 0 deletions blade-graphics/src/gles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,8 @@ struct FormatInfo {
fn describe_texture_format(format: crate::TextureFormat) -> FormatInfo {
use crate::TextureFormat as Tf;
let (internal, external, data_type) = match format {
Tf::Rg8Unorm => (glow::RG8, glow::RG, glow::UNSIGNED_BYTE),
Tf::Rg8Snorm => (glow::RG8, glow::RG, glow::BYTE),
Tf::Rgba8Unorm => (glow::RGBA8, glow::RGBA, glow::UNSIGNED_BYTE),
Tf::Rgba8UnormSrgb => (glow::SRGB8_ALPHA8, glow::RGBA, glow::UNSIGNED_BYTE),
Tf::Bgra8UnormSrgb => (glow::SRGB8_ALPHA8, glow::BGRA, glow::UNSIGNED_BYTE),
Expand Down
2 changes: 2 additions & 0 deletions blade-graphics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ impl From<Texture> for TexturePiece {
#[derive(Clone, Copy, Debug, Hash, Eq, Ord, PartialEq, PartialOrd)]
pub enum TextureFormat {
// color
Rg8Unorm,
Rg8Snorm,
Rgba8Unorm,
Rgba8UnormSrgb,
Bgra8UnormSrgb,
Expand Down
2 changes: 2 additions & 0 deletions blade-graphics/src/metal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@ fn map_texture_format(format: crate::TextureFormat) -> metal::MTLPixelFormat {
use crate::TextureFormat as Tf;
use metal::MTLPixelFormat::*;
match format {
Tf::Rg8Unorm => RG8Unorm,
Tf::Rg8Snorm => RG8Snorm,
Tf::Rgba8Unorm => RGBA8Unorm,
Tf::Rgba8UnormSrgb => RGBA8Unorm_sRGB,
Tf::Bgra8UnormSrgb => BGRA8Unorm_sRGB,
Expand Down
2 changes: 2 additions & 0 deletions blade-graphics/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ impl super::TextureFormat {
}
}
match *self {
Self::Rg8Unorm => uncompressed(2),
Self::Rg8Snorm => uncompressed(2),
Self::Rgba8Unorm => uncompressed(4),
Self::Rgba8UnormSrgb => uncompressed(4),
Self::Bgra8UnormSrgb => uncompressed(4),
Expand Down
2 changes: 2 additions & 0 deletions blade-graphics/src/vulkan/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,8 @@ impl crate::traits::CommandDevice for Context {
fn map_texture_format(format: crate::TextureFormat) -> vk::Format {
use crate::TextureFormat as Tf;
match format {
Tf::Rg8Unorm => vk::Format::R8G8_UNORM,
Tf::Rg8Snorm => vk::Format::R8G8_SNORM,
Tf::Rgba8Unorm => vk::Format::R8G8B8A8_UNORM,
Tf::Rgba8UnormSrgb => vk::Format::R8G8B8A8_SRGB,
Tf::Bgra8UnormSrgb => vk::Format::B8G8R8A8_SRGB,
Expand Down
15 changes: 12 additions & 3 deletions blade-render/src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ struct RestirTargets {
basis: RenderTarget<2>,
flat_normal: RenderTarget<2>,
albedo: RenderTarget<1>,
motion: RenderTarget<1>,
light_diffuse: RenderTarget<3>,
camera_params: [CameraParams; 2],
}
Expand Down Expand Up @@ -258,6 +259,13 @@ impl RestirTargets {
encoder,
gpu,
),
motion: RenderTarget::new(
"motion",
blade_graphics::TextureFormat::Rg8Snorm,
size,
encoder,
gpu,
),
light_diffuse: RenderTarget::new("light-diffuse", RADIANCE_FORMAT, size, encoder, gpu),
camera_params: [CameraParams::default(); 2],
}
Expand All @@ -272,6 +280,7 @@ impl RestirTargets {
self.basis.destroy(gpu);
self.flat_normal.destroy(gpu);
self.albedo.destroy(gpu);
self.motion.destroy(gpu);
self.light_diffuse.destroy(gpu);
}
}
Expand All @@ -291,7 +300,6 @@ struct Blur {
/// - manage or submit any command encoders
/// - know about the window to display on
pub struct Renderer {
config: RenderConfig,
shaders: Shaders,
targets: RestirTargets,
post_proc_input_index: usize,
Expand All @@ -310,6 +318,7 @@ pub struct Renderer {
reservoir_size: u32,
debug: DebugRender,
screen_size: blade_graphics::Extent,
screen_format: blade_graphics::TextureFormat,
frame_index: usize,
//TODO: refactor `ResourceArray` to not carry the freelist logic
// This way we can embed user info into the allocator.
Expand Down Expand Up @@ -659,7 +668,6 @@ impl Renderer {
};

Self {
config: *config,
shaders,
targets,
post_proc_input_index: 0,
Expand All @@ -681,6 +689,7 @@ impl Renderer {
reservoir_size: sp.reservoir_size,
debug,
screen_size: config.screen_size,
screen_format: config.surface_format,
frame_index: 0,
texture_resource_lookup: HashMap::default(),
}
Expand Down Expand Up @@ -754,7 +763,7 @@ impl Renderer {
if self.shaders.post_proc != old.post_proc {
if let Ok(ref shader) = asset_hub.shaders[self.shaders.post_proc].raw {
self.post_proc_pipeline =
ShaderPipelines::create_post_proc(shader, self.config.surface_format, gpu);
ShaderPipelines::create_post_proc(shader, self.screen_format, gpu);
}
}
if self.shaders.debug_draw != old.debug_draw {
Expand Down

0 comments on commit 8c85a15

Please sign in to comment.