LoginSignup
0
0

More than 3 years have passed since last update.

初めてのVulkanプログラミング step5 シェーダモジュールの作成

Posted at

パイプラインにシェーダーを渡すには、シェーダーをVkShaderModuleオブジェクトに入れてして渡します。
CreateShaderModuleを行うクラスを作成します。

void Shader::create_shaderModule(const std::vector<char>& code, VkShaderModule *shaderModule )
{


    VkShaderModuleCreateInfo shaderCreateInfo;
    shaderCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
    shaderCreateInfo.pNext = nullptr;
    shaderCreateInfo.flags = 0;
    shaderCreateInfo.codeSize = code.size();
    shaderCreateInfo.pCode = (uint32_t*)code.data();


}

CreateShaderModuleで指定された構造体を作成します。1つ問題として、バイトコードを入れる、pCodeはcharポインターではなく、uint32_tタイプです。そのためキャストしてあげる必要があります。

    auto err = vkCreateShaderModule(_device, &shaderCreateInfo, nullptr, shaderModule);
    if (VK_SUCCESS != err) {
        assert(0 && "Vulkan ERROR: Create ShaderModule failed!!");
        std::exit(-1);
    }

オブジェクト作成のパラメータは、論理デバイス、CreateInfoを格納するポインター、カスタムアロケータのポインター、処理する変数です。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0