Page 1 of 1
Exclude DatablockMember from Shader Memcpy?
Posted: Sun Oct 18, 2015 4:08 pm
by white_waluigi
I'm currently creating a LightDatablock to Hold shader paramters for LigthMaterials.
But right now I have Debug Information in that Datablock (Id of the refernced Light) that I don't want to be send to the Shader.
But since the whole thing is getting memcpy'd it seams impossible to avoid.
So is there a way to exclude it from the memcopy or do I have to solve this another way?
Re: Exclude DatablockMember from Shader Memcpy?
Posted: Tue Oct 20, 2015 4:03 am
by dark_sylinc
I do not understand.
YOU are in control of what gets memcpy'd.
uploadToConstBuffer is a pure virtual call. The HlmsPbsDatablock::uploadToConstBuffer decides to use memcpy. But you don't have to.
Example:
Code: Select all
void LightDatablock::uploadToConstBuffer( char *dstPtr )
{
float * RESTRICT_ALIAS asFloat = *dstPtr;
asFloat[0] = 1.0f; //Always send a constant
//Leave asFloat[1] uninitialized
asFloat[2] = this->mMyVariable;
//Write after asFloat[2]. COMPLETELY OPTIONAL
memcpy( dstPtr + sizeof(float)*3, &this->startOfVarsIWantToCopy, sizeBytes );
//Write more data
asFloat[25] = this->mMyOtherVariable;
}
Ogre doesn't memcpy for you. It's the overriden function that may use memcpy. Ogre's default implementations use memcpy because it's fast and convenient. But you're not forced to do that.
In fact the HlmsPbsDatablock has a lot of information that is not being sent to the shaders (like the UV source variables, the blending modes, the fresnel mode, the std::vector holding the textures, etc). It's only memcpy'ing a tiny portion that is needed by the shaders as a buffer.
Re: Exclude DatablockMember from Shader Memcpy?
Posted: Tue Oct 20, 2015 3:07 pm
by white_waluigi
Thanks a lot, I probably should have looked at the code more, sorry about that