Commit 6a062afb authored by Zebediah Figura's avatar Zebediah Figura Committed by Alexandre Julliard

d3dcompiler: Implement D3DCompile2() using vkd3d_shader_compile().

parent aa2851f1
MODULE = d3dcompiler_33.dll
IMPORTS = dxguid uuid
IMPORTS = wined3d dxguid uuid
EXTRADEFS = -DD3D_COMPILER_VERSION=33
PARENTSRC = ../d3dcompiler_43
EXTRAINCL = $(VKD3D_PE_CFLAGS)
EXTRADLLFLAGS = -Wb,--prefer-native
......
MODULE = d3dcompiler_34.dll
IMPORTS = dxguid uuid
IMPORTS = wined3d dxguid uuid
EXTRADEFS = -DD3D_COMPILER_VERSION=34
PARENTSRC = ../d3dcompiler_43
EXTRAINCL = $(VKD3D_PE_CFLAGS)
EXTRADLLFLAGS = -Wb,--prefer-native
......
MODULE = d3dcompiler_35.dll
IMPORTS = dxguid uuid
IMPORTS = wined3d dxguid uuid
EXTRADEFS = -DD3D_COMPILER_VERSION=35
PARENTSRC = ../d3dcompiler_43
EXTRAINCL = $(VKD3D_PE_CFLAGS)
EXTRADLLFLAGS = -Wb,--prefer-native
......
MODULE = d3dcompiler_36.dll
IMPORTS = dxguid uuid
IMPORTS = wined3d dxguid uuid
EXTRADEFS = -DD3D_COMPILER_VERSION=36
PARENTSRC = ../d3dcompiler_43
EXTRAINCL = $(VKD3D_PE_CFLAGS)
EXTRADLLFLAGS = -Wb,--prefer-native
......
MODULE = d3dcompiler_37.dll
IMPORTS = dxguid uuid
IMPORTS = wined3d dxguid uuid
EXTRADEFS = -DD3D_COMPILER_VERSION=37
PARENTSRC = ../d3dcompiler_43
EXTRAINCL = $(VKD3D_PE_CFLAGS)
EXTRADLLFLAGS = -Wb,--prefer-native
......
MODULE = d3dcompiler_38.dll
IMPORTS = dxguid uuid
IMPORTS = wined3d dxguid uuid
EXTRADEFS = -DD3D_COMPILER_VERSION=38
PARENTSRC = ../d3dcompiler_43
EXTRAINCL = $(VKD3D_PE_CFLAGS)
EXTRADLLFLAGS = -Wb,--prefer-native
......
MODULE = d3dcompiler_39.dll
IMPORTS = dxguid uuid
IMPORTS = wined3d dxguid uuid
EXTRADEFS = -DD3D_COMPILER_VERSION=39
PARENTSRC = ../d3dcompiler_43
EXTRAINCL = $(VKD3D_PE_CFLAGS)
EXTRADLLFLAGS = -Wb,--prefer-native
......
MODULE = d3dcompiler_40.dll
IMPORTS = dxguid uuid
IMPORTS = wined3d dxguid uuid
EXTRADEFS = -DD3D_COMPILER_VERSION=40
PARENTSRC = ../d3dcompiler_43
EXTRAINCL = $(VKD3D_PE_CFLAGS)
EXTRADLLFLAGS = -Wb,--prefer-native
......
MODULE = d3dcompiler_41.dll
IMPORTS = dxguid uuid
IMPORTS = wined3d dxguid uuid
EXTRADEFS = -DD3D_COMPILER_VERSION=41
PARENTSRC = ../d3dcompiler_43
EXTRAINCL = $(VKD3D_PE_CFLAGS)
EXTRADLLFLAGS = -Wb,--prefer-native
......
MODULE = d3dcompiler_42.dll
IMPORTS = dxguid uuid
IMPORTS = wined3d dxguid uuid
EXTRADEFS = -DD3D_COMPILER_VERSION=42
PARENTSRC = ../d3dcompiler_43
EXTRAINCL = $(VKD3D_PE_CFLAGS)
EXTRADLLFLAGS = -Wb,--prefer-native
......
MODULE = d3dcompiler_43.dll
IMPORTLIB = d3dcompiler_43
EXTRADEFS = -DD3D_COMPILER_VERSION=43
IMPORTS = wined3d
EXTRAINCL = $(VKD3D_PE_CFLAGS)
EXTRADLLFLAGS = -Wb,--prefer-native
......
/*
* Copyright 2009 Matteo Bruni
* Copyright 2010 Matteo Bruni for CodeWeavers
* Copyright 2016,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
......@@ -25,8 +26,33 @@
#include "d3dcompiler_private.h"
#include "wpp_private.h"
#include <vkd3d_shader.h>
WINE_DEFAULT_DEBUG_CHANNEL(d3dcompiler);
static HRESULT hresult_from_vkd3d_result(int vkd3d_result)
{
switch (vkd3d_result)
{
case VKD3D_OK:
return S_OK;
case VKD3D_ERROR_INVALID_SHADER:
WARN("Invalid shader bytecode.\n");
/* fall-through */
case VKD3D_ERROR:
return E_FAIL;
case VKD3D_ERROR_OUT_OF_MEMORY:
return E_OUTOFMEMORY;
case VKD3D_ERROR_INVALID_ARGUMENT:
return E_INVALIDARG;
case VKD3D_ERROR_NOT_IMPLEMENTED:
return E_NOTIMPL;
default:
FIXME("Unhandled vkd3d result %d.\n", vkd3d_result);
return E_FAIL;
}
}
#define D3DXERR_INVALIDDATA 0x88760b59
#define BUFFER_INITIAL_CAPACITY 256
......@@ -736,39 +762,179 @@ HRESULT WINAPI D3DAssemble(const void *data, SIZE_T datasize, const char *filena
return hr;
}
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);
}
HRESULT WINAPI D3DCompile2(const void *data, SIZE_T data_size, const char *filename,
const D3D_SHADER_MACRO *defines, ID3DInclude *include, const char *entrypoint,
const char *target, UINT sflags, UINT eflags, UINT secondary_flags,
const void *secondary_data, SIZE_T secondary_data_size, ID3DBlob **shader,
ID3DBlob **error_messages)
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 d3dcompiler_include_from_file include_from_file;
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_info compile_info;
struct vkd3d_shader_compile_option *option;
struct vkd3d_shader_code byte_code;
const D3D_SHADER_MACRO *macro;
size_t profile_len, i;
char *messages;
HRESULT hr;
int ret;
TRACE("data %p, data_size %Iu, filename %s, defines %p, include %p, entrypoint %s, "
"target %s, sflags %#x, eflags %#x, secondary_flags %#x, secondary_data %p, "
"secondary_data_size %Iu, shader %p, error_messages %p.\n",
data, data_size, debugstr_a(filename), defines, include, debugstr_a(entrypoint),
debugstr_a(target), sflags, eflags, secondary_flags, secondary_data,
secondary_data_size, shader, error_messages);
static const char * const d3dbc_profiles[] =
{
"fx_2_",
if (secondary_data)
FIXME("secondary data not implemented yet\n");
"ps.1.",
"ps.2.",
"ps.3.",
if (shader) *shader = NULL;
if (error_messages) *error_messages = NULL;
"ps_1_",
"ps_2_",
"ps_3_",
EnterCriticalSection(&wpp_mutex);
"vs.1.",
"vs.2.",
"vs.3.",
hr = preprocess_shader(data, data_size, filename, defines, include, error_messages);
if (SUCCEEDED(hr))
"vs_1_",
"vs_2_",
"vs_3_",
"tx_1_",
};
TRACE("data %p, data_size %Iu, 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 %Iu, 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 (include == D3D_COMPILE_STANDARD_FILE_INCLUDE)
{
include_from_file.ID3DInclude_iface.lpVtbl = &d3dcompiler_include_from_file_vtbl;
include = &include_from_file.ID3DInclude_iface;
}
if (flags & ~D3DCOMPILE_DEBUG)
FIXME("Ignoring flags %#x.\n", flags);
if (effect_flags)
FIXME("Ignoring effect flags %#x.\n", effect_flags);
if (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_3;
compile_info.type = VKD3D_SHADER_STRUCTURE_TYPE_COMPILE_INFO;
compile_info.next = &preprocess_info;
compile_info.source.code = data;
compile_info.source.size = data_size;
compile_info.source_type = VKD3D_SHADER_SOURCE_HLSL;
compile_info.target_type = VKD3D_SHADER_TARGET_DXBC_TPF;
compile_info.options = options;
compile_info.option_count = 1;
compile_info.log_level = VKD3D_SHADER_LOG_INFO;
compile_info.source_name = filename;
profile_len = strlen(profile);
for (i = 0; i < ARRAY_SIZE(d3dbc_profiles); ++i)
{
FIXME("HLSL shader compilation is not yet implemented.\n");
hr = E_NOTIMPL;
size_t len = strlen(d3dbc_profiles[i]);
if (len <= profile_len && !memcmp(profile, d3dbc_profiles[i], len))
{
compile_info.target_type = VKD3D_SHADER_TARGET_D3D_BYTECODE;
break;
}
}
HeapFree(GetProcessHeap(), 0, wpp_output);
LeaveCriticalSection(&wpp_mutex);
return hr;
preprocess_info.type = VKD3D_SHADER_STRUCTURE_TYPE_PREPROCESS_INFO;
preprocess_info.next = &hlsl_info;
preprocess_info.macros = (const struct vkd3d_shader_macro *)macros;
preprocess_info.macro_count = 0;
if (macros)
{
for (macro = macros; macro->Name; ++macro)
++preprocess_info.macro_count;
}
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;
hlsl_info.next = NULL;
hlsl_info.profile = profile;
hlsl_info.entry_point = entry_point;
hlsl_info.secondary_code.code = secondary_data;
hlsl_info.secondary_code.size = secondary_data_size;
if (!(flags & D3DCOMPILE_DEBUG))
{
option = &options[compile_info.option_count++];
option->name = VKD3D_SHADER_COMPILE_OPTION_STRIP_DEBUG;
option->value = true;
}
ret = vkd3d_shader_compile(&compile_info, &byte_code, &messages);
if (messages)
{
if (messages_blob)
{
size_t size = strlen(messages);
if (FAILED(hr = D3DCreateBlob(size, messages_blob)))
{
vkd3d_shader_free_messages(messages);
vkd3d_shader_free_shader_code(&byte_code);
return hr;
}
memcpy(ID3D10Blob_GetBufferPointer(*messages_blob), messages, size);
}
else
vkd3d_shader_free_messages(messages);
}
if (!ret)
{
if (FAILED(hr = D3DCreateBlob(byte_code.size, shader_blob)))
{
vkd3d_shader_free_shader_code(&byte_code);
return hr;
}
memcpy(ID3D10Blob_GetBufferPointer(*shader_blob), byte_code.code, byte_code.size);
}
return hresult_from_vkd3d_result(ret);
}
HRESULT WINAPI D3DCompile(const void *data, SIZE_T data_size, const char *filename,
......
......@@ -383,20 +383,17 @@ static void test_swizzle(void)
if (!init_test_context(&test_context))
return;
todo_wine ps_code = compile_shader(ps_source, "ps_4_0");
if (ps_code)
{
cb = create_buffer(test_context.device, D3D11_BIND_CONSTANT_BUFFER, sizeof(uniform), &uniform);
ID3D11DeviceContext_PSSetConstantBuffers(test_context.immediate_context, 0, 1, &cb);
draw_quad(&test_context, ps_code);
ps_code = compile_shader(ps_source, "ps_4_0");
cb = create_buffer(test_context.device, D3D11_BIND_CONSTANT_BUFFER, sizeof(uniform), &uniform);
ID3D11DeviceContext_PSSetConstantBuffers(test_context.immediate_context, 0, 1, &cb);
draw_quad(&test_context, ps_code);
v = get_color_vec4(&test_context, 0, 0);
ok(compare_vec4(&v, 0.0101f, 0.0303f, 0.0202f, 0.0404f, 0),
"Got unexpected value {%.8e, %.8e, %.8e, %.8e}.\n", v.x, v.y, v.z, v.w);
v = get_color_vec4(&test_context, 0, 0);
ok(compare_vec4(&v, 0.0101f, 0.0303f, 0.0202f, 0.0404f, 0),
"Got unexpected value {%.8e, %.8e, %.8e, %.8e}.\n", v.x, v.y, v.z, v.w);
ID3D11Buffer_Release(cb);
ID3D10Blob_Release(ps_code);
}
ID3D11Buffer_Release(cb);
ID3D10Blob_Release(ps_code);
release_test_context(&test_context);
}
......@@ -421,20 +418,17 @@ static void test_math(void)
if (!init_test_context(&test_context))
return;
todo_wine ps_code = compile_shader(ps_source, "ps_4_0");
if (ps_code)
{
cb = create_buffer(test_context.device, D3D11_BIND_CONSTANT_BUFFER, sizeof(uniforms), uniforms);
ID3D11DeviceContext_PSSetConstantBuffers(test_context.immediate_context, 0, 1, &cb);
draw_quad(&test_context, ps_code);
ps_code = compile_shader(ps_source, "ps_4_0");
cb = create_buffer(test_context.device, D3D11_BIND_CONSTANT_BUFFER, sizeof(uniforms), uniforms);
ID3D11DeviceContext_PSSetConstantBuffers(test_context.immediate_context, 0, 1, &cb);
draw_quad(&test_context, ps_code);
v = get_color_vec4(&test_context, 0, 0);
ok(compare_vec4(&v, -12.43f, 9.833333f, 1.6f, 35.0f, 1),
"Got unexpected value {%.8e, %.8e, %.8e, %.8e}.\n", v.x, v.y, v.z, v.w);
v = get_color_vec4(&test_context, 0, 0);
ok(compare_vec4(&v, -12.43f, 9.833333f, 1.6f, 35.0f, 1),
"Got unexpected value {%.8e, %.8e, %.8e, %.8e}.\n", v.x, v.y, v.z, v.w);
ID3D11Buffer_Release(cb);
ID3D10Blob_Release(ps_code);
}
ID3D11Buffer_Release(cb);
ID3D10Blob_Release(ps_code);
release_test_context(&test_context);
}
......@@ -458,29 +452,26 @@ static void test_conditionals(void)
if (!init_test_context(&test_context))
return;
todo_wine ps_code = compile_shader(ps_source, "ps_4_0");
if (ps_code)
{
draw_quad(&test_context, ps_code);
init_readback(&test_context, &rb);
for (i = 0; i < 200; i += 40)
{
v = get_readback_vec4(&rb, i, 0);
ok(compare_vec4(v, 0.9f, 0.8f, 0.7f, 0.6f, 0),
"Got unexpected value {%.8e, %.8e, %.8e, %.8e}.\n", v->x, v->y, v->z, v->w);
}
ps_code = compile_shader(ps_source, "ps_4_0");
draw_quad(&test_context, ps_code);
init_readback(&test_context, &rb);
for (i = 240; i < 640; i += 40)
{
v = get_readback_vec4(&rb, i, 0);
ok(compare_vec4(v, 0.1f, 0.2f, 0.3f, 0.4f, 0),
"Got unexpected value {%.8e, %.8e, %.8e, %.8e}.\n", v->x, v->y, v->z, v->w);
}
for (i = 0; i < 200; i += 40)
{
v = get_readback_vec4(&rb, i, 0);
ok(compare_vec4(v, 0.9f, 0.8f, 0.7f, 0.6f, 0),
"Got unexpected value {%.8e, %.8e, %.8e, %.8e}.\n", v->x, v->y, v->z, v->w);
}
release_readback(&test_context, &rb);
ID3D10Blob_Release(ps_code);
for (i = 240; i < 640; i += 40)
{
v = get_readback_vec4(&rb, i, 0);
ok(compare_vec4(v, 0.1f, 0.2f, 0.3f, 0.4f, 0),
"Got unexpected value {%.8e, %.8e, %.8e, %.8e}.\n", v->x, v->y, v->z, v->w);
}
release_readback(&test_context, &rb);
ID3D10Blob_Release(ps_code);
release_test_context(&test_context);
}
......@@ -621,7 +612,8 @@ static void test_sampling(void)
winetest_push_context("Test %u", i);
ID3D11DeviceContext_ClearRenderTargetView(test_context.immediate_context, test_context.rtv, red);
todo_wine ps_code = compile_shader_flags(tests[i], "ps_4_0", D3DCOMPILE_ENABLE_BACKWARDS_COMPATIBILITY);
todo_wine_if (i < 3)
ps_code = compile_shader_flags(tests[i], "ps_4_0", D3DCOMPILE_ENABLE_BACKWARDS_COMPATIBILITY);
if (ps_code)
{
draw_quad(&test_context, ps_code);
......@@ -937,10 +929,12 @@ static void test_reflection(void)
static void check_parameter_desc(const D3D11_SIGNATURE_PARAMETER_DESC *desc,
const D3D11_SIGNATURE_PARAMETER_DESC *expect)
{
ok(!strcmp(desc->SemanticName, expect->SemanticName), "Got name %s.\n", debugstr_a(desc->SemanticName));
todo_wine_if(strcmp(desc->SemanticName, expect->SemanticName))
ok(!strcmp(desc->SemanticName, expect->SemanticName), "Got name %s.\n", debugstr_a(desc->SemanticName));
ok(desc->SemanticIndex == expect->SemanticIndex, "Got index %u.\n", desc->SemanticIndex);
ok(desc->Register == expect->Register, "Got register %u.\n", desc->Register);
ok(desc->SystemValueType == expect->SystemValueType, "Got sysval %u.\n", desc->SystemValueType);
todo_wine_if(desc->SystemValueType != expect->SystemValueType)
ok(desc->SystemValueType == expect->SystemValueType, "Got sysval %u.\n", desc->SystemValueType);
ok(desc->ComponentType == expect->ComponentType, "Got data type %u.\n", desc->ComponentType);
ok(desc->Mask == expect->Mask, "Got mask %#x.\n", desc->Mask);
todo_wine_if(desc->ReadWriteMask != expect->ReadWriteMask)
......@@ -1129,7 +1123,7 @@ static void test_semantic_reflection(void)
{
winetest_push_context("Test %u", i);
todo_wine code = compile_shader_flags(tests[i].source, tests[i].target,
todo_wine_if (i > 5) code = compile_shader_flags(tests[i].source, tests[i].target,
tests[i].legacy ? D3DCOMPILE_ENABLE_BACKWARDS_COMPATIBILITY : 0);
if (!code)
{
......@@ -1143,9 +1137,9 @@ static void test_semantic_reflection(void)
hr = reflection->lpVtbl->GetDesc(reflection, &shader_desc);
ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
todo_wine ok(shader_desc.InputParameters == tests[i].input_count,
ok(shader_desc.InputParameters == tests[i].input_count,
"Got %u input parameters.\n", shader_desc.InputParameters);
todo_wine ok(shader_desc.OutputParameters == tests[i].output_count,
ok(shader_desc.OutputParameters == tests[i].output_count,
"Got %u output parameters.\n", shader_desc.OutputParameters);
for (j = 0; j < shader_desc.InputParameters; ++j)
......
MODULE = d3dcompiler_46.dll
IMPORTLIB = d3dcompiler_46
IMPORTS = dxguid uuid
IMPORTS = wined3d dxguid uuid
EXTRADEFS = -DD3D_COMPILER_VERSION=46
PARENTSRC = ../d3dcompiler_43
EXTRAINCL = $(VKD3D_PE_CFLAGS)
EXTRADLLFLAGS = -Wb,--prefer-native
......
MODULE = d3dcompiler_47.dll
IMPORTLIB = d3dcompiler
IMPORTS = dxguid uuid
IMPORTS = wined3d dxguid uuid
EXTRADEFS = -DD3D_COMPILER_VERSION=47
PARENTSRC = ../d3dcompiler_43
EXTRAINCL = $(VKD3D_PE_CFLAGS)
EXTRADLLFLAGS = -Wb,--prefer-native
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment