Skip to content

Commit ba04465

Browse files
Samples: 004_YUV is now bilingual (GLSL + Slang)
1 parent be373ee commit ba04465

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

samples/004_YUV.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,36 @@
1010

1111
#include <filesystem>
1212

13+
const char* codeSlang = R"(
14+
struct VertexOutput {
15+
float4 sv_Position : SV_Position;
16+
float2 uv : TEXCOORD0;
17+
};
18+
19+
static const float2 pos[4] = {
20+
float2(-1.0, -1.0),
21+
float2(-1.0, +1.0),
22+
float2(+1.0, -1.0),
23+
float2(+1.0, +1.0)
24+
};
25+
26+
[[vk::constant_id(0)]] const uint textureId = 0;
27+
28+
[shader("vertex")]
29+
VertexOutput vertexMain(uint vertexID : SV_VertexID) {
30+
VertexOutput out;
31+
out.sv_Position = float4(pos[vertexID], 0.0, 1.0);
32+
out.uv = pos[vertexID] * 0.5 + 0.5;
33+
out.uv.y = 1.0 - out.uv.y;
34+
return out;
35+
}
36+
37+
[shader("fragment")]
38+
float4 fragmentMain(VertexOutput input) : SV_Target0 {
39+
return kSamplersYUV[textureId].Sample(input.uv);
40+
}
41+
)";
42+
1343
const char* codeVS = R"(
1444
#version 460
1545
layout (location=0) out vec2 uv;
@@ -116,8 +146,13 @@ VULKAN_APP_MAIN {
116146

117147
lvk::IContext* ctx = app.ctx_.get();
118148

149+
#if defined(LVK_DEMO_WITH_SLANG)
150+
res_.vert = ctx->createShaderModule({codeSlang, lvk::Stage_Vert, "Shader Module: main (vert)"});
151+
res_.frag = ctx->createShaderModule({codeSlang, lvk::Stage_Frag, "Shader Module: main (frag)"});
152+
#else
119153
res_.vert = ctx->createShaderModule({codeVS, lvk::Stage_Vert, "Shader Module: main (vert)"});
120154
res_.frag = ctx->createShaderModule({codeFS, lvk::Stage_Frag, "Shader Module: main (frag)"});
155+
#endif // defined(LVK_DEMO_WITH_SLANG)
121156

122157
createDemo(ctx, app.folderContentRoot_.c_str(), "YUV NV12", lvk::Format_YUV_NV12, "igl-samples/output_frame_900.nv12.yuv");
123158
createDemo(ctx, app.folderContentRoot_.c_str(), "YUV 420p", lvk::Format_YUV_420p, "igl-samples/output_frame_900.420p.yuv");

samples/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ endmacro()
150150
ADD_DEMO("001_HelloTriangle" LVK_WITH_SLANG)
151151
ADD_DEMO("002_RenderToCubeMap" LVK_WITH_SLANG)
152152
ADD_DEMO("003_RenderToCubeMapSinglePass" LVK_WITH_SLANG)
153-
ADD_DEMO("004_YUV")
153+
ADD_DEMO("004_YUV" LVK_WITH_SLANG)
154154
if(WIN32 OR UNIX AND NOT (APPLE))
155155
# Windows and Linux
156156
ADD_DEMO("005_MeshShaders")

0 commit comments

Comments
 (0)