in RenderScriptMigrationSample/app/src/main/cpp/ImageProcessor.cpp [83:121]
bool ImageProcessor::initialize(bool enableDebug, AAssetManager* assetManager) {
// Create context
mContext = VulkanContext::create(enableDebug);
RET_CHECK(mContext != nullptr);
// Allocate command buffer
mCommandBuffer =
std::make_unique<VulkanCommandBuffer>(mContext->device(), mContext->commandPool());
const VkCommandBufferAllocateInfo commandBufferAllocateInfo = {
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,
.pNext = nullptr,
.commandPool = mContext->commandPool(),
.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY,
.commandBufferCount = 1,
};
CALL_VK(vkAllocateCommandBuffers, mContext->device(), &commandBufferAllocateInfo,
mCommandBuffer->pHandle());
// Create compute pipeline for hue rotation
mRotateHuePipeline =
ComputePipeline::create(mContext.get(), "shaders/ColorMatrix.comp.spv", assetManager,
sizeof(mRotateHueData), /*useUniformBuffer=*/false);
RET_CHECK(mRotateHuePipeline != nullptr);
// Create two compute pipelines for blur
mBlurUniformBuffer = Buffer::create(
mContext.get(), sizeof(mBlurData), VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
RET_CHECK(mBlurUniformBuffer != nullptr);
mBlurHorizontalPipeline =
ComputePipeline::create(mContext.get(), "shaders/BlurHorizontal.comp.spv", assetManager,
sizeof(int32_t), /*useUniformBuffer=*/true);
RET_CHECK(mBlurHorizontalPipeline != nullptr);
mBlurVerticalPipeline =
ComputePipeline::create(mContext.get(), "shaders/BlurVertical.comp.spv", assetManager,
sizeof(int32_t), /*useUniformBuffer=*/true);
RET_CHECK(mBlurVerticalPipeline != nullptr);
return true;
}