Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions build/nuke/Native/SPIRVCross.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,22 @@ pub fn build(b: *std.Build) void {
if (mode != .Debug)
lib.defineCMacro(""NDEBUG"", ""1"");

lib.addCSourceFiles(&.{
root_path ++ ""spirv_cross.cpp"",
root_path ++ ""spirv_cfg.cpp"",
root_path ++ ""spirv_cpp.cpp"",
root_path ++ ""spirv_cross_c.cpp"",
root_path ++ ""spirv_cross_parsed_ir.cpp"",
root_path ++ ""spirv_cross_util.cpp"",
root_path ++ ""spirv_glsl.cpp"",
root_path ++ ""spirv_hlsl.cpp"",
root_path ++ ""spirv_msl.cpp"",
root_path ++ ""spirv_parser.cpp"",
root_path ++ ""spirv_reflect.cpp"",
}, flags);
lib.addCSourceFiles(.{
.files = &.{
root_path ++ ""spirv_cross.cpp"",
root_path ++ ""spirv_cfg.cpp"",
root_path ++ ""spirv_cpp.cpp"",
root_path ++ ""spirv_cross_c.cpp"",
root_path ++ ""spirv_cross_parsed_ir.cpp"",
root_path ++ ""spirv_cross_util.cpp"",
root_path ++ ""spirv_glsl.cpp"",
root_path ++ ""spirv_hlsl.cpp"",
root_path ++ ""spirv_msl.cpp"",
root_path ++ ""spirv_parser.cpp"",
root_path ++ ""spirv_reflect.cpp"",
},
.flags = flags
});

b.installArtifact(lib);
}
Expand Down
2 changes: 1 addition & 1 deletion build/nuke/Native/SPIRVReflect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub fn build(b: *std.Build) void {
const lib: *std.build.LibExeObjStep = b.addSharedLibrary(shared_lib_options);
lib.linkLibC();

lib.addCSourceFiles(&.{""spirv_reflect.c""}, &.{ ""-std=c99"", ""-fPIC"" });
lib.addCSourceFiles(.{ .files = &.{""spirv_reflect.c""}, .flags = &.{ ""-std=c99"", ""-fPIC"" } });
b.installArtifact(lib);
}";

Expand Down
639 changes: 327 additions & 312 deletions build/nuke/Native/Shaderc.cs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/submodules/vkd3d
Submodule vkd3d updated 209 files
3 changes: 0 additions & 3 deletions src/Microsoft/Vkd3dCompiler/build.sh

This file was deleted.

4 changes: 2 additions & 2 deletions src/Microsoft/Vkd3dCompiler/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ pub fn build(b: *std.Build) void {
};

const vkd3d_compiler: *std.build.LibExeObjStep = b.addSharedLibrary(shared_lib_options);
vkd3d_compiler.addLibraryPath(".");
vkd3d_compiler.addLibraryPath(.{ .path = "." });
vkd3d_compiler.linkSystemLibraryName("vkd3d-shader");
//Since we statically link with vkd3d-shader, we need to dynamically link against SPIRV-Tools ourselves
vkd3d_compiler.linkSystemLibraryName("SPIRV-Tools-shared");
vkd3d_compiler.linkLibC();

vkd3d_compiler.addCSourceFiles(&.{"lib.c"}, &.{ "-std=c99", "-fPIC" });
vkd3d_compiler.addSystemIncludePath("../../../build/submodules/vkd3d/include/");
vkd3d_compiler.addIncludePath(.{ .path = "../../../build/submodules/vkd3d/include/" });
b.installArtifact(vkd3d_compiler);
}
182 changes: 127 additions & 55 deletions src/Microsoft/Vkd3dCompiler/lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,48 @@
#define COM_NO_WINDOWS_H

/* Macros for COM interfaces */
# define interface struct
# define BEGIN_INTERFACE
# define END_INTERFACE
# define MIDL_INTERFACE(x) struct
#define interface struct
#define BEGIN_INTERFACE
#define END_INTERFACE
#define MIDL_INTERFACE(x) struct

#define D3DCOMPILE_DEBUG 0x00000001
#define D3DCOMPILE_SKIP_VALIDATION 0x00000002
#define D3DCOMPILE_SKIP_OPTIMIZATION 0x00000004
#define D3DCOMPILE_PACK_MATRIX_ROW_MAJOR 0x00000008
#define D3DCOMPILE_PACK_MATRIX_COLUMN_MAJOR 0x00000010
#define D3DCOMPILE_PARTIAL_PRECISION 0x00000020
#define D3DCOMPILE_FORCE_VS_SOFTWARE_NO_OPT 0x00000040
#define D3DCOMPILE_FORCE_PS_SOFTWARE_NO_OPT 0x00000080
#define D3DCOMPILE_NO_PRESHADER 0x00000100
#define D3DCOMPILE_AVOID_FLOW_CONTROL 0x00000200
#define D3DCOMPILE_PREFER_FLOW_CONTROL 0x00000400
#define D3DCOMPILE_ENABLE_STRICTNESS 0x00000800
#define D3DCOMPILE_ENABLE_BACKWARDS_COMPATIBILITY 0x00001000
#define D3DCOMPILE_IEEE_STRICTNESS 0x00002000
#define D3DCOMPILE_OPTIMIZATION_LEVEL0 0x00004000
#define D3DCOMPILE_OPTIMIZATION_LEVEL1 0x00000000
#define D3DCOMPILE_OPTIMIZATION_LEVEL2 0x0000c000
#define D3DCOMPILE_OPTIMIZATION_LEVEL3 0x00008000
#define D3DCOMPILE_RESERVED16 0x00010000
#define D3DCOMPILE_RESERVED17 0x00020000
#define D3DCOMPILE_WARNINGS_ARE_ERRORS 0x00040000
#define D3DCOMPILE_RESOURCES_MAY_ALIAS 0x00080000
#define D3DCOMPILE_ENABLE_UNBOUNDED_DESCRIPTOR_TABLES 0x00100000
#define D3DCOMPILE_ALL_RESOURCES_BOUND 0x00200000
#define D3DCOMPILE_DEBUG_NAME_FOR_SOURCE 0x00400000
#define D3DCOMPILE_DEBUG_NAME_FOR_BINARY 0x00800000

#define D3DCOMPILE_EFFECT_CHILD_EFFECT 0x00000001
#define D3DCOMPILE_EFFECT_ALLOW_SLOW_OPS 0x00000002

#define D3DCOMPILE_FLAGS2_FORCE_ROOT_SIGNATURE_LATEST 0x00000000
#define D3DCOMPILE_FLAGS2_FORCE_ROOT_SIGNATURE_1_0 0x00000010
#define D3DCOMPILE_FLAGS2_FORCE_ROOT_SIGNATURE_1_1 0x00000020

#define D3DCOMPILE_SECDATA_MERGE_UAV_SLOTS 0x00000001
#define D3DCOMPILE_SECDATA_PRESERVE_TEMPLATE_SLOTS 0x00000002
#define D3DCOMPILE_SECDATA_REQUIRE_TEMPLATE_MATCH 0x00000004

#include <vkd3d_types.h>
#include <vkd3d_shader.h>
Expand All @@ -20,15 +58,40 @@

#define D3DCOMPILE_DEBUG 0x00000001

extern int32_t D3DCompile2(const void *data, void* data_size, const char *filename,
const D3D_SHADER_MACRO *macros, ID3DInclude *include, const char *entry_point,
const char *profile, UINT flags, UINT effect_flags, UINT secondary_flags,
const void *secondary_data, SIZE_T secondary_data_size, ID3DBlob **shader_blob,
ID3DBlob **messages_blob)
static int open_include(const char *filename, bool local, const char *parent_data, void *context,
struct vkd3d_shader_code *code)
{
ID3DInclude *iface = context;
unsigned int size = 0;

if (!iface)
return VKD3D_ERROR;

memset(code, 0, sizeof(*code));
if (FAILED(ID3DInclude_Open(iface, local ? D3D_INCLUDE_LOCAL : D3D_INCLUDE_SYSTEM,
filename, parent_data, &code->code, &size)))
return VKD3D_ERROR;

code->size = size;
return VKD3D_OK;
}

static void close_include(const struct vkd3d_shader_code *code, void *context)
{
ID3DInclude *iface = context;

ID3DInclude_Close(iface, code->code);
}

