From aa5d48eec4987c4c1cb55571b536cd485c25740b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B3zef=20Kucia?= Date: Fri, 28 Jul 2017 15:26:09 +0200 Subject: [PATCH] demos: Get rid of handwritten GLSL shaders. --- Makefile.am | 37 ++---- configure.ac | 3 - demos/demo_win32.h | 28 ----- demos/demo_xcb.h | 37 ------ demos/gears.c | 23 ++-- demos/gears.vert | 38 ------ demos/gears_flat.frag | 10 -- demos/gears_ps_flat.h | 73 +++++++++++ demos/gears_ps_smooth.h | 73 +++++++++++ demos/gears_smooth.frag | 10 -- demos/gears_vs.h | 272 ++++++++++++++++++++++++++++++++++++++++ demos/triangle.c | 21 ++-- demos/triangle.frag | 10 -- demos/triangle.vert | 13 -- demos/triangle_ps.h | 73 +++++++++++ demos/triangle_vs.h | 89 +++++++++++++ 16 files changed, 606 insertions(+), 204 deletions(-) delete mode 100644 demos/gears.vert delete mode 100644 demos/gears_flat.frag create mode 100644 demos/gears_ps_flat.h create mode 100644 demos/gears_ps_smooth.h delete mode 100644 demos/gears_smooth.frag create mode 100644 demos/gears_vs.h delete mode 100644 demos/triangle.frag delete mode 100644 demos/triangle.vert create mode 100644 demos/triangle_ps.h create mode 100644 demos/triangle_vs.h diff --git a/Makefile.am b/Makefile.am index c987b1b1..9e1f8549 100644 --- a/Makefile.am +++ b/Makefile.am @@ -23,21 +23,14 @@ vkd3d_public_headers = \ include/vkd3d_utils.h \ include/vkd3d_windows.h -spv_gears_shaders = \ - demos/gears.vert.spv \ - demos/gears_flat.frag.spv \ - demos/gears_smooth.frag.spv -spv_triangle_shaders = \ - demos/triangle.vert.spv \ - demos/triangle.frag.spv - -spv_shaders = \ - $(spv_gears_shaders) \ - $(spv_triangle_shaders) - -hlsl_shaders = \ +vkd3d_demos_shaders = \ demos/gears.hlsl \ - demos/triangle.hlsl + demos/gears_ps_flat.h \ + demos/gears_ps_smooth.h \ + demos/gears_vs.h \ + demos/triangle.hlsl \ + demos/triangle_ps.h \ + demos/triangle_vs.h vkd3d_tests = \ tests/d3d12 @@ -52,7 +45,6 @@ vkd3d_demos_headers = \ demos/demo_xcb.h BUILT_SOURCES = $(widl_headers) -CLEANFILES = $(spv_shaders) noinst_LTLIBRARIES = libvkd3d-common.la libvkd3d_common_la_SOURCES = \ @@ -101,7 +93,7 @@ EXTRA_DIST = LICENSE pkgconfigdir = $(libdir)/pkgconfig pkginclude_HEADERS = $(vkd3d_public_headers) nodist_pkgconfig_DATA = libvkd3d.pc libvkd3d-utils.pc -CLEANFILES += libvkd3d.pc libvkd3d-utils.pc +CLEANFILES = libvkd3d.pc libvkd3d-utils.pc EXTRA_DIST += libs/vkd3d/libvkd3d.pc.in libs/vkd3d-utils/libvkd3d-utils.pc.in bin_PROGRAMS = vkd3d-compiler @@ -119,11 +111,9 @@ DEMOS_CFLAGS = @XCB_CFLAGS@ noinst_PROGRAMS = $(vkd3d_demos) EXTRA_DIST += $(vkd3d_demos_headers) -EXTRA_demos_gears_DEPENDENCIES = $(spv_gears_shaders) demos_gears_CFLAGS = $(DEMOS_CFLAGS) demos_gears_LDADD = $(DEMOS_LDADD) -lm -EXTRA_demos_triangle_DEPENDENCIES = $(spv_triangle_shaders) demos_triangle_CFLAGS = $(DEMOS_CFLAGS) demos_triangle_LDADD = $(DEMOS_LDADD) @@ -136,16 +126,7 @@ EXTRA_DIST += $(widl_headers) $(widl_headers:.h=.idl) $(widl_headers): %.h: %.idl $(VKD3D_V_WIDL)$(WIDL) -o $@ $< -VKD3D_V_GLSLANG = $(vkd3d_v_glslang_@AM_V@) -vkd3d_v_glslang_ = $(vkd3d_v_glslang_@AM_DEFAULT_V@) -vkd3d_v_glslang_0 = @echo " GLSLANG " $@; -vkd3d_v_glslang_1 = - -EXTRA_DIST += $(spv_shaders:.spv=) -$(spv_shaders): %.spv: % - $(VKD3D_V_GLSLANG)$(GLSLANG) -V -o $@ $< - -EXTRA_DIST += $(hlsl_shaders) +EXTRA_DIST += $(vkd3d_demos_shaders) libvkd3d-utils.pc: $(srcdir)/libs/vkd3d-utils/libvkd3d-utils.pc.in sed -e 's![@]prefix[@]!$(prefix)!g' \ diff --git a/configure.ac b/configure.ac index 01ac07b5..38705e7b 100644 --- a/configure.ac +++ b/configure.ac @@ -7,7 +7,6 @@ AC_CONFIG_LIBOBJ_DIR([portable]) AC_CONFIG_HEADERS(include/config.h) AC_ARG_VAR([WIDL], [widl IDL compiler]) -AC_ARG_VAR([GLSLANG], [glslangValidator GLSL compiler]) AC_ARG_VAR([CROSSCC32], [32-bit Windows cross compiler]) AC_ARG_VAR([CROSSCC64], [64-bit Windows cross compiler]) AC_ARG_WITH([spirv-tools], AS_HELP_STRING([--with-spirv-tools], @@ -21,8 +20,6 @@ AC_PROG_SED AC_PROG_MKDIR_P AC_CHECK_PROG([WIDL], [widl], [widl], [no]) AS_IF([test "x$WIDL" = "xno"], [AC_MSG_WARN([widl is required to build header files.])]) -AC_CHECK_PROG([GLSLANG], [glslangValidator], [glslangValidator], [no]) -AS_IF([test "x$GLSLANG" = "xno"], [AC_MSG_ERROR([glslangValidator is required to compile shaders.])]) AM_INIT_AUTOMAKE([1.11 foreign silent-rules subdir-objects no-dist-gzip dist-xz -Wall -Werror]) AM_MAINTAINER_MODE([enable]) diff --git a/demos/demo_win32.h b/demos/demo_win32.h index c31cc0ca..3cdce889 100644 --- a/demos/demo_win32.h +++ b/demos/demo_win32.h @@ -340,31 +340,3 @@ static inline HRESULT demo_create_root_signature(ID3D12Device *device, return hr; } - -static inline bool demo_load_shader(struct demo *demo, const wchar_t *hlsl_name, const char *entry_point, - const char *profile, const char *spv_name, D3D12_SHADER_BYTECODE *shader) -{ - ID3D10Blob *blob, *errors; - HRESULT hr; - - hr = demo->compile_from_file(hlsl_name, NULL, NULL, entry_point, profile, 0, 0, &blob, &errors); - if (errors) - { - fprintf(stderr, "%.*s\n", (int)ID3D10Blob_GetBufferSize(errors), (char *)ID3D10Blob_GetBufferPointer(errors)); - ID3D10Blob_Release(errors); - } - if (FAILED(hr)) - return false; - - shader->BytecodeLength = ID3D10Blob_GetBufferSize(blob); - if (!(shader->pShaderBytecode = malloc(shader->BytecodeLength))) - { - ID3D10Blob_Release(blob); - return false; - } - - memcpy((void *)shader->pShaderBytecode, ID3D10Blob_GetBufferPointer(blob), shader->BytecodeLength); - - ID3D10Blob_Release(blob); - return true; -} diff --git a/demos/demo_xcb.h b/demos/demo_xcb.h index 070d14a7..1ba18ce4 100644 --- a/demos/demo_xcb.h +++ b/demos/demo_xcb.h @@ -554,40 +554,3 @@ static inline HRESULT demo_create_root_signature(ID3D12Device *device, return ID3D12Device_CreateRootSignature(device, 0, desc, ~(SIZE_T)0, &IID_ID3D12RootSignature, (void **)signature); } - -static inline bool demo_load_shader(struct demo *demo, const wchar_t *hlsl_name, const char *entry_point, - const char *profile, const char *spv_name, D3D12_SHADER_BYTECODE *shader) -{ - size_t data_size; - struct stat st; - ssize_t res; - void *data; - int fd; - - if ((fd = open(spv_name, O_RDONLY)) == -1) - return false; - - if (fstat(fd, &st) == -1) - goto fail; - - data_size = st.st_size; - if (!(data = malloc(data_size))) - goto fail; - - res = read(fd, data, data_size); - close(fd); - if (res != data_size) - { - free(data); - return false; - } - - shader->pShaderBytecode = data; - shader->BytecodeLength = data_size; - - return true; - -fail: - close(fd); - return false; -} diff --git a/demos/gears.c b/demos/gears.c index db909b4b..f7b8cada 100644 --- a/demos/gears.c +++ b/demos/gears.c @@ -48,6 +48,10 @@ #include #include "demo.h" +#include "gears_vs.h" +#include "gears_ps_flat.h" +#include "gears_ps_smooth.h" + struct cxg_fence { ID3D12Fence *fence; @@ -655,7 +659,6 @@ static void cxg_load_assets(struct cx_gears *cxg) D3D12_RANGE read_range = {0, 0}; D3D12_CLEAR_VALUE clear_value; HRESULT hr; - bool ret; root_parameter.ParameterType = D3D12_ROOT_PARAMETER_TYPE_CBV; root_parameter.Descriptor.ShaderRegister = 0; @@ -677,11 +680,10 @@ static void cxg_load_assets(struct cx_gears *cxg) pso_desc.InputLayout.pInputElementDescs = il_desc; pso_desc.InputLayout.NumElements = ARRAY_SIZE(il_desc); pso_desc.pRootSignature = cxg->root_signature; - ret = demo_load_shader(&cxg->demo, L"gears.hlsl", "vs_main", "vs_5_0", "gears.vert.spv", &pso_desc.VS); - assert(ret); - ret = demo_load_shader(&cxg->demo, L"gears.hlsl", "ps_main_flat", - "ps_5_0", "gears_flat.frag.spv", &pso_desc.PS); - assert(ret); + pso_desc.VS.pShaderBytecode = g_vs_main; + pso_desc.VS.BytecodeLength = sizeof(g_vs_main); + pso_desc.PS.pShaderBytecode = g_ps_main_flat; + pso_desc.PS.BytecodeLength = sizeof(g_ps_main_flat); demo_rasterizer_desc_init_default(&pso_desc.RasterizerState); pso_desc.RasterizerState.FrontCounterClockwise = TRUE; @@ -700,17 +702,12 @@ static void cxg_load_assets(struct cx_gears *cxg) &IID_ID3D12PipelineState, (void **)&cxg->pipeline_state_flat); assert(SUCCEEDED(hr)); - free((void *)pso_desc.PS.pShaderBytecode); - ret = demo_load_shader(&cxg->demo, L"gears.hlsl", "ps_main_smooth", - "ps_5_0", "gears_smooth.frag.spv", &pso_desc.PS); - assert(ret); + pso_desc.PS.pShaderBytecode = g_ps_main_smooth; + pso_desc.PS.BytecodeLength = sizeof(g_ps_main_smooth); hr = ID3D12Device_CreateGraphicsPipelineState(cxg->device, &pso_desc, &IID_ID3D12PipelineState, (void **)&cxg->pipeline_state_smooth); assert(SUCCEEDED(hr)); - free((void *)pso_desc.PS.pShaderBytecode); - free((void *)pso_desc.VS.pShaderBytecode); - hr = ID3D12Device_CreateCommandList(cxg->device, 0, D3D12_COMMAND_LIST_TYPE_DIRECT, cxg->command_allocator[0], cxg->pipeline_state_flat, &IID_ID3D12GraphicsCommandList, (void **)&cxg->command_list[0]); assert(SUCCEEDED(hr)); diff --git a/demos/gears.vert b/demos/gears.vert deleted file mode 100644 index ecba4975..00000000 --- a/demos/gears.vert +++ /dev/null @@ -1,38 +0,0 @@ -#version 150 -#extension GL_ARB_separate_shader_objects : enable - -layout(location = 0) in vec4 position_in; -layout(location = 1) in vec3 normal_in; -layout(location = 2) in vec3 diffuse_in; -layout(location = 3) in vec4 transform_in; - -layout(location = 0) out vec4 colour_out; - -uniform gear_block -{ - uniform mat4 mvp_matrix; - uniform mat3 normal_matrix; -} gear; - -void main() -{ - const vec3 l_pos = vec3(5.0, 5.0, 10.0); - vec3 dir, normal; - vec4 position; - float att; - - position.x = transform_in.x * position_in.x - transform_in.y * position_in.y + transform_in.z; - position.y = transform_in.x * position_in.y + transform_in.y * position_in.x + transform_in.w; - position.zw = position_in.zw; - - gl_Position = gear.mvp_matrix * position; - dir = normalize(l_pos - gl_Position.xyz / gl_Position.w); - - normal.x = transform_in.x * normal_in.x - transform_in.y * normal_in.y; - normal.y = transform_in.x * normal_in.y + transform_in.y * normal_in.x; - normal.z = normal_in.z; - att = 0.2 + dot(dir, normalize(gear.normal_matrix * normal)); - - colour_out.xyz = diffuse_in.xyz * att; - colour_out.w = 1.0; -} diff --git a/demos/gears_flat.frag b/demos/gears_flat.frag deleted file mode 100644 index 0fbabe6f..00000000 --- a/demos/gears_flat.frag +++ /dev/null @@ -1,10 +0,0 @@ -#version 150 -#extension GL_ARB_separate_shader_objects : enable - -layout(location = 0) flat in vec4 colour_in; -layout(location = 0) out vec4 colour_out; - -void main(void) -{ - colour_out = colour_in; -} diff --git a/demos/gears_ps_flat.h b/demos/gears_ps_flat.h new file mode 100644 index 00000000..413981bf --- /dev/null +++ b/demos/gears_ps_flat.h @@ -0,0 +1,73 @@ +#if 0 +// +// Generated by Microsoft (R) D3D Shader Disassembler +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_POSITION 0 xyzw 0 POS float +// COLOR 0 xyzw 1 NONE float xyzw +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_TARGET 0 xyzw 0 TARGET float xyzw +// +ps_5_0 +dcl_globalFlags refactoringAllowed +dcl_input_ps constant v1.xyzw +dcl_output o0.xyzw +mov o0.xyzw, v1.xyzw +ret +// Approximately 0 instruction slots used +#endif + +const BYTE g_ps_main_flat[] = +{ + 68, 88, 66, 67, 254, 211, + 50, 72, 228, 208, 73, 13, + 143, 221, 134, 105, 6, 165, + 26, 140, 1, 0, 0, 0, + 248, 0, 0, 0, 3, 0, + 0, 0, 44, 0, 0, 0, + 128, 0, 0, 0, 180, 0, + 0, 0, 73, 83, 71, 78, + 76, 0, 0, 0, 2, 0, + 0, 0, 8, 0, 0, 0, + 56, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 15, 0, 0, 0, + 68, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 15, 15, 0, 0, + 83, 86, 95, 80, 79, 83, + 73, 84, 73, 79, 78, 0, + 67, 79, 76, 79, 82, 0, + 171, 171, 79, 83, 71, 78, + 44, 0, 0, 0, 1, 0, + 0, 0, 8, 0, 0, 0, + 32, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 15, 0, 0, 0, + 83, 86, 95, 84, 65, 82, + 71, 69, 84, 0, 171, 171, + 83, 72, 69, 88, 60, 0, + 0, 0, 80, 0, 0, 0, + 15, 0, 0, 0, 106, 8, + 0, 1, 98, 8, 0, 3, + 242, 16, 16, 0, 1, 0, + 0, 0, 101, 0, 0, 3, + 242, 32, 16, 0, 0, 0, + 0, 0, 54, 0, 0, 5, + 242, 32, 16, 0, 0, 0, + 0, 0, 70, 30, 16, 0, + 1, 0, 0, 0, 62, 0, + 0, 1 +}; diff --git a/demos/gears_ps_smooth.h b/demos/gears_ps_smooth.h new file mode 100644 index 00000000..0407adb5 --- /dev/null +++ b/demos/gears_ps_smooth.h @@ -0,0 +1,73 @@ +#if 0 +// +// Generated by Microsoft (R) D3D Shader Disassembler +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_POSITION 0 xyzw 0 POS float +// COLOR 0 xyzw 1 NONE float xyzw +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_TARGET 0 xyzw 0 TARGET float xyzw +// +ps_5_0 +dcl_globalFlags refactoringAllowed +dcl_input_ps linear v1.xyzw +dcl_output o0.xyzw +mov o0.xyzw, v1.xyzw +ret +// Approximately 0 instruction slots used +#endif + +const BYTE g_ps_main_smooth[] = +{ + 68, 88, 66, 67, 80, 239, + 109, 26, 0, 147, 6, 156, + 240, 104, 206, 124, 185, 57, + 18, 98, 1, 0, 0, 0, + 248, 0, 0, 0, 3, 0, + 0, 0, 44, 0, 0, 0, + 128, 0, 0, 0, 180, 0, + 0, 0, 73, 83, 71, 78, + 76, 0, 0, 0, 2, 0, + 0, 0, 8, 0, 0, 0, + 56, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 15, 0, 0, 0, + 68, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 15, 15, 0, 0, + 83, 86, 95, 80, 79, 83, + 73, 84, 73, 79, 78, 0, + 67, 79, 76, 79, 82, 0, + 171, 171, 79, 83, 71, 78, + 44, 0, 0, 0, 1, 0, + 0, 0, 8, 0, 0, 0, + 32, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 15, 0, 0, 0, + 83, 86, 95, 84, 65, 82, + 71, 69, 84, 0, 171, 171, + 83, 72, 69, 88, 60, 0, + 0, 0, 80, 0, 0, 0, + 15, 0, 0, 0, 106, 8, + 0, 1, 98, 16, 0, 3, + 242, 16, 16, 0, 1, 0, + 0, 0, 101, 0, 0, 3, + 242, 32, 16, 0, 0, 0, + 0, 0, 54, 0, 0, 5, + 242, 32, 16, 0, 0, 0, + 0, 0, 70, 30, 16, 0, + 1, 0, 0, 0, 62, 0, + 0, 1 +}; diff --git a/demos/gears_smooth.frag b/demos/gears_smooth.frag deleted file mode 100644 index aa4bfed5..00000000 --- a/demos/gears_smooth.frag +++ /dev/null @@ -1,10 +0,0 @@ -#version 150 -#extension GL_ARB_separate_shader_objects : enable - -layout(location = 0) in vec4 colour_in; -layout(location = 0) out vec4 colour_out; - -void main(void) -{ - colour_out = colour_in; -} diff --git a/demos/gears_vs.h b/demos/gears_vs.h new file mode 100644 index 00000000..e3ccea8b --- /dev/null +++ b/demos/gears_vs.h @@ -0,0 +1,272 @@ +#if 0 +// +// Generated by Microsoft (R) D3D Shader Disassembler +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// POSITION 0 xyzw 0 NONE float xyzw +// NORMAL 0 xyz 1 NONE float xyz +// DIFFUSE 0 xyz 2 NONE float xyz +// TRANSFORM 0 xyzw 3 NONE float xyzw +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_POSITION 0 xyzw 0 POS float xyzw +// COLOR 0 xyzw 1 NONE float xyzw +// +vs_5_0 +dcl_globalFlags refactoringAllowed +dcl_constantbuffer CB0[7], immediateIndexed +dcl_input v0.xyzw +dcl_input v1.xyz +dcl_input v2.xyz +dcl_input v3.xyzw +dcl_output_siv o0.xyzw, position +dcl_output o1.xyzw +dcl_temps 2 +mul r0.x, v0.y, v3.y +mad r0.x, v3.x, v0.x, -r0.x +dp2 r0.y, v3.yxyy, v0.xyxx +add r0.xy, r0.xyxx, v3.zwzz +mul r1.xyzw, r0.yyyy, cb0[1].xyzw +mad r0.xyzw, cb0[0].xyzw, r0.xxxx, r1.xyzw +mad r0.xyzw, cb0[2].xyzw, v0.zzzz, r0.xyzw +mad r0.xyzw, cb0[3].xyzw, v0.wwww, r0.xyzw +mov o0.xyzw, r0.xyzw +div r0.xyz, r0.xyzx, r0.wwww +add r0.xyz, -r0.xyzx, l(5.000000, 5.000000, 10.000000, 0.000000) +dp3 r0.w, r0.xyzx, r0.xyzx +rsq r0.w, r0.w +mul r0.xyz, r0.wwww, r0.xyzx +mul r0.w, v1.y, v3.y +mad r0.w, v3.x, v1.x, -r0.w +dp2 r1.x, v3.yxyy, v1.xyxx +mul r1.xyz, r1.xxxx, cb0[5].xyzx +mad r1.xyz, cb0[4].xyzx, r0.wwww, r1.xyzx +mad r1.xyz, cb0[6].xyzx, v1.zzzz, r1.xyzx +dp3 r0.w, r1.xyzx, r1.xyzx +rsq r0.w, r0.w +mul r1.xyz, r0.wwww, r1.xyzx +dp3 r0.x, r0.xyzx, r1.xyzx +add r0.x, r0.x, l(0.200000) +mul o1.xyz, r0.xxxx, v2.xyzx +mov o1.w, l(1.000000) +ret +// Approximately 0 instruction slots used +#endif + +const BYTE g_vs_main[] = +{ + 68, 88, 66, 67, 82, 90, + 22, 185, 41, 66, 113, 173, + 43, 53, 199, 35, 30, 50, + 78, 7, 1, 0, 0, 0, + 208, 4, 0, 0, 3, 0, + 0, 0, 44, 0, 0, 0, + 192, 0, 0, 0, 20, 1, + 0, 0, 73, 83, 71, 78, + 140, 0, 0, 0, 4, 0, + 0, 0, 8, 0, 0, 0, + 104, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 15, 15, 0, 0, + 113, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 7, 7, 0, 0, + 120, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 7, 7, 0, 0, + 128, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 3, 0, + 0, 0, 15, 15, 0, 0, + 80, 79, 83, 73, 84, 73, + 79, 78, 0, 78, 79, 82, + 77, 65, 76, 0, 68, 73, + 70, 70, 85, 83, 69, 0, + 84, 82, 65, 78, 83, 70, + 79, 82, 77, 0, 171, 171, + 79, 83, 71, 78, 76, 0, + 0, 0, 2, 0, 0, 0, + 8, 0, 0, 0, 56, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 15, 0, 0, 0, 68, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 15, 0, 0, 0, 83, 86, + 95, 80, 79, 83, 73, 84, + 73, 79, 78, 0, 67, 79, + 76, 79, 82, 0, 171, 171, + 83, 72, 69, 88, 180, 3, + 0, 0, 80, 0, 1, 0, + 237, 0, 0, 0, 106, 8, + 0, 1, 89, 0, 0, 4, + 70, 142, 32, 0, 0, 0, + 0, 0, 7, 0, 0, 0, + 95, 0, 0, 3, 242, 16, + 16, 0, 0, 0, 0, 0, + 95, 0, 0, 3, 114, 16, + 16, 0, 1, 0, 0, 0, + 95, 0, 0, 3, 114, 16, + 16, 0, 2, 0, 0, 0, + 95, 0, 0, 3, 242, 16, + 16, 0, 3, 0, 0, 0, + 103, 0, 0, 4, 242, 32, + 16, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 101, 0, + 0, 3, 242, 32, 16, 0, + 1, 0, 0, 0, 104, 0, + 0, 2, 2, 0, 0, 0, + 56, 0, 0, 7, 18, 0, + 16, 0, 0, 0, 0, 0, + 26, 16, 16, 0, 0, 0, + 0, 0, 26, 16, 16, 0, + 3, 0, 0, 0, 50, 0, + 0, 10, 18, 0, 16, 0, + 0, 0, 0, 0, 10, 16, + 16, 0, 3, 0, 0, 0, + 10, 16, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 128, + 65, 0, 0, 0, 0, 0, + 0, 0, 15, 0, 0, 7, + 34, 0, 16, 0, 0, 0, + 0, 0, 22, 21, 16, 0, + 3, 0, 0, 0, 70, 16, + 16, 0, 0, 0, 0, 0, + 0, 0, 0, 7, 50, 0, + 16, 0, 0, 0, 0, 0, + 70, 0, 16, 0, 0, 0, + 0, 0, 230, 26, 16, 0, + 3, 0, 0, 0, 56, 0, + 0, 8, 242, 0, 16, 0, + 1, 0, 0, 0, 86, 5, + 16, 0, 0, 0, 0, 0, + 70, 142, 32, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 50, 0, 0, 10, 242, 0, + 16, 0, 0, 0, 0, 0, + 70, 142, 32, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 6, 0, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 50, 0, + 0, 10, 242, 0, 16, 0, + 0, 0, 0, 0, 70, 142, + 32, 0, 0, 0, 0, 0, + 2, 0, 0, 0, 166, 26, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 50, 0, 0, 10, + 242, 0, 16, 0, 0, 0, + 0, 0, 70, 142, 32, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 246, 31, 16, 0, + 0, 0, 0, 0, 70, 14, + 16, 0, 0, 0, 0, 0, + 54, 0, 0, 5, 242, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 14, 0, 0, 7, + 114, 0, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 0, 0, 0, 0, 246, 15, + 16, 0, 0, 0, 0, 0, + 0, 0, 0, 11, 114, 0, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 128, 65, 0, + 0, 0, 0, 0, 0, 0, + 2, 64, 0, 0, 0, 0, + 160, 64, 0, 0, 160, 64, + 0, 0, 32, 65, 0, 0, + 0, 0, 16, 0, 0, 7, + 130, 0, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 0, 0, 0, 0, + 68, 0, 0, 5, 130, 0, + 16, 0, 0, 0, 0, 0, + 58, 0, 16, 0, 0, 0, + 0, 0, 56, 0, 0, 7, + 114, 0, 16, 0, 0, 0, + 0, 0, 246, 15, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 0, 0, 0, 0, + 56, 0, 0, 7, 130, 0, + 16, 0, 0, 0, 0, 0, + 26, 16, 16, 0, 1, 0, + 0, 0, 26, 16, 16, 0, + 3, 0, 0, 0, 50, 0, + 0, 10, 130, 0, 16, 0, + 0, 0, 0, 0, 10, 16, + 16, 0, 3, 0, 0, 0, + 10, 16, 16, 0, 1, 0, + 0, 0, 58, 0, 16, 128, + 65, 0, 0, 0, 0, 0, + 0, 0, 15, 0, 0, 7, + 18, 0, 16, 0, 1, 0, + 0, 0, 22, 21, 16, 0, + 3, 0, 0, 0, 70, 16, + 16, 0, 1, 0, 0, 0, + 56, 0, 0, 8, 114, 0, + 16, 0, 1, 0, 0, 0, + 6, 0, 16, 0, 1, 0, + 0, 0, 70, 130, 32, 0, + 0, 0, 0, 0, 5, 0, + 0, 0, 50, 0, 0, 10, + 114, 0, 16, 0, 1, 0, + 0, 0, 70, 130, 32, 0, + 0, 0, 0, 0, 4, 0, + 0, 0, 246, 15, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 1, 0, 0, 0, + 50, 0, 0, 10, 114, 0, + 16, 0, 1, 0, 0, 0, + 70, 130, 32, 0, 0, 0, + 0, 0, 6, 0, 0, 0, + 166, 26, 16, 0, 1, 0, + 0, 0, 70, 2, 16, 0, + 1, 0, 0, 0, 16, 0, + 0, 7, 130, 0, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 1, 0, 0, 0, + 70, 2, 16, 0, 1, 0, + 0, 0, 68, 0, 0, 5, + 130, 0, 16, 0, 0, 0, + 0, 0, 58, 0, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 7, 114, 0, 16, 0, + 1, 0, 0, 0, 246, 15, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 1, 0, + 0, 0, 16, 0, 0, 7, + 18, 0, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 1, 0, 0, 0, + 0, 0, 0, 7, 18, 0, + 16, 0, 0, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 1, 64, 0, 0, + 205, 204, 76, 62, 56, 0, + 0, 7, 114, 32, 16, 0, + 1, 0, 0, 0, 6, 0, + 16, 0, 0, 0, 0, 0, + 70, 18, 16, 0, 2, 0, + 0, 0, 54, 0, 0, 5, + 130, 32, 16, 0, 1, 0, + 0, 0, 1, 64, 0, 0, + 0, 0, 128, 63, 62, 0, + 0, 1 +}; diff --git a/demos/triangle.c b/demos/triangle.c index 6366ec5f..15f348f6 100644 --- a/demos/triangle.c +++ b/demos/triangle.c @@ -45,6 +45,9 @@ #include #include "demo.h" +#include "triangle_vs.h" +#include "triangle_ps.h" + struct cxt_fence { ID3D12Fence *fence; @@ -236,16 +239,6 @@ static void cxt_destroy_assets(struct cx_triangle *cxt) ID3D12RootSignature_Release(cxt->root_signature); } -static void cxt_load_shaders(struct cx_triangle *cxt, D3D12_SHADER_BYTECODE *vs, D3D12_SHADER_BYTECODE *ps) -{ - bool ret; - - ret = demo_load_shader(&cxt->demo, L"triangle.hlsl", "vs_main", "vs_5_0", "triangle.vert.spv", vs); - assert(ret); - ret = demo_load_shader(&cxt->demo, L"triangle.hlsl", "ps_main", "ps_5_0", "triangle.frag.spv", ps); - assert(ret); -} - static void cxt_fence_create(struct cxt_fence *fence, ID3D12Device *device) { HRESULT hr; @@ -295,7 +288,10 @@ static void cxt_load_assets(struct cx_triangle *cxt) pso_desc.InputLayout.pInputElementDescs = il_desc; pso_desc.InputLayout.NumElements = ARRAY_SIZE(il_desc); pso_desc.pRootSignature = cxt->root_signature; - cxt_load_shaders(cxt, &pso_desc.VS, &pso_desc.PS); + pso_desc.VS.pShaderBytecode = g_vs_main; + pso_desc.VS.BytecodeLength = sizeof(g_vs_main); + pso_desc.PS.pShaderBytecode = g_ps_main; + pso_desc.PS.BytecodeLength = sizeof(g_ps_main); demo_rasterizer_desc_init_default(&pso_desc.RasterizerState); demo_blend_desc_init_default(&pso_desc.BlendState); pso_desc.DepthStencilState.DepthEnable = FALSE; @@ -309,9 +305,6 @@ static void cxt_load_assets(struct cx_triangle *cxt) &IID_ID3D12PipelineState, (void **)&cxt->pipeline_state); assert(SUCCEEDED(hr)); - free((void *)pso_desc.PS.pShaderBytecode); - free((void *)pso_desc.VS.pShaderBytecode); - hr = ID3D12Device_CreateCommandList(cxt->device, 0, D3D12_COMMAND_LIST_TYPE_DIRECT, cxt->command_allocator, cxt->pipeline_state, &IID_ID3D12GraphicsCommandList, (void **)&cxt->command_list); assert(SUCCEEDED(hr)); diff --git a/demos/triangle.frag b/demos/triangle.frag deleted file mode 100644 index aa4bfed5..00000000 --- a/demos/triangle.frag +++ /dev/null @@ -1,10 +0,0 @@ -#version 150 -#extension GL_ARB_separate_shader_objects : enable - -layout(location = 0) in vec4 colour_in; -layout(location = 0) out vec4 colour_out; - -void main(void) -{ - colour_out = colour_in; -} diff --git a/demos/triangle.vert b/demos/triangle.vert deleted file mode 100644 index 05362368..00000000 --- a/demos/triangle.vert +++ /dev/null @@ -1,13 +0,0 @@ -#version 150 -#extension GL_ARB_separate_shader_objects : enable - -layout(location = 0) in vec4 position_in; -layout(location = 1) in vec4 colour_in; - -layout(location = 0) out vec4 colour_out; - -void main(void) -{ - gl_Position = position_in; - colour_out = colour_in; -} diff --git a/demos/triangle_ps.h b/demos/triangle_ps.h new file mode 100644 index 00000000..82bcd3cb --- /dev/null +++ b/demos/triangle_ps.h @@ -0,0 +1,73 @@ +#if 0 +// +// Generated by Microsoft (R) D3D Shader Disassembler +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_POSITION 0 xyzw 0 POS float +// COLOR 0 xyzw 1 NONE float xyzw +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_TARGET 0 xyzw 0 TARGET float xyzw +// +ps_5_0 +dcl_globalFlags refactoringAllowed +dcl_input_ps linear v1.xyzw +dcl_output o0.xyzw +mov o0.xyzw, v1.xyzw +ret +// Approximately 0 instruction slots used +#endif + +const BYTE g_ps_main[] = +{ + 68, 88, 66, 67, 80, 239, + 109, 26, 0, 147, 6, 156, + 240, 104, 206, 124, 185, 57, + 18, 98, 1, 0, 0, 0, + 248, 0, 0, 0, 3, 0, + 0, 0, 44, 0, 0, 0, + 128, 0, 0, 0, 180, 0, + 0, 0, 73, 83, 71, 78, + 76, 0, 0, 0, 2, 0, + 0, 0, 8, 0, 0, 0, + 56, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 15, 0, 0, 0, + 68, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 15, 15, 0, 0, + 83, 86, 95, 80, 79, 83, + 73, 84, 73, 79, 78, 0, + 67, 79, 76, 79, 82, 0, + 171, 171, 79, 83, 71, 78, + 44, 0, 0, 0, 1, 0, + 0, 0, 8, 0, 0, 0, + 32, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 15, 0, 0, 0, + 83, 86, 95, 84, 65, 82, + 71, 69, 84, 0, 171, 171, + 83, 72, 69, 88, 60, 0, + 0, 0, 80, 0, 0, 0, + 15, 0, 0, 0, 106, 8, + 0, 1, 98, 16, 0, 3, + 242, 16, 16, 0, 1, 0, + 0, 0, 101, 0, 0, 3, + 242, 32, 16, 0, 0, 0, + 0, 0, 54, 0, 0, 5, + 242, 32, 16, 0, 0, 0, + 0, 0, 70, 30, 16, 0, + 1, 0, 0, 0, 62, 0, + 0, 1 +}; diff --git a/demos/triangle_vs.h b/demos/triangle_vs.h new file mode 100644 index 00000000..655b72bf --- /dev/null +++ b/demos/triangle_vs.h @@ -0,0 +1,89 @@ +#if 0 +// +// Generated by Microsoft (R) D3D Shader Disassembler +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// POSITION 0 xyzw 0 NONE float xyzw +// COLOR 0 xyzw 1 NONE float xyzw +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_POSITION 0 xyzw 0 POS float xyzw +// COLOR 0 xyzw 1 NONE float xyzw +// +vs_5_0 +dcl_globalFlags refactoringAllowed +dcl_input v0.xyzw +dcl_input v1.xyzw +dcl_output_siv o0.xyzw, position +dcl_output o1.xyzw +mov o0.xyzw, v0.xyzw +mov o1.xyzw, v1.xyzw +ret +// Approximately 0 instruction slots used +#endif + +const BYTE g_vs_main[] = +{ + 68, 88, 66, 67, 17, 201, + 143, 165, 233, 56, 0, 40, + 84, 255, 207, 20, 40, 195, + 63, 228, 1, 0, 0, 0, + 68, 1, 0, 0, 3, 0, + 0, 0, 44, 0, 0, 0, + 124, 0, 0, 0, 208, 0, + 0, 0, 73, 83, 71, 78, + 72, 0, 0, 0, 2, 0, + 0, 0, 8, 0, 0, 0, + 56, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 15, 15, 0, 0, + 65, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 15, 15, 0, 0, + 80, 79, 83, 73, 84, 73, + 79, 78, 0, 67, 79, 76, + 79, 82, 0, 171, 79, 83, + 71, 78, 76, 0, 0, 0, + 2, 0, 0, 0, 8, 0, + 0, 0, 56, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 15, 0, + 0, 0, 68, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 1, 0, 0, 0, 15, 0, + 0, 0, 83, 86, 95, 80, + 79, 83, 73, 84, 73, 79, + 78, 0, 67, 79, 76, 79, + 82, 0, 171, 171, 83, 72, + 69, 88, 108, 0, 0, 0, + 80, 0, 1, 0, 27, 0, + 0, 0, 106, 8, 0, 1, + 95, 0, 0, 3, 242, 16, + 16, 0, 0, 0, 0, 0, + 95, 0, 0, 3, 242, 16, + 16, 0, 1, 0, 0, 0, + 103, 0, 0, 4, 242, 32, + 16, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 101, 0, + 0, 3, 242, 32, 16, 0, + 1, 0, 0, 0, 54, 0, + 0, 5, 242, 32, 16, 0, + 0, 0, 0, 0, 70, 30, + 16, 0, 0, 0, 0, 0, + 54, 0, 0, 5, 242, 32, + 16, 0, 1, 0, 0, 0, + 70, 30, 16, 0, 1, 0, + 0, 0, 62, 0, 0, 1 +};