/*
 * Copyright 2010 Matteo Bruni 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
 */

import "vkd3d_d3dcommon.idl";

/* If not defined set d3dcompiler_47 by default. */
cpp_quote("#ifndef D3D_COMPILER_VERSION")
cpp_quote("#define D3D_COMPILER_VERSION 47")
cpp_quote("#endif")

const unsigned int D3D_SHADER_REQUIRES_DOUBLES                      = 0x00000001u;
const unsigned int D3D_SHADER_REQUIRES_EARLY_DEPTH_STENCIL          = 0x00000002u;
const unsigned int D3D_SHADER_REQUIRES_UAVS_AT_EVERY_STAGE          = 0x00000004u;
const unsigned int D3D_SHADER_REQUIRES_64_UAVS                      = 0x00000008u;
const unsigned int D3D_SHADER_REQUIRES_MINIMUM_PRECISION            = 0x00000010u;
const unsigned int D3D_SHADER_REQUIRES_11_1_DOUBLE_EXTENSIONS       = 0x00000020u;
const unsigned int D3D_SHADER_REQUIRES_11_1_SHADER_EXTENSIONS       = 0x00000040u;
const unsigned int D3D_SHADER_REQUIRES_LEVEL_9_COMPARISON_FILTERING = 0x00000080u;
const unsigned int D3D_SHADER_REQUIRES_TILED_RESOURCES              = 0x00000100u;

typedef enum D3D11_SHADER_VERSION_TYPE
{
    D3D11_SHVER_PIXEL_SHADER    = 0x0,
    D3D11_SHVER_VERTEX_SHADER   = 0x1,
    D3D11_SHVER_GEOMETRY_SHADER = 0x2,
    D3D11_SHVER_HULL_SHADER     = 0x3,
    D3D11_SHVER_DOMAIN_SHADER   = 0x4,
    D3D11_SHVER_COMPUTE_SHADER  = 0x5,
    D3D11_SHVER_RESERVED0       = 0xfff0,
} D3D11_SHADER_VERSION_TYPE;

typedef struct _D3D11_SHADER_DESC
{
    UINT Version;
    const char *Creator;
    UINT Flags;
    UINT ConstantBuffers;
    UINT BoundResources;
    UINT InputParameters;
    UINT OutputParameters;
    UINT InstructionCount;
    UINT TempRegisterCount;
    UINT TempArrayCount;
    UINT DefCount;
    UINT DclCount;
    UINT TextureNormalInstructions;
    UINT TextureLoadInstructions;
    UINT TextureCompInstructions;
    UINT TextureBiasInstructions;
    UINT TextureGradientInstructions;
    UINT FloatInstructionCount;
    UINT IntInstructionCount;
    UINT UintInstructionCount;
    UINT StaticFlowControlCount;
    UINT DynamicFlowControlCount;
    UINT MacroInstructionCount;
    UINT ArrayInstructionCount;
    UINT CutInstructionCount;
    UINT EmitInstructionCount;
    D3D_PRIMITIVE_TOPOLOGY GSOutputTopology;
    UINT GSMaxOutputVertexCount;
    D3D_PRIMITIVE InputPrimitive;
    UINT PatchConstantParameters;
    UINT cGSInstanceCount;
    UINT cControlPoints;
    D3D_TESSELLATOR_OUTPUT_PRIMITIVE HSOutputPrimitive;
    D3D_TESSELLATOR_PARTITIONING HSPartitioning;
    D3D_TESSELLATOR_DOMAIN TessellatorDomain;
    UINT cBarrierInstructions;
    UINT cInterlockedInstructions;
    UINT cTextureStoreInstructions;
} D3D11_SHADER_DESC;

struct _D3D11_SHADER_VARIABLE_DESC_v40
{
    const char *Name;
    UINT StartOffset;
    UINT Size;
    UINT uFlags;
    void *DefaultValue;
};

struct _D3D11_SHADER_VARIABLE_DESC_v41
{
    const char *Name;
    UINT StartOffset;
    UINT Size;
    UINT uFlags;
    void *DefaultValue;
    UINT StartTexture;
    UINT TextureSize;
    UINT StartSampler;
    UINT SamplerSize;
};

cpp_quote("#if D3D_COMPILER_VERSION >= 41")
cpp_quote("#define _D3D11_SHADER_VARIABLE_DESC _D3D11_SHADER_VARIABLE_DESC_v41")
cpp_quote("#else")
cpp_quote("#define _D3D11_SHADER_VARIABLE_DESC _D3D11_SHADER_VARIABLE_DESC_v40")
cpp_quote("#endif")
typedef struct _D3D11_SHADER_VARIABLE_DESC D3D11_SHADER_VARIABLE_DESC;

typedef struct _D3D11_SHADER_TYPE_DESC
{
    D3D_SHADER_VARIABLE_CLASS Class;
    D3D_SHADER_VARIABLE_TYPE Type;
    UINT Rows;
    UINT Columns;
    UINT Elements;
    UINT Members;
    UINT Offset;
    const char *Name;
} D3D11_SHADER_TYPE_DESC;

typedef struct _D3D11_SHADER_BUFFER_DESC
{
    const char *Name;
    D3D_CBUFFER_TYPE Type;
    UINT Variables;
    UINT Size;
    UINT uFlags;
} D3D11_SHADER_BUFFER_DESC;

typedef struct _D3D11_SHADER_INPUT_BIND_DESC
{
    const char *Name;
    D3D_SHADER_INPUT_TYPE Type;
    UINT BindPoint;
    UINT BindCount;
    UINT uFlags;
    D3D_RESOURCE_RETURN_TYPE ReturnType;
    D3D_SRV_DIMENSION Dimension;
    UINT NumSamples;
} D3D11_SHADER_INPUT_BIND_DESC;

struct _D3D11_SIGNATURE_PARAMETER_DESC_v40
{
    const char *SemanticName;
    UINT SemanticIndex;
    UINT Register;
    D3D_NAME SystemValueType;
    D3D_REGISTER_COMPONENT_TYPE ComponentType;
    BYTE Mask;
    BYTE ReadWriteMask;
    UINT Stream;
};

struct _D3D11_SIGNATURE_PARAMETER_DESC_v46
{
    const char *SemanticName;
    UINT SemanticIndex;
    UINT Register;
    D3D_NAME SystemValueType;
    D3D_REGISTER_COMPONENT_TYPE ComponentType;
    BYTE Mask;
    BYTE ReadWriteMask;
    UINT Stream;
    D3D_MIN_PRECISION MinPrecision;
};

cpp_quote("#if D3D_COMPILER_VERSION >= 46")
cpp_quote("#define _D3D11_SIGNATURE_PARAMETER_DESC _D3D11_SIGNATURE_PARAMETER_DESC_v46")
cpp_quote("#else")
cpp_quote("#define _D3D11_SIGNATURE_PARAMETER_DESC _D3D11_SIGNATURE_PARAMETER_DESC_v40")
cpp_quote("#endif")
typedef struct _D3D11_SIGNATURE_PARAMETER_DESC D3D11_SIGNATURE_PARAMETER_DESC;

typedef struct _D3D11_PARAMETER_DESC
{
    const char *Name;
    const char *SemanticName;
    D3D_SHADER_VARIABLE_TYPE Type;
    D3D_SHADER_VARIABLE_CLASS Class;
    UINT Rows;
    UINT Columns;
    D3D_INTERPOLATION_MODE InterpolationMode;
    D3D_PARAMETER_FLAGS Flags;
    UINT FirstInRegister;
    UINT FirstInComponent;
    UINT FirstOutRegister;
    UINT FirstOutComponent;
} D3D11_PARAMETER_DESC;

