Re-land: "ES31: Add vector and matrix support in SSBO for D3D"

Re-land skips ProgramInterfaceTestES31.GetProgramInterface/ES3_1_D3D11 to pass
the bots. In fact, ProgramInterfaceTestES31.GetProgramInterface/ES3_1_D3D11 is
not a regression. The reverted CL added more SSBO features and triggered the
failure. To enable ProgramInterfaceTestES31.GetProgramInterface/ES3_1_D3D11,
we should support SSBO in render pipeline. This needs to bind SSBO to UAV
registers in link time instead of compile time since output variables also
occupies the UAVs. Let's enable this test when we support SSBO in render
pipeline. Currently, we shouldn't block the SSBO implementation in some common
features.

Bug: angleproject:1951
Change-Id: Ic339e8327e79335e6db1d86bedf0072635976f5f
Reviewed-on: https://chromium-review.googlesource.com/c/1282277
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Commit-Queue: Jiajia Qin <jiajia.qin@intel.com>
This commit is contained in:
Qin Jiajia 2018-10-09 13:59:56 +08:00 коммит произвёл Commit Bot
Родитель a8a25d1746
Коммит 1d8a783c9d
3 изменённых файлов: 227 добавлений и 29 удалений

Просмотреть файл

@ -9,45 +9,100 @@
#include "compiler/translator/ShaderStorageBlockFunctionHLSL.h" #include "compiler/translator/ShaderStorageBlockFunctionHLSL.h"
#include "compiler/translator/UtilsHLSL.h" #include "compiler/translator/UtilsHLSL.h"
#include "compiler/translator/blocklayout.h"
#include "compiler/translator/blocklayoutHLSL.h"
#include "compiler/translator/util.h"
namespace sh namespace sh
{ {
namespace
{
unsigned int GetMatrixStride(const TType &type)
{
sh::Std140BlockEncoder std140Encoder;
sh::HLSLBlockEncoder hlslEncoder(sh::HLSLBlockEncoder::ENCODE_PACKED, false);
sh::BlockLayoutEncoder *encoder = nullptr;
if (type.getLayoutQualifier().blockStorage == EbsStd140)
{
encoder = &std140Encoder;
}
else
{
// TODO(jiajia.qin@intel.com): add std430 support. http://anglebug.com/1951
encoder = &hlslEncoder;
}
const bool isRowMajorLayout = (type.getLayoutQualifier().matrixPacking == EmpRowMajor);
std::vector<unsigned int> arraySizes;
auto *typeArraySizes = type.getArraySizes();
if (typeArraySizes != nullptr)
{
arraySizes.assign(typeArraySizes->begin(), typeArraySizes->end());
}
const BlockMemberInfo &memberInfo =
encoder->encodeType(GLVariableType(type), arraySizes, isRowMajorLayout);
return memberInfo.matrixStride;
}
} // anonymous namespace
// static // static
void ShaderStorageBlockFunctionHLSL::OutputSSBOLoadFunctionBody( void ShaderStorageBlockFunctionHLSL::OutputSSBOLoadFunctionBody(
TInfoSinkBase &out, TInfoSinkBase &out,
const ShaderStorageBlockFunction &ssboFunction) const ShaderStorageBlockFunction &ssboFunction)
{ {
if (ssboFunction.type.isScalar()) const char *convertString;
switch (ssboFunction.type.getBasicType())
{ {
TString convertString; case EbtFloat:
switch (ssboFunction.type.getBasicType()) convertString = "asfloat(";
{ break;
case EbtFloat: case EbtInt:
convertString = "asfloat("; convertString = "asint(";
break; break;
case EbtInt: case EbtUInt:
convertString = "asint("; convertString = "asuint(";
break; break;
case EbtUInt: case EbtBool:
convertString = "asuint("; convertString = "asint(";
break; break;
case EbtBool: default:
convertString = "asint("; UNREACHABLE();
break; return;
default:
UNREACHABLE();
break;
}
out << " " << ssboFunction.typeString << " result = " << convertString
<< "buffer.Load(loc));\n";
out << " return result;\n";
return;
} }
// TODO(jiajia.qin@intel.com): Process all possible return types. out << " " << ssboFunction.typeString << " result";
out << " return 1.0;\n"; if (ssboFunction.type.isScalar())
{
out << " = " << convertString << "buffer.Load(loc));\n";
}
else if (ssboFunction.type.isVector())
{
out << " = " << convertString << "buffer.Load" << ssboFunction.type.getNominalSize()
<< "(loc));\n";
}
else if (ssboFunction.type.isMatrix())
{
unsigned int matrixStride = GetMatrixStride(ssboFunction.type);
out << " = {";
for (int rowIndex = 0; rowIndex < ssboFunction.type.getRows(); rowIndex++)
{
out << "asfloat(buffer.Load" << ssboFunction.type.getCols() << "(loc +"
<< rowIndex * matrixStride << ")), ";
}
out << "};\n";
}
else
{
// TODO(jiajia.qin@intel.com): Process all possible return types. http://anglebug.com/1951
out << ";\n";
}
out << " return result;\n";
return;
} }
// static // static
@ -59,8 +114,24 @@ void ShaderStorageBlockFunctionHLSL::OutputSSBOStoreFunctionBody(
{ {
out << " buffer.Store(loc, asuint(value));\n"; out << " buffer.Store(loc, asuint(value));\n";
} }
else if (ssboFunction.type.isVector())
// TODO(jiajia.qin@intel.com): Process all possible return types. {
out << " buffer.Store" << ssboFunction.type.getNominalSize()
<< "(loc, asuint(value));\n";
}
else if (ssboFunction.type.isMatrix())
{
unsigned int matrixStride = GetMatrixStride(ssboFunction.type);
for (int rowIndex = 0; rowIndex < ssboFunction.type.getRows(); rowIndex++)
{
out << " buffer.Store" << ssboFunction.type.getCols() << "(loc +"
<< rowIndex * matrixStride << ", asuint(value[" << rowIndex << "]));\n";
}
}
else
{
// TODO(jiajia.qin@intel.com): Process all possible return types. http://anglebug.com/1951
}
} }
bool ShaderStorageBlockFunctionHLSL::ShaderStorageBlockFunction::operator<( bool ShaderStorageBlockFunctionHLSL::ShaderStorageBlockFunction::operator<(

Просмотреть файл

@ -253,6 +253,10 @@ TEST_P(ProgramInterfaceTestES31, GetResource)
// Tests glGetProgramInterfaceiv. // Tests glGetProgramInterfaceiv.
TEST_P(ProgramInterfaceTestES31, GetProgramInterface) TEST_P(ProgramInterfaceTestES31, GetProgramInterface)
{ {
// TODO(jiajia.qin@intel.com): Don't skip this test once SSBO are supported on render pipeline.
// http://anglebug.com/1951
ANGLE_SKIP_TEST_IF(IsD3D11());
const std::string &fragmentShaderSource = const std::string &fragmentShaderSource =
"#version 310 es\n" "#version 310 es\n"
"precision highp float;\n" "precision highp float;\n"

Просмотреть файл

@ -190,6 +190,129 @@ TEST_P(ShaderStorageBufferTest31, ShaderStorageBufferReadWrite)
EXPECT_GL_NO_ERROR(); EXPECT_GL_NO_ERROR();
} }
// Test that access/write to vector data in shader storage buffer.
TEST_P(ShaderStorageBufferTest31, ShaderStorageBufferVector)
{
constexpr char kComputeShaderSource[] =
R"(#version 310 es
layout(local_size_x=1, local_size_y=1, local_size_z=1) in;
layout(std140, binding = 0) buffer blockIn {
uvec2 data;
} instanceIn;
layout(std140, binding = 1) buffer blockOut {
uvec2 data;
} instanceOut;
void main()
{
instanceOut.data[0] = instanceIn.data[0];
instanceOut.data[1] = instanceIn.data[1];
}
)";
ANGLE_GL_COMPUTE_PROGRAM(program, kComputeShaderSource);
glUseProgram(program.get());
constexpr unsigned int kComponentCount = 2;
constexpr unsigned int kBytesPerComponent = sizeof(unsigned int);
constexpr unsigned int kExpectedValues[kComponentCount] = {3u, 4u};
// Create shader storage buffer
GLBuffer shaderStorageBuffer[2];
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer[0]);
glBufferData(GL_SHADER_STORAGE_BUFFER, kComponentCount * kBytesPerComponent, kExpectedValues,
GL_STATIC_DRAW);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer[1]);
glBufferData(GL_SHADER_STORAGE_BUFFER, kComponentCount * kBytesPerComponent, nullptr,
GL_STATIC_DRAW);
// Bind shader storage buffer
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, shaderStorageBuffer[0]);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, shaderStorageBuffer[1]);
glDispatchCompute(1, 1, 1);
glFinish();
// Read back shader storage buffer
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer[1]);
const GLuint *ptr = reinterpret_cast<const GLuint *>(glMapBufferRange(
GL_SHADER_STORAGE_BUFFER, 0, kComponentCount * kBytesPerComponent, GL_MAP_READ_BIT));
for (unsigned int idx = 0; idx < kComponentCount; idx++)
{
EXPECT_EQ(kExpectedValues[idx], *(ptr + idx));
}
EXPECT_GL_NO_ERROR();
}
// Test that access/write to matrix data in shader storage buffer.
TEST_P(ShaderStorageBufferTest31, ShaderStorageBufferMatrix)
{
constexpr char kComputeShaderSource[] =
R"(#version 310 es
layout(local_size_x=1, local_size_y=1, local_size_z=1) in;
layout(std140, binding = 0) buffer blockIn {
mat2x3 data;
} instanceIn;
layout(std140, binding = 1) buffer blockOut {
mat2x3 data;
} instanceOut;
void main()
{
instanceOut.data[0][0] = instanceIn.data[0][0];
instanceOut.data[0][1] = instanceIn.data[0][1];
instanceOut.data[0][2] = instanceIn.data[0][2];
instanceOut.data[1][0] = instanceIn.data[1][0];
instanceOut.data[1][1] = instanceIn.data[1][1];
instanceOut.data[1][2] = instanceIn.data[1][2];
}
)";
ANGLE_GL_COMPUTE_PROGRAM(program, kComputeShaderSource);
glUseProgram(program.get());
constexpr unsigned int kColumns = 2;
constexpr unsigned int kRows = 3;
constexpr unsigned int kBytesPerComponent = sizeof(float);
constexpr unsigned int kVectorStride = 16;
// kVectorStride / kBytesPerComponent is used instead of kRows is because std140 layout requires
// that base alignment and stride of arrays of scalars and vectors are rounded up a multiple of
// the base alignment of a vec4.
constexpr float kInputDada[kColumns][kVectorStride / kBytesPerComponent] = {
{0.1, 0.2, 0.3, 0.0}, {0.4, 0.5, 0.6, 0.0}};
// Create shader storage buffer
GLBuffer shaderStorageBuffer[2];
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer[0]);
glBufferData(GL_SHADER_STORAGE_BUFFER, kColumns * kVectorStride, kInputDada, GL_STATIC_DRAW);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer[1]);
glBufferData(GL_SHADER_STORAGE_BUFFER, kColumns * kVectorStride, nullptr, GL_STATIC_DRAW);
// Bind shader storage buffer
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, shaderStorageBuffer[0]);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, shaderStorageBuffer[1]);
glDispatchCompute(1, 1, 1);
glFinish();
// Read back shader storage buffer
constexpr float kExpectedValues[kColumns][kRows] = {{0.1, 0.2, 0.3}, {0.4, 0.5, 0.6}};
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer[1]);
const GLfloat *ptr = reinterpret_cast<const GLfloat *>(
glMapBufferRange(GL_SHADER_STORAGE_BUFFER, 0, kColumns * kVectorStride, GL_MAP_READ_BIT));
for (unsigned int idx = 0; idx < kColumns; idx++)
{
for (unsigned int idy = 0; idy < kRows; idy++)
{
EXPECT_EQ(kExpectedValues[idx][idy],
*(ptr + idx * (kVectorStride / kBytesPerComponent) + idy));
}
}
EXPECT_GL_NO_ERROR();
}
// Test atomic memory functions. // Test atomic memory functions.
TEST_P(ShaderStorageBufferTest31, AtomicMemoryFunctions) TEST_P(ShaderStorageBufferTest31, AtomicMemoryFunctions)
{ {