16. Image Operations
16.1. Image Operations Overview
Vulkan Image Operations are operations performed by those SPIRV Image
Instructions which take an OpTypeImage
(representing a
VkImageView
) or OpTypeSampledImage
(representing a
(VkImageView
, VkSampler
) pair).
Read, write, and atomic operations also take texel coordinates as operands,
and return a value based on a neighborhood of texture elements (texels)
within the image.
Query operations return properties of the bound image or of the lookup
itself.
The “Depth” operand of OpTypeImage
is ignored.
Note
Texel is a term which is a combination of the words texture and element. Early interactive computer graphics supported texture operations on textures, a small subset of the image operations on images described here. The discrete samples remain essentially equivalent, however, so we retain the historical term texel to refer to them. 
Image Operations include the functionality of the following SPIRV Image Instructions:

OpImageSample*
andOpImageSparseSample*
read one or more neighboring texels of the image, and filter the texel values based on the state of the sampler.
Instructions with
ImplicitLod
in the name determine the LOD used in the sampling operation based on the coordinates used in neighboring fragments. 
Instructions with
ExplicitLod
in the name determine the LOD used in the sampling operation based on additional coordinates. 
Instructions with
Proj
in the name apply homogeneous projection to the coordinates.


OpImageFetch
andOpImageSparseFetch
return a single texel of the image. No sampler is used. 
OpImage*Gather
andOpImageSparse*Gather
read neighboring texels and return a single component of each. 
OpImageRead
(andOpImageSparseRead
) andOpImageWrite
read and write, respectively, a texel in the image. No sampler is used. 
OpImageSampleFootprintNV
identifies and returns information about the set of texels in the image that would be accessed by an equivalentOpImageSample*
instruction. 
OpImage*Dref*
instructions apply depth comparison on the texel values. 
OpImageSparse*
instructions additionally return a sparse residency code. 
OpImageQuerySize
,OpImageQuerySizeLod
,OpImageQueryLevels
, andOpImageQuerySamples
return properties of the image descriptor that would be accessed. The image itself is not accessed. 
OpImageQueryLod
returns the LOD parameters that would be used in a sample operation. The actual operation is not performed. 
OpImageWeightedSampleQCOM
reads a 2D neighborhood of texels and computes a weighted average using weight values from a separate weight texture. 
opImageBlockMatchSADQCOM
andopTextureBlockMatchSSD
compare 2D neighborhoods of texels from two textures. 
OpImageBoxFilterQCOM
reads a 2D neighborhood of texels and computes a weighted average of the texels. 
opImageBlockMatchWindowSADQCOM
andopImageBlockMatchWindowSSDQCOM
compare 2D neighborhoods of texels from two textures with the comparison repeated across a window region in the target texture. 
opImageBlockMatchGatherSADQCOM
andopImageBlockMatchWindowSSDQCOM
compares four 2D neighborhoods of texels from a target texture with a single 2D neighborhood in the reference texture. The R component of each comparison is gathered and returned in the output.
16.1.1. Texel Coordinate Systems
Images are addressed by texel coordinates. There are three texel coordinate systems:

normalized texel coordinates [0.0, 1.0]

unnormalized texel coordinates [0.0, width / height / depth)

integer texel coordinates [0, width / height / depth)
SPIRV OpImageFetch
, OpImageSparseFetch
, OpImageRead
,
OpImageSparseRead
,
opImageBlockMatchSADQCOM
, opImageBlockMatchSSDQCOM
,
opImageBlockMatchWindowSADQCOM
, opImageBlockMatchWindowSSDQCOM
,
and OpImageWrite
instructions use integer texel coordinates.
Other image instructions can use either normalized or unnormalized texel
coordinates (selected by the unnormalizedCoordinates
state of the
sampler used in the instruction), but there are
limitations on what operations, image
state, and sampler state is supported.
Normalized coordinates are logically
converted to unnormalized as part of
image operations, and certain steps are
only performed on normalized coordinates.
The array layer coordinate is always treated as unnormalized even when other
coordinates are normalized.
Normalized texel coordinates are referred to as (s,t,r,q,a), with the coordinates having the following meanings:

s: Coordinate in the first dimension of an image.

t: Coordinate in the second dimension of an image.

r: Coordinate in the third dimension of an image.

(s,t,r) are interpreted as a direction vector for Cube images.


q: Fourth coordinate, for homogeneous (projective) coordinates.

a: Coordinate for array layer.
The coordinates are extracted from the SPIRV operand based on the
dimensionality of the image variable and type of instruction.
For Proj
instructions, the components are in order (s, [t,] [r,]
q), with t and r being conditionally present based on the
Dim
of the image.
For nonProj
instructions, the coordinates are (s [,t] [,r]
[,a]), with t and r being conditionally present based on the
Dim
of the image and a being conditionally present based on the
Arrayed
property of the image.
Projective image instructions are not supported on Arrayed
images.
Unnormalized texel coordinates are referred to as (u,v,w,a), with the coordinates having the following meanings:

u: Coordinate in the first dimension of an image.

v: Coordinate in the second dimension of an image.

w: Coordinate in the third dimension of an image.

a: Coordinate for array layer.
Only the u and v coordinates are directly extracted from the
SPIRV operand, because only 1D and 2D (nonArrayed
) dimensionalities
support unnormalized coordinates.
The components are in order (u [,v]), with v being conditionally
present when the dimensionality is 2D.
When normalized coordinates are converted to unnormalized coordinates, all
four coordinates are used.
Integer texel coordinates are referred to as (i,j,k,l,n), with the coordinates having the following meanings:

i: Coordinate in the first dimension of an image.

j: Coordinate in the second dimension of an image.

k: Coordinate in the third dimension of an image.

l: Coordinate for array layer.

n: Index of the sample within the texel.
They are extracted from the SPIRV operand in order (i [,j] [,k] [,l]
[,n]), with j and k conditionally present based on the Dim
of the image, and l conditionally present based on the Arrayed
property of the image.
n is conditionally present and is taken from the Sample
image
operand.
If an accessed image was created from a view using
VkImageViewSlicedCreateInfoEXT and accessed through a
VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
descriptor, then the value of k
is incremented by VkImageViewSlicedCreateInfoEXT::sliceOffset
,
giving k ← sliceOffset + k.
The image’s accessible range in the third dimension is k < sliceOffset
+ sliceCount.
If VkImageViewSlicedCreateInfoEXT::sliceCount
is
VK_REMAINING_3D_SLICES_EXT
, the range is inherited from the image’s
depth extent as specified by Image Mip
Level Sizing.
For all coordinate types, unused coordinates are assigned a value of zero.
The Texel Coordinate Systems  For the example shown of an 8×4 texel two dimensional image.