typedef struct _D3D11_FUNCTION_DESC
{
    UINT Version;
    const char *Creator;
    UINT Flags;
    UINT ConstantBuffers;
    UINT BoundResources;
    UINT InstructionCount;
    UINT TempRegisterCount;
    UINT TempArrayCount;
    UINT DefCount;
    UINT DclCount;
    UINT TextureNormalInstructions;
    UINT TextureLoadInstructions;
    UINT TextureCompInstructions;
    UINT TextureBiasInstructions;
    UINT TextureGradientInstructions;
    UINT FloatInstructionCount;
    UINT IntInstructionCount;
    UINT UintInstructionCount;
    UINT StaticFlowControlCount;
    UINT DynamicFlowControlCount;
    UINT MacroInstructionCount;
    UINT ArrayInstructionCount;
    UINT MovInstructionCount;
    UINT MovcInstructionCount;
    UINT ConversionInstructionCount;
    UINT BitwiseInstructionCount;
    D3D_FEATURE_LEVEL MinFeatureLevel;
    UINT64 RequiredFeatureFlags;
    const char *Name;
    INT FunctionParameterCount;
    BOOL HasReturn;
    BOOL Has10Level9VertexShader;
    BOOL Has10Level9PixelShader;
} D3D11_FUNCTION_DESC;

typedef struct _D3D11_LIBRARY_DESC
{
    const char *Creator;
    UINT Flags;
    UINT FunctionCount;
} D3D11_LIBRARY_DESC;

/* These are defined as version-neutral in vkd3d_d3dcommon.idl. */
typedef D3D_CBUFFER_TYPE D3D11_CBUFFER_TYPE;
typedef D3D_RESOURCE_RETURN_TYPE D3D11_RESOURCE_RETURN_TYPE;
typedef D3D_TESSELLATOR_DOMAIN D3D11_TESSELLATOR_DOMAIN;
typedef D3D_TESSELLATOR_PARTITIONING D3D11_TESSELLATOR_PARTITIONING;
typedef D3D_TESSELLATOR_OUTPUT_PRIMITIVE D3D11_TESSELLATOR_OUTPUT_PRIMITIVE;

interface ID3D11ShaderReflectionConstantBuffer;

[
    uuid(6e6ffa6a-9bae-4613-a51e-91652d508c21),
    object,
    local,
]
interface ID3D11ShaderReflectionType
{
    HRESULT GetDesc(D3D11_SHADER_TYPE_DESC *desc);
    ID3D11ShaderReflectionType *GetMemberTypeByIndex(UINT index);
    ID3D11ShaderReflectionType *GetMemberTypeByName(const char *name);
    const char *GetMemberTypeName(UINT index);
    HRESULT IsEqual(ID3D11ShaderReflectionType *type);
    ID3D11ShaderReflectionType *GetSubType();
    ID3D11ShaderReflectionType *GetBaseClass();
    UINT GetNumInterfaces();
    ID3D11ShaderReflectionType *GetInterfaceByIndex(UINT index);
    HRESULT IsOfType(ID3D11ShaderReflectionType *type);
    HRESULT ImplementsInterface(ID3D11ShaderReflectionType *base);
}

[
    uuid(51f23923-f3e5-4bd1-91cb-606177d8db4c),
    object,
    local,
]
interface ID3D11ShaderReflectionVariable
{
    HRESULT GetDesc(D3D11_SHADER_VARIABLE_DESC *desc);
    ID3D11ShaderReflectionType *GetType();
    ID3D11ShaderReflectionConstantBuffer *GetBuffer();
    UINT GetInterfaceSlot(UINT index);
}

[
    uuid(eb62d63d-93dd-4318-8ae8-c6f83ad371b8),
    object,
    local,
]
interface ID3D11ShaderReflectionConstantBuffer
{
    HRESULT GetDesc(D3D11_SHADER_BUFFER_DESC *desc);
    ID3D11ShaderReflectionVariable *GetVariableByIndex(UINT index);
    ID3D11ShaderReflectionVariable *GetVariableByName(const char *name);
}

cpp_quote("DEFINE_GUID(IID_ID3D11ShaderReflection_v40, 0x17f27486, 0xa342, 0x4d10, 0x88, 0x42, 0xab, 0x08, 0x74, 0xe7, 0xf6, 0x70);")
cpp_quote("DEFINE_GUID(IID_ID3D11ShaderReflection_v43, 0x0a233719, 0x3960, 0x4578, 0x9d, 0x7c, 0x20, 0x3b, 0x8b, 0x1d, 0x9c, 0xc1);")
cpp_quote("DEFINE_GUID(IID_ID3D11ShaderReflection_v46, 0x8d536ca1, 0x0cca, 0x4956, 0xa8, 0x37, 0x78, 0x69, 0x63, 0x75, 0x55, 0x84);")

cpp_quote("#if D3D_COMPILER_VERSION <= 42")
cpp_quote("# define IID_ID3D11ShaderReflection IID_ID3D11ShaderReflection_v40")
cpp_quote("#elif D3D_COMPILER_VERSION == 43")
cpp_quote("# define IID_ID3D11ShaderReflection IID_ID3D11ShaderReflection_v43")
cpp_quote("#else")
cpp_quote("# define IID_ID3D11ShaderReflection IID_ID3D11ShaderReflection_v46")
cpp_quote("#endif")

[
    object,
    local,
]
interface ID3D11ShaderReflection : IUnknown
{
    HRESULT GetDesc(D3D11_SHADER_DESC *desc);
    ID3D11ShaderReflectionConstantBuffer *GetConstantBufferByIndex(UINT index);
    ID3D11ShaderReflectionConstantBuffer *GetConstantBufferByName(const char *name);
    HRESULT GetResourceBindingDesc(UINT index, D3D11_SHADER_INPUT_BIND_DESC *desc);
    HRESULT GetInputParameterDesc(UINT index, D3D11_SIGNATURE_PARAMETER_DESC *desc);
    HRESULT GetOutputParameterDesc(UINT index, D3D11_SIGNATURE_PARAMETER_DESC *desc);
    HRESULT GetPatchConstantParameterDesc(UINT index, D3D11_SIGNATURE_PARAMETER_DESC *desc);
    ID3D11ShaderReflectionVariable *GetVariableByName(const char *name);
    HRESULT GetResourceBindingDescByName(const char *name, D3D11_SHADER_INPUT_BIND_DESC *desc);
    UINT GetMovInstructionCount();
    UINT GetMovcInstructionCount();
    UINT GetConversionInstructionCount();
    UINT GetBitwiseInstructionCount();
    D3D_PRIMITIVE GetGSInputPrimitive();
    BOOL IsSampleFrequencyShader();
    UINT GetNumInterfaceSlots();
    HRESULT GetMinFeatureLevel(D3D_FEATURE_LEVEL *level);
    UINT GetThreadGroupSize(UINT *size_x, UINT *size_y, UINT *size_z);
    UINT64 GetRequiresFlags();
}

[
    uuid(42757488-334f-47fe-982e-1a65d08cc462),
    object,
    local,
]
interface ID3D11FunctionParameterReflection
{
    HRESULT GetDesc(D3D11_PARAMETER_DESC *desc);
}

[
    uuid(207bcecb-d683-4a06-a8a3-9b149b9f73a4),
    object,
    local,
]
interface ID3D11FunctionReflection
{
    HRESULT GetDesc(D3D11_FUNCTION_DESC *desc);
    ID3D11ShaderReflectionConstantBuffer *GetConstantBufferByIndex(UINT index);
    ID3D11ShaderReflectionConstantBuffer *GetConstantBufferByName(const char *name);
    HRESULT GetResourceBindingDesc(UINT index, D3D11_SHADER_INPUT_BIND_DESC *desc);
    ID3D11ShaderReflectionVariable *GetVariableByName(const char *name);
    HRESULT GetResourceBindingDescByName(const char *name, D3D11_SHADER_INPUT_BIND_DESC *desc);
    ID3D11FunctionParameterReflection *GetFunctionParameter(INT index);
}

