This is Rust/wgpu compiled to wasm/webgl and running on Chrome. The baffling part is that the variables it claims I use -- I don't actually use.
full error
used by:
In Device::create_render_pipeline
Internal error in VERTEX shader: ERROR: 0:20: 'Temp1__block_0Vertex' : identifiers containing two consecutive underscores (__) are reserved as possible future keywords
ERROR: 0:22: 'Temp2__block_1Vertex' : identifiers containing two consecutive underscores (__) are reserved as possible future keywords
rust code used to set everything up:
let skybox_pipeline = {
let vertex_shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: Some("Shader"),
source: wgpu::ShaderSource::Wgsl(include_str!("shaders/skybox.vert.wgsl").into()),});
let fragment_shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: Some("Shader"),
source: wgpu::ShaderSource::Wgsl(include_str!("shaders/skybox.frag.wgsl").into()),});
create_default_pipeline(
"skybox",
device,
&vpm_bind_group_layout,
vertex_shader,
fragment_shader,
wgpu::PrimitiveTopology::TriangleList,
wgpu::VertexBufferLayout {
array_stride: std::mem::size_of::<SkyboxVertex>() as u64,
step_mode: wgpu::VertexStepMode::Vertex,
attributes: &SKYBOX_VERTEX_ATTRIBUTES,},
false,
surface_format,)};
skybox.vert (original; not wgsl; not used)
#version 450
layout(location = 0) in vec3 a_Pos;
layout(location = 0) out vec3 pos;
layout(set = 0, binding = 0) uniform Temp1 { mat4 u_ViewProj; };
layout(set = 0, binding = 1) uniform Temp2 { mat4 u_Model; };
void main() {
pos = a_Pos;
gl_Position = u_ViewProj * u_Model * vec4(a_Pos, 1.0);
}
skybox.frag (original; not wgsl; not used)
#version 450
layout(location = 0) in vec3 pos;
layout(location = 0) out vec4 ColorBuffer;
float dist_sphere(vec3 v1, vec3 v2){
float cos_angle = dot(v1, v2);
float angle = acos(cos_angle);
return min(angle, 2.0*3.1415926535 - angle);
}
vec3 getSky(vec3 pos, vec3 sun_pos)
{
float y_lim = clamp(pos.y, 0.0, 1.0) - 5*clamp(pos.y, -0.2, 0.0);
float atmosphere = pow(1.0-y_lim, 1.4);
vec3 skyColor = vec3(0.2,0.4,0.8);
float scatter = pow(1.0 - dist_sphere(pos, sun_pos)/(3.1415926535), 1.0 / 30.0);
scatter = 1.0 - clamp(scatter,0.8,1.0);
vec3 scatterColor = mix(vec3(1.0),vec3(1.0,0.3,0.0) * 1.5,scatter);
return mix(skyColor,vec3(scatterColor), atmosphere / 1.3);
}
vec3 getSun(vec3 pos, vec3 sun_pos){
float sun = 1.0 - dist_sphere(pos, sun_pos);
sun = clamp(sun,0.0,1.0);
float glow = sun;
glow = clamp(glow,0.0,1.0);
sun = pow(sun,100.0);
sun *= 100.0;
sun = clamp(sun,0.0,1.0);
float y_lim = clamp(pos.y, 0.0, 1.0) - 5*clamp(pos.y, -0.2, 0.0);
glow = pow(glow,6.0) * 1.0;
glow = pow(glow,(y_lim));
glow = clamp(glow,0.0,1.0);
sun *= pow((y_lim * y_lim), 1.0 / 1.65);
glow *= pow((y_lim * y_lim), 1.0 / 2.0);
sun += glow;
vec3 sunColor = vec3(1.0,0.6,0.05) * sun;
return vec3(sunColor);
}
void main() {
vec3 pos_norm = normalize(pos);
vec3 sun_pos = normalize(vec3(1.0, 0.75, 1.0));
vec3 sky = getSky(pos_norm, sun_pos);
vec3 sun = getSun(pos_norm, sun_pos);
ColorBuffer = vec4(sky + sun,1.0);
}
skybox.vert.wgsl (generated via naga)
struct Temp1 {
u_ViewProj: mat4x4<f32>,
}
struct Temp2 {
u_Model: mat4x4<f32>,
}
struct VertexOutput {
@location(0) v_Norm: vec3<f32>,
@location(1) occl: f32,
@location(2) v_Rgb: vec3<f32>,
@builtin(position) member: vec4<f32>,
}
var<private> a_Pos_1: vec3<f32>;
var<private> a_Info_1: u32;
@group(0) @binding(0)
var<uniform> global: Temp1;
@group(0) @binding(1)
var<uniform> global_1: Temp2;
var<private> v_Norm: vec3<f32>;
var<private> occl: f32;
var<private> v_Rgb: vec3<f32>;
var<private> gl_Position: vec4<f32>;
fn get_normal(id: u32) -> vec3<f32> {
var id_1: u32;
_ = (&global.u_ViewProj);
_ = (&global_1.u_Model);
id_1 = id;
let _e11 = id_1;
if (_e11 == 0u) {
{
return vec3<f32>(1.0, 0.0, 0.0);
}
} else {
let _e18 = id_1;
if (_e18 == 1u) {
{
return vec3<f32>(-(1.0), 0.0, 0.0);
}
} else {
let _e26 = id_1;
if (_e26 == 2u) {
{
return vec3<f32>(0.0, 1.0, 0.0);
}
} else {
let _e33 = id_1;
if (_e33 == 3u) {
{
return vec3<f32>(0.0, -(1.0), 0.0);
}
} else {
let _e41 = id_1;
if (_e41 == 4u) {
{
return vec3<f32>(0.0, 0.0, 1.0);
}
} else {
{
return vec3<f32>(0.0, 0.0, -(1.0));
}
}
}
}
}
}
}
fn main_1() {
var b: u32;
var g: u32;
var r: u32;
var code_occl: u32;
var normal: u32;
var rr: f32;
var gg: f32;
var bb: f32;
let _e10 = global.u_ViewProj;
let _e11 = global_1.u_Model;
let _e13 = a_Pos_1;
gl_Position = ((_e10 * _e11) * vec4<f32>(_e13.x, _e13.y, _e13.z, 1.0));
let _e20 = a_Info_1;
b = ((_e20 & 16711680u) >> 16u);
let _e26 = a_Info_1;
g = ((_e26 & 65280u) >> 8u);
let _e32 = a_Info_1;
r = (_e32 & 255u);
let _e36 = a_Info_1;
code_occl = (_e36 >> 27u);
let _e40 = a_Info_1;
let _e41 = code_occl;
normal = ((_e40 - (_e41 << 27u)) >> 24u);
let _e48 = code_occl;
if (_e48 == 3u) {
{
occl = 1.0;
}
} else {
let _e52 = code_occl;
if (_e52 == 2u) {
{
occl = 0.800000011920929;
}
} else {
let _e56 = code_occl;
if (_e56 == 1u) {
{
occl = 0.6000000238418579;
}
} else {
{
occl = 0.5;
}
}
}
}
_ = normal;
let _e62 = normal;
let _e63 = get_normal(_e62);
v_Norm = _e63;
let _e64 = r;
rr = (f32(_e64) / 255.0);
let _e69 = g;
gg = (f32(_e69) / 255.0);
let _e74 = b;
bb = (f32(_e74) / 255.0);
let _e79 = rr;
let _e80 = gg;
let _e81 = bb;
v_Rgb = vec3<f32>(_e79, _e80, _e81);
return;
}
@vertex
fn main(@location(0) a_Pos: vec3<f32>, @location(1) a_Info: u32) -> VertexOutput {
a_Pos_1 = a_Pos;
a_Info_1 = a_Info;
_ = (&global.u_ViewProj);
_ = (&global_1.u_Model);
main_1();
let _e19 = v_Norm;
let _e21 = occl;
let _e23 = v_Rgb;
let _e25 = gl_Position;
return VertexOutput(_e19, _e21, _e23, _e25);
}
skybox.frag.wgsl (generated via naga)
struct FragmentOutput {
@location(0) ColorBuffer: vec4<f32>,
}
var<private> pos_5: vec3<f32>;
var<private> ColorBuffer: vec4<f32>;
fn dist_sphere(v1_: vec3<f32>, v2_: vec3<f32>) -> f32 {
var v1_1: vec3<f32>;
var v2_1: vec3<f32>;
var cos_angle: f32;
var angle: f32;
v1_1 = v1_;
v2_1 = v2_;
_ = v1_1;
_ = v2_1;
let _e8 = v1_1;
let _e9 = v2_1;
cos_angle = dot(_e8, _e9);
_ = cos_angle;
let _e13 = cos_angle;
angle = acos(_e13);
_ = angle;
let _e20 = angle;
_ = ((2.0 * 3.1415927410125732) - _e20);
let _e22 = angle;
let _e26 = angle;
return min(_e22, ((2.0 * 3.1415927410125732) - _e26));
}
fn getSky(pos_1: vec3<f32>, sun_pos: vec3<f32>) -> vec3<f32> {
var pos_2: vec3<f32>;
var sun_pos_1: vec3<f32>;
var y_lim: f32;
var atmosphere: f32;
var skyColor: vec3<f32>;
var scatter: f32;
var scatterColor: vec3<f32>;
pos_2 = pos_1;
sun_pos_1 = sun_pos;
let _e6 = pos_2;
_ = _e6.y;
let _e10 = pos_2;
let _e16 = pos_2;
_ = _e16.y;
_ = -(0.20000000298023224);
let _e21 = pos_2;
y_lim = (clamp(_e10.y, 0.0, 1.0) - (f32(5) * clamp(_e21.y, -(0.20000000298023224), 0.0)));
let _e32 = y_lim;
_ = (1.0 - _e32);
let _e36 = y_lim;
atmosphere = pow((1.0 - _e36), 1.399999976158142);
skyColor = vec3<f32>(0.20000000298023224, 0.4000000059604645, 0.800000011920929);
_ = pos_2;
_ = sun_pos_1;
let _e49 = pos_2;
let _e50 = sun_pos_1;
let _e51 = dist_sphere(_e49, _e50);
_ = (1.0 - (_e51 / 3.1415927410125732));
_ = (1.0 / 30.0);
_ = pos_2;
_ = sun_pos_1;
let _e61 = pos_2;
let _e62 = sun_pos_1;
let _e63 = dist_sphere(_e61, _e62);
scatter = pow((1.0 - (_e63 / 3.1415927410125732)), (1.0 / 30.0));
_ = scatter;
let _e76 = scatter;
scatter = (1.0 - clamp(_e76, 0.800000011920929, 1.0));
_ = vec3<f32>(1.0);
_ = (vec3<f32>(1.0, 0.30000001192092896, 0.0) * 1.5);
_ = scatter;
let _e98 = scatter;
scatterColor = mix(vec3<f32>(1.0), (vec3<f32>(1.0, 0.30000001192092896, 0.0) * 1.5), vec3<f32>(_e98));
_ = skyColor;
let _e103 = scatterColor;
_ = vec3<f32>(_e103);
let _e105 = atmosphere;
_ = (_e105 / 1.2999999523162842);
let _e108 = skyColor;
let _e109 = scatterColor;
let _e111 = atmosphere;
return mix(_e108, vec3<f32>(_e109), vec3<f32>((_e111 / 1.2999999523162842)));
}
fn getSun(pos_3: vec3<f32>, sun_pos_2: vec3<f32>) -> vec3<f32> {
var pos_4: vec3<f32>;
var sun_pos_3: vec3<f32>;
var sun: f32;
var glow: f32;
var y_lim_1: f32;
var sunColor: vec3<f32>;
pos_4 = pos_3;
sun_pos_3 = sun_pos_2;
_ = pos_4;
_ = sun_pos_3;
let _e9 = pos_4;
let _e10 = sun_pos_3;
let _e11 = dist_sphere(_e9, _e10);
sun = (1.0 - _e11);
_ = sun;
let _e17 = sun;
sun = clamp(_e17, 0.0, 1.0);
let _e21 = sun;
glow = _e21;
_ = glow;
let _e26 = glow;
glow = clamp(_e26, 0.0, 1.0);
_ = sun;
let _e32 = sun;
sun = pow(_e32, 100.0);
let _e35 = sun;
sun = (_e35 * 100.0);
_ = sun;
let _e41 = sun;
sun = clamp(_e41, 0.0, 1.0);
let _e45 = pos_4;
_ = _e45.y;
let _e49 = pos_4;
let _e55 = pos_4;
_ = _e55.y;
_ = -(0.20000000298023224);
let _e60 = pos_4;
y_lim_1 = (clamp(_e49.y, 0.0, 1.0) - (f32(5) * clamp(_e60.y, -(0.20000000298023224), 0.0)));
_ = glow;
let _e72 = glow;
glow = (pow(_e72, 6.0) * 1.0);
_ = glow;
_ = y_lim_1;
let _e79 = glow;
let _e80 = y_lim_1;
glow = pow(_e79, _e80);
_ = glow;
let _e85 = glow;
glow = clamp(_e85, 0.0, 1.0);
let _e89 = sun;
let _e90 = y_lim_1;
let _e91 = y_lim_1;
_ = (_e90 * _e91);
_ = (1.0 / 1.649999976158142);
let _e96 = y_lim_1;
let _e97 = y_lim_1;
sun = (_e89 * pow((_e96 * _e97), (1.0 / 1.649999976158142)));
let _e104 = glow;
let _e105 = y_lim_1;
let _e106 = y_lim_1;
_ = (_e105 * _e106);
_ = (1.0 / 2.0);
let _e111 = y_lim_1;
let _e112 = y_lim_1;
glow = (_e104 * pow((_e111 * _e112), (1.0 / 2.0)));
let _e119 = sun;
let _e120 = glow;
sun = (_e119 + _e120);
let _e126 = sun;
sunColor = (vec3<f32>(1.0, 0.6000000238418579, 0.05000000074505806) * _e126);
let _e129 = sunColor;
return vec3<f32>(_e129);
}
fn main_1() {
var pos_norm: vec3<f32>;
var sun_pos_4: vec3<f32>;
var sky: vec3<f32>;
var sun_1: vec3<f32>;
_ = pos_5;
let _e3 = pos_5;
pos_norm = normalize(_e3);
_ = vec3<f32>(1.0, 0.75, 1.0);
sun_pos_4 = normalize(vec3<f32>(1.0, 0.75, 1.0));
_ = pos_norm;
_ = sun_pos_4;
let _e18 = pos_norm;
let _e19 = sun_pos_4;
let _e20 = getSky(_e18, _e19);
sky = _e20;
_ = pos_norm;
_ = sun_pos_4;
let _e24 = pos_norm;
let _e25 = sun_pos_4;
let _e26 = getSun(_e24, _e25);
sun_1 = _e26;
let _e28 = sky;
let _e29 = sun_1;
let _e30 = (_e28 + _e29);
ColorBuffer = vec4<f32>(_e30.x, _e30.y, _e30.z, 1.0);
return;
}
@fragment
fn main(@location(0) pos: vec3<f32>) -> FragmentOutput {
pos_5 = pos;
main_1();
let _e7 = ColorBuffer;
return FragmentOutput(_e7);
}
questions:
So the variable Temp1__block_0Vertex never appears in the source above. WTF is going on ?
is the wtsl -> glsl compiler adding in these new variables? If so, is there a way to tell wtgpu to dump out the glsl it is generating ?
Thanks!