Beispiel #1
0
 public void FindField(ShaderType owningType, string fieldName, out ShaderField shaderField, out int fieldIndex)
 {
     FindInstanceField(owningType, fieldName, out shaderField, out fieldIndex);
     if (shaderField == null)
     {
         GlobalShaderField globalShaderField;
         FindStaticField(owningType, fieldName, out globalShaderField, out fieldIndex);
         shaderField = globalShaderField;
     }
 }
Beispiel #2
0
        public ShaderField CreateField(ShaderType owningType, ShaderType fieldType, string name, IShaderIR initializerExpression)
        {
            var shaderField = new ShaderField();

            shaderField.mMeta          = new ShaderFieldMeta();
            shaderField.mType          = fieldType;
            shaderField.mMeta.mName    = name;
            shaderField.DebugInfo.Name = name;
            owningType.mFields.Add(shaderField);

            return(shaderField);
        }
 IShaderIR GetInitialValue(VariableDeclaratorSyntax variable, ShaderField shaderField)
 {
     // If this field has an initializer expression then walk and visit it.
     if (variable.Initializer != null)
     {
         return(mCommonPass.WalkAndGetValueTypeResult(variable.Initializer));
     }
     // Otherwise, build the default value based upon the type.
     else
     {
         return(GenerateDefaultValueOp(shaderField));
     }
 }
        void WriteFieldDebugName(ShaderType owningType, int memberIndex, ShaderField field, string debugName)
        {
            if (string.IsNullOrEmpty(debugName))
            {
                return;
            }

            var wordCount       = mWriter.GetPaddedWordCount(debugName);
            var instructionSize = (UInt16)(3 + wordCount);

            mWriter.WriteInstruction(instructionSize, Spv.Op.OpMemberName);
            mWriter.Write(GetId(owningType));
            mWriter.Write(memberIndex);
            mWriter.Write(debugName);
        }
        ShaderOp GenerateDefaultValueOp(ShaderField shaderField)
        {
            var shaderFieldDerefType = shaderField.mType.GetDereferenceType();

            if (shaderFieldDerefType == FindType(typeof(bool)))
            {
                return(mFrontEnd.CreateConstantOp(shaderFieldDerefType, false));
            }
            else if (shaderFieldDerefType == FindType(typeof(int)))
            {
                var contantLiteral = mFrontEnd.CreateConstantLiteral(0);
                return(mFrontEnd.CreateConstantOp(shaderFieldDerefType, contantLiteral));
            }
            else if (shaderFieldDerefType == FindType(typeof(uint)))
            {
                var contantLiteral = mFrontEnd.CreateConstantLiteral(0u);
                return(mFrontEnd.CreateConstantOp(shaderFieldDerefType, contantLiteral));
            }
            else if (shaderFieldDerefType == FindType(typeof(float)))
            {
                var contantLiteral = mFrontEnd.CreateConstantLiteral(shaderFieldDerefType, 0.0f.ToString());
                return(mFrontEnd.CreateConstantOp(shaderFieldDerefType, contantLiteral));
            }
            else if (shaderFieldDerefType.mBaseType == OpType.Struct)
            {
                var fieldPtrType    = shaderFieldDerefType.FindPointerType(StorageClass.Function);
                var localVariableOp = mFrontEnd.CreateOpVariable(fieldPtrType, mContext);
                localVariableOp.DebugInfo.Name = "temp" + shaderFieldDerefType.mMeta.mName;

                var resultType = FindType(typeof(void));
                var fnCall     = CreateOp(mContext.mCurrentBlock, OpInstructionType.OpFunctionCall, resultType, new List <IShaderIR> {
                    shaderFieldDerefType.mImplicitConstructor, localVariableOp
                });
                var loadOp = mFrontEnd.CreateOp(mContext.mCurrentBlock, OpInstructionType.OpLoad, shaderFieldDerefType, new List <IShaderIR> {
                    localVariableOp
                });
                return(loadOp);
            }
            return(null);
        }
Beispiel #6
0
 public void Visit(ShaderField field)
 {
     Visit(field.mType);
 }
Beispiel #7
0
 public void ExtractDebugInfo(ShaderField field, ISymbol symbol, SyntaxNode node)
 {
     field.DebugInfo.Name     = symbol.Name;
     field.DebugInfo.Location = node.GetLocation();
 }
Beispiel #8
0
 public FieldKey(ShaderField field)
 {
     mKey = $"{field.mType.mMeta.mName}_{field.mMeta.mName}";
 }
Beispiel #9
0
 public void FindInstanceField(ShaderType owningType, string fieldName, out ShaderField shaderField, out int fieldIndex)
 {
     FindField(owningType.mFields, fieldName, out shaderField, out fieldIndex);
 }