Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vulkan validator prints error on fragment compilation (vkCreateShaderModule) #139

Closed
ar-visions opened this issue Jun 4, 2023 · 8 comments

Comments

@ar-visions
Copy link

ar-visions commented Jun 4, 2023

line 300 in vkvg_device_internal.c:

	VkShaderModuleCreateInfo createInfo = { .sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO,
											.pCode = (uint32_t*)vkvg_main_vert_spv,
											.codeSize = vkvg_main_vert_spv_len };
	VK_CHECK_RESULT(vkCreateShaderModule(dev->vkDev, &createInfo, NULL, &modVert));
#if defined(VKVG_LCD_FONT_FILTER) && defined(FT_CONFIG_OPTION_SUBPIXEL_RENDERING)
	createInfo.pCode = (uint32_t*)vkvg_main_lcd_frag_spv;
	createInfo.codeSize = vkvg_main_lcd_frag_spv_len;
#else
	createInfo.pCode = (uint32_t*)vkvg_main_frag_spv;
	createInfo.codeSize = vkvg_main_frag_spv_len;
#endif
	VK_CHECK_RESULT(vkCreateShaderModule(dev->vkDev, &createInfo, NULL, &modFrag)); /// errors.

This is inside the _device_setupPipelines(vkvg_device) function

Validator error:

validation layer: Validation Error: [ VUID-VkShaderModuleCreateInfo-pCode-01379 ] Object 0: handle = 0x555557288900, type = VK_OBJECT_TYPE_DEVICE; | MessageID = 0x2a1bf17f | SPIR-V module not valid: Structure id 90 decorated as Block for variable in Uniform storage class must follow relaxed uniform buffer layout rules: member 1 contains an array with stride 4 not satisfying alignment to 16
  %_uboGrad = OpTypeStruct %_arr_v4float_uint_16 %_arr_float_uint_16 %_arr_v4float_uint_2 %uint

I suppose for me this means find the fragment & vertex sources and compile them with my own glslc. I was reasonably certain that VkVG did this during its build process, though? At any rate I am having this error and am trying to get it going..

I really appreciate your work on this!

@ar-visions
Copy link
Author

ar-visions commented Jun 4, 2023

#if defined(VKVG_LCD_FONT_FILTER) && defined(FT_CONFIG_OPTION_SUBPIXEL_RENDERING)
	createInfo.pCode = (uint32_t*)vkvg_main_lcd_frag_spv;
	createInfo.codeSize = vkvg_main_lcd_frag_spv_len;
#else
	createInfo.pCode = (uint32_t*)vkvg_main_frag_spv; /// <- this specific one is being used
	createInfo.codeSize = vkvg_main_frag_spv_len;
#endif

> git branch
* (HEAD detached at 84cf72d)

I am remembering some changes being made to this file that I may not have pulled in yet

@ar-visions
Copy link
Author

I pulled in those changes and still seem to get the error. I did rebuild but I'll update my json to pull in the master so all changes are applied since that spv change.

@ar-visions
Copy link
Author

ar-visions commented Jun 4, 2023

A change I had to make in order to get this going this far was an upgrade to VMA version as I use it already in a specific version that is greater than the one used in VkVG. So, I had to pass the instance in vkvg_device.c as well as vh_device.c:

#ifdef VKH_USE_VMA
	VmaAllocatorCreateInfo allocatorInfo = {
		.physicalDevice = phy,
		.device = vkDev,
                .instance = inst /// passing this as well in vkvg_device.c for use with the later version of VMA
	};
	vmaCreateAllocator(&allocatorInfo, &dev->allocator);

In the ion.git repo there is a project.json which pulls in externals and lets you compile them how you want. The CMake reads the JSON expanded from a python script. So you've got a fields format such as:

{
            "name":     "vma",
            "version":  "3.0.1",
            "url":      "https://github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator",
            "commit":   "a6bfc23",
            "includes": ["./include"],
            "libs":     ["./ion-build"],
            "install":  true
        },
        {
            "name":     "glm",
            "version":  "0.9.9.8",
            "commit":   "bf71a83",
            "url":      "https://github.com/g-truc/glm",
            "includes": ["./"],
            "libs":     ["./ion-build"]
        },
        {
            "name":     "glfw",
            "version":  "3.3.8",
            "commit":   "7482de6",
            "url":      "https://github.com/glfw/glfw",
            "includes": ["./include"],
            "libs":     ["./ion-build/src"]
        },
        {
            "name":     "vkvg",
            "version":  "0.2.2",
            "commit":   "0a181e01c758691d981c6d5ed2b17c1d7e95c284",
            "url":      "https://github.com/jpbruyere/vkvg.git",
            "includes": ["./include","./vkh/include"],
            "libs":     ["./ion-build","./ion-build/vkh","./ion-build/external/glutess"],
            "cmake":    {"args": ["-DVKVG_USE_GLUTESS=True","-DVKVG_BUILD_SHARED_LIB=Off","-DVKVG_USE_FONTCONFIG=Off","-DVKVG_USE_HARFBUZZ=On"]},
            "install":  true
        },
        {
            "name":     "mbedtls",
            "version":  "3.4.0",
            "commit":   "1873d3b",
            "url":      "https://github.com/Mbed-TLS/mbedtls",
            "includes": ["./include"],
            "libs":     ["./ion-build/library"]
        }

I had it not installing the libs but found that to make it do so. So the format need not require the 'libs' and 'includes' ultimately. I cant do it now because work is required to 'finish' install scripts like glm's which doesnt seem to have one.

@ar-visions
Copy link
Author

ar-visions commented Jun 5, 2023

Undefining VKVG_ENABLE_VK_SCALAR_BLOCK_LAYOUT lets it pass the validator as it doesnt use that method in the main fragment. I am onto another issue now.

vkvg_device_internal.c @ ~358: (last vkCreateGraphicsPipelines call in function: _device_setupPipelines)

code executed:

VK_CHECK_RESULT(vkCreateGraphicsPipelines(
     dev->vkDev, dev->pipelineCache, 1, 
     &pipelineCreateInfo, NULL, &dev->pipe_CLEAR));

validation error:

Validation Error: [ VUID-VkPipelineColorBlendStateCreateInfo-logicOpEnable-00606 ] 
Object 0: handle = 0x5555572889a0, type = VK_OBJECT_TYPE_DEVICE; | MessageID = 0x234f6296 | 
vkCreateGraphicsPipelines() pCreateInfo[0]: If logic operations feature not enabled, 
logicOpEnable must be VK_FALSE. The Vulkan spec states: If the logicOp feature is 
not enabled, logicOpEnable must be VK_FALSE 
(https://vulkan.lunarg.com/doc/view/1.3.250.0/linux/1.3-extensions/vkspec.html#VUID-VkPipelineColorBlendStateCreateInfo-logicOpEnable-00606)

@ar-visions
Copy link
Author

ar-visions commented Jun 5, 2023

The above was due to my mistake at Vulkan Device creation. I needed to add the following. 'aa' is unlikely to ever be false as I assume that would break vkvg's pipeline requirements

VkPhysicalDeviceFeatures features {
.logicOp = VK_TRUE,
.samplerAnisotropy = aa ? VK_TRUE : VK_FALSE
};

@ar-visions
Copy link
Author

ar-visions commented Jun 5, 2023

Important to note that VKVG_ENABLE_VK_SCALAR_BLOCK_LAYOUT should be OFF (not defined) for current version of vulkan validator not to error. Perhaps it could be default or we fix by padding the float[16]

@jpbruyere
Copy link
Owner

The above was due to my mistake at Vulkan Device creation. I needed to add the following. 'aa' is unlikely to ever be false as I assume that would break vkvg's pipeline requirements

VkPhysicalDeviceFeatures features { .logicOp = VK_TRUE, .samplerAnisotropy = aa ? VK_TRUE : VK_FALSE };

You should call 'vkvg_get_device_requirements' to populate the 'VkPhysicalDeviceFeatures' struct.

Important to note that VKVG_ENABLE_VK_SCALAR_BLOCK_LAYOUT should be OFF (not defined) for current version of vulkan validator not to error. Perhaps it could be default or we fix by padding the float[16]

What is you vulkan version? What is your platform, driver and gpu? SCALAR block layout could be unsupported by driver, vulkan side should be ok.

@jpbruyere
Copy link
Owner

jpbruyere commented Jun 5, 2023

I was reasonably certain that VkVG did this during its build process, though? At any rate I am having this error and am trying to get it going..

If 'glslc' and 'xxd' binaries are found by cmake, shaders should be compiled by the cmake build. I've stored in the git tree a default version of pre-compiled spir-v shaders, but macros are forwarded to glslc compile command depending on cmake options. So, if you use the pre-compiled shaders from the git tree, cmake options and spir-v macros may be out of sync.
We could maybe set the most secured options if cmake failed detecting glslc or xxd, and ensure pre-compiled shaders have the same options compiled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants