[Vulkan] GLSL language integration 支持

一、下载插件

请直接参考这个教程:

Visual Studio设置shader(CG 、GLSL)语法提示及高亮和显示行号 使用GLSL language integration插件

二、添加 Vulkan 支持

配置完插件后,插件只支持 OpenGL 相关的关键字/变量

想要支持 Vulkan 相关的(比如:gl_VertexIndex、推送常量等等)

在 工具->选项 中按照以下内容进行配置

这里方便你直接复制:

–target-env vulkan1.2

%VK_SDK_PATH%\Bin\glslangValidator.exe

注意: VK_SDK_PATH 这个环境变量要装了 LunarG 的 SDK 才有(装的时候自动生成的)。总之给出 glslangValidator 的路径就是了

[C++] 根据运算符获取对应枚举

// app::DepthTest::Func::Type
enum class Type : GLenum 
{
	Always = GL_ALWAYS,
	Never = GL_NEVER,
	Less = GL_LESS,
	Equal = GL_EQUAL,
	LEqual = GL_LEQUAL,
	Greater = GL_GREATER,
	NotEqual = GL_NOTEQUAL,
	GEqual = GL_GEQUAL,

	Default = Less,
};
#define APP_DEPTH_FUNC_OP(op)\
(([] {\
	struct { void operator##op (int) { } };/* X APP_DEPTH_FUNC_OP(== 1 && 2 ==) X */\
	static_assert(std::is_same_v<bool, decltype(0 op 0)>, "Comparison operator only.");\
	switch (((1 op 2) << 2) | ((3 op 3) << 1) | (5 op 4))\
	{\
	case 0b001: return app::DepthTest::Func::Type::Greater;\
	case 0b010: return app::DepthTest::Func::Type::Equal;\
	case 0b011: return app::DepthTest::Func::Type::GEqual;\
	case 0b100: return app::DepthTest::Func::Type::Less;\
	case 0b101: return app::DepthTest::Func::Type::NotEqual;\
	case 0b110: return app::DepthTest::Func::Type::LEqual;\
	}\
})())

用例:

APP_DEPTH_FUNC_OP(==) == Type::Equal;// (bool)true

[力扣] 算法 525 (C++)

525. 连续数组

class Solution {
	static inline int f(int x)
	{
		return 2 * x - 1;
	}
public:
	int findMaxLength(vector<int>& nums) {
		unordered_map<int, size_t> map;
		nums[0] = f(nums[0]);
		map.emplace(nums[0], 0);
		size_t ret = 0;
		for (size_t i = 1, size = nums.size(), tmp; i < size; ++i)
		{
			nums[i] = nums[i - 1] + f(nums[i]);
			if (nums[i] == 0 && (tmp = i + 1) > ret)
			{
				ret = tmp;
			}
			else
			{
				auto found = map.find(nums[i]);
				if (found == map.end())
				{
					map.emplace(nums[i], i);
				}
				else if ((tmp = i - found->second) > ret)
				{
					ret = tmp;
				}
			}
		}
		return ret;
	}
};

[力扣] 算法 523 (C++)

523. 连续的子数组和

class Solution {
public:
	bool checkSubarraySum(vector<int>& nums, int k) {
		if (nums.size() < 2)
		{
			return false;
		}
		unordered_map<int, size_t> map;
		map[nums[0] % k] = 0;
		for (size_t i = 1; i < nums.size(); ++i)
		{
			nums[i] += nums[i - 1];
			nums[i] %= k;
			if (nums[i] == 0)
			{
				return true;
			}
			auto found = map.find(nums[i]);
			if (found == map.end())
			{
				map[nums[i]] = i;
			}
			else
			{
				if (i - found->second > 1)
				{
					return true;
				}
			}
		}
		return false;
	}
};