Normalized texel coordinates:

The s coordinate goes from 0.0 to 1.0.

The t coordinate goes from 0.0 to 1.0.


Unnormalized texel coordinates:

The u coordinate within the range 0.0 to 8.0 is within the image, otherwise it is outside the image.

The v coordinate within the range 0.0 to 4.0 is within the image, otherwise it is outside the image.


Integer texel coordinates:

The i coordinate within the range 0 to 7 addresses texels within the image, otherwise it is outside the image.

The j coordinate within the range 0 to 3 addresses texels within the image, otherwise it is outside the image.


Also shown for linear filtering:

Given the unnormalized coordinates (u,v), the four texels selected are i_{0}j_{0}, i_{1}j_{0}, i_{0}j_{1}, and i_{1}j_{1}.

The fractions α and β.

Given the offset Δ_{i} and Δ_{j}, the four texels selected by the offset are i_{0}j'_{0}, i_{1}j'_{0}, i_{0}j'_{1}, and i_{1}j'_{1}.

Note
For formats with reducedresolution components, Δ_{i} and Δ_{j} are relative to the resolution of the highestresolution component, and therefore may be divided by two relative to the unnormalized coordinate space of the lowerresolution components. 
The Texel Coordinate Systems  For the example shown of an 8×4 texel two dimensional image.

Texel coordinates as above. Also shown for nearest filtering:

Given the unnormalized coordinates (u,v), the texel selected is ij.

Given the offset Δ_{i} and Δ_{j}, the texel selected by the offset is ij'.

For cornersampled images, the texel samples are located at the grid intersections instead of the texel centers.
16.2. Conversion Formulas
16.2.1. RGB to Shared Exponent Conversion
An RGB color (red, green, blue) is transformed to a shared exponent color (red_{shared}, green_{shared}, blue_{shared}, exp_{shared}) as follows:
First, the components (red, green, blue) are clamped to (red_{clamped}, green_{clamped}, blue_{clamped}) as:

red_{clamped} = max(0, min(sharedexp_{max}, red))

green_{clamped} = max(0, min(sharedexp_{max}, green))

blue_{clamped} = max(0, min(sharedexp_{max}, blue))
where:
Note
NaN, if supported, is handled as in 
The largest clamped component, max_{clamped} is determined:

max_{clamped} = max(red_{clamped}, green_{clamped}, blue_{clamped})
A preliminary shared exponent exp' is computed:
The shared exponent exp_{shared} is computed:
Finally, three integer values in the range 0 to 2^{N} are computed:
16.2.2. Shared Exponent to RGB
A shared exponent color (red_{shared}, green_{shared}, blue_{shared}, exp_{shared}) is transformed to an RGB color (red, green, blue) as follows:

$red=red_{shared}×2_{(exp_{shared}−B−N)}$

$green=green_{shared}×2_{(exp_{shared}−B−N)}$

$blue=blue_{shared}×2_{(exp_{shared}−B−N)}$
where:

N = 9 (number of mantissa bits per component)

B = 15 (exponent bias)
16.3. Texel Input Operations
Texel input instructions are SPIRV image instructions that read from an image. Texel input operations are a set of steps that are performed on state, coordinates, and texel values while processing a texel input instruction, and which are common to some or all texel input instructions. They include the following steps, which are performed in the listed order:
For texel input instructions involving multiple texels (for sampling or gathering), these steps are applied for each texel that is used in the instruction. Depending on the type of image instruction, other steps are conditionally performed between these steps or involving multiple coordinate or texel values.
If Chroma Reconstruction is implicit, Texel Filtering instead takes place during chroma reconstruction, before sampler Y′C_{B}C_{R} conversion occurs.
The operations described in block matching and weight image sampling are performed before Conversion to RGBA and Component swizzle.
16.3.1. Texel Input Validation Operations
Texel input validation operations inspect instruction/image/sampler state or coordinates, and in certain circumstances cause the texel value to be replaced or become undefined. There are a series of validations that the texel undergoes.
Instruction/Sampler/Image View Validation
There are a number of cases where a SPIRV instruction can mismatch with the sampler, the image view, or both, and a number of further cases where the sampler can mismatch with the image view. In such cases the value of the texel returned is undefined.
These cases include:

The sampler
borderColor
is an integer type and the image viewformat
is not one of the VkFormat integer types or a stencil component of a depth/stencil format. 
The sampler
borderColor
is a float type and the image viewformat
is not one of the VkFormat float types or a depth component of a depth/stencil format. 
The sampler
borderColor
is one of the opaque black colors (VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
orVK_BORDER_COLOR_INT_OPAQUE_BLACK
) and the image view VkComponentSwizzle for any of the VkComponentMapping components is not the identity swizzle, and VkPhysicalDeviceBorderColorSwizzleFeaturesEXT::borderColorSwizzleFromImage
feature is not enabled, and VkSamplerBorderColorComponentMappingCreateInfoEXT is not specified. 
VkSamplerBorderColorComponentMappingCreateInfoEXT::
components
, if specified, has a component swizzle that does not match the component swizzle of the image view, and either component swizzle is not a form of identity swizzle. 
VkSamplerBorderColorComponentMappingCreateInfoEXT::
srgb
, if specified, does not match the sRGB encoding of the image view. 
The sampler
borderColor
is a custom color (VK_BORDER_COLOR_FLOAT_CUSTOM_EXT
orVK_BORDER_COLOR_INT_CUSTOM_EXT
) and the supplied VkSamplerCustomBorderColorCreateInfoEXT::customBorderColor
is outside the bounds of the values representable in the image view’sformat
. 
The sampler
borderColor
is a custom color (VK_BORDER_COLOR_FLOAT_CUSTOM_EXT
orVK_BORDER_COLOR_INT_CUSTOM_EXT
) and the image view VkComponentSwizzle for any of the VkComponentMapping components is not the identity swizzle, and VkPhysicalDeviceBorderColorSwizzleFeaturesEXT::borderColorSwizzleFromImage
feature is not enabled, and VkSamplerBorderColorComponentMappingCreateInfoEXT is not specified. 
The VkImageLayout of any subresource in the image view does not match the VkDescriptorImageInfo::
imageLayout
used to write the image descriptor. 
The SPIRV Image Format is not compatible with the image view’s
format
. 
The sampler
unnormalizedCoordinates
isVK_TRUE
and any of the limitations of unnormalized coordinates are violated. 
The sampler was created with
flags
containingVK_SAMPLER_CREATE_SUBSAMPLED_BIT_EXT
and the image was not created withflags
containingVK_IMAGE_CREATE_SUBSAMPLED_BIT_EXT
. 
The sampler was not created with
flags
containingVK_SAMPLER_CREATE_SUBSAMPLED_BIT_EXT
and the image was created withflags
containingVK_IMAGE_CREATE_SUBSAMPLED_BIT_EXT
. 
The sampler was created with
flags
containingVK_SAMPLER_CREATE_SUBSAMPLED_BIT_EXT
and is used with a function that is notOpImageSampleImplicitLod
orOpImageSampleExplicitLod
, or is used with operandsOffset
orConstOffsets
. 
The SPIRV instruction is one of the
OpImage*Dref*
instructions and the samplercompareEnable
isVK_FALSE

