Skip to content
This repository has been archived by the owner on Jan 29, 2025. It is now read-only.

Force-bake array values in MSL #1578

Closed
kvark opened this issue Dec 6, 2021 · 2 comments
Closed

Force-bake array values in MSL #1578

kvark opened this issue Dec 6, 2021 · 2 comments
Labels
area: back-end Outputs of shader conversion kind: feature New feature or request lang: Metal Metal Shading Language

Comments

@kvark
Copy link
Member

kvark commented Dec 6, 2021

Input WGSL

[[block]] struct BufferCoords { coords: array<vec2<f32>>; };
[[group(0), binding(0)]] var<storage, read> bufferCoords : BufferCoords;

var<private> coords : array<vec2<f32>, 3> = array<vec2<f32>, 3>(
	vec2<f32>(-1.0, -1.0),
	vec2<f32>( 1.0, -1.0),
	vec2<f32>( 0.0,  1.0)
);

struct VertInput { [[builtin(vertex_index)]] index : u32; };
struct VertOutput { [[builtin(position)]] Position : vec4<f32>; };
struct FragOutput { [[location(0)]] color : vec4<f32>; };

[[stage(vertex)]] fn vertMain(input : VertInput) -> VertOutput {
	var coord = bufferCoords.coords[0];

	 var coords : array<vec2<f32>, 3> = array<vec2<f32>, 3>(
	 	vec2<f32>(-1.0, -1.0),
	 	vec2<f32>( 1.0, -1.0),
	 	vec2<f32>( 0.0,  1.0)
	 );

	return VertOutput(vec4<f32>(coords[i32(input.index)], 0.0, 1.0));
}

[[stage(fragment)]] fn fragMain() -> FragOutput {
	return FragOutput(vec4<f32>(1.0));
}

Translates to Metal with this piece:

    type_2 coords;
    metal::float2 _e6 = bufferCoords.coords[0];
    coord = _e6;
    for(int _i=0; _i<3; ++_i) coords.inner[_i] = type_2 {metal::float2(-1.0, -1.0), metal::float2(1.0, -1.0), metal::float2(0.0, 1.0)}.inner[_i];

It's unfortunate because it creates the array inside the copy loop.
We should at least force it to bake that value first.

@kvark kvark added kind: feature New feature or request lang: Metal Metal Shading Language area: back-end Outputs of shader conversion labels Dec 6, 2021
@kvark
Copy link
Member Author

kvark commented Dec 6, 2021

We should do it after #1532 since there is going to be infrastructure to forcing the baking of more expressions.

@teoxoy
Copy link
Member

teoxoy commented May 10, 2023

This is no longer necessary due to #764 and #2331.

@teoxoy teoxoy closed this as not planned Won't fix, can't repro, duplicate, stale May 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: back-end Outputs of shader conversion kind: feature New feature or request lang: Metal Metal Shading Language
Projects
None yet
Development

No branches or pull requests

2 participants