mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2025-01-28 13:05:02 -08:00
demos: Use the assembler to embed HLSL sources.
This commit is contained in:
parent
4227858cfe
commit
fb4b150f27
Notes:
Henri Verbeet
2025-01-13 16:45:58 +01:00
Approved-by: Henri Verbeet (@hverbeet) Approved-by: Giovanni Mascellani (@giomasce) Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/1337
14
Makefile.am
14
Makefile.am
@ -516,16 +516,18 @@ EXTRA_DIST += $(vkd3d_shader_tests)
|
||||
|
||||
if BUILD_DEMOS
|
||||
DEMOS_LDADD = $(LDADD) libvkd3d-shader.la @DL_LIBS@ @DEMO_LIBS@
|
||||
DEMOS_CFLAGS = $(AM_CFLAGS) @DEMO_CFLAGS@
|
||||
DEMOS_CFLAGS = $(AM_CFLAGS) @DEMO_CFLAGS@ -Wa,-I$(srcdir)/demos
|
||||
bin_PROGRAMS += $(vkd3d_demos)
|
||||
|
||||
demos_vkd3d_gears_SOURCES = demos/gears.c demos/gears_hlsl.h
|
||||
demos_vkd3d_gears_SOURCES = demos/gears.c demos/gears.hlsl
|
||||
demos_vkd3d_gears_CFLAGS = $(DEMOS_CFLAGS)
|
||||
demos_vkd3d_gears_LDADD = $(DEMOS_LDADD) -lm
|
||||
demos/vkd3d_gears-gears.$(OBJEXT): demos/gears.hlsl
|
||||
|
||||
demos_vkd3d_triangle_SOURCES = demos/triangle.c demos/triangle_hlsl.h
|
||||
demos_vkd3d_triangle_SOURCES = demos/triangle.c demos/triangle.hlsl
|
||||
demos_vkd3d_triangle_CFLAGS = $(DEMOS_CFLAGS)
|
||||
demos_vkd3d_triangle_LDADD = $(DEMOS_LDADD)
|
||||
demos/vkd3d_triangle-triangle.$(OBJEXT): demos/triangle.hlsl
|
||||
endif
|
||||
|
||||
noinst_HEADERS = $(vkd3d_test_headers) $(vkd3d_demos_headers)
|
||||
@ -586,7 +588,7 @@ dummy-vkd3d-version:
|
||||
## Cross-compile tests
|
||||
cross_implibs = crosslibs/d3d12
|
||||
CROSS_CPPFLAGS = -I$(srcdir)/include -I$(srcdir)/include/private -I$(builddir)/include -I$(builddir)/tests
|
||||
CROSS_CFLAGS = -g -O2 -Wall -municode ${CROSS_CPPFLAGS} \
|
||||
CROSS_CFLAGS = -g -O2 -Wall -municode ${CROSS_CPPFLAGS} -Wa,-I$(srcdir)/demos \
|
||||
-D_WIN32_WINNT=0x0600 -D__USE_MINGW_ANSI_STDIO=0 -DVKD3D_CROSSTEST=1
|
||||
EXTRA_DIST += $(cross_implibs:=.cross32.def) $(cross_implibs:=.cross64.def)
|
||||
EXTRA_DIST += tests/driver.c tests/shader_runner_d3d11.c tests/shader_runner_d3d9.c
|
||||
@ -610,6 +612,8 @@ CROSS32_EXEFILES += $(vkd3d_cross_tests:=.cross32.exe)
|
||||
endif
|
||||
if BUILD_DEMOS
|
||||
CROSS32_EXEFILES += $(vkd3d_demos:demos/vkd3d-%=demos/%.cross32.exe)
|
||||
demos/gears.cross32.exe: demos/gears.hlsl
|
||||
demos/triangle.cross32.exe: demos/triangle.hlsl
|
||||
endif
|
||||
|
||||
CROSS32_FILES = $(CROSS32_EXEFILES)
|
||||
@ -657,6 +661,8 @@ CROSS64_EXEFILES += $(vkd3d_cross_tests:=.cross64.exe)
|
||||
endif
|
||||
if BUILD_DEMOS
|
||||
CROSS64_EXEFILES += $(vkd3d_demos:demos/vkd3d-%=demos/%.cross64.exe)
|
||||
demos/gears.cross64.exe: demos/gears.hlsl
|
||||
demos/triangle.cross64.exe: demos/triangle.hlsl
|
||||
endif
|
||||
|
||||
CROSS64_FILES = $(CROSS64_EXEFILES)
|
||||
|
36
demos/demo.h
36
demos/demo.h
@ -39,6 +39,42 @@
|
||||
#include <vkd3d_d3d12.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#ifdef __WIN32__
|
||||
#define DEMO_ASM_PUSHSECTION ".section rdata\n\t"
|
||||
#define DEMO_ASM_POPSECTION ".text\n\t"
|
||||
#define DEMO_ASM_OBJECT_TYPE(name)
|
||||
#else
|
||||
#define DEMO_ASM_PUSHSECTION ".pushsection .rodata\n\t"
|
||||
#define DEMO_ASM_POPSECTION ".popsection\n\t"
|
||||
#define DEMO_ASM_OBJECT_TYPE(name) ".type "name", @object\n\t"
|
||||
#endif
|
||||
|
||||
#if defined(__WIN32__) && defined(__i386__)
|
||||
#define DEMO_ASM_NAME(name) "_"#name
|
||||
#else
|
||||
#define DEMO_ASM_NAME(name) #name
|
||||
#endif
|
||||
|
||||
#define DEMO_EMBED_ASM(name, file) \
|
||||
DEMO_ASM_PUSHSECTION \
|
||||
".global "name"\n\t" \
|
||||
DEMO_ASM_OBJECT_TYPE(name) \
|
||||
".balign 8\n\t" \
|
||||
name":\n\t" \
|
||||
".incbin \""file"\"\n\t" \
|
||||
name"_end:\n\t" \
|
||||
".global "name"_size\n\t" \
|
||||
DEMO_ASM_OBJECT_TYPE(name"_size") \
|
||||
".balign 8\n\t" \
|
||||
name"_size:\n\t" \
|
||||
".int "name"_end - "name"\n\t" \
|
||||
DEMO_ASM_POPSECTION
|
||||
|
||||
#define DEMO_EMBED(name, file) \
|
||||
extern const unsigned int name##_size; \
|
||||
extern const uint8_t name[]; \
|
||||
__asm__(DEMO_EMBED_ASM(DEMO_ASM_NAME(name), file))
|
||||
|
||||
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(*x))
|
||||
|
||||
#define DEMO_KEY_UNKNOWN 0x0000
|
||||
|
@ -48,7 +48,7 @@
|
||||
#include <math.h>
|
||||
#include "demo.h"
|
||||
|
||||
#include "gears_hlsl.h"
|
||||
DEMO_EMBED(gears_hlsl, "gears.hlsl");
|
||||
|
||||
struct cxg_fence
|
||||
{
|
||||
@ -681,11 +681,14 @@ static void cxg_load_assets(struct cx_gears *cxg)
|
||||
hr = demo_create_root_signature(cxg->device, &root_signature_desc, &cxg->root_signature);
|
||||
assert(SUCCEEDED(hr));
|
||||
|
||||
hr = D3DCompile(gears_hlsl, strlen(gears_hlsl), NULL, NULL, NULL, "vs_main", "vs_5_0", 0, 0, &vs, NULL);
|
||||
hr = D3DCompile(gears_hlsl, gears_hlsl_size, "gears.hlsl",
|
||||
NULL, NULL, "vs_main", "vs_5_0", 0, 0, &vs, NULL);
|
||||
assert(SUCCEEDED(hr));
|
||||
hr = D3DCompile(gears_hlsl, strlen(gears_hlsl), NULL, NULL, NULL, "ps_main_flat", "ps_5_0", 0, 0, &ps_flat, NULL);
|
||||
hr = D3DCompile(gears_hlsl, gears_hlsl_size, "gears.hlsl",
|
||||
NULL, NULL, "ps_main_flat", "ps_5_0", 0, 0, &ps_flat, NULL);
|
||||
assert(SUCCEEDED(hr));
|
||||
hr = D3DCompile(gears_hlsl, strlen(gears_hlsl), NULL, NULL, NULL, "ps_main_smooth", "ps_5_0", 0, 0, &ps_smooth, NULL);
|
||||
hr = D3DCompile(gears_hlsl, gears_hlsl_size, "gears.hlsl",
|
||||
NULL, NULL, "ps_main_smooth", "ps_5_0", 0, 0, &ps_smooth, NULL);
|
||||
assert(SUCCEEDED(hr));
|
||||
|
||||
memset(&pso_desc, 0, sizeof(pso_desc));
|
||||
|
55
demos/gears.hlsl
Normal file
55
demos/gears.hlsl
Normal file
@ -0,0 +1,55 @@
|
||||
cbuffer gear_block : register(b0)
|
||||
{
|
||||
float4x4 mvp_matrix;
|
||||
float3x3 normal_matrix;
|
||||
};
|
||||
|
||||
struct vs_in
|
||||
{
|
||||
float4 position : POSITION;
|
||||
float3 normal : NORMAL;
|
||||
float3 diffuse : DIFFUSE;
|
||||
float4 transform : TRANSFORM;
|
||||
};
|
||||
|
||||
struct vs_out
|
||||
{
|
||||
float4 position : SV_POSITION;
|
||||
float4 colour : COLOR;
|
||||
};
|
||||
|
||||
struct vs_out vs_main(struct vs_in i)
|
||||
{
|
||||
const float3 l_pos = float3(5.0, 5.0, 10.0);
|
||||
float3 dir, normal;
|
||||
float4 position;
|
||||
struct vs_out o;
|
||||
float att;
|
||||
|
||||
position.x = i.transform.x * i.position.x - i.transform.y * i.position.y + i.transform.z;
|
||||
position.y = i.transform.x * i.position.y + i.transform.y * i.position.x + i.transform.w;
|
||||
position.zw = i.position.zw;
|
||||
|
||||
o.position = mul(mvp_matrix, position);
|
||||
dir = normalize(l_pos - o.position.xyz / o.position.w);
|
||||
|
||||
normal.x = i.transform.x * i.normal.x - i.transform.y * i.normal.y;
|
||||
normal.y = i.transform.x * i.normal.y + i.transform.y * i.normal.x;
|
||||
normal.z = i.normal.z;
|
||||
att = 0.2 + dot(dir, normalize(mul(normal_matrix, normal)));
|
||||
|
||||
o.colour.xyz = i.diffuse.xyz * att;
|
||||
o.colour.w = 1.0;
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
float4 ps_main_smooth(float4 position : SV_POSITION, float4 colour : COLOR) : SV_TARGET
|
||||
{
|
||||
return colour;
|
||||
}
|
||||
|
||||
float4 ps_main_flat(float4 position : SV_POSITION, nointerpolation float4 colour : COLOR) : SV_TARGET
|
||||
{
|
||||
return colour;
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
static const char gears_hlsl[] =
|
||||
"cbuffer gear_block : register(b0)\n"
|
||||
"{\n"
|
||||
" float4x4 mvp_matrix;\n"
|
||||
" float3x3 normal_matrix;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"struct vs_in\n"
|
||||
"{\n"
|
||||
" float4 position : POSITION;\n"
|
||||
" float3 normal : NORMAL;\n"
|
||||
" float3 diffuse : DIFFUSE;\n"
|
||||
" float4 transform : TRANSFORM;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"struct vs_out\n"
|
||||
"{\n"
|
||||
" float4 position : SV_POSITION;\n"
|
||||
" float4 colour : COLOR;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"struct vs_out vs_main(struct vs_in i)\n"
|
||||
"{\n"
|
||||
" const float3 l_pos = float3(5.0, 5.0, 10.0);\n"
|
||||
" float3 dir, normal;\n"
|
||||
" float4 position;\n"
|
||||
" struct vs_out o;\n"
|
||||
" float att;\n"
|
||||
"\n"
|
||||
" position.x = i.transform.x * i.position.x - i.transform.y * i.position.y + i.transform.z;\n"
|
||||
" position.y = i.transform.x * i.position.y + i.transform.y * i.position.x + i.transform.w;\n"
|
||||
" position.zw = i.position.zw;\n"
|
||||
"\n"
|
||||
" o.position = mul(mvp_matrix, position);\n"
|
||||
" dir = normalize(l_pos - o.position.xyz / o.position.w);\n"
|
||||
"\n"
|
||||
" normal.x = i.transform.x * i.normal.x - i.transform.y * i.normal.y;\n"
|
||||
" normal.y = i.transform.x * i.normal.y + i.transform.y * i.normal.x;\n"
|
||||
" normal.z = i.normal.z;\n"
|
||||
" att = 0.2 + dot(dir, normalize(mul(normal_matrix, normal)));\n"
|
||||
"\n"
|
||||
" o.colour.xyz = i.diffuse.xyz * att;\n"
|
||||
" o.colour.w = 1.0;\n"
|
||||
"\n"
|
||||
" return o;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"float4 ps_main_smooth(float4 position : SV_POSITION, float4 colour : COLOR) : SV_TARGET\n"
|
||||
"{\n"
|
||||
" return colour;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"float4 ps_main_flat(float4 position : SV_POSITION, nointerpolation float4 colour : COLOR) : SV_TARGET\n"
|
||||
"{\n"
|
||||
" return colour;\n"
|
||||
"}\n";
|
@ -45,7 +45,7 @@
|
||||
#include <assert.h>
|
||||
#include "demo.h"
|
||||
|
||||
#include "triangle_hlsl.h"
|
||||
DEMO_EMBED(triangle_hlsl, "triangle.hlsl");
|
||||
|
||||
struct cxt_fence
|
||||
{
|
||||
@ -285,9 +285,11 @@ static void cxt_load_assets(struct cx_triangle *cxt)
|
||||
hr = demo_create_root_signature(cxt->device, &root_signature_desc, &cxt->root_signature);
|
||||
assert(SUCCEEDED(hr));
|
||||
|
||||
hr = D3DCompile(triangle_hlsl, strlen(triangle_hlsl), NULL, NULL, NULL, "vs_main", "vs_5_0", 0, 0, &vs, NULL);
|
||||
hr = D3DCompile(triangle_hlsl, triangle_hlsl_size, "triangle.hlsl",
|
||||
NULL, NULL, "vs_main", "vs_5_0", 0, 0, &vs, NULL);
|
||||
assert(SUCCEEDED(hr));
|
||||
hr = D3DCompile(triangle_hlsl, strlen(triangle_hlsl), NULL, NULL, NULL, "ps_main", "ps_5_0", 0, 0, &ps, NULL);
|
||||
hr = D3DCompile(triangle_hlsl, triangle_hlsl_size, "triangle.hlsl",
|
||||
NULL, NULL, "ps_main", "ps_5_0", 0, 0, &ps, NULL);
|
||||
assert(SUCCEEDED(hr));
|
||||
|
||||
memset(&pso_desc, 0, sizeof(pso_desc));
|
||||
|
20
demos/triangle.hlsl
Normal file
20
demos/triangle.hlsl
Normal file
@ -0,0 +1,20 @@
|
||||
struct ps_in
|
||||
{
|
||||
float4 position : SV_POSITION;
|
||||
float4 colour : COLOR;
|
||||
};
|
||||
|
||||
struct ps_in vs_main(float4 position : POSITION, float4 colour : COLOR)
|
||||
{
|
||||
struct ps_in o;
|
||||
|
||||
o.position = position;
|
||||
o.colour = colour;
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
float4 ps_main(struct ps_in i) : SV_TARGET
|
||||
{
|
||||
return i.colour;
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
static const char triangle_hlsl[] =
|
||||
"struct ps_in\n"
|
||||
"{\n"
|
||||
" float4 position : SV_POSITION;\n"
|
||||
" float4 colour : COLOR;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"struct ps_in vs_main(float4 position : POSITION, float4 colour : COLOR)\n"
|
||||
"{\n"
|
||||
" struct ps_in o;\n"
|
||||
"\n"
|
||||
" o.position = position;\n"
|
||||
" o.colour = colour;\n"
|
||||
"\n"
|
||||
" return o;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"float4 ps_main(struct ps_in i) : SV_TARGET\n"
|
||||
"{\n"
|
||||
" return i.colour;\n"
|
||||
"}\n";
|
Loading…
x
Reference in New Issue
Block a user