The SPIRV instruction is not one of the
OpImage*Dref*
instructions and the samplercompareEnable
isVK_TRUE

The SPIRV instruction is one of the
OpImage*Dref*
instructions, the image viewformat
is one of the depth/stencil formats, and the image view aspect is notVK_IMAGE_ASPECT_DEPTH_BIT
. 
The SPIRV instruction’s image variable’s properties are not compatible with the image view:

Rules for
viewType
:
VK_IMAGE_VIEW_TYPE_1D
must haveDim
= 1D,Arrayed
= 0,MS
= 0. 
VK_IMAGE_VIEW_TYPE_2D
must haveDim
= 2D,Arrayed
= 0. 
VK_IMAGE_VIEW_TYPE_3D
must haveDim
= 3D,Arrayed
= 0,MS
= 0. 
VK_IMAGE_VIEW_TYPE_CUBE
must haveDim
= Cube,Arrayed
= 0,MS
= 0. 
VK_IMAGE_VIEW_TYPE_1D_ARRAY
must haveDim
= 1D,Arrayed
= 1,MS
= 0. 
VK_IMAGE_VIEW_TYPE_2D_ARRAY
must haveDim
= 2D,Arrayed
= 1. 
VK_IMAGE_VIEW_TYPE_CUBE_ARRAY
must haveDim
= Cube,Arrayed
= 1,MS
= 0.


If the image was created with VkImageCreateInfo::
samples
equal toVK_SAMPLE_COUNT_1_BIT
, the instruction must haveMS
= 0. 
If the image was created with VkImageCreateInfo::
samples
not equal toVK_SAMPLE_COUNT_1_BIT
, the instruction must haveMS
= 1. 
If the
Sampled
Type
of theOpTypeImage
does not match the SPIRV Type. 
If the signedness of any read or sample operation does not match the signedness of the image’s format.


If the image was created with VkImageCreateInfo::
flags
containingVK_IMAGE_CREATE_CORNER_SAMPLED_BIT_NV
, the sampler addressing modes must only use a VkSamplerAddressMode ofVK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE
. 
The SPIRV instruction is
OpImageSampleFootprintNV
withDim
= 2D andaddressModeU
oraddressModeV
in the sampler is notVK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE
. 
The SPIRV instruction is
OpImageSampleFootprintNV
withDim
= 3D andaddressModeU
,addressModeV
, oraddressModeW
in the sampler is notVK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE
. 
The sampler was created with a specified VkSamplerCustomBorderColorCreateInfoEXT::
format
which does not match the VkFormat of the image view(s) it is sampling. 
The sampler is sampling an image view of
VK_FORMAT_B4G4R4A4_UNORM_PACK16
,VK_FORMAT_B5G6R5_UNORM_PACK16
, orVK_FORMAT_B5G5R5A1_UNORM_PACK16
format without a specified VkSamplerCustomBorderColorCreateInfoEXT::format
.
Only OpImageSample*
and OpImageSparseSample*
can be used with a
sampler or image view that enables sampler
Y′C_{B}C_{R} conversion.
OpImageFetch
, OpImageSparseFetch
, OpImage*Gather
, and
OpImageSparse*Gather
must not be used with a sampler or image view
that enables sampler Y′C_{B}C_{R} conversion.
The ConstOffset
and Offset
operands must not be used with a
sampler or image view that enables sampler
Y′C_{B}C_{R} conversion.
If the underlying VkImage
format has an X component in its format
description, undefined values are read from those bits.
Note
If the 
Note
Some implementations will return undefined values in the case where a
sampler uses a VkSamplerAddressMode of
This behavior was not tested prior to Vulkan conformance test suite version 1.3.8.0. Affected implementations will have a conformance test waiver for this issue. 
Integer Texel Coordinate Validation
Integer texel coordinates are validated against the size of the image level, and the number of layers and number of samples in the image. For SPIRV instructions that use integer texel coordinates, this is performed directly on the integer coordinates. For instructions that use normalized or unnormalized texel coordinates, this is performed on the coordinates that result after conversion to integer texel coordinates.
If the integer texel coordinates do not satisfy all of the conditions

0 ≤ i < w_{s}

0 ≤ j < h_{s}

0 ≤ k < d_{s}

0 ≤ l < layers

0 ≤ n < samples
where:

w_{s} = width of the image level

h_{s} = height of the image level

d_{s} = depth of the image level

layers = number of layers in the image

samples = number of samples per texel in the image
then the texel fails integer texel coordinate validation.
There are four cases to consider:

Valid Texel Coordinates

If the texel coordinates pass validation (that is, the coordinates lie within the image),
then the texel value comes from the value in image memory.


Border Texel

If the texel coordinates fail validation, and

If the read is the result of an image sample instruction or image gather instruction, and

If the image is not a cube image, or if a sampler created with
VK_SAMPLER_CREATE_NON_SEAMLESS_CUBE_MAP_BIT_EXT
is used,
then the texel is a border texel and texel replacement is performed.


Invalid Texel

If the texel coordinates fail validation, and

If the read is the result of an image fetch instruction, image read instruction, or atomic instruction,
then the texel is an invalid texel and texel replacement is performed.


Cube Map Edge or Corner
Otherwise the texel coordinates lie beyond the edges or corners of the selected cube map face, and Cube map edge handling is performed.
Cube Map Edge Handling
If the texel coordinates lie beyond the edges or corners of the selected
cube map face (as described in the prior section), the following steps are
performed.
Note that this does not occur when using VK_FILTER_NEAREST
filtering
within a mip level, since VK_FILTER_NEAREST
is treated as using
VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE
.

Cube Map Edge Texel

If the texel lies beyond the selected cube map face in either only i or only j, then the coordinates (i,j) and the array layer l are transformed to select the adjacent texel from the appropriate neighboring face.


Cube Map Corner Texel

If the texel lies beyond the selected cube map face in both i and j, then there is no unique neighboring face from which to read that texel. The texel should be replaced by the average of the three values of the adjacent texels in each incident face. However, implementations may replace the cube map corner texel by other methods. The methods are subject to the constraint that for linear filtering if the three available texels have the same value, the resulting filtered texel must have that value, and for cubic filtering if the twelve available samples have the same value, the resulting filtered texel must have that value.

Sparse Validation
If the texel reads from an unbound region of a sparse image, the texel is a sparse unbound texel, and processing continues with texel replacement.
Layout Validation
If all planes of a disjoint multiplanar image are not in the same image layout, the image must not be sampled with sampler Y′C_{B}C_{R} conversion enabled.
16.3.2. Format Conversion
Texels undergo a format conversion from the VkFormat of the image view to a vector of either floating point or signed or unsigned integer components, with the number of components based on the number of components present in the format.

Color formats have one, two, three, or four components, according to the format.

Depth/stencil formats are one component. The depth or stencil component is selected by the
aspectMask
of the image view.
Each component is converted based on its type and size (as defined in the Format Definition section for each VkFormat), using the appropriate equations in 16Bit FloatingPoint Numbers, Unsigned 11Bit FloatingPoint Numbers, Unsigned 10Bit FloatingPoint Numbers, FixedPoint Data Conversion, and Shared Exponent to RGB. Signed integer components smaller than 32 bits are signextended.
If the image view format is sRGB, the color components are first converted as if they are UNORM, and then sRGB to linear conversion is applied to the R, G, and B components as described in the “sRGB EOTF” section of the Khronos Data Format Specification. The A component, if present, is unchanged.
If
VkSamplerYcbcrConversionYcbcrDegammaCreateInfoQCOM::enableYDegamma
is equal to VK_TRUE
, then sRGB to linear conversion is applied to the
G component as described in the “sRGB EOTF” section of the
Khronos Data Format Specification.
If
VkSamplerYcbcrConversionYcbcrDegammaCreateInfoQCOM::enableCbCrDegamma
is equal to VK_TRUE
, then sRGB to linear conversion is applied to the
R and B components as described in the “sRGB EOTF” section of the
Khronos Data Format Specification.
The A component, if present, is unchanged.
If the image view format is blockcompressed, then the texel value is first decoded, then converted based on the type and number of components defined by the compressed format.
16.3.3. Texel Replacement
A texel is replaced if it is one (and only one) of:

a border texel,

an invalid texel, or

a sparse unbound texel.
Border texels are replaced with a value based on the image format and the
borderColor
of the sampler.
The border color is:
Sampler borderColor 
Corresponding Border Color 


[B_{r}, B_{g}, B_{b}, B_{a}] = [0.0, 0.0, 0.0, 0.0] 

[B_{r}, B_{g}, B_{b}, B_{a}] = [0.0, 0.0, 0.0, 1.0] 

[B_{r}, B_{g}, B_{b}, B_{a}] = [1.0, 1.0, 1.0, 1.0] 

[B_{r}, B_{g}, B_{b}, B_{a}] = [0, 0, 0, 0] 

[B_{r}, B_{g}, B_{b}, B_{a}] = [0, 0, 0, 1] 

[B_{r}, B_{g}, B_{b}, B_{a}] = [1, 1, 1, 1] 

[B_{r}, B_{g}, B_{b}, B_{a}] = [U_{r}, U_{g}, U_{b}, U_{a}] 

[B_{r}, B_{g}, B_{b}, B_{a}] = [U_{r}, U_{g}, U_{b}, U_{a}] 
The custom border color (U) may be rounded by implementations prior
to texel replacement, but the error introduced by such a rounding must not
exceed one ULP of the image’s format
.
Note
The names 
This is substituted for the texel value by replacing the number of components in the image format
Texel Aspect or Format  Component Assignment 

Depth aspect 
D = B_{r} 
Stencil aspect 
S = B_{r}† 
One component color format 
Color_{r} = B_{r} 
Two component color format 
[Color_{r},Color_{g}] = [B_{r},B_{g}] 
Three component color format 
[Color_{r},Color_{g},Color_{b}] = [B_{r},B_{g},B_{b}] 
Four component color format 
[Color_{r},Color_{g},Color_{b},Color_{a}] = [B_{r},B_{g},B_{b},B_{a}] 
Single component alpha format 
[Color_{r},Color_{g},Color_{b}, Color_{a}] = [0,0,0,B_{a}] 
† S = B_{g} may be substituted as the replacement method by the
implementation when VkSamplerCreateInfo::borderColor
is
VK_BORDER_COLOR_INT_CUSTOM_EXT
and
VkSamplerCustomBorderColorCreateInfoEXT::format
is
VK_FORMAT_UNDEFINED
.
Implementations should use S = B_{r} as the replacement method.
The value returned by a read of an invalid texel is undefined, unless that
read operation is from a buffer resource and the robustBufferAccess
feature is enabled.
In that case, an invalid texel is replaced as described by the
robustBufferAccess
feature.
If the access is to an image resource and the x, y, z, or layer coordinate
validation fails and
the robustImageAccess
feature is
enabled, then zero must be returned for the R, G, and B components, if
present.
Either zero or one must be returned for the A component, if present.
If
If the robustImageAccess2
feature is
enabled, zero values must be returned.
If only the sample index was invalid, the values returned are undefined.
Additionally, if the robustImageAccess
feature is enabled,
but the robustImageAccess2
feature is
not,
any invalid texels may be expanded to four components prior to texel
replacement.
This means that components not present in the image format may be replaced
with 0 or may undergo conversion to RGBA as
normal.
Loads from a null descriptor return a four component color value of all zeros. However, for storage images and storage texel buffers using an explicit SPIRV Image Format, loads from a null descriptor may return an alpha value of 1 (float or integer, depending on format) if the format does not include alpha.
If the
VkPhysicalDeviceSparseProperties::residencyNonResidentStrict
property is VK_TRUE
, a sparse unbound texel is replaced with 0 or 0.0
values for integer and floatingpoint components of the image format,
respectively.
If residencyNonResidentStrict
is VK_FALSE
, the value of the
sparse unbound texel is undefined.
16.3.4. Depth Compare Operation
If the image view has a depth/stencil format, the depth component is
selected by the aspectMask
, and the operation is an OpImage*Dref*
instruction, a depth comparison is performed.
The result is 1.0 if the comparison evaluates to true, and
0.0 otherwise.
This value replaces the depth component D.
The compare operation is selected by the VkCompareOp value set by
VkSamplerCreateInfo::compareOp
.
The reference value from the SPIRV operand D_{ref} and the texel depth
value D_{tex} are used as the reference and test values,
respectively, in that operation.
If the image being sampled has an unsigned normalized fixedpoint format, then D_{ref} is clamped to [0,1] before the compare operation.
16.3.5. Conversion to RGBA
The texel is expanded from one, two, or three components to four components based on the image base color:
Texel Aspect or Format  RGBA Color 

