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