namespace SharpDX.D3DCompiler
{
using System;
using Direct3D;
///
/// Represents a profile of a shader stage - stage type and version
///
public struct ShaderProfile
{
private const string shortStringFormat = "{0}_{1}_{2}";
private const string longStringFormat = "{0}_{1}_{2}_level_{3}_{4}";
///
/// Gets the shader version - that is the shader stage type
///
/// For example, it is the "vs" part from "vs_5_0".
public readonly ShaderVersion Version;
// REMARK: used int instad of uint to make this more CLS-Compliant
///
/// Gets the major version of the shader profile.
///
/// For example, it is the "5" part from "vs_5_0".
public readonly int Major;
///
/// Gets the minor version of the shader profile.
///
/// For example, it is the "0" part from "vs_5_0".
public readonly int Minor;
///
/// Gets the major version of the shader sub-profile.
///
/// For example, it is the "9" part from "vs_4_0_profile_9_3".
public readonly int ProfileMajor;
///
/// Gets the minor version of the shader sub-profile.
///
/// For example, it is the "3" part from "vs_4_0_profile_9_3".
public readonly int ProfileMinor;
///
/// Creates a new instance of the struct.
///
/// The shader stage type.
/// The major version.
/// The minor version.
/// The profile major version.
/// The profile minor version.
public ShaderProfile(ShaderVersion version, int major, int minor, int profileMajor, int profileMinor)
{
Version = version;
Major = major;
Minor = minor;
ProfileMajor = profileMajor;
ProfileMinor = profileMinor;
}
///
/// Returns the string representation of the current profile.
///
/// The string representation, for example "ps_5_0" or "vs_4_0_profile_9_3".
public override string ToString()
{
// get the textual representation of stage type
var versionText = GetTypePrefix();
// if we don't have a major profile - then it is the short version
return ProfileMajor != 0
? string.Format(longStringFormat, versionText, Major, Minor, ProfileMajor, ProfileMinor)
: string.Format(shortStringFormat, versionText, Major, Minor);
}
///
/// Gets the shader type prefix.
///
/// Type prefix, for example "vs" or "ps".
public string GetTypePrefix()
{
switch (Version)
{
case ShaderVersion.PixelShader:
return "ps";
case ShaderVersion.VertexShader:
return "vs";
case ShaderVersion.GeometryShader:
return "gs";
case ShaderVersion.HullShader:
return "hs";
case ShaderVersion.DomainShader:
return "ds";
case ShaderVersion.ComputeShader:
return "cs";
default:
throw new ArgumentOutOfRangeException();
}
}
///
/// Gets the corresponding for this .
///
/// The minimum that corresponds to current profile.
public FeatureLevel GetFeatureLevel()
{
if (Major == 5 && Minor == 0)
return FeatureLevel.Level_11_0;
if (Major == 4 && Minor == 1)
return FeatureLevel.Level_10_1;
if (Major == 4 && Minor == 0)
{
if (ProfileMajor == 9 && ProfileMinor == 3) return FeatureLevel.Level_9_3;
if (ProfileMajor == 9 && ProfileMinor == 1) return FeatureLevel.Level_9_1;
if (ProfileMajor == 0 && ProfileMinor == 0) return FeatureLevel.Level_10_0;
}
throw new InvalidOperationException("Cannot convert profile to feature level.");
}
}
}