• 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
jakovo

CopyResource Texture Format compatibility

7 posts in this topic

When Microsoft [url="http://msdn.microsoft.com/en-us/library/windows/desktop/ff476392(v=vs.85).aspx"]says[/url]:

[quote name='MSDN']
Must have compatible DXGI formats, which means the formats must be identical or at least from the same type group. For example, a DXGI_FORMAT_R32G32B32_FLOAT texture can be copied to an DXGI_FORMAT_R32G32B32_UINT texture since both of these formats are in the DXGI_FORMAT_R32G32B32_TYPELESS group.
[/quote]

how can I know which formats are compatible or in the same group?

I mean, since in the given example both formats are R32G32B32 but with different type, could also [b]DXGI_FORMAT_D32_FLOAT [/b]and [b]DXGI_FORMAT_R32_FLOAT [/b]be considered compatible or in the same group? (they are the same type, but one is D32 and the otherone R32).


if they are not, then how could I copy the contents of a DepthBuffer to a normal texture?

Thanks!
0

Share this post


Link to post
Share on other sites
[quote name='???' timestamp='1337964771' post='4943281']
When Microsoft [url="http://msdn.microsoft.com/en-us/library/windows/desktop/ff476392(v=vs.85).aspx"]says[/url]:

[quote name='MSDN']
Must have compatible DXGI formats, which means the formats must be identical or at least from the same type group. For example, a DXGI_FORMAT_R32G32B32_FLOAT texture can be copied to an DXGI_FORMAT_R32G32B32_UINT texture since both of these formats are in the DXGI_FORMAT_R32G32B32_TYPELESS group.
[/quote]

how can I know which formats are compatible or in the same group?

I mean, since in the given example both formats are R32G32B32 but with different type, could also [b]DXGI_FORMAT_D32_FLOAT [/b]and [b]DXGI_FORMAT_R32_FLOAT [/b]be considered compatible or in the same group? (they are the same type, but one is D32 and the otherone R32).


if they are not, then how could I copy the contents of a DepthBuffer to a normal texture?

Thanks!
[/quote]

What do you mean by copying depth buffer content to a "normal texture"?
A depth buffer is a texture2d with specific setup and a depthStencilView. (I assume you are using d3d10/11 from your post.) You can still have a shader resource view to sample the texture in your shaders. Or are you trying to do something different?
To answer your question though just have a look at the typeless formats in the dxgi_format list. The compatible format ones have the same format, only different interpretation of the data.
If ever you want to do something funkier, you can always copy the depth buffer in a shader by sampling it using it's shader resource view, and outputing to a rendertarget with your reinterpreted depth data. Can't think of many uses for that though.
1

Share this post


Link to post
Share on other sites
I would just try it and find out. If it doesn't work you can always do the copy manually by writing a simple pixel shader that samples the depth buffer as a texture and writes the result to the copy texture.
2

Share this post


Link to post
Share on other sites
Thanks [b]ATEFred[/b],

[quote name='ATEFred' timestamp='1337970529' post='4943306']
What do you mean by copying depth buffer content to a "normal texture"?
A depth buffer is a texture2d with specific setup and a depthStencilView. (I assume you are using d3d10/11 from your post.)
[/quote]

