Exemplo n.º 1
0
    def createComputePipeline(self):
        self.__computeShaderModule = self.__device.createShaderModule('shaders/mandelbrot_compute.spv')

        shaderStageCreateInfo = _vk.PipelineShaderStageCreateInfo()
        shaderStageCreateInfo.stage = _vk.VK_SHADER_STAGE_COMPUTE_BIT
        shaderStageCreateInfo.module = self.__computeShaderModule
        shaderStageCreateInfo.name = 'main'

        pipelineLayoutInfo = _vk.PipelineLayoutCreateInfo()
        pipelineLayoutInfo.setLayouts = [self.__descriptorSetLayout, ]
        
        self.__pipelineLayout = self.__device.createPipelineLayout(pipelineLayoutInfo)

        pipelineCreateInfo = _vk.ComputePipelineCreateInfo()
        pipelineCreateInfo.stage = shaderStageCreateInfo
        pipelineCreateInfo.layout = self.__pipelineLayout

        self.__pipeline = self.__device.createComputePipelines(_vk.PipelineCache(), [pipelineCreateInfo, ])[0]
Exemplo n.º 2
0
    def __createGraphicsPipeline(self):
        vertShaderModule = self.__device.createShaderModule(
            'shaders/17_shader_vertexbuffer_vert.spv')
        fragShaderModule = self.__device.createShaderModule(
            'shaders/17_shader_vertexbuffer_frag.spv')

        vertShaderStageInfo = _vk.PipelineShaderStageCreateInfo()
        vertShaderStageInfo.stage = _vk.VK_SHADER_STAGE_VERTEX_BIT
        vertShaderStageInfo.module = vertShaderModule
        vertShaderStageInfo.name = 'main'

        fragShaderStageInfo = _vk.PipelineShaderStageCreateInfo()
        fragShaderStageInfo.stage = _vk.VK_SHADER_STAGE_FRAGMENT_BIT
        fragShaderStageInfo.module = fragShaderModule
        fragShaderStageInfo.name = 'main'

        shaderStages = [vertShaderStageInfo, fragShaderStageInfo]

        vertexInputInfo = _vk.PipelineVertexInputStateCreateInfo()
        vertexInputInfo.vertexBindingDescriptions = [
            Vertex.getBindingDescription(),
        ]
        vertexInputInfo.vertexAttributeDescriptions = Vertex.getAttributeDescriptions(
        )

        inputAssembly = _vk.PipelineInputAssemblyStateCreateInfo()
        inputAssembly.topology = _vk.VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST
        inputAssembly.primitiveRestartEnable = False

        viewport = _vk.Viewport()
        viewport.x = 0.0
        viewport.y = 0.0
        viewport.width = float(self.__swapChainExtent.width)
        viewport.height = float(self.__swapChainExtent.height)
        viewport.minDepth = 0.0
        viewport.maxDepth = 1.0

        scissor = _vk.Rect2D()
        scissor.offset = _vk.Offset2D(0, 0)
        scissor.extent = self.__swapChainExtent

        viewportState = _vk.PipelineViewportStateCreateInfo()
        viewportState.viewports = [
            viewport,
        ]
        viewportState.scissors = [
            scissor,
        ]

        rasterizer = _vk.PipelineRasterizationStateCreateInfo()
        rasterizer.depthClampEnable = False
        rasterizer.rasterizerDiscardEnable = False
        rasterizer.polygonMode = _vk.VK_POLYGON_MODE_FILL
        rasterizer.lineWidth = 1.0
        rasterizer.cullMode = _vk.VK_CULL_MODE_BACK_BIT
        rasterizer.frontFace = _vk.VK_FRONT_FACE_CLOCKWISE
        rasterizer.depthBiasEnable = False

        multisampling = _vk.PipelineMultisampleStateCreateInfo()
        multisampling.sampleShadingEnable = False
        multisampling.rasterizationSamples = _vk.VK_SAMPLE_COUNT_1_BIT

        colorBlendAttachment = _vk.PipelineColorBlendAttachmentState()
        colorBlendAttachment.colorWriteMask = _vk.VK_COLOR_COMPONENT_R_BIT | _vk.VK_COLOR_COMPONENT_G_BIT | _vk.VK_COLOR_COMPONENT_B_BIT | _vk.VK_COLOR_COMPONENT_A_BIT
        colorBlendAttachment.blendEnable = False

        colorBlending = _vk.PipelineColorBlendStateCreateInfo()
        colorBlending.logicOpEnable = False
        colorBlending.logicOp = _vk.VK_LOGIC_OP_COPY
        colorBlending.attachments = [
            colorBlendAttachment,
        ]
        colorBlending.blendConstants = [0.0, 0.0, 0.0, 0.0]

        pipelineLayoutInfo = _vk.PipelineLayoutCreateInfo()

        self.__pipelineLayout = self.__device.createPipelineLayout(
            pipelineLayoutInfo)

        pipelineInfo = _vk.GraphicsPipelineCreateInfo()
        pipelineInfo.stages = shaderStages
        pipelineInfo.vertexInputState = vertexInputInfo
        pipelineInfo.inputAssemblyState = inputAssembly
        pipelineInfo.viewportState = viewportState
        pipelineInfo.rasterizationState = rasterizer
        pipelineInfo.multisampleState = multisampling
        pipelineInfo.colorBlendState = colorBlending
        pipelineInfo.layout = self.__pipelineLayout
        pipelineInfo.renderPass = self.__renderPass
        pipelineInfo.subpass = 0
        #pipelineInfo.basePipelineHandle = _vk.Pipeline()

        graphicsPipelines = self.__device.createGraphicsPipelines(
            _vk.PipelineCache(), [
                pipelineInfo,
            ])
        self.__graphicsPipeline = graphicsPipelines[0]

        del vertShaderModule
        del fragShaderModule