Esempio n. 1
0
 /// <summary>
 /// Creates a new instance of <see cref="StaticSampler"/>
 /// </summary>
 public StaticSampler(Sampler sampler, uint shaderRegister, uint registerSpace, ShaderVisibility visibility)
 {
     Sampler        = sampler;
     ShaderRegister = shaderRegister;
     RegisterSpace  = registerSpace;
     Visibility     = visibility;
 }
    /// <summary>
    /// Initializes a new instance of the <see cref="StaticSamplerDescription"/> struct.
    /// </summary>
    /// <param name="samplerDescription">Sampler description</param>
    /// <param name="shaderVisibility">The shader visibility.</param>
    /// <param name="shaderRegister">The shader register.</param>
    /// <param name="registerSpace">The register space.</param>
    public StaticSamplerDescription(SamplerDescription samplerDescription, ShaderVisibility shaderVisibility, int shaderRegister, int registerSpace) : this()
    {
        ShaderVisibility = shaderVisibility;
        ShaderRegister   = shaderRegister;
        RegisterSpace    = registerSpace;

        // Unlike regular samplers, static samplers only support three possible border colors: opaque white, opaque black, and transparent.
        // So if the sampler has a border color that matches one of those exactly, we can convert it; otherwise it's left as the default (transparent).
        if (samplerDescription.BorderColor == Colors.White)
        {
            BorderColor = StaticBorderColor.OpaqueWhite;
        }
        else if (samplerDescription.BorderColor == Colors.Black)
        {
            BorderColor = StaticBorderColor.OpaqueBlack;
        }
        else
        {
            BorderColor = StaticBorderColor.TransparentBlack;
        }

        Filter             = samplerDescription.Filter;
        AddressU           = samplerDescription.AddressU;
        AddressV           = samplerDescription.AddressV;
        AddressW           = samplerDescription.AddressW;
        MinLOD             = samplerDescription.MinLOD;
        MaxLOD             = samplerDescription.MaxLOD;
        MipLODBias         = samplerDescription.MipLODBias;
        MaxAnisotropy      = samplerDescription.MaxAnisotropy;
        ComparisonFunction = samplerDescription.ComparisonFunction;
    }
Esempio n. 3
0
        /// <summary>
        /// The InitAsBufferUAV
        /// </summary>
        /// <param name="register">The <see cref="int"/></param>
        /// <param name="visibility">The <see cref="ShaderVisibility"/></param>
        public void InitAsBufferUAV(int register, ShaderVisibility visibility = ShaderVisibility.All)
        {
            var buffer = new RootDescriptor1 {
                RegisterSpace = 0, ShaderRegister = register, Flags = RootDescriptorFlags.None
            };

            Parameter = new RootParameter1(visibility, buffer, RootParameterType.UnorderedAccessView);
        }
Esempio n. 4
0
 private RootParameter(D3D12_DESCRIPTOR_RANGE1[] descriptorTable, ShaderVisibility visibility)
 {
     Type            = RootParameterType.DescriptorTable;
     Visibility      = visibility;
     DescriptorTable = descriptorTable;
     Descriptor      = default;
     Constants       = default;
 }
Esempio n. 5
0
 private RootParameter(RootParameterType type, D3D12_ROOT_DESCRIPTOR1 descriptor, ShaderVisibility visibility)
 {
     Type            = type;
     Visibility      = visibility;
     DescriptorTable = default;
     Descriptor      = descriptor;
     Constants       = default;
 }
Esempio n. 6
0
 private RootParameter(D3D12_ROOT_CONSTANTS constants, ShaderVisibility visibility)
 {
     Type            = RootParameterType.DwordConstants;
     Visibility      = visibility;
     DescriptorTable = default;
     Descriptor      = default;
     Constants       = constants;
 }
Esempio n. 7
0
        /// <summary>
        /// The InitAsConstantBuffer
        /// </summary>
        /// <param name="register">The <see cref="int"/></param>
        /// <param name="visibility">The <see cref="ShaderVisibility"/></param>
        public void InitAsConstantBuffer(int register, ShaderVisibility visibility = ShaderVisibility.All)
        {
            var cbuffer = new RootDescriptor1 {
                RegisterSpace = 0, ShaderRegister = register, Flags = RootDescriptorFlags.None
            };

            Parameter = new RootParameter1(visibility, cbuffer, RootParameterType.ConstantBufferView);
        }
Esempio n. 8
0
 /// <summary>
 /// Creates a new descriptor table root parameter
 /// </summary>
 /// <returns>A new <see cref="RootParameter"/> representing a descriptor table</returns>
 public static RootParameter CreateDescriptorTable(
     DescriptorRangeType type,
     uint baseShaderRegister,
     uint descriptorCount,
     uint registerSpace,
     uint offsetInDescriptorsFromTableStart = DescriptorRangeParameter.AppendAfterLastDescriptor,
     ShaderVisibility visibility            = ShaderVisibility.All
     )
 => CreateDescriptorTable(new DescriptorRangeParameter(type, baseShaderRegister, descriptorCount, registerSpace, offsetInDescriptorsFromTableStart), visibility);
Esempio n. 9
0
        Boolean InitAsBufferUAV(Int32 register, ShaderVisibility visibility = ShaderVisibility.All)
        {
            if (m_RootParameter != null)
            {
                return(false);
            }

            m_RootParameter = new RootParameter(visibility, new DescriptorRange(DescriptorRangeType.UnorderedAccessView, 1, register));
            return(true);
        }
Esempio n. 10
0
        Boolean InitAsConstants(Int32 register, Int32 numDWORDs, ShaderVisibility visibility = ShaderVisibility.All)
        {
            if (m_RootParameter != null)
            {
                return(false);
            }

            m_RootParameter = new RootParameter(visibility, new RootConstants(register, 0, numDWORDs));
            return(true);
        }
Esempio n. 11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RootParameter"/> struct.
        /// </summary>
        /// <param name="rootDescriptor">The root descriptor.</param>
        /// <param name="type">The type.</param>
        /// <param name="visibility">The visibility.</param>
        /// <exception cref="System.ArgumentException">type</exception>
        public RootParameter1(ShaderVisibility visibility, RootDescriptor1 rootDescriptor, RootParameterType type)
            : this()
        {
            if(type == RootParameterType.Constant32Bits || type == RootParameterType.DescriptorTable)
            {
                throw new ArgumentException(string.Format("Cannot this type [{0}] for a RootDescriptor", type), "type");
            }

            native.ParameterType = type;
            Descriptor = rootDescriptor;
            ShaderVisibility = visibility;
        }
Esempio n. 12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RootParameter"/> struct.
        /// </summary>
        /// <param name="rootDescriptor">The root descriptor.</param>
        /// <param name="type">The type.</param>
        /// <param name="visibility">The visibility.</param>
        /// <exception cref="System.ArgumentException">type</exception>
        public RootParameter1(ShaderVisibility visibility, RootDescriptor1 rootDescriptor, RootParameterType type)
            : this()
        {
            if (type == RootParameterType.Constant32Bits || type == RootParameterType.DescriptorTable)
            {
                throw new ArgumentException(string.Format("Cannot this type [{0}] for a RootDescriptor", type), "type");
            }

            native.ParameterType = type;
            Descriptor           = rootDescriptor;
            ShaderVisibility     = visibility;
        }
