BUG: shared param float arrays don't work in D3D

Discussion area about developing or extending OGRE, adding plugins for it or building applications on it. No newbie questions please, use the Help forum for that.
User avatar
lunkhound
Gremlin
Posts: 169
Joined: Sun Apr 29, 2012 1:03 am
Location: Santa Monica, California
x 19

BUG: shared param float arrays don't work in D3D

Post by lunkhound »

I just found out why my arrays of floats in my shared params aren't working, but arrays of float4 are.

in OgreGpuProgramParams.cpp, method GpuSharedParametersUsage::_copySharedParamsToTargetParams()

Code: Select all

...
   // target params may be padded to 4 elements, shared params are packed
   assert(e.dstDefinition->elementSize % 4 == 0);
   size_t iterations = e.dstDefinition->elementSize / 4
               * e.dstDefinition->arraySize;
   assert(iterations > 0);
   size_t valsPerIteration = e.srcDefinition->elementSize / iterations;  // <-- BUG, valsPerIteration computes to zero
   for (size_t l = 0; l < iterations; ++l)
   {
      memcpy(pDst, pSrc, sizeof(float) * valsPerIteration);
      pSrc += valsPerIteration;
      pDst += 4;
   }
In D3D (and maybe other cases too) the code is trying to pad each element of my array to a multiple of 4 floats. In my example, the element size is 1, and iterations is 4, so valsPerIteration = 1 / 4 = ZERO. So nothing is copied and my shader gets no data.
Clearly, division by iterations is a mistake here. I will put up a patch.
User avatar
lunkhound
Gremlin
Posts: 169
Joined: Sun Apr 29, 2012 1:03 am
Location: Santa Monica, California
x 19

Re: BUG: shared param float arrays don't work in D3D

Post by lunkhound »

The fix worked. My shaders are now getting data. Patch posted on sourceforge (3563552).

[edit] Hmm. Just noticed that the same bug is repeated later in the same function. It looks like "int" arrays are also broken.