Image Operations Overview

Vulkan Image Operations are operations performed by those SPIR-V 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.

  • OpImageSample* and OpImageSparseSample* read one or more neighboring texels of the image, and filter the texel values based on the state of the sampler.
  • OpImageFetch and OpImageSparseFetch return a single texel of the image. No sampler is used.
  • OpImage*Gather and OpImageSparse*Gather read neighboring texels and return a single component of each.
  • OpImageRead (and OpImageSparseRead) and OpImageWrite read and write, respectively, a texel in the image. No sampler is used.
  • Instructions with Dref in the name apply depth comparison on the texel values.
  • Instructions with Sparse in the name additionally return a sparse residency code.
  • OpImageQuerySize, OpImageQuerySizeLod, OpImageQueryLevels, and OpImageQuerySamples 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.

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)

OpImageFetch, OpImageSparseFetch, OpImageRead, OpImageSparseRead, 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.

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.

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.

For all coordinate types, unused coordinates are assigned a value of zero.

Vulkan

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 i0j0, i1j0, i0j1, and i1j1. ◦ The fractions α and β. ◦ Given the offset Δi and Δj, the four texels selected by the offset are i0j'0, i1j'0, i0j'1, and i1j'1.

For formats with reduced-resolution components, Δi and Δj are relative to the resolution of the highest-resolution component, and therefore may be divided by two relative to the unnormalized coordinate space of the lower-resolution components.

Vulkan

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'.

Conversion Formulas

Texel Input Operations

Texel Input Validation Operations

  • Instruction/Sampler/Image View Validation
  • Integer Texel Coordinate Validation
  • Cube Map Edge Handling
  • Sparse Validation
  • Layout Validation

Format Conversion

Texel Replacement

  • a border texel,
  • an invalid texel,
  • a sparse unbound texel.

Depth Compare Operation

Conversion to RGBA

Vulkan

Component Swizzle

Sparse Residency

Chroma Reconstruction

Sampler Y′CBCR Conversion

Texel Output Operations

Texel Output Validation Operations

Integer Texel Coordinate Validation

Sparse Texel Operation

Texel Output Format Conversion

Normalized Texel Coordinate Operations

Projection Operation

Derivative Image Operations

Cube Map Face Selection and Transformations

Cube Map Face Selection

Cube Map Coordinate Transformation

Cube Map Derivative Transformation

Scale Factor Operation, Level-of-Detail Operation and Image Level(s) Selection

(s,t,r,q,a) to (u,v,w,a) Transformation

Unnormalized Texel Coordinate Operations

(u,v,w,a) to (i,j,k,l,n) Transformation And Array Layer Selection

Integer Texel Coordinate Operations

Image Sample Operations

Wrapping Operation

Texel Gathering

Texel Filtering

Image Operation Steps

Each step described in this chapter is performed by a subset of the image instructions:

  • Texel Input Validation Operations, Format Conversion, Texel Replacement, Conversion to RGBA, and Component Swizzle: Performed by all instructions except OpImageWrite.
  • TDepth Comparison: Performed by OpImage*Dref instructions.
  • TAll Texel output operations: Performed by OpImageWrite.
  • TProjection: Performed by all OpImage*Proj instructions.
  • TDerivative Image Operations, Cube Map Operations, Scale Factor Operation, Level-of-Detail Operation and Image Level(s) Selection, and Texel Anisotropic Filtering: Performed by all OpImageSample* and OpImageSparseSample* instructions.
  • T(s,t,r,q,a) to (u,v,w,a) Transformation, Wrapping, and (u,v,w,a) to (i,j,k,l,n) Transformation And Array Layer Selection: Performed by all OpImageSample, OpImageSparseSample, and OpImage*Gather instructions.
  • TTexel Gathering: Performed by OpImage*Gather instructions.
  • TTexel Filtering: Performed by all OpImageSample* and OpImageSparseSample* instructions.
  • TSparse Residency: Performed by all OpImageSparse* instructions.
Image Query Instructions

Image Property Queries

OpImageQuerySize, OpImageQuerySizeLod, OpImageQueryLevels, and OpImageQuerySamples query properties of the image descriptor that would be accessed by a shader image operation.

OpImageQuerySizeLod returns the size of the image level identified by the Level of Detail operand. If that level does not exist in the image, then the value returned is undefined.

Lod Query

OpImageQueryLod returns the Lod parameters that would be used in an image operation with the given image and coordinates. The steps described in this chapter are performed as if for OpImageSampleImplicitLod, up to Scale Factor Operation, Level-of-Detail Operation and Image Level(s) Selection. The return value is the vector (λ', dl). These values may be subject to implementation-specific maxima and minima for very large, out-of-range values.

本节教程就到此结束,希望大家继续阅读我之后的教程。

谢谢大家,再见!


原创技术文章,撰写不易,转载请注明出处:电子设备中的画家|王烁 于 2021 年 5 月 10 日发表,原文链接(http://geekfaner.com/shineengine/blog20_Vulkanv1.2_6.html)