2020-10-01 21:09:48 -07:00
|
|
|
[pixel shader]
|
|
|
|
#pragma pack_matrix(row_major)
|
|
|
|
uniform float2x2 r;
|
|
|
|
#pragma pack_matrix(column_major)
|
|
|
|
uniform float2x2 c;
|
|
|
|
|
|
|
|
float4 main() : sv_target
|
|
|
|
{
|
|
|
|
float4 ret;
|
|
|
|
ret.xy = mul(r, float2(0.5, 0.6));
|
|
|
|
ret.zw = mul(c, float2(0.5, 0.6));
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
[test]
|
|
|
|
uniform 0 float4 0.1 0.2 0.0 0.0
|
|
|
|
uniform 4 float4 0.3 0.4 0.0 0.0
|
|
|
|
uniform 8 float4 0.1 0.3 0.0 0.0
|
|
|
|
uniform 12 float4 0.2 0.4 0.0 0.0
|
2024-10-21 07:23:27 -07:00
|
|
|
todo(msl) draw quad
|
2024-02-10 11:16:22 -08:00
|
|
|
probe (0, 0) rgba (0.17, 0.39, 0.17, 0.39) 1
|
2021-09-14 16:07:10 -07:00
|
|
|
|
2022-03-29 15:39:34 -07:00
|
|
|
|
|
|
|
%% Test with a struct.
|
|
|
|
|
|
|
|
[pixel shader]
|
|
|
|
#pragma pack_matrix(row_major)
|
|
|
|
struct apple
|
|
|
|
{
|
|
|
|
float2x2 m;
|
|
|
|
};
|
|
|
|
#pragma pack_matrix(column_major)
|
|
|
|
uniform struct apple a;
|
|
|
|
|
|
|
|
float4 main() : sv_target
|
|
|
|
{
|
|
|
|
return float4(a.m[0], a.m[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
[test]
|
|
|
|
uniform 0 float4 0.1 0.2 0.0 0.0
|
|
|
|
uniform 4 float4 0.3 0.4 0.0 0.0
|
2024-11-04 02:54:30 -08:00
|
|
|
draw quad
|
2024-02-10 11:16:22 -08:00
|
|
|
probe (0, 0) rgba (0.1, 0.2, 0.3, 0.4)
|
2022-03-29 15:39:34 -07:00
|
|
|
|
|
|
|
|
|
|
|
%% Test with an array.
|
|
|
|
|
|
|
|
[pixel shader]
|
|
|
|
#pragma pack_matrix(row_major)
|
|
|
|
uniform float2x2 m[2];
|
|
|
|
#pragma pack_matrix(column_major)
|
|
|
|
|
|
|
|
float4 main() : sv_target
|
|
|
|
{
|
|
|
|
return float4(m[1][0], m[1][1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
[test]
|
|
|
|
uniform 0 float4 0.0 0.0 0.0 0.0
|
|
|
|
uniform 4 float4 0.0 0.0 0.0 0.0
|
|
|
|
uniform 8 float4 0.5 0.6 0.0 0.0
|
|
|
|
uniform 12 float4 0.7 0.8 0.0 0.0
|
2024-11-04 02:54:30 -08:00
|
|
|
draw quad
|
2024-02-10 11:16:22 -08:00
|
|
|
probe (0, 0) rgba (0.5, 0.6, 0.7, 0.8)
|
2022-03-29 15:39:34 -07:00
|
|
|
|
|
|
|
|
2021-09-14 16:07:10 -07:00
|
|
|
% The documentation claims these strings are subject to macro expansion.
|
2023-12-10 22:18:41 -08:00
|
|
|
% In SM < 6.0 they are not.
|
2021-09-14 16:07:10 -07:00
|
|
|
|
|
|
|
[pixel shader]
|
|
|
|
|
|
|
|
#define KEY pack_matrix
|
|
|
|
#pragma KEY(row_major)
|
|
|
|
#define VALUE row_major
|
|
|
|
#pragma pack_matrix(VALUE)
|
|
|
|
#define PRAGMA pack_matrix(row_major)
|
|
|
|
#pragma PRAGMA
|
|
|
|
|
|
|
|
uniform float2x2 r;
|
|
|
|
|
|
|
|
float4 main() : sv_target
|
|
|
|
{
|
|
|
|
float4 ret;
|
|
|
|
ret.xy = mul(r, float2(0.5, 0.6));
|
|
|
|
ret.zw = 0.5;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
[test]
|
|
|
|
uniform 0 float4 0.1 0.2 0.0 0.0
|
|
|
|
uniform 4 float4 0.3 0.4 0.0 0.0
|
2024-10-21 07:23:27 -07:00
|
|
|
todo(msl) draw quad
|
2024-02-10 11:16:22 -08:00
|
|
|
if(sm<6) probe (0,0) rgba (0.23, 0.34, 0.5, 0.5) 1
|
|
|
|
if(sm>=6) probe (0,0) rgba (0.17, 0.39, 0.5, 0.5) 1
|
2022-03-29 15:39:34 -07:00
|
|
|
|
|
|
|
|
|
|
|
% The majority that applies to a typedef is the latent majority at the time
|
|
|
|
% that typedef was declared.
|
|
|
|
|
|
|
|
[pixel shader]
|
|
|
|
#pragma pack_matrix(row_major)
|
|
|
|
typedef float2x2 mat_t;
|
|
|
|
#pragma pack_matrix(column_major)
|
|
|
|
uniform mat_t m;
|
|
|
|
|
|
|
|
float4 main() : sv_target
|
|
|
|
{
|
|
|
|
return float4(m[0], m[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
[test]
|
|
|
|
uniform 0 float4 0.1 0.2 0.0 0.0
|
|
|
|
uniform 4 float4 0.3 0.4 0.0 0.0
|
2024-11-04 02:54:30 -08:00
|
|
|
draw quad
|
2024-02-10 11:16:22 -08:00
|
|
|
probe (0, 0) rgba (0.1, 0.2, 0.3, 0.4)
|
2022-03-29 15:39:34 -07:00
|
|
|
|
|
|
|
|
|
|
|
% In fact, it's illegal to specify a contradictory majority.
|
|
|
|
|
2022-03-29 17:15:40 -07:00
|
|
|
[pixel shader fail]
|
2022-03-29 15:39:34 -07:00
|
|
|
#pragma pack_matrix(row_major)
|
|
|
|
typedef float2x2 mat_t;
|
|
|
|
uniform column_major mat_t m;
|
|
|
|
|
|
|
|
float4 main() : sv_target
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-02-15 16:07:33 -08:00
|
|
|
% This applies to arrays as well. Note that struct fields already have latent
|
|
|
|
% majority applied (even if there have been no pragmas, as shown below), so the
|
|
|
|
% question of typedefs is moot there.
|
|
|
|
|
|
|
|
|
|
|
|
[pixel shader]
|
|
|
|
#pragma pack_matrix(row_major)
|
|
|
|
typedef float2x2 myarray_t[2];
|
|
|
|
#pragma pack_matrix(column_major)
|
|
|
|
uniform myarray_t a;
|
|
|
|
|
|
|
|
float4 main() : sv_target
|
|
|
|
{
|
|
|
|
return float4(a[0][0], a[1][1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
[test]
|
|
|
|
uniform 0 float4 0.3 0.4 0.0 0.0
|
|
|
|
uniform 4 float4 0.0 0.0 0.0 0.0
|
|
|
|
uniform 8 float4 0.0 0.0 0.0 0.0
|
|
|
|
uniform 12 float4 0.5 0.6 0.0 0.0
|
2024-11-04 02:54:30 -08:00
|
|
|
draw quad
|
2024-02-10 11:16:22 -08:00
|
|
|
probe (0, 0) rgba (0.3, 0.4, 0.5, 0.6)
|
2023-02-15 16:07:33 -08:00
|
|
|
|
|
|
|
|
2022-03-29 15:39:34 -07:00
|
|
|
% However, if no pack_matrix directive has been used yet, a typedef has no
|
|
|
|
% defined majority, and the majority can be overwritten, including by a
|
|
|
|
% subsequent pragma.
|
|
|
|
|
|
|
|
[pixel shader]
|
|
|
|
typedef float2x2 mat_t;
|
|
|
|
#pragma pack_matrix(row_major)
|
|
|
|
uniform mat_t m;
|
|
|
|
|
|
|
|
uniform row_major mat_t r;
|
|
|
|
uniform column_major mat_t c;
|
|
|
|
|
|
|
|
float4 main() : sv_target
|
|
|
|
{
|
|
|
|
return float4(m[0], m[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
[test]
|
|
|
|
uniform 0 float4 0.1 0.2 0.0 0.0
|
|
|
|
uniform 4 float4 0.3 0.4 0.0 0.0
|
2024-11-04 02:54:30 -08:00
|
|
|
draw quad
|
2024-02-10 11:16:22 -08:00
|
|
|
probe (0, 0) rgba (0.1, 0.2, 0.3, 0.4)
|
2022-03-29 15:39:34 -07:00
|
|
|
|
|
|
|
|
|
|
|
% This does not apply recursively to struct or array members, however. Members
|
|
|
|
% defined while there is no latent majority are always column-major, even if
|
|
|
|
% the type is later used after a pack_matrix(row_major) directive.
|
|
|
|
|
|
|
|
% Note that the majority of the struct or array type cannot itself be
|
|
|
|
% overwritten with modifiers; those are only valid on matrix types.
|
|
|
|
|
|
|
|
[pixel shader]
|
|
|
|
struct apple
|
|
|
|
{
|
|
|
|
float2x2 m;
|
|
|
|
};
|
|
|
|
#pragma pack_matrix(row_major)
|
|
|
|
typedef struct apple apple_t;
|
|
|
|
uniform apple_t a;
|
|
|
|
|
|
|
|
float4 main() : sv_target
|
|
|
|
{
|
|
|
|
return float4(a.m[0], a.m[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
[test]
|
|
|
|
uniform 0 float4 0.2 0.4 0.0 0.0
|
|
|
|
uniform 4 float4 0.3 0.5 0.0 0.0
|
2024-11-04 02:54:30 -08:00
|
|
|
draw quad
|
2024-02-10 11:16:22 -08:00
|
|
|
probe (0, 0) rgba (0.2, 0.3, 0.4, 0.5)
|
2023-02-15 16:07:33 -08:00
|
|
|
|
|
|
|
|
|
|
|
[pixel shader]
|
|
|
|
typedef float2x2 myarray_t[2];
|
|
|
|
#pragma pack_matrix(row_major)
|
|
|
|
typedef myarray_t myarray2_t;
|
|
|
|
uniform myarray2_t a;
|
|
|
|
|
|
|
|
float4 main() : sv_target
|
|
|
|
{
|
|
|
|
return float4(a[0][0], a[1][1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
[test]
|
|
|
|
uniform 0 float4 0.3 0.0 0.0 0.0
|
|
|
|
uniform 4 float4 0.4 0.0 0.0 0.0
|
|
|
|
uniform 8 float4 0.0 0.5 0.0 0.0
|
|
|
|
uniform 12 float4 0.0 0.6 0.0 0.0
|
2024-11-04 02:54:30 -08:00
|
|
|
draw quad
|
2024-02-10 11:16:22 -08:00
|
|
|
probe (0, 0) rgba (0.3, 0.4, 0.5, 0.6)
|
2023-07-12 23:09:12 -07:00
|
|
|
|
|
|
|
% Compiler options
|
|
|
|
[require]
|
|
|
|
options: row-major
|
|
|
|
|
|
|
|
[pixel shader]
|
|
|
|
#pragma pack_matrix(column_major)
|
|
|
|
uniform float4x4 m;
|
|
|
|
|
|
|
|
float4 main() : sv_target
|
|
|
|
{
|
|
|
|
float4 ret;
|
|
|
|
ret.xy = m[0].yz;
|
|
|
|
ret.zw = m[1].yz;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
[test]
|
|
|
|
uniform 0 float4 0.1 0.5 0.9 1.3
|
|
|
|
uniform 4 float4 0.2 0.6 1.0 1.4
|
|
|
|
uniform 8 float4 0.3 0.7 1.1 1.5
|
|
|
|
uniform 12 float4 0.4 0.8 1.2 1.6
|
2024-11-04 02:54:30 -08:00
|
|
|
draw quad
|
2024-02-10 11:16:22 -08:00
|
|
|
probe (0, 0) rgba (0.2, 0.3, 0.6, 0.7) 1
|
2023-07-12 23:09:12 -07:00
|
|
|
|
|
|
|
[require]
|
|
|
|
options: column-major
|
|
|
|
|
|
|
|
[pixel shader]
|
|
|
|
uniform float4x4 m;
|
|
|
|
|
|
|
|
float4 main() : sv_target
|
|
|
|
{
|
|
|
|
float4 ret;
|
|
|
|
ret.xy = m[0].yz;
|
|
|
|
ret.zw = m[1].yz;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
[test]
|
|
|
|
uniform 0 float4 0.1 0.5 0.9 1.3
|
|
|
|
uniform 4 float4 0.2 0.6 1.0 1.4
|
|
|
|
uniform 8 float4 0.3 0.7 1.1 1.5
|
|
|
|
uniform 12 float4 0.4 0.8 1.2 1.6
|
2024-11-04 02:54:30 -08:00
|
|
|
draw quad
|
2024-02-10 11:16:22 -08:00
|
|
|
probe (0, 0) rgba (0.2, 0.3, 0.6, 0.7) 1
|
2023-07-12 23:09:12 -07:00
|
|
|
|
|
|
|
[require]
|
|
|
|
options: row-major
|
|
|
|
|
|
|
|
[pixel shader]
|
|
|
|
uniform float4x4 m;
|
|
|
|
|
|
|
|
float4 main() : sv_target
|
|
|
|
{
|
|
|
|
float4 ret;
|
|
|
|
ret.xy = m[0].yz;
|
|
|
|
ret.zw = m[1].yz;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
[test]
|
|
|
|
uniform 0 float4 0.1 0.5 0.9 1.3
|
|
|
|
uniform 4 float4 0.2 0.6 1.0 1.4
|
|
|
|
uniform 8 float4 0.3 0.7 1.1 1.5
|
|
|
|
uniform 12 float4 0.4 0.8 1.2 1.6
|
2024-11-04 02:54:30 -08:00
|
|
|
draw quad
|
2024-02-10 11:16:22 -08:00
|
|
|
probe (0, 0) rgba (0.5, 0.9, 0.6, 1.0) 1
|
2023-07-12 23:09:12 -07:00
|
|
|
|
|
|
|
[require]
|
|
|
|
options: column-major
|
|
|
|
|
|
|
|
[pixel shader]
|
|
|
|
uniform float4x4 m1;
|
|
|
|
#pragma pack_matrix(row_major)
|
|
|
|
uniform float4x4 m2;
|
|
|
|
|
|
|
|
float4 main() : sv_target
|
|
|
|
{
|
|
|
|
float4 ret;
|
|
|
|
ret.xy = m1[0].zw;
|
|
|
|
ret.zw = m2[0].zw;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
[test]
|
|
|
|
uniform 0 float4 0.1 0.5 0.9 1.3
|
|
|
|
uniform 4 float4 0.2 0.6 1.0 1.4
|
|
|
|
uniform 8 float4 0.3 0.7 1.1 1.5
|
|
|
|
uniform 12 float4 0.4 0.8 1.2 1.6
|
|
|
|
uniform 16 float4 1.7 2.1 2.5 2.9
|
|
|
|
uniform 20 float4 1.8 2.2 2.6 3.0
|
|
|
|
uniform 24 float4 1.9 2.3 2.7 3.1
|
|
|
|
uniform 28 float4 2.0 2.4 2.8 3.2
|
2024-11-04 02:54:30 -08:00
|
|
|
draw quad
|
2024-02-10 11:16:22 -08:00
|
|
|
probe (0, 0) rgba (0.3, 0.4, 2.5, 2.9) 1
|
2023-07-12 23:09:12 -07:00
|
|
|
|
|
|
|
[require]
|
|
|
|
options: row-major
|
|
|
|
|
|
|
|
[pixel shader]
|
|
|
|
uniform float4x4 m1;
|
|
|
|
#pragma pack_matrix(column_major)
|
|
|
|
uniform float4x4 m2;
|
|
|
|
|
|
|
|
float4 main() : sv_target
|
|
|
|
{
|
|
|
|
float4 ret;
|
|
|
|
ret.xy = m1[3].zw;
|
|
|
|
ret.zw = m2[3].zw;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
[test]
|
|
|
|
uniform 0 float4 0.1 0.5 0.9 1.3
|
|
|
|
uniform 4 float4 0.2 0.6 1.0 1.4
|
|
|
|
uniform 8 float4 0.3 0.7 1.1 1.5
|
|
|
|
uniform 12 float4 0.4 0.8 1.2 1.6
|
|
|
|
uniform 16 float4 1.7 2.1 2.5 2.9
|
|
|
|
uniform 20 float4 1.8 2.2 2.6 3.0
|
|
|
|
uniform 24 float4 1.9 2.3 2.7 3.1
|
|
|
|
uniform 28 float4 2.0 2.4 2.8 3.2
|
2024-11-04 02:54:30 -08:00
|
|
|
draw quad
|
2024-02-10 11:16:22 -08:00
|
|
|
probe (0, 0) rgba (1.2, 1.6, 3.1, 3.2) 1
|
2023-07-12 23:09:12 -07:00
|
|
|
|
|
|
|
[require]
|
|
|
|
options: column-major row-major
|
|
|
|
|
|
|
|
[pixel shader]
|
|
|
|
uniform float2x2 m;
|
|
|
|
|
|
|
|
float4 main() : sv_target
|
|
|
|
{
|
|
|
|
float4 ret;
|
|
|
|
ret.xy = m[0];
|
|
|
|
ret.zw = m[1];
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
[test]
|
|
|
|
uniform 0 float4 0.1 0.2 0.0 0.0
|
|
|
|
uniform 4 float4 0.3 0.4 0.0 0.0
|
2024-11-04 02:54:30 -08:00
|
|
|
draw quad
|
2024-02-10 11:16:22 -08:00
|
|
|
probe (0, 0) rgba (0.1, 0.3, 0.2, 0.4) 1
|