Esempio n. 1
0
        public static void AddDecorationLocations(FrontEndTranslator translator, ShaderType shaderType, ShaderInterfaceSet interfaceSet, LocationCallback locationCallback, ShaderBlock decorationsBlock)
        {
            int GetNextLocation(Dictionary <int, ShaderInterfaceField> usedLocations, int currLocation)
            {
                while (usedLocations.ContainsKey(currLocation))
                {
                    ++currLocation;
                }
                return(currLocation);
            };
            var usedLocations = new Dictionary <int, ShaderInterfaceField>();
            List <(ShaderInterfaceField Field, ShaderOp FieldOp)> unknownLocationFields = new List <(ShaderInterfaceField Field, ShaderOp FieldOp)>();

            foreach (var field in interfaceSet)
            {
                var fieldOp = interfaceSet.GetFieldInstance(translator, field, null);

                int location  = -1;
                int component = -1;
                locationCallback(field.ShaderField, out location, out component);
                if (location != -1)
                {
                    Decorations.AddDecorationLocation(translator, fieldOp, location, decorationsBlock);
                    usedLocations.Add(location, field);
                    if (component != -1)
                    {
                        Decorations.AddDecorationComponent(translator, fieldOp, location, decorationsBlock);
                    }
                }
                else
                {
                    unknownLocationFields.Add((field, fieldOp));
                }
            }

            var nextLocation = 0;

            foreach (var pair in unknownLocationFields)
            {
                nextLocation = GetNextLocation(usedLocations, nextLocation);
                Decorations.AddDecorationLocation(translator, pair.FieldOp, nextLocation, decorationsBlock);
                usedLocations.Add(nextLocation, pair.Field);
            }
        }
Esempio n. 2
0
        public static void CopyInterfaceFields(FrontEndTranslator translator, ShaderOp thisOp, ShaderInterfaceSet interfaceSet, InterfaceFieldCopyMode copyMode, FrontEndContext context)
        {
            foreach (var interfaceField in interfaceSet)
            {
                var interfaceInstance = interfaceSet.GetFieldInstance(translator, interfaceField, context);
                if (interfaceInstance == null)
                {
                    continue;
                }

                var shaderFieldInstance = translator.GenerateAccessChain(thisOp, interfaceField.ShaderField.mMeta.mName, context);
                if (copyMode == InterfaceFieldCopyMode.Input)
                {
                    translator.CreateStoreOp(context.mCurrentBlock, shaderFieldInstance, interfaceInstance);
                }
                else
                {
                    translator.CreateStoreOp(context.mCurrentBlock, interfaceInstance, shaderFieldInstance);
                }
            }
        }