Skip to content

Commit

Permalink
iglu | Faster ShaderUniforms::setFloat3Array()
Browse files Browse the repository at this point in the history
Summary: Faster `ShaderUniforms::setFloat3Array()` without heap allocations and multiple memory overwrites.

Reviewed By: dmannemela, AmesingFlank

Differential Revision: D51089951

fbshipit-source-id: 2b3c4e58f33b692c50512e68332091416d932268
  • Loading branch information
corporateshark authored and facebook-github-bot committed Nov 9, 2023
1 parent 5c6bdff commit 9fb179e
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions IGLU/simple_renderer/ShaderUniforms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,18 +423,20 @@ void ShaderUniforms::setFloat3Array(const igl::NameHandle& uniformName,
setUniformBytes(uniformName, value, sizeof(iglu::simdtypes::float3), count, arrayIndex);
} else {
// simdtypes::float3 is padded to have an extra float.
// Remove it so we can send the packed version to OpenGL/Vulkan
auto* packedArray = new float[3 * count];
float* packedArrayPtr = packedArray;
auto paddedArrayPtr = reinterpret_cast<const float*>(value);
// This code path should not be used for Vulkan. (it should only be used for OpenGL when uniform
// blocks are not used).
const size_t size = sizeof(float) * 3u * count;
IGL_ASSERT(size <= 65536);
float* IGL_RESTRICT packedArray = reinterpret_cast<float*>(alloca(size));
float* IGL_RESTRICT packedArrayPtr = packedArray;
const float* paddedArrayPtr = reinterpret_cast<const float*>(value);
for (size_t i = 0; i < count; i++) {
for (int j = 0; j < 3; j++) {
*packedArrayPtr++ = *paddedArrayPtr++;
}
paddedArrayPtr++; // padded float
}
setUniformBytes(uniformName, packedArray, sizeof(float) * 3 * count, 1, arrayIndex);
delete[] packedArray;
setUniformBytes(uniformName, packedArray, size, 1, arrayIndex);
}
}

Expand Down

0 comments on commit 9fb179e

Please sign in to comment.