コード例 #1
0
ファイル: ShaderCompiler.cs プロジェクト: Powerino73/paradox
 /// <inheritdoc/>
 public ShaderReflectionOld GetReflection(ShaderBytecode shaderBytecode)
 {
     // TODO: Implement this for separate shaders?
     // Otherwise it is only available at runtime.
     return null;
 }
コード例 #2
0
ファイル: ShaderCompiler.cs プロジェクト: Powerino73/paradox
        /// <inheritdoc/>
        public ShaderReflectionOld GetReflection(ShaderBytecode shaderBytecode)
        {
            var shaderReflection = new SharpDX.D3DCompiler.ShaderReflection(shaderBytecode);
            var shaderReflectionDesc = shaderReflection.Description;

            // Extract reflection data
            var shaderReflectionCopy = new ShaderReflectionOld();
            shaderReflectionCopy.BoundResources = new List<InputBindingDescription>();
            shaderReflectionCopy.ConstantBuffers = new List<ShaderReflectionConstantBuffer>();

            // BoundResources
            for (int i = 0; i < shaderReflectionDesc.BoundResources; ++i)
            {
                var boundResourceDesc = shaderReflection.GetResourceBindingDescription(i);
                shaderReflectionCopy.BoundResources.Add(new InputBindingDescription
                {
                    BindPoint = boundResourceDesc.BindPoint,
                    BindCount = boundResourceDesc.BindCount,
                    Name = boundResourceDesc.Name,
                    Type = (ShaderInputType)boundResourceDesc.Type,
                });
            }

            // ConstantBuffers
            for (int i = 0; i < shaderReflectionDesc.ConstantBuffers; ++i)
            {
                var constantBuffer = shaderReflection.GetConstantBuffer(i);
                var constantBufferDesc = constantBuffer.Description;
                var constantBufferCopy = new ShaderReflectionConstantBuffer
                {
                    Name = constantBufferDesc.Name,
                    Size = constantBufferDesc.Size,
                    Variables = new List<ShaderReflectionVariable>(),
                };

                switch (constantBufferDesc.Type)
                {
                    case SharpDX.D3DCompiler.ConstantBufferType.ConstantBuffer: constantBufferCopy.Type = ConstantBufferType.ConstantBuffer; break;
                    case SharpDX.D3DCompiler.ConstantBufferType.TextureBuffer: constantBufferCopy.Type = ConstantBufferType.TextureBuffer; break;
                    default: constantBufferCopy.Type = ConstantBufferType.Unknown; break;
                }

                // ConstantBuffers variables
                for (int j = 0; j < constantBufferDesc.VariableCount; ++j)
                {
                    var variable = constantBuffer.GetVariable(j);
                    var variableType = variable.GetVariableType().Description;
                    var variableDesc = variable.Description;

                    var variableCopy = new ShaderReflectionVariable
                    {
                        Name = variableDesc.Name,
                        Size = variableDesc.Size,
                        StartOffset = variableDesc.StartOffset,
                        Type = new ShaderReflectionType { Offset = variable.GetVariableType().Description.Offset },
                    };

                    constantBufferCopy.Variables.Add(variableCopy);
                }

                shaderReflectionCopy.ConstantBuffers.Add(constantBufferCopy);
            }

            return shaderReflectionCopy;
        }
コード例 #3
0
ファイル: ShaderCompiler.cs プロジェクト: Powerino73/paradox
 /// <inheritdoc/>
 public ShaderBytecode StripReflection(ShaderBytecode shaderBytecode)
 {
     // Doesn't exist in OpenGL.
     return shaderBytecode;
 }
コード例 #4
0
ファイル: ShaderCompiler.cs プロジェクト: Powerino73/paradox
 /// <inheritdoc/>
 public ShaderBytecode StripReflection(ShaderBytecode shaderBytecode)
 {
     var bytecode = new SharpDX.D3DCompiler.ShaderBytecode(shaderBytecode).Strip(SharpDX.D3DCompiler.StripFlags.CompilerStripReflectionData);
     return new ShaderBytecode(bytecode);
 }