#Texture does not display correctly in D3D11

19 messages · Page 1 of 1 (latest)

viral kraken
#

I create an image on the CPU of dimensions 33x33 and format R32F, and color it all white (1.f).

Every frame I upload that to the GPU via ID3D11DeviceContext::Map and then sample it in the shader, but I get this:

#

I expect it to be all white

#

If I create a 32x32 image, I get all white

#

Another interesting thing is that the buggy case appears fine in RenderDoc

#

(this is the first 33x33 case)

#

I may be violating something in the spec, but I'm not comfortable with D3D11 enough to know and find what :/

modest stag
#

Do you mind posting your code to fill the texture data after calling Map? Are you respecting the RowPitch that’s returned when calling Map?

humble gyro
#

Generally what this means is undefined behavior for future reference, you probably are not respecting a memory padding of some sort when copying data as MJP states

tough sapphire
viral kraken
#

I was just directly memcpy-ing the entire buffer into the mapped texture

#
memcpy(mapped_subresource.pData, density_field, SimulationResolution.x * SimulationResolution.y * sizeof(Real));
#

Now changed to

#
for (uint32_t y = 0; y < SimulationResolution.y; ++y)
{
    uint8_t* dst = reinterpret_cast<uint8_t*>(mapped_subresource.pData) + y * mapped_subresource.RowPitch;
    uint8_t* src = reinterpret_cast<uint8_t*>(density_field) + y * SimulationResolution.x * sizeof(Real);
    memcpy(dst, src, SimulationResolution.x * sizeof(Real));
}
#

and now it works perfectly

#

Thanks a ton

modest stag
#

Nice! Glad it’s working now.