November 26, 2019 10:24 PM, "Henri Verbeet" hverbeet@gmail.com wrote:
On Tue, 26 Nov 2019 at 15:04, Conor McCarthy cmccarthy@codeweavers.com wrote:
How about this: estimated_size = (desc->Height / format->block_height) * (desc->Width / format->block_width)
- format->byte_count * format->block_byte_count;
That will result in a 0 estimated size for textures with any dimension smaller than the block size. That would be fine for e.g. a 1x1 texture since the total size would be smaller than D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT anyway, but note that that would also affect textures that are e.g. very wide but only 1 pixel tall.
When I was messing with this in Windows I think a resource was invalid if any dimension was not aligned with the block size in that dimension. I didn't check tiny dimensions, or if 1D textures are valid at all with a compressed format. I'll test all of these. But in any case the following should work. With dimension limits there's no chance of overflow.
estimated_size = desc->Width * desc->Height * format->byte_count * format->block_byte_count / (format->block_width * format->block_height);