• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
carkey

CopySubresourceRegion copying wrong part on some devices

8 posts in this topic

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.

 

0

Share this post


Link to post
Share on other sites

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.

2

Share this post


Link to post
Share on other sites

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.

0

Share this post


Link to post
Share on other sites
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
0

Share this post


Link to post
Share on other sites

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!

0

Share this post


Link to post
Share on other sites

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?

0

Share this post


Link to post
Share on other sites

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
0

Share this post


Link to post
Share on other sites

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
0

Share this post


Link to post
Share on other sites


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.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0