Snapshot for built-ins

This commit is contained in:
Dzmitry Malyshau
2021-05-17 22:00:12 -04:00
committed by Dzmitry Malyshau
parent 8b60171403
commit 96ec0b61e7
6 changed files with 239 additions and 1 deletions

View File

@@ -97,7 +97,7 @@ impl FeaturesManager {
// gl_ClipDistance is supported by core versions > 1.3 and aren't supported by an es versions without extensions
check_feature!(CLIP_DISTANCE, 130, 300);
check_feature!(CULL_DISTANCE, 450, 300);
check_feature!(SAMPLE_VARIABLES, 300, 300);
check_feature!(SAMPLE_VARIABLES, 400, 300);
// Return an error if there are missing features
if missing.is_empty() {

View File

@@ -0,0 +1,5 @@
(
spv_version: (1, 0),
spv_capabilities: [ Shader, SampleRateShading ],
spv_adjust_coordinate_space: false,
)

45
tests/in/interface.wgsl Normal file
View File

@@ -0,0 +1,45 @@
// Testing various parts of the pipeline interface: locations, built-ins, bindings, and entry points
struct VertexOutput {
[[builtin(position)]] position: vec4<f32>;
[[location(1)]] varying: f32;
};
[[stage(vertex)]]
fn vertex(
[[builtin(vertex_index)]] vertex_index: u32,
[[builtin(instance_index)]] instance_index: u32,
[[location(10)]] color: u32,
) -> VertexOutput {
let tmp = vertex_index + instance_index + color;
return VertexOutput(vec4<f32>(1.0), f32(tmp));
}
struct FragmentOutput {
[[builtin(frag_depth)]] depth: f32;
[[builtin(sample_mask)]] sample_mask: u32;
[[location(0)]] color: f32;
};
[[stage(fragment)]]
fn fragment(
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);
}
[[stage(compute), workgroup_size(1)]]
fn compute(
[[builtin(global_invocation_id)]] global_id: vec3<u32>,
[[builtin(local_invocation_id)]] local_id: vec3<u32>,
[[builtin(local_invocation_index)]] local_index: u32,
[[builtin(workgroup_id)]] wg_id: vec3<u32>,
//TODO: https://github.com/gpuweb/gpuweb/issues/1590
//[[builtin(workgroup_size)]] wg_size: vec3<u32>,
) {
}

62
tests/out/interface.msl Normal file
View File

@@ -0,0 +1,62 @@
#include <metal_stdlib>
#include <simd/simd.h>
struct VertexOutput {
metal::float4 position;
float varying;
};
struct FragmentOutput {
float depth;
metal::uint sample_mask;
float color;
};
struct vertex1Input {
metal::uint color1 [[attribute(10)]];
};
struct vertex1Output {
metal::float4 position [[position]];
float varying [[user(loc1), center_perspective]];
};
vertex vertex1Output vertex1(
vertex1Input varyings [[stage_in]]
, metal::uint vertex_index [[vertex_id]]
, metal::uint instance_index [[instance_id]]
) {
const auto color1 = varyings.color1;
const auto _tmp = VertexOutput {metal::float4(1.0), static_cast<float>((vertex_index + instance_index) + color1)};
return vertex1Output { _tmp.position, _tmp.varying };
}
struct fragment1Input {
float varying [[user(loc1), center_perspective]];
};
struct fragment1Output {
float depth [[depth(any)]];
metal::uint sample_mask [[sample_mask]];
float color [[color(0)]];
};
fragment fragment1Output fragment1(
fragment1Input varyings1 [[stage_in]]
, metal::float4 position [[position]]
, bool front_facing [[front_facing]]
, metal::uint sample_index [[sample_id]]
, metal::uint sample_mask1 [[sample_mask]]
) {
const VertexOutput in = { position, varyings1.varying };
const auto _tmp = FragmentOutput {in.varying, sample_mask1 & (1u << sample_index), front_facing ? 0.0 : 1.0};
return fragment1Output { _tmp.depth, _tmp.sample_mask, _tmp.color };
}
struct compute1Input {
};
kernel void compute1(
metal::uint3 global_id [[thread_position_in_grid]]
, metal::uint3 local_id [[thread_position_in_threadgroup]]
, metal::uint local_index [[thread_index_in_threadgroup]]
, metal::uint3 wg_id [[threadgroup_position_in_grid]]
) {
return;
}

124
tests/out/interface.spvasm Normal file
View File

@@ -0,0 +1,124 @@
; SPIR-V
; Version: 1.0
; Generator: rspirv
; Bound: 76
OpCapability Shader
OpCapability SampleRateShading
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Vertex %25 "vertex" %14 %17 %19 %21 %23
OpEntryPoint Fragment %54 "fragment" %37 %40 %43 %46 %48 %50 %51 %53
OpEntryPoint GLCompute %74 "compute" %65 %68 %70 %72
OpExecutionMode %54 OriginUpperLeft
OpExecutionMode %54 DepthReplacing
OpExecutionMode %74 LocalSize 1 1 1
OpMemberDecorate %9 0 Offset 0
OpMemberDecorate %9 1 Offset 16
OpMemberDecorate %10 0 Offset 0
OpMemberDecorate %10 1 Offset 4
OpMemberDecorate %10 2 Offset 8
OpDecorate %14 BuiltIn VertexIndex
OpDecorate %17 BuiltIn InstanceIndex
OpDecorate %19 Location 10
OpDecorate %21 BuiltIn Position
OpDecorate %23 Location 1
OpDecorate %37 BuiltIn FragCoord
OpDecorate %40 Location 1
OpDecorate %43 BuiltIn FrontFacing
OpDecorate %46 BuiltIn SampleId
OpDecorate %48 BuiltIn SampleMask
OpDecorate %50 BuiltIn FragDepth
OpDecorate %51 BuiltIn SampleMask
OpDecorate %53 Location 0
OpDecorate %65 BuiltIn GlobalInvocationId
OpDecorate %68 BuiltIn LocalInvocationId
OpDecorate %70 BuiltIn LocalInvocationIndex
OpDecorate %72 BuiltIn WorkgroupId
%2 = OpTypeVoid
%4 = OpTypeFloat 32
%3 = OpConstant %4 1.0
%6 = OpTypeInt 32 0
%5 = OpConstant %6 1
%7 = OpConstant %4 0.0
%8 = OpTypeVector %4 4
%9 = OpTypeStruct %8 %4
%10 = OpTypeStruct %4 %6 %4
%11 = OpTypeBool
%12 = OpTypeVector %6 3
%15 = OpTypePointer Input %6
%14 = OpVariable %15 Input
%17 = OpVariable %15 Input
%19 = OpVariable %15 Input
%22 = OpTypePointer Output %8
%21 = OpVariable %22 Output
%24 = OpTypePointer Output %4
%23 = OpVariable %24 Output
%26 = OpTypeFunction %2
%38 = OpTypePointer Input %8
%37 = OpVariable %38 Input
%41 = OpTypePointer Input %4
%40 = OpVariable %41 Input
%44 = OpTypePointer Input %11
%43 = OpVariable %44 Input
%46 = OpVariable %15 Input
%48 = OpVariable %15 Input
%50 = OpVariable %24 Output
%52 = OpTypePointer Output %6
%51 = OpVariable %52 Output
%53 = OpVariable %24 Output
%66 = OpTypePointer Input %12
%65 = OpVariable %66 Input
%68 = OpVariable %66 Input
%70 = OpVariable %15 Input
%72 = OpVariable %66 Input
%25 = OpFunction %2 None %26
%13 = OpLabel
%16 = OpLoad %6 %14
%18 = OpLoad %6 %17
%20 = OpLoad %6 %19
OpBranch %27
%27 = OpLabel
%28 = OpIAdd %6 %16 %18
%29 = OpIAdd %6 %28 %20
%30 = OpCompositeConstruct %8 %3 %3 %3 %3
%31 = OpConvertUToF %4 %29
%32 = OpCompositeConstruct %9 %30 %31
%33 = OpCompositeExtract %8 %32 0
OpStore %21 %33
%34 = OpCompositeExtract %4 %32 1
OpStore %23 %34
OpReturn
OpFunctionEnd
%54 = OpFunction %2 None %26
%35 = OpLabel
%39 = OpLoad %8 %37
%42 = OpLoad %4 %40
%36 = OpCompositeConstruct %9 %39 %42
%45 = OpLoad %11 %43
%47 = OpLoad %6 %46
%49 = OpLoad %6 %48
OpBranch %55
%55 = OpLabel
%56 = OpShiftLeftLogical %6 %5 %47
%57 = OpBitwiseAnd %6 %49 %56
%58 = OpSelect %4 %45 %7 %3
%59 = OpCompositeExtract %4 %36 1
%60 = OpCompositeConstruct %10 %59 %57 %58
%61 = OpCompositeExtract %4 %60 0
OpStore %50 %61
%62 = OpCompositeExtract %6 %60 1
OpStore %51 %62
%63 = OpCompositeExtract %4 %60 2
OpStore %53 %63
OpReturn
OpFunctionEnd
%74 = OpFunction %2 None %26
%64 = OpLabel
%67 = OpLoad %12 %65
%69 = OpLoad %12 %68
%71 = OpLoad %6 %70
%73 = OpLoad %12 %72
OpBranch %75
%75 = OpLabel
OpReturn
OpFunctionEnd

View File

@@ -267,6 +267,8 @@ fn convert_wgsl() {
Targets::SPIRV | Targets::METAL | Targets::GLSL,
),
("standard", Targets::SPIRV | Targets::METAL | Targets::GLSL),
//TODO: GLSL https://github.com/gfx-rs/naga/issues/874
("interface", Targets::SPIRV | Targets::METAL),
];
for &(name, targets) in inputs.iter() {