[
    uuid(54384f1b-5b3e-4bb7-ae01-60ba3097cbb6),
    object,
    local,
]
interface ID3D11LibraryReflection : IUnknown
{
    HRESULT GetDesc(D3D11_LIBRARY_DESC *desc);
    ID3D11FunctionReflection *GetFunctionByIndex(INT index);
}

[
    uuid(469e07f7-045a-48d5-aa12-68a478cdf75d),
    object,
    local,
]
interface ID3D11ModuleInstance : IUnknown
{
    HRESULT BindConstantBuffer(UINT src_slot, UINT dst_slot, UINT dst_offset);
    HRESULT BindConstantBufferByName(const char *name, UINT dst_slot, UINT dst_offset);
    HRESULT BindResource(UINT src_slot, UINT dst_slot, UINT count);
    HRESULT BindResourceByName(const char *name, UINT dst_slot, UINT count);
    HRESULT BindSampler(UINT src_slot,  UINT dst_slot,  UINT count);
    HRESULT BindSamplerByName(const char *name,  UINT dst_slot, UINT count);
    HRESULT BindUnorderedAccessView(UINT src_slot,  UINT dst_slot, UINT count);
    HRESULT BindUnorderedAccessViewByName(const char *name, UINT dst_slot, UINT count);
    HRESULT BindResourceAsUnorderedAccessView(UINT src_slot, UINT dst_slot, UINT count);
    HRESULT BindResourceAsUnorderedAccessViewByName(const char *name, UINT dst_slot, UINT count);
}

[
    uuid(cac701ee-80fc-4122-8242-10b39c8cec34),
    object,
    local,
]
interface ID3D11Module : IUnknown
{
    HRESULT CreateInstance(const char *instance_namespace, ID3D11ModuleInstance **instance);
}

[
    uuid(59a6cd0e-e10d-4c1f-88c0-63aba1daf30e),
    object,
    local,
]
interface ID3D11Linker : IUnknown
{
    HRESULT Link(ID3D11ModuleInstance *instance, const char *instance_name,
            const char *target_name, UINT flags, ID3DBlob **shader, ID3DBlob **messages);
    HRESULT UseLibrary(ID3D11ModuleInstance *instance);
    HRESULT AddClipPlaneFromCBuffer(UINT slot, UINT entry);
}

[
    uuid(d80dd70c-8d2f-4751-94a1-03c79b3556db),
    object,
    local,
]
interface ID3D11LinkingNode : IUnknown
{
}

[
    uuid(54133220-1ce8-43d3-8236-9855c5ceecff),
    object,
    local,
]
interface ID3D11FunctionLinkingGraph : IUnknown
{
    HRESULT CreateModuleInstance(ID3D11ModuleInstance **instance, ID3DBlob **messages);
    HRESULT SetInputSignature(const D3D11_PARAMETER_DESC *parameter_desc,
            UINT parameter_count, ID3D11LinkingNode **input_node);
    HRESULT SetOutputSignature(const D3D11_PARAMETER_DESC *parameter_desc,
            UINT parameter_count, ID3D11LinkingNode **output_node);
    HRESULT CallFunction(const char *instance_namespace, ID3D11Module *function_module,
            const char *function_name, ID3D11LinkingNode **call_node);
    HRESULT PassValue(ID3D11LinkingNode *src_node, INT src_parameter_index,
            ID3D11LinkingNode *dst_node, INT dst_parameter_index);
    HRESULT PassValueWithSwizzle(ID3D11LinkingNode *src_node, INT src_parameter_index, const char *src_swizzle,
            ID3D11LinkingNode *dst_node, INT dst_parameter_index, const char *dst_swizzle);
    HRESULT GetLastError(ID3DBlob **error);
    HRESULT GenerateHlsl(UINT flags, ID3DBlob **hlsl);
}
