Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Branchless sky shader #71

Merged
merged 40 commits into from
Oct 21, 2020
Merged

Branchless sky shader #71

merged 40 commits into from
Oct 21, 2020

Conversation

Jasper-Bekkers
Copy link
Contributor

@Jasper-Bekkers Jasper-Bekkers commented Oct 19, 2020

Right now this shader doesn't compile because it outputs a lot of error: OpCopyMemorySized (memcpy) without OpCapability Addresses and error: static_addr_of. However, this shader is a relatively complex workload that looks nice and doesn't have any branching in it, so it could be a nice show-case for the project.

Source: https://github.com/Tw1ddle/Sky-Shader/blob/master/src/shaders/glsl/sky.fragment

@repi
Copy link
Contributor

repi commented Oct 19, 2020

cool!

@khyperia
Copy link
Contributor

Changing

  1. Vec3 to #[repr(simd)]
  2. a few hacky bugfixes

gives... whatever this is supposed to be! \o/

image

@repi
Copy link
Contributor

repi commented Oct 19, 2020

Maybe starting to become a red dawn on Mars? so a very specific sky shader :)

@Jasper-Bekkers
Copy link
Contributor Author

Jasper-Bekkers commented Oct 19, 2020

Alright, it should look different but I hacked in an up and view vector so it probably looks wrong.

What does #[repr(simd)] do in this case?

@Jasper-Bekkers
Copy link
Contributor Author

Actually - I think the sky function here may just be returning zero; I was outputting part of the vertex color still.

@khyperia
Copy link
Contributor

khyperia commented Oct 20, 2020

What does #[repr(simd)] do in this case?

Hacky way to avoid the memcpys - vectors apparently use a different mechanism to copy than structs.

I probably won't get to implementing all those bugfixes properly before we opensource - some of them are kind of in-depth. Maybe if I high-priority it, but, there's a lot of other things on my plate.

Also yeah, I tried playing around with input values and whatnot, but couldn't get anything other than pure white output and pure black output.

@Jasper-Bekkers
Copy link
Contributor Author

image

Copy link
Contributor

@khyperia khyperia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like this to either be a pristine example if we're going to put it as the main item in examples/example-shader, or it to be a second example. If it's the main item, I'd like all the vector/helper stuff to be in spirv-std (ideally with the same ops defined on f32x4, etc.), and some thought put into the design of the library. Seeing all this boilerplate as a first user experience isn't a great first impression.

The actual mathy bits/implementation look fine, though!

rustc_codegen_spirv/Cargo.lock Outdated Show resolved Hide resolved
Copy link
Contributor

@khyperia khyperia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it should be the final implementation

yeah, needs some work, but it's decent for a first hack-together!

implement pow and a few others on f32 directly

could do an extension trait, right?

spirv-std/src/math/vec4.rs Outdated Show resolved Hide resolved

/// A 2x2 column major matrix.
#[derive(Clone, Copy, PartialEq, PartialOrd, Debug)]
#[repr(C)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why repr(C) for all of these? why not repr(simd)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was like this in glam - not sure if it matters much?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it does indeed matter, repr(rust) or repr(c) gets translated to OpTypeStruct, repr(simd) gets translated to OpTypeVector and we really want to do that, right? (all the discussions around nvidia load/store perf and whatnot)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah right, yeah I figured it'd be fine for now since our final store needs to happen through a f32x4 anyway, which is repr(simd). Let me take a look at a few of these, it might be nicer to remove the repr(C) indeed.

@Jasper-Bekkers
Copy link
Contributor Author

could do an extension trait, right?

Oh of course. Hold on.

@khyperia
Copy link
Contributor

FYI, filed #81 after seeing the horror that is acos_approx.

Copy link
Contributor

@repi repi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice looks good! Will try and run locally also and poke at some more, but think we can get this in.

Added tiny suggestion

spirv-std/src/math/mod.rs Show resolved Hide resolved
@Jasper-Bekkers
Copy link
Contributor Author

FYI, filed #81 after seeing the horror that is acos_approx.

These kind of approximations are fairly common in graphics so it might be nice to have a crate later on with a bunch of these, or add them as _approx functions (potentially unsafe) to our std. However getting all of the GLExt builtins would be really nice.

@Jasper-Bekkers Jasper-Bekkers merged commit a06b2e4 into main Oct 21, 2020
@Jasper-Bekkers Jasper-Bekkers deleted the test-sky-shader branch October 21, 2020 18:16
@khyperia khyperia mentioned this pull request Oct 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants