예제 #1
0
    def __createCommandBuffers(self):
        allocInfo = _vk.CommandBufferAllocateInfo()
        allocInfo.commandPool = self.__commandPool
        allocInfo.level = _vk.VK_COMMAND_BUFFER_LEVEL_PRIMARY
        allocInfo.commandBufferCount = len(self.__swapChainFramebuffers)

        self.__commandBuffers = self.__device.allocateCommandBuffers(allocInfo)

        for i in range(len(self.__commandBuffers)):
            cmdBuffer = self.__commandBuffers[i]
            print("commandBuffer is valid: {}".format(cmdBuffer.isValid))

            beginInfo = _vk.CommandBufferBeginInfo()
            beginInfo.flags = _vk.VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT

            cmdBuffer.begin(beginInfo)

            renderPassInfo = _vk.RenderPassBeginInfo()
            renderPassInfo.renderPass = self.__renderPass
            renderPassInfo.framebuffer = self.__swapChainFramebuffers[i]
            renderPassInfo.renderArea.offset = _vk.Offset2D(0, 0)
            renderPassInfo.renderArea.extent = self.__swapChainExtent
            renderPassInfo.clearValues = [_vk.ClearValue(_vk.ClearColorValue(0.0, 0.0, 0.0, 1.0)),]

            cmdBuffer.beginRenderPass(renderPassInfo, _vk.VK_SUBPASS_CONTENTS_INLINE)

            cmdBuffer.bindPipeline(_vk.VK_PIPELINE_BIND_POINT_GRAPHICS, self.__graphicsPipeline)

            cmdBuffer.draw(3, 1, 0, 0)

            cmdBuffer.endRenderPass()

            cmdBuffer.end()
            #i += 1
            print("commandBuffer is valid: {}".format(cmdBuffer.isValid))
예제 #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
예제 #3
0
    def __createGraphicsPipeline(self):
        vertShaderModule = self.__device.createShaderModule('shaders/09_shader_base_vert.spv')
        fragShaderModule = self.__device.createShaderModule('shaders/09_shader_base_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()
        
        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)
        print("pipeline layout is valid: {}".format(self.__pipelineLayout.isValid))

        del vertShaderModule
        del fragShaderModule