Jump to content
  • Advertisement
Sign in to follow this  
Tape_Worm

DX11 [SharpDX] Error saving a 2D texture to a stream/file.

This topic is 2464 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm getting an odd exception (HRESULT 0x80004005, and the debug info isn't telling me anything at all) whenever I try and persist a 2D texture to a stream or file. It works if I use a DXGI_FORMAT_R8G8B8A8_UNORM format, but if I use DXGI_FORMAT_B8G8R8X8_UNORM it gives me an error. Internally, SharpDX is using D3DX11SaveTextureToMemory to copy the data into a (what I assume is a) D3D10BLOB. I usually save my files to a FileStream object when sending to disk, but that's failing too. FYI, this is using downlevel feature levels for D3D9 cards and D3D10.1 (no idea if D3D 10.0 or 11.0 works or not).

Is there some known incompatibility with D3DX11SaveTextureToMemory and specific formats?

Share this post


Link to post
Share on other sites
Advertisement
So, a little more info:
It works if I use DDS instead of PNG. I guess that's somewhat understandable since PNG doesn't natively use that format.

Share this post


Link to post
Share on other sites
This looks to be a driver issue (ATI 4550 running Catalyst 12.1 if you're wondering). If I use the reference rasterizer, everything works as it should.

Share this post


Link to post
Share on other sites

This looks to be a driver issue (ATI 4550 running Catalyst 12.1 if you're wondering). If I use the reference rasterizer, everything works as it should.


OK, scratch that, the reference rasterizer is giving me the same error (HRESULT 0x80004005 with no debug info from D3D11).

So, on feature level 11, 10.1, 10, 9.3 I get that error when I do the following (in hardware and ref rast):
1. Create a texture with a format that isn't DXGI_FORMAT_R8G8B8A8_UNORM (I used DXGI_FORMAT_B8G8R8X8_UNORM, and several other formats).
2. Save as PNG to memory with D3DX11SaveTextureToMemory (saving to a file with D3DX11SaveTextureToFile does not work either).

On feature level 9.3, things get weirder. I try and save a regular DXGI_FORMAT_R8G8B8A8_UNORM format texture and I get this:
D3D11: INFO: Create Texture2D: Name="unnamed", Addr=0x06F6D58C, ExtRef=1, IntRef=0 [ STATE_CREATION INFO #2097234: CREATE_TEXTURE2D ]
D3D11: Removing Device.
D3D11: WARNING: ID3D11Device::RemoveDevice: Device removal has been triggered for the following reason (DXGI_ERROR_DRIVER_INTERNAL_ERROR: There is strong evidence that the driver has performed an undefined operation; but it may be because the application performed an illegal or undefined operation to begin with.). [ EXECUTION WARNING #379: DEVICE_REMOVAL_PROCESS_POSSIBLY_AT_FAULT ]
D3D11: ERROR: ID3D11DeviceContext::Map: Returning DXGI_ERROR_DEVICE_REMOVED, when a Resource was trying to be mapped with READ or READWRITE. [ RESOURCE_MANIPULATION ERROR #2097214: RESOURCE_MAP_DEVICEREMOVED_RETURN ]
D3D11: INFO: Destroy Texture2D: Name="D3DX11SaveTexture Staging Texture Temporary", Addr=0x06F6D58C [ STATE_CREATION INFO #2097236: DESTROY_TEXTURE2D ]
A first chance exception of type 'SharpDX.SharpDXException' occurred in SharpDX.dll[/quote]
This happens only in hardware, in ref rast it works just as it should.

Help? Please?

Share this post


Link to post
Share on other sites
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.
[/quote]
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!