Moving the node computations to the GPU
The process of loading a compute shader differs only slightly from a vertex or fragment shader. For OpenGL, we have to set the shader type in the glCreateShader()
call:
glCreateShader(GL_COMPUTE_SHADER);
For Vulkan, we must set the correct shader stage during the creation of the VkShaderModule
:
VkPipelineShaderStageCreateInfo computeShaderStageInfo{};
computeShaderStageInfo.sType =
VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; computeShaderStageInfo.stage =
VK_SHADER_STAGE_COMPUTE_BIT;
All the other steps of loading the shader code, linking, or creating the shader module, stay the same. Because we have only a single shader file, additional methods have been added to the Shader
class. Loading a compute shader in OpenGL can now be achieved by calling the loadComputeShader()
method of the Shader
class with the relative file name of the shader source:
if (!mAssimpTransformComputeShader.loadComputeShader(
...