Update README.md
This commit is contained in:
parent
1b4214b52e
commit
9cec2d7810
1 changed files with 2 additions and 81 deletions
83
README.md
83
README.md
|
|
@ -31,6 +31,8 @@ src/rhi/vulkan/vulkan.zig
|
||||||
src/rhi/vulkan/resource.zig
|
src/rhi/vulkan/resource.zig
|
||||||
└─ Adapter / Device / Shader
|
└─ Adapter / Device / Shader
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## API
|
||||||
| Function | Description |
|
| Function | Description |
|
||||||
| ------------------- | ----------------------------------------------------------------- |
|
| ------------------- | ----------------------------------------------------------------- |
|
||||||
| `makeX(...)` | Creates an RHI resource and returns its handle |
|
| `makeX(...)` | Creates an RHI resource and returns its handle |
|
||||||
|
|
@ -40,87 +42,6 @@ src/rhi/vulkan/resource.zig
|
||||||
| `getRawX(handle)` | Returns backend-specific raw GPU handle |
|
| `getRawX(handle)` | Returns backend-specific raw GPU handle |
|
||||||
| `getRawFrame()` | Returns backend-specific raw GPU frame resources |
|
| `getRawFrame()` | Returns backend-specific raw GPU frame resources |
|
||||||
|
|
||||||
## Example
|
|
||||||
### Core
|
|
||||||
```zig
|
|
||||||
const adapter = try gfx.makeAdapter(.{});
|
|
||||||
const surface = try gfx.makeSurface();
|
|
||||||
const device = try gfx.makeDevice(adapter, surface);
|
|
||||||
const swapchain = try gfx.makeSwapchain(adapter, device, surface);
|
|
||||||
```
|
|
||||||
### Buffers
|
|
||||||
```zig
|
|
||||||
const vbuf = try gfx.makeBuffer(vertices, .vertex, adapter, device);
|
|
||||||
const ibuf = try gfx.makeBuffer(indices, .index, adapter, device);
|
|
||||||
```
|
|
||||||
### Shaders
|
|
||||||
```zig
|
|
||||||
const simple_vert = try gfx.makeShader("examples/assets/shaders/compiled/simple.vert.spv", device);
|
|
||||||
const simple_frag = try gfx.makeShader("examples/assets/shaders/compiled/simple.frag.spv", device);
|
|
||||||
```
|
|
||||||
### Pipelines
|
|
||||||
```zig
|
|
||||||
const pipeline = try gfx.makePipeline(.{
|
|
||||||
.vertex_attributes = &.{
|
|
||||||
.{ .location = 0, .format = .vec2, .offset = @offsetOf(Vertex, "pos") },
|
|
||||||
.{ .location = 1, .format = .vec2, .offset = @offsetOf(Vertex, "normal") },
|
|
||||||
.{ .location = 2, .format = .vec2, .offset = @offsetOf(Vertex, "uv") },
|
|
||||||
},
|
|
||||||
.vertex_binding = .{ .stride = @sizeOf(Vertex) },
|
|
||||||
|
|
||||||
.uniforms = &.{
|
|
||||||
.{ .name = "material", .offset = 0, .size = @sizeOf(UnlitMaterial) },
|
|
||||||
},
|
|
||||||
|
|
||||||
.textures = &.{texture},
|
|
||||||
|
|
||||||
.blend_mode = .alpha,
|
|
||||||
|
|
||||||
.vert_shader = simple_vert,
|
|
||||||
.frag_shader = simple_frag,
|
|
||||||
|
|
||||||
.device = device,
|
|
||||||
.swapchain = swapchain,
|
|
||||||
});
|
|
||||||
```
|
|
||||||
### Render Pass
|
|
||||||
```zig
|
|
||||||
if (gfx.beginPass(swapchain, .{
|
|
||||||
.clear_color = .{ 0.01, 0.01, 0.01, 1.0 },
|
|
||||||
})) |pass| {
|
|
||||||
defer pass.end();
|
|
||||||
|
|
||||||
try vbuf.bind();
|
|
||||||
try ibuf.bind();
|
|
||||||
|
|
||||||
try pipeline.setUniform("material", material);
|
|
||||||
|
|
||||||
try pipeline.bind();
|
|
||||||
pass.drawIndexed(indices.len, 1, 0, 0, 0);
|
|
||||||
}
|
|
||||||
```
|
|
||||||
### House
|
|
||||||
```zig
|
|
||||||
switch (try gfx.getRawAdapter(adapter)) {
|
|
||||||
.vulkan => |v| std.debug.print("---> {}\n", .{v}),
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (try gfx.getRawDevice(device)) {
|
|
||||||
.vulkan => |v| std.debug.print("---> {}\n", .{v}),
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (try gfx.getRawFrame()) {
|
|
||||||
.vulkan => |v| {
|
|
||||||
const draw_data = im.ImGui_GetDrawData() orelse return;
|
|
||||||
|
|
||||||
im_vk.cImGui_ImplVulkan_RenderDrawData(
|
|
||||||
@ptrCast(draw_data),
|
|
||||||
@ptrCast(v.cmd_buf),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
- ```zig build run-simple```
|
- ```zig build run-simple```
|
||||||
- ```zig build run-3D```
|
- ```zig build run-3D```
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue