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

Remove NaN uniform #9174

Merged
merged 3 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export type AggregatorTransformProps = {
binIdRange: NumberArray4;
isCount: NumberArray3;
isMean: NumberArray3;
naN: number;
bins: Texture;
};

Expand All @@ -25,7 +24,6 @@ export const aggregatorTransformUniforms = {
uniformTypes: {
binIdRange: 'vec4<i32>',
isCount: 'vec3<f32>',
isMean: 'vec3<f32>',
naN: 'f32'
isMean: 'vec3<f32>'
}
} as const satisfies ShaderModule<AggregatorTransformProps>;
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ export class WebGLAggregationTransform {
this.device = device;
this.channelCount = props.channelCount;
this.transform = createTransform(device, props);
// Passed in as uniform because 1) there is no GLSL symbol for NaN 2) any expression that exploits undefined behavior to produces NaN
// will subject to platform differences and shader optimization
this.transform.model.shaderInputs.setProps({aggregatorTransform: {naN: NaN}});
this.domainFBO = createRenderTarget(device, 2, 1);
}

Expand Down Expand Up @@ -145,6 +142,8 @@ flat out vec2 values;
flat out vec3 values;
#endif

const float NAN = intBitsToFloat(-1);

void main() {
int row = gl_VertexID / SAMPLER_WIDTH;
int col = gl_VertexID - row * SAMPLER_WIDTH;
Expand All @@ -155,7 +154,7 @@ void main() {
aggregatorTransform.isMean
);
if (weights.a == 0.0) {
value3 = vec3(aggregatorTransform.naN);
value3 = vec3(NAN);
}

#if NUM_DIMS == 1
Expand Down Expand Up @@ -199,11 +198,6 @@ flat in vec3 values;
out vec4 fragColor;

void main() {
#if NUM_CHANNELS > 1
if (isnan(values.x)) discard;
#else
if (isnan(values)) discard;
#endif
vec3 value3;
#if NUM_CHANNELS == 3
value3 = values;
Expand All @@ -212,6 +206,7 @@ void main() {
#else
value3.x = values;
#endif
if (isnan(value3.x)) discard;
// This shader renders into a 2x1 texture with blending=max
// The left pixel yields the max value of each channel
// The right pixel yields the min value of each channel
Expand Down
Loading