Skip to content

Commit 159f4e2

Browse files
committed
Fixup docs
1 parent 58fe823 commit 159f4e2

File tree

3 files changed

+25
-35
lines changed

3 files changed

+25
-35
lines changed

guide/src/shader_objects/drawing_triangle.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33
Add a `ShaderProgram` to `App` and its create function:
44

55
```cpp
6+
[[nodiscard]] auto asset_path(std::string_view uri) const -> fs::path;
7+
8+
// ...
69
void create_shader();
710

811
// ...
912
std::optional<ShaderProgram> m_shader{};
1013
```
1114
12-
Implement and call `create_shader()`:
15+
Implement and call `create_shader()` (and `asset_path()`):
1316
1417
```cpp
1518
void App::create_shader() {
@@ -22,6 +25,10 @@ void App::create_shader() {
2225
};
2326
m_shader.emplace(shader_ci);
2427
}
28+
29+
auto App::asset_path(std::string_view const uri) const -> fs::path {
30+
return m_assets_dir / uri;
31+
}
2532
```
2633

2734
Before `render()` grows to an unwieldy size, extract the higher level logic into two member functions:

guide/src/shader_objects/shader_program.md

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
# Shader Program
22

3-
SPIR-V modules are binary files with a stride/alignment of 4 bytes. The Vulkan API accepts a span of `std::uint32_t`s, so we need to load it into such a buffer (and _not_ `std::vector<std::byte>` or other 1-byte equivalents). We will encapsulate both vertex and fragment shaders into a single `ShaderProgram`, which will also bind the shaders before a draw, and expose/set various dynamic states.
3+
To use Shader Objects we need to enable the corresponding feature and extension during device creation:
4+
5+
```cpp
6+
auto shader_object_feature =
7+
vk::PhysicalDeviceShaderObjectFeaturesEXT{vk::True};
8+
dynamic_rendering_feature.setPNext(&shader_object_feature);
9+
10+
// ...
11+
// we need two device extensions: Swapchain and Shader Object.
12+
static constexpr auto extensions_v = std::array{
13+
VK_KHR_SWAPCHAIN_EXTENSION_NAME,
14+
"VK_EXT_shader_object",
15+
};
16+
```
17+
18+
We will encapsulate both vertex and fragment shaders into a single `ShaderProgram`, which will also bind the shaders before a draw, and expose/set various dynamic states.
419

520
In `shader_program.hpp`, first add a `ShaderProgramCreateInfo` struct:
621

@@ -233,35 +248,3 @@ void ShaderProgram::bind_shaders(vk::CommandBuffer const command_buffer) const {
233248
command_buffer.bindShadersEXT(stages_v, shaders);
234249
}
235250
```
236-
237-
## TODO: MOVE
238-
239-
Add new members to `App`:
240-
241-
```cpp
242-
void create_pipelines();
243-
244-
[[nodiscard]] auto asset_path(std::string_view uri) const -> fs::path;
245-
```
246-
247-
Add code to load shaders in `create_pipelines()` and call it before starting the main loop:
248-
249-
```cpp
250-
void App::create_pipelines() {
251-
auto shader_loader = ShaderLoader{*m_device};
252-
// we only need shader modules to create the pipelines, thus no need to
253-
// store them as members.
254-
auto const vertex = shader_loader.load(asset_path("shader.vert"));
255-
auto const fragment = shader_loader.load(asset_path("shader.frag"));
256-
if (!vertex || !fragment) {
257-
throw std::runtime_error{"Failed to load Shaders"};
258-
}
259-
std::println("[lvk] Shaders loaded");
260-
261-
// TODO
262-
}
263-
264-
auto App::asset_path(std::string_view const uri) const -> fs::path {
265-
return m_assets_dir / uri;
266-
}
267-
```

src/app.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ void App::create_device() {
134134
dynamic_rendering_feature.setPNext(&shader_object_feature);
135135

136136
auto device_ci = vk::DeviceCreateInfo{};
137-
// we only need one device extension: Swapchain.
137+
// we need two device extensions: Swapchain and Shader Object.
138138
static constexpr auto extensions_v = std::array{
139139
VK_KHR_SWAPCHAIN_EXTENSION_NAME,
140140
"VK_EXT_shader_object",

0 commit comments

Comments
 (0)