Depth aspect 
[Color_{r},Color_{g},Color_{b}, Color_{a}] = [D,0,0,one] 
Stencil aspect 
[Color_{r},Color_{g},Color_{b}, Color_{a}] = [S,0,0,one] 
One component color format 
[Color_{r},Color_{g},Color_{b}, Color_{a}] = [Color_{r},0,0,one] 
Two component color format 
[Color_{r},Color_{g},Color_{b}, Color_{a}] = [Color_{r},Color_{g},0,one] 
Three component color format 
[Color_{r},Color_{g},Color_{b}, Color_{a}] = [Color_{r},Color_{g},Color_{b},one] 
Four component color format 
[Color_{r},Color_{g},Color_{b}, Color_{a}] = [Color_{r},Color_{g},Color_{b},Color_{a}] 
One alpha component color format 
[Color_{r},Color_{g},Color_{b}, Color_{a}] = [0,0,0,Color_{a}] 
where one = 1.0f for floatingpoint formats and depth aspects, and one = 1 for integer formats and stencil aspects.
16.3.6. Component Swizzle
All texel input instructions apply a swizzle based on:

the VkComponentSwizzle enums in the
components
member of the VkImageViewCreateInfo structure for the image being read if sampler Y′C_{B}C_{R} conversion is not enabled, and 
the VkComponentSwizzle enums in the
components
member of the VkSamplerYcbcrConversionCreateInfo structure for the sampler Y′C_{B}C_{R} conversion if sampler Y′C_{B}C_{R} conversion is enabled.
The swizzle can rearrange the components of the texel, or substitute zero or one for any components. It is defined as follows for each color component:
where:
If the border color is one of the VK_BORDER_COLOR_*_OPAQUE_BLACK
enums
and the VkComponentSwizzle is not the
identity swizzle for all
components, the value of the texel after swizzle is undefined.
If the image view has a depth/stencil format and the
VkComponentSwizzle is VK_COMPONENT_SWIZZLE_ONE
, and
VkPhysicalDeviceMaintenance5PropertiesKHR
::depthStencilSwizzleOneSupport
is not set to VK_TRUE
, the value of the texel after swizzle is
undefined.
16.3.7. Sparse Residency
OpImageSparse*
instructions return a structure which includes a
residency code indicating whether any texels accessed by the instruction
are sparse unbound texels.
This code can be interpreted by the OpImageSparseTexelsResident
instruction which converts the residency code to a boolean value.
16.3.8. Chroma Reconstruction
In some color models, the color representation is defined in terms of monochromatic light intensity (often called “luma”) and color differences relative to this intensity, often called “chroma”. It is common for color models other than RGB to represent the chroma components at lower spatial resolution than the luma component. This approach is used to take advantage of the eye’s lower spatial sensitivity to color compared with its sensitivity to brightness. Less commonly, the same approach is used with additive color, since the green component dominates the eye’s sensitivity to light intensity and the spatial sensitivity to color introduced by red and blue is lower.
Lowerresolution components are “downsampled” by resizing them to a lower spatial resolution than the component representing luminance. This process is also commonly known as “chroma subsampling”. There is one luminance sample in each texture texel, but each chrominance sample may be shared among several texels in one or both texture dimensions.

“
_444
” formats do not spatially downsample chroma values compared with luma: there are unique chroma samples for each texel. 
“
_422
” formats have downsampling in the x dimension (corresponding to u or s coordinates): they are sampled at half the resolution of luma in that dimension. 
“
_420
” formats have downsampling in the x dimension (corresponding to u or s coordinates) and the y dimension (corresponding to v or t coordinates): they are sampled at half the resolution of luma in both dimensions.
The process of reconstructing a full color value for texture access involves accessing both chroma and luma values at the same location. To generate the color accurately, the values of the lowerresolution components at the location of the luma samples must be reconstructed from the lowerresolution sample locations, an operation known here as “chroma reconstruction” irrespective of the actual color model.
The location of the chroma samples relative to the luma coordinates is
determined by the xChromaOffset
and yChromaOffset
members of the
VkSamplerYcbcrConversionCreateInfo structure used to create the
sampler Y′C_{B}C_{R} conversion.
The following diagrams show the relationship between unnormalized (u,v) coordinates and (i,j) integer texel positions in the luma component (shown in black, with circles showing integer sample positions) and the texel coordinates of reducedresolution chroma components, shown as crosses in red.
Note
If the chroma values are reconstructed at the locations of the luma samples
by means of interpolation, chroma samples from outside the image bounds are
needed; these are determined according to Wrapping Operation.
These diagrams represent this by showing the bounds of the “chroma texel”
extending beyond the image bounds, and including additional chroma sample
positions where required for interpolation.
The limits of a sample for 
Reconstruction is implemented in one of two ways:
If the format of the image that is to be sampled sets
VK_FORMAT_FEATURE_SAMPLED_IMAGE_YCBCR_CONVERSION_CHROMA_RECONSTRUCTION_EXPLICIT_BIT
,
or the VkSamplerYcbcrConversionCreateInfo’s
forceExplicitReconstruction
is set to VK_TRUE
, reconstruction is
performed as an explicit step independent of filtering, described in the
Explicit Reconstruction section.
If the format of the image that is to be sampled does not set
VK_FORMAT_FEATURE_SAMPLED_IMAGE_YCBCR_CONVERSION_CHROMA_RECONSTRUCTION_EXPLICIT_BIT
and if the VkSamplerYcbcrConversionCreateInfo’s
forceExplicitReconstruction
is set to VK_FALSE
, reconstruction
is performed as an implicit part of filtering prior to color model
conversion, with no separate postconversion texel filtering step, as
described in the Implicit Reconstruction
section.
Explicit Reconstruction

If the
chromaFilter
member of the VkSamplerYcbcrConversionCreateInfo structure isVK_FILTER_NEAREST
:
If the format’s R and B components are reduced in resolution in just width by a factor of two relative to the G component (i.e. this is a “
_422
” format), the $τ_{ijk}[level]$ values accessed by texel filtering are reconstructed as follows:$τ_{R}(i,j)τ_{B}(i,j) =τ_{R}(⌊i×0.5⌋,j)[level]=τ_{B}(⌊i×0.5⌋,j)[level] $ 
If the format’s R and B components are reduced in resolution in width and height by a factor of two relative to the G component (i.e. this is a “
_420
” format), the $τ_{ijk}[level]$ values accessed by texel filtering are reconstructed as follows:$τ_{R}(i,j)τ_{B}(i,j) =τ_{R}(⌊i×0.5⌋,⌊j×0.5⌋)[level]=τ_{B}(⌊i×0.5⌋,⌊j×0.5⌋)[level] $NotexChromaOffset
andyChromaOffset
have no effect ifchromaFilter
isVK_FILTER_NEAREST
for explicit reconstruction.


