Skip to content

Commit

Permalink
Add Support for Handling Block Based Mat3x3 Arrays
Browse files Browse the repository at this point in the history
Summary:
Same as what's already there, except now use the
block aware version of setUniformBytes

Reviewed By: corporateshark, AmesingFlank

Differential Revision: D51923508

fbshipit-source-id: f97305985f8993c5ebdc3b56c89db6ea308a8b86
  • Loading branch information
syeh1 authored and facebook-github-bot committed Jan 19, 2024
1 parent d7bce97 commit 36a5c18
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
46 changes: 46 additions & 0 deletions IGLU/simple_renderer/ShaderUniforms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,52 @@ void ShaderUniforms::setFloat3x3Array(const igl::NameHandle& uniformName,
}
}

void ShaderUniforms::setFloat3x3Array(const igl::NameHandle& blockTypeName,
const igl::NameHandle& blockInstanceName,
const igl::NameHandle& memberName,
const iglu::simdtypes::float3x3* value,
size_t count,
size_t arrayIndex) {
auto isOglBlock = device_.getBackendType() == igl::BackendType::OpenGL &&
_bufferDescs.find(blockTypeName) != _bufferDescs.end();

if (device_.getBackendType() == igl::BackendType::Metal ||
device_.getBackendType() == igl::BackendType::Vulkan || isOglBlock) {
setUniformBytes(blockTypeName,
blockInstanceName,
memberName,
value,
sizeof(iglu::simdtypes::float3x3),
count,
arrayIndex);
} else {
// simdtypes::float3x3 has an extra float per float-vector.
// Remove it so we can send the packed version to OpenGL
const size_t size = sizeof(float) * 9u * count;
IGL_ASSERT(size <= 65536);
float* IGL_RESTRICT packedMatrix = reinterpret_cast<float*>(alloca(size));
float* IGL_RESTRICT packedMatrixPtr = packedMatrix;

const auto* paddedMatrixPtr = reinterpret_cast<const float*>(value);
for (size_t n = 0; n < count; n++) {
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
*packedMatrixPtr++ = *paddedMatrixPtr++;
}
paddedMatrixPtr++; // skip over padded float
}
}

setUniformBytes(blockTypeName,
blockInstanceName,
memberName,
packedMatrix,
sizeof(float) * 9,
count,
arrayIndex);
}
}

void ShaderUniforms::setFloat4x4(const igl::NameHandle& uniformName,
const iglu::simdtypes::float4x4& value,
size_t arrayIndex) {
Expand Down
6 changes: 6 additions & 0 deletions IGLU/simple_renderer/ShaderUniforms.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ class ShaderUniforms final {
const iglu::simdtypes::float3x3* value,
size_t count = 1,
size_t arrayIndex = 0);
void setFloat3x3Array(const igl::NameHandle& blockTypeName,
const igl::NameHandle& blockInstanceName,
const igl::NameHandle& memberName,
const iglu::simdtypes::float3x3* value,
size_t count = 1,
size_t arrayIndex = 0);

void setFloat4x4(const igl::NameHandle& uniformName,
const iglu::simdtypes::float4x4& value,
Expand Down

0 comments on commit 36a5c18

Please sign in to comment.