1
\$\begingroup\$

I'm having some trouble copying a subregion from a source texture (2D) to a destination texture.

Both textures are mipmapped 2D textures, with dimensions (at mip 0) of 512 x 32.

Rather than tell you about each parameter, it's easier to show you, according to the Visual Studio debugger, at the call site:

CopySubresourceRegion parameters

So, question 1: Is there anything wrong here that would cause CopySubresourceRegion to fail? There is nothing in the Debug window (the debug layer is enabled). The destination texture is a Staging resource with the CPU Read access flag.

If that seems okay to you, here's the rest of the question:

I'm making this call as part of a unit test, and attempting to read the data right out of the destination texture immediately after. If I replace the CopySubresourceRegion call with a CopyResource instead, the answer is wrong, but there is definitely data copied across. However, after making the call to CopySubresourceRegion and then using a Map/Read/Unmap chain, the data that comes back is all zeroes. The texel type is R32G32B32A32_FLOAT (or whatever it is).

I realise that the call is made asynchronously, so I added the following code between the copy and the read:

for (UINT i = 0U; i < numDeferredContexts; ++i) {
    CHECK_CALL(deferredContextPtrArr[i]->FinishCommandList(FALSE, &outCommandList));
    immediateContextPtr->ExecuteCommandList(outCommandList, FALSE);
}

And still, all zeroes. So I went one further, and changed it to the following (desperate) code:

for (UINT i = 0U; i < numDeferredContexts; ++i) {
    deferredContextPtrArr[i]->Flush();
    CHECK_CALL(deferredContextPtrArr[i]->FinishCommandList(FALSE, &outCommandList));
    immediateContextPtr->ExecuteCommandList(outCommandList, FALSE);
}
immediateContextPtr->Flush();
Sleep(10000);

But still nothing. Finally, I turned off the multithreaded rendering so it all executes on the immediate context, but even then, still zeroes.

So I'm totally stuck, and any ideas are appreciated: How can I make CopySubresourceRegion actually copy the data?

\$\endgroup\$
  • 1
    \$\begingroup\$ The doc page says in the Remarks section that for the operation to work, "source and destination resources may not be currently mapped". Also it says that your resource should not be multisampled. Does it fulfill both criteria? \$\endgroup\$ – Babis Nov 13 '14 at 8:07
  • \$\begingroup\$ @Babis Yes, both those criteria are fulfilled (the unit test doesn't share the resources with anyone). I'm getting close to fixing it, actually, I'm starting to play with parameters and getting different data. I'll post an answer if I figure it out. \$\endgroup\$ – Xenoprimate Nov 13 '14 at 10:07
1
\$\begingroup\$

False alarm, my apologies. I was passing the number of texels to the initial data struct's row-stride field, rather than the number of bytes.

By pure unlucky coincedence, the other unit tests I had on this area were using single-element 8-bit texel formats, which meant I was getting really lucky (as the texel count and the byte count were the same).

Thanks for your time anyway.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.