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

[wgsl] Remove buffer, texture, in, out, input, output from reserved keywords #1870

Merged
merged 1 commit into from
Apr 29, 2022
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
6 changes: 0 additions & 6 deletions src/keywords/wgsl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ pub const RESERVED: &[&str] = &[
"await",
"become",
"bf16",
"buffer",
"cast",
"catch",
"cbuffer",
Expand Down Expand Up @@ -217,10 +216,8 @@ pub const RESERVED: &[&str] = &[
"impl",
"implements",
"import",
"in",
"inline",
"inout",
"input",
"instanceof",
"interface",
"invariant",
Expand Down Expand Up @@ -276,8 +273,6 @@ pub const RESERVED: &[&str] = &[
"nullptr",
"of",
"operator",
"out",
"output",
"package",
"packoffset",
"partition",
Expand Down Expand Up @@ -348,7 +343,6 @@ pub const RESERVED: &[&str] = &[
"technique10",
"technique11",
"template",
"texture",
"texture1D",
"texture1DArray",
"texture2D",
Expand Down
8 changes: 4 additions & 4 deletions tests/in/extra.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ struct FragmentIn {
}

@fragment
fn main(_in: FragmentIn) -> @location(0) vec4<f32> {
if _in.primitive_index == pc.index {
return _in.color;
fn main(in: FragmentIn) -> @location(0) vec4<f32> {
if in.primitive_index == pc.index {
return in.color;
} else {
return vec4<f32>(vec3<f32>(1.0) - _in.color.rgb, _in.color.a);
return vec4<f32>(vec3<f32>(1.0) - in.color.rgb, in.color.a);
}
}
8 changes: 4 additions & 4 deletions tests/in/interface.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ struct FragmentOutput {

@fragment
fn fragment(
_in: VertexOutput,
in: VertexOutput,
@builtin(front_facing) front_facing: bool,
@builtin(sample_index) sample_index: u32,
@builtin(sample_mask) sample_mask: u32,
) -> FragmentOutput {
let mask = sample_mask & (1u << sample_index);
let color = select(0.0, 1.0, front_facing);
return FragmentOutput(_in._varying, mask, color);
return FragmentOutput(in._varying, mask, color);
}

var<workgroup> _output: array<u32, 1>;
var<workgroup> output: array<u32, 1>;

@compute @workgroup_size(1)
fn compute(
Expand All @@ -43,7 +43,7 @@ fn compute(
@builtin(workgroup_id) wg_id: vec3<u32>,
@builtin(num_workgroups) num_wgs: vec3<u32>,
) {
_output[0] = global_id.x + local_id.x + local_index + wg_id.x + num_wgs.x;
output[0] = global_id.x + local_id.x + local_index + wg_id.x + num_wgs.x;
}

struct Input1 {
Expand Down
20 changes: 10 additions & 10 deletions tests/in/interpolate.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ struct FragmentInput {

@vertex
fn vert_main() -> FragmentInput {
var _out: FragmentInput;
var out: FragmentInput;

_out.position = vec4<f32>(2.0, 4.0, 5.0, 6.0);
_out._flat = 8u;
_out._linear = 27.0;
_out.linear_centroid = vec2<f32>(64.0, 125.0);
_out.linear_sample = vec3<f32>(216.0, 343.0, 512.0);
_out.perspective = vec4<f32>(729.0, 1000.0, 1331.0, 1728.0);
_out.perspective_centroid = 2197.0;
_out.perspective_sample = 2744.0;
out.position = vec4<f32>(2.0, 4.0, 5.0, 6.0);
out._flat = 8u;
out._linear = 27.0;
out.linear_centroid = vec2<f32>(64.0, 125.0);
out.linear_sample = vec3<f32>(216.0, 343.0, 512.0);
out.perspective = vec4<f32>(729.0, 1000.0, 1331.0, 1728.0);
out.perspective_centroid = 2197.0;
out.perspective_sample = 2744.0;

return _out;
return out;
}

@fragment
Expand Down
4 changes: 2 additions & 2 deletions tests/in/push-constants.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ struct FragmentIn {
}

@fragment
fn main(_in: FragmentIn) -> @location(0) vec4<f32> {
return _in.color * pc.multiplier;
fn main(in: FragmentIn) -> @location(0) vec4<f32> {
return in.color * pc.multiplier;
}
26 changes: 13 additions & 13 deletions tests/in/shadow.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ fn vs_main(
) -> VertexOutput {
let w = u_entity.world;
let world_pos = u_entity.world * vec4<f32>(position);
var _out: VertexOutput;
_out.world_normal = mat3x3<f32>(w.x.xyz, w.y.xyz, w.z.xyz) * vec3<f32>(normal.xyz);
_out.world_position = world_pos;
_out.proj_position = u_globals.view_proj * world_pos;
return _out;
var out: VertexOutput;
out.world_normal = mat3x3<f32>(w.x.xyz, w.y.xyz, w.z.xyz) * vec3<f32>(normal.xyz);
out.world_position = world_pos;
out.proj_position = u_globals.view_proj * world_pos;
return out;
}

// fragment shader
Expand Down Expand Up @@ -81,16 +81,16 @@ let c_ambient: vec3<f32> = vec3<f32>(0.05, 0.05, 0.05);
let c_max_lights: u32 = 10u;

@fragment
fn fs_main(_in: VertexOutput) -> @location(0) vec4<f32> {
let normal = normalize(_in.world_normal);
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
let normal = normalize(in.world_normal);
// accumulate color
var color: vec3<f32> = c_ambient;
for(var i = 0u; i < min(u_globals.num_lights.x, c_max_lights); i++) {
let light = s_lights[i];
// project into the light space
let shadow = fetch_shadow(i, light.proj * _in.world_position);
let shadow = fetch_shadow(i, light.proj * in.world_position);
// compute Lambertian diffuse term
let light_dir = normalize(light.pos.xyz - _in.world_position.xyz);
let light_dir = normalize(light.pos.xyz - in.world_position.xyz);
let diffuse = max(0.0, dot(normal, light_dir));
// add light contribution
color += shadow * diffuse * light.color.xyz;
Expand All @@ -101,15 +101,15 @@ fn fs_main(_in: VertexOutput) -> @location(0) vec4<f32> {

// The fragment entrypoint used when storage buffers are not available for the lights
@fragment
fn fs_main_without_storage(_in: VertexOutput) -> @location(0) vec4<f32> {
let normal = normalize(_in.world_normal);
fn fs_main_without_storage(in: VertexOutput) -> @location(0) vec4<f32> {
let normal = normalize(in.world_normal);
var color: vec3<f32> = c_ambient;
for(var i = 0u; i < min(u_globals.num_lights.x, c_max_lights); i++) {
// This line is the only difference from the entrypoint above. It uses the lights
// uniform instead of the lights storage buffer
let light = u_lights[i];
let shadow = fetch_shadow(i, light.proj * _in.world_position);
let light_dir = normalize(light.pos.xyz - _in.world_position.xyz);
let shadow = fetch_shadow(i, light.proj * in.world_position);
let light_dir = normalize(light.pos.xyz - in.world_position.xyz);
let diffuse = max(0.0, dot(normal, light_dir));
color += shadow * diffuse * light.color.xyz;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/in/skybox.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ var r_texture: texture_cube<f32>;
var r_sampler: sampler;

@fragment
fn fs_main(_in: VertexOutput) -> @location(0) vec4<f32> {
return textureSample(r_texture, r_sampler, _in.uv);
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
return textureSample(r_texture, r_sampler, in.uv);
}
20 changes: 10 additions & 10 deletions tests/out/glsl/interpolate.vert_main.Vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ smooth centroid out float _vs2fs_location5;
smooth sample out float _vs2fs_location6;

void main() {
FragmentInput _out = FragmentInput(vec4(0.0), 0u, 0.0, vec2(0.0), vec3(0.0), vec4(0.0), 0.0, 0.0);
_out.position = vec4(2.0, 4.0, 5.0, 6.0);
_out._flat = 8u;
_out._linear = 27.0;
_out.linear_centroid = vec2(64.0, 125.0);
_out.linear_sample = vec3(216.0, 343.0, 512.0);
_out.perspective = vec4(729.0, 1000.0, 1331.0, 1728.0);
_out.perspective_centroid = 2197.0;
_out.perspective_sample = 2744.0;
FragmentInput _e30 = _out;
FragmentInput out_ = FragmentInput(vec4(0.0), 0u, 0.0, vec2(0.0), vec3(0.0), vec4(0.0), 0.0, 0.0);
out_.position = vec4(2.0, 4.0, 5.0, 6.0);
out_._flat = 8u;
out_._linear = 27.0;
out_.linear_centroid = vec2(64.0, 125.0);
out_.linear_sample = vec3(216.0, 343.0, 512.0);
out_.perspective = vec4(729.0, 1000.0, 1331.0, 1728.0);
out_.perspective_centroid = 2197.0;
out_.perspective_sample = 2744.0;
FragmentInput _e30 = out_;
gl_Position = _e30.position;
_vs2fs_location0 = _e30._flat;
_vs2fs_location1 = _e30._linear;
Expand Down
4 changes: 2 additions & 2 deletions tests/out/glsl/push-constants.main.Fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ layout(location = 0) smooth in vec4 _vs2fs_location0;
layout(location = 0) out vec4 _fs2p_location0;

void main() {
FragmentIn _in = FragmentIn(_vs2fs_location0);
FragmentIn in_ = FragmentIn(_vs2fs_location0);
float _e4 = pc.multiplier;
_fs2p_location0 = (_in.color * _e4);
_fs2p_location0 = (in_.color * _e4);
return;
}

8 changes: 4 additions & 4 deletions tests/out/glsl/shadow.fs_main.Fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ float fetch_shadow(uint light_id, vec4 homogeneous_coords) {
}

void main() {
VertexOutput _in = VertexOutput(gl_FragCoord, _vs2fs_location0, _vs2fs_location1);
VertexOutput in_ = VertexOutput(gl_FragCoord, _vs2fs_location0, _vs2fs_location1);
vec3 color = vec3(0.05000000074505806, 0.05000000074505806, 0.05000000074505806);
uint i = 0u;
vec3 normal_1 = normalize(_in.world_normal);
vec3 normal_1 = normalize(in_.world_normal);
bool loop_init = true;
while(true) {
if (!loop_init) {
Expand All @@ -65,8 +65,8 @@ void main() {
uint _e23 = i;
Light light = _group_0_binding_1_fs[_e23];
uint _e26 = i;
float _e30 = fetch_shadow(_e26, (light.proj * _in.world_position));
vec3 light_dir = normalize((light.pos.xyz - _in.world_position.xyz));
float _e30 = fetch_shadow(_e26, (light.proj * in_.world_position));
vec3 light_dir = normalize((light.pos.xyz - in_.world_position.xyz));
float diffuse = max(0.0, dot(normal_1, light_dir));
vec3 _e40 = color;
color = (_e40 + ((_e30 * diffuse) * light.color.xyz));
Expand Down
8 changes: 4 additions & 4 deletions tests/out/glsl/shadow.fs_main_without_storage.Fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ float fetch_shadow(uint light_id, vec4 homogeneous_coords) {
}

void main() {
VertexOutput _in_1 = VertexOutput(gl_FragCoord, _vs2fs_location0, _vs2fs_location1);
VertexOutput in_1 = VertexOutput(gl_FragCoord, _vs2fs_location0, _vs2fs_location1);
vec3 color_1 = vec3(0.05000000074505806, 0.05000000074505806, 0.05000000074505806);
uint i_1 = 0u;
vec3 normal_1 = normalize(_in_1.world_normal);
vec3 normal_1 = normalize(in_1.world_normal);
bool loop_init = true;
while(true) {
if (!loop_init) {
Expand All @@ -65,8 +65,8 @@ void main() {
uint _e23 = i_1;
Light light = _group_0_binding_1_fs[_e23];
uint _e26 = i_1;
float _e30 = fetch_shadow(_e26, (light.proj * _in_1.world_position));
vec3 light_dir = normalize((light.pos.xyz - _in_1.world_position.xyz));
float _e30 = fetch_shadow(_e26, (light.proj * in_1.world_position));
vec3 light_dir = normalize((light.pos.xyz - in_1.world_position.xyz));
float diffuse = max(0.0, dot(normal_1, light_dir));
vec3 _e40 = color_1;
color_1 = (_e40 + ((_e30 * diffuse) * light.color.xyz));
Expand Down
10 changes: 5 additions & 5 deletions tests/out/glsl/shadow.vs_main.Vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ layout(location = 1) smooth out vec4 _vs2fs_location1;
void main() {
ivec4 position = _p2vs_location0;
ivec4 normal = _p2vs_location1;
VertexOutput _out = VertexOutput(vec4(0.0), vec3(0.0), vec4(0.0));
VertexOutput out_ = VertexOutput(vec4(0.0), vec3(0.0), vec4(0.0));
mat4x4 w = _group_1_binding_0_vs.world;
mat4x4 _e7 = _group_1_binding_0_vs.world;
vec4 world_pos = (_e7 * vec4(position));
_out.world_normal = (mat3x3(w[0].xyz, w[1].xyz, w[2].xyz) * vec3(normal.xyz));
_out.world_position = world_pos;
out_.world_normal = (mat3x3(w[0].xyz, w[1].xyz, w[2].xyz) * vec3(normal.xyz));
out_.world_position = world_pos;
mat4x4 _e25 = _group_0_binding_0_vs.view_proj;
_out.proj_position = (_e25 * world_pos);
VertexOutput _e27 = _out;
out_.proj_position = (_e25 * world_pos);
VertexOutput _e27 = out_;
gl_Position = _e27.proj_position;
_vs2fs_location0 = _e27.world_normal;
_vs2fs_location1 = _e27.world_position;
Expand Down
4 changes: 2 additions & 2 deletions tests/out/glsl/skybox.fs_main.Fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ layout(location = 0) smooth in vec3 _vs2fs_location0;
layout(location = 0) out vec4 _fs2p_location0;

void main() {
VertexOutput _in = VertexOutput(gl_FragCoord, _vs2fs_location0);
vec4 _e5 = texture(_group_0_binding_1_fs, vec3(_in.uv));
VertexOutput in_ = VertexOutput(gl_FragCoord, _vs2fs_location0);
vec4 _e5 = texture(_group_0_binding_1_fs, vec3(in_.uv));
_fs2p_location0 = _e5;
return;
}
Expand Down
8 changes: 4 additions & 4 deletions tests/out/hlsl/interface.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct Input2_ {
uint index : SV_InstanceID;
};

groupshared uint _output[1];
groupshared uint output[1];

struct VertexOutput_vertex {
float _varying : LOC1;
Expand Down Expand Up @@ -64,20 +64,20 @@ FragmentOutput ConstructFragmentOutput(float arg0, uint arg1, float arg2) {

FragmentOutput fragment(FragmentInput_fragment fragmentinput_fragment)
{
VertexOutput _in = { fragmentinput_fragment.position_1, fragmentinput_fragment._varying_1 };
VertexOutput in_ = { fragmentinput_fragment.position_1, fragmentinput_fragment._varying_1 };
bool front_facing = fragmentinput_fragment.front_facing_1;
uint sample_index = fragmentinput_fragment.sample_index_1;
uint sample_mask = fragmentinput_fragment.sample_mask_1;
uint mask = (sample_mask & (1u << sample_index));
float color_1 = (front_facing ? 1.0 : 0.0);
const FragmentOutput fragmentoutput = ConstructFragmentOutput(_in._varying, mask, color_1);
const FragmentOutput fragmentoutput = ConstructFragmentOutput(in_._varying, mask, color_1);
return fragmentoutput;
}

[numthreads(1, 1, 1)]
void compute(uint3 global_id : SV_DispatchThreadID, uint3 local_id : SV_GroupThreadID, uint local_index : SV_GroupIndex, uint3 wg_id : SV_GroupID, uint3 num_wgs : SV_GroupID)
{
_output[0] = ((((global_id.x + local_id.x) + local_index) + wg_id.x) + uint3(_NagaConstants.base_vertex, _NagaConstants.base_instance, _NagaConstants.other).x);
output[0] = ((((global_id.x + local_id.x) + local_index) + wg_id.x) + uint3(_NagaConstants.base_vertex, _NagaConstants.base_instance, _NagaConstants.other).x);
return;
}

Expand Down
20 changes: 10 additions & 10 deletions tests/out/hlsl/interpolate.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ struct FragmentInput_frag_main {

VertexOutput_vert_main vert_main()
{
FragmentInput _out = (FragmentInput)0;
FragmentInput out_ = (FragmentInput)0;

_out.position = float4(2.0, 4.0, 5.0, 6.0);
_out._flat = 8u;
_out._linear = 27.0;
_out.linear_centroid = float2(64.0, 125.0);
_out.linear_sample = float3(216.0, 343.0, 512.0);
_out.perspective = float4(729.0, 1000.0, 1331.0, 1728.0);
_out.perspective_centroid = 2197.0;
_out.perspective_sample = 2744.0;
FragmentInput _expr30 = _out;
out_.position = float4(2.0, 4.0, 5.0, 6.0);
out_._flat = 8u;
out_._linear = 27.0;
out_.linear_centroid = float2(64.0, 125.0);
out_.linear_sample = float3(216.0, 343.0, 512.0);
out_.perspective = float4(729.0, 1000.0, 1331.0, 1728.0);
out_.perspective_centroid = 2197.0;
out_.perspective_sample = 2744.0;
FragmentInput _expr30 = out_;
const FragmentInput fragmentinput = _expr30;
const VertexOutput_vert_main fragmentinput_1 = { fragmentinput._flat, fragmentinput._linear, fragmentinput.linear_centroid, fragmentinput.linear_sample, fragmentinput.perspective, fragmentinput.perspective_centroid, fragmentinput.perspective_sample, fragmentinput.position };
return fragmentinput_1;
Expand Down
Loading