1// Copyright (c) 2020 Qualcomm Technologies Incorporated 2// 3// SPDX-License-Identifier: CC-BY-4.0 4 5[[copies-images-scaling-rotation]] 6=== Image Blits with Scaling and Rotation 7 8When slink:VkCopyCommandTransformInfoQCOM is in the pname:pNext chain of 9slink:VkImageBlit2KHR, the specified region is rotated during the blit. 10The following description of rotated addressing replaces the description in 11flink:vkCmdBlitImage. 12 13The following code computes rotation of normalized coordinates. 14 15[source,c] 16--------------------------------------------------- 17// rotation of normalized coordinates 18VkOffset2D RotateNormUV(VkOffset2D in, VkSurfaceTransformFlagBitsKHR flags) 19{ 20 VkOffset2D output; 21 switch (flags) 22 { 23 case VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR: 24 out.x = in.x; 25 out.y = in.y; 26 break; 27 case VK_SURFACE_TRANSFORM_ROTATE_90_BIT_KHR: 28 out.x = in.y; 29 out.y = 1.0 - in.x; 30 break; 31 case VK_SURFACE_TRANSFORM_ROTATE_180_BIT_KHR: 32 out.x = 1.0 - in.x; 33 out.y = 1.0 - in.y; 34 break; 35 case VK_SURFACE_TRANSFORM_ROTATE_270_BIT_KHR: 36 out.x = 1.0 - in.y; 37 out.y = in.x; 38 break; 39 } 40 return out; 41} 42 43--------------------------------------------------- 44 45 * For each destination texel, the integer coordinate of that texel is 46 converted to an unnormalized texture coordinate, using the effective 47 inverse of the equations described in 48 <<textures-unnormalized-to-integer, unnormalized to integer 49 conversion>>: 50 {empty}:: [eq]#u~base~ = i {plus} {onehalf}# 51 {empty}:: [eq]#v~base~ = j {plus} {onehalf}# 52 {empty}:: [eq]#w~base~ = k {plus} {onehalf}# 53 * These base coordinates are then offset by the first destination offset: 54 {empty}:: [eq]#u~offset~ = u~base~ - x~dst0~# 55 {empty}:: [eq]#v~offset~ = v~base~ - y~dst0~# 56 {empty}:: [eq]#w~offset~ = w~base~ - z~dst0~# 57 {empty}:: [eq]#a~offset~ = a - pname:baseArrayCount~dst~# 58 59 * The UV destination coordinates are scaled by the destination region, 60 rotated, and scaled by the source region. 61 {empty}:: [eq]#u~dest_scaled~ = u~offset~ / (x~dst1~ - x~dst0~)# 62 {empty}:: [eq]#v~dest_scaled~ = v~offset~ / (y~dst1~ - y~dst0~)# 63 {empty}:: [eq]#(u~src_scaled~, v~src_scaled~) = 64 code:RotateNormUV(u~dest_scaled~, v~dest_scaled~, 65 pname:transform)# 66 {empty}:: [eq]#u~scaled~ = u~src_scaled~ * (x~Src1~ - x~Src0~)# 67 {empty}:: [eq]#v~scaled~ = v~src_scaled~ * (y~Src1~ - y~Src0~)# 68 69 * The W coordinate is unaffected by rotation. 70 The scale is determined from the ratio of source and destination 71 regions, and applied to the offset coordinate: 72 {empty}:: [eq]#scale~w~ = (z~Src1~ - z~Src0~) / (z~dst1~ - z~dst0~)# 73 {empty}:: [eq]#w~scaled~ = w~offset~ * scale~w~# 74 75 76 * Finally the source offset is added to the scaled source coordinates, to 77 determine the final unnormalized coordinates used to sample from 78 pname:srcImage: 79 {empty}:: [eq]#u = u~scaled~ {plus} x~Src0~# 80 {empty}:: [eq]#v = v~scaled~ {plus} y~Src0~# 81 {empty}:: [eq]#w = w~scaled~ {plus} z~Src0~# 82 {empty}:: [eq]#q = pname:mipLevel# 83 {empty}:: [eq]#a = a~offset~ {plus} pname:baseArrayCount~src~# 84 85These coordinates are used to sample from the source image as described for 86<<textures, Image Operations>>, with the filter mode equal to that of 87pname:filter; a mipmap mode of ename:VK_SAMPLER_MIPMAP_MODE_NEAREST; and an 88address mode of ename:VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE. 89Implementations must: clamp at the edge of the source image, and may: 90additionally clamp to the edge of the source region. 91