If the
chromaFilter
member of the VkSamplerYcbcrConversionCreateInfo structure isVK_FILTER_LINEAR
:
If the format’s R and B components are reduced in resolution in just width by a factor of two relative to the G component (i.e. this is a “
_422
” format):
If
xChromaOffset
isVK_CHROMA_LOCATION_COSITED_EVEN
:$τ_{RB}(i,j)=⎩⎪⎪⎨⎪⎪⎧ τ_{RB}(⌊i×0.5⌋,j)[level],0.5×τ_{RB}(⌊i×0.5⌋,j)[level]+0.5×τ_{RB}(⌊i×0.5⌋+1,j)[level], 0.5×i=⌊0.5×i⌋0.5×i =⌊0.5×i⌋ $ 
If
xChromaOffset
isVK_CHROMA_LOCATION_MIDPOINT
:$τ_{RB}(i,j)=⎩⎪⎪⎪⎪⎨⎪⎪⎪⎪⎧ 0.25×τ_{RB}(⌊i×0.5⌋−1,j)[level]+0.75×τ_{RB}(⌊i×0.5⌋,j)[level],0.75×τ_{RB}(⌊i×0.5⌋,j)[level]+0.25×τ_{RB}(⌊i×0.5⌋+1,j)[level], 0.5×i=⌊0.5×i⌋0.5×i =⌊0.5×i⌋ $


