Jump to content

  • Log In with Google      Sign In   
  • Create Account

CopySubresourceRegion copying wrong part on some devices


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
8 replies to this topic

#1 carkey   Members   -  Reputation: 106

Like
0Likes
Like

Posted 17 September 2013 - 04:01 AM

I'm working on a project when I want to use GPU picking, basically it's all set up fine, assigning unique colors to objects etc. but my current problem is that when creating the 1x1 texture, it doesn't do this where the pointer is for some reason, but about -250 pixels in the x and y.

I start by rendering the scene to my own ID3D11RenderTargetView and then use GetResource() to copy this buffer data to a ID3D11Resource.

 

This all works fine and I know it is capturing it correctly because I'm using the DirectXTK function SaveWICTextureToFile() to save off this resource to a PNG - which I can open on the desktop and it looks fine.

 

I then create a D3D11_TEXTURE2D_DESC of height 1px and width 1px and call CreateTexture2D() to create this texture.

I then create a D3D11_BOX whose left is at mouse position X and top is at mouse position Y and whose width and height are both 1.

I then call CopySubresourceRegion() like so:

 

CopySubresourceRegion(texture1x1, 0, 0, 0, 0, textureFromRenderTargetView, 0, box1x1);

 

I then look at the pixel RGBA value but it's always wrong.

 

I thought I might be able to debug it by creating a larger texture and seeing where it thinks the "mouse pointer" is:

So I changed box to be 200x200 pixels rather than 1x1 and use the DirectXTK function to save it to a PNG.

 

If I compare the original buffer texture PNG and the new 200x200 PNG there is something weird going on. The 200x200's top left corner is nowhere near where the mouse point is, it is about -250 in the X and Y axes. And even weirder, the 200x200 image seems like it has been scaled up, when I overlay it onto the original buffer texture PNG the objects are definitely larger.

Does anyone know what is going on here and what I can do to solve it?

 

Below is my D3D11_TEXTURE2D_DESC I use for the 1x1 texture and also its D3D11_SUBRESOURCE_DATA:

 

 

D3D11_TEXTURE2D_DESC desc;

desc.Width = 1;
desc.Height = 1;
desc.MipLevels = 1;
desc.ArraySize = 1;
desc.SampleDesc.Count = 1;
desc.SampleDesc.Quality = 0;
desc.Usage = D3D11_USAGE_STAGING;
desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
desc.BindFlags = 0;
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
desc.MiscFlags = 0;

D3D11_SUBRESOURCE_DATA subData;
float buff[4] = {0,0,0,0};
subData.pSysMem = (void *)buff;
subData.SysMemPitch = 4;
subData.SysMemSlicePitch = 4;

device->CreateTexture2D(&tdesc, &subData, &texture1x1);

 

I then create the box to have a 1 pixel height and width, starting at the pointer position.

 

The strange thing is, this works fine on some devices but not others. When on my desktop and laptop it works fine but on my tablet (windows) it does this strange 200pixels off thing. Could it be something to do with resolution or something?

 

I really can't work out what's going on on this one particular device (which is the target device).

Any ideas?

 

Thanks for your time.

 

P.S. disclaimer: this is a cross-post from stackoverflow but I put that question up a week ago and have had no response so I thought I'd try here.

 



Sponsor:

#2 mhagain   Crossbones+   -  Reputation: 8001

Like
2Likes
Like

Posted 17 September 2013 - 05:10 AM

The cause of this almost definitely seems to be in how you're creating your box, i.e. getting the x and y values for that, rather than anything to do with CopySubresourceRegion.  The fact that it gives different results on a tablet, which will have a different input mechanism, definitely supports this guess.

 

Have you a way of printing the x and y to screen while you're using the program?  Also, when creating the box, be sure that you don't forget to set front 0 and back 1.


It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#3 carkey   Members   -  Reputation: 106

Like
0Likes
Like

Posted 17 September 2013 - 07:47 AM

Hi,

 

I have also tried it on another windows tablet now and it works on that tablet so now I'm even more confused!

 

I have been printing out the cursor/pointer x/y positions as well as the box coordinates.

 

I can't see any significant difference in the two at all. The thing is, if I touch the screen about 250px (in x and y) from where I want it to hit, it will hit there, so other than it being the cursor position problem (and I can't see how it can be this at this point) I'm thinking it's maybe a problem when I create the texture from the buffer, maybe I'm creating the 'screenshot' of the render too big so it is scaled in the x and y (meaning its about 250px away), is this possible that it would do it on one device and not another?

 

Thanks.



#4 unbird   Crossbones+   -  Reputation: 5090

Like
0Likes
Like

Posted 17 September 2013 - 09:29 AM

