Skip to content

Commit b8d1465

Browse files
committed
Add renderheadless rust shader
1 parent 813ecce commit b8d1465

7 files changed

Lines changed: 55 additions & 3 deletions

File tree

examples/renderheadless/renderheadless.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,17 @@ class VulkanExample
9999

100100
std::string shaderDir = "glsl";
101101

102+
const char* getShaderEntryPoint(VkShaderStageFlagBits stage) const {
103+
if (shaderDir == "rust") {
104+
switch (stage) {
105+
case VK_SHADER_STAGE_VERTEX_BIT: return "main_vs";
106+
case VK_SHADER_STAGE_FRAGMENT_BIT: return "main_fs";
107+
default: return "main";
108+
}
109+
}
110+
return "main";
111+
}
112+
102113
uint32_t getMemoryTypeIndex(uint32_t typeBits, VkMemoryPropertyFlags properties) {
103114
VkPhysicalDeviceMemoryProperties deviceMemoryProperties;
104115
vkGetPhysicalDeviceMemoryProperties(physicalDevice, &deviceMemoryProperties);
@@ -667,10 +678,10 @@ class VulkanExample
667678

668679
shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
669680
shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
670-
shaderStages[0].pName = "main";
681+
shaderStages[0].pName = getShaderEntryPoint(VK_SHADER_STAGE_VERTEX_BIT);
671682
shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
672683
shaderStages[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT;
673-
shaderStages[1].pName = "main";
684+
shaderStages[1].pName = getShaderEntryPoint(VK_SHADER_STAGE_FRAGMENT_BIT);
674685
#if defined(VK_USE_PLATFORM_ANDROID_KHR)
675686
shaderStages[0].module = vks::tools::loadShader(androidapp->activity->assetManager, (shadersPath + "triangle.vert.spv").c_str(), device);
676687
shaderStages[1].module = vks::tools::loadShader(androidapp->activity->assetManager, (shadersPath + "triangle.frag.spv").c_str(), device);

shaders/rust/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ members = [
6464
"texture3d",
6565
"texturecubemap/reflect",
6666
"texturecubemap/skybox",
67+
"renderheadless/triangle",
6768
]
6869

6970
[workspace.dependencies]

shaders/rust/compileshaders.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def compile_shader(shader_dir):
6868
print(f" Created {final_path.name} (entry point: {entry_point})")
6969

7070
# Special case: move to parent directory for nested shader structures
71-
if shader_dir.parent.name in ["base", "descriptorsets", "dynamicuniformbuffer", "multisampling", "pipelines", "specializationconstants", "computeshader", "texturearray", "screenshot", "negativeviewportheight", "stencilbuffer", "parallaxmapping", "computecloth", "ssao", "shadowmapping", "deferred", "computenbody", "bloom", "hdr", "radialblur", "pbribl", "indirectdraw", "instancing", "texturecubemap"]:
71+
if shader_dir.parent.name in ["base", "descriptorsets", "dynamicuniformbuffer", "multisampling", "pipelines", "specializationconstants", "computeshader", "texturearray", "screenshot", "negativeviewportheight", "stencilbuffer", "parallaxmapping", "computecloth", "ssao", "shadowmapping", "deferred", "computenbody", "bloom", "hdr", "radialblur", "pbribl", "indirectdraw", "instancing", "texturecubemap", "renderheadless"]:
7272
parent_dir = shader_dir.parent
7373
parent_final_path = parent_dir / f"{shader_name}.{shader_type}.spv"
7474
shutil.move(str(final_path), str(parent_final_path))
416 Bytes
Binary file not shown.
1.65 KB
Binary file not shown.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name = "renderheadless-triangle"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[lib]
7+
crate-type = ["dylib"]
8+
9+
[dependencies]
10+
spirv-std = { workspace = true }
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#![cfg_attr(target_arch = "spirv", no_std)]
2+
#![allow(clippy::missing_safety_doc)]
3+
4+
use spirv_std::{spirv, glam::{vec4, Mat4, Vec3, Vec4}};
5+
6+
#[repr(C)]
7+
#[derive(Copy, Clone)]
8+
pub struct PushConsts {
9+
pub mvp: Mat4,
10+
}
11+
12+
#[spirv(vertex)]
13+
pub fn main_vs(
14+
in_pos: Vec3,
15+
in_color: Vec3,
16+
#[spirv(push_constant)] push_consts: &PushConsts,
17+
#[spirv(position)] out_position: &mut Vec4,
18+
out_color: &mut Vec3,
19+
) {
20+
*out_color = in_color;
21+
*out_position = push_consts.mvp * vec4(in_pos.x, in_pos.y, in_pos.z, 1.0);
22+
}
23+
24+
#[spirv(fragment)]
25+
pub fn main_fs(
26+
in_color: Vec3,
27+
out_frag_color: &mut Vec4,
28+
) {
29+
*out_frag_color = vec4(in_color.x, in_color.y, in_color.z, 1.0);
30+
}

0 commit comments

Comments
 (0)