Yes, sorry... what I intended to say is to copy a depth buffer's contents into a non-depth-buffer.
(and yes, I'm using Dx11)

[quote name='ATEFred' timestamp='1337970529' post='4943306']
You can still have a shader resource view to sample the texture in your shaders. Or are you trying to do something different?
[/quote]

Basically, I want to read in the CPU the contents of the DepthBuffer, something like this:

[CODE]
// Create texture: DepthStencil | 2xMultiSampled | USAGE_DEFAULT
D3D11_TEXTURE2D_DESC descDepth;
descDepth.Width = 800;
descDepth.Height = 600;
descDepth.MipLevels = 1;
descDepth.ArraySize = 1;
descDepth.Format = DXGI_FORMAT_D32_FLOAT;
descDepth.SampleDesc.Count = 2;
descDepth.SampleDesc.Quality = 0;
descDepth.Usage = D3D11_USAGE_DEFAULT;
descDepth.BindFlags = D3D11_BIND_DEPTH_STENCIL;
descDepth.CPUAccessFlags = 0;
descDepth.MiscFlags = 0;
ID3D11Texture2D* pDepthStencil = nullptr;
m_pDevice->CreateTexture2D( &descDepth, NULL, &pDepthStencil );

// Create texture: R32 | SingleSampled | USAGE_DEFAULT
descDepth.SampleDesc.Count = 1;
descDepth.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
descDepth.Format = DXGI_FORMAT_R32_FLOAT;
ID3D11Texture2D* pTemp1 = nullptr;
m_pDevice->CreateTexture2D( &descDepth, NULL, &pTemp1 );

// Create texture: R32 | SingleSampled | USAGE_STAGING
descDepth.BindFlags = 0;
descDepth.Usage = D3D11_USAGE_STAGING;
descDepth.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
ID3D11Texture2D* pCPUReadable = nullptr;
m_pDevice->CreateTexture2D( &descDepth, NULL, &pCPUReadable );

// RENDER SOMETHING

// Src must be multisampled, Dst must be singlesampled and USAGE_DEFAULT
m_pDevice->ResolveSubresource( pTemp1, 0, pDepthStencil, 0, DXGI_FORMAT_R32_FLOAT );
// Both, Src & Dst, must be singlesampled or multisampled, must be compatible formats, have same Multisampling count and Qlty
m_pDevice->CopyResource( pCPUReadable, pTemp1 );

D3D11_MAPPED_SUBRESOURCE MappedResource;
m_pDevice->Map( pCPUReadable, 0, D3D11_MAP_READ, 0, &MappedResource );

[/CODE]

However, no matter what MappedResource.pData is always 0000000000000000000000000000000000000000000000000000000000000000......


[quote name='ATEFred' timestamp='1337970529' post='4943306']
If ever you want to do something funkier, you can always copy the depth buffer in a shader by sampling it using it's shader resource view, and outputing to a rendertarget with your reinterpreted depth data.
[/quote]

I'm trying to keep away from copying it in a shader as much as possible, in theory this should be working, but if there is no way to do it without using the shader then yes, I think I will have to do it that way.

[quote name='MJP' timestamp='1337977201' post='4943342']
I would just try it and find out
[/quote]

Thanks [b]MJP[/b], I tryed but it doesn't send any error (the destination only keeps as 0's)

Any ideas of what could I be missing?

Thanks!
0

Share this post


Link to post
Share on other sites
in theory (acording to MSDN's documentation) ResolveSubresource() does not restrict the change between [b]pDepthStencil[/b]'s [i]DXGI_FORMAT_D32_FLOAT[/i] to [b]pTemp1[/b]'s [i]DXGI_FORMAT_R32_FLOAT[/i].... so, by the time CopyResource() copies from [b]pTemp1[/b] to [b]pCPUReadable[/b] (which is also [i]DXGI_FORMAT_R32_FLOAT[/i]) there should be no problem (since CopyResource does restrict the copy to be some compatible format).

Unless.... in using ResolveSubresource() apply the same restrictions that on CopyResource().
0

Share this post


Link to post
Share on other sites
[url="http://msdn.microsoft.com/en-us/library/windows/desktop/ff471325%28v=vs.85%29.aspx"]This page[/url] explicitly calls out the formats that support multisample resolve, and D32_FLOAT is not one of them.
1

Share this post


Link to post
Share on other sites
Thanks [b]MJP[/b],

I can't read the table up to that column, but is good to know there is actually no way of doing it besides using a pixel shader.

Thanks!
0

Share this post


Link to post
Share on other sites
Oh yeah you're right, it's messed up for me too. I actually looked it up in the documentation that comes with the SDK, and then google'd for the MSDN link based on the title.
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