mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-19 14:01:08 +01:00
Fixes #1745: Support out-of-order module scope declarations in WGSL Fixes #1044: Forbid local variable shadowing in WGSL Fixes #2076: [wgsl-in] no error for duplicated type definition Fixes #2071: Global item does not support 'const' Fixes #2105: [wgsl-in] Type aliases for a vecN<T> doesn't work when constructing vec from a single argument Fixes #1775: Referencing a function without a return type yields an unknown identifier error. Fixes #2089: Error span reported on the declaration of a variable instead of its use Fixes #1996: [wgsl-in] Confusing error: "expected unsigned/signed integer literal, found '1'" Separate parsing from lowering by generating an AST, which desugars as much as possible down to something like Naga IR. The AST is then used to resolve identifiers while lowering to Naga IR. Co-authored-by: Teodor Tanasoaia <28601907+teoxoy@users.noreply.github.com> Co-authored-by: Jim Blandy <jimb@red-bean.com>
67 lines
2.0 KiB
Plaintext
67 lines
2.0 KiB
Plaintext
// language: metal2.1
|
|
#include <metal_stdlib>
|
|
#include <simd/simd.h>
|
|
|
|
using metal::uint;
|
|
|
|
struct VertexOutput {
|
|
metal::float4 position;
|
|
metal::float3 uv;
|
|
};
|
|
struct Data {
|
|
metal::float4x4 proj_inv;
|
|
metal::float4x4 view;
|
|
};
|
|
|
|
struct vs_mainInput {
|
|
};
|
|
struct vs_mainOutput {
|
|
metal::float4 position [[position]];
|
|
metal::float3 uv [[user(loc0), center_perspective]];
|
|
};
|
|
vertex vs_mainOutput vs_main(
|
|
uint vertex_index [[vertex_id]]
|
|
, constant Data& r_data [[buffer(0)]]
|
|
) {
|
|
int tmp1_ = {};
|
|
int tmp2_ = {};
|
|
tmp1_ = static_cast<int>(vertex_index) / 2;
|
|
tmp2_ = static_cast<int>(vertex_index) & 1;
|
|
int _e9 = tmp1_;
|
|
int _e15 = tmp2_;
|
|
metal::float4 pos = metal::float4((static_cast<float>(_e9) * 4.0) - 1.0, (static_cast<float>(_e15) * 4.0) - 1.0, 0.0, 1.0);
|
|
metal::float4 _e27 = r_data.view[0];
|
|
metal::float4 _e32 = r_data.view[1];
|
|
metal::float4 _e37 = r_data.view[2];
|
|
metal::float3x3 inv_model_view = metal::transpose(metal::float3x3(_e27.xyz, _e32.xyz, _e37.xyz));
|
|
metal::float4x4 _e43 = r_data.proj_inv;
|
|
metal::float4 unprojected = _e43 * pos;
|
|
const auto _tmp = VertexOutput {pos, inv_model_view * unprojected.xyz};
|
|
return vs_mainOutput { _tmp.position, _tmp.uv };
|
|
}
|
|
|
|
|
|
struct fs_mainInput {
|
|
metal::float3 uv [[user(loc0), center_perspective]];
|
|
};
|
|
struct fs_mainOutput {
|
|
metal::float4 member_1 [[color(0)]];
|
|
};
|
|
fragment fs_mainOutput fs_main(
|
|
fs_mainInput varyings_1 [[stage_in]]
|
|
, metal::float4 position [[position]]
|
|
, metal::texturecube<float, metal::access::sample> r_texture [[texture(0)]]
|
|
) {
|
|
constexpr metal::sampler r_sampler(
|
|
metal::s_address::clamp_to_edge,
|
|
metal::t_address::clamp_to_edge,
|
|
metal::r_address::clamp_to_edge,
|
|
metal::mag_filter::linear,
|
|
metal::min_filter::linear,
|
|
metal::coord::normalized
|
|
);
|
|
const VertexOutput in = { position, varyings_1.uv };
|
|
metal::float4 _e4 = r_texture.sample(r_sampler, in.uv);
|
|
return fs_mainOutput { _e4 };
|
|
}
|