public GlobalConstantBufferBinding(int slot, BufferProviderPair pair, bool isLocalBinding, bool isVertexBuffer, bool isGeometryShader, bool isPixelShader)
            {
                Slot           = slot;
                Pair           = pair;
                IsLocalBinding = isLocalBinding;
                ShaderStageApplicabilityFlags applicability = 0;

                if (isVertexBuffer)
                {
                    applicability |= ShaderStageApplicabilityFlags.Vertex;
                }
                if (isGeometryShader)
                {
                    applicability |= ShaderStageApplicabilityFlags.Geometry;
                }
                if (isPixelShader)
                {
                    applicability |= ShaderStageApplicabilityFlags.Fragment;
                }

                _applicability = applicability;
            }
        public D3DShaderConstantBindings(
            RenderContext rc,
            Device device,
            ShaderSet shaderSet,
            MaterialInputs <MaterialGlobalInputElement> globalInputs,
            MaterialInputs <MaterialPerObjectInputElement> perObjectInputs)
        {
            _device = device;

            ShaderReflection vsReflection = new ShaderReflection(((D3DVertexShader)shaderSet.VertexShader).Bytecode.Data);
            ShaderReflection psReflection = new ShaderReflection(((D3DFragmentShader)shaderSet.FragmentShader).Bytecode.Data);
            ShaderReflection gsReflection = null;

            if (shaderSet.GeometryShader != null)
            {
                gsReflection = new ShaderReflection(((D3DGeometryShader)shaderSet.GeometryShader).Bytecode.Data);
            }

            int numGlobalElements = globalInputs.Elements.Length;

            _constantBufferBindings =
                (numGlobalElements > 0)
                ? new GlobalConstantBufferBinding[numGlobalElements]
                : Array.Empty <GlobalConstantBufferBinding>();
            for (int i = 0; i < numGlobalElements; i++)
            {
                var genericElement = globalInputs.Elements[i];
                BufferProviderPair          pair;
                GlobalConstantBufferBinding cbb;
                bool isVsBuffer = DoesConstantBufferExist(vsReflection, i, genericElement.Name);
                bool isPsBuffer = DoesConstantBufferExist(psReflection, i, genericElement.Name);
                bool isGsBuffer = false;
                if (gsReflection != null)
                {
                    isGsBuffer = DoesConstantBufferExist(gsReflection, i, genericElement.Name);
                }

                if (genericElement.UseGlobalNamedBuffer)
                {
                    pair = rc.GetNamedGlobalBufferProviderPair(genericElement.GlobalProviderName);
                    cbb  = new GlobalConstantBufferBinding(i, pair, false, isVsBuffer, isGsBuffer, isPsBuffer);
                }
                else
                {
                    D3DConstantBuffer constantBuffer = new D3DConstantBuffer(device, genericElement.DataProvider.DataSizeInBytes);
                    pair = new BufferProviderPair(constantBuffer, genericElement.DataProvider);
                    cbb  = new GlobalConstantBufferBinding(i, pair, true, isVsBuffer, isGsBuffer, isPsBuffer);
                }

                _constantBufferBindings[i] = cbb;
            }

            int numPerObjectInputs = perObjectInputs.Elements.Length;

            _perObjectBufferBindings =
                (numPerObjectInputs > 0)
                ? new PerObjectConstantBufferBinding[numPerObjectInputs]
                : Array.Empty <PerObjectConstantBufferBinding>();
            for (int i = 0; i < numPerObjectInputs; i++)
            {
                var  genericElement = perObjectInputs.Elements[i];
                int  bufferSlot     = i + numGlobalElements;
                bool isVsBuffer     = DoesConstantBufferExist(vsReflection, bufferSlot, genericElement.Name);
                bool isPsBuffer     = DoesConstantBufferExist(psReflection, bufferSlot, genericElement.Name);
                bool isGsBuffer     = false;
                if (gsReflection != null)
                {
                    isGsBuffer = DoesConstantBufferExist(gsReflection, bufferSlot, genericElement.Name);
                }
                D3DConstantBuffer constantBuffer     = new D3DConstantBuffer(device, genericElement.BufferSizeInBytes);
                PerObjectConstantBufferBinding pocbb = new PerObjectConstantBufferBinding(bufferSlot, constantBuffer, isVsBuffer, isGsBuffer, isPsBuffer);
                _perObjectBufferBindings[i] = pocbb;
            }
        }