[D3D12] Use a rectangular subset of a texture ?

Started by
2 comments, last by Matias Goldberg 8 years, 4 months ago

Since D3D12 gives us a finer grained access to memory I wonder if it's possible to reinterpret a part of a texture as a new texture without copying it.

For instance if I have a 1024 x 1024 render target, is it possible to create a resource view out of the 512x512 left hand lower corner out of it without using a texture copy operation ? Or any arbitrary 512 x 512 pixel windows ?

I didn't find any obvious way to create such a texture view in d3d12 api. I know textures may be stored in a tiled/swizzled way for performance reasons and in such way it's impossible to get a texture out of another one by carefully choosing offset and pitch. On the other hand d3d12 texture may be created with the "layout row major" flag which description is available here :

https://msdn.microsoft.com/en-us/library/windows/desktop/dn770442(v=vs.85).aspx

but even with a well defined texture layout I'm not sure the API allows to reinterpret texture data in 2 different ways.

To be honest I didn't test with D3D12 Heap and texture aliasing functions at the moment.

Advertisement

In short, no, not without making use of the Tiled Resources functionality.

In textures that are Tiled Resources subsections of the textures (tiles) have a fixed size in the region of 64x64 to 128x128 depending on pixel format. In theory you could create a new, smaller texture that references all the same tiles as another texture achieving your goal of not using any more memory that the original much larger texture.

The drawbacks would be the fact that the sub-rectangle would need to be a multiple of the tile size and 2D Tiled Resources aren't guaranteed to be supported unless the device supports Feature Level 12_0.

Generally this sort of thing is just achieved by scaling and offsetting texture coordinates into the correct location. You do lose the ability to do things like Wrap/Clamp/Mirror addressing and you might start getting some bleeding from unwanted texels as you head down the mip chain, but it suits most people's need for doing what you describe.

Adam Miles - Principal Software Development Engineer - Microsoft Xbox Advanced Technology Group

Or any arbitrary 512 x 512 pixel windows

Arbitrary - no. Constraints such as alignment will always pose a problem to an arbitrary/generic solution.
If D3D12 lets you arbitrarily supply the pitch of a "layout row major" texture (I'm not sure if it does), then yes, you could alias some specific subset of "windows" within the texture.

I didn't find any obvious way to create such a texture view in d3d12 api

"Placed resources"

For instance if I have a 1024 x 1024 render target, is it possible to create a resource view out of the 512x512 left hand lower corner out of it without using a texture copy operation ? Or any arbitrary 512 x 512 pixel windows ?

The others have explained it very well.
I just want to add is that the reason for this is that textures aren't internally stored as a contiguous array. Usually the data is scrambled for more efficient cache access and faster filtering.

It's probably possible to hack away and end up reinterpret casting a texture to a different resolution, but you will end up with garbage rather than a coherent subsection of the original image.

This topic is closed to new replies.

Advertisement