-
Notifications
You must be signed in to change notification settings - Fork 398
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Re-enable bilinear interpolation again (#1860)
* Revert "Revert "Implement billinear filtering of textures (#1850)" (#1859)" This reverts commit 625d2bd. * Split rectangle.wgsl into fragme/vertex parts to work around naga bug
- Loading branch information
Showing
6 changed files
with
188 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
#import <./rectangle.wgsl> | ||
|
||
fn is_magnifying(pixel_coord: Vec2) -> bool { | ||
return fwidth(pixel_coord.x) < 1.0; | ||
} | ||
|
||
fn tex_filter(pixel_coord: Vec2) -> u32 { | ||
if is_magnifying(pixel_coord) { | ||
return rect_info.magnification_filter; | ||
} else { | ||
return rect_info.minification_filter; | ||
} | ||
} | ||
|
||
@fragment | ||
fn fs_main(in: VertexOut) -> @location(0) Vec4 { | ||
// Sample the main texture: | ||
var sampled_value: Vec4; | ||
if rect_info.sample_type == SAMPLE_TYPE_FLOAT_FILTER { | ||
// TODO(emilk): support mipmaps | ||
sampled_value = textureSampleLevel(texture_float_filterable, texture_sampler, in.texcoord, 0.0); | ||
} else if rect_info.sample_type == SAMPLE_TYPE_FLOAT_NOFILTER { | ||
let coord = in.texcoord * Vec2(textureDimensions(texture_float).xy); | ||
if tex_filter(coord) == FILTER_NEAREST { | ||
// nearest | ||
sampled_value = textureLoad(texture_float, IVec2(coord + vec2(0.5)), 0); | ||
} else { | ||
// bilinear | ||
let v00 = textureLoad(texture_float, IVec2(coord) + IVec2(0, 0), 0); | ||
let v01 = textureLoad(texture_float, IVec2(coord) + IVec2(0, 1), 0); | ||
let v10 = textureLoad(texture_float, IVec2(coord) + IVec2(1, 0), 0); | ||
let v11 = textureLoad(texture_float, IVec2(coord) + IVec2(1, 1), 0); | ||
let top = mix(v00, v10, fract(coord.x)); | ||
let bottom = mix(v01, v11, fract(coord.x)); | ||
sampled_value = mix(top, bottom, fract(coord.y)); | ||
} | ||
} else if rect_info.sample_type == SAMPLE_TYPE_SINT_NOFILTER { | ||
let coord = in.texcoord * Vec2(textureDimensions(texture_sint).xy); | ||
if tex_filter(coord) == FILTER_NEAREST { | ||
// nearest | ||
sampled_value = Vec4(textureLoad(texture_sint, IVec2(coord + vec2(0.5)), 0)); | ||
} else { | ||
// bilinear | ||
let v00 = Vec4(textureLoad(texture_sint, IVec2(coord) + IVec2(0, 0), 0)); | ||
let v01 = Vec4(textureLoad(texture_sint, IVec2(coord) + IVec2(0, 1), 0)); | ||
let v10 = Vec4(textureLoad(texture_sint, IVec2(coord) + IVec2(1, 0), 0)); | ||
let v11 = Vec4(textureLoad(texture_sint, IVec2(coord) + IVec2(1, 1), 0)); | ||
let top = mix(v00, v10, fract(coord.x)); | ||
let bottom = mix(v01, v11, fract(coord.x)); | ||
sampled_value = mix(top, bottom, fract(coord.y)); | ||
} | ||
} else if rect_info.sample_type == SAMPLE_TYPE_UINT_NOFILTER { | ||
let coord = in.texcoord * Vec2(textureDimensions(texture_uint).xy); | ||
if tex_filter(coord) == FILTER_NEAREST { | ||
// nearest | ||
sampled_value = Vec4(textureLoad(texture_uint, IVec2(coord + vec2(0.5)), 0)); | ||
} else { | ||
// bilinear | ||
let v00 = Vec4(textureLoad(texture_uint, IVec2(coord) + IVec2(0, 0), 0)); | ||
let v01 = Vec4(textureLoad(texture_uint, IVec2(coord) + IVec2(0, 1), 0)); | ||
let v10 = Vec4(textureLoad(texture_uint, IVec2(coord) + IVec2(1, 0), 0)); | ||
let v11 = Vec4(textureLoad(texture_uint, IVec2(coord) + IVec2(1, 1), 0)); | ||
let top = mix(v00, v10, fract(coord.x)); | ||
let bottom = mix(v01, v11, fract(coord.x)); | ||
sampled_value = mix(top, bottom, fract(coord.y)); | ||
} | ||
} else { | ||
return ERROR_RGBA; // unknown sample type | ||
} | ||
|
||
// Normalize the sample: | ||
let range = rect_info.range_min_max; | ||
var normalized_value: Vec4 = (sampled_value - range.x) / (range.y - range.x); | ||
|
||
// Apply gamma: | ||
normalized_value = vec4(pow(normalized_value.rgb, vec3(rect_info.gamma)), normalized_value.a); // TODO(emilk): handle premultiplied alpha | ||
|
||
// Apply colormap, if any: | ||
var texture_color: Vec4; | ||
if rect_info.color_mapper == COLOR_MAPPER_OFF { | ||
texture_color = normalized_value; | ||
} else if rect_info.color_mapper == COLOR_MAPPER_FUNCTION { | ||
let rgb = colormap_linear(rect_info.colormap_function, normalized_value.r); | ||
texture_color = Vec4(rgb, 1.0); | ||
} else if rect_info.color_mapper == COLOR_MAPPER_TEXTURE { | ||
let colormap_size = textureDimensions(colormap_texture).xy; | ||
let color_index = normalized_value.r * f32(colormap_size.x * colormap_size.y); | ||
// TODO(emilk): interpolate between neighboring colors for non-integral color indices | ||
let color_index_i32 = i32(color_index); | ||
let x = color_index_i32 % colormap_size.x; | ||
let y = color_index_i32 / colormap_size.x; | ||
texture_color = textureLoad(colormap_texture, IVec2(x, y), 0); | ||
} else { | ||
return ERROR_RGBA; // unknown color mapper | ||
} | ||
|
||
return texture_color * rect_info.multiplicative_tint; | ||
} | ||
|
||
@fragment | ||
fn fs_main_picking_layer(in: VertexOut) -> @location(0) UVec4 { | ||
return UVec4(0u, 0u, 0u, 0u); // TODO(andreas): Implement picking layer id pass-through. | ||
} | ||
|
||
@fragment | ||
fn fs_main_outline_mask(in: VertexOut) -> @location(0) UVec2 { | ||
return rect_info.outline_mask; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#import <./rectangle.wgsl> | ||
|
||
@vertex | ||
fn vs_main(@builtin(vertex_index) v_idx: u32) -> VertexOut { | ||
let texcoord = Vec2(f32(v_idx / 2u), f32(v_idx % 2u)); | ||
let pos = texcoord.x * rect_info.extent_u + texcoord.y * rect_info.extent_v + | ||
rect_info.top_left_corner_position; | ||
|
||
var out: VertexOut; | ||
out.position = apply_depth_offset(frame.projection_from_world * Vec4(pos, 1.0), rect_info.depth_offset); | ||
out.texcoord = texcoord; | ||
|
||
return out; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
adf9856
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rust Benchmark
datastore/num_rows=1000/num_instances=1000/packed=false/insert/default
3884493
ns/iter (± 224684
)3453605
ns/iter (± 85619
)1.12
datastore/num_rows=1000/num_instances=1000/packed=false/latest_at/default
370
ns/iter (± 1
)382
ns/iter (± 1
)0.97
datastore/num_rows=1000/num_instances=1000/packed=false/latest_at_missing/primary/default
261
ns/iter (± 0
)260
ns/iter (± 0
)1.00
datastore/num_rows=1000/num_instances=1000/packed=false/latest_at_missing/secondaries/default
420
ns/iter (± 0
)429
ns/iter (± 0
)0.98
datastore/num_rows=1000/num_instances=1000/packed=false/range/default
3839235
ns/iter (± 208720
)3587312
ns/iter (± 78211
)1.07
datastore/num_rows=1000/num_instances=1000/gc/default
2386181
ns/iter (± 7225
)2393440
ns/iter (± 5822
)1.00
mono_points_arrow/generate_message_bundles
31121592
ns/iter (± 444364
)28645528
ns/iter (± 1103451
)1.09
mono_points_arrow/generate_messages
127961340
ns/iter (± 1094579
)126079280
ns/iter (± 1122217
)1.01
mono_points_arrow/encode_log_msg
161906054
ns/iter (± 2440212
)158006436
ns/iter (± 1489958
)1.02
mono_points_arrow/encode_total
319505901
ns/iter (± 2471660
)316136034
ns/iter (± 2245072
)1.01
mono_points_arrow/decode_log_msg
193377167
ns/iter (± 1176387
)190644173
ns/iter (± 1090403
)1.01
mono_points_arrow/decode_message_bundles
71953200
ns/iter (± 627613
)70246697
ns/iter (± 643546
)1.02
mono_points_arrow/decode_total
262749089
ns/iter (± 1904379
)258257827
ns/iter (± 1651580
)1.02
mono_points_arrow_batched/generate_message_bundles
25979718
ns/iter (± 1444642
)24318215
ns/iter (± 1613499
)1.07
mono_points_arrow_batched/generate_messages
5046246
ns/iter (± 489858
)4626122
ns/iter (± 292249
)1.09
mono_points_arrow_batched/encode_log_msg
1395661
ns/iter (± 4692
)1374366
ns/iter (± 2270
)1.02
mono_points_arrow_batched/encode_total
32890333
ns/iter (± 1815439
)32679020
ns/iter (± 1819398
)1.01
mono_points_arrow_batched/decode_log_msg
786757
ns/iter (± 3628
)782142
ns/iter (± 3285
)1.01
mono_points_arrow_batched/decode_message_bundles
8010830
ns/iter (± 467979
)7679188
ns/iter (± 155523
)1.04
mono_points_arrow_batched/decode_total
9320700
ns/iter (± 528144
)8692322
ns/iter (± 286545
)1.07
batch_points_arrow/generate_message_bundles
193675
ns/iter (± 435
)191478
ns/iter (± 494
)1.01
batch_points_arrow/generate_messages
5140
ns/iter (± 10
)5195
ns/iter (± 8
)0.99
batch_points_arrow/encode_log_msg
266170
ns/iter (± 1730
)264805
ns/iter (± 1647
)1.01
batch_points_arrow/encode_total
495605
ns/iter (± 3605
)485864
ns/iter (± 3357
)1.02
batch_points_arrow/decode_log_msg
213925
ns/iter (± 1642
)212794
ns/iter (± 649
)1.01
batch_points_arrow/decode_message_bundles
1870
ns/iter (± 8
)1899
ns/iter (± 2
)0.98
batch_points_arrow/decode_total
223284
ns/iter (± 1391
)221980
ns/iter (± 1781
)1.01
arrow_mono_points/insert
2520560471
ns/iter (± 5545821
)2525712931
ns/iter (± 6101896
)1.00
arrow_mono_points/query
1219187
ns/iter (± 15121
)1195489
ns/iter (± 6901
)1.02
arrow_batch_points/insert
1153495
ns/iter (± 10456
)1143470
ns/iter (± 5090
)1.01
arrow_batch_points/query
15049
ns/iter (± 70
)14892
ns/iter (± 29
)1.01
arrow_batch_vecs/insert
26690
ns/iter (± 82
)28145
ns/iter (± 54
)0.95
arrow_batch_vecs/query
325241
ns/iter (± 830
)368260
ns/iter (± 226
)0.88
tuid/Tuid::random
34
ns/iter (± 0
)34
ns/iter (± 0
)1
This comment was automatically generated by workflow using github-action-benchmark.