Skip to content

Commit

Permalink
Add test for sample mask bulk load/store.
Browse files Browse the repository at this point in the history
  • Loading branch information
HansKristian-Work committed Oct 23, 2023
1 parent 0bedb69 commit 56bdcfa
Show file tree
Hide file tree
Showing 12 changed files with 457 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
static uint gl_SampleMaskIn[1];
static uint gl_SampleMask[1];
struct SPIRV_Cross_Input
{
uint gl_SampleMaskIn : SV_Coverage;
};

struct SPIRV_Cross_Output
{
uint gl_SampleMask : SV_Coverage;
};

void frag_main()
{
uint copy_sample_mask[1] = gl_SampleMaskIn;
gl_SampleMask = copy_sample_mask;
}

SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
{
gl_SampleMaskIn[0] = stage_input.gl_SampleMaskIn;
frag_main();
SPIRV_Cross_Output stage_output;
stage_output.gl_SampleMask = gl_SampleMask[0];
return stage_output;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
static int gl_SampleMaskIn[1];
static int gl_SampleMask[1];
struct SPIRV_Cross_Input
{
uint gl_SampleMaskIn : SV_Coverage;
};

struct SPIRV_Cross_Output
{
uint gl_SampleMask : SV_Coverage;
};

void frag_main()
{
int copy_sample_mask[1] = gl_SampleMaskIn;
gl_SampleMask = copy_sample_mask;
}

SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
{
gl_SampleMaskIn[0] = stage_input.gl_SampleMaskIn;
frag_main();
SPIRV_Cross_Output stage_output;
stage_output.gl_SampleMask = gl_SampleMask[0];
return stage_output;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#pragma clang diagnostic ignored "-Wmissing-prototypes"
#pragma clang diagnostic ignored "-Wmissing-braces"

#include <metal_stdlib>
#include <simd/simd.h>

using namespace metal;

template<typename T, size_t Num>
struct spvUnsafeArray
{
T elements[Num ? Num : 1];

thread T& operator [] (size_t pos) thread
{
return elements[pos];
}
constexpr const thread T& operator [] (size_t pos) const thread
{
return elements[pos];
}

device T& operator [] (size_t pos) device
{
return elements[pos];
}
constexpr const device T& operator [] (size_t pos) const device
{
return elements[pos];
}

constexpr const constant T& operator [] (size_t pos) const constant
{
return elements[pos];
}

threadgroup T& operator [] (size_t pos) threadgroup
{
return elements[pos];
}
constexpr const threadgroup T& operator [] (size_t pos) const threadgroup
{
return elements[pos];
}
};

struct main0_out
{
uint gl_SampleMask [[sample_mask]];
};

fragment main0_out main0(uint gl_SampleMaskIn [[sample_mask]])
{
main0_out out = {};
spvUnsafeArray<uint, 1> copy_sample_mask = gl_SampleMaskIn;
out.gl_SampleMask = copy_sample_mask;
return out;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#pragma clang diagnostic ignored "-Wmissing-prototypes"
#pragma clang diagnostic ignored "-Wmissing-braces"

#include <metal_stdlib>
#include <simd/simd.h>

using namespace metal;

template<typename T, size_t Num>
struct spvUnsafeArray
{
T elements[Num ? Num : 1];

thread T& operator [] (size_t pos) thread
{
return elements[pos];
}
constexpr const thread T& operator [] (size_t pos) const thread
{
return elements[pos];
}

device T& operator [] (size_t pos) device
{
return elements[pos];
}
constexpr const device T& operator [] (size_t pos) const device
{
return elements[pos];
}

constexpr const constant T& operator [] (size_t pos) const constant
{
return elements[pos];
}

threadgroup T& operator [] (size_t pos) threadgroup
{
return elements[pos];
}
constexpr const threadgroup T& operator [] (size_t pos) const threadgroup
{
return elements[pos];
}
};

struct main0_out
{
uint gl_SampleMask [[sample_mask]];
};

fragment main0_out main0(uint gl_SampleMaskIn [[sample_mask]])
{
main0_out out = {};
spvUnsafeArray<int, 1> copy_sample_mask = gl_SampleMaskIn;
out.gl_SampleMask = copy_sample_mask;
return out;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#version 450

void main()
{
uint _16_unrolled[1];
for (int i = 0; i < int(1); i++)
{
_16_unrolled[i] = int(gl_SampleMaskIn[i]);
}
uint copy_sample_mask[1] = _16_unrolled;
for (int i = 0; i < int(1); i++)
{
gl_SampleMask[i] = int(copy_sample_mask[i]);
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#version 450

void main()
{
int _21_unrolled[1];
for (int i = 0; i < int(1); i++)
{
_21_unrolled[i] = gl_SampleMaskIn[i];
}
int copy_sample_mask[1] = _21_unrolled;
for (int i = 0; i < int(1); i++)
{
gl_SampleMask[i] = copy_sample_mask[i];
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
; SPIR-V
; Version: 1.0
; Generator: Khronos Glslang Reference Front End; 11
; Bound: 30
; Schema: 0
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %main "main" %gl_SampleMaskIn %gl_SampleMask
OpExecutionMode %main OriginUpperLeft
OpSource GLSL 450
OpName %main "main"
OpName %copy_sample_mask "copy_sample_mask"
OpName %gl_SampleMaskIn "gl_SampleMaskIn"
OpName %out_sample_mask "out_sample_mask"
OpName %gl_SampleMask "gl_SampleMask"
OpDecorate %gl_SampleMaskIn Flat
OpDecorate %gl_SampleMaskIn BuiltIn SampleMask
OpDecorate %gl_SampleMask BuiltIn SampleMask
%void = OpTypeVoid
%3 = OpTypeFunction %void
%uint = OpTypeInt 32 0
%uint_1 = OpConstant %uint 1
%_arr_int_uint_1 = OpTypeArray %uint %uint_1
%_ptr_Function__arr_int_uint_1 = OpTypePointer Function %_arr_int_uint_1
%_ptr_Input__arr_int_uint_1 = OpTypePointer Input %_arr_int_uint_1
%gl_SampleMaskIn = OpVariable %_ptr_Input__arr_int_uint_1 Input
%_ptr_Output__arr_int_uint_1 = OpTypePointer Output %_arr_int_uint_1
%gl_SampleMask = OpVariable %_ptr_Output__arr_int_uint_1 Output
%main = OpFunction %void None %3
%5 = OpLabel
%copy_sample_mask = OpVariable %_ptr_Function__arr_int_uint_1 Function
%out_sample_mask = OpVariable %_ptr_Function__arr_int_uint_1 Function

%loaded_sample_mask_in = OpLoad %_arr_int_uint_1 %gl_SampleMaskIn
OpStore %copy_sample_mask %loaded_sample_mask_in
%loaded_copy = OpLoad %_arr_int_uint_1 %copy_sample_mask
OpStore %gl_SampleMask %loaded_copy
OpReturn
OpFunctionEnd
45 changes: 45 additions & 0 deletions shaders-hlsl-no-opt/asm/frag/sample-mask-load-store-array.asm.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
; SPIR-V
; Version: 1.0
; Generator: Khronos Glslang Reference Front End; 11
; Bound: 30
; Schema: 0
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %main "main" %gl_SampleMaskIn %gl_SampleMask
OpExecutionMode %main OriginUpperLeft
OpSource GLSL 450
OpName %main "main"
OpName %copy_sample_mask "copy_sample_mask"
OpName %gl_SampleMaskIn "gl_SampleMaskIn"
OpName %out_sample_mask "out_sample_mask"
OpName %gl_SampleMask "gl_SampleMask"
OpDecorate %gl_SampleMaskIn Flat
OpDecorate %gl_SampleMaskIn BuiltIn SampleMask
OpDecorate %gl_SampleMask BuiltIn SampleMask
%void = OpTypeVoid
%3 = OpTypeFunction %void
%int = OpTypeInt 32 1
%uint = OpTypeInt 32 0
%uint_1 = OpConstant %uint 1
%_arr_int_uint_1 = OpTypeArray %int %uint_1
%_ptr_Function__arr_int_uint_1 = OpTypePointer Function %_arr_int_uint_1
%int_0 = OpConstant %int 0
%_ptr_Input__arr_int_uint_1 = OpTypePointer Input %_arr_int_uint_1
%gl_SampleMaskIn = OpVariable %_ptr_Input__arr_int_uint_1 Input
%_ptr_Input_int = OpTypePointer Input %int
%_ptr_Function_int = OpTypePointer Function %int
%_ptr_Output__arr_int_uint_1 = OpTypePointer Output %_arr_int_uint_1
%gl_SampleMask = OpVariable %_ptr_Output__arr_int_uint_1 Output
%_ptr_Output_int = OpTypePointer Output %int
%main = OpFunction %void None %3
%5 = OpLabel
%copy_sample_mask = OpVariable %_ptr_Function__arr_int_uint_1 Function
%out_sample_mask = OpVariable %_ptr_Function__arr_int_uint_1 Function

%loaded_sample_mask_in = OpLoad %_arr_int_uint_1 %gl_SampleMaskIn
OpStore %copy_sample_mask %loaded_sample_mask_in
%loaded_copy = OpLoad %_arr_int_uint_1 %copy_sample_mask
OpStore %gl_SampleMask %loaded_copy
OpReturn
OpFunctionEnd
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
; SPIR-V
; Version: 1.0
; Generator: Khronos Glslang Reference Front End; 11
; Bound: 30
; Schema: 0
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %main "main" %gl_SampleMaskIn %gl_SampleMask
OpExecutionMode %main OriginUpperLeft
OpSource GLSL 450
OpName %main "main"
OpName %copy_sample_mask "copy_sample_mask"
OpName %gl_SampleMaskIn "gl_SampleMaskIn"
OpName %out_sample_mask "out_sample_mask"
OpName %gl_SampleMask "gl_SampleMask"
OpDecorate %gl_SampleMaskIn Flat
OpDecorate %gl_SampleMaskIn BuiltIn SampleMask
OpDecorate %gl_SampleMask BuiltIn SampleMask
%void = OpTypeVoid
%3 = OpTypeFunction %void
%uint = OpTypeInt 32 0
%uint_1 = OpConstant %uint 1
%_arr_int_uint_1 = OpTypeArray %uint %uint_1
%_ptr_Function__arr_int_uint_1 = OpTypePointer Function %_arr_int_uint_1
%_ptr_Input__arr_int_uint_1 = OpTypePointer Input %_arr_int_uint_1
%gl_SampleMaskIn = OpVariable %_ptr_Input__arr_int_uint_1 Input
%_ptr_Output__arr_int_uint_1 = OpTypePointer Output %_arr_int_uint_1
%gl_SampleMask = OpVariable %_ptr_Output__arr_int_uint_1 Output
%main = OpFunction %void None %3
%5 = OpLabel
%copy_sample_mask = OpVariable %_ptr_Function__arr_int_uint_1 Function
%out_sample_mask = OpVariable %_ptr_Function__arr_int_uint_1 Function

%loaded_sample_mask_in = OpLoad %_arr_int_uint_1 %gl_SampleMaskIn
OpStore %copy_sample_mask %loaded_sample_mask_in
%loaded_copy = OpLoad %_arr_int_uint_1 %copy_sample_mask
OpStore %gl_SampleMask %loaded_copy
OpReturn
OpFunctionEnd
45 changes: 45 additions & 0 deletions shaders-msl-no-opt/asm/frag/sample-mask-load-store-array.asm.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
; SPIR-V
; Version: 1.0
; Generator: Khronos Glslang Reference Front End; 11
; Bound: 30
; Schema: 0
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %main "main" %gl_SampleMaskIn %gl_SampleMask
OpExecutionMode %main OriginUpperLeft
OpSource GLSL 450
OpName %main "main"
OpName %copy_sample_mask "copy_sample_mask"
OpName %gl_SampleMaskIn "gl_SampleMaskIn"
OpName %out_sample_mask "out_sample_mask"
OpName %gl_SampleMask "gl_SampleMask"
OpDecorate %gl_SampleMaskIn Flat
OpDecorate %gl_SampleMaskIn BuiltIn SampleMask
OpDecorate %gl_SampleMask BuiltIn SampleMask
%void = OpTypeVoid
%3 = OpTypeFunction %void
%int = OpTypeInt 32 1
%uint = OpTypeInt 32 0
%uint_1 = OpConstant %uint 1
%_arr_int_uint_1 = OpTypeArray %int %uint_1
%_ptr_Function__arr_int_uint_1 = OpTypePointer Function %_arr_int_uint_1
%int_0 = OpConstant %int 0
%_ptr_Input__arr_int_uint_1 = OpTypePointer Input %_arr_int_uint_1
%gl_SampleMaskIn = OpVariable %_ptr_Input__arr_int_uint_1 Input
%_ptr_Input_int = OpTypePointer Input %int
%_ptr_Function_int = OpTypePointer Function %int
%_ptr_Output__arr_int_uint_1 = OpTypePointer Output %_arr_int_uint_1
%gl_SampleMask = OpVariable %_ptr_Output__arr_int_uint_1 Output
%_ptr_Output_int = OpTypePointer Output %int
%main = OpFunction %void None %3
%5 = OpLabel
%copy_sample_mask = OpVariable %_ptr_Function__arr_int_uint_1 Function
%out_sample_mask = OpVariable %_ptr_Function__arr_int_uint_1 Function

%loaded_sample_mask_in = OpLoad %_arr_int_uint_1 %gl_SampleMaskIn
OpStore %copy_sample_mask %loaded_sample_mask_in
%loaded_copy = OpLoad %_arr_int_uint_1 %copy_sample_mask
OpStore %gl_SampleMask %loaded_copy
OpReturn
OpFunctionEnd
Loading

0 comments on commit 56bdcfa

Please sign in to comment.