Esempio n. 13
0
        /// <summary>
        /// Initializes a new instance of the <see cref="StaticSamplerDescription"/> struct.
        /// </summary>
        /// <param name="shaderVisibility">The shader visibility.</param>
        /// <param name="shaderRegister">The shader register.</param>
        /// <param name="registerSpace">The register space.</param>
        public StaticSamplerDescription(ShaderVisibility shaderVisibility, int shaderRegister, int registerSpace) : this()
        {
            ShaderVisibility = shaderVisibility;
            ShaderRegister   = shaderRegister;
            RegisterSpace    = registerSpace;

            Filter         = Filter.MinMagMipLinear;
            AddressU       = TextureAddressMode.Clamp;
            AddressV       = TextureAddressMode.Clamp;
            AddressW       = TextureAddressMode.Clamp;
            MinLOD         = -float.MaxValue;
            MaxLOD         = float.MaxValue;
            MipLODBias     = 0.0f;
            MaxAnisotropy  = 16;
            ComparisonFunc = Comparison.Never;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="StaticSamplerDescription"/> struct.
        /// </summary>
        /// <param name="shaderVisibility">The shader visibility.</param>
        /// <param name="shaderRegister">The shader register.</param>
        /// <param name="registerSpace">The register space.</param>
        public StaticSamplerDescription(ShaderVisibility shaderVisibility, int shaderRegister, int registerSpace) : this()
        {
            ShaderVisibility = shaderVisibility;
            ShaderRegister = shaderRegister;
            RegisterSpace = registerSpace;

            Filter = Filter.MinMagMipLinear;
            AddressU = TextureAddressMode.Clamp;
            AddressV = TextureAddressMode.Clamp;
            AddressW = TextureAddressMode.Clamp;
            MinLOD = -float.MaxValue;
            MaxLOD = float.MaxValue;
            MipLODBias = 0.0f;
            MaxAnisotropy = 16;
            ComparisonFunc = Comparison.Never;
            BorderColor = StaticBorderColor.TransparentBlack;
        }
    /// <summary>
    /// Initializes a new instance of the <see cref="StaticSamplerDescription"/> struct.
    /// </summary>
    /// <param name="shaderVisibility">The shader visibility.</param>
    /// <param name="shaderRegister">The shader register.</param>
    /// <param name="registerSpace">The register space.</param>
    public StaticSamplerDescription(ShaderVisibility shaderVisibility, int shaderRegister, int registerSpace)
    {
        Filter             = Filter.MinMagMipLinear;
        AddressU           = TextureAddressMode.Clamp;
        AddressV           = TextureAddressMode.Clamp;
        AddressW           = TextureAddressMode.Clamp;
        MipLODBias         = 0.0f;
        MaxAnisotropy      = 1;
        ComparisonFunction = ComparisonFunction.Never;
        BorderColor        = StaticBorderColor.TransparentBlack;
        MinLOD             = float.MinValue;
        MaxLOD             = float.MaxValue;

        ShaderRegister   = shaderRegister;
        RegisterSpace    = registerSpace;
        ShaderVisibility = shaderVisibility;
    }
        /// <summary>
        /// Initializes a new instance of the <see cref="StaticSamplerDescription"/> struct.
        /// </summary>
        /// <param name="samplerDescription">Sampler description</param>
        /// <param name="shaderVisibility">The shader visibility.</param>
        /// <param name="shaderRegister">The shader register.</param>
        /// <param name="registerSpace">The register space.</param>
        public StaticSamplerDescription(SamplerDescription samplerDescription, ShaderVisibility shaderVisibility, int shaderRegister, int registerSpace) : this()
        {
            ShaderVisibility = shaderVisibility;
            ShaderRegister   = shaderRegister;
            RegisterSpace    = registerSpace;
            BorderColor      = StaticBorderColor.TransparentBlack;

            Filter             = samplerDescription.Filter;
            AddressU           = samplerDescription.AddressU;
            AddressV           = samplerDescription.AddressV;
            AddressW           = samplerDescription.AddressW;
            MinLOD             = samplerDescription.MinLOD;
            MaxLOD             = samplerDescription.MaxLOD;
            MipLODBias         = samplerDescription.MipLODBias;
            MaxAnisotropy      = samplerDescription.MaxAnisotropy;
            ComparisonFunction = samplerDescription.ComparisonFunction;
        }
Esempio n. 17
0
        /// <summary>
        /// Creates a new descriptor table root parameter
        /// </summary>
        /// <param name="ranges">The <see cref="DescriptorRange"/>s to bind</param>
        /// <param name="visibility">Indicates which shaders have access to this parameter</param>
        /// <returns>A new <see cref="RootParameter"/> representing a descriptor table</returns>
        public static RootParameter CreateDescriptorTable(DescriptorRange[] ranges, ShaderVisibility visibility = ShaderVisibility.All)
        {
            // do NOT make this a not pinned array. RootSignature.TranslateRootParameters relies on it
            var d3d12Ranges = GC.AllocateArray <D3D12_DESCRIPTOR_RANGE>(ranges.Length, pinned: true);

            for (var i = 0; i < ranges.Length; i++)
            {
                var range = ranges[i];
                d3d12Ranges[i] = new D3D12_DESCRIPTOR_RANGE(
                    (D3D12_DESCRIPTOR_RANGE_TYPE)range.Type,
                    range.DescriptorCount,
                    range.BaseShaderRegister,
                    range.RegisterSpace,
                    range.DescriptorOffset
                    );
            }

            return(new RootParameter(d3d12Ranges, visibility));
        }
Esempio n. 18
0
 public RootParameter(RootParameterType parameterType, RootDescriptor rootDescriptor, ShaderVisibility visibility)
 {
     NativeRootParameter = new RootParameter1((Vortice.Direct3D12.RootParameterType)parameterType, Unsafe.As <RootDescriptor, RootDescriptor1>(ref rootDescriptor), (Vortice.Direct3D12.ShaderVisibility)visibility);
 }
Esempio n. 19
0
 /// <summary>
 /// Creates a new descriptor table root parameter
 /// </summary>
 /// <param name="range">The <see cref="DescriptorRangeParameter"/> to bind</param>
 /// <param name="visibility">Indicates which shaders have access to this parameter</param>
 /// <returns>A new <see cref="RootParameter"/> representing a descriptor table</returns>
 public static RootParameter CreateDescriptorTable(DescriptorRangeParameter range, ShaderVisibility visibility = ShaderVisibility.All)
 => CreateDescriptorTable(new[] { range }, visibility);
Esempio n. 20
0
 public RootParameter(RootDescriptorTable descriptorTable, ShaderVisibility visibility)
 {
     NativeRootParameter = new RootParameter1(new RootDescriptorTable1(descriptorTable.Ranges.Select(r => Unsafe.As <DescriptorRange, DescriptorRange1>(ref r)).ToArray()), (Vortice.Direct3D12.ShaderVisibility)visibility);
 }
Esempio n. 21
0
 /// <summary>
 /// Creates a new directly-bound descriptor root parameter
 /// </summary>
 /// <param name="type">The type of the descriptor to bind. This must either be <see cref="RootParameterType.ConstantBufferView"/>,
 /// <see cref="RootParameterType.ShaderResourceView"/>, or <see cref="RootParameterType.UnorderedAccessView"/></param>
 /// <param name="shaderRegister">The shader register to bind this parameter to</param>
 /// <param name="registerSpace">The space to bind this parameter in</param>
 /// <param name="visibility">Indicates which shaders have access to this parameter</param>
 /// <returns>A new <see cref="RootParameter"/> representing a directly-bound descriptor</returns>
 public static RootParameter CreateDescriptor(RootParameterType type, uint shaderRegister, uint registerSpace, ShaderVisibility visibility = ShaderVisibility.All)
 {
     Debug.Assert(type is RootParameterType.ConstantBufferView or RootParameterType.ShaderResourceView or RootParameterType.UnorderedAccessView);
     return(new RootParameter(type, new D3D12_ROOT_DESCRIPTOR1 {
         ShaderRegister = shaderRegister, RegisterSpace = registerSpace
     }, visibility));
 }
Esempio n. 22
0
        Boolean InitAsDescriptorRange(DescriptorRangeType type, Int32 register, Int32 counts, ShaderVisibility visibility = ShaderVisibility.All)
        {
            if (m_RootParameter != null)
            {
                return(false);
            }

            m_RootParameter = new RootParameter(visibility, new DescriptorRange(type, counts, register));
            return(true);
        }
Esempio n. 23
0
        public Boolean InitStaticSampler(Int32 register, H1SamplerDescription samplerDesc, ShaderVisibility visibility)
        {
            if (m_NumInitializedStaticSamplers > m_NumSamplers)
            {
                return(false); // there are no available to initialize static samplers
            }
            StaticSamplerDescription staticSamplerDesc = m_SamplerArray[m_NumInitializedStaticSamplers];

            staticSamplerDesc                = new StaticSamplerDescription(visibility, register, 0); // initialize static sampler description
            staticSamplerDesc.Filter         = H1RHIDefinitionHelper.ConvertToFilter(samplerDesc.Filter);
            staticSamplerDesc.AddressU       = H1RHIDefinitionHelper.ConvertToTextureAddressMode(samplerDesc.AddressU);
            staticSamplerDesc.AddressV       = H1RHIDefinitionHelper.ConvertToTextureAddressMode(samplerDesc.AddressV);
            staticSamplerDesc.AddressW       = H1RHIDefinitionHelper.ConvertToTextureAddressMode(samplerDesc.AddressW);
            staticSamplerDesc.MipLODBias     = samplerDesc.MipLODBias;
            staticSamplerDesc.MaxAnisotropy  = samplerDesc.MaxAnisotropy;
            staticSamplerDesc.ComparisonFunc = H1RHIDefinitionHelper.ConvertToComparisonFunc(samplerDesc.ComparisonFunc);
            staticSamplerDesc.BorderColor    = StaticBorderColor.OpaqueWhite;
            staticSamplerDesc.MinLOD         = samplerDesc.MinLOD;
            staticSamplerDesc.MaxLOD         = samplerDesc.MaxLOD;

            if (staticSamplerDesc.AddressU == TextureAddressMode.Border ||
                staticSamplerDesc.AddressV == TextureAddressMode.Border ||
                staticSamplerDesc.AddressW == TextureAddressMode.Border)
            {
                //@TODO - warning for the case, different border color with 'samplerDesc'
            }

            return(true);
        }
Esempio n. 24
0
 /// <summary>
 /// Creates a new constant values root parameter to fit a certain type
 /// </summary>
 /// <typeparam name="T">The type to create a constant root parameter for</typeparam>
 /// <param name="shaderRegister">The shader register to bind this parameter to</param>
 /// <param name="registerSpace">The space to bind this parameter in</param>
 /// <param name="visibility">Indicates which shaders have access to this parameter</param>
 /// <returns>A new <see cref="RootParameter"/> representing a set of constants</returns>
 public static RootParameter CreateConstants <T>(uint shaderRegister, uint registerSpace, ShaderVisibility visibility = ShaderVisibility.All)
 => CreateConstants(Num32BitValues <T>(), shaderRegister, registerSpace, visibility);
Esempio n. 25
0
 public RootParameter(RootConstants rootConstants, ShaderVisibility visibility)
 {
     NativeRootParameter = new RootParameter1(Unsafe.As <RootConstants, Vortice.Direct3D12.RootConstants>(ref rootConstants), (Vortice.Direct3D12.ShaderVisibility)visibility);
 }
Esempio n. 26
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RootParameter1"/> struct.
 /// </summary>
 /// <param name="rootConstants">The root constants.</param>
 /// <param name="visibility">The shader visibility.</param>
 public RootParameter1(ShaderVisibility visibility, RootConstants rootConstants)
     : this()
 {
     Constants        = rootConstants;
     ShaderVisibility = visibility;
 }
Esempio n. 27
0
        /// <summary>
        /// The InitAsConstants
        /// </summary>
        /// <param name="register">The <see cref="int"/></param>
        /// <param name="numDwords">The <see cref="int"/></param>
        /// <param name="visibility">The <see cref="ShaderVisibility"/></param>
        public void InitAsConstants(int register, int numDwords, ShaderVisibility visibility = ShaderVisibility.All)
        {
            var constant = new RootConstants(register, 0, numDwords);

            Parameter = new RootParameter1(visibility, constant);
        }
Esempio n. 28
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RootParameter1"/> struct.
 /// </summary>
 /// <param name="rootConstants">The root constants.</param>
 /// <param name="visibility">The shader visibility.</param>
 public RootParameter1(ShaderVisibility visibility, RootConstants rootConstants)
     : this()
 {
     Constants = rootConstants;
     ShaderVisibility = visibility;
 }
Esempio n. 29
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RootParameter"/> struct.
 /// </summary>
 /// <param name="descriptorTable">The descriptor table.</param>
 /// <param name="visibility">The shader visibility.</param>
 public RootParameter1(ShaderVisibility visibility, params DescriptorRange[] descriptorTable) : this()
 {
     DescriptorTable = descriptorTable;
     ShaderVisibility = visibility;
 }
Esempio n. 30
0
        /// <summary>
        /// The InitAsDescriptorTable
        /// </summary>
        /// <param name="rangeCount">The <see cref="int"/></param>
        /// <param name="visibility">The <see cref="ShaderVisibility"/></param>
        public void InitAsDescriptorTable(int rangeCount, ShaderVisibility visibility)
        {
            var ranges = new List <DescriptorRange>(rangeCount);

            Parameter = new RootParameter1(visibility, ranges.ToArray());
        }
Esempio n. 31
0
 /// <summary>
 /// The InitStaticSampler
 /// </summary>
 /// <param name="register">The <see cref="int"/></param>
 /// <param name="nonstaticSamplerDesc">The <see cref="SamplerStateDescription"/></param>
 /// <param name="visibility">The <see cref="ShaderVisibility"/></param>
 public void InitStaticSampler(int register, SamplerStateDescription nonstaticSamplerDesc, ShaderVisibility visibility = ShaderVisibility.All)
 {
     Debug.Assert(InitializedStaticSamplersCount < SamplersCount);
     ref var staticSamplerDesc = ref SamplerArray[InitializedStaticSamplersCount++];
Esempio n. 32
0
 /// <summary>
 /// Creates a new constant values root parameter
 /// </summary>
 /// <param name="num32bitValues">The size, in 32 bit values, of all the constants combined</param>
 /// <param name="shaderRegister">The shader register to bind this parameter to</param>
 /// <param name="registerSpace">The space to bind this parameter in</param>
 /// <param name="visibility">Indicates which shaders have access to this parameter</param>
 /// <returns>A new <see cref="RootParameter"/> representing a set of constants</returns>
 public static RootParameter CreateConstants(uint num32bitValues, uint shaderRegister, uint registerSpace, ShaderVisibility visibility = ShaderVisibility.All)
 => new RootParameter(new D3D12_ROOT_CONSTANTS {
     Num32BitValues = num32bitValues, ShaderRegister = shaderRegister, RegisterSpace = registerSpace
 }, visibility);
Esempio n. 33
0
 /// <summary>
 /// The InitAsDescriptorRange
 /// </summary>
 /// <param name="type">The <see cref="DescriptorRangeType"/></param>
 /// <param name="register">The <see cref="int"/></param>
 /// <param name="count">The <see cref="int"/></param>
 /// <param name="visibility">The <see cref="ShaderVisibility"/></param>
 public void InitAsDescriptorRange(DescriptorRangeType type, int register, int count, ShaderVisibility visibility = ShaderVisibility.All)
 {
     InitAsDescriptorTable(1, visibility);
     SetTableRange(0, type, register, count, 0);
 }
Esempio n. 34
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RootParameter"/> struct.
 /// </summary>
 /// <param name="descriptorTable">The descriptor table.</param>
 /// <param name="visibility">The shader visibility.</param>
 public RootParameter1(ShaderVisibility visibility, params DescriptorRange[] descriptorTable) : this()
 {
     DescriptorTable  = descriptorTable;
     ShaderVisibility = visibility;
 }