Esempio n. 1
0
        public override void VisitStructDeclaration(StructDeclarationSyntax node)
        {
            var        structSymbol = GetDeclaredSymbol(node) as INamedTypeSymbol;
            ShaderType shaderType   = mFrontEnd.mCurrentLibrary.FindType(new TypeKey(structSymbol));

            // Primitive types already handled
            if (shaderType != null)
            {
                if (shaderType.IsPrimitiveType())
                {
                    return;
                }
                throw new Exception("Non primitive shader type already existed");
            }

            var attributes = mFrontEnd.ParseAttributes(structSymbol);

            shaderType = CreateShaderType(structSymbol, attributes);
            if (attributes.Contains(typeof(Shader.Vertex)))
            {
                shaderType.mFragmentType = FragmentType.Vertex;
            }
            else if (attributes.Contains(typeof(Shader.Pixel)))
            {
                shaderType.mFragmentType = FragmentType.Pixel;
            }

            shaderType.mMeta.mAttributes = attributes;
            ExtractDebugInfo(shaderType, structSymbol, node);
        }
Esempio n. 2
0
        void GenerateIds(ShaderType shaderType)
        {
            if (mIdMap.ContainsKey(shaderType))
            {
                return;
            }

            // SpirV only allows one instance of a primitive type, but for convenience we allow multiple
            // distinct types that share the same underlying primitive type (e.g. Vector4, Quaternion).
            // To handle this, we dedupe the types to the same underlying id.
            if (shaderType.IsPrimitiveType())
            {
                if (TryDedupePrimitiveType(shaderType))
                {
                    return;
                }
            }

            GetId(shaderType);
            if (shaderType.StorageClassCollection != null)
            {
                GetId(shaderType.FindPointerType(StorageClass.Function));
            }
            foreach (var param in shaderType.mParameters)
            {
                GenerateIds(param);
            }
            foreach (var field in shaderType.mFields)
            {
                GetId(field.mType);
            }
        }