public void WriteValueByName <T>(string name, T value) where T : unmanaged
            {
                if (IsValid && IsAttached)
                {
                    lock (lck)
                    {
                        if (IsValid && IsAttached)
                        {
                            if (ModelConstBuffer.TryGetVariableByName(name, out var variable))
                            {
                                if (UnsafeHelper.SizeOf <T>() > variable.Size)
                                {
                                    var structSize = UnsafeHelper.SizeOf <T>();
                                    throw new ArgumentException($"Input struct size {structSize} is larger than shader variable {variable.Name} size {variable.Size}");
                                }
                                if (!storage.Write(storageId, variable.StartOffset, ref value))
                                {
                                    throw new ArgumentException($"Failed to write value on {name}");
                                }
                            }
                            else
                            {
#if DEBUG
                                throw new ArgumentException($"Variable not found in constant buffer {bufferDesc.Name}. Variable = {name}");
#else
                                Technique.EffectsManager.Logger.Log(Logger.LogLevel.Warning, $"Variable not found in constant buffer {bufferDesc.Name}. Variable = {name}");
#endif
                            }
                        }
                    }
                }
            }
예제 #2
0
            public void WriteValue <T>(string name, ref T value) where T : unmanaged
            {
                if (materialCB != null && materialCB.TryGetVariableByName(name, out var variable))
                {
                    if (UnsafeHelper.SizeOf <T>() > variable.Size)
                    {
                        var structSize = UnsafeHelper.SizeOf <T>();
                        throw new ArgumentException($"Input struct size {structSize} is larger than shader variable {variable.Name} size {variable.Size}");
                    }

                    if (!storage.Write(storageId, variable.StartOffset, ref value))
                    {
                        throw new ArgumentException($"Failed to write value on {name}");
                    }
                }
                else
                {
#if DEBUG
                    throw new ArgumentException($"Variable not found in constant buffer {materialCB.Name}. Variable = {name}");
#else
                    logger.LogWarning("Variable not found in constant buffer {}. Variable = {}", materialCB.Name, name);
#endif
                }
            }