Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GPU Instancing Experiment #2664

Draft
wants to merge 54 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
61afea1
WIP -- Use gpu instancing for rendering faces with GLTF materials app…
RunitaiLinden Sep 24, 2024
7ab2fc9
Fix alpha masking, texture transforms, and HUDs
RunitaiLinden Sep 24, 2024
8e8333a
GPU instancing support for rigged meshes
RunitaiLinden Sep 26, 2024
36b2886
Split doublesided into its own pass, sanitize variant batch management
RunitaiLinden Sep 27, 2024
6638e8b
Sanitize GLTF shader variant handling
RunitaiLinden Sep 27, 2024
8278edc
Take advantage of ALPHA_MASK and DOUBLE_SIDED in GLTF shader
RunitaiLinden Sep 27, 2024
02b41cf
Use UBOs for material parameters
RunitaiLinden Sep 28, 2024
a700b31
GPU planar texture projection
RunitaiLinden Sep 28, 2024
0eb09d6
Remove pointers from LLGLTFDrawInfo
RunitaiLinden Sep 30, 2024
48ca5e1
GPU instancing texture animation support
RunitaiLinden Oct 3, 2024
9a32385
Disable legacy render pipes. Accelerate batch map build.
RunitaiLinden Oct 4, 2024
a52af56
Bring back ability for LLImageGL to change texname to reduce framestalls
RunitaiLinden Oct 4, 2024
3746279
Fix for occasional bad mesh.
RunitaiLinden Oct 7, 2024
a21e76a
WIP - Plumb up render batches and shaders for blinn-phong GPU instancing
RunitaiLinden Oct 8, 2024
307d2c1
Merge branch 'develop' into davep-gpu-instancing
RunitaiLinden Oct 8, 2024
23871ce
Fix for no geometry rendering on Mac
RunitaiLinden Oct 10, 2024
80c74f0
Stub out blinn-phong GPU instancing
RunitaiLinden Oct 14, 2024
470cf36
Blinn Phong GPU instancing WIP
RunitaiLinden Oct 15, 2024
aaa1842
Remove dedicated prim scale UBO, add support for 32-bit indices, remo…
RunitaiLinden Oct 15, 2024
0cea27f
Cull some now-dead code and tune octree a bit
RunitaiLinden Oct 16, 2024
d196833
Merge branch 'develop' into davep-gpu-instancing
RunitaiLinden Oct 16, 2024
29a5e6a
Add fullbright/glossiness/env intensity support to gpu instancing pipe
RunitaiLinden Oct 16, 2024
0e59fee
Add fast transform updates, instrument some lambdas
RunitaiLinden Oct 16, 2024
929f2d7
Cull dead code
RunitaiLinden Oct 17, 2024
5b3a1da
Merge branch 'develop' into davep-gpu-instancing
RunitaiLinden Oct 17, 2024
8e5c92d
Fix for child transforms not updating
RunitaiLinden Oct 17, 2024
68da13f
Fix for GLTFDrawInfo referencing deleted textures
RunitaiLinden Oct 21, 2024
d5e49da
Render alpha blended objects with gpu-instancing (unsorted)
RunitaiLinden Oct 22, 2024
bdd695c
Add bag render batch debug display, batch texture transforms
RunitaiLinden Oct 23, 2024
53b52d6
Optimize transform management for attachment linksets
RunitaiLinden Oct 26, 2024
2605a8c
Add support for glow
RunitaiLinden Oct 28, 2024
b76f3b6
Add "IdleThread" setting to chuck LLAppViewer::idle onto a background…
RunitaiLinden Oct 29, 2024
210ef32
Multi-threaded idle followup. Shuffle some operations into and out o…
RunitaiLinden Oct 30, 2024
a9177b3
More "IdleThread" coverage.
RunitaiLinden Oct 31, 2024
ea9abc1
Merge branch 'develop' into davep-gpu-instancing
RunitaiLinden Oct 31, 2024
fa395de
Merge branch 'develop' into davep-gpu-instancing
RunitaiLinden Oct 31, 2024
01ba168
Pre-commit cleanup (and add missing refcount include)
RunitaiLinden Oct 31, 2024
14eff3f
Disable chunks of the render pipe for the cube map update when reflec…
RunitaiLinden Oct 31, 2024
d064820
Mac build fix
RunitaiLinden Oct 31, 2024
75db507
Disable some now broken unit tests (temporarily, to get a build)
RunitaiLinden Nov 1, 2024
0063fa0
Merge branch 'davep-gpu-instancing' of https://github.com/secondlife/…
RunitaiLinden Nov 1, 2024
cd8d6a0
Don't render 100% transparent faces
RunitaiLinden Nov 1, 2024
964ee5f
Add dedicated shadow batches. IdleThread fixes. Fix shadow alpha ma…
RunitaiLinden Nov 4, 2024
8fcf642
Add depth pre-pass support, prune shadow render, optimize batch build…
RunitaiLinden Nov 5, 2024
c1e6626
Merge branch 'develop' into davep-gpu-instancing
RunitaiLinden Nov 5, 2024
d86aee6
Add no-normal map blinn-phong variant. Add option to disable normal …
RunitaiLinden Nov 5, 2024
7270f76
Add shader variants for every combination of textures, fix for transp…
RunitaiLinden Nov 6, 2024
c3f518a
Add ability to defer shader compilation until first use.
RunitaiLinden Nov 7, 2024
81ceb99
Merge from develop
RunitaiLinden Nov 7, 2024
cbad1e5
Merge cleanup
RunitaiLinden Nov 7, 2024
5d31d62
Fix for region crossing.
RunitaiLinden Nov 12, 2024
eec732f
Merge branch 'develop' into davep-gpu-instancing
RunitaiLinden Nov 13, 2024
e342e33
Merge branch 'develop' into davep-gpu-instancing
RunitaiLinden Nov 13, 2024
511bb38
Merge branch 'develop' into davep-gpu-instancing
RunitaiLinden Nov 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions indra/llappearance/llavatarappearance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -797,9 +797,8 @@ void LLAvatarAppearance::buildCharacter()
LLTimer timer;

