1e5c31af7Sopenharmony_ci// Copyright 2015-2021 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== Image Operations Overview
9e5c31af7Sopenharmony_ci
10e5c31af7Sopenharmony_ciVulkan Image Operations are operations performed by those SPIR-V Image
11e5c31af7Sopenharmony_ciInstructions which take an code:OpTypeImage (representing a
12e5c31af7Sopenharmony_cisname:VkImageView) or code:OpTypeSampledImage (representing a
13e5c31af7Sopenharmony_ci(sname:VkImageView, sname:VkSampler) pair).
14e5c31af7Sopenharmony_ciRead, write, and atomic operations also take texel coordinates as operands,
15e5c31af7Sopenharmony_ciand return a value based on a neighborhood of texture elements (_texels_)
16e5c31af7Sopenharmony_ciwithin the image.
17e5c31af7Sopenharmony_ciQuery operations return properties of the bound image or of the lookup
18e5c31af7Sopenharmony_ciitself.
19e5c31af7Sopenharmony_ciThe "`Depth`" operand of code:OpTypeImage is ignored.
20e5c31af7Sopenharmony_ci
21e5c31af7Sopenharmony_ci[NOTE]
22e5c31af7Sopenharmony_ci.Note
23e5c31af7Sopenharmony_ci====
24e5c31af7Sopenharmony_ciTexel is a term which is a combination of the words texture and element.
25e5c31af7Sopenharmony_ciEarly interactive computer graphics supported texture operations on
26e5c31af7Sopenharmony_citextures, a small subset of the image operations on images described here.
27e5c31af7Sopenharmony_ciThe discrete samples remain essentially equivalent, however, so we retain
28e5c31af7Sopenharmony_cithe historical term texel to refer to them.
29e5c31af7Sopenharmony_ci====
30e5c31af7Sopenharmony_ci
31e5c31af7Sopenharmony_ciImage Operations include the functionality of the following SPIR-V Image
32e5c31af7Sopenharmony_ciInstructions:
33e5c31af7Sopenharmony_ci
34e5c31af7Sopenharmony_ci  * code:OpImageSample* and code:OpImageSparseSample* read one or more
35e5c31af7Sopenharmony_ci    neighboring texels of the image, and <<textures-texel-filtering,filter>>
36e5c31af7Sopenharmony_ci    the texel values based on the state of the sampler.
37e5c31af7Sopenharmony_ci  ** Instructions with code:ImplicitLod in the name
38e5c31af7Sopenharmony_ci     <<textures-level-of-detail-operation,determine>> the LOD used in the
39e5c31af7Sopenharmony_ci     sampling operation based on the coordinates used in neighboring
40e5c31af7Sopenharmony_ci     fragments.
41e5c31af7Sopenharmony_ci  ** Instructions with code:ExplicitLod in the name
42e5c31af7Sopenharmony_ci     <<textures-level-of-detail-operation,determine>> the LOD used in the
43e5c31af7Sopenharmony_ci     sampling operation based on additional coordinates.
44e5c31af7Sopenharmony_ci  ** Instructions with code:Proj in the name apply homogeneous
45e5c31af7Sopenharmony_ci     <<textures-projection,projection>> to the coordinates.
46e5c31af7Sopenharmony_ci  * code:OpImageFetch and code:OpImageSparseFetch return a single texel of
47e5c31af7Sopenharmony_ci    the image.
48e5c31af7Sopenharmony_ci    No sampler is used.
49e5c31af7Sopenharmony_ci  * code:OpImage*Gather and code:OpImageSparse*Gather read neighboring
50e5c31af7Sopenharmony_ci    texels and <<textures-gather,return a single component>> of each.
51e5c31af7Sopenharmony_ci  * code:OpImageRead (and code:OpImageSparseRead) and code:OpImageWrite read
52e5c31af7Sopenharmony_ci    and write, respectively, a texel in the image.
53e5c31af7Sopenharmony_ci    No sampler is used.
54e5c31af7Sopenharmony_ciifdef::VK_NV_shader_image_footprint[]
55e5c31af7Sopenharmony_ci  * code:OpImageSampleFootprintNV identifies and returns information about
56e5c31af7Sopenharmony_ci    the set of texels in the image that would be accessed by an equivalent
57e5c31af7Sopenharmony_ci    code:OpImageSample* instruction.
58e5c31af7Sopenharmony_ciendif::VK_NV_shader_image_footprint[]
59e5c31af7Sopenharmony_ci  * Instructions with code:Dref in the name apply
60e5c31af7Sopenharmony_ci    <<textures-depth-compare-operation,depth comparison>> on the texel
61e5c31af7Sopenharmony_ci    values.
62e5c31af7Sopenharmony_ci  * Instructions with code:Sparse in the name additionally return a
63e5c31af7Sopenharmony_ci    <<textures-sparse-residency,sparse residency>> code.
64e5c31af7Sopenharmony_ci  * code:OpImageQuerySize, code:OpImageQuerySizeLod,
65e5c31af7Sopenharmony_ci    code:OpImageQueryLevels, and code:OpImageQuerySamples return properties
66e5c31af7Sopenharmony_ci    of the image descriptor that would be accessed.
67e5c31af7Sopenharmony_ci    The image itself is not accessed.
68e5c31af7Sopenharmony_ci  * code:OpImageQueryLod returns the lod parameters that would be used in a
69e5c31af7Sopenharmony_ci    sample operation.
70e5c31af7Sopenharmony_ci    The actual operation is not performed.
71e5c31af7Sopenharmony_ci
72e5c31af7Sopenharmony_ci[[textures-texel-coordinate-systems]]
73e5c31af7Sopenharmony_ci=== Texel Coordinate Systems
74e5c31af7Sopenharmony_ci
75e5c31af7Sopenharmony_ciImages are addressed by _texel coordinates_.
76e5c31af7Sopenharmony_ciThere are three _texel coordinate systems_:
77e5c31af7Sopenharmony_ci
78e5c31af7Sopenharmony_ci  * normalized texel coordinates [eq]#[0.0, 1.0]#
79e5c31af7Sopenharmony_ci  * unnormalized texel coordinates [eq]#[0.0, width / height / depth)#
80e5c31af7Sopenharmony_ci  * integer texel coordinates [eq]#[0, width / height / depth)#
81e5c31af7Sopenharmony_ci
82e5c31af7Sopenharmony_ciSPIR-V code:OpImageFetch, code:OpImageSparseFetch, code:OpImageRead,
83e5c31af7Sopenharmony_cicode:OpImageSparseRead, and code:OpImageWrite instructions use integer texel
84e5c31af7Sopenharmony_cicoordinates.
85e5c31af7Sopenharmony_ciOther image instructions can: use either normalized or unnormalized texel
86e5c31af7Sopenharmony_cicoordinates (selected by the pname:unnormalizedCoordinates state of the
87e5c31af7Sopenharmony_cisampler used in the instruction), but there are
88e5c31af7Sopenharmony_ci<<samplers-unnormalizedCoordinates,limitations>> on what operations, image
89e5c31af7Sopenharmony_cistate, and sampler state is supported.
90e5c31af7Sopenharmony_ciNormalized coordinates are logically
91e5c31af7Sopenharmony_ci<<textures-normalized-to-unnormalized,converted>> to unnormalized as part of
92e5c31af7Sopenharmony_ciimage operations, and <<textures-normalized-operations,certain steps>> are
93e5c31af7Sopenharmony_cionly performed on normalized coordinates.
94e5c31af7Sopenharmony_ciThe array layer coordinate is always treated as unnormalized even when other
95e5c31af7Sopenharmony_cicoordinates are normalized.
96e5c31af7Sopenharmony_ci
97e5c31af7Sopenharmony_ciNormalized texel coordinates are referred to as [eq]#(s,t,r,q,a)#, with the
98e5c31af7Sopenharmony_cicoordinates having the following meanings:
99e5c31af7Sopenharmony_ci
100e5c31af7Sopenharmony_ci  * [eq]#s#: Coordinate in the first dimension of an image.
101e5c31af7Sopenharmony_ci  * [eq]#t#: Coordinate in the second dimension of an image.
102e5c31af7Sopenharmony_ci  * [eq]#r#: Coordinate in the third dimension of an image.
103e5c31af7Sopenharmony_ci  ** [eq]#(s,t,r)# are interpreted as a direction vector for Cube images.
104e5c31af7Sopenharmony_ci  * [eq]#q#: Fourth coordinate, for homogeneous (projective) coordinates.
105e5c31af7Sopenharmony_ci  * [eq]#a#: Coordinate for array layer.
106e5c31af7Sopenharmony_ci
107e5c31af7Sopenharmony_ciThe coordinates are extracted from the SPIR-V operand based on the
108e5c31af7Sopenharmony_cidimensionality of the image variable and type of instruction.
109e5c31af7Sopenharmony_ciFor code:Proj instructions, the components are in order [eq]#(s, [t,] [r,]
110e5c31af7Sopenharmony_ciq)#, with [eq]#t# and [eq]#r# being conditionally present based on the
111e5c31af7Sopenharmony_cicode:Dim of the image.
112e5c31af7Sopenharmony_ciFor non-code:Proj instructions, the coordinates are [eq]#(s [,t] [,r]
113e5c31af7Sopenharmony_ci[,a])#, with [eq]#t# and [eq]#r# being conditionally present based on the
114e5c31af7Sopenharmony_cicode:Dim of the image and [eq]#a# being conditionally present based on the
115e5c31af7Sopenharmony_cicode:Arrayed property of the image.
116e5c31af7Sopenharmony_ciProjective image instructions are not supported on code:Arrayed images.
117e5c31af7Sopenharmony_ci
118e5c31af7Sopenharmony_ciUnnormalized texel coordinates are referred to as [eq]#(u,v,w,a)#, with the
119e5c31af7Sopenharmony_cicoordinates having the following meanings:
120e5c31af7Sopenharmony_ci
121e5c31af7Sopenharmony_ci  * [eq]#u#: Coordinate in the first dimension of an image.
122e5c31af7Sopenharmony_ci  * [eq]#v#: Coordinate in the second dimension of an image.
123e5c31af7Sopenharmony_ci  * [eq]#w#: Coordinate in the third dimension of an image.
124e5c31af7Sopenharmony_ci  * [eq]#a#: Coordinate for array layer.
125e5c31af7Sopenharmony_ci
126e5c31af7Sopenharmony_ciOnly the [eq]#u# and [eq]#v# coordinates are directly extracted from the
127e5c31af7Sopenharmony_ciSPIR-V operand, because only 1D and 2D (non-code:Arrayed) dimensionalities
128e5c31af7Sopenharmony_cisupport unnormalized coordinates.
129e5c31af7Sopenharmony_ciThe components are in order [eq]#(u [,v])#, with [eq]#v# being conditionally
130e5c31af7Sopenharmony_cipresent when the dimensionality is 2D.
131e5c31af7Sopenharmony_ciWhen normalized coordinates are converted to unnormalized coordinates, all
132e5c31af7Sopenharmony_cifour coordinates are used.
133e5c31af7Sopenharmony_ci
134e5c31af7Sopenharmony_ciInteger texel coordinates are referred to as [eq]#(i,j,k,l,n)#, with the
135e5c31af7Sopenharmony_cicoordinates having the following meanings:
136e5c31af7Sopenharmony_ci
137e5c31af7Sopenharmony_ci  * [eq]#i#: Coordinate in the first dimension of an image.
138e5c31af7Sopenharmony_ci  * [eq]#j#: Coordinate in the second dimension of an image.
139e5c31af7Sopenharmony_ci  * [eq]#k#: Coordinate in the third dimension of an image.
140e5c31af7Sopenharmony_ci  * [eq]#l#: Coordinate for array layer.
141e5c31af7Sopenharmony_ci  * [eq]#n#: Index of the sample within the texel.
142e5c31af7Sopenharmony_ci
143e5c31af7Sopenharmony_ciThey are extracted from the SPIR-V operand in order [eq]#(i [,j] [,k] [,l]
144e5c31af7Sopenharmony_ci[,n])#, with [eq]#j# and [eq]#k# conditionally present based on the code:Dim
145e5c31af7Sopenharmony_ciof the image, and [eq]#l# conditionally present based on the code:Arrayed
146e5c31af7Sopenharmony_ciproperty of the image.
147e5c31af7Sopenharmony_ci[eq]#n# is conditionally present and is taken from the code:Sample image
148e5c31af7Sopenharmony_cioperand.
149e5c31af7Sopenharmony_ci
150e5c31af7Sopenharmony_ciFor all coordinate types, unused coordinates are assigned a value of zero.
151e5c31af7Sopenharmony_ci
152e5c31af7Sopenharmony_ci[[textures-texel-coordinate-systems-diagrams]]
153e5c31af7Sopenharmony_ciimage::{images}/vulkantexture0-ll.svg[align="center",title="Texel Coordinate Systems, Linear Filtering",opts="{imageopts}"]
154e5c31af7Sopenharmony_ciThe Texel Coordinate Systems - For the example shown of an 8{times}4 texel
155e5c31af7Sopenharmony_citwo dimensional image.
156e5c31af7Sopenharmony_ci
157e5c31af7Sopenharmony_ci  * Normalized texel coordinates:
158e5c31af7Sopenharmony_ci  ** The [eq]#s# coordinate goes from 0.0 to 1.0.
159e5c31af7Sopenharmony_ci  ** The [eq]#t# coordinate goes from 0.0 to 1.0.
160e5c31af7Sopenharmony_ci  * Unnormalized texel coordinates:
161e5c31af7Sopenharmony_ci  ** The [eq]#u# coordinate within the range 0.0 to 8.0 is within the image,
162e5c31af7Sopenharmony_ci     otherwise it is outside the image.
163e5c31af7Sopenharmony_ci  ** The [eq]#v# coordinate within the range 0.0 to 4.0 is within the image,
164e5c31af7Sopenharmony_ci     otherwise it is outside the image.
165e5c31af7Sopenharmony_ci  * Integer texel coordinates:
166e5c31af7Sopenharmony_ci  ** The [eq]#i# coordinate within the range 0 to 7 addresses texels within
167e5c31af7Sopenharmony_ci     the image, otherwise it is outside the image.
168e5c31af7Sopenharmony_ci  ** The [eq]#j# coordinate within the range 0 to 3 addresses texels within
169e5c31af7Sopenharmony_ci     the image, otherwise it is outside the image.
170e5c31af7Sopenharmony_ci  * Also shown for linear filtering:
171e5c31af7Sopenharmony_ci  ** Given the unnormalized coordinates [eq]#(u,v)#, the four texels
172e5c31af7Sopenharmony_ci     selected are [eq]#i~0~j~0~#, [eq]#i~1~j~0~#, [eq]#i~0~j~1~#, and
173e5c31af7Sopenharmony_ci     [eq]#i~1~j~1~#.
174e5c31af7Sopenharmony_ci  ** The fractions [eq]#{alpha}# and [eq]#{beta}#.
175e5c31af7Sopenharmony_ci  ** Given the offset [eq]#{DeltaUpper}~i~# and [eq]#{DeltaUpper}~j~#, the
176e5c31af7Sopenharmony_ci     four texels selected by the offset are [eq]#i~0~j'~0~#,
177e5c31af7Sopenharmony_ci     [eq]#i~1~j'~0~#, [eq]#i~0~j'~1~#, and [eq]#i~1~j'~1~#.
178e5c31af7Sopenharmony_ci
179e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_1,VK_KHR_sampler_ycbcr_conversion[]
180e5c31af7Sopenharmony_ci[NOTE]
181e5c31af7Sopenharmony_ci.Note
182e5c31af7Sopenharmony_ci====
183e5c31af7Sopenharmony_ciFor formats with reduced-resolution components, [eq]#{DeltaUpper}~i~# and
184e5c31af7Sopenharmony_ci[eq]#{DeltaUpper}~j~# are relative to the resolution of the
185e5c31af7Sopenharmony_cihighest-resolution component, and therefore may be divided by two relative
186e5c31af7Sopenharmony_cito the unnormalized coordinate space of the lower-resolution components.
187e5c31af7Sopenharmony_ci====
188e5c31af7Sopenharmony_ciendif::VK_VERSION_1_1,VK_KHR_sampler_ycbcr_conversion[]
189e5c31af7Sopenharmony_ci
190e5c31af7Sopenharmony_ciimage::{images}/vulkantexture1-ll.svg[align="center",title="Texel Coordinate Systems, Nearest Filtering",opts="{imageopts}"]
191e5c31af7Sopenharmony_ci
192e5c31af7Sopenharmony_ciThe Texel Coordinate Systems - For the example shown of an 8{times}4 texel
193e5c31af7Sopenharmony_citwo dimensional image.
194e5c31af7Sopenharmony_ci
195e5c31af7Sopenharmony_ci  * Texel coordinates as above.
196e5c31af7Sopenharmony_ci    Also shown for nearest filtering:
197e5c31af7Sopenharmony_ci  ** Given the unnormalized coordinates [eq]#(u,v)#, the texel selected is
198e5c31af7Sopenharmony_ci     [eq]#ij#.
199e5c31af7Sopenharmony_ci  ** Given the offset [eq]#{DeltaUpper}~i~# and [eq]#{DeltaUpper}~j~#, the
200e5c31af7Sopenharmony_ci     texel selected by the offset is [eq]#ij'#.
201e5c31af7Sopenharmony_ci
202e5c31af7Sopenharmony_ciifdef::VK_NV_corner_sampled_image[]
203e5c31af7Sopenharmony_ciFor corner-sampled images, the texel samples are located at the grid
204e5c31af7Sopenharmony_ciintersections instead of the texel centers.
205e5c31af7Sopenharmony_ci
206e5c31af7Sopenharmony_ciimage::{images}/vulkantexture0-corner-alternative-a-ll.svg[align="center",title="Texel Coordinate Systems, Corner Sampling",opts="{imageopts}"]
207e5c31af7Sopenharmony_ci
208e5c31af7Sopenharmony_ciendif::VK_NV_corner_sampled_image[]
209e5c31af7Sopenharmony_ci
210e5c31af7Sopenharmony_ci== Conversion Formulas
211e5c31af7Sopenharmony_ci
212e5c31af7Sopenharmony_ciifdef::editing-notes[]
213e5c31af7Sopenharmony_ci[NOTE]
214e5c31af7Sopenharmony_ci.editing-note
215e5c31af7Sopenharmony_ci====
216e5c31af7Sopenharmony_ci(Bill) These Conversion Formulas will likely move to Section 2.7 Fixed-Point
217e5c31af7Sopenharmony_ciData Conversions (RGB to sRGB and sRGB to RGB) and section 2.6 Numeric
218e5c31af7Sopenharmony_ciRepresentation and Computation (RGB to Shared Exponent and Shared Exponent
219e5c31af7Sopenharmony_cito RGB)
220e5c31af7Sopenharmony_ci====
221e5c31af7Sopenharmony_ciendif::editing-notes[]
222e5c31af7Sopenharmony_ci
223e5c31af7Sopenharmony_ci[[textures-RGB-sexp]]
224e5c31af7Sopenharmony_ci=== RGB to Shared Exponent Conversion
225e5c31af7Sopenharmony_ci
226e5c31af7Sopenharmony_ciAn RGB color [eq]#(red, green, blue)# is transformed to a shared exponent
227e5c31af7Sopenharmony_cicolor [eq]#(red~shared~, green~shared~, blue~shared~, exp~shared~)# as
228e5c31af7Sopenharmony_cifollows:
229e5c31af7Sopenharmony_ci
230e5c31af7Sopenharmony_ciFirst, the components [eq]#(red, green, blue)# are clamped to
231e5c31af7Sopenharmony_ci[eq]#(red~clamped~, green~clamped~, blue~clamped~)# as:
232e5c31af7Sopenharmony_ci
233e5c31af7Sopenharmony_ci  {empty}:: [eq]#red~clamped~ = max(0, min(sharedexp~max~, red))#
234e5c31af7Sopenharmony_ci  {empty}:: [eq]#green~clamped~ = max(0, min(sharedexp~max~, green))#
235e5c31af7Sopenharmony_ci  {empty}:: [eq]#blue~clamped~ = max(0, min(sharedexp~max~, blue))#
236e5c31af7Sopenharmony_ci
237e5c31af7Sopenharmony_ciwhere:
238e5c31af7Sopenharmony_ci
239e5c31af7Sopenharmony_ci[latexmath]
240e5c31af7Sopenharmony_ci+++++++++++++++++++
241e5c31af7Sopenharmony_ci\begin{aligned}
242e5c31af7Sopenharmony_ciN               & = 9  & \text{number of mantissa bits per component} \\
243e5c31af7Sopenharmony_ciB               & = 15 & \text{exponent bias} \\
244e5c31af7Sopenharmony_ciE_{max}         & = 31 & \text{maximum possible biased exponent value} \\
245e5c31af7Sopenharmony_cisharedexp_{max} & = \frac{(2^N-1)}{2^N} \times 2^{(E_{max}-B)}
246e5c31af7Sopenharmony_ci\end{aligned}
247e5c31af7Sopenharmony_ci+++++++++++++++++++
248e5c31af7Sopenharmony_ci
249e5c31af7Sopenharmony_ci[NOTE]
250e5c31af7Sopenharmony_ci.Note
251e5c31af7Sopenharmony_ci====
252e5c31af7Sopenharmony_ci[eq]#NaN#, if supported, is handled as in <<ieee-754,IEEE 754-2008>>
253e5c31af7Sopenharmony_ci`minNum()` and `maxNum()`.
254e5c31af7Sopenharmony_ciThis results in any [eq]#NaN# being mapped to zero.
255e5c31af7Sopenharmony_ci====
256e5c31af7Sopenharmony_ci
257e5c31af7Sopenharmony_ciThe largest clamped component, [eq]#max~clamped~# is determined:
258e5c31af7Sopenharmony_ci
259e5c31af7Sopenharmony_ci  {empty}:: [eq]#max~clamped~ = max(red~clamped~, green~clamped~,
260e5c31af7Sopenharmony_ci            blue~clamped~)#
261e5c31af7Sopenharmony_ci
262e5c31af7Sopenharmony_ciA preliminary shared exponent [eq]#exp'# is computed:
263e5c31af7Sopenharmony_ci[latexmath]
264e5c31af7Sopenharmony_ci+++++++++++++++++++
265e5c31af7Sopenharmony_ci\begin{aligned}
266e5c31af7Sopenharmony_ciexp' =
267e5c31af7Sopenharmony_ci  \begin{cases}
268e5c31af7Sopenharmony_ci    \left \lfloor \log_2(max_{clamped}) \right \rfloor + (B+1)
269e5c31af7Sopenharmony_ci      & \text{for}\  max_{clamped} > 2^{-(B+1)} \\
270e5c31af7Sopenharmony_ci    0
271e5c31af7Sopenharmony_ci      & \text{for}\  max_{clamped} \leq 2^{-(B+1)}
272e5c31af7Sopenharmony_ci  \end{cases}
273e5c31af7Sopenharmony_ci\end{aligned}
274e5c31af7Sopenharmony_ci+++++++++++++++++++
275e5c31af7Sopenharmony_ci
276e5c31af7Sopenharmony_ciThe shared exponent [eq]#exp~shared~# is computed:
277e5c31af7Sopenharmony_ci
278e5c31af7Sopenharmony_ci[latexmath]
279e5c31af7Sopenharmony_ci+++++++++++++++++++
280e5c31af7Sopenharmony_ci\begin{aligned}
281e5c31af7Sopenharmony_cimax_{shared} =
282e5c31af7Sopenharmony_ci    \left \lfloor
283e5c31af7Sopenharmony_ci        { \frac{max_{clamped}}{2^{(exp'-B-N)}} + \frac{1}{2} }
284e5c31af7Sopenharmony_ci    \right \rfloor
285e5c31af7Sopenharmony_ci\end{aligned}
286e5c31af7Sopenharmony_ci+++++++++++++++++++
287e5c31af7Sopenharmony_ci
288e5c31af7Sopenharmony_ci[latexmath]
289e5c31af7Sopenharmony_ci+++++++++++++++++++
290e5c31af7Sopenharmony_ci\begin{aligned}
291e5c31af7Sopenharmony_ciexp_{shared} =
292e5c31af7Sopenharmony_ci  \begin{cases}
293e5c31af7Sopenharmony_ci    exp'   & \text{for}\  0 \leq max_{shared} < 2^N \\
294e5c31af7Sopenharmony_ci    exp'+1 & \text{for}\  max_{shared} = 2^N
295e5c31af7Sopenharmony_ci  \end{cases}
296e5c31af7Sopenharmony_ci\end{aligned}
297e5c31af7Sopenharmony_ci+++++++++++++++++++
298e5c31af7Sopenharmony_ci
299e5c31af7Sopenharmony_ciFinally, three integer values in the range [eq]#0# to [eq]#2^N^# are
300e5c31af7Sopenharmony_cicomputed:
301e5c31af7Sopenharmony_ci
302e5c31af7Sopenharmony_ci[latexmath]
303e5c31af7Sopenharmony_ci+++++++++++++++++++
304e5c31af7Sopenharmony_ci\begin{aligned}
305e5c31af7Sopenharmony_cired_{shared} & =
306e5c31af7Sopenharmony_ci    \left \lfloor
307e5c31af7Sopenharmony_ci        { \frac{red_{clamped}}{2^{(exp_{shared}-B-N)}}+ \frac{1}{2} }
308e5c31af7Sopenharmony_ci    \right \rfloor \\
309e5c31af7Sopenharmony_cigreen_{shared} & =
310e5c31af7Sopenharmony_ci    \left \lfloor
311e5c31af7Sopenharmony_ci        { \frac{green_{clamped}}{2^{(exp_{shared}-B-N)}}+ \frac{1}{2} }
312e5c31af7Sopenharmony_ci    \right \rfloor \\
313e5c31af7Sopenharmony_ciblue_{shared} & =
314e5c31af7Sopenharmony_ci    \left \lfloor
315e5c31af7Sopenharmony_ci        { \frac{blue_{clamped}}{2^{(exp_{shared}-B-N)}}+ \frac{1}{2} }
316e5c31af7Sopenharmony_ci    \right \rfloor
317e5c31af7Sopenharmony_ci\end{aligned}
318e5c31af7Sopenharmony_ci+++++++++++++++++++
319e5c31af7Sopenharmony_ci
320e5c31af7Sopenharmony_ci
321e5c31af7Sopenharmony_ci[[textures-sexp-RGB]]
322e5c31af7Sopenharmony_ci=== Shared Exponent to RGB
323e5c31af7Sopenharmony_ci
324e5c31af7Sopenharmony_ciA shared exponent color [eq]#(red~shared~, green~shared~, blue~shared~,
325e5c31af7Sopenharmony_ciexp~shared~)# is transformed to an RGB color [eq]#(red, green, blue)# as
326e5c31af7Sopenharmony_cifollows:
327e5c31af7Sopenharmony_ci
328e5c31af7Sopenharmony_ci  {empty}:: latexmath:[red = red_{shared} \times {2^{(exp_{shared}-B-N)}}]
329e5c31af7Sopenharmony_ci  {empty}:: latexmath:[green = green_{shared} \times
330e5c31af7Sopenharmony_ci            {2^{(exp_{shared}-B-N)}}]
331e5c31af7Sopenharmony_ci  {empty}:: latexmath:[blue = blue_{shared} \times {2^{(exp_{shared}-B-N)}}]
332e5c31af7Sopenharmony_ci
333e5c31af7Sopenharmony_ciwhere:
334e5c31af7Sopenharmony_ci
335e5c31af7Sopenharmony_ci  {empty}:: [eq]#N = 9# (number of mantissa bits per component)
336e5c31af7Sopenharmony_ci  {empty}:: [eq]#B = 15# (exponent bias)
337e5c31af7Sopenharmony_ci
338e5c31af7Sopenharmony_ci
339e5c31af7Sopenharmony_ci== Texel Input Operations
340e5c31af7Sopenharmony_ci
341e5c31af7Sopenharmony_ci_Texel input instructions_ are SPIR-V image instructions that read from an
342e5c31af7Sopenharmony_ciimage.
343e5c31af7Sopenharmony_ci_Texel input operations_ are a set of steps that are performed on state,
344e5c31af7Sopenharmony_cicoordinates, and texel values while processing a texel input instruction,
345e5c31af7Sopenharmony_ciand which are common to some or all texel input instructions.
346e5c31af7Sopenharmony_ciThey include the following steps, which are performed in the listed order:
347e5c31af7Sopenharmony_ci
348e5c31af7Sopenharmony_ci  * <<textures-input-validation,Validation operations>>
349e5c31af7Sopenharmony_ci  ** <<textures-operation-validation,Instruction/Sampler/Image validation>>
350e5c31af7Sopenharmony_ci  ** <<textures-integer-coordinate-validation,Coordinate validation>>
351e5c31af7Sopenharmony_ci  ** <<textures-sparse-validation,Sparse validation>>
352e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_1,VK_KHR_sampler_ycbcr_conversion[]
353e5c31af7Sopenharmony_ci  ** <<textures-layout-validation,Layout validation>>
354e5c31af7Sopenharmony_ciendif::VK_VERSION_1_1,VK_KHR_sampler_ycbcr_conversion[]
355e5c31af7Sopenharmony_ci  * <<textures-format-conversion,Format conversion>>
356e5c31af7Sopenharmony_ci  * <<textures-texel-replacement,Texel replacement>>
357e5c31af7Sopenharmony_ci  * <<textures-depth-compare-operation,Depth comparison>>
358e5c31af7Sopenharmony_ci  * <<textures-conversion-to-rgba,Conversion to RGBA>>
359e5c31af7Sopenharmony_ci  * <<textures-component-swizzle,Component swizzle>>
360e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_1,VK_KHR_sampler_ycbcr_conversion[]
361e5c31af7Sopenharmony_ci  * <<textures-chroma-reconstruction,Chroma reconstruction>>
362e5c31af7Sopenharmony_ci  * <<textures-sampler-YCbCr-conversion,{YCbCr} conversion>>
363e5c31af7Sopenharmony_ciendif::VK_VERSION_1_1,VK_KHR_sampler_ycbcr_conversion[]
364e5c31af7Sopenharmony_ci
365e5c31af7Sopenharmony_ciFor texel input instructions involving multiple texels (for sampling or
366e5c31af7Sopenharmony_cigathering), these steps are applied for each texel that is used in the
367e5c31af7Sopenharmony_ciinstruction.
368e5c31af7Sopenharmony_ciDepending on the type of image instruction, other steps are conditionally
369e5c31af7Sopenharmony_ciperformed between these steps or involving multiple coordinate or texel
370e5c31af7Sopenharmony_civalues.
371e5c31af7Sopenharmony_ci
372e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_1,VK_KHR_sampler_ycbcr_conversion[]
373e5c31af7Sopenharmony_ciIf <<textures-chroma-reconstruction,Chroma Reconstruction>> is implicit,
374e5c31af7Sopenharmony_ci<<textures-texel-filtering, Texel Filtering>> instead takes place during
375e5c31af7Sopenharmony_cichroma reconstruction, before <<textures-sampler-YCbCr-conversion,sampler
376e5c31af7Sopenharmony_ci{YCbCr} conversion>> occurs.
377e5c31af7Sopenharmony_ciendif::VK_VERSION_1_1,VK_KHR_sampler_ycbcr_conversion[]
378e5c31af7Sopenharmony_ci
379e5c31af7Sopenharmony_ci
380e5c31af7Sopenharmony_ci[[textures-input-validation]]
381e5c31af7Sopenharmony_ci=== Texel Input Validation Operations
382e5c31af7Sopenharmony_ci
383e5c31af7Sopenharmony_ci_Texel input validation operations_ inspect instruction/image/sampler state
384e5c31af7Sopenharmony_cior coordinates, and in certain circumstances cause the texel value to be
385e5c31af7Sopenharmony_cireplaced or become undefined:.
386e5c31af7Sopenharmony_ciThere are a series of validations that the texel undergoes.
387e5c31af7Sopenharmony_ci
388e5c31af7Sopenharmony_ci[[textures-operation-validation]]
389e5c31af7Sopenharmony_ci==== Instruction/Sampler/Image View Validation
390e5c31af7Sopenharmony_ci
391e5c31af7Sopenharmony_ciThere are a number of cases where a SPIR-V instruction can: mismatch with
392e5c31af7Sopenharmony_cithe sampler, the image view, or both, and a number of further cases where
393e5c31af7Sopenharmony_cithe sampler can: mismatch with the image view.
394e5c31af7Sopenharmony_ciIn such cases the value of the texel returned is undefined:.
395e5c31af7Sopenharmony_ci
396e5c31af7Sopenharmony_ciThese cases include:
397e5c31af7Sopenharmony_ci
398e5c31af7Sopenharmony_ci  * The sampler pname:borderColor is an integer type and the image view
399e5c31af7Sopenharmony_ci    pname:format is not one of the elink:VkFormat integer types or a stencil
400e5c31af7Sopenharmony_ci    component of a depth/stencil format.
401e5c31af7Sopenharmony_ci  * The sampler pname:borderColor is a float type and the image view
402e5c31af7Sopenharmony_ci    pname:format is not one of the elink:VkFormat float types or a depth
403e5c31af7Sopenharmony_ci    component of a depth/stencil format.
404e5c31af7Sopenharmony_ciifndef::VK_EXT_border_color_swizzle[]
405e5c31af7Sopenharmony_ci  * The sampler pname:borderColor is one of the opaque black colors
406e5c31af7Sopenharmony_ci    (ename:VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK or
407e5c31af7Sopenharmony_ci    ename:VK_BORDER_COLOR_INT_OPAQUE_BLACK) and the image view
408e5c31af7Sopenharmony_ci    elink:VkComponentSwizzle for any of the slink:VkComponentMapping
409e5c31af7Sopenharmony_ci    components is not the <<resources-image-views-identity-mappings,identity
410e5c31af7Sopenharmony_ci    swizzle>>.
411e5c31af7Sopenharmony_ciendif::VK_EXT_border_color_swizzle[]
412e5c31af7Sopenharmony_ciifdef::VK_EXT_border_color_swizzle[]
413e5c31af7Sopenharmony_ci  * The sampler pname:borderColor is one of the opaque black colors
414e5c31af7Sopenharmony_ci    (ename:VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK or
415e5c31af7Sopenharmony_ci    ename:VK_BORDER_COLOR_INT_OPAQUE_BLACK) and the image view
416e5c31af7Sopenharmony_ci    elink:VkComponentSwizzle for any of the slink:VkComponentMapping
417e5c31af7Sopenharmony_ci    components is not the <<resources-image-views-identity-mappings,identity
418e5c31af7Sopenharmony_ci    swizzle>>, and
419e5c31af7Sopenharmony_ci    slink:VkPhysicalDeviceBorderColorSwizzleFeaturesEXT::pname:borderColorSwizzleFromImage
420e5c31af7Sopenharmony_ci    feature is not enabled, and
421e5c31af7Sopenharmony_ci    slink:VkSamplerBorderColorComponentMappingCreateInfoEXT is not
422e5c31af7Sopenharmony_ci    specified.
423e5c31af7Sopenharmony_ci  * slink:VkSamplerBorderColorComponentMappingCreateInfoEXT::pname:components,
424e5c31af7Sopenharmony_ci    if specified, has a component swizzle that does not match the component
425e5c31af7Sopenharmony_ci    swizzle of the image view, and either component swizzle is not a form of
426e5c31af7Sopenharmony_ci    identity swizzle.
427e5c31af7Sopenharmony_ci  * slink:VkSamplerBorderColorComponentMappingCreateInfoEXT::pname:srgb, if
428e5c31af7Sopenharmony_ci    specified, does not match the sRGB encoding of the image view.
429e5c31af7Sopenharmony_ciendif::VK_EXT_border_color_swizzle[]
430e5c31af7Sopenharmony_ciifdef::VK_EXT_custom_border_color[]
431e5c31af7Sopenharmony_ci  * The sampler pname:borderColor is a custom color
432e5c31af7Sopenharmony_ci    (ename:VK_BORDER_COLOR_FLOAT_CUSTOM_EXT or
433e5c31af7Sopenharmony_ci    ename:VK_BORDER_COLOR_INT_CUSTOM_EXT) and the supplied
434e5c31af7Sopenharmony_ci    slink:VkSamplerCustomBorderColorCreateInfoEXT::pname:customBorderColor
435e5c31af7Sopenharmony_ci    is outside the bounds of the values representable in the image view's
436e5c31af7Sopenharmony_ci    pname:format.
437e5c31af7Sopenharmony_ciifndef::VK_EXT_border_color_swizzle[]
438e5c31af7Sopenharmony_ci  * The sampler pname:borderColor is a custom color
439e5c31af7Sopenharmony_ci    (ename:VK_BORDER_COLOR_FLOAT_CUSTOM_EXT or
440e5c31af7Sopenharmony_ci    ename:VK_BORDER_COLOR_INT_CUSTOM_EXT) and the image view
441e5c31af7Sopenharmony_ci    elink:VkComponentSwizzle for any of the slink:VkComponentMapping
442e5c31af7Sopenharmony_ci    components is not the <<resources-image-views-identity-mappings,identity
443e5c31af7Sopenharmony_ci    swizzle>>.
444e5c31af7Sopenharmony_ciendif::VK_EXT_border_color_swizzle[]
445e5c31af7Sopenharmony_ciifdef::VK_EXT_border_color_swizzle[]
446e5c31af7Sopenharmony_ci  * The sampler pname:borderColor is a custom color
447e5c31af7Sopenharmony_ci    (ename:VK_BORDER_COLOR_FLOAT_CUSTOM_EXT or
448e5c31af7Sopenharmony_ci    ename:VK_BORDER_COLOR_INT_CUSTOM_EXT) and the image view
449e5c31af7Sopenharmony_ci    elink:VkComponentSwizzle for any of the slink:VkComponentMapping
450e5c31af7Sopenharmony_ci    components is not the <<resources-image-views-identity-mappings,identity
451e5c31af7Sopenharmony_ci    swizzle>>, and
452e5c31af7Sopenharmony_ci    slink:VkPhysicalDeviceBorderColorSwizzleFeaturesEXT::pname:borderColorSwizzleFromImage
453e5c31af7Sopenharmony_ci    feature is not enabled, and
454e5c31af7Sopenharmony_ci    slink:VkSamplerBorderColorComponentMappingCreateInfoEXT is not
455e5c31af7Sopenharmony_ci    specified.
456e5c31af7Sopenharmony_ciendif::VK_EXT_border_color_swizzle[]
457e5c31af7Sopenharmony_ciendif::VK_EXT_custom_border_color[]
458e5c31af7Sopenharmony_ci  * The elink:VkImageLayout of any subresource in the image view does not
459e5c31af7Sopenharmony_ci    match the slink:VkDescriptorImageInfo::pname:imageLayout used to write
460e5c31af7Sopenharmony_ci    the image descriptor.
461e5c31af7Sopenharmony_ci  * The SPIR-V Image Format is not <<spirvenv-image-formats,compatible>>
462e5c31af7Sopenharmony_ci    with the image view's pname:format.
463e5c31af7Sopenharmony_ci  * The sampler pname:unnormalizedCoordinates is ename:VK_TRUE and any of
464e5c31af7Sopenharmony_ci    the <<samplers-unnormalizedCoordinates,limitations of unnormalized
465e5c31af7Sopenharmony_ci    coordinates>> are violated.
466e5c31af7Sopenharmony_ciifdef::VK_EXT_fragment_density_map[]
467e5c31af7Sopenharmony_ci  * The sampler was created with pname:flags containing
468e5c31af7Sopenharmony_ci    ename:VK_SAMPLER_CREATE_SUBSAMPLED_BIT_EXT and the image was not created
469e5c31af7Sopenharmony_ci    with pname:flags containing ename:VK_IMAGE_CREATE_SUBSAMPLED_BIT_EXT.
470e5c31af7Sopenharmony_ci  * The sampler was not created with pname:flags containing
471e5c31af7Sopenharmony_ci    ename:VK_SAMPLER_CREATE_SUBSAMPLED_BIT_EXT and the image was created
472e5c31af7Sopenharmony_ci    with pname:flags containing ename:VK_IMAGE_CREATE_SUBSAMPLED_BIT_EXT.
473e5c31af7Sopenharmony_ci  * The sampler was created with pname:flags containing
474e5c31af7Sopenharmony_ci    ename:VK_SAMPLER_CREATE_SUBSAMPLED_BIT_EXT and is used with a function
475e5c31af7Sopenharmony_ci    that is not code:OpImageSampleImplicitLod or
476e5c31af7Sopenharmony_ci    code:OpImageSampleExplicitLod, or is used with operands code:Offset or
477e5c31af7Sopenharmony_ci    code:ConstOffsets.
478e5c31af7Sopenharmony_ciendif::VK_EXT_fragment_density_map[]
479e5c31af7Sopenharmony_ci  * The SPIR-V instruction is one of the code:OpImage*Dref* instructions and
480e5c31af7Sopenharmony_ci    the sampler pname:compareEnable is ename:VK_FALSE
481e5c31af7Sopenharmony_ci  * The SPIR-V instruction is not one of the code:OpImage*Dref* instructions
482e5c31af7Sopenharmony_ci    and the sampler pname:compareEnable is ename:VK_TRUE
483e5c31af7Sopenharmony_ciifndef::VK_KHR_format_feature_flags2[]
484e5c31af7Sopenharmony_ci  * The SPIR-V instruction is one of the code:OpImage*Dref* instructions and
485e5c31af7Sopenharmony_ci    the image view pname:format is not one of the depth/stencil formats with
486e5c31af7Sopenharmony_ci    a depth component, or the image view aspect is not
487e5c31af7Sopenharmony_ci    ename:VK_IMAGE_ASPECT_DEPTH_BIT.
488e5c31af7Sopenharmony_ciendif::VK_KHR_format_feature_flags2[]
489e5c31af7Sopenharmony_ciifdef::VK_KHR_format_feature_flags2[]
490e5c31af7Sopenharmony_ci  * The SPIR-V instruction is one of the code:OpImage*Dref* instructions,
491e5c31af7Sopenharmony_ci    the image view pname:format is one of the depth/stencil formats, and the
492e5c31af7Sopenharmony_ci    image view aspect is not ename:VK_IMAGE_ASPECT_DEPTH_BIT.
493e5c31af7Sopenharmony_ciendif::VK_KHR_format_feature_flags2[]
494e5c31af7Sopenharmony_ci  * The SPIR-V instruction's image variable's properties are not compatible
495e5c31af7Sopenharmony_ci    with the image view:
496e5c31af7Sopenharmony_ci  ** Rules for pname:viewType:
497e5c31af7Sopenharmony_ci  *** ename:VK_IMAGE_VIEW_TYPE_1D must: have code:Dim = 1D, code:Arrayed =
498e5c31af7Sopenharmony_ci      0, code:MS = 0.
499e5c31af7Sopenharmony_ci  *** ename:VK_IMAGE_VIEW_TYPE_2D must: have code:Dim = 2D, code:Arrayed = 0.
500e5c31af7Sopenharmony_ci  *** ename:VK_IMAGE_VIEW_TYPE_3D must: have code:Dim = 3D, code:Arrayed =
501e5c31af7Sopenharmony_ci      0, code:MS = 0.
502e5c31af7Sopenharmony_ci  *** ename:VK_IMAGE_VIEW_TYPE_CUBE must: have code:Dim = Cube, code:Arrayed
503e5c31af7Sopenharmony_ci      = 0, code:MS = 0.
504e5c31af7Sopenharmony_ci  *** ename:VK_IMAGE_VIEW_TYPE_1D_ARRAY must: have code:Dim = 1D,
505e5c31af7Sopenharmony_ci      code:Arrayed = 1, code:MS = 0.
506e5c31af7Sopenharmony_ci  *** ename:VK_IMAGE_VIEW_TYPE_2D_ARRAY must: have code:Dim = 2D,
507e5c31af7Sopenharmony_ci      code:Arrayed = 1.
508e5c31af7Sopenharmony_ci  *** ename:VK_IMAGE_VIEW_TYPE_CUBE_ARRAY must: have code:Dim = Cube,
509e5c31af7Sopenharmony_ci      code:Arrayed = 1, code:MS = 0.
510e5c31af7Sopenharmony_ci  ** If the image was created with slink:VkImageCreateInfo::pname:samples
511e5c31af7Sopenharmony_ci     equal to ename:VK_SAMPLE_COUNT_1_BIT, the instruction must: have
512e5c31af7Sopenharmony_ci     code:MS = 0.
513e5c31af7Sopenharmony_ci  ** If the image was created with slink:VkImageCreateInfo::pname:samples
514e5c31af7Sopenharmony_ci     not equal to ename:VK_SAMPLE_COUNT_1_BIT, the instruction must: have
515e5c31af7Sopenharmony_ci     code:MS = 1.
516e5c31af7Sopenharmony_ci  ** If the code:Sampled code:Type of the code:OpTypeImage does not match
517e5c31af7Sopenharmony_ci     the numeric format of the image, as shown in the _SPIR-V Sampled Type_
518e5c31af7Sopenharmony_ci     column of the <<formats-numericformat>> table.
519e5c31af7Sopenharmony_ci  ** If the <<spirvenv-image-signedness,signedness of any read or sample
520e5c31af7Sopenharmony_ci     operation>> does not match the signedness of the image's format.
521e5c31af7Sopenharmony_ciifdef::VK_NV_corner_sampled_image[]
522e5c31af7Sopenharmony_ci  * If the image was created with slink:VkImageCreateInfo::pname:flags
523e5c31af7Sopenharmony_ci    containing ename:VK_IMAGE_CREATE_CORNER_SAMPLED_BIT_NV, the sampler
524e5c31af7Sopenharmony_ci    addressing modes must: only use a elink:VkSamplerAddressMode of
525e5c31af7Sopenharmony_ci    ename:VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE.
526e5c31af7Sopenharmony_ciendif::VK_NV_corner_sampled_image[]
527e5c31af7Sopenharmony_ciifdef::VK_NV_shader_image_footprint[]
528e5c31af7Sopenharmony_ci  * The SPIR-V instruction is code:OpImageSampleFootprintNV with code:Dim =
529e5c31af7Sopenharmony_ci    2D and pname:addressModeU or pname:addressModeV in the sampler is not
530e5c31af7Sopenharmony_ci    ename:VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE.
531e5c31af7Sopenharmony_ci  * The SPIR-V instruction is code:OpImageSampleFootprintNV with code:Dim =
532e5c31af7Sopenharmony_ci    3D and pname:addressModeU, pname:addressModeV, or pname:addressModeW in
533e5c31af7Sopenharmony_ci    the sampler is not ename:VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE.
534e5c31af7Sopenharmony_ciendif::VK_NV_shader_image_footprint[]
535e5c31af7Sopenharmony_ciifdef::VK_EXT_custom_border_color[]
536e5c31af7Sopenharmony_ci  * The sampler was created with a specified
537e5c31af7Sopenharmony_ci    slink:VkSamplerCustomBorderColorCreateInfoEXT::pname:format which does
538e5c31af7Sopenharmony_ci    not match the elink:VkFormat of the image view(s) it is sampling.
539e5c31af7Sopenharmony_ci  * The sampler is sampling an image view of
540e5c31af7Sopenharmony_ci    ename:VK_FORMAT_B4G4R4A4_UNORM_PACK16,
541e5c31af7Sopenharmony_ci    ename:VK_FORMAT_B5G6R5_UNORM_PACK16, or
542e5c31af7Sopenharmony_ci    ename:VK_FORMAT_B5G5R5A1_UNORM_PACK16 format without a specified
543e5c31af7Sopenharmony_ci    slink:VkSamplerCustomBorderColorCreateInfoEXT::pname:format.
544e5c31af7Sopenharmony_ciendif::VK_EXT_custom_border_color[]
545e5c31af7Sopenharmony_ci
546e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_1,VK_KHR_sampler_ycbcr_conversion[]
547e5c31af7Sopenharmony_ciOnly code:OpImageSample* and code:OpImageSparseSample* can: be used with a
548e5c31af7Sopenharmony_cisampler that enables <<samplers-YCbCr-conversion,sampler {YCbCr}
549e5c31af7Sopenharmony_ciconversion>>.
550e5c31af7Sopenharmony_ci
551e5c31af7Sopenharmony_cicode:OpImageFetch, code:OpImageSparseFetch, code:OpImage*Gather, and
552e5c31af7Sopenharmony_cicode:OpImageSparse*Gather must: not be used with a sampler that enables
553e5c31af7Sopenharmony_ci<<samplers-YCbCr-conversion,sampler {YCbCr} conversion>>.
554e5c31af7Sopenharmony_ci
555e5c31af7Sopenharmony_ciThe code:ConstOffset and code:Offset operands must: not be used with a
556e5c31af7Sopenharmony_cisampler that enables <<samplers-YCbCr-conversion,sampler {YCbCr}
557e5c31af7Sopenharmony_ciconversion>>.
558e5c31af7Sopenharmony_ciendif::VK_VERSION_1_1,VK_KHR_sampler_ycbcr_conversion[]
559e5c31af7Sopenharmony_ci
560e5c31af7Sopenharmony_ci
561e5c31af7Sopenharmony_ci[[textures-integer-coordinate-validation]]
562e5c31af7Sopenharmony_ci==== Integer Texel Coordinate Validation
563e5c31af7Sopenharmony_ci
564e5c31af7Sopenharmony_ciInteger texel coordinates are validated against the size of the image level,
565e5c31af7Sopenharmony_ciand the number of layers and number of samples in the image.
566e5c31af7Sopenharmony_ciFor SPIR-V instructions that use integer texel coordinates, this is
567e5c31af7Sopenharmony_ciperformed directly on the integer coordinates.
568e5c31af7Sopenharmony_ciFor instructions that use normalized or unnormalized texel coordinates, this
569e5c31af7Sopenharmony_ciis performed on the coordinates that result after
570e5c31af7Sopenharmony_ci<<textures-unnormalized-to-integer,conversion>> to integer texel
571e5c31af7Sopenharmony_cicoordinates.
572e5c31af7Sopenharmony_ci
573e5c31af7Sopenharmony_ciIf the integer texel coordinates do not satisfy all of the conditions
574e5c31af7Sopenharmony_ci
575e5c31af7Sopenharmony_ci  {empty}:: [eq]#0 {leq} i < w~s~#
576e5c31af7Sopenharmony_ci  {empty}:: [eq]#0 {leq} j < h~s~#
577e5c31af7Sopenharmony_ci  {empty}:: [eq]#0 {leq} k < d~s~#
578e5c31af7Sopenharmony_ci  {empty}:: [eq]#0 {leq} l < layers#
579e5c31af7Sopenharmony_ci  {empty}:: [eq]#0 {leq} n < samples#
580e5c31af7Sopenharmony_ci
581e5c31af7Sopenharmony_ciwhere:
582e5c31af7Sopenharmony_ci
583e5c31af7Sopenharmony_ci  {empty}:: [eq]#w~s~ =# width of the image level
584e5c31af7Sopenharmony_ci  {empty}:: [eq]#h~s~ =# height of the image level
585e5c31af7Sopenharmony_ci  {empty}:: [eq]#d~s~ =# depth of the image level
586e5c31af7Sopenharmony_ci  {empty}:: [eq]#layers =# number of layers in the image
587e5c31af7Sopenharmony_ci  {empty}:: [eq]#samples =# number of samples per texel in the image
588e5c31af7Sopenharmony_ci
589e5c31af7Sopenharmony_cithen the texel fails integer texel coordinate validation.
590e5c31af7Sopenharmony_ci
591e5c31af7Sopenharmony_ciThere are four cases to consider:
592e5c31af7Sopenharmony_ci
593e5c31af7Sopenharmony_ci  . Valid Texel Coordinates
594e5c31af7Sopenharmony_ci+
595e5c31af7Sopenharmony_ci  * If the texel coordinates pass validation (that is, the coordinates lie
596e5c31af7Sopenharmony_ci    within the image),
597e5c31af7Sopenharmony_ci+
598e5c31af7Sopenharmony_cithen the texel value comes from the value in image memory.
599e5c31af7Sopenharmony_ci
600e5c31af7Sopenharmony_ci  . Border Texel
601e5c31af7Sopenharmony_ci+
602e5c31af7Sopenharmony_ci  * If the texel coordinates fail validation, and
603e5c31af7Sopenharmony_ci  * If the read is the result of an image sample instruction or image gather
604e5c31af7Sopenharmony_ci    instruction, and
605e5c31af7Sopenharmony_ci  * If the image is not a cube image,
606e5c31af7Sopenharmony_ci+
607e5c31af7Sopenharmony_cithen the texel is a border texel and <<textures-texel-replacement,texel
608e5c31af7Sopenharmony_cireplacement>> is performed.
609e5c31af7Sopenharmony_ci
610e5c31af7Sopenharmony_ci  . Invalid Texel
611e5c31af7Sopenharmony_ci+
612e5c31af7Sopenharmony_ci  * If the texel coordinates fail validation, and
613e5c31af7Sopenharmony_ci  * If the read is the result of an image fetch instruction, image read
614e5c31af7Sopenharmony_ci    instruction, or atomic instruction,
615e5c31af7Sopenharmony_ci+
616e5c31af7Sopenharmony_cithen the texel is an invalid texel and <<textures-texel-replacement,texel
617e5c31af7Sopenharmony_cireplacement>> is performed.
618e5c31af7Sopenharmony_ci
619e5c31af7Sopenharmony_ci  . Cube Map Edge or Corner
620e5c31af7Sopenharmony_ci+
621e5c31af7Sopenharmony_ciOtherwise the texel coordinates lie beyond the edges or corners of the
622e5c31af7Sopenharmony_ciselected cube map face, and <<textures-cubemapedge, Cube map edge handling>>
623e5c31af7Sopenharmony_ciis performed.
624e5c31af7Sopenharmony_ci
625e5c31af7Sopenharmony_ci
626e5c31af7Sopenharmony_ci[[textures-cubemapedge]]
627e5c31af7Sopenharmony_ci==== Cube Map Edge Handling
628e5c31af7Sopenharmony_ci
629e5c31af7Sopenharmony_ciIf the texel coordinates lie beyond the edges or corners of the selected
630e5c31af7Sopenharmony_cicube map face, the following steps are performed.
631e5c31af7Sopenharmony_ciNote that this does not occur when using ename:VK_FILTER_NEAREST filtering
632e5c31af7Sopenharmony_ciwithin a mip level, since ename:VK_FILTER_NEAREST is treated as using
633e5c31af7Sopenharmony_ciename:VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE.
634e5c31af7Sopenharmony_ci
635e5c31af7Sopenharmony_ci  * Cube Map Edge Texel
636e5c31af7Sopenharmony_ci+
637e5c31af7Sopenharmony_ci  ** If the texel lies beyond the selected cube map face in either only
638e5c31af7Sopenharmony_ci     [eq]#i# or only [eq]#j#, then the coordinates [eq]#(i,j)# and the array
639e5c31af7Sopenharmony_ci     layer [eq]#l# are transformed to select the adjacent texel from the
640e5c31af7Sopenharmony_ci     appropriate neighboring face.
641e5c31af7Sopenharmony_ci
642e5c31af7Sopenharmony_ci  * Cube Map Corner Texel
643e5c31af7Sopenharmony_ci+
644e5c31af7Sopenharmony_ci  ** If the texel lies beyond the selected cube map face in both [eq]#i# and
645e5c31af7Sopenharmony_ci     [eq]#j#, then there is no unique neighboring face from which to read
646e5c31af7Sopenharmony_ci     that texel.
647e5c31af7Sopenharmony_ci     The texel should: be replaced by the average of the three values of the
648e5c31af7Sopenharmony_ci     adjacent texels in each incident face.
649e5c31af7Sopenharmony_ci     However, implementations may: replace the cube map corner texel by
650e5c31af7Sopenharmony_ci     other methods.
651e5c31af7Sopenharmony_ciifndef::VK_EXT_filter_cubic[]
652e5c31af7Sopenharmony_ciThe methods are subject to the constraint that if the three available texels
653e5c31af7Sopenharmony_cihave the same value, the resulting filtered texel must: have that value.
654e5c31af7Sopenharmony_ciendif::VK_EXT_filter_cubic[]
655e5c31af7Sopenharmony_ciifdef::VK_EXT_filter_cubic[]
656e5c31af7Sopenharmony_ciThe methods are subject to the constraint that for linear filtering if the
657e5c31af7Sopenharmony_cithree available texels have the same value, the resulting filtered texel
658e5c31af7Sopenharmony_cimust: have that value, and for cubic filtering if the twelve available
659e5c31af7Sopenharmony_cisamples have the same value, the resulting filtered texel must: have that
660e5c31af7Sopenharmony_civalue.
661e5c31af7Sopenharmony_ciendif::VK_EXT_filter_cubic[]
662e5c31af7Sopenharmony_ci
663e5c31af7Sopenharmony_ci[[textures-sparse-validation]]
664e5c31af7Sopenharmony_ci==== Sparse Validation
665e5c31af7Sopenharmony_ci
666e5c31af7Sopenharmony_ciIf the texel reads from an unbound region of a sparse image, the texel is a
667e5c31af7Sopenharmony_ci_sparse unbound texel_, and processing continues with
668e5c31af7Sopenharmony_ci<<textures-texel-replacement,texel replacement>>.
669e5c31af7Sopenharmony_ci
670e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_1,VK_KHR_sampler_ycbcr_conversion[]
671e5c31af7Sopenharmony_ci
672e5c31af7Sopenharmony_ci[[textures-layout-validation]]
673e5c31af7Sopenharmony_ci==== Layout Validation
674e5c31af7Sopenharmony_ci
675e5c31af7Sopenharmony_ciIf all planes of a _disjoint_ _multi-planar_ image are not in the same
676e5c31af7Sopenharmony_ci<<resources-image-layouts,image layout>>, the image must: not be sampled
677e5c31af7Sopenharmony_ciwith <<samplers-YCbCr-conversion,sampler {YCbCr} conversion>> enabled.
678e5c31af7Sopenharmony_ci
679e5c31af7Sopenharmony_ciendif::VK_VERSION_1_1,VK_KHR_sampler_ycbcr_conversion[]
680e5c31af7Sopenharmony_ci
681e5c31af7Sopenharmony_ci[[textures-format-conversion]]
682e5c31af7Sopenharmony_ci=== Format Conversion
683e5c31af7Sopenharmony_ci
684e5c31af7Sopenharmony_ciTexels undergo a format conversion from the elink:VkFormat of the image view
685e5c31af7Sopenharmony_cito a vector of either floating point or signed or unsigned integer
686e5c31af7Sopenharmony_cicomponents, with the number of components based on the number of components
687e5c31af7Sopenharmony_cipresent in the format.
688e5c31af7Sopenharmony_ci
689e5c31af7Sopenharmony_ci  * Color formats have one, two, three, or four components, according to the
690e5c31af7Sopenharmony_ci    format.
691e5c31af7Sopenharmony_ci  * Depth/stencil formats are one component.
692e5c31af7Sopenharmony_ci    The depth or stencil component is selected by the pname:aspectMask of
693e5c31af7Sopenharmony_ci    the image view.
694e5c31af7Sopenharmony_ci
695e5c31af7Sopenharmony_ciEach component is converted based on its type and size (as defined in the
696e5c31af7Sopenharmony_ci<<formats-definition,Format Definition>> section for each elink:VkFormat),
697e5c31af7Sopenharmony_ciusing the appropriate equations in <<fundamentals-fp16,16-Bit Floating-Point
698e5c31af7Sopenharmony_ciNumbers>>, <<fundamentals-fp11,Unsigned 11-Bit Floating-Point Numbers>>,
699e5c31af7Sopenharmony_ci<<fundamentals-fp10,Unsigned 10-Bit Floating-Point Numbers>>,
700e5c31af7Sopenharmony_ci<<fundamentals-fixedconv,Fixed-Point Data Conversion>>, and
701e5c31af7Sopenharmony_ci<<textures-sexp-RGB,Shared Exponent to RGB>>.
702e5c31af7Sopenharmony_ciSigned integer components smaller than 32 bits are sign-extended.
703e5c31af7Sopenharmony_ci
704e5c31af7Sopenharmony_ciIf the image view format is sRGB, the color components are first converted
705e5c31af7Sopenharmony_cias if they are UNORM, and then sRGB to linear conversion is applied to the
706e5c31af7Sopenharmony_ciR, G, and B components as described in the "`sRGB EOTF`" section of the
707e5c31af7Sopenharmony_ci<<data-format,Khronos Data Format Specification>>.
708e5c31af7Sopenharmony_ciThe A component, if present, is unchanged.
709e5c31af7Sopenharmony_ci
710e5c31af7Sopenharmony_ciIf the image view format is block-compressed, then the texel value is first
711e5c31af7Sopenharmony_cidecoded, then converted based on the type and number of components defined
712e5c31af7Sopenharmony_ciby the compressed format.
713e5c31af7Sopenharmony_ci
714e5c31af7Sopenharmony_ci
715e5c31af7Sopenharmony_ci[[textures-texel-replacement]]
716e5c31af7Sopenharmony_ci=== Texel Replacement
717e5c31af7Sopenharmony_ci
718e5c31af7Sopenharmony_ciA texel is replaced if it is one (and only one) of:
719e5c31af7Sopenharmony_ci
720e5c31af7Sopenharmony_ci  * a border texel,
721e5c31af7Sopenharmony_ci  * an invalid texel, or
722e5c31af7Sopenharmony_ci  * a sparse unbound texel.
723e5c31af7Sopenharmony_ci
724e5c31af7Sopenharmony_ciBorder texels are replaced with a value based on the image format and the
725e5c31af7Sopenharmony_cipname:borderColor of the sampler.
726e5c31af7Sopenharmony_ciThe border color is:
727e5c31af7Sopenharmony_ci
728e5c31af7Sopenharmony_ci[[textures-border-replacement-color]]
729e5c31af7Sopenharmony_ciifdef::VK_EXT_custom_border_color[]
730e5c31af7Sopenharmony_ci.Border Color [eq]#B#, Custom Border Color slink:VkSamplerCustomBorderColorCreateInfoEXT::pname:customBorderColor [eq]#U#
731e5c31af7Sopenharmony_ciendif::VK_EXT_custom_border_color[]
732e5c31af7Sopenharmony_ciifndef::VK_EXT_custom_border_color[]
733e5c31af7Sopenharmony_ci.Border Color [eq]#B#
734e5c31af7Sopenharmony_ciendif::VK_EXT_custom_border_color[]
735e5c31af7Sopenharmony_ci[options="header",cols="60%,40%"]
736e5c31af7Sopenharmony_ci|====
737e5c31af7Sopenharmony_ci| Sampler pname:borderColor                     | Corresponding Border Color
738e5c31af7Sopenharmony_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]#
739e5c31af7Sopenharmony_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]#
740e5c31af7Sopenharmony_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]#
741e5c31af7Sopenharmony_ci| ename:VK_BORDER_COLOR_INT_TRANSPARENT_BLACK   | [eq]#[B~r~, B~g~, B~b~, B~a~] = [0, 0, 0, 0]#
742e5c31af7Sopenharmony_ci| ename:VK_BORDER_COLOR_INT_OPAQUE_BLACK        | [eq]#[B~r~, B~g~, B~b~, B~a~] = [0, 0, 0, 1]#
743e5c31af7Sopenharmony_ci| ename:VK_BORDER_COLOR_INT_OPAQUE_WHITE        | [eq]#[B~r~, B~g~, B~b~, B~a~] = [1, 1, 1, 1]#
744e5c31af7Sopenharmony_ciifdef::VK_EXT_custom_border_color[]
745e5c31af7Sopenharmony_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~]#
746e5c31af7Sopenharmony_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~]#
747e5c31af7Sopenharmony_ciendif::VK_EXT_custom_border_color[]
748e5c31af7Sopenharmony_ci|====
749e5c31af7Sopenharmony_ci
750e5c31af7Sopenharmony_ciifdef::VK_EXT_custom_border_color[]
751e5c31af7Sopenharmony_ciThe custom border color ([eq]#U#) may: be rounded by implementations prior
752e5c31af7Sopenharmony_cito texel replacement, but the error introduced by such a rounding must: not
753e5c31af7Sopenharmony_ciexceed one ULP of the image's pname:format.
754e5c31af7Sopenharmony_ciendif::VK_EXT_custom_border_color[]
755e5c31af7Sopenharmony_ci
756e5c31af7Sopenharmony_ci[NOTE]
757e5c31af7Sopenharmony_ci.Note
758e5c31af7Sopenharmony_ci====
759e5c31af7Sopenharmony_ciThe names etext:VK_BORDER_COLOR_*\_TRANSPARENT_BLACK,
760e5c31af7Sopenharmony_cietext:VK_BORDER_COLOR_*\_OPAQUE_BLACK, and
761e5c31af7Sopenharmony_cietext:VK_BORDER_COLOR_*_OPAQUE_WHITE are meant to describe which components
762e5c31af7Sopenharmony_ciare zeros and ones in the vocabulary of compositing, and are not meant to
763e5c31af7Sopenharmony_ciimply that the numerical value of ename:VK_BORDER_COLOR_INT_OPAQUE_WHITE is
764e5c31af7Sopenharmony_cia saturating value for integers.
765e5c31af7Sopenharmony_ci====
766e5c31af7Sopenharmony_ci
767e5c31af7Sopenharmony_ciThis is substituted for the texel value by replacing the number of
768e5c31af7Sopenharmony_cicomponents in the image format
769e5c31af7Sopenharmony_ci
770e5c31af7Sopenharmony_ci[[textures-border-replacement-table]]
771e5c31af7Sopenharmony_ci.Border Texel Components After Replacement
772e5c31af7Sopenharmony_ci[width="100%",options="header"]
773e5c31af7Sopenharmony_ci|====
774e5c31af7Sopenharmony_ci| Texel Aspect or Format      | Component Assignment
775e5c31af7Sopenharmony_ci| Depth aspect                | [eq]#D                                     = B~r~#
776e5c31af7Sopenharmony_ci| Stencil aspect              | [eq]#S                                     = B~r~#
777e5c31af7Sopenharmony_ci| One component color format  | [eq]#Color~r~                              = B~r~#
778e5c31af7Sopenharmony_ci| Two component color format  | [eq]#[Color~r~,Color~g~]                   = [B~r~,B~g~]#
779e5c31af7Sopenharmony_ci| Three component color format| [eq]#[Color~r~,Color~g~,Color~b~]          = [B~r~,B~g~,B~b~]#
780e5c31af7Sopenharmony_ci| Four component color format | [eq]#[Color~r~,Color~g~,Color~b~,Color~a~] = [B~r~,B~g~,B~b~,B~a~]#
781e5c31af7Sopenharmony_ci|====
782e5c31af7Sopenharmony_ci
783e5c31af7Sopenharmony_ciThe value returned by a read of an invalid texel is undefined:, unless that
784e5c31af7Sopenharmony_ciread operation is from a buffer resource and the pname:robustBufferAccess
785e5c31af7Sopenharmony_cifeature is enabled.
786e5c31af7Sopenharmony_ciIn that case, an invalid texel is replaced as described by the
787e5c31af7Sopenharmony_ci<<features-robustBufferAccess,pname:robustBufferAccess feature>>.
788e5c31af7Sopenharmony_ciifdef::VK_EXT_image_robustness,VK_EXT_robustness2[]
789e5c31af7Sopenharmony_ciIf the access is to an image resource and the x, y, z, or layer coordinate
790e5c31af7Sopenharmony_civalidation fails and
791e5c31af7Sopenharmony_ciifdef::VK_EXT_image_robustness[]
792e5c31af7Sopenharmony_ci<<features-robustImageAccess,pname:robustImageAccess>> is enabled then zero
793e5c31af7Sopenharmony_cimust: be returned for the R, G, and B components, if present.
794e5c31af7Sopenharmony_ciEither zero or one must: be returned for the A component, if present.
795e5c31af7Sopenharmony_ciendif::VK_EXT_image_robustness[]
796e5c31af7Sopenharmony_ciifdef::VK_EXT_image_robustness+VK_EXT_robustness2[If]
797e5c31af7Sopenharmony_ciifdef::VK_EXT_robustness2[]
798e5c31af7Sopenharmony_ci<<features-robustImageAccess2,pname:robustImageAccess2>> is enabled, zero
799e5c31af7Sopenharmony_civalues must: be returned.
800e5c31af7Sopenharmony_ciendif::VK_EXT_robustness2[]
801e5c31af7Sopenharmony_ciIf only the sample index was invalid, the values returned are undefined:.
802e5c31af7Sopenharmony_ciendif::VK_EXT_image_robustness,VK_EXT_robustness2[]
803e5c31af7Sopenharmony_ci
804e5c31af7Sopenharmony_ciifdef::VK_EXT_image_robustness[]
805e5c31af7Sopenharmony_ciAdditionally, if <<features-robustImageAccess,pname:robustImageAccess>> is
806e5c31af7Sopenharmony_cienabled,
807e5c31af7Sopenharmony_ciifdef::VK_EXT_robustness2[]
808e5c31af7Sopenharmony_cibut <<features-robustImageAccess2,pname:robustImageAccess2>> is not,
809e5c31af7Sopenharmony_ciendif::VK_EXT_robustness2[]
810e5c31af7Sopenharmony_ciany invalid texels may: be expanded to four components prior to texel
811e5c31af7Sopenharmony_cireplacement.
812e5c31af7Sopenharmony_ciThis means that components not present in the image format may be replaced
813e5c31af7Sopenharmony_ciwith 0 or may undergo <<textures-conversion-to-rgba,conversion to RGBA>> as
814e5c31af7Sopenharmony_cinormal.
815e5c31af7Sopenharmony_ciendif::VK_EXT_image_robustness[]
816e5c31af7Sopenharmony_ci
817e5c31af7Sopenharmony_ciifdef::VK_EXT_robustness2[]
818e5c31af7Sopenharmony_ciLoads from a null descriptor return a four component color value of all
819e5c31af7Sopenharmony_cizeros.
820e5c31af7Sopenharmony_ciHowever, for storage images and storage texel buffers using an explicit
821e5c31af7Sopenharmony_ciSPIR-V Image Format, loads from a null descriptor may: return an alpha value
822e5c31af7Sopenharmony_ciof 1 (float or integer, depending on format) if the format does not include
823e5c31af7Sopenharmony_cialpha.
824e5c31af7Sopenharmony_ciendif::VK_EXT_robustness2[]
825e5c31af7Sopenharmony_ci
826e5c31af7Sopenharmony_ciIf the
827e5c31af7Sopenharmony_cislink:VkPhysicalDeviceSparseProperties::pname:residencyNonResidentStrict
828e5c31af7Sopenharmony_ciproperty is ename:VK_TRUE, a sparse unbound texel is replaced with 0 or 0.0
829e5c31af7Sopenharmony_civalues for integer and floating-point components of the image format,
830e5c31af7Sopenharmony_cirespectively.
831e5c31af7Sopenharmony_ci
832e5c31af7Sopenharmony_ciIf pname:residencyNonResidentStrict is ename:VK_FALSE, the value of the
833e5c31af7Sopenharmony_cisparse unbound texel is undefined:.
834e5c31af7Sopenharmony_ci
835e5c31af7Sopenharmony_ci
836e5c31af7Sopenharmony_ci[[textures-depth-compare-operation]]
837e5c31af7Sopenharmony_ci=== Depth Compare Operation
838e5c31af7Sopenharmony_ci
839e5c31af7Sopenharmony_ciIf the image view has a depth/stencil format, the depth component is
840e5c31af7Sopenharmony_ciselected by the pname:aspectMask, and the operation is a code:Dref
841e5c31af7Sopenharmony_ciinstruction, a depth comparison is performed.
842e5c31af7Sopenharmony_ciThe value of the result [eq]#D# is [eq]#1.0# if the result of the compare
843e5c31af7Sopenharmony_cioperation is [eq]#true#, and [eq]#0.0# otherwise.
844e5c31af7Sopenharmony_ciThe compare operation is selected by the pname:compareOp member of the
845e5c31af7Sopenharmony_cisampler.
846e5c31af7Sopenharmony_ci
847e5c31af7Sopenharmony_ci[latexmath]
848e5c31af7Sopenharmony_ci+++++++++++++++++++
849e5c31af7Sopenharmony_ci\begin{aligned}
850e5c31af7Sopenharmony_ciD & = 1.0 &
851e5c31af7Sopenharmony_ci  \begin{cases}
852e5c31af7Sopenharmony_ci    D_{\textit{ref}} \leq D_{\textit{tex}} & \text{for LEQUAL}   \\
853e5c31af7Sopenharmony_ci    D_{\textit{ref}} \geq D_{\textit{tex}} & \text{for GEQUAL}   \\
854e5c31af7Sopenharmony_ci    D_{\textit{ref}} < D_{\textit{tex}}    & \text{for LESS}     \\
855e5c31af7Sopenharmony_ci    D_{\textit{ref}} > D_{\textit{tex}}    & \text{for GREATER}  \\
856e5c31af7Sopenharmony_ci    D_{\textit{ref}} = D_{\textit{tex}}    & \text{for EQUAL}    \\
857e5c31af7Sopenharmony_ci    D_{\textit{ref}} \neq D_{\textit{tex}} & \text{for NOTEQUAL} \\
858e5c31af7Sopenharmony_ci    \textit{true}                          & \text{for ALWAYS}   \\
859e5c31af7Sopenharmony_ci    \textit{false}                         & \text{for NEVER}
860e5c31af7Sopenharmony_ci  \end{cases} \\
861e5c31af7Sopenharmony_ciD & = 0.0 & \text{otherwise}
862e5c31af7Sopenharmony_ci\end{aligned}
863e5c31af7Sopenharmony_ci+++++++++++++++++++
864e5c31af7Sopenharmony_ci
865e5c31af7Sopenharmony_ciwhere [eq]#D~tex~# is the texel depth value and [eq]#D~ref~# is the
866e5c31af7Sopenharmony_cireference value from the SPIR-V operand.
867e5c31af7Sopenharmony_ciIf the image being sampled has a fixed-point format then the reference value
868e5c31af7Sopenharmony_ciis clamped to [0, 1] before the comparison operation.
869e5c31af7Sopenharmony_ci
870e5c31af7Sopenharmony_ci
871e5c31af7Sopenharmony_ci[[textures-conversion-to-rgba]]
872e5c31af7Sopenharmony_ci=== Conversion to RGBA
873e5c31af7Sopenharmony_ci
874e5c31af7Sopenharmony_ciThe texel is expanded from one, two, or three components to four components
875e5c31af7Sopenharmony_cibased on the image base color:
876e5c31af7Sopenharmony_ci
877e5c31af7Sopenharmony_ci[[textures-texel-color-rgba-conversion-table]]
878e5c31af7Sopenharmony_ci.Texel Color After Conversion To RGBA
879e5c31af7Sopenharmony_ci[width="100%", options="header", cols="<4,<6"]
880e5c31af7Sopenharmony_ci|====
881e5c31af7Sopenharmony_ci| Texel Aspect or Format      | RGBA Color
882e5c31af7Sopenharmony_ci| Depth aspect                | [eq]#[Color~r~,Color~g~,Color~b~, Color~a~] = [D,0,0,one]#
883e5c31af7Sopenharmony_ci| Stencil aspect              | [eq]#[Color~r~,Color~g~,Color~b~, Color~a~] = [S,0,0,one]#
884e5c31af7Sopenharmony_ci| One component color format  | [eq]#[Color~r~,Color~g~,Color~b~, Color~a~] = [Color~r~,0,0,one]#
885e5c31af7Sopenharmony_ci| Two component color format  | [eq]#[Color~r~,Color~g~,Color~b~, Color~a~] = [Color~r~,Color~g~,0,one]#
886e5c31af7Sopenharmony_ci| Three component color format| [eq]#[Color~r~,Color~g~,Color~b~, Color~a~] = [Color~r~,Color~g~,Color~b~,one]#
887e5c31af7Sopenharmony_ci| Four component color format | [eq]#[Color~r~,Color~g~,Color~b~, Color~a~] = [Color~r~,Color~g~,Color~b~,Color~a~]#
888e5c31af7Sopenharmony_ci|====
889e5c31af7Sopenharmony_ci
890e5c31af7Sopenharmony_ciwhere [eq]#one = 1.0f# for floating-point formats and depth aspects, and
891e5c31af7Sopenharmony_ci[eq]#one = 1# for integer formats and stencil aspects.
892e5c31af7Sopenharmony_ci
893e5c31af7Sopenharmony_ci
894e5c31af7Sopenharmony_ci[[textures-component-swizzle]]
895e5c31af7Sopenharmony_ci=== Component Swizzle
896e5c31af7Sopenharmony_ci
897e5c31af7Sopenharmony_ciifndef::VK_VERSION_1_1,VK_KHR_sampler_ycbcr_conversion[]
898e5c31af7Sopenharmony_ciAll texel input instructions apply a _swizzle_ based on the
899e5c31af7Sopenharmony_cielink:VkComponentSwizzle enums in the pname:components member of the
900e5c31af7Sopenharmony_cislink:VkImageViewCreateInfo structure for the image being read.
901e5c31af7Sopenharmony_ciendif::VK_VERSION_1_1,VK_KHR_sampler_ycbcr_conversion[]
902e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_1,VK_KHR_sampler_ycbcr_conversion[]
903e5c31af7Sopenharmony_ciAll texel input instructions apply a _swizzle_ based on:
904e5c31af7Sopenharmony_ci
905e5c31af7Sopenharmony_ci  * the elink:VkComponentSwizzle enums in the pname:components member of the
906e5c31af7Sopenharmony_ci    slink:VkImageViewCreateInfo structure for the image being read if
907e5c31af7Sopenharmony_ci    <<samplers-YCbCr-conversion,sampler {YCbCr} conversion>> is not enabled,
908e5c31af7Sopenharmony_ci    and
909e5c31af7Sopenharmony_ci  * the elink:VkComponentSwizzle enums in the pname:components member of the
910e5c31af7Sopenharmony_ci    slink:VkSamplerYcbcrConversionCreateInfo structure for the
911e5c31af7Sopenharmony_ci    <<samplers-YCbCr-conversion,sampler {YCbCr} conversion>> if sampler
912e5c31af7Sopenharmony_ci    {YCbCr} conversion is enabled.
913e5c31af7Sopenharmony_ci
914e5c31af7Sopenharmony_ciendif::VK_VERSION_1_1,VK_KHR_sampler_ycbcr_conversion[]
915e5c31af7Sopenharmony_ci
916e5c31af7Sopenharmony_ciThe swizzle can: rearrange the components of the texel, or substitute zero
917e5c31af7Sopenharmony_cior one for any components.
918e5c31af7Sopenharmony_ciIt is defined as follows for each color [eq]#component#:
919e5c31af7Sopenharmony_ci
920e5c31af7Sopenharmony_ci
921e5c31af7Sopenharmony_ci[latexmath]
922e5c31af7Sopenharmony_ci+++++++++++++++++++
923e5c31af7Sopenharmony_ci\begin{aligned}
924e5c31af7Sopenharmony_ciColor'_{component} & =
925e5c31af7Sopenharmony_ci\begin{cases}
926e5c31af7Sopenharmony_ciColor_r          & \text{for RED swizzle}   \\
927e5c31af7Sopenharmony_ciColor_g          & \text{for GREEN swizzle} \\
928e5c31af7Sopenharmony_ciColor_b          & \text{for BLUE swizzle}  \\
929e5c31af7Sopenharmony_ciColor_a          & \text{for ALPHA swizzle} \\
930e5c31af7Sopenharmony_ci0                & \text{for ZERO swizzle}  \\
931e5c31af7Sopenharmony_cione              & \text{for ONE swizzle} \\
932e5c31af7Sopenharmony_ciidentity         & \text{for IDENTITY swizzle}
933e5c31af7Sopenharmony_ci\end{cases}
934e5c31af7Sopenharmony_ci\end{aligned}
935e5c31af7Sopenharmony_ci+++++++++++++++++++
936e5c31af7Sopenharmony_ci
937e5c31af7Sopenharmony_ciwhere:
938e5c31af7Sopenharmony_ci
939e5c31af7Sopenharmony_ci[latexmath]
940e5c31af7Sopenharmony_ci+++++++++++++++++++
941e5c31af7Sopenharmony_ci\begin{aligned}
942e5c31af7Sopenharmony_cione & =
943e5c31af7Sopenharmony_ci\begin{cases}
944e5c31af7Sopenharmony_ci& 1.0\text{f}  & \text{for floating point components} \\
945e5c31af7Sopenharmony_ci& 1            & \text{for integer components} \\
946e5c31af7Sopenharmony_ci\end{cases}
947e5c31af7Sopenharmony_ci\\
948e5c31af7Sopenharmony_ciidentity & =
949e5c31af7Sopenharmony_ci\begin{cases}
950e5c31af7Sopenharmony_ci& Color_r          & \text{for}\ component = r \\
951e5c31af7Sopenharmony_ci& Color_g          & \text{for}\ component = g \\
952e5c31af7Sopenharmony_ci& Color_b          & \text{for}\ component = b \\
953e5c31af7Sopenharmony_ci& Color_a          & \text{for}\ component = a \\
954e5c31af7Sopenharmony_ci\end{cases}
955e5c31af7Sopenharmony_ci\end{aligned}
956e5c31af7Sopenharmony_ci+++++++++++++++++++
957e5c31af7Sopenharmony_ci
958e5c31af7Sopenharmony_ciIf the border color is one of the etext:VK_BORDER_COLOR_*_OPAQUE_BLACK enums
959e5c31af7Sopenharmony_ciand the elink:VkComponentSwizzle is not the
960e5c31af7Sopenharmony_ci<<resources-image-views-identity-mappings,identity swizzle>> for all
961e5c31af7Sopenharmony_cicomponents, the value of the texel after swizzle is undefined:.
962e5c31af7Sopenharmony_ci
963e5c31af7Sopenharmony_ci[[textures-sparse-residency]]
964e5c31af7Sopenharmony_ci=== Sparse Residency
965e5c31af7Sopenharmony_ci
966e5c31af7Sopenharmony_cicode:OpImageSparse* instructions return a structure which includes a
967e5c31af7Sopenharmony_ci_residency code_ indicating whether any texels accessed by the instruction
968e5c31af7Sopenharmony_ciare sparse unbound texels.
969e5c31af7Sopenharmony_ciThis code can: be interpreted by the code:OpImageSparseTexelsResident
970e5c31af7Sopenharmony_ciinstruction which converts the residency code to a boolean value.
971e5c31af7Sopenharmony_ci
972e5c31af7Sopenharmony_ci
973e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_1,VK_KHR_sampler_ycbcr_conversion[]
974e5c31af7Sopenharmony_ci[[textures-chroma-reconstruction]]
975e5c31af7Sopenharmony_ci=== Chroma Reconstruction
976e5c31af7Sopenharmony_ci
977e5c31af7Sopenharmony_ciIn some color models, the color representation is defined in terms of
978e5c31af7Sopenharmony_cimonochromatic light intensity (often called "`luma`") and color differences
979e5c31af7Sopenharmony_cirelative to this intensity, often called "`chroma`".
980e5c31af7Sopenharmony_ciIt is common for color models other than RGB to represent the chroma
981e5c31af7Sopenharmony_cicomponents at lower spatial resolution than the luma component.
982e5c31af7Sopenharmony_ciThis approach is used to take advantage of the eye's lower spatial
983e5c31af7Sopenharmony_cisensitivity to color compared with its sensitivity to brightness.
984e5c31af7Sopenharmony_ciLess commonly, the same approach is used with additive color, since the
985e5c31af7Sopenharmony_cigreen component dominates the eye's sensitivity to light intensity and the
986e5c31af7Sopenharmony_cispatial sensitivity to color introduced by red and blue is lower.
987e5c31af7Sopenharmony_ci
988e5c31af7Sopenharmony_ciLower-resolution components are "`downsampled`" by resizing them to a lower
989e5c31af7Sopenharmony_cispatial resolution than the component representing luminance.
990e5c31af7Sopenharmony_ciThis process is also commonly known as "`chroma subsampling`".
991e5c31af7Sopenharmony_ciThere is one luminance sample in each texture texel, but each chrominance
992e5c31af7Sopenharmony_cisample may be shared among several texels in one or both texture dimensions.
993e5c31af7Sopenharmony_ci
994e5c31af7Sopenharmony_ci * "`etext:_444`" formats do not spatially downsample chroma values compared
995e5c31af7Sopenharmony_ci   with luma: there are unique chroma samples for each texel.
996e5c31af7Sopenharmony_ci
997e5c31af7Sopenharmony_ci * "`etext:_422`" formats have downsampling in the x dimension
998e5c31af7Sopenharmony_ci   (corresponding to _u_ or _s_ coordinates): they are sampled at half the
999e5c31af7Sopenharmony_ci   resolution of luma in that dimension.
1000e5c31af7Sopenharmony_ci
1001e5c31af7Sopenharmony_ci * "`etext:_420`" formats have downsampling in the x dimension
1002e5c31af7Sopenharmony_ci   (corresponding to _u_ or _s_ coordinates) and the y dimension
1003e5c31af7Sopenharmony_ci   (corresponding to _v_ or _t_ coordinates): they are sampled at half the
1004e5c31af7Sopenharmony_ci   resolution of luma in both dimensions.
1005e5c31af7Sopenharmony_ci
1006e5c31af7Sopenharmony_ciThe process of reconstructing a full color value for texture access involves
1007e5c31af7Sopenharmony_ciaccessing both chroma and luma values at the same location.
1008e5c31af7Sopenharmony_ciTo generate the color accurately, the values of the lower-resolution
1009e5c31af7Sopenharmony_cicomponents at the location of the luma samples must be reconstructed from
1010e5c31af7Sopenharmony_cithe lower-resolution sample locations, an operation known here as "`chroma
1011e5c31af7Sopenharmony_cireconstruction`" irrespective of the actual color model.
1012e5c31af7Sopenharmony_ci
1013e5c31af7Sopenharmony_ciThe location of the chroma samples relative to the luma coordinates is
1014e5c31af7Sopenharmony_cidetermined by the pname:xChromaOffset and pname:yChromaOffset members of the
1015e5c31af7Sopenharmony_cislink:VkSamplerYcbcrConversionCreateInfo structure used to create the
1016e5c31af7Sopenharmony_cisampler {YCbCr} conversion.
1017e5c31af7Sopenharmony_ci
1018e5c31af7Sopenharmony_ciThe following diagrams show the relationship between unnormalized (_u_,_v_)
1019e5c31af7Sopenharmony_cicoordinates and (_i_,_j_) integer texel positions in the luma component
1020e5c31af7Sopenharmony_ci(shown in black, with circles showing integer sample positions) and the
1021e5c31af7Sopenharmony_citexel coordinates of reduced-resolution chroma components, shown as crosses
1022e5c31af7Sopenharmony_ciin red.
1023e5c31af7Sopenharmony_ci
1024e5c31af7Sopenharmony_ci[NOTE]
1025e5c31af7Sopenharmony_ci.Note
1026e5c31af7Sopenharmony_ci====
1027e5c31af7Sopenharmony_ciIf the chroma values are reconstructed at the locations of the luma samples
1028e5c31af7Sopenharmony_ciby means of interpolation, chroma samples from outside the image bounds are
1029e5c31af7Sopenharmony_cineeded; these are determined according to <<textures-wrapping-operation>>.
1030e5c31af7Sopenharmony_ciThese diagrams represent this by showing the bounds of the "`chroma texel`"
1031e5c31af7Sopenharmony_ciextending beyond the image bounds, and including additional chroma sample
1032e5c31af7Sopenharmony_cipositions where required for interpolation.
1033e5c31af7Sopenharmony_ciThe limits of a sample for etext:NEAREST sampling is shown as a grid.
1034e5c31af7Sopenharmony_ci====
1035e5c31af7Sopenharmony_ci
1036e5c31af7Sopenharmony_ciimage::{images}/chromasamples_422_cosited.svg[align="center",title="422 downsampling, xChromaOffset=COSITED_EVEN",opts="{imageopts}"]
1037e5c31af7Sopenharmony_ci
1038e5c31af7Sopenharmony_ciimage::{images}/chromasamples_422_midpoint.svg[align="center",title="422 downsampling, xChromaOffset=MIDPOINT",opts="{imageopts}"]
1039e5c31af7Sopenharmony_ci
1040e5c31af7Sopenharmony_ciimage::{images}/chromasamples_420_xcosited_ycosited.svg[align="center",title="420 downsampling, xChromaOffset=COSITED_EVEN, yChromaOffset=COSITED_EVEN",opts="{imageopts}"]
1041e5c31af7Sopenharmony_ci
1042e5c31af7Sopenharmony_ciimage::{images}/chromasamples_420_xmidpoint_ycosited.svg[align="center",title="420 downsampling, xChromaOffset=MIDPOINT, yChromaOffset=COSITED_EVEN",opts="{imageopts}"]
1043e5c31af7Sopenharmony_ci
1044e5c31af7Sopenharmony_ciimage::{images}/chromasamples_420_xcosited_ymidpoint.svg[align="center",title="420 downsampling, xChromaOffset=COSITED_EVEN, yChromaOffset=MIDPOINT",opts="{imageopts}"]
1045e5c31af7Sopenharmony_ci
1046e5c31af7Sopenharmony_ciimage::{images}/chromasamples_420_xmidpoint_ymidpoint.svg[align="center",title="420 downsampling, xChromaOffset=MIDPOINT, yChromaOffset=MIDPOINT",opts="{imageopts}"]
1047e5c31af7Sopenharmony_ci
1048e5c31af7Sopenharmony_ciReconstruction is implemented in one of two ways:
1049e5c31af7Sopenharmony_ci
1050e5c31af7Sopenharmony_ciIf the format of the image that is to be sampled sets
1051e5c31af7Sopenharmony_ciename:VK_FORMAT_FEATURE_SAMPLED_IMAGE_YCBCR_CONVERSION_CHROMA_RECONSTRUCTION_EXPLICIT_BIT,
1052e5c31af7Sopenharmony_cior the slink:VkSamplerYcbcrConversionCreateInfo's
1053e5c31af7Sopenharmony_cipname:forceExplicitReconstruction is set to ename:VK_TRUE, reconstruction is
1054e5c31af7Sopenharmony_ciperformed as an explicit step independent of filtering, described in the
1055e5c31af7Sopenharmony_ci<<textures-explicit-reconstruction>> section.
1056e5c31af7Sopenharmony_ci
1057e5c31af7Sopenharmony_ciIf the format of the image that is to be sampled does not set
1058e5c31af7Sopenharmony_ciename:VK_FORMAT_FEATURE_SAMPLED_IMAGE_YCBCR_CONVERSION_CHROMA_RECONSTRUCTION_EXPLICIT_BIT
1059e5c31af7Sopenharmony_ciand if the slink:VkSamplerYcbcrConversionCreateInfo's
1060e5c31af7Sopenharmony_cipname:forceExplicitReconstruction is set to ename:VK_FALSE, reconstruction
1061e5c31af7Sopenharmony_ciis performed as an implicit part of filtering prior to color model
1062e5c31af7Sopenharmony_ciconversion, with no separate post-conversion texel filtering step, as
1063e5c31af7Sopenharmony_cidescribed in the <<textures-implict-reconstruction,Implicit Reconstruction>>
1064e5c31af7Sopenharmony_cisection.
1065e5c31af7Sopenharmony_ci
1066e5c31af7Sopenharmony_ci
1067e5c31af7Sopenharmony_ci[[textures-explicit-reconstruction]]
1068e5c31af7Sopenharmony_ci==== Explicit Reconstruction
1069e5c31af7Sopenharmony_ci
1070e5c31af7Sopenharmony_ci  * If the pname:chromaFilter member of the
1071e5c31af7Sopenharmony_ci    slink:VkSamplerYcbcrConversionCreateInfo structure is
1072e5c31af7Sopenharmony_ci    ename:VK_FILTER_NEAREST:
1073e5c31af7Sopenharmony_ci  ** If the format's R and B components are reduced in resolution in just
1074e5c31af7Sopenharmony_ci     width by a factor of two relative to the G component (i.e. this is a
1075e5c31af7Sopenharmony_ci     "`etext:_422`" format), the latexmath:[\tau_{ijk}[level\]] values
1076e5c31af7Sopenharmony_ci     accessed by <<textures-texel-filtering,texel filtering>> are
1077e5c31af7Sopenharmony_ci     reconstructed as follows:
1078e5c31af7Sopenharmony_ci+
1079e5c31af7Sopenharmony_ci[latexmath]
1080e5c31af7Sopenharmony_ci++++++++++++++
1081e5c31af7Sopenharmony_ci\begin{aligned}
1082e5c31af7Sopenharmony_ci\tau_R'(i, j) & = \tau_R(\left\lfloor{i\times 0.5}\right\rfloor, j)[level] \\
1083e5c31af7Sopenharmony_ci\tau_B'(i, j) & = \tau_B(\left\lfloor{i\times 0.5}\right\rfloor, j)[level]
1084e5c31af7Sopenharmony_ci\end{aligned}
1085e5c31af7Sopenharmony_ci++++++++++++++
1086e5c31af7Sopenharmony_ci
1087e5c31af7Sopenharmony_ci  ** If the format's R and B components are reduced in resolution in width
1088e5c31af7Sopenharmony_ci     and height by a factor of two relative to the G component (i.e. this is
1089e5c31af7Sopenharmony_ci     a "`etext:_420`" format), the latexmath:[\tau_{ijk}[level\]] values
1090e5c31af7Sopenharmony_ci     accessed by <<textures-texel-filtering,texel filtering>> are
1091e5c31af7Sopenharmony_ci     reconstructed as follows:
1092e5c31af7Sopenharmony_ci+
1093e5c31af7Sopenharmony_ci[latexmath]
1094e5c31af7Sopenharmony_ci++++++++++++++
1095e5c31af7Sopenharmony_ci\begin{aligned}
1096e5c31af7Sopenharmony_ci\tau_R'(i, j) & = \tau_R(\left\lfloor{i\times 0.5}\right\rfloor, \left\lfloor{j\times 0.5}\right\rfloor)[level] \\
1097e5c31af7Sopenharmony_ci\tau_B'(i, j) & = \tau_B(\left\lfloor{i\times 0.5}\right\rfloor, \left\lfloor{j\times 0.5}\right\rfloor)[level]
1098e5c31af7Sopenharmony_ci\end{aligned}
1099e5c31af7Sopenharmony_ci++++++++++++++
1100e5c31af7Sopenharmony_ci+
1101e5c31af7Sopenharmony_ci[NOTE]
1102e5c31af7Sopenharmony_ci.Note
1103e5c31af7Sopenharmony_ci====
1104e5c31af7Sopenharmony_cipname:xChromaOffset and pname:yChromaOffset have no effect if
1105e5c31af7Sopenharmony_cipname:chromaFilter is ename:VK_FILTER_NEAREST for explicit reconstruction.
1106e5c31af7Sopenharmony_ci====
1107e5c31af7Sopenharmony_ci
1108e5c31af7Sopenharmony_ci  * If the pname:chromaFilter member of the
1109e5c31af7Sopenharmony_ci    slink:VkSamplerYcbcrConversionCreateInfo structure is
1110e5c31af7Sopenharmony_ci    ename:VK_FILTER_LINEAR:
1111e5c31af7Sopenharmony_ci  ** If the format's R and B components are reduced in resolution in just
1112e5c31af7Sopenharmony_ci     width by a factor of two relative to the G component (i.e. this is a
1113e5c31af7Sopenharmony_ci     "`etext:_422`" format):
1114e5c31af7Sopenharmony_ci  *** If pname:xChromaOffset is ename:VK_CHROMA_LOCATION_COSITED_EVEN:
1115e5c31af7Sopenharmony_ci+
1116e5c31af7Sopenharmony_ci[latexmath]
1117e5c31af7Sopenharmony_ci+++++
1118e5c31af7Sopenharmony_ci\tau_{RB}'(i,j) = \begin{cases}
1119e5c31af7Sopenharmony_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\\
1120e5c31af7Sopenharmony_ci0.5\times\tau_{RB}(\left\lfloor{i\times 0.5}\right\rfloor,j)[level] + \\
1121e5c31af7Sopenharmony_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
1122e5c31af7Sopenharmony_ci\end{cases}
1123e5c31af7Sopenharmony_ci+++++
1124e5c31af7Sopenharmony_ci+
1125e5c31af7Sopenharmony_ci  *** If pname:xChromaOffset is ename:VK_CHROMA_LOCATION_MIDPOINT:
1126e5c31af7Sopenharmony_ci+
1127e5c31af7Sopenharmony_ci[latexmath]
1128e5c31af7Sopenharmony_ci+++++
1129e5c31af7Sopenharmony_ci\tau_{RB}'(i,j) = \begin{cases}
1130e5c31af7Sopenharmony_ci0.25 \times \tau_{RB}(\left\lfloor{i\times 0.5}\right\rfloor - 1,j)[level] + \\
1131e5c31af7Sopenharmony_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\\
1132e5c31af7Sopenharmony_ci0.75 \times \tau_{RB}(\left\lfloor{i\times 0.5}\right\rfloor,j)[level] + \\
1133e5c31af7Sopenharmony_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
1134e5c31af7Sopenharmony_ci\end{cases}
1135e5c31af7Sopenharmony_ci+++++
1136e5c31af7Sopenharmony_ci
1137e5c31af7Sopenharmony_ci  ** If the format's R and B components are reduced in resolution in width
1138e5c31af7Sopenharmony_ci     and height by a factor of two relative to the G component (i.e. this is
1139e5c31af7Sopenharmony_ci     a "`etext:_420`" format), a similar relationship applies.
1140e5c31af7Sopenharmony_ci     Due to the number of options, these formulae are expressed more
1141e5c31af7Sopenharmony_ci     concisely as follows:
1142e5c31af7Sopenharmony_ci+
1143e5c31af7Sopenharmony_ci[latexmath]
1144e5c31af7Sopenharmony_ci+++++
1145e5c31af7Sopenharmony_ci\begin{aligned}
1146e5c31af7Sopenharmony_ci  i_{RB} & =
1147e5c31af7Sopenharmony_ci    \begin{cases}
1148e5c31af7Sopenharmony_ci      0.5 \times (i) & \textrm{xChromaOffset = COSITED}\_\textrm{EVEN} \\
1149e5c31af7Sopenharmony_ci      0.5 \times (i - 0.5) & \textrm{xChromaOffset = MIDPOINT}
1150e5c31af7Sopenharmony_ci    \end{cases}\\
1151e5c31af7Sopenharmony_ci  j_{RB} & =
1152e5c31af7Sopenharmony_ci    \begin{cases}
1153e5c31af7Sopenharmony_ci      0.5 \times (j) & \textrm{yChromaOffset = COSITED}\_\textrm{EVEN} \\
1154e5c31af7Sopenharmony_ci      0.5 \times (j - 0.5) & \textrm{yChromaOffset = MIDPOINT}
1155e5c31af7Sopenharmony_ci    \end{cases}\\
1156e5c31af7Sopenharmony_ci  \\
1157e5c31af7Sopenharmony_ci  i_{floor} & = \left\lfloor i_{RB} \right\rfloor \\
1158e5c31af7Sopenharmony_ci  j_{floor} & = \left\lfloor j_{RB} \right\rfloor \\
1159e5c31af7Sopenharmony_ci  \\
1160e5c31af7Sopenharmony_ci  i_{frac} & = i_{RB} - i_{floor} \\
1161e5c31af7Sopenharmony_ci  j_{frac} & = j_{RB} - j_{floor}
1162e5c31af7Sopenharmony_ci\end{aligned}
1163e5c31af7Sopenharmony_ci+++++
1164e5c31af7Sopenharmony_ci+
1165e5c31af7Sopenharmony_ci[latexmath]
1166e5c31af7Sopenharmony_ci+++++
1167e5c31af7Sopenharmony_ci\begin{aligned}
1168e5c31af7Sopenharmony_ci\tau_{RB}'(i,j) =
1169e5c31af7Sopenharmony_ci    & \tau_{RB}(     i_{floor},     j_{floor})[level]
1170e5c31af7Sopenharmony_ci        & \times & ( 1 - i_{frac} ) &
1171e5c31af7Sopenharmony_ci        & \times & ( 1 - j_{frac} ) & + \\
1172e5c31af7Sopenharmony_ci    & \tau_{RB}( 1 + i_{floor},     j_{floor})[level]
1173e5c31af7Sopenharmony_ci        & \times & (     i_{frac} ) &
1174e5c31af7Sopenharmony_ci        & \times & ( 1 - j_{frac} ) & + \\
1175e5c31af7Sopenharmony_ci    & \tau_{RB}(     i_{floor}, 1 + j_{floor})[level]
1176e5c31af7Sopenharmony_ci        & \times & ( 1 - i_{frac} ) &
1177e5c31af7Sopenharmony_ci        & \times & (     j_{frac} ) & + \\
1178e5c31af7Sopenharmony_ci    & \tau_{RB}( 1 + i_{floor}, 1 + j_{floor})[level]
1179e5c31af7Sopenharmony_ci        & \times & (     i_{frac} ) &
1180e5c31af7Sopenharmony_ci        & \times & (     j_{frac} ) &
1181e5c31af7Sopenharmony_ci\end{aligned}
1182e5c31af7Sopenharmony_ci+++++
1183e5c31af7Sopenharmony_ci
1184e5c31af7Sopenharmony_ci[NOTE]
1185e5c31af7Sopenharmony_ci.Note
1186e5c31af7Sopenharmony_ci====
1187e5c31af7Sopenharmony_ciIn the case where the texture itself is bilinearly interpolated as described
1188e5c31af7Sopenharmony_ciin <<textures-texel-filtering,Texel Filtering>>, thus requiring four
1189e5c31af7Sopenharmony_cifull-color samples for the filtering operation, and where the reconstruction
1190e5c31af7Sopenharmony_ciof these samples uses bilinear interpolation in the chroma components due to
1191e5c31af7Sopenharmony_cipname:chromaFilter=ename:VK_FILTER_LINEAR, up to nine chroma samples may be
1192e5c31af7Sopenharmony_cirequired, depending on the sample location.
1193e5c31af7Sopenharmony_ci====
1194e5c31af7Sopenharmony_ci
1195e5c31af7Sopenharmony_ci
1196e5c31af7Sopenharmony_ci[[textures-implict-reconstruction]]
1197e5c31af7Sopenharmony_ci==== Implicit Reconstruction
1198e5c31af7Sopenharmony_ci
1199e5c31af7Sopenharmony_ciImplicit reconstruction takes place by the samples being interpolated, as
1200e5c31af7Sopenharmony_cirequired by the filter settings of the sampler, except that
1201e5c31af7Sopenharmony_cipname:chromaFilter takes precedence for the chroma samples.
1202e5c31af7Sopenharmony_ci
1203e5c31af7Sopenharmony_ciIf pname:chromaFilter is ename:VK_FILTER_NEAREST, an implementation may:
1204e5c31af7Sopenharmony_cibehave as if pname:xChromaOffset and pname:yChromaOffset were both
1205e5c31af7Sopenharmony_ciename:VK_CHROMA_LOCATION_MIDPOINT, irrespective of the values set.
1206e5c31af7Sopenharmony_ci
1207e5c31af7Sopenharmony_ci[NOTE]
1208e5c31af7Sopenharmony_ci.Note
1209e5c31af7Sopenharmony_ci====
1210e5c31af7Sopenharmony_ciThis will not have any visible effect if the locations of the luma samples
1211e5c31af7Sopenharmony_cicoincide with the location of the samples used for rasterization.
1212e5c31af7Sopenharmony_ci====
1213e5c31af7Sopenharmony_ci
1214e5c31af7Sopenharmony_ciThe sample coordinates are adjusted by the downsample factor of the
1215e5c31af7Sopenharmony_cicomponent (such that, for example, the sample coordinates are divided by two
1216e5c31af7Sopenharmony_ciif the component has a downsample factor of two relative to the luma
1217e5c31af7Sopenharmony_cicomponent):
1218e5c31af7Sopenharmony_ci
1219e5c31af7Sopenharmony_ci[latexmath]
1220e5c31af7Sopenharmony_ci++++++
1221e5c31af7Sopenharmony_ci\begin{aligned}
1222e5c31af7Sopenharmony_ciu_{RB}' (422/420) &=
1223e5c31af7Sopenharmony_ci  \begin{cases}
1224e5c31af7Sopenharmony_ci     0.5\times (u + 0.5), & \textrm{xChromaOffset = COSITED}\_\textrm{EVEN} \\
1225e5c31af7Sopenharmony_ci     0.5\times u, & \textrm{xChromaOffset = MIDPOINT}
1226e5c31af7Sopenharmony_ci  \end{cases} \\
1227e5c31af7Sopenharmony_civ_{RB}' (420) &=
1228e5c31af7Sopenharmony_ci  \begin{cases}
1229e5c31af7Sopenharmony_ci     0.5\times (v + 0.5), & \textrm{yChromaOffset = COSITED}\_\textrm{EVEN} \\
1230e5c31af7Sopenharmony_ci     0.5\times v, & \textrm{yChromaOffset = MIDPOINT}
1231e5c31af7Sopenharmony_ci  \end{cases}
1232e5c31af7Sopenharmony_ci\end{aligned}
1233e5c31af7Sopenharmony_ci++++++
1234e5c31af7Sopenharmony_ci
1235e5c31af7Sopenharmony_ci
1236e5c31af7Sopenharmony_ci[[textures-sampler-YCbCr-conversion]]
1237e5c31af7Sopenharmony_ci=== Sampler {YCbCr} Conversion
1238e5c31af7Sopenharmony_ci
1239e5c31af7Sopenharmony_ciSampler {YCbCr} conversion performs the following operations, which an
1240e5c31af7Sopenharmony_ciimplementation may: combine into a single mathematical operation:
1241e5c31af7Sopenharmony_ci
1242e5c31af7Sopenharmony_ci  * <<textures-sampler-YCbCr-conversion-rangeexpand,Sampler {YCbCr} Range
1243e5c31af7Sopenharmony_ci    Expansion>>
1244e5c31af7Sopenharmony_ci  * <<textures-sampler-YCbCr-conversion-modelconversion,Sampler {YCbCr}
1245e5c31af7Sopenharmony_ci    Model Conversion>>
1246e5c31af7Sopenharmony_ci
1247e5c31af7Sopenharmony_ci[[textures-sampler-YCbCr-conversion-rangeexpand]]
1248e5c31af7Sopenharmony_ci==== Sampler {YCbCr} Range Expansion
1249e5c31af7Sopenharmony_ci
1250e5c31af7Sopenharmony_ciSampler {YCbCr} range expansion is applied to color component values after
1251e5c31af7Sopenharmony_ciall texel input operations which are not specific to sampler {YCbCr}
1252e5c31af7Sopenharmony_ciconversion.
1253e5c31af7Sopenharmony_ciFor example, the input values to this stage have been converted using the
1254e5c31af7Sopenharmony_cinormal <<textures-format-conversion,format conversion>> rules.
1255e5c31af7Sopenharmony_ci
1256e5c31af7Sopenharmony_ciSampler {YCbCr} range expansion is not applied if pname:ycbcrModel is
1257e5c31af7Sopenharmony_ciename:VK_SAMPLER_YCBCR_MODEL_CONVERSION_RGB_IDENTITY.
1258e5c31af7Sopenharmony_ciThat is, the shader receives the vector C'~rgba~ as output by the Component
1259e5c31af7Sopenharmony_ciSwizzle stage without further modification.
1260e5c31af7Sopenharmony_ci
1261e5c31af7Sopenharmony_ciFor other values of pname:ycbcrModel, range expansion is applied to the
1262e5c31af7Sopenharmony_citexel component values output by the <<textures-component-swizzle,Component
1263e5c31af7Sopenharmony_ciSwizzle>> defined by the pname:components member of
1264e5c31af7Sopenharmony_cislink:VkSamplerYcbcrConversionCreateInfo.
1265e5c31af7Sopenharmony_ciRange expansion applies independently to each component of the image.
1266e5c31af7Sopenharmony_ciFor the purposes of range expansion and {YCbCr} model conversion, the R and
1267e5c31af7Sopenharmony_ciB components contain color difference (chroma) values and the G component
1268e5c31af7Sopenharmony_cicontains luma.
1269e5c31af7Sopenharmony_ciThe A component is not modified by sampler {YCbCr} range expansion.
1270e5c31af7Sopenharmony_ci
1271e5c31af7Sopenharmony_ciThe range expansion to be applied is defined by the pname:ycbcrRange member
1272e5c31af7Sopenharmony_ciof the slink:VkSamplerYcbcrConversionCreateInfo structure:
1273e5c31af7Sopenharmony_ci
1274e5c31af7Sopenharmony_ci  * If pname:ycbcrRange is ename:VK_SAMPLER_YCBCR_RANGE_ITU_FULL, the
1275e5c31af7Sopenharmony_ci    following transformations are applied:
1276e5c31af7Sopenharmony_ci+
1277e5c31af7Sopenharmony_ci[latexmath]
1278e5c31af7Sopenharmony_ci+++++++++++++++++++
1279e5c31af7Sopenharmony_ci\begin{aligned}
1280e5c31af7Sopenharmony_ciY' &= C'_{rgba}[G] \\
1281e5c31af7Sopenharmony_ciC_B &= C'_{rgba}[B] - {{2^{(n-1)}}\over{(2^n) - 1}} \\
1282e5c31af7Sopenharmony_ciC_R &= C'_{rgba}[R] - {{2^{(n-1)}}\over{(2^n) - 1}}
1283e5c31af7Sopenharmony_ci\end{aligned}
1284e5c31af7Sopenharmony_ci+++++++++++++++++++
1285e5c31af7Sopenharmony_ci+
1286e5c31af7Sopenharmony_ci[NOTE]
1287e5c31af7Sopenharmony_ci.Note
1288e5c31af7Sopenharmony_ci====
1289e5c31af7Sopenharmony_ciThese formulae correspond to the "`full range`" encoding in the
1290e5c31af7Sopenharmony_ci"`Quantization schemes`" chapter of the <<data-format,Khronos Data Format
1291e5c31af7Sopenharmony_ciSpecification>>.
1292e5c31af7Sopenharmony_ci
1293e5c31af7Sopenharmony_ciShould any future amendments be made to the ITU specifications from which
1294e5c31af7Sopenharmony_cithese equations are derived, the formulae used by Vulkan may: also be
1295e5c31af7Sopenharmony_ciupdated to maintain parity.
1296e5c31af7Sopenharmony_ci====
1297e5c31af7Sopenharmony_ci  * If pname:ycbcrRange is ename:VK_SAMPLER_YCBCR_RANGE_ITU_NARROW, the
1298e5c31af7Sopenharmony_ci    following transformations are applied:
1299e5c31af7Sopenharmony_ci+
1300e5c31af7Sopenharmony_ci[latexmath]
1301e5c31af7Sopenharmony_ci+++++++++++++++++++
1302e5c31af7Sopenharmony_ci\begin{aligned}
1303e5c31af7Sopenharmony_ciY' &= {{C'_{rgba}[G] \times (2^n-1) - 16\times 2^{n-8}}\over{219\times 2^{n-8}}} \\
1304e5c31af7Sopenharmony_ciC_B &= {{C'_{rgba}[B] \times \left(2^n-1\right) - 128\times 2^{n-8}}\over{224\times 2^{n-8}}} \\
1305e5c31af7Sopenharmony_ciC_R &= {{C'_{rgba}[R] \times \left(2^n-1\right) - 128\times 2^{n-8}}\over{224\times 2^{n-8}}}
1306e5c31af7Sopenharmony_ci\end{aligned}
1307e5c31af7Sopenharmony_ci+++++++++++++++++++
1308e5c31af7Sopenharmony_ci+
1309e5c31af7Sopenharmony_ci[NOTE]
1310e5c31af7Sopenharmony_ci.Note
1311e5c31af7Sopenharmony_ci====
1312e5c31af7Sopenharmony_ciThese formulae correspond to the "`narrow range`" encoding in the
1313e5c31af7Sopenharmony_ci"`Quantization schemes`" chapter of the <<data-format,Khronos Data Format
1314e5c31af7Sopenharmony_ciSpecification>>.
1315e5c31af7Sopenharmony_ci====
1316e5c31af7Sopenharmony_ci  * _n_ is the bit-depth of the components in the format.
1317e5c31af7Sopenharmony_ci
1318e5c31af7Sopenharmony_ciThe precision of the operations performed during range expansion must: be at
1319e5c31af7Sopenharmony_cileast that of the source format.
1320e5c31af7Sopenharmony_ci
1321e5c31af7Sopenharmony_ciAn implementation may: clamp the results of these range expansion operations
1322e5c31af7Sopenharmony_cisuch that Y{prime} falls in the range [0,1], and/or such that C~B~ and C~R~
1323e5c31af7Sopenharmony_cifall in the range [-0.5,0.5].
1324e5c31af7Sopenharmony_ci
1325e5c31af7Sopenharmony_ci[[textures-sampler-YCbCr-conversion-modelconversion]]
1326e5c31af7Sopenharmony_ci==== Sampler {YCbCr} Model Conversion
1327e5c31af7Sopenharmony_ci
1328e5c31af7Sopenharmony_ciThe range-expanded values are converted between color models, according to
1329e5c31af7Sopenharmony_cithe color model conversion specified in the pname:ycbcrModel member:
1330e5c31af7Sopenharmony_ci
1331e5c31af7Sopenharmony_ciename:VK_SAMPLER_YCBCR_MODEL_CONVERSION_RGB_IDENTITY::
1332e5c31af7Sopenharmony_ci  The color components are not modified by the color model conversion since
1333e5c31af7Sopenharmony_ci  they are assumed already to represent the desired color model in which the
1334e5c31af7Sopenharmony_ci  shader is operating; {YCbCr} range expansion is also ignored.
1335e5c31af7Sopenharmony_ciename:VK_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_IDENTITY::
1336e5c31af7Sopenharmony_ci  The color components are not modified by the color model conversion and
1337e5c31af7Sopenharmony_ci  are assumed to be treated as though in {YCbCr} form both in memory and in
1338e5c31af7Sopenharmony_ci  the shader; {YCbCr} range expansion is applied to the components as for
1339e5c31af7Sopenharmony_ci  other {YCbCr} models, with the vector (C~R~,Y{prime},C~B~,A) provided to
1340e5c31af7Sopenharmony_ci  the shader.
1341e5c31af7Sopenharmony_ciename:VK_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_709::
1342e5c31af7Sopenharmony_ci  The color components are transformed from a {YCbCr} representation to an
1343e5c31af7Sopenharmony_ci  {RGBprime} representation as described in the "`BT.709 {YCbCr}
1344e5c31af7Sopenharmony_ci  conversion`" section of the <<data-format,Khronos Data Format
1345e5c31af7Sopenharmony_ci  Specification>>.
1346e5c31af7Sopenharmony_ciename:VK_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_601::
1347e5c31af7Sopenharmony_ci  The color components are transformed from a {YCbCr} representation to an
1348e5c31af7Sopenharmony_ci  {RGBprime} representation as described in the "`BT.601 {YCbCr}
1349e5c31af7Sopenharmony_ci  conversion`" section of the <<data-format,Khronos Data Format
1350e5c31af7Sopenharmony_ci  Specification>>.
1351e5c31af7Sopenharmony_ciename:VK_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_2020::
1352e5c31af7Sopenharmony_ci  The color components are transformed from a {YCbCr} representation to an
1353e5c31af7Sopenharmony_ci  {RGBprime} representation as described in the "`BT.2020 {YCbCr}
1354e5c31af7Sopenharmony_ci  conversion`" section of the <<data-format,Khronos Data Format
1355e5c31af7Sopenharmony_ci  Specification>>.
1356e5c31af7Sopenharmony_ci
1357e5c31af7Sopenharmony_ciIn this operation, each output component is dependent on each input
1358e5c31af7Sopenharmony_cicomponent.
1359e5c31af7Sopenharmony_ci
1360e5c31af7Sopenharmony_ciAn implementation may: clamp the {RGBprime} results of these conversions to
1361e5c31af7Sopenharmony_cithe range [0,1].
1362e5c31af7Sopenharmony_ci
1363e5c31af7Sopenharmony_ciThe precision of the operations performed during model conversion must: be
1364e5c31af7Sopenharmony_ciat least that of the source format.
1365e5c31af7Sopenharmony_ci
1366e5c31af7Sopenharmony_ciThe alpha component is not modified by these model conversions.
1367e5c31af7Sopenharmony_ci
1368e5c31af7Sopenharmony_ci[NOTE]
1369e5c31af7Sopenharmony_ci.Note
1370e5c31af7Sopenharmony_ci====
1371e5c31af7Sopenharmony_ciSampling operations in a non-linear color space can introduce color and
1372e5c31af7Sopenharmony_ciintensity shifts at sharp transition boundaries.
1373e5c31af7Sopenharmony_ciTo avoid this issue, the technically precise color correction sequence
1374e5c31af7Sopenharmony_cidescribed in the "`Introduction to Color Conversions`" chapter of the
1375e5c31af7Sopenharmony_ci<<data-format,Khronos Data Format Specification>> may be performed as
1376e5c31af7Sopenharmony_cifollows:
1377e5c31af7Sopenharmony_ci
1378e5c31af7Sopenharmony_ci  * Calculate the <<textures-normalized-to-unnormalized,unnormalized texel
1379e5c31af7Sopenharmony_ci    coordinates>> corresponding to the desired sample position.
1380e5c31af7Sopenharmony_ci  * For a pname:minFilter or pname:magFilter of ename:VK_FILTER_NEAREST:
1381e5c31af7Sopenharmony_ci    . Calculate (_i_,_j_) for the sample location as described under the
1382e5c31af7Sopenharmony_ci      "`nearest filtering`" formulae in <<textures-unnormalized-to-integer>>
1383e5c31af7Sopenharmony_ci    . Calculate the normalized texel coordinates corresponding to these
1384e5c31af7Sopenharmony_ci      integer coordinates.
1385e5c31af7Sopenharmony_ci    . Sample using <<samplers-YCbCr-conversion,sampler {YCbCr} conversion>>
1386e5c31af7Sopenharmony_ci      at this location.
1387e5c31af7Sopenharmony_ci  * For a pname:minFilter or pname:magFilter of ename:VK_FILTER_LINEAR:
1388e5c31af7Sopenharmony_ci    . Calculate (_i~[0,1]~_,_j~[0,1]~_) for the sample location as described
1389e5c31af7Sopenharmony_ci      under the "`linear filtering`" formulae in
1390e5c31af7Sopenharmony_ci      <<textures-unnormalized-to-integer>>
1391e5c31af7Sopenharmony_ci    . Calculate the normalized texel coordinates corresponding to these
1392e5c31af7Sopenharmony_ci      integer coordinates.
1393e5c31af7Sopenharmony_ci    . Sample using <<samplers-YCbCr-conversion,sampler {YCbCr} conversion>>
1394e5c31af7Sopenharmony_ci      at each of these locations.
1395e5c31af7Sopenharmony_ci    . Convert the non-linear A{prime}{RGBprime} outputs of the {YCbCr}
1396e5c31af7Sopenharmony_ci      conversions to linear ARGB values as described in the "`Transfer
1397e5c31af7Sopenharmony_ci      Functions`" chapter of the <<data-format,Khronos Data Format
1398e5c31af7Sopenharmony_ci      Specification>>.
1399e5c31af7Sopenharmony_ci    . Interpolate the linear ARGB values using the [eq]#{alpha}# and
1400e5c31af7Sopenharmony_ci      [eq]#{beta}# values described in the "`linear filtering`" section of
1401e5c31af7Sopenharmony_ci      <<textures-unnormalized-to-integer>> and the equations in
1402e5c31af7Sopenharmony_ci      <<textures-texel-filtering>>.
1403e5c31af7Sopenharmony_ci
1404e5c31af7Sopenharmony_ciThe additional calculations and, especially, additional number of sampling
1405e5c31af7Sopenharmony_cioperations in the ename:VK_FILTER_LINEAR case can be expected to have a
1406e5c31af7Sopenharmony_ciperformance impact compared with using the outputs directly.
1407e5c31af7Sopenharmony_ciSince the variations from "`correct`" results are subtle for most content,
1408e5c31af7Sopenharmony_cithe application author should determine whether a more costly implementation
1409e5c31af7Sopenharmony_ciis strictly necessary.
1410e5c31af7Sopenharmony_ci
1411e5c31af7Sopenharmony_ciIf pname:chromaFilter, and pname:minFilter or pname:magFilter are both
1412e5c31af7Sopenharmony_ciename:VK_FILTER_NEAREST, these operations are redundant and sampling using
1413e5c31af7Sopenharmony_ci<<samplers-YCbCr-conversion,sampler {YCbCr} conversion>> at the desired
1414e5c31af7Sopenharmony_cisample coordinates will produce the "`correct`" results without further
1415e5c31af7Sopenharmony_ciprocessing.
1416e5c31af7Sopenharmony_ci====
1417e5c31af7Sopenharmony_ciendif::VK_VERSION_1_1,VK_KHR_sampler_ycbcr_conversion[]
1418e5c31af7Sopenharmony_ci
1419e5c31af7Sopenharmony_ci
1420e5c31af7Sopenharmony_ci== Texel Output Operations
1421e5c31af7Sopenharmony_ci
1422e5c31af7Sopenharmony_ci_Texel output instructions_ are SPIR-V image instructions that write to an
1423e5c31af7Sopenharmony_ciimage.
1424e5c31af7Sopenharmony_ci_Texel output operations_ are a set of steps that are performed on state,
1425e5c31af7Sopenharmony_cicoordinates, and texel values while processing a texel output instruction,
1426e5c31af7Sopenharmony_ciand which are common to some or all texel output instructions.
1427e5c31af7Sopenharmony_ciThey include the following steps, which are performed in the listed order:
1428e5c31af7Sopenharmony_ci
1429e5c31af7Sopenharmony_ci  * <<textures-output-validation,Validation operations>>
1430e5c31af7Sopenharmony_ci  ** <<textures-format-validation,Format validation>>
1431e5c31af7Sopenharmony_ci  ** <<textures-type-validation,Type validation>>
1432e5c31af7Sopenharmony_ci  ** <<textures-output-coordinate-validation,Coordinate validation>>
1433e5c31af7Sopenharmony_ci  ** <<textures-output-sparse-validation,Sparse validation>>
1434e5c31af7Sopenharmony_ci  * <<textures-output-format-conversion,Texel output format conversion>>
1435e5c31af7Sopenharmony_ci
1436e5c31af7Sopenharmony_ci[[textures-output-validation]]
1437e5c31af7Sopenharmony_ci=== Texel Output Validation Operations
1438e5c31af7Sopenharmony_ci
1439e5c31af7Sopenharmony_ci_Texel output validation operations_ inspect instruction/image state or
1440e5c31af7Sopenharmony_cicoordinates, and in certain circumstances cause the write to have no effect.
1441e5c31af7Sopenharmony_ciThere are a series of validations that the texel undergoes.
1442e5c31af7Sopenharmony_ci
1443e5c31af7Sopenharmony_ci
1444e5c31af7Sopenharmony_ci[[textures-format-validation]]
1445e5c31af7Sopenharmony_ci==== Texel Format Validation
1446e5c31af7Sopenharmony_ci
1447e5c31af7Sopenharmony_ciIf the image format of the code:OpTypeImage is not
1448e5c31af7Sopenharmony_ci<<spirvenv-image-formats,compatible>> with the sname:VkImageView's
1449e5c31af7Sopenharmony_cipname:format, the write causes the contents of the image's memory to become
1450e5c31af7Sopenharmony_ciundefined:.
1451e5c31af7Sopenharmony_ci
1452e5c31af7Sopenharmony_ci
1453e5c31af7Sopenharmony_ci[[textures-type-validation]]
1454e5c31af7Sopenharmony_ci==== Texel Type Validation
1455e5c31af7Sopenharmony_ci
1456e5c31af7Sopenharmony_ciIf the code:Sampled code:Type of the code:OpTypeImage does not match the
1457e5c31af7Sopenharmony_citype defined for the format, as specified in the _SPIR-V Sampled Type_
1458e5c31af7Sopenharmony_cicolumn of the <<formats-numericformat>> table, the write causes the value of
1459e5c31af7Sopenharmony_cithe texel to become undefined:.
1460e5c31af7Sopenharmony_ciFor integer types, if the <<spirvenv-image-signedness,signedness of the
1461e5c31af7Sopenharmony_ciaccess>> does not match the signedness of the accessed resource, the write
1462e5c31af7Sopenharmony_cicauses the value of the texel to become undefined:.
1463e5c31af7Sopenharmony_ci
1464e5c31af7Sopenharmony_ci
1465e5c31af7Sopenharmony_ci[[textures-output-coordinate-validation]]
1466e5c31af7Sopenharmony_ci=== Integer Texel Coordinate Validation
1467e5c31af7Sopenharmony_ci
1468e5c31af7Sopenharmony_ciThe integer texel coordinates are validated according to the same rules as
1469e5c31af7Sopenharmony_cifor texel input <<textures-integer-coordinate-validation,coordinate
1470e5c31af7Sopenharmony_civalidation>>.
1471e5c31af7Sopenharmony_ci
1472e5c31af7Sopenharmony_ciIf the texel fails integer texel coordinate validation, then the write has
1473e5c31af7Sopenharmony_cino effect.
1474e5c31af7Sopenharmony_ci
1475e5c31af7Sopenharmony_ci
1476e5c31af7Sopenharmony_ci[[textures-output-sparse-validation]]
1477e5c31af7Sopenharmony_ci=== Sparse Texel Operation
1478e5c31af7Sopenharmony_ci
1479e5c31af7Sopenharmony_ciIf the texel attempts to write to an unbound region of a sparse image, the
1480e5c31af7Sopenharmony_citexel is a sparse unbound texel.
1481e5c31af7Sopenharmony_ciIn such a case, if the
1482e5c31af7Sopenharmony_cislink:VkPhysicalDeviceSparseProperties::pname:residencyNonResidentStrict
1483e5c31af7Sopenharmony_ciproperty is ename:VK_TRUE, the sparse unbound texel write has no effect.
1484e5c31af7Sopenharmony_ciIf pname:residencyNonResidentStrict is ename:VK_FALSE, the write may: have a
1485e5c31af7Sopenharmony_ciside effect that becomes visible to other accesses to unbound texels in any
1486e5c31af7Sopenharmony_ciresource, but will not be visible to any device memory allocated by the
1487e5c31af7Sopenharmony_ciapplication.
1488e5c31af7Sopenharmony_ci
1489e5c31af7Sopenharmony_ci
1490e5c31af7Sopenharmony_ci[[textures-output-format-conversion]]
1491e5c31af7Sopenharmony_ci=== Texel Output Format Conversion
1492e5c31af7Sopenharmony_ci
1493e5c31af7Sopenharmony_ciIf the image format is sRGB, a linear to sRGB conversion is applied to the
1494e5c31af7Sopenharmony_ciR, G, and B components as described in the "`sRGB EOTF`" section of the
1495e5c31af7Sopenharmony_ci<<data-format,Khronos Data Format Specification>>.
1496e5c31af7Sopenharmony_ciThe A component, if present, is unchanged.
1497e5c31af7Sopenharmony_ci
1498e5c31af7Sopenharmony_ciTexels then undergo a format conversion from the floating point, signed, or
1499e5c31af7Sopenharmony_ciunsigned integer type of the texel data to the elink:VkFormat of the image
1500e5c31af7Sopenharmony_ciview.
1501e5c31af7Sopenharmony_ciAny unused components are ignored.
1502e5c31af7Sopenharmony_ci
1503e5c31af7Sopenharmony_ciEach component is converted based on its type and size (as defined in the
1504e5c31af7Sopenharmony_ci<<formats-definition,Format Definition>> section for each elink:VkFormat).
1505e5c31af7Sopenharmony_ciFloating-point outputs are converted as described in
1506e5c31af7Sopenharmony_ci<<fundamentals-fp-conversion,Floating-Point Format Conversions>> and
1507e5c31af7Sopenharmony_ci<<fundamentals-fixedconv,Fixed-Point Data Conversion>>.
1508e5c31af7Sopenharmony_ciInteger outputs are converted such that their value is preserved.
1509e5c31af7Sopenharmony_ciThe converted value of any integer that cannot be represented in the target
1510e5c31af7Sopenharmony_ciformat is undefined:.
1511e5c31af7Sopenharmony_ci
1512e5c31af7Sopenharmony_ci
1513e5c31af7Sopenharmony_ci[[textures-normalized-operations]]
1514e5c31af7Sopenharmony_ci== Normalized Texel Coordinate Operations
1515e5c31af7Sopenharmony_ci
1516e5c31af7Sopenharmony_ciIf the image sampler instruction provides normalized texel coordinates, some
1517e5c31af7Sopenharmony_ciof the following operations are performed.
1518e5c31af7Sopenharmony_ci
1519e5c31af7Sopenharmony_ci
1520e5c31af7Sopenharmony_ci[[textures-projection]]
1521e5c31af7Sopenharmony_ci=== Projection Operation
1522e5c31af7Sopenharmony_ci
1523e5c31af7Sopenharmony_ciFor code:Proj image operations, the normalized texel coordinates
1524e5c31af7Sopenharmony_ci[eq]#(s,t,r,q,a)# and (if present) the [eq]#D~ref~# coordinate are
1525e5c31af7Sopenharmony_citransformed as follows:
1526e5c31af7Sopenharmony_ci
1527e5c31af7Sopenharmony_ci[latexmath]
1528e5c31af7Sopenharmony_ci+++++++++++++++++++
1529e5c31af7Sopenharmony_ci\begin{aligned}
1530e5c31af7Sopenharmony_cis       & = \frac{s}{q},       & \text{for 1D, 2D, or 3D image} \\
1531e5c31af7Sopenharmony_ci\\
1532e5c31af7Sopenharmony_cit       & = \frac{t}{q},       & \text{for 2D or 3D image} \\
1533e5c31af7Sopenharmony_ci\\
1534e5c31af7Sopenharmony_cir       & = \frac{r}{q},       & \text{for 3D image} \\
1535e5c31af7Sopenharmony_ci\\
1536e5c31af7Sopenharmony_ciD_{\textit{ref}} & = \frac{D_{\textit{ref}}}{q}, & \text{if provided}
1537e5c31af7Sopenharmony_ci\end{aligned}
1538e5c31af7Sopenharmony_ci+++++++++++++++++++
1539e5c31af7Sopenharmony_ci
1540e5c31af7Sopenharmony_ci
1541e5c31af7Sopenharmony_ci[[textures-derivative-image-operations]]
1542e5c31af7Sopenharmony_ci=== Derivative Image Operations
1543e5c31af7Sopenharmony_ci
1544e5c31af7Sopenharmony_ciDerivatives are used for LOD selection.
1545e5c31af7Sopenharmony_ciThese derivatives are either implicit (in an code:ImplicitLod image
1546e5c31af7Sopenharmony_ciinstruction in a fragment shader) or explicit (provided explicitly by shader
1547e5c31af7Sopenharmony_cito the image instruction in any shader).
1548e5c31af7Sopenharmony_ci
1549e5c31af7Sopenharmony_ciFor implicit derivatives image instructions, the derivatives of texel
1550e5c31af7Sopenharmony_cicoordinates are calculated in the same manner as
1551e5c31af7Sopenharmony_ci<<shaders-derivative-operations, derivative operations>>.
1552e5c31af7Sopenharmony_ciThat is:
1553e5c31af7Sopenharmony_ci
1554e5c31af7Sopenharmony_ci[latexmath]
1555e5c31af7Sopenharmony_ci+++++++++++++++++++
1556e5c31af7Sopenharmony_ci\begin{aligned}
1557e5c31af7Sopenharmony_ci\partial{s}/\partial{x} & = dPdx(s), & \partial{s}/\partial{y} & = dPdy(s), & \text{for 1D, 2D, Cube, or 3D image} \\
1558e5c31af7Sopenharmony_ci\partial{t}/\partial{x} & = dPdx(t), & \partial{t}/\partial{y} & = dPdy(t), & \text{for 2D, Cube, or 3D image} \\
1559e5c31af7Sopenharmony_ci\partial{r}/\partial{x} & = dPdx(r), & \partial{r}/\partial{y} & = dPdy(r), & \text{for Cube or 3D image}
1560e5c31af7Sopenharmony_ci\end{aligned}
1561e5c31af7Sopenharmony_ci+++++++++++++++++++
1562e5c31af7Sopenharmony_ci
1563e5c31af7Sopenharmony_ciPartial derivatives not defined above for certain image dimensionalities are
1564e5c31af7Sopenharmony_ciset to zero.
1565e5c31af7Sopenharmony_ci
1566e5c31af7Sopenharmony_ciFor explicit LOD image instructions, if the optional: SPIR-V operand
1567e5c31af7Sopenharmony_cicode:Grad is provided, then the operand values are used for the derivatives.
1568e5c31af7Sopenharmony_ciThe number of components present in each derivative for a given image
1569e5c31af7Sopenharmony_cidimensionality matches the number of partial derivatives computed above.
1570e5c31af7Sopenharmony_ci
1571e5c31af7Sopenharmony_ciIf the optional: SPIR-V operand code:Lod is provided, then derivatives are
1572e5c31af7Sopenharmony_ciset to zero, the cube map derivative transformation is skipped, and the
1573e5c31af7Sopenharmony_ciscale factor operation is skipped.
1574e5c31af7Sopenharmony_ciInstead, the floating point scalar coordinate is directly assigned to
1575e5c31af7Sopenharmony_ci[eq]#{lambda}~base~# as described in <<textures-level-of-detail-operation,
1576e5c31af7Sopenharmony_ciLevel-of-Detail Operation>>.
1577e5c31af7Sopenharmony_ci
1578e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_2,VK_EXT_descriptor_indexing[]
1579e5c31af7Sopenharmony_ciIf the image or sampler object used by an implicit derivative image
1580e5c31af7Sopenharmony_ciinstruction is not uniform across the quad and
1581e5c31af7Sopenharmony_ci<<limits-quadDivergentImplicitLod,pname:quadDivergentImplicitLod>> is not
1582e5c31af7Sopenharmony_cisupported, then the derivative and LOD values are undefined:.
1583e5c31af7Sopenharmony_ciImplicit derivatives are well-defined when the image and sampler and control
1584e5c31af7Sopenharmony_ciflow are uniform across the quad, even if they diverge between different
1585e5c31af7Sopenharmony_ciquads.
1586e5c31af7Sopenharmony_ci
1587e5c31af7Sopenharmony_ciIf <<limits-quadDivergentImplicitLod,pname:quadDivergentImplicitLod>> is
1588e5c31af7Sopenharmony_cisupported, then derivatives and implicit LOD values are well-defined even if
1589e5c31af7Sopenharmony_cithe image or sampler object are not uniform within a quad.
1590e5c31af7Sopenharmony_ciThe derivatives are computed as specified above, and the implicit LOD
1591e5c31af7Sopenharmony_cicalculation proceeds for each shader invocation using its respective image
1592e5c31af7Sopenharmony_ciand sampler object.
1593e5c31af7Sopenharmony_ciendif::VK_VERSION_1_2,VK_EXT_descriptor_indexing[]
1594e5c31af7Sopenharmony_ci
1595e5c31af7Sopenharmony_ci
1596e5c31af7Sopenharmony_ci=== Cube Map Face Selection and Transformations
1597e5c31af7Sopenharmony_ci
1598e5c31af7Sopenharmony_ciFor cube map image instructions, the [eq]#(s,t,r)# coordinates are treated
1599e5c31af7Sopenharmony_cias a direction vector [eq]#(r~x~,r~y~,r~z~)#.
1600e5c31af7Sopenharmony_ciThe direction vector is used to select a cube map face.
1601e5c31af7Sopenharmony_ciThe direction vector is transformed to a per-face texel coordinate system
1602e5c31af7Sopenharmony_ci[eq]#(s~face~,t~face~)#, The direction vector is also used to transform the
1603e5c31af7Sopenharmony_ciderivatives to per-face derivatives.
1604e5c31af7Sopenharmony_ci
1605e5c31af7Sopenharmony_ci
1606e5c31af7Sopenharmony_ci=== Cube Map Face Selection
1607e5c31af7Sopenharmony_ci
1608e5c31af7Sopenharmony_ciThe direction vector selects one of the cube map's faces based on the
1609e5c31af7Sopenharmony_cilargest magnitude coordinate direction (the major axis direction).
1610e5c31af7Sopenharmony_ciSince two or more coordinates can: have identical magnitude, the
1611e5c31af7Sopenharmony_ciimplementation must: have rules to disambiguate this situation.
1612e5c31af7Sopenharmony_ci
1613e5c31af7Sopenharmony_ciThe rules should: have as the first rule that [eq]#r~z~# wins over
1614e5c31af7Sopenharmony_ci[eq]#r~y~# and [eq]#r~x~#, and the second rule that [eq]#r~y~# wins over
1615e5c31af7Sopenharmony_ci[eq]#r~x~#.
1616e5c31af7Sopenharmony_ciAn implementation may: choose other rules, but the rules must: be
1617e5c31af7Sopenharmony_cideterministic and depend only on [eq]#(r~x~,r~y~,r~z~)#.
1618e5c31af7Sopenharmony_ci
1619e5c31af7Sopenharmony_ciThe layer number (corresponding to a cube map face), the coordinate
1620e5c31af7Sopenharmony_ciselections for [eq]#s~c~#, [eq]#t~c~#, [eq]#r~c~#, and the selection of
1621e5c31af7Sopenharmony_ciderivatives, are determined by the major axis direction as specified in the
1622e5c31af7Sopenharmony_cifollowing two tables.
1623e5c31af7Sopenharmony_ci
1624e5c31af7Sopenharmony_ci.Cube map face and coordinate selection
1625e5c31af7Sopenharmony_ci[width="75%",frame="all",options="header"]
1626e5c31af7Sopenharmony_ci|====
1627e5c31af7Sopenharmony_ci| Major Axis Direction | Layer Number | Cube Map Face | [eq]#s~c~#  | [eq]#t~c~#  | [eq]#r~c~#
1628e5c31af7Sopenharmony_ci| [eq]#+r~x~#          | [eq]#0#      | Positive X    | [eq]#-r~z~# | [eq]#-r~y~# | [eq]#r~x~#
1629e5c31af7Sopenharmony_ci| [eq]#-r~x~#          | [eq]#1#      | Negative X    | [eq]#+r~z~# | [eq]#-r~y~# | [eq]#r~x~#
1630e5c31af7Sopenharmony_ci| [eq]#+r~y~#          | [eq]#2#      | Positive Y    | [eq]#+r~x~# | [eq]#+r~z~# | [eq]#r~y~#
1631e5c31af7Sopenharmony_ci| [eq]#-r~y~#          | [eq]#3#      | Negative Y    | [eq]#+r~x~# | [eq]#-r~z~# | [eq]#r~y~#
1632e5c31af7Sopenharmony_ci| [eq]#+r~z~#          | [eq]#4#      | Positive Z    | [eq]#+r~x~# | [eq]#-r~y~# | [eq]#r~z~#
1633e5c31af7Sopenharmony_ci| [eq]#-r~z~#          | [eq]#5#      | Negative Z    | [eq]#-r~x~# | [eq]#-r~y~# | [eq]#r~z~#
1634e5c31af7Sopenharmony_ci|====
1635e5c31af7Sopenharmony_ci
1636e5c31af7Sopenharmony_ci
1637e5c31af7Sopenharmony_ci.Cube map derivative selection
1638e5c31af7Sopenharmony_ci[width="75%",frame="all",options="header"]
1639e5c31af7Sopenharmony_ci|====
1640e5c31af7Sopenharmony_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#
1641e5c31af7Sopenharmony_ci
1642e5c31af7Sopenharmony_ci| [eq]#+r~x~#
1643e5c31af7Sopenharmony_ci| [eq]#-{partial}r~z~ / {partial}x# | [eq]#-{partial}r~z~ / {partial}y#
1644e5c31af7Sopenharmony_ci| [eq]#-{partial}r~y~ / {partial}x# | [eq]#-{partial}r~y~ / {partial}y#
1645e5c31af7Sopenharmony_ci| [eq]#+{partial}r~x~ / {partial}x# | [eq]#+{partial}r~x~ / {partial}y#
1646e5c31af7Sopenharmony_ci
1647e5c31af7Sopenharmony_ci| [eq]#-r~x~#
1648e5c31af7Sopenharmony_ci| [eq]#+{partial}r~z~ / {partial}x# | [eq]#+{partial}r~z~ / {partial}y#
1649e5c31af7Sopenharmony_ci| [eq]#-{partial}r~y~ / {partial}x# | [eq]#-{partial}r~y~ / {partial}y#
1650e5c31af7Sopenharmony_ci| [eq]#-{partial}r~x~ / {partial}x# | [eq]#-{partial}r~x~ / {partial}y#
1651e5c31af7Sopenharmony_ci
1652e5c31af7Sopenharmony_ci| [eq]#+r~y~#
1653e5c31af7Sopenharmony_ci| [eq]#+{partial}r~x~ / {partial}x# | [eq]#+{partial}r~x~ / {partial}y#
1654e5c31af7Sopenharmony_ci| [eq]#+{partial}r~z~ / {partial}x# | [eq]#+{partial}r~z~ / {partial}y#
1655e5c31af7Sopenharmony_ci| [eq]#+{partial}r~y~ / {partial}x# | [eq]#+{partial}r~y~ / {partial}y#
1656e5c31af7Sopenharmony_ci
1657e5c31af7Sopenharmony_ci| [eq]#-r~y~#
1658e5c31af7Sopenharmony_ci| [eq]#+{partial}r~x~ / {partial}x# | [eq]#+{partial}r~x~ / {partial}y#
1659e5c31af7Sopenharmony_ci| [eq]#-{partial}r~z~ / {partial}x# | [eq]#-{partial}r~z~ / {partial}y#
1660e5c31af7Sopenharmony_ci| [eq]#-{partial}r~y~ / {partial}x# | [eq]#-{partial}r~y~ / {partial}y#
1661e5c31af7Sopenharmony_ci
1662e5c31af7Sopenharmony_ci| [eq]#+r~z~#
1663e5c31af7Sopenharmony_ci| [eq]#+{partial}r~x~ / {partial}x# | [eq]#+{partial}r~x~ / {partial}y#
1664e5c31af7Sopenharmony_ci| [eq]#-{partial}r~y~ / {partial}x# | [eq]#-{partial}r~y~ / {partial}y#
1665e5c31af7Sopenharmony_ci| [eq]#+{partial}r~z~ / {partial}x# | [eq]#+{partial}r~z~ / {partial}y#
1666e5c31af7Sopenharmony_ci
1667e5c31af7Sopenharmony_ci| [eq]#-r~z~#
1668e5c31af7Sopenharmony_ci| [eq]#-{partial}r~x~ / {partial}x# | [eq]#-{partial}r~x~ / {partial}y#
1669e5c31af7Sopenharmony_ci| [eq]#-{partial}r~y~ / {partial}x# | [eq]#-{partial}r~y~ / {partial}y#
1670e5c31af7Sopenharmony_ci| [eq]#-{partial}r~z~ / {partial}x# | [eq]#-{partial}r~z~ / {partial}y#
1671e5c31af7Sopenharmony_ci|====
1672e5c31af7Sopenharmony_ci
1673e5c31af7Sopenharmony_ci
1674e5c31af7Sopenharmony_ci=== Cube Map Coordinate Transformation
1675e5c31af7Sopenharmony_ci
1676e5c31af7Sopenharmony_ci[latexmath]
1677e5c31af7Sopenharmony_ci++++++++++++++++++++++++
1678e5c31af7Sopenharmony_ci\begin{aligned}
1679e5c31af7Sopenharmony_cis_{\textit{face}} & =
1680e5c31af7Sopenharmony_ci    \frac{1}{2} \times \frac{s_c}{|r_c|} + \frac{1}{2} \\
1681e5c31af7Sopenharmony_cit_{\textit{face}} & =
1682e5c31af7Sopenharmony_ci    \frac{1}{2} \times \frac{t_c}{|r_c|} + \frac{1}{2} \\
1683e5c31af7Sopenharmony_ci\end{aligned}
1684e5c31af7Sopenharmony_ci++++++++++++++++++++++++
1685e5c31af7Sopenharmony_ci
1686e5c31af7Sopenharmony_ci
1687e5c31af7Sopenharmony_ci=== Cube Map Derivative Transformation
1688e5c31af7Sopenharmony_ci
1689e5c31af7Sopenharmony_ci[latexmath]
1690e5c31af7Sopenharmony_ci++++++++++++++++++++++++
1691e5c31af7Sopenharmony_ci\begin{aligned}
1692e5c31af7Sopenharmony_ci\frac{\partial{s_{\textit{face}}}}{\partial{x}} &=
1693e5c31af7Sopenharmony_ci    \frac{\partial}{\partial{x}} \left ( \frac{1}{2} \times \frac{s_{c}}{|r_{c}|}
1694e5c31af7Sopenharmony_ci    + \frac{1}{2}\right ) \\
1695e5c31af7Sopenharmony_ci\frac{\partial{s_{\textit{face}}}}{\partial{x}} &=
1696e5c31af7Sopenharmony_ci    \frac{1}{2} \times \frac{\partial}{\partial{x}}
1697e5c31af7Sopenharmony_ci    \left ( \frac{s_{c}}{|r_{c}|}  \right ) \\
1698e5c31af7Sopenharmony_ci\frac{\partial{s_{\textit{face}}}}{\partial{x}} &=
1699e5c31af7Sopenharmony_ci    \frac{1}{2} \times
1700e5c31af7Sopenharmony_ci    \left (
1701e5c31af7Sopenharmony_ci    \frac{
1702e5c31af7Sopenharmony_ci      |r_{c}| \times \partial{s_c}/\partial{x}
1703e5c31af7Sopenharmony_ci      -s_c \times {\partial{r_{c}}}/{\partial{x}}}
1704e5c31af7Sopenharmony_ci    {\left ( r_{c} \right )^2}
1705e5c31af7Sopenharmony_ci    \right )
1706e5c31af7Sopenharmony_ci\end{aligned}
1707e5c31af7Sopenharmony_ci++++++++++++++++++++++++
1708e5c31af7Sopenharmony_ci
1709e5c31af7Sopenharmony_ci[latexmath]
1710e5c31af7Sopenharmony_ci++++++++++++++++++++++++
1711e5c31af7Sopenharmony_ci\begin{aligned}
1712e5c31af7Sopenharmony_ci\frac{\partial{s_{\textit{face}}}}{\partial{y}} &=
1713e5c31af7Sopenharmony_ci    \frac{1}{2} \times
1714e5c31af7Sopenharmony_ci    \left (
1715e5c31af7Sopenharmony_ci    \frac{
1716e5c31af7Sopenharmony_ci      |r_{c}| \times \partial{s_c}/\partial{y}
1717e5c31af7Sopenharmony_ci      -s_c \times {\partial{r_{c}}}/{\partial{y}}}
1718e5c31af7Sopenharmony_ci    {\left ( r_{c} \right )^2}
1719e5c31af7Sopenharmony_ci    \right )\\
1720e5c31af7Sopenharmony_ci\frac{\partial{t_{\textit{face}}}}{\partial{x}} &=
1721e5c31af7Sopenharmony_ci    \frac{1}{2} \times
1722e5c31af7Sopenharmony_ci    \left (
1723e5c31af7Sopenharmony_ci    \frac{
1724e5c31af7Sopenharmony_ci      |r_{c}| \times \partial{t_c}/\partial{x}
1725e5c31af7Sopenharmony_ci      -t_c \times {\partial{r_{c}}}/{\partial{x}}}
1726e5c31af7Sopenharmony_ci    {\left ( r_{c} \right )^2}
1727e5c31af7Sopenharmony_ci    \right ) \\
1728e5c31af7Sopenharmony_ci\frac{\partial{t_{\textit{face}}}}{\partial{y}} &=
1729e5c31af7Sopenharmony_ci    \frac{1}{2} \times
1730e5c31af7Sopenharmony_ci    \left (
1731e5c31af7Sopenharmony_ci    \frac{
1732e5c31af7Sopenharmony_ci       |r_{c}| \times \partial{t_c}/\partial{y}
1733e5c31af7Sopenharmony_ci      -t_c \times {\partial{r_{c}}}/{\partial{y}}}
1734e5c31af7Sopenharmony_ci    {\left ( r_{c} \right )^2}
1735e5c31af7Sopenharmony_ci    \right )
1736e5c31af7Sopenharmony_ci\end{aligned}
1737e5c31af7Sopenharmony_ci++++++++++++++++++++++++
1738e5c31af7Sopenharmony_ci
1739e5c31af7Sopenharmony_ciifdef::editing-notes[]
1740e5c31af7Sopenharmony_ci[NOTE]
1741e5c31af7Sopenharmony_ci.editing-note
1742e5c31af7Sopenharmony_ci====
1743e5c31af7Sopenharmony_ci(Bill) Note that we never revisited ARB_texture_cubemap after we introduced
1744e5c31af7Sopenharmony_cidependent texture fetches (ARB_fragment_program and ARB_fragment_shader).
1745e5c31af7Sopenharmony_ci
1746e5c31af7Sopenharmony_ciThe derivatives of [eq]#s~face~# and [eq]#t~face~# are only valid for
1747e5c31af7Sopenharmony_cinon-dependent texture fetches (pre OpenGL 2.0).
1748e5c31af7Sopenharmony_ci====
1749e5c31af7Sopenharmony_ciendif::editing-notes[]
1750e5c31af7Sopenharmony_ci
1751e5c31af7Sopenharmony_ci
1752e5c31af7Sopenharmony_ci[[textures-lod-and-scale-factor]]
1753e5c31af7Sopenharmony_ci=== Scale Factor Operation, Level-of-Detail Operation and Image Level(s) Selection
1754e5c31af7Sopenharmony_ci
1755e5c31af7Sopenharmony_ciLOD selection can: be either explicit (provided explicitly by the image
1756e5c31af7Sopenharmony_ciinstruction) or implicit (determined from a scale factor calculated from the
1757e5c31af7Sopenharmony_ciderivatives).
1758e5c31af7Sopenharmony_ciThe LOD must: be computed with pname:mipmapPrecisionBits of accuracy.
1759e5c31af7Sopenharmony_ci
1760e5c31af7Sopenharmony_ci
1761e5c31af7Sopenharmony_ci[[textures-scale-factor]]
1762e5c31af7Sopenharmony_ci==== Scale Factor Operation
1763e5c31af7Sopenharmony_ci
1764e5c31af7Sopenharmony_ciThe magnitude of the derivatives are calculated by:
1765e5c31af7Sopenharmony_ci
1766e5c31af7Sopenharmony_ci  {empty}:: [eq]#m~ux~ = {vert}{partial}s/{partial}x{vert} {times} w~base~#
1767e5c31af7Sopenharmony_ci  {empty}:: [eq]#m~vx~ = {vert}{partial}t/{partial}x{vert} {times} h~base~#
1768e5c31af7Sopenharmony_ci  {empty}:: [eq]#m~wx~ = {vert}{partial}r/{partial}x{vert} {times} d~base~#
1769e5c31af7Sopenharmony_ci
1770e5c31af7Sopenharmony_ci  {empty}:: [eq]#m~uy~ = {vert}{partial}s/{partial}y{vert} {times} w~base~#
1771e5c31af7Sopenharmony_ci  {empty}:: [eq]#m~vy~ = {vert}{partial}t/{partial}y{vert} {times} h~base~#
1772e5c31af7Sopenharmony_ci  {empty}:: [eq]#m~wy~ = {vert}{partial}r/{partial}y{vert} {times} d~base~#
1773e5c31af7Sopenharmony_ci
1774e5c31af7Sopenharmony_ci
1775e5c31af7Sopenharmony_ciwhere:
1776e5c31af7Sopenharmony_ci
1777e5c31af7Sopenharmony_ci  {empty}:: [eq]#{partial}t/{partial}x = {partial}t/{partial}y = 0# (for 1D
1778e5c31af7Sopenharmony_ci            images)
1779e5c31af7Sopenharmony_ci  {empty}:: [eq]#{partial}r/{partial}x = {partial}r/{partial}y = 0# (for 1D,
1780e5c31af7Sopenharmony_ci            2D or Cube images)
1781e5c31af7Sopenharmony_ci
1782e5c31af7Sopenharmony_ciand:
1783e5c31af7Sopenharmony_ci
1784e5c31af7Sopenharmony_ci  {empty}:: [eq]#w~base~ = image.w#
1785e5c31af7Sopenharmony_ci  {empty}:: [eq]#h~base~ = image.h#
1786e5c31af7Sopenharmony_ci  {empty}:: [eq]#d~base~ = image.d#
1787e5c31af7Sopenharmony_ci
1788e5c31af7Sopenharmony_ci(for the pname:baseMipLevel, from the image descriptor).
1789e5c31af7Sopenharmony_ci
1790e5c31af7Sopenharmony_ciifdef::VK_NV_corner_sampled_image[]
1791e5c31af7Sopenharmony_ci
1792e5c31af7Sopenharmony_ciFor corner-sampled images, the [eq]#w~base~#, [eq]#h~base~#, and
1793e5c31af7Sopenharmony_ci[eq]#d~base~# are instead:
1794e5c31af7Sopenharmony_ci
1795e5c31af7Sopenharmony_ci  {empty}:: [eq]#w~base~ = image.w - 1#
1796e5c31af7Sopenharmony_ci  {empty}:: [eq]#h~base~ = image.h - 1#
1797e5c31af7Sopenharmony_ci  {empty}:: [eq]#d~base~ = image.d - 1#
1798e5c31af7Sopenharmony_ci
1799e5c31af7Sopenharmony_ciendif::VK_NV_corner_sampled_image[]
1800e5c31af7Sopenharmony_ci
1801e5c31af7Sopenharmony_ciA point sampled in screen space has an elliptical footprint in texture
1802e5c31af7Sopenharmony_cispace.
1803e5c31af7Sopenharmony_ciThe minimum and maximum scale factors [eq]#({rho}~min~, {rho}~max~)# should:
1804e5c31af7Sopenharmony_cibe the minor and major axes of this ellipse.
1805e5c31af7Sopenharmony_ci
1806e5c31af7Sopenharmony_ciThe _scale factors_ [eq]#{rho}~x~# and [eq]#{rho}~y~#, calculated from the
1807e5c31af7Sopenharmony_cimagnitude of the derivatives in x and y, are used to compute the minimum and
1808e5c31af7Sopenharmony_cimaximum scale factors.
1809e5c31af7Sopenharmony_ci
1810e5c31af7Sopenharmony_ci[eq]#{rho}~x~# and [eq]#{rho}~y~# may: be approximated with functions
1811e5c31af7Sopenharmony_ci[eq]#f~x~# and [eq]#f~y~#, subject to the following constraints:
1812e5c31af7Sopenharmony_ci
1813e5c31af7Sopenharmony_ci[latexmath]
1814e5c31af7Sopenharmony_ci++++++++++++++++++++++++
1815e5c31af7Sopenharmony_ci\begin{aligned}
1816e5c31af7Sopenharmony_ci& f_x \text{\ is\ continuous\ and\ monotonically\ increasing\ in\ each\ of\ }
1817e5c31af7Sopenharmony_ci    m_{ux},
1818e5c31af7Sopenharmony_ci    m_{vx}, \text{\ and\ }
1819e5c31af7Sopenharmony_ci    m_{wx} \\
1820e5c31af7Sopenharmony_ci& f_y \text{\ is\ continuous\ and\ monotonically\ increasing\ in\ each\ of\ }
1821e5c31af7Sopenharmony_ci    m_{uy},
1822e5c31af7Sopenharmony_ci    m_{vy}, \text{\ and\ }
1823e5c31af7Sopenharmony_ci    m_{wy}
1824e5c31af7Sopenharmony_ci\end{aligned}
1825e5c31af7Sopenharmony_ci++++++++++++++++++++++++
1826e5c31af7Sopenharmony_ci
1827e5c31af7Sopenharmony_ci[latexmath]
1828e5c31af7Sopenharmony_ci++++++++++++++++++++++++
1829e5c31af7Sopenharmony_ci\begin{aligned}
1830e5c31af7Sopenharmony_ci\max(|m_{ux}|, |m_{vx}|, |m_{wx}|) \leq f_{x}
1831e5c31af7Sopenharmony_ci\leq \sqrt{2} (|m_{ux}| + |m_{vx}| + |m_{wx}|) \\
1832e5c31af7Sopenharmony_ci\max(|m_{uy}|, |m_{vy}|, |m_{wy}|) \leq f_{y}
1833e5c31af7Sopenharmony_ci\leq \sqrt{2} (|m_{uy}| + |m_{vy}| + |m_{wy}|)
1834e5c31af7Sopenharmony_ci\end{aligned}
1835e5c31af7Sopenharmony_ci++++++++++++++++++++++++
1836e5c31af7Sopenharmony_ci
1837e5c31af7Sopenharmony_ci
1838e5c31af7Sopenharmony_ciifdef::editing-notes[]
1839e5c31af7Sopenharmony_ci[NOTE]
1840e5c31af7Sopenharmony_ci.editing-note
1841e5c31af7Sopenharmony_ci====
1842e5c31af7Sopenharmony_ci(Bill) For reviewers only - anticipating questions.
1843e5c31af7Sopenharmony_ci
1844e5c31af7Sopenharmony_ciWe only support implicit derivatives for normalized texel coordinates.
1845e5c31af7Sopenharmony_ci
1846e5c31af7Sopenharmony_ciSo we are documenting the derivatives in s,t,r (normalized texel
1847e5c31af7Sopenharmony_cicoordinates) rather than u,v,w (unnormalized texel coordinates) as in OpenGL
1848e5c31af7Sopenharmony_ciand OpenGL ES specifications.
1849e5c31af7Sopenharmony_ci(I know, u,v,w is the way it has been documented since OpenGL V1.0.)
1850e5c31af7Sopenharmony_ci
1851e5c31af7Sopenharmony_ciAlso there is no reason to have conditional application of [eq]#w~base~,
1852e5c31af7Sopenharmony_cih~base~, d~base~# for rectangle textures either, since they do not support
1853e5c31af7Sopenharmony_ciimplicit derivatives.
1854e5c31af7Sopenharmony_ci====
1855e5c31af7Sopenharmony_ciendif::editing-notes[]
1856e5c31af7Sopenharmony_ci
1857e5c31af7Sopenharmony_ci
1858e5c31af7Sopenharmony_ciThe minimum and maximum scale factors [eq]#({rho}~min~,{rho}~max~)# are
1859e5c31af7Sopenharmony_cidetermined by:
1860e5c31af7Sopenharmony_ci
1861e5c31af7Sopenharmony_ci  {empty}:: [eq]#{rho}~max~ = max({rho}~x~, {rho}~y~)#
1862e5c31af7Sopenharmony_ci  {empty}:: [eq]#{rho}~min~ = min({rho}~x~, {rho}~y~)#
1863e5c31af7Sopenharmony_ci
1864e5c31af7Sopenharmony_ciThe ratio of anisotropy is determined by:
1865e5c31af7Sopenharmony_ci
1866e5c31af7Sopenharmony_ci  {empty}:: [eq]#{eta} = min({rho}~max~/{rho}~min~, max~Aniso~)#
1867e5c31af7Sopenharmony_ci
1868e5c31af7Sopenharmony_ciwhere:
1869e5c31af7Sopenharmony_ci
1870e5c31af7Sopenharmony_ci  {empty}:: [eq]#sampler.max~Aniso~ = pname:maxAnisotropy# (from sampler
1871e5c31af7Sopenharmony_ci            descriptor)
1872e5c31af7Sopenharmony_ci  {empty}:: [eq]#limits.max~Aniso~ = pname:maxSamplerAnisotropy# (from
1873e5c31af7Sopenharmony_ci            physical device limits)
1874e5c31af7Sopenharmony_ci  {empty}:: [eq]#max~Aniso~ = min(sampler.max~Aniso~, limits.max~Aniso~)#
1875e5c31af7Sopenharmony_ci
1876e5c31af7Sopenharmony_ciIf [eq]#{rho}~max~ = {rho}~min~ = 0#, then all the partial derivatives are
1877e5c31af7Sopenharmony_cizero, the fragment's footprint in texel space is a point, and [eq]#{eta}#
1878e5c31af7Sopenharmony_cishould: be treated as 1.
1879e5c31af7Sopenharmony_ciIf [eq]#{rho}~max~ {neq} 0# and [eq]#{rho}~min~ = 0# then all partial
1880e5c31af7Sopenharmony_ciderivatives along one axis are zero, the fragment's footprint in texel space
1881e5c31af7Sopenharmony_ciis a line segment, and [eq]#{eta}# should: be treated as [eq]#max~Aniso~#.
1882e5c31af7Sopenharmony_ciHowever, anytime the footprint is small in texel space the implementation
1883e5c31af7Sopenharmony_cimay: use a smaller value of [eq]#{eta}#, even when [eq]#{rho}~min~# is zero
1884e5c31af7Sopenharmony_cior close to zero.
1885e5c31af7Sopenharmony_ciIf either slink:VkPhysicalDeviceFeatures::pname:samplerAnisotropy or
1886e5c31af7Sopenharmony_cislink:VkSamplerCreateInfo::pname:anisotropyEnable are ename:VK_FALSE,
1887e5c31af7Sopenharmony_ci[eq]#max~Aniso~# is set to 1.
1888e5c31af7Sopenharmony_ci
1889e5c31af7Sopenharmony_ciIf [eq]#{eta} = 1#, sampling is isotropic.
1890e5c31af7Sopenharmony_ciIf [eq]#{eta} > 1#, sampling is anisotropic.
1891e5c31af7Sopenharmony_ci
1892e5c31af7Sopenharmony_ciThe sampling rate ([eq]#N#) is derived as:
1893e5c31af7Sopenharmony_ci
1894e5c31af7Sopenharmony_ci  {empty}:: [eq]#N = {lceil}{eta}{rceil}#
1895e5c31af7Sopenharmony_ci
1896e5c31af7Sopenharmony_ciAn implementation may: round [eq]#N# up to the nearest supported sampling
1897e5c31af7Sopenharmony_cirate.
1898e5c31af7Sopenharmony_ciAn implementation may: use the value of [eq]#N# as an approximation of
1899e5c31af7Sopenharmony_ci[eq]#{eta}#.
1900e5c31af7Sopenharmony_ci
1901e5c31af7Sopenharmony_ci
1902e5c31af7Sopenharmony_ci[[textures-level-of-detail-operation]]
1903e5c31af7Sopenharmony_ci==== Level-of-Detail Operation
1904e5c31af7Sopenharmony_ci
1905e5c31af7Sopenharmony_ciThe LOD parameter [eq]#{lambda}# is computed as follows:
1906e5c31af7Sopenharmony_ci
1907e5c31af7Sopenharmony_ci[latexmath]
1908e5c31af7Sopenharmony_ci++++++++++++++++++++++++
1909e5c31af7Sopenharmony_ci\begin{aligned}
1910e5c31af7Sopenharmony_ci\lambda_{base}(x,y) & =
1911e5c31af7Sopenharmony_ci  \begin{cases}
1912e5c31af7Sopenharmony_ci    shaderOp.Lod                                    & \text{(from optional SPIR-V operand)} \\
1913e5c31af7Sopenharmony_ci    \log_2 \left ( \frac{\rho_{max}}{\eta} \right ) & \text{otherwise}
1914e5c31af7Sopenharmony_ci  \end{cases} \\
1915e5c31af7Sopenharmony_ci\lambda'(x,y)       & = \lambda_{base} + \mathbin{clamp}(sampler.bias + shaderOp.bias,-maxSamplerLodBias,maxSamplerLodBias) \\
1916e5c31af7Sopenharmony_ci\lambda             & =
1917e5c31af7Sopenharmony_ci  \begin{cases}
1918e5c31af7Sopenharmony_ci    lod_{max}, & \lambda' > lod_{max} \\
1919e5c31af7Sopenharmony_ci    \lambda',  & lod_{min} \leq \lambda' \leq lod_{max} \\
1920e5c31af7Sopenharmony_ci    lod_{min}, & \lambda' < lod_{min} \\
1921e5c31af7Sopenharmony_ci    \textit{undefined}, & lod_{min} > lod_{max}
1922e5c31af7Sopenharmony_ci  \end{cases}
1923e5c31af7Sopenharmony_ci\end{aligned}
1924e5c31af7Sopenharmony_ci++++++++++++++++++++++++
1925e5c31af7Sopenharmony_ci
1926e5c31af7Sopenharmony_ciwhere:
1927e5c31af7Sopenharmony_ci
1928e5c31af7Sopenharmony_ci[latexmath]
1929e5c31af7Sopenharmony_ci++++++++++++++++++++++++
1930e5c31af7Sopenharmony_ci\begin{aligned}
1931e5c31af7Sopenharmony_cisampler.bias       & = mipLodBias & \text{(from sampler descriptor)} \\
1932e5c31af7Sopenharmony_cishaderOp.bias      & =
1933e5c31af7Sopenharmony_ci  \begin{cases}
1934e5c31af7Sopenharmony_ci    Bias & \text{(from optional SPIR-V operand)} \\
1935e5c31af7Sopenharmony_ci    0    & \text{otherwise}
1936e5c31af7Sopenharmony_ci  \end{cases} \\
1937e5c31af7Sopenharmony_cisampler.lod_{min}  & = minLod & \text{(from sampler descriptor)} \\
1938e5c31af7Sopenharmony_cishaderOp.lod_{min} & =
1939e5c31af7Sopenharmony_ci  \begin{cases}
1940e5c31af7Sopenharmony_ci    MinLod & \text{(from optional SPIR-V operand)} \\
1941e5c31af7Sopenharmony_ci    0      & \text{otherwise}
1942e5c31af7Sopenharmony_ci  \end{cases} \\
1943e5c31af7Sopenharmony_ci\\
1944e5c31af7Sopenharmony_cilod_{min}          & = \max(sampler.lod_{min}, shaderOp.lod_{min}) \\
1945e5c31af7Sopenharmony_cilod_{max}          & = maxLod & \text{(from sampler descriptor)}
1946e5c31af7Sopenharmony_ci\end{aligned}
1947e5c31af7Sopenharmony_ci++++++++++++++++++++++++
1948e5c31af7Sopenharmony_ci
1949e5c31af7Sopenharmony_ciand [eq]#maxSamplerLodBias# is the value of the slink:VkPhysicalDeviceLimits
1950e5c31af7Sopenharmony_cifeature <<limits-maxSamplerLodBias,pname:maxSamplerLodBias>>.
1951e5c31af7Sopenharmony_ci
1952e5c31af7Sopenharmony_ci
1953e5c31af7Sopenharmony_ci[[textures-image-level-selection]]
1954e5c31af7Sopenharmony_ci==== Image Level(s) Selection
1955e5c31af7Sopenharmony_ci
1956e5c31af7Sopenharmony_ciThe image level(s) [eq]#d#, [eq]#d~hi~#, and [eq]#d~lo~# which texels are
1957e5c31af7Sopenharmony_ciread from are determined by an image-level parameter [eq]#d~l~#, which is
1958e5c31af7Sopenharmony_cicomputed based on the LOD parameter, as follows:
1959e5c31af7Sopenharmony_ci
1960e5c31af7Sopenharmony_ci[latexmath]
1961e5c31af7Sopenharmony_ci++++++++++++++++++++++++
1962e5c31af7Sopenharmony_ci\begin{aligned}
1963e5c31af7Sopenharmony_cid_{l} =
1964e5c31af7Sopenharmony_ci  \begin{cases}
1965e5c31af7Sopenharmony_ci    nearest(d'),  & \text{mipmapMode is VK\_SAMPLER\_MIPMAP\_MODE\_NEAREST} \\
1966e5c31af7Sopenharmony_ci    d',           & \text{otherwise}
1967e5c31af7Sopenharmony_ci  \end{cases}
1968e5c31af7Sopenharmony_ci\end{aligned}
1969e5c31af7Sopenharmony_ci++++++++++++++++++++++++
1970e5c31af7Sopenharmony_ci
1971e5c31af7Sopenharmony_ciwhere:
1972e5c31af7Sopenharmony_ci
1973e5c31af7Sopenharmony_ci[latexmath]
1974e5c31af7Sopenharmony_ci++++++++++++++++++++++++
1975e5c31af7Sopenharmony_ci\begin{aligned}
1976e5c31af7Sopenharmony_ciifdef::VK_EXT_image_view_min_lod[]
1977e5c31af7Sopenharmony_cid' = max(level_{base} + \text{clamp}(\lambda, 0, q), minLod_{imageView})
1978e5c31af7Sopenharmony_ciendif::VK_EXT_image_view_min_lod[]
1979e5c31af7Sopenharmony_ciifndef::VK_EXT_image_view_min_lod[]
1980e5c31af7Sopenharmony_cid' = level_{base} + \text{clamp}(\lambda, 0, q)
1981e5c31af7Sopenharmony_ciendif::VK_EXT_image_view_min_lod[]
1982e5c31af7Sopenharmony_ci
1983e5c31af7Sopenharmony_ci\end{aligned}
1984e5c31af7Sopenharmony_ci++++++++++++++++++++++++
1985e5c31af7Sopenharmony_ci
1986e5c31af7Sopenharmony_ci[latexmath]
1987e5c31af7Sopenharmony_ci++++++++++++++++++++++++
1988e5c31af7Sopenharmony_ci\begin{aligned}
1989e5c31af7Sopenharmony_cinearest(d') & =
1990e5c31af7Sopenharmony_ci  \begin{cases}
1991e5c31af7Sopenharmony_ci    \left \lceil d' + 0.5\right \rceil - 1, &
1992e5c31af7Sopenharmony_ci        \text{preferred} \\
1993e5c31af7Sopenharmony_ci    \left \lfloor d' + 0.5\right \rfloor,   &
1994e5c31af7Sopenharmony_ci        \text{alternative}
1995e5c31af7Sopenharmony_ci  \end{cases}
1996e5c31af7Sopenharmony_ci\end{aligned}
1997e5c31af7Sopenharmony_ci++++++++++++++++++++++++
1998e5c31af7Sopenharmony_ci
1999e5c31af7Sopenharmony_ciand:
2000e5c31af7Sopenharmony_ci
2001e5c31af7Sopenharmony_ciifdef::VK_EXT_image_view_min_lod[]
2002e5c31af7Sopenharmony_ci  {empty}:: [eq]#minLod~imageView~ = pname:minLod#
2003e5c31af7Sopenharmony_ciendif::VK_EXT_image_view_min_lod[]
2004e5c31af7Sopenharmony_ci  {empty}:: [eq]#level~base~ = pname:baseMipLevel#
2005e5c31af7Sopenharmony_ci  {empty}:: [eq]#q = pname:levelCount - 1#
2006e5c31af7Sopenharmony_ci
2007e5c31af7Sopenharmony_cipname:baseMipLevel and pname:levelCount are taken from the
2008e5c31af7Sopenharmony_cipname:subresourceRange of the image view.
2009e5c31af7Sopenharmony_ci
2010e5c31af7Sopenharmony_ciifdef::VK_EXT_image_view_min_lod[]
2011e5c31af7Sopenharmony_cipname:minLod is taken from the
2012e5c31af7Sopenharmony_cislink:VkImageViewMinLodCreateInfoEXT::pname:minLod of the image view if
2013e5c31af7Sopenharmony_cipresent and the selection is part of the result of a sampling operation,
2014e5c31af7Sopenharmony_ciotherwise it is `0.0`.
2015e5c31af7Sopenharmony_cipname:minLod must: be less or equal to [eq]#level~base~ + q#.
2016e5c31af7Sopenharmony_ciendif::VK_EXT_image_view_min_lod[]
2017e5c31af7Sopenharmony_ci
2018e5c31af7Sopenharmony_ciIf the sampler's pname:mipmapMode is ename:VK_SAMPLER_MIPMAP_MODE_NEAREST,
2019e5c31af7Sopenharmony_cithen the level selected is [eq]#d = d~l~#.
2020e5c31af7Sopenharmony_ci
2021e5c31af7Sopenharmony_ciIf the sampler's pname:mipmapMode is ename:VK_SAMPLER_MIPMAP_MODE_LINEAR,
2022e5c31af7Sopenharmony_citwo neighboring levels are selected:
2023e5c31af7Sopenharmony_ci
2024e5c31af7Sopenharmony_ci[latexmath]
2025e5c31af7Sopenharmony_ci++++++++++++++++++++++++
2026e5c31af7Sopenharmony_ci\begin{aligned}
2027e5c31af7Sopenharmony_cid_{hi} & = \left\lfloor d_{l} \right\rfloor \\
2028e5c31af7Sopenharmony_cid_{lo} & = min( d_{hi} + 1, q ) \\
2029e5c31af7Sopenharmony_ci\delta & = d_{l} - d_{hi}
2030e5c31af7Sopenharmony_ci\end{aligned}
2031e5c31af7Sopenharmony_ci++++++++++++++++++++++++
2032e5c31af7Sopenharmony_ci
2033e5c31af7Sopenharmony_ci[eq]#{delta}# is the fractional value, quantized to the number of
2034e5c31af7Sopenharmony_ci<<limits-mipmapPrecisionBits,mipmap precision bits>>, used for
2035e5c31af7Sopenharmony_ci<<textures-texel-filtering, linear filtering>> between levels.
2036e5c31af7Sopenharmony_ci
2037e5c31af7Sopenharmony_ci[[textures-normalized-to-unnormalized]]
2038e5c31af7Sopenharmony_ci=== (s,t,r,q,a) to (u,v,w,a) Transformation
2039e5c31af7Sopenharmony_ci
2040e5c31af7Sopenharmony_ciThe normalized texel coordinates are scaled by the image level dimensions
2041e5c31af7Sopenharmony_ciand the array layer is selected.
2042e5c31af7Sopenharmony_ci
2043e5c31af7Sopenharmony_ciThis transformation is performed once for each level used in
2044e5c31af7Sopenharmony_ci<<textures-texel-filtering,filtering>> (either [eq]#d#, or [eq]#d~hi~# and
2045e5c31af7Sopenharmony_ci[eq]#d~lo~#).
2046e5c31af7Sopenharmony_ci
2047e5c31af7Sopenharmony_ci[latexmath]
2048e5c31af7Sopenharmony_ci++++++++++++++++++++++++
2049e5c31af7Sopenharmony_ci\begin{aligned}
2050e5c31af7Sopenharmony_ciu(x,y) & = s(x,y) \times width_{scale} + \Delta_i\\
2051e5c31af7Sopenharmony_civ(x,y) & =
2052e5c31af7Sopenharmony_ci  \begin{cases}
2053e5c31af7Sopenharmony_ci    0                         & \text{for 1D images} \\
2054e5c31af7Sopenharmony_ci    t(x,y) \times height_{scale} + \Delta_j & \text{otherwise}
2055e5c31af7Sopenharmony_ci  \end{cases} \\
2056e5c31af7Sopenharmony_ciw(x,y) & =
2057e5c31af7Sopenharmony_ci  \begin{cases}
2058e5c31af7Sopenharmony_ci    0                         & \text{for 2D or Cube images} \\
2059e5c31af7Sopenharmony_ci    r(x,y) \times depth_{scale}  + \Delta_k & \text{otherwise}
2060e5c31af7Sopenharmony_ci  \end{cases} \\
2061e5c31af7Sopenharmony_ci\\
2062e5c31af7Sopenharmony_cia(x,y) & =
2063e5c31af7Sopenharmony_ci  \begin{cases}
2064e5c31af7Sopenharmony_ci    a(x,y)                    & \text{for array images} \\
2065e5c31af7Sopenharmony_ci    0                         & \text{otherwise}
2066e5c31af7Sopenharmony_ci  \end{cases}
2067e5c31af7Sopenharmony_ci\end{aligned}
2068e5c31af7Sopenharmony_ci++++++++++++++++++++++++
2069e5c31af7Sopenharmony_ci
2070e5c31af7Sopenharmony_ciwhere:
2071e5c31af7Sopenharmony_ci
2072e5c31af7Sopenharmony_ci  {empty}:: [eq]#width~scale~ = width~level~#
2073e5c31af7Sopenharmony_ci  {empty}:: [eq]#height~scale~ = height~level~#
2074e5c31af7Sopenharmony_ci  {empty}:: [eq]#depth~scale~ = depth~level~#
2075e5c31af7Sopenharmony_ci
2076e5c31af7Sopenharmony_ciifdef::VK_NV_corner_sampled_image[]
2077e5c31af7Sopenharmony_cifor conventional images, and:
2078e5c31af7Sopenharmony_ci
2079e5c31af7Sopenharmony_ci  {empty}:: [eq]#width~scale~ = width~level~ - 1#
2080e5c31af7Sopenharmony_ci  {empty}:: [eq]#height~scale~ = height~level~ - 1#
2081e5c31af7Sopenharmony_ci  {empty}:: [eq]#depth~scale~ = depth~level~ - 1#
2082e5c31af7Sopenharmony_ci
2083e5c31af7Sopenharmony_cifor corner-sampled images.
2084e5c31af7Sopenharmony_ciendif::VK_NV_corner_sampled_image[]
2085e5c31af7Sopenharmony_ci
2086e5c31af7Sopenharmony_ciand where [eq]#({DeltaUpper}~i~, {DeltaUpper}~j~, {DeltaUpper}~k~)# are
2087e5c31af7Sopenharmony_citaken from the image instruction if it includes a code:ConstOffset or
2088e5c31af7Sopenharmony_cicode:Offset operand, otherwise they are taken to be zero.
2089e5c31af7Sopenharmony_ci
2090e5c31af7Sopenharmony_ci
2091e5c31af7Sopenharmony_ciOperations then proceed to Unnormalized Texel Coordinate Operations.
2092e5c31af7Sopenharmony_ci
2093e5c31af7Sopenharmony_ci
2094e5c31af7Sopenharmony_ci== Unnormalized Texel Coordinate Operations
2095e5c31af7Sopenharmony_ci
2096e5c31af7Sopenharmony_ci
2097e5c31af7Sopenharmony_ci[[textures-unnormalized-to-integer]]
2098e5c31af7Sopenharmony_ci=== (u,v,w,a) to (i,j,k,l,n) Transformation And Array Layer Selection
2099e5c31af7Sopenharmony_ci
2100e5c31af7Sopenharmony_ciThe unnormalized texel coordinates are transformed to integer texel
2101e5c31af7Sopenharmony_cicoordinates relative to the selected mipmap level.
2102e5c31af7Sopenharmony_ci
2103e5c31af7Sopenharmony_ciThe layer index [eq]#l# is computed as:
2104e5c31af7Sopenharmony_ci
2105e5c31af7Sopenharmony_ci  {empty}:: [eq]#l = clamp(RNE(a), 0, pname:layerCount - 1) {plus}
2106e5c31af7Sopenharmony_ci            pname:baseArrayLayer#
2107e5c31af7Sopenharmony_ci
2108e5c31af7Sopenharmony_ciwhere pname:layerCount is the number of layers in the image subresource
2109e5c31af7Sopenharmony_cirange of the image view, pname:baseArrayLayer is the first layer from the
2110e5c31af7Sopenharmony_cisubresource range, and where:
2111e5c31af7Sopenharmony_ci
2112e5c31af7Sopenharmony_ci[latexmath]
2113e5c31af7Sopenharmony_ci++++++++++++++++++++++++
2114e5c31af7Sopenharmony_ci\begin{aligned}
2115e5c31af7Sopenharmony_ci\mathbin{RNE}(a) & =
2116e5c31af7Sopenharmony_ci  \begin{cases}
2117e5c31af7Sopenharmony_ci    \mathbin{roundTiesToEven}(a)                  & \text{preferred, from IEEE Std 754-2008 Floating-Point Arithmetic} \\
2118e5c31af7Sopenharmony_ci    \left \lfloor a + 0.5 \right \rfloor & \text{alternative}
2119e5c31af7Sopenharmony_ci  \end{cases}
2120e5c31af7Sopenharmony_ci\end{aligned}
2121e5c31af7Sopenharmony_ci++++++++++++++++++++++++
2122e5c31af7Sopenharmony_ci
2123e5c31af7Sopenharmony_ciThe sample index [eq]#n# is assigned the value 0.
2124e5c31af7Sopenharmony_ci
2125e5c31af7Sopenharmony_ciNearest filtering (ename:VK_FILTER_NEAREST) computes the integer texel
2126e5c31af7Sopenharmony_cicoordinates that the unnormalized coordinates lie within:
2127e5c31af7Sopenharmony_ci
2128e5c31af7Sopenharmony_ci[latexmath]
2129e5c31af7Sopenharmony_ci++++++++++++++++++++++++
2130e5c31af7Sopenharmony_ci\begin{aligned}
2131e5c31af7Sopenharmony_cii &= \left\lfloor u + shift \right\rfloor \\
2132e5c31af7Sopenharmony_cij &= \left\lfloor v + shift \right\rfloor \\
2133e5c31af7Sopenharmony_cik &= \left\lfloor w + shift \right\rfloor
2134e5c31af7Sopenharmony_ci\end{aligned}
2135e5c31af7Sopenharmony_ci++++++++++++++++++++++++
2136e5c31af7Sopenharmony_ciwhere:
2137e5c31af7Sopenharmony_ci
2138e5c31af7Sopenharmony_ci  {empty}:: [eq]#shift = 0.0#
2139e5c31af7Sopenharmony_ci
2140e5c31af7Sopenharmony_ciifdef::VK_NV_corner_sampled_image[]
2141e5c31af7Sopenharmony_cifor conventional images, and:
2142e5c31af7Sopenharmony_ci
2143e5c31af7Sopenharmony_ci  {empty}:: [eq]#shift = 0.5#
2144e5c31af7Sopenharmony_ci
2145e5c31af7Sopenharmony_cifor corner-sampled images.
2146e5c31af7Sopenharmony_ciendif::VK_NV_corner_sampled_image[]
2147e5c31af7Sopenharmony_ci
2148e5c31af7Sopenharmony_ciLinear filtering (ename:VK_FILTER_LINEAR) computes a set of neighboring
2149e5c31af7Sopenharmony_cicoordinates which bound the unnormalized coordinates.
2150e5c31af7Sopenharmony_ciThe integer texel coordinates are combinations of [eq]#i~0~# or [eq]#i~1~#,
2151e5c31af7Sopenharmony_ci[eq]#j~0~# or [eq]#j~1~#, [eq]#k~0~# or [eq]#k~1~#, as well as weights
2152e5c31af7Sopenharmony_ci[eq]#{alpha}, {beta}#, and [eq]#{gamma}#.
2153e5c31af7Sopenharmony_ci
2154e5c31af7Sopenharmony_ci[latexmath]
2155e5c31af7Sopenharmony_ci++++++++++++++++++++++++
2156e5c31af7Sopenharmony_ci\begin{aligned}
2157e5c31af7Sopenharmony_cii_0 &= \left\lfloor u - shift \right\rfloor \\
2158e5c31af7Sopenharmony_cii_1 &= i_0 + 1 \\
2159e5c31af7Sopenharmony_cij_0 &= \left\lfloor v - shift \right\rfloor \\
2160e5c31af7Sopenharmony_cij_1 &= j_0 + 1 \\
2161e5c31af7Sopenharmony_cik_0 &= \left\lfloor w - shift \right\rfloor \\
2162e5c31af7Sopenharmony_cik_1 &= k_0 + 1
2163e5c31af7Sopenharmony_ci\end{aligned}
2164e5c31af7Sopenharmony_ci++++++++++++++++++++++++
2165e5c31af7Sopenharmony_ci
2166e5c31af7Sopenharmony_ci[latexmath]
2167e5c31af7Sopenharmony_ci++++++++++++++++++++++++
2168e5c31af7Sopenharmony_ci\begin{aligned}
2169e5c31af7Sopenharmony_ci\alpha &= \mathbin{frac}\left(u - shift\right)  \\[1em]
2170e5c31af7Sopenharmony_ci\beta &= \mathbin{frac}\left(v - shift\right)  \\[1em]
2171e5c31af7Sopenharmony_ci\gamma &= \mathbin{frac}\left(w - shift\right)
2172e5c31af7Sopenharmony_ci\end{aligned}
2173e5c31af7Sopenharmony_ci++++++++++++++++++++++++
2174e5c31af7Sopenharmony_ci
2175e5c31af7Sopenharmony_ciwhere:
2176e5c31af7Sopenharmony_ci
2177e5c31af7Sopenharmony_ci  {empty}:: [eq]#shift = 0.5#
2178e5c31af7Sopenharmony_ci
2179e5c31af7Sopenharmony_ciifdef::VK_NV_corner_sampled_image[]
2180e5c31af7Sopenharmony_cifor conventional images, and:
2181e5c31af7Sopenharmony_ci
2182e5c31af7Sopenharmony_ci  {empty}:: [eq]#shift = 0.0#
2183e5c31af7Sopenharmony_ci
2184e5c31af7Sopenharmony_cifor corner-sampled images,
2185e5c31af7Sopenharmony_ciendif::VK_NV_corner_sampled_image[]
2186e5c31af7Sopenharmony_ciand where:
2187e5c31af7Sopenharmony_ci
2188e5c31af7Sopenharmony_ci[latexmath]
2189e5c31af7Sopenharmony_ci++++++++++++++++++++++++
2190e5c31af7Sopenharmony_ci\mathbin{frac}(x) = x -  \left\lfloor x \right\rfloor
2191e5c31af7Sopenharmony_ci++++++++++++++++++++++++
2192e5c31af7Sopenharmony_ciwhere the number of fraction bits retained is specified by
2193e5c31af7Sopenharmony_cisname:VkPhysicalDeviceLimits::pname:subTexelPrecisionBits.
2194e5c31af7Sopenharmony_ci
2195e5c31af7Sopenharmony_ciifdef::VK_IMG_filter_cubic,VK_EXT_filter_cubic[]
2196e5c31af7Sopenharmony_ciCubic filtering (ename:VK_FILTER_CUBIC_EXT) computes a set of neighboring
2197e5c31af7Sopenharmony_cicoordinates which bound the unnormalized coordinates.
2198e5c31af7Sopenharmony_ciThe integer texel coordinates are combinations of [eq]#i~0~#, [eq]#i~1~#,
2199e5c31af7Sopenharmony_ci[eq]#i~2~# or [eq]#i~3~#, [eq]#j~0~#, [eq]#j~1~#, [eq]#j~2~# or [eq]#j~3~#,
2200e5c31af7Sopenharmony_ciifndef::VK_EXT_filter_cubic[]
2201e5c31af7Sopenharmony_cias well as weights [eq]#{alpha}# and [eq]#{beta}#.
2202e5c31af7Sopenharmony_ciendif::VK_EXT_filter_cubic[]
2203e5c31af7Sopenharmony_ciifdef::VK_EXT_filter_cubic[]
2204e5c31af7Sopenharmony_ci[eq]#k~0~#, [eq]#k~1~#, [eq]#k~2~# or [eq]#k~3~#, as well as weights
2205e5c31af7Sopenharmony_ci[eq]#{alpha}#, [eq]#{beta}#, and [eq]#{gamma}#.
2206e5c31af7Sopenharmony_ciendif::VK_EXT_filter_cubic[]
2207e5c31af7Sopenharmony_ci
2208e5c31af7Sopenharmony_ciifndef::VK_EXT_filter_cubic[]
2209e5c31af7Sopenharmony_ci[latexmath]
2210e5c31af7Sopenharmony_ci++++++++++++++++++++++++
2211e5c31af7Sopenharmony_ci\begin{aligned}
2212e5c31af7Sopenharmony_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]
2213e5c31af7Sopenharmony_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
2214e5c31af7Sopenharmony_ci\end{aligned}
2215e5c31af7Sopenharmony_ci++++++++++++++++++++++++
2216e5c31af7Sopenharmony_ci
2217e5c31af7Sopenharmony_ci[latexmath]
2218e5c31af7Sopenharmony_ci++++++++++++++++++++++++
2219e5c31af7Sopenharmony_ci\begin{aligned}
2220e5c31af7Sopenharmony_cialpha &= \mathbin{frac}\left(u - \frac{1}{2}\right)  \\[1em]
2221e5c31af7Sopenharmony_ci\beta &= \mathbin{frac}\left(v - \frac{1}{2}\right)
2222e5c31af7Sopenharmony_ci\end{aligned}
2223e5c31af7Sopenharmony_ci++++++++++++++++++++++++
2224e5c31af7Sopenharmony_ci
2225e5c31af7Sopenharmony_ciendif::VK_EXT_filter_cubic[]
2226e5c31af7Sopenharmony_ci
2227e5c31af7Sopenharmony_ciifdef::VK_EXT_filter_cubic[]
2228e5c31af7Sopenharmony_ci[latexmath]
2229e5c31af7Sopenharmony_ci++++++++++++++++++++++++
2230e5c31af7Sopenharmony_ci\begin{aligned}
2231e5c31af7Sopenharmony_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]
2232e5c31af7Sopenharmony_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]
2233e5c31af7Sopenharmony_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
2234e5c31af7Sopenharmony_ci\end{aligned}
2235e5c31af7Sopenharmony_ci++++++++++++++++++++++++
2236e5c31af7Sopenharmony_ci
2237e5c31af7Sopenharmony_ci[latexmath]
2238e5c31af7Sopenharmony_ci++++++++++++++++++++++++
2239e5c31af7Sopenharmony_ci\begin{aligned}
2240e5c31af7Sopenharmony_ci\alpha &= \mathbin{frac}\left(u - \frac{1}{2}\right)  \\[1em]
2241e5c31af7Sopenharmony_ci\beta &= \mathbin{frac}\left(v - \frac{1}{2}\right)  \\[1em]
2242e5c31af7Sopenharmony_ci\gamma &= \mathbin{frac}\left(w - \frac{1}{2}\right)
2243e5c31af7Sopenharmony_ci\end{aligned}
2244e5c31af7Sopenharmony_ci++++++++++++++++++++++++
2245e5c31af7Sopenharmony_ci
2246e5c31af7Sopenharmony_ciendif::VK_EXT_filter_cubic[]
2247e5c31af7Sopenharmony_ci
2248e5c31af7Sopenharmony_ciwhere:
2249e5c31af7Sopenharmony_ci
2250e5c31af7Sopenharmony_ci[latexmath]
2251e5c31af7Sopenharmony_ci++++++++++++++++++++++++
2252e5c31af7Sopenharmony_ci\mathbin{frac}(x) = x -  \left\lfloor x \right\rfloor
2253e5c31af7Sopenharmony_ci++++++++++++++++++++++++
2254e5c31af7Sopenharmony_ci
2255e5c31af7Sopenharmony_ciwhere the number of fraction bits retained is specified by
2256e5c31af7Sopenharmony_cisname:VkPhysicalDeviceLimits::pname:subTexelPrecisionBits.
2257e5c31af7Sopenharmony_ciendif::VK_IMG_filter_cubic,VK_EXT_filter_cubic[]
2258e5c31af7Sopenharmony_ci
2259e5c31af7Sopenharmony_ci
2260e5c31af7Sopenharmony_ci[[textures-integer-coordinate-operations]]
2261e5c31af7Sopenharmony_ci== Integer Texel Coordinate Operations
2262e5c31af7Sopenharmony_ci
2263e5c31af7Sopenharmony_ciifdef::VK_AMD_shader_image_load_store_lod[]
2264e5c31af7Sopenharmony_ciInteger texel coordinate operations may: supply a LOD which texels are to be
2265e5c31af7Sopenharmony_ciread from or written to using the optional SPIR-V operand code:Lod.
2266e5c31af7Sopenharmony_ciendif::VK_AMD_shader_image_load_store_lod[]
2267e5c31af7Sopenharmony_ciifndef::VK_AMD_shader_image_load_store_lod[]
2268e5c31af7Sopenharmony_ciThe code:OpImageFetch and code:OpImageFetchSparse SPIR-V instructions may:
2269e5c31af7Sopenharmony_cisupply a LOD from which texels are to be fetched using the optional SPIR-V
2270e5c31af7Sopenharmony_cioperand code:Lod.
2271e5c31af7Sopenharmony_ciOther integer-coordinate operations must: not.
2272e5c31af7Sopenharmony_ciendif::VK_AMD_shader_image_load_store_lod[]
2273e5c31af7Sopenharmony_ciIf the code:Lod is provided then it must: be an integer.
2274e5c31af7Sopenharmony_ci
2275e5c31af7Sopenharmony_ciThe image level selected is:
2276e5c31af7Sopenharmony_ci[latexmath]
2277e5c31af7Sopenharmony_ci++++++++++++++++++++++++
2278e5c31af7Sopenharmony_ci\begin{aligned}
2279e5c31af7Sopenharmony_cid & = level_{base} +
2280e5c31af7Sopenharmony_ci  \begin{cases}
2281e5c31af7Sopenharmony_ci    Lod & \text{(from optional SPIR-V operand)} \\
2282e5c31af7Sopenharmony_ci    0   & \text{otherwise}
2283e5c31af7Sopenharmony_ci  \end{cases} \\
2284e5c31af7Sopenharmony_ci\end{aligned}
2285e5c31af7Sopenharmony_ci++++++++++++++++++++++++
2286e5c31af7Sopenharmony_ci
2287e5c31af7Sopenharmony_ciIf [eq]#d# does not lie in the range [eq]#[pname:baseMipLevel,
2288e5c31af7Sopenharmony_cipname:baseMipLevel {plus} pname:levelCount)#
2289e5c31af7Sopenharmony_ciifdef::VK_EXT_image_view_min_lod[]
2290e5c31af7Sopenharmony_cior [eq]#d# is less than minLodInteger~imageView~,
2291e5c31af7Sopenharmony_ciendif::VK_EXT_image_view_min_lod[]
2292e5c31af7Sopenharmony_cithen any values fetched are
2293e5c31af7Sopenharmony_ciifdef::VK_EXT_robustness2[]
2294e5c31af7Sopenharmony_cizero if <<features-robustImageAccess2,pname:robustImageAccess2>> is enabled,
2295e5c31af7Sopenharmony_ciotherwise are
2296e5c31af7Sopenharmony_ciendif::VK_EXT_robustness2[]
2297e5c31af7Sopenharmony_ciundefined:, and any writes (if supported) are discarded.
2298e5c31af7Sopenharmony_ci
2299e5c31af7Sopenharmony_ciifdef::VK_EXT_image_view_min_lod[]
2300e5c31af7Sopenharmony_ciwhere:
2301e5c31af7Sopenharmony_ci
2302e5c31af7Sopenharmony_ci[eq]#minLodInteger~imageView~ = {lfloor}pname:minLod{rfloor}#
2303e5c31af7Sopenharmony_ci
2304e5c31af7Sopenharmony_cipname:minLod is taken from the
2305e5c31af7Sopenharmony_cislink:VkImageViewMinLodCreateInfoEXT::pname:minLod of the image view if
2306e5c31af7Sopenharmony_cipresent and the selection is part of the result of a sampling operation,
2307e5c31af7Sopenharmony_ciotherwise it is `0.0`.
2308e5c31af7Sopenharmony_ciIf the integer texel operation is not a sampling operation, the image view
2309e5c31af7Sopenharmony_ciparameter is ignored, and pname:minLod is `0.0`.
2310e5c31af7Sopenharmony_ciendif::VK_EXT_image_view_min_lod[]
2311e5c31af7Sopenharmony_ci
2312e5c31af7Sopenharmony_ci[[textures-sample-operations]]
2313e5c31af7Sopenharmony_ci== Image Sample Operations
2314e5c31af7Sopenharmony_ci
2315e5c31af7Sopenharmony_ci
2316e5c31af7Sopenharmony_ci[[textures-wrapping-operation]]
2317e5c31af7Sopenharmony_ci=== Wrapping Operation
2318e5c31af7Sopenharmony_ci
2319e5c31af7Sopenharmony_cicode:Cube images ignore the wrap modes specified in the sampler.
2320e5c31af7Sopenharmony_ciInstead, if ename:VK_FILTER_NEAREST is used within a mip level then
2321e5c31af7Sopenharmony_ciename:VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE is used, and if
2322e5c31af7Sopenharmony_ciename:VK_FILTER_LINEAR is used within a mip level then sampling at the edges
2323e5c31af7Sopenharmony_ciis performed as described earlier in the <<textures-cubemapedge,Cube map
2324e5c31af7Sopenharmony_ciedge handling>> section.
2325e5c31af7Sopenharmony_ci
2326e5c31af7Sopenharmony_ciThe first integer texel coordinate i is transformed based on the
2327e5c31af7Sopenharmony_cipname:addressModeU parameter of the sampler.
2328e5c31af7Sopenharmony_ci
2329e5c31af7Sopenharmony_ci[latexmath]
2330e5c31af7Sopenharmony_ci++++++++++++++++++++++++
2331e5c31af7Sopenharmony_ci\begin{aligned}
2332e5c31af7Sopenharmony_cii &=
2333e5c31af7Sopenharmony_ci  \begin{cases}
2334e5c31af7Sopenharmony_ci    i \bmod size                                & \text{for repeat} \\
2335e5c31af7Sopenharmony_ci    (size - 1) - \mathbin{mirror}
2336e5c31af7Sopenharmony_ci        ((i \bmod (2 \times size)) - size)      & \text{for mirrored repeat} \\
2337e5c31af7Sopenharmony_ci    \mathbin{clamp}(i,0,size-1)                  & \text{for clamp to edge} \\
2338e5c31af7Sopenharmony_ci    \mathbin{clamp}(i,-1,size)                   & \text{for clamp to border} \\
2339e5c31af7Sopenharmony_ci    \mathbin{clamp}(\mathbin{mirror}(i),0,size-1) & \text{for mirror clamp to edge}
2340e5c31af7Sopenharmony_ci  \end{cases}
2341e5c31af7Sopenharmony_ci\end{aligned}
2342e5c31af7Sopenharmony_ci++++++++++++++++++++++++
2343e5c31af7Sopenharmony_ci
2344e5c31af7Sopenharmony_ciwhere:
2345e5c31af7Sopenharmony_ci
2346e5c31af7Sopenharmony_ci[latexmath]
2347e5c31af7Sopenharmony_ci++++++++++++++++++++++++
2348e5c31af7Sopenharmony_ci\begin{aligned}
2349e5c31af7Sopenharmony_ci& \mathbin{mirror}(n) =
2350e5c31af7Sopenharmony_ci  \begin{cases}
2351e5c31af7Sopenharmony_ci    n      & \text{for}\  n \geq 0 \\
2352e5c31af7Sopenharmony_ci    -(1+n) & \text{otherwise}
2353e5c31af7Sopenharmony_ci  \end{cases}
2354e5c31af7Sopenharmony_ci\end{aligned}
2355e5c31af7Sopenharmony_ci++++++++++++++++++++++++
2356e5c31af7Sopenharmony_ci
2357e5c31af7Sopenharmony_ci[eq]#j# (for 2D and Cube image) and [eq]#k# (for 3D image) are similarly
2358e5c31af7Sopenharmony_citransformed based on the pname:addressModeV and pname:addressModeW
2359e5c31af7Sopenharmony_ciparameters of the sampler, respectively.
2360e5c31af7Sopenharmony_ci
2361e5c31af7Sopenharmony_ci
2362e5c31af7Sopenharmony_ci[[textures-gather]]
2363e5c31af7Sopenharmony_ci=== Texel Gathering
2364e5c31af7Sopenharmony_ci
2365e5c31af7Sopenharmony_ciSPIR-V instructions with code:Gather in the name return a vector derived
2366e5c31af7Sopenharmony_cifrom 4 texels in the base level of the image view.
2367e5c31af7Sopenharmony_ciThe rules for the ename:VK_FILTER_LINEAR minification filter are applied to
2368e5c31af7Sopenharmony_ciidentify the four selected texels.
2369e5c31af7Sopenharmony_ciEach texel is then converted to an RGBA value according to
2370e5c31af7Sopenharmony_ci<<textures-conversion-to-rgba,conversion to RGBA>> and then
2371e5c31af7Sopenharmony_ci<<textures-component-swizzle,swizzled>>.
2372e5c31af7Sopenharmony_ciA four-component vector is then assembled by taking the component indicated
2373e5c31af7Sopenharmony_ciby the code:Component value in the instruction from the swizzled color value
2374e5c31af7Sopenharmony_ciof the four texels.
2375e5c31af7Sopenharmony_ciIf the operation does not use the code:ConstOffsets image operand then the
2376e5c31af7Sopenharmony_cifour texels form the 2 {times} 2 rectangle used for texture filtering:
2377e5c31af7Sopenharmony_ci
2378e5c31af7Sopenharmony_ci[latexmath]
2379e5c31af7Sopenharmony_ci++++++++++++++++++++++++
2380e5c31af7Sopenharmony_ci\begin{aligned}
2381e5c31af7Sopenharmony_ci\tau[R] &= \tau_{i0j1}[level_{base}][comp] \\
2382e5c31af7Sopenharmony_ci\tau[G] &= \tau_{i1j1}[level_{base}][comp] \\
2383e5c31af7Sopenharmony_ci\tau[B] &= \tau_{i1j0}[level_{base}][comp] \\
2384e5c31af7Sopenharmony_ci\tau[A] &= \tau_{i0j0}[level_{base}][comp]
2385e5c31af7Sopenharmony_ci\end{aligned}
2386e5c31af7Sopenharmony_ci++++++++++++++++++++++++
2387e5c31af7Sopenharmony_ci
2388e5c31af7Sopenharmony_ciIf the operation does use the code:ConstOffsets image operand then the
2389e5c31af7Sopenharmony_cioffsets allow a custom filter to be defined:
2390e5c31af7Sopenharmony_ci
2391e5c31af7Sopenharmony_ci[latexmath]
2392e5c31af7Sopenharmony_ci++++++++++++++++++++++++
2393e5c31af7Sopenharmony_ci\begin{aligned}
2394e5c31af7Sopenharmony_ci\tau[R] &= \tau_{i0j0 + \Delta_0}[level_{base}][comp] \\
2395e5c31af7Sopenharmony_ci\tau[G] &= \tau_{i0j0 + \Delta_1}[level_{base}][comp] \\
2396e5c31af7Sopenharmony_ci\tau[B] &= \tau_{i0j0 + \Delta_2}[level_{base}][comp] \\
2397e5c31af7Sopenharmony_ci\tau[A] &= \tau_{i0j0 + \Delta_3}[level_{base}][comp]
2398e5c31af7Sopenharmony_ci\end{aligned}
2399e5c31af7Sopenharmony_ci++++++++++++++++++++++++
2400e5c31af7Sopenharmony_ci
2401e5c31af7Sopenharmony_ciwhere:
2402e5c31af7Sopenharmony_ci
2403e5c31af7Sopenharmony_ci[latexmath]
2404e5c31af7Sopenharmony_ci++++++++++++++++++++++++
2405e5c31af7Sopenharmony_ci\begin{aligned}
2406e5c31af7Sopenharmony_ci\tau[level_{base}][comp] &=
2407e5c31af7Sopenharmony_ci  \begin{cases}
2408e5c31af7Sopenharmony_ci    \tau[level_{base}][R], & \text{for}\  comp = 0 \\
2409e5c31af7Sopenharmony_ci    \tau[level_{base}][G], & \text{for}\  comp = 1 \\
2410e5c31af7Sopenharmony_ci    \tau[level_{base}][B], & \text{for}\  comp = 2 \\
2411e5c31af7Sopenharmony_ci    \tau[level_{base}][A], & \text{for}\  comp = 3
2412e5c31af7Sopenharmony_ci  \end{cases}\\
2413e5c31af7Sopenharmony_cicomp & \,\text{from SPIR-V operand Component}
2414e5c31af7Sopenharmony_ci\end{aligned}
2415e5c31af7Sopenharmony_ci++++++++++++++++++++++++
2416e5c31af7Sopenharmony_ci
2417e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_1,VK_KHR_sampler_ycbcr_conversion[]
2418e5c31af7Sopenharmony_cicode:OpImage*Gather must: not be used on a sampled image with
2419e5c31af7Sopenharmony_ci<<samplers-YCbCr-conversion,sampler {YCbCr} conversion>> enabled.
2420e5c31af7Sopenharmony_ciendif::VK_VERSION_1_1,VK_KHR_sampler_ycbcr_conversion[]
2421e5c31af7Sopenharmony_ci
2422e5c31af7Sopenharmony_ci
2423e5c31af7Sopenharmony_ci[[textures-texel-filtering]]
2424e5c31af7Sopenharmony_ci=== Texel Filtering
2425e5c31af7Sopenharmony_ci
2426e5c31af7Sopenharmony_ciTexel filtering is first performed for each level (either [eq]#d# or
2427e5c31af7Sopenharmony_ci[eq]#d~hi~# and [eq]#d~lo~#).
2428e5c31af7Sopenharmony_ci
2429e5c31af7Sopenharmony_ciIf [eq]#{lambda}# is less than or equal to zero, the texture is said to be
2430e5c31af7Sopenharmony_ci_magnified_, and the filter mode within a mip level is selected by the
2431e5c31af7Sopenharmony_cipname:magFilter in the sampler.
2432e5c31af7Sopenharmony_ciIf [eq]#{lambda}# is greater than zero, the texture is said to be
2433e5c31af7Sopenharmony_ci_minified_, and the filter mode within a mip level is selected by the
2434e5c31af7Sopenharmony_cipname:minFilter in the sampler.
2435e5c31af7Sopenharmony_ci
2436e5c31af7Sopenharmony_ci[[textures-texel-nearest-filtering]]
2437e5c31af7Sopenharmony_ci==== Texel Nearest Filtering
2438e5c31af7Sopenharmony_ci
2439e5c31af7Sopenharmony_ciWithin a mip level, ename:VK_FILTER_NEAREST filtering selects a single value
2440e5c31af7Sopenharmony_ciusing the [eq]#(i, j, k)# texel coordinates, with all texels taken from
2441e5c31af7Sopenharmony_cilayer l.
2442e5c31af7Sopenharmony_ci
2443e5c31af7Sopenharmony_ci[latexmath]
2444e5c31af7Sopenharmony_ci++++++++++++++++++++++++
2445e5c31af7Sopenharmony_ci\begin{aligned}
2446e5c31af7Sopenharmony_ci\tau[level] &=
2447e5c31af7Sopenharmony_ci  \begin{cases}
2448e5c31af7Sopenharmony_ci     \tau_{ijk}[level], & \text{for 3D image} \\
2449e5c31af7Sopenharmony_ci     \tau_{ij}[level],  & \text{for 2D or Cube image} \\
2450e5c31af7Sopenharmony_ci     \tau_{i}[level],   & \text{for 1D image}
2451e5c31af7Sopenharmony_ci   \end{cases}
2452e5c31af7Sopenharmony_ci\end{aligned}
2453e5c31af7Sopenharmony_ci++++++++++++++++++++++++
2454e5c31af7Sopenharmony_ci
2455e5c31af7Sopenharmony_ci[[textures-texel-linear-filtering]]
2456e5c31af7Sopenharmony_ci==== Texel Linear Filtering
2457e5c31af7Sopenharmony_ci
2458e5c31af7Sopenharmony_ciWithin a mip level, ename:VK_FILTER_LINEAR filtering combines 8 (for 3D), 4
2459e5c31af7Sopenharmony_ci(for 2D or Cube), or 2 (for 1D) texel values, together with their linear
2460e5c31af7Sopenharmony_ciweights.
2461e5c31af7Sopenharmony_ciThe linear weights are derived from the fractions computed earlier:
2462e5c31af7Sopenharmony_ci
2463e5c31af7Sopenharmony_ci[latexmath]
2464e5c31af7Sopenharmony_ci
2465e5c31af7Sopenharmony_ci++++++++++++++++++++++++
2466e5c31af7Sopenharmony_ci\begin{aligned}
2467e5c31af7Sopenharmony_ciw_{i_0} &= (1-\alpha) \\
2468e5c31af7Sopenharmony_ciw_{i_1} &= (\alpha)   \\
2469e5c31af7Sopenharmony_ciw_{j_0} &= (1-\beta)  \\
2470e5c31af7Sopenharmony_ciw_{j_1} &= (\beta)    \\
2471e5c31af7Sopenharmony_ciw_{k_0} &= (1-\gamma) \\
2472e5c31af7Sopenharmony_ciw_{k_1} &= (\gamma)
2473e5c31af7Sopenharmony_ci\end{aligned}
2474e5c31af7Sopenharmony_ci++++++++++++++++++++++++
2475e5c31af7Sopenharmony_ci
2476e5c31af7Sopenharmony_ciifndef::VK_VERSION_1_2,VK_EXT_sampler_filter_minmax[]
2477e5c31af7Sopenharmony_ciThe values of multiple texels, together with their weights, are combined
2478e5c31af7Sopenharmony_ciusing a weighted average to produce a filtered value:
2479e5c31af7Sopenharmony_ciendif::VK_VERSION_1_2,VK_EXT_sampler_filter_minmax[]
2480e5c31af7Sopenharmony_ci
2481e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_2,VK_EXT_sampler_filter_minmax[]
2482e5c31af7Sopenharmony_ciThe values of multiple texels, together with their weights, are combined to
2483e5c31af7Sopenharmony_ciproduce a filtered value.
2484e5c31af7Sopenharmony_ci
2485e5c31af7Sopenharmony_ciThe slink:VkSamplerReductionModeCreateInfo::pname:reductionMode can: control
2486e5c31af7Sopenharmony_cithe process by which multiple texels, together with their weights, are
2487e5c31af7Sopenharmony_cicombined to produce a filtered texture value.
2488e5c31af7Sopenharmony_ci
2489e5c31af7Sopenharmony_ciWhen the pname:reductionMode is set (explicitly or implicitly) to
2490e5c31af7Sopenharmony_ciename:VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE, a weighted average is
2491e5c31af7Sopenharmony_cicomputed:
2492e5c31af7Sopenharmony_ciendif::VK_VERSION_1_2,VK_EXT_sampler_filter_minmax[]
2493e5c31af7Sopenharmony_ci
2494e5c31af7Sopenharmony_ci[latexmath]
2495e5c31af7Sopenharmony_ci++++++++++++++++++++++++
2496e5c31af7Sopenharmony_ci\begin{aligned}
2497e5c31af7Sopenharmony_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} \\
2498e5c31af7Sopenharmony_ci\tau_{2D} &= \sum_{j=j_0}^{j_1}\sum_{i=i_0}^{i_1}(w_{i})(w_{j})\tau_{ij} \\
2499e5c31af7Sopenharmony_ci\tau_{1D} &= \sum_{i=i_0}^{i_1}(w_{i})\tau_{i}
2500e5c31af7Sopenharmony_ci\end{aligned}
2501e5c31af7Sopenharmony_ci++++++++++++++++++++++++
2502e5c31af7Sopenharmony_ci
2503e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_2,VK_EXT_sampler_filter_minmax[]
2504e5c31af7Sopenharmony_ciHowever, if the reduction mode is ename:VK_SAMPLER_REDUCTION_MODE_MIN or
2505e5c31af7Sopenharmony_ciename:VK_SAMPLER_REDUCTION_MODE_MAX, the process operates on the above set
2506e5c31af7Sopenharmony_ciof multiple texels, together with their weights, computing a component-wise
2507e5c31af7Sopenharmony_ciminimum or maximum, respectively, of the components of the set of texels
2508e5c31af7Sopenharmony_ciwith non-zero weights.
2509e5c31af7Sopenharmony_ciendif::VK_VERSION_1_2,VK_EXT_sampler_filter_minmax[]
2510e5c31af7Sopenharmony_ci
2511e5c31af7Sopenharmony_ciifdef::VK_IMG_filter_cubic,VK_EXT_filter_cubic[]
2512e5c31af7Sopenharmony_ci
2513e5c31af7Sopenharmony_ci[[textures-texel-cubic-filtering]]
2514e5c31af7Sopenharmony_ci==== Texel Cubic Filtering
2515e5c31af7Sopenharmony_ci
2516e5c31af7Sopenharmony_ciWithin a mip level, ename:VK_FILTER_CUBIC_EXT, filtering computes a weighted
2517e5c31af7Sopenharmony_ciaverage of
2518e5c31af7Sopenharmony_ciifdef::VK_EXT_filter_cubic[]
2519e5c31af7Sopenharmony_ci64 (for 3D),
2520e5c31af7Sopenharmony_ciendif::VK_EXT_filter_cubic[]
2521e5c31af7Sopenharmony_ci16 (for 2D), or 4 (for 1D) texel values, together with their Catmull-Rom
2522e5c31af7Sopenharmony_ciweights.
2523e5c31af7Sopenharmony_ci
2524e5c31af7Sopenharmony_ciCatmull-Rom weights are derived from the fractions computed earlier.
2525e5c31af7Sopenharmony_ci
2526e5c31af7Sopenharmony_ciifndef::VK_EXT_filter_cubic[]
2527e5c31af7Sopenharmony_ci[latexmath]
2528e5c31af7Sopenharmony_ci++++++++++++++++++++++++
2529e5c31af7Sopenharmony_ci\begin{aligned}
2530e5c31af7Sopenharmony_ci\begin{bmatrix}
2531e5c31af7Sopenharmony_ciw_{i_0}\phantom{,} w_{i_1}\phantom{,} w_{i_2}\phantom{,} w_{i_3}
2532e5c31af7Sopenharmony_ci\end{bmatrix}
2533e5c31af7Sopenharmony_ci= \frac{1}{2}
2534e5c31af7Sopenharmony_ci\begin{bmatrix}
2535e5c31af7Sopenharmony_ci1 & \alpha & \alpha^2 & \alpha^3
2536e5c31af7Sopenharmony_ci\end{bmatrix}
2537e5c31af7Sopenharmony_ci\begin{bmatrix}
2538e5c31af7Sopenharmony_ci\phantom{-}0 &  \phantom{-}2 &  \phantom{-}0 &  \phantom{-}0 \\
2539e5c31af7Sopenharmony_ci-1 &  \phantom{-}0 &  \phantom{-}1 &  \phantom{-}0 \\
2540e5c31af7Sopenharmony_ci\phantom{-}2 & -5 &  \phantom{-}4 &  -1 \\
2541e5c31af7Sopenharmony_ci-1 &  \phantom{-}3 & -3 &  \phantom{-}1
2542e5c31af7Sopenharmony_ci\end{bmatrix}
2543e5c31af7Sopenharmony_ci\\
2544e5c31af7Sopenharmony_ci\begin{bmatrix}
2545e5c31af7Sopenharmony_ciw_{j_0}\phantom{,} w_{j_1}\phantom{,} w_{j_2}\phantom{,} w_{j_3}
2546e5c31af7Sopenharmony_ci\end{bmatrix}
2547e5c31af7Sopenharmony_ci= \frac{1}{2}
2548e5c31af7Sopenharmony_ci\begin{bmatrix}
2549e5c31af7Sopenharmony_ci1 & \beta & \beta^2 & \beta^3
2550e5c31af7Sopenharmony_ci\end{bmatrix}
2551e5c31af7Sopenharmony_ci\begin{bmatrix}
2552e5c31af7Sopenharmony_ci\phantom{-}0 &  \phantom{-}2 &  \phantom{-}0 &  \phantom{-}0 \\
2553e5c31af7Sopenharmony_ci-1 &  \phantom{-}0 &  \phantom{-}1 &  \phantom{-}0 \\
2554e5c31af7Sopenharmony_ci\phantom{-}2 & -5 &  \phantom{-}4 &  -1 \\
2555e5c31af7Sopenharmony_ci-1 &  \phantom{-}3 & -3 &  \phantom{-}1
2556e5c31af7Sopenharmony_ci\end{bmatrix}
2557e5c31af7Sopenharmony_ci\end{aligned}
2558e5c31af7Sopenharmony_ci++++++++++++++++++++++++
2559e5c31af7Sopenharmony_ci
2560e5c31af7Sopenharmony_ciThe values of multiple texels, together with their weights, are combined
2561e5c31af7Sopenharmony_ciusing a weighted average to produce a filtered value:
2562e5c31af7Sopenharmony_ci
2563e5c31af7Sopenharmony_ci[latexmath]
2564e5c31af7Sopenharmony_ci++++++++++++++++++++++++
2565e5c31af7Sopenharmony_ci\begin{aligned}
2566e5c31af7Sopenharmony_ci\tau_{2D} &= \sum_{j=j_0}^{j_3}\sum_{i=i_0}^{i_3}(w_{i})(w_{j})\tau_{ij} \\
2567e5c31af7Sopenharmony_ci\tau_{1D} &= \sum_{i=i_0}^{i_3}(w_{i})\tau_{i}
2568e5c31af7Sopenharmony_ci\end{aligned}
2569e5c31af7Sopenharmony_ci++++++++++++++++++++++++
2570e5c31af7Sopenharmony_ciendif::VK_EXT_filter_cubic[]
2571e5c31af7Sopenharmony_ci
2572e5c31af7Sopenharmony_ciifdef::VK_EXT_filter_cubic[]
2573e5c31af7Sopenharmony_ci
2574e5c31af7Sopenharmony_ci[latexmath]
2575e5c31af7Sopenharmony_ci++++++++++++++++++++++++
2576e5c31af7Sopenharmony_ci\begin{aligned}
2577e5c31af7Sopenharmony_ci\begin{bmatrix}
2578e5c31af7Sopenharmony_ciw_{i_0}\phantom{,} w_{i_1}\phantom{,} w_{i_2}\phantom{,} w_{i_3}
2579e5c31af7Sopenharmony_ci\end{bmatrix}
2580e5c31af7Sopenharmony_ci= \frac{1}{2}
2581e5c31af7Sopenharmony_ci\begin{bmatrix}
2582e5c31af7Sopenharmony_ci1 & \alpha & \alpha^2 & \alpha^3
2583e5c31af7Sopenharmony_ci\end{bmatrix}
2584e5c31af7Sopenharmony_ci\begin{bmatrix}
2585e5c31af7Sopenharmony_ci\phantom{-}0 &  \phantom{-}2 &  \phantom{-}0 &  \phantom{-}0 \\
2586e5c31af7Sopenharmony_ci-1 &  \phantom{-}0 &  \phantom{-}1 &  \phantom{-}0 \\
2587e5c31af7Sopenharmony_ci\phantom{-}2 & -5 &  \phantom{-}4 &  -1 \\
2588e5c31af7Sopenharmony_ci-1 &  \phantom{-}3 & -3 &  \phantom{-}1
2589e5c31af7Sopenharmony_ci\end{bmatrix}
2590e5c31af7Sopenharmony_ci\\
2591e5c31af7Sopenharmony_ci\begin{bmatrix}
2592e5c31af7Sopenharmony_ciw_{j_0}\phantom{,} w_{j_1}\phantom{,} w_{j_2}\phantom{,} w_{j_3}
2593e5c31af7Sopenharmony_ci\end{bmatrix}
2594e5c31af7Sopenharmony_ci= \frac{1}{2}
2595e5c31af7Sopenharmony_ci\begin{bmatrix}
2596e5c31af7Sopenharmony_ci1 & \beta & \beta^2 & \beta^3
2597e5c31af7Sopenharmony_ci\end{bmatrix}
2598e5c31af7Sopenharmony_ci\begin{bmatrix}
2599e5c31af7Sopenharmony_ci\phantom{-}0 &  \phantom{-}2 &  \phantom{-}0 &  \phantom{-}0 \\
2600e5c31af7Sopenharmony_ci-1 &  \phantom{-}0 &  \phantom{-}1 &  \phantom{-}0 \\
2601e5c31af7Sopenharmony_ci\phantom{-}2 & -5 &  \phantom{-}4 &  -1 \\
2602e5c31af7Sopenharmony_ci-1 &  \phantom{-}3 & -3 &  \phantom{-}1
2603e5c31af7Sopenharmony_ci\end{bmatrix}
2604e5c31af7Sopenharmony_ci\\
2605e5c31af7Sopenharmony_ci\begin{bmatrix}
2606e5c31af7Sopenharmony_ciw_{k_0}\phantom{,} w_{k_1}\phantom{,} w_{k_2}\phantom{,} w_{k_3}
2607e5c31af7Sopenharmony_ci\end{bmatrix}
2608e5c31af7Sopenharmony_ci= \frac{1}{2}
2609e5c31af7Sopenharmony_ci\begin{bmatrix}
2610e5c31af7Sopenharmony_ci1 & \gamma & \gamma^2 & \gamma^3
2611e5c31af7Sopenharmony_ci\end{bmatrix}
2612e5c31af7Sopenharmony_ci\begin{bmatrix}
2613e5c31af7Sopenharmony_ci\phantom{-}0 &  \phantom{-}2 &  \phantom{-}0 &  \phantom{-}0 \\
2614e5c31af7Sopenharmony_ci-1 &  \phantom{-}0 &  \phantom{-}1 &  \phantom{-}0 \\
2615e5c31af7Sopenharmony_ci\phantom{-}2 & -5 &  \phantom{-}4 &  -1 \\
2616e5c31af7Sopenharmony_ci-1 &  \phantom{-}3 & -3 &  \phantom{-}1
2617e5c31af7Sopenharmony_ci\end{bmatrix}
2618e5c31af7Sopenharmony_ci\end{aligned}
2619e5c31af7Sopenharmony_ci++++++++++++++++++++++++
2620e5c31af7Sopenharmony_ci
2621e5c31af7Sopenharmony_ciThe values of multiple texels, together with their weights, are combined to
2622e5c31af7Sopenharmony_ciproduce a filtered value.
2623e5c31af7Sopenharmony_ci
2624e5c31af7Sopenharmony_ciThe slink:VkSamplerReductionModeCreateInfo::pname:reductionMode can: control
2625e5c31af7Sopenharmony_cithe process by which multiple texels, together with their weights, are
2626e5c31af7Sopenharmony_cicombined to produce a filtered texture value.
2627e5c31af7Sopenharmony_ci
2628e5c31af7Sopenharmony_ciWhen the pname:reductionMode is set (explicitly or implicitly) to
2629e5c31af7Sopenharmony_ciename:VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE, a weighted average is
2630e5c31af7Sopenharmony_cicomputed:
2631e5c31af7Sopenharmony_ci
2632e5c31af7Sopenharmony_ci[latexmath]
2633e5c31af7Sopenharmony_ci++++++++++++++++++++++++
2634e5c31af7Sopenharmony_ci\begin{aligned}
2635e5c31af7Sopenharmony_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} \\
2636e5c31af7Sopenharmony_ci\tau_{2D} &= \sum_{j=j_0}^{j_3}\sum_{i=i_0}^{i_3}(w_{i})(w_{j})\tau_{ij} \\
2637e5c31af7Sopenharmony_ci\tau_{1D} &= \sum_{i=i_0}^{i_3}(w_{i})\tau_{i}
2638e5c31af7Sopenharmony_ci\end{aligned}
2639e5c31af7Sopenharmony_ci++++++++++++++++++++++++
2640e5c31af7Sopenharmony_ci
2641e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_2,VK_EXT_sampler_filter_minmax[]
2642e5c31af7Sopenharmony_ciHowever, if the reduction mode is ename:VK_SAMPLER_REDUCTION_MODE_MIN or
2643e5c31af7Sopenharmony_ciename:VK_SAMPLER_REDUCTION_MODE_MAX, the process operates on the above set
2644e5c31af7Sopenharmony_ciof multiple texels, together with their weights, computing a component-wise
2645e5c31af7Sopenharmony_ciminimum or maximum, respectively, of the components of the set of texels
2646e5c31af7Sopenharmony_ciwith non-zero weights.
2647e5c31af7Sopenharmony_ciendif::VK_VERSION_1_2,VK_EXT_sampler_filter_minmax[]
2648e5c31af7Sopenharmony_ci
2649e5c31af7Sopenharmony_ciendif::VK_EXT_filter_cubic[]
2650e5c31af7Sopenharmony_ciendif::VK_IMG_filter_cubic,VK_EXT_filter_cubic[]
2651e5c31af7Sopenharmony_ci
2652e5c31af7Sopenharmony_ci[[textures-texel-mipmap-filtering]]
2653e5c31af7Sopenharmony_ci
2654e5c31af7Sopenharmony_ci==== Texel Mipmap Filtering
2655e5c31af7Sopenharmony_ci
2656e5c31af7Sopenharmony_ciename:VK_SAMPLER_MIPMAP_MODE_NEAREST filtering returns the value of a single
2657e5c31af7Sopenharmony_cimipmap level,
2658e5c31af7Sopenharmony_ci
2659e5c31af7Sopenharmony_ci[eq]#{tau} = {tau}[d]#.
2660e5c31af7Sopenharmony_ci
2661e5c31af7Sopenharmony_ciename:VK_SAMPLER_MIPMAP_MODE_LINEAR filtering combines the values of
2662e5c31af7Sopenharmony_cimultiple mipmap levels ({tau}[hi] and {tau}[lo]), together with their linear
2663e5c31af7Sopenharmony_ciweights.
2664e5c31af7Sopenharmony_ci
2665e5c31af7Sopenharmony_ciThe linear weights are derived from the fraction computed earlier:
2666e5c31af7Sopenharmony_ci
2667e5c31af7Sopenharmony_ci[latexmath]
2668e5c31af7Sopenharmony_ci++++++++++++++++++++++++
2669e5c31af7Sopenharmony_ci\begin{aligned}
2670e5c31af7Sopenharmony_ciw_{hi} &= (1-\delta) \\
2671e5c31af7Sopenharmony_ciw_{lo} &= (\delta)   \\
2672e5c31af7Sopenharmony_ci\end{aligned}
2673e5c31af7Sopenharmony_ci++++++++++++++++++++++++
2674e5c31af7Sopenharmony_ci
2675e5c31af7Sopenharmony_ciifndef::VK_VERSION_1_2,VK_EXT_sampler_filter_minmax[]
2676e5c31af7Sopenharmony_ciThe values of multiple mipmap levels together with their linear weights, are
2677e5c31af7Sopenharmony_cicombined using a weighted average to produce a final filtered value:
2678e5c31af7Sopenharmony_ciendif::VK_VERSION_1_2,VK_EXT_sampler_filter_minmax[]
2679e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_2,VK_EXT_sampler_filter_minmax[]
2680e5c31af7Sopenharmony_ciThe values of multiple mipmap levels, together with their weights, are
2681e5c31af7Sopenharmony_cicombined to produce a final filtered value.
2682e5c31af7Sopenharmony_ci
2683e5c31af7Sopenharmony_ciThe slink:VkSamplerReductionModeCreateInfo::pname:reductionMode can: control
2684e5c31af7Sopenharmony_cithe process by which multiple texels, together with their weights, are
2685e5c31af7Sopenharmony_cicombined to produce a filtered texture value.
2686e5c31af7Sopenharmony_ci
2687e5c31af7Sopenharmony_ciWhen the pname:reductionMode is set (explicitly or implicitly) to
2688e5c31af7Sopenharmony_ciename:VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE, a weighted average is
2689e5c31af7Sopenharmony_cicomputed:
2690e5c31af7Sopenharmony_ciendif::VK_VERSION_1_2,VK_EXT_sampler_filter_minmax[]
2691e5c31af7Sopenharmony_ci
2692e5c31af7Sopenharmony_ci[latexmath]
2693e5c31af7Sopenharmony_ci++++++++++++++++++++++++
2694e5c31af7Sopenharmony_ci\begin{aligned}
2695e5c31af7Sopenharmony_ci\tau &= (w_{hi})\tau[hi]+(w_{lo})\tau[lo]
2696e5c31af7Sopenharmony_ci\end{aligned}
2697e5c31af7Sopenharmony_ci++++++++++++++++++++++++
2698e5c31af7Sopenharmony_ci
2699e5c31af7Sopenharmony_ci[[textures-texel-anisotropic-filtering]]
2700e5c31af7Sopenharmony_ci==== Texel Anisotropic Filtering
2701e5c31af7Sopenharmony_ci
2702e5c31af7Sopenharmony_ciAnisotropic filtering is enabled by the pname:anisotropyEnable in the
2703e5c31af7Sopenharmony_cisampler.
2704e5c31af7Sopenharmony_ciWhen enabled, the image filtering scheme accounts for a degree of
2705e5c31af7Sopenharmony_cianisotropy.
2706e5c31af7Sopenharmony_ci
2707e5c31af7Sopenharmony_ciThe particular scheme for anisotropic texture filtering is
2708e5c31af7Sopenharmony_ciimplementation-dependent.
2709e5c31af7Sopenharmony_ciImplementations should: consider the pname:magFilter, pname:minFilter and
2710e5c31af7Sopenharmony_cipname:mipmapMode of the sampler to control the specifics of the anisotropic
2711e5c31af7Sopenharmony_cifiltering scheme used.
2712e5c31af7Sopenharmony_ciIn addition, implementations should: consider pname:minLod and pname:maxLod
2713e5c31af7Sopenharmony_ciof the sampler.
2714e5c31af7Sopenharmony_ci
2715e5c31af7Sopenharmony_ciThe following describes one particular approach to implementing anisotropic
2716e5c31af7Sopenharmony_cifiltering for the 2D Image case, implementations may: choose other methods:
2717e5c31af7Sopenharmony_ci
2718e5c31af7Sopenharmony_ciGiven a pname:magFilter, pname:minFilter of ename:VK_FILTER_LINEAR and a
2719e5c31af7Sopenharmony_cipname:mipmapMode of ename:VK_SAMPLER_MIPMAP_MODE_NEAREST:
2720e5c31af7Sopenharmony_ci
2721e5c31af7Sopenharmony_ciInstead of a single isotropic sample, N isotropic samples are sampled within
2722e5c31af7Sopenharmony_cithe image footprint of the image level [eq]#d# to approximate an anisotropic
2723e5c31af7Sopenharmony_cifilter.
2724e5c31af7Sopenharmony_ciThe sum [eq]#{tau}~2Daniso~# is defined using the single isotropic
2725e5c31af7Sopenharmony_ci[eq]#{tau}~2D~(u,v)# at level [eq]#d#.
2726e5c31af7Sopenharmony_ci
2727e5c31af7Sopenharmony_ci[latexmath]
2728e5c31af7Sopenharmony_ci++++++++++++++++++++++++
2729e5c31af7Sopenharmony_ci\begin{aligned}
2730e5c31af7Sopenharmony_ci\tau_{2Daniso} & =
2731e5c31af7Sopenharmony_ci     \frac{1}{N}\sum_{i=1}^{N}
2732e5c31af7Sopenharmony_ci     {\tau_{2D}\left (
2733e5c31af7Sopenharmony_ci       u \left ( x - \frac{1}{2} + \frac{i}{N+1} , y \right ),
2734e5c31af7Sopenharmony_ci         \left ( v \left (x-\frac{1}{2}+\frac{i}{N+1}, y \right ),
2735e5c31af7Sopenharmony_ci\right )
2736e5c31af7Sopenharmony_ci     \right )},
2737e5c31af7Sopenharmony_ci     & \text{when}\  \rho_{x} > \rho_{y} \\
2738e5c31af7Sopenharmony_ci\tau_{2Daniso} &=
2739e5c31af7Sopenharmony_ci     \frac{1}{N}\sum_{i=1}^{N}
2740e5c31af7Sopenharmony_ci     {\tau_{2D}\left (
2741e5c31af7Sopenharmony_ci        u \left  ( x, y - \frac{1}{2} + \frac{i}{N+1} \right ),
2742e5c31af7Sopenharmony_ci          \left ( v \left (x,y-\frac{1}{2}+\frac{i}{N+1} \right )
2743e5c31af7Sopenharmony_ci\right )
2744e5c31af7Sopenharmony_ci     \right )},
2745e5c31af7Sopenharmony_ci     & \text{when}\  \rho_{y} \geq \rho_{x}
2746e5c31af7Sopenharmony_ci\end{aligned}
2747e5c31af7Sopenharmony_ci++++++++++++++++++++++++
2748e5c31af7Sopenharmony_ci
2749e5c31af7Sopenharmony_ciifdef::VK_VERSION_1_2,VK_EXT_sampler_filter_minmax[]
2750e5c31af7Sopenharmony_ciWhen slink:VkSamplerReductionModeCreateInfo::pname:reductionMode is set to
2751e5c31af7Sopenharmony_ciename:VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE, the above summation is
2752e5c31af7Sopenharmony_ciused.
2753e5c31af7Sopenharmony_ciHowever, if the reduction mode is ename:VK_SAMPLER_REDUCTION_MODE_MIN or
2754e5c31af7Sopenharmony_ciename:VK_SAMPLER_REDUCTION_MODE_MAX, the process operates on the above
2755e5c31af7Sopenharmony_civalues, together with their weights, computing a component-wise minimum or
2756e5c31af7Sopenharmony_cimaximum, respectively, of the components of the values with non-zero
2757e5c31af7Sopenharmony_ciweights.
2758e5c31af7Sopenharmony_ciendif::VK_VERSION_1_2,VK_EXT_sampler_filter_minmax[]
2759e5c31af7Sopenharmony_ci
2760e5c31af7Sopenharmony_ci
2761e5c31af7Sopenharmony_ciifdef::VK_NV_shader_image_footprint[]
2762e5c31af7Sopenharmony_ci[[textures-footprint]]
2763e5c31af7Sopenharmony_ci== Texel Footprint Evaluation
2764e5c31af7Sopenharmony_ci
2765e5c31af7Sopenharmony_ciThe SPIR-V instruction code:OpImageSampleFootprintNV evaluates the set of
2766e5c31af7Sopenharmony_citexels from a single mip level that would be accessed during a
2767e5c31af7Sopenharmony_ci<<textures-texel-filtering, texel filtering>> operation.
2768e5c31af7Sopenharmony_ciIn addition to the inputs that would be accepted by an equivalent
2769e5c31af7Sopenharmony_cicode:OpImageSample* instruction, code:OpImageSampleFootprintNV accepts two
2770e5c31af7Sopenharmony_ciadditional inputs.
2771e5c31af7Sopenharmony_ciThe code:Granularity input is an integer identifying the size of texel
2772e5c31af7Sopenharmony_cigroups used to evaluate the footprint.
2773e5c31af7Sopenharmony_ciEach bit in the returned footprint mask corresponds to an aligned block of
2774e5c31af7Sopenharmony_citexels whose size is given by the following table:
2775e5c31af7Sopenharmony_ci
2776e5c31af7Sopenharmony_ci.Texel footprint granularity values
2777e5c31af7Sopenharmony_ci[width="50%",options="header"]
2778e5c31af7Sopenharmony_ci|=====
2779e5c31af7Sopenharmony_ci| code:Granularity  | code:Dim = 2D |  code:Dim = 3D
2780e5c31af7Sopenharmony_ci|         0         |  unsupported  |  unsupported
2781e5c31af7Sopenharmony_ci|         1         |      2x2      |     2x2x2
2782e5c31af7Sopenharmony_ci|         2         |      4x2      |  unsupported
2783e5c31af7Sopenharmony_ci|         3         |      4x4      |     4x4x2
2784e5c31af7Sopenharmony_ci|         4         |      8x4      |  unsupported
2785e5c31af7Sopenharmony_ci|         5         |      8x8      |  unsupported
2786e5c31af7Sopenharmony_ci|         6         |     16x8      |  unsupported
2787e5c31af7Sopenharmony_ci|         7         |     16x16     |  unsupported
2788e5c31af7Sopenharmony_ci|         8         |  unsupported  |  unsupported
2789e5c31af7Sopenharmony_ci|         9         |  unsupported  |  unsupported
2790e5c31af7Sopenharmony_ci|         10        |  unsupported  |    16x16x16
2791e5c31af7Sopenharmony_ci|         11        |     64x64     |    32x16x16
2792e5c31af7Sopenharmony_ci|         12        |    128x64     |    32x32x16
2793e5c31af7Sopenharmony_ci|         13        |    128x128    |    32x32x32
2794e5c31af7Sopenharmony_ci|         14        |    256x128    |    64x32x32
2795e5c31af7Sopenharmony_ci|         15        |    256x256    |  unsupported
2796e5c31af7Sopenharmony_ci|=====
2797e5c31af7Sopenharmony_ci
2798e5c31af7Sopenharmony_ciThe code:Coarse input is used to select between the two mip levels that may:
2799e5c31af7Sopenharmony_cibe accessed during texel filtering when using a pname:mipmapMode of
2800e5c31af7Sopenharmony_ciename:VK_SAMPLER_MIPMAP_MODE_LINEAR.
2801e5c31af7Sopenharmony_ciWhen filtering between two mip levels, a code:Coarse value of code:true
2802e5c31af7Sopenharmony_cirequests the footprint in the lower-resolution mip level (higher level
2803e5c31af7Sopenharmony_cinumber), while code:false requests the footprint in the higher-resolution
2804e5c31af7Sopenharmony_cimip level.
2805e5c31af7Sopenharmony_ciIf texel filtering would access only a single mip level, the footprint in
2806e5c31af7Sopenharmony_cithat level would be returned when code:Coarse is set to code:false; an empty
2807e5c31af7Sopenharmony_cifootprint would be returned when code:Coarse is set to code:true.
2808e5c31af7Sopenharmony_ci
2809e5c31af7Sopenharmony_ciThe footprint for code:OpImageSampleFootprintNV is returned in a structure
2810e5c31af7Sopenharmony_ciwith six members:
2811e5c31af7Sopenharmony_ci
2812e5c31af7Sopenharmony_ci  * The first member is a boolean value that is true if the texel filtering
2813e5c31af7Sopenharmony_ci    operation would access only a single mip level.
2814e5c31af7Sopenharmony_ci  * The second member is a two- or three-component integer vector holding
2815e5c31af7Sopenharmony_ci    the footprint anchor location.
2816e5c31af7Sopenharmony_ci    For two-dimensional images, the returned components are in units of
2817e5c31af7Sopenharmony_ci    eight texel groups.
2818e5c31af7Sopenharmony_ci    For three-dimensional images, the returned components are in units of
2819e5c31af7Sopenharmony_ci    four texel groups.
2820e5c31af7Sopenharmony_ci  * The third member is a two- or three-component integer vector holding a
2821e5c31af7Sopenharmony_ci    footprint offset relative to the anchor.
2822e5c31af7Sopenharmony_ci    All returned components are in units of texel groups.
2823e5c31af7Sopenharmony_ci  * The fourth member is a two-component integer vector mask, which holds a
2824e5c31af7Sopenharmony_ci    bitfield identifying the set of texel groups in an 8x8 or 4x4x4
2825e5c31af7Sopenharmony_ci    neighborhood relative to the anchor and offset.
2826e5c31af7Sopenharmony_ci  * The fifth member is an integer identifying the mip level containing the
2827e5c31af7Sopenharmony_ci    footprint identified by the anchor, offset, and mask.
2828e5c31af7Sopenharmony_ci  * The sixth member is an integer identifying the granularity of the
2829e5c31af7Sopenharmony_ci    returned footprint.
2830e5c31af7Sopenharmony_ci
2831e5c31af7Sopenharmony_ciFor footprints in two-dimensional images (code:Dim2D), the mask returned by
2832e5c31af7Sopenharmony_cicode:OpImageSampleFootprintNV indicates whether each texel group in a 8x8
2833e5c31af7Sopenharmony_cilocal neighborhood of texel groups would have one or more texels accessed
2834e5c31af7Sopenharmony_ciduring texel filtering.
2835e5c31af7Sopenharmony_ciIn the mask, the texel group with local group coordinates
2836e5c31af7Sopenharmony_cilatexmath:[(lgx,lgy)] is considered covered if and only if
2837e5c31af7Sopenharmony_ci
2838e5c31af7Sopenharmony_ci[latexmath]
2839e5c31af7Sopenharmony_ci+++++++++++++++++++
2840e5c31af7Sopenharmony_ci\begin{aligned}
2841e5c31af7Sopenharmony_ci0 \neq ((mask.x + (mask.y << 32)) \text{ \& } (1 << (lgy \times 8 + lgx)))
2842e5c31af7Sopenharmony_ci\end{aligned}
2843e5c31af7Sopenharmony_ci+++++++++++++++++++
2844e5c31af7Sopenharmony_ci
2845e5c31af7Sopenharmony_ciwhere:
2846e5c31af7Sopenharmony_ci
2847e5c31af7Sopenharmony_ci  * latexmath:[0 \leq lgx < 8] and latexmath:[0 \leq lgy < 8]; and
2848e5c31af7Sopenharmony_ci  * latexmath:[mask] is the returned two-component mask.
2849e5c31af7Sopenharmony_ci
2850e5c31af7Sopenharmony_ciThe local group with coordinates latexmath:[(lgx,lgy)] in the mask is
2851e5c31af7Sopenharmony_ciconsidered covered if and only if the texel filtering operation would access
2852e5c31af7Sopenharmony_cione or more texels latexmath:[\tau_{ij}] in the returned miplevel where:
2853e5c31af7Sopenharmony_ci[latexmath]
2854e5c31af7Sopenharmony_ci+++++++++++++++++++
2855e5c31af7Sopenharmony_ci\begin{aligned}
2856e5c31af7Sopenharmony_cii0 & =
2857e5c31af7Sopenharmony_ci  \begin{cases}
2858e5c31af7Sopenharmony_ci    gran.x \times (8 \times anchor.x + lgx), & \text{if } lgx + offset.x < 8 \\
2859e5c31af7Sopenharmony_ci    gran.x \times (8 \times (anchor.x - 1) + lgx), & \text{otherwise}
2860e5c31af7Sopenharmony_ci  \end{cases} \\
2861e5c31af7Sopenharmony_cii1 & = i0 + gran.x - 1 \\
2862e5c31af7Sopenharmony_cij0 & =
2863e5c31af7Sopenharmony_ci  \begin{cases}
2864e5c31af7Sopenharmony_ci    gran.y \times (8 \times anchor.y + lgy), & \text{if } lgy + offset.y < 8 \\
2865e5c31af7Sopenharmony_ci    gran.y \times (8 \times (anchor.y - 1) + lgy), & otherwise
2866e5c31af7Sopenharmony_ci  \end{cases} \\
2867e5c31af7Sopenharmony_cij1 & = j0 + gran.y - 1
2868e5c31af7Sopenharmony_ci\end{aligned}
2869e5c31af7Sopenharmony_ci+++++++++++++++++++
2870e5c31af7Sopenharmony_ciand
2871e5c31af7Sopenharmony_ci
2872e5c31af7Sopenharmony_ci  * latexmath:[i0 \leq i \leq i1] and latexmath:[j0 \leq j \leq j1];
2873e5c31af7Sopenharmony_ci  * latexmath:[gran] is a two-component vector holding the width and height
2874e5c31af7Sopenharmony_ci    of the texel group identified by the granularity;
2875e5c31af7Sopenharmony_ci  * latexmath:[anchor] is the returned two-component anchor vector; and
2876e5c31af7Sopenharmony_ci  * latexmath:[offset] is the returned two-component offset vector.
2877e5c31af7Sopenharmony_ci
2878e5c31af7Sopenharmony_ciFor footprints in three-dimensional images (code:Dim3D), the mask returned
2879e5c31af7Sopenharmony_ciby code:OpImageSampleFootprintNV indicates whether each texel group in a
2880e5c31af7Sopenharmony_ci4x4x4 local neighborhood of texel groups would have one or more texels
2881e5c31af7Sopenharmony_ciaccessed during texel filtering.
2882e5c31af7Sopenharmony_ciIn the mask, the texel group with local group coordinates
2883e5c31af7Sopenharmony_cilatexmath:[(lgx,lgy,lgz)], is considered covered if and only if:
2884e5c31af7Sopenharmony_ci[latexmath]
2885e5c31af7Sopenharmony_ci+++++++++++++++++++
2886e5c31af7Sopenharmony_ci\begin{aligned}
2887e5c31af7Sopenharmony_ci0 \neq ((mask.x + (mask.y << 32)) \text{ \& } (1 << (lgz \times 16 + lgy \times 4 + lgx)))
2888e5c31af7Sopenharmony_ci\end{aligned}
2889e5c31af7Sopenharmony_ci+++++++++++++++++++
2890e5c31af7Sopenharmony_ciwhere:
2891e5c31af7Sopenharmony_ci
2892e5c31af7Sopenharmony_ci  * latexmath:[0 \leq lgx < 4], latexmath:[0 \leq lgy < 4], and latexmath:[0
2893e5c31af7Sopenharmony_ci    \leq lgz < 4]; and
2894e5c31af7Sopenharmony_ci  * latexmath:[mask] is the returned two-component mask.
2895e5c31af7Sopenharmony_ci
2896e5c31af7Sopenharmony_ciThe local group with coordinates latexmath:[(lgx,lgy,lgz)] in the mask is
2897e5c31af7Sopenharmony_ciconsidered covered if and only if the texel filtering operation would access
2898e5c31af7Sopenharmony_cione or more texels latexmath:[\tau_{ijk}] in the returned miplevel where:
2899e5c31af7Sopenharmony_ci[latexmath]
2900e5c31af7Sopenharmony_ci+++++++++++++++++++
2901e5c31af7Sopenharmony_ci\begin{aligned}
2902e5c31af7Sopenharmony_cii0 & =
2903e5c31af7Sopenharmony_ci  \begin{cases}
2904e5c31af7Sopenharmony_ci    gran.x \times (4 \times anchor.x + lgx), & \text{if } lgx + offset.x < 4 \\
2905e5c31af7Sopenharmony_ci    gran.x \times (4 \times (anchor.x - 1) + lgx), & \text{otherwise}
2906e5c31af7Sopenharmony_ci  \end{cases} \\
2907e5c31af7Sopenharmony_cii1 & = i0 + gran.x - 1 \\
2908e5c31af7Sopenharmony_cij0 & =
2909e5c31af7Sopenharmony_ci  \begin{cases}
2910e5c31af7Sopenharmony_ci    gran.y \times (4 \times anchor.y + lgy), & \text{if } lgy + offset.y < 4 \\
2911e5c31af7Sopenharmony_ci    gran.y \times (4 \times (anchor.y - 1) + lgy), & otherwise
2912e5c31af7Sopenharmony_ci  \end{cases} \\
2913e5c31af7Sopenharmony_cij1 & = j0 + gran.y - 1 \\
2914e5c31af7Sopenharmony_cik0 & =
2915e5c31af7Sopenharmony_ci  \begin{cases}
2916e5c31af7Sopenharmony_ci    gran.z \times (4 \times anchor.z + lgz), & \text{if } lgz + offset.z < 4 \\
2917e5c31af7Sopenharmony_ci    gran.z \times (4 \times (anchor.z - 1) + lgz), & otherwise
2918e5c31af7Sopenharmony_ci  \end{cases} \\
2919e5c31af7Sopenharmony_cik1 & = k0 + gran.z - 1
2920e5c31af7Sopenharmony_ci\end{aligned}
2921e5c31af7Sopenharmony_ci+++++++++++++++++++
2922e5c31af7Sopenharmony_ciand
2923e5c31af7Sopenharmony_ci
2924e5c31af7Sopenharmony_ci  * latexmath:[i0 \leq i \leq i1], latexmath:[j0 \leq j \leq j1],
2925e5c31af7Sopenharmony_ci    latexmath:[k0 \leq k \leq k1];
2926e5c31af7Sopenharmony_ci  * latexmath:[gran] is a three-component vector holding the width, height,
2927e5c31af7Sopenharmony_ci    and depth of the texel group identified by the granularity;
2928e5c31af7Sopenharmony_ci  * latexmath:[anchor] is the returned three-component anchor vector; and
2929e5c31af7Sopenharmony_ci  * latexmath:[offset] is the returned three-component offset vector.
2930e5c31af7Sopenharmony_ci
2931e5c31af7Sopenharmony_ciIf the sampler used by code:OpImageSampleFootprintNV enables anisotropic
2932e5c31af7Sopenharmony_citexel filtering via pname:anisotropyEnable, it is possible that the set of
2933e5c31af7Sopenharmony_citexel groups accessed in a mip level may be too large to be expressed using
2934e5c31af7Sopenharmony_cian 8x8 or 4x4x4 mask using the granularity requested in the instruction.
2935e5c31af7Sopenharmony_ciIn this case, the implementation uses a texel group larger than the
2936e5c31af7Sopenharmony_cirequested granularity.
2937e5c31af7Sopenharmony_ciWhen a larger texel group size is used, code:OpImageSampleFootprintNV
2938e5c31af7Sopenharmony_cireturns an integer granularity value that can: be interpreted in the same
2939e5c31af7Sopenharmony_cimanner as the granularity value provided to the instruction to determine the
2940e5c31af7Sopenharmony_citexel group size used.
2941e5c31af7Sopenharmony_ciIf anisotropic texel filtering is disabled in the sampler, or if an
2942e5c31af7Sopenharmony_cianisotropic footprint can be represented as an 8x8 or 4x4x4 mask with the
2943e5c31af7Sopenharmony_cirequested granularity, code:OpImageSampleFootprintNV will use the requested
2944e5c31af7Sopenharmony_cigranularity as-is and return a granularity value of zero.
2945e5c31af7Sopenharmony_ci
2946e5c31af7Sopenharmony_cicode:OpImageSampleFootprintNV supports only two- and three-dimensional image
2947e5c31af7Sopenharmony_ciaccesses (code:Dim2D and code:Dim3D), and the footprint returned is
2948e5c31af7Sopenharmony_ciundefined: if a sampler uses an addressing mode other than
2949e5c31af7Sopenharmony_ciename:VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE.
2950e5c31af7Sopenharmony_ci
2951e5c31af7Sopenharmony_ciendif::VK_NV_shader_image_footprint[]
2952e5c31af7Sopenharmony_ci
2953e5c31af7Sopenharmony_ci
2954e5c31af7Sopenharmony_ci[[textures-instructions]]
2955e5c31af7Sopenharmony_ci== Image Operation Steps
2956e5c31af7Sopenharmony_ci
2957e5c31af7Sopenharmony_ciEach step described in this chapter is performed by a subset of the image
2958e5c31af7Sopenharmony_ciinstructions:
2959e5c31af7Sopenharmony_ci
2960e5c31af7Sopenharmony_ci  * Texel Input Validation Operations, Format Conversion, Texel Replacement,
2961e5c31af7Sopenharmony_ci    Conversion to RGBA, and Component Swizzle: Performed by all instructions
2962e5c31af7Sopenharmony_ci    except code:OpImageWrite.
2963e5c31af7Sopenharmony_ci  * Depth Comparison: Performed by code:OpImage*Dref instructions.
2964e5c31af7Sopenharmony_ci  * All Texel output operations: Performed by code:OpImageWrite.
2965e5c31af7Sopenharmony_ci  * Projection: Performed by all code:OpImage*Proj instructions.
2966e5c31af7Sopenharmony_ci  * Derivative Image Operations, Cube Map Operations, Scale Factor
2967e5c31af7Sopenharmony_ci    Operation, Level-of-Detail Operation and Image Level(s) Selection, and
2968e5c31af7Sopenharmony_ci    Texel Anisotropic Filtering: Performed by all code:OpImageSample* and
2969e5c31af7Sopenharmony_ci    code:OpImageSparseSample* instructions.
2970e5c31af7Sopenharmony_ci  * (s,t,r,q,a) to (u,v,w,a) Transformation, Wrapping, and (u,v,w,a) to
2971e5c31af7Sopenharmony_ci    (i,j,k,l,n) Transformation And Array Layer Selection: Performed by all
2972e5c31af7Sopenharmony_ci    code:OpImageSample, code:OpImageSparseSample, and code:OpImage*Gather
2973e5c31af7Sopenharmony_ci    instructions.
2974e5c31af7Sopenharmony_ci  * Texel Gathering: Performed by code:OpImage*Gather instructions.
2975e5c31af7Sopenharmony_ciifdef::VK_NV_shader_image_footprint[]
2976e5c31af7Sopenharmony_ci  * Texel Footprint Evaluation: Performed by code:OpImageSampleFootprint
2977e5c31af7Sopenharmony_ci    instructions.
2978e5c31af7Sopenharmony_ciendif::VK_NV_shader_image_footprint[]
2979e5c31af7Sopenharmony_ci  * Texel Filtering: Performed by all code:OpImageSample* and
2980e5c31af7Sopenharmony_ci    code:OpImageSparseSample* instructions.
2981e5c31af7Sopenharmony_ci  * Sparse Residency: Performed by all code:OpImageSparse* instructions.
2982e5c31af7Sopenharmony_ci
2983e5c31af7Sopenharmony_ci
2984e5c31af7Sopenharmony_ci[[textures-queries]]
2985e5c31af7Sopenharmony_ci== Image Query Instructions
2986e5c31af7Sopenharmony_ci
2987e5c31af7Sopenharmony_ci=== Image Property Queries
2988e5c31af7Sopenharmony_ci
2989e5c31af7Sopenharmony_cicode:OpImageQuerySize, code:OpImageQuerySizeLod, code:OpImageQueryLevels,
2990e5c31af7Sopenharmony_ciand code:OpImageQuerySamples query properties of the image descriptor that
2991e5c31af7Sopenharmony_ciwould be accessed by a shader image operation.
2992e5c31af7Sopenharmony_ciifdef::VK_EXT_robustness2[]
2993e5c31af7Sopenharmony_ciThey return 0 if the bound descriptor is a null descriptor.
2994e5c31af7Sopenharmony_ciendif::VK_EXT_robustness2[]
2995e5c31af7Sopenharmony_ci
2996e5c31af7Sopenharmony_cicode:OpImageQuerySizeLod returns the size of the image level identified by
2997e5c31af7Sopenharmony_cithe code:Level code:of code:Detail operand.
2998e5c31af7Sopenharmony_ciIf that level does not exist in the image,
2999e5c31af7Sopenharmony_ciifdef::VK_EXT_robustness2[and the descriptor is not null,]
3000e5c31af7Sopenharmony_cithen the value returned is undefined:.
3001e5c31af7Sopenharmony_ci
3002e5c31af7Sopenharmony_ci
3003e5c31af7Sopenharmony_ci=== Lod Query
3004e5c31af7Sopenharmony_ci
3005e5c31af7Sopenharmony_cicode:OpImageQueryLod returns the Lod parameters that would be used in an
3006e5c31af7Sopenharmony_ciimage operation with the given image and coordinates.
3007e5c31af7Sopenharmony_ciifdef::VK_EXT_robustness2[]
3008e5c31af7Sopenharmony_ciIf the descriptor that would be accessed is a null descriptor then (0, 0) is
3009e5c31af7Sopenharmony_cireturned.
3010e5c31af7Sopenharmony_ciendif::VK_EXT_robustness2[]
3011e5c31af7Sopenharmony_ciifdef::VK_EXT_robustness2[Otherwise, the]
3012e5c31af7Sopenharmony_ciifndef::VK_EXT_robustness2[The]
3013e5c31af7Sopenharmony_cisteps described in this chapter are performed as if for
3014e5c31af7Sopenharmony_cicode:OpImageSampleImplicitLod, up to <<textures-lod-and-scale-factor>>.
3015e5c31af7Sopenharmony_ciThe return value is the vector [eq]#({lambda}', d~l~)#.
3016e5c31af7Sopenharmony_ciThese values may: be subject to implementation-specific maxima and minima
3017e5c31af7Sopenharmony_cifor very large, out-of-range values.
3018