Skip to content

Conversation

@samw-improbable
Copy link
Contributor

Description

If you try to use a type that requires flat interpolation (e.g. u32) then you will get browser errors saying you need to add @interpolate(flat). If you add this though, this got included in the var<private> line (i.e. varying @interpolate(flat) myValue: u32 -> var<private> @interpolate(flat) myValue: u32), which resulted in a WGSL compilation error.

This PR updates the regex to pull out the type as well as the name, and then constructs the var<private> lines from that, rather than reusing the entire matched line, to avoid the syntax error.

Checklist

  • I have read the contributing guidelines
  • My code follows the project's coding standards
  • This PR focuses on a single change

@samw-improbable samw-improbable changed the title fix varying bug [Fix] varying bug Oct 27, 2025
@samw-improbable samw-improbable changed the title [Fix] varying bug [Fix] varying bug when using @interpolate Oct 27, 2025
@willeastcott willeastcott requested review from Copilot and mvaligursky and removed request for mvaligursky October 27, 2025 14:46
@willeastcott willeastcott added bug Something isn't working area: graphics Graphics related issue labels Oct 27, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a WGSL compilation error that occurred when using @interpolate attributes with varying declarations. The issue was that the entire varying declaration line (including interpolation attributes) was being reused in var<private> declarations, which caused syntax errors since attributes are not allowed in private variable declarations.

Key Changes:

  • Updated the VARYING regex to capture both the variable name and type
  • Modified the private variable declaration to reconstruct the line from captured name and type only, excluding interpolation attributes

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

// match varying name from string like: '@interpolate(perspective, centroid) smoothColor : vec3f;'
// eslint-disable-next-line
const VARYING = /(?:@interpolate\([^)]*\)\s*)?([\w]+)\s*:/;
const VARYING = /(?:@interpolate\([^)]*\)\s*)?([\w]+)\s*:\s*([\w<>]+)/;
Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

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

The regex pattern [\w<>]+ for capturing the type is too permissive and will not correctly handle nested generic types or array types with dimensions (e.g., vec3<f32> or array<vec4<f32>, 4>). Consider using a more robust pattern like [\w<>,\s\d]+ to properly capture complex type syntax including spaces, commas, and numbers in type parameters.

Suggested change
const VARYING = /(?:@interpolate\([^)]*\)\s*)?([\w]+)\s*:\s*([\w<>]+)/;
const VARYING = /(?:@interpolate\([^)]*\)\s*)?([\w]+)\s*:\s*([\w<>,\s\d]+)/;

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: graphics Graphics related issue bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants