1e5c31af7Sopenharmony_ci// Copyright 2015-2024 The Khronos Group Inc. 2e5c31af7Sopenharmony_ci// 3e5c31af7Sopenharmony_ci// SPDX-License-Identifier: CC-BY-4.0 4e5c31af7Sopenharmony_ci 5e5c31af7Sopenharmony_ci[[textures]] 6e5c31af7Sopenharmony_ci= Image Operations 7e5c31af7Sopenharmony_ci 8e5c31af7Sopenharmony_ci 9e5c31af7Sopenharmony_ci== Image Operations Overview 10e5c31af7Sopenharmony_ci 11e5c31af7Sopenharmony_ciVulkan Image Operations are operations performed by those SPIR-V Image 12e5c31af7Sopenharmony_ciInstructions which take an code:OpTypeImage (representing a 13e5c31af7Sopenharmony_cisname:VkImageView) or code:OpTypeSampledImage (representing a 14e5c31af7Sopenharmony_ci(sname:VkImageView, sname:VkSampler) pair). 15e5c31af7Sopenharmony_ciRead, write, and atomic operations also take texel coordinates as operands, 16e5c31af7Sopenharmony_ciand return a value based on a neighborhood of texture elements (_texels_) 17e5c31af7Sopenharmony_ciwithin the image. 18e5c31af7Sopenharmony_ciQuery operations return properties of the bound image or of the lookup 19e5c31af7Sopenharmony_ciitself. 20e5c31af7Sopenharmony_ciThe "`Depth`" operand of code:OpTypeImage is ignored. 21e5c31af7Sopenharmony_ci 22e5c31af7Sopenharmony_ci[NOTE] 23e5c31af7Sopenharmony_ci.Note 24e5c31af7Sopenharmony_ci==== 25e5c31af7Sopenharmony_ciTexel is a term which is a combination of the words texture and element. 26e5c31af7Sopenharmony_ciEarly interactive computer graphics supported texture operations on 27e5c31af7Sopenharmony_citextures, a small subset of the image operations on images described here. 28e5c31af7Sopenharmony_ciThe discrete samples remain essentially equivalent, however, so we retain 29e5c31af7Sopenharmony_cithe historical term texel to refer to them. 30e5c31af7Sopenharmony_ci==== 31e5c31af7Sopenharmony_ci 32e5c31af7Sopenharmony_ciImage Operations include the functionality of the following SPIR-V Image 33e5c31af7Sopenharmony_ciInstructions: 34e5c31af7Sopenharmony_ci 35e5c31af7Sopenharmony_ci * code:OpImageSample* and code:OpImageSparseSample* read one or more 36e5c31af7Sopenharmony_ci neighboring texels of the image, and <<textures-texel-filtering,filter>> 37e5c31af7Sopenharmony_ci the texel values based on the state of the sampler. 38e5c31af7Sopenharmony_ci ** Instructions with code:ImplicitLod in the name 39e5c31af7Sopenharmony_ci <<textures-level-of-detail-operation,determine>> the LOD used in the 40e5c31af7Sopenharmony_ci sampling operation based on the coordinates used in neighboring 41e5c31af7Sopenharmony_ci fragments. 42e5c31af7Sopenharmony_ci ** Instructions with code:ExplicitLod in the name 43e5c31af7Sopenharmony_ci <<textures-level-of-detail-operation,determine>> the LOD used in the 44e5c31af7Sopenharmony_ci sampling operation based on additional coordinates. 45e5c31af7Sopenharmony_ci ** Instructions with code:Proj in the name apply homogeneous 46e5c31af7Sopenharmony_ci <<textures-projection,projection>> to the coordinates. 47e5c31af7Sopenharmony_ci * code:OpImageFetch and code:OpImageSparseFetch return a single texel of 48e5c31af7Sopenharmony_ci the image. 49e5c31af7Sopenharmony_ci No sampler is used. 50e5c31af7Sopenharmony_ci * code:OpImage*Gather and code:OpImageSparse*Gather read neighboring 51e5c31af7Sopenharmony_ci texels and <<textures-gather,return a single component>> of each. 52e5c31af7Sopenharmony_ci * code:OpImageRead (and code:OpImageSparseRead) and code:OpImageWrite read 53e5c31af7Sopenharmony_ci and write, respectively, a texel in the image. 54e5c31af7Sopenharmony_ci No sampler is used. 55e5c31af7Sopenharmony_ciifdef::VK_NV_shader_image_footprint[] 56e5c31af7Sopenharmony_ci * code:OpImageSampleFootprintNV identifies and returns information about 57e5c31af7Sopenharmony_ci the set of texels in the image that would be accessed by an equivalent 58e5c31af7Sopenharmony_ci code:OpImageSample* instruction. 59e5c31af7Sopenharmony_ciendif::VK_NV_shader_image_footprint[] 60e5c31af7Sopenharmony_ci * code:OpImage*Dref* instructions apply 61e5c31af7Sopenharmony_ci <<textures-depth-compare-operation,depth comparison>> on the texel 62e5c31af7Sopenharmony_ci values. 63e5c31af7Sopenharmony_ci * code:OpImageSparse* instructions additionally return a 64e5c31af7Sopenharmony_ci <<textures-sparse-residency,sparse residency>> code. 65e5c31af7Sopenharmony_ci * code:OpImageQuerySize, code:OpImageQuerySizeLod, 66e5c31af7Sopenharmony_ci code:OpImageQueryLevels, and code:OpImageQuerySamples return properties 67e5c31af7Sopenharmony_ci of the image descriptor that would be accessed. 68e5c31af7Sopenharmony_ci The image itself is not accessed. 69e5c31af7Sopenharmony_ci * code:OpImageQueryLod returns the LOD parameters that would be used in a 70e5c31af7Sopenharmony_ci sample operation. 71e5c31af7Sopenharmony_ci The actual operation is not performed. 72e5c31af7Sopenharmony_ciifdef::VK_QCOM_image_processing[] 73e5c31af7Sopenharmony_ci * code:OpImageWeightedSampleQCOM reads a 2D neighborhood of texels and 74e5c31af7Sopenharmony_ci computes a weighted average using weight values from a separate weight 75e5c31af7Sopenharmony_ci texture. 76e5c31af7Sopenharmony_ci * code:opImageBlockMatchSADQCOM and code:opTextureBlockMatchSSD compare 2D 77e5c31af7Sopenharmony_ci neighborhoods of texels from two textures. 78e5c31af7Sopenharmony_ci * code:OpImageBoxFilterQCOM reads a 2D neighborhood of texels and computes 79e5c31af7Sopenharmony_ci a weighted average of the texels. 80e5c31af7Sopenharmony_ciendif::VK_QCOM_image_processing[] 81e5c31af7Sopenharmony_ciifdef::VK_QCOM_image_processing2[] 82e5c31af7Sopenharmony_ci * code:opImageBlockMatchWindowSADQCOM and 83e5c31af7Sopenharmony_ci code:opImageBlockMatchWindowSSDQCOM compare 2D neighborhoods of texels 84e5c31af7Sopenharmony_ci from two textures with the comparison repeated across a window region in 85e5c31af7Sopenharmony_ci the target texture. 86e5c31af7Sopenharmony_ci * code:opImageBlockMatchGatherSADQCOM and 87e5c31af7Sopenharmony_ci code:opImageBlockMatchWindowSSDQCOM compares four 2D neighborhoods of 88e5c31af7Sopenharmony_ci texels from a target texture with a single 2D neighborhood in the 89e5c31af7Sopenharmony_ci reference texture. 90e5c31af7Sopenharmony_ci The R component of each comparison is gathered and returned in the 91e5c31af7Sopenharmony_ci output. 92e5c31af7Sopenharmony_ciendif::VK_QCOM_image_processing2[] 93e5c31af7Sopenharmony_ci 94e5c31af7Sopenharmony_ci 95e5c31af7Sopenharmony_ci[[textures-texel-coordinate-systems]] 96e5c31af7Sopenharmony_ci=== Texel Coordinate Systems 97e5c31af7Sopenharmony_ci 98e5c31af7Sopenharmony_ciImages are addressed by _texel coordinates_. 99e5c31af7Sopenharmony_ciThere are three _texel coordinate systems_: 100e5c31af7Sopenharmony_ci 101e5c31af7Sopenharmony_ci * normalized texel coordinates [eq]#[0.0, 1.0]# 102e5c31af7Sopenharmony_ci * unnormalized texel coordinates [eq]#[0.0, width / height / depth)# 103e5c31af7Sopenharmony_ci * integer texel coordinates [eq]#[0, width / height / depth)# 104e5c31af7Sopenharmony_ci 105e5c31af7Sopenharmony_ciSPIR-V code:OpImageFetch, code:OpImageSparseFetch, code:OpImageRead, 106e5c31af7Sopenharmony_cicode:OpImageSparseRead, 107e5c31af7Sopenharmony_ciifdef::VK_QCOM_image_processing[] 108e5c31af7Sopenharmony_cicode:opImageBlockMatchSADQCOM, code:opImageBlockMatchSSDQCOM, 109e5c31af7Sopenharmony_ciendif::VK_QCOM_image_processing[] 110e5c31af7Sopenharmony_ciifdef::VK_QCOM_image_processing2[] 111e5c31af7Sopenharmony_cicode:opImageBlockMatchWindowSADQCOM, code:opImageBlockMatchWindowSSDQCOM, 112e5c31af7Sopenharmony_ciendif::VK_QCOM_image_processing2[] 113e5c31af7Sopenharmony_ciand code:OpImageWrite instructions use integer texel coordinates. 114e5c31af7Sopenharmony_ci 115e5c31af7Sopenharmony_ciOther image instructions can: use either normalized or unnormalized texel 116e5c31af7Sopenharmony_cicoordinates (selected by the pname:unnormalizedCoordinates state of the 117e5c31af7Sopenharmony_cisampler used in the instruction), but there are 118e5c31af7Sopenharmony_ci<<samplers-unnormalizedCoordinates,limitations>> on what operations, image 119e5c31af7Sopenharmony_cistate, and sampler state is supported. 120e5c31af7Sopenharmony_ciNormalized coordinates are logically 121e5c31af7Sopenharmony_ci<<textures-normalized-to-unnormalized,converted>> to unnormalized as part of 122e5c31af7Sopenharmony_ciimage operations, and <<textures-normalized-operations,certain steps>> are 123e5c31af7Sopenharmony_cionly performed on normalized coordinates. 124e5c31af7Sopenharmony_ciThe array layer coordinate is always treated as unnormalized even when other 125e5c31af7Sopenharmony_cicoordinates are normalized. 126e5c31af7Sopenharmony_ci 127e5c31af7Sopenharmony_ciNormalized texel coordinates are referred to as [eq]#(s,t,r,q,a)#, with the 128e5c31af7Sopenharmony_cicoordinates having the following meanings: 129e5c31af7Sopenharmony_ci 130e5c31af7Sopenharmony_ci * [eq]#s#: Coordinate in the first dimension of an image. 131e5c31af7Sopenharmony_ci * [eq]#t#: Coordinate in the second dimension of an image. 132e5c31af7Sopenharmony_ci * [eq]#r#: Coordinate in the third dimension of an image. 133e5c31af7Sopenharmony_ci ** [eq]#(s,t,r)# are interpreted as a direction vector for Cube images. 134e5c31af7Sopenharmony_ci * [eq]#q#: Fourth coordinate, for homogeneous (projective) coordinates. 135e5c31af7Sopenharmony_ci * [eq]#a#: Coordinate for array layer. 136e5c31af7Sopenharmony_ci 137e5c31af7Sopenharmony_ciThe coordinates are extracted from the SPIR-V operand based on the 138e5c31af7Sopenharmony_cidimensionality of the image variable and type of instruction. 139e5c31af7Sopenharmony_ciFor code:Proj instructions, the components are in order [eq]#(s, [t,] [r,] 140e5c31af7Sopenharmony_ciq)#, with [eq]#t# and [eq]#r# being conditionally present based on the 141e5c31af7Sopenharmony_cicode:Dim of the image. 142e5c31af7Sopenharmony_ciFor non-code:Proj instructions, the coordinates are [eq]#(s [,t] [,r] 143e5c31af7Sopenharmony_ci[,a])#, with [eq]#t# and [eq]#r# being conditionally present based on the 144e5c31af7Sopenharmony_cicode:Dim of the image and [eq]#a# being conditionally present based on the 145e5c31af7Sopenharmony_cicode:Arrayed property of the image. 146e5c31af7Sopenharmony_ciProjective image instructions are not supported on code:Arrayed images. 147e5c31af7Sopenharmony_ci 148e5c31af7Sopenharmony_ciUnnormalized texel coordinates are referred to as [eq]#(u,v,w,a)#, with the 149e5c31af7Sopenharmony_cicoordinates having the following meanings: 150e5c31af7Sopenharmony_ci 151e5c31af7Sopenharmony_ci * [eq]#u#: Coordinate in the first dimension of an image. 152e5c31af7Sopenharmony_ci * [eq]#v#: Coordinate in the second dimension of an image. 153e5c31af7Sopenharmony_ci * [eq]#w#: Coordinate in the third dimension of an image. 154e5c31af7Sopenharmony_ci * [eq]#a#: Coordinate for array layer. 155e5c31af7Sopenharmony_ci 156e5c31af7Sopenharmony_ciOnly the [eq]#u# and [eq]#v# coordinates are directly extracted from the 157e5c31af7Sopenharmony_ciSPIR-V operand, because only 1D and 2D (non-code:Arrayed) dimensionalities 158e5c31af7Sopenharmony_cisupport unnormalized coordinates. 159e5c31af7Sopenharmony_ciThe components are in order [eq]#(u [,v])#, with [eq]#v# being conditionally 160e5c31af7Sopenharmony_cipresent when the dimensionality is 2D. 161e5c31af7Sopenharmony_ciWhen normalized coordinates are converted to unnormalized coordinates, all 162e5c31af7Sopenharmony_cifour coordinates are used. 163e5c31af7Sopenharmony_ci 164e5c31af7Sopenharmony_ciInteger texel coordinates are referred to as [eq]#(i,j,k,l,n)#, with the 165e5c31af7Sopenharmony_cicoordinates having the following meanings: 166e5c31af7Sopenharmony_ci 167e5c31af7Sopenharmony_ci * [eq]#i#: Coordinate in the first dimension of an image. 168e5c31af7Sopenharmony_ci * [eq]#j#: Coordinate in the second dimension of an image. 169e5c31af7Sopenharmony_ci * [eq]#k#: Coordinate in the third dimension of an image. 170e5c31af7Sopenharmony_ci * [eq]#l#: Coordinate for array layer. 171e5c31af7Sopenharmony_ci * [eq]#n#: Index of the sample within the texel. 172e5c31af7Sopenharmony_ci 173e5c31af7Sopenharmony_ciThey are extracted from the SPIR-V operand in order [eq]#(i [,j] [,k] [,l] 174e5c31af7Sopenharmony_ci[,n])#, with [eq]#j# and [eq]#k# conditionally present based on the code:Dim 175e5c31af7Sopenharmony_ciof the image, and [eq]#l# conditionally present based on the code:Arrayed 176e5c31af7Sopenharmony_ciproperty of the image. 177e5c31af7Sopenharmony_ci[eq]#n# is conditionally present and is taken from the code:Sample image 178e5c31af7Sopenharmony_cioperand. 179e5c31af7Sopenharmony_ci 180e5c31af7Sopenharmony_ciifdef::VK_EXT_image_sliced_view_of_3d[] 181e5c31af7Sopenharmony_ciIf an accessed image was created from a view using 182e5c31af7Sopenharmony_cislink:VkImageViewSlicedCreateInfoEXT and accessed through a 183e5c31af7Sopenharmony_ciename:VK_DESCRIPTOR_TYPE_STORAGE_IMAGE descriptor, then the value of [eq]#k# 184e5c31af7Sopenharmony_ciis incremented by slink:VkImageViewSlicedCreateInfoEXT::pname:sliceOffset, 185e5c31af7Sopenharmony_cigiving [eq]#k <- sliceOffset {plus} k#. 186e5c31af7Sopenharmony_ciThe image's accessible range in the third dimension is [eq]#k < sliceOffset 187e5c31af7Sopenharmony_ci+ sliceCount#. 188e5c31af7Sopenharmony_ciIf slink:VkImageViewSlicedCreateInfoEXT::pname:sliceCount is 189e5c31af7Sopenharmony_ciename:VK_REMAINING_3D_SLICES_EXT, the range is inherited from the image's 190e5c31af7Sopenharmony_cidepth extent as specified by <<resources-image-mip-level-sizing, Image Mip 191e5c31af7Sopenharmony_ciLevel Sizing>>. 192e5c31af7Sopenharmony_ciendif::VK_EXT_image_sliced_view_of_3d[] 193e5c31af7Sopenharmony_ci 194e5c31af7Sopenharmony_ciFor all coordinate types, unused coordinates are assigned a value of zero. 195e5c31af7Sopenharmony_ci 196e5c31af7Sopenharmony_ci[[textures-texel-coordinate-systems-diagrams]] 197e5c31af7Sopenharmony_ciimage::{images}/vulkantexture0-ll.svg[align="center",title="Texel Coordinate Systems, Linear Filtering",opts="{imageopts}"] 198e5c31af7Sopenharmony_ciThe Texel Coordinate Systems - For the example shown of an 8{times}4 texel 199e5c31af7Sopenharmony_citwo dimensional image. 200e5c31af7Sopenharmony_ci 201e5c31af7Sopenharmony_ci * Normalized texel coordinates: 202e5c31af7Sopenharmony_ci ** The [eq]#s# coordinate goes from 0.0 to 1.0. 203e5c31af7Sopenharmony_ci ** The [eq]#t# coordinate goes from 0.0 to 1.0. 204e5c31af7Sopenharmony_ci * Unnormalized texel coordinates: 205e5c31af7Sopenharmony_ci ** The [eq]#u# coordinate within the range 0.0 to 8.0 is within the image, 206e5c31af7Sopenharmony_ci otherwise it is outside the image. 207e5c31af7Sopenharmony_ci ** The [eq]#v# coordinate within the range 0.0 to 4.0 is within the image, 208e5c31af7Sopenharmony_ci otherwise it is outside the image. 209e5c31af7Sopenharmony_ci * Integer texel coordinates: 210e5c31af7Sopenharmony_ci ** The [eq]#i# coordinate within the range 0 to 7 addresses texels within 211e5c31af7Sopenharmony_ci the image, otherwise it is outside the image. 212e5c31af7Sopenharmony_ci ** The [eq]#j# coordinate within the range 0 to 3 addresses texels within 213e5c31af7Sopenharmony_ci the image, otherwise it is outside the image. 214e5c31af7Sopenharmony_ci * Also shown for linear filtering: 215e5c31af7Sopenharmony_ci ** Given the unnormalized coordinates [eq]#(u,v)#, the four texels 216e5c31af7Sopenharmony_ci selected are [eq]#i~0~j~0~#, [eq]#i~1~j~0~#, [eq]#i~0~j~1~#, and 217e5c31af7Sopenharmony_ci [eq]#i~1~j~1~#. 218e5c31af7Sopenharmony_ci ** The fractions [eq]#{alpha}# and [eq]#{beta}#. 219e5c31af7Sopenharmony_ci ** Given the offset [eq]#{DeltaUpper}~i~# and [eq]#{DeltaUpper}~j~#, the 220e5c31af7Sopenharmony_ci four texels selected by the offset are [eq]#i~0~j'~0~#, 221e5c31af7Sopenharmony_ci [eq]#i~1~j'~0~#, [eq]#i~0~j'~1~#, and [eq]#i~1~j'~1~#. 222e5c31af7Sopenharmony_ci 223e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_1,VK_KHR_sampler_ycbcr_conversion[] 224e5c31af7Sopenharmony_ci[NOTE] 225e5c31af7Sopenharmony_ci.Note 226e5c31af7Sopenharmony_ci==== 227e5c31af7Sopenharmony_ciFor formats with reduced-resolution components, [eq]#{DeltaUpper}~i~# and 228e5c31af7Sopenharmony_ci[eq]#{DeltaUpper}~j~# are relative to the resolution of the 229e5c31af7Sopenharmony_cihighest-resolution component, and therefore may be divided by two relative 230e5c31af7Sopenharmony_cito the unnormalized coordinate space of the lower-resolution components. 231e5c31af7Sopenharmony_ci==== 232e5c31af7Sopenharmony_ciendif::VK_VERSION_1_1,VK_KHR_sampler_ycbcr_conversion[] 233e5c31af7Sopenharmony_ci 234e5c31af7Sopenharmony_ciimage::{images}/vulkantexture1-ll.svg[align="center",title="Texel Coordinate Systems, Nearest Filtering",opts="{imageopts}"] 235e5c31af7Sopenharmony_ci 236e5c31af7Sopenharmony_ciThe Texel Coordinate Systems - For the example shown of an 8{times}4 texel 237e5c31af7Sopenharmony_citwo dimensional image. 238e5c31af7Sopenharmony_ci 239e5c31af7Sopenharmony_ci * Texel coordinates as above. 240e5c31af7Sopenharmony_ci Also shown for nearest filtering: 241e5c31af7Sopenharmony_ci ** Given the unnormalized coordinates [eq]#(u,v)#, the texel selected is 242e5c31af7Sopenharmony_ci [eq]#ij#. 243e5c31af7Sopenharmony_ci ** Given the offset [eq]#{DeltaUpper}~i~# and [eq]#{DeltaUpper}~j~#, the 244e5c31af7Sopenharmony_ci texel selected by the offset is [eq]#ij'#. 245e5c31af7Sopenharmony_ci 246e5c31af7Sopenharmony_ciifdef::VK_NV_corner_sampled_image[] 247e5c31af7Sopenharmony_ciFor corner-sampled images, the texel samples are located at the grid 248e5c31af7Sopenharmony_ciintersections instead of the texel centers. 249e5c31af7Sopenharmony_ci 250e5c31af7Sopenharmony_ciimage::{images}/vulkantexture0-corner-alternative-a-ll.svg[align="center",title="Texel Coordinate Systems, Corner Sampling",opts="{imageopts}"] 251e5c31af7Sopenharmony_ci 252e5c31af7Sopenharmony_ciendif::VK_NV_corner_sampled_image[] 253e5c31af7Sopenharmony_ci 254e5c31af7Sopenharmony_ci 255e5c31af7Sopenharmony_ci== Conversion Formulas 256e5c31af7Sopenharmony_ci 257e5c31af7Sopenharmony_ciifdef::editing-notes[] 258e5c31af7Sopenharmony_ci[NOTE] 259e5c31af7Sopenharmony_ci.editing-note 260e5c31af7Sopenharmony_ci==== 261e5c31af7Sopenharmony_ci(Bill) These Conversion Formulas will likely move to Section 2.7 Fixed-Point 262e5c31af7Sopenharmony_ciData Conversions (RGB to sRGB and sRGB to RGB) and section 2.6 Numeric 263e5c31af7Sopenharmony_ciRepresentation and Computation (RGB to Shared Exponent and Shared Exponent 264e5c31af7Sopenharmony_cito RGB) 265e5c31af7Sopenharmony_ci==== 266e5c31af7Sopenharmony_ciendif::editing-notes[] 267e5c31af7Sopenharmony_ci 268e5c31af7Sopenharmony_ci 269e5c31af7Sopenharmony_ci[[textures-RGB-sexp]] 270e5c31af7Sopenharmony_ci=== RGB to Shared Exponent Conversion 271e5c31af7Sopenharmony_ci 272e5c31af7Sopenharmony_ciAn RGB color [eq]#(red, green, blue)# is transformed to a shared exponent 273e5c31af7Sopenharmony_cicolor [eq]#(red~shared~, green~shared~, blue~shared~, exp~shared~)# as 274e5c31af7Sopenharmony_cifollows: 275e5c31af7Sopenharmony_ci 276e5c31af7Sopenharmony_ciFirst, the components [eq]#(red, green, blue)# are clamped to 277e5c31af7Sopenharmony_ci[eq]#(red~clamped~, green~clamped~, blue~clamped~)# as: 278e5c31af7Sopenharmony_ci 279e5c31af7Sopenharmony_ci {empty}:: [eq]#red~clamped~ = max(0, min(sharedexp~max~, red))# 280e5c31af7Sopenharmony_ci {empty}:: [eq]#green~clamped~ = max(0, min(sharedexp~max~, green))# 281e5c31af7Sopenharmony_ci {empty}:: [eq]#blue~clamped~ = max(0, min(sharedexp~max~, blue))# 282e5c31af7Sopenharmony_ci 283e5c31af7Sopenharmony_ciwhere: 284e5c31af7Sopenharmony_ci 285e5c31af7Sopenharmony_ci[latexmath] 286e5c31af7Sopenharmony_ci+++++++++++++++++++ 287e5c31af7Sopenharmony_ci\begin{aligned} 288e5c31af7Sopenharmony_ciN & = 9 & \text{number of mantissa bits per component} \\ 289e5c31af7Sopenharmony_ciB & = 15 & \text{exponent bias} \\ 290e5c31af7Sopenharmony_ciE_{max} & = 31 & \text{maximum possible biased exponent value} \\ 291e5c31af7Sopenharmony_cisharedexp_{max} & = \frac{(2^N-1)}{2^N} \times 2^{(E_{max}-B)} 292e5c31af7Sopenharmony_ci\end{aligned} 293e5c31af7Sopenharmony_ci+++++++++++++++++++ 294e5c31af7Sopenharmony_ci 295e5c31af7Sopenharmony_ci[NOTE] 296e5c31af7Sopenharmony_ci.Note 297e5c31af7Sopenharmony_ci==== 298e5c31af7Sopenharmony_ci// The trailing + is to avoid the asciidoc parser treating the custom role 299e5c31af7Sopenharmony_ci// as a block attribute in some cases. 300e5c31af7Sopenharmony_ci[eq]#NaN#, if supported, is handled as in + 301e5c31af7Sopenharmony_ci<<ieee-754,IEEE 754-2008>> `minNum()` and `maxNum()`. 302e5c31af7Sopenharmony_ciThis results in any [eq]#NaN# being mapped to zero. 303e5c31af7Sopenharmony_ci==== 304e5c31af7Sopenharmony_ci 305e5c31af7Sopenharmony_ciThe largest clamped component, [eq]#max~clamped~# is determined: 306e5c31af7Sopenharmony_ci 307e5c31af7Sopenharmony_ci {empty}:: [eq]#max~clamped~ = max(red~clamped~, green~clamped~, 308e5c31af7Sopenharmony_ci blue~clamped~)# 309e5c31af7Sopenharmony_ci 310e5c31af7Sopenharmony_ciA preliminary shared exponent [eq]#exp'# is computed: 311e5c31af7Sopenharmony_ci[latexmath] 312e5c31af7Sopenharmony_ci+++++++++++++++++++ 313e5c31af7Sopenharmony_ci\begin{aligned} 314e5c31af7Sopenharmony_ciexp' = 315e5c31af7Sopenharmony_ci \begin{cases} 316e5c31af7Sopenharmony_ci \left \lfloor \log_2(max_{clamped}) \right \rfloor + (B+1) 317e5c31af7Sopenharmony_ci & \text{for}\ max_{clamped} > 2^{-(B+1)} \\ 318e5c31af7Sopenharmony_ci 0 319e5c31af7Sopenharmony_ci & \text{for}\ max_{clamped} \leq 2^{-(B+1)} 320e5c31af7Sopenharmony_ci \end{cases} 321e5c31af7Sopenharmony_ci\end{aligned} 322e5c31af7Sopenharmony_ci+++++++++++++++++++ 323e5c31af7Sopenharmony_ci 324e5c31af7Sopenharmony_ciThe shared exponent [eq]#exp~shared~# is computed: 325e5c31af7Sopenharmony_ci 326e5c31af7Sopenharmony_ci[latexmath] 327e5c31af7Sopenharmony_ci+++++++++++++++++++ 328e5c31af7Sopenharmony_ci\begin{aligned} 329e5c31af7Sopenharmony_cimax_{shared} = 330e5c31af7Sopenharmony_ci \left \lfloor 331e5c31af7Sopenharmony_ci { \frac{max_{clamped}}{2^{(exp'-B-N)}} + \frac{1}{2} } 332e5c31af7Sopenharmony_ci \right \rfloor 333e5c31af7Sopenharmony_ci\end{aligned} 334e5c31af7Sopenharmony_ci+++++++++++++++++++ 335e5c31af7Sopenharmony_ci 336e5c31af7Sopenharmony_ci[latexmath] 337e5c31af7Sopenharmony_ci+++++++++++++++++++ 338e5c31af7Sopenharmony_ci\begin{aligned} 339e5c31af7Sopenharmony_ciexp_{shared} = 340e5c31af7Sopenharmony_ci \begin{cases} 341e5c31af7Sopenharmony_ci exp' & \text{for}\ 0 \leq max_{shared} < 2^N \\ 342e5c31af7Sopenharmony_ci exp'+1 & \text{for}\ max_{shared} = 2^N 343e5c31af7Sopenharmony_ci \end{cases} 344e5c31af7Sopenharmony_ci\end{aligned} 345e5c31af7Sopenharmony_ci+++++++++++++++++++ 346e5c31af7Sopenharmony_ci 347e5c31af7Sopenharmony_ciFinally, three integer values in the range [eq]#0# to [eq]#2^N^# are 348e5c31af7Sopenharmony_cicomputed: 349e5c31af7Sopenharmony_ci 350e5c31af7Sopenharmony_ci[latexmath] 351e5c31af7Sopenharmony_ci+++++++++++++++++++ 352e5c31af7Sopenharmony_ci\begin{aligned} 353e5c31af7Sopenharmony_cired_{shared} & = 354e5c31af7Sopenharmony_ci \left \lfloor 355e5c31af7Sopenharmony_ci { \frac{red_{clamped}}{2^{(exp_{shared}-B-N)}}+ \frac{1}{2} } 356e5c31af7Sopenharmony_ci \right \rfloor \\ 357e5c31af7Sopenharmony_cigreen_{shared} & = 358e5c31af7Sopenharmony_ci \left \lfloor 359e5c31af7Sopenharmony_ci { \frac{green_{clamped}}{2^{(exp_{shared}-B-N)}}+ \frac{1}{2} } 360e5c31af7Sopenharmony_ci \right \rfloor \\ 361e5c31af7Sopenharmony_ciblue_{shared} & = 362e5c31af7Sopenharmony_ci \left \lfloor 363e5c31af7Sopenharmony_ci { \frac{blue_{clamped}}{2^{(exp_{shared}-B-N)}}+ \frac{1}{2} } 364e5c31af7Sopenharmony_ci \right \rfloor 365e5c31af7Sopenharmony_ci\end{aligned} 366e5c31af7Sopenharmony_ci+++++++++++++++++++ 367e5c31af7Sopenharmony_ci 368e5c31af7Sopenharmony_ci 369e5c31af7Sopenharmony_ci[[textures-sexp-RGB]] 370e5c31af7Sopenharmony_ci=== Shared Exponent to RGB 371e5c31af7Sopenharmony_ci 372e5c31af7Sopenharmony_ciA shared exponent color [eq]#(red~shared~, green~shared~, blue~shared~, 373e5c31af7Sopenharmony_ciexp~shared~)# is transformed to an RGB color [eq]#(red, green, blue)# as 374e5c31af7Sopenharmony_cifollows: 375e5c31af7Sopenharmony_ci 376e5c31af7Sopenharmony_ci {empty}:: latexmath:[red = red_{shared} \times {2^{(exp_{shared}-B-N)}}] 377e5c31af7Sopenharmony_ci {empty}:: latexmath:[green = green_{shared} \times 378e5c31af7Sopenharmony_ci {2^{(exp_{shared}-B-N)}}] 379e5c31af7Sopenharmony_ci {empty}:: latexmath:[blue = blue_{shared} \times {2^{(exp_{shared}-B-N)}}] 380e5c31af7Sopenharmony_ci 381e5c31af7Sopenharmony_ciwhere: 382e5c31af7Sopenharmony_ci 383e5c31af7Sopenharmony_ci {empty}:: [eq]#N = 9# (number of mantissa bits per component) 384e5c31af7Sopenharmony_ci {empty}:: [eq]#B = 15# (exponent bias) 385e5c31af7Sopenharmony_ci 386e5c31af7Sopenharmony_ci 387e5c31af7Sopenharmony_ci== Texel Input Operations 388e5c31af7Sopenharmony_ci 389e5c31af7Sopenharmony_ci_Texel input instructions_ are SPIR-V image instructions that read from an 390e5c31af7Sopenharmony_ciimage. 391e5c31af7Sopenharmony_ci_Texel input operations_ are a set of steps that are performed on state, 392e5c31af7Sopenharmony_cicoordinates, and texel values while processing a texel input instruction, 393e5c31af7Sopenharmony_ciand which are common to some or all texel input instructions. 394e5c31af7Sopenharmony_ciThey include the following steps, which are performed in the listed order: 395e5c31af7Sopenharmony_ci 396e5c31af7Sopenharmony_ci * <<textures-input-validation,Validation operations>> 397e5c31af7Sopenharmony_ci ** <<textures-operation-validation,Instruction/Sampler/Image validation>> 398e5c31af7Sopenharmony_ci ** <<textures-integer-coordinate-validation,Coordinate validation>> 399e5c31af7Sopenharmony_ci ** <<textures-sparse-validation,Sparse validation>> 400e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_1,VK_KHR_sampler_ycbcr_conversion[] 401e5c31af7Sopenharmony_ci ** <<textures-layout-validation,Layout validation>> 402e5c31af7Sopenharmony_ciendif::VK_VERSION_1_1,VK_KHR_sampler_ycbcr_conversion[] 403e5c31af7Sopenharmony_ci * <<textures-format-conversion,Format conversion>> 404e5c31af7Sopenharmony_ci * <<textures-texel-replacement,Texel replacement>> 405e5c31af7Sopenharmony_ci * <<textures-depth-compare-operation,Depth comparison>> 406e5c31af7Sopenharmony_ci * <<textures-conversion-to-rgba,Conversion to RGBA>> 407e5c31af7Sopenharmony_ci * <<textures-component-swizzle,Component swizzle>> 408e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_1,VK_KHR_sampler_ycbcr_conversion[] 409e5c31af7Sopenharmony_ci * <<textures-chroma-reconstruction,Chroma reconstruction>> 410e5c31af7Sopenharmony_ci * <<textures-sampler-YCbCr-conversion,{YCbCr} conversion>> 411e5c31af7Sopenharmony_ciendif::VK_VERSION_1_1,VK_KHR_sampler_ycbcr_conversion[] 412e5c31af7Sopenharmony_ci 413e5c31af7Sopenharmony_ciFor texel input instructions involving multiple texels (for sampling or 414e5c31af7Sopenharmony_cigathering), these steps are applied for each texel that is used in the 415e5c31af7Sopenharmony_ciinstruction. 416e5c31af7Sopenharmony_ciDepending on the type of image instruction, other steps are conditionally 417e5c31af7Sopenharmony_ciperformed between these steps or involving multiple coordinate or texel 418e5c31af7Sopenharmony_civalues. 419e5c31af7Sopenharmony_ci 420e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_1,VK_KHR_sampler_ycbcr_conversion[] 421e5c31af7Sopenharmony_ciIf <<textures-chroma-reconstruction,Chroma Reconstruction>> is implicit, 422e5c31af7Sopenharmony_ci<<textures-texel-filtering, Texel Filtering>> instead takes place during 423e5c31af7Sopenharmony_cichroma reconstruction, before <<textures-sampler-YCbCr-conversion,sampler 424e5c31af7Sopenharmony_ci{YCbCr} conversion>> occurs. 425e5c31af7Sopenharmony_ciendif::VK_VERSION_1_1,VK_KHR_sampler_ycbcr_conversion[] 426e5c31af7Sopenharmony_ci 427e5c31af7Sopenharmony_ciifdef::VK_QCOM_image_processing[] 428e5c31af7Sopenharmony_ciThe operations described in <<textures-blockmatch,block matching>> and 429e5c31af7Sopenharmony_ci<<textures-weightimage,weight image sampling>> are performed before 430e5c31af7Sopenharmony_ci<<textures-conversion-to-rgba,Conversion to RGBA>> and 431e5c31af7Sopenharmony_ci<<textures-component-swizzle,Component swizzle>>. 432e5c31af7Sopenharmony_ciendif::VK_QCOM_image_processing[] 433e5c31af7Sopenharmony_ci 434e5c31af7Sopenharmony_ci 435e5c31af7Sopenharmony_ci[[textures-input-validation]] 436e5c31af7Sopenharmony_ci=== Texel Input Validation Operations 437e5c31af7Sopenharmony_ci 438e5c31af7Sopenharmony_ci_Texel input validation operations_ inspect instruction/image/sampler state 439e5c31af7Sopenharmony_cior coordinates, and in certain circumstances cause the texel value to be 440e5c31af7Sopenharmony_cireplaced or become undefined:. 441e5c31af7Sopenharmony_ciThere are a series of validations that the texel undergoes. 442e5c31af7Sopenharmony_ci 443e5c31af7Sopenharmony_ci 444e5c31af7Sopenharmony_ci[[textures-operation-validation]] 445e5c31af7Sopenharmony_ci==== Instruction/Sampler/Image View Validation 446e5c31af7Sopenharmony_ci 447e5c31af7Sopenharmony_ciThere are a number of cases where a SPIR-V instruction can: mismatch with 448e5c31af7Sopenharmony_cithe sampler, the image view, or both, and a number of further cases where 449e5c31af7Sopenharmony_cithe sampler can: mismatch with the image view. 450e5c31af7Sopenharmony_ciIn such cases the value of the texel returned is undefined:. 451e5c31af7Sopenharmony_ci 452e5c31af7Sopenharmony_ciThese cases include: 453e5c31af7Sopenharmony_ci 454e5c31af7Sopenharmony_ci * The sampler pname:borderColor is an integer type and the image view 455e5c31af7Sopenharmony_ci pname:format is not one of the elink:VkFormat integer types or a stencil 456e5c31af7Sopenharmony_ci component of a depth/stencil format. 457e5c31af7Sopenharmony_ci * The sampler pname:borderColor is a float type and the image view 458e5c31af7Sopenharmony_ci pname:format is not one of the elink:VkFormat float types or a depth 459e5c31af7Sopenharmony_ci component of a depth/stencil format. 460e5c31af7Sopenharmony_ciifndef::VK_EXT_border_color_swizzle[] 461e5c31af7Sopenharmony_ci * The sampler pname:borderColor is one of the opaque black colors 462e5c31af7Sopenharmony_ci (ename:VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK or 463e5c31af7Sopenharmony_ci ename:VK_BORDER_COLOR_INT_OPAQUE_BLACK) and the image view 464e5c31af7Sopenharmony_ci elink:VkComponentSwizzle for any of the slink:VkComponentMapping 465e5c31af7Sopenharmony_ci components is not the <<resources-image-views-identity-mappings,identity 466e5c31af7Sopenharmony_ci swizzle>>. 467e5c31af7Sopenharmony_ciendif::VK_EXT_border_color_swizzle[] 468e5c31af7Sopenharmony_ciifdef::VK_EXT_border_color_swizzle[] 469e5c31af7Sopenharmony_ci * The sampler pname:borderColor is one of the opaque black colors 470e5c31af7Sopenharmony_ci (ename:VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK or 471e5c31af7Sopenharmony_ci ename:VK_BORDER_COLOR_INT_OPAQUE_BLACK) and the image view 472e5c31af7Sopenharmony_ci elink:VkComponentSwizzle for any of the slink:VkComponentMapping 473e5c31af7Sopenharmony_ci components is not the <<resources-image-views-identity-mappings,identity 474e5c31af7Sopenharmony_ci swizzle>>, and 475e5c31af7Sopenharmony_ci slink:VkPhysicalDeviceBorderColorSwizzleFeaturesEXT::pname:borderColorSwizzleFromImage 476e5c31af7Sopenharmony_ci feature is not enabled, and 477e5c31af7Sopenharmony_ci slink:VkSamplerBorderColorComponentMappingCreateInfoEXT is not 478e5c31af7Sopenharmony_ci specified. 479e5c31af7Sopenharmony_ci * slink:VkSamplerBorderColorComponentMappingCreateInfoEXT::pname:components, 480e5c31af7Sopenharmony_ci if specified, has a component swizzle that does not match the component 481e5c31af7Sopenharmony_ci swizzle of the image view, and either component swizzle is not a form of 482e5c31af7Sopenharmony_ci identity swizzle. 483e5c31af7Sopenharmony_ci * slink:VkSamplerBorderColorComponentMappingCreateInfoEXT::pname:srgb, if 484e5c31af7Sopenharmony_ci specified, does not match the sRGB encoding of the image view. 485e5c31af7Sopenharmony_ciendif::VK_EXT_border_color_swizzle[] 486e5c31af7Sopenharmony_ciifdef::VK_EXT_custom_border_color[] 487e5c31af7Sopenharmony_ci * The sampler pname:borderColor is a custom color 488e5c31af7Sopenharmony_ci (ename:VK_BORDER_COLOR_FLOAT_CUSTOM_EXT or 489e5c31af7Sopenharmony_ci ename:VK_BORDER_COLOR_INT_CUSTOM_EXT) and the supplied 490e5c31af7Sopenharmony_ci slink:VkSamplerCustomBorderColorCreateInfoEXT::pname:customBorderColor 491e5c31af7Sopenharmony_ci is outside the bounds of the values representable in the image view's 492e5c31af7Sopenharmony_ci pname:format. 493e5c31af7Sopenharmony_ciifndef::VK_EXT_border_color_swizzle[] 494e5c31af7Sopenharmony_ci * The sampler pname:borderColor is a custom color 495e5c31af7Sopenharmony_ci (ename:VK_BORDER_COLOR_FLOAT_CUSTOM_EXT or 496e5c31af7Sopenharmony_ci ename:VK_BORDER_COLOR_INT_CUSTOM_EXT) and the image view 497e5c31af7Sopenharmony_ci elink:VkComponentSwizzle for any of the slink:VkComponentMapping 498e5c31af7Sopenharmony_ci components is not the <<resources-image-views-identity-mappings,identity 499e5c31af7Sopenharmony_ci swizzle>>. 500e5c31af7Sopenharmony_ciendif::VK_EXT_border_color_swizzle[] 501e5c31af7Sopenharmony_ciifdef::VK_EXT_border_color_swizzle[] 502e5c31af7Sopenharmony_ci * The sampler pname:borderColor is a custom color 503e5c31af7Sopenharmony_ci (ename:VK_BORDER_COLOR_FLOAT_CUSTOM_EXT or 504e5c31af7Sopenharmony_ci ename:VK_BORDER_COLOR_INT_CUSTOM_EXT) and the image view 505e5c31af7Sopenharmony_ci elink:VkComponentSwizzle for any of the slink:VkComponentMapping 506e5c31af7Sopenharmony_ci components is not the <<resources-image-views-identity-mappings,identity 507e5c31af7Sopenharmony_ci swizzle>>, and 508e5c31af7Sopenharmony_ci slink:VkPhysicalDeviceBorderColorSwizzleFeaturesEXT::pname:borderColorSwizzleFromImage 509e5c31af7Sopenharmony_ci feature is not enabled, and 510e5c31af7Sopenharmony_ci slink:VkSamplerBorderColorComponentMappingCreateInfoEXT is not 511e5c31af7Sopenharmony_ci specified. 512e5c31af7Sopenharmony_ciendif::VK_EXT_border_color_swizzle[] 513e5c31af7Sopenharmony_ciendif::VK_EXT_custom_border_color[] 514e5c31af7Sopenharmony_ci * The elink:VkImageLayout of any subresource in the image view does not 515e5c31af7Sopenharmony_ci match the slink:VkDescriptorImageInfo::pname:imageLayout used to write 516e5c31af7Sopenharmony_ci the image descriptor. 517e5c31af7Sopenharmony_ci * The SPIR-V Image Format is not <<spirvenv-image-formats,compatible>> 518e5c31af7Sopenharmony_ci with the image view's pname:format. 519e5c31af7Sopenharmony_ci * The sampler pname:unnormalizedCoordinates is ename:VK_TRUE and any of 520e5c31af7Sopenharmony_ci the <<samplers-unnormalizedCoordinates,limitations of unnormalized 521e5c31af7Sopenharmony_ci coordinates>> are violated. 522e5c31af7Sopenharmony_ciifdef::VK_EXT_fragment_density_map[] 523e5c31af7Sopenharmony_ci * The sampler was created with pname:flags containing 524e5c31af7Sopenharmony_ci ename:VK_SAMPLER_CREATE_SUBSAMPLED_BIT_EXT and the image was not created 525e5c31af7Sopenharmony_ci with pname:flags containing ename:VK_IMAGE_CREATE_SUBSAMPLED_BIT_EXT. 526e5c31af7Sopenharmony_ci * The sampler was not created with pname:flags containing 527e5c31af7Sopenharmony_ci ename:VK_SAMPLER_CREATE_SUBSAMPLED_BIT_EXT and the image was created 528e5c31af7Sopenharmony_ci with pname:flags containing ename:VK_IMAGE_CREATE_SUBSAMPLED_BIT_EXT. 529e5c31af7Sopenharmony_ci * The sampler was created with pname:flags containing 530e5c31af7Sopenharmony_ci ename:VK_SAMPLER_CREATE_SUBSAMPLED_BIT_EXT and is used with a function 531e5c31af7Sopenharmony_ci that is not code:OpImageSampleImplicitLod or 532e5c31af7Sopenharmony_ci code:OpImageSampleExplicitLod, or is used with operands code:Offset or 533e5c31af7Sopenharmony_ci code:ConstOffsets. 534e5c31af7Sopenharmony_ciendif::VK_EXT_fragment_density_map[] 535e5c31af7Sopenharmony_ci * The SPIR-V instruction is one of the code:OpImage*Dref* instructions and 536e5c31af7Sopenharmony_ci the sampler pname:compareEnable is ename:VK_FALSE 537e5c31af7Sopenharmony_ci * The SPIR-V instruction is not one of the code:OpImage*Dref* instructions 538e5c31af7Sopenharmony_ci and the sampler pname:compareEnable is ename:VK_TRUE 539e5c31af7Sopenharmony_ciifndef::VK_VERSION_1_3,VK_KHR_format_feature_flags2[] 540e5c31af7Sopenharmony_ci * The SPIR-V instruction is one of the code:OpImage*Dref* instructions and 541e5c31af7Sopenharmony_ci the image view pname:format is not one of the depth/stencil formats with 542e5c31af7Sopenharmony_ci a depth component, or the image view aspect is not 543e5c31af7Sopenharmony_ci ename:VK_IMAGE_ASPECT_DEPTH_BIT. 544e5c31af7Sopenharmony_ciendif::VK_VERSION_1_3,VK_KHR_format_feature_flags2[] 545e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_3,VK_KHR_format_feature_flags2[] 546e5c31af7Sopenharmony_ci * The SPIR-V instruction is one of the code:OpImage*Dref* instructions, 547e5c31af7Sopenharmony_ci the image view pname:format is one of the depth/stencil formats, and the 548e5c31af7Sopenharmony_ci image view aspect is not ename:VK_IMAGE_ASPECT_DEPTH_BIT. 549e5c31af7Sopenharmony_ciendif::VK_VERSION_1_3,VK_KHR_format_feature_flags2[] 550e5c31af7Sopenharmony_ci * The SPIR-V instruction's image variable's properties are not compatible 551e5c31af7Sopenharmony_ci with the image view: 552e5c31af7Sopenharmony_ci ** Rules for pname:viewType: 553e5c31af7Sopenharmony_ci *** ename:VK_IMAGE_VIEW_TYPE_1D must: have code:Dim = 1D, code:Arrayed = 554e5c31af7Sopenharmony_ci 0, code:MS = 0. 555e5c31af7Sopenharmony_ci *** ename:VK_IMAGE_VIEW_TYPE_2D must: have code:Dim = 2D, code:Arrayed = 0. 556e5c31af7Sopenharmony_ci *** ename:VK_IMAGE_VIEW_TYPE_3D must: have code:Dim = 3D, code:Arrayed = 557e5c31af7Sopenharmony_ci 0, code:MS = 0. 558e5c31af7Sopenharmony_ci *** ename:VK_IMAGE_VIEW_TYPE_CUBE must: have code:Dim = Cube, code:Arrayed 559e5c31af7Sopenharmony_ci = 0, code:MS = 0. 560e5c31af7Sopenharmony_ci *** ename:VK_IMAGE_VIEW_TYPE_1D_ARRAY must: have code:Dim = 1D, 561e5c31af7Sopenharmony_ci code:Arrayed = 1, code:MS = 0. 562e5c31af7Sopenharmony_ci *** ename:VK_IMAGE_VIEW_TYPE_2D_ARRAY must: have code:Dim = 2D, 563e5c31af7Sopenharmony_ci code:Arrayed = 1. 564e5c31af7Sopenharmony_ci *** ename:VK_IMAGE_VIEW_TYPE_CUBE_ARRAY must: have code:Dim = Cube, 565e5c31af7Sopenharmony_ci code:Arrayed = 1, code:MS = 0. 566e5c31af7Sopenharmony_ci ** If the image was created with slink:VkImageCreateInfo::pname:samples 567e5c31af7Sopenharmony_ci equal to ename:VK_SAMPLE_COUNT_1_BIT, the instruction must: have 568e5c31af7Sopenharmony_ci code:MS = 0. 569e5c31af7Sopenharmony_ci ** If the image was created with slink:VkImageCreateInfo::pname:samples 570e5c31af7Sopenharmony_ci not equal to ename:VK_SAMPLE_COUNT_1_BIT, the instruction must: have 571e5c31af7Sopenharmony_ci code:MS = 1. 572e5c31af7Sopenharmony_ci ** If the code:Sampled code:Type of the code:OpTypeImage does not match 573e5c31af7Sopenharmony_ci the <<spirv-type,SPIR-V Type>>. 574e5c31af7Sopenharmony_ci ** If the <<spirvenv-image-signedness,signedness of any read or sample 575e5c31af7Sopenharmony_ci operation>> does not match the signedness of the image's format. 576e5c31af7Sopenharmony_ciifdef::VK_NV_corner_sampled_image[] 577e5c31af7Sopenharmony_ci * If the image was created with slink:VkImageCreateInfo::pname:flags 578e5c31af7Sopenharmony_ci containing ename:VK_IMAGE_CREATE_CORNER_SAMPLED_BIT_NV, the sampler 579e5c31af7Sopenharmony_ci addressing modes must: only use a elink:VkSamplerAddressMode of 580e5c31af7Sopenharmony_ci ename:VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE. 581e5c31af7Sopenharmony_ciendif::VK_NV_corner_sampled_image[] 582e5c31af7Sopenharmony_ciifdef::VK_NV_shader_image_footprint[] 583e5c31af7Sopenharmony_ci * The SPIR-V instruction is code:OpImageSampleFootprintNV with code:Dim = 584e5c31af7Sopenharmony_ci 2D and pname:addressModeU or pname:addressModeV in the sampler is not 585e5c31af7Sopenharmony_ci ename:VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE. 586e5c31af7Sopenharmony_ci * The SPIR-V instruction is code:OpImageSampleFootprintNV with code:Dim = 587e5c31af7Sopenharmony_ci 3D and pname:addressModeU, pname:addressModeV, or pname:addressModeW in 588e5c31af7Sopenharmony_ci the sampler is not ename:VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE. 589e5c31af7Sopenharmony_ciendif::VK_NV_shader_image_footprint[] 590e5c31af7Sopenharmony_ciifdef::VK_EXT_custom_border_color[] 591e5c31af7Sopenharmony_ci * The sampler was created with a specified 592e5c31af7Sopenharmony_ci slink:VkSamplerCustomBorderColorCreateInfoEXT::pname:format which does 593e5c31af7Sopenharmony_ci not match the elink:VkFormat of the image view(s) it is sampling. 594e5c31af7Sopenharmony_ci * The sampler is sampling an image view of 595e5c31af7Sopenharmony_ci ename:VK_FORMAT_B4G4R4A4_UNORM_PACK16, 596e5c31af7Sopenharmony_ci ename:VK_FORMAT_B5G6R5_UNORM_PACK16, or 597e5c31af7Sopenharmony_ci ename:VK_FORMAT_B5G5R5A1_UNORM_PACK16 format without a specified 598e5c31af7Sopenharmony_ci slink:VkSamplerCustomBorderColorCreateInfoEXT::pname:format. 599e5c31af7Sopenharmony_ciendif::VK_EXT_custom_border_color[] 600e5c31af7Sopenharmony_ci 601e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_1,VK_KHR_sampler_ycbcr_conversion[] 602e5c31af7Sopenharmony_ciOnly code:OpImageSample* and code:OpImageSparseSample* can: be used with a 603e5c31af7Sopenharmony_cisampler or image view that enables <<samplers-YCbCr-conversion,sampler 604e5c31af7Sopenharmony_ci{YCbCr} conversion>>. 605e5c31af7Sopenharmony_ci 606e5c31af7Sopenharmony_cicode:OpImageFetch, code:OpImageSparseFetch, code:OpImage*Gather, and 607e5c31af7Sopenharmony_cicode:OpImageSparse*Gather must: not be used with a sampler or image view 608e5c31af7Sopenharmony_cithat enables <<samplers-YCbCr-conversion,sampler {YCbCr} conversion>>. 609e5c31af7Sopenharmony_ci 610e5c31af7Sopenharmony_ciThe code:ConstOffset and code:Offset operands must: not be used with a 611e5c31af7Sopenharmony_cisampler or image view that enables <<samplers-YCbCr-conversion,sampler 612e5c31af7Sopenharmony_ci{YCbCr} conversion>>. 613e5c31af7Sopenharmony_ciendif::VK_VERSION_1_1,VK_KHR_sampler_ycbcr_conversion[] 614e5c31af7Sopenharmony_ci 615e5c31af7Sopenharmony_ci 616e5c31af7Sopenharmony_ci[[textures-integer-coordinate-validation]] 617e5c31af7Sopenharmony_ci==== Integer Texel Coordinate Validation 618e5c31af7Sopenharmony_ci 619e5c31af7Sopenharmony_ciInteger texel coordinates are validated against the size of the image level, 620e5c31af7Sopenharmony_ciand the number of layers and number of samples in the image. 621e5c31af7Sopenharmony_ciFor SPIR-V instructions that use integer texel coordinates, this is 622e5c31af7Sopenharmony_ciperformed directly on the integer coordinates. 623e5c31af7Sopenharmony_ciFor instructions that use normalized or unnormalized texel coordinates, this 624e5c31af7Sopenharmony_ciis performed on the coordinates that result after 625e5c31af7Sopenharmony_ci<<textures-unnormalized-to-integer,conversion>> to integer texel 626e5c31af7Sopenharmony_cicoordinates. 627e5c31af7Sopenharmony_ci 628e5c31af7Sopenharmony_ciIf the integer texel coordinates do not satisfy all of the conditions 629e5c31af7Sopenharmony_ci 630e5c31af7Sopenharmony_ci {empty}:: [eq]#0 {leq} i < w~s~# 631e5c31af7Sopenharmony_ci {empty}:: [eq]#0 {leq} j < h~s~# 632e5c31af7Sopenharmony_ci {empty}:: [eq]#0 {leq} k < d~s~# 633e5c31af7Sopenharmony_ci {empty}:: [eq]#0 {leq} l < layers# 634e5c31af7Sopenharmony_ci {empty}:: [eq]#0 {leq} n < samples# 635e5c31af7Sopenharmony_ci 636e5c31af7Sopenharmony_ciwhere: 637e5c31af7Sopenharmony_ci 638e5c31af7Sopenharmony_ci {empty}:: [eq]#w~s~ =# width of the image level 639e5c31af7Sopenharmony_ci {empty}:: [eq]#h~s~ =# height of the image level 640e5c31af7Sopenharmony_ci {empty}:: [eq]#d~s~ =# depth of the image level 641e5c31af7Sopenharmony_ci {empty}:: [eq]#layers =# number of layers in the image 642e5c31af7Sopenharmony_ci {empty}:: [eq]#samples =# number of samples per texel in the image 643e5c31af7Sopenharmony_ci 644e5c31af7Sopenharmony_cithen the texel fails integer texel coordinate validation. 645e5c31af7Sopenharmony_ci 646e5c31af7Sopenharmony_ciThere are four cases to consider: 647e5c31af7Sopenharmony_ci 648e5c31af7Sopenharmony_ci . Valid Texel Coordinates 649e5c31af7Sopenharmony_ci+ 650e5c31af7Sopenharmony_ci * If the texel coordinates pass validation (that is, the coordinates lie 651e5c31af7Sopenharmony_ci within the image), 652e5c31af7Sopenharmony_ci+ 653e5c31af7Sopenharmony_cithen the texel value comes from the value in image memory. 654e5c31af7Sopenharmony_ci 655e5c31af7Sopenharmony_ci . Border Texel 656e5c31af7Sopenharmony_ci+ 657e5c31af7Sopenharmony_ci * If the texel coordinates fail validation, and 658e5c31af7Sopenharmony_ci * If the read is the result of an image sample instruction or image gather 659e5c31af7Sopenharmony_ci instruction, and 660e5c31af7Sopenharmony_ci * If the image is not a cube image, 661e5c31af7Sopenharmony_ciifdef::VK_EXT_non_seamless_cube_map[] 662e5c31af7Sopenharmony_ci or if a sampler created with 663e5c31af7Sopenharmony_ci ename:VK_SAMPLER_CREATE_NON_SEAMLESS_CUBE_MAP_BIT_EXT is used, 664e5c31af7Sopenharmony_ciendif::VK_EXT_non_seamless_cube_map[] 665e5c31af7Sopenharmony_ci 666e5c31af7Sopenharmony_ci+ 667e5c31af7Sopenharmony_cithen the texel is a border texel and <<textures-texel-replacement,texel 668e5c31af7Sopenharmony_cireplacement>> is performed. 669e5c31af7Sopenharmony_ci 670e5c31af7Sopenharmony_ci . Invalid Texel 671e5c31af7Sopenharmony_ci+ 672e5c31af7Sopenharmony_ci * If the texel coordinates fail validation, and 673e5c31af7Sopenharmony_ci * If the read is the result of an image fetch instruction, image read 674e5c31af7Sopenharmony_ci instruction, or atomic instruction, 675e5c31af7Sopenharmony_ci+ 676e5c31af7Sopenharmony_cithen the texel is an invalid texel and <<textures-texel-replacement,texel 677e5c31af7Sopenharmony_cireplacement>> is performed. 678e5c31af7Sopenharmony_ci 679e5c31af7Sopenharmony_ci . Cube Map Edge or Corner 680e5c31af7Sopenharmony_ci+ 681e5c31af7Sopenharmony_ciOtherwise the texel coordinates lie beyond the edges or corners of the 682e5c31af7Sopenharmony_ciselected cube map face, and <<textures-cubemapedge, Cube map edge handling>> 683e5c31af7Sopenharmony_ciis performed. 684e5c31af7Sopenharmony_ci 685e5c31af7Sopenharmony_ci 686e5c31af7Sopenharmony_ci[[textures-cubemapedge]] 687e5c31af7Sopenharmony_ci==== Cube Map Edge Handling 688e5c31af7Sopenharmony_ci 689e5c31af7Sopenharmony_ciIf the texel coordinates lie beyond the edges or corners of the selected 690e5c31af7Sopenharmony_cicube map face (as described in the prior section), the following steps are 691e5c31af7Sopenharmony_ciperformed. 692e5c31af7Sopenharmony_ciNote that this does not occur when using ename:VK_FILTER_NEAREST filtering 693e5c31af7Sopenharmony_ciwithin a mip level, since ename:VK_FILTER_NEAREST is treated as using 694e5c31af7Sopenharmony_ciename:VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE. 695e5c31af7Sopenharmony_ci 696e5c31af7Sopenharmony_ci * Cube Map Edge Texel 697e5c31af7Sopenharmony_ci+ 698e5c31af7Sopenharmony_ci ** If the texel lies beyond the selected cube map face in either only 699e5c31af7Sopenharmony_ci [eq]#i# or only [eq]#j#, then the coordinates [eq]#(i,j)# and the array 700e5c31af7Sopenharmony_ci layer [eq]#l# are transformed to select the adjacent texel from the 701e5c31af7Sopenharmony_ci appropriate neighboring face. 702e5c31af7Sopenharmony_ci 703e5c31af7Sopenharmony_ci * Cube Map Corner Texel 704e5c31af7Sopenharmony_ci+ 705e5c31af7Sopenharmony_ci ** If the texel lies beyond the selected cube map face in both [eq]#i# and 706e5c31af7Sopenharmony_ci [eq]#j#, then there is no unique neighboring face from which to read 707e5c31af7Sopenharmony_ci that texel. 708e5c31af7Sopenharmony_ci The texel should: be replaced by the average of the three values of the 709e5c31af7Sopenharmony_ci adjacent texels in each incident face. 710e5c31af7Sopenharmony_ci However, implementations may: replace the cube map corner texel by 711e5c31af7Sopenharmony_ci other methods. 712e5c31af7Sopenharmony_ciifndef::VK_EXT_filter_cubic[] 713e5c31af7Sopenharmony_ciThe methods are subject to the constraint that if the three available texels 714e5c31af7Sopenharmony_cihave the same value, the resulting filtered texel must: have that value. 715e5c31af7Sopenharmony_ciendif::VK_EXT_filter_cubic[] 716e5c31af7Sopenharmony_ciifdef::VK_EXT_filter_cubic[] 717e5c31af7Sopenharmony_ciThe methods are subject to the constraint that for linear filtering if the 718e5c31af7Sopenharmony_cithree available texels have the same value, the resulting filtered texel 719e5c31af7Sopenharmony_cimust: have that value, and for cubic filtering if the twelve available 720e5c31af7Sopenharmony_cisamples have the same value, the resulting filtered texel must: have that 721e5c31af7Sopenharmony_civalue. 722e5c31af7Sopenharmony_ciendif::VK_EXT_filter_cubic[] 723e5c31af7Sopenharmony_ci 724e5c31af7Sopenharmony_ci 725e5c31af7Sopenharmony_ci[[textures-sparse-validation]] 726e5c31af7Sopenharmony_ci==== Sparse Validation 727e5c31af7Sopenharmony_ci 728e5c31af7Sopenharmony_ciIf the texel reads from an unbound region of a sparse image, the texel is a 729e5c31af7Sopenharmony_ci_sparse unbound texel_, and processing continues with 730e5c31af7Sopenharmony_ci<<textures-texel-replacement,texel replacement>>. 731e5c31af7Sopenharmony_ci 732e5c31af7Sopenharmony_ci 733e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_1,VK_KHR_sampler_ycbcr_conversion[] 734e5c31af7Sopenharmony_ci[[textures-layout-validation]] 735e5c31af7Sopenharmony_ci==== Layout Validation 736e5c31af7Sopenharmony_ci 737e5c31af7Sopenharmony_ciIf all planes of a _disjoint_ _multi-planar_ image are not in the same 738e5c31af7Sopenharmony_ci<<resources-image-layouts,image layout>>, the image must: not be sampled 739e5c31af7Sopenharmony_ciwith <<samplers-YCbCr-conversion,sampler {YCbCr} conversion>> enabled. 740e5c31af7Sopenharmony_ci 741e5c31af7Sopenharmony_ciendif::VK_VERSION_1_1,VK_KHR_sampler_ycbcr_conversion[] 742e5c31af7Sopenharmony_ci 743e5c31af7Sopenharmony_ci 744e5c31af7Sopenharmony_ci[[textures-format-conversion]] 745e5c31af7Sopenharmony_ci=== Format Conversion 746e5c31af7Sopenharmony_ci 747e5c31af7Sopenharmony_ciTexels undergo a format conversion from the elink:VkFormat of the image view 748e5c31af7Sopenharmony_cito a vector of either floating point or signed or unsigned integer 749e5c31af7Sopenharmony_cicomponents, with the number of components based on the number of components 750e5c31af7Sopenharmony_cipresent in the format. 751e5c31af7Sopenharmony_ci 752e5c31af7Sopenharmony_ci * Color formats have one, two, three, or four components, according to the 753e5c31af7Sopenharmony_ci format. 754e5c31af7Sopenharmony_ci * Depth/stencil formats are one component. 755e5c31af7Sopenharmony_ci The depth or stencil component is selected by the pname:aspectMask of 756e5c31af7Sopenharmony_ci the image view. 757e5c31af7Sopenharmony_ci 758e5c31af7Sopenharmony_ciEach component is converted based on its type and size (as defined in the 759e5c31af7Sopenharmony_ci<<formats-definition,Format Definition>> section for each elink:VkFormat), 760e5c31af7Sopenharmony_ciusing the appropriate equations in <<fundamentals-fp16,16-Bit Floating-Point 761e5c31af7Sopenharmony_ciNumbers>>, <<fundamentals-fp11,Unsigned 11-Bit Floating-Point Numbers>>, 762e5c31af7Sopenharmony_ci<<fundamentals-fp10,Unsigned 10-Bit Floating-Point Numbers>>, 763e5c31af7Sopenharmony_ci<<fundamentals-fixedconv,Fixed-Point Data Conversion>>, and 764e5c31af7Sopenharmony_ci<<textures-sexp-RGB,Shared Exponent to RGB>>. 765e5c31af7Sopenharmony_ciSigned integer components smaller than 32 bits are sign-extended. 766e5c31af7Sopenharmony_ci 767e5c31af7Sopenharmony_ciIf the image view format is sRGB, the color components are first converted 768e5c31af7Sopenharmony_cias if they are UNORM, and then sRGB to linear conversion is applied to the 769e5c31af7Sopenharmony_ciR, G, and B components as described in the "`sRGB EOTF`" section of the 770e5c31af7Sopenharmony_ci<<data-format,Khronos Data Format Specification>>. 771e5c31af7Sopenharmony_ciThe A component, if present, is unchanged. 772e5c31af7Sopenharmony_ci 773e5c31af7Sopenharmony_ciifdef::VK_QCOM_ycbcr_degamma[] 774e5c31af7Sopenharmony_ci[[textures-ycbcr-degamma]] 775e5c31af7Sopenharmony_ciIf 776e5c31af7Sopenharmony_cislink:VkSamplerYcbcrConversionYcbcrDegammaCreateInfoQCOM::pname:enableYDegamma 777e5c31af7Sopenharmony_ciis equal to ename:VK_TRUE, then sRGB to linear conversion is applied to the 778e5c31af7Sopenharmony_ciG component as described in the "`sRGB EOTF`" section of the 779e5c31af7Sopenharmony_ci<<data-format,Khronos Data Format Specification>>. 780e5c31af7Sopenharmony_ciIf 781e5c31af7Sopenharmony_cislink:VkSamplerYcbcrConversionYcbcrDegammaCreateInfoQCOM::pname:enableCbCrDegamma 782e5c31af7Sopenharmony_ciis equal to ename:VK_TRUE, then sRGB to linear conversion is applied to the 783e5c31af7Sopenharmony_ciR and B components as described in the "`sRGB EOTF`" section of the 784e5c31af7Sopenharmony_ci<<data-format,Khronos Data Format Specification>>. 785e5c31af7Sopenharmony_ciThe A component, if present, is unchanged. 786e5c31af7Sopenharmony_ciendif::VK_QCOM_ycbcr_degamma[] 787e5c31af7Sopenharmony_ci 788e5c31af7Sopenharmony_ciIf the image view format is block-compressed, then the texel value is first 789e5c31af7Sopenharmony_cidecoded, then converted based on the type and number of components defined 790e5c31af7Sopenharmony_ciby the compressed format. 791e5c31af7Sopenharmony_ci 792e5c31af7Sopenharmony_ci 793e5c31af7Sopenharmony_ci[[textures-texel-replacement]] 794e5c31af7Sopenharmony_ci=== Texel Replacement 795e5c31af7Sopenharmony_ci 796e5c31af7Sopenharmony_ciA texel is replaced if it is one (and only one) of: 797e5c31af7Sopenharmony_ci 798e5c31af7Sopenharmony_ci * a border texel, 799e5c31af7Sopenharmony_ci * an invalid texel, or 800e5c31af7Sopenharmony_ci * a sparse unbound texel. 801e5c31af7Sopenharmony_ci 802e5c31af7Sopenharmony_ciBorder texels are replaced with a value based on the image format and the 803e5c31af7Sopenharmony_cipname:borderColor of the sampler. 804e5c31af7Sopenharmony_ciThe border color is: 805e5c31af7Sopenharmony_ci 806e5c31af7Sopenharmony_ci[[textures-border-replacement-color]] 807e5c31af7Sopenharmony_ciifdef::VK_EXT_custom_border_color[] 808e5c31af7Sopenharmony_ci.Border Color [eq]#B#, Custom Border Color slink:VkSamplerCustomBorderColorCreateInfoEXT::pname:customBorderColor [eq]#U# 809e5c31af7Sopenharmony_ciendif::VK_EXT_custom_border_color[] 810e5c31af7Sopenharmony_ciifndef::VK_EXT_custom_border_color[] 811e5c31af7Sopenharmony_ci.Border Color [eq]#B# 812e5c31af7Sopenharmony_ciendif::VK_EXT_custom_border_color[] 813e5c31af7Sopenharmony_ci[options="header",cols="60%,40%"] 814e5c31af7Sopenharmony_ci|==== 815e5c31af7Sopenharmony_ci| Sampler pname:borderColor | Corresponding Border Color 816e5c31af7Sopenharmony_ci| ename:VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK | [eq]#[B~r~, B~g~, B~b~, B~a~] = [0.0, 0.0, 0.0, 0.0]# 817e5c31af7Sopenharmony_ci| ename:VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK | [eq]#[B~r~, B~g~, B~b~, B~a~] = [0.0, 0.0, 0.0, 1.0]# 818e5c31af7Sopenharmony_ci| ename:VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE | [eq]#[B~r~, B~g~, B~b~, B~a~] = [1.0, 1.0, 1.0, 1.0]# 819e5c31af7Sopenharmony_ci| ename:VK_BORDER_COLOR_INT_TRANSPARENT_BLACK | [eq]#[B~r~, B~g~, B~b~, B~a~] = [0, 0, 0, 0]# 820e5c31af7Sopenharmony_ci| ename:VK_BORDER_COLOR_INT_OPAQUE_BLACK | [eq]#[B~r~, B~g~, B~b~, B~a~] = [0, 0, 0, 1]# 821e5c31af7Sopenharmony_ci| ename:VK_BORDER_COLOR_INT_OPAQUE_WHITE | [eq]#[B~r~, B~g~, B~b~, B~a~] = [1, 1, 1, 1]# 822e5c31af7Sopenharmony_ciifdef::VK_EXT_custom_border_color[] 823e5c31af7Sopenharmony_ci| ename:VK_BORDER_COLOR_FLOAT_CUSTOM_EXT | [eq]#[B~r~, B~g~, B~b~, B~a~] = [U~r~, U~g~, U~b~, U~a~]# 824e5c31af7Sopenharmony_ci| ename:VK_BORDER_COLOR_INT_CUSTOM_EXT | [eq]#[B~r~, B~g~, B~b~, B~a~] = [U~r~, U~g~, U~b~, U~a~]# 825e5c31af7Sopenharmony_ciendif::VK_EXT_custom_border_color[] 826e5c31af7Sopenharmony_ci|==== 827e5c31af7Sopenharmony_ci 828e5c31af7Sopenharmony_ciifdef::VK_EXT_custom_border_color[] 829e5c31af7Sopenharmony_ciThe custom border color ([eq]#U#) may: be rounded by implementations prior 830e5c31af7Sopenharmony_cito texel replacement, but the error introduced by such a rounding must: not 831e5c31af7Sopenharmony_ciexceed one ULP of the image's pname:format. 832e5c31af7Sopenharmony_ciendif::VK_EXT_custom_border_color[] 833e5c31af7Sopenharmony_ci 834e5c31af7Sopenharmony_ci[NOTE] 835e5c31af7Sopenharmony_ci.Note 836e5c31af7Sopenharmony_ci==== 837e5c31af7Sopenharmony_ciThe names etext:VK_BORDER_COLOR_*\_TRANSPARENT_BLACK, 838e5c31af7Sopenharmony_cietext:VK_BORDER_COLOR_*\_OPAQUE_BLACK, and 839e5c31af7Sopenharmony_cietext:VK_BORDER_COLOR_*_OPAQUE_WHITE are meant to describe which components 840e5c31af7Sopenharmony_ciare zeros and ones in the vocabulary of compositing, and are not meant to 841e5c31af7Sopenharmony_ciimply that the numerical value of ename:VK_BORDER_COLOR_INT_OPAQUE_WHITE is 842e5c31af7Sopenharmony_cia saturating value for integers. 843e5c31af7Sopenharmony_ci==== 844e5c31af7Sopenharmony_ci 845e5c31af7Sopenharmony_ciThis is substituted for the texel value by replacing the number of 846e5c31af7Sopenharmony_cicomponents in the image format 847e5c31af7Sopenharmony_ci 848e5c31af7Sopenharmony_ci[[textures-border-replacement-table]] 849e5c31af7Sopenharmony_ci.Border Texel Components After Replacement 850e5c31af7Sopenharmony_ci[width="100%",options="header"] 851e5c31af7Sopenharmony_ci|==== 852e5c31af7Sopenharmony_ci| Texel Aspect or Format | Component Assignment 853e5c31af7Sopenharmony_ci| Depth aspect | [eq]#D = B~r~# 854e5c31af7Sopenharmony_ciifdef::VK_EXT_custom_border_color[] 855e5c31af7Sopenharmony_ci| Stencil aspect | [eq]#S = B~r~#{sym2} 856e5c31af7Sopenharmony_ciendif::VK_EXT_custom_border_color[] 857e5c31af7Sopenharmony_ciifndef::VK_EXT_custom_border_color[] 858e5c31af7Sopenharmony_ci| Stencil aspect | [eq]#S = B~r~# 859e5c31af7Sopenharmony_ciendif::VK_EXT_custom_border_color[] 860e5c31af7Sopenharmony_ci| One component color format | [eq]#Color~r~ = B~r~# 861e5c31af7Sopenharmony_ci| Two component color format | [eq]#[Color~r~,Color~g~] = [B~r~,B~g~]# 862e5c31af7Sopenharmony_ci| Three component color format| [eq]#[Color~r~,Color~g~,Color~b~] = [B~r~,B~g~,B~b~]# 863e5c31af7Sopenharmony_ci| Four component color format | [eq]#[Color~r~,Color~g~,Color~b~,Color~a~] = [B~r~,B~g~,B~b~,B~a~]# 864e5c31af7Sopenharmony_ciifdef::VK_KHR_maintenance5[] 865e5c31af7Sopenharmony_ci| Single component alpha format | [eq]#[Color~r~,Color~g~,Color~b~, Color~a~] = [0,0,0,B~a~]# 866e5c31af7Sopenharmony_ciendif::VK_KHR_maintenance5[] 867e5c31af7Sopenharmony_ci|==== 868e5c31af7Sopenharmony_ciifdef::VK_EXT_custom_border_color[] 869e5c31af7Sopenharmony_ci{sym2} [eq]#S = B~g~# may: be substituted as the replacement method by the 870e5c31af7Sopenharmony_ciimplementation when slink:VkSamplerCreateInfo::pname:borderColor is 871e5c31af7Sopenharmony_ciename:VK_BORDER_COLOR_INT_CUSTOM_EXT and 872e5c31af7Sopenharmony_cislink:VkSamplerCustomBorderColorCreateInfoEXT::pname:format is 873e5c31af7Sopenharmony_ciename:VK_FORMAT_UNDEFINED. 874e5c31af7Sopenharmony_ciImplementations should: use [eq]#S = B~r~# as the replacement method. 875e5c31af7Sopenharmony_ciendif::VK_EXT_custom_border_color[] 876e5c31af7Sopenharmony_ci 877e5c31af7Sopenharmony_ciThe value returned by a read of an invalid texel is undefined:, unless that 878e5c31af7Sopenharmony_ciread operation is from a buffer resource and the pname:robustBufferAccess 879e5c31af7Sopenharmony_cifeature is enabled. 880e5c31af7Sopenharmony_ciIn that case, an invalid texel is replaced as described by the 881e5c31af7Sopenharmony_ci<<features-robustBufferAccess, pname:robustBufferAccess>> feature. 882e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_3,VK_EXT_image_robustness,VK_EXT_robustness2[] 883e5c31af7Sopenharmony_ciIf the access is to an image resource and the x, y, z, or layer coordinate 884e5c31af7Sopenharmony_civalidation fails and 885e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_3,VK_EXT_image_robustness[] 886e5c31af7Sopenharmony_cithe <<features-robustImageAccess, pname:robustImageAccess>> feature is 887e5c31af7Sopenharmony_cienabled, then zero must: be returned for the R, G, and B components, if 888e5c31af7Sopenharmony_cipresent. 889e5c31af7Sopenharmony_ciEither zero or one must: be returned for the A component, if present. 890e5c31af7Sopenharmony_ciifdef::VK_EXT_robustness2[If] 891e5c31af7Sopenharmony_ciendif::VK_VERSION_1_3,VK_EXT_image_robustness[] 892e5c31af7Sopenharmony_ciifdef::VK_EXT_robustness2[] 893e5c31af7Sopenharmony_ciIf the <<features-robustImageAccess2, pname:robustImageAccess2>> feature is 894e5c31af7Sopenharmony_cienabled, zero values must: be returned. 895e5c31af7Sopenharmony_ciendif::VK_EXT_robustness2[] 896e5c31af7Sopenharmony_ciIf only the sample index was invalid, the values returned are undefined:. 897e5c31af7Sopenharmony_ciendif::VK_VERSION_1_3,VK_EXT_image_robustness,VK_EXT_robustness2[] 898e5c31af7Sopenharmony_ci 899e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_3,VK_EXT_image_robustness[] 900e5c31af7Sopenharmony_ciAdditionally, if the <<features-robustImageAccess, pname:robustImageAccess>> 901e5c31af7Sopenharmony_cifeature is enabled, 902e5c31af7Sopenharmony_ciifdef::VK_EXT_robustness2[] 903e5c31af7Sopenharmony_cibut the <<features-robustImageAccess2, pname:robustImageAccess2>> feature is 904e5c31af7Sopenharmony_cinot, 905e5c31af7Sopenharmony_ciendif::VK_EXT_robustness2[] 906e5c31af7Sopenharmony_ciany invalid texels may: be expanded to four components prior to texel 907e5c31af7Sopenharmony_cireplacement. 908e5c31af7Sopenharmony_ciThis means that components not present in the image format may be replaced 909e5c31af7Sopenharmony_ciwith 0 or may undergo <<textures-conversion-to-rgba,conversion to RGBA>> as 910e5c31af7Sopenharmony_cinormal. 911e5c31af7Sopenharmony_ciendif::VK_VERSION_1_3,VK_EXT_image_robustness[] 912e5c31af7Sopenharmony_ci 913e5c31af7Sopenharmony_ciifdef::VK_EXT_robustness2[] 914e5c31af7Sopenharmony_ciLoads from a null descriptor return a four component color value of all 915e5c31af7Sopenharmony_cizeros. 916e5c31af7Sopenharmony_ciHowever, for storage images and storage texel buffers using an explicit 917e5c31af7Sopenharmony_ciSPIR-V Image Format, loads from a null descriptor may: return an alpha value 918e5c31af7Sopenharmony_ciof 1 (float or integer, depending on format) if the format does not include 919e5c31af7Sopenharmony_cialpha. 920e5c31af7Sopenharmony_ciendif::VK_EXT_robustness2[] 921e5c31af7Sopenharmony_ci 922e5c31af7Sopenharmony_ciIf the 923e5c31af7Sopenharmony_cislink:VkPhysicalDeviceSparseProperties::pname:residencyNonResidentStrict 924e5c31af7Sopenharmony_ciproperty is ename:VK_TRUE, a sparse unbound texel is replaced with 0 or 0.0 925e5c31af7Sopenharmony_civalues for integer and floating-point components of the image format, 926e5c31af7Sopenharmony_cirespectively. 927e5c31af7Sopenharmony_ci 928e5c31af7Sopenharmony_ciIf pname:residencyNonResidentStrict is ename:VK_FALSE, the value of the 929e5c31af7Sopenharmony_cisparse unbound texel is undefined:. 930e5c31af7Sopenharmony_ci 931e5c31af7Sopenharmony_ci 932e5c31af7Sopenharmony_ci[[textures-depth-compare-operation]] 933e5c31af7Sopenharmony_ci=== Depth Compare Operation 934e5c31af7Sopenharmony_ci 935e5c31af7Sopenharmony_ciIf the image view has a depth/stencil format, the depth component is 936e5c31af7Sopenharmony_ciselected by the pname:aspectMask, and the operation is an code:OpImage*Dref* 937e5c31af7Sopenharmony_ciinstruction, a depth comparison is performed. 938e5c31af7Sopenharmony_ciThe result is [eq]#1.0# if the comparison evaluates to [eq]#true#, and 939e5c31af7Sopenharmony_ci[eq]#0.0# otherwise. 940e5c31af7Sopenharmony_ciThis value replaces the depth component [eq]#D#. 941e5c31af7Sopenharmony_ci 942e5c31af7Sopenharmony_ciThe compare operation is selected by the elink:VkCompareOp value set by 943e5c31af7Sopenharmony_cislink:VkSamplerCreateInfo::pname:compareOp. 944e5c31af7Sopenharmony_ciThe reference value from the SPIR-V operand [eq]#D~ref~# and the texel depth 945e5c31af7Sopenharmony_civalue [eq]#D~tex~# are used as the _reference_ and _test_ values, 946e5c31af7Sopenharmony_cirespectively, in that operation. 947e5c31af7Sopenharmony_ci 948e5c31af7Sopenharmony_ciIf the image being sampled has an unsigned normalized fixed-point format, 949e5c31af7Sopenharmony_cithen [eq]#D~ref~# is clamped to [eq]#[0,1]# before the compare operation. 950e5c31af7Sopenharmony_ci 951e5c31af7Sopenharmony_ci 952e5c31af7Sopenharmony_ci[[textures-conversion-to-rgba]] 953e5c31af7Sopenharmony_ci=== Conversion to RGBA 954e5c31af7Sopenharmony_ci 955e5c31af7Sopenharmony_ciThe texel is expanded from one, two, or three components to four components 956e5c31af7Sopenharmony_cibased on the image base color: 957e5c31af7Sopenharmony_ci 958e5c31af7Sopenharmony_ci[[textures-texel-color-rgba-conversion-table]] 959e5c31af7Sopenharmony_ci.Texel Color After Conversion To RGBA 960e5c31af7Sopenharmony_ci[width="100%", options="header", cols="<4,<6"] 961e5c31af7Sopenharmony_ci|==== 962e5c31af7Sopenharmony_ci| Texel Aspect or Format | RGBA Color 963e5c31af7Sopenharmony_ci| Depth aspect | [eq]#[Color~r~,Color~g~,Color~b~, Color~a~] = [D,0,0,one]# 964e5c31af7Sopenharmony_ci| Stencil aspect | [eq]#[Color~r~,Color~g~,Color~b~, Color~a~] = [S,0,0,one]# 965e5c31af7Sopenharmony_ci| One component color format | [eq]#[Color~r~,Color~g~,Color~b~, Color~a~] = [Color~r~,0,0,one]# 966e5c31af7Sopenharmony_ci| Two component color format | [eq]#[Color~r~,Color~g~,Color~b~, Color~a~] = [Color~r~,Color~g~,0,one]# 967e5c31af7Sopenharmony_ci| Three component color format| [eq]#[Color~r~,Color~g~,Color~b~, Color~a~] = [Color~r~,Color~g~,Color~b~,one]# 968e5c31af7Sopenharmony_ci| Four component color format | [eq]#[Color~r~,Color~g~,Color~b~, Color~a~] = [Color~r~,Color~g~,Color~b~,Color~a~]# 969e5c31af7Sopenharmony_ciifdef::VK_KHR_maintenance5[] 970e5c31af7Sopenharmony_ci| One alpha component color format | [eq]#[Color~r~,Color~g~,Color~b~, Color~a~] = [0,0,0,Color~a~]# 971e5c31af7Sopenharmony_ciendif::VK_KHR_maintenance5[] 972e5c31af7Sopenharmony_ci|==== 973e5c31af7Sopenharmony_ci 974e5c31af7Sopenharmony_ciwhere [eq]#one = 1.0f# for floating-point formats and depth aspects, and 975e5c31af7Sopenharmony_ci[eq]#one = 1# for integer formats and stencil aspects. 976e5c31af7Sopenharmony_ci 977e5c31af7Sopenharmony_ci 978e5c31af7Sopenharmony_ci[[textures-component-swizzle]] 979e5c31af7Sopenharmony_ci=== Component Swizzle 980e5c31af7Sopenharmony_ci 981e5c31af7Sopenharmony_ciifndef::VK_VERSION_1_1,VK_KHR_sampler_ycbcr_conversion[] 982e5c31af7Sopenharmony_ciAll texel input instructions apply a _swizzle_ based on the 983e5c31af7Sopenharmony_cielink:VkComponentSwizzle enums in the pname:components member of the 984e5c31af7Sopenharmony_cislink:VkImageViewCreateInfo structure for the image being read. 985e5c31af7Sopenharmony_ciendif::VK_VERSION_1_1,VK_KHR_sampler_ycbcr_conversion[] 986e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_1,VK_KHR_sampler_ycbcr_conversion[] 987e5c31af7Sopenharmony_ciAll texel input instructions apply a _swizzle_ based on: 988e5c31af7Sopenharmony_ci 989e5c31af7Sopenharmony_ci * the elink:VkComponentSwizzle enums in the pname:components member of the 990e5c31af7Sopenharmony_ci slink:VkImageViewCreateInfo structure for the image being read if 991e5c31af7Sopenharmony_ci <<samplers-YCbCr-conversion,sampler {YCbCr} conversion>> is not enabled, 992e5c31af7Sopenharmony_ci and 993e5c31af7Sopenharmony_ci * the elink:VkComponentSwizzle enums in the pname:components member of the 994e5c31af7Sopenharmony_ci slink:VkSamplerYcbcrConversionCreateInfo structure for the 995e5c31af7Sopenharmony_ci <<samplers-YCbCr-conversion,sampler {YCbCr} conversion>> if sampler 996e5c31af7Sopenharmony_ci {YCbCr} conversion is enabled. 997e5c31af7Sopenharmony_ci 998e5c31af7Sopenharmony_ciendif::VK_VERSION_1_1,VK_KHR_sampler_ycbcr_conversion[] 999e5c31af7Sopenharmony_ci 1000e5c31af7Sopenharmony_ciThe swizzle can: rearrange the components of the texel, or substitute zero 1001e5c31af7Sopenharmony_cior one for any components. 1002e5c31af7Sopenharmony_ciIt is defined as follows for each color [eq]#component#: 1003e5c31af7Sopenharmony_ci 1004e5c31af7Sopenharmony_ci 1005e5c31af7Sopenharmony_ci[latexmath] 1006e5c31af7Sopenharmony_ci+++++++++++++++++++ 1007e5c31af7Sopenharmony_ci\begin{aligned} 1008e5c31af7Sopenharmony_ciColor'_{component} & = 1009e5c31af7Sopenharmony_ci\begin{cases} 1010e5c31af7Sopenharmony_ciColor_r & \text{for RED swizzle} \\ 1011e5c31af7Sopenharmony_ciColor_g & \text{for GREEN swizzle} \\ 1012e5c31af7Sopenharmony_ciColor_b & \text{for BLUE swizzle} \\ 1013e5c31af7Sopenharmony_ciColor_a & \text{for ALPHA swizzle} \\ 1014e5c31af7Sopenharmony_ci0 & \text{for ZERO swizzle} \\ 1015e5c31af7Sopenharmony_cione & \text{for ONE swizzle} \\ 1016e5c31af7Sopenharmony_ciidentity & \text{for IDENTITY swizzle} 1017e5c31af7Sopenharmony_ci\end{cases} 1018e5c31af7Sopenharmony_ci\end{aligned} 1019e5c31af7Sopenharmony_ci+++++++++++++++++++ 1020e5c31af7Sopenharmony_ci 1021e5c31af7Sopenharmony_ciwhere: 1022e5c31af7Sopenharmony_ci 1023e5c31af7Sopenharmony_ci[latexmath] 1024e5c31af7Sopenharmony_ci+++++++++++++++++++ 1025e5c31af7Sopenharmony_ci\begin{aligned} 1026e5c31af7Sopenharmony_cione & = 1027e5c31af7Sopenharmony_ci\begin{cases} 1028e5c31af7Sopenharmony_ci& 1.0\text{f} & \text{for floating point components} \\ 1029e5c31af7Sopenharmony_ci& 1 & \text{for integer components} \\ 1030e5c31af7Sopenharmony_ci\end{cases} 1031e5c31af7Sopenharmony_ci\\ 1032e5c31af7Sopenharmony_ciidentity & = 1033e5c31af7Sopenharmony_ci\begin{cases} 1034e5c31af7Sopenharmony_ci& Color_r & \text{for}\ component = r \\ 1035e5c31af7Sopenharmony_ci& Color_g & \text{for}\ component = g \\ 1036e5c31af7Sopenharmony_ci& Color_b & \text{for}\ component = b \\ 1037e5c31af7Sopenharmony_ci& Color_a & \text{for}\ component = a \\ 1038e5c31af7Sopenharmony_ci\end{cases} 1039e5c31af7Sopenharmony_ci\end{aligned} 1040e5c31af7Sopenharmony_ci+++++++++++++++++++ 1041e5c31af7Sopenharmony_ci 1042e5c31af7Sopenharmony_ciIf the border color is one of the etext:VK_BORDER_COLOR_*_OPAQUE_BLACK enums 1043e5c31af7Sopenharmony_ciand the elink:VkComponentSwizzle is not the 1044e5c31af7Sopenharmony_ci<<resources-image-views-identity-mappings,identity swizzle>> for all 1045e5c31af7Sopenharmony_cicomponents, the value of the texel after swizzle is undefined:. 1046e5c31af7Sopenharmony_ci 1047e5c31af7Sopenharmony_ciifndef::VK_KHR_maintenance5[] 1048e5c31af7Sopenharmony_ciIf the image view has a depth/stencil format and the 1049e5c31af7Sopenharmony_cielink:VkComponentSwizzle is ename:VK_COMPONENT_SWIZZLE_ONE, the value of the 1050e5c31af7Sopenharmony_citexel after swizzle is undefined:. 1051e5c31af7Sopenharmony_ciendif::VK_KHR_maintenance5[] 1052e5c31af7Sopenharmony_ciifdef::VK_KHR_maintenance5[] 1053e5c31af7Sopenharmony_ciIf the image view has a depth/stencil format and the 1054e5c31af7Sopenharmony_cielink:VkComponentSwizzle is ename:VK_COMPONENT_SWIZZLE_ONE, and 1055e5c31af7Sopenharmony_cisname:VkPhysicalDeviceMaintenance5PropertiesKHR::pname:depthStencilSwizzleOneSupport 1056e5c31af7Sopenharmony_ciis not set to ename:VK_TRUE, the value of the texel after swizzle is 1057e5c31af7Sopenharmony_ciundefined:. 1058e5c31af7Sopenharmony_ciendif::VK_KHR_maintenance5[] 1059e5c31af7Sopenharmony_ci 1060e5c31af7Sopenharmony_ci 1061e5c31af7Sopenharmony_ci[[textures-sparse-residency]] 1062e5c31af7Sopenharmony_ci=== Sparse Residency 1063e5c31af7Sopenharmony_ci 1064e5c31af7Sopenharmony_cicode:OpImageSparse* instructions return a structure which includes a 1065e5c31af7Sopenharmony_ci_residency code_ indicating whether any texels accessed by the instruction 1066e5c31af7Sopenharmony_ciare sparse unbound texels. 1067e5c31af7Sopenharmony_ciThis code can: be interpreted by the code:OpImageSparseTexelsResident 1068e5c31af7Sopenharmony_ciinstruction which converts the residency code to a boolean value. 1069e5c31af7Sopenharmony_ci 1070e5c31af7Sopenharmony_ci 1071e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_1,VK_KHR_sampler_ycbcr_conversion[] 1072e5c31af7Sopenharmony_ci[[textures-chroma-reconstruction]] 1073e5c31af7Sopenharmony_ci=== Chroma Reconstruction 1074e5c31af7Sopenharmony_ci 1075e5c31af7Sopenharmony_ciIn some color models, the color representation is defined in terms of 1076e5c31af7Sopenharmony_cimonochromatic light intensity (often called "`luma`") and color differences 1077e5c31af7Sopenharmony_cirelative to this intensity, often called "`chroma`". 1078e5c31af7Sopenharmony_ciIt is common for color models other than RGB to represent the chroma 1079e5c31af7Sopenharmony_cicomponents at lower spatial resolution than the luma component. 1080e5c31af7Sopenharmony_ciThis approach is used to take advantage of the eye's lower spatial 1081e5c31af7Sopenharmony_cisensitivity to color compared with its sensitivity to brightness. 1082e5c31af7Sopenharmony_ciLess commonly, the same approach is used with additive color, since the 1083e5c31af7Sopenharmony_cigreen component dominates the eye's sensitivity to light intensity and the 1084e5c31af7Sopenharmony_cispatial sensitivity to color introduced by red and blue is lower. 1085e5c31af7Sopenharmony_ci 1086e5c31af7Sopenharmony_ciLower-resolution components are "`downsampled`" by resizing them to a lower 1087e5c31af7Sopenharmony_cispatial resolution than the component representing luminance. 1088e5c31af7Sopenharmony_ciThis process is also commonly known as "`chroma subsampling`". 1089e5c31af7Sopenharmony_ciThere is one luminance sample in each texture texel, but each chrominance 1090e5c31af7Sopenharmony_cisample may be shared among several texels in one or both texture dimensions. 1091e5c31af7Sopenharmony_ci 1092e5c31af7Sopenharmony_ci * "`etext:_444`" formats do not spatially downsample chroma values 1093e5c31af7Sopenharmony_ci compared with luma: there are unique chroma samples for each texel. 1094e5c31af7Sopenharmony_ci * "`etext:_422`" formats have downsampling in the x dimension 1095e5c31af7Sopenharmony_ci (corresponding to _u_ or _s_ coordinates): they are sampled at half the 1096e5c31af7Sopenharmony_ci resolution of luma in that dimension. 1097e5c31af7Sopenharmony_ci * "`etext:_420`" formats have downsampling in the x dimension 1098e5c31af7Sopenharmony_ci (corresponding to _u_ or _s_ coordinates) and the y dimension 1099e5c31af7Sopenharmony_ci (corresponding to _v_ or _t_ coordinates): they are sampled at half the 1100e5c31af7Sopenharmony_ci resolution of luma in both dimensions. 1101e5c31af7Sopenharmony_ci 1102e5c31af7Sopenharmony_ciThe process of reconstructing a full color value for texture access involves 1103e5c31af7Sopenharmony_ciaccessing both chroma and luma values at the same location. 1104e5c31af7Sopenharmony_ciTo generate the color accurately, the values of the lower-resolution 1105e5c31af7Sopenharmony_cicomponents at the location of the luma samples must be reconstructed from 1106e5c31af7Sopenharmony_cithe lower-resolution sample locations, an operation known here as "`chroma 1107e5c31af7Sopenharmony_cireconstruction`" irrespective of the actual color model. 1108e5c31af7Sopenharmony_ci 1109e5c31af7Sopenharmony_ciThe location of the chroma samples relative to the luma coordinates is 1110e5c31af7Sopenharmony_cidetermined by the pname:xChromaOffset and pname:yChromaOffset members of the 1111e5c31af7Sopenharmony_cislink:VkSamplerYcbcrConversionCreateInfo structure used to create the 1112e5c31af7Sopenharmony_cisampler {YCbCr} conversion. 1113e5c31af7Sopenharmony_ci 1114e5c31af7Sopenharmony_ciThe following diagrams show the relationship between unnormalized (_u_,_v_) 1115e5c31af7Sopenharmony_cicoordinates and (_i_,_j_) integer texel positions in the luma component 1116e5c31af7Sopenharmony_ci(shown in black, with circles showing integer sample positions) and the 1117e5c31af7Sopenharmony_citexel coordinates of reduced-resolution chroma components, shown as crosses 1118e5c31af7Sopenharmony_ciin red. 1119e5c31af7Sopenharmony_ci 1120e5c31af7Sopenharmony_ci[NOTE] 1121e5c31af7Sopenharmony_ci.Note 1122e5c31af7Sopenharmony_ci==== 1123e5c31af7Sopenharmony_ciIf the chroma values are reconstructed at the locations of the luma samples 1124e5c31af7Sopenharmony_ciby means of interpolation, chroma samples from outside the image bounds are 1125e5c31af7Sopenharmony_cineeded; these are determined according to <<textures-wrapping-operation>>. 1126e5c31af7Sopenharmony_ciThese diagrams represent this by showing the bounds of the "`chroma texel`" 1127e5c31af7Sopenharmony_ciextending beyond the image bounds, and including additional chroma sample 1128e5c31af7Sopenharmony_cipositions where required for interpolation. 1129e5c31af7Sopenharmony_ciThe limits of a sample for etext:NEAREST sampling is shown as a grid. 1130e5c31af7Sopenharmony_ci==== 1131e5c31af7Sopenharmony_ci 1132e5c31af7Sopenharmony_ciimage::{images}/chromasamples_422_cosited.svg[align="center",title="422 downsampling, xChromaOffset=COSITED_EVEN",opts="{imageopts}"] 1133e5c31af7Sopenharmony_ci 1134e5c31af7Sopenharmony_ciimage::{images}/chromasamples_422_midpoint.svg[align="center",title="422 downsampling, xChromaOffset=MIDPOINT",opts="{imageopts}"] 1135e5c31af7Sopenharmony_ci 1136e5c31af7Sopenharmony_ciimage::{images}/chromasamples_420_xcosited_ycosited.svg[align="center",title="420 downsampling, xChromaOffset=COSITED_EVEN, yChromaOffset=COSITED_EVEN",opts="{imageopts}"] 1137e5c31af7Sopenharmony_ci 1138e5c31af7Sopenharmony_ciimage::{images}/chromasamples_420_xmidpoint_ycosited.svg[align="center",title="420 downsampling, xChromaOffset=MIDPOINT, yChromaOffset=COSITED_EVEN",opts="{imageopts}"] 1139e5c31af7Sopenharmony_ci 1140e5c31af7Sopenharmony_ciimage::{images}/chromasamples_420_xcosited_ymidpoint.svg[align="center",title="420 downsampling, xChromaOffset=COSITED_EVEN, yChromaOffset=MIDPOINT",opts="{imageopts}"] 1141e5c31af7Sopenharmony_ci 1142e5c31af7Sopenharmony_ciimage::{images}/chromasamples_420_xmidpoint_ymidpoint.svg[align="center",title="420 downsampling, xChromaOffset=MIDPOINT, yChromaOffset=MIDPOINT",opts="{imageopts}"] 1143e5c31af7Sopenharmony_ci 1144e5c31af7Sopenharmony_ciReconstruction is implemented in one of two ways: 1145e5c31af7Sopenharmony_ci 1146e5c31af7Sopenharmony_ciIf the format of the image that is to be sampled sets 1147e5c31af7Sopenharmony_ciename:VK_FORMAT_FEATURE_SAMPLED_IMAGE_YCBCR_CONVERSION_CHROMA_RECONSTRUCTION_EXPLICIT_BIT, 1148e5c31af7Sopenharmony_cior the slink:VkSamplerYcbcrConversionCreateInfo's 1149e5c31af7Sopenharmony_cipname:forceExplicitReconstruction is set to ename:VK_TRUE, reconstruction is 1150e5c31af7Sopenharmony_ciperformed as an explicit step independent of filtering, described in the 1151e5c31af7Sopenharmony_ci<<textures-explicit-reconstruction>> section. 1152e5c31af7Sopenharmony_ci 1153e5c31af7Sopenharmony_ciIf the format of the image that is to be sampled does not set 1154e5c31af7Sopenharmony_ciename:VK_FORMAT_FEATURE_SAMPLED_IMAGE_YCBCR_CONVERSION_CHROMA_RECONSTRUCTION_EXPLICIT_BIT 1155e5c31af7Sopenharmony_ciand if the slink:VkSamplerYcbcrConversionCreateInfo's 1156e5c31af7Sopenharmony_cipname:forceExplicitReconstruction is set to ename:VK_FALSE, reconstruction 1157e5c31af7Sopenharmony_ciis performed as an implicit part of filtering prior to color model 1158e5c31af7Sopenharmony_ciconversion, with no separate post-conversion texel filtering step, as 1159e5c31af7Sopenharmony_cidescribed in the <<textures-implict-reconstruction,Implicit Reconstruction>> 1160e5c31af7Sopenharmony_cisection. 1161e5c31af7Sopenharmony_ci 1162e5c31af7Sopenharmony_ci 1163e5c31af7Sopenharmony_ci[[textures-explicit-reconstruction]] 1164e5c31af7Sopenharmony_ci==== Explicit Reconstruction 1165e5c31af7Sopenharmony_ci 1166e5c31af7Sopenharmony_ci * If the pname:chromaFilter member of the 1167e5c31af7Sopenharmony_ci slink:VkSamplerYcbcrConversionCreateInfo structure is 1168e5c31af7Sopenharmony_ci ename:VK_FILTER_NEAREST: 1169e5c31af7Sopenharmony_ci ** If the format's R and B components are reduced in resolution in just 1170e5c31af7Sopenharmony_ci width by a factor of two relative to the G component (i.e. this is a 1171e5c31af7Sopenharmony_ci "`etext:_422`" format), the latexmath:[\tau_{ijk}[level\]] values 1172e5c31af7Sopenharmony_ci accessed by <<textures-texel-filtering,texel filtering>> are 1173e5c31af7Sopenharmony_ci reconstructed as follows: 1174e5c31af7Sopenharmony_ci+ 1175e5c31af7Sopenharmony_ci[latexmath] 1176e5c31af7Sopenharmony_ci++++++++++++++ 1177e5c31af7Sopenharmony_ci\begin{aligned} 1178e5c31af7Sopenharmony_ci\tau_R'(i, j) & = \tau_R(\left\lfloor{i\times 0.5}\right\rfloor, j)[level] \\ 1179e5c31af7Sopenharmony_ci\tau_B'(i, j) & = \tau_B(\left\lfloor{i\times 0.5}\right\rfloor, j)[level] 1180e5c31af7Sopenharmony_ci\end{aligned} 1181e5c31af7Sopenharmony_ci++++++++++++++ 1182e5c31af7Sopenharmony_ci 1183e5c31af7Sopenharmony_ci ** If the format's R and B components are reduced in resolution in width 1184e5c31af7Sopenharmony_ci and height by a factor of two relative to the G component (i.e. this is 1185e5c31af7Sopenharmony_ci a "`etext:_420`" format), the latexmath:[\tau_{ijk}[level\]] values 1186e5c31af7Sopenharmony_ci accessed by <<textures-texel-filtering,texel filtering>> are 1187e5c31af7Sopenharmony_ci reconstructed as follows: 1188e5c31af7Sopenharmony_ci+ 1189e5c31af7Sopenharmony_ci[latexmath] 1190e5c31af7Sopenharmony_ci++++++++++++++ 1191e5c31af7Sopenharmony_ci\begin{aligned} 1192e5c31af7Sopenharmony_ci\tau_R'(i, j) & = \tau_R(\left\lfloor{i\times 0.5}\right\rfloor, \left\lfloor{j\times 0.5}\right\rfloor)[level] \\ 1193e5c31af7Sopenharmony_ci\tau_B'(i, j) & = \tau_B(\left\lfloor{i\times 0.5}\right\rfloor, \left\lfloor{j\times 0.5}\right\rfloor)[level] 1194e5c31af7Sopenharmony_ci\end{aligned} 1195e5c31af7Sopenharmony_ci++++++++++++++ 1196e5c31af7Sopenharmony_ci+ 1197e5c31af7Sopenharmony_ci[NOTE] 1198e5c31af7Sopenharmony_ci.Note 1199e5c31af7Sopenharmony_ci==== 1200e5c31af7Sopenharmony_cipname:xChromaOffset and pname:yChromaOffset have no effect if 1201e5c31af7Sopenharmony_cipname:chromaFilter is ename:VK_FILTER_NEAREST for explicit reconstruction. 1202e5c31af7Sopenharmony_ci==== 1203e5c31af7Sopenharmony_ci 1204e5c31af7Sopenharmony_ci * If the pname:chromaFilter member of the 1205e5c31af7Sopenharmony_ci slink:VkSamplerYcbcrConversionCreateInfo structure is 1206e5c31af7Sopenharmony_ci ename:VK_FILTER_LINEAR: 1207e5c31af7Sopenharmony_ci ** If the format's R and B components are reduced in resolution in just 1208e5c31af7Sopenharmony_ci width by a factor of two relative to the G component (i.e. this is a 1209e5c31af7Sopenharmony_ci "`etext:_422`" format): 1210e5c31af7Sopenharmony_ci *** If pname:xChromaOffset is ename:VK_CHROMA_LOCATION_COSITED_EVEN: 1211e5c31af7Sopenharmony_ci+ 1212e5c31af7Sopenharmony_ci[latexmath] 1213e5c31af7Sopenharmony_ci+++++ 1214e5c31af7Sopenharmony_ci\tau_{RB}'(i,j) = \begin{cases} 1215e5c31af7Sopenharmony_ci\tau_{RB}(\left\lfloor{i\times 0.5}\right\rfloor,j)[level], & 0.5 \times i = \left\lfloor{0.5 \times i}\right\rfloor\\ 1216e5c31af7Sopenharmony_ci0.5\times\tau_{RB}(\left\lfloor{i\times 0.5}\right\rfloor,j)[level] + \\ 1217e5c31af7Sopenharmony_ci0.5\times\tau_{RB}(\left\lfloor{i\times 0.5}\right\rfloor + 1,j)[level], & 0.5 \times i \neq \left\lfloor{0.5 \times i}\right\rfloor 1218e5c31af7Sopenharmony_ci\end{cases} 1219e5c31af7Sopenharmony_ci+++++ 1220e5c31af7Sopenharmony_ci+ 1221e5c31af7Sopenharmony_ci *** If pname:xChromaOffset is ename:VK_CHROMA_LOCATION_MIDPOINT: 1222e5c31af7Sopenharmony_ci+ 1223e5c31af7Sopenharmony_ci[latexmath] 1224e5c31af7Sopenharmony_ci+++++ 1225e5c31af7Sopenharmony_ci\tau_{RB}'(i,j) = \begin{cases} 1226e5c31af7Sopenharmony_ci0.25 \times \tau_{RB}(\left\lfloor{i\times 0.5}\right\rfloor - 1,j)[level] + \\ 1227e5c31af7Sopenharmony_ci0.75 \times \tau_{RB}(\left\lfloor{i\times 0.5}\right\rfloor,j)[level], & 0.5 \times i = \left\lfloor{0.5 \times i}\right\rfloor\\ 1228e5c31af7Sopenharmony_ci0.75 \times \tau_{RB}(\left\lfloor{i\times 0.5}\right\rfloor,j)[level] + \\ 1229e5c31af7Sopenharmony_ci0.25 \times \tau_{RB}(\left\lfloor{i\times 0.5}\right\rfloor + 1,j)[level], & 0.5 \times i \neq \left\lfloor{0.5 \times i}\right\rfloor 1230e5c31af7Sopenharmony_ci\end{cases} 1231e5c31af7Sopenharmony_ci+++++ 1232e5c31af7Sopenharmony_ci 1233e5c31af7Sopenharmony_ci ** If the format's R and B components are reduced in resolution in width 1234e5c31af7Sopenharmony_ci and height by a factor of two relative to the G component (i.e. this is 1235e5c31af7Sopenharmony_ci a "`etext:_420`" format), a similar relationship applies. 1236e5c31af7Sopenharmony_ci Due to the number of options, these formulae are expressed more 1237e5c31af7Sopenharmony_ci concisely as follows: 1238e5c31af7Sopenharmony_ci+ 1239e5c31af7Sopenharmony_ci[latexmath] 1240e5c31af7Sopenharmony_ci+++++ 1241e5c31af7Sopenharmony_ci\begin{aligned} 1242e5c31af7Sopenharmony_ci i_{RB} & = 1243e5c31af7Sopenharmony_ci \begin{cases} 1244e5c31af7Sopenharmony_ci 0.5 \times (i) & \textrm{xChromaOffset = COSITED}\_\textrm{EVEN} \\ 1245e5c31af7Sopenharmony_ci 0.5 \times (i - 0.5) & \textrm{xChromaOffset = MIDPOINT} 1246e5c31af7Sopenharmony_ci \end{cases}\\ 1247e5c31af7Sopenharmony_ci j_{RB} & = 1248e5c31af7Sopenharmony_ci \begin{cases} 1249e5c31af7Sopenharmony_ci 0.5 \times (j) & \textrm{yChromaOffset = COSITED}\_\textrm{EVEN} \\ 1250e5c31af7Sopenharmony_ci 0.5 \times (j - 0.5) & \textrm{yChromaOffset = MIDPOINT} 1251e5c31af7Sopenharmony_ci \end{cases}\\ 1252e5c31af7Sopenharmony_ci \\ 1253e5c31af7Sopenharmony_ci i_{floor} & = \left\lfloor i_{RB} \right\rfloor \\ 1254e5c31af7Sopenharmony_ci j_{floor} & = \left\lfloor j_{RB} \right\rfloor \\ 1255e5c31af7Sopenharmony_ci \\ 1256e5c31af7Sopenharmony_ci i_{frac} & = i_{RB} - i_{floor} \\ 1257e5c31af7Sopenharmony_ci j_{frac} & = j_{RB} - j_{floor} 1258e5c31af7Sopenharmony_ci\end{aligned} 1259e5c31af7Sopenharmony_ci+++++ 1260e5c31af7Sopenharmony_ci+ 1261e5c31af7Sopenharmony_ci[latexmath] 1262e5c31af7Sopenharmony_ci+++++ 1263e5c31af7Sopenharmony_ci\begin{aligned} 1264e5c31af7Sopenharmony_ci\tau_{RB}'(i,j) = 1265e5c31af7Sopenharmony_ci & \tau_{RB}( i_{floor}, j_{floor})[level] 1266e5c31af7Sopenharmony_ci & \times & ( 1 - i_{frac} ) & 1267e5c31af7Sopenharmony_ci & \times & ( 1 - j_{frac} ) & + \\ 1268e5c31af7Sopenharmony_ci & \tau_{RB}( 1 + i_{floor}, j_{floor})[level] 1269e5c31af7Sopenharmony_ci & \times & ( i_{frac} ) & 1270e5c31af7Sopenharmony_ci & \times & ( 1 - j_{frac} ) & + \\ 1271e5c31af7Sopenharmony_ci & \tau_{RB}( i_{floor}, 1 + j_{floor})[level] 1272e5c31af7Sopenharmony_ci & \times & ( 1 - i_{frac} ) & 1273e5c31af7Sopenharmony_ci & \times & ( j_{frac} ) & + \\ 1274e5c31af7Sopenharmony_ci & \tau_{RB}( 1 + i_{floor}, 1 + j_{floor})[level] 1275e5c31af7Sopenharmony_ci & \times & ( i_{frac} ) & 1276e5c31af7Sopenharmony_ci & \times & ( j_{frac} ) & 1277e5c31af7Sopenharmony_ci\end{aligned} 1278e5c31af7Sopenharmony_ci+++++ 1279e5c31af7Sopenharmony_ci 1280e5c31af7Sopenharmony_ci[NOTE] 1281e5c31af7Sopenharmony_ci.Note 1282e5c31af7Sopenharmony_ci==== 1283e5c31af7Sopenharmony_ciIn the case where the texture itself is bilinearly interpolated as described 1284e5c31af7Sopenharmony_ciin <<textures-texel-filtering,Texel Filtering>>, thus requiring four 1285e5c31af7Sopenharmony_cifull-color samples for the filtering operation, and where the reconstruction 1286e5c31af7Sopenharmony_ciof these samples uses bilinear interpolation in the chroma components due to 1287e5c31af7Sopenharmony_cipname:chromaFilter=ename:VK_FILTER_LINEAR, up to nine chroma samples may be 1288e5c31af7Sopenharmony_cirequired, depending on the sample location. 1289e5c31af7Sopenharmony_ci==== 1290e5c31af7Sopenharmony_ci 1291e5c31af7Sopenharmony_ci 1292e5c31af7Sopenharmony_ci[[textures-implict-reconstruction]] 1293e5c31af7Sopenharmony_ci==== Implicit Reconstruction 1294e5c31af7Sopenharmony_ci 1295e5c31af7Sopenharmony_ciImplicit reconstruction takes place by the samples being interpolated, as 1296e5c31af7Sopenharmony_cirequired by the filter settings of the sampler, except that 1297e5c31af7Sopenharmony_cipname:chromaFilter takes precedence for the chroma samples. 1298e5c31af7Sopenharmony_ci 1299e5c31af7Sopenharmony_ciIf pname:chromaFilter is ename:VK_FILTER_NEAREST, an implementation may: 1300e5c31af7Sopenharmony_cibehave as if pname:xChromaOffset and pname:yChromaOffset were both 1301e5c31af7Sopenharmony_ciename:VK_CHROMA_LOCATION_MIDPOINT, irrespective of the values set. 1302e5c31af7Sopenharmony_ci 1303e5c31af7Sopenharmony_ci[NOTE] 1304e5c31af7Sopenharmony_ci.Note 1305e5c31af7Sopenharmony_ci==== 1306e5c31af7Sopenharmony_ciThis will not have any visible effect if the locations of the luma samples 1307e5c31af7Sopenharmony_cicoincide with the location of the samples used for rasterization. 1308e5c31af7Sopenharmony_ci==== 1309e5c31af7Sopenharmony_ci 1310e5c31af7Sopenharmony_ciThe sample coordinates are adjusted by the downsample factor of the 1311e5c31af7Sopenharmony_cicomponent (such that, for example, the sample coordinates are divided by two 1312e5c31af7Sopenharmony_ciif the component has a downsample factor of two relative to the luma 1313e5c31af7Sopenharmony_cicomponent): 1314e5c31af7Sopenharmony_ci 1315e5c31af7Sopenharmony_ci[latexmath] 1316e5c31af7Sopenharmony_ci++++++ 1317e5c31af7Sopenharmony_ci\begin{aligned} 1318e5c31af7Sopenharmony_ciu_{RB}' (422/420) &= 1319e5c31af7Sopenharmony_ci \begin{cases} 1320e5c31af7Sopenharmony_ci 0.5\times (u + 0.5), & \textrm{xChromaOffset = COSITED}\_\textrm{EVEN} \\ 1321e5c31af7Sopenharmony_ci 0.5\times u, & \textrm{xChromaOffset = MIDPOINT} 1322e5c31af7Sopenharmony_ci \end{cases} \\ 1323e5c31af7Sopenharmony_civ_{RB}' (420) &= 1324e5c31af7Sopenharmony_ci \begin{cases} 1325e5c31af7Sopenharmony_ci 0.5\times (v + 0.5), & \textrm{yChromaOffset = COSITED}\_\textrm{EVEN} \\ 1326e5c31af7Sopenharmony_ci 0.5\times v, & \textrm{yChromaOffset = MIDPOINT} 1327e5c31af7Sopenharmony_ci \end{cases} 1328e5c31af7Sopenharmony_ci\end{aligned} 1329e5c31af7Sopenharmony_ci++++++ 1330e5c31af7Sopenharmony_ci 1331e5c31af7Sopenharmony_ci 1332e5c31af7Sopenharmony_ci[[textures-sampler-YCbCr-conversion]] 1333e5c31af7Sopenharmony_ci=== Sampler {YCbCr} Conversion 1334e5c31af7Sopenharmony_ci 1335e5c31af7Sopenharmony_ciSampler {YCbCr} conversion performs the following operations, which an 1336e5c31af7Sopenharmony_ciimplementation may: combine into a single mathematical operation: 1337e5c31af7Sopenharmony_ci 1338e5c31af7Sopenharmony_ci * <<textures-sampler-YCbCr-conversion-rangeexpand,Sampler {YCbCr} Range 1339e5c31af7Sopenharmony_ci Expansion>> 1340e5c31af7Sopenharmony_ci * <<textures-sampler-YCbCr-conversion-modelconversion,Sampler {YCbCr} 1341e5c31af7Sopenharmony_ci Model Conversion>> 1342e5c31af7Sopenharmony_ci 1343e5c31af7Sopenharmony_ci 1344e5c31af7Sopenharmony_ci[[textures-sampler-YCbCr-conversion-rangeexpand]] 1345e5c31af7Sopenharmony_ci==== Sampler {YCbCr} Range Expansion 1346e5c31af7Sopenharmony_ci 1347e5c31af7Sopenharmony_ciSampler {YCbCr} range expansion is applied to color component values after 1348e5c31af7Sopenharmony_ciall texel input operations which are not specific to sampler {YCbCr} 1349e5c31af7Sopenharmony_ciconversion. 1350e5c31af7Sopenharmony_ciFor example, the input values to this stage have been converted using the 1351e5c31af7Sopenharmony_cinormal <<textures-format-conversion,format conversion>> rules. 1352e5c31af7Sopenharmony_ci 1353e5c31af7Sopenharmony_ciifdef::VK_QCOM_ycbcr_degamma[] 1354e5c31af7Sopenharmony_ciThe input values to this stage may have been converted using sRGB to linear 1355e5c31af7Sopenharmony_ciconversion if <<features-ycbcr-degamma,pname:ycbcrDegamma>> is enabled. 1356e5c31af7Sopenharmony_ciendif::VK_QCOM_ycbcr_degamma[] 1357e5c31af7Sopenharmony_ci 1358e5c31af7Sopenharmony_ciSampler {YCbCr} range expansion is not applied if pname:ycbcrModel is 1359e5c31af7Sopenharmony_ciename:VK_SAMPLER_YCBCR_MODEL_CONVERSION_RGB_IDENTITY. 1360e5c31af7Sopenharmony_ciThat is, the shader receives the vector C'~rgba~ as output by the Component 1361e5c31af7Sopenharmony_ciSwizzle stage without further modification. 1362e5c31af7Sopenharmony_ci 1363e5c31af7Sopenharmony_ciFor other values of pname:ycbcrModel, range expansion is applied to the 1364e5c31af7Sopenharmony_citexel component values output by the <<textures-component-swizzle,Component 1365e5c31af7Sopenharmony_ciSwizzle>> defined by the pname:components member of 1366e5c31af7Sopenharmony_cislink:VkSamplerYcbcrConversionCreateInfo. 1367e5c31af7Sopenharmony_ciRange expansion applies independently to each component of the image. 1368e5c31af7Sopenharmony_ciFor the purposes of range expansion and {YCbCr} model conversion, the R and 1369e5c31af7Sopenharmony_ciB components contain color difference (chroma) values and the G component 1370e5c31af7Sopenharmony_cicontains luma. 1371e5c31af7Sopenharmony_ciThe A component is not modified by sampler {YCbCr} range expansion. 1372e5c31af7Sopenharmony_ci 1373e5c31af7Sopenharmony_ciThe range expansion to be applied is defined by the pname:ycbcrRange member 1374e5c31af7Sopenharmony_ciof the slink:VkSamplerYcbcrConversionCreateInfo structure: 1375e5c31af7Sopenharmony_ci 1376e5c31af7Sopenharmony_ci * If pname:ycbcrRange is ename:VK_SAMPLER_YCBCR_RANGE_ITU_FULL, the 1377e5c31af7Sopenharmony_ci following transformations are applied: 1378e5c31af7Sopenharmony_ci+ 1379e5c31af7Sopenharmony_ci[latexmath] 1380e5c31af7Sopenharmony_ci+++++++++++++++++++ 1381e5c31af7Sopenharmony_ci\begin{aligned} 1382e5c31af7Sopenharmony_ciY' &= C'_{rgba}[G] \\ 1383e5c31af7Sopenharmony_ciC_B &= C'_{rgba}[B] - {{2^{(n-1)}}\over{(2^n) - 1}} \\ 1384e5c31af7Sopenharmony_ciC_R &= C'_{rgba}[R] - {{2^{(n-1)}}\over{(2^n) - 1}} 1385e5c31af7Sopenharmony_ci\end{aligned} 1386e5c31af7Sopenharmony_ci+++++++++++++++++++ 1387e5c31af7Sopenharmony_ci+ 1388e5c31af7Sopenharmony_ci[NOTE] 1389e5c31af7Sopenharmony_ci.Note 1390e5c31af7Sopenharmony_ci==== 1391e5c31af7Sopenharmony_ciThese formulae correspond to the "`full range`" encoding in the 1392e5c31af7Sopenharmony_ci"`Quantization schemes`" chapter of the <<data-format,Khronos Data Format 1393e5c31af7Sopenharmony_ciSpecification>>. 1394e5c31af7Sopenharmony_ci 1395e5c31af7Sopenharmony_ciShould any future amendments be made to the ITU specifications from which 1396e5c31af7Sopenharmony_cithese equations are derived, the formulae used by Vulkan may: also be 1397e5c31af7Sopenharmony_ciupdated to maintain parity. 1398e5c31af7Sopenharmony_ci==== 1399e5c31af7Sopenharmony_ci * If pname:ycbcrRange is ename:VK_SAMPLER_YCBCR_RANGE_ITU_NARROW, the 1400e5c31af7Sopenharmony_ci following transformations are applied: 1401e5c31af7Sopenharmony_ci+ 1402e5c31af7Sopenharmony_ci[latexmath] 1403e5c31af7Sopenharmony_ci+++++++++++++++++++ 1404e5c31af7Sopenharmony_ci\begin{aligned} 1405e5c31af7Sopenharmony_ciY' &= {{C'_{rgba}[G] \times (2^n-1) - 16\times 2^{n-8}}\over{219\times 2^{n-8}}} \\ 1406e5c31af7Sopenharmony_ciC_B &= {{C'_{rgba}[B] \times \left(2^n-1\right) - 128\times 2^{n-8}}\over{224\times 2^{n-8}}} \\ 1407e5c31af7Sopenharmony_ciC_R &= {{C'_{rgba}[R] \times \left(2^n-1\right) - 128\times 2^{n-8}}\over{224\times 2^{n-8}}} 1408e5c31af7Sopenharmony_ci\end{aligned} 1409e5c31af7Sopenharmony_ci+++++++++++++++++++ 1410e5c31af7Sopenharmony_ci+ 1411e5c31af7Sopenharmony_ci[NOTE] 1412e5c31af7Sopenharmony_ci.Note 1413e5c31af7Sopenharmony_ci==== 1414e5c31af7Sopenharmony_ciThese formulae correspond to the "`narrow range`" encoding in the 1415e5c31af7Sopenharmony_ci"`Quantization schemes`" chapter of the <<data-format,Khronos Data Format 1416e5c31af7Sopenharmony_ciSpecification>>. 1417e5c31af7Sopenharmony_ci==== 1418e5c31af7Sopenharmony_ci * _n_ is the bit-depth of the components in the format. 1419e5c31af7Sopenharmony_ci 1420e5c31af7Sopenharmony_ciThe precision of the operations performed during range expansion must: be at 1421e5c31af7Sopenharmony_cileast that of the source format. 1422e5c31af7Sopenharmony_ci 1423e5c31af7Sopenharmony_ciAn implementation may: clamp the results of these range expansion operations 1424e5c31af7Sopenharmony_cisuch that Y{prime} falls in the range [0,1], and/or such that C~B~ and C~R~ 1425e5c31af7Sopenharmony_cifall in the range [-0.5,0.5]. 1426e5c31af7Sopenharmony_ci 1427e5c31af7Sopenharmony_ci 1428e5c31af7Sopenharmony_ci[[textures-sampler-YCbCr-conversion-modelconversion]] 1429e5c31af7Sopenharmony_ci==== Sampler {YCbCr} Model Conversion 1430e5c31af7Sopenharmony_ci 1431e5c31af7Sopenharmony_ciThe range-expanded values are converted between color models, according to 1432e5c31af7Sopenharmony_cithe color model conversion specified in the pname:ycbcrModel member: 1433e5c31af7Sopenharmony_ci 1434e5c31af7Sopenharmony_ciename:VK_SAMPLER_YCBCR_MODEL_CONVERSION_RGB_IDENTITY:: 1435e5c31af7Sopenharmony_ci The color components are not modified by the color model conversion 1436e5c31af7Sopenharmony_ci since they are assumed already to represent the desired color model in 1437e5c31af7Sopenharmony_ci which the shader is operating; {YCbCr} range expansion is also ignored. 1438e5c31af7Sopenharmony_ciename:VK_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_IDENTITY:: 1439e5c31af7Sopenharmony_ci The color components are not modified by the color model conversion and 1440e5c31af7Sopenharmony_ci are assumed to be treated as though in {YCbCr} form both in memory and 1441e5c31af7Sopenharmony_ci in the shader; {YCbCr} range expansion is applied to the components as 1442e5c31af7Sopenharmony_ci for other {YCbCr} models, with the vector (C~R~,Y{prime},C~B~,A) 1443e5c31af7Sopenharmony_ci provided to the shader. 1444e5c31af7Sopenharmony_ciename:VK_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_709:: 1445e5c31af7Sopenharmony_ci The color components are transformed from a {YCbCr} representation to an 1446e5c31af7Sopenharmony_ci {RGBprime} representation as described in the "`BT.709 {YCbCr} 1447e5c31af7Sopenharmony_ci conversion`" section of the <<data-format,Khronos Data Format 1448e5c31af7Sopenharmony_ci Specification>>. 1449e5c31af7Sopenharmony_ciename:VK_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_601:: 1450e5c31af7Sopenharmony_ci The color components are transformed from a {YCbCr} representation to an 1451e5c31af7Sopenharmony_ci {RGBprime} representation as described in the "`BT.601 {YCbCr} 1452e5c31af7Sopenharmony_ci conversion`" section of the <<data-format,Khronos Data Format 1453e5c31af7Sopenharmony_ci Specification>>. 1454e5c31af7Sopenharmony_ciename:VK_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_2020:: 1455e5c31af7Sopenharmony_ci The color components are transformed from a {YCbCr} representation to an 1456e5c31af7Sopenharmony_ci {RGBprime} representation as described in the "`BT.2020 {YCbCr} 1457e5c31af7Sopenharmony_ci conversion`" section of the <<data-format,Khronos Data Format 1458e5c31af7Sopenharmony_ci Specification>>. 1459e5c31af7Sopenharmony_ci 1460e5c31af7Sopenharmony_ciIn this operation, each output component is dependent on each input 1461e5c31af7Sopenharmony_cicomponent. 1462e5c31af7Sopenharmony_ci 1463e5c31af7Sopenharmony_ciAn implementation may: clamp the {RGBprime} results of these conversions to 1464e5c31af7Sopenharmony_cithe range [0,1]. 1465e5c31af7Sopenharmony_ci 1466e5c31af7Sopenharmony_ciThe precision of the operations performed during model conversion must: be 1467e5c31af7Sopenharmony_ciat least that of the source format. 1468e5c31af7Sopenharmony_ci 1469e5c31af7Sopenharmony_ciThe alpha component is not modified by these model conversions. 1470e5c31af7Sopenharmony_ci 1471e5c31af7Sopenharmony_ci[NOTE] 1472e5c31af7Sopenharmony_ci.Note 1473e5c31af7Sopenharmony_ci==== 1474e5c31af7Sopenharmony_ciSampling operations in a non-linear color space can introduce color and 1475e5c31af7Sopenharmony_ciintensity shifts at sharp transition boundaries. 1476e5c31af7Sopenharmony_ciTo avoid this issue, the technically precise color correction sequence 1477e5c31af7Sopenharmony_cidescribed in the "`Introduction to Color Conversions`" chapter of the 1478e5c31af7Sopenharmony_ci<<data-format,Khronos Data Format Specification>> may be performed as 1479e5c31af7Sopenharmony_cifollows: 1480e5c31af7Sopenharmony_ci 1481e5c31af7Sopenharmony_ci * Calculate the <<textures-normalized-to-unnormalized,unnormalized texel 1482e5c31af7Sopenharmony_ci coordinates>> corresponding to the desired sample position. 1483e5c31af7Sopenharmony_ci * For a pname:minFilter or pname:magFilter of ename:VK_FILTER_NEAREST: 1484e5c31af7Sopenharmony_ci . Calculate (_i_,_j_) for the sample location as described under the 1485e5c31af7Sopenharmony_ci "`nearest filtering`" formulae in <<textures-unnormalized-to-integer>> 1486e5c31af7Sopenharmony_ci . Calculate the normalized texel coordinates corresponding to these 1487e5c31af7Sopenharmony_ci integer coordinates. 1488e5c31af7Sopenharmony_ci . Sample using <<samplers-YCbCr-conversion,sampler {YCbCr} conversion>> 1489e5c31af7Sopenharmony_ci at this location. 1490e5c31af7Sopenharmony_ci * For a pname:minFilter or pname:magFilter of ename:VK_FILTER_LINEAR: 1491e5c31af7Sopenharmony_ci . Calculate (_i~[0,1]~_,_j~[0,1]~_) for the sample location as described 1492e5c31af7Sopenharmony_ci under the "`linear filtering`" formulae in 1493e5c31af7Sopenharmony_ci <<textures-unnormalized-to-integer>> 1494e5c31af7Sopenharmony_ci . Calculate the normalized texel coordinates corresponding to these 1495e5c31af7Sopenharmony_ci integer coordinates. 1496e5c31af7Sopenharmony_ci . Sample using <<samplers-YCbCr-conversion,sampler {YCbCr} conversion>> 1497e5c31af7Sopenharmony_ci at each of these locations. 1498e5c31af7Sopenharmony_ci . Convert the non-linear A{prime}{RGBprime} outputs of the {YCbCr} 1499e5c31af7Sopenharmony_ci conversions to linear ARGB values as described in the "`Transfer 1500e5c31af7Sopenharmony_ci Functions`" chapter of the <<data-format,Khronos Data Format 1501e5c31af7Sopenharmony_ci Specification>>. 1502e5c31af7Sopenharmony_ci . Interpolate the linear ARGB values using the [eq]#{alpha}# and 1503e5c31af7Sopenharmony_ci [eq]#{beta}# values described in the "`linear filtering`" section of 1504e5c31af7Sopenharmony_ci <<textures-unnormalized-to-integer>> and the equations in 1505e5c31af7Sopenharmony_ci <<textures-texel-filtering>>. 1506e5c31af7Sopenharmony_ci 1507e5c31af7Sopenharmony_ciThe additional calculations and, especially, additional number of sampling 1508e5c31af7Sopenharmony_cioperations in the ename:VK_FILTER_LINEAR case can be expected to have a 1509e5c31af7Sopenharmony_ciperformance impact compared with using the outputs directly. 1510e5c31af7Sopenharmony_ciSince the variations from "`correct`" results are subtle for most content, 1511e5c31af7Sopenharmony_cithe application author should determine whether a more costly implementation 1512e5c31af7Sopenharmony_ciis strictly necessary. 1513e5c31af7Sopenharmony_ci 1514e5c31af7Sopenharmony_ciIf pname:chromaFilter, and pname:minFilter or pname:magFilter are both 1515e5c31af7Sopenharmony_ciename:VK_FILTER_NEAREST, these operations are redundant and sampling using 1516e5c31af7Sopenharmony_ci<<samplers-YCbCr-conversion,sampler {YCbCr} conversion>> at the desired 1517e5c31af7Sopenharmony_cisample coordinates will produce the "`correct`" results without further 1518e5c31af7Sopenharmony_ciprocessing. 1519e5c31af7Sopenharmony_ci==== 1520e5c31af7Sopenharmony_ciendif::VK_VERSION_1_1,VK_KHR_sampler_ycbcr_conversion[] 1521e5c31af7Sopenharmony_ci 1522e5c31af7Sopenharmony_ci 1523e5c31af7Sopenharmony_ci== Texel Output Operations 1524e5c31af7Sopenharmony_ci 1525e5c31af7Sopenharmony_ci_Texel output instructions_ are SPIR-V image instructions that write to an 1526e5c31af7Sopenharmony_ciimage. 1527e5c31af7Sopenharmony_ci_Texel output operations_ are a set of steps that are performed on state, 1528e5c31af7Sopenharmony_cicoordinates, and texel values while processing a texel output instruction, 1529e5c31af7Sopenharmony_ciand which are common to some or all texel output instructions. 1530e5c31af7Sopenharmony_ciThey include the following steps, which are performed in the listed order: 1531e5c31af7Sopenharmony_ci 1532e5c31af7Sopenharmony_ci * <<textures-output-validation,Validation operations>> 1533e5c31af7Sopenharmony_ci ** <<textures-format-validation,Format validation>> 1534e5c31af7Sopenharmony_ci ** <<textures-type-validation,Type validation>> 1535e5c31af7Sopenharmony_ci ** <<textures-output-coordinate-validation,Coordinate validation>> 1536e5c31af7Sopenharmony_ci ** <<textures-output-sparse-validation,Sparse validation>> 1537e5c31af7Sopenharmony_ci * <<textures-output-format-conversion,Texel output format conversion>> 1538e5c31af7Sopenharmony_ci 1539e5c31af7Sopenharmony_ci 1540e5c31af7Sopenharmony_ci[[textures-output-validation]] 1541e5c31af7Sopenharmony_ci=== Texel Output Validation Operations 1542e5c31af7Sopenharmony_ci 1543e5c31af7Sopenharmony_ci_Texel output validation operations_ inspect instruction/image state or 1544e5c31af7Sopenharmony_cicoordinates, and in certain circumstances cause the write to have no effect. 1545e5c31af7Sopenharmony_ciThere are a series of validations that the texel undergoes. 1546e5c31af7Sopenharmony_ci 1547e5c31af7Sopenharmony_ci 1548e5c31af7Sopenharmony_ci[[textures-format-validation]] 1549e5c31af7Sopenharmony_ci==== Texel Format Validation 1550e5c31af7Sopenharmony_ci 1551e5c31af7Sopenharmony_ciIf the image format of the code:OpTypeImage is not 1552e5c31af7Sopenharmony_ci<<spirvenv-image-formats,compatible>> with the sname:VkImageView's 1553e5c31af7Sopenharmony_cipname:format, the write causes the contents of the image's memory to become 1554e5c31af7Sopenharmony_ciundefined:. 1555e5c31af7Sopenharmony_ci 1556e5c31af7Sopenharmony_ci 1557e5c31af7Sopenharmony_ci[[textures-type-validation]] 1558e5c31af7Sopenharmony_ci==== Texel Type Validation 1559e5c31af7Sopenharmony_ci 1560e5c31af7Sopenharmony_ciIf the code:Sampled code:Type of the code:OpTypeImage does not match the 1561e5c31af7Sopenharmony_ci<<spirv-type,SPIR-V Type>>, the write causes the value of the texel to 1562e5c31af7Sopenharmony_cibecome undefined:. 1563e5c31af7Sopenharmony_ciFor integer types, if the <<spirvenv-image-signedness,signedness of the 1564e5c31af7Sopenharmony_ciaccess>> does not match the signedness of the accessed resource, the write 1565e5c31af7Sopenharmony_cicauses the value of the texel to become undefined:. 1566e5c31af7Sopenharmony_ci 1567e5c31af7Sopenharmony_ci 1568e5c31af7Sopenharmony_ci[[textures-output-coordinate-validation]] 1569e5c31af7Sopenharmony_ci=== Integer Texel Coordinate Validation 1570e5c31af7Sopenharmony_ci 1571e5c31af7Sopenharmony_ciThe integer texel coordinates are validated according to the same rules as 1572e5c31af7Sopenharmony_cifor texel input <<textures-integer-coordinate-validation,coordinate 1573e5c31af7Sopenharmony_civalidation>>. 1574e5c31af7Sopenharmony_ci 1575e5c31af7Sopenharmony_ciIf the texel fails integer texel coordinate validation, then the write has 1576e5c31af7Sopenharmony_cino effect. 1577e5c31af7Sopenharmony_ci 1578e5c31af7Sopenharmony_ci 1579e5c31af7Sopenharmony_ci[[textures-output-sparse-validation]] 1580e5c31af7Sopenharmony_ci=== Sparse Texel Operation 1581e5c31af7Sopenharmony_ci 1582e5c31af7Sopenharmony_ciIf the texel attempts to write to an unbound region of a sparse image, the 1583e5c31af7Sopenharmony_citexel is a sparse unbound texel. 1584e5c31af7Sopenharmony_ciIn such a case, if the 1585e5c31af7Sopenharmony_cislink:VkPhysicalDeviceSparseProperties::pname:residencyNonResidentStrict 1586e5c31af7Sopenharmony_ciproperty is ename:VK_TRUE, the sparse unbound texel write has no effect. 1587e5c31af7Sopenharmony_ciIf pname:residencyNonResidentStrict is ename:VK_FALSE, the write may: have a 1588e5c31af7Sopenharmony_ciside effect that becomes visible to other accesses to unbound texels in any 1589e5c31af7Sopenharmony_ciresource, but will not be visible to any device memory allocated by the 1590e5c31af7Sopenharmony_ciapplication. 1591e5c31af7Sopenharmony_ci 1592e5c31af7Sopenharmony_ci 1593e5c31af7Sopenharmony_ci[[textures-output-format-conversion]] 1594e5c31af7Sopenharmony_ci=== Texel Output Format Conversion 1595e5c31af7Sopenharmony_ci 1596e5c31af7Sopenharmony_ciIf the image format is sRGB, a linear to sRGB conversion is applied to the 1597e5c31af7Sopenharmony_ciR, G, and B components as described in the "`sRGB EOTF`" section of the 1598e5c31af7Sopenharmony_ci<<data-format,Khronos Data Format Specification>>. 1599e5c31af7Sopenharmony_ciThe A component, if present, is unchanged. 1600e5c31af7Sopenharmony_ci 1601e5c31af7Sopenharmony_ciTexels then undergo a format conversion from the floating point, signed, or 1602e5c31af7Sopenharmony_ciunsigned integer type of the texel data to the elink:VkFormat of the image 1603e5c31af7Sopenharmony_ciview. 1604e5c31af7Sopenharmony_ciIf the number of components in the texel data is larger than the number of 1605e5c31af7Sopenharmony_cicomponents in the format, additional components are discarded. 1606e5c31af7Sopenharmony_ci 1607e5c31af7Sopenharmony_ciEach component is converted based on its type and size (as defined in the 1608e5c31af7Sopenharmony_ci<<formats-definition,Format Definition>> section for each elink:VkFormat). 1609e5c31af7Sopenharmony_ciFloating-point outputs are converted as described in 1610e5c31af7Sopenharmony_ci<<fundamentals-fp-conversion,Floating-Point Format Conversions>> and 1611e5c31af7Sopenharmony_ci<<fundamentals-fixedconv,Fixed-Point Data Conversion>>. 1612e5c31af7Sopenharmony_ciInteger outputs are converted such that their value is preserved. 1613e5c31af7Sopenharmony_ciThe converted value of any integer that cannot be represented in the target 1614e5c31af7Sopenharmony_ciformat is undefined:. 1615e5c31af7Sopenharmony_ci 1616e5c31af7Sopenharmony_ci 1617e5c31af7Sopenharmony_ci[[textures-normalized-operations]] 1618e5c31af7Sopenharmony_ci== Normalized Texel Coordinate Operations 1619e5c31af7Sopenharmony_ci 1620e5c31af7Sopenharmony_ciIf the image sampler instruction provides normalized texel coordinates, some 1621e5c31af7Sopenharmony_ciof the following operations are performed. 1622e5c31af7Sopenharmony_ci 1623e5c31af7Sopenharmony_ci 1624e5c31af7Sopenharmony_ci[[textures-projection]] 1625e5c31af7Sopenharmony_ci=== Projection Operation 1626e5c31af7Sopenharmony_ci 1627e5c31af7Sopenharmony_ciFor code:Proj image operations, the normalized texel coordinates 1628e5c31af7Sopenharmony_ci[eq]#(s,t,r,q,a)# and (if present) the [eq]#D~ref~# coordinate are 1629e5c31af7Sopenharmony_citransformed as follows: 1630e5c31af7Sopenharmony_ci 1631e5c31af7Sopenharmony_ci[latexmath] 1632e5c31af7Sopenharmony_ci+++++++++++++++++++ 1633e5c31af7Sopenharmony_ci\begin{aligned} 1634e5c31af7Sopenharmony_cis & = \frac{s}{q}, & \text{for 1D, 2D, or 3D image} \\ 1635e5c31af7Sopenharmony_ci\\ 1636e5c31af7Sopenharmony_cit & = \frac{t}{q}, & \text{for 2D or 3D image} \\ 1637e5c31af7Sopenharmony_ci\\ 1638e5c31af7Sopenharmony_cir & = \frac{r}{q}, & \text{for 3D image} \\ 1639e5c31af7Sopenharmony_ci\\ 1640e5c31af7Sopenharmony_ciD_{\textit{ref}} & = \frac{D_{\textit{ref}}}{q}, & \text{if provided} 1641e5c31af7Sopenharmony_ci\end{aligned} 1642e5c31af7Sopenharmony_ci+++++++++++++++++++ 1643e5c31af7Sopenharmony_ci 1644e5c31af7Sopenharmony_ci 1645e5c31af7Sopenharmony_ci[[textures-derivative-image-operations]] 1646e5c31af7Sopenharmony_ci=== Derivative Image Operations 1647e5c31af7Sopenharmony_ci 1648e5c31af7Sopenharmony_ciDerivatives are used for LOD selection. 1649e5c31af7Sopenharmony_ciThese derivatives are either implicit (in an code:ImplicitLod image 1650e5c31af7Sopenharmony_ciinstruction in a fragment shader) or explicit (provided explicitly by shader 1651e5c31af7Sopenharmony_cito the image instruction in any shader). 1652e5c31af7Sopenharmony_ci 1653e5c31af7Sopenharmony_ciFor implicit derivatives image instructions, the derivatives of texel 1654e5c31af7Sopenharmony_cicoordinates are calculated in the same manner as 1655e5c31af7Sopenharmony_ci<<shaders-derivative-operations, derivative operations>>. 1656e5c31af7Sopenharmony_ciThat is: 1657e5c31af7Sopenharmony_ci 1658e5c31af7Sopenharmony_ci[latexmath] 1659e5c31af7Sopenharmony_ci+++++++++++++++++++ 1660e5c31af7Sopenharmony_ci\begin{aligned} 1661e5c31af7Sopenharmony_ci\partial{s}/\partial{x} & = dPdx(s), & \partial{s}/\partial{y} & = dPdy(s), & \text{for 1D, 2D, Cube, or 3D image} \\ 1662e5c31af7Sopenharmony_ci\partial{t}/\partial{x} & = dPdx(t), & \partial{t}/\partial{y} & = dPdy(t), & \text{for 2D, Cube, or 3D image} \\ 1663e5c31af7Sopenharmony_ci\partial{r}/\partial{x} & = dPdx(r), & \partial{r}/\partial{y} & = dPdy(r), & \text{for Cube or 3D image} 1664e5c31af7Sopenharmony_ci\end{aligned} 1665e5c31af7Sopenharmony_ci+++++++++++++++++++ 1666e5c31af7Sopenharmony_ci 1667e5c31af7Sopenharmony_ciPartial derivatives not defined above for certain image dimensionalities are 1668e5c31af7Sopenharmony_ciset to zero. 1669e5c31af7Sopenharmony_ci 1670e5c31af7Sopenharmony_ciFor explicit LOD image instructions, if the optional: SPIR-V operand 1671e5c31af7Sopenharmony_cicode:Grad is provided, then the operand values are used for the derivatives. 1672e5c31af7Sopenharmony_ciThe number of components present in each derivative for a given image 1673e5c31af7Sopenharmony_cidimensionality matches the number of partial derivatives computed above. 1674e5c31af7Sopenharmony_ci 1675e5c31af7Sopenharmony_ciIf the optional: SPIR-V operand code:Lod is provided, then derivatives are 1676e5c31af7Sopenharmony_ciset to zero, the cube map derivative transformation is skipped, and the 1677e5c31af7Sopenharmony_ciscale factor operation is skipped. 1678e5c31af7Sopenharmony_ciInstead, the floating point scalar coordinate is directly assigned to 1679e5c31af7Sopenharmony_ci[eq]#{lambda}~base~# as described in <<textures-level-of-detail-operation, 1680e5c31af7Sopenharmony_ciLOD Operation>>. 1681e5c31af7Sopenharmony_ci 1682e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_2,VK_EXT_descriptor_indexing[] 1683e5c31af7Sopenharmony_ciIf the image or sampler object used by an implicit derivative image 1684e5c31af7Sopenharmony_ciinstruction is not uniform across the quad and 1685e5c31af7Sopenharmony_ci<<limits-quadDivergentImplicitLod, pname:quadDivergentImplicitLod>> is not 1686e5c31af7Sopenharmony_cisupported, then the derivative and LOD values are undefined:. 1687e5c31af7Sopenharmony_ciImplicit derivatives are well-defined when the image and sampler and control 1688e5c31af7Sopenharmony_ciflow are uniform across the quad, even if they diverge between different 1689e5c31af7Sopenharmony_ciquads. 1690e5c31af7Sopenharmony_ci 1691e5c31af7Sopenharmony_ciIf <<limits-quadDivergentImplicitLod, pname:quadDivergentImplicitLod>> is 1692e5c31af7Sopenharmony_cisupported, then derivatives and implicit LOD values are well-defined even if 1693e5c31af7Sopenharmony_cithe image or sampler object are not uniform within a quad. 1694e5c31af7Sopenharmony_ciThe derivatives are computed as specified above, and the implicit LOD 1695e5c31af7Sopenharmony_cicalculation proceeds for each shader invocation using its respective image 1696e5c31af7Sopenharmony_ciand sampler object. 1697e5c31af7Sopenharmony_ciendif::VK_VERSION_1_2,VK_EXT_descriptor_indexing[] 1698e5c31af7Sopenharmony_ci 1699e5c31af7Sopenharmony_ci 1700e5c31af7Sopenharmony_ci=== Cube Map Face Selection and Transformations 1701e5c31af7Sopenharmony_ci 1702e5c31af7Sopenharmony_ciFor cube map image instructions, the [eq]#(s,t,r)# coordinates are treated 1703e5c31af7Sopenharmony_cias a direction vector [eq]#(r~x~,r~y~,r~z~)#. 1704e5c31af7Sopenharmony_ciThe direction vector is used to select a cube map face. 1705e5c31af7Sopenharmony_ciThe direction vector is transformed to a per-face texel coordinate system 1706e5c31af7Sopenharmony_ci[eq]#(s~face~,t~face~)#, The direction vector is also used to transform the 1707e5c31af7Sopenharmony_ciderivatives to per-face derivatives. 1708e5c31af7Sopenharmony_ci 1709e5c31af7Sopenharmony_ci 1710e5c31af7Sopenharmony_ci=== Cube Map Face Selection 1711e5c31af7Sopenharmony_ci 1712e5c31af7Sopenharmony_ciThe direction vector selects one of the cube map's faces based on the 1713e5c31af7Sopenharmony_cilargest magnitude coordinate direction (the major axis direction). 1714e5c31af7Sopenharmony_ciSince two or more coordinates can: have identical magnitude, the 1715e5c31af7Sopenharmony_ciimplementation must: have rules to disambiguate this situation. 1716e5c31af7Sopenharmony_ci 1717e5c31af7Sopenharmony_ciThe rules should: have as the first rule that [eq]#r~z~# wins over 1718e5c31af7Sopenharmony_ci[eq]#r~y~# and [eq]#r~x~#, and the second rule that [eq]#r~y~# wins over 1719e5c31af7Sopenharmony_ci[eq]#r~x~#. 1720e5c31af7Sopenharmony_ciAn implementation may: choose other rules, but the rules must: be 1721e5c31af7Sopenharmony_cideterministic and depend only on [eq]#(r~x~,r~y~,r~z~)#. 1722e5c31af7Sopenharmony_ci 1723e5c31af7Sopenharmony_ciThe layer number (corresponding to a cube map face), the coordinate 1724e5c31af7Sopenharmony_ciselections for [eq]#s~c~#, [eq]#t~c~#, [eq]#r~c~#, and the selection of 1725e5c31af7Sopenharmony_ciderivatives, are determined by the major axis direction as specified in the 1726e5c31af7Sopenharmony_cifollowing two tables. 1727e5c31af7Sopenharmony_ci 1728e5c31af7Sopenharmony_ci.Cube map face and coordinate selection 1729e5c31af7Sopenharmony_ci[width="75%",frame="all",options="header"] 1730e5c31af7Sopenharmony_ci|==== 1731e5c31af7Sopenharmony_ci| Major Axis Direction | Layer Number | Cube Map Face | [eq]#s~c~# | [eq]#t~c~# | [eq]#r~c~# 1732e5c31af7Sopenharmony_ci| [eq]#+r~x~# | [eq]#0# | Positive X | [eq]#-r~z~# | [eq]#-r~y~# | [eq]#r~x~# 1733e5c31af7Sopenharmony_ci| [eq]#-r~x~# | [eq]#1# | Negative X | [eq]#+r~z~# | [eq]#-r~y~# | [eq]#r~x~# 1734e5c31af7Sopenharmony_ci| [eq]#+r~y~# | [eq]#2# | Positive Y | [eq]#+r~x~# | [eq]#+r~z~# | [eq]#r~y~# 1735e5c31af7Sopenharmony_ci| [eq]#-r~y~# | [eq]#3# | Negative Y | [eq]#+r~x~# | [eq]#-r~z~# | [eq]#r~y~# 1736e5c31af7Sopenharmony_ci| [eq]#+r~z~# | [eq]#4# | Positive Z | [eq]#+r~x~# | [eq]#-r~y~# | [eq]#r~z~# 1737e5c31af7Sopenharmony_ci| [eq]#-r~z~# | [eq]#5# | Negative Z | [eq]#-r~x~# | [eq]#-r~y~# | [eq]#r~z~# 1738e5c31af7Sopenharmony_ci|==== 1739e5c31af7Sopenharmony_ci 1740e5c31af7Sopenharmony_ci 1741e5c31af7Sopenharmony_ci.Cube map derivative selection 1742e5c31af7Sopenharmony_ci[width="75%",frame="all",options="header"] 1743e5c31af7Sopenharmony_ci|==== 1744e5c31af7Sopenharmony_ci| Major Axis Direction | [eq]#{partial}s~c~ / {partial}x# | [eq]#{partial}s~c~ / {partial}y# | [eq]#{partial}t~c~ / {partial}x# | [eq]#{partial}t~c~ / {partial}y# | [eq]#{partial}r~c~ / {partial}x# | [eq]#{partial}r~c~ / {partial}y# 1745e5c31af7Sopenharmony_ci 1746e5c31af7Sopenharmony_ci| [eq]#+r~x~# 1747e5c31af7Sopenharmony_ci| [eq]#-{partial}r~z~ / {partial}x# | [eq]#-{partial}r~z~ / {partial}y# 1748e5c31af7Sopenharmony_ci| [eq]#-{partial}r~y~ / {partial}x# | [eq]#-{partial}r~y~ / {partial}y# 1749e5c31af7Sopenharmony_ci| [eq]#+{partial}r~x~ / {partial}x# | [eq]#+{partial}r~x~ / {partial}y# 1750e5c31af7Sopenharmony_ci 1751e5c31af7Sopenharmony_ci| [eq]#-r~x~# 1752e5c31af7Sopenharmony_ci| [eq]#+{partial}r~z~ / {partial}x# | [eq]#+{partial}r~z~ / {partial}y# 1753e5c31af7Sopenharmony_ci| [eq]#-{partial}r~y~ / {partial}x# | [eq]#-{partial}r~y~ / {partial}y# 1754e5c31af7Sopenharmony_ci| [eq]#-{partial}r~x~ / {partial}x# | [eq]#-{partial}r~x~ / {partial}y# 1755e5c31af7Sopenharmony_ci 1756e5c31af7Sopenharmony_ci| [eq]#+r~y~# 1757e5c31af7Sopenharmony_ci| [eq]#+{partial}r~x~ / {partial}x# | [eq]#+{partial}r~x~ / {partial}y# 1758e5c31af7Sopenharmony_ci| [eq]#+{partial}r~z~ / {partial}x# | [eq]#+{partial}r~z~ / {partial}y# 1759e5c31af7Sopenharmony_ci| [eq]#+{partial}r~y~ / {partial}x# | [eq]#+{partial}r~y~ / {partial}y# 1760e5c31af7Sopenharmony_ci 1761e5c31af7Sopenharmony_ci| [eq]#-r~y~# 1762e5c31af7Sopenharmony_ci| [eq]#+{partial}r~x~ / {partial}x# | [eq]#+{partial}r~x~ / {partial}y# 1763e5c31af7Sopenharmony_ci| [eq]#-{partial}r~z~ / {partial}x# | [eq]#-{partial}r~z~ / {partial}y# 1764e5c31af7Sopenharmony_ci| [eq]#-{partial}r~y~ / {partial}x# | [eq]#-{partial}r~y~ / {partial}y# 1765e5c31af7Sopenharmony_ci 1766e5c31af7Sopenharmony_ci| [eq]#+r~z~# 1767e5c31af7Sopenharmony_ci| [eq]#+{partial}r~x~ / {partial}x# | [eq]#+{partial}r~x~ / {partial}y# 1768e5c31af7Sopenharmony_ci| [eq]#-{partial}r~y~ / {partial}x# | [eq]#-{partial}r~y~ / {partial}y# 1769e5c31af7Sopenharmony_ci| [eq]#+{partial}r~z~ / {partial}x# | [eq]#+{partial}r~z~ / {partial}y# 1770e5c31af7Sopenharmony_ci 1771e5c31af7Sopenharmony_ci| [eq]#-r~z~# 1772e5c31af7Sopenharmony_ci| [eq]#-{partial}r~x~ / {partial}x# | [eq]#-{partial}r~x~ / {partial}y# 1773e5c31af7Sopenharmony_ci| [eq]#-{partial}r~y~ / {partial}x# | [eq]#-{partial}r~y~ / {partial}y# 1774e5c31af7Sopenharmony_ci| [eq]#-{partial}r~z~ / {partial}x# | [eq]#-{partial}r~z~ / {partial}y# 1775e5c31af7Sopenharmony_ci|==== 1776e5c31af7Sopenharmony_ci 1777e5c31af7Sopenharmony_ci 1778e5c31af7Sopenharmony_ci=== Cube Map Coordinate Transformation 1779e5c31af7Sopenharmony_ci 1780e5c31af7Sopenharmony_ci[latexmath] 1781e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 1782e5c31af7Sopenharmony_ci\begin{aligned} 1783e5c31af7Sopenharmony_cis_{\textit{face}} & = 1784e5c31af7Sopenharmony_ci \frac{1}{2} \times \frac{s_c}{|r_c|} + \frac{1}{2} \\ 1785e5c31af7Sopenharmony_cit_{\textit{face}} & = 1786e5c31af7Sopenharmony_ci \frac{1}{2} \times \frac{t_c}{|r_c|} + \frac{1}{2} \\ 1787e5c31af7Sopenharmony_ci\end{aligned} 1788e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 1789e5c31af7Sopenharmony_ci 1790e5c31af7Sopenharmony_ci 1791e5c31af7Sopenharmony_ci=== Cube Map Derivative Transformation 1792e5c31af7Sopenharmony_ci 1793e5c31af7Sopenharmony_ci[latexmath] 1794e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 1795e5c31af7Sopenharmony_ci\begin{aligned} 1796e5c31af7Sopenharmony_ci\frac{\partial{s_{\textit{face}}}}{\partial{x}} &= 1797e5c31af7Sopenharmony_ci \frac{\partial}{\partial{x}} \left ( \frac{1}{2} \times \frac{s_{c}}{|r_{c}|} 1798e5c31af7Sopenharmony_ci + \frac{1}{2}\right ) \\ 1799e5c31af7Sopenharmony_ci\frac{\partial{s_{\textit{face}}}}{\partial{x}} &= 1800e5c31af7Sopenharmony_ci \frac{1}{2} \times \frac{\partial}{\partial{x}} 1801e5c31af7Sopenharmony_ci \left ( \frac{s_{c}}{|r_{c}|} \right ) \\ 1802e5c31af7Sopenharmony_ci\frac{\partial{s_{\textit{face}}}}{\partial{x}} &= 1803e5c31af7Sopenharmony_ci \frac{1}{2} \times 1804e5c31af7Sopenharmony_ci \left ( 1805e5c31af7Sopenharmony_ci \frac{ 1806e5c31af7Sopenharmony_ci |r_{c}| \times \partial{s_c}/\partial{x} 1807e5c31af7Sopenharmony_ci -s_c \times {\partial{r_{c}}}/{\partial{x}}} 1808e5c31af7Sopenharmony_ci {\left ( r_{c} \right )^2} 1809e5c31af7Sopenharmony_ci \right ) 1810e5c31af7Sopenharmony_ci\end{aligned} 1811e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 1812e5c31af7Sopenharmony_ci 1813e5c31af7Sopenharmony_ci[latexmath] 1814e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 1815e5c31af7Sopenharmony_ci\begin{aligned} 1816e5c31af7Sopenharmony_ci\frac{\partial{s_{\textit{face}}}}{\partial{y}} &= 1817e5c31af7Sopenharmony_ci \frac{1}{2} \times 1818e5c31af7Sopenharmony_ci \left ( 1819e5c31af7Sopenharmony_ci \frac{ 1820e5c31af7Sopenharmony_ci |r_{c}| \times \partial{s_c}/\partial{y} 1821e5c31af7Sopenharmony_ci -s_c \times {\partial{r_{c}}}/{\partial{y}}} 1822e5c31af7Sopenharmony_ci {\left ( r_{c} \right )^2} 1823e5c31af7Sopenharmony_ci \right )\\ 1824e5c31af7Sopenharmony_ci\frac{\partial{t_{\textit{face}}}}{\partial{x}} &= 1825e5c31af7Sopenharmony_ci \frac{1}{2} \times 1826e5c31af7Sopenharmony_ci \left ( 1827e5c31af7Sopenharmony_ci \frac{ 1828e5c31af7Sopenharmony_ci |r_{c}| \times \partial{t_c}/\partial{x} 1829e5c31af7Sopenharmony_ci -t_c \times {\partial{r_{c}}}/{\partial{x}}} 1830e5c31af7Sopenharmony_ci {\left ( r_{c} \right )^2} 1831e5c31af7Sopenharmony_ci \right ) \\ 1832e5c31af7Sopenharmony_ci\frac{\partial{t_{\textit{face}}}}{\partial{y}} &= 1833e5c31af7Sopenharmony_ci \frac{1}{2} \times 1834e5c31af7Sopenharmony_ci \left ( 1835e5c31af7Sopenharmony_ci \frac{ 1836e5c31af7Sopenharmony_ci |r_{c}| \times \partial{t_c}/\partial{y} 1837e5c31af7Sopenharmony_ci -t_c \times {\partial{r_{c}}}/{\partial{y}}} 1838e5c31af7Sopenharmony_ci {\left ( r_{c} \right )^2} 1839e5c31af7Sopenharmony_ci \right ) 1840e5c31af7Sopenharmony_ci\end{aligned} 1841e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 1842e5c31af7Sopenharmony_ci 1843e5c31af7Sopenharmony_ciifdef::editing-notes[] 1844e5c31af7Sopenharmony_ci[NOTE] 1845e5c31af7Sopenharmony_ci.editing-note 1846e5c31af7Sopenharmony_ci==== 1847e5c31af7Sopenharmony_ci(Bill) Note that we never revisited ARB_texture_cubemap after we introduced 1848e5c31af7Sopenharmony_cidependent texture fetches (ARB_fragment_program and ARB_fragment_shader). 1849e5c31af7Sopenharmony_ci 1850e5c31af7Sopenharmony_ciThe derivatives of [eq]#s~face~# and [eq]#t~face~# are only valid for 1851e5c31af7Sopenharmony_cinon-dependent texture fetches (pre OpenGL 2.0). 1852e5c31af7Sopenharmony_ci==== 1853e5c31af7Sopenharmony_ciendif::editing-notes[] 1854e5c31af7Sopenharmony_ci 1855e5c31af7Sopenharmony_ci 1856e5c31af7Sopenharmony_ci[[textures-lod-and-scale-factor]] 1857e5c31af7Sopenharmony_ci=== Scale Factor Operation, LOD Operation and Image Level(s) Selection 1858e5c31af7Sopenharmony_ci 1859e5c31af7Sopenharmony_ciLOD selection can: be either explicit (provided explicitly by the image 1860e5c31af7Sopenharmony_ciinstruction) or implicit (determined from a scale factor calculated from the 1861e5c31af7Sopenharmony_ciderivatives). 1862e5c31af7Sopenharmony_ciThe LOD must: be computed with pname:mipmapPrecisionBits of accuracy. 1863e5c31af7Sopenharmony_ci 1864e5c31af7Sopenharmony_ci 1865e5c31af7Sopenharmony_ci[[textures-scale-factor]] 1866e5c31af7Sopenharmony_ci==== Scale Factor Operation 1867e5c31af7Sopenharmony_ci 1868e5c31af7Sopenharmony_ciThe magnitude of the derivatives are calculated by: 1869e5c31af7Sopenharmony_ci 1870e5c31af7Sopenharmony_ci {empty}:: [eq]#m~ux~ = {vert}{partial}s/{partial}x{vert} {times} w~base~# 1871e5c31af7Sopenharmony_ci {empty}:: [eq]#m~vx~ = {vert}{partial}t/{partial}x{vert} {times} h~base~# 1872e5c31af7Sopenharmony_ci {empty}:: [eq]#m~wx~ = {vert}{partial}r/{partial}x{vert} {times} d~base~# 1873e5c31af7Sopenharmony_ci 1874e5c31af7Sopenharmony_ci {empty}:: [eq]#m~uy~ = {vert}{partial}s/{partial}y{vert} {times} w~base~# 1875e5c31af7Sopenharmony_ci {empty}:: [eq]#m~vy~ = {vert}{partial}t/{partial}y{vert} {times} h~base~# 1876e5c31af7Sopenharmony_ci {empty}:: [eq]#m~wy~ = {vert}{partial}r/{partial}y{vert} {times} d~base~# 1877e5c31af7Sopenharmony_ci 1878e5c31af7Sopenharmony_ci 1879e5c31af7Sopenharmony_ciwhere: 1880e5c31af7Sopenharmony_ci 1881e5c31af7Sopenharmony_ci {empty}:: [eq]#{partial}t/{partial}x = {partial}t/{partial}y = 0# (for 1D 1882e5c31af7Sopenharmony_ci images) 1883e5c31af7Sopenharmony_ci {empty}:: [eq]#{partial}r/{partial}x = {partial}r/{partial}y = 0# (for 1D, 1884e5c31af7Sopenharmony_ci 2D or Cube images) 1885e5c31af7Sopenharmony_ci 1886e5c31af7Sopenharmony_ciand: 1887e5c31af7Sopenharmony_ci 1888e5c31af7Sopenharmony_ci {empty}:: [eq]#w~base~ = image.w# 1889e5c31af7Sopenharmony_ci {empty}:: [eq]#h~base~ = image.h# 1890e5c31af7Sopenharmony_ci {empty}:: [eq]#d~base~ = image.d# 1891e5c31af7Sopenharmony_ci 1892e5c31af7Sopenharmony_ci(for the pname:baseMipLevel, from the image descriptor). 1893e5c31af7Sopenharmony_ci 1894e5c31af7Sopenharmony_ciifdef::VK_NV_corner_sampled_image[] 1895e5c31af7Sopenharmony_ci 1896e5c31af7Sopenharmony_ciFor corner-sampled images, the [eq]#w~base~#, [eq]#h~base~#, and 1897e5c31af7Sopenharmony_ci[eq]#d~base~# are instead: 1898e5c31af7Sopenharmony_ci 1899e5c31af7Sopenharmony_ci {empty}:: [eq]#w~base~ = image.w - 1# 1900e5c31af7Sopenharmony_ci {empty}:: [eq]#h~base~ = image.h - 1# 1901e5c31af7Sopenharmony_ci {empty}:: [eq]#d~base~ = image.d - 1# 1902e5c31af7Sopenharmony_ci 1903e5c31af7Sopenharmony_ciendif::VK_NV_corner_sampled_image[] 1904e5c31af7Sopenharmony_ci 1905e5c31af7Sopenharmony_ciA point sampled in screen space has an elliptical footprint in texture 1906e5c31af7Sopenharmony_cispace. 1907e5c31af7Sopenharmony_ciThe minimum and maximum scale factors [eq]#({rho}~min~, {rho}~max~)# should: 1908e5c31af7Sopenharmony_cibe the minor and major axes of this ellipse. 1909e5c31af7Sopenharmony_ci 1910e5c31af7Sopenharmony_ciThe _scale factors_ [eq]#{rho}~x~# and [eq]#{rho}~y~#, calculated from the 1911e5c31af7Sopenharmony_cimagnitude of the derivatives in x and y, are used to compute the minimum and 1912e5c31af7Sopenharmony_cimaximum scale factors. 1913e5c31af7Sopenharmony_ci 1914e5c31af7Sopenharmony_ci[eq]#{rho}~x~# and [eq]#{rho}~y~# may: be approximated with functions 1915e5c31af7Sopenharmony_ci[eq]#f~x~# and [eq]#f~y~#, subject to the following constraints: 1916e5c31af7Sopenharmony_ci 1917e5c31af7Sopenharmony_ci[latexmath] 1918e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 1919e5c31af7Sopenharmony_ci\begin{aligned} 1920e5c31af7Sopenharmony_ci& f_x \text{\ is\ continuous\ and\ monotonically\ increasing\ in\ each\ of\ } 1921e5c31af7Sopenharmony_ci m_{ux}, 1922e5c31af7Sopenharmony_ci m_{vx}, \text{\ and\ } 1923e5c31af7Sopenharmony_ci m_{wx} \\ 1924e5c31af7Sopenharmony_ci& f_y \text{\ is\ continuous\ and\ monotonically\ increasing\ in\ each\ of\ } 1925e5c31af7Sopenharmony_ci m_{uy}, 1926e5c31af7Sopenharmony_ci m_{vy}, \text{\ and\ } 1927e5c31af7Sopenharmony_ci m_{wy} 1928e5c31af7Sopenharmony_ci\end{aligned} 1929e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 1930e5c31af7Sopenharmony_ci 1931e5c31af7Sopenharmony_ci[latexmath] 1932e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 1933e5c31af7Sopenharmony_ci\begin{aligned} 1934e5c31af7Sopenharmony_ci\max(|m_{ux}|, |m_{vx}|, |m_{wx}|) \leq f_{x} 1935e5c31af7Sopenharmony_ci\leq \sqrt{2} (|m_{ux}| + |m_{vx}| + |m_{wx}|) \\ 1936e5c31af7Sopenharmony_ci\max(|m_{uy}|, |m_{vy}|, |m_{wy}|) \leq f_{y} 1937e5c31af7Sopenharmony_ci\leq \sqrt{2} (|m_{uy}| + |m_{vy}| + |m_{wy}|) 1938e5c31af7Sopenharmony_ci\end{aligned} 1939e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 1940e5c31af7Sopenharmony_ci 1941e5c31af7Sopenharmony_ci 1942e5c31af7Sopenharmony_ciifdef::editing-notes[] 1943e5c31af7Sopenharmony_ci[NOTE] 1944e5c31af7Sopenharmony_ci.editing-note 1945e5c31af7Sopenharmony_ci==== 1946e5c31af7Sopenharmony_ci(Bill) For reviewers only - anticipating questions. 1947e5c31af7Sopenharmony_ci 1948e5c31af7Sopenharmony_ciWe only support implicit derivatives for normalized texel coordinates. 1949e5c31af7Sopenharmony_ci 1950e5c31af7Sopenharmony_ciSo we are documenting the derivatives in s,t,r (normalized texel 1951e5c31af7Sopenharmony_cicoordinates) rather than u,v,w (unnormalized texel coordinates) as in OpenGL 1952e5c31af7Sopenharmony_ciand OpenGL ES specifications. 1953e5c31af7Sopenharmony_ci(I know, u,v,w is the way it has been documented since OpenGL V1.0.) 1954e5c31af7Sopenharmony_ci 1955e5c31af7Sopenharmony_ciAlso there is no reason to have conditional application of [eq]#w~base~, 1956e5c31af7Sopenharmony_cih~base~, d~base~# for rectangle textures either, since they do not support 1957e5c31af7Sopenharmony_ciimplicit derivatives. 1958e5c31af7Sopenharmony_ci==== 1959e5c31af7Sopenharmony_ciendif::editing-notes[] 1960e5c31af7Sopenharmony_ci 1961e5c31af7Sopenharmony_ci 1962e5c31af7Sopenharmony_ciThe minimum and maximum scale factors [eq]#({rho}~min~,{rho}~max~)# are 1963e5c31af7Sopenharmony_cidetermined by: 1964e5c31af7Sopenharmony_ci 1965e5c31af7Sopenharmony_ci {empty}:: [eq]#{rho}~max~ = max({rho}~x~, {rho}~y~)# 1966e5c31af7Sopenharmony_ci {empty}:: [eq]#{rho}~min~ = min({rho}~x~, {rho}~y~)# 1967e5c31af7Sopenharmony_ci 1968e5c31af7Sopenharmony_ciThe ratio of anisotropy is determined by: 1969e5c31af7Sopenharmony_ci 1970e5c31af7Sopenharmony_ci {empty}:: [eq]#{eta} = min({rho}~max~/{rho}~min~, max~Aniso~)# 1971e5c31af7Sopenharmony_ci 1972e5c31af7Sopenharmony_ciwhere: 1973e5c31af7Sopenharmony_ci 1974e5c31af7Sopenharmony_ci {empty}:: [eq]#sampler.max~Aniso~ = pname:maxAnisotropy# (from sampler 1975e5c31af7Sopenharmony_ci descriptor) 1976e5c31af7Sopenharmony_ci {empty}:: [eq]#limits.max~Aniso~ = pname:maxSamplerAnisotropy# (from 1977e5c31af7Sopenharmony_ci physical device limits) 1978e5c31af7Sopenharmony_ci {empty}:: [eq]#max~Aniso~ = min(sampler.max~Aniso~, limits.max~Aniso~)# 1979e5c31af7Sopenharmony_ci 1980e5c31af7Sopenharmony_ciIf [eq]#{rho}~max~ = {rho}~min~ = 0#, then all the partial derivatives are 1981e5c31af7Sopenharmony_cizero, the fragment's footprint in texel space is a point, and [eq]#{eta}# 1982e5c31af7Sopenharmony_cishould: be treated as 1. 1983e5c31af7Sopenharmony_ciIf [eq]#{rho}~max~ {neq} 0# and [eq]#{rho}~min~ = 0# then all partial 1984e5c31af7Sopenharmony_ciderivatives along one axis are zero, the fragment's footprint in texel space 1985e5c31af7Sopenharmony_ciis a line segment, and [eq]#{eta}# should: be treated as [eq]#max~Aniso~#. 1986e5c31af7Sopenharmony_ciHowever, anytime the footprint is small in texel space the implementation 1987e5c31af7Sopenharmony_cimay: use a smaller value of [eq]#{eta}#, even when [eq]#{rho}~min~# is zero 1988e5c31af7Sopenharmony_cior close to zero. 1989e5c31af7Sopenharmony_ciIf either slink:VkPhysicalDeviceFeatures::pname:samplerAnisotropy or 1990e5c31af7Sopenharmony_cislink:VkSamplerCreateInfo::pname:anisotropyEnable are ename:VK_FALSE, 1991e5c31af7Sopenharmony_ci[eq]#max~Aniso~# is set to 1. 1992e5c31af7Sopenharmony_ci 1993e5c31af7Sopenharmony_ciIf [eq]#{eta} = 1#, sampling is isotropic. 1994e5c31af7Sopenharmony_ciIf [eq]#{eta} > 1#, sampling is anisotropic. 1995e5c31af7Sopenharmony_ci 1996e5c31af7Sopenharmony_ciThe sampling rate ([eq]#N#) is derived as: 1997e5c31af7Sopenharmony_ci 1998e5c31af7Sopenharmony_ci {empty}:: [eq]#N = {lceil}{eta}{rceil}# 1999e5c31af7Sopenharmony_ci 2000e5c31af7Sopenharmony_ciAn implementation may: round [eq]#N# up to the nearest supported sampling 2001e5c31af7Sopenharmony_cirate. 2002e5c31af7Sopenharmony_ciAn implementation may: use the value of [eq]#N# as an approximation of 2003e5c31af7Sopenharmony_ci[eq]#{eta}#. 2004e5c31af7Sopenharmony_ci 2005e5c31af7Sopenharmony_ci 2006e5c31af7Sopenharmony_ci[[textures-level-of-detail-operation]] 2007e5c31af7Sopenharmony_ci==== LOD Operation 2008e5c31af7Sopenharmony_ci 2009e5c31af7Sopenharmony_ciThe LOD parameter [eq]#{lambda}# is computed as follows: 2010e5c31af7Sopenharmony_ci 2011e5c31af7Sopenharmony_ci[latexmath] 2012e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2013e5c31af7Sopenharmony_ci\begin{aligned} 2014e5c31af7Sopenharmony_ci\lambda_{base}(x,y) & = 2015e5c31af7Sopenharmony_ci \begin{cases} 2016e5c31af7Sopenharmony_ci shaderOp.Lod & \text{(from optional SPIR-V operand)} \\ 2017e5c31af7Sopenharmony_ci \log_2 \left ( \frac{\rho_{max}}{\eta} \right ) & \text{otherwise} 2018e5c31af7Sopenharmony_ci \end{cases} \\ 2019e5c31af7Sopenharmony_ci\lambda'(x,y) & = \lambda_{base} + \mathbin{clamp}(sampler.bias + shaderOp.bias,-maxSamplerLodBias,maxSamplerLodBias) \\ 2020e5c31af7Sopenharmony_ci\lambda & = 2021e5c31af7Sopenharmony_ci \begin{cases} 2022e5c31af7Sopenharmony_ci lod_{max}, & \lambda' > lod_{max} \\ 2023e5c31af7Sopenharmony_ci \lambda', & lod_{min} \leq \lambda' \leq lod_{max} \\ 2024e5c31af7Sopenharmony_ci lod_{min}, & \lambda' < lod_{min} \\ 2025e5c31af7Sopenharmony_ci \textit{undefined}, & lod_{min} > lod_{max} 2026e5c31af7Sopenharmony_ci \end{cases} 2027e5c31af7Sopenharmony_ci\end{aligned} 2028e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2029e5c31af7Sopenharmony_ci 2030e5c31af7Sopenharmony_ciwhere: 2031e5c31af7Sopenharmony_ci 2032e5c31af7Sopenharmony_ci[latexmath] 2033e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2034e5c31af7Sopenharmony_ci\begin{aligned} 2035e5c31af7Sopenharmony_cisampler.bias & = mipLodBias & \text{(from sampler descriptor)} \\ 2036e5c31af7Sopenharmony_cishaderOp.bias & = 2037e5c31af7Sopenharmony_ci \begin{cases} 2038e5c31af7Sopenharmony_ci Bias & \text{(from optional SPIR-V operand)} \\ 2039e5c31af7Sopenharmony_ci 0 & \text{otherwise} 2040e5c31af7Sopenharmony_ci \end{cases} \\ 2041e5c31af7Sopenharmony_cisampler.lod_{min} & = minLod & \text{(from sampler descriptor)} \\ 2042e5c31af7Sopenharmony_cishaderOp.lod_{min} & = 2043e5c31af7Sopenharmony_ci \begin{cases} 2044e5c31af7Sopenharmony_ci MinLod & \text{(from optional SPIR-V operand)} \\ 2045e5c31af7Sopenharmony_ci 0 & \text{otherwise} 2046e5c31af7Sopenharmony_ci \end{cases} \\ 2047e5c31af7Sopenharmony_ci\\ 2048e5c31af7Sopenharmony_cilod_{min} & = \max(sampler.lod_{min}, shaderOp.lod_{min}) \\ 2049e5c31af7Sopenharmony_cilod_{max} & = maxLod & \text{(from sampler descriptor)} 2050e5c31af7Sopenharmony_ci\end{aligned} 2051e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2052e5c31af7Sopenharmony_ci 2053e5c31af7Sopenharmony_ciand [eq]#maxSamplerLodBias# is the value of the slink:VkPhysicalDeviceLimits 2054e5c31af7Sopenharmony_cifeature <<limits-maxSamplerLodBias, pname:maxSamplerLodBias>>. 2055e5c31af7Sopenharmony_ci 2056e5c31af7Sopenharmony_ci 2057e5c31af7Sopenharmony_ci[[textures-image-level-selection]] 2058e5c31af7Sopenharmony_ci==== Image Level(s) Selection 2059e5c31af7Sopenharmony_ci 2060e5c31af7Sopenharmony_ciThe image level(s) [eq]#d#, [eq]#d~hi~#, and [eq]#d~lo~# which texels are 2061e5c31af7Sopenharmony_ciread from are determined by an image-level parameter [eq]#d~l~#, which is 2062e5c31af7Sopenharmony_cicomputed based on the LOD parameter, as follows: 2063e5c31af7Sopenharmony_ci 2064e5c31af7Sopenharmony_ci[latexmath] 2065e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2066e5c31af7Sopenharmony_ci\begin{aligned} 2067e5c31af7Sopenharmony_cid_{l} = 2068e5c31af7Sopenharmony_ci \begin{cases} 2069e5c31af7Sopenharmony_ci nearest(d'), & \text{mipmapMode is VK\_SAMPLER\_MIPMAP\_MODE\_NEAREST} \\ 2070e5c31af7Sopenharmony_ci d', & \text{otherwise} 2071e5c31af7Sopenharmony_ci \end{cases} 2072e5c31af7Sopenharmony_ci\end{aligned} 2073e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2074e5c31af7Sopenharmony_ci 2075e5c31af7Sopenharmony_ciwhere: 2076e5c31af7Sopenharmony_ci 2077e5c31af7Sopenharmony_ci[latexmath] 2078e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2079e5c31af7Sopenharmony_ci\begin{aligned} 2080e5c31af7Sopenharmony_ciifdef::VK_EXT_image_view_min_lod[] 2081e5c31af7Sopenharmony_cid' = max(level_{base} + \text{clamp}(\lambda, 0, q), minLod_{imageView}) 2082e5c31af7Sopenharmony_ciendif::VK_EXT_image_view_min_lod[] 2083e5c31af7Sopenharmony_ciifndef::VK_EXT_image_view_min_lod[] 2084e5c31af7Sopenharmony_cid' = level_{base} + \text{clamp}(\lambda, 0, q) 2085e5c31af7Sopenharmony_ciendif::VK_EXT_image_view_min_lod[] 2086e5c31af7Sopenharmony_ci 2087e5c31af7Sopenharmony_ci\end{aligned} 2088e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2089e5c31af7Sopenharmony_ci 2090e5c31af7Sopenharmony_ci[latexmath] 2091e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2092e5c31af7Sopenharmony_ci\begin{aligned} 2093e5c31af7Sopenharmony_cinearest(d') & = 2094e5c31af7Sopenharmony_ci \begin{cases} 2095e5c31af7Sopenharmony_ci \left \lceil d' + 0.5\right \rceil - 1, & 2096e5c31af7Sopenharmony_ci \text{preferred} \\ 2097e5c31af7Sopenharmony_ci \left \lfloor d' + 0.5\right \rfloor, & 2098e5c31af7Sopenharmony_ci \text{alternative} 2099e5c31af7Sopenharmony_ci \end{cases} 2100e5c31af7Sopenharmony_ci\end{aligned} 2101e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2102e5c31af7Sopenharmony_ci 2103e5c31af7Sopenharmony_ciand: 2104e5c31af7Sopenharmony_ci 2105e5c31af7Sopenharmony_ciifdef::VK_EXT_image_view_min_lod[] 2106e5c31af7Sopenharmony_ci[latexmath] 2107e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2108e5c31af7Sopenharmony_ci\begin{aligned} 2109e5c31af7Sopenharmony_ciminLod_{imageView} & = 2110e5c31af7Sopenharmony_ci \begin{cases} 2111e5c31af7Sopenharmony_ci minLodFloat_{imageView}, & \text{preferred} \\ 2112e5c31af7Sopenharmony_ci minLodInteger_{imageView}, & \text{alternative} 2113e5c31af7Sopenharmony_ci \end{cases} \\ 2114e5c31af7Sopenharmony_cilevel_{base} & = baseMipLevel \\ 2115e5c31af7Sopenharmony_ciq & = levelCount - 1 2116e5c31af7Sopenharmony_ci\end{aligned} 2117e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2118e5c31af7Sopenharmony_ciendif::VK_EXT_image_view_min_lod[] 2119e5c31af7Sopenharmony_ciifndef::VK_EXT_image_view_min_lod[] 2120e5c31af7Sopenharmony_ci[latexmath] 2121e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2122e5c31af7Sopenharmony_ci\begin{aligned} 2123e5c31af7Sopenharmony_cilevel_{base} & = baseMipLevel \\ 2124e5c31af7Sopenharmony_ciq & = levelCount - 1 2125e5c31af7Sopenharmony_ci\end{aligned} 2126e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2127e5c31af7Sopenharmony_ciendif::VK_EXT_image_view_min_lod[] 2128e5c31af7Sopenharmony_ci 2129e5c31af7Sopenharmony_cipname:baseMipLevel and pname:levelCount are taken from the 2130e5c31af7Sopenharmony_cipname:subresourceRange of the image view. 2131e5c31af7Sopenharmony_ci 2132e5c31af7Sopenharmony_ciifdef::VK_EXT_image_view_min_lod[] 2133e5c31af7Sopenharmony_ci[eq]#minLod~imageView~# must: be less or equal to [eq]#level~base~ + q#. 2134e5c31af7Sopenharmony_ciendif::VK_EXT_image_view_min_lod[] 2135e5c31af7Sopenharmony_ci 2136e5c31af7Sopenharmony_ciIf the sampler's pname:mipmapMode is ename:VK_SAMPLER_MIPMAP_MODE_NEAREST, 2137e5c31af7Sopenharmony_cithen the level selected is [eq]#d = d~l~#. 2138e5c31af7Sopenharmony_ci 2139e5c31af7Sopenharmony_ciIf the sampler's pname:mipmapMode is ename:VK_SAMPLER_MIPMAP_MODE_LINEAR, 2140e5c31af7Sopenharmony_citwo neighboring levels are selected: 2141e5c31af7Sopenharmony_ci 2142e5c31af7Sopenharmony_ci[latexmath] 2143e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2144e5c31af7Sopenharmony_ci\begin{aligned} 2145e5c31af7Sopenharmony_cid_{hi} & = \left\lfloor d_{l} \right\rfloor \\ 2146e5c31af7Sopenharmony_cid_{lo} & = min( d_{hi} + 1, level_{base} + q ) \\ 2147e5c31af7Sopenharmony_ci\delta & = d_{l} - d_{hi} 2148e5c31af7Sopenharmony_ci\end{aligned} 2149e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2150e5c31af7Sopenharmony_ci 2151e5c31af7Sopenharmony_ci[eq]#{delta}# is the fractional value, quantized to the number of 2152e5c31af7Sopenharmony_ci<<limits-mipmapPrecisionBits, mipmap precision bits>>, used for 2153e5c31af7Sopenharmony_ci<<textures-texel-filtering, linear filtering>> between levels. 2154e5c31af7Sopenharmony_ci 2155e5c31af7Sopenharmony_ci 2156e5c31af7Sopenharmony_ci[[textures-normalized-to-unnormalized]] 2157e5c31af7Sopenharmony_ci=== (s,t,r,q,a) to (u,v,w,a) Transformation 2158e5c31af7Sopenharmony_ci 2159e5c31af7Sopenharmony_ciThe normalized texel coordinates are scaled by the image level dimensions 2160e5c31af7Sopenharmony_ciand the array layer is selected. 2161e5c31af7Sopenharmony_ci 2162e5c31af7Sopenharmony_ciThis transformation is performed once for each level used in 2163e5c31af7Sopenharmony_ci<<textures-texel-filtering,filtering>> (either [eq]#d#, or [eq]#d~hi~# and 2164e5c31af7Sopenharmony_ci[eq]#d~lo~#). 2165e5c31af7Sopenharmony_ci 2166e5c31af7Sopenharmony_ci[latexmath] 2167e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2168e5c31af7Sopenharmony_ci\begin{aligned} 2169e5c31af7Sopenharmony_ciu(x,y) & = s(x,y) \times width_{scale} + \Delta_i\\ 2170e5c31af7Sopenharmony_civ(x,y) & = 2171e5c31af7Sopenharmony_ci \begin{cases} 2172e5c31af7Sopenharmony_ci 0 & \text{for 1D images} \\ 2173e5c31af7Sopenharmony_ci t(x,y) \times height_{scale} + \Delta_j & \text{otherwise} 2174e5c31af7Sopenharmony_ci \end{cases} \\ 2175e5c31af7Sopenharmony_ciw(x,y) & = 2176e5c31af7Sopenharmony_ci \begin{cases} 2177e5c31af7Sopenharmony_ci 0 & \text{for 2D or Cube images} \\ 2178e5c31af7Sopenharmony_ci r(x,y) \times depth_{scale} + \Delta_k & \text{otherwise} 2179e5c31af7Sopenharmony_ci \end{cases} \\ 2180e5c31af7Sopenharmony_ci\\ 2181e5c31af7Sopenharmony_cia(x,y) & = 2182e5c31af7Sopenharmony_ci \begin{cases} 2183e5c31af7Sopenharmony_ci a(x,y) & \text{for array images} \\ 2184e5c31af7Sopenharmony_ci 0 & \text{otherwise} 2185e5c31af7Sopenharmony_ci \end{cases} 2186e5c31af7Sopenharmony_ci\end{aligned} 2187e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2188e5c31af7Sopenharmony_ci 2189e5c31af7Sopenharmony_ciwhere: 2190e5c31af7Sopenharmony_ci 2191e5c31af7Sopenharmony_ci {empty}:: [eq]#width~scale~ = width~level~# 2192e5c31af7Sopenharmony_ci {empty}:: [eq]#height~scale~ = height~level~# 2193e5c31af7Sopenharmony_ci {empty}:: [eq]#depth~scale~ = depth~level~# 2194e5c31af7Sopenharmony_ci 2195e5c31af7Sopenharmony_ciifdef::VK_NV_corner_sampled_image[] 2196e5c31af7Sopenharmony_cifor conventional images, and: 2197e5c31af7Sopenharmony_ci 2198e5c31af7Sopenharmony_ci {empty}:: [eq]#width~scale~ = width~level~ - 1# 2199e5c31af7Sopenharmony_ci {empty}:: [eq]#height~scale~ = height~level~ - 1# 2200e5c31af7Sopenharmony_ci {empty}:: [eq]#depth~scale~ = depth~level~ - 1# 2201e5c31af7Sopenharmony_ci 2202e5c31af7Sopenharmony_cifor corner-sampled images. 2203e5c31af7Sopenharmony_ciendif::VK_NV_corner_sampled_image[] 2204e5c31af7Sopenharmony_ci 2205e5c31af7Sopenharmony_ciand where [eq]#({DeltaUpper}~i~, {DeltaUpper}~j~, {DeltaUpper}~k~)# are 2206e5c31af7Sopenharmony_citaken from the image instruction if it includes a code:ConstOffset or 2207e5c31af7Sopenharmony_cicode:Offset operand, otherwise they are taken to be zero. 2208e5c31af7Sopenharmony_ci 2209e5c31af7Sopenharmony_ci 2210e5c31af7Sopenharmony_ciOperations then proceed to Unnormalized Texel Coordinate Operations. 2211e5c31af7Sopenharmony_ci 2212e5c31af7Sopenharmony_ci 2213e5c31af7Sopenharmony_ci== Unnormalized Texel Coordinate Operations 2214e5c31af7Sopenharmony_ci 2215e5c31af7Sopenharmony_ci 2216e5c31af7Sopenharmony_ci[[textures-unnormalized-to-integer]] 2217e5c31af7Sopenharmony_ci=== (u,v,w,a) to (i,j,k,l,n) Transformation and Array Layer Selection 2218e5c31af7Sopenharmony_ci 2219e5c31af7Sopenharmony_ciThe unnormalized texel coordinates are transformed to integer texel 2220e5c31af7Sopenharmony_cicoordinates relative to the selected mipmap level. 2221e5c31af7Sopenharmony_ci 2222e5c31af7Sopenharmony_ciThe layer index [eq]#l# is computed as: 2223e5c31af7Sopenharmony_ci 2224e5c31af7Sopenharmony_ci {empty}:: [eq]#l = clamp(RNE(a), 0, pname:layerCount - 1) {plus} 2225e5c31af7Sopenharmony_ci pname:baseArrayLayer# 2226e5c31af7Sopenharmony_ci 2227e5c31af7Sopenharmony_ciwhere pname:layerCount is the number of layers in the image subresource 2228e5c31af7Sopenharmony_cirange of the image view, pname:baseArrayLayer is the first layer from the 2229e5c31af7Sopenharmony_cisubresource range, and where: 2230e5c31af7Sopenharmony_ci 2231e5c31af7Sopenharmony_ci[latexmath] 2232e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2233e5c31af7Sopenharmony_ci\begin{aligned} 2234e5c31af7Sopenharmony_ci\mathbin{RNE}(a) & = 2235e5c31af7Sopenharmony_ci \begin{cases} 2236e5c31af7Sopenharmony_ci \mathbin{roundTiesToEven}(a) & \text{preferred, from IEEE Std 754-2008 Floating-Point Arithmetic} \\ 2237e5c31af7Sopenharmony_ci \left \lfloor a + 0.5 \right \rfloor & \text{alternative} 2238e5c31af7Sopenharmony_ci \end{cases} 2239e5c31af7Sopenharmony_ci\end{aligned} 2240e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2241e5c31af7Sopenharmony_ci 2242e5c31af7Sopenharmony_ciThe sample index [eq]#n# is assigned the value 0. 2243e5c31af7Sopenharmony_ci 2244e5c31af7Sopenharmony_ciNearest filtering (ename:VK_FILTER_NEAREST) computes the integer texel 2245e5c31af7Sopenharmony_cicoordinates that the unnormalized coordinates lie within: 2246e5c31af7Sopenharmony_ci 2247e5c31af7Sopenharmony_ci[latexmath] 2248e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2249e5c31af7Sopenharmony_ci\begin{aligned} 2250e5c31af7Sopenharmony_cii &= \left\lfloor u + shift \right\rfloor \\ 2251e5c31af7Sopenharmony_cij &= \left\lfloor v + shift \right\rfloor \\ 2252e5c31af7Sopenharmony_cik &= \left\lfloor w + shift \right\rfloor 2253e5c31af7Sopenharmony_ci\end{aligned} 2254e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2255e5c31af7Sopenharmony_ciwhere: 2256e5c31af7Sopenharmony_ci 2257e5c31af7Sopenharmony_ci {empty}:: [eq]#shift = 0.0# 2258e5c31af7Sopenharmony_ci 2259e5c31af7Sopenharmony_ciifdef::VK_NV_corner_sampled_image[] 2260e5c31af7Sopenharmony_cifor conventional images, and: 2261e5c31af7Sopenharmony_ci 2262e5c31af7Sopenharmony_ci {empty}:: [eq]#shift = 0.5# 2263e5c31af7Sopenharmony_ci 2264e5c31af7Sopenharmony_cifor corner-sampled images. 2265e5c31af7Sopenharmony_ciendif::VK_NV_corner_sampled_image[] 2266e5c31af7Sopenharmony_ci 2267e5c31af7Sopenharmony_ciLinear filtering (ename:VK_FILTER_LINEAR) computes a set of neighboring 2268e5c31af7Sopenharmony_cicoordinates which bound the unnormalized coordinates. 2269e5c31af7Sopenharmony_ciThe integer texel coordinates are combinations of [eq]#i~0~# or [eq]#i~1~#, 2270e5c31af7Sopenharmony_ci[eq]#j~0~# or [eq]#j~1~#, [eq]#k~0~# or [eq]#k~1~#, as well as weights 2271e5c31af7Sopenharmony_ci[eq]#{alpha}, {beta}#, and [eq]#{gamma}#. 2272e5c31af7Sopenharmony_ci 2273e5c31af7Sopenharmony_ci[latexmath] 2274e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2275e5c31af7Sopenharmony_ci\begin{aligned} 2276e5c31af7Sopenharmony_cii_0 &= \left\lfloor u - shift \right\rfloor \\ 2277e5c31af7Sopenharmony_cii_1 &= i_0 + 1 \\ 2278e5c31af7Sopenharmony_cij_0 &= \left\lfloor v - shift \right\rfloor \\ 2279e5c31af7Sopenharmony_cij_1 &= j_0 + 1 \\ 2280e5c31af7Sopenharmony_cik_0 &= \left\lfloor w - shift \right\rfloor \\ 2281e5c31af7Sopenharmony_cik_1 &= k_0 + 1 2282e5c31af7Sopenharmony_ci\end{aligned} 2283e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2284e5c31af7Sopenharmony_ci 2285e5c31af7Sopenharmony_ci[latexmath] 2286e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2287e5c31af7Sopenharmony_ci\begin{aligned} 2288e5c31af7Sopenharmony_ci\alpha &= \mathbin{frac}\left(u - shift\right) \\[1em] 2289e5c31af7Sopenharmony_ci\beta &= \mathbin{frac}\left(v - shift\right) \\[1em] 2290e5c31af7Sopenharmony_ci\gamma &= \mathbin{frac}\left(w - shift\right) 2291e5c31af7Sopenharmony_ci\end{aligned} 2292e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2293e5c31af7Sopenharmony_ci 2294e5c31af7Sopenharmony_ciwhere: 2295e5c31af7Sopenharmony_ci 2296e5c31af7Sopenharmony_ci {empty}:: [eq]#shift = 0.5# 2297e5c31af7Sopenharmony_ci 2298e5c31af7Sopenharmony_ciifdef::VK_NV_corner_sampled_image[] 2299e5c31af7Sopenharmony_cifor conventional images, and: 2300e5c31af7Sopenharmony_ci 2301e5c31af7Sopenharmony_ci {empty}:: [eq]#shift = 0.0# 2302e5c31af7Sopenharmony_ci 2303e5c31af7Sopenharmony_cifor corner-sampled images, 2304e5c31af7Sopenharmony_ciendif::VK_NV_corner_sampled_image[] 2305e5c31af7Sopenharmony_ciand where: 2306e5c31af7Sopenharmony_ci 2307e5c31af7Sopenharmony_ci[latexmath] 2308e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2309e5c31af7Sopenharmony_ci\mathbin{frac}(x) = x - \left\lfloor x \right\rfloor 2310e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2311e5c31af7Sopenharmony_ciwhere the number of fraction bits retained is specified by 2312e5c31af7Sopenharmony_cisname:VkPhysicalDeviceLimits::pname:subTexelPrecisionBits. 2313e5c31af7Sopenharmony_ci 2314e5c31af7Sopenharmony_ciifdef::VK_IMG_filter_cubic,VK_EXT_filter_cubic[] 2315e5c31af7Sopenharmony_ciCubic filtering (ename:VK_FILTER_CUBIC_EXT) computes a set of neighboring 2316e5c31af7Sopenharmony_cicoordinates which bound the unnormalized coordinates. 2317e5c31af7Sopenharmony_ciThe integer texel coordinates are combinations of [eq]#i~0~#, [eq]#i~1~#, 2318e5c31af7Sopenharmony_ci[eq]#i~2~# or [eq]#i~3~#, [eq]#j~0~#, [eq]#j~1~#, [eq]#j~2~# or [eq]#j~3~#, 2319e5c31af7Sopenharmony_ciifndef::VK_EXT_filter_cubic[] 2320e5c31af7Sopenharmony_cias well as weights [eq]#{alpha}# and [eq]#{beta}#. 2321e5c31af7Sopenharmony_ciendif::VK_EXT_filter_cubic[] 2322e5c31af7Sopenharmony_ciifdef::VK_EXT_filter_cubic[] 2323e5c31af7Sopenharmony_ci[eq]#k~0~#, [eq]#k~1~#, [eq]#k~2~# or [eq]#k~3~#, as well as weights 2324e5c31af7Sopenharmony_ci[eq]#{alpha}#, [eq]#{beta}#, and [eq]#{gamma}#. 2325e5c31af7Sopenharmony_ciendif::VK_EXT_filter_cubic[] 2326e5c31af7Sopenharmony_ci 2327e5c31af7Sopenharmony_ciifndef::VK_EXT_filter_cubic[] 2328e5c31af7Sopenharmony_ci[latexmath] 2329e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2330e5c31af7Sopenharmony_ci\begin{aligned} 2331e5c31af7Sopenharmony_cii_{0} & = {\left \lfloor {u - \frac{3}{2}} \right \rfloor} & i_{1} & = i_{0} + 1 & i_{2} & = i_{1} + 1 & i_{3} & = i_{2} + 1 \\[1em] 2332e5c31af7Sopenharmony_cij_{0} & = {\left \lfloor {v - \frac{3}{2}} \right \rfloor} & j_{1} & = j_{0} + 1 & j_{2} & = j_{1} + 1 & j_{3} & = j_{2} + 1 2333e5c31af7Sopenharmony_ci\end{aligned} 2334e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2335e5c31af7Sopenharmony_ci 2336e5c31af7Sopenharmony_ci[latexmath] 2337e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2338e5c31af7Sopenharmony_ci\begin{aligned} 2339e5c31af7Sopenharmony_cialpha &= \mathbin{frac}\left(u - \frac{1}{2}\right) \\[1em] 2340e5c31af7Sopenharmony_ci\beta &= \mathbin{frac}\left(v - \frac{1}{2}\right) 2341e5c31af7Sopenharmony_ci\end{aligned} 2342e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2343e5c31af7Sopenharmony_ci 2344e5c31af7Sopenharmony_ciendif::VK_EXT_filter_cubic[] 2345e5c31af7Sopenharmony_ci 2346e5c31af7Sopenharmony_ciifdef::VK_EXT_filter_cubic[] 2347e5c31af7Sopenharmony_ci[latexmath] 2348e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2349e5c31af7Sopenharmony_ci\begin{aligned} 2350e5c31af7Sopenharmony_cii_{0} & = {\left \lfloor {u - \frac{3}{2}} \right \rfloor} & i_{1} & = i_{0} + 1 & i_{2} & = i_{1} + 1 & i_{3} & = i_{2} + 1 \\[1em] 2351e5c31af7Sopenharmony_cij_{0} & = {\left \lfloor {v - \frac{3}{2}} \right \rfloor} & j_{1} & = j_{0} + 1 & j_{2} & = j_{1} + 1 & j_{3} & = j_{2} + 1 \\[1em] 2352e5c31af7Sopenharmony_cik_{0} & = {\left \lfloor {w - \frac{3}{2}} \right \rfloor} & k_{1} & = k_{0} + 1 & k_{2} & = k_{1} + 1 & k_{3} & = k_{2} + 1 2353e5c31af7Sopenharmony_ci\end{aligned} 2354e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2355e5c31af7Sopenharmony_ci 2356e5c31af7Sopenharmony_ci[latexmath] 2357e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2358e5c31af7Sopenharmony_ci\begin{aligned} 2359e5c31af7Sopenharmony_ci\alpha &= \mathbin{frac}\left(u - \frac{1}{2}\right) \\[1em] 2360e5c31af7Sopenharmony_ci\beta &= \mathbin{frac}\left(v - \frac{1}{2}\right) \\[1em] 2361e5c31af7Sopenharmony_ci\gamma &= \mathbin{frac}\left(w - \frac{1}{2}\right) 2362e5c31af7Sopenharmony_ci\end{aligned} 2363e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2364e5c31af7Sopenharmony_ci 2365e5c31af7Sopenharmony_ciendif::VK_EXT_filter_cubic[] 2366e5c31af7Sopenharmony_ci 2367e5c31af7Sopenharmony_ciwhere: 2368e5c31af7Sopenharmony_ci 2369e5c31af7Sopenharmony_ci[latexmath] 2370e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2371e5c31af7Sopenharmony_ci\mathbin{frac}(x) = x - \left\lfloor x \right\rfloor 2372e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2373e5c31af7Sopenharmony_ci 2374e5c31af7Sopenharmony_ciwhere the number of fraction bits retained is specified by 2375e5c31af7Sopenharmony_cisname:VkPhysicalDeviceLimits::pname:subTexelPrecisionBits. 2376e5c31af7Sopenharmony_ciendif::VK_IMG_filter_cubic,VK_EXT_filter_cubic[] 2377e5c31af7Sopenharmony_ci 2378e5c31af7Sopenharmony_ci 2379e5c31af7Sopenharmony_ci[[textures-integer-coordinate-operations]] 2380e5c31af7Sopenharmony_ci== Integer Texel Coordinate Operations 2381e5c31af7Sopenharmony_ci 2382e5c31af7Sopenharmony_ciifdef::VK_AMD_shader_image_load_store_lod[] 2383e5c31af7Sopenharmony_ciInteger texel coordinate operations may: supply a LOD which texels are to be 2384e5c31af7Sopenharmony_ciread from or written to using the optional SPIR-V operand code:Lod. 2385e5c31af7Sopenharmony_ciendif::VK_AMD_shader_image_load_store_lod[] 2386e5c31af7Sopenharmony_ciifndef::VK_AMD_shader_image_load_store_lod[] 2387e5c31af7Sopenharmony_ciThe code:OpImageFetch and code:OpImageFetchSparse SPIR-V instructions may: 2388e5c31af7Sopenharmony_cisupply a LOD from which texels are to be fetched using the optional SPIR-V 2389e5c31af7Sopenharmony_cioperand code:Lod. 2390e5c31af7Sopenharmony_ciOther integer-coordinate operations must: not. 2391e5c31af7Sopenharmony_ciendif::VK_AMD_shader_image_load_store_lod[] 2392e5c31af7Sopenharmony_ciIf the code:Lod is provided then it must: be an integer. 2393e5c31af7Sopenharmony_ci 2394e5c31af7Sopenharmony_ciThe image level selected is: 2395e5c31af7Sopenharmony_ci[latexmath] 2396e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2397e5c31af7Sopenharmony_ci\begin{aligned} 2398e5c31af7Sopenharmony_cid & = level_{base} + 2399e5c31af7Sopenharmony_ci \begin{cases} 2400e5c31af7Sopenharmony_ci Lod & \text{(from optional SPIR-V operand)} \\ 2401e5c31af7Sopenharmony_ci 0 & \text{otherwise} 2402e5c31af7Sopenharmony_ci \end{cases} \\ 2403e5c31af7Sopenharmony_ci\end{aligned} 2404e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2405e5c31af7Sopenharmony_ci 2406e5c31af7Sopenharmony_ciIf [eq]#d# does not lie in the range [eq]#[pname:baseMipLevel, 2407e5c31af7Sopenharmony_cipname:baseMipLevel {plus} pname:levelCount)# 2408e5c31af7Sopenharmony_ciifdef::VK_EXT_image_view_min_lod[] 2409e5c31af7Sopenharmony_cior [eq]#d# is less than minLodInteger~imageView~, 2410e5c31af7Sopenharmony_ciendif::VK_EXT_image_view_min_lod[] 2411e5c31af7Sopenharmony_cithen any values fetched are 2412e5c31af7Sopenharmony_ciifdef::VK_EXT_robustness2[] 2413e5c31af7Sopenharmony_cizero if the <<features-robustImageAccess2, pname:robustImageAccess2>> 2414e5c31af7Sopenharmony_cifeature is enabled, otherwise are 2415e5c31af7Sopenharmony_ciendif::VK_EXT_robustness2[] 2416e5c31af7Sopenharmony_ciundefined:, and any writes (if supported) are discarded. 2417e5c31af7Sopenharmony_ci 2418e5c31af7Sopenharmony_ci 2419e5c31af7Sopenharmony_ci[[textures-sample-operations]] 2420e5c31af7Sopenharmony_ci== Image Sample Operations 2421e5c31af7Sopenharmony_ci 2422e5c31af7Sopenharmony_ci 2423e5c31af7Sopenharmony_ci[[textures-wrapping-operation]] 2424e5c31af7Sopenharmony_ci=== Wrapping Operation 2425e5c31af7Sopenharmony_ci 2426e5c31af7Sopenharmony_ciifdef::VK_EXT_non_seamless_cube_map[] 2427e5c31af7Sopenharmony_ciIf the used sampler was created without 2428e5c31af7Sopenharmony_ciename:VK_SAMPLER_CREATE_NON_SEAMLESS_CUBE_MAP_BIT_EXT, 2429e5c31af7Sopenharmony_ciendif::VK_EXT_non_seamless_cube_map[] 2430e5c31af7Sopenharmony_cicode:Cube images ignore the wrap modes specified in the sampler. 2431e5c31af7Sopenharmony_ciInstead, if ename:VK_FILTER_NEAREST is used within a mip level then 2432e5c31af7Sopenharmony_ciename:VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE is used, and if 2433e5c31af7Sopenharmony_ciename:VK_FILTER_LINEAR is used within a mip level then sampling at the edges 2434e5c31af7Sopenharmony_ciis performed as described earlier in the <<textures-cubemapedge,Cube map 2435e5c31af7Sopenharmony_ciedge handling>> section. 2436e5c31af7Sopenharmony_ci 2437e5c31af7Sopenharmony_ciThe first integer texel coordinate i is transformed based on the 2438e5c31af7Sopenharmony_cipname:addressModeU parameter of the sampler. 2439e5c31af7Sopenharmony_ci 2440e5c31af7Sopenharmony_ci[latexmath] 2441e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2442e5c31af7Sopenharmony_ci\begin{aligned} 2443e5c31af7Sopenharmony_cii &= 2444e5c31af7Sopenharmony_ci \begin{cases} 2445e5c31af7Sopenharmony_ci i \bmod size & \text{for repeat} \\ 2446e5c31af7Sopenharmony_ci (size - 1) - \mathbin{mirror} 2447e5c31af7Sopenharmony_ci ((i \bmod (2 \times size)) - size) & \text{for mirrored repeat} \\ 2448e5c31af7Sopenharmony_ci \mathbin{clamp}(i,0,size-1) & \text{for clamp to edge} \\ 2449e5c31af7Sopenharmony_ci \mathbin{clamp}(i,-1,size) & \text{for clamp to border} \\ 2450e5c31af7Sopenharmony_ci \mathbin{clamp}(\mathbin{mirror}(i),0,size-1) & \text{for mirror clamp to edge} 2451e5c31af7Sopenharmony_ci \end{cases} 2452e5c31af7Sopenharmony_ci\end{aligned} 2453e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2454e5c31af7Sopenharmony_ci 2455e5c31af7Sopenharmony_ciwhere: 2456e5c31af7Sopenharmony_ci 2457e5c31af7Sopenharmony_ci[latexmath] 2458e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2459e5c31af7Sopenharmony_ci\begin{aligned} 2460e5c31af7Sopenharmony_ci& \mathbin{mirror}(n) = 2461e5c31af7Sopenharmony_ci \begin{cases} 2462e5c31af7Sopenharmony_ci n & \text{for}\ n \geq 0 \\ 2463e5c31af7Sopenharmony_ci -(1+n) & \text{otherwise} 2464e5c31af7Sopenharmony_ci \end{cases} 2465e5c31af7Sopenharmony_ci\end{aligned} 2466e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2467e5c31af7Sopenharmony_ci 2468e5c31af7Sopenharmony_ci[eq]#j# (for 2D and Cube image) and [eq]#k# (for 3D image) are similarly 2469e5c31af7Sopenharmony_citransformed based on the pname:addressModeV and pname:addressModeW 2470e5c31af7Sopenharmony_ciparameters of the sampler, respectively. 2471e5c31af7Sopenharmony_ci 2472e5c31af7Sopenharmony_ci 2473e5c31af7Sopenharmony_ci[[textures-gather]] 2474e5c31af7Sopenharmony_ci=== Texel Gathering 2475e5c31af7Sopenharmony_ci 2476e5c31af7Sopenharmony_ciSPIR-V instructions with code:Gather in the name return a vector derived 2477e5c31af7Sopenharmony_cifrom 4 texels in the base level of the image view. 2478e5c31af7Sopenharmony_ciThe rules for the ename:VK_FILTER_LINEAR minification filter are applied to 2479e5c31af7Sopenharmony_ciidentify the four selected texels. 2480e5c31af7Sopenharmony_ciEach texel is then converted to an RGBA value according to 2481e5c31af7Sopenharmony_ci<<textures-conversion-to-rgba,conversion to RGBA>> and then 2482e5c31af7Sopenharmony_ci<<textures-component-swizzle,swizzled>>. 2483e5c31af7Sopenharmony_ciA four-component vector is then assembled by taking the component indicated 2484e5c31af7Sopenharmony_ciby the code:Component value in the instruction from the swizzled color value 2485e5c31af7Sopenharmony_ciof the four texels. 2486e5c31af7Sopenharmony_ciIf the operation does not use the code:ConstOffsets image operand then the 2487e5c31af7Sopenharmony_cifour texels form the 2 {times} 2 rectangle used for texture filtering: 2488e5c31af7Sopenharmony_ci 2489e5c31af7Sopenharmony_ci[latexmath] 2490e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2491e5c31af7Sopenharmony_ci\begin{aligned} 2492e5c31af7Sopenharmony_ci\tau[R] &= \tau_{i0j1}[level_{base}][comp] \\ 2493e5c31af7Sopenharmony_ci\tau[G] &= \tau_{i1j1}[level_{base}][comp] \\ 2494e5c31af7Sopenharmony_ci\tau[B] &= \tau_{i1j0}[level_{base}][comp] \\ 2495e5c31af7Sopenharmony_ci\tau[A] &= \tau_{i0j0}[level_{base}][comp] 2496e5c31af7Sopenharmony_ci\end{aligned} 2497e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2498e5c31af7Sopenharmony_ci 2499e5c31af7Sopenharmony_ciIf the operation does use the code:ConstOffsets image operand then the 2500e5c31af7Sopenharmony_cioffsets allow a custom filter to be defined: 2501e5c31af7Sopenharmony_ci 2502e5c31af7Sopenharmony_ci[latexmath] 2503e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2504e5c31af7Sopenharmony_ci\begin{aligned} 2505e5c31af7Sopenharmony_ci\tau[R] &= \tau_{i0j0 + \Delta_0}[level_{base}][comp] \\ 2506e5c31af7Sopenharmony_ci\tau[G] &= \tau_{i0j0 + \Delta_1}[level_{base}][comp] \\ 2507e5c31af7Sopenharmony_ci\tau[B] &= \tau_{i0j0 + \Delta_2}[level_{base}][comp] \\ 2508e5c31af7Sopenharmony_ci\tau[A] &= \tau_{i0j0 + \Delta_3}[level_{base}][comp] 2509e5c31af7Sopenharmony_ci\end{aligned} 2510e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2511e5c31af7Sopenharmony_ci 2512e5c31af7Sopenharmony_ciwhere: 2513e5c31af7Sopenharmony_ci 2514e5c31af7Sopenharmony_ci[latexmath] 2515e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2516e5c31af7Sopenharmony_ci\begin{aligned} 2517e5c31af7Sopenharmony_ci\tau[level_{base}][comp] &= 2518e5c31af7Sopenharmony_ci \begin{cases} 2519e5c31af7Sopenharmony_ci \tau[level_{base}][R], & \text{for}\ comp = 0 \\ 2520e5c31af7Sopenharmony_ci \tau[level_{base}][G], & \text{for}\ comp = 1 \\ 2521e5c31af7Sopenharmony_ci \tau[level_{base}][B], & \text{for}\ comp = 2 \\ 2522e5c31af7Sopenharmony_ci \tau[level_{base}][A], & \text{for}\ comp = 3 2523e5c31af7Sopenharmony_ci \end{cases}\\ 2524e5c31af7Sopenharmony_cicomp & \,\text{from SPIR-V operand Component} 2525e5c31af7Sopenharmony_ci\end{aligned} 2526e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2527e5c31af7Sopenharmony_ci 2528e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_1,VK_KHR_sampler_ycbcr_conversion[] 2529e5c31af7Sopenharmony_cicode:OpImage*Gather must: not be used on a sampled image with 2530e5c31af7Sopenharmony_ci<<samplers-YCbCr-conversion,sampler {YCbCr} conversion>> enabled. 2531e5c31af7Sopenharmony_ciendif::VK_VERSION_1_1,VK_KHR_sampler_ycbcr_conversion[] 2532e5c31af7Sopenharmony_ci 2533e5c31af7Sopenharmony_ciifdef::VK_EXT_image_view_min_lod[] 2534e5c31af7Sopenharmony_ciIf [eq]#level~base~ < minLodInteger~imageView~#, then any values fetched are 2535e5c31af7Sopenharmony_ciifdef::VK_EXT_robustness2[] 2536e5c31af7Sopenharmony_cizero if <<features-robustImageAccess2, pname:robustImageAccess2>> is 2537e5c31af7Sopenharmony_cienabled. 2538e5c31af7Sopenharmony_ciOtherwise values are 2539e5c31af7Sopenharmony_ciendif::VK_EXT_robustness2[] 2540e5c31af7Sopenharmony_ciundefined:. 2541e5c31af7Sopenharmony_ciendif::VK_EXT_image_view_min_lod[] 2542e5c31af7Sopenharmony_ci 2543e5c31af7Sopenharmony_ci 2544e5c31af7Sopenharmony_ci[[textures-texel-filtering]] 2545e5c31af7Sopenharmony_ci=== Texel Filtering 2546e5c31af7Sopenharmony_ci 2547e5c31af7Sopenharmony_ciTexel filtering is first performed for each level (either [eq]#d# or 2548e5c31af7Sopenharmony_ci[eq]#d~hi~# and [eq]#d~lo~#). 2549e5c31af7Sopenharmony_ci 2550e5c31af7Sopenharmony_ciIf [eq]#{lambda}# is less than or equal to zero, the texture is said to be 2551e5c31af7Sopenharmony_ci_magnified_, and the filter mode within a mip level is selected by the 2552e5c31af7Sopenharmony_cipname:magFilter in the sampler. 2553e5c31af7Sopenharmony_ciIf [eq]#{lambda}# is greater than zero, the texture is said to be 2554e5c31af7Sopenharmony_ci_minified_, and the filter mode within a mip level is selected by the 2555e5c31af7Sopenharmony_cipname:minFilter in the sampler. 2556e5c31af7Sopenharmony_ci 2557e5c31af7Sopenharmony_ci 2558e5c31af7Sopenharmony_ci[[textures-texel-nearest-filtering]] 2559e5c31af7Sopenharmony_ci==== Texel Nearest Filtering 2560e5c31af7Sopenharmony_ci 2561e5c31af7Sopenharmony_ciWithin a mip level, ename:VK_FILTER_NEAREST filtering selects a single value 2562e5c31af7Sopenharmony_ciusing the [eq]#(i, j, k)# texel coordinates, with all texels taken from 2563e5c31af7Sopenharmony_cilayer l. 2564e5c31af7Sopenharmony_ci 2565e5c31af7Sopenharmony_ci[latexmath] 2566e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2567e5c31af7Sopenharmony_ci\begin{aligned} 2568e5c31af7Sopenharmony_ci\tau[level] &= 2569e5c31af7Sopenharmony_ci \begin{cases} 2570e5c31af7Sopenharmony_ci \tau_{ijk}[level], & \text{for 3D image} \\ 2571e5c31af7Sopenharmony_ci \tau_{ij}[level], & \text{for 2D or Cube image} \\ 2572e5c31af7Sopenharmony_ci \tau_{i}[level], & \text{for 1D image} 2573e5c31af7Sopenharmony_ci \end{cases} 2574e5c31af7Sopenharmony_ci\end{aligned} 2575e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2576e5c31af7Sopenharmony_ci 2577e5c31af7Sopenharmony_ci 2578e5c31af7Sopenharmony_ci[[textures-texel-linear-filtering]] 2579e5c31af7Sopenharmony_ci==== Texel Linear Filtering 2580e5c31af7Sopenharmony_ci 2581e5c31af7Sopenharmony_ciWithin a mip level, ename:VK_FILTER_LINEAR filtering combines 8 (for 3D), 4 2582e5c31af7Sopenharmony_ci(for 2D or Cube), or 2 (for 1D) texel values, together with their linear 2583e5c31af7Sopenharmony_ciweights. 2584e5c31af7Sopenharmony_ciThe linear weights are derived from the fractions computed earlier: 2585e5c31af7Sopenharmony_ci 2586e5c31af7Sopenharmony_ci[latexmath] 2587e5c31af7Sopenharmony_ci 2588e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2589e5c31af7Sopenharmony_ci\begin{aligned} 2590e5c31af7Sopenharmony_ciw_{i_0} &= (1-\alpha) \\ 2591e5c31af7Sopenharmony_ciw_{i_1} &= (\alpha) \\ 2592e5c31af7Sopenharmony_ciw_{j_0} &= (1-\beta) \\ 2593e5c31af7Sopenharmony_ciw_{j_1} &= (\beta) \\ 2594e5c31af7Sopenharmony_ciw_{k_0} &= (1-\gamma) \\ 2595e5c31af7Sopenharmony_ciw_{k_1} &= (\gamma) 2596e5c31af7Sopenharmony_ci\end{aligned} 2597e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2598e5c31af7Sopenharmony_ci 2599e5c31af7Sopenharmony_ciifndef::VK_VERSION_1_2,VK_EXT_sampler_filter_minmax[] 2600e5c31af7Sopenharmony_ciThe values of multiple texels, together with their weights, are combined 2601e5c31af7Sopenharmony_ciusing a weighted average to produce a filtered value: 2602e5c31af7Sopenharmony_ciendif::VK_VERSION_1_2,VK_EXT_sampler_filter_minmax[] 2603e5c31af7Sopenharmony_ci 2604e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_2,VK_EXT_sampler_filter_minmax[] 2605e5c31af7Sopenharmony_ciThe values of multiple texels, together with their weights, are combined to 2606e5c31af7Sopenharmony_ciproduce a filtered value. 2607e5c31af7Sopenharmony_ci 2608e5c31af7Sopenharmony_ciThe slink:VkSamplerReductionModeCreateInfo::pname:reductionMode can: control 2609e5c31af7Sopenharmony_cithe process by which multiple texels, together with their weights, are 2610e5c31af7Sopenharmony_cicombined to produce a filtered texture value. 2611e5c31af7Sopenharmony_ci 2612e5c31af7Sopenharmony_ciWhen the pname:reductionMode is set (explicitly or implicitly) to 2613e5c31af7Sopenharmony_ciename:VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE, a weighted average is 2614e5c31af7Sopenharmony_cicomputed: 2615e5c31af7Sopenharmony_ciendif::VK_VERSION_1_2,VK_EXT_sampler_filter_minmax[] 2616e5c31af7Sopenharmony_ci 2617e5c31af7Sopenharmony_ci[latexmath] 2618e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2619e5c31af7Sopenharmony_ci\begin{aligned} 2620e5c31af7Sopenharmony_ci\tau_{3D} &= \sum_{k=k_0}^{k_1}\sum_{j=j_0}^{j_1}\sum_{i=i_0}^{i_1}(w_{i})(w_{j})(w_{k})\tau_{ijk} \\ 2621e5c31af7Sopenharmony_ci\tau_{2D} &= \sum_{j=j_0}^{j_1}\sum_{i=i_0}^{i_1}(w_{i})(w_{j})\tau_{ij} \\ 2622e5c31af7Sopenharmony_ci\tau_{1D} &= \sum_{i=i_0}^{i_1}(w_{i})\tau_{i} 2623e5c31af7Sopenharmony_ci\end{aligned} 2624e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2625e5c31af7Sopenharmony_ci 2626e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_2,VK_EXT_sampler_filter_minmax[] 2627e5c31af7Sopenharmony_ciHowever, if the reduction mode is ename:VK_SAMPLER_REDUCTION_MODE_MIN or 2628e5c31af7Sopenharmony_ciename:VK_SAMPLER_REDUCTION_MODE_MAX, the process operates on the above set 2629e5c31af7Sopenharmony_ciof multiple texels, together with their weights, computing a component-wise 2630e5c31af7Sopenharmony_ciminimum or maximum, respectively, of the components of the set of texels 2631e5c31af7Sopenharmony_ciwith non-zero weights. 2632e5c31af7Sopenharmony_ciendif::VK_VERSION_1_2,VK_EXT_sampler_filter_minmax[] 2633e5c31af7Sopenharmony_ci 2634e5c31af7Sopenharmony_ci 2635e5c31af7Sopenharmony_ciifdef::VK_IMG_filter_cubic,VK_EXT_filter_cubic[] 2636e5c31af7Sopenharmony_ci[[textures-texel-cubic-filtering]] 2637e5c31af7Sopenharmony_ci==== Texel Cubic Filtering 2638e5c31af7Sopenharmony_ci 2639e5c31af7Sopenharmony_ciWithin a mip level, ename:VK_FILTER_CUBIC_EXT, filtering computes a weighted 2640e5c31af7Sopenharmony_ciaverage of 2641e5c31af7Sopenharmony_ciifdef::VK_EXT_filter_cubic[] 2642e5c31af7Sopenharmony_ci64 (for 3D), 2643e5c31af7Sopenharmony_ciendif::VK_EXT_filter_cubic[] 2644e5c31af7Sopenharmony_ci16 (for 2D), or 4 (for 1D) texel values, together with their 2645e5c31af7Sopenharmony_ciifndef::VK_QCOM_filter_cubic_weights[] 2646e5c31af7Sopenharmony_ciCatmull-Rom weights. 2647e5c31af7Sopenharmony_ciendif::VK_QCOM_filter_cubic_weights[] 2648e5c31af7Sopenharmony_ciifdef::VK_QCOM_filter_cubic_weights[] 2649e5c31af7Sopenharmony_ciCatmull-Rom, Zero Tangent Cardinal, B-Spline, or Mitchell-Netravali weights 2650e5c31af7Sopenharmony_cias specified by slink:VkSamplerCubicWeightsCreateInfoQCOM. 2651e5c31af7Sopenharmony_ciendif::VK_QCOM_filter_cubic_weights[] 2652e5c31af7Sopenharmony_ci 2653e5c31af7Sopenharmony_ci 2654e5c31af7Sopenharmony_ciCatmull-Rom weights 2655e5c31af7Sopenharmony_ciifdef::VK_QCOM_filter_cubic_weights[] 2656e5c31af7Sopenharmony_cispecified by ename:VK_CUBIC_FILTER_WEIGHTS_CATMULL_ROM_QCOM 2657e5c31af7Sopenharmony_ciendif::VK_QCOM_filter_cubic_weights[] 2658e5c31af7Sopenharmony_ciare derived from the fractions computed earlier. 2659e5c31af7Sopenharmony_ci 2660e5c31af7Sopenharmony_ciifndef::VK_EXT_filter_cubic[] 2661e5c31af7Sopenharmony_ci[latexmath] 2662e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2663e5c31af7Sopenharmony_ci\begin{aligned} 2664e5c31af7Sopenharmony_ci\begin{bmatrix} 2665e5c31af7Sopenharmony_ciw_{i_0}\phantom{,} w_{i_1}\phantom{,} w_{i_2}\phantom{,} w_{i_3} 2666e5c31af7Sopenharmony_ci\end{bmatrix} 2667e5c31af7Sopenharmony_ci= \frac{1}{2} 2668e5c31af7Sopenharmony_ci\begin{bmatrix} 2669e5c31af7Sopenharmony_ci1 & \alpha & \alpha^2 & \alpha^3 2670e5c31af7Sopenharmony_ci\end{bmatrix} 2671e5c31af7Sopenharmony_ci\begin{bmatrix} 2672e5c31af7Sopenharmony_ci\phantom{-}0 & \phantom{-}2 & \phantom{-}0 & \phantom{-}0 \\ 2673e5c31af7Sopenharmony_ci-1 & \phantom{-}0 & \phantom{-}1 & \phantom{-}0 \\ 2674e5c31af7Sopenharmony_ci\phantom{-}2 & -5 & \phantom{-}4 & -1 \\ 2675e5c31af7Sopenharmony_ci-1 & \phantom{-}3 & -3 & \phantom{-}1 2676e5c31af7Sopenharmony_ci\end{bmatrix} 2677e5c31af7Sopenharmony_ci\\ 2678e5c31af7Sopenharmony_ci\begin{bmatrix} 2679e5c31af7Sopenharmony_ciw_{j_0}\phantom{,} w_{j_1}\phantom{,} w_{j_2}\phantom{,} w_{j_3} 2680e5c31af7Sopenharmony_ci\end{bmatrix} 2681e5c31af7Sopenharmony_ci= \frac{1}{2} 2682e5c31af7Sopenharmony_ci\begin{bmatrix} 2683e5c31af7Sopenharmony_ci1 & \beta & \beta^2 & \beta^3 2684e5c31af7Sopenharmony_ci\end{bmatrix} 2685e5c31af7Sopenharmony_ci\begin{bmatrix} 2686e5c31af7Sopenharmony_ci\phantom{-}0 & \phantom{-}2 & \phantom{-}0 & \phantom{-}0 \\ 2687e5c31af7Sopenharmony_ci-1 & \phantom{-}0 & \phantom{-}1 & \phantom{-}0 \\ 2688e5c31af7Sopenharmony_ci\phantom{-}2 & -5 & \phantom{-}4 & -1 \\ 2689e5c31af7Sopenharmony_ci-1 & \phantom{-}3 & -3 & \phantom{-}1 2690e5c31af7Sopenharmony_ci\end{bmatrix} 2691e5c31af7Sopenharmony_ci\end{aligned} 2692e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2693e5c31af7Sopenharmony_ci 2694e5c31af7Sopenharmony_ciThe values of multiple texels, together with their weights, are combined 2695e5c31af7Sopenharmony_ciusing a weighted average to produce a filtered value: 2696e5c31af7Sopenharmony_ci 2697e5c31af7Sopenharmony_ci[latexmath] 2698e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2699e5c31af7Sopenharmony_ci\begin{aligned} 2700e5c31af7Sopenharmony_ci\tau_{2D} &= \sum_{j=j_0}^{j_3}\sum_{i=i_0}^{i_3}(w_{i})(w_{j})\tau_{ij} \\ 2701e5c31af7Sopenharmony_ci\tau_{1D} &= \sum_{i=i_0}^{i_3}(w_{i})\tau_{i} 2702e5c31af7Sopenharmony_ci\end{aligned} 2703e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2704e5c31af7Sopenharmony_ciendif::VK_EXT_filter_cubic[] 2705e5c31af7Sopenharmony_ci 2706e5c31af7Sopenharmony_ciifdef::VK_EXT_filter_cubic[] 2707e5c31af7Sopenharmony_ci 2708e5c31af7Sopenharmony_ci[latexmath] 2709e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2710e5c31af7Sopenharmony_ci\begin{aligned} 2711e5c31af7Sopenharmony_ci\begin{bmatrix} 2712e5c31af7Sopenharmony_ciw_{i_0}\phantom{,} w_{i_1}\phantom{,} w_{i_2}\phantom{,} w_{i_3} 2713e5c31af7Sopenharmony_ci\end{bmatrix} 2714e5c31af7Sopenharmony_ci= \frac{1}{2} 2715e5c31af7Sopenharmony_ci\begin{bmatrix} 2716e5c31af7Sopenharmony_ci1 & \alpha & \alpha^2 & \alpha^3 2717e5c31af7Sopenharmony_ci\end{bmatrix} 2718e5c31af7Sopenharmony_ci\begin{bmatrix} 2719e5c31af7Sopenharmony_ci\phantom{-}0 & \phantom{-}2 & \phantom{-}0 & \phantom{-}0 \\ 2720e5c31af7Sopenharmony_ci-1 & \phantom{-}0 & \phantom{-}1 & \phantom{-}0 \\ 2721e5c31af7Sopenharmony_ci\phantom{-}2 & -5 & \phantom{-}4 & -1 \\ 2722e5c31af7Sopenharmony_ci-1 & \phantom{-}3 & -3 & \phantom{-}1 2723e5c31af7Sopenharmony_ci\end{bmatrix} 2724e5c31af7Sopenharmony_ci\\ 2725e5c31af7Sopenharmony_ci\begin{bmatrix} 2726e5c31af7Sopenharmony_ciw_{j_0}\phantom{,} w_{j_1}\phantom{,} w_{j_2}\phantom{,} w_{j_3} 2727e5c31af7Sopenharmony_ci\end{bmatrix} 2728e5c31af7Sopenharmony_ci= \frac{1}{2} 2729e5c31af7Sopenharmony_ci\begin{bmatrix} 2730e5c31af7Sopenharmony_ci1 & \beta & \beta^2 & \beta^3 2731e5c31af7Sopenharmony_ci\end{bmatrix} 2732e5c31af7Sopenharmony_ci\begin{bmatrix} 2733e5c31af7Sopenharmony_ci\phantom{-}0 & \phantom{-}2 & \phantom{-}0 & \phantom{-}0 \\ 2734e5c31af7Sopenharmony_ci-1 & \phantom{-}0 & \phantom{-}1 & \phantom{-}0 \\ 2735e5c31af7Sopenharmony_ci\phantom{-}2 & -5 & \phantom{-}4 & -1 \\ 2736e5c31af7Sopenharmony_ci-1 & \phantom{-}3 & -3 & \phantom{-}1 2737e5c31af7Sopenharmony_ci\end{bmatrix} 2738e5c31af7Sopenharmony_ci\\ 2739e5c31af7Sopenharmony_ci\begin{bmatrix} 2740e5c31af7Sopenharmony_ciw_{k_0}\phantom{,} w_{k_1}\phantom{,} w_{k_2}\phantom{,} w_{k_3} 2741e5c31af7Sopenharmony_ci\end{bmatrix} 2742e5c31af7Sopenharmony_ci= \frac{1}{2} 2743e5c31af7Sopenharmony_ci\begin{bmatrix} 2744e5c31af7Sopenharmony_ci1 & \gamma & \gamma^2 & \gamma^3 2745e5c31af7Sopenharmony_ci\end{bmatrix} 2746e5c31af7Sopenharmony_ci\begin{bmatrix} 2747e5c31af7Sopenharmony_ci\phantom{-}0 & \phantom{-}2 & \phantom{-}0 & \phantom{-}0 \\ 2748e5c31af7Sopenharmony_ci-1 & \phantom{-}0 & \phantom{-}1 & \phantom{-}0 \\ 2749e5c31af7Sopenharmony_ci\phantom{-}2 & -5 & \phantom{-}4 & -1 \\ 2750e5c31af7Sopenharmony_ci-1 & \phantom{-}3 & -3 & \phantom{-}1 2751e5c31af7Sopenharmony_ci\end{bmatrix} 2752e5c31af7Sopenharmony_ci\end{aligned} 2753e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2754e5c31af7Sopenharmony_ci 2755e5c31af7Sopenharmony_ciifdef::VK_QCOM_filter_cubic_weights[] 2756e5c31af7Sopenharmony_ciZero Tangent Cardinal weights specified by 2757e5c31af7Sopenharmony_ciename:VK_CUBIC_FILTER_WEIGHTS_ZERO_TANGENT_CARDINAL_QCOM are derived from 2758e5c31af7Sopenharmony_cithe fractions computed earlier. 2759e5c31af7Sopenharmony_ci 2760e5c31af7Sopenharmony_ci[latexmath] 2761e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2762e5c31af7Sopenharmony_ci\begin{aligned} 2763e5c31af7Sopenharmony_ci\begin{bmatrix} 2764e5c31af7Sopenharmony_ciw_{i_0}\phantom{,} w_{i_1}\phantom{,} w_{i_2}\phantom{,} w_{i_3} 2765e5c31af7Sopenharmony_ci\end{bmatrix} 2766e5c31af7Sopenharmony_ci= \frac{1}{2} 2767e5c31af7Sopenharmony_ci\begin{bmatrix} 2768e5c31af7Sopenharmony_ci1 & \alpha & \alpha^2 & \alpha^3 2769e5c31af7Sopenharmony_ci\end{bmatrix} 2770e5c31af7Sopenharmony_ci\begin{bmatrix} 2771e5c31af7Sopenharmony_ci\phantom{-}0 & \phantom{-}2 & \phantom{-}0 & \phantom{-}0 \\ 2772e5c31af7Sopenharmony_ci-2 & \phantom{-}0 & \phantom{-}2 & \phantom{-}0 \\ 2773e5c31af7Sopenharmony_ci\phantom{-}4 & -4 & \phantom{-}2 & -2 \\ 2774e5c31af7Sopenharmony_ci-2 & \phantom{-}2 & -2 & \phantom{-}1 2775e5c31af7Sopenharmony_ci\end{bmatrix} 2776e5c31af7Sopenharmony_ci\\ 2777e5c31af7Sopenharmony_ci\begin{bmatrix} 2778e5c31af7Sopenharmony_ciw_{j_0}\phantom{,} w_{j_1}\phantom{,} w_{j_2}\phantom{,} w_{j_3} 2779e5c31af7Sopenharmony_ci\end{bmatrix} 2780e5c31af7Sopenharmony_ci= \frac{1}{2} 2781e5c31af7Sopenharmony_ci\begin{bmatrix} 2782e5c31af7Sopenharmony_ci1 & \beta & \beta^2 & \beta^3 2783e5c31af7Sopenharmony_ci\end{bmatrix} 2784e5c31af7Sopenharmony_ci\begin{bmatrix} 2785e5c31af7Sopenharmony_ci\phantom{-}0 & \phantom{-}2 & \phantom{-}0 & \phantom{-}0 \\ 2786e5c31af7Sopenharmony_ci-2 & \phantom{-}0 & \phantom{-}2 & \phantom{-}0 \\ 2787e5c31af7Sopenharmony_ci\phantom{-}4 & -4 & \phantom{-}2 & -2 \\ 2788e5c31af7Sopenharmony_ci-2 & \phantom{-}2 & -2 & \phantom{-}1 2789e5c31af7Sopenharmony_ci\end{bmatrix} 2790e5c31af7Sopenharmony_ci\\ 2791e5c31af7Sopenharmony_ci\begin{bmatrix} 2792e5c31af7Sopenharmony_ciw_{k_0}\phantom{,} w_{k_1}\phantom{,} w_{k_2}\phantom{,} w_{k_3} 2793e5c31af7Sopenharmony_ci\end{bmatrix} 2794e5c31af7Sopenharmony_ci= \frac{1}{2} 2795e5c31af7Sopenharmony_ci\begin{bmatrix} 2796e5c31af7Sopenharmony_ci1 & \gamma & \gamma^2 & \gamma^3 2797e5c31af7Sopenharmony_ci\end{bmatrix} 2798e5c31af7Sopenharmony_ci\begin{bmatrix} 2799e5c31af7Sopenharmony_ci\phantom{-}0 & \phantom{-}2 & \phantom{-}0 & \phantom{-}0 \\ 2800e5c31af7Sopenharmony_ci-2 & \phantom{-}0 & \phantom{-}2 & \phantom{-}0 \\ 2801e5c31af7Sopenharmony_ci\phantom{-}4 & -4 & \phantom{-}2 & -2 \\ 2802e5c31af7Sopenharmony_ci-2 & \phantom{-}2 & -2 & \phantom{-}1 2803e5c31af7Sopenharmony_ci\end{bmatrix} 2804e5c31af7Sopenharmony_ci\end{aligned} 2805e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2806e5c31af7Sopenharmony_ci 2807e5c31af7Sopenharmony_ciB-Spline weights specified by ename:VK_CUBIC_FILTER_WEIGHTS_B_SPLINE_QCOM 2808e5c31af7Sopenharmony_ciare derived from the fractions computed earlier. 2809e5c31af7Sopenharmony_ci 2810e5c31af7Sopenharmony_ci[latexmath] 2811e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2812e5c31af7Sopenharmony_ci\begin{aligned} 2813e5c31af7Sopenharmony_ci\begin{bmatrix} 2814e5c31af7Sopenharmony_ciw_{i_0}\phantom{,} w_{i_1}\phantom{,} w_{i_2}\phantom{,} w_{i_3} 2815e5c31af7Sopenharmony_ci\end{bmatrix} 2816e5c31af7Sopenharmony_ci= \frac{1}{6} 2817e5c31af7Sopenharmony_ci\begin{bmatrix} 2818e5c31af7Sopenharmony_ci1 & \alpha & \alpha^2 & \alpha^3 2819e5c31af7Sopenharmony_ci\end{bmatrix} 2820e5c31af7Sopenharmony_ci\begin{bmatrix} 2821e5c31af7Sopenharmony_ci\phantom{-}1 & \phantom{-}4 & \phantom{-}1 & \phantom{-}0 \\ 2822e5c31af7Sopenharmony_ci-3 & \phantom{-}0 & \phantom{-}3 & \phantom{-}0 \\ 2823e5c31af7Sopenharmony_ci\phantom{-}3 & -6 & \phantom{-}3 & \phantom{-}0 \\ 2824e5c31af7Sopenharmony_ci-1 & \phantom{-}3 & -3 & \phantom{-}1 2825e5c31af7Sopenharmony_ci\end{bmatrix} 2826e5c31af7Sopenharmony_ci\\ 2827e5c31af7Sopenharmony_ci\begin{bmatrix} 2828e5c31af7Sopenharmony_ciw_{j_0}\phantom{,} w_{j_1}\phantom{,} w_{j_2}\phantom{,} w_{j_3} 2829e5c31af7Sopenharmony_ci\end{bmatrix} 2830e5c31af7Sopenharmony_ci= \frac{1}{6} 2831e5c31af7Sopenharmony_ci\begin{bmatrix} 2832e5c31af7Sopenharmony_ci1 & \beta & \beta^2 & \beta^3 2833e5c31af7Sopenharmony_ci\end{bmatrix} 2834e5c31af7Sopenharmony_ci\begin{bmatrix} 2835e5c31af7Sopenharmony_ci\phantom{-}1 & \phantom{-}4 & \phantom{-}1 & \phantom{-}0 \\ 2836e5c31af7Sopenharmony_ci-3 & \phantom{-}0 & \phantom{-}3 & \phantom{-}0 \\ 2837e5c31af7Sopenharmony_ci\phantom{-}3 & -6 & \phantom{-}3 & \phantom{-}0 \\ 2838e5c31af7Sopenharmony_ci-1 & \phantom{-}3 & -3 & \phantom{-}1 2839e5c31af7Sopenharmony_ci\end{bmatrix} 2840e5c31af7Sopenharmony_ci\\ 2841e5c31af7Sopenharmony_ci\begin{bmatrix} 2842e5c31af7Sopenharmony_ciw_{k_0}\phantom{,} w_{k_1}\phantom{,} w_{k_2}\phantom{,} w_{k_3} 2843e5c31af7Sopenharmony_ci\end{bmatrix} 2844e5c31af7Sopenharmony_ci= \frac{1}{6} 2845e5c31af7Sopenharmony_ci\begin{bmatrix} 2846e5c31af7Sopenharmony_ci1 & \gamma & \gamma^2 & \gamma^3 2847e5c31af7Sopenharmony_ci\end{bmatrix} 2848e5c31af7Sopenharmony_ci\begin{bmatrix} 2849e5c31af7Sopenharmony_ci\phantom{-}1 & \phantom{-}4 & \phantom{-}1 & \phantom{-}0 \\ 2850e5c31af7Sopenharmony_ci-3 & \phantom{-}0 & \phantom{-}3 & \phantom{-}0 \\ 2851e5c31af7Sopenharmony_ci\phantom{-}3 & -6 & \phantom{-}3 & \phantom{-}0 \\ 2852e5c31af7Sopenharmony_ci-1 & \phantom{-}3 & -3 & \phantom{-}1 2853e5c31af7Sopenharmony_ci\end{bmatrix} 2854e5c31af7Sopenharmony_ci\end{aligned} 2855e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2856e5c31af7Sopenharmony_ci 2857e5c31af7Sopenharmony_ciMitchell-Netravali weights specified by 2858e5c31af7Sopenharmony_ciename:VK_CUBIC_FILTER_WEIGHTS_MITCHELL_NETRAVALI_QCOM are derived from the 2859e5c31af7Sopenharmony_cifractions computed earlier. 2860e5c31af7Sopenharmony_ci 2861e5c31af7Sopenharmony_ci[latexmath] 2862e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2863e5c31af7Sopenharmony_ci\begin{aligned} 2864e5c31af7Sopenharmony_ci\begin{bmatrix} 2865e5c31af7Sopenharmony_ciw_{i_0}\phantom{,} w_{i_1}\phantom{,} w_{i_2}\phantom{,} w_{i_3} 2866e5c31af7Sopenharmony_ci\end{bmatrix} 2867e5c31af7Sopenharmony_ci= \frac{1}{18} 2868e5c31af7Sopenharmony_ci\begin{bmatrix} 2869e5c31af7Sopenharmony_ci1 & \alpha & \alpha^2 & \alpha^3 2870e5c31af7Sopenharmony_ci\end{bmatrix} 2871e5c31af7Sopenharmony_ci\begin{bmatrix} 2872e5c31af7Sopenharmony_ci\phantom{-}1 & \phantom{-}16 & \phantom{-}1 & \phantom{-}0 \\ 2873e5c31af7Sopenharmony_ci-9 & \phantom{-}0 & \phantom{-}9 & \phantom{-}0 \\ 2874e5c31af7Sopenharmony_ci\phantom{-}15 & -36 & \phantom{-}27 & -6 \\ 2875e5c31af7Sopenharmony_ci-7 & \phantom{-}21 & -21 & \phantom{-}7 2876e5c31af7Sopenharmony_ci\end{bmatrix} 2877e5c31af7Sopenharmony_ci\\ 2878e5c31af7Sopenharmony_ci\begin{bmatrix} 2879e5c31af7Sopenharmony_ciw_{j_0}\phantom{,} w_{j_1}\phantom{,} w_{j_2}\phantom{,} w_{j_3} 2880e5c31af7Sopenharmony_ci\end{bmatrix} 2881e5c31af7Sopenharmony_ci= \frac{1}{18} 2882e5c31af7Sopenharmony_ci\begin{bmatrix} 2883e5c31af7Sopenharmony_ci1 & \beta & \beta^2 & \beta^3 2884e5c31af7Sopenharmony_ci\end{bmatrix} 2885e5c31af7Sopenharmony_ci\begin{bmatrix} 2886e5c31af7Sopenharmony_ci\phantom{-}1 & \phantom{-}16 & \phantom{-}1 & \phantom{-}0 \\ 2887e5c31af7Sopenharmony_ci-9 & \phantom{-}0 & \phantom{-}9 & \phantom{-}0 \\ 2888e5c31af7Sopenharmony_ci\phantom{-}15 & -36 & \phantom{-}27 & -6 \\ 2889e5c31af7Sopenharmony_ci-7 & \phantom{-}21 & -21 & \phantom{-}7 2890e5c31af7Sopenharmony_ci\end{bmatrix} 2891e5c31af7Sopenharmony_ci\\ 2892e5c31af7Sopenharmony_ci\begin{bmatrix} 2893e5c31af7Sopenharmony_ciw_{k_0}\phantom{,} w_{k_1}\phantom{,} w_{k_2}\phantom{,} w_{k_3} 2894e5c31af7Sopenharmony_ci\end{bmatrix} 2895e5c31af7Sopenharmony_ci= \frac{1}{18} 2896e5c31af7Sopenharmony_ci\begin{bmatrix} 2897e5c31af7Sopenharmony_ci1 & \gamma & \gamma^2 & \gamma^3 2898e5c31af7Sopenharmony_ci\end{bmatrix} 2899e5c31af7Sopenharmony_ci\begin{bmatrix} 2900e5c31af7Sopenharmony_ci\phantom{-}1 & \phantom{-}16 & \phantom{-}1 & \phantom{-}0 \\ 2901e5c31af7Sopenharmony_ci-9 & \phantom{-}0 & \phantom{-}9 & \phantom{-}0 \\ 2902e5c31af7Sopenharmony_ci\phantom{-}15 & -36 & \phantom{-}27 & -6 \\ 2903e5c31af7Sopenharmony_ci-7 & \phantom{-}21 & -21 & \phantom{-}7 2904e5c31af7Sopenharmony_ci\end{bmatrix} 2905e5c31af7Sopenharmony_ci\end{aligned} 2906e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2907e5c31af7Sopenharmony_ci 2908e5c31af7Sopenharmony_ciendif::VK_QCOM_filter_cubic_weights[] 2909e5c31af7Sopenharmony_ci 2910e5c31af7Sopenharmony_ci 2911e5c31af7Sopenharmony_ciThe values of multiple texels, together with their weights, are combined to 2912e5c31af7Sopenharmony_ciproduce a filtered value. 2913e5c31af7Sopenharmony_ci 2914e5c31af7Sopenharmony_ciThe slink:VkSamplerReductionModeCreateInfo::pname:reductionMode can: control 2915e5c31af7Sopenharmony_cithe process by which multiple texels, together with their weights, are 2916e5c31af7Sopenharmony_cicombined to produce a filtered texture value. 2917e5c31af7Sopenharmony_ci 2918e5c31af7Sopenharmony_ciWhen the pname:reductionMode is set (explicitly or implicitly) to 2919e5c31af7Sopenharmony_ciename:VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE 2920e5c31af7Sopenharmony_ciifdef::VK_QCOM_filter_cubic_clamp[] 2921e5c31af7Sopenharmony_cior ename:VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE_RANGECLAMP_QCOM 2922e5c31af7Sopenharmony_ciendif::VK_QCOM_filter_cubic_clamp[] 2923e5c31af7Sopenharmony_ci, a weighted average is computed: 2924e5c31af7Sopenharmony_ci 2925e5c31af7Sopenharmony_ci[latexmath] 2926e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2927e5c31af7Sopenharmony_ci\begin{aligned} 2928e5c31af7Sopenharmony_ci\tau_{3D} &= \sum_{k=j_0}^{k_3}\sum_{j=j_0}^{j_3}\sum_{i=i_0}^{i_3}(w_{i})(w_{j})(w_{k})\tau_{ijk} \\ 2929e5c31af7Sopenharmony_ci\tau_{2D} &= \sum_{j=j_0}^{j_3}\sum_{i=i_0}^{i_3}(w_{i})(w_{j})\tau_{ij} \\ 2930e5c31af7Sopenharmony_ci\tau_{1D} &= \sum_{i=i_0}^{i_3}(w_{i})\tau_{i} 2931e5c31af7Sopenharmony_ci\end{aligned} 2932e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2933e5c31af7Sopenharmony_ci 2934e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_2,VK_EXT_sampler_filter_minmax[] 2935e5c31af7Sopenharmony_ciHowever, if the reduction mode is ename:VK_SAMPLER_REDUCTION_MODE_MIN or 2936e5c31af7Sopenharmony_ciename:VK_SAMPLER_REDUCTION_MODE_MAX, the process operates on the above set 2937e5c31af7Sopenharmony_ciof multiple texels, together with their weights, computing a component-wise 2938e5c31af7Sopenharmony_ciminimum or maximum, respectively, of the components of the set of texels 2939e5c31af7Sopenharmony_ciwith non-zero weights. 2940e5c31af7Sopenharmony_ciendif::VK_VERSION_1_2,VK_EXT_sampler_filter_minmax[] 2941e5c31af7Sopenharmony_ci 2942e5c31af7Sopenharmony_ci 2943e5c31af7Sopenharmony_ciifdef::VK_QCOM_filter_cubic_clamp[] 2944e5c31af7Sopenharmony_ci[[textures-texel-range-clamp]] 2945e5c31af7Sopenharmony_ci==== Texel Range Clamp 2946e5c31af7Sopenharmony_ciWhen the pname:reductionMode is set to 2947e5c31af7Sopenharmony_ciename:VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE_RANGECLAMP_QCOM, the 2948e5c31af7Sopenharmony_ciweighted average is clamped to be within the component-wise minimum and 2949e5c31af7Sopenharmony_cimaximum of the set of texels with non-zero weights. 2950e5c31af7Sopenharmony_ciendif::VK_QCOM_filter_cubic_clamp[] 2951e5c31af7Sopenharmony_ci 2952e5c31af7Sopenharmony_ciendif::VK_EXT_filter_cubic[] 2953e5c31af7Sopenharmony_ciendif::VK_IMG_filter_cubic,VK_EXT_filter_cubic[] 2954e5c31af7Sopenharmony_ci 2955e5c31af7Sopenharmony_ci 2956e5c31af7Sopenharmony_ci[[textures-texel-mipmap-filtering]] 2957e5c31af7Sopenharmony_ci==== Texel Mipmap Filtering 2958e5c31af7Sopenharmony_ci 2959e5c31af7Sopenharmony_ciename:VK_SAMPLER_MIPMAP_MODE_NEAREST filtering returns the value of a single 2960e5c31af7Sopenharmony_cimipmap level, 2961e5c31af7Sopenharmony_ci 2962e5c31af7Sopenharmony_ci[eq]#{tau} = {tau}[d]#. 2963e5c31af7Sopenharmony_ci 2964e5c31af7Sopenharmony_ciename:VK_SAMPLER_MIPMAP_MODE_LINEAR filtering combines the values of 2965e5c31af7Sopenharmony_cimultiple mipmap levels ({tau}[hi] and {tau}[lo]), together with their linear 2966e5c31af7Sopenharmony_ciweights. 2967e5c31af7Sopenharmony_ci 2968e5c31af7Sopenharmony_ciThe linear weights are derived from the fraction computed earlier: 2969e5c31af7Sopenharmony_ci 2970e5c31af7Sopenharmony_ci[latexmath] 2971e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2972e5c31af7Sopenharmony_ci\begin{aligned} 2973e5c31af7Sopenharmony_ciw_{hi} &= (1-\delta) \\ 2974e5c31af7Sopenharmony_ciw_{lo} &= (\delta) \\ 2975e5c31af7Sopenharmony_ci\end{aligned} 2976e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2977e5c31af7Sopenharmony_ci 2978e5c31af7Sopenharmony_ciifndef::VK_VERSION_1_2,VK_EXT_sampler_filter_minmax[] 2979e5c31af7Sopenharmony_ciThe values of multiple mipmap levels together with their linear weights, are 2980e5c31af7Sopenharmony_cicombined using a weighted average to produce a final filtered value: 2981e5c31af7Sopenharmony_ciendif::VK_VERSION_1_2,VK_EXT_sampler_filter_minmax[] 2982e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_2,VK_EXT_sampler_filter_minmax[] 2983e5c31af7Sopenharmony_ciThe values of multiple mipmap levels, together with their weights, are 2984e5c31af7Sopenharmony_cicombined to produce a final filtered value. 2985e5c31af7Sopenharmony_ci 2986e5c31af7Sopenharmony_ciThe slink:VkSamplerReductionModeCreateInfo::pname:reductionMode can: control 2987e5c31af7Sopenharmony_cithe process by which multiple texels, together with their weights, are 2988e5c31af7Sopenharmony_cicombined to produce a filtered texture value. 2989e5c31af7Sopenharmony_ci 2990e5c31af7Sopenharmony_ciWhen the pname:reductionMode is set (explicitly or implicitly) to 2991e5c31af7Sopenharmony_ciename:VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE, a weighted average is 2992e5c31af7Sopenharmony_cicomputed: 2993e5c31af7Sopenharmony_ciendif::VK_VERSION_1_2,VK_EXT_sampler_filter_minmax[] 2994e5c31af7Sopenharmony_ci 2995e5c31af7Sopenharmony_ci[latexmath] 2996e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 2997e5c31af7Sopenharmony_ci\begin{aligned} 2998e5c31af7Sopenharmony_ci\tau &= (w_{hi})\tau[hi]+(w_{lo})\tau[lo] 2999e5c31af7Sopenharmony_ci\end{aligned} 3000e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 3001e5c31af7Sopenharmony_ci 3002e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_2,VK_EXT_sampler_filter_minmax[] 3003e5c31af7Sopenharmony_ciHowever, if the reduction mode is ename:VK_SAMPLER_REDUCTION_MODE_MIN or 3004e5c31af7Sopenharmony_ciename:VK_SAMPLER_REDUCTION_MODE_MAX, the process operates on the above 3005e5c31af7Sopenharmony_civalues, together with their weights, computing a component-wise minimum or 3006e5c31af7Sopenharmony_cimaximum, respectively, of the components of the values with non-zero 3007e5c31af7Sopenharmony_ciweights. 3008e5c31af7Sopenharmony_ciendif::VK_VERSION_1_2,VK_EXT_sampler_filter_minmax[] 3009e5c31af7Sopenharmony_ci 3010e5c31af7Sopenharmony_ci 3011e5c31af7Sopenharmony_ci[[textures-texel-anisotropic-filtering]] 3012e5c31af7Sopenharmony_ci==== Texel Anisotropic Filtering 3013e5c31af7Sopenharmony_ci 3014e5c31af7Sopenharmony_ciAnisotropic filtering is enabled by the pname:anisotropyEnable in the 3015e5c31af7Sopenharmony_cisampler. 3016e5c31af7Sopenharmony_ciWhen enabled, the image filtering scheme accounts for a degree of 3017e5c31af7Sopenharmony_cianisotropy. 3018e5c31af7Sopenharmony_ci 3019e5c31af7Sopenharmony_ciThe particular scheme for anisotropic texture filtering is 3020e5c31af7Sopenharmony_ciimplementation-dependent. 3021e5c31af7Sopenharmony_ciImplementations should: consider the pname:magFilter, pname:minFilter and 3022e5c31af7Sopenharmony_cipname:mipmapMode of the sampler to control the specifics of the anisotropic 3023e5c31af7Sopenharmony_cifiltering scheme used. 3024e5c31af7Sopenharmony_ciIn addition, implementations should: consider pname:minLod and pname:maxLod 3025e5c31af7Sopenharmony_ciof the sampler. 3026e5c31af7Sopenharmony_ci 3027e5c31af7Sopenharmony_ci[NOTE] 3028e5c31af7Sopenharmony_ci.Note 3029e5c31af7Sopenharmony_ci==== 3030e5c31af7Sopenharmony_ciFor historical reasons, vendor implementations of anisotropic filtering 3031e5c31af7Sopenharmony_ciinterpret these sampler parameters in different ways, particularly in corner 3032e5c31af7Sopenharmony_cicases such as pname:magFilter, pname:minFilter of ename:NEAREST or 3033e5c31af7Sopenharmony_cipname:maxAnisotropy equal to 1.0. 3034e5c31af7Sopenharmony_ciApplications should not expect consistent behavior in such cases, and should 3035e5c31af7Sopenharmony_ciuse anisotropic filtering only with parameters which are expected to give a 3036e5c31af7Sopenharmony_ciquality improvement relative to etext:LINEAR filtering. 3037e5c31af7Sopenharmony_ci 3038e5c31af7Sopenharmony_ciThe following describes one particular approach to implementing anisotropic 3039e5c31af7Sopenharmony_cifiltering for the 2D Image case; implementations may: choose other methods: 3040e5c31af7Sopenharmony_ci 3041e5c31af7Sopenharmony_ciGiven a pname:magFilter, pname:minFilter of ename:VK_FILTER_LINEAR and a 3042e5c31af7Sopenharmony_cipname:mipmapMode of ename:VK_SAMPLER_MIPMAP_MODE_NEAREST: 3043e5c31af7Sopenharmony_ci 3044e5c31af7Sopenharmony_ciInstead of a single isotropic sample, N isotropic samples are sampled within 3045e5c31af7Sopenharmony_cithe image footprint of the image level [eq]#d# to approximate an anisotropic 3046e5c31af7Sopenharmony_cifilter. 3047e5c31af7Sopenharmony_ciThe sum [eq]#{tau}~2Daniso~# is defined using the single isotropic 3048e5c31af7Sopenharmony_ci[eq]#{tau}~2D~(u,v)# at level [eq]#d#. 3049e5c31af7Sopenharmony_ci 3050e5c31af7Sopenharmony_ci[latexmath] 3051e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 3052e5c31af7Sopenharmony_ci\begin{aligned} 3053e5c31af7Sopenharmony_ci\tau_{2Daniso} & = 3054e5c31af7Sopenharmony_ci \frac{1}{N}\sum_{i=1}^{N} 3055e5c31af7Sopenharmony_ci {\tau_{2D}\left ( 3056e5c31af7Sopenharmony_ci u \left ( x - \frac{1}{2} + \frac{i}{N+1} , y \right ), 3057e5c31af7Sopenharmony_ci v \left (x-\frac{1}{2}+\frac{i}{N+1}, y \right ) 3058e5c31af7Sopenharmony_ci \right )}, 3059e5c31af7Sopenharmony_ci & \text{when}\ \rho_{x} > \rho_{y} \\ 3060e5c31af7Sopenharmony_ci\tau_{2Daniso} &= 3061e5c31af7Sopenharmony_ci \frac{1}{N}\sum_{i=1}^{N} 3062e5c31af7Sopenharmony_ci {\tau_{2D}\left ( 3063e5c31af7Sopenharmony_ci u \left ( x, y - \frac{1}{2} + \frac{i}{N+1} \right ), 3064e5c31af7Sopenharmony_ci v \left (x,y-\frac{1}{2}+\frac{i}{N+1} \right ) 3065e5c31af7Sopenharmony_ci \right )}, 3066e5c31af7Sopenharmony_ci & \text{when}\ \rho_{y} \geq \rho_{x} 3067e5c31af7Sopenharmony_ci\end{aligned} 3068e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 3069e5c31af7Sopenharmony_ci 3070e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_2,VK_EXT_sampler_filter_minmax[] 3071e5c31af7Sopenharmony_ciWhen slink:VkSamplerReductionModeCreateInfo::pname:reductionMode is set to 3072e5c31af7Sopenharmony_ciename:VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE, the above summation is 3073e5c31af7Sopenharmony_ciused. 3074e5c31af7Sopenharmony_ciHowever, if the reduction mode is ename:VK_SAMPLER_REDUCTION_MODE_MIN or 3075e5c31af7Sopenharmony_ciename:VK_SAMPLER_REDUCTION_MODE_MAX, the process operates on the above 3076e5c31af7Sopenharmony_civalues, together with their weights, computing a component-wise minimum or 3077e5c31af7Sopenharmony_cimaximum, respectively, of the components of the values with non-zero 3078e5c31af7Sopenharmony_ciweights. 3079e5c31af7Sopenharmony_ciendif::VK_VERSION_1_2,VK_EXT_sampler_filter_minmax[] 3080e5c31af7Sopenharmony_ci==== 3081e5c31af7Sopenharmony_ci 3082e5c31af7Sopenharmony_ci 3083e5c31af7Sopenharmony_ciifdef::VK_NV_shader_image_footprint[] 3084e5c31af7Sopenharmony_ci[[textures-footprint]] 3085e5c31af7Sopenharmony_ci== Texel Footprint Evaluation 3086e5c31af7Sopenharmony_ci 3087e5c31af7Sopenharmony_ciThe SPIR-V instruction code:OpImageSampleFootprintNV evaluates the set of 3088e5c31af7Sopenharmony_citexels from a single mip level that would be accessed during a 3089e5c31af7Sopenharmony_ci<<textures-texel-filtering, texel filtering>> operation. 3090e5c31af7Sopenharmony_ciIn addition to the inputs that would be accepted by an equivalent 3091e5c31af7Sopenharmony_cicode:OpImageSample* instruction, code:OpImageSampleFootprintNV accepts two 3092e5c31af7Sopenharmony_ciadditional inputs. 3093e5c31af7Sopenharmony_ciThe code:Granularity input is an integer identifying the size of texel 3094e5c31af7Sopenharmony_cigroups used to evaluate the footprint. 3095e5c31af7Sopenharmony_ciEach bit in the returned footprint mask corresponds to an aligned block of 3096e5c31af7Sopenharmony_citexels whose size is given by the following table: 3097e5c31af7Sopenharmony_ci 3098e5c31af7Sopenharmony_ci.Texel footprint granularity values 3099e5c31af7Sopenharmony_ci[width="50%",options="header"] 3100e5c31af7Sopenharmony_ci|==== 3101e5c31af7Sopenharmony_ci| code:Granularity | code:Dim = 2D | code:Dim = 3D 3102e5c31af7Sopenharmony_ci| 0 | unsupported | unsupported 3103e5c31af7Sopenharmony_ci| 1 | 2x2 | 2x2x2 3104e5c31af7Sopenharmony_ci| 2 | 4x2 | unsupported 3105e5c31af7Sopenharmony_ci| 3 | 4x4 | 4x4x2 3106e5c31af7Sopenharmony_ci| 4 | 8x4 | unsupported 3107e5c31af7Sopenharmony_ci| 5 | 8x8 | unsupported 3108e5c31af7Sopenharmony_ci| 6 | 16x8 | unsupported 3109e5c31af7Sopenharmony_ci| 7 | 16x16 | unsupported 3110e5c31af7Sopenharmony_ci| 8 | unsupported | unsupported 3111e5c31af7Sopenharmony_ci| 9 | unsupported | unsupported 3112e5c31af7Sopenharmony_ci| 10 | unsupported | 16x16x16 3113e5c31af7Sopenharmony_ci| 11 | 64x64 | 32x16x16 3114e5c31af7Sopenharmony_ci| 12 | 128x64 | 32x32x16 3115e5c31af7Sopenharmony_ci| 13 | 128x128 | 32x32x32 3116e5c31af7Sopenharmony_ci| 14 | 256x128 | 64x32x32 3117e5c31af7Sopenharmony_ci| 15 | 256x256 | unsupported 3118e5c31af7Sopenharmony_ci|==== 3119e5c31af7Sopenharmony_ci 3120e5c31af7Sopenharmony_ciThe code:Coarse input is used to select between the two mip levels that may: 3121e5c31af7Sopenharmony_cibe accessed during texel filtering when using a pname:mipmapMode of 3122e5c31af7Sopenharmony_ciename:VK_SAMPLER_MIPMAP_MODE_LINEAR. 3123e5c31af7Sopenharmony_ciWhen filtering between two mip levels, a code:Coarse value of code:true 3124e5c31af7Sopenharmony_cirequests the footprint in the lower-resolution mip level (higher level 3125e5c31af7Sopenharmony_cinumber), while code:false requests the footprint in the higher-resolution 3126e5c31af7Sopenharmony_cimip level. 3127e5c31af7Sopenharmony_ciIf texel filtering would access only a single mip level, the footprint in 3128e5c31af7Sopenharmony_cithat level would be returned when code:Coarse is set to code:false; an empty 3129e5c31af7Sopenharmony_cifootprint would be returned when code:Coarse is set to code:true. 3130e5c31af7Sopenharmony_ci 3131e5c31af7Sopenharmony_ciThe footprint for code:OpImageSampleFootprintNV is returned in a structure 3132e5c31af7Sopenharmony_ciwith six members: 3133e5c31af7Sopenharmony_ci 3134e5c31af7Sopenharmony_ci * The first member is a boolean value that is true if the texel filtering 3135e5c31af7Sopenharmony_ci operation would access only a single mip level. 3136e5c31af7Sopenharmony_ci * The second member is a two- or three-component integer vector holding 3137e5c31af7Sopenharmony_ci the footprint anchor location. 3138e5c31af7Sopenharmony_ci For two-dimensional images, the returned components are in units of 3139e5c31af7Sopenharmony_ci eight texel groups. 3140e5c31af7Sopenharmony_ci For three-dimensional images, the returned components are in units of 3141e5c31af7Sopenharmony_ci four texel groups. 3142e5c31af7Sopenharmony_ci * The third member is a two- or three-component integer vector holding a 3143e5c31af7Sopenharmony_ci footprint offset relative to the anchor. 3144e5c31af7Sopenharmony_ci All returned components are in units of texel groups. 3145e5c31af7Sopenharmony_ci * The fourth member is a two-component integer vector mask, which holds a 3146e5c31af7Sopenharmony_ci bitfield identifying the set of texel groups in an 8x8 or 4x4x4 3147e5c31af7Sopenharmony_ci neighborhood relative to the anchor and offset. 3148e5c31af7Sopenharmony_ci * The fifth member is an integer identifying the mip level containing the 3149e5c31af7Sopenharmony_ci footprint identified by the anchor, offset, and mask. 3150e5c31af7Sopenharmony_ci * The sixth member is an integer identifying the granularity of the 3151e5c31af7Sopenharmony_ci returned footprint. 3152e5c31af7Sopenharmony_ci 3153e5c31af7Sopenharmony_ciFor footprints in two-dimensional images (code:Dim2D), the mask returned by 3154e5c31af7Sopenharmony_cicode:OpImageSampleFootprintNV indicates whether each texel group in a 8x8 3155e5c31af7Sopenharmony_cilocal neighborhood of texel groups would have one or more texels accessed 3156e5c31af7Sopenharmony_ciduring texel filtering. 3157e5c31af7Sopenharmony_ciIn the mask, the texel group with local group coordinates 3158e5c31af7Sopenharmony_cilatexmath:[(lgx,lgy)] is considered covered if and only if 3159e5c31af7Sopenharmony_ci 3160e5c31af7Sopenharmony_ci[latexmath] 3161e5c31af7Sopenharmony_ci+++++++++++++++++++ 3162e5c31af7Sopenharmony_ci\begin{aligned} 3163e5c31af7Sopenharmony_ci0 \neq ((mask.x + (mask.y << 32)) \text{ \& } (1 << (lgy \times 8 + lgx))) 3164e5c31af7Sopenharmony_ci\end{aligned} 3165e5c31af7Sopenharmony_ci+++++++++++++++++++ 3166e5c31af7Sopenharmony_ci 3167e5c31af7Sopenharmony_ciwhere: 3168e5c31af7Sopenharmony_ci 3169e5c31af7Sopenharmony_ci * latexmath:[0 \leq lgx < 8] and latexmath:[0 \leq lgy < 8]; and 3170e5c31af7Sopenharmony_ci * latexmath:[mask] is the returned two-component mask. 3171e5c31af7Sopenharmony_ci 3172e5c31af7Sopenharmony_ciThe local group with coordinates latexmath:[(lgx,lgy)] in the mask is 3173e5c31af7Sopenharmony_ciconsidered covered if and only if the texel filtering operation would access 3174e5c31af7Sopenharmony_cione or more texels latexmath:[\tau_{ij}] in the returned mip level where: 3175e5c31af7Sopenharmony_ci[latexmath] 3176e5c31af7Sopenharmony_ci+++++++++++++++++++ 3177e5c31af7Sopenharmony_ci\begin{aligned} 3178e5c31af7Sopenharmony_cii0 & = 3179e5c31af7Sopenharmony_ci \begin{cases} 3180e5c31af7Sopenharmony_ci gran.x \times (8 \times anchor.x + lgx), & \text{if } lgx + offset.x < 8 \\ 3181e5c31af7Sopenharmony_ci gran.x \times (8 \times (anchor.x - 1) + lgx), & \text{otherwise} 3182e5c31af7Sopenharmony_ci \end{cases} \\ 3183e5c31af7Sopenharmony_cii1 & = i0 + gran.x - 1 \\ 3184e5c31af7Sopenharmony_cij0 & = 3185e5c31af7Sopenharmony_ci \begin{cases} 3186e5c31af7Sopenharmony_ci gran.y \times (8 \times anchor.y + lgy), & \text{if } lgy + offset.y < 8 \\ 3187e5c31af7Sopenharmony_ci gran.y \times (8 \times (anchor.y - 1) + lgy), & otherwise 3188e5c31af7Sopenharmony_ci \end{cases} \\ 3189e5c31af7Sopenharmony_cij1 & = j0 + gran.y - 1 3190e5c31af7Sopenharmony_ci\end{aligned} 3191e5c31af7Sopenharmony_ci+++++++++++++++++++ 3192e5c31af7Sopenharmony_ciand 3193e5c31af7Sopenharmony_ci 3194e5c31af7Sopenharmony_ci * latexmath:[i0 \leq i \leq i1] and latexmath:[j0 \leq j \leq j1]; 3195e5c31af7Sopenharmony_ci * latexmath:[gran] is a two-component vector holding the width and height 3196e5c31af7Sopenharmony_ci of the texel group identified by the granularity; 3197e5c31af7Sopenharmony_ci * latexmath:[anchor] is the returned two-component anchor vector; and 3198e5c31af7Sopenharmony_ci * latexmath:[offset] is the returned two-component offset vector. 3199e5c31af7Sopenharmony_ci 3200e5c31af7Sopenharmony_ciFor footprints in three-dimensional images (code:Dim3D), the mask returned 3201e5c31af7Sopenharmony_ciby code:OpImageSampleFootprintNV indicates whether each texel group in a 3202e5c31af7Sopenharmony_ci4x4x4 local neighborhood of texel groups would have one or more texels 3203e5c31af7Sopenharmony_ciaccessed during texel filtering. 3204e5c31af7Sopenharmony_ciIn the mask, the texel group with local group coordinates 3205e5c31af7Sopenharmony_cilatexmath:[(lgx,lgy,lgz)], is considered covered if and only if: 3206e5c31af7Sopenharmony_ci[latexmath] 3207e5c31af7Sopenharmony_ci+++++++++++++++++++ 3208e5c31af7Sopenharmony_ci\begin{aligned} 3209e5c31af7Sopenharmony_ci0 \neq ((mask.x + (mask.y << 32)) \text{ \& } (1 << (lgz \times 16 + lgy \times 4 + lgx))) 3210e5c31af7Sopenharmony_ci\end{aligned} 3211e5c31af7Sopenharmony_ci+++++++++++++++++++ 3212e5c31af7Sopenharmony_ciwhere: 3213e5c31af7Sopenharmony_ci 3214e5c31af7Sopenharmony_ci * latexmath:[0 \leq lgx < 4], latexmath:[0 \leq lgy < 4], and latexmath:[0 3215e5c31af7Sopenharmony_ci \leq lgz < 4]; and 3216e5c31af7Sopenharmony_ci * latexmath:[mask] is the returned two-component mask. 3217e5c31af7Sopenharmony_ci 3218e5c31af7Sopenharmony_ciThe local group with coordinates latexmath:[(lgx,lgy,lgz)] in the mask is 3219e5c31af7Sopenharmony_ciconsidered covered if and only if the texel filtering operation would access 3220e5c31af7Sopenharmony_cione or more texels latexmath:[\tau_{ijk}] in the returned mip level where: 3221e5c31af7Sopenharmony_ci[latexmath] 3222e5c31af7Sopenharmony_ci+++++++++++++++++++ 3223e5c31af7Sopenharmony_ci\begin{aligned} 3224e5c31af7Sopenharmony_cii0 & = 3225e5c31af7Sopenharmony_ci \begin{cases} 3226e5c31af7Sopenharmony_ci gran.x \times (4 \times anchor.x + lgx), & \text{if } lgx + offset.x < 4 \\ 3227e5c31af7Sopenharmony_ci gran.x \times (4 \times (anchor.x - 1) + lgx), & \text{otherwise} 3228e5c31af7Sopenharmony_ci \end{cases} \\ 3229e5c31af7Sopenharmony_cii1 & = i0 + gran.x - 1 \\ 3230e5c31af7Sopenharmony_cij0 & = 3231e5c31af7Sopenharmony_ci \begin{cases} 3232e5c31af7Sopenharmony_ci gran.y \times (4 \times anchor.y + lgy), & \text{if } lgy + offset.y < 4 \\ 3233e5c31af7Sopenharmony_ci gran.y \times (4 \times (anchor.y - 1) + lgy), & otherwise 3234e5c31af7Sopenharmony_ci \end{cases} \\ 3235e5c31af7Sopenharmony_cij1 & = j0 + gran.y - 1 \\ 3236e5c31af7Sopenharmony_cik0 & = 3237e5c31af7Sopenharmony_ci \begin{cases} 3238e5c31af7Sopenharmony_ci gran.z \times (4 \times anchor.z + lgz), & \text{if } lgz + offset.z < 4 \\ 3239e5c31af7Sopenharmony_ci gran.z \times (4 \times (anchor.z - 1) + lgz), & otherwise 3240e5c31af7Sopenharmony_ci \end{cases} \\ 3241e5c31af7Sopenharmony_cik1 & = k0 + gran.z - 1 3242e5c31af7Sopenharmony_ci\end{aligned} 3243e5c31af7Sopenharmony_ci+++++++++++++++++++ 3244e5c31af7Sopenharmony_ciand 3245e5c31af7Sopenharmony_ci 3246e5c31af7Sopenharmony_ci * latexmath:[i0 \leq i \leq i1], latexmath:[j0 \leq j \leq j1], 3247e5c31af7Sopenharmony_ci latexmath:[k0 \leq k \leq k1]; 3248e5c31af7Sopenharmony_ci * latexmath:[gran] is a three-component vector holding the width, height, 3249e5c31af7Sopenharmony_ci and depth of the texel group identified by the granularity; 3250e5c31af7Sopenharmony_ci * latexmath:[anchor] is the returned three-component anchor vector; and 3251e5c31af7Sopenharmony_ci * latexmath:[offset] is the returned three-component offset vector. 3252e5c31af7Sopenharmony_ci 3253e5c31af7Sopenharmony_ciIf the sampler used by code:OpImageSampleFootprintNV enables anisotropic 3254e5c31af7Sopenharmony_citexel filtering via pname:anisotropyEnable, it is possible that the set of 3255e5c31af7Sopenharmony_citexel groups accessed in a mip level may be too large to be expressed using 3256e5c31af7Sopenharmony_cian 8x8 or 4x4x4 mask using the granularity requested in the instruction. 3257e5c31af7Sopenharmony_ciIn this case, the implementation uses a texel group larger than the 3258e5c31af7Sopenharmony_cirequested granularity. 3259e5c31af7Sopenharmony_ciWhen a larger texel group size is used, code:OpImageSampleFootprintNV 3260e5c31af7Sopenharmony_cireturns an integer granularity value that can: be interpreted in the same 3261e5c31af7Sopenharmony_cimanner as the granularity value provided to the instruction to determine the 3262e5c31af7Sopenharmony_citexel group size used. 3263e5c31af7Sopenharmony_ciIf anisotropic texel filtering is disabled in the sampler, or if an 3264e5c31af7Sopenharmony_cianisotropic footprint can be represented as an 8x8 or 4x4x4 mask with the 3265e5c31af7Sopenharmony_cirequested granularity, code:OpImageSampleFootprintNV will use the requested 3266e5c31af7Sopenharmony_cigranularity as-is and return a granularity value of zero. 3267e5c31af7Sopenharmony_ci 3268e5c31af7Sopenharmony_cicode:OpImageSampleFootprintNV supports only two- and three-dimensional image 3269e5c31af7Sopenharmony_ciaccesses (code:Dim2D and code:Dim3D), and the footprint returned is 3270e5c31af7Sopenharmony_ciundefined: if a sampler uses an addressing mode other than 3271e5c31af7Sopenharmony_ciename:VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE. 3272e5c31af7Sopenharmony_ci 3273e5c31af7Sopenharmony_ciendif::VK_NV_shader_image_footprint[] 3274e5c31af7Sopenharmony_ci 3275e5c31af7Sopenharmony_ci 3276e5c31af7Sopenharmony_ciifdef::VK_QCOM_image_processing[] 3277e5c31af7Sopenharmony_ci[[textures-weightimage]] 3278e5c31af7Sopenharmony_ci== Weight Image Sampling 3279e5c31af7Sopenharmony_ci 3280e5c31af7Sopenharmony_ciThe SPIR-V instruction code:OpImageWeightedSampleQCOM specifies a texture 3281e5c31af7Sopenharmony_cisampling operation involving two images: the _sampled image_ and the _weight 3282e5c31af7Sopenharmony_ciimage_. 3283e5c31af7Sopenharmony_ciIt is similar to bilinear filtering except more than 2x2 texels may 3284e5c31af7Sopenharmony_ciparticipate in the filter and the filter weights are user-specified rather 3285e5c31af7Sopenharmony_cithan computed by fixed-function hardware. 3286e5c31af7Sopenharmony_ciThe weight image view defines a 2D kernel weights used during sampling. 3287e5c31af7Sopenharmony_ci 3288e5c31af7Sopenharmony_ciThe code:OpImageWeightedSampleQCOM support normalized or unnormalized texel 3289e5c31af7Sopenharmony_cicoordinates. 3290e5c31af7Sopenharmony_ciIn addition to the inputs that would be accepted by an equivalent 3291e5c31af7Sopenharmony_cicode:OpImageSample* instruction, code:OpImageWeightedSampleQCOM accepts a 3292e5c31af7Sopenharmony_cicode:weight input that specifies the view of a sample weight image 3293e5c31af7Sopenharmony_ci 3294e5c31af7Sopenharmony_ciThe input code:weight must: be a view of a 2D or 1D image with 3295e5c31af7Sopenharmony_cicode:miplevels equal to `1`, code:samples equal to 3296e5c31af7Sopenharmony_ciename:VK_SAMPLE_COUNT_1_BIT, created with an identity swizzle, and created 3297e5c31af7Sopenharmony_ciwith code:usage that includes ename:VK_IMAGE_USAGE_SAMPLE_WEIGHT_BIT_QCOM. 3298e5c31af7Sopenharmony_ciThe slink:VkImageViewSampleWeightCreateInfoQCOM specifies additional 3299e5c31af7Sopenharmony_ciparameters of the view: pname:filterCenter, pname:filterSize, and 3300e5c31af7Sopenharmony_cipname:numPhases. 3301e5c31af7Sopenharmony_cidescribed in more detail below. 3302e5c31af7Sopenharmony_ci 3303e5c31af7Sopenharmony_ciThe code:weight input must: be bound using a 3304e5c31af7Sopenharmony_ci<<descriptorsets-weightimage,sample weight image>> descriptor type. 3305e5c31af7Sopenharmony_ciThe code:weight view defines a filtering kernel that is a region of view's 3306e5c31af7Sopenharmony_cisubresource range. 3307e5c31af7Sopenharmony_ciThe kernel spans a region from integer texel coordinate [eq]#(0,0)# to 3308e5c31af7Sopenharmony_ci[eq]#(pname:filterSize.x-1, pname:filterSize.y-1)#. 3309e5c31af7Sopenharmony_ciIt is valid for the view's subresource to have dimensions larger than the 3310e5c31af7Sopenharmony_cikernel but the texels with integer coordinates greater than 3311e5c31af7Sopenharmony_ci[eq]#(pname:filterSize.width-1, pname:filterSize.height-1)# are ignored by 3312e5c31af7Sopenharmony_ciweight sampling. 3313e5c31af7Sopenharmony_ciThe value returned by queries code:OpImageQuerySize, 3314e5c31af7Sopenharmony_cicode:OpImageQuerySizeLod, code:OpImageQueryLevels, and 3315e5c31af7Sopenharmony_cicode:OpImageQuerySamples return for a weight image is undefined:. 3316e5c31af7Sopenharmony_ci 3317e5c31af7Sopenharmony_cipname:filterCenter designates an integer texel coordinate within the filter 3318e5c31af7Sopenharmony_cikernel as being the 'center' of the kernel. 3319e5c31af7Sopenharmony_ciThe center must: be in the range [eq]#(0,0)# to [eq]#(pname:filterSize.x-1, 3320e5c31af7Sopenharmony_cipname:filterSize.y-1)#. 3321e5c31af7Sopenharmony_cipname:numPhases describes the number of filter phases used to provide 3322e5c31af7Sopenharmony_cisub-pixel filtering. 3323e5c31af7Sopenharmony_ciBoth are described in more detail below. 3324e5c31af7Sopenharmony_ci 3325e5c31af7Sopenharmony_ci 3326e5c31af7Sopenharmony_ci[[textures-weightimage-layout]] 3327e5c31af7Sopenharmony_ci=== Weight Image Layout 3328e5c31af7Sopenharmony_ci 3329e5c31af7Sopenharmony_ciThe weight image specifies filtering kernel weight values. 3330e5c31af7Sopenharmony_ciA 2D image view can be used to specify a 2D matrix of filter weights. 3331e5c31af7Sopenharmony_ciFor separable filers, a 1D image view can be used to specity the horizontal 3332e5c31af7Sopenharmony_ciand vertical weights. 3333e5c31af7Sopenharmony_ci 3334e5c31af7Sopenharmony_ci 3335e5c31af7Sopenharmony_ci==== 2D Non-Separable Weight Filters 3336e5c31af7Sopenharmony_ci 3337e5c31af7Sopenharmony_ciA 2D image view defined with slink:VkImageViewSampleWeightCreateInfoQCOM 3338e5c31af7Sopenharmony_cidescribes a 2D matrix [eq]#(pname:filterSize.width {times} 3339e5c31af7Sopenharmony_cipname:filterSize.height)# of weight elements with filter's center point at 3340e5c31af7Sopenharmony_cipname:filterCenter. 3341e5c31af7Sopenharmony_ciNote that pname:filterSize can be smaller than the view's subresource, but 3342e5c31af7Sopenharmony_cithe filter will always be located starting at integer texel coordinate 3343e5c31af7Sopenharmony_ci[eq]#(0,0)#. 3344e5c31af7Sopenharmony_ci 3345e5c31af7Sopenharmony_ciThe following figure illustrates a 2D convolution filter having 3346e5c31af7Sopenharmony_cipname:filterSize of [eq]#(4,3)# and pname:filterCenter at [eq]#(1, 1)#. 3347e5c31af7Sopenharmony_ci 3348e5c31af7Sopenharmony_ciimage::{images}/weight_filter_2d.svg[align="center",title="2D Convolution Filter",opts="{imageopts}"] 3349e5c31af7Sopenharmony_ci 3350e5c31af7Sopenharmony_ciFor a 2D weight filter, the phases are stored as layers of a 2D array image. 3351e5c31af7Sopenharmony_ciThe width and height of the view's subresource range must: be less than or 3352e5c31af7Sopenharmony_ciequal to 3353e5c31af7Sopenharmony_cislink:VkPhysicalDeviceImageProcessingPropertiesQCOM::pname:maxWeightFilterDimension. 3354e5c31af7Sopenharmony_ciThe layers are stored in horizontal phase major order. 3355e5c31af7Sopenharmony_ciExpressed as a formula, the layer index for a each filter phase is computed 3356e5c31af7Sopenharmony_cias: 3357e5c31af7Sopenharmony_ci 3358e5c31af7Sopenharmony_ci[source,c] 3359e5c31af7Sopenharmony_ci---- 3360e5c31af7Sopenharmony_cilayerIndex(horizPhase,vertPhase,horizPhaseCount) = (vertPhase * horizPhaseCount) + horizPhase 3361e5c31af7Sopenharmony_ci---- 3362e5c31af7Sopenharmony_ci 3363e5c31af7Sopenharmony_ci 3364e5c31af7Sopenharmony_ci==== 1D Separable Weight Filters 3365e5c31af7Sopenharmony_ci 3366e5c31af7Sopenharmony_ciA separable weight filter is a 2D filter that can be specified by two 1D 3367e5c31af7Sopenharmony_cifilters in the [eq]#x# and [eq]#y# directions such that their product yields 3368e5c31af7Sopenharmony_cithe 2D filter. 3369e5c31af7Sopenharmony_ciThe following example shows a 2D filter and its associated separable 1D 3370e5c31af7Sopenharmony_cihorizontal and vertical filters. 3371e5c31af7Sopenharmony_ci 3372e5c31af7Sopenharmony_ciimage::{images}/weight_filter_1d_separable.svg[align="center",title="Separable 2D Convolution Filter",opts="{imageopts}"] 3373e5c31af7Sopenharmony_ci 3374e5c31af7Sopenharmony_ciA 1D array image view defined with 3375e5c31af7Sopenharmony_cislink:VkImageViewSampleWeightCreateInfoQCOM and with pname:layerCount equal 3376e5c31af7Sopenharmony_cito '2' describes a separable weight filter. 3377e5c31af7Sopenharmony_ciThe horizontal weights are specified in slice '0' and the vertical weights 3378e5c31af7Sopenharmony_ciin slice '1'. 3379e5c31af7Sopenharmony_ciThe pname:filterSize and pname:filterCenter specify the size and origin of 3380e5c31af7Sopenharmony_cithe of the horizontal and vertical filters. 3381e5c31af7Sopenharmony_ciFor many use cases, 1D separable filters can offer a performance advantage 3382e5c31af7Sopenharmony_ciover 2D filters. 3383e5c31af7Sopenharmony_ci 3384e5c31af7Sopenharmony_ciFor a 1D separable weight filter, the phases are arranged into a 1D array 3385e5c31af7Sopenharmony_ciimage with two layers. 3386e5c31af7Sopenharmony_ciThe horizontal weights are stored in layer 0 and the vertical weights in 3387e5c31af7Sopenharmony_cilayer 1. 3388e5c31af7Sopenharmony_ciWithin each layer of the 1D array image, the weights are arranged into 3389e5c31af7Sopenharmony_cigroups of 4, and then arranged by phase. 3390e5c31af7Sopenharmony_ciExpressed as a formula, the 1D texel offset for each weight within each 3391e5c31af7Sopenharmony_cilayer is computed as: 3392e5c31af7Sopenharmony_ci 3393e5c31af7Sopenharmony_ci[source,c] 3394e5c31af7Sopenharmony_ci---- 3395e5c31af7Sopenharmony_ci// Let horizontal weights have a weightIndex of [0, filterSize.width - 1] 3396e5c31af7Sopenharmony_ci// Let vertical weights have a weightIndex of [0, filterSize.height - 1] 3397e5c31af7Sopenharmony_ci// Let phaseCount be the number of phases in either the vertical or horizontal direction. 3398e5c31af7Sopenharmony_ci 3399e5c31af7Sopenharmony_citexelOffset(phaseIndex,weightIndex,phaseCount) = (phaseCount * 4 * (weightIndex / 4)) + (phaseIndex * 4) + (weightIndex % 4) 3400e5c31af7Sopenharmony_ci---- 3401e5c31af7Sopenharmony_ci 3402e5c31af7Sopenharmony_ci 3403e5c31af7Sopenharmony_ci[[textures-weightimage-filterphases]] 3404e5c31af7Sopenharmony_ci=== Weight Sampling Phases 3405e5c31af7Sopenharmony_ci 3406e5c31af7Sopenharmony_ciWhen using weight image sampling, the texture coordinates may not align with 3407e5c31af7Sopenharmony_cia texel center in the sampled image. 3408e5c31af7Sopenharmony_ciIn this case, the filter weights can be adjusted based on the subpixel 3409e5c31af7Sopenharmony_cilocation. 3410e5c31af7Sopenharmony_ciThis is termed "`subpixel filtering`" to indicate that the origin of the 3411e5c31af7Sopenharmony_cifilter lies at a subpixel location other than the texel center. 3412e5c31af7Sopenharmony_ciConceptually, this means that the weight filter is positioned such that 3413e5c31af7Sopenharmony_cifilter taps do not align with sampled texels exactly. 3414e5c31af7Sopenharmony_ciIn such a case, modified filter weights may be needed to adjust for the 3415e5c31af7Sopenharmony_cioff-center filter taps. 3416e5c31af7Sopenharmony_ciUnlike bilinear filtering where the subpixel weights are computed by the 3417e5c31af7Sopenharmony_ciimplementation, subpixel weight image sampling requires that the per-phase 3418e5c31af7Sopenharmony_cifilter weights are pre-computed by the application and stored in an array 3419e5c31af7Sopenharmony_ciwhere each slice of the array is a "`filter phase`". 3420e5c31af7Sopenharmony_ciThe array is indexed by the implementation based on subpixel positioning. 3421e5c31af7Sopenharmony_ciRather than a single 2D kernel of filter weights, the application provides 3422e5c31af7Sopenharmony_cian array of kernels, one set of filter weights per phase. 3423e5c31af7Sopenharmony_ci 3424e5c31af7Sopenharmony_ciThe number of phases are restricted by following requirements, which apply 3425e5c31af7Sopenharmony_cito both separable and non-separable filters: 3426e5c31af7Sopenharmony_ci 3427e5c31af7Sopenharmony_ci * The number of phases in the vertical direction, [eq]#phaseCount~vert~#, 3428e5c31af7Sopenharmony_ci must: be a power of two (i.e., 1, 2, 4, etc.). 3429e5c31af7Sopenharmony_ci * The number of phases in the horizontal direction 3430e5c31af7Sopenharmony_ci [eq]#phaseCount~horiz~#, must: equal [eq]#phaseCount~vert~#. 3431e5c31af7Sopenharmony_ci * The total number of phases, [eq]#phaseCount~vert~ {times} 3432e5c31af7Sopenharmony_ci phaseCount~horiz~#, must: be less than or equal to 3433e5c31af7Sopenharmony_ci slink:VkPhysicalDeviceImageProcessingPropertiesQCOM::pname:maxWeightFilterPhases. 3434e5c31af7Sopenharmony_ci 3435e5c31af7Sopenharmony_ci 3436e5c31af7Sopenharmony_ci[[textures-weightimage-sampler]] 3437e5c31af7Sopenharmony_ci=== Weight Sampler Parameters 3438e5c31af7Sopenharmony_ci 3439e5c31af7Sopenharmony_ciWeight sampling requires sname:VkSamplerCreateInfo pname:addressModeU and 3440e5c31af7Sopenharmony_cipname:addressModeV must: be set to 3441e5c31af7Sopenharmony_ciename:VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE or 3442e5c31af7Sopenharmony_ciename:VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER. 3443e5c31af7Sopenharmony_ciIf ename:VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER is used, then the border 3444e5c31af7Sopenharmony_cicolor must: be set to transparent black. 3445e5c31af7Sopenharmony_ci 3446e5c31af7Sopenharmony_ci 3447e5c31af7Sopenharmony_ci[[textures-weightimage-filteroperation]] 3448e5c31af7Sopenharmony_ci=== Weight Sampling Operation 3449e5c31af7Sopenharmony_ci 3450e5c31af7Sopenharmony_ciThe 2D unnormalized texel coordinates latexmath:[(u,v)] are transformed by 3451e5c31af7Sopenharmony_cilatexmath:[filterCenter] to specify coordinates latexmath:[i_{0}, j_{0}]. 3452e5c31af7Sopenharmony_ci 3453e5c31af7Sopenharmony_ci[latexmath] 3454e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 3455e5c31af7Sopenharmony_ci\begin{aligned} 3456e5c31af7Sopenharmony_cii_{0} &= \left\lfloor u - filterCenter_{x} \right\rfloor \\[1em] 3457e5c31af7Sopenharmony_cij_{0} &= \left\lfloor v - filterCenter_{y} \right\rfloor 3458e5c31af7Sopenharmony_ci\end{aligned} 3459e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 3460e5c31af7Sopenharmony_ciwhere latexmath:[filterCenter] is specified by 3461e5c31af7Sopenharmony_cislink:VkImageViewSampleWeightCreateInfoQCOM::pname:filterCenter. 3462e5c31af7Sopenharmony_ci 3463e5c31af7Sopenharmony_ci 3464e5c31af7Sopenharmony_ciTwo sets of neighboring integer 2D texel coordinates are generated. 3465e5c31af7Sopenharmony_ciThe first set is used for selecting texels from the sampled image 3466e5c31af7Sopenharmony_cilatexmath:[\tau] and the second set used for selecting texels from the 3467e5c31af7Sopenharmony_ciweight image latexmath:[w]. 3468e5c31af7Sopenharmony_ciThe first set of neighboring coordinates are combinations of 3469e5c31af7Sopenharmony_cilatexmath:[i_{0}] to latexmath:[i_{filterWidth-1}] and latexmath:[j_{0}] to 3470e5c31af7Sopenharmony_cilatexmath:[j_{filterHeight-1}]. 3471e5c31af7Sopenharmony_ciThe second set of neighboring coordinates are combinations of 3472e5c31af7Sopenharmony_cilatexmath:[k_{0}] to latexmath:[k_{filterWidth-1}] and latexmath:[l_{0}] to 3473e5c31af7Sopenharmony_cilatexmath:[l_{filterHeight-1}]. 3474e5c31af7Sopenharmony_ciThe first and second sets each contain latexmath:[(filterWidth \times 3475e5c31af7Sopenharmony_cifilterHeight)] of pairs of latexmath:[(i,j)] and latexmath:[(k,l)] 3476e5c31af7Sopenharmony_cicoordinates respectively. 3477e5c31af7Sopenharmony_ci 3478e5c31af7Sopenharmony_ci[latexmath] 3479e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 3480e5c31af7Sopenharmony_ci\begin{aligned} 3481e5c31af7Sopenharmony_ci\{i_q\}_{q=0}^{q=filterWidth-1} \quad &= i_{0} + q \\[1em] 3482e5c31af7Sopenharmony_ci\{j_q\}_{q=0}^{q=filterHeight-1} \quad &= j_{0} + q \\[1em] 3483e5c31af7Sopenharmony_ci\{k_q\}_{q=0}^{q=filterWidth-1} \quad &= q \\[1em] 3484e5c31af7Sopenharmony_ci\{l_q\}_{q=0}^{q=filterHeight-1} \quad &= q 3485e5c31af7Sopenharmony_ci\end{aligned} 3486e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 3487e5c31af7Sopenharmony_ci 3488e5c31af7Sopenharmony_ciwhere latexmath:[filterWidth] and latexmath:[filterHeight] are specified by 3489e5c31af7Sopenharmony_cislink:VkImageViewSampleWeightCreateInfoQCOM::pname:filterSize. 3490e5c31af7Sopenharmony_ci 3491e5c31af7Sopenharmony_ciEach of the generated integer coordinates latexmath:[({i_q}, {j_q})] is 3492e5c31af7Sopenharmony_citransformed by <<textures-wrapping-operation, texture wrapping operation>>, 3493e5c31af7Sopenharmony_cifollowed by <<textures-integer-coordinate-validation,integer texel 3494e5c31af7Sopenharmony_cicoordinate validation>>, If any coordinate fails coordinate validation, it 3495e5c31af7Sopenharmony_ciis a Border Texel and <<textures-texel-replacement,texel replacement>> is 3496e5c31af7Sopenharmony_ciperformed. 3497e5c31af7Sopenharmony_ci 3498e5c31af7Sopenharmony_ci 3499e5c31af7Sopenharmony_ciThe phase index latexmath:[\psi] is computed from the fraction bits of the 3500e5c31af7Sopenharmony_ciunnormalized 2D texel coordinates: 3501e5c31af7Sopenharmony_ci 3502e5c31af7Sopenharmony_ci[latexmath] 3503e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 3504e5c31af7Sopenharmony_ci\begin{aligned} 3505e5c31af7Sopenharmony_ciphaseCount_{h} = phaseCount_{v} &= \sqrt{numPhases} \\[1em] 3506e5c31af7Sopenharmony_cihPhase &= \left\lfloor\mathbin{frac}\left( u \right) \times phaseCount_{h} \right\rfloor \\[1em] 3507e5c31af7Sopenharmony_civPhase &= \left\lfloor\mathbin{frac}\left( v \right) \times phaseCount_{v} \right\rfloor \\[1em] 3508e5c31af7Sopenharmony_ci\psi &= \left(vPhase \times phaseCount_{h}\right) + hPhase 3509e5c31af7Sopenharmony_ci\end{aligned} 3510e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 3511e5c31af7Sopenharmony_ci 3512e5c31af7Sopenharmony_ciwhere the number of fraction bits retained is 3513e5c31af7Sopenharmony_cilatexmath:[\mathbin{log2}\left( numPhases \right)] specified by 3514e5c31af7Sopenharmony_cislink:VkImageViewSampleWeightCreateInfoQCOM::pname:numPhases 3515e5c31af7Sopenharmony_ci 3516e5c31af7Sopenharmony_ciEach pair of texel coordinates latexmath:[(i,j)] in the first set selects a 3517e5c31af7Sopenharmony_cisingle texel value latexmath:[\tau_{ij}] from the sampled image. 3518e5c31af7Sopenharmony_ciEach pair of texel coordinates latexmath:[(k,l)] in the second set, combined 3519e5c31af7Sopenharmony_ciwith phaseIndex latexmath:[\psi], selects a single weight from the weight 3520e5c31af7Sopenharmony_ciimage latexmath:[w(k,l,\psi)] . 3521e5c31af7Sopenharmony_ci 3522e5c31af7Sopenharmony_ci 3523e5c31af7Sopenharmony_ci[latexmath] 3524e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 3525e5c31af7Sopenharmony_ci\begin{aligned} 3526e5c31af7Sopenharmony_ciw(k,l,\psi) &= 3527e5c31af7Sopenharmony_ci \begin{cases} 3528e5c31af7Sopenharmony_ci w_{kl}[\psi]\quad\text{(}\psi\text{ as layer index)} & \text{for 2D array view (non-separable filter) } \\ 3529e5c31af7Sopenharmony_ci weight_{h} \times weight_{v} & \text{for 1D array view (separable filter) } \\ 3530e5c31af7Sopenharmony_ci \end{cases} 3531e5c31af7Sopenharmony_ci\end{aligned} 3532e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 3533e5c31af7Sopenharmony_ci 3534e5c31af7Sopenharmony_ciIf latexmath:[w] is a 2D array view, then non-separable filtering is 3535e5c31af7Sopenharmony_cispecified, and integer coordinates latexmath:[(k,l)] are used to select 3536e5c31af7Sopenharmony_citexels from layer latexmath:[\psi] of latexmath:[(w)]. 3537e5c31af7Sopenharmony_ciIf latexmath:[w] is a 1D array view, then separable filtering is specified 3538e5c31af7Sopenharmony_ciand integer coordinates latexmath:[(k,l)] are transformed to 3539e5c31af7Sopenharmony_cilatexmath:[(k_{packed},l_{packed})], and used to select horizontal weight 3540e5c31af7Sopenharmony_cilatexmath:[(weight_{h})] and vertical weight latexmath:[(weight_{v})] texels 3541e5c31af7Sopenharmony_cifrom layer 0 and layer 1 of latexmath:[(w)] respectively. 3542e5c31af7Sopenharmony_ci 3543e5c31af7Sopenharmony_ci[latexmath] 3544e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 3545e5c31af7Sopenharmony_ci\begin{aligned} 3546e5c31af7Sopenharmony_cik_{packed} &= \left(phaseCount_{h} \times 4 \times \left\lfloor k / 4 \right\rfloor\right) + \left(hPhase \times 4\right) + \left(k \mathbin{\%} 4\right) \\[1em] 3547e5c31af7Sopenharmony_cil_{packed}& = \left(phaseCount_{v} \times 4 \times \left\lfloor l / 4 \right\rfloor\right) + \left(vPhase \times 4\right) + \left(l \mathbin{\%} 4\right) \\[1em] 3548e5c31af7Sopenharmony_ciweight_{h} &= w_{k_{packed}}[0] & \text{(horizontal weights packed in layer 0)} \\[1em] 3549e5c31af7Sopenharmony_ciweight_{v} &= w_{l_{packed}}[1] & \text{(vertical weights packed in layer 1)} 3550e5c31af7Sopenharmony_ci 3551e5c31af7Sopenharmony_ci\end{aligned} 3552e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 3553e5c31af7Sopenharmony_ci 3554e5c31af7Sopenharmony_ciWhere latexmath:[\mathbin{\%}] refers to the integer modulo operator. 3555e5c31af7Sopenharmony_ci 3556e5c31af7Sopenharmony_ciThe values of multiple texels, together with their weights, are combined to 3557e5c31af7Sopenharmony_ciproduce a filtered value. 3558e5c31af7Sopenharmony_ci 3559e5c31af7Sopenharmony_ci 3560e5c31af7Sopenharmony_ci[latexmath] 3561e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 3562e5c31af7Sopenharmony_ci\begin{aligned} 3563e5c31af7Sopenharmony_ci\tau_{weightSampling} &= \sum_{{j=j_0} \atop {l=l_0}}^{j_{blockHeight-1} \atop {l_{blockHeight-1}}}\quad \sum_{{i=i_0}\atop {k=k_0}}^{i_{blockWidth-1} \atop {k_{blockWidth-1}}}w(k,l,\psi)\tau_{ij} \\ 3564e5c31af7Sopenharmony_ci\end{aligned} 3565e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 3566e5c31af7Sopenharmony_ci 3567e5c31af7Sopenharmony_ciWhen slink:VkSamplerReductionModeCreateInfo::pname:reductionMode is set to 3568e5c31af7Sopenharmony_ciename:VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE, the above summation is 3569e5c31af7Sopenharmony_ciused. 3570e5c31af7Sopenharmony_ciHowever, if the reduction mode is ename:VK_SAMPLER_REDUCTION_MODE_MIN or 3571e5c31af7Sopenharmony_ciename:VK_SAMPLER_REDUCTION_MODE_MAX, the process operates on the above 3572e5c31af7Sopenharmony_civalues, computing a component-wise minimum or maximum of the texels with 3573e5c31af7Sopenharmony_cinon-zero weights. 3574e5c31af7Sopenharmony_ciIf the reduction mode is ename:VK_SAMPLER_REDUCTION_MODE_MIN or 3575e5c31af7Sopenharmony_ciename:VK_SAMPLER_REDUCTION_MODE_MAX, each latexmath:[w(k,l,\psi)] weight 3576e5c31af7Sopenharmony_cimust: be equal to 0.0 or 1.0, otherwise the undefined: values are returned. 3577e5c31af7Sopenharmony_ci 3578e5c31af7Sopenharmony_ciFinally, the operations described in 3579e5c31af7Sopenharmony_ci<<textures-conversion-to-rgba,Conversion to RGBA>> and 3580e5c31af7Sopenharmony_ci<<textures-component-swizzle,Component swizzle>> are performed and the final 3581e5c31af7Sopenharmony_ciresult is returned to the shader. 3582e5c31af7Sopenharmony_ci 3583e5c31af7Sopenharmony_ci 3584e5c31af7Sopenharmony_ci[[textures-blockmatch]] 3585e5c31af7Sopenharmony_ci== Block Matching 3586e5c31af7Sopenharmony_ci 3587e5c31af7Sopenharmony_ciThe SPIR-V instruction code:opImageBlockMatchSAD and 3588e5c31af7Sopenharmony_cicode:opImageBlockMatchSSD specify texture block matching operations where a 3589e5c31af7Sopenharmony_ciblock or region of texels within a _target image_ is compared with a 3590e5c31af7Sopenharmony_cisame-sized region a _reference image_. 3591e5c31af7Sopenharmony_ciThe instructions make use of two image views: the _target view_ and the 3592e5c31af7Sopenharmony_ci_reference view_. 3593e5c31af7Sopenharmony_ciThe target view and reference view can be the same view, allowing block 3594e5c31af7Sopenharmony_cimatching of two blocks within a single image. 3595e5c31af7Sopenharmony_ci 3596e5c31af7Sopenharmony_ciSimilar to an equivalent code:OpImageFetch instruction, 3597e5c31af7Sopenharmony_cicode:opImageBlockMatchSAD and code:opImageBlockMatchSAD specify a code:image 3598e5c31af7Sopenharmony_ciand an integer texel code:coordinate which which describes the bottom-left 3599e5c31af7Sopenharmony_citexel of the target block. 3600e5c31af7Sopenharmony_ciThere are three additional inputs. 3601e5c31af7Sopenharmony_ciThe code:reference and code:refCoodinate specifies bottom-left texel of the 3602e5c31af7Sopenharmony_cireference block. 3603e5c31af7Sopenharmony_ciThe code:blockSize specifies the integer width and height of the target and 3604e5c31af7Sopenharmony_cireference blocks to be compared, and must: not be greater than 3605e5c31af7Sopenharmony_cislink:VkPhysicalDeviceImageProcessingPropertiesQCOM.code:maxBlockMatchRegion. 3606e5c31af7Sopenharmony_ci 3607e5c31af7Sopenharmony_ciifdef::VK_QCOM_image_processing2[] 3608e5c31af7Sopenharmony_cicode:opImageBlockMatchWindowSAD and code:opImageBlockMatchWindowSAD take the 3609e5c31af7Sopenharmony_cisame input parameters as the corresponding non-window instructions. 3610e5c31af7Sopenharmony_ciThe block matching comparison is performed for all pixel values within a 2D 3611e5c31af7Sopenharmony_ciwindow whose dimensions are specified in the sampler. 3612e5c31af7Sopenharmony_ciendif::VK_QCOM_image_processing2[] 3613e5c31af7Sopenharmony_ci 3614e5c31af7Sopenharmony_ci 3615e5c31af7Sopenharmony_ci[[textures-blockmatch-sampler]] 3616e5c31af7Sopenharmony_ci=== Block Matching Sampler Parameters 3617e5c31af7Sopenharmony_ci 3618e5c31af7Sopenharmony_ciFor code:opImageBlockMatchSAD and code:opImageBlockMatchSSD, the input 3619e5c31af7Sopenharmony_cicode:sampler must: be created with code:addressModeU and code:addressModeV, 3620e5c31af7Sopenharmony_ciequal to ename:VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, or 3621e5c31af7Sopenharmony_ciename:VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER with 3622e5c31af7Sopenharmony_ciename:VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK. 3623e5c31af7Sopenharmony_ciThe input code:sampler must: be created with code:unnormalizedCoordinates 3624e5c31af7Sopenharmony_ciequal to ename:VK_TRUE. 3625e5c31af7Sopenharmony_ciThe input code:sampler must: be created with pname:components equal to 3626e5c31af7Sopenharmony_ciename:VK_COMPONENT_SWIZZLE_IDENTITY. 3627e5c31af7Sopenharmony_ci 3628e5c31af7Sopenharmony_ci 3629e5c31af7Sopenharmony_ciifdef::VK_QCOM_image_processing2[] 3630e5c31af7Sopenharmony_ciFor code:opImageBlockMatchWindowSAD and code:opImageBlockMatchWindowSSD 3631e5c31af7Sopenharmony_ciinstructions, the code:target sampler must: have been created with 3632e5c31af7Sopenharmony_cislink:VkSamplerBlockMatchWindowCreateInfoQCOM in the code:pNext chain. 3633e5c31af7Sopenharmony_ci 3634e5c31af7Sopenharmony_ciFor code:opImageBlockMatchWindowSAD, code:opImageBlockMatchWindowSSD, 3635e5c31af7Sopenharmony_cicode:opImageBlockMatchGatherSAD, or 3636e5c31af7Sopenharmony_cicode:opImageBlockMatchGatherSSDinstructions, the input code:sampler must: be 3637e5c31af7Sopenharmony_cicreated with code:addressModeU and code:addressModeV, equal to 3638e5c31af7Sopenharmony_ciename:VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER with 3639e5c31af7Sopenharmony_ciename:VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK. 3640e5c31af7Sopenharmony_ciendif::VK_QCOM_image_processing2[] 3641e5c31af7Sopenharmony_ci 3642e5c31af7Sopenharmony_ciOther sampler states are ignored. 3643e5c31af7Sopenharmony_ci 3644e5c31af7Sopenharmony_ci 3645e5c31af7Sopenharmony_ci[[textures-blockmatch-filteroperation]] 3646e5c31af7Sopenharmony_ci=== Block Matching Operation 3647e5c31af7Sopenharmony_ci 3648e5c31af7Sopenharmony_ciBlock matching SPIR-V instructions code:opImageBlockMatchSAD and 3649e5c31af7Sopenharmony_cicode:opImageBlockMatchSSD specify two sets of 2D integer texel coordinates: 3650e5c31af7Sopenharmony_citarget coordinates latexmath:[(u,v)] and reference coordinates 3651e5c31af7Sopenharmony_cilatexmath:[(s,t)]. 3652e5c31af7Sopenharmony_ci 3653e5c31af7Sopenharmony_ciThe coordinates define the bottom-left texel of the target block 3654e5c31af7Sopenharmony_cilatexmath:[(i_{0}, j_{0})] and the reference block latexmath:[(k_{0}, 3655e5c31af7Sopenharmony_cil_{0})]. 3656e5c31af7Sopenharmony_ci 3657e5c31af7Sopenharmony_ci[latexmath] 3658e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 3659e5c31af7Sopenharmony_ci\begin{aligned} 3660e5c31af7Sopenharmony_cii_{0} &= u \\[1em] 3661e5c31af7Sopenharmony_cij_{0} &= v \\[1em] 3662e5c31af7Sopenharmony_cik_{0} &= s \\[1em] 3663e5c31af7Sopenharmony_cil_{0} &= t 3664e5c31af7Sopenharmony_ci\end{aligned} 3665e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 3666e5c31af7Sopenharmony_ci 3667e5c31af7Sopenharmony_ciFor the target block, a set of neighboring integer texel coordinates are 3668e5c31af7Sopenharmony_cigenerated. 3669e5c31af7Sopenharmony_ciThe neighboring coordinates are combinations of latexmath:[i_{0}] to 3670e5c31af7Sopenharmony_cilatexmath:[i_{blockWidth-1}] and latexmath:[j_{0}] to 3671e5c31af7Sopenharmony_cilatexmath:[j_{blockHeight-1}]. 3672e5c31af7Sopenharmony_ciThe set is of size latexmath:[blockWidth \times blockHeight]. 3673e5c31af7Sopenharmony_ci 3674e5c31af7Sopenharmony_ci[latexmath] 3675e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 3676e5c31af7Sopenharmony_ci\begin{aligned} 3677e5c31af7Sopenharmony_ci\{i_q\}_{q=0}^{q=blockWidth-1} \quad &= i_{0} + q \\[1em] 3678e5c31af7Sopenharmony_ci\{j_q\}_{q=0}^{q=blockHeight-1} \quad &= j_{0} + q 3679e5c31af7Sopenharmony_ci\end{aligned} 3680e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 3681e5c31af7Sopenharmony_ci 3682e5c31af7Sopenharmony_ciwhere latexmath:[blockWidth] and latexmath:[blockHeight] is specified by the 3683e5c31af7Sopenharmony_cicode:blockSize operand. 3684e5c31af7Sopenharmony_ci 3685e5c31af7Sopenharmony_ciIf any target integer texel coordinate latexmath:[(i,j)] in the set fails 3686e5c31af7Sopenharmony_ci<<textures-integer-coordinate-validation,integer texel coordinate 3687e5c31af7Sopenharmony_civalidation>>, then the texel is an invalid texel and 3688e5c31af7Sopenharmony_ci<<textures-texel-replacement,texel replacement>> is performed. 3689e5c31af7Sopenharmony_ci 3690e5c31af7Sopenharmony_ciSimilarly for the reference block, a set of neighboring integer texel 3691e5c31af7Sopenharmony_cicoordinates are generated. 3692e5c31af7Sopenharmony_ci 3693e5c31af7Sopenharmony_ci[latexmath] 3694e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 3695e5c31af7Sopenharmony_ci\begin{aligned} 3696e5c31af7Sopenharmony_ci\{k_q\}_{q=0}^{q=blockWidth-1} \quad &= k_{0} + q \\[1em] 3697e5c31af7Sopenharmony_ci\{l_q\}_{q=0}^{q=blockHeight-1} \quad &= l_{0} + q 3698e5c31af7Sopenharmony_ci\end{aligned} 3699e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 3700e5c31af7Sopenharmony_ci 3701e5c31af7Sopenharmony_ciEach reference texel coordinate latexmath:[(k,l)] in the set must: not fail 3702e5c31af7Sopenharmony_ci<<textures-integer-coordinate-validation,integer texel coordinate 3703e5c31af7Sopenharmony_civalidation>>. 3704e5c31af7Sopenharmony_ciTo avoid undefined: behavior, application shader should guarantee that the 3705e5c31af7Sopenharmony_cireference block is fully within the bounds of the reference image. 3706e5c31af7Sopenharmony_ci 3707e5c31af7Sopenharmony_ciEach pair of texel coordinates latexmath:[(i,j)] in the set selects a single 3708e5c31af7Sopenharmony_citexel value from the target image latexmath:[\tau_{ij}]. 3709e5c31af7Sopenharmony_ciEach pair of texel coordinates latexmath:[(k,l)] in the set selects a single 3710e5c31af7Sopenharmony_citexel value from the reference image latexmath:[\upsilon_{kl}]. 3711e5c31af7Sopenharmony_ci 3712e5c31af7Sopenharmony_ciThe difference between target and reference texel values is summed to 3713e5c31af7Sopenharmony_cicompute a difference metric. 3714e5c31af7Sopenharmony_ciThe code:opTextureBlockMatchSAD computes the sum of absolute differences. 3715e5c31af7Sopenharmony_ci 3716e5c31af7Sopenharmony_ci[latexmath] 3717e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 3718e5c31af7Sopenharmony_ci\begin{aligned} 3719e5c31af7Sopenharmony_ci\tau_{SAD} &= \sum_{{j=j_0} \atop {l=l_0}}^{{j_{blockHeight-1}} \atop {l_{blockHeight-1}}} \quad\sum_{{i=i_0} \atop {k=k_0}}^{{i_{blockWidth-1}} \atop {k_{blockWidth-1}}}|\upsilon_{kl}-\tau_{ij}| \\ 3720e5c31af7Sopenharmony_ci\end{aligned} 3721e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 3722e5c31af7Sopenharmony_ci 3723e5c31af7Sopenharmony_ciThe code:opImageBlockMatchSSD computes the sum of the squared differences. 3724e5c31af7Sopenharmony_ci 3725e5c31af7Sopenharmony_ci[latexmath] 3726e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 3727e5c31af7Sopenharmony_ci\begin{aligned} 3728e5c31af7Sopenharmony_ci\tau_{SSD} &= \sum_{{j=j_0} \atop {l=l_0}}^{{j_{blockHeight-1}} \atop {l_{blockHeight-1}}} \quad\sum_{{i=i_0} \atop {k=k_0}}^{{i_{blockWidth-1}} \atop {k_{blockWidth-1}}}|\upsilon_{kl}-\tau_{ij}|^2 \\ 3729e5c31af7Sopenharmony_ci\end{aligned} 3730e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 3731e5c31af7Sopenharmony_ci 3732e5c31af7Sopenharmony_ciWhen slink:VkSamplerReductionModeCreateInfo::pname:reductionMode is set to 3733e5c31af7Sopenharmony_ciename:VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE, the above summation is 3734e5c31af7Sopenharmony_ciused. 3735e5c31af7Sopenharmony_ciHowever, if the reduction mode is ename:VK_SAMPLER_REDUCTION_MODE_MIN or 3736e5c31af7Sopenharmony_ciename:VK_SAMPLER_REDUCTION_MODE_MAX, the process operates on the above 3737e5c31af7Sopenharmony_civalues, computing a component-wise minimum or maximum of 3738e5c31af7Sopenharmony_cilatexmath:[|\upsilon_{kl}-\tau_{ij}|], respectively. 3739e5c31af7Sopenharmony_ciFor latexmath:[\tau_{SAD}], the minimum or maximum difference is computed 3740e5c31af7Sopenharmony_ciand for latexmath:[\tau_{SSD}], the square of the minimum or maximum is 3741e5c31af7Sopenharmony_cicomputed. 3742e5c31af7Sopenharmony_ci 3743e5c31af7Sopenharmony_ciFinally, the operations described in 3744e5c31af7Sopenharmony_ci<<textures-conversion-to-rgba,Conversion to RGBA>> and 3745e5c31af7Sopenharmony_ci<<textures-component-swizzle,Component swizzle>> are performed and the final 3746e5c31af7Sopenharmony_ciresult is returned to the shader. 3747e5c31af7Sopenharmony_ciThe component swizzle is specified by the _target image_ descriptor; any 3748e5c31af7Sopenharmony_ciswizzle specified by the _reference image_ descriptor is ignored. 3749e5c31af7Sopenharmony_ci 3750e5c31af7Sopenharmony_ci 3751e5c31af7Sopenharmony_ciifdef::VK_QCOM_image_processing2[] 3752e5c31af7Sopenharmony_ci[[textures-blockmatchwindow-filteroperation]] 3753e5c31af7Sopenharmony_ci==== Block Matching Window Operation 3754e5c31af7Sopenharmony_ci 3755e5c31af7Sopenharmony_ciWindow block matching SPIR-V instructions code:opImageBlockMatchWindowSAD 3756e5c31af7Sopenharmony_ciand code:opImageBlockMatchWindowSSD specify two sets of 2D integer texel 3757e5c31af7Sopenharmony_cicoordinates: target coordinates latexmath:[(u,v)] and reference coordinates 3758e5c31af7Sopenharmony_cilatexmath:[(s,t)]. 3759e5c31af7Sopenharmony_ciThe <<textures-blockmatch-filteroperation,block matching operation>> is 3760e5c31af7Sopenharmony_ciperformed repeatedly, for multiple sets of target integer coordinates within 3761e5c31af7Sopenharmony_cithe specified window. 3762e5c31af7Sopenharmony_ciThese instructions effectively search a region or "`window`" within the 3763e5c31af7Sopenharmony_citarget texture and identify the window coordinates where the minimum or 3764e5c31af7Sopenharmony_cimaximum error metric is found. 3765e5c31af7Sopenharmony_ciThese instructions only support single component image formats. 3766e5c31af7Sopenharmony_ci 3767e5c31af7Sopenharmony_ciThe target coordinates are combinations of coordinates from 3768e5c31af7Sopenharmony_cilatexmath:[(u,v)] to latexmath:[(u + windowWidth - 1, v + windowHeight - 1)] 3769e5c31af7Sopenharmony_ciwhere latexmath:[windowHeight] and latexmath:[windowWidth] are specified by 3770e5c31af7Sopenharmony_cislink:VkSamplerBlockMatchWindowCreateInfoQCOM::pname:windowExtent. 3771e5c31af7Sopenharmony_ciAt each each target coordinate, a 3772e5c31af7Sopenharmony_ci<<textures-blockmatch-filteroperation,block matching operation>> is 3773e5c31af7Sopenharmony_ciperformed, resulting in a difference metric. 3774e5c31af7Sopenharmony_ciThe reference coordinate latexmath:[(s,t)] is fixed. 3775e5c31af7Sopenharmony_ciThe block matching operation is repeated latexmath:[windowWidth \times 3776e5c31af7Sopenharmony_ciwindowHeight] times. 3777e5c31af7Sopenharmony_ci 3778e5c31af7Sopenharmony_ciThe resulting minimum or maximum error is returned in the R component of the 3779e5c31af7Sopenharmony_cioutput. 3780e5c31af7Sopenharmony_ciThe integer window coordinates latexmath:[(x,y)] are returned in the G and B 3781e5c31af7Sopenharmony_cicomponents of the output. 3782e5c31af7Sopenharmony_ciThe A component is 0. 3783e5c31af7Sopenharmony_ciThe minimum or maximum behavior is selected by 3784e5c31af7Sopenharmony_cislink:VkSamplerBlockMatchWindowCreateInfoQCOM::pname:windowCompareMode. 3785e5c31af7Sopenharmony_ci 3786e5c31af7Sopenharmony_ciThe following pseudocode describes the operation 3787e5c31af7Sopenharmony_cicode:opImageBlockMatchWindowSAD. 3788e5c31af7Sopenharmony_ciThe pseudocode for code:opImageBlockMatchWindowSSD follows an identical 3789e5c31af7Sopenharmony_cipattern. 3790e5c31af7Sopenharmony_ci 3791e5c31af7Sopenharmony_ci[source,c] 3792e5c31af7Sopenharmony_ci---- 3793e5c31af7Sopenharmony_civec4 opImageBlockMatchGatherSAD( sampler2D target, 3794e5c31af7Sopenharmony_ci uvec2 targetCoord, 3795e5c31af7Sopenharmony_ci samler2D reference, 3796e5c31af7Sopenharmony_ci uvec2 refCoord, 3797e5c31af7Sopenharmony_ci uvec2 blocksize) { 3798e5c31af7Sopenharmony_ci // Two parameters are sourced from the VkSampler associated with 3799e5c31af7Sopenharmony_ci // `target`: 3800e5c31af7Sopenharmony_ci // compareMode (which can be either `MIN` or `MAX`) 3801e5c31af7Sopenharmony_ci // uvec2 window (which defines the search window) 3802e5c31af7Sopenharmony_ci 3803e5c31af7Sopenharmony_ci minSAD = INF; 3804e5c31af7Sopenharmony_ci maxSAD = -INF; 3805e5c31af7Sopenharmony_ci uvec2 minCoord; 3806e5c31af7Sopenharmony_ci uvec2 maxCoord; 3807e5c31af7Sopenharmony_ci 3808e5c31af7Sopenharmony_ci for (uint x=0, x<window.width; x++) { 3809e5c31af7Sopenharmony_ci for (uint y=0; y<window.height; y++) { 3810e5c31af7Sopenharmony_ci float SAD = textureBlockMatchSAD(target, 3811e5c31af7Sopenharmony_ci targetCoord + uvec2(x, y), 3812e5c31af7Sopenharmony_ci reference, 3813e5c31af7Sopenharmony_ci refCoord, 3814e5c31af7Sopenharmony_ci blocksize).x; 3815e5c31af7Sopenharmony_ci if (SAD < minSAD) { 3816e5c31af7Sopenharmony_ci minSAD = SAD; 3817e5c31af7Sopenharmony_ci minCoord = uvec2(x,y); 3818e5c31af7Sopenharmony_ci } 3819e5c31af7Sopenharmony_ci if (SAD > maxSAD) { 3820e5c31af7Sopenharmony_ci maxSAD = SAD; 3821e5c31af7Sopenharmony_ci maxCoord = uvec2(x,y); 3822e5c31af7Sopenharmony_ci } 3823e5c31af7Sopenharmony_ci } 3824e5c31af7Sopenharmony_ci } 3825e5c31af7Sopenharmony_ci if (compareMode==MIN) { 3826e5c31af7Sopenharmony_ci return vec4(minSAD, minCoord.x, minCoord.y, 0.0); 3827e5c31af7Sopenharmony_ci } else { 3828e5c31af7Sopenharmony_ci return vec4(maxSAD, maxCoord.x, maxCoord.y, 0.0); 3829e5c31af7Sopenharmony_ci } 3830e5c31af7Sopenharmony_ci} 3831e5c31af7Sopenharmony_ci---- 3832e5c31af7Sopenharmony_ci 3833e5c31af7Sopenharmony_ci 3834e5c31af7Sopenharmony_ci[[textures-blockmatchgather-filteroperation]] 3835e5c31af7Sopenharmony_ci==== Block Matching Gather Operation 3836e5c31af7Sopenharmony_ci 3837e5c31af7Sopenharmony_ciBlock matching Gather SPIR-V instructions code:opImageBlockMatchGatherSAD 3838e5c31af7Sopenharmony_ciand code:opImageBlockMatchGatherSSD specify two sets of 2D integer texel 3839e5c31af7Sopenharmony_cicoordinates: target coordinates latexmath:[(u,v)] and reference coordinates 3840e5c31af7Sopenharmony_cilatexmath:[(s,t)]. 3841e5c31af7Sopenharmony_ci 3842e5c31af7Sopenharmony_ciThese instructions perform the <<textures-blockmatch-filteroperation,block 3843e5c31af7Sopenharmony_cimatching operation>> 4 times, using integer target coordinates 3844e5c31af7Sopenharmony_cilatexmath:[(u,v)], latexmath:[(u+1,v)], latexmath:[(u+2,v)], and 3845e5c31af7Sopenharmony_cilatexmath:[(u+3,v)]. 3846e5c31af7Sopenharmony_ciThe R component from each of those 4 operations is gathered and returned in 3847e5c31af7Sopenharmony_cithe R, G, B, and A components of the output respectively. 3848e5c31af7Sopenharmony_ciFor each block match operation, the reference coordinate is 3849e5c31af7Sopenharmony_cilatexmath:[(s,t)]. 3850e5c31af7Sopenharmony_ciFor each block match operation, only the R component of the target and 3851e5c31af7Sopenharmony_cireference images are compared. 3852e5c31af7Sopenharmony_ciThe following pseudocode describes the operation opImageBlockMatchGatherSAD. 3853e5c31af7Sopenharmony_ciThe pseudocode for opImageBlockMatchGatherSSD follows an identical pattern. 3854e5c31af7Sopenharmony_ci 3855e5c31af7Sopenharmony_ci[source,c] 3856e5c31af7Sopenharmony_ci---- 3857e5c31af7Sopenharmony_civec4 opImageBlockMatchGatherSAD(sampler2D target, 3858e5c31af7Sopenharmony_ci uvec2 targetCoord, 3859e5c31af7Sopenharmony_ci samler2D reference, 3860e5c31af7Sopenharmony_ci uvec2 refCoord, 3861e5c31af7Sopenharmony_ci uvec2 blocksize) { 3862e5c31af7Sopenharmony_ci vec4 out; 3863e5c31af7Sopenharmony_ci for (uint x=0, x<4; x++) { 3864e5c31af7Sopenharmony_ci float SAD = textureBlockMatchSAD(target, 3865e5c31af7Sopenharmony_ci targetCoord + uvec2(x, 0), 3866e5c31af7Sopenharmony_ci reference, 3867e5c31af7Sopenharmony_ci refCoord, 3868e5c31af7Sopenharmony_ci blocksize).x; 3869e5c31af7Sopenharmony_ci if (x == 0) { 3870e5c31af7Sopenharmony_ci out.x = SAD; 3871e5c31af7Sopenharmony_ci } 3872e5c31af7Sopenharmony_ci if (x == 1) { 3873e5c31af7Sopenharmony_ci out.y = SAD; 3874e5c31af7Sopenharmony_ci } 3875e5c31af7Sopenharmony_ci if (x == 2) { 3876e5c31af7Sopenharmony_ci out.z = SAD; 3877e5c31af7Sopenharmony_ci } 3878e5c31af7Sopenharmony_ci if (x == 3) { 3879e5c31af7Sopenharmony_ci out.w = SAD; 3880e5c31af7Sopenharmony_ci } 3881e5c31af7Sopenharmony_ci } 3882e5c31af7Sopenharmony_ci return out; 3883e5c31af7Sopenharmony_ci} 3884e5c31af7Sopenharmony_ci---- 3885e5c31af7Sopenharmony_ciendif::VK_QCOM_image_processing2[] 3886e5c31af7Sopenharmony_ci 3887e5c31af7Sopenharmony_ci 3888e5c31af7Sopenharmony_ci[[textures-boxfilter]] 3889e5c31af7Sopenharmony_ci== Box Filter Sampling 3890e5c31af7Sopenharmony_ci 3891e5c31af7Sopenharmony_ciThe SPIR-V instruction code:OpImageBoxFilterQCOM specifies texture box 3892e5c31af7Sopenharmony_cifiltering operation where a weighted average of a region of texels is 3893e5c31af7Sopenharmony_cicomputed, with the weights proportional to the coverage of each of the 3894e5c31af7Sopenharmony_citexels. 3895e5c31af7Sopenharmony_ci 3896e5c31af7Sopenharmony_ciIn addition to the inputs that would be accepted by an equivalent 3897e5c31af7Sopenharmony_cicode:OpImageSample* instruction, code:OpImageBoxFilterQCOM accepts one 3898e5c31af7Sopenharmony_ciadditional input, code:boxSize which specifies the width and height in 3899e5c31af7Sopenharmony_citexels of the region to be averaged. 3900e5c31af7Sopenharmony_ci 3901e5c31af7Sopenharmony_ciThe figure below shows an example of using code:OpImageBoxFilterQCOM to 3902e5c31af7Sopenharmony_cisample from a [eq]#8 {times} 4# texel two-dimensional image, with 3903e5c31af7Sopenharmony_ciunnormalized texture coordinates [eq]#(4.125, 2.625)# and code:boxSize of 3904e5c31af7Sopenharmony_ci[eq]#(2.75, 2.25)#. 3905e5c31af7Sopenharmony_ciThe filter will read 12 texel values and compute a weights based portion of 3906e5c31af7Sopenharmony_ciof each texel covered by the box. 3907e5c31af7Sopenharmony_ci 3908e5c31af7Sopenharmony_ci[[textures-box-filter-diagrams]] 3909e5c31af7Sopenharmony_ciimage::{images}/vulkantexture_boxFilter.svg[align="center",title="Box Filter Sampling Example",opts="{imageopts}"] 3910e5c31af7Sopenharmony_ci 3911e5c31af7Sopenharmony_ciIf code:boxSize has height and width both equal to 1.0, then this 3912e5c31af7Sopenharmony_ciinstruction will behave as traditional bilinear filtering. 3913e5c31af7Sopenharmony_ciThe code:boxSize parameter must: be greater than or equal to 1.0 and must: 3914e5c31af7Sopenharmony_cinot be greater than 3915e5c31af7Sopenharmony_cislink:VkPhysicalDeviceImageProcessingPropertiesQCOM.code:maxBoxFilterBlockSize. 3916e5c31af7Sopenharmony_ci 3917e5c31af7Sopenharmony_ci 3918e5c31af7Sopenharmony_ci[[textures-boxfilter-sampler]] 3919e5c31af7Sopenharmony_ci=== Box Filter Sampler Parameters 3920e5c31af7Sopenharmony_ci 3921e5c31af7Sopenharmony_ciThe input code:sampler must: be created with code:addressModeU and 3922e5c31af7Sopenharmony_cicode:addressModeV, equal to ename:VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, or 3923e5c31af7Sopenharmony_ciename:VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER with 3924e5c31af7Sopenharmony_ciename:VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK. 3925e5c31af7Sopenharmony_ci 3926e5c31af7Sopenharmony_ci 3927e5c31af7Sopenharmony_ci[[textures-boxfilter-filteroperation]] 3928e5c31af7Sopenharmony_ci=== Box Filter Operation 3929e5c31af7Sopenharmony_ci 3930e5c31af7Sopenharmony_ciThe 2D unnormalized texel coordinates latexmath:[(u,v)] are transformed by 3931e5c31af7Sopenharmony_cilatexmath:[boxSize] to specify integer texel coordinates latexmath:[(i_{0}, 3932e5c31af7Sopenharmony_cij_{0})] of the bottom left texel for the filter. 3933e5c31af7Sopenharmony_ci 3934e5c31af7Sopenharmony_ci[latexmath] 3935e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 3936e5c31af7Sopenharmony_ci\begin{aligned} 3937e5c31af7Sopenharmony_cii_{0} &= \left\lfloor u - \frac{boxWidth}{2} \right\rfloor \\[1em] 3938e5c31af7Sopenharmony_cij_{0} &= \left\lfloor v - \frac{boxHeight}{2} \right\rfloor 3939e5c31af7Sopenharmony_ci\end{aligned} 3940e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 3941e5c31af7Sopenharmony_ci 3942e5c31af7Sopenharmony_ciwhere latexmath:[boxWidth] and latexmath:[boxHeight] are specified by the 3943e5c31af7Sopenharmony_cicode:(x,y) components of the code:boxSize operand. 3944e5c31af7Sopenharmony_ci 3945e5c31af7Sopenharmony_ciThe filter dimensions latexmath:[(filterWidth \times filterHeight)] are 3946e5c31af7Sopenharmony_cicomputed from the fractional portion of the latexmath:[(u,v)] coordinates 3947e5c31af7Sopenharmony_ciand the latexmath:[boxSize]. 3948e5c31af7Sopenharmony_ci 3949e5c31af7Sopenharmony_ci[latexmath] 3950e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 3951e5c31af7Sopenharmony_ci\begin{aligned} 3952e5c31af7Sopenharmony_cistartFracU &= \mathbin{frac}\left(u - \frac{boxWidth}{2} \right) \\[1em] 3953e5c31af7Sopenharmony_cistartFracV &= \mathbin{frac}\left(v - \frac{boxHeight}{2} \right) \\[1em] 3954e5c31af7Sopenharmony_ciendFracU &= \mathbin{frac}\left( startFracU + boxWidth \right) \\[1em] 3955e5c31af7Sopenharmony_ciendFracV &= \mathbin{frac}\left( startFracV + boxHeight \right) \\[1em] 3956e5c31af7Sopenharmony_cifilterWidth &= \left\lceil startFracU + boxWidth \right\rceil \\[1em] 3957e5c31af7Sopenharmony_cifilterHeight &= \left\lceil startFracV + boxHeight \right\rceil 3958e5c31af7Sopenharmony_ci\end{aligned} 3959e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 3960e5c31af7Sopenharmony_ci 3961e5c31af7Sopenharmony_ciwhere the number of fraction bits retained by latexmath:[frac()] is 3962e5c31af7Sopenharmony_cispecified by sname:VkPhysicalDeviceLimits::pname:subTexelPrecisionBits. 3963e5c31af7Sopenharmony_ci 3964e5c31af7Sopenharmony_ciA set of neighboring integer texel coordinates are generated. 3965e5c31af7Sopenharmony_ciThe neighboring coordinates are combinations of latexmath:[i_{0}] to 3966e5c31af7Sopenharmony_cilatexmath:[i_{filterWidth-1}] and latexmath:[j_{0}] to 3967e5c31af7Sopenharmony_cilatexmath:[j_{filterHeight-1}], with latexmath:[i_{0}, j_{0}] being the 3968e5c31af7Sopenharmony_citop-left coordinate of this set. 3969e5c31af7Sopenharmony_ciThe set is of size latexmath:[(filterWidth \times filterHeight)]. 3970e5c31af7Sopenharmony_ci 3971e5c31af7Sopenharmony_ci[latexmath] 3972e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 3973e5c31af7Sopenharmony_ci\begin{aligned} 3974e5c31af7Sopenharmony_ci\{i_q\}_{q=0}^{q=filterWidth-1} \quad &= i_{0} + q \\[1em] 3975e5c31af7Sopenharmony_ci\{j_q\}_{q=0}^{q=filterHeight-1} \quad &= j_{0} + q 3976e5c31af7Sopenharmony_ci\end{aligned} 3977e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 3978e5c31af7Sopenharmony_ci 3979e5c31af7Sopenharmony_ciEach of the generated integer coordinates latexmath:[({i_q}, {j_q})] is 3980e5c31af7Sopenharmony_citransformed by <<textures-wrapping-operation, texture wrapping operation>>, 3981e5c31af7Sopenharmony_cifollowed by <<textures-integer-coordinate-validation,integer texel 3982e5c31af7Sopenharmony_cicoordinate validation>>, If any coordinate fails coordinate validation, it 3983e5c31af7Sopenharmony_ciis a Border Texel and <<textures-texel-replacement,texel replacement>> is 3984e5c31af7Sopenharmony_ciperformed. 3985e5c31af7Sopenharmony_ci 3986e5c31af7Sopenharmony_ciHorizontal weights latexmath:[horizWeight_{0}] to 3987e5c31af7Sopenharmony_cilatexmath:[horizWeight_{boxWidth-1}] and vertical weights 3988e5c31af7Sopenharmony_cilatexmath:[vertWeight_{0}] to latexmath:[vertWeight_{boxHeight-1}] are 3989e5c31af7Sopenharmony_cicomputed. 3990e5c31af7Sopenharmony_ciTexels that are fully covered by the box will have a horizontal and vertical 3991e5c31af7Sopenharmony_ciweight of 1. 3992e5c31af7Sopenharmony_ciTexels partially covered by the box will have will have a reduced weights 3993e5c31af7Sopenharmony_ciproportional to the coverage. 3994e5c31af7Sopenharmony_ci 3995e5c31af7Sopenharmony_ci[latexmath] 3996e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 3997e5c31af7Sopenharmony_ci\begin{aligned} 3998e5c31af7Sopenharmony_cihorizWeight_{i} &= 3999e5c31af7Sopenharmony_ci \begin{cases} 4000e5c31af7Sopenharmony_ci \left(1-startFracU \right), & \text{for } (i == 0) \\ 4001e5c31af7Sopenharmony_ci \left(endFracU \right), & \text{for } (i == filterWidth-1) \text{ and } (endFracU != 0) \\ 4002e5c31af7Sopenharmony_ci \left(1\right), & \text{otherwise} \\ 4003e5c31af7Sopenharmony_ci \end{cases} 4004e5c31af7Sopenharmony_ci\end{aligned} 4005e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 4006e5c31af7Sopenharmony_ci 4007e5c31af7Sopenharmony_ci[latexmath] 4008e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 4009e5c31af7Sopenharmony_ci\begin{aligned} 4010e5c31af7Sopenharmony_civertWeight_{j} &= 4011e5c31af7Sopenharmony_ci \begin{cases} 4012e5c31af7Sopenharmony_ci \left(1-startFracV \right), & \text{for } (j == 0) \\ 4013e5c31af7Sopenharmony_ci \left(endFracV \right), & \text{for } (j == filterHeight-1) \text{ and } (endFracV !=0) \\ 4014e5c31af7Sopenharmony_ci \left(1\right), & \text{otherwise} \\ 4015e5c31af7Sopenharmony_ci \end{cases} 4016e5c31af7Sopenharmony_ci\end{aligned} 4017e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 4018e5c31af7Sopenharmony_ci 4019e5c31af7Sopenharmony_ci 4020e5c31af7Sopenharmony_ciThe values of multiple texels, together with their horizontal and vertical 4021e5c31af7Sopenharmony_ciweights, are combined to produce a box filtered value. 4022e5c31af7Sopenharmony_ci 4023e5c31af7Sopenharmony_ci[latexmath] 4024e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 4025e5c31af7Sopenharmony_ci\begin{aligned} 4026e5c31af7Sopenharmony_ci\tau_{boxFilter} &= \frac{1}{boxHeight \times boxWidth} \sum_{j=j_0}^{j_{filterHeight-1}}\quad\sum_{i=i_0}^{i_{filterWidth-1}}(horizWeight_i)(vertWeight_j)\tau_{ij} \\ 4027e5c31af7Sopenharmony_ci\end{aligned} 4028e5c31af7Sopenharmony_ci++++++++++++++++++++++++ 4029e5c31af7Sopenharmony_ci 4030e5c31af7Sopenharmony_ciWhen slink:VkSamplerReductionModeCreateInfo::pname:reductionMode is set to 4031e5c31af7Sopenharmony_ciename:VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE, the above summation is 4032e5c31af7Sopenharmony_ciused. 4033e5c31af7Sopenharmony_ciHowever, if the reduction mode is ename:VK_SAMPLER_REDUCTION_MODE_MIN or 4034e5c31af7Sopenharmony_ciename:VK_SAMPLER_REDUCTION_MODE_MAX, the process operates on the above 4035e5c31af7Sopenharmony_civalues, computing a component-wise minimum or maximum of the texels. 4036e5c31af7Sopenharmony_ci 4037e5c31af7Sopenharmony_ciendif::VK_QCOM_image_processing[] 4038e5c31af7Sopenharmony_ci 4039e5c31af7Sopenharmony_ci 4040e5c31af7Sopenharmony_ci[[textures-instructions]] 4041e5c31af7Sopenharmony_ci== Image Operation Steps 4042e5c31af7Sopenharmony_ci 4043e5c31af7Sopenharmony_ciEach step described in this chapter is performed by a subset of the image 4044e5c31af7Sopenharmony_ciinstructions: 4045e5c31af7Sopenharmony_ci 4046e5c31af7Sopenharmony_ci * Texel Input Validation Operations, Format Conversion, Texel Replacement, 4047e5c31af7Sopenharmony_ci Conversion to RGBA, and Component Swizzle: Performed by all instructions 4048e5c31af7Sopenharmony_ci except code:OpImageWrite. 4049e5c31af7Sopenharmony_ci * Depth Comparison: Performed by code:OpImage*Dref instructions. 4050e5c31af7Sopenharmony_ci * All Texel output operations: Performed by code:OpImageWrite. 4051e5c31af7Sopenharmony_ci * Projection: Performed by all code:OpImage*Proj instructions. 4052e5c31af7Sopenharmony_ci * Derivative Image Operations, Cube Map Operations, Scale Factor 4053e5c31af7Sopenharmony_ci Operation, LOD Operation and Image Level(s) Selection, and Texel 4054e5c31af7Sopenharmony_ci Anisotropic Filtering: Performed by all code:OpImageSample* and 4055e5c31af7Sopenharmony_ci code:OpImageSparseSample* instructions. 4056e5c31af7Sopenharmony_ci * (s,t,r,q,a) to (u,v,w,a) Transformation, Wrapping, and (u,v,w,a) to 4057e5c31af7Sopenharmony_ci (i,j,k,l,n) Transformation And Array Layer Selection: Performed by all 4058e5c31af7Sopenharmony_ci code:OpImageSample, code:OpImageSparseSample, and code:OpImage*Gather 4059e5c31af7Sopenharmony_ci instructions. 4060e5c31af7Sopenharmony_ci * Texel Gathering: Performed by code:OpImage*Gather instructions. 4061e5c31af7Sopenharmony_ciifdef::VK_NV_shader_image_footprint[] 4062e5c31af7Sopenharmony_ci * Texel Footprint Evaluation: Performed by code:OpImageSampleFootprint 4063e5c31af7Sopenharmony_ci instructions. 4064e5c31af7Sopenharmony_ciendif::VK_NV_shader_image_footprint[] 4065e5c31af7Sopenharmony_ci * Texel Filtering: Performed by all code:OpImageSample* and 4066e5c31af7Sopenharmony_ci code:OpImageSparseSample* instructions. 4067e5c31af7Sopenharmony_ci * Sparse Residency: Performed by all code:OpImageSparse* instructions. 4068e5c31af7Sopenharmony_ciifdef::VK_QCOM_image_processing[] 4069e5c31af7Sopenharmony_ci * (s,t,r,q,a) to (u,v,w,a) Transformation, Wrapping, and Weight Image 4070e5c31af7Sopenharmony_ci Sampling: Performed by code:OpImageWeightedSample* instructions. 4071e5c31af7Sopenharmony_ci * (s,t,r,q,a) to (u,v,w,a) Transformation, Wrapping, and Block Matching: 4072e5c31af7Sopenharmony_ci Performed by code:opImageBlockMatch* instructions. 4073e5c31af7Sopenharmony_ci * (s,t,r,q,a) to (u,v,w,a) Transformation, Wrapping, and Box Filter 4074e5c31af7Sopenharmony_ci Sampling: Performed by code:OpImageBoxFilter* instructions. 4075e5c31af7Sopenharmony_ciendif::VK_QCOM_image_processing[] 4076e5c31af7Sopenharmony_ci 4077e5c31af7Sopenharmony_ci 4078e5c31af7Sopenharmony_ci[[textures-queries]] 4079e5c31af7Sopenharmony_ci== Image Query Instructions 4080e5c31af7Sopenharmony_ci 4081e5c31af7Sopenharmony_ci 4082e5c31af7Sopenharmony_ci=== Image Property Queries 4083e5c31af7Sopenharmony_ci 4084e5c31af7Sopenharmony_cicode:OpImageQuerySize, code:OpImageQuerySizeLod, code:OpImageQueryLevels, 4085e5c31af7Sopenharmony_ciand code:OpImageQuerySamples query properties of the image descriptor that 4086e5c31af7Sopenharmony_ciwould be accessed by a shader image operation. 4087e5c31af7Sopenharmony_ciifdef::VK_EXT_robustness2[] 4088e5c31af7Sopenharmony_ciThey return 0 if the bound descriptor is a null descriptor. 4089e5c31af7Sopenharmony_ciendif::VK_EXT_robustness2[] 4090e5c31af7Sopenharmony_ci 4091e5c31af7Sopenharmony_cicode:OpImageQuerySizeLod returns the size of the image level identified by 4092e5c31af7Sopenharmony_cithe code:Level code:of code:Detail operand. 4093e5c31af7Sopenharmony_ciIf that level does not exist in the image, 4094e5c31af7Sopenharmony_ciifdef::VK_EXT_robustness2[and the descriptor is not null,] 4095e5c31af7Sopenharmony_cithen the value returned is undefined:. 4096e5c31af7Sopenharmony_ci 4097e5c31af7Sopenharmony_ci 4098e5c31af7Sopenharmony_ci=== Lod Query 4099e5c31af7Sopenharmony_ci 4100e5c31af7Sopenharmony_cicode:OpImageQueryLod returns the Lod parameters that would be used in an 4101e5c31af7Sopenharmony_ciimage operation with the given image and coordinates. 4102e5c31af7Sopenharmony_ciifdef::VK_EXT_robustness2[] 4103e5c31af7Sopenharmony_ciIf the descriptor that would be accessed is a null descriptor then 4104e5c31af7Sopenharmony_ci[eq]#(0,0)# is returned. 4105e5c31af7Sopenharmony_ciendif::VK_EXT_robustness2[] 4106e5c31af7Sopenharmony_ciifdef::VK_EXT_robustness2[Otherwise, the] 4107e5c31af7Sopenharmony_ciifndef::VK_EXT_robustness2[The] 4108e5c31af7Sopenharmony_cisteps described in this chapter are performed as if for 4109e5c31af7Sopenharmony_cicode:OpImageSampleImplicitLod, up to <<textures-lod-and-scale-factor>>. 4110e5c31af7Sopenharmony_ciThe return value is the vector [eq]#({lambda}', d~l~)#. 4111e5c31af7Sopenharmony_ciThese values may: be subject to implementation-specific maxima and minima 4112e5c31af7Sopenharmony_cifor very large, out-of-range values. 4113