• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright (c) 2023 Qualcomm Technologies, Inc.
2//
3// SPDX-License-Identifier: CC-BY-4.0
4
5include::{generated}/meta/{refprefix}VK_QCOM_image_processing2.adoc[]
6
7=== Other Extension Metadata
8
9*Last Modified Date*::
10    2023-03-10
11*Interactions and External Dependencies*::
12  - This extension provides API support for
13    {GLSLregistry}/qcom/GLSL_QCOM_image_processing2.txt[`GL_QCOM_image_processing2`]
14
15*Contributors*::
16  - Jeff Leger, Qualcomm Technologies, Inc.
17
18=== Description
19
20This extension enables support for the SPIR-V code:TextureBlockMatch2QCOM
21capability.
22It builds on the functionality of QCOM_image_processing with the addition of
234 new image processing operations.
24
25  * The code:opImageBlockMatchWindowSADQCOM` SPIR-V instruction builds upon
26    the functionality of code:opImageBlockMatchSADQCOM` by repeatedly
27    performing block match operations across a 2D window.
28    The "`2D windowExtent`" and "`compareMode`" are are specified by
29    slink:VkSamplerBlockMatchWindowCreateInfoQCOM in the sampler used to
30    create the _target image_.
31    Like code:OpImageBlockMatchSADQCOM, code:opImageBlockMatchWindowSADQCOM
32    computes an error metric, that describes whether a block of texels in
33    the _target image_ matches a corresponding block of texels in the
34    _reference image_.
35    Unlike code:OpImageBlockMatchSADQCOM, this instruction computes an error
36    metric at each (X,Y) location within the 2D window and returns either
37    the minimum or maximum error.
38    The instruction only supports single-component formats.
39    Refer to the pseudocode below for details.
40  * The code:opImageBlockMatchWindowSSDQCOM follows the same pattern,
41    computing the SSD error metric at each location within the 2D window.
42  * The code:opImageBlockMatchGatherSADQCOM builds upon
43    code:OpImageBlockMatchSADQCOM.
44    This instruction computes an error metric, that describes whether a
45    block of texels in the _target image_ matches a corresponding block of
46    texels in the _reference image_.
47    The instruction computes the SAD error metric at 4 texel offsets and
48    returns the error metric for each offset in the X,Y,Z,and W components.
49    The instruction only supports single-component texture formats.
50    Refer to the pseudocode below for details.
51  * The code:opImageBlockMatchGatherSSDQCOM follows the same pattern,
52    computing the SSD error metric for 4 offsets.
53
54Each of the above 4 image processing instructions are limited to
55single-component formats.
56
57Below is the pseudocode for GLSL built-in function
58code:textureWindowBlockMatchSADQCOM.
59The pseudocode for code:textureWindowBlockMatchSSD is identical other than
60replacing all instances of `"SAD"` with `"SSD"`.
61
62[source,c]
63----
64vec4 textureBlockMatchWindowSAD( sampler2D target,
65                                 uvec2 targetCoord,
66                                 samler2D reference,
67                                 uvec2 refCoord,
68                                 uvec2 blocksize) {
69    // compareMode (MIN or MAX) comes from the vkSampler associated with `target`
70    // uvec2 window  comes from the vkSampler associated with `target`
71    minSAD = INF;
72    maxSAD = -INF;
73    uvec2 minCoord;
74    uvec2 maxCoord;
75
76    for (uint x=0, x < window.width; x++) {
77        for (uint y=0; y < window.height; y++) {
78            float SAD = textureBlockMatchSAD(target,
79                                            targetCoord + uvec2(x, y),
80                                            reference,
81                                            refCoord,
82                                            blocksize).x;
83            // Note: the below comparison operator will produce undefined results
84            // if SAD is a denorm value.
85            if (SAD < minSAD) {
86                minSAD = SAD;
87                minCoord = uvec2(x,y);
88            }
89            if (SAD > maxSAD) {
90                maxSAD = SAD;
91                maxCoord = uvec2(x,y);
92            }
93        }
94    }
95    if (compareMode=MIN) {
96        return vec4(minSAD, minCoord.x, minCoord.y, 0.0);
97    } else {
98        return vec4(maxSAD, maxCoord.x, maxCoord.y, 0.0);
99    }
100}
101----
102
103Below is the pseudocode for code:textureBlockMatchGatherSADQCOM.
104The pseudocode for code:textureBlockMatchGatherSSD follows an identical
105pattern.
106
107[source,c]
108----
109vec4 textureBlockMatchGatherSAD( sampler2D target,
110                                 uvec2 targetCoord,
111                                 samler2D reference,
112                                 uvec2 refCoord,
113                                 uvec2 blocksize) {
114    vec4 out;
115    for (uint x=0, x<4; x++) {
116            float SAD = textureBlockMatchSAD(target,
117                                            targetCoord + uvec2(x, 0),
118                                            reference,
119                                            refCoord,
120                                            blocksize).x;
121            out[x] = SAD;
122    }
123    return out;
124}
125----
126
127include::{generated}/interfaces/VK_QCOM_image_processing2.adoc[]
128
129=== Issues
130
1311) What is the precision of the min/max comparison checks?
132
133*RESOLVED*: Intermediate computations for the new operations are performed
134at 16-bit floating point precision.
135If the value of `"float SAD"` in the above code sample is a 16-bit denorm
136value, then behavior of the MIN/MAX comparison is undefined.
137
138=== Version History
139
140  * Revision 1, 2023-03-10 (Jeff Leger)
141