render: Bump wgpu to 0.17 and naga to 0.13

This commit is contained in:
Aaron Hill 2023-07-29 14:50:27 -04:00
parent 20db9f8326
commit 1c0ae0b6d8
16 changed files with 240 additions and 274 deletions

121
Cargo.lock generated
View File

@ -331,12 +331,6 @@ version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1181e1e0d1fce796a03db1ae795d67167da795f9cf4a39c37589e85ef57f26d3"
[[package]]
name = "atomic_refcell"
version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "112ef6b3f6cb3cb6fc5b6b494ef7a848492cff1ab0ef4de10b0f7d572861c905"
[[package]]
name = "autocfg"
version = "1.1.0"
@ -813,7 +807,7 @@ dependencies = [
"bitflags 1.3.2",
"core-foundation",
"core-graphics-types",
"foreign-types",
"foreign-types 0.3.2",
"libc",
]
@ -1022,12 +1016,12 @@ dependencies = [
[[package]]
name = "d3d12"
version = "0.6.0"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8f0de2f5a8e7bd4a9eec0e3c781992a4ce1724f68aec7d7a3715344de8b39da"
checksum = "e16e44ab292b1dddfdaf7be62cfd8877df52f2f3fde5858d95bab606be259f20"
dependencies = [
"bitflags 1.3.2",
"libloading 0.7.4",
"bitflags 2.4.0",
"libloading 0.8.0",
"winapi",
]
@ -1275,8 +1269,7 @@ checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650"
[[package]]
name = "ecolor"
version = "0.22.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2e479a7fa3f23d4e794f8b2f8b3568dd4e47886ad1b12c9c095e141cb591eb63"
source = "git+https://github.com/emilk/egui?rev=98087029e020a1b2d78a4eb840d0a8505340ecad#98087029e020a1b2d78a4eb840d0a8505340ecad"
dependencies = [
"bytemuck",
]
@ -1284,8 +1277,7 @@ dependencies = [
[[package]]
name = "egui"
version = "0.22.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a3aef8ec3ae1b772f340170c65bf27d5b8c28f543a0116c844d2ac08d01123e7"
source = "git+https://github.com/emilk/egui?rev=98087029e020a1b2d78a4eb840d0a8505340ecad#98087029e020a1b2d78a4eb840d0a8505340ecad"
dependencies = [
"ahash 0.8.3",
"epaint",
@ -1296,8 +1288,7 @@ dependencies = [
[[package]]
name = "egui-wgpu"
version = "0.22.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33caaedd8283779c787298af23d8754a7e88421ff32e89ad0040c855fc0b0224"
source = "git+https://github.com/emilk/egui?rev=98087029e020a1b2d78a4eb840d0a8505340ecad#98087029e020a1b2d78a4eb840d0a8505340ecad"
dependencies = [
"bytemuck",
"epaint",
@ -1311,8 +1302,7 @@ dependencies = [
[[package]]
name = "egui-winit"
version = "0.22.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4a49155fd4a0a4fb21224407a91de0030847972ef90fc64edb63621caea61cb2"
source = "git+https://github.com/emilk/egui?rev=98087029e020a1b2d78a4eb840d0a8505340ecad#98087029e020a1b2d78a4eb840d0a8505340ecad"
dependencies = [
"arboard",
"egui",
@ -1327,8 +1317,7 @@ dependencies = [
[[package]]
name = "egui_extras"
version = "0.22.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9278f4337b526f0d57e5375e5a7340a311fa6ee8f9fcc75721ac50af13face02"
source = "git+https://github.com/emilk/egui?rev=98087029e020a1b2d78a4eb840d0a8505340ecad#98087029e020a1b2d78a4eb840d0a8505340ecad"
dependencies = [
"egui",
"serde",
@ -1343,8 +1332,7 @@ checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07"
[[package]]
name = "emath"
version = "0.22.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3857d743a6e0741cdd60b622a74c7a36ea75f5f8f11b793b41d905d2c9721a4b"
source = "git+https://github.com/emilk/egui?rev=98087029e020a1b2d78a4eb840d0a8505340ecad#98087029e020a1b2d78a4eb840d0a8505340ecad"
dependencies = [
"bytemuck",
]
@ -1434,12 +1422,10 @@ dependencies = [
[[package]]
name = "epaint"
version = "0.22.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09333964d4d57f40a85338ba3ca5ed4716070ab184dcfed966b35491c5c64f3b"
source = "git+https://github.com/emilk/egui?rev=98087029e020a1b2d78a4eb840d0a8505340ecad#98087029e020a1b2d78a4eb840d0a8505340ecad"
dependencies = [
"ab_glyph",
"ahash 0.8.3",
"atomic_refcell",
"bytemuck",
"ecolor",
"emath",
@ -1698,7 +1684,28 @@ version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1"
dependencies = [
"foreign-types-shared",
"foreign-types-shared 0.1.1",
]
[[package]]
name = "foreign-types"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d737d9aa519fb7b749cbc3b962edcf310a8dd1f4b67c91c4f83975dbdd17d965"
dependencies = [
"foreign-types-macros",
"foreign-types-shared 0.3.1",
]
[[package]]
name = "foreign-types-macros"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a5c6c585bc94aaf2c7b51dd4c2ba22680844aba4c687be581871a6f518c5742"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.31",
]
[[package]]
@ -1707,6 +1714,12 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"
[[package]]
name = "foreign-types-shared"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa9a19cbb55df58761df49b23516a86d432839add4af60fc256da840f66ed35b"
[[package]]
name = "form_urlencoded"
version = "1.2.0"
@ -2008,21 +2021,21 @@ dependencies = [
[[package]]
name = "gpu-alloc"
version = "0.5.4"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22beaafc29b38204457ea030f6fb7a84c9e4dd1b86e311ba0542533453d87f62"
checksum = "fbcd2dba93594b227a1f57ee09b8b9da8892c34d55aa332e034a228d0fe6a171"
dependencies = [
"bitflags 1.3.2",
"bitflags 2.4.0",
"gpu-alloc-types",
]
[[package]]
name = "gpu-alloc-types"
version = "0.2.0"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "54804d0d6bc9d7f26db4eaec1ad10def69b599315f487d32c334a80d1efe67a5"
checksum = "98ff03b468aa837d70984d55f5d3f846f6ec31fe34bbb97c4f85219caeee1ca4"
dependencies = [
"bitflags 1.3.2",
"bitflags 2.4.0",
]
[[package]]
@ -2800,16 +2813,17 @@ dependencies = [
[[package]]
name = "metal"
version = "0.24.0"
version = "0.26.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "de11355d1f6781482d027a3b4d4de7825dcedb197bf573e0596d00008402d060"
checksum = "623b5e6cefd76e58f774bd3cc0c6f5c7615c58c03a97815245a25c3c9bdee318"
dependencies = [
"bitflags 1.3.2",
"bitflags 2.4.0",
"block",
"core-graphics-types",
"foreign-types",
"foreign-types 0.5.0",
"log",
"objc",
"paste",
]
[[package]]
@ -2859,12 +2873,12 @@ dependencies = [
[[package]]
name = "naga"
version = "0.12.3"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbcc2e0513220fd2b598e6068608d4462db20322c0e77e47f6f488dfcfc279cb"
checksum = "c1ceaaa4eedaece7e4ec08c55c640ba03dbb73fb812a6570a59bcf1930d0f70e"
dependencies = [
"bit-set",
"bitflags 1.3.2",
"bitflags 2.4.0",
"codespan-reporting",
"hexf-parse",
"indexmap 1.9.3",
@ -2904,9 +2918,9 @@ dependencies = [
[[package]]
name = "naga_oil"
version = "0.8.1"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8d9c27fc9c84580434af75123d13ad98d9a56e16d033b16dcfa6940728c8c225"
checksum = "9a5e64da99d79501b244fb645154cd17d0f726b572cb7b029942fb8aa0c48823"
dependencies = [
"bit-set",
"codespan-reporting",
@ -3401,6 +3415,12 @@ dependencies = [
"windows-targets 0.48.5",
]
[[package]]
name = "paste"
version = "1.0.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c"
[[package]]
name = "path-slash"
version = "0.2.1"
@ -5418,9 +5438,9 @@ checksum = "9193164d4de03a926d909d3bc7c30543cecb35400c02114792c2cae20d5e2dbb"
[[package]]
name = "wgpu"
version = "0.16.3"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "480c965c9306872eb6255fa55e4b4953be55a8b64d57e61d7ff840d3dcc051cd"
checksum = "7472f3b69449a8ae073f6ec41d05b6f846902d92a6c45313c50cb25857b736ce"
dependencies = [
"arrayvec",
"cfg-if",
@ -5443,9 +5463,9 @@ dependencies = [
[[package]]
name = "wgpu-core"
version = "0.16.1"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f478237b4bf0d5b70a39898a66fa67ca3a007d79f2520485b8b0c3dfc46f8c2"
checksum = "ecf7454d9386f602f7399225c92dd2fbdcde52c519bc8fb0bd6fbeb388075dc2"
dependencies = [
"arrayvec",
"bit-vec",
@ -5468,9 +5488,9 @@ dependencies = [
[[package]]
name = "wgpu-hal"
version = "0.16.2"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ecb3258078e936deee14fd4e0febe1cfe9bbb5ffef165cb60218d2ee5eb4448"
checksum = "6654a13885a17f475e8324efb46dc6986d7aaaa98353330f8de2077b153d0101"
dependencies = [
"android_system_properties",
"arrayvec",
@ -5480,7 +5500,6 @@ dependencies = [
"block",
"core-graphics-types",
"d3d12",
"foreign-types",
"glow",
"gpu-alloc",
"gpu-allocator",
@ -5510,9 +5529,9 @@ dependencies = [
[[package]]
name = "wgpu-types"
version = "0.16.1"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d0c153280bb108c2979eb5c7391cb18c56642dd3c072e55f52065e13e2a1252a"
checksum = "ee64d7398d0c2f9ca48922c902ef69c42d000c759f3db41e355f4a570b052b67"
dependencies = [
"bitflags 2.4.0",
"js-sys",

View File

@ -43,9 +43,10 @@ version = "0.1.0"
# gc-arena = { git = "https://github.com/kyren/gc-arena", rev = "efd89fc683c6bb456af3e226c33763cb822645e9" }
tracing = "0.1.37"
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
naga = { version = "0.12.3", features = ["validate", "wgsl-out"] }
naga_oil = "0.8.1"
wgpu = "0.16.3"
naga = { version = "0.13.0", features = ["validate", "wgsl-out"] }
naga_oil = "0.9.0"
wgpu = { version = "0.17.0" }
egui = { git = "https://github.com/emilk/egui", rev = "98087029e020a1b2d78a4eb840d0a8505340ecad" }
# Don't optimize build scripts and macros.
[profile.release.build-override]

View File

@ -51,8 +51,8 @@ realfft = "3.3.0"
hashbrown = { version = "0.14.0", features = ["raw"] }
scopeguard = "1.2.0"
fluent-templates = "0.8.0"
egui = { version = "0.22.0", optional = true }
egui_extras = { version = "0.22.0", optional = true }
egui = { workspace = true, optional = true }
egui_extras = { git = "https://github.com/emilk/egui", rev = "98087029e020a1b2d78a4eb840d0a8505340ecad", optional = true }
png = { version = "0.17.10", optional = true }
flv-rs = { path = "../flv" }
async-channel = "1.9.0"

View File

@ -10,9 +10,9 @@ version.workspace = true
[dependencies]
clap = { version = "4.4.2", features = ["derive"] }
cpal = "0.15.2"
egui = "0.22.0"
egui-wgpu = { version = "0.22.0", features = ["winit"] }
egui-winit = "0.22.0"
egui = { workspace = true }
egui-wgpu = { git = "https://github.com/emilk/egui", rev = "98087029e020a1b2d78a4eb840d0a8505340ecad", features = ["winit"] }
egui-winit = { git = "https://github.com/emilk/egui", rev = "98087029e020a1b2d78a4eb840d0a8505340ecad" }
fontdb = "0.14"
ruffle_core = { path = "../core", features = ["audio", "clap", "mp3", "nellymoser", "default_compatibility_rules", "egui"] }
ruffle_render = { path = "../render", features = ["clap"] }

View File

@ -1,9 +1,10 @@
use std::io::Read;
use std::num::NonZeroU32;
use naga::{
AddressSpace, ArraySize, Block, BuiltIn, Constant, ConstantInner, DerivativeControl,
EntryPoint, FunctionArgument, FunctionResult, GlobalVariable, ImageClass, ImageDimension,
ResourceBinding, ScalarValue, ShaderStage, StructMember, SwizzleComponent, UnaryOperator,
AddressSpace, ArraySize, Block, BuiltIn, Constant, DerivativeControl, EntryPoint,
FunctionArgument, FunctionResult, GlobalVariable, ImageClass, ImageDimension, Literal,
Override, ResourceBinding, ShaderStage, StructMember, SwizzleComponent, UnaryOperator,
};
use naga::{BinaryOperator, MathFunction};
use naga::{
@ -103,6 +104,12 @@ pub(crate) struct NagaBuilder<'a> {
// The Naga representation of `texture_cube<f32>`
imagecube: Handle<Type>,
// The Naga representation of `f32`
f32_type: Handle<Type>,
// The Naga representation of `u32`
u32_type: Handle<Type>,
// For a fragment shader, our 4 bound texture samplers
texture_samplers: Option<TextureSamplers>,
@ -192,14 +199,17 @@ impl VertexAttributeFormat {
}
}
let const_expr_f32_zero = builder
.module
.const_expressions
.append(Expression::Literal(Literal::F32(0.0)), Span::UNDEFINED);
let constant_zero = builder.module.constants.append(
Constant {
name: None,
specialization: None,
inner: ConstantInner::Scalar {
width: 4,
value: ScalarValue::Float(0.0),
},
r#override: Override::None,
ty: builder.f32_type,
init: const_expr_f32_zero,
},
Span::UNDEFINED,
);
@ -212,14 +222,18 @@ impl VertexAttributeFormat {
.append(Expression::Constant(constant_zero), Span::UNDEFINED),
);
}
let const_expr_f32_1 = builder
.module
.const_expressions
.append(Expression::Literal(Literal::F32(1.0)), Span::UNDEFINED);
let constant_one = builder.module.constants.append(
Constant {
name: None,
specialization: None,
inner: ConstantInner::Scalar {
width: 4,
value: ScalarValue::Float(1.0),
},
r#override: Override::None,
ty: builder.f32_type,
init: const_expr_f32_1,
},
Span::UNDEFINED,
);
@ -418,6 +432,28 @@ impl<'a> NagaBuilder<'a> {
Span::UNDEFINED,
);
let f32_type = module.types.insert(
Type {
name: None,
inner: TypeInner::Scalar {
kind: ScalarKind::Float,
width: 4,
},
},
Span::UNDEFINED,
);
let u32_type = module.types.insert(
Type {
name: None,
inner: TypeInner::Scalar {
kind: ScalarKind::Uint,
width: 4,
},
},
Span::UNDEFINED,
);
// The return type always has at least one component - the vec4f that's the 'main'
// output of our shader (the position for the vertex shader, and the color for the fragment shader)
let return_type = match shader_config.shader_type {
@ -485,21 +521,6 @@ impl<'a> NagaBuilder<'a> {
Span::UNDEFINED,
);
let num_const_registers = module.constants.append(
Constant {
name: None,
specialization: None,
inner: ConstantInner::Scalar {
width: 4,
value: ScalarValue::Uint(match shader_config.shader_type {
ShaderType::Vertex => VERTEX_PROGRAM_CONTANTS,
ShaderType::Fragment => FRAGMENT_PROGRAM_CONSTANTS,
}),
},
},
Span::UNDEFINED,
);
let binding_num = match shader_config.shader_type {
ShaderType::Vertex => 0,
ShaderType::Fragment => 1,
@ -518,7 +539,13 @@ impl<'a> NagaBuilder<'a> {
name: None,
inner: TypeInner::Array {
base: vec4f,
size: ArraySize::Constant(num_const_registers),
size: ArraySize::Constant(
NonZeroU32::new(match shader_config.shader_type {
ShaderType::Vertex => VERTEX_PROGRAM_CONTANTS as u32,
ShaderType::Fragment => FRAGMENT_PROGRAM_CONSTANTS as u32,
})
.unwrap(),
),
stride: std::mem::size_of::<f32>() as u32 * 4,
},
},
@ -592,6 +619,8 @@ impl<'a> NagaBuilder<'a> {
matrix4x3f,
matrix4x4f,
vec4f,
f32_type,
u32_type,
constant_registers,
texture_samplers,
texture_bindings: [None; 8],
@ -660,14 +689,16 @@ impl<'a> NagaBuilder<'a> {
}
fn emit_const_register_load(&mut self, index: usize) -> Result<Handle<Expression>> {
let const_value_expr = self.module.const_expressions.append(
Expression::Literal(Literal::U32(index as u32)),
Span::UNDEFINED,
);
let index_const = self.module.constants.append(
Constant {
name: None,
specialization: None,
inner: ConstantInner::Scalar {
width: 4,
value: ScalarValue::Uint(index as u64),
},
r#override: Override::None,
ty: self.u32_type,
init: const_value_expr,
},
Span::UNDEFINED,
);
@ -807,14 +838,17 @@ impl<'a> NagaBuilder<'a> {
convert: Some(4),
});
let const_indirect_offset = self.module.const_expressions.append(
Expression::Literal(Literal::U32(source.indirect_offset as u32)),
Span::UNDEFINED,
);
let offset_constant = self.module.constants.append(
Constant {
name: None,
specialization: None,
inner: ConstantInner::Scalar {
width: 4,
value: ScalarValue::Uint(source.indirect_offset as u64),
},
r#override: Override::None,
ty: self.u32_type,
init: const_indirect_offset,
},
Span::UNDEFINED,
);
@ -1567,15 +1601,18 @@ impl<'a> NagaBuilder<'a> {
index: 0,
});
let constant_f32_zero = self
.module
.const_expressions
.append(Expression::Literal(Literal::F32(0.0)), Span::UNDEFINED);
// Check `source < 0.0`.
let constant_zero = self.module.constants.append(
Constant {
name: None,
specialization: None,
inner: ConstantInner::Scalar {
width: 4,
value: ScalarValue::Float(0.0),
},
r#override: Override::None,
ty: self.f32_type,
init: constant_f32_zero,
},
Span::UNDEFINED,
);

View File

@ -8,7 +8,7 @@ struct FragmentOutput {
}
@group(0) @binding(1)
var<uniform> constant_registers: array<vec4<f32>,28u>;
var<uniform> constant_registers: array<vec4<f32>, 28>;
@group(0) @binding(2)
var sampler0_: sampler;
@group(0) @binding(3)

View File

@ -1,5 +1,6 @@
---
source: render/naga-agal/tests/wgsl.rs
assertion_line: 117
expression: output
---
struct VertexOutput {
@ -8,7 +9,7 @@ struct VertexOutput {
}
@group(0) @binding(0)
var<uniform> constant_registers: array<vec4<f32>,128u>;
var<uniform> constant_registers: array<vec4<f32>, 128>;
@vertex
fn main(@location(0) param: vec2<f32>, @location(1) param_1: vec2<f32>) -> VertexOutput {

View File

@ -8,7 +8,7 @@ struct FragmentOutput {
}
@group(0) @binding(1)
var<uniform> constant_registers: array<vec4<f32>,28u>;
var<uniform> constant_registers: array<vec4<f32>, 28>;
@group(0) @binding(2)
var sampler0_: sampler;
@group(0) @binding(3)

View File

@ -9,7 +9,7 @@ struct VertexOutput {
}
@group(0) @binding(0)
var<uniform> constant_registers: array<vec4<f32>,128u>;
var<uniform> constant_registers: array<vec4<f32>, 128>;
@vertex
fn main(@location(0) param: vec4<f32>) -> VertexOutput {

View File

@ -1,6 +1,6 @@
---
source: render/naga-agal/tests/wgsl.rs
assertion_line: 160
assertion_line: 195
expression: output
---
struct FragmentOutput {
@ -8,7 +8,7 @@ struct FragmentOutput {
}
@group(0) @binding(1)
var<uniform> constant_registers: array<vec4<f32>,28u>;
var<uniform> constant_registers: array<vec4<f32>, 28>;
@group(0) @binding(2)
var sampler0_: sampler;
@group(0) @binding(3)

View File

@ -1,6 +1,6 @@
---
source: render/naga-agal/tests/wgsl.rs
assertion_line: 144
assertion_line: 180
expression: output
---
struct VertexOutput {
@ -8,7 +8,7 @@ struct VertexOutput {
}
@group(0) @binding(0)
var<uniform> constant_registers: array<vec4<f32>,128u>;
var<uniform> constant_registers: array<vec4<f32>, 128>;
@vertex
fn main(@location(0) param: vec4<f32>) -> VertexOutput {

View File

@ -1,6 +1,6 @@
---
source: render/naga-agal/tests/wgsl.rs
assertion_line: 143
assertion_line: 146
expression: output
---
struct VertexOutput {
@ -8,7 +8,7 @@ struct VertexOutput {
}
@group(0) @binding(0)
var<uniform> constant_registers: array<vec4<f32>,128u>;
var<uniform> constant_registers: array<vec4<f32>, 128>;
@vertex
fn main(@location(0) param: vec4<f32>, @location(1) param_1: vec4<f32>) -> VertexOutput {

View File

@ -1,6 +1,6 @@
---
source: tests/wgsl.rs
assertion_line: 53
source: render/naga-agal/tests/wgsl.rs
assertion_line: 54
expression: output
---
struct VertexOutput {
@ -9,7 +9,7 @@ struct VertexOutput {
}
@group(0) @binding(0)
var<uniform> constant_registers: array<vec4<f32>,128u>;
var<uniform> constant_registers: array<vec4<f32>, 128>;
@vertex
fn main(@location(0) param: vec4<f32>, @location(1) param_1: vec4<f32>) -> VertexOutput {

View File

@ -8,7 +8,7 @@ struct FragmentOutput {
}
@group(0) @binding(1)
var<uniform> constant_registers: array<vec4<f32>,28u>;
var<uniform> constant_registers: array<vec4<f32>, 28>;
@group(0) @binding(2)
var sampler0_: sampler;
@group(0) @binding(3)

View File

@ -1,6 +1,6 @@
---
source: tests/wgsl.rs
assertion_line: 35
source: render/naga-agal/tests/wgsl.rs
assertion_line: 33
expression: output
---
struct VertexOutput {
@ -9,7 +9,7 @@ struct VertexOutput {
}
@group(0) @binding(0)
var<uniform> constant_registers: array<vec4<f32>,128u>;
var<uniform> constant_registers: array<vec4<f32>, 128>;
@vertex
fn main(@location(0) param: vec3<f32>, @location(1) param_1: vec3<f32>) -> VertexOutput {

View File

@ -1,13 +1,12 @@
use std::{sync::OnceLock, vec};
use std::{num::NonZeroU32, sync::OnceLock, vec};
use anyhow::Result;
use naga::{
valid::{Capabilities, ValidationFlags, Validator},
AddressSpace, ArraySize, BinaryOperator, Binding, Block, BuiltIn, Constant, ConstantInner,
EntryPoint, Expression, Function, FunctionArgument, FunctionResult, GlobalVariable, Handle,
ImageClass, ImageDimension, ImageQuery, LocalVariable, MathFunction, Module,
RelationalFunction, ResourceBinding, ScalarKind, ScalarValue, ShaderStage, Span, Statement,
SwizzleComponent, Type, TypeInner, VectorSize,
AddressSpace, ArraySize, BinaryOperator, Binding, Block, BuiltIn, EntryPoint, Expression,
Function, FunctionArgument, FunctionResult, GlobalVariable, Handle, ImageClass, ImageDimension,
ImageQuery, Literal, LocalVariable, MathFunction, Module, RelationalFunction, ResourceBinding,
ScalarKind, ShaderStage, Span, Statement, SwizzleComponent, Type, TypeInner, VectorSize,
};
use naga_oil::compose::{Composer, NagaModuleDescriptor};
use ruffle_render::pixel_bender::{
@ -298,67 +297,28 @@ impl<'a> ShaderBuilder<'a> {
})
.collect::<Vec<_>>();
let const_zeroi32 = module.constants.append(
Constant {
name: None,
specialization: None,
inner: ConstantInner::Scalar {
width: 4,
value: ScalarValue::Sint(0),
},
},
Span::UNDEFINED,
);
let zeroi32 = func
.expressions
.append(Expression::Constant(const_zeroi32), Span::UNDEFINED);
.append(Expression::Literal(Literal::I32(0)), Span::UNDEFINED);
let const_zerof32 = module.constants.append(
Constant {
name: None,
specialization: None,
inner: ConstantInner::Scalar {
width: 4,
value: ScalarValue::Float(0.0),
},
},
Span::UNDEFINED,
);
let zerof32 = func
.expressions
.append(Expression::Constant(const_zerof32), Span::UNDEFINED);
let const_zerovec4f = module.constants.append(
Constant {
name: None,
specialization: None,
inner: ConstantInner::Composite {
ty: vec4f,
components: vec![const_zerof32, const_zerof32, const_zerof32, const_zerof32],
},
},
Span::UNDEFINED,
);
let zerovec4f = func
.expressions
.append(Expression::Constant(const_zerovec4f), Span::UNDEFINED);
let const_onef32 = module.constants.append(
crate::Constant {
name: None,
specialization: None,
inner: crate::ConstantInner::Scalar {
width: 4,
value: crate::ScalarValue::Float(1.0),
},
},
Span::UNDEFINED,
);
.append(Expression::Literal(Literal::F32(0.0)), Span::UNDEFINED);
let onef32 = func
.expressions
.append(Expression::Constant(const_onef32), Span::UNDEFINED);
.append(Expression::Literal(Literal::F32(1.0)), Span::UNDEFINED);
let mut blocks = vec![BlockStackEntry::Normal(Block::new())];
let zerovec4f = evaluate_expr(
&mut func,
&mut blocks,
Expression::Compose {
ty: vec4f,
components: vec![zerof32, zerof32, zerof32, zerof32],
},
);
let temp_vec4f_local = func.local_variables.append(
LocalVariable {
@ -396,7 +356,7 @@ impl<'a> ShaderBuilder<'a> {
textures: Vec::new(),
float_registers: Vec::new(),
int_registers: Vec::new(),
blocks: vec![BlockStackEntry::Normal(Block::new())],
blocks,
};
let zeroed_out_of_range_mode_global = builder.module.global_variables.append(
@ -607,30 +567,6 @@ impl<'a> ShaderBuilder<'a> {
// These globals must have at least one entry in the array to satisfy naga,
// even if we don't have any parameters of that type.
let num_floats_constant = self.module.constants.append(
Constant {
name: None,
specialization: None,
inner: naga::ConstantInner::Scalar {
width: 4,
value: naga::ScalarValue::Uint(num_vec4fs.max(1) as u64),
},
},
Span::UNDEFINED,
);
let num_ints_constant = self.module.constants.append(
Constant {
name: None,
specialization: None,
inner: naga::ConstantInner::Scalar {
width: 4,
value: naga::ScalarValue::Uint(num_vec4is.max(1) as u64),
},
},
Span::UNDEFINED,
);
let shader_float_parameters = self.module.global_variables.append(
GlobalVariable {
name: Some("shader_float_parameters".to_string()),
@ -644,7 +580,7 @@ impl<'a> ShaderBuilder<'a> {
name: None,
inner: TypeInner::Array {
base: self.vec4f,
size: ArraySize::Constant(num_floats_constant),
size: ArraySize::Constant(NonZeroU32::new(num_vec4fs.max(1)).unwrap()),
stride: std::mem::size_of::<f32>() as u32 * 4,
},
},
@ -668,7 +604,7 @@ impl<'a> ShaderBuilder<'a> {
name: None,
inner: TypeInner::Array {
base: self.vec4i,
size: ArraySize::Constant(num_ints_constant),
size: ArraySize::Constant(NonZeroU32::new(num_vec4is.max(1)).unwrap()),
stride: std::mem::size_of::<i32>() as u32 * 4,
},
},
@ -949,25 +885,9 @@ impl<'a> ShaderBuilder<'a> {
let evaluated = match opcode {
Opcode::Mov => src,
Opcode::Rcp => {
let const_one = self.module.constants.append(
Constant {
name: None,
specialization: None,
inner: naga::ConstantInner::Scalar {
width: 4,
value: naga::ScalarValue::Float(1.0),
},
},
Span::UNDEFINED,
);
let expr_one = self
.func
.expressions
.append(Expression::Constant(const_one), Span::UNDEFINED);
let vec_one = self.evaluate_expr(Expression::Splat {
size: naga::VectorSize::Quad,
value: expr_one,
value: self.onef32,
});
// Perform 'vec4(1.0, 1.0, 1.0. 1.0) / src'
@ -1368,48 +1288,24 @@ impl<'a> ShaderBuilder<'a> {
self.emit_dest_store(sample_result, dst)?;
}
Operation::LoadFloat { dst, val } => {
let const_val = self.module.constants.append(
crate::Constant {
name: None,
specialization: None,
inner: ConstantInner::Scalar {
width: 4,
value: ScalarValue::Float(*val as f64),
},
},
Span::UNDEFINED,
);
let const_expr = self
let val_expr = self
.func
.expressions
.append(Expression::Constant(const_val), Span::UNDEFINED);
.append(Expression::Literal(Literal::F32(*val)), Span::UNDEFINED);
let const_vec = self.evaluate_expr(Expression::Splat {
size: naga::VectorSize::Quad,
value: const_expr,
value: val_expr,
});
self.emit_dest_store(const_vec, dst)?;
}
Operation::LoadInt { dst, val } => {
let const_val = self.module.constants.append(
crate::Constant {
name: None,
specialization: None,
inner: ConstantInner::Scalar {
width: 4,
value: ScalarValue::Sint(*val as i64),
},
},
Span::UNDEFINED,
);
let const_expr = self
let val_expr = self
.func
.expressions
.append(Expression::Constant(const_val), Span::UNDEFINED);
.append(Expression::Literal(Literal::I32(*val)), Span::UNDEFINED);
let const_vec = self.evaluate_expr(Expression::Splat {
size: naga::VectorSize::Quad,
value: const_expr,
value: val_expr,
});
self.emit_dest_store(const_vec, dst)?;
}
@ -1616,11 +1512,7 @@ impl<'a> ShaderBuilder<'a> {
/// Creates a `Statement::Emit` covering `expr`
fn evaluate_expr(&mut self, expr: Expression) -> Handle<Expression> {
let prev_len = self.func.expressions.len();
let expr = self.func.expressions.append(expr, Span::UNDEFINED);
let range = self.func.expressions.range_from(prev_len);
self.push_statement(Statement::Emit(range));
expr
evaluate_expr(&mut self.func, &mut self.blocks, expr)
}
/// Normally, we pad all loads (including scalar loads) to a vec4, and operate component-wise
@ -1770,22 +1662,7 @@ impl<'a> ShaderBuilder<'a> {
/// Pushes a statement, taking into account our current 'if' block.
/// Use this instead of `self.func.body.push`
fn push_statement(&mut self, stmt: Statement) {
let block = match self.blocks.last_mut().unwrap() {
BlockStackEntry::Normal(block) => block,
BlockStackEntry::IfElse {
after_if,
after_else,
in_after_if,
condition: _,
} => {
if *in_after_if {
after_if
} else {
after_else
}
}
};
block.push(stmt, Span::UNDEFINED);
push_statement(&mut self.blocks, stmt)
}
// Loads a Matrix with a size determined by `channel`. Each column of the matrix
@ -1914,3 +1791,34 @@ fn to_wgsl(module: &naga::Module) -> String {
writer.write(module, &module_info).expect("Writing failed");
out
}
fn evaluate_expr(
func: &mut Function,
blocks: &mut [BlockStackEntry],
expr: Expression,
) -> Handle<Expression> {
let prev_len = func.expressions.len();
let expr = func.expressions.append(expr, Span::UNDEFINED);
let range = func.expressions.range_from(prev_len);
push_statement(blocks, Statement::Emit(range));
expr
}
fn push_statement(blocks: &mut [BlockStackEntry], stmt: Statement) {
let block = match blocks.last_mut().unwrap() {
BlockStackEntry::Normal(block) => block,
BlockStackEntry::IfElse {
after_if,
after_else,
in_after_if,
condition: _,
} => {
if *in_after_if {
after_if
} else {
after_else
}
}
};
block.push(stmt, Span::UNDEFINED);
}