AMD APU 6520g fails on texture map from size

Started by
3 comments, last by Nik02 11 years, 7 months ago
i have a texture of some random size, usually a base 2 but recently i have had to accommodate random sizes like 128x455 instead of 128x512. in the hardware it wants some multiple of 32 or else it will wrap around and mess up the image so i rearranged the sizing


the texture is still only xsize*ysize (ie 128 x 455)

newtdesc.Width = xsize;
newtdesc.Height = ysize;
...
pTexture = new SlimDX.Direct3D10.Texture2D(g_pd3dDevice, newtdesc);


i map the texture and fill with new data like normal but if i am using the actual size of the texture on the new data it will wrap when it is not a 32 multiple


DataRectangle mappedTex = null;
mappedTex = pTexture.Map(0, D3D10.MapMode.WriteDiscard, D3D10.MapFlags.None);
mappedTex.Data.WriteRange<byte>(NewData);
pTexture.Unmap(0);



so i have to pad the new data with zeros to get the multiple of 32 for the total new data size even though the texture is smaller

int texsizefix = ysize + (32 - (ysize % 32));
Byte[] NewData = new Byte[(int)((texsizefix * xsize) * 4)]; // * 4 due to r8g8b8a8

(ie 128x480 zero padded on each line)


so now this all works fine on several cards, im running a gtx 460m, a gtx 560m, and an amd 6750m but now i picked up a bottom end amd apu with a 6520g integrated gpu and it will not work, it gives me an 'attempted to read past the end of stream' error from this size difference between the texture and the NewData on the map instruction. i tried upgrading drivers and slimdx/directx versions etc but nothing seems to change it. i know i am being a little lazy about it in that i could force all the textures to be some multiple of 32 and handle some stretching in the shaders/vertex mapping but it will set me back significantly if i have to recalculate everything involved with that. am i missing something obvious that fixes the wrapping bug in slimdx/directx or is this just an issue with the new chips not having mature enough drivers to handle this.
Advertisement
I'm not super-familiar with SlimDX so I wouldn't know for sure, but perhaps you need to account for the pitch of the mapped texture when writing the new data? This is what you normally have to do in native DX. The pitch will change for different hardware/drivers, so it would account for the strange behavior you're experiencing. There shouldn't be any limitations regarding power-of-2 textures or dimensions being a multiple of 32, so I'm thinking that was the same problem.
Yes, the returned DataRectangle object will tell you the pitch so that you don't have to guess at the amount of padding, like you're currently doing. Take that into account when writing the data and you should be good.
Mike Popoloski | Journal | SlimDX
ok cool i moved texsizefix to a global and plugged this in everywhere i change the dimensions of the texture, to try and minimize the locking time on the texture resource, and it works great.

DataRectangle tempTex = null;
tempTex = pTexture.Map(0, D3D10.MapMode.WriteDiscard, D3D10.MapFlags.None);
pTexture.Unmap(0);
texsizefix = tempTex.Pitch / 4; // div by 4 as the returned value is for r8g8b8a8


thanks guys
The pitch could be potentially different every time you map the resource. This is because the driver can relocate the physical memory for the resource when it deems it necessary. To your application, this is a completely transparent operation.

GPU resource virtualization - as implemented in DXGI - can cause very frequent physical GPU memory relocations.

If you map a resource for writing, it is generally not the map/unmap operation itself that causes performance loss. The true reason for performance drop is usually the fact that the GPU may have to wait for access to the resource, if it is - for example - used in a rendering operation at the same time. Of course, large copies will also consume bus bandwidth, which is a separate potential performance hog.

Niko Suni

This topic is closed to new replies.

Advertisement