void setupVertexDescriptions() { // Binding description vertices_bindingDescriptions.Count = 1; vertices_bindingDescriptions[0] = Initializers.vertexInputBindingDescription( VERTEX_BUFFER_BIND_ID, (uint)sizeof(Vertex), VkVertexInputRate.Vertex); // Attribute descriptions // Describes memory layout and shader positions vertices_attributeDescriptions.Count = 4; // Location 0 : Position vertices_attributeDescriptions[0] = Initializers.vertexInputAttributeDescription( VERTEX_BUFFER_BIND_ID, 0, VkFormat.R32g32b32Sfloat, Vertex.PositionOffset); // Location 1 : Normal vertices_attributeDescriptions[1] = Initializers.vertexInputAttributeDescription( VERTEX_BUFFER_BIND_ID, 1, VkFormat.R32g32b32Sfloat, Vertex.NormalOffset); // Location 2 : Texture coordinates vertices_attributeDescriptions[2] = Initializers.vertexInputAttributeDescription( VERTEX_BUFFER_BIND_ID, 2, VkFormat.R32g32Sfloat, Vertex.UvOffset); // Location 3 : Color vertices_attributeDescriptions[3] = Initializers.vertexInputAttributeDescription( VERTEX_BUFFER_BIND_ID, 3, VkFormat.R32g32b32Sfloat, Vertex.ColorOffset); vertices_inputState = Initializers.pipelineVertexInputStateCreateInfo(); vertices_inputState.vertexBindingDescriptionCount = (vertices_bindingDescriptions.Count); vertices_inputState.pVertexBindingDescriptions = (VkVertexInputBindingDescription *)vertices_bindingDescriptions.Data; vertices_inputState.vertexAttributeDescriptionCount = (vertices_attributeDescriptions.Count); vertices_inputState.pVertexAttributeDescriptions = (VkVertexInputAttributeDescription *)vertices_attributeDescriptions.Data; }
void setupVertexDescriptions() { // Binding description vertices_bindingDescriptions.Count = 1; vertices_bindingDescriptions[0] = Initializers.vertexInputBindingDescription( VERTEX_BUFFER_BIND_ID, vertexLayout.stride(), VK_VERTEX_INPUT_RATE_VERTEX); // Attribute descriptions vertices_attributeDescriptions.Count = 4; // Location 0 : Position vertices_attributeDescriptions[0] = Initializers.vertexInputAttributeDescription( VERTEX_BUFFER_BIND_ID, 0, VK_FORMAT_R32G32B32_SFLOAT, 0); // Location 1 : Texture coordinates vertices_attributeDescriptions[1] = Initializers.vertexInputAttributeDescription( VERTEX_BUFFER_BIND_ID, 1, VK_FORMAT_R32G32_SFLOAT, sizeof(float) * 3); // Location 2 : Color vertices_attributeDescriptions[2] = Initializers.vertexInputAttributeDescription( VERTEX_BUFFER_BIND_ID, 2, VK_FORMAT_R32G32B32_SFLOAT, sizeof(float) * 5); // Location 3 : Normal vertices_attributeDescriptions[3] = Initializers.vertexInputAttributeDescription( VERTEX_BUFFER_BIND_ID, 3, VK_FORMAT_R32G32B32_SFLOAT, sizeof(float) * 8); vertices_inputState = Initializers.pipelineVertexInputStateCreateInfo(); vertices_inputState.vertexBindingDescriptionCount = vertices_bindingDescriptions.Count; vertices_inputState.pVertexBindingDescriptions = (VkVertexInputBindingDescription *)vertices_bindingDescriptions.Data; vertices_inputState.vertexAttributeDescriptionCount = vertices_attributeDescriptions.Count; vertices_inputState.pVertexAttributeDescriptions = (VkVertexInputAttributeDescription *)vertices_attributeDescriptions.Data; }
void setupVertexDescriptions() { // Binding description vertices.bindingDescriptions.Count = 1; vertices.bindingDescriptions[0] = Initializers.vertexInputBindingDescription( VERTEX_BUFFER_BIND_ID, vertexLayout.GetStride(), VkVertexInputRate.Vertex); // Attribute descriptions // Describes memory layout and shader positions vertices.attributeDescriptions.Count = 3; // Location 0 : Position vertices.attributeDescriptions[0] = Initializers.vertexInputAttributeDescription( VERTEX_BUFFER_BIND_ID, 0, VkFormat.R32g32b32Sfloat, 0); // Location 1 : Normal vertices.attributeDescriptions[1] = Initializers.vertexInputAttributeDescription( VERTEX_BUFFER_BIND_ID, 1, VkFormat.R32g32b32Sfloat, sizeof(float) * 3); // Location 2 : Texture coordinates vertices.attributeDescriptions[2] = Initializers.vertexInputAttributeDescription( VERTEX_BUFFER_BIND_ID, 2, VkFormat.R32g32Sfloat, sizeof(float) * 5); vertices.inputState = Initializers.pipelineVertexInputStateCreateInfo(); vertices.inputState.vertexBindingDescriptionCount = vertices.bindingDescriptions.Count; vertices.inputState.pVertexBindingDescriptions = (VkVertexInputBindingDescription*)vertices.bindingDescriptions.Data; vertices.inputState.vertexAttributeDescriptionCount = vertices.attributeDescriptions.Count; vertices.inputState.pVertexAttributeDescriptions = (VkVertexInputAttributeDescription*)vertices.attributeDescriptions.Data; }
void setupVertexDescriptions() { // Binding description vertices_bindingDescriptions = new NativeList <VkVertexInputBindingDescription> { Initializers.vertexInputBindingDescription(VERTEX_BUFFER_BIND_ID, (uint)sizeof(Vertex), VK_VERTEX_INPUT_RATE_VERTEX), }; // Attribute descriptions vertices_attributeDescriptions = new NativeList <VkVertexInputAttributeDescription> { Initializers.vertexInputAttributeDescription(VERTEX_BUFFER_BIND_ID, 0, VK_FORMAT_R32G32B32_SFLOAT, 0), // Location 0 : Position Initializers.vertexInputAttributeDescription(VERTEX_BUFFER_BIND_ID, 1, VK_FORMAT_R32G32B32_SFLOAT, (uint)sizeof(Vector3)), // Location 1 : Color }; vertices_inputState = Initializers.pipelineVertexInputStateCreateInfo(); vertices_inputState.vertexBindingDescriptionCount = vertices_bindingDescriptions.Count; vertices_inputState.pVertexBindingDescriptions = (VkVertexInputBindingDescription *)vertices_bindingDescriptions.Data; vertices_inputState.vertexAttributeDescriptionCount = vertices_attributeDescriptions.Count; vertices_inputState.pVertexAttributeDescriptions = (VkVertexInputAttributeDescription *)vertices_attributeDescriptions.Data; }
void preparePipelines() { VkPipelineInputAssemblyStateCreateInfo inputAssemblyState = Initializers.pipelineInputAssemblyStateCreateInfo( VkPrimitiveTopology.TriangleList, 0, False); VkPipelineRasterizationStateCreateInfo rasterizationState = Initializers.pipelineRasterizationStateCreateInfo( VkPolygonMode.Fill, VkCullModeFlags.Back, VkFrontFace.Clockwise, 0); VkPipelineColorBlendAttachmentState blendAttachmentState = Initializers.pipelineColorBlendAttachmentState( (VkColorComponentFlags)0xf, False); VkPipelineColorBlendStateCreateInfo colorBlendState = Initializers.pipelineColorBlendStateCreateInfo( 1, &blendAttachmentState); VkPipelineDepthStencilStateCreateInfo depthStencilState = Initializers.pipelineDepthStencilStateCreateInfo( True, True, VkCompareOp.LessOrEqual); VkPipelineViewportStateCreateInfo viewportState = Initializers.pipelineViewportStateCreateInfo(1, 1, 0); VkPipelineMultisampleStateCreateInfo multisampleState = Initializers.pipelineMultisampleStateCreateInfo(VkSampleCountFlags._1); FixedArray3 <VkDynamicState> dynamicStateEnables = new FixedArray3 <VkDynamicState>( VkDynamicState.Viewport, VkDynamicState.Scissor, VkDynamicState.LineWidth); VkPipelineDynamicStateCreateInfo dynamicState = Initializers.pipelineDynamicStateCreateInfo((VkDynamicState *)Unsafe.AsPointer(ref dynamicStateEnables), dynamicStateEnables.Count); VkGraphicsPipelineCreateInfo pipelineCreateInfo = Initializers.pipelineCreateInfo(pipelineLayout, RenderPass); FixedArray2 <VkPipelineShaderStageCreateInfo> shaderStages = new FixedArray2 <VkPipelineShaderStageCreateInfo>(); shaderStages.First = loadShader(getAssetPath() + "shaders/pipelines/phong.vert.spv", VkShaderStageFlags.Vertex); shaderStages.Second = loadShader(getAssetPath() + "shaders/pipelines/phong.frag.spv", VkShaderStageFlags.Fragment); pipelineCreateInfo.pInputAssemblyState = &inputAssemblyState; pipelineCreateInfo.pRasterizationState = &rasterizationState; pipelineCreateInfo.pColorBlendState = &colorBlendState; pipelineCreateInfo.pMultisampleState = &multisampleState; pipelineCreateInfo.pViewportState = &viewportState; pipelineCreateInfo.pDepthStencilState = &depthStencilState; pipelineCreateInfo.pDynamicState = &dynamicState; pipelineCreateInfo.stageCount = shaderStages.Count; pipelineCreateInfo.pStages = (VkPipelineShaderStageCreateInfo *)Unsafe.AsPointer(ref shaderStages); // Shared vertex bindings and attributes used by all pipelines // Binding description VkVertexInputBindingDescription vertexInputBindings = Initializers.vertexInputBindingDescription(VERTEX_BUFFER_BIND_ID, vertexLayout.GetStride(), VkVertexInputRate.Vertex); // Attribute descriptions FixedArray4 <VkVertexInputAttributeDescription> vertexInputAttributes = new FixedArray4 <VkVertexInputAttributeDescription> { First = Initializers.vertexInputAttributeDescription(VERTEX_BUFFER_BIND_ID, 0, VkFormat.R32g32b32Sfloat, 0), // Location 0: Position Second = Initializers.vertexInputAttributeDescription(VERTEX_BUFFER_BIND_ID, 1, VkFormat.R32g32b32Sfloat, sizeof(float) * 3), // Location 1: Color Third = Initializers.vertexInputAttributeDescription(VERTEX_BUFFER_BIND_ID, 2, VkFormat.R32g32Sfloat, sizeof(float) * 6), // Location 2 : Texture coordinates Fourth = Initializers.vertexInputAttributeDescription(VERTEX_BUFFER_BIND_ID, 3, VkFormat.R32g32b32Sfloat, sizeof(float) * 8), // Location 3 : Normal }; VkPipelineVertexInputStateCreateInfo vertexInputState = VkPipelineVertexInputStateCreateInfo.New(); vertexInputState.vertexBindingDescriptionCount = 1; vertexInputState.pVertexBindingDescriptions = &vertexInputBindings; vertexInputState.vertexAttributeDescriptionCount = vertexInputAttributes.Count; vertexInputState.pVertexAttributeDescriptions = (VkVertexInputAttributeDescription *)Unsafe.AsPointer(ref vertexInputAttributes); pipelineCreateInfo.pVertexInputState = &vertexInputState; // Create the graphics pipeline state objects // We are using this pipeline as the base for the other pipelines (derivatives) // Pipeline derivatives can be used for pipelines that share most of their state // Depending on the implementation this may result in better performance for pipeline // switchting and faster creation time pipelineCreateInfo.flags = VkPipelineCreateFlags.AllowDerivatives; // Textured pipeline // Phong shading pipeline shaderStages.First = loadShader(getAssetPath() + "shaders/pipelines/phong.vert.spv", VkShaderStageFlags.Vertex); shaderStages.Second = loadShader(getAssetPath() + "shaders/pipelines/phong.frag.spv", VkShaderStageFlags.Fragment); Util.CheckResult(vkCreateGraphicsPipelines(Device, PipelineCache, 1, ref pipelineCreateInfo, null, out pipelines_phong)); // All pipelines created after the base pipeline will be derivatives pipelineCreateInfo.flags = VkPipelineCreateFlags.Derivative; // Base pipeline will be our first created pipeline pipelineCreateInfo.basePipelineHandle = pipelines_phong; // It's only allowed to either use a handle or index for the base pipeline // As we use the handle, we must set the index to -1 (see section 9.5 of the specification) pipelineCreateInfo.basePipelineIndex = -1; // Toon shading pipeline shaderStages.First = loadShader(getAssetPath() + "shaders/pipelines/toon.vert.spv", VkShaderStageFlags.Vertex); shaderStages.Second = loadShader(getAssetPath() + "shaders/pipelines/toon.frag.spv", VkShaderStageFlags.Fragment); Util.CheckResult(vkCreateGraphicsPipelines(Device, PipelineCache, 1, ref pipelineCreateInfo, null, out pipelines_toon)); // Pipeline for wire frame rendering // Non solid rendering is not a mandatory Vulkan feature if (DeviceFeatures.fillModeNonSolid != 0) { rasterizationState.polygonMode = VkPolygonMode.Line; shaderStages.First = loadShader(getAssetPath() + "shaders/pipelines/wireframe.vert.spv", VkShaderStageFlags.Vertex); shaderStages.Second = loadShader(getAssetPath() + "shaders/pipelines/wireframe.frag.spv", VkShaderStageFlags.Fragment); Util.CheckResult(vkCreateGraphicsPipelines(Device, PipelineCache, 1, ref pipelineCreateInfo, null, out pipelines_wireframe)); } }