Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

#ActualTape_Worm

Posted 11 March 2012 - 10:46 PM

So, just to present a reason why things are breaking so badly:

It turns out you can't use CopyResource in feature level 9.x when the source texture has a shader binding flag:

ID3D11DeviceContext::CopyResource
Feature Level Behavior Differences
D3D_FEATURE_LEVEL_9_1, D3D_FEATURE_LEVEL_9_2, D3D_FEATURE_LEVEL_9_3:
Only Texture2D and buffers may be copied within GPU-accessible memory.
Texture3D cannot be copied from GPU-accessible memory to CPU-accessible memory.
Any resource that has only D3D10_BIND_SHADER_RESOURCE cannot be copied from GPU-accessible memory to CPU-accessible memory.

And I guess the driver was not handling it well.  On the up side, I did get it working by copying into a rendertarget texture without a shader binding (which does limit the formats some), and then saved that with no issues.

As for the first part of the issue, well, I guess the D3DX functions aren't very friendly when it comes to saying it can't save a file format with specific texture formats.  My solution there was to just copy to a temporary R8G8B8A8_UNORM texture and save that instead.

Now, I do have one last question:
The solution for the feature level 9.x issue is not ideal.  Mostly because some formats can't be used as a render target.  So, I wondered if I could use CopyResource to copy it to an ID3D11Buffer?  And if this is indeed possible and since the buffer requires a size in bytes, how would I go about calculating the size of a texture in bytes (uncompressed)?  I could go through each mip level, get the width/height and multiply by the pitch and add each mip size together.  But if there's an easier way, I'd like to know what it is?

Thanks

#1Tape_Worm

Posted 11 March 2012 - 10:45 PM

So, just to present a reason why things are breaking so badly:

It turns out you can't use CopyResource in feature level 9.x when the source texture has a shader binding flag:

ID3D11DeviceContext::CopyResource
Feature Level Behavior Differences
D3D_FEATURE_LEVEL_9_1, D3D_FEATURE_LEVEL_9_2, D3D_FEATURE_LEVEL_9_3:
Only Texture2D and buffers may be copied within GPU-accessible memory.
Texture3D cannot be copied from GPU-accessible memory to CPU-accessible memory.
Any resource that has only D3D10_BIND_SHADER_RESOURCE cannot be copied from GPU-accessible memory to CPU-accessible memory.

And I guess the driver was not handling it well.  On the up side, I did get it working by copying into a rendertarget texture without a shader binding (which does limit the formats some), and then saved that with no issues.

As for the first part of the issue, well, I guess the D3DX functions aren't very friendly when it comes to saying it can't save a file format with specific texture formats.  My solution there was to just copy to a temporary R8G8B8A8_UNORM texture and save that instead.

Now, I do have one last question:
The solution for the feature level 9.x issue is not ideal.  Mostly because some formats can't be used as a render target.  So, I wondered if I could use CopyResource to copy it to an ID3D11Buffer?  And if this is indeed possible and since the buffer requires a size in bytes, how would I go about calculating the size of a texture in bytes (uncompressed)?  I could go through each mip level, get the width/height and multiply by the pitch and add each mip size together.  But if there's an easier way, I'd like to know what it is?

Thanks

PARTNERS