Yeah, definitively sounds like some size or offset mismatch. To locate such bugs dump every rectangle/coords in question online or to a log-file: swapchain and/or texture dimensions, windows position and client area, mouse coords etc. Drawing the mouse manually with some sprite, making a Windows PrintScreen screenshot and analyzing images in a image editor to compare coordinates helps, too.

Edit: Though I consider it unlikely it could be a driver issue, actually. Either use the reference rasterizer (D3D_DRIVER_TYPE_REFERENCE) on the problematic hardware (will need D3D SDK installation) or - if possible - D3D_DRIVER_TYPE_WARP. The latter won't need a SDK install but depending on what D3D11.x you're using, you won't have the full D3D 11 feature set. If it works with either of these driver types, then the driver on the target hardware is bad.

Edited by unbird, 17 September 2013 - 09:42 AM.


#5 carkey   Members   -  Reputation: 106

Like
0Likes
Like

Posted 17 September 2013 - 09:47 AM

Okay I'll have a go at doing some more debugging.

The thing is I remember it working on this device a few months ago when I first added GPU picking. I've added a lot of other stuff since then but haven't touched the GPU picking class so I really don't know what has happened to make it not work on this device...but I'll keep digging thanks!



#6 carkey   Members   -  Reputation: 106

Like
0Likes
Like

Posted 17 September 2013 - 12:02 PM

Edit: Though I consider it unlikely it could be a driver issue, actually. Either use the reference rasterizer (D3D_DRIVER_TYPE_REFERENCE) on the problematic hardware (will need D3D SDK installation) or - if possible - D3D_DRIVER_TYPE_WARP. The latter won't need a SDK install but depending on what D3D11.x you're using, you won't have the full D3D 11 feature set. If it works with either of these driver types, then the driver on the target hardware is bad.

 

I don't really understand how to do what you're saying here, is it a simple thing to set up?



#7 carkey   Members   -  Reputation: 106

Like
0Likes
Like

Posted 17 September 2013 - 12:26 PM

Ah! I think I'm part way to finding the problem, I'm printing the pointer position out and:

 

My desktop is 1920x1080 and if I move the cursor all the way to the bottom right of the screen it's saying its position is 1920x1080.

 

The tablet that works is 1366x768 and if I go to the bottom right it says its position is 1366x768.

 

Now on the tablet that isn't working: it is also 1920x1080 but if I move the pointer to the bottom right...it says it is 1366x768.

 

So there is something strange going on here where the DirectX DXSwapChain is 1920x1080 (as I get a 1920x1080 screenshot if I use the DirectXTK SaveWic...() function) but the actual windows app itself thinks that it is 1366x768.

 

Does anyone with windows store app experience know how this could have happened? Why does the pointer think its range is only 1366x768?

 

Thanks for your time and the help so far!

 

Edit: I've just taken a print screen on the 1920x1080 device and it saves as a 1920x1080 png...so the app thinks it's 1920x1080, directx thinks it is 1920x1080 but the pointer framework/library thinks it is 1366x768 (which the other tablet is but my desktop isn't).


Edited by carkey, 17 September 2013 - 12:29 PM.


#8 unbird   Crossbones+   -  Reputation: 5090

Like
0Likes
Like

Posted 17 September 2013 - 12:59 PM

I don't really understand how to do what you're saying here, is it a simple thing to set up?


It's a flag in the device creation call (D3D11CreateDevice, DriverType parameter). Play with them on your developer machine.. Just know it can be really slow since all rendering is done on the CPU now.
 

So there is something strange going on here where the DirectX DXSwapChain is 1920x1080 (as I get a 1920x1080 screenshot if I use the DirectXTK SaveWic...() function) but the actual windows app itself thinks that it is 1366x768.

Does anyone with windows store app experience know how this could have happened? Why does the pointer think its range is only 1366x768?


Never worked with tablets (Edit: sounds like some virtual desktop or something). For anyone who has you still need to give more clues. How do you determine the windows/desktop/backbuffer size, i.e. what function call do you use ? Also how do you grab the pointer coordinates ?

 

And another edit: Do you setup the device in fullscreen mode ? I also wonder if the pointer coordinates do have the higher resolution - hardware-wise. 


Edited by unbird, 17 September 2013 - 01:18 PM.


#9 carkey   Members   -  Reputation: 106

Like
0Likes
Like

Posted 17 September 2013 - 01:50 PM


Never worked with tablets (Edit: sounds like some virtual desktop or something). For anyone who has you still need to give more clues. How do you determine the windows/desktop/backbuffer size, i.e. what function call do you use ? Also how do you grab the pointer coordinates ?



And another edit: Do you setup the device in fullscreen mode ? I also wonder if the pointer coordinates do have the higher resolution - hardware-wise.

 

It is a windows store app (metro) so windows is supposed to handle all that. Windows decides that this device is this resolution, this other device is another resolution etc.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS