module external.directx.d3d12shader;

/*-------------------------------------------------------------------------------------
 *
 * Copyright (c) Microsoft Corporation
 * 
 *-------------------------------------------------------------------------------------*/
// DirectX 12 Shader Header translation from d3d12shader.h
// D3D12 Shader Types and APIs
// Latest update: Windows 10, version 1809

public import external.directx.d3dcommon;

mixin(uuid!(ID3D12ShaderReflectionType, "E913C351", "783D", "48CA", ["A1", "D1", "4F", "30", "62", "84", "AD", "56"]));
extern (C++) interface ID3D12ShaderReflectionType : IUnknown
{
    HRESULT GetDesc(D3D12_SHADER_TYPE_DESC* pDesc);
    ID3D12ShaderReflectionType* GetMemberTypeByIndex(uint Index);
    ID3D12ShaderReflectionType* GetMemberTypeByName(LPCSTR Name);
    LPCSTR GetMemberTypeName(uint Index);
    HRESULT IsEqual(ID3D12ShaderReflectionType* pType);
    ID3D12ShaderReflectionType* GetSubType();
    ID3D12ShaderReflectionType* GetBaseClass();
    uint GetNumInterfaces();
    ID3D12ShaderReflectionType* GetInterfaceByIndex(uint uIndex);
    HRESULT IsOfType(ID3D12ShaderReflectionType* pType);
    HRESULT ImplementsInterface(ID3D12ShaderReflectionType* pBase);
}

mixin(uuid!(ID3D12ShaderReflectionVariable, "8337A8A6", "A216", "444A", ["B2", "F4", "31", "47", "33", "A7", "3A", "EA"]));
extern (C++) interface ID3D12ShaderReflectionVariable : IUnknown
{
    HRESULT GetDesc(D3D12_SHADER_TYPE_DESC* pDesc);
    ID3D12ShaderReflectionType* GetType();
    ID3D12ShaderReflectionConstantBuffer* GetBuffer();
    uint GetInterfaceSlot(uint uArrayIndex);
}

mixin(uuid!(ID3D12ShaderReflectionConstantBuffer, "C59598B4", "48B3", "4869", ["B9", "B1", "B1", "61", "8B", "14", "A8", "B7"]));
extern (C++) interface ID3D12ShaderReflectionConstantBuffer : IUnknown
{
    HRESULT GetDesc(D3D12_SHADER_TYPE_DESC* pDesc);
    ID3D12ShaderReflectionVariable* GetVariableByIndex(uint Index);
    ID3D12ShaderReflectionVariable* GetVariableByName(LPCSTR Name);
}

mixin(uuid!(ID3D12ShaderReflection, "5A58797D", "A72C", "478D", ["8B", "A2", "EF", "C6", "B0", "EF", "E8", "8E"]));
extern (C++) interface ID3D12ShaderReflection : IUnknown
{
    HRESULT QueryInterface(REFIID iid, LPVOID** ppv);
    ULONG AddRef();
    ULONG Release();
    HRESULT GetDesc(D3D12_SHADER_TYPE_DESC* pDesc);
    ID3D12ShaderReflectionConstantBuffer* GetConstantBufferByIndex(uint Index);
    ID3D12ShaderReflectionConstantBuffer* GetConstantBufferByName(LPCSTR Name);
    HRESULT GetResourceBindingDesc(uint ResourceIndex, D3D12_SHADER_INPUT_BIND_DESC* pDesc);
    HRESULT GetInputParameterDesc(uint ParameterIndex, D3D12_SIGNATURE_PARAMETER_DESC* pDesc);
    HRESULT GetOutputParameterDesc(uint ParameterIndex, D3D12_SIGNATURE_PARAMETER_DESC* pDesc);
    HRESULT GetPatchConstantParameterDesc(uint ParameterIndex, D3D12_SIGNATURE_PARAMETER_DESC* pDesc);
    ID3D12ShaderReflectionVariable* GetVariableByName(LPCSTR Name);
    HRESULT GetResourceBindingDescByName(LPCSTR Name, D3D12_SHADER_INPUT_BIND_DESC* pDesc);
    uint GetMovInstructionCount();
    uint GetMovcInstructionCount();
    uint GetConversionInstructionCount();
    uint GetBitwiseInstructionCount();
    D3D_PRIMITIVE GetGSInputPrimitive();
    bool IsSampleFrequencyShader();
    uint GetNumInterfaceSlots();
    HRESULT GetMinFeatureLevel(D3D_FEATURE_LEVEL* pLevel);
    uint GetThreadGroupSize(uint* pSizeX, uint* pSizeY, uint* pSizeZ);
    ulong GetRequiresFlags();
}

mixin(uuid!(ID3D12LibraryReflection, "8E349D19", "54DB", "4A56", ["9D", "C9", "11", "9D", "87", "BD", "B8", "04"]));
extern (C++) interface ID3D12LibraryReflection : IUnknown
{
    HRESULT QueryInterface(REFIID iid, LPVOID** ppv);
    ULONG AddRef();
    ULONG Release();
    HRESULT GetDesc(D3D12_SHADER_TYPE_DESC* pDesc);
    ID3D12FunctionReflection* GetFunctionByIndex(int FunctionIndex);
}

mixin(uuid!(ID3D12FunctionReflection, "1108795C", "2772", "4BA9", ["B2", "A8", "D4", "64", "DC", "7E", "27", "99"]));
extern (C++) interface ID3D12FunctionReflection : IUnknown
{
    HRESULT GetDesc(D3D12_SHADER_TYPE_DESC* pDesc);
    ID3D12ShaderReflectionConstantBuffer* GetConstantBufferByIndex(uint BufferIndex);
    ID3D12ShaderReflectionConstantBuffer* GetConstantBufferByName(LPCSTR Name);
    HRESULT GetResourceBindingDesc(uint ResourceIndex, D3D12_SHADER_INPUT_BIND_DESC* pDesc);
    ID3D12ShaderReflectionVariable* GetVariableByName(LPCSTR Name);
    HRESULT GetResourceBindingDescByName(LPCSTR Name, D3D12_SHADER_INPUT_BIND_DESC* pDesc);
    ID3D12FunctionParameterReflection* GetFunctionParameter(int ParameterIndex);
}

mixin(uuid!(ID3D12FunctionParameterReflection, "EC25F42D", "7006", "4F2B", ["B3", "3E", "02", "CC", "33", "75", "73", "3F"]));
extern (C++) interface ID3D12FunctionParameterReflection : IUnknown
{
    HRESULT GetDesc(D3D12_SHADER_TYPE_DESC* pDesc);
}

alias D3D12_SHADER_VERSION_TYPE = uint;
enum : D3D12_SHADER_VERSION_TYPE
{
    D3D12_SHVER_PIXEL_SHADER = 0,
    D3D12_SHVER_VERTEX_SHADER = 1,
    D3D12_SHVER_GEOMETRY_SHADER = 2,
    D3D12_SHVER_HULL_SHADER = 3,
    D3D12_SHVER_DOMAIN_SHADER = 4,
    D3D12_SHVER_COMPUTE_SHADER = 5,
    D3D12_SHVER_RESERVED0 = 0xFFF0,
}

pure nothrow @safe @nogc
{
    DWORD D3D12_SHVER_GET_TYPE(DWORD _Version)
    {
        return ((_Version >> 16) & 0xffff);
    }

    DWORD D3D12_SHVER_GET_MAJOR(DWORD _Version)
    {
        return ((_Version >> 4) & 0xf);
    }

    DWORD D3D12_SHVER_GET_MINOR(DWORD _Version)
    {
        return ((_Version >> 0) & 0xf);
    }
}

enum D3D_RETURN_PARAMETER_INDEX = -1;
alias D3D12_RESOURCE_RETURN_TYPE = D3D_RESOURCE_RETURN_TYPE;
alias D3D12_CBUFFER_TYPE = D3D_CBUFFER_TYPE;

struct D3D12_SIGNATURE_PARAMETER_DESC
{
    LPCSTR SemanticName;
    uint SemanticIndex;
    uint Register;
    D3D_NAME SystemValueType;
    D3D_REGISTER_COMPONENT_TYPE ComponentType;
    byte Mask;
    byte ReadWriteMask;
    uint Stream;
    D3D_MIN_PRECISION MinPrecision;
}

struct D3D12_SHADER_BUFFER_DESC
{
    LPCSTR Name;
    D3D_CBUFFER_TYPE Type;
    uint Variables;
    uint Size;
    uint uFlags;
}

struct D3D12_SHADER_VARIABLE_DESC
{
    LPCSTR Name;
    uint StartOffset;
    uint Size;
    uint uFlags;
    LPVOID DefaultValue;
    uint StartTexture;
    uint TextureSize;
    uint StartSampler;
    uint SamplerSize;
}

struct D3D12_SHADER_TYPE_DESC
{
    D3D_SHADER_VARIABLE_CLASS Class;
    D3D_SHADER_VARIABLE_TYPE Type;
    uint Rows;
    uint Columns;
    uint Elements;
    uint Members;
    uint Offset;
    LPCSTR Name;
}

alias D3D12_TESSELLATOR_DOMAIN = D3D_TESSELLATOR_DOMAIN;
alias D3D12_TESSELLATOR_PARTITIONING = D3D_TESSELLATOR_PARTITIONING;
alias D3D12_TESSELLATOR_OUTPUT_PRIMITIVE = D3D_TESSELLATOR_OUTPUT_PRIMITIVE;

struct D3D12_SHADER_DESC
{
    uint Version;
    LPCSTR 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;
}

struct D3D12_SHADER_INPUT_BIND_DESC
{
    LPCSTR Name;
    D3D_SHADER_INPUT_TYPE Type;
    uint BindPoint;
    uint BindCount;
    uint uFlags;
    D3D_RESOURCE_RETURN_TYPE ReturnType;
    D3D_SRV_DIMENSION Dimension;
    uint NumSamples;
    uint Space;
    uint uID;
}

enum D3D_SHADER_REQUIRES_DOUBLES = 0x00000001;
enum D3D_SHADER_REQUIRES_EARLY_DEPTH_STENCIL = 0x00000002;
enum D3D_SHADER_REQUIRES_UAVS_AT_EVERY_STAGE = 0x00000004;
enum D3D_SHADER_REQUIRES_64_UAVS = 0x00000008;
enum D3D_SHADER_REQUIRES_MINIMUM_PRECISION = 0x00000010;
enum D3D_SHADER_REQUIRES_11_1_DOUBLE_EXTENSIONS = 0x00000020;
enum D3D_SHADER_REQUIRES_11_1_SHADER_EXTENSIONS = 0x00000040;
enum D3D_SHADER_REQUIRES_LEVEL_9_COMPARISON_FILTERING = 0x00000080;
enum D3D_SHADER_REQUIRES_TILED_RESOURCES = 0x00000100;
enum D3D_SHADER_REQUIRES_STENCIL_REF = 0x00000200;
enum D3D_SHADER_REQUIRES_INNER_COVERAGE = 0x00000400;
enum D3D_SHADER_REQUIRES_TYPED_UAV_LOAD_ADDITIONAL_FORMATS = 0x00000800;
enum D3D_SHADER_REQUIRES_ROVS = 0x00001000;
enum D3D_SHADER_REQUIRES_VIEWPORT_AND_RT_ARRAY_INDEX_FROM_ANY_SHADER_FEEDING_RASTERIZER = 0x00002000;

struct D3D12_LIBRARY_DESC
{
    LPCSTR Creator;
    uint Flags;
    uint FunctionCount;
}

struct D3D12_FUNCTION_DESC
{
    uint Version;
    LPCSTR 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;
    ulong RequiredFeatureFlags;
    LPCSTR Name;
    int FunctionParameterCount;
    bool HasReturn;
    bool Has10Level9VertexShader;
    bool Has10Level9PixelShader;
}

struct D3D12_PARAMETER_DESC
{
    LPCSTR Name;
    LPCSTR 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;
}
