• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright (c) 2017-2020 Advanced Micro Devices, Inc.
2//
3// SPDX-License-Identifier: CC-BY-4.0
4
5include::{generated}/meta/{refprefix}VK_AMD_shader_fragment_mask.adoc[]
6
7=== Other Extension Metadata
8
9*Last Modified Date*::
10    2017-08-16
11*IP Status*::
12    No known IP claims.
13*Interactions and External Dependencies*::
14  - This extension requires
15    {spirv}/AMD/SPV_AMD_shader_fragment_mask.html[`SPV_AMD_shader_fragment_mask`]
16  - This extension provides API support for
17    {GLSLregistry}/amd/GL_AMD_shader_fragment_mask.txt[`GL_AMD_shader_fragment_mask`]
18*Contributors*::
19  - Aaron Hagan, AMD
20  - Daniel Rakos, AMD
21  - Timothy Lottes, AMD
22
23=== Description
24
25This extension provides efficient read access to the fragment mask in
26compressed multisampled color surfaces.
27The fragment mask is a lookup table that associates color samples with color
28fragment values.
29
30From a shader, the fragment mask can be fetched with a call to
31code:fragmentMaskFetchAMD, which returns a single code:uint where each
32subsequent four bits specify the color fragment index corresponding to the
33color sample, starting from the least significant bit.
34For example, when eight color samples are used, the color fragment index for
35color sample 0 will be in bits 0-3 of the fragment mask, for color sample 7
36the index will be in bits 28-31.
37
38The color fragment for a particular color sample may then be fetched with
39the corresponding fragment mask value using the code:fragmentFetchAMD shader
40function.
41
42include::{generated}/interfaces/VK_AMD_shader_fragment_mask.adoc[]
43
44=== New SPIR-V Capabilities
45
46  * <<spirvenv-capabilities-table-FragmentMaskAMD, code:FragmentMaskAMD>>
47
48=== Examples
49
50This example shows a shader that queries the fragment mask from a
51multisampled compressed surface and uses it to query fragment values.
52
53[source,c++]
54----------------------------------------
55#version 450 core
56
57#extension GL_AMD_shader_fragment_mask: enable
58
59layout(binding = 0) uniform sampler2DMS       s2DMS;
60layout(binding = 1) uniform isampler2DMSArray is2DMSArray;
61
62layout(binding = 2, input_attachment_index = 0) uniform usubpassInputMS usubpassMS;
63
64layout(location = 0) out vec4 fragColor;
65
66void main()
67{
68    vec4 fragOne = vec4(0.0);
69
70    uint fragMask = fragmentMaskFetchAMD(s2DMS, ivec2(2, 3));
71    uint fragIndex = (fragMask & 0xF0) >> 4;
72    fragOne += fragmentFetchAMD(s2DMS, ivec2(2, 3), 1);
73
74    fragMask = fragmentMaskFetchAMD(is2DMSArray, ivec3(2, 3, 1));
75    fragIndex = (fragMask & 0xF0) >> 4;
76    fragOne += fragmentFetchAMD(is2DMSArray, ivec3(2, 3, 1), fragIndex);
77
78    fragMask = fragmentMaskFetchAMD(usubpassMS);
79    fragIndex = (fragMask & 0xF0) >> 4;
80    fragOne += fragmentFetchAMD(usubpassMS, fragIndex);
81
82    fragColor = fragOne;
83}
84----------------------------------------
85
86=== Version History
87
88  * Revision 1, 2017-08-16 (Aaron Hagan)
89  ** Initial draft
90