-
Notifications
You must be signed in to change notification settings - Fork 3
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
Generics: Bevy use case #63
Comments
With the current conditional translation spec only, the code cannot be fundamentally improved. But I think even with bevy preprocessor the code would be more readable by moving arguments into declarations. Bevy: #ifdef BINDLESS
let texture = pbr_bindings::base_color_texture[slot];
let sampler = pbr_bindings::base_color_sampler[slot];
#else
let texture = pbr_bindings::base_color_texture;
let sampler = pbr_bindings::base_color_sampler;
#endif
#ifdef STANDARD_MATERIAL_BASE_COLOR_UV_B
let coords = uv_b;
#else
let coords = uv;
#endif
#ifdef MESHLET_MESH_MATERIAL_PASS
let color = textureSampleGrad(texture, sampler, coords, bias.ddx_uv, bias.ddy_uv);
#else
let color = textureSampleBias(texture, sampler, coords, bias.mip_bias);
#endif
pbr_input.material.base_color *= color; WESL: @if(BINDLESS)
let texture = pbr_bindings::base_color_texture[slot];
@else
let texture = pbr_bindings::base_color_texture;
@if(BINDLESS)
let sampler = pbr_bindings::base_color_sampler[slot];
@else
let sampler = pbr_bindings::base_color_sampler;
@if(STANDARD_MATERIAL_BASE_COLOR_UV_B)
let coords = uv_b;
@else
let coords = uv;
@if(MESHLET_MESH_MATERIAL_PASS)
let color = textureSampleGrad(texture, sampler, coords, bias.ddx_uv, bias.ddy_uv);
@else
let color = textureSampleBias(texture, sampler, coords, bias.mip_bias);
pbr_input.material.base_color *= color; WESL, if we allow let texture = @if(BINDLESS) pbr_bindings::base_color_texture[slot] @else pbr_bindings::base_color_texture;
let sampler = @if(BINDLESS) pbr_bindings::base_color_sampler[slot] @else pbr_bindings::base_color_sampler;
let coords = @if(STANDARD_MATERIAL_BASE_COLOR_UV_B) uv_b @else uv;
let color =
@if(MESHLET_MESH_MATERIAL_PASS) textureSampleGrad(texture, sampler, coords, bias.ddx_uv, bias.ddy_uv)
@else textureSampleBias(texture, sampler, coords, bias.mip_bias);
pbr_input.material.base_color *= color; I think tho a better approach would be something similar to what Use.GPU does, i.e. getter functions // pbr_bindings.wesl
@if(BINDLESS) @group() @binding() var base_color_texture: ...;
@else @group() @binding() var base_color_texture: ...;
fn get_base_color_texture() -> texture_2d<f32> {
@if(BINDLESS) {
return base_color_texture[slot];
} @else {
return base_color_texture;
}
}
// main.wesl
import pbr_bindings::{ get_base_color_texture, get_base_color_sampler, get_coords };
pbr_input.material.base_color *=
@if(MESHLET_MESH_MATERIAL_PASS)
textureSampleGrad(get_base_color_texture(), get_base_color_sampler(), get_coords(), bias.ddx_uv, bias.ddy_uv)
@else
textureSampleBias(tget_base_color_texture(), get_base_color_sampler(), get_coords(), bias.mip_bias); This is a good exercise to find the flaws in our design. In this particular example, the attributes on expressions with mandatory else would be very useful. I also found that the current syntax does not allow declaration grouping: #if SOME_CONDITION
let foo = ...
let bar = ...
let baz = ...
#else
let foo = ...
let bar = ...
let baz = ...
#endif @if (SOME_CONDITION)
let foo = ...
@else
let foo = ...
@if (SOME_CONDITION)
let bar = ...
@else
let bar = ...
@if (SOME_CONDITION)
let baz = ...
@else
let baz = ... |
So, perhaps the getter function ought be written manually by the programmer for now? Seems like it adds clarity to this example..
The wesl version you have here looks a lot cleaner! // pbr_bindings.wesl
@if(BINDLESS) @group() @binding() var base_color_texture: ...;
@else @group() @binding() var base_color_texture: ...;
fn get_base_color_texture() -> texture_2d<f32> {
@if(BINDLESS) {
return base_color_texture[slot];
} @else {
return base_color_texture;
}
}
// main.wesl
import pbr_bindings::{ get_base_color_texture, get_base_color_sampler, get_coords };
pbr_input.material.base_color *=
@if(MESHLET_MESH_MATERIAL_PASS)
textureSampleGrad(get_base_color_texture(), get_base_color_sampler(), get_coords(), bias.ddx_uv, bias.ddy_uv)
@else
textureSampleBias(tget_base_color_texture(), get_base_color_sampler(), get_coords(), bias.mip_bias); If deferring Do you think we should continue to defer |
Yes and no. Having the So TL;DR
I would not suggest having the else be part of MVP, we already have much on our plate :) Let's keep it that way for now. Besides, I have not yet submitted the grammar change proposal I mentionned on discord to the gpuweb folks, but if they agree with that it would make the grammar significantly more friendly to those attributes :) |
from @pcwalton on the bevy discord:
The text was updated successfully, but these errors were encountered: