상속: MidType, IMidMemberRef
예제 #1
0
 public MidBuiltinTypeDecl(
     IBuilder parent,
     string name,
     IEnumerable <object> args,
     IEnumerable <ResBuiltinTag> tags)
     : base(parent)
 {
     _type = new MidBuiltinType(name, args, tags);
 }
예제 #2
0
 private static void DumpTypeImpl(
     MidBuiltinType builtin,
     Span span)
 {
     span.Write("{0}", builtin.Name);
     if (builtin.Args.Length != 0)
     {
         span.Write("[");
         span.Add(from a in builtin.Args select((MidType)a).Dump(), ", ");
         span.Write("]");
     }
 }
        private ITypeHLSL EmitTypeImpl(MidBuiltinType type)
        {
            var template = type.GetTemplate("hlsl");
            if (template == null)
            {
                Diagnostics.Add(
                    Severity.Error,
                    new SourceRange(),
                    "No HLSL equivalent for type {0}", type);
                return new ErrorTypeHLSL();
            }
            if (type.Args == null)
                return new ScalarTypeHLSL(template);

            var args = (from a in type.Args
                        select EmitGenericArg(a)).Eager();

            // I hate hacks... :(
            if (template == "__Array")
            {
                var baseType = (EmitTypeHLSL)args[0];
                var count = (EmitValHLSL)args[1];

                return MakeArrayType(
                    baseType,
                    count);
            }

            return new ScalarTypeHLSL(string.Format(template, args));
        }
        private int CountSlotsImpl(MidBuiltinType builtin)
        {
            switch (builtin.Name)
            {
                case "uint": return 1;
                case "uint2": return 1;
                case "uint3": return 1;
                case "uint4": return 1;
                case "float": return 1;
                case "float2": return 1;
                case "float3": return 1;
                case "float4": return 1;
                case "float4x4": return 4;
                case "Array":
                    {
                        var args = builtin.Args.ToArray();
                        var elementType = ((MidType)args[0]);
                        var elementTypeSlots = CountSlots(elementType);
                        var elementCountVal = ((MidVal)args[1]);

                        var elementCount = GetIntLit(elementCountVal);

                        return elementCount * elementTypeSlots;
                    }
                default:
                    throw new NotImplementedException();
            }
        }
        private EmitValHLSL EmitShaderResourceRef(
            MidBuiltinType type,
            MidVal uniformVal,
            Span span)
        {
            object key = GetUniformValKey(uniformVal);
            EmitValHLSL result = VoidVal;
            if (_uniformResourceCache.TryGetValue(key, out result))
            {
                return result;
            }

            int index = _shaderResources.Count;
            string name = _shared.GenerateName(uniformVal.ToString());

            DeclareFields(
                EmitType(type),
                _resourceHeaderSpan,
                name,
                suffix: string.Format(" : register(t{0})", index));
            _shaderResources.Add(uniformVal);

            result = new SimpleValHLSL(
                name,
                (SimpleTypeHLSL)EmitType(uniformVal.Type));
            _uniformResourceCache[key] = result;
            return result;
        }
예제 #6
0
 public MidBuiltinTypeDecl(
     IBuilder parent,
     string name,
     IEnumerable<object> args,
     IEnumerable<ResBuiltinTag> tags )
     : base(parent)
 {
     _type = new MidBuiltinType(name, args, tags);
 }
예제 #7
0
 private SizeInfo GetSizeInfoImpl(MidBuiltinType type)
 {
     switch (type.Name)
     {
         case "ubyte4": return new SizeInfo { Size = 1 * 4, Align = 4 };
         case "unorm4": return new SizeInfo { Size = 1 * 4, Align = 4 };
         case "float2": return new SizeInfo { Size = 2 * 4, Align = 4 };
         case "Tangent":
         case "float3": return new SizeInfo { Size = 3 * 4, Align = 4 };
         case "float4": return new SizeInfo { Size = 4 * 4, Align = 4 };
         default:
             throw new NotImplementedException();
     }
 }
        private IEmitVal MapBuiltinTypeFormat(MidBuiltinType type)
        {
            switch (type.Name)
            {
                case "int":
                    return InitBlock.Enum32("DXGI_FORMAT", "DXGI_FORMAT_R32_SINT", DXGI_FORMAT.DXGI_FORMAT_R32_SINT);
                case "float2":
                    return InitBlock.Enum32("DXGI_FORMAT", "DXGI_FORMAT_R32G32_FLOAT", DXGI_FORMAT.DXGI_FORMAT_R32G32_FLOAT);
                case "float3":
                case "Tangent":
                    return InitBlock.Enum32("DXGI_FORMAT", "DXGI_FORMAT_R32G32B32_FLOAT", DXGI_FORMAT.DXGI_FORMAT_R32G32B32_FLOAT);
                case "float4":
                    return InitBlock.Enum32("DXGI_FORMAT", "DXGI_FORMAT_R32G32B32A32_FLOAT", DXGI_FORMAT.DXGI_FORMAT_R32G32B32A32_FLOAT);

                case "ubyte4":
                    return InitBlock.Enum32("DXGI_FORMAT", "DXGI_FORMAT_R8G8B8A8_UINT", DXGI_FORMAT.DXGI_FORMAT_R8G8B8A8_UINT);
                case "unorm4":
                    return InitBlock.Enum32("DXGI_FORMAT", "DXGI_FORMAT_R8G8B8A8_UNORM", DXGI_FORMAT.DXGI_FORMAT_R8G8B8A8_UNORM);

                default:
                    throw new NotImplementedException();
            }
        }
        private AttributeInfo GenerateInputElementsImpl(
            SourceRange range,
            string name,
            MidBuiltinType type,
            int vertexStream,
            IndexSourceInfo index,
            UInt32 baseOffset,
            int inputSlotIndex)
        {
            var format = MapBuiltinTypeFormat(type);

            return new InputElementInfo(range)
            {
                Name = name,
                Format = format,
                ByteOffset = baseOffset,
                Index = index,
                InputSlotIndex = inputSlotIndex,
            };
        }