コード例 #1
0
ファイル: fn_buffer_object.cpp プロジェクト: YoutaVen/Vulkan
IBufferObjectSP VKTS_APIENTRY bufferObjectCreate(const IInitialResourcesSP& initialResources, const VkBufferCreateInfo& bufferCreateInfo, const VkMemoryPropertyFlags memoryPropertyFlag)
{
    if (!initialResources.get())
    {
        return IBufferObjectSP();
    }

    //

    IBufferSP buffer;

    IDeviceMemorySP deviceMemory;

    if (!bufferObjectPrepare(buffer, deviceMemory, initialResources, bufferCreateInfo, memoryPropertyFlag))
    {
        return IBufferObjectSP();
    }

    //

    IBufferViewSP noBufferView;

    auto newInstance = new BufferObject(initialResources, buffer, noBufferView, deviceMemory);

    if (!newInstance)
    {
        buffer->destroy();

        return IBufferObjectSP();
    }

    return IBufferObjectSP(newInstance);
}
コード例 #2
0
ファイル: fn_buffer_object.cpp プロジェクト: YoutaVen/Vulkan
IBufferObjectSP VKTS_APIENTRY bufferObjectCreate(const IInitialResourcesSP& initialResources, const VkBufferCreateInfo& bufferCreateInfo, const VkMemoryPropertyFlags memoryPropertyFlag, const VkFormat format)
{
    if (!initialResources.get())
    {
        return IBufferObjectSP();
    }

    //

    IBufferSP buffer;

    IDeviceMemorySP deviceMemory;

    if (!bufferObjectPrepare(buffer, deviceMemory, initialResources, bufferCreateInfo, memoryPropertyFlag))
    {
        return IBufferObjectSP();
    }

    //

    auto bufferView = bufferViewCreate(initialResources->getDevice()->getDevice(), 0, buffer->getBuffer(), format, 0, bufferCreateInfo.size);

    if (!bufferView.get())
    {
        buffer->destroy();

        return IBufferObjectSP();
    }

    //

    auto newInstance = new BufferObject(initialResources, buffer, bufferView, deviceMemory);

    if (!newInstance)
    {
        bufferView->destroy();

        buffer->destroy();

        return IBufferObjectSP();
    }

    return IBufferObjectSP(newInstance);
}
コード例 #3
0
ファイル: fn_buffer_object.cpp プロジェクト: YoutaVen/Vulkan
IBufferObjectSP VKTS_APIENTRY bufferObjectCreate(IBufferSP& stageBuffer, IDeviceMemorySP& stageDeviceMemory, const IInitialResourcesSP& initialResources, const ICommandBuffersSP& cmdBuffer, const IBinaryBufferSP& binaryBuffer, const VkBufferCreateInfo& bufferCreateInfo, const VkMemoryPropertyFlags memoryPropertyFlag)
{
    if (!initialResources.get() || !cmdBuffer.get() || !binaryBuffer.get())
    {
        return IBufferObjectSP();
    }

    //

    VkResult result;

    //

    IBufferSP buffer;

    IDeviceMemorySP deviceMemory;

    if (!bufferObjectPrepare(buffer, deviceMemory, initialResources, bufferCreateInfo, memoryPropertyFlag))
    {
        return IBufferObjectSP();
    }

    //

    if (memoryPropertyFlag & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT)
    {
        result = deviceMemory->upload(0, deviceMemory->getAllocationSize(), 0, binaryBuffer->getData(), binaryBuffer->getSize());

        if (result != VK_SUCCESS)
        {
            logPrint(VKTS_LOG_ERROR, "BufferObject: Could not upload vertex data.");

            return IBufferObjectSP();
        }
    }
    else
    {
        if (!bufferObjectPrepare(stageBuffer, stageDeviceMemory, initialResources, bufferCreateInfo, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT))
        {
            logPrint(VKTS_LOG_ERROR, "BufferObject: Could not create vertex buffer.");

            return IBufferObjectSP();
        }

        result = stageDeviceMemory->upload(0, stageDeviceMemory->getAllocationSize(), 0, binaryBuffer->getData(), binaryBuffer->getSize());

        if (result != VK_SUCCESS)
        {
            logPrint(VKTS_LOG_ERROR, "BufferObject: Could not upload vertex data.");

            return IBufferObjectSP();
        }

        VkBufferCopy bufferCopy;

        bufferCopy.srcOffset = 0;
        bufferCopy.dstOffset = 0;
        bufferCopy.size = binaryBuffer->getSize();

        stageBuffer->copyBuffer(cmdBuffer->getCommandBuffer(), buffer->getBuffer(), buffer->getSize(), 1, &bufferCopy);
    }

    //

    IBufferViewSP noBufferView;

    auto newInstance = new BufferObject(initialResources, buffer, noBufferView, deviceMemory);

    if (!newInstance)
    {
        buffer->destroy();

        return IBufferObjectSP();
    }

    return IBufferObjectSP(newInstance);
}