Ejemplo n.º 1
0
        public bool Update(ShaderParameterUpdater parameterUpdater)
        {
            bool dataChanged = false;

            //fixed (BoundConstantBufferParam* paramReferences = &this.constantBufferParams[0])
            {
                for (int i = 0; i < this.constantBufferParams.Length; ++i)
                {
                    dataChanged |= UpdateValue(parameterUpdater, ref Desc.Members[i], i);
                }
            }
            return(dataChanged);
        }
Ejemplo n.º 2
0
        public void Update(GraphicsDevice graphicsDevice, ShaderParameterUpdater parameterUpdater)
        {
            var  threadIndex = graphicsDevice.ThreadIndex;
            bool dataChanged = constantBufferDatas[threadIndex].Update(parameterUpdater);

            // Check if update is really needed
            if (forceDataChanged)
            {
                forceDataChanged = false;
            }
            else if (!dataChanged)
            {
                return;
            }

            // Upload data to constant buffer
            Buffer.SetData(graphicsDevice, dataStreams[threadIndex]);
        }
Ejemplo n.º 3
0
        private unsafe bool UpdateValue(ShaderParameterUpdater parameterUpdater, ref EffectParameterValueData shaderVariable, int i)
        {
            if (shaderVariable.Param.KeyIndex == -1)
            {
                throw new InvalidOperationException();
            }

            BoundConstantBufferParam paramReference = constantBufferParams[i];

            var internalValue = parameterUpdater.GetInternalValue(shaderVariable.Param.KeyIndex);

            // TODO: Comparing Counter+DataPointer is not enough (if realloc on same address)
            if (internalValue.Counter == paramReference.DirtyCount &&
                internalValue == paramReference.DataPointer)
            {
                return(false);
            }

            constantBufferParams[i] = new BoundConstantBufferParam
            {
                DataPointer = internalValue,
                DirtyCount  = internalValue.Counter
            };

            var destination = (byte *)(Data + shaderVariable.Offset);

            int sourceOffset = 0;

            float *variableData = (float *)destination; // + shaderVariable.Offset);

            Matrix tempMatrix;

            switch (shaderVariable.Param.Class)
            {
            case EffectParameterClass.Struct:
                internalValue.ReadFrom((IntPtr)variableData, sourceOffset, shaderVariable.Size);
                break;

            case EffectParameterClass.Scalar:
                for (int elt = 0; elt < shaderVariable.Count; ++elt)
                {
                    internalValue.ReadFrom((IntPtr)variableData, sourceOffset, sizeof(float));
                    //*variableData = *source++;
                    sourceOffset += 4;
                    variableData += 4;     // 4 floats
                }
                break;

            case EffectParameterClass.Vector:
            case EffectParameterClass.Color:
                for (int elt = 0; elt < shaderVariable.Count; ++elt)
                {
                    //Framework.Utilities.CopyMemory((IntPtr)variableData, (IntPtr)source, (int)(shaderVariable.ColumnCount * sizeof(float)));
                    internalValue.ReadFrom((IntPtr)variableData, sourceOffset, (int)(shaderVariable.ColumnCount * sizeof(float)));
                    sourceOffset += (int)shaderVariable.ColumnCount * 4;
                    variableData += 4;
                }
                break;

            case EffectParameterClass.MatrixColumns:
                for (int elt = 0; elt < shaderVariable.Count; ++elt)
                {
                    //fixed (Matrix* p = &tempMatrix)
                    {
                        internalValue.ReadFrom((IntPtr)(byte *)&tempMatrix, sourceOffset, (int)(shaderVariable.ColumnCount * shaderVariable.RowCount * sizeof(float)));
                        ((Matrix *)variableData)->CopyMatrixFrom((float *)&tempMatrix, unchecked ((int)shaderVariable.ColumnCount), unchecked ((int)shaderVariable.RowCount));
                        sourceOffset += (int)(shaderVariable.ColumnCount * shaderVariable.RowCount) * 4;
                        variableData += 4 * shaderVariable.RowCount;
                    }
                }
                break;

            case EffectParameterClass.MatrixRows:
                for (int elt = 0; elt < shaderVariable.Count; ++elt)
                {
                    //fixed (Matrix* p = &tempMatrix)
                    {
                        internalValue.ReadFrom((IntPtr)(byte *)&tempMatrix, sourceOffset, (int)(shaderVariable.ColumnCount * shaderVariable.RowCount * sizeof(float)));
                        ((Matrix *)variableData)->TransposeMatrixFrom((float *)&tempMatrix, unchecked ((int)shaderVariable.ColumnCount), unchecked ((int)shaderVariable.RowCount));
                        //source += shaderVariable.ColumnCount * shaderVariable.RowCount;
                        sourceOffset += (int)(shaderVariable.ColumnCount * shaderVariable.RowCount) * 4;
                        variableData += 4 * shaderVariable.RowCount;
                    }
                }
                break;
            }

            return(true);
        }
Ejemplo n.º 4
0
 public ShaderStageSetup()
 {
     parameterUpdater     = new ShaderParameterUpdater();
     ParameterCollections = new ParameterCollection[16];
 }
Ejemplo n.º 5
0
        private static void UpdateUnorderedAccessView(GraphicsDevice graphicsDevice, ref EffectParameterResourceData binding, ShaderParameterUpdater parameterUpdater)
        {
            var unorderedAccessView = (GraphicsResource)parameterUpdater.GetObject(binding.Param.KeyIndex);

            graphicsDevice.SetUnorderedAccessView(binding.Stage, binding.SlotStart, unorderedAccessView);
        }
Ejemplo n.º 6
0
        private static void UpdateSampler(GraphicsDevice graphicsDevice, ref EffectParameterResourceData binding, ShaderParameterUpdater parameterUpdater)
        {
            var samplerState = (SamplerState)parameterUpdater.GetObject(binding.Param.KeyIndex);

            graphicsDevice.SetSamplerState(binding.Stage, binding.SlotStart, samplerState);
        }
Ejemplo n.º 7
0
        private static void UpdateConstantBuffer(GraphicsDevice graphicsDevice, ref EffectParameterResourceData binding, ShaderParameterUpdater parameterUpdater)
        {
            var constantBufferHelper = parameterUpdater.GetValue <ParameterConstantBuffer>(binding.Param.KeyIndex);

            // Update constant buffer content (if required)
            constantBufferHelper.Update(graphicsDevice, parameterUpdater);

            graphicsDevice.SetConstantBuffer(binding.Stage, binding.SlotStart, constantBufferHelper.Buffer);
        }