extern int32_t D3DCompile2(const void *data, void *data_size, const char *filename,
const D3D_SHADER_MACRO *macros, ID3DInclude *include, const char *entry_point,
const char *profile, UINT flags, UINT effect_flags, UINT secondary_flags,
const void *secondary_data, SIZE_T secondary_data_size, ID3DBlob **shader_blob,
ID3DBlob **messages_blob)
{
struct vkd3d_shader_preprocess_info preprocess_info;
struct vkd3d_shader_hlsl_source_info hlsl_info;
struct vkd3d_shader_compile_option options[2];
struct vkd3d_shader_compile_option options[3];
struct vkd3d_shader_compile_info compile_info;
struct vkd3d_shader_compile_option *option;
struct vkd3d_shader_code byte_code;
Expand All @@ -38,49 +101,49 @@ extern int32_t D3DCompile2(const void *data, void* data_size, const char *filena
HRESULT hr;
int ret;

static const char * const d3dbc_profiles[] =
{
"fx_2_",
static const char *const d3dbc_profiles[] =
{
"fx_2_",

"ps.1.",
"ps.2.",
"ps.3.",
"ps.1.",
"ps.2.",
"ps.3.",

"ps_1_",
"ps_2_",
"ps_3_",
"ps_1_",
"ps_2_",
"ps_3_",

"vs.1.",
"vs.2.",
"vs.3.",
"vs.1.",
"vs.2.",
"vs.3.",

"vs_1_",
"vs_2_",
"vs_3_",
"vs_1_",
"vs_2_",
"vs_3_",

"tx_1_",
};
"tx_1_",
};

// TRACE("data %p, data_size %lu, filename %s, macros %p, include %p, entry_point %s, "
// "profile %s, flags %#x, effect_flags %#x, secondary_flags %#x, secondary_data %p, "
// "secondary_data_size %lu, shader_blob %p, messages_blob %p.\n",
// data, data_size, debugstr_a(filename), macros, include, debugstr_a(entry_point),
// debugstr_a(profile), flags, effect_flags, secondary_flags, secondary_data,
// secondary_data_size, shader_blob, messages_blob);

// if (flags & ~D3DCOMPILE_DEBUG)
// FIXME("Ignoring flags %#x.\n", flags);
// "profile %s, flags %#x, effect_flags %#x, secondary_flags %#x, secondary_data %p, "
// "secondary_data_size %lu, shader_blob %p, messages_blob %p.\n",
// data, data_size, debugstr_a(filename), macros, include, debugstr_a(entry_point),
// debugstr_a(profile), flags, effect_flags, secondary_flags, secondary_data,
// secondary_data_size, shader_blob, messages_blob);

// if (flags & ~(D3DCOMPILE_DEBUG | D3DCOMPILE_PACK_MATRIX_ROW_MAJOR | D3DCOMPILE_PACK_MATRIX_COLUMN_MAJOR))
// FIXME("Ignoring flags %#x.\n", flags);
// if (effect_flags)
// FIXME("Ignoring effect flags %#x.\n", effect_flags);
// FIXME("Ignoring effect flags %#x.\n", effect_flags);
// if (secondary_flags)
// FIXME("Ignoring secondary flags %#x.\n", secondary_flags);
// FIXME("Ignoring secondary flags %#x.\n", secondary_flags);

if (messages_blob)
*messages_blob = NULL;

option = &options[0];
option->name = VKD3D_SHADER_COMPILE_OPTION_API_VERSION;
option->value = VKD3D_SHADER_API_VERSION_1_6;
option->value = VKD3D_SHADER_API_VERSION_1_9;

compile_info.type = VKD3D_SHADER_STRUCTURE_TYPE_COMPILE_INFO;
compile_info.next = &preprocess_info;
Expand Down Expand Up @@ -114,8 +177,8 @@ extern int32_t D3DCompile2(const void *data, void* data_size, const char *filena
for (macro = macros; macro->Name; ++macro)
++preprocess_info.macro_count;
}
preprocess_info.pfn_open_include = NULL;
preprocess_info.pfn_close_include = NULL;
preprocess_info.pfn_open_include = open_include;
preprocess_info.pfn_close_include = close_include;
preprocess_info.include_context = include;

hlsl_info.type = VKD3D_SHADER_STRUCTURE_TYPE_HLSL_SOURCE_INFO;
Expand All @@ -132,6 +195,17 @@ extern int32_t D3DCompile2(const void *data, void* data_size, const char *filena
option->value = true;
}

if (flags & (D3DCOMPILE_PACK_MATRIX_ROW_MAJOR | D3DCOMPILE_PACK_MATRIX_COLUMN_MAJOR))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does the code in this file actually come from?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels like a bit too much human intervention (and code that isn't ours, in our repo, effectively untracked)

I know it's cursed, but we could do something like

#include "vkd3d_utils_main.c"
#undef D3D12GetDebugInterface
#undef D3D12CreateDeviceVKD3D
#undef D3D12CreateRootSignatureDeserializer
#undef D3D12CreateVersionedRootSignatureDeserializer
// etc...

Alternatively we could leave the irrelevant parts in... just not really keen on us having our own "buffer" of upstream

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels like a bit too much human intervention (and code that isn't ours, in our repo, effectively untracked)

I know it's cursed, but we could do something like

#include "vkd3d_utils_main.c"
#undef D3D12GetDebugInterface
#undef D3D12CreateDeviceVKD3D
#undef D3D12CreateRootSignatureDeserializer
#undef D3D12CreateVersionedRootSignatureDeserializer
// etc...

Alternatively we could leave the irrelevant parts in... just not really keen on us having our own "buffer" of upstream

The irrelevant parts more meant it complicated the build process, since stuff like the logging macros were causing a billion undefined symbol errors i was not too keen on debugging/fixing, but i can give using the original source a shot with some well placed def and undef if desired

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the main thing is I had no idea this existed (yes I know clearly I don't pay that much attention) and wouldn't have thought to check here when updating vkd3d, and the same will definitely be said for whoever comes after you & I.

Eliminating as much human error as possible should be key, and this I feel like is definitely human-error-prone

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the main thing is I had no idea this existed (yes I know clearly I don't pay that much attention) and wouldn't have thought to check here when updating vkd3d, and the same will definitely be said for whoever comes after you & I.

Eliminating as much human error as possible should be key, and this I feel like is definitely human-error-prone

to be fair i also had to reference my own commits to figure out what i had done, so its a bit error prone yeah, i'll try to get the original source working at some point soon (and also update past .405 so we get them LLVM 17 benefits)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notably 4 months ago they removed ms_abi so we are likely to have fixed #1634

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...although you probably already knew that as you've already linked the issue 🤦

{
option = &options[compile_info.option_count++];
option->name = VKD3D_SHADER_COMPILE_OPTION_PACK_MATRIX_ORDER;
option->value = 0;
if (flags & D3DCOMPILE_PACK_MATRIX_ROW_MAJOR)
option->value |= VKD3D_SHADER_COMPILE_OPTION_PACK_MATRIX_ROW_MAJOR;
if (flags & D3DCOMPILE_PACK_MATRIX_COLUMN_MAJOR)
option->value |= VKD3D_SHADER_COMPILE_OPTION_PACK_MATRIX_COLUMN_MAJOR;
}

ret = vkd3d_shader_compile(&compile_info, &byte_code, &messages);

if (messages && messages_blob)
Expand All @@ -140,7 +214,6 @@ extern int32_t D3DCompile2(const void *data, void* data_size, const char *filena
{
vkd3d_shader_free_messages(messages);
vkd3d_shader_free_shader_code(&byte_code);
printf("Failed to create blob for messages.\n");
return hr;
}
messages = NULL;
Expand All @@ -151,28 +224,27 @@ extern int32_t D3DCompile2(const void *data, void* data_size, const char *filena
{
if (FAILED(hr = vkd3d_blob_create((void *)byte_code.code, byte_code.size, shader_blob)))
{
printf("Failed to create blob for bytecode.\n");
vkd3d_shader_free_shader_code(&byte_code);
return hr;
}
}

printf("got to end?.\n");
return hresult_from_vkd3d_result(ret);
}

extern int32_t D3DCompile(void* data,
void* data_size,
void* filename,
const void* macros,
void* include,
void* entrypoint,
void* profile,
int32_t flags,
int32_t effect_flags,
void* shader,
void* error_messages) {
extern int32_t D3DCompile(void *data,
void *data_size,
void *filename,
const void *macros,
void *include,
void *entrypoint,
void *profile,
int32_t flags,
int32_t effect_flags,
void *shader,
void *error_messages)
{

return D3DCompile2(data, data_size, filename, macros, include, entrypoint, profile, flags,
effect_flags, 0, NULL, 0, shader, error_messages);
effect_flags, 0, NULL, 0, shader, error_messages);
}
Loading