1// Copyright (c) 2020 Qualcomm Technologies Incorporated 2// 3// SPDX-License-Identifier: CC-BY-4.0 4 5 6[[copies-buffers-images-rotation-addressing]] 7=== Buffer and Image Addressing with Rotation 8 9When slink:VkCopyCommandTransformInfoQCOM is in the pname:pNext chain of 10slink:VkBufferImageCopy2KHR, a _rotated copy_ is specified. 11For both flink:vkCmdCopyImageToBuffer2KHR and 12flink:vkCmdCopyBufferToImage2KHR, a rotation is applied to the region used 13for image accesses, but a non-rotated region is used for buffer accesses. 14In the case of rotated flink:vkCmdCopyImageToBuffer2KHR, the source image 15region is rotated. 16In the case of rotated flink:vkCmdCopyBufferToImage2KHR, the destination 17image region is rotated. 18 19For a _rotated copy_, the following description of rotated addressing 20replaces the description in <<copies-buffers-images-addressing,Buffer and 21Image Addressing>>. 22 23The following code computes rotation of unnormalized coordinates. 24[source,c] 25--------------------------------------------------- 26// Forward rotation of unnormalized coordinates 27VkOffset2D RotateUV(VkOffset2D in, VkSurfaceTransformFlagBitsKHR flags) 28{ 29 VkOffset2D output; 30 switch (flags) 31 { 32 case VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR: 33 out.x = in.x; 34 out.y = in.y; 35 break; 36 case VK_SURFACE_TRANSFORM_ROTATE_90_BIT_KHR: 37 out.x = -in.y; 38 out.y = in.x; 39 break; 40 case VK_SURFACE_TRANSFORM_ROTATE_180_BIT_KHR: 41 out.x = -in.x; 42 out.y = -in.y; 43 break; 44 case VK_SURFACE_TRANSFORM_ROTATE_270_BIT_KHR: 45 out.x = in.y; 46 out.y = -in.x; 47 break; 48 } 49 return out; 50} 51--------------------------------------------------- 52 53Pseudocode for image/buffer addressing of uncompressed formats with rotation 54is: 55 56[source,c] 57--------------------------------------------------- 58rowLength = region->bufferRowLength; 59if (rowLength == 0) 60 rowLength = region->imageExtent.width; 61 62imageHeight = region->bufferImageHeight; 63if (imageHeight == 0) 64 imageHeight = region->imageExtent.height; 65 66texelBlockSize = <texel block size of the format of the src/dstImage>; 67 68// Buffer addressing is unaffected by rotation: 69address of (x,y,z) = region->bufferOffset + (((z * imageHeight) + y) * rowLength + x) * texelBlockSize; 70 71// When copying from buffer to image, the source buffer coordinates x,y,z range from (0,0,0) to 72// region->imageExtent.{width,height,depth}. The source extent is rotated by the specified 73// VK_SURFACE_TRANSFORM, centered on the imageOffset, to define a rotated destination region. 74// For each source buffer texel with coordinates (x,y) the rotated destination image texel has 75// coordinates (x',y') defined as: 76(x',y')= RotateUV(x,y) + ImageOffset.{x,y} 77 78// When copying from image to buffer, the the destination buffer coordinates x,y,z range from (0,0,0) to 79// region->imageExtent.{width,height,depth}. The destination extent is rotated by the specified 80// VK_SURFACE_TRANSFORM, centered on the imageOffset, to define a rotated source region. For each destination 81// buffer texel with coordinates (x,y) the rotated source image texel has coordinates (x',y') defined as: 82(x',y')= RotateUV(x,y) + ImageOffset.{x,y} 83 84--------------------------------------------------- 85 86Note that pname:imageOffset does not affect addressing calculations for 87buffer memory. 88Instead, pname:bufferOffset can: be used to select the starting address in 89buffer memory. 90