Fix calculation of array stride on structs in D3D

# Conflicts:
#	util/test/tests/GL/GL_CBuffer_Zoo.py
This commit is contained in:
baldurk
2020-05-13 13:33:13 +01:00
parent 15fa728ab9
commit 78335f7d00
9 changed files with 162 additions and 22 deletions
@@ -66,7 +66,7 @@ static ShaderVariableType MakeShaderVariableType(DXBC::CBufferVariableType type)
{
uint32_t stride = type.descriptor.bytesize / RDCMAX(1U, type.descriptor.elements);
RDCASSERTMSG("Stride is too large for uint16_t", stride <= 0xffff);
ret.descriptor.arrayByteStride = RDCMIN(stride, 0xffffu) & 0xffff;
ret.descriptor.arrayByteStride = AlignUp16(RDCMIN(stride, 0xffffu) & 0xffff);
ret.descriptor.rows = ret.descriptor.columns = 0;
}
+16 -1
View File
@@ -60,6 +60,12 @@ struct nested_with_empty
float2 c; // 4, 5, <6, 7>
};
struct misaligned_struct
{
float4 a;
float2 b;
};
cbuffer consts : register(b0)
{
// dummy* entries are just to 'reset' packing to avoid pollution between tests
@@ -268,7 +274,16 @@ cbuffer consts : register(b0)
nested_with_empty nested_empty; // empty struct will take up a float4
float4 test; // {520, 521, 522, 523}
misaligned_struct ao[2]; // [0] = {
// .a = { 520, 521, 522, 523 }
// .b = { 524, 525 } <526, 527>
// }
// [1] = {
// .a = { 528, 529, 530, 531 }
// .b = { 532, 533 } <534, 535>
// }
float4 test; // {536, 537, 538, 539}
};
float4 main() : SV_Target0
+16 -1
View File
@@ -60,6 +60,12 @@ struct nested_with_empty
float2 c; // 4, 5, <6, 7>
};
struct misaligned_struct
{
float4 a;
float2 b;
};
cbuffer consts : register(b7)
{
// dummy* entries are just to 'reset' packing to avoid pollution between tests
@@ -268,7 +274,16 @@ cbuffer consts : register(b7)
nested_with_empty nested_empty; // empty struct will take up a float4
float4 test; // {520, 521, 522, 523}
misaligned_struct ao[2]; // [0] = {
// .a = { 520, 521, 522, 523 }
// .b = { 524, 525 } <526, 527>
// }
// [1] = {
// .a = { 528, 529, 530, 531 }
// .b = { 532, 533 } <534, 535>
// }
float4 test; // {536, 537, 538, 539}
};
// this comes from root signature constants
+17 -2
View File
@@ -84,6 +84,12 @@ struct nested_with_padding
// [3]: {24, 25, 26}, <27>
};
struct misaligned_struct
{
vec4 a;
vec2 b;
};
layout(binding = 0, std140) uniform constsbuf
{
// dummy* entries are just to 'reset' packing to avoid pollution between tests
@@ -284,12 +290,21 @@ layout(binding = 0, std140) uniform constsbuf
vec4 dummy13[2]; // empty structs on D3D
vec4 test; // {520, 521, 522, 523}
misaligned_struct ao[2]; // [0] = {
// .a = { 520, 521, 522, 523 }
// .b = { 524, 525 } <526, 527>
// }
// [1] = {
// .a = { 528, 529, 530, 531 }
// .b = { 532, 533 } <534, 535>
// }
vec4 test; // {536, 537, 538, 539}
// because GL has worse handling of multidimensional arrays than other APIs, we add an extra test
// here with more than 2 dimensions
vec4 multiarray2[4][3][2]; // [0][0][0] = {524, 525, 526, ...}
vec4 multiarray2[4][3][2]; // [0][0][0] = {540, 541, 542, ...}
// [0][0][1] = {..., ..., ..., ...}
// [0][1][0] = {..., ..., ..., ...}
// [0][1][1] = {..., ..., ..., ...}
+32 -2
View File
@@ -83,6 +83,12 @@ struct nested_with_padding
// [3]: {24, 25, 26}, <27>
};
struct misaligned_struct
{
vec4 a;
vec2 b;
};
layout(set = 0, binding = 0, std140) uniform constsbuf
{
// dummy* entries are just to 'reset' packing to avoid pollution between tests
@@ -283,7 +289,16 @@ layout(set = 0, binding = 0, std140) uniform constsbuf
vec4 dummy13[2]; // empty structs on D3D
vec4 test; // {520, 521, 522, 523}
misaligned_struct ao[2]; // [0] = {
// .a = { 520, 521, 522, 523 }
// .b = { 524, 525 } <526, 527>
// }
// [1] = {
// .a = { 528, 529, 530, 531 }
// .b = { 532, 533 } <534, 535>
// }
vec4 test; // {536, 537, 538, 539}
};
layout (constant_id = 0) const int A = 10;
@@ -316,6 +331,12 @@ struct nested_with_padding
// [3]: {24, 25, 26}, <27>
};
struct misaligned_struct
{
float4 a;
float2 b;
};
layout(set = 0, binding = 0) cbuffer consts
{
// dummy* entries are just to 'reset' packing to avoid pollution between tests
@@ -526,7 +547,16 @@ layout(set = 0, binding = 0) cbuffer consts
float4 dummy15[2]; // empty structs on D3D
float4 test; // {520, 521, 522, 523}
misaligned_struct ao[2]; // [0] = {
// .a = { 520, 521, 522, 523 }
// .b = { 524, 525 } <526, 527>
// }
// [1] = {
// .a = { 528, 529, 530, 531 }
// .b = { 532, 533 } <534, 535>
// }
float4 test; // {536, 537, 538, 539}
};
float4 main() : SV_Target0
+17 -4
View File
@@ -69,16 +69,16 @@ class D3D11_CBuffer_Zoo(rdtest.TestCase):
debugged = self.evaluate_source_var(output, variables)
if not rdtest.util.value_compare(debugged.value.fv[0:4], [520.1, 521.0, 522.0, 523.0]):
if not rdtest.util.value_compare(debugged.value.fv[0:4], [536.1, 537.0, 538.0, 539.0]):
raise rdtest.TestFailureException(
"Debugged output {} did not match expected {}".format(
debugged.value.fv[0:4], [520.1, 521.0, 522.0, 523.0]))
debugged.value.fv[0:4], [536.1, 537.0, 538.0, 539.0]))
rdtest.log.success("Debugged output matched as expected")
self.controller.FreeTrace(trace)
self.check_pixel_value(pipe.GetOutputTargets()[0].resourceId, 0.5, 0.5, [520.1, 521.0, 522.0, 523.0])
self.check_pixel_value(pipe.GetOutputTargets()[0].resourceId, 0.5, 0.5, [536.1, 537.0, 538.0, 539.0])
rdtest.log.success("Picked value is as expected")
@@ -426,7 +426,20 @@ class D3D11_CBuffer_Zoo(rdtest.TestCase):
'c': lambda y: y.rows(1).cols(2).value([516.0, 517.0]),
})
# misaligned_struct ao[2];
var_check.check('ao').rows(0).cols(0).arraySize(2).members({
# ao[0]
0: lambda s: s.rows(0).cols(0).structSize(2).members({
'a': lambda y: y.rows(1).cols(4).value([520.0, 521.0, 522.0, 523.0]),
'b': lambda y: y.rows(1).cols(2).value([524.0, 525.0]),
}),
1: lambda s: s.rows(0).cols(0).structSize(2).members({
'a': lambda y: y.rows(1).cols(4).value([528.0, 529.0, 530.0, 531.0]),
'b': lambda y: y.rows(1).cols(2).value([532.0, 533.0]),
}),
})
# float4 test;
var_check.check('test').rows(1).cols(4).value([520.0, 521.0, 522.0, 523.0])
var_check.check('test').rows(1).cols(4).value([536.0, 537.0, 538.0, 539.0])
var_check.done()
+17 -4
View File
@@ -110,16 +110,16 @@ class D3D12_CBuffer_Zoo(rdtest.TestCase):
debugged = self.evaluate_source_var(output, variables)
if not rdtest.util.value_compare(debugged.value.fv[0:4], [520.1, 521.0, 522.0, 523.0]):
if not rdtest.util.value_compare(debugged.value.fv[0:4], [536.1, 537.0, 538.0, 539.0]):
raise rdtest.TestFailureException(
"Debugged output {} did not match expected {}".format(
debugged.value.fv[0:4], [520.1, 521.0, 522.0, 523.0]))
debugged.value.fv[0:4], [536.1, 537.0, 538.0, 539.0]))
rdtest.log.success("Debugged output matched as expected")
self.controller.FreeTrace(trace)
self.check_pixel_value(pipe.GetOutputTargets()[0].resourceId, 0.5, 0.5, [520.1, 521.0, 522.0, 523.0])
self.check_pixel_value(pipe.GetOutputTargets()[0].resourceId, 0.5, 0.5, [536.1, 537.0, 538.0, 539.0])
rdtest.log.success("Picked value is as expected")
@@ -467,8 +467,21 @@ class D3D12_CBuffer_Zoo(rdtest.TestCase):
'c': lambda y: y.rows(1).cols(2).value([516.0, 517.0]),
})
# misaligned_struct ao[2];
var_check.check('ao').rows(0).cols(0).arraySize(2).members({
# ao[0]
0: lambda s: s.rows(0).cols(0).structSize(2).members({
'a': lambda y: y.rows(1).cols(4).value([520.0, 521.0, 522.0, 523.0]),
'b': lambda y: y.rows(1).cols(2).value([524.0, 525.0]),
}),
1: lambda s: s.rows(0).cols(0).structSize(2).members({
'a': lambda y: y.rows(1).cols(4).value([528.0, 529.0, 530.0, 531.0]),
'b': lambda y: y.rows(1).cols(2).value([532.0, 533.0]),
}),
})
# float4 test;
var_check.check('test').rows(1).cols(4).value([520.0, 521.0, 522.0, 523.0])
var_check.check('test').rows(1).cols(4).value([536.0, 537.0, 538.0, 539.0])
var_check.done()
+16 -3
View File
@@ -342,11 +342,24 @@ class GL_CBuffer_Zoo(rdtest.TestCase):
# float4 dummy13[2];
var_check.check('dummy13')
# misaligned_struct ao[2];
var_check.check('ao').rows(0).cols(0).arraySize(2).members({
# ao[0]
0: lambda s: s.rows(0).cols(0).structSize(2).members({
'a': lambda y: y.rows(1).cols(4).value([520.0, 521.0, 522.0, 523.0]),
'b': lambda y: y.rows(1).cols(2).value([524.0, 525.0]),
}),
1: lambda s: s.rows(0).cols(0).structSize(2).members({
'a': lambda y: y.rows(1).cols(4).value([528.0, 529.0, 530.0, 531.0]),
'b': lambda y: y.rows(1).cols(2).value([532.0, 533.0]),
}),
})
# float4 test;
var_check.check('test').rows(1).cols(4).value([520.0, 521.0, 522.0, 523.0])
var_check.check('test').rows(1).cols(4).value([536.0, 537.0, 538.0, 539.0])
# to save duplicating if this array changes, we calculate out from the start, as the array is tightly packed
base = 524.0
base = 540.0
exp_vals = lambda wi,yi,xi: [base + wi * 24.0 + yi * 8.0 + xi * 4.0 + c * 1.0 for c in range(0,4)]
@@ -414,7 +427,7 @@ class GL_CBuffer_Zoo(rdtest.TestCase):
rdtest.log.success("CBuffer variables are as expected")
self.check_pixel_value(pipe.GetOutputTargets()[0].resourceId, 0.5, 0.5, [520.1, 521.0, 522.0, 523.0])
self.check_pixel_value(pipe.GetOutputTargets()[0].resourceId, 0.5, 0.5, [536.1, 537.0, 538.0, 539.0])
rdtest.log.success("Picked value is as expected")
+30 -4
View File
@@ -36,7 +36,7 @@ class VK_CBuffer_Zoo(rdtest.TestCase):
rdtest.log.success("GLSL CBuffer variables are as expected")
self.check_pixel_value(pipe.GetOutputTargets()[0].resourceId, 0.5, 0.5, [520.1, 521.0, 522.0, 523.0])
self.check_pixel_value(pipe.GetOutputTargets()[0].resourceId, 0.5, 0.5, [536.1, 537.0, 538.0, 539.0])
rdtest.log.success("GLSL picked value is as expected")
@@ -92,7 +92,7 @@ class VK_CBuffer_Zoo(rdtest.TestCase):
rdtest.log.success("HLSL CBuffer variables are as expected")
self.check_pixel_value(pipe.GetOutputTargets()[0].resourceId, 0.5, 0.5, [520.1, 521.0, 522.0, 523.0])
self.check_pixel_value(pipe.GetOutputTargets()[0].resourceId, 0.5, 0.5, [536.1, 537.0, 538.0, 539.0])
rdtest.log.success("HLSL picked value is as expected")
@@ -416,8 +416,21 @@ class VK_CBuffer_Zoo(rdtest.TestCase):
# float4 dummy13[2];
var_check.check('dummy13')
# misaligned_struct ao[2];
var_check.check('ao').rows(0).cols(0).arraySize(2).members({
# ao[0]
0: lambda s: s.rows(0).cols(0).structSize(2).members({
'a': lambda y: y.rows(1).cols(4).value([520.0, 521.0, 522.0, 523.0]),
'b': lambda y: y.rows(1).cols(2).value([524.0, 525.0]),
}),
1: lambda s: s.rows(0).cols(0).structSize(2).members({
'a': lambda y: y.rows(1).cols(4).value([528.0, 529.0, 530.0, 531.0]),
'b': lambda y: y.rows(1).cols(2).value([532.0, 533.0]),
}),
})
# float4 test;
var_check.check('test').rows(1).cols(4).value([520.0, 521.0, 522.0, 523.0])
var_check.check('test').rows(1).cols(4).value([536.0, 537.0, 538.0, 539.0])
var_check.done()
@@ -762,8 +775,21 @@ class VK_CBuffer_Zoo(rdtest.TestCase):
# float4 dummy15[2];
var_check.check('dummy15')
# misaligned_struct ao[2];
var_check.check('ao').rows(0).cols(0).arraySize(2).members({
# ao[0]
0: lambda s: s.rows(0).cols(0).structSize(2).members({
'a': lambda y: y.rows(1).cols(4).value([520.0, 521.0, 522.0, 523.0]),
'b': lambda y: y.rows(1).cols(2).value([524.0, 525.0]),
}),
1: lambda s: s.rows(0).cols(0).structSize(2).members({
'a': lambda y: y.rows(1).cols(4).value([528.0, 529.0, 530.0, 531.0]),
'b': lambda y: y.rows(1).cols(2).value([532.0, 533.0]),
}),
})
# float4 test;
var_check.check('test').rows(1).cols(4).value([520.0, 521.0, 522.0, 523.0])
var_check.check('test').rows(1).cols(4).value([536.0, 537.0, 538.0, 539.0])
var_check.done()