andy-thomason / Vookoo

A set of utilities for taking the pain out of Vulkan in header only modern C++
MIT License
521 stars 52 forks source link

Shader specialization #37

Closed FunMiles closed 3 years ago

FunMiles commented 3 years ago

This PR adds general constant specialization with demo of bool, int and float. Use 05-teapot -i <xFactor> to set a bool to true, and an integer constant to xFactor; use 05-teapot -f <xFactor> to set the bool to false and a float constant to xFactor. The x coordinate is scaled by xFactor.

The syntax accepts an initializer list or a vector of SpecConst which is { id, value }, where value can be any type accepted by Vulkan (tested with int_32, uint_32, bool and float). It should accept double as well, but I do not have a card/driver accepting doubles at the moment.

lhog commented 3 years ago

Runs good on my end, but I noticed my compiler throws:

1>G:\_programming\Rendering Engines\Vookoo\examples\teapot\teapot.cpp(160): message : see reference to function template instantiation 'vku::PipelineMaker::SpecData::SpecData<std::vector<vku::SpecConst,std::allocator<_Ty>>>(const SCList &)' being compiled
1>G:\_programming\Rendering Engines\Vookoo\examples\teapot\teapot.cpp(160): message :         with
1>G:\_programming\Rendering Engines\Vookoo\examples\teapot\teapot.cpp(160): message :         [
1>G:\_programming\Rendering Engines\Vookoo\examples\teapot\teapot.cpp(160): message :             _Ty=vku::SpecConst,
1>G:\_programming\Rendering Engines\Vookoo\examples\teapot\teapot.cpp(160): message :             SCList=std::vector<vku::SpecConst,std::allocator<vku::SpecConst>>
1>G:\_programming\Rendering Engines\Vookoo\examples\teapot\teapot.cpp(160): message :         ]

in the process.

It's quite obscure what compiler is trying to say, but if I fix type conversion warning here: https://github.com/andy-thomason/Vookoo/pull/37/files#diff-844d302f2ffb46d4f0a65426c548586c4c188af80e236658d459620eb40d4a9bR1131

to specializationInfo_.mapEntryCount = static_cast<uint32_t>(specConstants.size()); then it makes the warning above go away.

I'll merge with that "fix"