1/*
2 * Copyright © 2020 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24#include "vk_standard_sample_locations.h"
25
26#include "vk_graphics_state.h"
27
28/**
29 * 1x MSAA has a single sample at the center: (0.5, 0.5) -> (0x8, 0x8).
30 */
31static const struct vk_sample_locations_state sample_locations_state_1x = {
32   .per_pixel = VK_SAMPLE_COUNT_1_BIT,
33   .grid_size = { 1, 1 },
34   .locations = {
35      { 0.5, 0.5 },
36   },
37};
38
39
40/**
41 * 2x MSAA sample positions are (0.25, 0.25) and (0.75, 0.75):
42 *   4 c
43 * 4 0
44 * c   1
45 */
46static const struct vk_sample_locations_state sample_locations_state_2x = {
47   .per_pixel = VK_SAMPLE_COUNT_2_BIT,
48   .grid_size = { 1, 1 },
49   .locations = {
50      { 0.75, 0.75 },
51      { 0.25, 0.25 },
52   },
53};
54
55/**
56 * Sample positions:
57 *   2 6 a e
58 * 2   0
59 * 6       1
60 * a 2
61 * e     3
62 */
63static const struct vk_sample_locations_state sample_locations_state_4x = {
64   .per_pixel = VK_SAMPLE_COUNT_4_BIT,
65   .grid_size = { 1, 1 },
66   .locations = {
67      { 0.375, 0.125 },
68      { 0.875, 0.375 },
69      { 0.125, 0.625 },
70      { 0.625, 0.875 },
71   },
72};
73
74/**
75 * Sample positions:
76 *   1 3 5 7 9 b d f
77 * 1               7
78 * 3     3
79 * 5         0
80 * 7 5
81 * 9             2
82 * b       1
83 * d   4
84 * f           6
85 */
86static const struct vk_sample_locations_state sample_locations_state_8x = {
87   .per_pixel = VK_SAMPLE_COUNT_8_BIT,
88   .grid_size = { 1, 1 },
89   .locations = {
90      { 0.5625, 0.3125 },
91      { 0.4375, 0.6875 },
92      { 0.8125, 0.5625 },
93      { 0.3125, 0.1875 },
94      { 0.1875, 0.8125 },
95      { 0.0625, 0.4375 },
96      { 0.6875, 0.9375 },
97      { 0.9375, 0.0625 },
98   },
99};
100
101/**
102 * Sample positions:
103 *
104 *    0 1 2 3 4 5 6 7 8 9 a b c d e f
105 * 0   15
106 * 1                  9
107 * 2         10
108 * 3                        7
109 * 4                               13
110 * 5                1
111 * 6        4
112 * 7                          3
113 * 8 12
114 * 9                    0
115 * a            2
116 * b                            6
117 * c     11
118 * d                      5
119 * e              8
120 * f                             14
121 */
122static const struct vk_sample_locations_state sample_locations_state_16x = {
123   .per_pixel = VK_SAMPLE_COUNT_16_BIT,
124   .grid_size = { 1, 1 },
125   .locations = {
126      { 0.5625, 0.5625 },
127      { 0.4375, 0.3125 },
128      { 0.3125, 0.6250 },
129      { 0.7500, 0.4375 },
130      { 0.1875, 0.3750 },
131      { 0.6250, 0.8125 },
132      { 0.8125, 0.6875 },
133      { 0.6875, 0.1875 },
134      { 0.3750, 0.8750 },
135      { 0.5000, 0.0625 },
136      { 0.2500, 0.1250 },
137      { 0.1250, 0.7500 },
138      { 0.0000, 0.5000 },
139      { 0.9375, 0.2500 },
140      { 0.8750, 0.9375 },
141      { 0.0625, 0.0000 },
142   },
143};
144
145const struct vk_sample_locations_state *
146vk_standard_sample_locations_state(VkSampleCountFlagBits sample_count)
147{
148   switch (sample_count) {
149   case 1:  return &sample_locations_state_1x;
150   case 2:  return &sample_locations_state_2x;
151   case 4:  return &sample_locations_state_4x;
152   case 8:  return &sample_locations_state_8x;
153   case 16: return &sample_locations_state_16x;
154   default: unreachable("Sample count has no standard locations");
155   }
156}
157