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
Make sure that the shaders are loaded correctly by printing the size of the
344
-
buffers and checking if they match the actual file size in bytes.
344
+
buffers and checking if they match the actual file size in bytes. Note that the code doesn't need to be null terminated since it's binary code and we will later be explicit about its size.
345
345
346
346
## Creating shader modules
347
347
@@ -394,25 +394,18 @@ shader module:
394
394
return shaderModule;
395
395
```
396
396
397
-
The shader module objects are only required during the pipeline creation
398
-
process, so instead of declaring them as class members, we'll make them local
399
-
variables in the `createGraphicsPipeline` function:
397
+
Shader modules are just a thin wrapper around the shader bytecode that we've previously loaded from a file and the functions defined in it. The compilation and linking of the SPIR-V bytecode to machine code for execution by the GPU doesn't happen until the graphics pipeline is created. That means that we're allowed to destroy the shader modules again as soon as pipeline creation is finished, which is why we'll make them local variables in the `createGraphicsPipeline` function instead of class members:
400
398
401
399
```c++
402
-
VkShaderModule vertShaderModule;
403
-
VkShaderModule fragShaderModule;
404
-
```
405
-
406
-
Call the helper function we created to load the shader modules:
400
+
voidcreateGraphicsPipeline() {
401
+
auto vertShaderCode = readFile("shaders/vert.spv");
402
+
auto fragShaderCode = readFile("shaders/frag.spv");
They should be cleaned up when the graphics pipeline has been created and
414
-
`createGraphicsPipeline` returns, so make sure that they are deleted at the end
415
-
of the function:
408
+
The cleanup should then happen at the end of the function by adding two calls to `vkDestroyShaderModule`. ALl of the remaining code in this chapter will be inserted before these lines.
416
409
417
410
```c++
418
411
...
@@ -423,11 +416,7 @@ of the function:
423
416
424
417
## Shader stage creation
425
418
426
-
The `VkShaderModule` object is just a dumb wrapper around the bytecode buffer.
427
-
The shaders aren't linked to each other yet and they haven't even been given a
428
-
purpose yet. Assigning a shader module to either the vertex or fragment shader
429
-
stage in the pipeline happens through a `VkPipelineShaderStageCreateInfo`
430
-
structure, which is part of the actual pipeline creation process.
419
+
To actually use the shaders we'll need to assign them to a specific pipeline stage through `VkPipelineShaderStageCreateInfo` structures as part of the actual pipeline creation process.
431
420
432
421
We'll start by filling in the structure for the vertex shader, again in the
0 commit comments