bool status = loadAvatar();
stop_glerror();

// gPrintMessagesThisFrame = true;
// gPrintMessagesThisFrame = true;
LL_DEBUGS() << "Avatar load took " << timer.getElapsedTimeF32() << " seconds." << LL_ENDL;

if (!status)
Expand Down Expand Up @@ -870,8 +869,6 @@ void LLAvatarAppearance::buildCharacter()
mPelvisp->setPosition( LLVector3(0.0f, 0.0f, 0.0f) );

mIsBuilt = true;
stop_glerror();

}

bool LLAvatarAppearance::loadAvatar()
Expand Down
1 change: 0 additions & 1 deletion indra/llappearance/lllocaltextureobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ LLLocalTextureObject::LLLocalTextureObject(LLGLTexture* image, const LLUUID& id)
mDiscard(MAX_DISCARD_LEVEL+1)
{
mImage = image;
gGL.getTexUnit(0)->bind(mImage);
mID = id;
}

Expand Down
7 changes: 7 additions & 0 deletions indra/llaudio/llaudioengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ LLAudioEngine::LLAudioPlayState LLAudioEngine::isInternetStreamPlaying()
// virtual
void LLAudioEngine::setInternetStreamGain(F32 vol)
{
LL_PROFILE_ZONE_SCOPED;
if (mStreamingAudioImpl)
mStreamingAudioImpl->setGain(vol);
}
Expand All @@ -211,6 +212,7 @@ std::string LLAudioEngine::getInternetStreamURL()

