You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 10_Multisampling.md
+32-39Lines changed: 32 additions & 39 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -50,29 +50,31 @@ We will now use this function to set the `msaaSamples` variable during the physi
50
50
51
51
```c++
52
52
voidpickPhysicalDevice() {
53
-
...
54
-
if (isDeviceSuitable(device)) {
55
-
physicalDevice = device;
56
-
msaaSamples = getMaxUsableSampleCount();
57
-
break;
58
-
}
59
-
...
53
+
...
54
+
for (const auto& device : devices) {
55
+
if (isDeviceSuitable(device)) {
56
+
physicalDevice = device;
57
+
msaaSamples = getMaxUsableSampleCount();
58
+
break;
59
+
}
60
+
}
61
+
...
60
62
}
61
63
```
62
64
63
-
## Setting up render targets
65
+
## Setting up a render target
64
66
65
-
In MSAA, each pixel is sampled in an offscreen buffer which is then rendered to the screen. These new buffers are slightly different from regular images we've been rendering to - they have to be able to store more than one sample per pixel. Once a multisampled buffer is created, it has to be attached to the default framebuffer (which stores only a single sample per pixel). This is why we have to create additional render targets and modify our current drawing process. Add the following class members:
67
+
In MSAA, each pixel is sampled in an offscreen buffer which is then rendered to the screen. This new buffer is slightly different from regular images we've been rendering to - they have to be able to store more than one sample per pixel. Once a multisampled buffer is created, it has to be resolved to the default framebuffer (which stores only a single sample per pixel). This is why we have to create an additional render target and modify our current drawing process. We only need one render target since only one drawing operation is active at a time, just like with the depth buffer. Add the following class members:
66
68
67
69
```c++
68
70
...
69
-
std::vector<VkImage> colorImages;
70
-
std::vector<VkDeviceMemory> colorImagesMemory;
71
-
std::vector<VkImageView> colorImagesView;
71
+
VkImage colorImage;
72
+
VkDeviceMemory colorImageMemory;
73
+
VkImageView colorImageView;
72
74
...
73
75
```
74
76
75
-
These new images will have to store the desired number of samples per pixel, so we need to pass this number to `VkImageCreateInfo` during image creation process. Modify the `createImage` function by adding a `numSamples` parameter:
77
+
This new image will have to store the desired number of samples per pixel, so we need to pass this number to `VkImageCreateInfo` during the image creation process. Modify the `createImage` function by adding a `numSamples` parameter:
For now, update all calls to this function using `VK_SAMPLE_COUNT_1_BIT` - we will be replacing this with proper values as we progress with implementation:
We will now create a multisampled color buffer. Same as in case of non-multisampled image, we'll be dealing with dedicated resources for each swapchain image. Add a `createColorResources` function and note that we're using `msaaSamples` here as a function parameter to `createImage`. We're also using only one mip level, since this is enforced by the Vulkan specification in case of images with more than one sample per pixel. Also, this color buffer doesn't need mipmaps since it's not going to be used as a texture:
94
+
We will now create a multisampled color buffer. Add a `createColorResources` function and note that we're using `msaaSamples` here as a function parameter to `createImage`. We're also using only one mip level, since this is enforced by the Vulkan specification in case of images with more than one sample per pixel. Also, this color buffer doesn't need mipmaps since it's not going to be used as a texture:
And update the `recreateSwapChain` so that the new color images can be recreated in the correct resolution when the window is resized:
157
+
And update the `recreateSwapChain` so that the new color image can be recreated in the correct resolution when the window is resized:
165
158
166
159
```c++
167
160
voidrecreateSwapChain() {
@@ -173,7 +166,7 @@ void recreateSwapChain() {
173
166
}
174
167
```
175
168
176
-
We made it past the initial MSAA setup, now we need to start using these new resources in our graphics pipeline, framebuffer, render pass and see the results!
169
+
We made it past the initial MSAA setup, now we need to start using this new resource in our graphics pipeline, framebuffer, render pass and see the results!
177
170
178
171
## Adding new attachments
179
172
@@ -223,22 +216,22 @@ Set the `pResolveAttachments` subpass struct member to point to the newly create
223
216
...
224
217
```
225
218
226
-
Now update render pass info struct with new color attachment:
219
+
Now update render pass info struct with the new color attachment:
0 commit comments