vkd3d/tests/hlsl/struct-inheritance.shader_test
Shaun Ren 069b8aac64 vkd3d-shader/hlsl: Implement struct single inheritance.
Here, we implement single inheritance by inserting a field at the
beginning of the derived struct with name "$super".

For the following struct declarations

  struct a
  {
      float4 aa;
      float4 bb;
  };

  struct b : a
  {
      float4 cc;
  };

  struct c : b
  {
      float4 bb;
  };

this commit generates the following:

  struct a
  {
      float4 aa;
      float4 bb;
  };

  struct b
  {
      struct a $super;
      float4 cc;
  };

  struct c
  {
      struct b $super;
      float4 bb;
  };
2024-10-16 21:07:53 +02:00

135 lines
1.5 KiB
Plaintext

[pixel shader]
struct a
{
float4 aa;
float4 bb;
};
struct b : a
{
float4 cc;
};
struct c : b
{
float4 bb; // Shadows a.bb
};
c data;
float4 main() : sv_target
{
return data.aa + data.bb + data.cc;
}
[test]
uniform 0 float4 1 0 0 0
uniform 4 float4 0 2 0 0
uniform 8 float4 0 0 3 0
uniform 12 float4 0 0 0 4
draw quad
probe (0, 0) rgba (1, 0, 3, 4)
% Test writing to a field derived from a base class.
[pixel shader]
struct a
{
float4 aa;
float4 bb;
};
struct b : a
{
float4 cc;
};
struct c : b
{
float4 bb; // Shadows a.bb
};
c data;
float4 main() : sv_target
{
c data2 = data;
data2.aa = float4(-1, 0, 0, 0);
data2.bb = float4(0, 0, 0, -4);
return data2.aa + data2.bb + data2.cc;
}
[test]
uniform 0 float4 1 0 0 0
uniform 4 float4 0 2 0 0
uniform 8 float4 0 0 3 0
uniform 12 float4 0 0 0 4
draw quad
probe (0, 0) rgba (-1, 0, 3, -4)
% Multiple concrete base types are not allowed.
[pixel shader fail]
struct a
{
float4 aa;
};
struct b
{
float4 bb;
};
struct c : a, b
{
float4 cc;
};
float4 main() : sv_target
{
return 0;
}
% The concrete base type must be a struct.
[pixel shader fail]
struct a : float4
{
float4 aa;
};
float4 main() : sv_target
{
return 0;
}
[pixel shader fail]
struct a : vector<float, 4>
{
float4 aa;
};
float4 main() : sv_target
{
return 0;
}
[pixel shader fail]
struct a : Buffer<float>
{
float4 aa;
};
float4 main() : sv_target
{
return 0;
}