Commit 46bcea50 by Luc Ferron Committed by Commit Bot

D3D,Vulkan: Prep work to share useful functions from D3D

- Refactor and move some functions used by D3D that are not really renderer specific to be used by the Vulkan implementation to support setting matx uniforms. Bug: angleproject:2581 Change-Id: Ib37ddf4fc62bb8ecb3629893a24969e1f515795b Reviewed-on: https://chromium-review.googlesource.com/1079845 Commit-Queue: Luc Ferron <lucferron@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 77a2b4c3
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "libANGLE/renderer/d3d/ShaderD3D.h" #include "libANGLE/renderer/d3d/ShaderD3D.h"
#include "libANGLE/renderer/d3d/ShaderExecutableD3D.h" #include "libANGLE/renderer/d3d/ShaderExecutableD3D.h"
#include "libANGLE/renderer/d3d/VertexDataManager.h" #include "libANGLE/renderer/d3d/VertexDataManager.h"
#include "libANGLE/renderer/renderer_utils.h"
using namespace angle; using namespace angle;
...@@ -75,66 +76,6 @@ void GetDefaultOutputLayoutFromShader( ...@@ -75,66 +76,6 @@ void GetDefaultOutputLayoutFromShader(
} }
} }
template <typename T, int cols, int rows>
bool TransposeExpandMatrix(T *target, const GLfloat *value)
{
constexpr int targetWidth = 4;
constexpr int targetHeight = rows;
constexpr int srcWidth = rows;
constexpr int srcHeight = cols;
constexpr int copyWidth = std::min(targetHeight, srcWidth);
constexpr int copyHeight = std::min(targetWidth, srcHeight);
T staging[targetWidth * targetHeight] = {0};
for (int x = 0; x < copyWidth; x++)
{
for (int y = 0; y < copyHeight; y++)
{
staging[x * targetWidth + y] = static_cast<T>(value[y * srcWidth + x]);
}
}
if (memcmp(target, staging, targetWidth * targetHeight * sizeof(T)) == 0)
{
return false;
}
memcpy(target, staging, targetWidth * targetHeight * sizeof(T));
return true;
}
template <typename T, int cols, int rows>
bool ExpandMatrix(T *target, const GLfloat *value)
{
constexpr int targetWidth = 4;
constexpr int targetHeight = rows;
constexpr int srcWidth = cols;
constexpr int srcHeight = rows;
constexpr int copyWidth = std::min(targetWidth, srcWidth);
constexpr int copyHeight = std::min(targetHeight, srcHeight);
T staging[targetWidth * targetHeight] = {0};
for (int y = 0; y < copyHeight; y++)
{
for (int x = 0; x < copyWidth; x++)
{
staging[y * targetWidth + x] = static_cast<T>(value[y * srcWidth + x]);
}
}
if (memcmp(target, staging, targetWidth * targetHeight * sizeof(T)) == 0)
{
return false;
}
memcpy(target, staging, targetWidth * targetHeight * sizeof(T));
return true;
}
gl::PrimitiveMode GetGeometryShaderTypeFromDrawMode(gl::PrimitiveMode drawMode) gl::PrimitiveMode GetGeometryShaderTypeFromDrawMode(gl::PrimitiveMode drawMode)
{ {
switch (drawMode) switch (drawMode)
...@@ -1903,7 +1844,7 @@ void ProgramD3D::setUniformMatrix2fv(GLint location, ...@@ -1903,7 +1844,7 @@ void ProgramD3D::setUniformMatrix2fv(GLint location,
GLboolean transpose, GLboolean transpose,
const GLfloat *value) const GLfloat *value)
{ {
setUniformMatrixfvInternal<2, 2>(location, count, transpose, value, GL_FLOAT_MAT2); setUniformMatrixfvInternal<2, 2>(location, count, transpose, value);
} }
void ProgramD3D::setUniformMatrix3fv(GLint location, void ProgramD3D::setUniformMatrix3fv(GLint location,
...@@ -1911,7 +1852,7 @@ void ProgramD3D::setUniformMatrix3fv(GLint location, ...@@ -1911,7 +1852,7 @@ void ProgramD3D::setUniformMatrix3fv(GLint location,
GLboolean transpose, GLboolean transpose,
const GLfloat *value) const GLfloat *value)
{ {
setUniformMatrixfvInternal<3, 3>(location, count, transpose, value, GL_FLOAT_MAT3); setUniformMatrixfvInternal<3, 3>(location, count, transpose, value);
} }
void ProgramD3D::setUniformMatrix4fv(GLint location, void ProgramD3D::setUniformMatrix4fv(GLint location,
...@@ -1919,7 +1860,7 @@ void ProgramD3D::setUniformMatrix4fv(GLint location, ...@@ -1919,7 +1860,7 @@ void ProgramD3D::setUniformMatrix4fv(GLint location,
GLboolean transpose, GLboolean transpose,
const GLfloat *value) const GLfloat *value)
{ {
setUniformMatrixfvInternal<4, 4>(location, count, transpose, value, GL_FLOAT_MAT4); setUniformMatrixfvInternal<4, 4>(location, count, transpose, value);
} }
void ProgramD3D::setUniformMatrix2x3fv(GLint location, void ProgramD3D::setUniformMatrix2x3fv(GLint location,
...@@ -1927,7 +1868,7 @@ void ProgramD3D::setUniformMatrix2x3fv(GLint location, ...@@ -1927,7 +1868,7 @@ void ProgramD3D::setUniformMatrix2x3fv(GLint location,
GLboolean transpose, GLboolean transpose,
const GLfloat *value) const GLfloat *value)
{ {
setUniformMatrixfvInternal<2, 3>(location, count, transpose, value, GL_FLOAT_MAT2x3); setUniformMatrixfvInternal<2, 3>(location, count, transpose, value);
} }
void ProgramD3D::setUniformMatrix3x2fv(GLint location, void ProgramD3D::setUniformMatrix3x2fv(GLint location,
...@@ -1935,7 +1876,7 @@ void ProgramD3D::setUniformMatrix3x2fv(GLint location, ...@@ -1935,7 +1876,7 @@ void ProgramD3D::setUniformMatrix3x2fv(GLint location,
GLboolean transpose, GLboolean transpose,
const GLfloat *value) const GLfloat *value)
{ {
setUniformMatrixfvInternal<3, 2>(location, count, transpose, value, GL_FLOAT_MAT3x2); setUniformMatrixfvInternal<3, 2>(location, count, transpose, value);
} }
void ProgramD3D::setUniformMatrix2x4fv(GLint location, void ProgramD3D::setUniformMatrix2x4fv(GLint location,
...@@ -1943,7 +1884,7 @@ void ProgramD3D::setUniformMatrix2x4fv(GLint location, ...@@ -1943,7 +1884,7 @@ void ProgramD3D::setUniformMatrix2x4fv(GLint location,
GLboolean transpose, GLboolean transpose,
const GLfloat *value) const GLfloat *value)
{ {
setUniformMatrixfvInternal<2, 4>(location, count, transpose, value, GL_FLOAT_MAT2x4); setUniformMatrixfvInternal<2, 4>(location, count, transpose, value);
} }
void ProgramD3D::setUniformMatrix4x2fv(GLint location, void ProgramD3D::setUniformMatrix4x2fv(GLint location,
...@@ -1951,7 +1892,7 @@ void ProgramD3D::setUniformMatrix4x2fv(GLint location, ...@@ -1951,7 +1892,7 @@ void ProgramD3D::setUniformMatrix4x2fv(GLint location,
GLboolean transpose, GLboolean transpose,
const GLfloat *value) const GLfloat *value)
{ {
setUniformMatrixfvInternal<4, 2>(location, count, transpose, value, GL_FLOAT_MAT4x2); setUniformMatrixfvInternal<4, 2>(location, count, transpose, value);
} }
void ProgramD3D::setUniformMatrix3x4fv(GLint location, void ProgramD3D::setUniformMatrix3x4fv(GLint location,
...@@ -1959,7 +1900,7 @@ void ProgramD3D::setUniformMatrix3x4fv(GLint location, ...@@ -1959,7 +1900,7 @@ void ProgramD3D::setUniformMatrix3x4fv(GLint location,
GLboolean transpose, GLboolean transpose,
const GLfloat *value) const GLfloat *value)
{ {
setUniformMatrixfvInternal<3, 4>(location, count, transpose, value, GL_FLOAT_MAT3x4); setUniformMatrixfvInternal<3, 4>(location, count, transpose, value);
} }
void ProgramD3D::setUniformMatrix4x3fv(GLint location, void ProgramD3D::setUniformMatrix4x3fv(GLint location,
...@@ -1967,7 +1908,7 @@ void ProgramD3D::setUniformMatrix4x3fv(GLint location, ...@@ -1967,7 +1908,7 @@ void ProgramD3D::setUniformMatrix4x3fv(GLint location,
GLboolean transpose, GLboolean transpose,
const GLfloat *value) const GLfloat *value)
{ {
setUniformMatrixfvInternal<4, 3>(location, count, transpose, value, GL_FLOAT_MAT4x3); setUniformMatrixfvInternal<4, 3>(location, count, transpose, value);
} }
void ProgramD3D::setUniform1iv(GLint location, GLsizei count, const GLint *v) void ProgramD3D::setUniform1iv(GLint location, GLsizei count, const GLint *v)
...@@ -2341,60 +2282,26 @@ void ProgramD3D::setUniformInternal(GLint location, GLsizei count, const T *v, G ...@@ -2341,60 +2282,26 @@ void ProgramD3D::setUniformInternal(GLint location, GLsizei count, const T *v, G
} }
template <int cols, int rows> template <int cols, int rows>
bool ProgramD3D::setUniformMatrixfvImpl(GLint location,
GLsizei countIn,
GLboolean transpose,
const GLfloat *value,
uint8_t *targetData,
GLenum targetUniformType)
{
D3DUniform *targetUniform = getD3DUniformFromLocation(location);
unsigned int elementCount = targetUniform->getArraySizeProduct();
unsigned int arrayElementOffset = mState.getUniformLocations()[location].arrayIndex;
unsigned int count =
std::min(elementCount - arrayElementOffset, static_cast<unsigned int>(countIn));
const unsigned int targetMatrixStride = (4 * rows);
GLfloat *target = reinterpret_cast<GLfloat *>(
targetData + arrayElementOffset * sizeof(GLfloat) * targetMatrixStride);
bool dirty = false;
for (unsigned int i = 0; i < count; i++)
{
// Internally store matrices as transposed versions to accomodate HLSL matrix indexing
if (transpose == GL_FALSE)
{
dirty = TransposeExpandMatrix<GLfloat, cols, rows>(target, value) || dirty;
}
else
{
dirty = ExpandMatrix<GLfloat, cols, rows>(target, value) || dirty;
}
target += targetMatrixStride;
value += cols * rows;
}
return dirty;
}
template <int cols, int rows>
void ProgramD3D::setUniformMatrixfvInternal(GLint location, void ProgramD3D::setUniformMatrixfvInternal(GLint location,
GLsizei countIn, GLsizei countIn,
GLboolean transpose, GLboolean transpose,
const GLfloat *value, const GLfloat *value)
GLenum targetUniformType)
{ {
D3DUniform *targetUniform = getD3DUniformFromLocation(location); D3DUniform *targetUniform = getD3DUniformFromLocation(location);
const gl::VariableLocation &uniformLocation = mState.getUniformLocations()[location];
unsigned int arrayElementOffset = uniformLocation.arrayIndex;
unsigned int elementCount = targetUniform->getArraySizeProduct();
// Internally store matrices as transposed versions to accomodate HLSL matrix indexing
transpose = !transpose;
for (gl::ShaderType shaderType : gl::AllShaderTypes()) for (gl::ShaderType shaderType : gl::AllShaderTypes())
{ {
if (targetUniform->mShaderData[shaderType]) if (targetUniform->mShaderData[shaderType])
{ {
if (setUniformMatrixfvImpl<cols, rows>(location, countIn, transpose, value, if (SetFloatUniformMatrix<cols, rows>(arrayElementOffset, elementCount, countIn,
targetUniform->mShaderData[shaderType], transpose, value,
targetUniformType)) targetUniform->mShaderData[shaderType]))
{ {
mShaderUniformsDirty.set(shaderType); mShaderUniformsDirty.set(shaderType);
} }
......
...@@ -437,19 +437,10 @@ class ProgramD3D : public ProgramImpl ...@@ -437,19 +437,10 @@ class ProgramD3D : public ProgramImpl
void setUniformInternal(GLint location, GLsizei count, const T *v, GLenum uniformType); void setUniformInternal(GLint location, GLsizei count, const T *v, GLenum uniformType);
template <int cols, int rows> template <int cols, int rows>
bool setUniformMatrixfvImpl(GLint location,
GLsizei count,
GLboolean transpose,
const GLfloat *value,
uint8_t *targetData,
GLenum targetUniformType);
template <int cols, int rows>
void setUniformMatrixfvInternal(GLint location, void setUniformMatrixfvInternal(GLint location,
GLsizei count, GLsizei count,
GLboolean transpose, GLboolean transpose,
const GLfloat *value, const GLfloat *value);
GLenum targetUniformType);
gl::LinkResult compileProgramExecutables(const gl::Context *context, gl::InfoLog &infoLog); gl::LinkResult compileProgramExecutables(const gl::Context *context, gl::InfoLog &infoLog);
gl::LinkResult compileComputeExecutable(const gl::Context *context, gl::InfoLog &infoLog); gl::LinkResult compileComputeExecutable(const gl::Context *context, gl::InfoLog &infoLog);
......
...@@ -225,6 +225,66 @@ void WriteFloatColor(const gl::ColorF &color, ...@@ -225,6 +225,66 @@ void WriteFloatColor(const gl::ColorF &color,
colorWriteFunction(reinterpret_cast<const uint8_t *>(&color), destPixelData); colorWriteFunction(reinterpret_cast<const uint8_t *>(&color), destPixelData);
} }
template <typename T, int cols, int rows>
bool TransposeExpandMatrix(T *target, const GLfloat *value)
{
constexpr int targetWidth = 4;
constexpr int targetHeight = rows;
constexpr int srcWidth = rows;
constexpr int srcHeight = cols;
constexpr int copyWidth = std::min(targetHeight, srcWidth);
constexpr int copyHeight = std::min(targetWidth, srcHeight);
T staging[targetWidth * targetHeight] = {0};
for (int x = 0; x < copyWidth; x++)
{
for (int y = 0; y < copyHeight; y++)
{
staging[x * targetWidth + y] = static_cast<T>(value[y * srcWidth + x]);
}
}
if (memcmp(target, staging, targetWidth * targetHeight * sizeof(T)) == 0)
{
return false;
}
memcpy(target, staging, targetWidth * targetHeight * sizeof(T));
return true;
}
template <typename T, int cols, int rows>
bool ExpandMatrix(T *target, const GLfloat *value)
{
constexpr int kTargetWidth = 4;
constexpr int kTargetHeight = rows;
constexpr int kSrcWidth = cols;
constexpr int kSrcHeight = rows;
constexpr int kCopyWidth = std::min(kTargetWidth, kSrcWidth);
constexpr int kCopyHeight = std::min(kTargetHeight, kSrcHeight);
T staging[kTargetWidth * kTargetHeight] = {0};
for (int y = 0; y < kCopyHeight; y++)
{
for (int x = 0; x < kCopyWidth; x++)
{
staging[y * kTargetWidth + x] = static_cast<T>(value[y * kSrcWidth + x]);
}
}
if (memcmp(target, staging, kTargetWidth * kTargetHeight * sizeof(T)) == 0)
{
return false;
}
memcpy(target, staging, kTargetWidth * kTargetHeight * sizeof(T));
return true;
}
} // anonymous namespace } // anonymous namespace
PackPixelsParams::PackPixelsParams() PackPixelsParams::PackPixelsParams()
...@@ -546,4 +606,54 @@ gl::Error IncompleteTextureSet::getIncompleteTexture( ...@@ -546,4 +606,54 @@ gl::Error IncompleteTextureSet::getIncompleteTexture(
return gl::NoError(); return gl::NoError();
} }
#define ANGLE_INSTANTIATE_SET_UNIFORM_MATRIX_FUNC(cols, rows) \
template bool SetFloatUniformMatrix<cols, rows>(unsigned int, unsigned int, GLsizei, \
GLboolean, const GLfloat *, uint8_t *)
ANGLE_INSTANTIATE_SET_UNIFORM_MATRIX_FUNC(2, 2);
ANGLE_INSTANTIATE_SET_UNIFORM_MATRIX_FUNC(3, 3);
ANGLE_INSTANTIATE_SET_UNIFORM_MATRIX_FUNC(4, 4);
ANGLE_INSTANTIATE_SET_UNIFORM_MATRIX_FUNC(2, 3);
ANGLE_INSTANTIATE_SET_UNIFORM_MATRIX_FUNC(3, 2);
ANGLE_INSTANTIATE_SET_UNIFORM_MATRIX_FUNC(2, 4);
ANGLE_INSTANTIATE_SET_UNIFORM_MATRIX_FUNC(4, 2);
ANGLE_INSTANTIATE_SET_UNIFORM_MATRIX_FUNC(3, 4);
ANGLE_INSTANTIATE_SET_UNIFORM_MATRIX_FUNC(4, 3);
#undef ANGLE_INSTANTIATE_SET_UNIFORM_MATRIX_FUNC
template <int cols, int rows>
bool SetFloatUniformMatrix(unsigned int arrayElementOffset,
unsigned int elementCount,
GLsizei countIn,
GLboolean transpose,
const GLfloat *value,
uint8_t *targetData)
{
unsigned int count =
std::min(elementCount - arrayElementOffset, static_cast<unsigned int>(countIn));
const unsigned int targetMatrixStride = (4 * rows);
GLfloat *target = reinterpret_cast<GLfloat *>(
targetData + arrayElementOffset * sizeof(GLfloat) * targetMatrixStride);
bool dirty = false;
for (unsigned int i = 0; i < count; i++)
{
if (transpose == GL_FALSE)
{
dirty = ExpandMatrix<GLfloat, cols, rows>(target, value) || dirty;
}
else
{
dirty = TransposeExpandMatrix<GLfloat, cols, rows>(target, value) || dirty;
}
target += targetMatrixStride;
value += cols * rows;
}
return dirty;
}
} // namespace rx } // namespace rx
...@@ -258,6 +258,15 @@ class IncompleteTextureSet final : angle::NonCopyable ...@@ -258,6 +258,15 @@ class IncompleteTextureSet final : angle::NonCopyable
gl::TextureMap mIncompleteTextures; gl::TextureMap mIncompleteTextures;
}; };
// The return value indicate if the data was updated or not.
template <int cols, int rows>
bool SetFloatUniformMatrix(unsigned int arrayElementOffset,
unsigned int elementCount,
GLsizei countIn,
GLboolean transpose,
const GLfloat *value,
uint8_t *targetData);
} // namespace rx } // namespace rx
#endif // LIBANGLE_RENDERER_RENDERER_UTILS_H_ #endif // LIBANGLE_RENDERER_RENDERER_UTILS_H_
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