Example #1
0
 /// <inheritdoc/>
 public ShaderReflectionOld GetReflection(ShaderBytecode shaderBytecode)
 {
     // TODO: Implement this for separate shaders?
     // Otherwise it is only available at runtime.
     return null;
 }
Example #2
0
        /// <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;
        }
Example #3
0
 /// <inheritdoc/>
 public ShaderBytecode StripReflection(ShaderBytecode shaderBytecode)
 {
     // Doesn't exist in OpenGL.
     return shaderBytecode;
 }
Example #4
0
 /// <inheritdoc/>
 public ShaderBytecode StripReflection(ShaderBytecode shaderBytecode)
 {
     var bytecode = new SharpDX.D3DCompiler.ShaderBytecode(shaderBytecode).Strip(SharpDX.D3DCompiler.StripFlags.CompilerStripReflectionData);
     return new ShaderBytecode(bytecode);
 }