diff options
| author | ruki <[email protected]> | 2025-12-08 09:47:56 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-12-08 09:47:56 +0800 |
| commit | c5ca6a600f87ca54ce8361638c7f49b682fa57ff (patch) | |
| tree | a0fe773e7cbb4102747231ca958952867263c8f2 /tests/projects | |
| parent | 4e4b28eb4cad79cc4df5fca887b4f4b709f2b211 (diff) | |
| parent | c4f48bbfda999f7b6dfb575059f4c5b676643294 (diff) | |
Merge pull request #7105 from xmake-io/spv
add bin2obj support for glsl/hlsl2spv
Diffstat (limited to 'tests/projects')
22 files changed, 485 insertions, 79 deletions
diff --git a/tests/projects/other/glsl2spv/.gitignore b/tests/projects/other/glsl2spv/.gitignore deleted file mode 100644 index 152105761..000000000 --- a/tests/projects/other/glsl2spv/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Xmake cache -.xmake/ -build/ - -# MacOS Cache -.DS_Store - - diff --git a/tests/projects/other/glsl2spv/src/main.c b/tests/projects/other/glsl2spv/src/main.c deleted file mode 100644 index 56e54d771..000000000 --- a/tests/projects/other/glsl2spv/src/main.c +++ /dev/null @@ -1,16 +0,0 @@ -#include <stdio.h> - -static unsigned char g_test_vert_spv_data[] = { - #include "test.vert.spv.h" -}; - -static unsigned char g_test_frag_spv_data[] = { - #include "test.frag.spv.h" -}; - -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_bin2c/src/main.c b/tests/projects/other/glsl2spv_bin2c/src/main.c new file mode 100644 index 000000000..3dfe7b351 --- /dev/null +++ b/tests/projects/other/glsl2spv_bin2c/src/main.c @@ -0,0 +1,99 @@ +#include <stdio.h> +#include <stdint.h> +#include <ctype.h> + +static unsigned char g_test_vert_spv_data[] = { + #include "test.vert.spv.h" +}; + +static unsigned char g_test_frag_spv_data[] = { + #include "test.frag.spv.h" +}; + +static void hexdump(const char* name, const uint8_t* data, uint32_t size) { + printf("%s: size: %u bytes\n", name, (unsigned int)size); + if (size == 0) { + return; + } + + // if file is larger than 128 bytes, only dump first 64 and last 64 bytes + uint32_t dump_size = size; + uint32_t start_offset = 0; + uint32_t end_offset = 0; + uint32_t skip_size = 0; + + if (size > 128) { + dump_size = 64; + start_offset = 0; + end_offset = size - 64; + skip_size = end_offset - start_offset - dump_size; + } + + // dump start + for (uint32_t offset = start_offset; offset < start_offset + dump_size; offset += 16) { + // print offset + printf("%08x ", (unsigned int)offset); + + // print hex bytes (8 bytes, space, 8 bytes) + for (uint32_t i = 0; i < 16; i++) { + if (offset + i < size) { + printf("%02x ", data[offset + i]); + } else { + printf(" "); + } + if (i == 7) { + printf(" "); + } + } + + // print ASCII representation + printf(" |"); + for (uint32_t i = 0; i < 16 && offset + i < size; i++) { + uint8_t c = data[offset + i]; + printf("%c", isprint(c) ? c : '.'); + } + printf("|\n"); + } + + // print skip indicator if needed + if (skip_size > 0) { + printf(" ... (skipped %u bytes) ...\n", (unsigned int)skip_size); + } + + // dump end if needed + if (size > 128) { + for (uint32_t offset = end_offset; offset < size; offset += 16) { + // print offset + printf("%08x ", (unsigned int)offset); + + // print hex bytes (8 bytes, space, 8 bytes) + for (uint32_t i = 0; i < 16; i++) { + if (offset + i < size) { + printf("%02x ", data[offset + i]); + } else { + printf(" "); + } + if (i == 7) { + printf(" "); + } + } + + // print ASCII representation + printf(" |"); + for (uint32_t i = 0; i < 16 && offset + i < size; i++) { + uint8_t c = data[offset + i]; + printf("%c", isprint(c) ? c : '.'); + } + printf("|\n"); + } + } +} + +int main(int argc, char** argv) +{ + hexdump("test.vert.spv", g_test_vert_spv_data, (uint32_t)sizeof(g_test_vert_spv_data)); + printf("\n"); + hexdump("test.frag.spv", g_test_frag_spv_data, (uint32_t)sizeof(g_test_frag_spv_data)); + return 0; +} + diff --git a/tests/projects/other/glsl2spv/src/test.frag b/tests/projects/other/glsl2spv_bin2c/src/test.frag index 9aeec4257..9aeec4257 100644 --- a/tests/projects/other/glsl2spv/src/test.frag +++ b/tests/projects/other/glsl2spv_bin2c/src/test.frag diff --git a/tests/projects/other/glsl2spv/src/test.vert b/tests/projects/other/glsl2spv_bin2c/src/test.vert index 31dedf3e7..9aeec4257 100644 --- a/tests/projects/other/glsl2spv/src/test.vert +++ b/tests/projects/other/glsl2spv_bin2c/src/test.vert @@ -3,3 +3,4 @@ precision mediump float; void main() { } + diff --git a/tests/projects/other/glsl2spv/xmake.lua b/tests/projects/other/glsl2spv_bin2c/xmake.lua index 111927e56..111927e56 100644 --- a/tests/projects/other/glsl2spv/xmake.lua +++ b/tests/projects/other/glsl2spv_bin2c/xmake.lua 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..6e5449fac --- /dev/null +++ b/tests/projects/other/glsl2spv_bin2obj/src/main.c @@ -0,0 +1,99 @@ +#include <stdio.h> +#include <stdint.h> +#include <ctype.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[]; + +static void hexdump(const char* name, const uint8_t* data, uint32_t size) { + printf("%s: size: %u bytes\n", name, (unsigned int)size); + if (size == 0) { + return; + } + + // if file is larger than 128 bytes, only dump first 64 and last 64 bytes + uint32_t dump_size = size; + uint32_t start_offset = 0; + uint32_t end_offset = 0; + uint32_t skip_size = 0; + + if (size > 128) { + dump_size = 64; + start_offset = 0; + end_offset = size - 64; + skip_size = end_offset - start_offset - dump_size; + } + + // dump start + for (uint32_t offset = start_offset; offset < start_offset + dump_size; offset += 16) { + // print offset + printf("%08x ", (unsigned int)offset); + + // print hex bytes (8 bytes, space, 8 bytes) + for (uint32_t i = 0; i < 16; i++) { + if (offset + i < size) { + printf("%02x ", data[offset + i]); + } else { + printf(" "); + } + if (i == 7) { + printf(" "); + } + } + + // print ASCII representation + printf(" |"); + for (uint32_t i = 0; i < 16 && offset + i < size; i++) { + uint8_t c = data[offset + i]; + printf("%c", isprint(c) ? c : '.'); + } + printf("|\n"); + } + + // print skip indicator if needed + if (skip_size > 0) { + printf(" ... (skipped %u bytes) ...\n", (unsigned int)skip_size); + } + + // dump end if needed + if (size > 128) { + for (uint32_t offset = end_offset; offset < size; offset += 16) { + // print offset + printf("%08x ", (unsigned int)offset); + + // print hex bytes (8 bytes, space, 8 bytes) + for (uint32_t i = 0; i < 16; i++) { + if (offset + i < size) { + printf("%02x ", data[offset + i]); + } else { + printf(" "); + } + if (i == 7) { + printf(" "); + } + } + + // print ASCII representation + printf(" |"); + for (uint32_t i = 0; i < 16 && offset + i < size; i++) { + uint8_t c = data[offset + i]; + printf("%c", isprint(c) ? c : '.'); + } + printf("|\n"); + } + } +} + +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); + + hexdump("test.vert.spv", _binary_test_vert_spv_start, vert_size); + printf("\n"); + hexdump("test.frag.spv", _binary_test_frag_spv_start, frag_size); + 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/.gitignore b/tests/projects/other/hlsl2spv/.gitignore deleted file mode 100644 index 152105761..000000000 --- a/tests/projects/other/hlsl2spv/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Xmake cache -.xmake/ -build/ - -# MacOS Cache -.DS_Store - - diff --git a/tests/projects/other/hlsl2spv/src/main.c b/tests/projects/other/hlsl2spv/src/main.c deleted file mode 100644 index 29a65edb1..000000000 --- a/tests/projects/other/hlsl2spv/src/main.c +++ /dev/null @@ -1,16 +0,0 @@ -#include <stdio.h> - -static unsigned char g_test_vert_spv_data[] = { - #include "test.vs.spv.h" -}; - -static unsigned char g_test_frag_spv_data[] = { - #include "test.ps.spv.h" -}; - -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/src/test.ps.hlsl b/tests/projects/other/hlsl2spv/src/test.ps.hlsl deleted file mode 100644 index 95c63d53c..000000000 --- a/tests/projects/other/hlsl2spv/src/test.ps.hlsl +++ /dev/null @@ -1,10 +0,0 @@ -struct PS_INPUT -{ - float4 pos : SV_POSITION; - float3 color : COLOR0; -}; - -float4 main(PS_INPUT input) : SV_Target -{ - return float4(input.color, 1.0); -} diff --git a/tests/projects/other/hlsl2spv/src/test.vs.hlsl b/tests/projects/other/hlsl2spv/src/test.vs.hlsl deleted file mode 100644 index 97fab0408..000000000 --- a/tests/projects/other/hlsl2spv/src/test.vs.hlsl +++ /dev/null @@ -1,19 +0,0 @@ -struct VS_INPUT -{ - float2 pos : POSITION; - float3 color : COLOR0; -}; - -struct VS_OUTPUT -{ - float4 pos : SV_POSITION; - float3 color : COLOR0; -}; - -VS_OUTPUT main(VS_INPUT input) -{ - VS_OUTPUT output; - output.pos = float4(input.pos, 0.0, 1.0); - output.color = input.color; - return output; -} diff --git a/tests/projects/other/hlsl2spv_bin2c/src/main.c b/tests/projects/other/hlsl2spv_bin2c/src/main.c new file mode 100644 index 000000000..0a05e7506 --- /dev/null +++ b/tests/projects/other/hlsl2spv_bin2c/src/main.c @@ -0,0 +1,99 @@ +#include <stdio.h> +#include <stdint.h> +#include <ctype.h> + +static unsigned char g_test_vs_spv_data[] = { + #include "test.vs.spv.h" +}; + +static unsigned char g_test_ps_spv_data[] = { + #include "test.ps.spv.h" +}; + +static void hexdump(const char* name, const uint8_t* data, uint32_t size) { + printf("%s: size: %u bytes\n", name, (unsigned int)size); + if (size == 0) { + return; + } + + // if file is larger than 128 bytes, only dump first 64 and last 64 bytes + uint32_t dump_size = size; + uint32_t start_offset = 0; + uint32_t end_offset = 0; + uint32_t skip_size = 0; + + if (size > 128) { + dump_size = 64; + start_offset = 0; + end_offset = size - 64; + skip_size = end_offset - start_offset - dump_size; + } + + // dump start + for (uint32_t offset = start_offset; offset < start_offset + dump_size; offset += 16) { + // print offset + printf("%08x ", (unsigned int)offset); + + // print hex bytes (8 bytes, space, 8 bytes) + for (uint32_t i = 0; i < 16; i++) { + if (offset + i < size) { + printf("%02x ", data[offset + i]); + } else { + printf(" "); + } + if (i == 7) { + printf(" "); + } + } + + // print ASCII representation + printf(" |"); + for (uint32_t i = 0; i < 16 && offset + i < size; i++) { + uint8_t c = data[offset + i]; + printf("%c", isprint(c) ? c : '.'); + } + printf("|\n"); + } + + // print skip indicator if needed + if (skip_size > 0) { + printf(" ... (skipped %u bytes) ...\n", (unsigned int)skip_size); + } + + // dump end if needed + if (size > 128) { + for (uint32_t offset = end_offset; offset < size; offset += 16) { + // print offset + printf("%08x ", (unsigned int)offset); + + // print hex bytes (8 bytes, space, 8 bytes) + for (uint32_t i = 0; i < 16; i++) { + if (offset + i < size) { + printf("%02x ", data[offset + i]); + } else { + printf(" "); + } + if (i == 7) { + printf(" "); + } + } + + // print ASCII representation + printf(" |"); + for (uint32_t i = 0; i < 16 && offset + i < size; i++) { + uint8_t c = data[offset + i]; + printf("%c", isprint(c) ? c : '.'); + } + printf("|\n"); + } + } +} + +int main(int argc, char** argv) +{ + hexdump("test.vs.spv", g_test_vs_spv_data, (uint32_t)sizeof(g_test_vs_spv_data)); + printf("\n"); + hexdump("test.ps.spv", g_test_ps_spv_data, (uint32_t)sizeof(g_test_ps_spv_data)); + return 0; +} + diff --git a/tests/projects/other/hlsl2spv_bin2c/src/test.ps.hlsl b/tests/projects/other/hlsl2spv_bin2c/src/test.ps.hlsl new file mode 100644 index 000000000..5c534d30b --- /dev/null +++ b/tests/projects/other/hlsl2spv_bin2c/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_bin2c/src/test.vs.hlsl b/tests/projects/other/hlsl2spv_bin2c/src/test.vs.hlsl new file mode 100644 index 000000000..e86b3b263 --- /dev/null +++ b/tests/projects/other/hlsl2spv_bin2c/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_bin2c/xmake.lua b/tests/projects/other/hlsl2spv_bin2c/xmake.lua new file mode 100644 index 000000000..944747cba --- /dev/null +++ b/tests/projects/other/hlsl2spv_bin2c/xmake.lua @@ -0,0 +1,11 @@ +add_rules("mode.debug", "mode.release") + +add_requires("directxshadercompiler", {configs = {binaryonly = true}}) + +target("test") + set_kind("binary") + add_rules("utils.hlsl2spv", {bin2c = true}) + add_files("src/*.c") + add_files("src/*.vs.hlsl", "src/*.ps.hlsl") + add_packages("directxshadercompiler") + 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..4d163f576 --- /dev/null +++ b/tests/projects/other/hlsl2spv_bin2obj/src/main.c @@ -0,0 +1,99 @@ +#include <stdio.h> +#include <stdint.h> +#include <ctype.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[]; + +static void hexdump(const char* name, const uint8_t* data, uint32_t size) { + printf("%s: size: %u bytes\n", name, (unsigned int)size); + if (size == 0) { + return; + } + + // if file is larger than 128 bytes, only dump first 64 and last 64 bytes + uint32_t dump_size = size; + uint32_t start_offset = 0; + uint32_t end_offset = 0; + uint32_t skip_size = 0; + + if (size > 128) { + dump_size = 64; + start_offset = 0; + end_offset = size - 64; + skip_size = end_offset - start_offset - dump_size; + } + + // dump start + for (uint32_t offset = start_offset; offset < start_offset + dump_size; offset += 16) { + // print offset + printf("%08x ", (unsigned int)offset); + + // print hex bytes (8 bytes, space, 8 bytes) + for (uint32_t i = 0; i < 16; i++) { + if (offset + i < size) { + printf("%02x ", data[offset + i]); + } else { + printf(" "); + } + if (i == 7) { + printf(" "); + } + } + + // print ASCII representation + printf(" |"); + for (uint32_t i = 0; i < 16 && offset + i < size; i++) { + uint8_t c = data[offset + i]; + printf("%c", isprint(c) ? c : '.'); + } + printf("|\n"); + } + + // print skip indicator if needed + if (skip_size > 0) { + printf(" ... (skipped %u bytes) ...\n", (unsigned int)skip_size); + } + + // dump end if needed + if (size > 128) { + for (uint32_t offset = end_offset; offset < size; offset += 16) { + // print offset + printf("%08x ", (unsigned int)offset); + + // print hex bytes (8 bytes, space, 8 bytes) + for (uint32_t i = 0; i < 16; i++) { + if (offset + i < size) { + printf("%02x ", data[offset + i]); + } else { + printf(" "); + } + if (i == 7) { + printf(" "); + } + } + + // print ASCII representation + printf(" |"); + for (uint32_t i = 0; i < 16 && offset + i < size; i++) { + uint8_t c = data[offset + i]; + printf("%c", isprint(c) ? c : '.'); + } + printf("|\n"); + } + } +} + +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); + + hexdump("test.vs.spv", _binary_test_vs_spv_start, vs_size); + printf("\n"); + hexdump("test.ps.spv", _binary_test_ps_spv_start, ps_size); + 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/xmake.lua b/tests/projects/other/hlsl2spv_bin2obj/xmake.lua index 0487fba5d..4d09e5036 100644 --- a/tests/projects/other/hlsl2spv/xmake.lua +++ b/tests/projects/other/hlsl2spv_bin2obj/xmake.lua @@ -4,8 +4,8 @@ add_requires("glslang", {configs = {binaryonly = true}}) target("test") set_kind("binary") - add_rules("utils.hlsl2spv", {bin2c = true}) + add_rules("utils.hlsl2spv", {bin2obj = true}) add_files("src/*.c") - add_files("src/*.hlsl", "src/*.hlsl") + add_files("src/*.hlsl") add_packages("directxshadercompiler") |
