diff options
| author | ruki <[email protected]> | 2025-12-07 23:00:26 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2025-12-07 23:00:26 +0800 |
| commit | 0187b34737611b7b194761ef1a241dd4ac6eee05 (patch) | |
| tree | a5b7017281430fc19b51b58d683bc795218b1a60 /tests | |
| parent | 4e4b28eb4cad79cc4df5fca887b4f4b709f2b211 (diff) | |
add bin2obj support for glsl/hlsl2spv
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/projects/other/glsl2spv/src/main.c | 3 | ||||
| -rw-r--r-- | tests/projects/other/glsl2spv_bin2obj/src/main.c | 36 | ||||
| -rw-r--r-- | tests/projects/other/glsl2spv_bin2obj/src/test.frag | 6 | ||||
| -rw-r--r-- | tests/projects/other/glsl2spv_bin2obj/src/test.vert | 6 | ||||
| -rw-r--r-- | tests/projects/other/glsl2spv_bin2obj/xmake.lua | 11 | ||||
| -rw-r--r-- | tests/projects/other/hlsl2spv/src/main.c | 3 | ||||
| -rw-r--r-- | tests/projects/other/hlsl2spv_bin2obj/src/main.c | 36 | ||||
| -rw-r--r-- | tests/projects/other/hlsl2spv_bin2obj/src/test.ps.hlsl | 9 | ||||
| -rw-r--r-- | tests/projects/other/hlsl2spv_bin2obj/src/test.vs.hlsl | 17 | ||||
| -rw-r--r-- | tests/projects/other/hlsl2spv_bin2obj/xmake.lua | 11 |
10 files changed, 134 insertions, 4 deletions
diff --git a/tests/projects/other/glsl2spv/src/main.c b/tests/projects/other/glsl2spv/src/main.c index 56e54d771..eba8286ae 100644 --- a/tests/projects/other/glsl2spv/src/main.c +++ b/tests/projects/other/glsl2spv/src/main.c @@ -8,8 +8,7 @@ static unsigned char g_test_frag_spv_data[] = { #include "test.frag.spv.h" }; -int main(int argc, char** argv) -{ +int main(int argc, char** argv) { printf("test.vert.spv: %s, size: %d\n", g_test_vert_spv_data, (int)sizeof(g_test_vert_spv_data)); printf("test.frag.spv: %s, size: %d\n", g_test_frag_spv_data, (int)sizeof(g_test_frag_spv_data)); return 0; diff --git a/tests/projects/other/glsl2spv_bin2obj/src/main.c b/tests/projects/other/glsl2spv_bin2obj/src/main.c new file mode 100644 index 000000000..64d62ce8b --- /dev/null +++ b/tests/projects/other/glsl2spv_bin2obj/src/main.c @@ -0,0 +1,36 @@ +#include <stdio.h> +#include <stdint.h> + +extern const uint8_t _binary_test_vert_spv_start[]; +extern const uint8_t _binary_test_vert_spv_end[]; + +extern const uint8_t _binary_test_frag_spv_start[]; +extern const uint8_t _binary_test_frag_spv_end[]; + +int main(int argc, char** argv) { + const uint32_t vert_size = (uint32_t)(_binary_test_vert_spv_end - _binary_test_vert_spv_start); + const uint32_t frag_size = (uint32_t)(_binary_test_frag_spv_end - _binary_test_frag_spv_start); + + printf("test.vert.spv: size: %u bytes\n", vert_size); + printf("test.frag.spv: size: %u bytes\n", frag_size); + + // Print first few bytes + if (vert_size > 0) { + printf("test.vert.spv first 4 bytes: "); + for (uint32_t i = 0; i < 4 && i < vert_size; i++) { + printf("%02x ", _binary_test_vert_spv_start[i]); + } + printf("\n"); + } + + if (frag_size > 0) { + printf("test.frag.spv first 4 bytes: "); + for (uint32_t i = 0; i < 4 && i < frag_size; i++) { + printf("%02x ", _binary_test_frag_spv_start[i]); + } + printf("\n"); + } + + return 0; +} + diff --git a/tests/projects/other/glsl2spv_bin2obj/src/test.frag b/tests/projects/other/glsl2spv_bin2obj/src/test.frag new file mode 100644 index 000000000..9aeec4257 --- /dev/null +++ b/tests/projects/other/glsl2spv_bin2obj/src/test.frag @@ -0,0 +1,6 @@ +#version 330 +precision mediump float; + +void main() { +} + diff --git a/tests/projects/other/glsl2spv_bin2obj/src/test.vert b/tests/projects/other/glsl2spv_bin2obj/src/test.vert new file mode 100644 index 000000000..9aeec4257 --- /dev/null +++ b/tests/projects/other/glsl2spv_bin2obj/src/test.vert @@ -0,0 +1,6 @@ +#version 330 +precision mediump float; + +void main() { +} + diff --git a/tests/projects/other/glsl2spv_bin2obj/xmake.lua b/tests/projects/other/glsl2spv_bin2obj/xmake.lua new file mode 100644 index 000000000..36382be66 --- /dev/null +++ b/tests/projects/other/glsl2spv_bin2obj/xmake.lua @@ -0,0 +1,11 @@ +add_rules("mode.debug", "mode.release") + +add_requires("glslang", {configs = {binaryonly = true}}) + +target("test") + set_kind("binary") + add_rules("utils.glsl2spv", {bin2obj = true}) + add_files("src/*.c") + add_files("src/*.vert", "src/*.frag") + add_packages("glslang") + diff --git a/tests/projects/other/hlsl2spv/src/main.c b/tests/projects/other/hlsl2spv/src/main.c index 29a65edb1..30c475abe 100644 --- a/tests/projects/other/hlsl2spv/src/main.c +++ b/tests/projects/other/hlsl2spv/src/main.c @@ -8,8 +8,7 @@ static unsigned char g_test_frag_spv_data[] = { #include "test.ps.spv.h" }; -int main(int argc, char** argv) -{ +int main(int argc, char** argv) { printf("test.vert.spv: %s, size: %d\n", g_test_vert_spv_data, (int)sizeof(g_test_vert_spv_data)); printf("test.frag.spv: %s, size: %d\n", g_test_frag_spv_data, (int)sizeof(g_test_frag_spv_data)); return 0; diff --git a/tests/projects/other/hlsl2spv_bin2obj/src/main.c b/tests/projects/other/hlsl2spv_bin2obj/src/main.c new file mode 100644 index 000000000..343e5ac2f --- /dev/null +++ b/tests/projects/other/hlsl2spv_bin2obj/src/main.c @@ -0,0 +1,36 @@ +#include <stdio.h> +#include <stdint.h> + +extern const uint8_t _binary_test_vs_spv_start[]; +extern const uint8_t _binary_test_vs_spv_end[]; + +extern const uint8_t _binary_test_ps_spv_start[]; +extern const uint8_t _binary_test_ps_spv_end[]; + +int main(int argc, char** argv) { + const uint32_t vs_size = (uint32_t)(_binary_test_vs_spv_end - _binary_test_vs_spv_start); + const uint32_t ps_size = (uint32_t)(_binary_test_ps_spv_end - _binary_test_ps_spv_start); + + printf("test.vs.spv: size: %u bytes\n", vs_size); + printf("test.ps.spv: size: %u bytes\n", ps_size); + + // Print first few bytes + if (vs_size > 0) { + printf("test.vs.spv first 4 bytes: "); + for (uint32_t i = 0; i < 4 && i < vs_size; i++) { + printf("%02x ", _binary_test_vs_spv_start[i]); + } + printf("\n"); + } + + if (ps_size > 0) { + printf("test.ps.spv first 4 bytes: "); + for (uint32_t i = 0; i < 4 && i < ps_size; i++) { + printf("%02x ", _binary_test_ps_spv_start[i]); + } + printf("\n"); + } + + return 0; +} + diff --git a/tests/projects/other/hlsl2spv_bin2obj/src/test.ps.hlsl b/tests/projects/other/hlsl2spv_bin2obj/src/test.ps.hlsl new file mode 100644 index 000000000..5c534d30b --- /dev/null +++ b/tests/projects/other/hlsl2spv_bin2obj/src/test.ps.hlsl @@ -0,0 +1,9 @@ +struct PSInput { + float4 position : SV_POSITION; + float2 texcoord : TEXCOORD0; +}; + +float4 main(PSInput input) : SV_TARGET { + return float4(input.texcoord, 0.0, 1.0); +} + diff --git a/tests/projects/other/hlsl2spv_bin2obj/src/test.vs.hlsl b/tests/projects/other/hlsl2spv_bin2obj/src/test.vs.hlsl new file mode 100644 index 000000000..e86b3b263 --- /dev/null +++ b/tests/projects/other/hlsl2spv_bin2obj/src/test.vs.hlsl @@ -0,0 +1,17 @@ +struct VSInput { + float3 position : POSITION; + float2 texcoord : TEXCOORD0; +}; + +struct VSOutput { + float4 position : SV_POSITION; + float2 texcoord : TEXCOORD0; +}; + +VSOutput main(VSInput input) { + VSOutput output; + output.position = float4(input.position, 1.0); + output.texcoord = input.texcoord; + return output; +} + diff --git a/tests/projects/other/hlsl2spv_bin2obj/xmake.lua b/tests/projects/other/hlsl2spv_bin2obj/xmake.lua new file mode 100644 index 000000000..2184d24cc --- /dev/null +++ b/tests/projects/other/hlsl2spv_bin2obj/xmake.lua @@ -0,0 +1,11 @@ +add_rules("mode.debug", "mode.release") + +add_requires("glslang", {configs = {binaryonly = true}}) + +target("test") + set_kind("binary") + add_rules("utils.hlsl2spv", {bin2obj = true}) + add_files("src/*.c") + add_files("src/*.hlsl", "src/*.hlsl") + add_packages("directxshadercompiler") + |
