#pragma region CPL License /* Nuclex Native Framework Copyright (C) 2002-2013 Nuclex Development Labs This library is free software; you can redistribute it and/or modify it under the terms of the IBM Common Public License as published by the IBM Corporation; either version 1.0 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the IBM Common Public License for more details. You should have received a copy of the IBM Common Public License along with this library */ #pragma endregion // CPL License // If the library is compiled as a DLL, this ensures symbols are exported #define NUCLEX_GRAPHICS_SOURCE 1 #include "HlslInputSignatureSerializer.h" #define INITGUID 1 #define D3D11_NO_HELPERS #include namespace { // ------------------------------------------------------------------------------------------- // /// Looks up the matching built-in semantic for a Direct3D parameter name /// Name for which the built-in semantic will be looked up /// The built-in semantic matching the specified parameter name Nuclex::Graphics::Introspection::BuiltInSemantic::Enum builtInSemanticFromName( D3D_NAME name ) { using namespace Nuclex::Graphics::Introspection; switch(name) { case D3D10_NAME_UNDEFINED: { return BuiltInSemantic::NotBuiltIn; } case D3D10_NAME_POSITION: { return BuiltInSemantic::Position; } case D3D10_NAME_CLIP_DISTANCE: { return BuiltInSemantic::ClipDistance; } case D3D10_NAME_CULL_DISTANCE: { return BuiltInSemantic::CullDistance; } case D3D10_NAME_RENDER_TARGET_ARRAY_INDEX: { return BuiltInSemantic::RenderTargetArrayIndex; } case D3D10_NAME_VIEWPORT_ARRAY_INDEX: { return BuiltInSemantic::ViewportArrayIndex; } case D3D10_NAME_VERTEX_ID: { return BuiltInSemantic::VertexId; } case D3D10_NAME_PRIMITIVE_ID: { return BuiltInSemantic::PrimitiveId; } case D3D10_NAME_INSTANCE_ID: { return BuiltInSemantic::InstanceId; } case D3D10_NAME_IS_FRONT_FACE: { return BuiltInSemantic::IsFrontFace; } case D3D10_NAME_SAMPLE_INDEX: { return BuiltInSemantic::SampleIndex; } case D3D10_NAME_TARGET: { return BuiltInSemantic::Target; } case D3D10_NAME_DEPTH: { return BuiltInSemantic::Depth; } case D3D10_NAME_COVERAGE: { return BuiltInSemantic::Coverage; } case D3D11_NAME_DEPTH_GREATER_EQUAL: { return BuiltInSemantic::DepthGreaterEqual; } case D3D11_NAME_DEPTH_LESS_EQUAL: { return BuiltInSemantic::DepthLessEqual; } case D3D11_NAME_FINAL_QUAD_EDGE_TESSFACTOR: case D3D11_NAME_FINAL_QUAD_INSIDE_TESSFACTOR: case D3D11_NAME_FINAL_TRI_EDGE_TESSFACTOR: case D3D11_NAME_FINAL_TRI_INSIDE_TESSFACTOR: case D3D11_NAME_FINAL_LINE_DETAIL_TESSFACTOR: case D3D11_NAME_FINAL_LINE_DENSITY_TESSFACTOR: default: { return BuiltInSemantic::NotBuiltIn; } } } // ------------------------------------------------------------------------------------------- // /// Looks up the matching parameter type for a Direct3D component type /// Component type whose parameter type will be looked up /// the parameter type matching the specified component type Nuclex::Graphics::Introspection::ParameterType::Enum parameterTypeFromComponentType( D3D_REGISTER_COMPONENT_TYPE componentType ) { using namespace Nuclex::Graphics::Introspection; switch(componentType) { case D3D10_REGISTER_COMPONENT_UNKNOWN: { return ParameterType::Unknown; } case D3D10_REGISTER_COMPONENT_UINT32: { return ParameterType::Unsigned32; } case D3D10_REGISTER_COMPONENT_SINT32: { return ParameterType::Signed32; } case D3D10_REGISTER_COMPONENT_FLOAT32: { return ParameterType::Float32; } default: { return ParameterType::Unknown; } } } // ------------------------------------------------------------------------------------------- // } // anonymous namespace namespace Nuclex { namespace Graphics { namespace Introspection { void HlslInputSignatureSerializer::Read(const MiniReader &reader, ShaderMetadata &metadata) { MiniReader headerReader(reader); // Number of input parameters the shader processes std::uint32_t inputParameterCount; headerReader.Read(inputParameterCount); // Version of the file format being processed (always 8, it seems - this could // also indicate a flags field, but there's no place these flags could go) std::uint32_t formatVersion; headerReader.Read(formatVersion); for(std::size_t index = 0; index < inputParameterCount; ++index) { InputParameter inputParameterMetadata; readInputParameter(reader, headerReader, inputParameterMetadata); metadata.Inputs.push_back(inputParameterMetadata); } } // ------------------------------------------------------------------------------------------- // void HlslInputSignatureSerializer::readInputParameter( const MiniReader &reader, MiniReader ¶meterReader, InputParameter &inputParameterMetadata ) { // Semantic name { std::uint32_t nameOffset; parameterReader.Read(nameOffset); MiniReader nameReader(reader); nameReader.Skip(nameOffset); nameReader.Read(inputParameterMetadata.Semantic); } // Index if the same semantic name appears multiple times std::uint32_t semanticIndex; parameterReader.Read(semanticIndex); inputParameterMetadata.SemanticIndex = static_cast(semanticIndex); // Built-in semantic std::uint32_t systemValueType; parameterReader.Read(systemValueType); inputParameterMetadata.BuiltInSemantic = builtInSemanticFromName( static_cast(systemValueType) ); // Data type used for the parameter's components std::uint32_t componentType; parameterReader.Read(componentType); inputParameterMetadata.Type = parameterTypeFromComponentType( static_cast(componentType) ); // Shader register the parameter goes into std::uint32_t registerIndex; parameterReader.Read(registerIndex); inputParameterMetadata.RegisterIndex = static_cast(registerIndex); // Which components of the parameter are used (not sure about the exact // layout here, rest, the third byte seems to mirror the fourth, // the first two bytes were always empty). std::uint32_t masks; parameterReader.Read(masks); inputParameterMetadata.UsedComponents = static_cast(masks & 0x0F); } // ------------------------------------------------------------------------------------------- // }}} // namespace Nuclex::Graphics::Introspection