Пример #1
0
        public ShaderReflection WithEntryPoint(Spv.ExecutionModel executionModel, Function value, string name = null)
        {
            var interfaceCollector = new InterfaceCollector();

            interfaceCollector.Visit(value);
            return(this.With(new EntryPoint(executionModel, value, name ?? value.DebugName ?? "main", interfaceCollector.Inputs.Concat(interfaceCollector.Outputs).Concat(interfaceCollector.Uniforms))));
        }
Пример #2
0
 public EntryPoint(Spv.ExecutionModel executionModel, Function value, string name, IEnumerable <Node> @interface, string debugName = null)
 {
     this.ExecutionModel = executionModel;
     this.Value          = value;
     this.Name           = name;
     if (@interface != null)
     {
         foreach (var node in @interface)
         {
             this.Interface.Add(node);
         }
     }
     DebugName = debugName;
 }
Пример #3
0
        void WriteHeader()
        {
            mWriter.Write(MagicNumber);
            mWriter.Write(0, 1, 4, 0);
            mWriter.Write(0);
            mWriter.Write(IdGenerator.Count + 1);
            mWriter.Write(0);

            // Capabilities
            mWriter.WriteInstruction(2, Spv.Op.OpCapability, (UInt32)Spv.Capability.CapabilityShader);
            mWriter.WriteInstruction(2, Spv.Op.OpCapability, (UInt32)Spv.Capability.CapabilityLinkage);
            foreach (var capability in mTypeCollector.RequiredCapabilities)
            {
                mWriter.WriteInstruction(2, Spv.Op.OpCapability, (UInt32)capability);
            }

            // Extension Instance Imports
            foreach (var extLibraryImport in mTypeCollector.mReferencedExtensionLibraryImports)
            {
                var    byteCount = mWriter.GetPaddedByteCount(extLibraryImport.ExtensionLibraryName);
                var    wordCount = byteCount / 4;
                UInt16 totalSize = (UInt16)(2 + wordCount);
                mWriter.WriteInstruction(totalSize, Spv.Op.OpExtInstImport, GetId(extLibraryImport));
                mWriter.Write(extLibraryImport.ExtensionLibraryName);
            }
            // Memory Models
            mWriter.WriteInstruction(3, Spv.Op.OpMemoryModel, (UInt32)Spv.AddressingModel.AddressingModelLogical, (UInt32)Spv.MemoryModel.MemoryModelGLSL450);
            // EntryPoints
            foreach (var entryPoint in mTypeCollector.mEntryPoints)
            {
                var    entryPointFn   = entryPoint.mEntryPointFunction;
                var    entryPointId   = GetId(entryPointFn);
                var    entryPointName = entryPointFn.DebugInfo.Name;
                var    byteCount      = mWriter.GetPaddedByteCount(entryPointName);
                var    wordCount      = byteCount / 4;
                var    interfaceSize  = entryPoint.mGlobalVariablesBlock.mLocalVariables.Count + entryPoint.mInterfaceVariables.mLocalVariables.Count;
                UInt16 totalSize      = (UInt16)(3 + wordCount + interfaceSize);

                Spv.ExecutionModel executionModel = Spv.ExecutionModel.ExecutionModelFragment;
                if (entryPoint.mStageType == FragmentType.Vertex)
                {
                    executionModel = Spv.ExecutionModel.ExecutionModelVertex;
                }
                else if (entryPoint.mStageType == FragmentType.Pixel)
                {
                    executionModel = Spv.ExecutionModel.ExecutionModelFragment;
                }

                mWriter.WriteInstruction(totalSize, Spv.Op.OpEntryPoint, (UInt32)executionModel, entryPointId);
                mWriter.Write(entryPointFn.DebugInfo.Name);
                foreach (var interfaceVar in entryPoint.mGlobalVariablesBlock.mLocalVariables)
                {
                    mWriter.Write(GetId(interfaceVar));
                }
                foreach (var interfaceVar in entryPoint.mInterfaceVariables.mLocalVariables)
                {
                    mWriter.Write(GetId(interfaceVar));
                }
            }
            // ExecutionMode (per entry point)
            foreach (var entryPoint in mTypeCollector.mEntryPoints)
            {
                WriteBlockInstructions(entryPoint.mExecutionModesBlock, entryPoint.mExecutionModesBlock.mOps);
            }

            mWriter.WriteInstruction(3, Spv.Op.OpSource, 0, 100);

            var capabilities = new HashSet <Spv.Capability>();
            //foreach(var entryPoint in mTypeCollector.mEntryPoints)
            //{
            //  foreach(var capability in entryPoint.m)
            //}
        }
Пример #4
0
 public ShaderReflection WithEntryPoint(Spv.ExecutionModel executionModel, Function value, string name, IEnumerable <Node> @interface)
 {
     return(this.With(new EntryPoint(executionModel, value, name, @interface)));
 }