From 4f1818ff5bf4345b9c1409b7292d4faa0cdc2dbf Mon Sep 17 00:00:00 2001 From: Nielsbishere Date: Thu, 25 Jul 2024 19:49:35 +0200 Subject: [PATCH 01/28] d3d12shader.h now includes ways of retrieving more information from library files --- include/directx/d3d12shader.h | 149 ++++++++++++++++++++++++++-------- 1 file changed, 113 insertions(+), 36 deletions(-) diff --git a/include/directx/d3d12shader.h b/include/directx/d3d12shader.h index 65728dd..f445b25 100644 --- a/include/directx/d3d12shader.h +++ b/include/directx/d3d12shader.h @@ -208,7 +208,6 @@ typedef struct _D3D12_SHADER_INPUT_BIND_DESC #define D3D_SHADER_REQUIRES_SAMPLE_CMP_GRADIENT_OR_BIAS 0x80000000 #define D3D_SHADER_REQUIRES_EXTENDED_COMMAND_INFO 0x100000000ull - typedef struct _D3D12_LIBRARY_DESC { LPCSTR Creator; // The name of the originator of the library. @@ -216,44 +215,122 @@ typedef struct _D3D12_LIBRARY_DESC UINT FunctionCount; // Number of functions exported from the library. } D3D12_LIBRARY_DESC; +typedef struct _D3D12_FUNCTION_COMPUTE_DESC { + UINT WaveSizeMin; // SM 6.8+ WaveSize(n, ..., ...) min, max, pref + UINT WaveSizeMax; // SM 6.8+ WaveSize(..., n, ...) min, max, pref + UINT WaveSizePreferred; // SM 6.6 WaveSize(n) or WaveSize(.., ..., n) + UINT NumThreads[3]; // numthreads(x, y, z) +} D3D12_FUNCTION_COMPUTE_DESC; + +typedef struct _D3D12_FUNCTION_NODE_DESC { + D3D12_FUNCTION_COMPUTE_DESC ComputeDesc; // Node extends ComputeDesc + D3D12_NODE_OVERRIDES_TYPE LaunchType; // Launch type + BOOL IsProgramEntry; // Is program entry + INT LocalRootArgumentsTableIndex; // Local root arguments table index + UINT DispatchGrid[3]; // Dispatch grid + UINT MaxDispatchGrid[3]; // Max dispatch grid + UINT MaxRecursionDepth; // Max recursion depth +} D3D12_FUNCTION_NODE_DESC; + +typedef struct _D3D12_FUNCTION_RAYTRACING_DESC { + UINT ParamPayloadSize; // Payload or param size (callable) in bytes + UINT AttributeSize; // Attribute size in bytes +} D3D12_FUNCTION_RAYTRACING_DESC; + +typedef struct _D3D12_FUNCTION_AMPLIFICATION_DESC { + UINT PayloadSize; // Payload size in bytes +} D3D12_FUNCTION_AMPLIFICATION_DESC; + +typedef struct _D3D12_FUNCTION_PIXEL_DESC { + BOOL EarlyDepthStencil; // Early depth stencil +} D3D12_FUNCTION_PIXEL_DESC; + +typedef struct _D3D12_FUNCTION_DOMAIN_DESC { + D3D12_TESSELLATOR_DOMAIN Domain; // Domain + UINT InputControlPoints; // Input control points +} D3D12_FUNCTION_DOMAIN_DESC; + +typedef struct _D3D12_FUNCTION_HULL_DESC { + D3D12_TESSELLATOR_DOMAIN Domain; // Domain + D3D12_TESSELLATOR_PARTITIONING Partition; // Partition + D3D12_TESSELLATOR_OUTPUT_PRIMITIVE OutputPrimitive; // Output primitive + UINT InputControlPoints; // Input control points + UINT OutputControlPoints; // Output control points + FLOAT MaxTessFactor; // Max tessellation factor +} D3D12_FUNCTION_HULL_DESC; + +typedef struct _D3D12_FUNCTION_GEOMETRY_DESC { + D3D12_PRIMITIVE InputPrimitive; // Input primitive + UINT MaxVertexCount; // Max vertex count + UINT InstanceCount; // Instance count + D3D12_PRIMITIVE_TOPOLOGY StreamPrimitiveTopologies[4]; // Stream primitive topologies +} D3D12_FUNCTION_GEOMETRY_DESC; + +typedef enum D3D12_MESH_OUTPUT_TOPOLOGY { + D3D12_MESH_OUTPUT_TOPOLOGY_LINE = 1, + D3D12_MESH_OUTPUT_TOPOLOGY_TRIANGLE = 2 +} D3D12_MESH_OUTPUT_TOPOLOGY; + +typedef struct _D3D12_FUNCTION_MESH_DESC { + UINT PayloadSize; // Payload size in bytes + UINT MaxVertexCount; // Max vertex count + UINT MaxPrimitiveCount; // Max primitive count + D3D12_MESH_OUTPUT_TOPOLOGY OutputTopology; // Output topology +} D3D12_FUNCTION_MESH_DESC; + typedef struct _D3D12_FUNCTION_DESC { - UINT Version; // Shader version - LPCSTR Creator; // Creator string - UINT Flags; // Shader compilation/parse flags - - UINT ConstantBuffers; // Number of constant buffers - UINT BoundResources; // Number of bound resources + UINT Version; // Shader version + LPCSTR Creator; // Creator string + UINT Flags; // Shader compilation/parse flags + + UINT ConstantBuffers; // Number of constant buffers + UINT BoundResources; // Number of bound resources + + UINT InstructionCount; // Number of emitted instructions + UINT TempRegisterCount; // Number of temporary registers used + UINT TempArrayCount; // Number of temporary arrays used + UINT DefCount; // Number of constant defines + UINT DclCount; // Number of declarations (input + output) + UINT TextureNormalInstructions; // Number of non-categorized texture instructions + UINT TextureLoadInstructions; // Number of texture load instructions + UINT TextureCompInstructions; // Number of texture comparison instructions + UINT TextureBiasInstructions; // Number of texture bias instructions + UINT TextureGradientInstructions; // Number of texture gradient instructions + UINT FloatInstructionCount; // Number of floating point arithmetic instructions used + UINT IntInstructionCount; // Number of signed integer arithmetic instructions used + UINT UintInstructionCount; // Number of unsigned integer arithmetic instructions used + UINT StaticFlowControlCount; // Number of static flow control instructions used + UINT DynamicFlowControlCount; // Number of dynamic flow control instructions used + UINT MacroInstructionCount; // Number of macro instructions used + UINT ArrayInstructionCount; // Number of array instructions used + UINT MovInstructionCount; // Number of mov instructions used + UINT MovcInstructionCount; // Number of movc instructions used + UINT ConversionInstructionCount; // Number of type conversion instructions used + UINT BitwiseInstructionCount; // Number of bitwise arithmetic instructions used + D3D_FEATURE_LEVEL MinFeatureLevel; // Min target of the function byte code + UINT64 RequiredFeatureFlags; // Required feature flags + + LPCSTR Name; // Function name + INT FunctionParameterCount; // Number of logical parameters in the function signature (not including return) + BOOL HasReturn; // TRUE, if function returns a value, false - it is a subroutine + BOOL Has10Level9VertexShader; // TRUE, if there is a 10L9 VS blob + BOOL Has10Level9PixelShader; // TRUE, if there is a 10L9 PS blob + + D3D12_SHADER_VERSION_TYPE ShaderType; // Function's shader stage + + union { + D3D12_FUNCTION_NODE_DESC NodeShader; // ShaderType == D3D12_SHVER_NODE_SHADER + D3D12_FUNCTION_HULL_DESC HullShader; // ShaderType == D3D12_SHVER_HULL_SHADER + D3D12_FUNCTION_COMPUTE_DESC ComputeShader; // ShaderType == D3D12_SHVER_COMPUTE_SHADER + D3D12_FUNCTION_MESH_DESC MeshShader; // ShaderType == D3D12_SHVER_MESH_SHADER + D3D12_FUNCTION_GEOMETRY_DESC GeometryShader; // ShaderType == D3D12_SHVER_GEOMETRY_SHADER + D3D12_FUNCTION_RAYTRACING_DESC RaytracingShader; // ShaderType > D3D12_SHVER_RAY_GENERATION_SHADER && <= D3D12_SHVER_CALLABLE_SHADER + D3D12_FUNCTION_DOMAIN_DESC DomainShader; // ShaderType == D3D12_SHVER_DOMAIN_SHADER + D3D12_FUNCTION_AMPLIFICATION_DESC AmplificationShader; // ShaderType == D3D12_SHVER_AMPLIFICATION_SHADER + D3D12_FUNCTION_PIXEL_DESC PixelShader; // ShaderType == D3D12_SHVER_PIXEL_SHADER + }; - UINT InstructionCount; // Number of emitted instructions - UINT TempRegisterCount; // Number of temporary registers used - UINT TempArrayCount; // Number of temporary arrays used - UINT DefCount; // Number of constant defines - UINT DclCount; // Number of declarations (input + output) - UINT TextureNormalInstructions; // Number of non-categorized texture instructions - UINT TextureLoadInstructions; // Number of texture load instructions - UINT TextureCompInstructions; // Number of texture comparison instructions - UINT TextureBiasInstructions; // Number of texture bias instructions - UINT TextureGradientInstructions; // Number of texture gradient instructions - UINT FloatInstructionCount; // Number of floating point arithmetic instructions used - UINT IntInstructionCount; // Number of signed integer arithmetic instructions used - UINT UintInstructionCount; // Number of unsigned integer arithmetic instructions used - UINT StaticFlowControlCount; // Number of static flow control instructions used - UINT DynamicFlowControlCount; // Number of dynamic flow control instructions used - UINT MacroInstructionCount; // Number of macro instructions used - UINT ArrayInstructionCount; // Number of array instructions used - UINT MovInstructionCount; // Number of mov instructions used - UINT MovcInstructionCount; // Number of movc instructions used - UINT ConversionInstructionCount; // Number of type conversion instructions used - UINT BitwiseInstructionCount; // Number of bitwise arithmetic instructions used - D3D_FEATURE_LEVEL MinFeatureLevel; // Min target of the function byte code - UINT64 RequiredFeatureFlags; // Required feature flags - - LPCSTR Name; // Function name - INT FunctionParameterCount; // Number of logical parameters in the function signature (not including return) - BOOL HasReturn; // TRUE, if function returns a value, false - it is a subroutine - BOOL Has10Level9VertexShader; // TRUE, if there is a 10L9 VS blob - BOOL Has10Level9PixelShader; // TRUE, if there is a 10L9 PS blob } D3D12_FUNCTION_DESC; typedef struct _D3D12_PARAMETER_DESC From df4640327c498a9b673542e943e4bb0e01c640a4 Mon Sep 17 00:00:00 2001 From: Nielsbishere Date: Thu, 25 Jul 2024 20:06:03 +0200 Subject: [PATCH 02/28] Renamed D3D12_FUNCTION_X_DESC to D3D12_X_SHADER_DESC and added it to D3D12_SHADER_DESC --- include/directx/d3d12shader.h | 208 +++++++++++++++++----------------- 1 file changed, 106 insertions(+), 102 deletions(-) diff --git a/include/directx/d3d12shader.h b/include/directx/d3d12shader.h index f445b25..d69c005 100644 --- a/include/directx/d3d12shader.h +++ b/include/directx/d3d12shader.h @@ -114,49 +114,101 @@ typedef D3D_TESSELLATOR_PARTITIONING D3D12_TESSELLATOR_PARTITIONING; typedef D3D_TESSELLATOR_OUTPUT_PRIMITIVE D3D12_TESSELLATOR_OUTPUT_PRIMITIVE; +typedef struct _D3D12_COMPUTE_SHADER_DESC { + UINT WaveSizeMin; // SM 6.8+ WaveSize(n, ..., ...) min, max, pref + UINT WaveSizeMax; // SM 6.8+ WaveSize(..., n, ...) min, max, pref + UINT WaveSizePreferred; // SM 6.6 WaveSize(n) or WaveSize(.., ..., n) + UINT NumThreads[3]; // numthreads(x, y, z) +} D3D12_COMPUTE_SHADER_DESC; + +typedef struct _D3D12_AMPLIFICATION_SHADER_DESC { + UINT PayloadSize; // Payload size in bytes +} D3D12_AMPLIFICATION_SHADER_DESC; + +typedef struct _D3D12_PIXEL_SHADER_DESC { + BOOL EarlyDepthStencil; // Early depth stencil +} D3D12_PIXEL_SHADER_DESC; + +typedef struct _D3D12_DOMAIN_SHADER_DESC { + D3D12_TESSELLATOR_DOMAIN Domain; // Domain + UINT InputControlPoints; // Input control points +} D3D12_DOMAIN_SHADER_DESC; + +typedef struct _D3D12_HULL_SHADER_DESC { + D3D12_TESSELLATOR_DOMAIN Domain; // Domain + D3D12_TESSELLATOR_PARTITIONING Partition; // Partition + D3D12_TESSELLATOR_OUTPUT_PRIMITIVE OutputPrimitive; // Output primitive + UINT InputControlPoints; // Input control points + UINT OutputControlPoints; // Output control points + FLOAT MaxTessFactor; // Max tessellation factor +} D3D12_HULL_SHADER_DESC; + +typedef struct _D3D12_GEOMETRY_SHADER_DESC { + D3D12_PRIMITIVE InputPrimitive; // Input primitive + UINT MaxVertexCount; // Max vertex count + UINT InstanceCount; // Instance count + D3D12_PRIMITIVE_TOPOLOGY StreamPrimitiveTopologies[4]; // Stream primitive topologies +} D3D12_GEOMETRY_SHADER_DESC; + +typedef enum D3D12_MESH_OUTPUT_TOPOLOGY { + D3D12_MESH_OUTPUT_TOPOLOGY_LINE = 1, + D3D12_MESH_OUTPUT_TOPOLOGY_TRIANGLE = 2 +} D3D12_MESH_OUTPUT_TOPOLOGY; + +typedef struct _D3D12_MESH_SHADER_DESC { + UINT PayloadSize; // Payload size in bytes + UINT MaxVertexCount; // Max vertex count + UINT MaxPrimitiveCount; // Max primitive count + D3D12_MESH_OUTPUT_TOPOLOGY OutputTopology; // Output topology +} D3D12_MESH_SHADER_DESC; + typedef struct _D3D12_SHADER_DESC { - UINT Version; // Shader version - LPCSTR Creator; // Creator string - UINT Flags; // Shader compilation/parse flags - - UINT ConstantBuffers; // Number of constant buffers - UINT BoundResources; // Number of bound resources - UINT InputParameters; // Number of parameters in the input signature - UINT OutputParameters; // Number of parameters in the output signature - - UINT InstructionCount; // Number of emitted instructions - UINT TempRegisterCount; // Number of temporary registers used - UINT TempArrayCount; // Number of temporary arrays used - UINT DefCount; // Number of constant defines - UINT DclCount; // Number of declarations (input + output) - UINT TextureNormalInstructions; // Number of non-categorized texture instructions - UINT TextureLoadInstructions; // Number of texture load instructions - UINT TextureCompInstructions; // Number of texture comparison instructions - UINT TextureBiasInstructions; // Number of texture bias instructions - UINT TextureGradientInstructions; // Number of texture gradient instructions - UINT FloatInstructionCount; // Number of floating point arithmetic instructions used - UINT IntInstructionCount; // Number of signed integer arithmetic instructions used - UINT UintInstructionCount; // Number of unsigned integer arithmetic instructions used - UINT StaticFlowControlCount; // Number of static flow control instructions used - UINT DynamicFlowControlCount; // Number of dynamic flow control instructions used - UINT MacroInstructionCount; // Number of macro instructions used - UINT ArrayInstructionCount; // Number of array instructions used - UINT CutInstructionCount; // Number of cut instructions used - UINT EmitInstructionCount; // Number of emit instructions used - D3D_PRIMITIVE_TOPOLOGY GSOutputTopology; // Geometry shader output topology - UINT GSMaxOutputVertexCount; // Geometry shader maximum output vertex count - D3D_PRIMITIVE InputPrimitive; // GS/HS input primitive - UINT PatchConstantParameters; // Number of parameters in the patch constant signature - UINT cGSInstanceCount; // Number of Geometry shader instances - UINT cControlPoints; // Number of control points in the HS->DS stage - D3D_TESSELLATOR_OUTPUT_PRIMITIVE HSOutputPrimitive; // Primitive output by the tessellator - D3D_TESSELLATOR_PARTITIONING HSPartitioning; // Partitioning mode of the tessellator - D3D_TESSELLATOR_DOMAIN TessellatorDomain; // Domain of the tessellator (quad, tri, isoline) - // instruction counts - UINT cBarrierInstructions; // Number of barrier instructions in a compute shader - UINT cInterlockedInstructions; // Number of interlocked instructions - UINT cTextureStoreInstructions; // Number of texture writes + UINT Version; // Shader version + LPCSTR Creator; // Creator string + UINT Flags; // Shader compilation/parse flags + + UINT ConstantBuffers; // Number of constant buffers + UINT BoundResources; // Number of bound resources + UINT InputParameters; // Number of parameters in the input signature + UINT OutputParameters; // Number of parameters in the output signature + + UINT InstructionCount; // Number of emitted instructions + UINT TempRegisterCount; // Number of temporary registers used + UINT TempArrayCount; // Number of temporary arrays used + UINT DefCount; // Number of constant defines + UINT DclCount; // Number of declarations (input + output) + UINT TextureNormalInstructions; // Number of non-categorized texture instructions + UINT TextureLoadInstructions; // Number of texture load instructions + UINT TextureCompInstructions; // Number of texture comparison instructions + UINT TextureBiasInstructions; // Number of texture bias instructions + UINT TextureGradientInstructions; // Number of texture gradient instructions + UINT FloatInstructionCount; // Number of floating point arithmetic instructions used + UINT IntInstructionCount; // Number of signed integer arithmetic instructions used + UINT UintInstructionCount; // Number of unsigned integer arithmetic instructions used + UINT StaticFlowControlCount; // Number of static flow control instructions used + UINT DynamicFlowControlCount; // Number of dynamic flow control instructions used + UINT MacroInstructionCount; // Number of macro instructions used + UINT ArrayInstructionCount; // Number of array instructions used + UINT CutInstructionCount; // Number of cut instructions used + UINT EmitInstructionCount; // Number of emit instructions used + + UINT cBarrierInstructions; // Number of barrier instructions in a compute shader + UINT cInterlockedInstructions; // Number of interlocked instructions + UINT cTextureStoreInstructions; // Number of texture writes + + D3D12_SHADER_VERSION_TYPE ShaderType; // Function's shader stage + + union { + D3D12_HULL_SHADER_DESC HullShader; // ShaderType == D3D12_SHVER_HULL_SHADER + D3D12_COMPUTE_SHADER_DESC ComputeShader; // ShaderType == D3D12_SHVER_COMPUTE_SHADER + D3D12_MESH_SHADER_DESC MeshShader; // ShaderType == D3D12_SHVER_MESH_SHADER + D3D12_GEOMETRY_SHADER_DESC GeometryShader; // ShaderType == D3D12_SHVER_GEOMETRY_SHADER + D3D12_DOMAIN_SHADER_DESC DomainShader; // ShaderType == D3D12_SHVER_DOMAIN_SHADER + D3D12_AMPLIFICATION_SHADER_DESC AmplificationShader; // ShaderType == D3D12_SHVER_AMPLIFICATION_SHADER + D3D12_PIXEL_SHADER_DESC PixelShader; // ShaderType == D3D12_SHVER_PIXEL_SHADER + }; + } D3D12_SHADER_DESC; typedef struct _D3D12_SHADER_INPUT_BIND_DESC @@ -215,14 +267,7 @@ typedef struct _D3D12_LIBRARY_DESC UINT FunctionCount; // Number of functions exported from the library. } D3D12_LIBRARY_DESC; -typedef struct _D3D12_FUNCTION_COMPUTE_DESC { - UINT WaveSizeMin; // SM 6.8+ WaveSize(n, ..., ...) min, max, pref - UINT WaveSizeMax; // SM 6.8+ WaveSize(..., n, ...) min, max, pref - UINT WaveSizePreferred; // SM 6.6 WaveSize(n) or WaveSize(.., ..., n) - UINT NumThreads[3]; // numthreads(x, y, z) -} D3D12_FUNCTION_COMPUTE_DESC; - -typedef struct _D3D12_FUNCTION_NODE_DESC { +typedef struct _D3D12_NODE_SHADER_DESC { D3D12_FUNCTION_COMPUTE_DESC ComputeDesc; // Node extends ComputeDesc D3D12_NODE_OVERRIDES_TYPE LaunchType; // Launch type BOOL IsProgramEntry; // Is program entry @@ -230,53 +275,12 @@ typedef struct _D3D12_FUNCTION_NODE_DESC { UINT DispatchGrid[3]; // Dispatch grid UINT MaxDispatchGrid[3]; // Max dispatch grid UINT MaxRecursionDepth; // Max recursion depth -} D3D12_FUNCTION_NODE_DESC; +} D3D12_NODE_SHADER_DESC; -typedef struct _D3D12_FUNCTION_RAYTRACING_DESC { +typedef struct _D3D12_RAYTRACING_SHADER_DESC { UINT ParamPayloadSize; // Payload or param size (callable) in bytes UINT AttributeSize; // Attribute size in bytes -} D3D12_FUNCTION_RAYTRACING_DESC; - -typedef struct _D3D12_FUNCTION_AMPLIFICATION_DESC { - UINT PayloadSize; // Payload size in bytes -} D3D12_FUNCTION_AMPLIFICATION_DESC; - -typedef struct _D3D12_FUNCTION_PIXEL_DESC { - BOOL EarlyDepthStencil; // Early depth stencil -} D3D12_FUNCTION_PIXEL_DESC; - -typedef struct _D3D12_FUNCTION_DOMAIN_DESC { - D3D12_TESSELLATOR_DOMAIN Domain; // Domain - UINT InputControlPoints; // Input control points -} D3D12_FUNCTION_DOMAIN_DESC; - -typedef struct _D3D12_FUNCTION_HULL_DESC { - D3D12_TESSELLATOR_DOMAIN Domain; // Domain - D3D12_TESSELLATOR_PARTITIONING Partition; // Partition - D3D12_TESSELLATOR_OUTPUT_PRIMITIVE OutputPrimitive; // Output primitive - UINT InputControlPoints; // Input control points - UINT OutputControlPoints; // Output control points - FLOAT MaxTessFactor; // Max tessellation factor -} D3D12_FUNCTION_HULL_DESC; - -typedef struct _D3D12_FUNCTION_GEOMETRY_DESC { - D3D12_PRIMITIVE InputPrimitive; // Input primitive - UINT MaxVertexCount; // Max vertex count - UINT InstanceCount; // Instance count - D3D12_PRIMITIVE_TOPOLOGY StreamPrimitiveTopologies[4]; // Stream primitive topologies -} D3D12_FUNCTION_GEOMETRY_DESC; - -typedef enum D3D12_MESH_OUTPUT_TOPOLOGY { - D3D12_MESH_OUTPUT_TOPOLOGY_LINE = 1, - D3D12_MESH_OUTPUT_TOPOLOGY_TRIANGLE = 2 -} D3D12_MESH_OUTPUT_TOPOLOGY; - -typedef struct _D3D12_FUNCTION_MESH_DESC { - UINT PayloadSize; // Payload size in bytes - UINT MaxVertexCount; // Max vertex count - UINT MaxPrimitiveCount; // Max primitive count - D3D12_MESH_OUTPUT_TOPOLOGY OutputTopology; // Output topology -} D3D12_FUNCTION_MESH_DESC; +} D3D12_RAYTRACING_SHADER_DESC; typedef struct _D3D12_FUNCTION_DESC { @@ -320,15 +324,15 @@ typedef struct _D3D12_FUNCTION_DESC D3D12_SHADER_VERSION_TYPE ShaderType; // Function's shader stage union { - D3D12_FUNCTION_NODE_DESC NodeShader; // ShaderType == D3D12_SHVER_NODE_SHADER - D3D12_FUNCTION_HULL_DESC HullShader; // ShaderType == D3D12_SHVER_HULL_SHADER - D3D12_FUNCTION_COMPUTE_DESC ComputeShader; // ShaderType == D3D12_SHVER_COMPUTE_SHADER - D3D12_FUNCTION_MESH_DESC MeshShader; // ShaderType == D3D12_SHVER_MESH_SHADER - D3D12_FUNCTION_GEOMETRY_DESC GeometryShader; // ShaderType == D3D12_SHVER_GEOMETRY_SHADER - D3D12_FUNCTION_RAYTRACING_DESC RaytracingShader; // ShaderType > D3D12_SHVER_RAY_GENERATION_SHADER && <= D3D12_SHVER_CALLABLE_SHADER - D3D12_FUNCTION_DOMAIN_DESC DomainShader; // ShaderType == D3D12_SHVER_DOMAIN_SHADER - D3D12_FUNCTION_AMPLIFICATION_DESC AmplificationShader; // ShaderType == D3D12_SHVER_AMPLIFICATION_SHADER - D3D12_FUNCTION_PIXEL_DESC PixelShader; // ShaderType == D3D12_SHVER_PIXEL_SHADER + D3D12_NODE_SHADER_DESC NodeShader; // ShaderType == D3D12_SHVER_NODE_SHADER + D3D12_HULL_SHADER_DESC HullShader; // ShaderType == D3D12_SHVER_HULL_SHADER + D3D12_COMPUTE_SHADER_DESC ComputeShader; // ShaderType == D3D12_SHVER_COMPUTE_SHADER + D3D12_MESH_SHADER_DESC MeshShader; // ShaderType == D3D12_SHVER_MESH_SHADER + D3D12_GEOMETRY_SHADER_DESC GeometryShader; // ShaderType == D3D12_SHVER_GEOMETRY_SHADER + D3D12_RAYTRACING_SHADER_DESC RaytracingShader; // ShaderType > D3D12_SHVER_RAY_GENERATION_SHADER && <= D3D12_SHVER_CALLABLE_SHADER + D3D12_DOMAIN_SHADER_DESC DomainShader; // ShaderType == D3D12_SHVER_DOMAIN_SHADER + D3D12_AMPLIFICATION_SHADER_DESC AmplificationShader; // ShaderType == D3D12_SHVER_AMPLIFICATION_SHADER + D3D12_PIXEL_SHADER_DESC PixelShader; // ShaderType == D3D12_SHVER_PIXEL_SHADER }; } D3D12_FUNCTION_DESC; From 918f977cdfc42e53ae724a6aa6008cae7409b32b Mon Sep 17 00:00:00 2001 From: Nielsbishere Date: Thu, 25 Jul 2024 21:35:43 +0200 Subject: [PATCH 03/28] Fixed compile error --- include/directx/d3d12shader.h | 114 ++++++++++++++++++++-------------- 1 file changed, 67 insertions(+), 47 deletions(-) diff --git a/include/directx/d3d12shader.h b/include/directx/d3d12shader.h index d69c005..a304644 100644 --- a/include/directx/d3d12shader.h +++ b/include/directx/d3d12shader.h @@ -143,6 +143,10 @@ typedef struct _D3D12_HULL_SHADER_DESC { FLOAT MaxTessFactor; // Max tessellation factor } D3D12_HULL_SHADER_DESC; +typedef D3D_PRIMITIVE_TOPOLOGY D3D12_PRIMITIVE_TOPOLOGY; + +typedef D3D_PRIMITIVE D3D12_PRIMITIVE; + typedef struct _D3D12_GEOMETRY_SHADER_DESC { D3D12_PRIMITIVE InputPrimitive; // Input primitive UINT MaxVertexCount; // Max vertex count @@ -162,52 +166,60 @@ typedef struct _D3D12_MESH_SHADER_DESC { D3D12_MESH_OUTPUT_TOPOLOGY OutputTopology; // Output topology } D3D12_MESH_SHADER_DESC; -typedef struct _D3D12_SHADER_DESC -{ - UINT Version; // Shader version - LPCSTR Creator; // Creator string - UINT Flags; // Shader compilation/parse flags - - UINT ConstantBuffers; // Number of constant buffers - UINT BoundResources; // Number of bound resources - UINT InputParameters; // Number of parameters in the input signature - UINT OutputParameters; // Number of parameters in the output signature - - UINT InstructionCount; // Number of emitted instructions - UINT TempRegisterCount; // Number of temporary registers used - UINT TempArrayCount; // Number of temporary arrays used - UINT DefCount; // Number of constant defines - UINT DclCount; // Number of declarations (input + output) - UINT TextureNormalInstructions; // Number of non-categorized texture instructions - UINT TextureLoadInstructions; // Number of texture load instructions - UINT TextureCompInstructions; // Number of texture comparison instructions - UINT TextureBiasInstructions; // Number of texture bias instructions - UINT TextureGradientInstructions; // Number of texture gradient instructions - UINT FloatInstructionCount; // Number of floating point arithmetic instructions used - UINT IntInstructionCount; // Number of signed integer arithmetic instructions used - UINT UintInstructionCount; // Number of unsigned integer arithmetic instructions used - UINT StaticFlowControlCount; // Number of static flow control instructions used - UINT DynamicFlowControlCount; // Number of dynamic flow control instructions used - UINT MacroInstructionCount; // Number of macro instructions used - UINT ArrayInstructionCount; // Number of array instructions used - UINT CutInstructionCount; // Number of cut instructions used - UINT EmitInstructionCount; // Number of emit instructions used - - UINT cBarrierInstructions; // Number of barrier instructions in a compute shader - UINT cInterlockedInstructions; // Number of interlocked instructions - UINT cTextureStoreInstructions; // Number of texture writes - - D3D12_SHADER_VERSION_TYPE ShaderType; // Function's shader stage - - union { - D3D12_HULL_SHADER_DESC HullShader; // ShaderType == D3D12_SHVER_HULL_SHADER - D3D12_COMPUTE_SHADER_DESC ComputeShader; // ShaderType == D3D12_SHVER_COMPUTE_SHADER - D3D12_MESH_SHADER_DESC MeshShader; // ShaderType == D3D12_SHVER_MESH_SHADER - D3D12_GEOMETRY_SHADER_DESC GeometryShader; // ShaderType == D3D12_SHVER_GEOMETRY_SHADER - D3D12_DOMAIN_SHADER_DESC DomainShader; // ShaderType == D3D12_SHVER_DOMAIN_SHADER - D3D12_AMPLIFICATION_SHADER_DESC AmplificationShader; // ShaderType == D3D12_SHVER_AMPLIFICATION_SHADER - D3D12_PIXEL_SHADER_DESC PixelShader; // ShaderType == D3D12_SHVER_PIXEL_SHADER - }; +typedef struct _D3D12_SHADER_DESC { + + UINT Version; // Shader version + LPCSTR Creator; // Creator string + UINT Flags; // Shader compilation/parse flags + + UINT ConstantBuffers; // Number of constant buffers + UINT BoundResources; // Number of bound resources + UINT InputParameters; // Number of parameters in the input signature + UINT OutputParameters; // Number of parameters in the output signature + + UINT InstructionCount; // Number of emitted instructions + UINT TempRegisterCount; // Number of temporary registers used + UINT TempArrayCount; // Number of temporary arrays used + UINT DefCount; // Number of constant defines + UINT DclCount; // Number of declarations (input + output) + UINT TextureNormalInstructions; // Number of non-categorized texture + // instructions + UINT TextureLoadInstructions; // Number of texture load instructions + UINT TextureCompInstructions; // Number of texture comparison instructions + UINT TextureBiasInstructions; // Number of texture bias instructions + UINT TextureGradientInstructions; // Number of texture gradient instructions + UINT FloatInstructionCount; // Number of floating point arithmetic + // instructions used + UINT IntInstructionCount; // Number of signed integer arithmetic + // instructions used + UINT UintInstructionCount; // Number of unsigned integer arithmetic + // instructions used + UINT StaticFlowControlCount; // Number of static flow control instructions + // used + UINT DynamicFlowControlCount; // Number of dynamic flow control instructions + // used + UINT MacroInstructionCount; // Number of macro instructions used + UINT ArrayInstructionCount; // Number of array instructions used + UINT CutInstructionCount; // Number of cut instructions used + UINT EmitInstructionCount; // Number of emit instructions used + D3D_PRIMITIVE_TOPOLOGY GSOutputTopology; // Geometry shader output topology + UINT GSMaxOutputVertexCount; // Geometry shader maximum output vertex count + D3D_PRIMITIVE InputPrimitive; // GS/HS input primitive + UINT PatchConstantParameters; // Number of parameters in the patch constant + // signature + UINT cGSInstanceCount; // Number of Geometry shader instances + UINT cControlPoints; // Number of control points in the HS->DS stage + D3D_TESSELLATOR_OUTPUT_PRIMITIVE + HSOutputPrimitive; // Primitive output by the tessellator + D3D_TESSELLATOR_PARTITIONING + HSPartitioning; // Partitioning mode of the tessellator + D3D_TESSELLATOR_DOMAIN + TessellatorDomain; // Domain of the tessellator (quad, tri, isoline) + // instruction counts + UINT cBarrierInstructions; // Number of barrier instructions in a compute + // shader + UINT cInterlockedInstructions; // Number of interlocked instructions + UINT cTextureStoreInstructions; // Number of texture writes } D3D12_SHADER_DESC; @@ -267,8 +279,16 @@ typedef struct _D3D12_LIBRARY_DESC UINT FunctionCount; // Number of functions exported from the library. } D3D12_LIBRARY_DESC; +typedef enum D3D12_NODE_OVERRIDES_TYPE { + D3D12_NODE_OVERRIDES_TYPE_NONE = 0, + D3D12_NODE_OVERRIDES_TYPE_BROADCASTING_LAUNCH = 1, + D3D12_NODE_OVERRIDES_TYPE_COALESCING_LAUNCH = 2, + D3D12_NODE_OVERRIDES_TYPE_THREAD_LAUNCH = 3, + D3D12_NODE_OVERRIDES_TYPE_COMMON_COMPUTE = 4 +} D3D12_NODE_OVERRIDES_TYPE; + typedef struct _D3D12_NODE_SHADER_DESC { - D3D12_FUNCTION_COMPUTE_DESC ComputeDesc; // Node extends ComputeDesc + D3D12_COMPUTE_SHADER_DESC ComputeDesc; // Node extends ComputeDesc D3D12_NODE_OVERRIDES_TYPE LaunchType; // Launch type BOOL IsProgramEntry; // Is program entry INT LocalRootArgumentsTableIndex; // Local root arguments table index From 56464468659ab5f59a25ea0617fd82802da68345 Mon Sep 17 00:00:00 2001 From: Nielsbishere Date: Thu, 25 Jul 2024 23:53:04 +0200 Subject: [PATCH 04/28] Fixed formatting issue for D3D12_SHADER_DESC --- include/directx/d3d12shader.h | 98 +++++++++++++++-------------------- 1 file changed, 41 insertions(+), 57 deletions(-) diff --git a/include/directx/d3d12shader.h b/include/directx/d3d12shader.h index a304644..9d85b4c 100644 --- a/include/directx/d3d12shader.h +++ b/include/directx/d3d12shader.h @@ -114,6 +114,47 @@ typedef D3D_TESSELLATOR_PARTITIONING D3D12_TESSELLATOR_PARTITIONING; typedef D3D_TESSELLATOR_OUTPUT_PRIMITIVE D3D12_TESSELLATOR_OUTPUT_PRIMITIVE; +typedef struct _D3D12_SHADER_DESC +{ + UINT Version; // Shader version + LPCSTR Creator; // Creator string + UINT Flags; // Shader compilation/parse flags + + UINT ConstantBuffers; // Number of constant buffers + UINT BoundResources; // Number of bound resources + UINT InputParameters; // Number of parameters in the input signature + UINT OutputParameters; // Number of parameters in the output signature + + UINT InstructionCount; // Number of emitted instructions + UINT TempRegisterCount; // Number of temporary registers used + UINT TempArrayCount; // Number of temporary arrays used + UINT DefCount; // Number of constant defines + UINT DclCount; // Number of declarations (input + output) + UINT TextureNormalInstructions; // Number of non-categorized texture instructions + UINT TextureLoadInstructions; // Number of texture load instructions + UINT TextureCompInstructions; // Number of texture comparison instructions + UINT TextureBiasInstructions; // Number of texture bias instructions + UINT TextureGradientInstructions; // Number of texture gradient instructions + UINT FloatInstructionCount; // Number of floating point arithmetic instructions used + UINT IntInstructionCount; // Number of signed integer arithmetic instructions used + UINT UintInstructionCount; // Number of unsigned integer arithmetic instructions used + UINT StaticFlowControlCount; // Number of static flow control instructions used + UINT DynamicFlowControlCount; // Number of dynamic flow control instructions used + UINT MacroInstructionCount; // Number of macro instructions used + UINT ArrayInstructionCount; // Number of array instructions used + UINT CutInstructionCount; // Number of cut instructions used + UINT EmitInstructionCount; // Number of emit instructions used + D3D_PRIMITIVE_TOPOLOGY GSOutputTopology; // Geometry shader output topology + UINT GSMaxOutputVertexCount; // Geometry shader maximum output vertex count + D3D_PRIMITIVE InputPrimitive; // GS/HS input primitive + UINT PatchConstantParameters; // Number of parameters in the patch constant signature + UINT cGSInstanceCount; // Number of Geometry shader instances + UINT cControlPoints; // Number of control points in the HS->DS stage + D3D_TESSELLATOR_OUTPUT_PRIMITIVE HSOutputPrimitive; // Primitive output by the tessellator + D3D_TESSELLATOR_PARTITIONING HSPartitioning; // Partitioning mode of the tessellator + D3D_TESSELLATOR_DOMAIN TessellatorDomain; // Domain of the tessellator (quad, tri, isoline) +} D3D12_SHADER_DESC; + typedef struct _D3D12_COMPUTE_SHADER_DESC { UINT WaveSizeMin; // SM 6.8+ WaveSize(n, ..., ...) min, max, pref UINT WaveSizeMax; // SM 6.8+ WaveSize(..., n, ...) min, max, pref @@ -166,63 +207,6 @@ typedef struct _D3D12_MESH_SHADER_DESC { D3D12_MESH_OUTPUT_TOPOLOGY OutputTopology; // Output topology } D3D12_MESH_SHADER_DESC; -typedef struct _D3D12_SHADER_DESC { - - UINT Version; // Shader version - LPCSTR Creator; // Creator string - UINT Flags; // Shader compilation/parse flags - - UINT ConstantBuffers; // Number of constant buffers - UINT BoundResources; // Number of bound resources - UINT InputParameters; // Number of parameters in the input signature - UINT OutputParameters; // Number of parameters in the output signature - - UINT InstructionCount; // Number of emitted instructions - UINT TempRegisterCount; // Number of temporary registers used - UINT TempArrayCount; // Number of temporary arrays used - UINT DefCount; // Number of constant defines - UINT DclCount; // Number of declarations (input + output) - UINT TextureNormalInstructions; // Number of non-categorized texture - // instructions - UINT TextureLoadInstructions; // Number of texture load instructions - UINT TextureCompInstructions; // Number of texture comparison instructions - UINT TextureBiasInstructions; // Number of texture bias instructions - UINT TextureGradientInstructions; // Number of texture gradient instructions - UINT FloatInstructionCount; // Number of floating point arithmetic - // instructions used - UINT IntInstructionCount; // Number of signed integer arithmetic - // instructions used - UINT UintInstructionCount; // Number of unsigned integer arithmetic - // instructions used - UINT StaticFlowControlCount; // Number of static flow control instructions - // used - UINT DynamicFlowControlCount; // Number of dynamic flow control instructions - // used - UINT MacroInstructionCount; // Number of macro instructions used - UINT ArrayInstructionCount; // Number of array instructions used - UINT CutInstructionCount; // Number of cut instructions used - UINT EmitInstructionCount; // Number of emit instructions used - D3D_PRIMITIVE_TOPOLOGY GSOutputTopology; // Geometry shader output topology - UINT GSMaxOutputVertexCount; // Geometry shader maximum output vertex count - D3D_PRIMITIVE InputPrimitive; // GS/HS input primitive - UINT PatchConstantParameters; // Number of parameters in the patch constant - // signature - UINT cGSInstanceCount; // Number of Geometry shader instances - UINT cControlPoints; // Number of control points in the HS->DS stage - D3D_TESSELLATOR_OUTPUT_PRIMITIVE - HSOutputPrimitive; // Primitive output by the tessellator - D3D_TESSELLATOR_PARTITIONING - HSPartitioning; // Partitioning mode of the tessellator - D3D_TESSELLATOR_DOMAIN - TessellatorDomain; // Domain of the tessellator (quad, tri, isoline) - // instruction counts - UINT cBarrierInstructions; // Number of barrier instructions in a compute - // shader - UINT cInterlockedInstructions; // Number of interlocked instructions - UINT cTextureStoreInstructions; // Number of texture writes - -} D3D12_SHADER_DESC; - typedef struct _D3D12_SHADER_INPUT_BIND_DESC { LPCSTR Name; // Name of the resource From aa04a8b6bbf905b22fc1f8b7b2a2b7d1a29d85eb Mon Sep 17 00:00:00 2001 From: Nielsbishere Date: Thu, 25 Jul 2024 23:53:39 +0200 Subject: [PATCH 05/28] Added missing parameters to D3D12_SHADER_DESC --- include/directx/d3d12shader.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/directx/d3d12shader.h b/include/directx/d3d12shader.h index 9d85b4c..127f00b 100644 --- a/include/directx/d3d12shader.h +++ b/include/directx/d3d12shader.h @@ -153,6 +153,10 @@ typedef struct _D3D12_SHADER_DESC D3D_TESSELLATOR_OUTPUT_PRIMITIVE HSOutputPrimitive; // Primitive output by the tessellator D3D_TESSELLATOR_PARTITIONING HSPartitioning; // Partitioning mode of the tessellator D3D_TESSELLATOR_DOMAIN TessellatorDomain; // Domain of the tessellator (quad, tri, isoline) + // instruction counts + UINT cBarrierInstructions; // Number of barrier instructions in a compute shader + UINT cInterlockedInstructions; // Number of interlocked instructions + UINT cTextureStoreInstructions; // Number of texture writes } D3D12_SHADER_DESC; typedef struct _D3D12_COMPUTE_SHADER_DESC { From 9cf5d621fd80023d9a40a1d0581048b1346c6003 Mon Sep 17 00:00:00 2001 From: Nielsbishere Date: Fri, 26 Jul 2024 00:20:01 +0200 Subject: [PATCH 06/28] Now exposed D3D12_FUNCTION_DESC1 as a separate struct. --- include/directx/d3d12shader.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/include/directx/d3d12shader.h b/include/directx/d3d12shader.h index 127f00b..6c7800d 100644 --- a/include/directx/d3d12shader.h +++ b/include/directx/d3d12shader.h @@ -329,6 +329,10 @@ typedef struct _D3D12_FUNCTION_DESC BOOL Has10Level9VertexShader; // TRUE, if there is a 10L9 VS blob BOOL Has10Level9PixelShader; // TRUE, if there is a 10L9 PS blob +} D3D12_FUNCTION_DESC; + +typedef struct _D3D12_FUNCTION_DESC1 { // Only accessible via DXC + D3D12_SHADER_VERSION_TYPE ShaderType; // Function's shader stage union { @@ -343,7 +347,7 @@ typedef struct _D3D12_FUNCTION_DESC D3D12_PIXEL_SHADER_DESC PixelShader; // ShaderType == D3D12_SHVER_PIXEL_SHADER }; -} D3D12_FUNCTION_DESC; +} D3D12_FUNCTION_DESC1; typedef struct _D3D12_PARAMETER_DESC { @@ -537,6 +541,7 @@ DEFINE_GUID(IID_ID3D12FunctionReflection, DECLARE_INTERFACE(ID3D12FunctionReflection) { STDMETHOD(GetDesc)(THIS_ _Out_ D3D12_FUNCTION_DESC * pDesc) PURE; + STDMETHOD(GetDesc1)(THIS_ _Out_ D3D12_FUNCTION_DESC1 * pDesc) PURE; STDMETHOD_(ID3D12ShaderReflectionConstantBuffer *, GetConstantBufferByIndex)(THIS_ _In_ UINT BufferIndex) PURE; STDMETHOD_(ID3D12ShaderReflectionConstantBuffer *, GetConstantBufferByName)(THIS_ _In_ LPCSTR Name) PURE; From 8698ca38dfe361bae06d3e7cb4e2c5fd4e98eb9d Mon Sep 17 00:00:00 2001 From: Nielsbishere Date: Fri, 26 Jul 2024 14:39:55 +0200 Subject: [PATCH 07/28] Added ID3D12LibraryReflection1 so ID3D12FunctionReflection1 can be queried, since ID3D12FunctionReflection isn't an IUnknown --- include/directx/d3d12shader.h | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/include/directx/d3d12shader.h b/include/directx/d3d12shader.h index 6c7800d..86123e8 100644 --- a/include/directx/d3d12shader.h +++ b/include/directx/d3d12shader.h @@ -389,6 +389,9 @@ typedef interface ID3D12LibraryReflection *LPD3D12LIBRARYREFLECTION; typedef interface ID3D12FunctionReflection ID3D12FunctionReflection; typedef interface ID3D12FunctionReflection *LPD3D12FUNCTIONREFLECTION; +typedef interface ID3D12FunctionReflection1 ID3D12FunctionReflection1; +typedef interface ID3D12FunctionReflection1 *LPD3D12FUNCTIONREFLECTION1; + typedef interface ID3D12FunctionParameterReflection ID3D12FunctionParameterReflection; typedef interface ID3D12FunctionParameterReflection *LPD3D12FUNCTIONPARAMETERREFLECTION; @@ -530,6 +533,19 @@ DECLARE_INTERFACE_(ID3D12LibraryReflection, IUnknown) STDMETHOD_(ID3D12FunctionReflection *, GetFunctionByIndex)(THIS_ _In_ INT FunctionIndex) PURE; }; +// {07692220-8721-4514-BFFE-969BB33196B6} +interface DECLSPEC_UUID("07692220-8721-4514-BFFE-969BB33196B6") ID3D12LibraryReflection1; +DEFINE_GUID(IID_ID3D12LibraryReflection1, +0x7692220, 0x8721, 0x4514, 0xbf, 0xfe, 0x96, 0x9b, 0xb3, 0x31, 0x96, 0xb6); + +#undef INTERFACE +#define INTERFACE ID3D12LibraryReflection1 + +DECLARE_INTERFACE_(ID3D12LibraryReflection1, ID3D12LibraryReflection) +{ + STDMETHOD_(ID3D12FunctionReflection1 *, GetFunctionByIndex1)(THIS_ _In_ INT FunctionIndex) PURE; +}; + // {1108795C-2772-4BA9-B2A8-D464DC7E2799} interface DECLSPEC_UUID("1108795C-2772-4BA9-B2A8-D464DC7E2799") ID3D12FunctionReflection; DEFINE_GUID(IID_ID3D12FunctionReflection, @@ -541,7 +557,6 @@ DEFINE_GUID(IID_ID3D12FunctionReflection, DECLARE_INTERFACE(ID3D12FunctionReflection) { STDMETHOD(GetDesc)(THIS_ _Out_ D3D12_FUNCTION_DESC * pDesc) PURE; - STDMETHOD(GetDesc1)(THIS_ _Out_ D3D12_FUNCTION_DESC1 * pDesc) PURE; STDMETHOD_(ID3D12ShaderReflectionConstantBuffer *, GetConstantBufferByIndex)(THIS_ _In_ UINT BufferIndex) PURE; STDMETHOD_(ID3D12ShaderReflectionConstantBuffer *, GetConstantBufferByName)(THIS_ _In_ LPCSTR Name) PURE; @@ -558,6 +573,19 @@ DECLARE_INTERFACE(ID3D12FunctionReflection) STDMETHOD_(ID3D12FunctionParameterReflection *, GetFunctionParameter)(THIS_ _In_ INT ParameterIndex) PURE; }; +// {3DE08670-5E87-4E72-AF92-35CF81947AD7} +interface DECLSPEC_UUID("3DE08670-5E87-4E72-AF92-35CF81947AD7") ID3D12FunctionReflection1; +DEFINE_GUID(IID_ID3D12FunctionReflection1, +0x3de08670, 0x5e87, 0x4e72, 0xaf, 0x92, 0x35, 0xcf, 0x81, 0x94, 0x7a, 0xd7); + +#undef INTERFACE +#define INTERFACE ID3D12FunctionReflection1 + +DECLARE_INTERFACE_(ID3D12FunctionReflection1, ID3D12FunctionReflection) +{ + STDMETHOD(GetDesc1)(THIS_ _Out_ D3D12_FUNCTION_DESC1 * pDesc) PURE; +}; + // {EC25F42D-7006-4F2B-B33E-02CC3375733F} interface DECLSPEC_UUID("EC25F42D-7006-4F2B-B33E-02CC3375733F") ID3D12FunctionParameterReflection; DEFINE_GUID(IID_ID3D12FunctionParameterReflection, From 47ad841800e33bb4d1bb02e1e1e48a715111faa4 Mon Sep 17 00:00:00 2001 From: Nielsbishere Date: Fri, 26 Jul 2024 15:26:34 +0200 Subject: [PATCH 08/28] Added missing declaration of ID3D12LibraryReflection1 --- include/directx/d3d12shader.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/directx/d3d12shader.h b/include/directx/d3d12shader.h index 86123e8..cceac56 100644 --- a/include/directx/d3d12shader.h +++ b/include/directx/d3d12shader.h @@ -386,6 +386,9 @@ typedef interface ID3D12ShaderReflection *LPD3D12SHADERREFLECTION; typedef interface ID3D12LibraryReflection ID3D12LibraryReflection; typedef interface ID3D12LibraryReflection *LPD3D12LIBRARYREFLECTION; +typedef interface ID3D12LibraryReflection1 ID3D12LibraryReflection1; +typedef interface ID3D12LibraryReflection1 *LPD3D12LIBRARYREFLECTION1; + typedef interface ID3D12FunctionReflection ID3D12FunctionReflection; typedef interface ID3D12FunctionReflection *LPD3D12FUNCTIONREFLECTION; From 5c20ea3857dd1bb06c94e9198f8cc5cdf0a45403 Mon Sep 17 00:00:00 2001 From: Nielsbishere Date: Fri, 26 Jul 2024 23:18:35 +0200 Subject: [PATCH 09/28] Exposed serialized root signature to D3D12_FUNCTION_DESC1, Added GetInputNode & GetOutputNode to ID3D12FunctionReflection1 to be able to be queried for Workgraphs. Added input/output node count and shaderId/shaderSharedInput (name & id) to D3D12_NODE_DESC --- include/directx/d3d12shader.h | 97 +++++++++++++++++++++++++++++++++-- 1 file changed, 93 insertions(+), 4 deletions(-) diff --git a/include/directx/d3d12shader.h b/include/directx/d3d12shader.h index cceac56..452c5cd 100644 --- a/include/directx/d3d12shader.h +++ b/include/directx/d3d12shader.h @@ -267,7 +267,8 @@ typedef struct _D3D12_LIBRARY_DESC UINT FunctionCount; // Number of functions exported from the library. } D3D12_LIBRARY_DESC; -typedef enum D3D12_NODE_OVERRIDES_TYPE { +typedef enum D3D12_NODE_OVERRIDES_TYPE +{ D3D12_NODE_OVERRIDES_TYPE_NONE = 0, D3D12_NODE_OVERRIDES_TYPE_BROADCASTING_LAUNCH = 1, D3D12_NODE_OVERRIDES_TYPE_COALESCING_LAUNCH = 2, @@ -275,7 +276,14 @@ typedef enum D3D12_NODE_OVERRIDES_TYPE { D3D12_NODE_OVERRIDES_TYPE_COMMON_COMPUTE = 4 } D3D12_NODE_OVERRIDES_TYPE; -typedef struct _D3D12_NODE_SHADER_DESC { +typedef struct _D3D12_NODE_ID_DESC +{ + const char* Name; + UINT ID; +} D3D12_NODE_ID_DESC; + +typedef struct _D3D12_NODE_SHADER_DESC +{ D3D12_COMPUTE_SHADER_DESC ComputeDesc; // Node extends ComputeDesc D3D12_NODE_OVERRIDES_TYPE LaunchType; // Launch type BOOL IsProgramEntry; // Is program entry @@ -283,9 +291,84 @@ typedef struct _D3D12_NODE_SHADER_DESC { UINT DispatchGrid[3]; // Dispatch grid UINT MaxDispatchGrid[3]; // Max dispatch grid UINT MaxRecursionDepth; // Max recursion depth + D3D12_NODE_ID_DESC ShaderId; // Node shader id + D3D12_NODE_ID_DESC ShaderSharedInput; // Node shader shared input + UINT InputNodes; // Input nodes + UINT OutputNodes; // Output nodes } D3D12_NODE_SHADER_DESC; -typedef struct _D3D12_RAYTRACING_SHADER_DESC { +typedef enum D3D12_NODE_IO_FLAGS +{ + D3D12_NODE_IO_FLAGS_NONE = 0, + D3D12_NODE_IO_FLAGS_INPUT = 1 << 0, + D3D12_NODE_IO_FLAGS_OUTPUT = 1 << 1, + D3D12_NODE_IO_FLAGS_READ_WRITE = 1 << 2, + D3D12_NODE_IO_FLAGS_EMPTY_RECORD = 1 << 3, + D3D12_NODE_IO_FLAGS_NODE_ARRAY = 1 << 4, + D3D12_NODE_IO_FLAGS_THREAD_RECORD = 1 << 5, + D3D12_NODE_IO_FLAGS_GROUP_RECORD = 1 << 6, + D3D12_NODE_IO_FLAGS_DISPATCH_RECORD = 1 << 7, + + D3D12_NODE_IO_FLAGS_NODE_IO_MASK = (1 << 8) - 1, + + D3D12_NODE_IO_FLAGS_TRACK_RW_INPUT_SHARING = 1 << 8, + D3D12_NODE_IO_FLAGS_GLOBALLY_COHERENT = 1 << 9, + + D3D12_NODE_IO_FLAGS_RECORD_FLAG_MASK = 3 << 8, + D3D12_NODE_IO_FLAGS_NODE_FLAGS_MASK = 1 << 8 + +} D3D12_NODE_IO_FLAGS; + +typedef enum D3D12_DISPATCH_COMPONENT_TYPE +{ + D3D12_DISPATCH_COMPONENT_TYPE_I1 = 1, + D3D12_DISPATCH_COMPONENT_TYPE_I16 = 2, + D3D12_DISPATCH_COMPONENT_TYPE_U16 = 3, + D3D12_DISPATCH_COMPONENT_TYPE_I32 = 4, + D3D12_DISPATCH_COMPONENT_TYPE_U32 = 5, + D3D12_DISPATCH_COMPONENT_TYPE_I64 = 6, + D3D12_DISPATCH_COMPONENT_TYPE_U64 = 7, + D3D12_DISPATCH_COMPONENT_TYPE_F16 = 8, + D3D12_DISPATCH_COMPONENT_TYPE_F32 = 9, + D3D12_DISPATCH_COMPONENT_TYPE_F64 = 10, + D3D12_DISPATCH_COMPONENT_TYPE_SNORM_F16 = 11, + D3D12_DISPATCH_COMPONENT_TYPE_UNORM_F16 = 12, + D3D12_DISPATCH_COMPONENT_TYPE_SNORM_F32 = 13, + D3D12_DISPATCH_COMPONENT_TYPE_UNORM_F32 = 14, + D3D12_DISPATCH_COMPONENT_TYPE_SNORM_F64 = 15, + D3D12_DISPATCH_COMPONENT_TYPE_UNORM_F64 = 16, + D3D12_DISPATCH_COMPONENT_TYPE_PACKED_S8X32 = 17, + D3D12_DISPATCH_COMPONENT_TYPE_PACKED_U8X32 = 18 + +} D3D12_DISPATCH_COMPONENT_TYPE; + +typedef struct _D3D12_DISPATCH_GRID_DESC +{ + UINT ByteOffset; // Byte offset + D3D12_DISPATCH_COMPONENT_TYPE ComponentType; // Component type + UINT NumComponents; +} D3D12_DISPATCH_GRID_DESC; + +typedef struct _D3D12_NODE_RECORD_TYPE_DESC +{ + UINT Size; // Size + UINT Alignment; // Alignment + D3D12_DISPATCH_GRID_DESC DispatchGrid; // Dispatch grid +} D3D12_NODE_RECORD_TYPE_DESC; + +typedef struct _D3D12_NODE_DESC +{ + D3D12_NODE_IO_FLAGS Flags; // Node flags + D3D12_NODE_RECORD_TYPE_DESC Type; // Node type + D3D12_NODE_ID_DESC OutputID; // Node output id + UINT MaxRecords; // Max records + INT MaxRecordsSharedWith; // Max records shared with + UINT OutputArraySize; // Output array size + BOOL AllowSparseNodes; // Allow sparse nodes +} D3D12_NODE_DESC; + +typedef struct _D3D12_RAYTRACING_SHADER_DESC +{ UINT ParamPayloadSize; // Payload or param size (callable) in bytes UINT AttributeSize; // Attribute size in bytes } D3D12_RAYTRACING_SHADER_DESC; @@ -331,7 +414,10 @@ typedef struct _D3D12_FUNCTION_DESC } D3D12_FUNCTION_DESC; -typedef struct _D3D12_FUNCTION_DESC1 { // Only accessible via DXC +typedef struct _D3D12_FUNCTION_DESC1 // Only accessible via DXC +{ + UINT RootSignatureSize; // Serialized root signature size + const uint8_t* RootSignaturePtr; // Serialized root signature pointer D3D12_SHADER_VERSION_TYPE ShaderType; // Function's shader stage @@ -587,6 +673,9 @@ DEFINE_GUID(IID_ID3D12FunctionReflection1, DECLARE_INTERFACE_(ID3D12FunctionReflection1, ID3D12FunctionReflection) { STDMETHOD(GetDesc1)(THIS_ _Out_ D3D12_FUNCTION_DESC1 * pDesc) PURE; + + STDMETHOD(GetInputNode)(UINT i, THIS_ _Out_ D3D12_NODE_DESC * pDesc) PURE; + STDMETHOD(GetOutputNode)(UINT i, THIS_ _Out_ D3D12_NODE_DESC * pDesc) PURE; }; // {EC25F42D-7006-4F2B-B33E-02CC3375733F} From 94bb304a26486cf26f7bc764cb2ac77b67207152 Mon Sep 17 00:00:00 2001 From: Nielsbishere Date: Fri, 26 Jul 2024 23:22:16 +0200 Subject: [PATCH 10/28] Fixed minor formatting issue --- include/directx/d3d12shader.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/directx/d3d12shader.h b/include/directx/d3d12shader.h index 452c5cd..59516e8 100644 --- a/include/directx/d3d12shader.h +++ b/include/directx/d3d12shader.h @@ -279,7 +279,7 @@ typedef enum D3D12_NODE_OVERRIDES_TYPE typedef struct _D3D12_NODE_ID_DESC { const char* Name; - UINT ID; + UINT ID; } D3D12_NODE_ID_DESC; typedef struct _D3D12_NODE_SHADER_DESC From 704af69710af880da5c6beff859511f00729fb5e Mon Sep 17 00:00:00 2001 From: Nielsbishere Date: Fri, 26 Jul 2024 23:25:44 +0200 Subject: [PATCH 11/28] Formatting and PR feedback --- include/directx/d3d12shader.h | 95 +++++++++++++++++++---------------- 1 file changed, 51 insertions(+), 44 deletions(-) diff --git a/include/directx/d3d12shader.h b/include/directx/d3d12shader.h index 59516e8..f5d178f 100644 --- a/include/directx/d3d12shader.h +++ b/include/directx/d3d12shader.h @@ -159,27 +159,32 @@ typedef struct _D3D12_SHADER_DESC UINT cTextureStoreInstructions; // Number of texture writes } D3D12_SHADER_DESC; -typedef struct _D3D12_COMPUTE_SHADER_DESC { +typedef struct _D3D12_COMPUTE_SHADER_DESC +{ UINT WaveSizeMin; // SM 6.8+ WaveSize(n, ..., ...) min, max, pref UINT WaveSizeMax; // SM 6.8+ WaveSize(..., n, ...) min, max, pref UINT WaveSizePreferred; // SM 6.6 WaveSize(n) or WaveSize(.., ..., n) UINT NumThreads[3]; // numthreads(x, y, z) } D3D12_COMPUTE_SHADER_DESC; -typedef struct _D3D12_AMPLIFICATION_SHADER_DESC { +typedef struct _D3D12_AMPLIFICATION_SHADER_DESC +{ UINT PayloadSize; // Payload size in bytes } D3D12_AMPLIFICATION_SHADER_DESC; -typedef struct _D3D12_PIXEL_SHADER_DESC { +typedef struct _D3D12_PIXEL_SHADER_DESC +{ BOOL EarlyDepthStencil; // Early depth stencil } D3D12_PIXEL_SHADER_DESC; -typedef struct _D3D12_DOMAIN_SHADER_DESC { +typedef struct _D3D12_DOMAIN_SHADER_DESC +{ D3D12_TESSELLATOR_DOMAIN Domain; // Domain UINT InputControlPoints; // Input control points } D3D12_DOMAIN_SHADER_DESC; -typedef struct _D3D12_HULL_SHADER_DESC { +typedef struct _D3D12_HULL_SHADER_DESC +{ D3D12_TESSELLATOR_DOMAIN Domain; // Domain D3D12_TESSELLATOR_PARTITIONING Partition; // Partition D3D12_TESSELLATOR_OUTPUT_PRIMITIVE OutputPrimitive; // Output primitive @@ -192,19 +197,22 @@ typedef D3D_PRIMITIVE_TOPOLOGY D3D12_PRIMITIVE_TOPOLOGY; typedef D3D_PRIMITIVE D3D12_PRIMITIVE; -typedef struct _D3D12_GEOMETRY_SHADER_DESC { +typedef struct _D3D12_GEOMETRY_SHADER_DESC +{ D3D12_PRIMITIVE InputPrimitive; // Input primitive UINT MaxVertexCount; // Max vertex count UINT InstanceCount; // Instance count D3D12_PRIMITIVE_TOPOLOGY StreamPrimitiveTopologies[4]; // Stream primitive topologies } D3D12_GEOMETRY_SHADER_DESC; -typedef enum D3D12_MESH_OUTPUT_TOPOLOGY { +typedef enum D3D12_MESH_OUTPUT_TOPOLOGY +{ D3D12_MESH_OUTPUT_TOPOLOGY_LINE = 1, D3D12_MESH_OUTPUT_TOPOLOGY_TRIANGLE = 2 } D3D12_MESH_OUTPUT_TOPOLOGY; -typedef struct _D3D12_MESH_SHADER_DESC { +typedef struct _D3D12_MESH_SHADER_DESC +{ UINT PayloadSize; // Payload size in bytes UINT MaxVertexCount; // Max vertex count UINT MaxPrimitiveCount; // Max primitive count @@ -260,6 +268,7 @@ typedef struct _D3D12_SHADER_INPUT_BIND_DESC #define D3D_SHADER_REQUIRES_SAMPLE_CMP_GRADIENT_OR_BIAS 0x80000000 #define D3D_SHADER_REQUIRES_EXTENDED_COMMAND_INFO 0x100000000ull + typedef struct _D3D12_LIBRARY_DESC { LPCSTR Creator; // The name of the originator of the library. @@ -375,43 +384,41 @@ typedef struct _D3D12_RAYTRACING_SHADER_DESC typedef struct _D3D12_FUNCTION_DESC { - UINT Version; // Shader version - LPCSTR Creator; // Creator string - UINT Flags; // Shader compilation/parse flags - - UINT ConstantBuffers; // Number of constant buffers - UINT BoundResources; // Number of bound resources - - UINT InstructionCount; // Number of emitted instructions - UINT TempRegisterCount; // Number of temporary registers used - UINT TempArrayCount; // Number of temporary arrays used - UINT DefCount; // Number of constant defines - UINT DclCount; // Number of declarations (input + output) - UINT TextureNormalInstructions; // Number of non-categorized texture instructions - UINT TextureLoadInstructions; // Number of texture load instructions - UINT TextureCompInstructions; // Number of texture comparison instructions - UINT TextureBiasInstructions; // Number of texture bias instructions - UINT TextureGradientInstructions; // Number of texture gradient instructions - UINT FloatInstructionCount; // Number of floating point arithmetic instructions used - UINT IntInstructionCount; // Number of signed integer arithmetic instructions used - UINT UintInstructionCount; // Number of unsigned integer arithmetic instructions used - UINT StaticFlowControlCount; // Number of static flow control instructions used - UINT DynamicFlowControlCount; // Number of dynamic flow control instructions used - UINT MacroInstructionCount; // Number of macro instructions used - UINT ArrayInstructionCount; // Number of array instructions used - UINT MovInstructionCount; // Number of mov instructions used - UINT MovcInstructionCount; // Number of movc instructions used - UINT ConversionInstructionCount; // Number of type conversion instructions used - UINT BitwiseInstructionCount; // Number of bitwise arithmetic instructions used - D3D_FEATURE_LEVEL MinFeatureLevel; // Min target of the function byte code - UINT64 RequiredFeatureFlags; // Required feature flags - - LPCSTR Name; // Function name - INT FunctionParameterCount; // Number of logical parameters in the function signature (not including return) - BOOL HasReturn; // TRUE, if function returns a value, false - it is a subroutine - BOOL Has10Level9VertexShader; // TRUE, if there is a 10L9 VS blob - BOOL Has10Level9PixelShader; // TRUE, if there is a 10L9 PS blob + UINT Version; // Shader version + LPCSTR Creator; // Creator string + UINT Flags; // Shader compilation/parse flags + UINT ConstantBuffers; // Number of constant buffers + UINT BoundResources; // Number of bound resources + UINT InstructionCount; // Number of emitted instructions + UINT TempRegisterCount; // Number of temporary registers used + UINT TempArrayCount; // Number of temporary arrays used + UINT DefCount; // Number of constant defines + UINT DclCount; // Number of declarations (input + output) + UINT TextureNormalInstructions; // Number of non-categorized texture instructions + UINT TextureLoadInstructions; // Number of texture load instructions + UINT TextureCompInstructions; // Number of texture comparison instructions + UINT TextureBiasInstructions; // Number of texture bias instructions + UINT TextureGradientInstructions; // Number of texture gradient instructions + UINT FloatInstructionCount; // Number of floating point arithmetic instructions used + UINT IntInstructionCount; // Number of signed integer arithmetic instructions used + UINT UintInstructionCount; // Number of unsigned integer arithmetic instructions used + UINT StaticFlowControlCount; // Number of static flow control instructions used + UINT DynamicFlowControlCount; // Number of dynamic flow control instructions used + UINT MacroInstructionCount; // Number of macro instructions used + UINT ArrayInstructionCount; // Number of array instructions used + UINT MovInstructionCount; // Number of mov instructions used + UINT MovcInstructionCount; // Number of movc instructions used + UINT ConversionInstructionCount; // Number of type conversion instructions used + UINT BitwiseInstructionCount; // Number of bitwise arithmetic instructions used + D3D_FEATURE_LEVEL MinFeatureLevel; // Min target of the function byte code + UINT64 RequiredFeatureFlags; // Required feature flags + + LPCSTR Name; // Function name + INT FunctionParameterCount; // Number of logical parameters in the function signature (not including return) + BOOL HasReturn; // TRUE, if function returns a value, false - it is a subroutine + BOOL Has10Level9VertexShader; // TRUE, if there is a 10L9 VS blob + BOOL Has10Level9PixelShader; // TRUE, if there is a 10L9 PS blob } D3D12_FUNCTION_DESC; typedef struct _D3D12_FUNCTION_DESC1 // Only accessible via DXC From 951446fac3d6dae081081678516eca18af22f9c0 Mon Sep 17 00:00:00 2001 From: Nielsbishere Date: Fri, 26 Jul 2024 23:28:46 +0200 Subject: [PATCH 12/28] Some more minor formatting from PR feedback --- include/directx/d3d12shader.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/directx/d3d12shader.h b/include/directx/d3d12shader.h index f5d178f..f26f831 100644 --- a/include/directx/d3d12shader.h +++ b/include/directx/d3d12shader.h @@ -119,7 +119,7 @@ typedef struct _D3D12_SHADER_DESC UINT Version; // Shader version LPCSTR Creator; // Creator string UINT Flags; // Shader compilation/parse flags - + UINT ConstantBuffers; // Number of constant buffers UINT BoundResources; // Number of bound resources UINT InputParameters; // Number of parameters in the input signature @@ -387,9 +387,10 @@ typedef struct _D3D12_FUNCTION_DESC UINT Version; // Shader version LPCSTR Creator; // Creator string UINT Flags; // Shader compilation/parse flags - + UINT ConstantBuffers; // Number of constant buffers UINT BoundResources; // Number of bound resources + UINT InstructionCount; // Number of emitted instructions UINT TempRegisterCount; // Number of temporary registers used UINT TempArrayCount; // Number of temporary arrays used From b180ff840c2d2b7c3212e90a842c9551b1330d5e Mon Sep 17 00:00:00 2001 From: Nielsbishere Date: Fri, 26 Jul 2024 23:48:26 +0200 Subject: [PATCH 13/28] Renamed D3D12_NODE_OVERRIDES_TYPE to D3D12_NODE_LAUNCH_TYPE (PR feedback) --- include/directx/d3d12shader.h | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/include/directx/d3d12shader.h b/include/directx/d3d12shader.h index f26f831..f8393b3 100644 --- a/include/directx/d3d12shader.h +++ b/include/directx/d3d12shader.h @@ -276,14 +276,13 @@ typedef struct _D3D12_LIBRARY_DESC UINT FunctionCount; // Number of functions exported from the library. } D3D12_LIBRARY_DESC; -typedef enum D3D12_NODE_OVERRIDES_TYPE +typedef enum D3D12_NODE_LAUNCH_TYPE { - D3D12_NODE_OVERRIDES_TYPE_NONE = 0, - D3D12_NODE_OVERRIDES_TYPE_BROADCASTING_LAUNCH = 1, - D3D12_NODE_OVERRIDES_TYPE_COALESCING_LAUNCH = 2, - D3D12_NODE_OVERRIDES_TYPE_THREAD_LAUNCH = 3, - D3D12_NODE_OVERRIDES_TYPE_COMMON_COMPUTE = 4 -} D3D12_NODE_OVERRIDES_TYPE; + D3D12_NODE_LAUNCH_TYPE_NONE = 0, + D3D12_NODE_LAUNCH_TYPE_BROADCASTING_LAUNCH = 1, + D3D12_NODE_LAUNCH_TYPE_COALESCING_LAUNCH = 2, + D3D12_NODE_LAUNCH_TYPE_THREAD_LAUNCH = 3 +} D3D12_NODE_LAUNCH_TYPE; typedef struct _D3D12_NODE_ID_DESC { @@ -294,7 +293,7 @@ typedef struct _D3D12_NODE_ID_DESC typedef struct _D3D12_NODE_SHADER_DESC { D3D12_COMPUTE_SHADER_DESC ComputeDesc; // Node extends ComputeDesc - D3D12_NODE_OVERRIDES_TYPE LaunchType; // Launch type + D3D12_NODE_LAUNCH_TYPE LaunchType; // Launch type BOOL IsProgramEntry; // Is program entry INT LocalRootArgumentsTableIndex; // Local root arguments table index UINT DispatchGrid[3]; // Dispatch grid From aa7d10e967f14ef8641503a022f4608da2e5f5a5 Mon Sep 17 00:00:00 2001 From: Nielsbishere Date: Mon, 5 Aug 2024 19:24:48 +0200 Subject: [PATCH 14/28] Changed ID3D12ShaderReflection's IID as noted by the comment above ID3D12ShaderReflection. Added GetWaveSize to query wave size. --- include/directx/d3d12shader.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/include/directx/d3d12shader.h b/include/directx/d3d12shader.h index f8393b3..37fd8f6 100644 --- a/include/directx/d3d12shader.h +++ b/include/directx/d3d12shader.h @@ -556,10 +556,10 @@ DECLARE_INTERFACE(ID3D12ShaderReflectionConstantBuffer) // from working with an old binary. Recompiling with the new header // will pick up the new IID. -// {5A58797D-A72C-478D-8BA2-EFC6B0EFE88E} -interface DECLSPEC_UUID("5A58797D-A72C-478D-8BA2-EFC6B0EFE88E") ID3D12ShaderReflection; +// {9C886958-23F1-4126-B294-FCF3DA13E7C6} +interface DECLSPEC_UUID("9C886958-23F1-4126-B294-FCF3DA13E7C6") ID3D12ShaderReflection; DEFINE_GUID(IID_ID3D12ShaderReflection, -0x5a58797d, 0xa72c, 0x478d, 0x8b, 0xa2, 0xef, 0xc6, 0xb0, 0xef, 0xe8, 0x8e); +0x9c886958, 0x23f1, 0x4126, { 0xb2, 0x94, 0xfc, 0xf3, 0xda, 0x13, 0xe7, 0xc6); #undef INTERFACE #define INTERFACE ID3D12ShaderReflection @@ -608,6 +608,10 @@ DECLARE_INTERFACE_(ID3D12ShaderReflection, IUnknown) _Out_opt_ UINT* pSizeZ) PURE; STDMETHOD_(UINT64, GetRequiresFlags)(THIS) PURE; + + STDMETHOD_(BOOL, GetWaveSize) + (THIS_ _Out_opt_ UINT* pWavePreferred, _Out_opt_ UINT* pWaveSizeMin, + _Out_opt_ UINT* pWaveSizeMax) PURE; }; // {8E349D19-54DB-4A56-9DC9-119D87BDB804} From 80dfa9fd451138eb3ffdd540c3cbebd966c34034 Mon Sep 17 00:00:00 2001 From: Nielsbishere Date: Mon, 5 Aug 2024 20:24:36 +0200 Subject: [PATCH 15/28] Added ID3D12ShaderReflection1 to replace ID3D12ShaderReflection due to newly added GetWaveSize --- include/directx/d3d12shader.h | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/include/directx/d3d12shader.h b/include/directx/d3d12shader.h index 37fd8f6..ed09492 100644 --- a/include/directx/d3d12shader.h +++ b/include/directx/d3d12shader.h @@ -551,15 +551,10 @@ DECLARE_INTERFACE(ID3D12ShaderReflectionConstantBuffer) STDMETHOD_(ID3D12ShaderReflectionVariable*, GetVariableByName)(THIS_ _In_ LPCSTR Name) PURE; }; -// The ID3D12ShaderReflection IID may change from SDK version to SDK version -// if the reflection API changes. This prevents new code with the new API -// from working with an old binary. Recompiling with the new header -// will pick up the new IID. - -// {9C886958-23F1-4126-B294-FCF3DA13E7C6} -interface DECLSPEC_UUID("9C886958-23F1-4126-B294-FCF3DA13E7C6") ID3D12ShaderReflection; +// {5A58797D-A72C-478D-8BA2-EFC6B0EFE88E} +interface DECLSPEC_UUID("5A58797D-A72C-478D-8BA2-EFC6B0EFE88E") ID3D12ShaderReflection; DEFINE_GUID(IID_ID3D12ShaderReflection, -0x9c886958, 0x23f1, 0x4126, { 0xb2, 0x94, 0xfc, 0xf3, 0xda, 0x13, 0xe7, 0xc6); +0x5a58797d, 0xa72c, 0x478d, 0x8b, 0xa2, 0xef, 0xc6, 0xb0, 0xef, 0xe8, 0x8e); #undef INTERFACE #define INTERFACE ID3D12ShaderReflection @@ -608,7 +603,18 @@ DECLARE_INTERFACE_(ID3D12ShaderReflection, IUnknown) _Out_opt_ UINT* pSizeZ) PURE; STDMETHOD_(UINT64, GetRequiresFlags)(THIS) PURE; +}; + +// {9C886958-23F1-4126-B294-FCF3DA13E7C6} +interface DECLSPEC_UUID("9C886958-23F1-4126-B294-FCF3DA13E7C6") ID3D12ShaderReflection1; +DEFINE_GUID(IID_ID3D12ShaderReflection1, +0x9c886958, 0x23f1, 0x4126, { 0xb2, 0x94, 0xfc, 0xf3, 0xda, 0x13, 0xe7, 0xc6); +#undef INTERFACE +#define INTERFACE ID3D12ShaderReflection1 + +DECLARE_INTERFACE_(ID3D12ShaderReflection1, ID3D12ShaderReflection) +{ STDMETHOD_(BOOL, GetWaveSize) (THIS_ _Out_opt_ UINT* pWavePreferred, _Out_opt_ UINT* pWaveSizeMin, _Out_opt_ UINT* pWaveSizeMax) PURE; From 3a96f3456ef01d9a2c9f3cc1272e511045d3b7c2 Mon Sep 17 00:00:00 2001 From: Nielsbishere Date: Mon, 5 Aug 2024 21:30:48 +0200 Subject: [PATCH 16/28] Mesh and amplification shaders both have numthreads too. However waveSize is missing as there's still an issue pending for that. --- include/directx/d3d12shader.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/directx/d3d12shader.h b/include/directx/d3d12shader.h index ed09492..295e165 100644 --- a/include/directx/d3d12shader.h +++ b/include/directx/d3d12shader.h @@ -170,6 +170,7 @@ typedef struct _D3D12_COMPUTE_SHADER_DESC typedef struct _D3D12_AMPLIFICATION_SHADER_DESC { UINT PayloadSize; // Payload size in bytes + UINT NumThreads[3]; // numthreads(x, y, z) } D3D12_AMPLIFICATION_SHADER_DESC; typedef struct _D3D12_PIXEL_SHADER_DESC @@ -217,6 +218,7 @@ typedef struct _D3D12_MESH_SHADER_DESC UINT MaxVertexCount; // Max vertex count UINT MaxPrimitiveCount; // Max primitive count D3D12_MESH_OUTPUT_TOPOLOGY OutputTopology; // Output topology + UINT NumThreads[3]; // numthreads(x, y, z) } D3D12_MESH_SHADER_DESC; typedef struct _D3D12_SHADER_INPUT_BIND_DESC From fb6a5a3776872a6874e658c66fb38280db31a215 Mon Sep 17 00:00:00 2001 From: Nielsbishere Date: Mon, 5 Aug 2024 21:34:49 +0200 Subject: [PATCH 17/28] Formatting --- include/directx/d3d12shader.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/directx/d3d12shader.h b/include/directx/d3d12shader.h index 295e165..e0b6c52 100644 --- a/include/directx/d3d12shader.h +++ b/include/directx/d3d12shader.h @@ -170,7 +170,7 @@ typedef struct _D3D12_COMPUTE_SHADER_DESC typedef struct _D3D12_AMPLIFICATION_SHADER_DESC { UINT PayloadSize; // Payload size in bytes - UINT NumThreads[3]; // numthreads(x, y, z) + UINT NumThreads[3]; // numthreads(x, y, z) } D3D12_AMPLIFICATION_SHADER_DESC; typedef struct _D3D12_PIXEL_SHADER_DESC @@ -218,7 +218,7 @@ typedef struct _D3D12_MESH_SHADER_DESC UINT MaxVertexCount; // Max vertex count UINT MaxPrimitiveCount; // Max primitive count D3D12_MESH_OUTPUT_TOPOLOGY OutputTopology; // Output topology - UINT NumThreads[3]; // numthreads(x, y, z) + UINT NumThreads[3]; // numthreads(x, y, z) } D3D12_MESH_SHADER_DESC; typedef struct _D3D12_SHADER_INPUT_BIND_DESC From 16a4ece497644fd3ede9aab0d732d5243f397c33 Mon Sep 17 00:00:00 2001 From: Nielsbishere Date: Wed, 7 Aug 2024 19:59:33 +0200 Subject: [PATCH 18/28] Missing interface predeclaration --- include/directx/d3d12shader.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/directx/d3d12shader.h b/include/directx/d3d12shader.h index e0b6c52..cf4f6e4 100644 --- a/include/directx/d3d12shader.h +++ b/include/directx/d3d12shader.h @@ -478,6 +478,9 @@ typedef interface ID3D12ShaderReflectionConstantBuffer *LPD3D12SHADERREFLECTIONC typedef interface ID3D12ShaderReflection ID3D12ShaderReflection; typedef interface ID3D12ShaderReflection *LPD3D12SHADERREFLECTION; +typedef interface ID3D12ShaderReflection1 ID3D12ShaderReflection1; +typedef interface ID3D12ShaderReflection1 *LPD3D12SHADERREFLECTION1; + typedef interface ID3D12LibraryReflection ID3D12LibraryReflection; typedef interface ID3D12LibraryReflection *LPD3D12LIBRARYREFLECTION; From c9c764639a388c3cb61976c2966f93f926a71fe7 Mon Sep 17 00:00:00 2001 From: Nielsbishere Date: Wed, 7 Aug 2024 22:26:01 +0200 Subject: [PATCH 19/28] Fixed compile issue with ID3D12ShaderReflection1. Important notes: DXC uses the assumption that bool* == LPBOOL, which isn't possible if BOOL is uint32_t, this needs some further attention to see if this is OK or has side effects, but DXC and DirectX12-Headers definitely don't agree on the size of a bool... Checking the define for LLVM_SUPPORT_WIN_ADAPTER_H is used to avoid duplicate defines and structs/typedefs, this is required on Linux since basestd.h from d3dcommon.h has its own definitions that are definitely different than from DXC. Made InlineIsEqualGUID equal to the implementation in DXC, since that one doesn't spam warnings. --- include/directx/d3d12shader.h | 2 +- include/wsl/stubs/basetsd.h | 70 ++++++++++++++++++++++++++--------- include/wsl/stubs/rpcndr.h | 2 + 3 files changed, 55 insertions(+), 19 deletions(-) diff --git a/include/directx/d3d12shader.h b/include/directx/d3d12shader.h index cf4f6e4..4c8d34f 100644 --- a/include/directx/d3d12shader.h +++ b/include/directx/d3d12shader.h @@ -613,7 +613,7 @@ DECLARE_INTERFACE_(ID3D12ShaderReflection, IUnknown) // {9C886958-23F1-4126-B294-FCF3DA13E7C6} interface DECLSPEC_UUID("9C886958-23F1-4126-B294-FCF3DA13E7C6") ID3D12ShaderReflection1; DEFINE_GUID(IID_ID3D12ShaderReflection1, -0x9c886958, 0x23f1, 0x4126, { 0xb2, 0x94, 0xfc, 0xf3, 0xda, 0x13, 0xe7, 0xc6); +0x9c886958, 0x23f1, 0x4126, 0xb2, 0x94, 0xfc, 0xf3, 0xda, 0x13, 0xe7, 0xc6); #undef INTERFACE #define INTERFACE ID3D12ShaderReflection1 diff --git a/include/wsl/stubs/basetsd.h b/include/wsl/stubs/basetsd.h index b1e57f4..075b6ba 100644 --- a/include/wsl/stubs/basetsd.h +++ b/include/wsl/stubs/basetsd.h @@ -20,7 +20,7 @@ typedef uint8_t UINT8; typedef int8_t INT8; typedef uint16_t UINT16; typedef int16_t INT16; -typedef uint32_t UINT32, UINT, ULONG, DWORD, BOOL, WINBOOL; +typedef uint32_t UINT32, UINT, ULONG, DWORD, WINBOOL; typedef int32_t INT32, INT, LONG; typedef uint64_t UINT64, ULONG_PTR; typedef int64_t INT64, LONG_PTR; @@ -48,6 +48,8 @@ typedef uint64_t ULONG_PTR, *PULONG_PTR; typedef uint64_t UINT_PTR, *PUINT_PTR; typedef int64_t INT_PTR, *PINT_PTR; +typedef bool BOOL; + // Note: WCHAR is not the same between Windows and Linux, to enable // string manipulation APIs to work with resulting strings. // APIs to D3D/DXCore will work on Linux wchars, but beware with @@ -63,26 +65,31 @@ typedef const wchar_t *LPCWSTR, *PCWSTR; #define ULONG_MAX UINT_MAX // Misc defines + +#ifndef LLVM_SUPPORT_WIN_ADAPTER_H #define MIDL_INTERFACE(x) interface -#define __analysis_assume(x) #define TRUE 1u #define FALSE 0u #define DECLSPEC_UUID(x) -#define DECLSPEC_NOVTABLE #define DECLSPEC_SELECTANY #ifdef __cplusplus #define EXTERN_C extern "C" #else #define EXTERN_C extern #endif +#define C_ASSERT(expr) static_assert((expr)) +#define _countof(a) (sizeof(a) / sizeof(*(a))) +#endif + +#define __analysis_assume(x) +#define DECLSPEC_NOVTABLE + #define APIENTRY #define OUT #define IN #define CONST const #define MAX_PATH 260 #define GENERIC_ALL 0x10000000L -#define C_ASSERT(expr) static_assert((expr)) -#define _countof(a) (sizeof(a) / sizeof(*(a))) typedef struct tagRECTL { @@ -98,6 +105,7 @@ typedef struct tagPOINT int y; } POINT; +#ifndef LLVM_SUPPORT_WIN_ADAPTER_H typedef struct _GUID { uint32_t Data1; uint16_t Data2; @@ -114,6 +122,7 @@ typedef struct _GUID { #else #define DEFINE_GUID(name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) EXTERN_C const GUID name #endif +#endif typedef GUID IID; typedef GUID UUID; @@ -123,13 +132,15 @@ typedef GUID CLSID; #define REFIID const IID & #define REFCLSID const IID & +#ifndef LLVM_SUPPORT_WIN_ADAPTER_H + __inline int InlineIsEqualGUID(REFGUID rguid1, REFGUID rguid2) { - return ( - ((uint32_t *)&rguid1)[0] == ((uint32_t *)&rguid2)[0] && - ((uint32_t *)&rguid1)[1] == ((uint32_t *)&rguid2)[1] && - ((uint32_t *)&rguid1)[2] == ((uint32_t *)&rguid2)[2] && - ((uint32_t *)&rguid1)[3] == ((uint32_t *)&rguid2)[3]); + // Optimization: + if (&rguid1 == &rguid2) + return true; + + return !memcmp(&rguid1, &rguid2, sizeof(GUID)); } inline bool operator==(REFGUID guidOne, REFGUID guidOther) @@ -142,6 +153,8 @@ inline bool operator!=(REFGUID guidOne, REFGUID guidOther) return !(guidOne == guidOther); } +#endif + #else #define REFGUID const GUID * #define REFIID const IID * @@ -149,25 +162,31 @@ inline bool operator!=(REFGUID guidOne, REFGUID guidOther) #endif // SAL annotations + +#ifndef LLVM_SUPPORT_WIN_ADAPTER_H #define _In_ #define _In_z_ #define _In_opt_ #define _In_opt_z_ -#define _In_reads_(x) -#define _In_reads_opt_(x) -#define _In_reads_bytes_(x) -#define _In_reads_bytes_opt_(x) -#define _In_range_(x, y) #define _In_bytecount_(x) #define _Out_ #define _Out_opt_ #define _Outptr_ #define _Outptr_opt_result_z_ -#define _Outptr_opt_result_bytebuffer_(x) #define _COM_Outptr_ #define _COM_Outptr_result_maybenull_ #define _COM_Outptr_opt_ #define _COM_Outptr_opt_result_maybenull_ +#define _In_count_(x) +#define _In_opt_count_(x) +#endif + +#define _In_reads_(x) +#define _In_reads_opt_(x) +#define _In_reads_bytes_(x) +#define _In_reads_bytes_opt_(x) +#define _In_range_(x, y) +#define _Outptr_opt_result_bytebuffer_(x) #define _Out_writes_(x) #define _Out_writes_z_(x) #define _Out_writes_opt_(x) @@ -205,8 +224,6 @@ inline bool operator!=(REFGUID guidOne, REFGUID guidOther) #define _Outptr_result_nullonfailure_ #define _Analysis_assume_(x) #define _Success_(x) -#define _In_count_(x) -#define _In_opt_count_(x) #define _Use_decl_annotations_ #define _Null_terminated_ @@ -218,6 +235,7 @@ inline bool operator!=(REFGUID guidOne, REFGUID guidOther) #define STDAPI EXTERN_C HRESULT STDAPICALLTYPE #define WINAPI +#ifndef LLVM_SUPPORT_WIN_ADAPTER_H #define interface struct #if defined (__cplusplus) && !defined (CINTERFACE) #define STDMETHOD(method) virtual HRESULT STDMETHODCALLTYPE method @@ -251,6 +269,7 @@ extern "C++" #endif #define DECLARE_INTERFACE_(iface, baseiface) DECLARE_INTERFACE (iface) #endif +#endif #define IFACEMETHOD(method) /*override*/ STDMETHOD (method) #define IFACEMETHOD_(type, method) /*override*/ STDMETHOD_(type, method) @@ -261,6 +280,8 @@ extern "C++" // Error codes typedef LONG HRESULT; + +#ifndef LLVM_SUPPORT_WIN_ADAPTER_H #define SUCCEEDED(hr) (((HRESULT)(hr)) >= 0) #define FAILED(hr) (((HRESULT)(hr)) < 0) #define S_OK ((HRESULT)0L) @@ -275,6 +296,8 @@ typedef LONG HRESULT; #define E_FAIL ((HRESULT)0x80004005L) #define E_ACCESSDENIED ((HRESULT)0x80070005L) #define E_UNEXPECTED ((HRESULT)0x8000FFFFL) +#endif + #define DXGI_ERROR_INVALID_CALL ((HRESULT)0x887A0001L) #define DXGI_ERROR_NOT_FOUND ((HRESULT)0x887A0002L) #define DXGI_ERROR_MORE_DATA ((HRESULT)0x887A0003L) @@ -299,6 +322,8 @@ typedef struct _RECT int bottom; } RECT; +#ifndef LLVM_SUPPORT_WIN_ADAPTER_H + typedef union _LARGE_INTEGER { struct { uint32_t LowPart; @@ -317,18 +342,23 @@ typedef union _ULARGE_INTEGER { } ULARGE_INTEGER; typedef ULARGE_INTEGER *PULARGE_INTEGER; + #define DECLARE_HANDLE(name) \ struct name##__ { \ int unused; \ }; \ typedef struct name##__ *name +#endif + typedef struct _SECURITY_ATTRIBUTES { DWORD nLength; LPVOID lpSecurityDescriptor; WINBOOL bInheritHandle; } SECURITY_ATTRIBUTES; +#ifndef LLVM_SUPPORT_WIN_ADAPTER_H + struct STATSTG; #ifdef __cplusplus @@ -385,12 +415,15 @@ inline ENUMTYPE &operator ^= (ENUMTYPE &a, ENUMTYPE b) { return (ENUMTYPE &)(((_ #else #define DEFINE_ENUM_FLAG_OPERATORS(ENUMTYPE) /* */ #endif +#endif // D3DX12 uses these #include #define HeapAlloc(heap, flags, size) malloc(size) #define HeapFree(heap, flags, ptr) free(ptr) + +#ifndef LLVM_SUPPORT_WIN_ADAPTER_H #if defined(lint) // Note: lint -e530 says don't complain about uninitialized variables for // this variable. Error 527 has to do with unreachable code. @@ -404,3 +437,4 @@ inline ENUMTYPE &operator ^= (ENUMTYPE &a, ENUMTYPE b) { return (ENUMTYPE &)(((_ #else #define UNREFERENCED_PARAMETER(P) (P) #endif +#endif diff --git a/include/wsl/stubs/rpcndr.h b/include/wsl/stubs/rpcndr.h index 68aa390..1f5c476 100644 --- a/include/wsl/stubs/rpcndr.h +++ b/include/wsl/stubs/rpcndr.h @@ -72,7 +72,9 @@ extern "C++" { } \ } #endif +#ifndef LLVM_SUPPORT_WIN_ADAPTER_H #define __uuidof(type) __wsl_stub_uuidof<__typeof(type)>() +#endif #else #define __CRT_UUID_DECL(type, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) #endif From e8e8634297bbe7ad09f6f10a1abdd864fbc83f99 Mon Sep 17 00:00:00 2001 From: Nielsbishere Date: Thu, 8 Aug 2024 00:41:33 +0200 Subject: [PATCH 20/28] HeapAlloc and HeapFree are duplicate defined in DXC --- include/wsl/stubs/basetsd.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/wsl/stubs/basetsd.h b/include/wsl/stubs/basetsd.h index 075b6ba..b8f8179 100644 --- a/include/wsl/stubs/basetsd.h +++ b/include/wsl/stubs/basetsd.h @@ -418,9 +418,11 @@ inline ENUMTYPE &operator ^= (ENUMTYPE &a, ENUMTYPE b) { return (ENUMTYPE &)(((_ #endif // D3DX12 uses these +#ifndef LLVM_SUPPORT_WINFUNCTIONS_H #include #define HeapAlloc(heap, flags, size) malloc(size) #define HeapFree(heap, flags, ptr) free(ptr) +#endif #ifndef LLVM_SUPPORT_WIN_ADAPTER_H From ba694809a1dca35de492b8f6b657397595e57e0a Mon Sep 17 00:00:00 2001 From: Nielsbishere Date: Thu, 8 Aug 2024 19:56:19 +0200 Subject: [PATCH 21/28] HeapAlloc and HeapFree is now only enabled in WinAdapter.h if DXC WinAdapter.h doesn't override it. --- include/wsl/stubs/basetsd.h | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/include/wsl/stubs/basetsd.h b/include/wsl/stubs/basetsd.h index b8f8179..24b3cd5 100644 --- a/include/wsl/stubs/basetsd.h +++ b/include/wsl/stubs/basetsd.h @@ -322,6 +322,12 @@ typedef struct _RECT int bottom; } RECT; +typedef struct _SECURITY_ATTRIBUTES { + DWORD nLength; + LPVOID lpSecurityDescriptor; + WINBOOL bInheritHandle; +} SECURITY_ATTRIBUTES; + #ifndef LLVM_SUPPORT_WIN_ADAPTER_H typedef union _LARGE_INTEGER { @@ -349,16 +355,6 @@ typedef ULARGE_INTEGER *PULARGE_INTEGER; }; \ typedef struct name##__ *name -#endif - -typedef struct _SECURITY_ATTRIBUTES { - DWORD nLength; - LPVOID lpSecurityDescriptor; - WINBOOL bInheritHandle; -} SECURITY_ATTRIBUTES; - -#ifndef LLVM_SUPPORT_WIN_ADAPTER_H - struct STATSTG; #ifdef __cplusplus @@ -415,17 +411,12 @@ inline ENUMTYPE &operator ^= (ENUMTYPE &a, ENUMTYPE b) { return (ENUMTYPE &)(((_ #else #define DEFINE_ENUM_FLAG_OPERATORS(ENUMTYPE) /* */ #endif -#endif // D3DX12 uses these -#ifndef LLVM_SUPPORT_WINFUNCTIONS_H #include #define HeapAlloc(heap, flags, size) malloc(size) #define HeapFree(heap, flags, ptr) free(ptr) -#endif - -#ifndef LLVM_SUPPORT_WIN_ADAPTER_H #if defined(lint) // Note: lint -e530 says don't complain about uninitialized variables for // this variable. Error 527 has to do with unreachable code. From 8cd1ddf8edecc3410df223104f936f6a3badf3e6 Mon Sep 17 00:00:00 2001 From: Nielsbishere Date: Fri, 9 Aug 2024 20:23:33 +0200 Subject: [PATCH 22/28] DXC compatibility update to allow it to update DXC-Headers since it's 2 years behind. Removed IN/OUT and interface since they interfere with lots of files. Made REFGUID/REFCLSID/REFIID typedefs, since these defines interfere with everything too. Turned IsEqualGUID into dxc's version, to avoid lots of warnings. --- include/wsl/stubs/basetsd.h | 67 +++++++++++++++------------------- include/wsl/stubs/unknwnbase.h | 4 +- 2 files changed, 32 insertions(+), 39 deletions(-) diff --git a/include/wsl/stubs/basetsd.h b/include/wsl/stubs/basetsd.h index b1e57f4..55d5d31 100644 --- a/include/wsl/stubs/basetsd.h +++ b/include/wsl/stubs/basetsd.h @@ -57,13 +57,15 @@ typedef const char *LPCSTR, *PCSTR, *LPCTSTR, *PCTSTR; typedef wchar_t WCHAR, *PWSTR, *LPWSTR, *PWCHAR; typedef const wchar_t *LPCWSTR, *PCWSTR; +typedef signed int HRESULT; + #undef LONG_MAX #define LONG_MAX INT_MAX #undef ULONG_MAX #define ULONG_MAX UINT_MAX // Misc defines -#define MIDL_INTERFACE(x) interface +#define MIDL_INTERFACE(x) struct #define __analysis_assume(x) #define TRUE 1u #define FALSE 0u @@ -76,8 +78,6 @@ typedef const wchar_t *LPCWSTR, *PCWSTR; #define EXTERN_C extern #endif #define APIENTRY -#define OUT -#define IN #define CONST const #define MAX_PATH 260 #define GENERIC_ALL 0x10000000L @@ -107,34 +107,36 @@ typedef struct _GUID { #ifdef INITGUID #ifdef __cplusplus -#define DEFINE_GUID(name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) EXTERN_C const GUID DECLSPEC_SELECTANY name = { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } } +#define DEFINE_GUID(IID_name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) EXTERN_C const GUID DECLSPEC_SELECTANY name = { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } } #else -#define DEFINE_GUID(name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) const GUID DECLSPEC_SELECTANY name = { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } } +#define DEFINE_GUID(IID_name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) const GUID DECLSPEC_SELECTANY name = { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } } #endif #else -#define DEFINE_GUID(name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) EXTERN_C const GUID name +#define DEFINE_GUID(IID_name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) EXTERN_C const GUID name #endif typedef GUID IID; typedef GUID UUID; typedef GUID CLSID; + #ifdef __cplusplus -#define REFGUID const GUID & -#define REFIID const IID & -#define REFCLSID const IID & -__inline int InlineIsEqualGUID(REFGUID rguid1, REFGUID rguid2) +typedef const GUID &REFGUID; +typedef const GUID &REFCLSID; +typedef const IID &REFIID; + +__inline int IsEqualGUID(REFGUID rguid1, REFGUID rguid2) { - return ( - ((uint32_t *)&rguid1)[0] == ((uint32_t *)&rguid2)[0] && - ((uint32_t *)&rguid1)[1] == ((uint32_t *)&rguid2)[1] && - ((uint32_t *)&rguid1)[2] == ((uint32_t *)&rguid2)[2] && - ((uint32_t *)&rguid1)[3] == ((uint32_t *)&rguid2)[3]); + // Optimization: + if (&rguid1 == &rguid2) + return true; + + return !memcmp(&rguid1, &rguid2, sizeof(GUID)); } inline bool operator==(REFGUID guidOne, REFGUID guidOther) { - return !!InlineIsEqualGUID(guidOne, guidOther); + return !!IsEqualGUID(guidOne, guidOther); } inline bool operator!=(REFGUID guidOne, REFGUID guidOther) @@ -218,17 +220,17 @@ inline bool operator!=(REFGUID guidOne, REFGUID guidOther) #define STDAPI EXTERN_C HRESULT STDAPICALLTYPE #define WINAPI -#define interface struct #if defined (__cplusplus) && !defined (CINTERFACE) #define STDMETHOD(method) virtual HRESULT STDMETHODCALLTYPE method #define STDMETHOD_(type, method) virtual type STDMETHODCALLTYPE method #define PURE = 0 #define THIS_ #define THIS void -#define DECLARE_INTERFACE(iface) interface DECLSPEC_NOVTABLE iface -#define DECLARE_INTERFACE_(iface, baseiface) interface DECLSPEC_NOVTABLE iface : public baseiface +#define DECLARE_INTERFACE(iface) struct DECLSPEC_NOVTABLE iface +#define DECLARE_INTERFACE_(iface, baseiface) struct DECLSPEC_NOVTABLE iface : public baseiface + +struct IUnknown; -interface IUnknown; extern "C++" { template void** IID_PPV_ARGS_Helper(T** pp) @@ -245,9 +247,9 @@ extern "C++" #define THIS_ INTERFACE *This, #define THIS INTERFACE *This #ifdef CONST_VTABLE -#define DECLARE_INTERFACE(iface) typedef interface iface { const struct iface##Vtbl *lpVtbl; } iface; typedef const struct iface##Vtbl iface##Vtbl; const struct iface##Vtbl +#define DECLARE_INTERFACE(iface) typedef struct iface { const struct iface##Vtbl *lpVtbl; } iface; typedef const struct iface##Vtbl iface##Vtbl; const struct iface##Vtbl #else -#define DECLARE_INTERFACE(iface) typedef interface iface { struct iface##Vtbl *lpVtbl; } iface; typedef struct iface##Vtbl iface##Vtbl; struct iface##Vtbl +#define DECLARE_INTERFACE(iface) typedef struct iface { struct iface##Vtbl *lpVtbl; } iface; typedef struct iface##Vtbl iface##Vtbl; struct iface##Vtbl #endif #define DECLARE_INTERFACE_(iface, baseiface) DECLARE_INTERFACE (iface) #endif @@ -260,7 +262,6 @@ extern "C++" #endif // Error codes -typedef LONG HRESULT; #define SUCCEEDED(hr) (((HRESULT)(hr)) >= 0) #define FAILED(hr) (((HRESULT)(hr)) < 0) #define S_OK ((HRESULT)0L) @@ -329,7 +330,7 @@ typedef struct _SECURITY_ATTRIBUTES { WINBOOL bInheritHandle; } SECURITY_ATTRIBUTES; -struct STATSTG; +typedef struct tagSTATSTG STATSTG; #ifdef __cplusplus // ENUM_FLAG_OPERATORS @@ -387,20 +388,12 @@ inline ENUMTYPE &operator ^= (ENUMTYPE &a, ENUMTYPE b) { return (ENUMTYPE &)(((_ #endif // D3DX12 uses these + +#ifndef LLVM_SUPPORT_WIN_ADAPTER_H #include #define HeapAlloc(heap, flags, size) malloc(size) #define HeapFree(heap, flags, ptr) free(ptr) - -#if defined(lint) -// Note: lint -e530 says don't complain about uninitialized variables for -// this variable. Error 527 has to do with unreachable code. -// -restore restores checking to the -save state -#define UNREFERENCED_PARAMETER(P) \ - /*lint -save -e527 -e530 */ \ - { \ - (P) = (P); \ - } \ - /*lint -restore */ -#else -#define UNREFERENCED_PARAMETER(P) (P) #endif + + +#define UNREFERENCED_PARAMETER(P) (void)(P) diff --git a/include/wsl/stubs/unknwnbase.h b/include/wsl/stubs/unknwnbase.h index 5c546f2..1c86fcf 100644 --- a/include/wsl/stubs/unknwnbase.h +++ b/include/wsl/stubs/unknwnbase.h @@ -42,7 +42,7 @@ #ifndef __IUnknown_FWD_DEFINED__ #define __IUnknown_FWD_DEFINED__ -typedef interface IUnknown IUnknown; +typedef struct IUnknown IUnknown; #endif /* __IUnknown_FWD_DEFINED__ */ @@ -104,7 +104,7 @@ typedef struct IUnknownVtbl { END_INTERFACE } IUnknownVtbl; -interface IUnknown { +struct IUnknown { CONST_VTBL IUnknownVtbl* lpVtbl; }; From bd5368b966c41efe6406b22b01a8cab11c24d3b2 Mon Sep 17 00:00:00 2001 From: Nielsbishere Date: Fri, 9 Aug 2024 22:52:02 +0200 Subject: [PATCH 23/28] rpc.h doesn't end with endline, which some compilers don't seem to like --- include/wsl/stubs/rpc.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/wsl/stubs/rpc.h b/include/wsl/stubs/rpc.h index 76f5b5f..a124495 100644 --- a/include/wsl/stubs/rpc.h +++ b/include/wsl/stubs/rpc.h @@ -2,4 +2,4 @@ // Licensed under the MIT License. // Stub header to satisfy d3d12.h include -#pragma once \ No newline at end of file +#pragma once From 353d37a09512cc737c9c08d3dfda8a0e632d0bcd Mon Sep 17 00:00:00 2001 From: Nielsbishere Date: Wed, 21 Aug 2024 11:29:04 +0200 Subject: [PATCH 24/28] Fixed a DEFINE_GUID problem, maybe a botched merge? --- include/wsl/stubs/basetsd.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/wsl/stubs/basetsd.h b/include/wsl/stubs/basetsd.h index d76dfe8..91c44f5 100644 --- a/include/wsl/stubs/basetsd.h +++ b/include/wsl/stubs/basetsd.h @@ -114,12 +114,12 @@ typedef struct _GUID { #ifdef INITGUID #ifdef __cplusplus -#define DEFINE_GUID(IID_name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) EXTERN_C const GUID DECLSPEC_SELECTANY name = { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } } +#define DEFINE_GUID(name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) EXTERN_C const GUID DECLSPEC_SELECTANY name = { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } } #else -#define DEFINE_GUID(IID_name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) const GUID DECLSPEC_SELECTANY name = { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } } +#define DEFINE_GUID(name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) const GUID DECLSPEC_SELECTANY name = { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } } #endif #else -#define DEFINE_GUID(IID_name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) EXTERN_C const GUID name +#define DEFINE_GUID(name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) EXTERN_C const GUID name #endif #endif From 6a21463c59c2170dfa3195c92a1f19d8f268a4b9 Mon Sep 17 00:00:00 2001 From: Nielsbishere Date: Wed, 21 Aug 2024 12:05:58 +0200 Subject: [PATCH 25/28] Some wonky merges left lots of problems that are now fixed --- include/wsl/stubs/basetsd.h | 50 +++++++++---------------------------- include/wsl/stubs/rpcndr.h | 2 -- 2 files changed, 12 insertions(+), 40 deletions(-) diff --git a/include/wsl/stubs/basetsd.h b/include/wsl/stubs/basetsd.h index 91c44f5..73cf43a 100644 --- a/include/wsl/stubs/basetsd.h +++ b/include/wsl/stubs/basetsd.h @@ -20,7 +20,7 @@ typedef uint8_t UINT8; typedef int8_t INT8; typedef uint16_t UINT16; typedef int16_t INT16; -typedef uint32_t UINT32, UINT, ULONG, DWORD, WINBOOL; +typedef uint32_t UINT32, UINT, ULONG, DWORD, BOOL, WINBOOL; typedef int32_t INT32, INT, LONG; typedef uint64_t UINT64, ULONG_PTR; typedef int64_t INT64, LONG_PTR; @@ -48,8 +48,6 @@ typedef uint64_t ULONG_PTR, *PULONG_PTR; typedef uint64_t UINT_PTR, *PUINT_PTR; typedef int64_t INT_PTR, *PINT_PTR; -typedef bool BOOL; - // Note: WCHAR is not the same between Windows and Linux, to enable // string manipulation APIs to work with resulting strings. // APIs to D3D/DXCore will work on Linux wchars, but beware with @@ -72,23 +70,19 @@ typedef signed int HRESULT; #define TRUE 1u #define FALSE 0u #define DECLSPEC_UUID(x) +#define DECLSPEC_NOVTABLE #define DECLSPEC_SELECTANY #ifdef __cplusplus #define EXTERN_C extern "C" #else #define EXTERN_C extern #endif -#define C_ASSERT(expr) static_assert((expr)) -#define _countof(a) (sizeof(a) / sizeof(*(a))) -#endif - -#define __analysis_assume(x) -#define DECLSPEC_NOVTABLE - #define APIENTRY #define CONST const #define MAX_PATH 260 #define GENERIC_ALL 0x10000000L +#define C_ASSERT(expr) static_assert((expr)) +#define _countof(a) (sizeof(a) / sizeof(*(a))) typedef struct tagRECTL { @@ -104,7 +98,6 @@ typedef struct tagPOINT int y; } POINT; -#ifndef LLVM_SUPPORT_WIN_ADAPTER_H typedef struct _GUID { uint32_t Data1; uint16_t Data2; @@ -121,7 +114,6 @@ typedef struct _GUID { #else #define DEFINE_GUID(name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) EXTERN_C const GUID name #endif -#endif typedef GUID IID; typedef GUID UUID; @@ -152,8 +144,6 @@ inline bool operator!=(REFGUID guidOne, REFGUID guidOther) return !(guidOne == guidOther); } -#endif - #else #define REFGUID const GUID * #define REFIID const IID * @@ -161,31 +151,25 @@ inline bool operator!=(REFGUID guidOne, REFGUID guidOther) #endif // SAL annotations - -#ifndef LLVM_SUPPORT_WIN_ADAPTER_H #define _In_ #define _In_z_ #define _In_opt_ #define _In_opt_z_ +#define _In_reads_(x) +#define _In_reads_opt_(x) +#define _In_reads_bytes_(x) +#define _In_reads_bytes_opt_(x) +#define _In_range_(x, y) #define _In_bytecount_(x) #define _Out_ #define _Out_opt_ #define _Outptr_ #define _Outptr_opt_result_z_ +#define _Outptr_opt_result_bytebuffer_(x) #define _COM_Outptr_ #define _COM_Outptr_result_maybenull_ #define _COM_Outptr_opt_ #define _COM_Outptr_opt_result_maybenull_ -#define _In_count_(x) -#define _In_opt_count_(x) -#endif - -#define _In_reads_(x) -#define _In_reads_opt_(x) -#define _In_reads_bytes_(x) -#define _In_reads_bytes_opt_(x) -#define _In_range_(x, y) -#define _Outptr_opt_result_bytebuffer_(x) #define _Out_writes_(x) #define _Out_writes_z_(x) #define _Out_writes_opt_(x) @@ -223,6 +207,8 @@ inline bool operator!=(REFGUID guidOne, REFGUID guidOther) #define _Outptr_result_nullonfailure_ #define _Analysis_assume_(x) #define _Success_(x) +#define _In_count_(x) +#define _In_opt_count_(x) #define _Use_decl_annotations_ #define _Null_terminated_ @@ -267,7 +253,6 @@ extern "C++" #endif #define DECLARE_INTERFACE_(iface, baseiface) DECLARE_INTERFACE (iface) #endif -#endif #define IFACEMETHOD(method) /*override*/ STDMETHOD (method) #define IFACEMETHOD_(type, method) /*override*/ STDMETHOD_(type, method) @@ -291,8 +276,6 @@ extern "C++" #define E_FAIL ((HRESULT)0x80004005L) #define E_ACCESSDENIED ((HRESULT)0x80070005L) #define E_UNEXPECTED ((HRESULT)0x8000FFFFL) -#endif - #define DXGI_ERROR_INVALID_CALL ((HRESULT)0x887A0001L) #define DXGI_ERROR_NOT_FOUND ((HRESULT)0x887A0002L) #define DXGI_ERROR_MORE_DATA ((HRESULT)0x887A0003L) @@ -317,14 +300,6 @@ typedef struct _RECT int bottom; } RECT; -typedef struct _SECURITY_ATTRIBUTES { - DWORD nLength; - LPVOID lpSecurityDescriptor; - WINBOOL bInheritHandle; -} SECURITY_ATTRIBUTES; - -#ifndef LLVM_SUPPORT_WIN_ADAPTER_H - typedef union _LARGE_INTEGER { struct { uint32_t LowPart; @@ -343,7 +318,6 @@ typedef union _ULARGE_INTEGER { } ULARGE_INTEGER; typedef ULARGE_INTEGER *PULARGE_INTEGER; - #define DECLARE_HANDLE(name) \ struct name##__ { \ int unused; \ diff --git a/include/wsl/stubs/rpcndr.h b/include/wsl/stubs/rpcndr.h index 1f5c476..68aa390 100644 --- a/include/wsl/stubs/rpcndr.h +++ b/include/wsl/stubs/rpcndr.h @@ -72,9 +72,7 @@ extern "C++" { } \ } #endif -#ifndef LLVM_SUPPORT_WIN_ADAPTER_H #define __uuidof(type) __wsl_stub_uuidof<__typeof(type)>() -#endif #else #define __CRT_UUID_DECL(type, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) #endif From dc27951f840703d8edfe6e2907bfff6410fe68eb Mon Sep 17 00:00:00 2001 From: Nielsbishere Date: Wed, 21 Aug 2024 13:32:21 +0200 Subject: [PATCH 26/28] Undid removal of #define interface, since there's definitely other stuff that relies on that --- include/wsl/stubs/basetsd.h | 13 +++++++------ include/wsl/stubs/unknwnbase.h | 4 ++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/include/wsl/stubs/basetsd.h b/include/wsl/stubs/basetsd.h index 73cf43a..5d68389 100644 --- a/include/wsl/stubs/basetsd.h +++ b/include/wsl/stubs/basetsd.h @@ -63,9 +63,10 @@ typedef signed int HRESULT; #define LONG_MAX INT_MAX #undef ULONG_MAX #define ULONG_MAX UINT_MAX +#define interface struct // Misc defines -#define MIDL_INTERFACE(x) struct +#define MIDL_INTERFACE(x) interface #define __analysis_assume(x) #define TRUE 1u #define FALSE 0u @@ -226,10 +227,10 @@ inline bool operator!=(REFGUID guidOne, REFGUID guidOther) #define PURE = 0 #define THIS_ #define THIS void -#define DECLARE_INTERFACE(iface) struct DECLSPEC_NOVTABLE iface -#define DECLARE_INTERFACE_(iface, baseiface) struct DECLSPEC_NOVTABLE iface : public baseiface +#define DECLARE_INTERFACE(iface) interface DECLSPEC_NOVTABLE iface +#define DECLARE_INTERFACE_(iface, baseiface) interface DECLSPEC_NOVTABLE iface : public baseiface -struct IUnknown; +interface IUnknown; extern "C++" { @@ -247,9 +248,9 @@ extern "C++" #define THIS_ INTERFACE *This, #define THIS INTERFACE *This #ifdef CONST_VTABLE -#define DECLARE_INTERFACE(iface) typedef struct iface { const struct iface##Vtbl *lpVtbl; } iface; typedef const struct iface##Vtbl iface##Vtbl; const struct iface##Vtbl +#define DECLARE_INTERFACE(iface) typedef interface iface { const struct iface##Vtbl *lpVtbl; } iface; typedef const struct iface##Vtbl iface##Vtbl; const struct iface##Vtbl #else -#define DECLARE_INTERFACE(iface) typedef struct iface { struct iface##Vtbl *lpVtbl; } iface; typedef struct iface##Vtbl iface##Vtbl; struct iface##Vtbl +#define DECLARE_INTERFACE(iface) typedef interface iface { struct iface##Vtbl *lpVtbl; } iface; typedef struct iface##Vtbl iface##Vtbl; struct iface##Vtbl #endif #define DECLARE_INTERFACE_(iface, baseiface) DECLARE_INTERFACE (iface) #endif diff --git a/include/wsl/stubs/unknwnbase.h b/include/wsl/stubs/unknwnbase.h index 1c86fcf..5c546f2 100644 --- a/include/wsl/stubs/unknwnbase.h +++ b/include/wsl/stubs/unknwnbase.h @@ -42,7 +42,7 @@ #ifndef __IUnknown_FWD_DEFINED__ #define __IUnknown_FWD_DEFINED__ -typedef struct IUnknown IUnknown; +typedef interface IUnknown IUnknown; #endif /* __IUnknown_FWD_DEFINED__ */ @@ -104,7 +104,7 @@ typedef struct IUnknownVtbl { END_INTERFACE } IUnknownVtbl; -struct IUnknown { +interface IUnknown { CONST_VTBL IUnknownVtbl* lpVtbl; }; From 281ac58ac173383dd6391c21403f2ced412b134e Mon Sep 17 00:00:00 2001 From: Nielsbishere Date: Sun, 15 Dec 2024 23:26:35 +0100 Subject: [PATCH 27/28] Added function for getting feature flags, which is a little bit important when checking if the GPU even supports the required featureset --- include/directx/d3d12shader.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/directx/d3d12shader.h b/include/directx/d3d12shader.h index 4c8d34f..89d463e 100644 --- a/include/directx/d3d12shader.h +++ b/include/directx/d3d12shader.h @@ -698,6 +698,8 @@ DECLARE_INTERFACE_(ID3D12FunctionReflection1, ID3D12FunctionReflection) STDMETHOD(GetInputNode)(UINT i, THIS_ _Out_ D3D12_NODE_DESC * pDesc) PURE; STDMETHOD(GetOutputNode)(UINT i, THIS_ _Out_ D3D12_NODE_DESC * pDesc) PURE; + + STDMETHOD_(UINT64, GetFeatureFlags)() PURE; }; // {EC25F42D-7006-4F2B-B33E-02CC3375733F} From 6eac2d2a197668fa4a8b236ab837b1f8f1b19417 Mon Sep 17 00:00:00 2001 From: Nielsbishere Date: Sun, 15 Dec 2024 23:28:28 +0100 Subject: [PATCH 28/28] Rename to be in line with ID3D12ShaderReflection --- include/directx/d3d12shader.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/directx/d3d12shader.h b/include/directx/d3d12shader.h index 89d463e..5e24ba5 100644 --- a/include/directx/d3d12shader.h +++ b/include/directx/d3d12shader.h @@ -699,7 +699,7 @@ DECLARE_INTERFACE_(ID3D12FunctionReflection1, ID3D12FunctionReflection) STDMETHOD(GetInputNode)(UINT i, THIS_ _Out_ D3D12_NODE_DESC * pDesc) PURE; STDMETHOD(GetOutputNode)(UINT i, THIS_ _Out_ D3D12_NODE_DESC * pDesc) PURE; - STDMETHOD_(UINT64, GetFeatureFlags)() PURE; + STDMETHOD_(UINT64, GetRequiresFlags)() PURE; }; // {EC25F42D-7006-4F2B-B33E-02CC3375733F}