Commit 3026f115 by Qin Jiajia Committed by Commit Bot

ES31: Collect shader storage blocks info for d3d.

This change collects shader storage blocks info for d3d backend. With this change, program interface APIs can get correct SSBO information for D3D. Bug: angleproject:1920 Change-Id: I6e2414494d0e8240bcb1d0ddc3d9a292eb7158ee Reviewed-on: https://chromium-review.googlesource.com/c/1269824Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Commit-Queue: Jiajia Qin <jiajia.qin@intel.com>
parent c4533eae
...@@ -28,31 +28,31 @@ bool IsRowMajorLayout(const ShaderVariable &var) ...@@ -28,31 +28,31 @@ bool IsRowMajorLayout(const ShaderVariable &var)
} }
template <typename VarT> template <typename VarT>
void GetUniformBlockInfo(const std::vector<VarT> &fields, void GetInterfaceBlockInfo(const std::vector<VarT> &fields,
const std::string &prefix, const std::string &prefix,
sh::BlockLayoutEncoder *encoder, sh::BlockLayoutEncoder *encoder,
bool inRowMajorLayout, bool inRowMajorLayout,
BlockLayoutMap *blockInfoOut); BlockLayoutMap *blockInfoOut);
template <typename VarT> template <typename VarT>
void GetUniformBlockStructMemberInfo(const std::vector<VarT> &fields, void GetInterfaceBlockStructMemberInfo(const std::vector<VarT> &fields,
const std::string &fieldName, const std::string &fieldName,
sh::BlockLayoutEncoder *encoder, sh::BlockLayoutEncoder *encoder,
bool inRowMajorLayout, bool inRowMajorLayout,
BlockLayoutMap *blockInfoOut) BlockLayoutMap *blockInfoOut)
{ {
encoder->enterAggregateType(); encoder->enterAggregateType();
GetUniformBlockInfo(fields, fieldName, encoder, inRowMajorLayout, blockInfoOut); GetInterfaceBlockInfo(fields, fieldName, encoder, inRowMajorLayout, blockInfoOut);
encoder->exitAggregateType(); encoder->exitAggregateType();
} }
template <typename VarT> template <typename VarT>
void GetUniformBlockStructArrayMemberInfo(const VarT &field, void GetInterfaceBlockStructArrayMemberInfo(const VarT &field,
unsigned int arrayNestingIndex, unsigned int arrayNestingIndex,
const std::string &arrayName, const std::string &arrayName,
sh::BlockLayoutEncoder *encoder, sh::BlockLayoutEncoder *encoder,
bool inRowMajorLayout, bool inRowMajorLayout,
BlockLayoutMap *blockInfoOut) BlockLayoutMap *blockInfoOut)
{ {
// Nested arrays are processed starting from outermost (arrayNestingIndex 0u) and ending at the // Nested arrays are processed starting from outermost (arrayNestingIndex 0u) and ending at the
// innermost. // innermost.
...@@ -62,24 +62,24 @@ void GetUniformBlockStructArrayMemberInfo(const VarT &field, ...@@ -62,24 +62,24 @@ void GetUniformBlockStructArrayMemberInfo(const VarT &field,
const std::string elementName = arrayName + ArrayString(arrayElement); const std::string elementName = arrayName + ArrayString(arrayElement);
if (arrayNestingIndex + 1u < field.arraySizes.size()) if (arrayNestingIndex + 1u < field.arraySizes.size())
{ {
GetUniformBlockStructArrayMemberInfo(field, arrayNestingIndex + 1u, elementName, GetInterfaceBlockStructArrayMemberInfo(field, arrayNestingIndex + 1u, elementName,
encoder, inRowMajorLayout, blockInfoOut); encoder, inRowMajorLayout, blockInfoOut);
} }
else else
{ {
GetUniformBlockStructMemberInfo(field.fields, elementName, encoder, inRowMajorLayout, GetInterfaceBlockStructMemberInfo(field.fields, elementName, encoder, inRowMajorLayout,
blockInfoOut); blockInfoOut);
} }
} }
} }
template <typename VarT> template <typename VarT>
void GetUniformBlockArrayOfArraysMemberInfo(const VarT &field, void GetInterfaceBlockArrayOfArraysMemberInfo(const VarT &field,
unsigned int arrayNestingIndex, unsigned int arrayNestingIndex,
const std::string &arrayName, const std::string &arrayName,
sh::BlockLayoutEncoder *encoder, sh::BlockLayoutEncoder *encoder,
bool isRowMajorMatrix, bool isRowMajorMatrix,
BlockLayoutMap *blockInfoOut) BlockLayoutMap *blockInfoOut)
{ {
const unsigned int currentArraySize = field.getNestedArraySize(arrayNestingIndex); const unsigned int currentArraySize = field.getNestedArraySize(arrayNestingIndex);
for (unsigned int arrayElement = 0u; arrayElement < currentArraySize; ++arrayElement) for (unsigned int arrayElement = 0u; arrayElement < currentArraySize; ++arrayElement)
...@@ -87,8 +87,8 @@ void GetUniformBlockArrayOfArraysMemberInfo(const VarT &field, ...@@ -87,8 +87,8 @@ void GetUniformBlockArrayOfArraysMemberInfo(const VarT &field,
const std::string elementName = arrayName + ArrayString(arrayElement); const std::string elementName = arrayName + ArrayString(arrayElement);
if (arrayNestingIndex + 2u < field.arraySizes.size()) if (arrayNestingIndex + 2u < field.arraySizes.size())
{ {
GetUniformBlockArrayOfArraysMemberInfo(field, arrayNestingIndex + 1u, elementName, GetInterfaceBlockArrayOfArraysMemberInfo(field, arrayNestingIndex + 1u, elementName,
encoder, isRowMajorMatrix, blockInfoOut); encoder, isRowMajorMatrix, blockInfoOut);
} }
else else
{ {
...@@ -101,11 +101,11 @@ void GetUniformBlockArrayOfArraysMemberInfo(const VarT &field, ...@@ -101,11 +101,11 @@ void GetUniformBlockArrayOfArraysMemberInfo(const VarT &field,
} }
template <typename VarT> template <typename VarT>
void GetUniformBlockInfo(const std::vector<VarT> &fields, void GetInterfaceBlockInfo(const std::vector<VarT> &fields,
const std::string &prefix, const std::string &prefix,
sh::BlockLayoutEncoder *encoder, sh::BlockLayoutEncoder *encoder,
bool inRowMajorLayout, bool inRowMajorLayout,
BlockLayoutMap *blockInfoOut) BlockLayoutMap *blockInfoOut)
{ {
for (const VarT &field : fields) for (const VarT &field : fields)
{ {
...@@ -124,20 +124,20 @@ void GetUniformBlockInfo(const std::vector<VarT> &fields, ...@@ -124,20 +124,20 @@ void GetUniformBlockInfo(const std::vector<VarT> &fields,
{ {
if (field.isArray()) if (field.isArray())
{ {
GetUniformBlockStructArrayMemberInfo(field, 0u, fieldName, encoder, rowMajorLayout, GetInterfaceBlockStructArrayMemberInfo(field, 0u, fieldName, encoder,
blockInfoOut); rowMajorLayout, blockInfoOut);
} }
else else
{ {
GetUniformBlockStructMemberInfo(field.fields, fieldName, encoder, rowMajorLayout, GetInterfaceBlockStructMemberInfo(field.fields, fieldName, encoder, rowMajorLayout,
blockInfoOut); blockInfoOut);
} }
} }
else if (field.isArrayOfArrays()) else if (field.isArrayOfArrays())
{ {
GetUniformBlockArrayOfArraysMemberInfo(field, 0u, fieldName, encoder, GetInterfaceBlockArrayOfArraysMemberInfo(field, 0u, fieldName, encoder,
rowMajorLayout && gl::IsMatrixType(field.type), rowMajorLayout && gl::IsMatrixType(field.type),
blockInfoOut); blockInfoOut);
} }
else else
{ {
...@@ -266,14 +266,14 @@ void Std140BlockEncoder::advanceOffset(GLenum type, ...@@ -266,14 +266,14 @@ void Std140BlockEncoder::advanceOffset(GLenum type,
} }
} }
void GetUniformBlockInfo(const std::vector<InterfaceBlockField> &fields, void GetInterfaceBlockInfo(const std::vector<InterfaceBlockField> &fields,
const std::string &prefix, const std::string &prefix,
sh::BlockLayoutEncoder *encoder, sh::BlockLayoutEncoder *encoder,
BlockLayoutMap *blockInfoOut) BlockLayoutMap *blockInfoOut)
{ {
// Matrix packing is always recorded in individual fields, so they'll set the row major layout // Matrix packing is always recorded in individual fields, so they'll set the row major layout
// flag to true if needed. // flag to true if needed.
GetUniformBlockInfo(fields, prefix, encoder, false, blockInfoOut); GetInterfaceBlockInfo(fields, prefix, encoder, false, blockInfoOut);
} }
void GetUniformBlockInfo(const std::vector<Uniform> &uniforms, void GetUniformBlockInfo(const std::vector<Uniform> &uniforms,
...@@ -283,7 +283,7 @@ void GetUniformBlockInfo(const std::vector<Uniform> &uniforms, ...@@ -283,7 +283,7 @@ void GetUniformBlockInfo(const std::vector<Uniform> &uniforms,
{ {
// Matrix packing is always recorded in individual fields, so they'll set the row major layout // Matrix packing is always recorded in individual fields, so they'll set the row major layout
// flag to true if needed. // flag to true if needed.
GetUniformBlockInfo(uniforms, prefix, encoder, false, blockInfoOut); GetInterfaceBlockInfo(uniforms, prefix, encoder, false, blockInfoOut);
} }
......
...@@ -131,10 +131,10 @@ class Std140BlockEncoder : public BlockLayoutEncoder ...@@ -131,10 +131,10 @@ class Std140BlockEncoder : public BlockLayoutEncoder
using BlockLayoutMap = std::map<std::string, BlockMemberInfo>; using BlockLayoutMap = std::map<std::string, BlockMemberInfo>;
void GetUniformBlockInfo(const std::vector<InterfaceBlockField> &fields, void GetInterfaceBlockInfo(const std::vector<InterfaceBlockField> &fields,
const std::string &prefix, const std::string &prefix,
sh::BlockLayoutEncoder *encoder, sh::BlockLayoutEncoder *encoder,
BlockLayoutMap *blockInfoOut); BlockLayoutMap *blockInfoOut);
// Used for laying out the default uniform block on the Vulkan backend. // Used for laying out the default uniform block on the Vulkan backend.
void GetUniformBlockInfo(const std::vector<Uniform> &uniforms, void GetUniformBlockInfo(const std::vector<Uniform> &uniforms,
......
...@@ -155,12 +155,12 @@ bool FindFlatInterpolationVarying(const gl::ShaderMap<gl::Shader *> &shaders) ...@@ -155,12 +155,12 @@ bool FindFlatInterpolationVarying(const gl::ShaderMap<gl::Shader *> &shaders)
return false; return false;
} }
class UniformBlockInfo final : angle::NonCopyable class InterfaceBlockInfo final : angle::NonCopyable
{ {
public: public:
UniformBlockInfo() {} InterfaceBlockInfo() {}
void getShaderBlockInfo(gl::Shader *shader); void getShaderBlockInfo(const std::vector<sh::InterfaceBlock> &interfaceBlocks);
bool getBlockSize(const std::string &name, const std::string &mappedName, size_t *sizeOut); bool getBlockSize(const std::string &name, const std::string &mappedName, size_t *sizeOut);
bool getBlockMemberInfo(const std::string &name, bool getBlockMemberInfo(const std::string &name,
...@@ -174,9 +174,9 @@ class UniformBlockInfo final : angle::NonCopyable ...@@ -174,9 +174,9 @@ class UniformBlockInfo final : angle::NonCopyable
sh::BlockLayoutMap mBlockLayout; sh::BlockLayoutMap mBlockLayout;
}; };
void UniformBlockInfo::getShaderBlockInfo(gl::Shader *shader) void InterfaceBlockInfo::getShaderBlockInfo(const std::vector<sh::InterfaceBlock> &interfaceBlocks)
{ {
for (const sh::InterfaceBlock &interfaceBlock : shader->getUniformBlocks()) for (const sh::InterfaceBlock &interfaceBlock : interfaceBlocks)
{ {
if (!interfaceBlock.active && interfaceBlock.layout == sh::BLOCKLAYOUT_PACKED) if (!interfaceBlock.active && interfaceBlock.layout == sh::BLOCKLAYOUT_PACKED)
continue; continue;
...@@ -189,7 +189,7 @@ void UniformBlockInfo::getShaderBlockInfo(gl::Shader *shader) ...@@ -189,7 +189,7 @@ void UniformBlockInfo::getShaderBlockInfo(gl::Shader *shader)
} }
} }
size_t UniformBlockInfo::getBlockInfo(const sh::InterfaceBlock &interfaceBlock) size_t InterfaceBlockInfo::getBlockInfo(const sh::InterfaceBlock &interfaceBlock)
{ {
ASSERT(interfaceBlock.active || interfaceBlock.layout != sh::BLOCKLAYOUT_PACKED); ASSERT(interfaceBlock.active || interfaceBlock.layout != sh::BLOCKLAYOUT_PACKED);
...@@ -207,15 +207,15 @@ size_t UniformBlockInfo::getBlockInfo(const sh::InterfaceBlock &interfaceBlock) ...@@ -207,15 +207,15 @@ size_t UniformBlockInfo::getBlockInfo(const sh::InterfaceBlock &interfaceBlock)
encoder = &hlslEncoder; encoder = &hlslEncoder;
} }
sh::GetUniformBlockInfo(interfaceBlock.fields, interfaceBlock.fieldPrefix(), encoder, sh::GetInterfaceBlockInfo(interfaceBlock.fields, interfaceBlock.fieldPrefix(), encoder,
&mBlockLayout); &mBlockLayout);
return encoder->getBlockSize(); return encoder->getBlockSize();
} }
bool UniformBlockInfo::getBlockSize(const std::string &name, bool InterfaceBlockInfo::getBlockSize(const std::string &name,
const std::string &mappedName, const std::string &mappedName,
size_t *sizeOut) size_t *sizeOut)
{ {
size_t nameLengthWithoutArrayIndex; size_t nameLengthWithoutArrayIndex;
gl::ParseArrayIndex(name, &nameLengthWithoutArrayIndex); gl::ParseArrayIndex(name, &nameLengthWithoutArrayIndex);
...@@ -231,9 +231,9 @@ bool UniformBlockInfo::getBlockSize(const std::string &name, ...@@ -231,9 +231,9 @@ bool UniformBlockInfo::getBlockSize(const std::string &name,
return true; return true;
}; };
bool UniformBlockInfo::getBlockMemberInfo(const std::string &name, bool InterfaceBlockInfo::getBlockMemberInfo(const std::string &name,
const std::string &mappedName, const std::string &mappedName,
sh::BlockMemberInfo *infoOut) sh::BlockMemberInfo *infoOut)
{ {
auto infoIter = mBlockLayout.find(name); auto infoIter = mBlockLayout.find(name);
if (infoIter == mBlockLayout.end()) if (infoIter == mBlockLayout.end())
...@@ -2931,13 +2931,13 @@ void ProgramD3D::updateCachedPixelExecutableIndex() ...@@ -2931,13 +2931,13 @@ void ProgramD3D::updateCachedPixelExecutableIndex()
void ProgramD3D::linkResources(const gl::ProgramLinkedResources &resources) void ProgramD3D::linkResources(const gl::ProgramLinkedResources &resources)
{ {
UniformBlockInfo uniformBlockInfo; InterfaceBlockInfo uniformBlockInfo;
for (gl::ShaderType shaderType : gl::AllShaderTypes()) for (gl::ShaderType shaderType : gl::AllShaderTypes())
{ {
gl::Shader *shader = mState.getAttachedShader(shaderType); gl::Shader *shader = mState.getAttachedShader(shaderType);
if (shader) if (shader)
{ {
uniformBlockInfo.getShaderBlockInfo(shader); uniformBlockInfo.getShaderBlockInfo(shader->getUniformBlocks());
} }
} }
...@@ -2956,18 +2956,26 @@ void ProgramD3D::linkResources(const gl::ProgramLinkedResources &resources) ...@@ -2956,18 +2956,26 @@ void ProgramD3D::linkResources(const gl::ProgramLinkedResources &resources)
resources.uniformBlockLinker.linkBlocks(getUniformBlockSize, getUniformBlockMemberInfo); resources.uniformBlockLinker.linkBlocks(getUniformBlockSize, getUniformBlockMemberInfo);
initializeUniformBlocks(); initializeUniformBlocks();
// TODO(jiajia.qin@intel.com): Determine correct shader storage block info. InterfaceBlockInfo shaderStorageBlockInfo;
auto getShaderStorageBlockSize = [](const std::string &name, const std::string &mappedName, for (gl::ShaderType shaderType : gl::AllShaderTypes())
size_t *sizeOut) { {
*sizeOut = 0; gl::Shader *shader = mState.getAttachedShader(shaderType);
return true; if (shader)
{
shaderStorageBlockInfo.getShaderBlockInfo(shader->getShaderStorageBlocks());
}
}
auto getShaderStorageBlockSize = [&shaderStorageBlockInfo](const std::string &name,
const std::string &mappedName,
size_t *sizeOut) {
return shaderStorageBlockInfo.getBlockSize(name, mappedName, sizeOut);
}; };
auto getShaderStorageBlockMemberInfo = auto getShaderStorageBlockMemberInfo = [&shaderStorageBlockInfo](const std::string &name,
[](const std::string &name, const std::string &mappedName, sh::BlockMemberInfo *infoOut) { const std::string &mappedName,
*infoOut = sh::BlockMemberInfo::getDefaultBlockInfo(); sh::BlockMemberInfo *infoOut) {
return true; return shaderStorageBlockInfo.getBlockMemberInfo(name, mappedName, infoOut);
}; };
resources.shaderStorageBlockLinker.linkBlocks(getShaderStorageBlockSize, resources.shaderStorageBlockLinker.linkBlocks(getShaderStorageBlockSize,
getShaderStorageBlockMemberInfo); getShaderStorageBlockMemberInfo);
......
...@@ -339,6 +339,10 @@ TEST_P(ProgramInterfaceTestES31, GetProgramInterface) ...@@ -339,6 +339,10 @@ TEST_P(ProgramInterfaceTestES31, GetProgramInterface)
// Tests the resource property query for uniform can be done correctly. // Tests the resource property query for uniform can be done correctly.
TEST_P(ProgramInterfaceTestES31, GetUniformProperties) TEST_P(ProgramInterfaceTestES31, GetUniformProperties)
{ {
// TODO(jiajia.qin@intel.com): Don't skip this test once atomic counter is supported on d3d
// backend. http://anglebug.com/1729
ANGLE_SKIP_TEST_IF(IsD3D11());
const std::string &vertexShaderSource = const std::string &vertexShaderSource =
"#version 310 es\n" "#version 310 es\n"
"precision highp float;\n" "precision highp float;\n"
...@@ -528,6 +532,10 @@ TEST_P(ProgramInterfaceTestES31, GetUniformBlockProperties) ...@@ -528,6 +532,10 @@ TEST_P(ProgramInterfaceTestES31, GetUniformBlockProperties)
// Tests atomic counter buffer qeury works correctly. // Tests atomic counter buffer qeury works correctly.
TEST_P(ProgramInterfaceTestES31, QueryAtomicCounteBuffer) TEST_P(ProgramInterfaceTestES31, QueryAtomicCounteBuffer)
{ {
// TODO(jiajia.qin@intel.com): Don't skip this test once atomic counter is supported on d3d
// backend. http://anglebug.com/1729
ANGLE_SKIP_TEST_IF(IsD3D11());
const std::string &vertShader = const std::string &vertShader =
"#version 310 es\n" "#version 310 es\n"
"precision highp float;\n" "precision highp float;\n"
...@@ -579,6 +587,10 @@ TEST_P(ProgramInterfaceTestES31, QueryAtomicCounteBuffer) ...@@ -579,6 +587,10 @@ TEST_P(ProgramInterfaceTestES31, QueryAtomicCounteBuffer)
// Tests the resource property query for buffer variable can be done correctly. // Tests the resource property query for buffer variable can be done correctly.
TEST_P(ProgramInterfaceTestES31, GetBufferVariableProperties) TEST_P(ProgramInterfaceTestES31, GetBufferVariableProperties)
{ {
// TODO(jiajia.qin@intel.com): Don't skip this test once non-simple SSBO sentences are supported
// on d3d backend. http://anglebug.com/1951
ANGLE_SKIP_TEST_IF(IsD3D11());
const std::string &vertexShaderSource = const std::string &vertexShaderSource =
"#version 310 es\n" "#version 310 es\n"
"precision highp float;\n" "precision highp float;\n"
...@@ -699,6 +711,10 @@ TEST_P(ProgramInterfaceTestES31, GetBufferVariableProperties) ...@@ -699,6 +711,10 @@ TEST_P(ProgramInterfaceTestES31, GetBufferVariableProperties)
// Tests the resource property query for shader storage block can be done correctly. // Tests the resource property query for shader storage block can be done correctly.
TEST_P(ProgramInterfaceTestES31, GetShaderStorageBlockProperties) TEST_P(ProgramInterfaceTestES31, GetShaderStorageBlockProperties)
{ {
// TODO(jiajia.qin@intel.com): Don't skip this test once non-simple SSBO sentences are supported
// on d3d backend. http://anglebug.com/1951
ANGLE_SKIP_TEST_IF(IsD3D11());
const std::string &vertexShaderSource = const std::string &vertexShaderSource =
"#version 310 es\n" "#version 310 es\n"
"precision highp float;\n" "precision highp float;\n"
...@@ -892,6 +908,6 @@ TEST_P(ProgramInterfaceTestES31, QueryTransformFeedbackVarying) ...@@ -892,6 +908,6 @@ TEST_P(ProgramInterfaceTestES31, QueryTransformFeedbackVarying)
glDeleteProgram(program); glDeleteProgram(program);
} }
ANGLE_INSTANTIATE_TEST(ProgramInterfaceTestES31, ES31_OPENGL(), ES31_OPENGLES()); ANGLE_INSTANTIATE_TEST(ProgramInterfaceTestES31, ES31_OPENGL(), ES31_OPENGLES(), ES31_D3D11());
} // anonymous namespace } // anonymous namespace
...@@ -256,10 +256,6 @@ TEST_P(ShaderStorageBufferTest31, AtomicMemoryFunctions) ...@@ -256,10 +256,6 @@ TEST_P(ShaderStorageBufferTest31, AtomicMemoryFunctions)
// bindings again. // bindings again.
TEST_P(ShaderStorageBufferTest31, MultiStorageBuffersForMultiPrograms) TEST_P(ShaderStorageBufferTest31, MultiStorageBuffersForMultiPrograms)
{ {
// TODO(jiajia.qin@intel.com): Don't skip this test once glGetProgramResourceiv is supported on
// d3d backend. http://anglebug.com/1920
ANGLE_SKIP_TEST_IF(IsD3D11());
const std::string &csSource1 = const std::string &csSource1 =
R"(#version 310 es R"(#version 310 es
layout(local_size_x=3, local_size_y=1, local_size_z=1) in; layout(local_size_x=3, local_size_y=1, local_size_z=1) in;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment