Don't require Int* capabilities for mouse-shader (#636)

* Don't require Int* capabilities for mouse-shader

* Make Int*/Float64 errors be zombie_even_in_user_code

* Demote glam back to a non-system crate
This commit is contained in:
Ashley Hauck 2021-05-31 11:56:15 +02:00 committed by GitHub
parent 62f375f148
commit ba689b5603
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 36 additions and 37 deletions

View File

@ -231,7 +231,6 @@ impl<'tcx> CodegenCx<'tcx> {
|| self.tcx.crate_name(LOCAL_CRATE) == self.sym.spirv_std
|| self.tcx.crate_name(LOCAL_CRATE) == self.sym.libm
|| self.tcx.crate_name(LOCAL_CRATE) == self.sym.num_traits
|| self.tcx.crate_name(LOCAL_CRATE) == self.sym.glam
}
// FIXME(eddyb) should this just be looking at `kernel_mode`?

View File

@ -105,15 +105,20 @@ impl SpirvType {
.emit_global()
.type_int(width, if signedness { 1 } else { 0 });
match width {
8 if !cx.builder.has_capability(Capability::Int8) => {
cx.zombie_with_span(result, def_span, "u8 without OpCapability Int8")
}
16 if !cx.builder.has_capability(Capability::Int16) => {
cx.zombie_with_span(result, def_span, "u16 without OpCapability Int16")
}
64 if !cx.builder.has_capability(Capability::Int64) => {
cx.zombie_with_span(result, def_span, "u64 without OpCapability Int64")
}
8 if !cx.builder.has_capability(Capability::Int8) => cx
.zombie_even_in_user_code(result, def_span, "u8 without OpCapability Int8"),
16 if !cx.builder.has_capability(Capability::Int16) => cx
.zombie_even_in_user_code(
result,
def_span,
"u16 without OpCapability Int16",
),
64 if !cx.builder.has_capability(Capability::Int64) => cx
.zombie_even_in_user_code(
result,
def_span,
"u64 without OpCapability Int64",
),
8 | 16 | 32 | 64 => (),
128 => cx.zombie_with_span(result, def_span, "u128"),
other => cx.zombie_with_span(
@ -127,9 +132,12 @@ impl SpirvType {
Self::Float(width) => {
let result = cx.emit_global().type_float(width);
match width {
64 if !cx.builder.has_capability(Capability::Float64) => {
cx.zombie_with_span(result, def_span, "f64 without OpCapability Float64")
}
64 if !cx.builder.has_capability(Capability::Float64) => cx
.zombie_even_in_user_code(
result,
def_span,
"f64 without OpCapability Float64",
),
32 | 64 => (),
other => cx.zombie_with_span(
result,

View File

@ -20,7 +20,6 @@ pub struct Symbols {
pub spirv_std: Symbol,
pub libm: Symbol,
pub num_traits: Symbol,
pub glam: Symbol,
pub entry_point_name: Symbol,
descriptor_set: Symbol,
binding: Symbol,
@ -379,7 +378,6 @@ impl Symbols {
spirv_std: Symbol::intern("spirv_std"),
libm: Symbol::intern("libm"),
num_traits: Symbol::intern("num_traits"),
glam: Symbol::intern("glam"),
descriptor_set: Symbol::intern("descriptor_set"),
binding: Symbol::intern("binding"),
image_type: Symbol::intern("image_type"),

View File

@ -29,10 +29,6 @@ fn main() -> Result<(), Box<dyn Error>> {
build_shader("../../../shaders/sky-shader", true, &[])?;
build_shader("../../../shaders/simplest-shader", false, &[])?;
build_shader("../../../shaders/compute-shader", false, &[])?;
build_shader(
"../../../shaders/mouse-shader",
false,
&[Capability::Int8, Capability::Int16, Capability::Int64],
)?;
build_shader("../../../shaders/mouse-shader", false, &[])?;
Ok(())
}

View File

@ -74,10 +74,7 @@ fn shader_module(shader: RustGPUShader) -> wgpu::ShaderModuleDescriptor<'static>
RustGPUShader::Simplest => ("simplest-shader", &[]),
RustGPUShader::Sky => ("sky-shader", &[]),
RustGPUShader::Compute => ("compute-shader", &[]),
RustGPUShader::Mouse => (
"mouse-shader",
&[Capability::Int8, Capability::Int16, Capability::Int64],
),
RustGPUShader::Mouse => ("mouse-shader", &[]),
};
let manifest_dir = env!("CARGO_MANIFEST_DIR");
let crate_path = [

View File

@ -119,7 +119,9 @@ struct Rectangle {
impl Shape for Rectangle {
fn distance(self, p: Vec2) -> f32 {
((p - self.center).abs() - self.size / 2.0).max_element()
let diff = p - self.center;
let diff = vec2(diff.x.abs(), diff.y.abs());
(diff - self.size / 2.0).max_element()
}
}
@ -158,15 +160,10 @@ pub fn main_fs(
let from_coord = move |coord: Vec2| (coord / resolution) * 2.0 - Vec2::splat(1.0);
let v = from_coord(frag_coord);
let mut distance = v.length();
if drag_start != drag_end {
distance /= 1.0
+ (v - from_coord(drag_start))
.extend(0.0)
.cross((from_coord(drag_end) - from_coord(drag_start)).extend(0.0))
.length()
.min(1.0)
.powf(2.0);
}
let to_frag = v - from_coord(drag_start);
let start_to_end = from_coord(drag_end) - from_coord(drag_start);
let det = to_frag.perp_dot(start_to_end).abs();
distance /= 1.0 + det.min(1.0).powf(2.0);
let t = constants.time;
let rot = move |factor: f32| {
(Mat2::from_angle((t / 3.0 + distance * factor).sin() * 3.0) * v).normalize()
@ -175,7 +172,11 @@ pub fn main_fs(
let rg = rot(2.0 + seed); // yellow
let rb = rot(3.0 + seed + rg.y); // magenta
let gb = rot(5.0 + seed + rb.x); // cyan
let color = (vec3(rg.x - rb.x, rg.y - gb.x, rb.y - gb.y).abs() / 2.0)
let color = (vec3(
(rg.x - rb.x).abs(),
(rg.y - gb.x).abs(),
(rb.y - gb.y).abs(),
) / 2.0)
.min(Vec3::splat(1.0))
.powf(1.2);
let vignette = smoothstep(1.0, 0.0, (v.x * v.y).abs());
@ -191,7 +192,7 @@ pub fn main_fs(
const WHITE: Vec4 = const_vec4!([1.0, 1.0, 1.0, 1.0]);
const RED: Vec4 = const_vec4!([1.0, 0.0, 0.0, 1.0]);
if drag_start != drag_end {
if drag_start.distance_squared(drag_end) > f32::EPSILON {
let drag_dir = (drag_end - drag_start).normalize();
let arrow_head = |p: Vec2| {
Line(p - Mat2::from_angle(-PI / 4.0) * drag_dir * 16.0, p)
@ -199,7 +200,7 @@ pub fn main_fs(
};
let arrow = arrow_head(drag_start - drag_dir).union(Line(drag_start, drag_end));
if drag_end != cursor {
if drag_end.distance_squared(cursor) > f32::EPSILON {
painter.fill_with_contrast_border(
arrow.union(arrow_head(drag_end + drag_dir)).stroke(4.0),
WHITE,