Skip to content

Conversation

@inner-daemons
Copy link
Collaborator

Connections
CC @atlv24 for doing the work so far, this is based off their branch here.

Description
Adds per-vertex stuff to the fragment shader as a follow-up to barycentric coordinates, allowing you to do your own stuff for interpolations.

Testing
Explain how this change is tested.

Squash or Rebase?

Squash

Checklist

  • Run cargo fmt.
  • Run taplo format.
  • Run cargo clippy --tests. If applicable, add:
    • --target wasm32-unknown-unknown
  • Run cargo xtask test to run tests.
  • If this contains user-facing changes, add a CHANGELOG.md entry.

@inner-daemons
Copy link
Collaborator Author

inner-daemons commented Nov 29, 2025

My references:

Vulkan
Vulkan sample
GLSL
SPIR-V - underspecified and useless

HLSL

Metal
MSL
MSL barycentrics

Copy link
Collaborator Author

@inner-daemons inner-daemons left a comment

Choose a reason for hiding this comment

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

I am leaving a bunch of comments here for my future self and because I want to have a better understanding of the code before I adopt it myself.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't think we need to be worrying about GLSL output, especially if this is only for Vulkan accepted GLSL

"invariant" => TokenValue::Invariant,
"flat" => TokenValue::Interpolation(crate::Interpolation::Flat),
"noperspective" => TokenValue::Interpolation(crate::Interpolation::Linear),
"pervertexEXT" => TokenValue::Interpolation(crate::Interpolation::PerVertex),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not sure that we need to be parsing this for GLSL. If its super simple then why not, but otherwise I'll probably ignore or remove it.

Comment on lines +101 to +102
#[error("The `PER_VERTEX` capability must be enabled to use per-vertex fragment inputs.")]
PerVertexNotAllowed,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This should probably just be a MissingCapability error

#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct Capabilities: u32 {
pub struct Capabilities: u64 {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've been waiting for the day!

.parameters(
TestParameters::default()
.test_features_limits()
.features(wgpu::Features::SHADER_BARYCENTRICS),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Probably also needs the other feature

)
.run_async(barycentric);

async fn barycentric(ctx: TestingContext) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This functino is quite long. In particular, I've been advised for some of my own tests to avoid vertex buffers and just generate the vertices in the fragment shader.

Copy link
Collaborator

Choose a reason for hiding this comment

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

its based off of the barycentric test (and i forgot to rename it, its copy pasta lol) which in turn is based off of the triangle indexing test. Generating vertices in the shader would make the shader more complicated, idk.

Comment on lines +9 to +31
// These tests render two triangles to a 2x2 render target. The first triangle
// in the vertex buffer covers the bottom-left pixel, the second triangle
// covers the top-right pixel.
// XY layout of the render target, with two triangles:
//
// (-1,1) (0,1) (1,1)
// +-------+-------+
// | |o-----o|
// | | \ / |
// | | \ / |
// | | o |
// (-1,0) +-------+-------+ (1,0)
// | o | |
// | / \ | |
// | / \ | |
// |o-----o| |
// +-------+-------+
// (-1,-1) (0,-1) (1,-1)
//
// The fragment shader outputs color based on per-vertex position:
//
// return vec4(z[0], z[1], z[2], 1.0);
//
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Is the reason for 2 triangles related to which vertex comes in index 1 or something? I'm not sure why we need 2

Copy link
Collaborator

Choose a reason for hiding this comment

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

One should be fine, i just wanted to have more assertion on the ordering of the per-vertex attributes being consistent between platforms. It is something i am a bit worried about

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Maybe a triangle strip topology or something would be a better test?

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.

2 participants