2018-12-11 06:48:02 -08:00
|
|
|
/*
|
|
|
|
* Copyright 2018 Józef Kucia for CodeWeavers
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "vkd3d_test.h"
|
|
|
|
#include <vkd3d_shader.h>
|
|
|
|
|
2019-04-30 05:33:48 -07:00
|
|
|
#include <locale.h>
|
|
|
|
|
2018-12-11 06:48:02 -08:00
|
|
|
static void test_invalid_shaders(void)
|
|
|
|
{
|
2020-06-19 04:43:32 -07:00
|
|
|
struct vkd3d_shader_compile_info info;
|
2018-12-11 06:48:02 -08:00
|
|
|
struct vkd3d_shader_code spirv;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
static const DWORD ps_break_code[] =
|
|
|
|
{
|
|
|
|
#if 0
|
|
|
|
ps_4_0
|
|
|
|
dcl_constantbuffer cb0[1], immediateIndexed
|
|
|
|
dcl_output o0.xyzw
|
|
|
|
if_z cb0[0].x
|
|
|
|
mov o0.xyzw, l(1.000000,1.000000,1.000000,1.000000)
|
|
|
|
break
|
|
|
|
endif
|
|
|
|
mov o0.xyzw, l(0,0,0,0)
|
|
|
|
ret
|
|
|
|
#endif
|
|
|
|
0x43425844, 0x1316702a, 0xb1a7ebfc, 0xf477753e, 0x72605647, 0x00000001, 0x000000f8, 0x00000003,
|
|
|
|
0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
|
|
|
|
0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
|
|
|
|
0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000080, 0x00000040, 0x00000020,
|
|
|
|
0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0400001f,
|
|
|
|
0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000,
|
|
|
|
0x3f800000, 0x3f800000, 0x3f800000, 0x01000002, 0x01000015, 0x08000036, 0x001020f2, 0x00000000,
|
|
|
|
0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0100003e,
|
|
|
|
};
|
2020-06-19 04:43:35 -07:00
|
|
|
static const struct vkd3d_shader_compile_option option =
|
|
|
|
{
|
|
|
|
.name = VKD3D_SHADER_COMPILE_OPTION_STRIP_DEBUG,
|
|
|
|
.value = 1,
|
|
|
|
};
|
2018-12-11 06:48:02 -08:00
|
|
|
|
2020-06-19 04:43:32 -07:00
|
|
|
info.type = VKD3D_SHADER_STRUCTURE_TYPE_COMPILE_INFO;
|
|
|
|
info.next = NULL;
|
|
|
|
info.source.code = ps_break_code;
|
|
|
|
info.source.size = sizeof(ps_break_code);
|
2020-06-19 04:43:36 -07:00
|
|
|
info.source_type = VKD3D_SHADER_SOURCE_DXBC_TPF;
|
2020-06-19 04:43:35 -07:00
|
|
|
info.options = &option;
|
|
|
|
info.option_count = 1;
|
2020-06-19 04:43:32 -07:00
|
|
|
|
2020-06-19 04:43:36 -07:00
|
|
|
rc = vkd3d_shader_compile(&info, &spirv);
|
2018-12-11 06:48:02 -08:00
|
|
|
ok(rc == VKD3D_ERROR_INVALID_SHADER, "Got unexpected error code %d.\n", rc);
|
|
|
|
}
|
|
|
|
|
2019-02-25 02:59:17 -08:00
|
|
|
static void test_vkd3d_shader_pfns(void)
|
|
|
|
{
|
2019-04-24 07:05:46 -07:00
|
|
|
PFN_vkd3d_shader_serialize_root_signature pfn_vkd3d_shader_serialize_root_signature;
|
2019-02-25 02:59:17 -08:00
|
|
|
PFN_vkd3d_shader_find_signature_element pfn_vkd3d_shader_find_signature_element;
|
|
|
|
PFN_vkd3d_shader_free_shader_signature pfn_vkd3d_shader_free_shader_signature;
|
|
|
|
PFN_vkd3d_shader_parse_input_signature pfn_vkd3d_shader_parse_input_signature;
|
2019-04-24 07:05:46 -07:00
|
|
|
PFN_vkd3d_shader_parse_root_signature pfn_vkd3d_shader_parse_root_signature;
|
|
|
|
PFN_vkd3d_shader_free_root_signature pfn_vkd3d_shader_free_root_signature;
|
2019-02-25 02:59:17 -08:00
|
|
|
PFN_vkd3d_shader_free_shader_code pfn_vkd3d_shader_free_shader_code;
|
|
|
|
PFN_vkd3d_shader_scan_dxbc pfn_vkd3d_shader_scan_dxbc;
|
2020-06-19 04:43:36 -07:00
|
|
|
PFN_vkd3d_shader_compile pfn_vkd3d_shader_compile;
|
2019-02-25 02:59:17 -08:00
|
|
|
|
2019-04-19 02:07:36 -07:00
|
|
|
struct vkd3d_versioned_root_signature_desc root_signature_desc;
|
2019-02-25 02:59:17 -08:00
|
|
|
struct vkd3d_shader_signature_element *element;
|
2020-06-19 04:43:32 -07:00
|
|
|
struct vkd3d_shader_compile_info compile_info;
|
2019-02-25 02:59:17 -08:00
|
|
|
struct vkd3d_shader_scan_info scan_info;
|
|
|
|
struct vkd3d_shader_signature signature;
|
|
|
|
struct vkd3d_shader_code dxbc, spirv;
|
|
|
|
int rc;
|
|
|
|
|
2019-04-22 01:58:35 -07:00
|
|
|
static const struct vkd3d_versioned_root_signature_desc empty_rs_desc =
|
|
|
|
{
|
|
|
|
.version = VKD3D_ROOT_SIGNATURE_VERSION_1_0,
|
|
|
|
};
|
2019-02-25 02:59:17 -08:00
|
|
|
static const DWORD vs_code[] =
|
|
|
|
{
|
|
|
|
#if 0
|
|
|
|
float4 main(int4 p : POSITION) : SV_Position
|
|
|
|
{
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
0x43425844, 0x3fd50ab1, 0x580a1d14, 0x28f5f602, 0xd1083e3a, 0x00000001, 0x000000d8, 0x00000003,
|
|
|
|
0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
|
|
|
|
0x00000000, 0x00000000, 0x00000002, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
|
|
|
|
0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
|
|
|
|
0x00000000, 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x52444853, 0x0000003c, 0x00010040,
|
|
|
|
0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
|
|
|
|
0x0500002b, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
|
|
|
|
};
|
|
|
|
static const struct vkd3d_shader_code vs = {vs_code, sizeof(vs_code)};
|
|
|
|
|
2019-04-24 07:05:46 -07:00
|
|
|
pfn_vkd3d_shader_serialize_root_signature = vkd3d_shader_serialize_root_signature;
|
2019-02-25 02:59:17 -08:00
|
|
|
pfn_vkd3d_shader_find_signature_element = vkd3d_shader_find_signature_element;
|
|
|
|
pfn_vkd3d_shader_free_shader_signature = vkd3d_shader_free_shader_signature;
|
|
|
|
pfn_vkd3d_shader_parse_input_signature = vkd3d_shader_parse_input_signature;
|
2019-04-24 07:05:46 -07:00
|
|
|
pfn_vkd3d_shader_parse_root_signature = vkd3d_shader_parse_root_signature;
|
|
|
|
pfn_vkd3d_shader_free_root_signature = vkd3d_shader_free_root_signature;
|
2019-02-25 02:59:17 -08:00
|
|
|
pfn_vkd3d_shader_free_shader_code = vkd3d_shader_free_shader_code;
|
|
|
|
pfn_vkd3d_shader_scan_dxbc = vkd3d_shader_scan_dxbc;
|
2020-06-19 04:43:36 -07:00
|
|
|
pfn_vkd3d_shader_compile = vkd3d_shader_compile;
|
2019-02-25 02:59:17 -08:00
|
|
|
|
2019-04-24 07:05:46 -07:00
|
|
|
rc = pfn_vkd3d_shader_serialize_root_signature(&empty_rs_desc, &dxbc);
|
2019-02-25 02:59:17 -08:00
|
|
|
ok(rc == VKD3D_OK, "Got unexpected error code %d.\n", rc);
|
2019-04-24 07:05:46 -07:00
|
|
|
rc = pfn_vkd3d_shader_parse_root_signature(&dxbc, &root_signature_desc);
|
2019-02-25 02:59:17 -08:00
|
|
|
ok(rc == VKD3D_OK, "Got unexpected error code %d.\n", rc);
|
2019-04-24 07:05:46 -07:00
|
|
|
pfn_vkd3d_shader_free_root_signature(&root_signature_desc);
|
2019-02-25 02:59:17 -08:00
|
|
|
pfn_vkd3d_shader_free_shader_code(&dxbc);
|
|
|
|
|
|
|
|
rc = pfn_vkd3d_shader_parse_input_signature(&vs, &signature);
|
|
|
|
ok(rc == VKD3D_OK, "Got unexpected error code %d.\n", rc);
|
2019-04-30 05:33:48 -07:00
|
|
|
element = pfn_vkd3d_shader_find_signature_element(&signature, "position", 0, 0);
|
2019-02-25 02:59:17 -08:00
|
|
|
ok(element, "Could not find shader signature element.\n");
|
|
|
|
pfn_vkd3d_shader_free_shader_signature(&signature);
|
|
|
|
|
2020-06-19 04:43:32 -07:00
|
|
|
compile_info.type = VKD3D_SHADER_STRUCTURE_TYPE_COMPILE_INFO;
|
|
|
|
compile_info.next = NULL;
|
|
|
|
compile_info.source = vs;
|
2020-06-19 04:43:36 -07:00
|
|
|
compile_info.source_type = VKD3D_SHADER_SOURCE_DXBC_TPF;
|
2020-06-19 04:43:35 -07:00
|
|
|
compile_info.options = NULL;
|
|
|
|
compile_info.option_count = 0;
|
2020-06-19 04:43:32 -07:00
|
|
|
|
2020-06-19 04:43:36 -07:00
|
|
|
rc = pfn_vkd3d_shader_compile(&compile_info, &spirv);
|
2019-02-25 02:59:17 -08:00
|
|
|
ok(rc == VKD3D_OK, "Got unexpected error code %d.\n", rc);
|
|
|
|
pfn_vkd3d_shader_free_shader_code(&spirv);
|
|
|
|
|
|
|
|
memset(&scan_info, 0, sizeof(scan_info));
|
|
|
|
scan_info.type = VKD3D_SHADER_STRUCTURE_TYPE_SCAN_INFO;
|
|
|
|
rc = pfn_vkd3d_shader_scan_dxbc(&vs, &scan_info);
|
|
|
|
ok(rc == VKD3D_OK, "Got unexpected error code %d.\n", rc);
|
|
|
|
}
|
|
|
|
|
2018-12-11 06:48:02 -08:00
|
|
|
START_TEST(vkd3d_shader_api)
|
|
|
|
{
|
2019-04-30 05:33:48 -07:00
|
|
|
setlocale(LC_ALL, "");
|
|
|
|
|
2018-12-11 06:48:02 -08:00
|
|
|
run_test(test_invalid_shaders);
|
2019-02-25 02:59:17 -08:00
|
|
|
run_test(test_vkd3d_shader_pfns);
|
2018-12-11 06:48:02 -08:00
|
|
|
}
|