void LLAudioEngine::updateChannels()
{
LL_PROFILE_ZONE_SCOPED;
S32 i;
for (i = 0; i < LL_MAX_AUDIO_CHANNELS; i++)
{
Expand All @@ -225,6 +227,7 @@ void LLAudioEngine::updateChannels()

void LLAudioEngine::idle()
{
LL_PROFILE_ZONE_SCOPED;
// "Update" all of our audio sources, clean up dead ones.
// Primarily does position updating, cleanup of unused audio sources.
// Also does regeneration of the current priority of each audio source.
Expand Down Expand Up @@ -666,6 +669,7 @@ bool LLAudioEngine::isWindEnabled()

void LLAudioEngine::setMuted(bool muted)
{
LL_PROFILE_ZONE_SCOPED;
if (muted != mMuted)
{
mMuted = muted;
Expand All @@ -676,6 +680,7 @@ void LLAudioEngine::setMuted(bool muted)

void LLAudioEngine::setMasterGain(const F32 gain)
{
LL_PROFILE_ZONE_SCOPED;
mMasterGain = gain;
F32 internal_gain = getMuted() ? 0.f : gain;
if (internal_gain != mInternalGain)
Expand Down Expand Up @@ -859,6 +864,7 @@ void LLAudioEngine::setListener(LLVector3 pos, LLVector3 vel, LLVector3 up, LLVe

void LLAudioEngine::setDopplerFactor(F32 factor)
{
LL_PROFILE_ZONE_SCOPED;
if (mListenerp)
{
mListenerp->setDopplerFactor(factor);
Expand All @@ -881,6 +887,7 @@ F32 LLAudioEngine::getDopplerFactor()

void LLAudioEngine::setRolloffFactor(F32 factor)
{
LL_PROFILE_ZONE_SCOPED;
if (mListenerp)
{
mListenerp->setRolloffFactor(factor);
Expand Down
6 changes: 3 additions & 3 deletions indra/llcommon/llsafehandle.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ class LLSafeHandle
}
}

public:
// Define an LLSingleton whose sole purpose is to hold a "null instance"
// of the subject Type: the canonical instance to dereference if this
// LLSafeHandle actually holds a null pointer. We use LLSingleton
Expand All @@ -178,11 +179,10 @@ class LLSafeHandle
// Of course, as with any LLSingleton, the "null instance" is only
// instantiated on demand -- in this case, if you actually try to
// dereference an LLSafeHandle containing null.
class NullInstanceHolder: public LLSingleton<NullInstanceHolder>
class NullInstanceHolder: public LLSimpleton<NullInstanceHolder>
{
LLSINGLETON_EMPTY_CTOR(NullInstanceHolder);
~NullInstanceHolder() {}
public:
~NullInstanceHolder() {}
Type mNullInstance;
};

Expand Down
2 changes: 1 addition & 1 deletion indra/llcommon/lltraceaccumulators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ void SampleAccumulator::reset(const SampleAccumulator* other)
mMin = mLastValue;
mMax = mLastValue;
mMean = mLastValue;
llassert(!mHasValue || mMean < 0 || mMean >= 0);
//llassert(!mHasValue || mMean < 0 || mMean >= 0);
mSumOfSquares = 0;
mLastSampleTimeStamp = LLTimer::getTotalSeconds();
mTotalSamplingTime = 0;
Expand Down
25 changes: 24 additions & 1 deletion indra/llmath/llmatrix4a.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,26 @@
class LLMatrix4a
{
public:
LL_ALIGN_16(LLVector4a mMatrix[4]);
union
{
LLVector4a mMatrix[4];
LLMatrix4 mMatrix4;
};

LLMatrix4a()
{

}

~LLMatrix4a()
{
}

LLMatrix4a(const LLMatrix4a& rhs)
{
*this = rhs;
}

explicit LLMatrix4a(const LLMatrix4& val)
{
loadu(val);
Expand All @@ -51,6 +64,16 @@ class LLMatrix4a
loadu(val);
}

inline const LLMatrix4a& operator=(const LLMatrix4a& rhs)
{
mMatrix[0] = rhs.mMatrix[0];
mMatrix[1] = rhs.mMatrix[1];
mMatrix[2] = rhs.mMatrix[2];
mMatrix[3] = rhs.mMatrix[3];

return *this;
}

static const LLMatrix4a& identity()
{
static const F32 v[] =
Expand Down
95 changes: 95 additions & 0 deletions indra/llmath/llvolume.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2320,6 +2320,7 @@ bool LLVolume::unpackVolumeFaces(U8* in_data, S32 size)
bool LLVolume::unpackVolumeFacesInternal(const LLSD& mdl)
{
{
mVertexBuffer = nullptr;
auto face_count = mdl.size();

if (face_count == 0)
Expand Down Expand Up @@ -2764,9 +2765,103 @@ bool LLVolume::cacheOptimize(bool gen_tangents)
return false;
}
}

return true;
}

extern U32 ll_gl_gen_arrays();

static bool validate_vertex_buffer(LLVolume* volume)
{
if (volume->mVertexBuffer.isNull())
{
// allowed to be null
return true;
}

U32 num_verts = 0;
U32 num_indices = 0;
for (auto& face: volume->getVolumeFaces())
{
num_verts += face.mNumVertices;
num_indices += face.mNumIndices;
}

bool same_verts = num_verts == volume->mVertexBuffer->getNumVerts();
bool same_indices = num_indices == volume->mVertexBuffer->getNumIndices();

return same_verts && same_indices;
}

void LLVolume::createVertexBuffer()
{
if (getNumFaces() && (mVertexBuffer.isNull() || !validate_vertex_buffer(this)))
{
LL_PROFILE_ZONE_SCOPED;

U32 mask = LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_NORMAL | LLVertexBuffer::MAP_TEXCOORD0 | LLVertexBuffer::MAP_TANGENT;
U32 vert_count = 0;
U32 index_count = 0;
for (auto& face : mVolumeFaces)
{
face.mVBGeomOffset = vert_count;
face.mVBIndexOffset = index_count;

vert_count += face.mNumVertices;
index_count += face.mNumIndices;

if (face.mWeights)
{
mask |= LLVertexBuffer::MAP_WEIGHT4;
}
}

bool large_indices = vert_count >= 65536;

mVertexBuffer = new LLVertexBuffer(mask);
if (large_indices)
{
mVertexBuffer->setIndicesType(GL_UNSIGNED_INT);
}
mVertexBuffer->allocateBuffer(vert_count, index_count);

mVertexBuffer->bindBuffer();

for (auto& face : mVolumeFaces)
{
face.mVertexBuffer = mVertexBuffer;
// ensure tangents have been created
face.createTangents();
mVertexBuffer->setPositionData(face.mPositions, face.mVBGeomOffset, face.mNumVertices);
mVertexBuffer->setNormalData(face.mNormals, face.mVBGeomOffset, face.mNumVertices);
mVertexBuffer->setTexCoord0Data(face.mTexCoords, face.mVBGeomOffset, face.mNumVertices);
mVertexBuffer->setTangentData(face.mTangents, face.mVBGeomOffset, face.mNumVertices);
if (face.mWeights)
{
mVertexBuffer->setWeight4Data(face.mWeights, face.mVBGeomOffset, face.mNumVertices);
}

if (face.mVBGeomOffset > 0)
{
static std::vector<U16> indices;
indices.resize(0);
for (S32 i = 0; i < face.mNumIndices; ++i)
{
indices.push_back(face.mIndices[i] + face.mVBGeomOffset);
}
mVertexBuffer->setIndexData(&indices[0], face.mVBIndexOffset, face.mNumIndices);
}
else
{
mVertexBuffer->setIndexData(face.mIndices, face.mVBIndexOffset, face.mNumIndices);
}
}

#if LL_DARWIN
mVertexBuffer->unmapBuffer();
#endif
}
}

S32 LLVolume::getNumFaces() const
{
Expand Down
12 changes: 12 additions & 0 deletions indra/llmath/llvolume.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class LLVolumeOctree;
#include "llfile.h"
#include "llalignedarray.h"
#include "llrigginginfo.h"
#include "../llrender/llvertexbuffer.h"

//============================================================================

Expand Down Expand Up @@ -976,6 +977,13 @@ class LLVolumeFace
// mWeights.size() should be empty or match mVertices.size()
LLVector4a* mWeights;

// vertex buffer that contains this face's geometry (may be null)
LLPointer<LLVertexBuffer> mVertexBuffer;
// offset into mVertexBuffer where this face's geometry starts
U32 mVBGeomOffset = 0;
// offset into mVertexBuffe where this face's indices start
U32 mVBIndexOffset = 0;

#if USE_SEPARATE_JOINT_INDICES_AND_WEIGHTS
LLVector4a* mJustWeights;
U8* mJointIndices;
Expand Down Expand Up @@ -1102,6 +1110,8 @@ class LLVolume : public LLRefCount
// gen_tangents - if true, generate MikkTSpace tangents if needed before optimizing index buffer
bool cacheOptimize(bool gen_tangents = false);

void createVertexBuffer();

private:
void sculptGenerateMapVertices(U16 sculpt_width, U16 sculpt_height, S8 sculpt_components, const U8* sculpt_data, U8 sculpt_type);
F32 sculptGetSurfaceArea();
Expand Down Expand Up @@ -1141,6 +1151,8 @@ class LLVolume : public LLRefCount
face_list_t mVolumeFaces;

public:
LLPointer<LLVertexBuffer> mVertexBuffer;

LLVector4a* mHullPoints;
U16* mHullIndices;
S32 mNumHullPoints;
Expand Down
7 changes: 7 additions & 0 deletions indra/llmath/v2math.h
Original file line number Diff line number Diff line change
Expand Up @@ -437,4 +437,11 @@ inline std::ostream& operator<<(std::ostream& s, const LLVector2& a)
return s;
}

// For use with boost containers.
inline size_t hash_value(const LLVector2& v) noexcept
{
return boost::hash_range(v.mV, v.mV + 1);
}


#endif
7 changes: 7 additions & 0 deletions indra/llmath/v3color.h
Original file line number Diff line number Diff line change
Expand Up @@ -507,4 +507,11 @@ void LLColor3::write(std::vector<T>& v) const
}
}

inline size_t hash_value(const LLColor3& c) noexcept
{
size_t hash = 0;
boost::hash_range(hash, (F32*) c.mV, (F32*) c.mV + 2);
return hash;
}

#endif
7 changes: 7 additions & 0 deletions indra/llmath/v4color.h
Original file line number Diff line number Diff line change
Expand Up @@ -674,4 +674,11 @@ void LLColor4::write(std::vector<T>& v) const
}
}

inline size_t hash_value(const LLColor4& c) noexcept
{
size_t hash = 0;
boost::hash_range(hash, (F32*)c.mV, (F32*)c.mV + 3);
return hash;
}

#endif
6 changes: 6 additions & 0 deletions indra/llmath/v4coloru.h
Original file line number Diff line number Diff line change
Expand Up @@ -495,4 +495,10 @@ inline void LLColor4U::fromRGBA(U32 aVal)
mV[3] = aVal & 0xFF;
}

// For use with boost containers.
inline size_t hash_value(const LLColor4U& c) noexcept
{
return (size_t) *((U32*)c.mV);
}

#endif
22 changes: 11 additions & 11 deletions indra/llprimitive/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ target_link_libraries(llprimitive
)

#add unit tests
if (LL_TESTS)
INCLUDE(LLAddBuildTest)
SET(llprimitive_TEST_SOURCE_FILES
llmediaentry.cpp
llprimitive.cpp
llgltfmaterial.cpp
)

set_property(SOURCE llprimitive.cpp PROPERTY LL_TEST_ADDITIONAL_LIBRARIES llmessage)
LL_ADD_PROJECT_UNIT_TESTS(llprimitive "${llprimitive_TEST_SOURCE_FILES}")
endif (LL_TESTS)
#if (LL_TESTS)
# INCLUDE(LLAddBuildTest)
# SET(llprimitive_TEST_SOURCE_FILES
# llmediaentry.cpp
# llprimitive.cpp
# llgltfmaterial.cpp
# )
#
# set_property(SOURCE llprimitive.cpp PROPERTY LL_TEST_ADDITIONAL_LIBRARIES llmessage)
# LL_ADD_PROJECT_UNIT_TESTS(llprimitive "${llprimitive_TEST_SOURCE_FILES}")
#endif (LL_TESTS)
Loading
Loading