module external.directx.d3d11shadertracing;

/*-------------------------------------------------------------------------------------
 *
 * Copyright (c) Microsoft Corporation
 *
 *-------------------------------------------------------------------------------------*/
// DirectX 11 Shader Tracing Header translation from d3d11shadertracing.h
// Latest update: Windows 10, version 1809

import external.directx.d3d11shader;

mixin(uuid!(ID3D11ShaderTrace, "36b013e6", "2811", "4845", ["ba", "a7", "d6", "23", "fe", "0d", "f1", "04"]));
extern (C++) interface ID3D11ShaderTrace : IUnknown
{
    HRESULT QueryInterface(REFIID riid, void** ppvObject);
    ULONG AddRef();
    ULONG Release();
    HRESULT TraceReady(ulong* pTestCount);
    void ResetTrace();
    HRESULT GetTraceStats(D3D11_TRACE_STATS* pTraceStats);
    HRESULT PSSelectStamp(uint stampIndex);
    HRESULT GetInitialRegisterContents(D3D11_TRACE_REGISTER* pRegister, D3D11_TRACE_VALUE* pValue);
    HRESULT GetStep(uint stepIndex, D3D11_TRACE_STEP* pTraceStep);
    HRESULT GetWrittenRegister(uint stepIndex, uint writtenRegisterIndex, D3D11_TRACE_REGISTER* pRegister, D3D11_TRACE_VALUE* pValue);
    HRESULT GetReadRegister(uint stepIndex, uint readRegisterIndex, D3D11_TRACE_REGISTER* pRegister, D3D11_TRACE_VALUE* pValue);
}

mixin(uuid!(ID3D11ShaderTraceFactory, "1fbad429", "66ab", "41cc", ["96", "17", "66", "7a", "c1", "0e", "44", "59"]));
extern (C++) interface ID3D11ShaderTraceFactory : IUnknown
{
    HRESULT QueryInterface(REFIID riid, void** ppvObject);
    ULONG AddRef();
    ULONG Release();
    HRESULT CreateShaderTrace(IUnknown* pShader, D3D11_SHADER_TRACE_DESC* pTraceDesc, ID3D11ShaderTrace** ppShaderTrace);
}

alias D3D11_SHADER_TYPE = uint;
enum : D3D11_SHADER_TYPE
{
    D3D11_VERTEX_SHADER = 1,
    D3D11_HULL_SHADER = 2,
    D3D11_DOMAIN_SHADER = 3,
    D3D11_GEOMETRY_SHADER = 4,
    D3D11_PIXEL_SHADER = 5,
    D3D11_COMPUTE_SHADER = 6
}
enum D3D11_TRACE_COMPONENT_X = 0x1;
enum D3D11_TRACE_COMPONENT_Y = 0x2;
enum D3D11_TRACE_COMPONENT_Z = 0x4;
enum D3D11_TRACE_COMPONENT_W = 0x8;

alias D3D11_TRACE_COMPONENT_MASK = ubyte;

struct D3D11_VERTEX_SHADER_TRACE_DESC
{
    ulong Invocation;
}

struct D3D11_HULL_SHADER_TRACE_DESC
{
    ulong Invocation;
}

struct D3D11_DOMAIN_SHADER_TRACE_DESC
{
    ulong Invocation;
}

struct D3D11_GEOMETRY_SHADER_TRACE_DESC
{
    ulong Invocation;
}

struct D3D11_PIXEL_SHADER_TRACE_DESC
{
    ulong Invocation;
    int X;
    int Y;
    ulong SampleMask;
}

struct D3D11_COMPUTE_SHADER_TRACE_DESC
{
    ulong Invocation;
    uint[3] ThreadIDInGroup;
    uint[3] ThreadGroupID;
}

enum D3D11_SHADER_TRACE_FLAG_RECORD_REGISTER_WRITES = 0x1;
enum D3D11_SHADER_TRACE_FLAG_RECORD_REGISTER_READS = 0x2;

struct D3D11_SHADER_TRACE_DESC
{
    D3D11_SHADER_TYPE Type;
    uint Flags;
    union
    {
        D3D11_VERTEX_SHADER_TRACE_DESC VertexShaderTraceDesc;
        D3D11_HULL_SHADER_TRACE_DESC HullShaderTraceDesc;
        D3D11_DOMAIN_SHADER_TRACE_DESC DomainShaderTraceDesc;
        D3D11_GEOMETRY_SHADER_TRACE_DESC GeometryShaderTraceDesc;
        D3D11_PIXEL_SHADER_TRACE_DESC PixelShaderTraceDesc;
        D3D11_COMPUTE_SHADER_TRACE_DESC ComputeShaderTraceDesc;
    }
}

alias D3D11_TRACE_GS_INPUT_PRIMITIVE = uint;
enum : D3D11_TRACE_GS_INPUT_PRIMITIVE
{
    D3D11_TRACE_GS_INPUT_PRIMITIVE_UNDEFINED = 0,
    D3D11_TRACE_GS_INPUT_PRIMITIVE_POINT = 1,
    D3D11_TRACE_GS_INPUT_PRIMITIVE_LINE = 2,
    D3D11_TRACE_GS_INPUT_PRIMITIVE_TRIANGLE = 3,
    D3D11_TRACE_GS_INPUT_PRIMITIVE_LINE_ADJ = 6,
    D3D11_TRACE_GS_INPUT_PRIMITIVE_TRIANGLE_ADJ = 7
}
struct D3D11_TRACE_STATS
{
    D3D11_SHADER_TRACE_DESC TraceDesc;
    ubyte NumInvocationsInStamp;
    ubyte TargetStampIndex;
    uint NumTraceSteps;
    D3D11_TRACE_COMPONENT_MASK[32] InputMask;
    D3D11_TRACE_COMPONENT_MASK[32] OutputMask;
    ushort NumTemps;
    ushort MaxIndexableTempIndex;
    ushort[4096] IndexableTempSize;
    ushort ImmediateConstantBufferSize;
    uint[4][2] PixelPosition;
    ulong[4] PixelCoverageMask;
    ulong[4] PixelDiscardedMask;
    ulong[4] PixelCoverageMaskAfterShader;
    ulong[4] PixelCoverageMaskAfterA2CSampleMask;
    ulong[4] PixelCoverageMaskAfterA2CSampleMaskDepth;
    ulong[4] PixelCoverageMaskAfterA2CSampleMaskDepthStencil;
    bool PSOutputsDepth;
    bool PSOutputsMask;
    D3D11_TRACE_GS_INPUT_PRIMITIVE GSInputPrimitive;
    bool GSInputsPrimitiveID;
    D3D11_TRACE_COMPONENT_MASK[32] HSOutputPatchConstantMask;
    D3D11_TRACE_COMPONENT_MASK[32] DSInputPatchConstantMask;
}

struct D3D11_TRACE_VALUE
{
    uint[4] Bits;
    D3D11_TRACE_COMPONENT_MASK ValidMask;
}

enum D3D11_TRACE_REGISTER_TYPE
{
    D3D11_TRACE_OUTPUT_NULL_REGISTER = 0,
    D3D11_TRACE_INPUT_REGISTER = (D3D11_TRACE_OUTPUT_NULL_REGISTER + 1),
    D3D11_TRACE_INPUT_PRIMITIVE_ID_REGISTER = (D3D11_TRACE_INPUT_REGISTER + 1),
    D3D11_TRACE_IMMEDIATE_CONSTANT_BUFFER = (D3D11_TRACE_INPUT_PRIMITIVE_ID_REGISTER + 1),
    D3D11_TRACE_TEMP_REGISTER = (D3D11_TRACE_IMMEDIATE_CONSTANT_BUFFER + 1),
    D3D11_TRACE_INDEXABLE_TEMP_REGISTER = (D3D11_TRACE_TEMP_REGISTER + 1),
    D3D11_TRACE_OUTPUT_REGISTER = (D3D11_TRACE_INDEXABLE_TEMP_REGISTER + 1),
    D3D11_TRACE_OUTPUT_DEPTH_REGISTER = (D3D11_TRACE_OUTPUT_REGISTER + 1),
    D3D11_TRACE_CONSTANT_BUFFER = (D3D11_TRACE_OUTPUT_DEPTH_REGISTER + 1),
    D3D11_TRACE_IMMEDIATE32 = (D3D11_TRACE_CONSTANT_BUFFER + 1),
    D3D11_TRACE_SAMPLER = (D3D11_TRACE_IMMEDIATE32 + 1),
    D3D11_TRACE_RESOURCE = (D3D11_TRACE_SAMPLER + 1),
    D3D11_TRACE_RASTERIZER = (D3D11_TRACE_RESOURCE + 1),
    D3D11_TRACE_OUTPUT_COVERAGE_MASK = (D3D11_TRACE_RASTERIZER + 1),
    D3D11_TRACE_STREAM = (D3D11_TRACE_OUTPUT_COVERAGE_MASK + 1),
    D3D11_TRACE_THIS_POINTER = (D3D11_TRACE_STREAM + 1),
    D3D11_TRACE_OUTPUT_CONTROL_POINT_ID_REGISTER = (D3D11_TRACE_THIS_POINTER + 1),
    D3D11_TRACE_INPUT_FORK_INSTANCE_ID_REGISTER = (D3D11_TRACE_OUTPUT_CONTROL_POINT_ID_REGISTER + 1),
    D3D11_TRACE_INPUT_JOIN_INSTANCE_ID_REGISTER = (D3D11_TRACE_INPUT_FORK_INSTANCE_ID_REGISTER + 1),
    D3D11_TRACE_INPUT_CONTROL_POINT_REGISTER = (D3D11_TRACE_INPUT_JOIN_INSTANCE_ID_REGISTER + 1),
    D3D11_TRACE_OUTPUT_CONTROL_POINT_REGISTER = (D3D11_TRACE_INPUT_CONTROL_POINT_REGISTER + 1),
    D3D11_TRACE_INPUT_PATCH_CONSTANT_REGISTER = (D3D11_TRACE_OUTPUT_CONTROL_POINT_REGISTER + 1),
    D3D11_TRACE_INPUT_DOMAIN_POINT_REGISTER = (D3D11_TRACE_INPUT_PATCH_CONSTANT_REGISTER + 1),
    D3D11_TRACE_UNORDERED_ACCESS_VIEW = (D3D11_TRACE_INPUT_DOMAIN_POINT_REGISTER + 1),
    D3D11_TRACE_THREAD_GROUP_SHARED_MEMORY = (D3D11_TRACE_UNORDERED_ACCESS_VIEW + 1),
    D3D11_TRACE_INPUT_THREAD_ID_REGISTER = (D3D11_TRACE_THREAD_GROUP_SHARED_MEMORY + 1),
    D3D11_TRACE_INPUT_THREAD_GROUP_ID_REGISTER = (D3D11_TRACE_INPUT_THREAD_ID_REGISTER + 1),
    D3D11_TRACE_INPUT_THREAD_ID_IN_GROUP_REGISTER = (D3D11_TRACE_INPUT_THREAD_GROUP_ID_REGISTER + 1),
    D3D11_TRACE_INPUT_COVERAGE_MASK_REGISTER = (D3D11_TRACE_INPUT_THREAD_ID_IN_GROUP_REGISTER + 1),
    D3D11_TRACE_INPUT_THREAD_ID_IN_GROUP_FLATTENED_REGISTER = (D3D11_TRACE_INPUT_COVERAGE_MASK_REGISTER + 1),
    D3D11_TRACE_INPUT_GS_INSTANCE_ID_REGISTER = (D3D11_TRACE_INPUT_THREAD_ID_IN_GROUP_FLATTENED_REGISTER + 1),
    D3D11_TRACE_OUTPUT_DEPTH_GREATER_EQUAL_REGISTER = (D3D11_TRACE_INPUT_GS_INSTANCE_ID_REGISTER + 1),
    D3D11_TRACE_OUTPUT_DEPTH_LESS_EQUAL_REGISTER = (D3D11_TRACE_OUTPUT_DEPTH_GREATER_EQUAL_REGISTER + 1),
    D3D11_TRACE_IMMEDIATE64 = (D3D11_TRACE_OUTPUT_DEPTH_LESS_EQUAL_REGISTER + 1),
    D3D11_TRACE_INPUT_CYCLE_COUNTER_REGISTER = (D3D11_TRACE_IMMEDIATE64 + 1),
    D3D11_TRACE_INTERFACE_POINTER = (D3D11_TRACE_INPUT_CYCLE_COUNTER_REGISTER + 1)
}

enum D3D11_TRACE_REGISTER_FLAGS_RELATIVE_INDEXING = 0x1;
struct D3D11_TRACE_REGISTER
{
    D3D11_TRACE_REGISTER_TYPE RegType;
    union
    {
        ushort Index1D;
        ushort[2] Index2D;
    }

    ubyte OperandIndex;
    ubyte Flags;
}

enum D3D11_TRACE_MISC_GS_EMIT = 0x1;
enum D3D11_TRACE_MISC_GS_CUT = 0x2;
enum D3D11_TRACE_MISC_PS_DISCARD = 0x4;
enum D3D11_TRACE_MISC_GS_EMIT_STREAM = 0x8;
enum D3D11_TRACE_MISC_GS_CUT_STREAM = 0x10;
enum D3D11_TRACE_MISC_HALT = 0x20;
enum D3D11_TRACE_MISC_MESSAGE = 0x40;
alias D3D11_TRACE_MISC_OPERATIONS_MASK = ushort;
struct D3D11_TRACE_STEP
{
    uint ID;
    bool InstructionActive;
    ubyte NumRegistersWritten;
    ubyte NumRegistersRead;
    D3D11_TRACE_MISC_OPERATIONS_MASK MiscOperations;
    uint OpcodeType;
    ulong CurrentGlobalCycle;
}

extern (Windows) nothrow HRESULT D3DDisassemble11Trace(const(void)* pSrcData, size_t SrcDataSize, ID3D11ShaderTrace* pTrace, uint StartStep, uint NumSteps, uint Flags, ID3D10Blob** ppDisassembly);