If the format’s R and B components are reduced in resolution in width and height by a factor of two relative to the G component (i.e. this is a “
_420
” format), a similar relationship applies. Due to the number of options, these formulae are expressed more concisely as follows:$i_{RB}j_{RB}i_{floor}j_{floor}i_{frac}j_{frac} ={0.5×(i)0.5×(i−0.5) xChromaOffset = COSITED_EVENxChromaOffset = MIDPOINT ={0.5×(j)0.5×(j−0.5) yChromaOffset = COSITED_EVENyChromaOffset = MIDPOINT =⌊i_{RB}⌋=⌊j_{RB}⌋=i_{RB}−i_{floor}=j_{RB}−j_{floor} $$τ_{RB}(i,j)= τ_{RB}(i_{floor},j_{floor})[level]τ_{RB}(1+i_{floor},j_{floor})[level]τ_{RB}(i_{floor},1+j_{floor})[level]τ_{RB}(1+i_{floor},1+j_{floor})[level] ×××× (1−i_{frac})(i_{frac})(1−i_{frac})(i_{frac}) ×××× (1−j_{frac})(1−j_{frac})(j_{frac})(j_{frac}) +++ $

Note
In the case where the texture itself is bilinearly interpolated as described
in Texel Filtering, thus requiring four
fullcolor samples for the filtering operation, and where the reconstruction
of these samples uses bilinear interpolation in the chroma components due to

Implicit Reconstruction
Implicit reconstruction takes place by the samples being interpolated, as
required by the filter settings of the sampler, except that
chromaFilter
takes precedence for the chroma samples.
If chromaFilter
is VK_FILTER_NEAREST
, an implementation may
behave as if xChromaOffset
and yChromaOffset
were both
VK_CHROMA_LOCATION_MIDPOINT
, irrespective of the values set.
Note
This will not have any visible effect if the locations of the luma samples coincide with the location of the samples used for rasterization. 
The sample coordinates are adjusted by the downsample factor of the component (such that, for example, the sample coordinates are divided by two if the component has a downsample factor of two relative to the luma component):
16.3.9. Sampler Y′C_{B}C_{R} Conversion
Sampler Y′C_{B}C_{R} conversion performs the following operations, which an implementation may combine into a single mathematical operation:
Sampler Y′C_{B}C_{R} Range Expansion
Sampler Y′C_{B}C_{R} range expansion is applied to color component values after all texel input operations which are not specific to sampler Y′C_{B}C_{R} conversion. For example, the input values to this stage have been converted using the normal format conversion rules.
The input values to this stage may have been converted using sRGB to linear
conversion if ycbcrDegamma
is enabled.
Sampler Y′C_{B}C_{R} range expansion is not applied if ycbcrModel
is
VK_SAMPLER_YCBCR_MODEL_CONVERSION_RGB_IDENTITY
.
That is, the shader receives the vector C'_{rgba} as output by the Component
Swizzle stage without further modification.
For other values of ycbcrModel
, range expansion is applied to the
texel component values output by the Component
Swizzle defined by the components
member of
VkSamplerYcbcrConversionCreateInfo.
Range expansion applies independently to each component of the image.
For the purposes of range expansion and Y′C_{B}C_{R} model conversion, the R and
B components contain color difference (chroma) values and the G component
contains luma.
The A component is not modified by sampler Y′C_{B}C_{R} range expansion.
The range expansion to be applied is defined by the ycbcrRange
member
of the VkSamplerYcbcrConversionCreateInfo structure:

If
ycbcrRange
isVK_SAMPLER_YCBCR_RANGE_ITU_FULL
, the following transformations are applied:$Y_{′}C_{B}C_{R} =C_{rgba}[G]=C_{rgba}[B]−(2_{n})−12_{(n−1)} =C_{rgba}[R]−(2_{n})−12_{(n−1)} $NoteThese formulae correspond to the “full range” encoding in the “Quantization schemes” chapter of the Khronos Data Format Specification.
Should any future amendments be made to the ITU specifications from which these equations are derived, the formulae used by Vulkan may also be updated to maintain parity.

If
ycbcrRange
isVK_SAMPLER_YCBCR_RANGE_ITU_NARROW
, the following transformations are applied:$Y_{′}C_{B}C_{R} =219×2_{n−8}C_{rgba}[G]×(2_{n}−1)−16×2_{n−8} =224×2_{n−8}C_{rgba}[B]×(2_{n}−1)−128×2_{n−8} =224×2_{n−8}C_{rgba}[R]×(2_{n}−1)−128×2_{n−8} $NoteThese formulae correspond to the “narrow range” encoding in the “Quantization schemes” chapter of the Khronos Data Format Specification.

n is the bitdepth of the components in the format.
The precision of the operations performed during range expansion must be at least that of the source format.
An implementation may clamp the results of these range expansion operations such that Y′ falls in the range [0,1], and/or such that C_{B} and C_{R} fall in the range [0.5,0.5].
Sampler Y′C_{B}C_{R} Model Conversion
The rangeexpanded values are converted between color models, according to
the color model conversion specified in the ycbcrModel
member:
VK_SAMPLER_YCBCR_MODEL_CONVERSION_RGB_IDENTITY

The color components are not modified by the color model conversion since they are assumed already to represent the desired color model in which the shader is operating; Y′C_{B}C_{R} range expansion is also ignored.
VK_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_IDENTITY

The color components are not modified by the color model conversion and are assumed to be treated as though in Y′C_{B}C_{R} form both in memory and in the shader; Y′C_{B}C_{R} range expansion is applied to the components as for other Y′C_{B}C_{R} models, with the vector (C_{R},Y′,C_{B},A) provided to the shader.
VK_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_709

The color components are transformed from a Y′C_{B}C_{R} representation to an R′G′B′ representation as described in the “BT.709 Y′C_{B}C_{R} conversion” section of the Khronos Data Format Specification.
VK_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_601

The color components are transformed from a Y′C_{B}C_{R} representation to an R′G′B′ representation as described in the “BT.601 Y′C_{B}C_{R} conversion” section of the Khronos Data Format Specification.
VK_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_2020

The color components are transformed from a Y′C_{B}C_{R} representation to an R′G′B′ representation as described in the “BT.2020 Y′C_{B}C_{R} conversion” section of the Khronos Data Format Specification.
In this operation, each output component is dependent on each input component.
An implementation may clamp the R′G′B′ results of these conversions to the range [0,1].
The precision of the operations performed during model conversion must be at least that of the source format.
The alpha component is not modified by these model conversions.
Note
Sampling operations in a nonlinear color space can introduce color and intensity shifts at sharp transition boundaries. To avoid this issue, the technically precise color correction sequence described in the “Introduction to Color Conversions” chapter of the Khronos Data Format Specification may be performed as follows:
The additional calculations and, especially, additional number of sampling
operations in the If 
16.4. Texel Output Operations
Texel output instructions are SPIRV image instructions that write to an image. Texel output operations are a set of steps that are performed on state, coordinates, and texel values while processing a texel output instruction, and which are common to some or all texel output instructions. They include the following steps, which are performed in the listed order:
16.4.1. Texel Output Validation Operations
Texel output validation operations inspect instruction/image state or coordinates, and in certain circumstances cause the write to have no effect. There are a series of validations that the texel undergoes.
Texel Format Validation
If the image format of the OpTypeImage
is not
compatible with the VkImageView
’s
format
, the write causes the contents of the image’s memory to become
undefined.
Texel Type Validation
If the Sampled
Type
of the OpTypeImage
does not match the
SPIRV Type, the write causes the value of the texel to
become undefined.
For integer types, if the signedness of the
access does not match the signedness of the accessed resource, the write
causes the value of the texel to become undefined.
16.4.2. Integer Texel Coordinate Validation
The integer texel coordinates are validated according to the same rules as for texel input coordinate validation.
If the texel fails integer texel coordinate validation, then the write has no effect.
16.4.3. Sparse Texel Operation
If the texel attempts to write to an unbound region of a sparse image, the
texel is a sparse unbound texel.
In such a case, if the
VkPhysicalDeviceSparseProperties::residencyNonResidentStrict
property is VK_TRUE
, the sparse unbound texel write has no effect.
If residencyNonResidentStrict
is VK_FALSE
, the write may have a
side effect that becomes visible to other accesses to unbound texels in any
resource, but will not be visible to any device memory allocated by the
application.
16.4.4. Texel Output Format Conversion
If the image format is sRGB, a linear to sRGB conversion is applied to the R, G, and B components as described in the “sRGB EOTF” section of the Khronos Data Format Specification. The A component, if present, is unchanged.
Texels then undergo a format conversion from the floating point, signed, or unsigned integer type of the texel data to the VkFormat of the image view. If the number of components in the texel data is larger than the number of components in the format, additional components are discarded.
Each component is converted based on its type and size (as defined in the Format Definition section for each VkFormat). Floatingpoint outputs are converted as described in FloatingPoint Format Conversions and FixedPoint Data Conversion. Integer outputs are converted such that their value is preserved. The converted value of any integer that cannot be represented in the target format is undefined.
If the VkImageView
format has an X component in its format
description, undefined values are written to those bits.
If the underlying VkImage
format has an X component in its format
description, undefined values are also written to those bits, even if
result format conversion produces a valid value for those bits because the
VkImageView
format is different.
16.5. Normalized Texel Coordinate Operations
If the image sampler instruction provides normalized texel coordinates, some of the following operations are performed.
16.5.1. Projection Operation
For Proj
image operations, the normalized texel coordinates
(s,t,r,q,a) and (if present) the D_{ref} coordinate are
transformed as follows:
16.5.2. Derivative Image Operations
Derivatives are used for LOD selection.
These derivatives are either implicit (in an ImplicitLod
image
instruction in a fragment shader) or explicit (provided explicitly by shader
to the image instruction in any shader).
For implicit derivatives image instructions, the derivatives of texel coordinates are calculated in the same manner as derivative operations. That is:
Partial derivatives not defined above for certain image dimensionalities are set to zero.
For explicit LOD image instructions, if the optional SPIRV operand
Grad
is provided, then the operand values are used for the derivatives.
The number of components present in each derivative for a given image
dimensionality matches the number of partial derivatives computed above.
If the optional SPIRV operand Lod
is provided, then derivatives are
set to zero, the cube map derivative transformation is skipped, and the
scale factor operation is skipped.
Instead, the floating point scalar coordinate is directly assigned to
λ_{base} as described in LOD Operation.
If the image or sampler object used by an implicit derivative image
instruction is not uniform across the quad and
quadDivergentImplicitLod
is not
supported, then the derivative and LOD values are undefined.
Implicit derivatives are welldefined when the image and sampler and control
flow are uniform across the quad, even if they diverge between different
quads.
If quadDivergentImplicitLod
is
supported, then derivatives and implicit LOD values are welldefined even if
the image or sampler object are not uniform within a quad.
The derivatives are computed as specified above, and the implicit LOD
calculation proceeds for each shader invocation using its respective image
and sampler object.
16.5.3. Cube Map Face Selection and Transformations
For cube map image instructions, the (s,t,r) coordinates are treated as a direction vector (r_{x},r_{y},r_{z}). The direction vector is used to select a cube map face. The direction vector is transformed to a perface texel coordinate system (s_{face},t_{face}), The direction vector is also used to transform the derivatives to perface derivatives.
16.5.4. Cube Map Face Selection
The direction vector selects one of the cube map’s faces based on the largest magnitude coordinate direction (the major axis direction). Since two or more coordinates can have identical magnitude, the implementation must have rules to disambiguate this situation.
The rules should have as the first rule that r_{z} wins over r_{y} and r_{x}, and the second rule that r_{y} wins over r_{x}. An implementation may choose other rules, but the rules must be deterministic and depend only on (r_{x},r_{y},r_{z}).
The layer number (corresponding to a cube map face), the coordinate selections for s_{c}, t_{c}, r_{c}, and the selection of derivatives, are determined by the major axis direction as specified in the following two tables.
Major Axis Direction  Layer Number  Cube Map Face  s_{c}  t_{c}  r_{c} 

+r_{x} 
0 
Positive X 
r_{z} 
r_{y} 
r_{x} 
r_{x} 
1 
Negative X 
+r_{z} 
r_{y} 
r_{x} 
+r_{y} 
2 
Positive Y 
+r_{x} 
+r_{z} 
r_{y} 
r_{y} 
3 
Negative Y 
+r_{x} 
r_{z} 
r_{y} 
+r_{z} 
4 
Positive Z 
+r_{x} 
r_{y} 
r_{z} 
r_{z} 
5 
Negative Z 
r_{x} 
r_{y} 
r_{z} 
Major Axis Direction  ∂s_{c} / ∂x  ∂s_{c} / ∂y  ∂t_{c} / ∂x  ∂t_{c} / ∂y  ∂r_{c} / ∂x  ∂r_{c} / ∂y 

+r_{x} 
∂r_{z} / ∂x 
∂r_{z} / ∂y 
∂r_{y} / ∂x 
∂r_{y} / ∂y 
+∂r_{x} / ∂x 
+∂r_{x} / ∂y 
r_{x} 
+∂r_{z} / ∂x 
+∂r_{z} / ∂y 
∂r_{y} / ∂x 
∂r_{y} / ∂y 
∂r_{x} / ∂x 
∂r_{x} / ∂y 
+r_{y} 
+∂r_{x} / ∂x 
+∂r_{x} / ∂y 
+∂r_{z} / ∂x 
+∂r_{z} / ∂y 
+∂r_{y} / ∂x 
+∂r_{y} / ∂y 
r_{y} 
+∂r_{x} / ∂x 
+∂r_{x} / ∂y 
∂r_{z} / ∂x 
∂r_{z} / ∂y 
∂r_{y} / ∂x 
∂r_{y} / ∂y 
+r_{z} 
+∂r_{x} / ∂x 
+∂r_{x} / ∂y 
∂r_{y} / ∂x 
∂r_{y} / ∂y 
+∂r_{z} / ∂x 
+∂r_{z} / ∂y 
r_{z} 
∂r_{x} / ∂x 
∂r_{x} / ∂y 
∂r_{y} / ∂x 
∂r_{y} / ∂y 
∂r_{z} / ∂x 
∂r_{z} / ∂y 
16.5.5. Cube Map Coordinate Transformation
16.5.6. Cube Map Derivative Transformation
16.5.7. Scale Factor Operation, LOD Operation and Image Level(s) Selection
LOD selection can be either explicit (provided explicitly by the image
instruction) or implicit (determined from a scale factor calculated from the
derivatives).
The LOD must be computed with mipmapPrecisionBits
of accuracy.
Scale Factor Operation
The magnitude of the derivatives are calculated by:

m_{ux} = ∂s/∂x × w_{base}

m_{vx} = ∂t/∂x × h_{base}

m_{wx} = ∂r/∂x × d_{base}

m_{uy} = ∂s/∂y × w_{base}

m_{vy} = ∂t/∂y × h_{base}

m_{wy} = ∂r/∂y × d_{base}
where:

∂t/∂x = ∂t/∂y = 0 (for 1D images)

∂r/∂x = ∂r/∂y = 0 (for 1D, 2D or Cube images)
and:

w_{base} = image.w

h_{base} = image.h

d_{base} = image.d
(for the baseMipLevel
, from the image descriptor).
For cornersampled images, the w_{base}, h_{base}, and d_{base} are instead:

w_{base} = image.w  1

h_{base} = image.h  1

d_{base} = image.d  1
A point sampled in screen space has an elliptical footprint in texture space. The minimum and maximum scale factors (ρ_{min}, ρ_{max}) should be the minor and major axes of this ellipse.
The scale factors ρ_{x} and ρ_{y}, calculated from the magnitude of the derivatives in x and y, are used to compute the minimum and maximum scale factors.
ρ_{x} and ρ_{y} may be approximated with functions f_{x} and f_{y}, subject to the following constraints:
The minimum and maximum scale factors (ρ_{min},ρ_{max}) are determined by:

ρ_{max} = max(ρ_{x}, ρ_{y})

ρ_{min} = min(ρ_{x}, ρ_{y})
The ratio of anisotropy is determined by:

η = min(ρ_{max}/ρ_{min}, max_{Aniso})
where:

sampler.max_{Aniso} =
maxAnisotropy
(from sampler descriptor) 
limits.max_{Aniso} =
maxSamplerAnisotropy
(from physical device limits) 
max_{Aniso} = min(sampler.max_{Aniso}, limits.max_{Aniso})
If ρ_{max} = ρ_{min} = 0, then all the partial derivatives are
zero, the fragment’s footprint in texel space is a point, and η
should be treated as 1.
If ρ_{max} ≠ 0 and ρ_{min} = 0 then all partial
derivatives along one axis are zero, the fragment’s footprint in texel space
is a line segment, and η should be treated as max_{Aniso}.
However, anytime the footprint is small in texel space the implementation
may use a smaller value of η, even when ρ_{min} is zero
or close to zero.
If either VkPhysicalDeviceFeatures::samplerAnisotropy
or
VkSamplerCreateInfo::anisotropyEnable
are VK_FALSE
,
max_{Aniso} is set to 1.
If η = 1, sampling is isotropic. If η > 1, sampling is anisotropic.
The sampling rate (N) is derived as:

N = ⌈η⌉
An implementation may round N up to the nearest supported sampling rate. An implementation may use the value of N as an approximation of η.
LOD Operation
The LOD parameter λ is computed as follows:
where:
and maxSamplerLodBias is the value of the VkPhysicalDeviceLimits
feature maxSamplerLodBias
.
Image Level(s) Selection
The image level(s) d, d_{hi}, and d_{lo} which texels are read from are determined by an imagelevel parameter d_{l}, which is computed based on the LOD parameter, as follows:
where:
and:
baseMipLevel
and levelCount
are taken from the
subresourceRange
of the image view.
minLod_{imageView} must be less or equal to level_{base} + q.
If the sampler’s mipmapMode
is VK_SAMPLER_MIPMAP_MODE_NEAREST
,
then the level selected is d = d_{l}.
If the sampler’s mipmapMode
is VK_SAMPLER_MIPMAP_MODE_LINEAR
,
two neighboring levels are selected:
δ is the fractional value, quantized to the number of mipmap precision bits, used for linear filtering between levels.
16.5.8. (s,t,r,q,a) to (u,v,w,a) Transformation
The normalized texel coordinates are scaled by the image level dimensions and the array layer is selected.
This transformation is performed once for each level used in filtering (either d, or d_{hi} and d_{lo}).