Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
259 changes: 143 additions & 116 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ objc2 = { version = "0.6" }
glow = { version = "0.16.0" }
glfw = { version = "0.59.0" }

wgpu = { version = "27", default-features = false }
wgpu-types = { version = "27" }
wgpu = { version = "28", default-features = false }
wgpu-types = { version = "28" }

clap = { version = "=4.3.0", features = ["derive"] }
rayon = { version = "1.10.0"}
Expand Down
9 changes: 9 additions & 0 deletions librashader-common/src/wgpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,15 @@ impl From<FilterMode> for wgpu_types::FilterMode {
}
}

impl From<FilterMode> for wgpu_types::MipmapFilterMode {
fn from(value: FilterMode) -> Self {
match value {
FilterMode::Linear => wgpu_types::MipmapFilterMode::Linear,
FilterMode::Nearest => wgpu_types::MipmapFilterMode::Nearest,
}
}
}

impl From<WrapMode> for wgpu_types::AddressMode {
fn from(value: WrapMode) -> Self {
match value {
Expand Down
2 changes: 1 addition & 1 deletion librashader-reflect/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ librashader-pack = { path = "../librashader-pack", version = "0.9.2" }

spirv-cross2 = { workspace = true, optional = true }

naga = { version = "27", optional = true }
naga = { version = "28", optional = true }
rspirv = { version = "0.12.0", optional = true }
spirv = { version = "0.3.0", optional = true}

Expand Down
4 changes: 3 additions & 1 deletion librashader-reflect/src/back/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,11 @@ where
mod test {
use crate::front::{Glslang, ShaderInputCompiler};
use librashader_preprocess::ShaderSource;
use librashader_presets::ShaderFeatures;

#[test]
pub fn test() {
let result = ShaderSource::load("../test/basic.slang").unwrap();
let result = ShaderSource::load("../test/basic.slang", ShaderFeatures::empty()).unwrap();
let _cross = Glslang::compile(&result).unwrap();
}
}
9 changes: 6 additions & 3 deletions librashader-reflect/src/back/wgsl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,17 @@ mod test {
use crate::reflect::naga::NagaLoweringOptions;
use crate::reflect::semantics::{Semantic, ShaderSemantics, UniformSemantic, UniqueSemantics};
use crate::reflect::ReflectShader;
use bitflags::Flags;
use librashader_common::map::{FastHashMap, ShortString};
use librashader_preprocess::ShaderSource;
use librashader_presets::ShaderFeatures;

#[test]
pub fn test_into() {
let result =
ShaderSource::load("../test/shaders_slang/crt/shaders/slotmask.slang").unwrap();
let result = ShaderSource::load(
"../test/shaders_slang/crt/shaders/slotmask.slang",
ShaderFeatures::empty(),
)
.unwrap();

// let result = ShaderSource::load("../test/shaders_slang/crt/shaders/crt-royale/src/crt-royale-scanlines-horizontal-apply-mask.slang").unwrap();
// let result = ShaderSource::load("../test/shaders_slang/crt/shaders/crt-royale/src/crt-royale-scanlines-horizontal-apply-mask.slang").unwrap();
Expand Down
3 changes: 2 additions & 1 deletion librashader-reflect/src/front/glslang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@ pub(crate) fn compile_spirv(source: &ShaderSource) -> Result<SpirvCompilation, S
mod test {
use crate::front::glslang::compile_spirv;
use librashader_preprocess::ShaderSource;
use librashader_presets::ShaderFeatures;
#[test]
pub fn compile_shader() {
let result = ShaderSource::load("../test/basic.slang").unwrap();
let result = ShaderSource::load("../test/basic.slang", ShaderFeatures::empty()).unwrap();
let _spirv = compile_spirv(&result).unwrap();
}
}
6 changes: 3 additions & 3 deletions librashader-reflect/src/reflect/cross/msl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,22 +112,22 @@ impl CompileShader<MSL> for CrossReflect<targets::Msl> {

#[cfg(test)]
mod test {
use crate::back::targets::{MSL, WGSL};
use crate::back::targets::MSL;
use crate::back::{CompileShader, FromCompilation};
use crate::reflect::cross::SpirvCross;
use crate::reflect::semantics::{Semantic, ShaderSemantics, UniformSemantic, UniqueSemantics};
use crate::reflect::ReflectShader;
use bitflags::Flags;
use librashader_common::map::{FastHashMap, ShortString};
use librashader_preprocess::ShaderSource;

use librashader_presets::ShaderFeatures;
use spirv_cross2::compile::msl::MslVersion;

#[test]
pub fn test_into() {
// let result = ShaderSource::load("../test/shaders_slang/crt/shaders/crt-royale/src/crt-royale-scanlines-horizontal-apply-mask.slang").unwrap();
// let result = ShaderSource::load("../test/shaders_slang/crt/shaders/crt-royale/src/crt-royale-scanlines-horizontal-apply-mask.slang").unwrap();
let result = ShaderSource::load("../test/basic.slang").unwrap();
let result = ShaderSource::load("../test/basic.slang", ShaderFeatures::empty()).unwrap();

let mut uniform_semantics: FastHashMap<ShortString, UniformSemantic> = Default::default();

Expand Down
18 changes: 9 additions & 9 deletions librashader-reflect/src/reflect/naga/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,19 @@ impl NagaReflect {
pub fn do_lowering(&mut self, options: &NagaLoweringOptions) {
if options.write_pcb_as_ubo {
for (_, gv) in self.fragment.global_variables.iter_mut() {
if gv.space == AddressSpace::PushConstant {
if gv.space == AddressSpace::Immediate {
gv.space = AddressSpace::Uniform;
}
}

for (_, gv) in self.vertex.global_variables.iter_mut() {
if gv.space == AddressSpace::PushConstant {
if gv.space == AddressSpace::Immediate {
gv.space = AddressSpace::Uniform;
}
}
} else {
for (_, gv) in self.fragment.global_variables.iter_mut() {
if gv.space == AddressSpace::PushConstant {
if gv.space == AddressSpace::Immediate {
gv.binding = None;
}
}
Expand Down Expand Up @@ -545,7 +545,7 @@ impl NagaReflect {
.vertex
.global_variables
.iter()
.filter(|(_, gv)| gv.space == AddressSpace::PushConstant)
.filter(|(_, gv)| gv.space == AddressSpace::Immediate)
.count();

if push_buffer_count > 1 {
Expand Down Expand Up @@ -598,7 +598,7 @@ impl NagaReflect {
.fragment
.global_variables
.iter()
.filter(|(_, gv)| gv.space == AddressSpace::PushConstant)
.filter(|(_, gv)| gv.space == AddressSpace::Immediate)
.count();

if push_buffer_count > 1 {
Expand Down Expand Up @@ -920,7 +920,7 @@ impl ReflectShader for NagaReflect {
.global_variables
.iter()
.find_map(|(handle, gv)| {
if gv.space == AddressSpace::PushConstant {
if gv.space == AddressSpace::Immediate {
Some(handle)
} else {
None
Expand All @@ -932,7 +932,7 @@ impl ReflectShader for NagaReflect {
.global_variables
.iter()
.find_map(|(handle, gv)| {
if gv.space == AddressSpace::PushConstant {
if gv.space == AddressSpace::Immediate {
Some(handle)
} else {
None
Expand Down Expand Up @@ -1024,7 +1024,7 @@ impl ReflectShader for NagaReflect {
.global_variables
.iter()
.find_map(|(handle, gv)| {
if gv.space == AddressSpace::PushConstant {
if gv.space == AddressSpace::Immediate {
Some(handle)
} else {
None
Expand All @@ -1036,7 +1036,7 @@ impl ReflectShader for NagaReflect {
.global_variables
.iter()
.find_map(|(handle, gv)| {
if gv.space == AddressSpace::PushConstant {
if gv.space == AddressSpace::Immediate {
Some(handle)
} else {
None
Expand Down
1 change: 1 addition & 0 deletions librashader-runtime-wgpu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,4 @@ raw-window-handle = "0.6.0"
winit = "0.29.10"
pollster = "0.3"
log = "0.4.20"
wgpu = { workspace = true, default-features = true }
27 changes: 3 additions & 24 deletions librashader-runtime-wgpu/src/filter_pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,14 @@ use librashader_common::map::FastHashMap;
use librashader_common::{ImageFormat, Size, Viewport};
use librashader_preprocess::ShaderSource;
use librashader_presets::PassMeta;
use librashader_reflect::reflect::semantics::{
BindingStage, MemberOffset, TextureBinding, UniformBinding,
};
use librashader_reflect::reflect::semantics::{MemberOffset, TextureBinding, UniformBinding};
use librashader_reflect::reflect::ShaderReflection;
use librashader_runtime::binding::{BindSemantics, TextureInput, UniformInputs};
use librashader_runtime::filter_pass::FilterPassMeta;
use librashader_runtime::quad::QuadType;
use librashader_runtime::render_target::RenderTarget;
use librashader_runtime::uniforms::{NoUniformBinder, UniformStorage, UniformStorageAccess};
use wgpu::{BindGroupDescriptor, BindGroupEntry, BindingResource, BufferBinding, ShaderStages};
use librashader_runtime::uniforms::{NoUniformBinder, UniformStorage};
use wgpu::{BindGroupDescriptor, BindGroupEntry, BindingResource, BufferBinding};

pub struct FilterPass {
pub reflection: ShaderReflection,
Expand Down Expand Up @@ -145,7 +143,6 @@ impl FilterPass {
});
}

let mut has_pcb_buffer = false;
if let Some(pcb) = &self.reflection.push_constant {
if let Some(binding) = pcb.binding {
main_heap_array.push(BindGroupEntry {
Expand All @@ -156,7 +153,6 @@ impl FilterPass {
size: None,
}),
});
has_pcb_buffer = true;
}
}

Expand All @@ -175,25 +171,8 @@ impl FilterPass {
let mut render_pass = self.graphics_pipeline.begin_rendering(output, cmd);

render_pass.set_bind_group(0, &main_bind_group, &[]);

render_pass.set_bind_group(1, &sampler_bind_group, &[]);

if let Some(push) = &self
.reflection
.push_constant
.as_ref()
.filter(|_| !has_pcb_buffer)
{
let mut stage_mask = ShaderStages::empty();
if push.stage_mask.contains(BindingStage::FRAGMENT) {
stage_mask |= ShaderStages::FRAGMENT;
}
if push.stage_mask.contains(BindingStage::VERTEX) {
stage_mask |= ShaderStages::VERTEX;
}
render_pass.set_push_constants(stage_mask, 0, self.uniform_storage.push_slice())
}

parent.draw_quad.draw_quad(&mut render_pass, vbo_type);

Ok(())
Expand Down
37 changes: 5 additions & 32 deletions librashader-runtime-wgpu/src/graphics_pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use std::borrow::Cow;
use std::convert::Infallible;
use wgpu::{
BindGroupLayout, BindGroupLayoutDescriptor, BindGroupLayoutEntry, BindingType,
BufferBindingType, BufferSize, CommandEncoder, Operations, PipelineLayout, PushConstantRange,
RenderPass, RenderPassColorAttachment, RenderPassDescriptor, SamplerBindingType, ShaderModule,
BufferBindingType, BufferSize, CommandEncoder, Operations, PipelineLayout, RenderPass,
RenderPassColorAttachment, RenderPassDescriptor, SamplerBindingType, ShaderModule,
ShaderSource, ShaderStages, TextureFormat, TextureSampleType, TextureViewDimension,
VertexBufferLayout,
};
Expand Down Expand Up @@ -52,34 +52,6 @@ impl PipelineLayoutObjects {
let mut main_bindings = Vec::new();
let mut sampler_bindings = Vec::new();

let mut push_constant_range = Vec::new();

if let Some(push_meta) = reflection
.push_constant
.as_ref()
.filter(|push_meta| !push_meta.stage_mask.is_empty())
{
let push_mask = util::binding_stage_to_wgpu_stage(push_meta.stage_mask);

if let Some(binding) = push_meta.binding {
main_bindings.push(BindGroupLayoutEntry {
binding,
visibility: push_mask,
ty: BindingType::Buffer {
ty: BufferBindingType::Uniform,
has_dynamic_offset: false,
min_binding_size: BufferSize::new(push_meta.size as u64),
},
count: None,
});
} else {
push_constant_range.push(PushConstantRange {
stages: push_mask,
range: 0..push_meta.size,
})
}
}

if let Some(ubo_meta) = reflection
.ubo
.as_ref()
Expand Down Expand Up @@ -132,7 +104,7 @@ impl PipelineLayoutObjects {
let layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
label: Some("shader pipeline layout"),
bind_group_layouts: &bind_group_layout_refs,
push_constant_ranges: &push_constant_range.as_ref(),
immediate_size: 0,
});

Self {
Expand Down Expand Up @@ -205,7 +177,7 @@ impl PipelineLayoutObjects {
mask: !0,
alpha_to_coverage_enabled: false,
},
multiview: None,
multiview_mask: None,
cache,
})
}
Expand Down Expand Up @@ -305,6 +277,7 @@ impl WgpuGraphicsPipeline {
depth_stencil_attachment: None,
timestamp_writes: None,
occlusion_query_set: None,
multiview_mask: None,
});

render_pass.set_scissor_rect(
Expand Down
3 changes: 2 additions & 1 deletion librashader-runtime-wgpu/src/mipmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl MipmapGen {
},
depth_stencil: None,
multisample: wgpu::MultisampleState::default(),
multiview: None,
multiview_mask: None,
cache: None,
});

Expand Down Expand Up @@ -112,6 +112,7 @@ impl MipmapGen {
depth_stencil_attachment: None,
timestamp_writes: None,
occlusion_query_set: None,
multiview_mask: None,
});

pass.set_pipeline(&pipeline);
Expand Down
5 changes: 3 additions & 2 deletions librashader-runtime-wgpu/tests/hello_triangle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ impl<'a> State<'a> {
device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
label: Some("Render Pipeline Layout"),
bind_group_layouts: &[],
push_constant_ranges: &[],
immediate_size: 0,
});
let render_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
label: Some("Render Pipeline"),
Expand Down Expand Up @@ -181,7 +181,7 @@ impl<'a> State<'a> {
mask: !0,
alpha_to_coverage_enabled: false,
},
multiview: None,
multiview_mask: None,
cache: None,
});

Expand Down Expand Up @@ -280,6 +280,7 @@ impl<'a> State<'a> {
depth_stencil_attachment: None,
timestamp_writes: None,
occlusion_query_set: None,
multiview_mask: None,
});
render_pass.set_pipeline(&self.render_pipeline);
render_pass.set_vertex_buffer(0, self.vertex_buffer.slice(..));
Expand Down