Beispiel #1
0
        public void OnAfterDeserialize()
        {
            if (!System.Enum.TryParse <UniformType>(uniformTypeString, out uniformType))
            {
                uniformType = UniformType.UnkownUniform;
            }

            stages = (VkShaderStageFlagBits)0;
            if (string.IsNullOrEmpty(stagesString) || stagesString == "UnkownStage")
            {
                return;
            }

            string[] enumstrs = stagesString.Split('|');
            foreach (string enumstr in enumstrs)
            {
                if (enumstr == "VertexStage")
                {
                    stages |= VkShaderStageFlagBits.VK_SHADER_STAGE_VERTEX_BIT;
                }
                if (enumstr == "FragmentStage")
                {
                    stages |= VkShaderStageFlagBits.VK_SHADER_STAGE_FRAGMENT_BIT;
                }
            }
        }
Beispiel #2
0
        protected VkPipelineShaderStageCreateInfo loadShader(string fileName, VkShaderStageFlagBits stage)
        {
            VkPipelineShaderStageCreateInfo shaderStage = new VkPipelineShaderStageCreateInfo();

            shaderStage.sType  = PipelineShaderStageCreateInfo;
            shaderStage.stage  = stage;
            shaderStage.module = Tools.loadShader(fileName, device, stage);
            shaderStage.pName  = Strings.main;
            Debug.Assert(shaderStage.module.handle != 0);
            shaderModules.Add(shaderStage.module);
            return(shaderStage);
        }
Beispiel #3
0
        public static VkShaderModule loadShader(string fileName, VkDevice device, VkShaderStageFlagBits stage)
        {
            using (var fs = File.OpenRead(fileName)) {
                var length = fs.Length;
            }
            byte[] shaderCode = File.ReadAllBytes(fileName);
            // Create a new shader module that will be used for Pipeline creation
            VkShaderModuleCreateInfo moduleCreateInfo = new VkShaderModuleCreateInfo();

            moduleCreateInfo.sType = ShaderModuleCreateInfo;
            moduleCreateInfo.code  = shaderCode;
            VkShaderModule module;

            vkCreateShaderModule(device, &moduleCreateInfo, null, &module);

            return(module);
        }
Beispiel #4
0
        public void OnAfterDeserialize()
        {
            stages = (VkShaderStageFlagBits)0;
            if (string.IsNullOrEmpty(stagesString) || stagesString == "UnkownStage")
            {
                return;
            }

            string[] enumstrs = stagesString.Split('|');
            foreach (string enumstr in enumstrs)
            {
                if (enumstr == "VertexStage")
                {
                    stages |= VkShaderStageFlagBits.VK_SHADER_STAGE_VERTEX_BIT;
                }
                if (enumstr == "FragmentStage")
                {
                    stages |= VkShaderStageFlagBits.VK_SHADER_STAGE_FRAGMENT_BIT;
                }
            }
        }
Beispiel #5
0
 public void CmdPushConstants(
     [FromProperty("this")] GenCommandBuffer commandBuffer,
     GenPipelineLayout layout,
     VkShaderStageFlagBits stageFlags,
     int offset,
     int size,
     IntPtr pValues)
 { }
        /// <summary>
        /// SPVシェーダーファイルを読み込んで VkPipelineShaderStageCreateInfo を作成します.
        /// </summary>
        /// <param name="device"></param>
        /// <param name="shaderFile"></param>
        /// <param name="stageFlag"></param>
        /// <returns></returns>
        public static VkPipelineShaderStageCreateInfo CreateShader(VkDevice device, string shaderFile, VkShaderStageFlagBits stageFlag)
        {
            var stageCreateInfo = new VkPipelineShaderStageCreateInfo();

            using (var fs = new FileStream(shaderFile, FileMode.Open, FileAccess.Read))
            {
                var code = new byte[fs.Length];
                fs.Read(code, 0, (int)fs.Length);

                var shaderModuleCreateInfo = new VkShaderModuleCreateInfo()
                {
                    shaderCodeBinary = code,
                };

                VkShaderModule shaderModule;
                VulkanAPI.vkCreateShaderModule(device, ref shaderModuleCreateInfo, out shaderModule);

                stageCreateInfo.flags  = 0;
                stageCreateInfo.stage  = stageFlag;
                stageCreateInfo.pName  = "main";
                stageCreateInfo.module = shaderModule;
            }
            return(stageCreateInfo);
        }
 /// <summary>
 /// VkDescriptorSetLayoutBinding - Structure specifying a descriptor set layout binding
 /// </summary>
 /// <param name="binding">binding is the binding number of this entry and corresponds to a
 /// resource of the same binding number in the shader stages</param>
 /// <param name="descriptorType">descriptorType is a VkDescriptorType specifying which type
 /// of resource descriptors are used for this binding</param>
 /// <param name="descriptorCount">descriptorCount is the number of descriptors contained in the
 /// binding, accessed in a shader as an array
 /// , except if descriptorType is
 /// VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT in which case
 /// descriptorCount is the size in bytes of the inline uniform block
 /// .
 /// If descriptorCount is zero this binding entry is reserved and the
 /// resource must not be accessed from any stage via this binding within
 /// any pipeline using the set layout</param>
 /// <param name="stageFlags">stageFlags member is a bitmask of VkShaderStageFlagBits
 /// specifying which pipeline shader stages can access a resource for this
 /// binding.
 /// VK_SHADER_STAGE_ALL is a shorthand specifying that all defined
 /// shader stages, including any additional stages defined by extensions,
 /// can access the resource</param>
 public VkDescriptorSetLayoutBinding(UInt32 binding, VkDescriptorType descriptorType, UInt32 descriptorCount, VkShaderStageFlagBits stageFlags)
 {
     this.binding            = binding; this.descriptorType = descriptorType;
     this.descriptorCount    = descriptorCount; this.stageFlags = stageFlags;
     this.pImmutableSamplers = null;
 }
Beispiel #8
0
 public void CmdPushConstants(IVkPipelineLayout layout, VkShaderStageFlagBits stageFlags, int offset, int size, IntPtr values)
 {
     var _commandBuffer = Handle;
     var _layout = layout?.Handle ?? VkPipelineLayout.HandleType.Null;
     var _stageFlags = stageFlags;
     var _offset = offset;
     var _size = size;
     var _pValues = values;
     Direct.CmdPushConstants(_commandBuffer, _layout, _stageFlags, _offset, _size, _pValues);
 }