dark_sylinc wrote: ↑Sat Sep 12, 2020 5:40 am
I strongly suspect that's why you can't see in windowed mode
Me too
Anyway, that's not a very big problem so you can do it later...
I've spent a bit of time investigating Vulkan+HLSL issue today. My plan is to change Ogre's HDR sample to use DownScale03_SumLumEnd_ps.hlsl for Vulkan, so I changed HDR.material
Code: Select all
fragment_program HDR/DownScale03_SumLumEnd_ps_VK hlslvk
{
source DownScale03_SumLumEnd_ps.hlsl
}
The only change is glslvk -> hlslvk and .glsl -> .hlsl. No more changes.
Before debugging, I learnt a bit of "vulkan hlsl" by compiling the glsl -> spirv and use spirv-cross to get back an hlsl:
Code: Select all
glslc -fshader-stage=frag 1.glsl -o 1.spv
spirv-cross 1.spv --hlsl --output 1.hlsl --stage frag --shader-model 50
It looks like glsl's `layout(binding = x)` directly corresponds to hlsl's register(tx/sx/bx), but uniform parameters in the `Params` struct is translated into:
Code: Select all
cbuffer Params : register(b0)
{
float3 _34_exposure : packoffset(c0);
float _34_timeSinceLast : packoffset(c0.w);
float4 _34_tex0Size : packoffset(c1);
};
instead of parameters of main(), as in current hlsl file:
Code: Select all
float4 main
(
in float2 uv : TEXCOORD0,
uniform float3 exposure,
uniform float timeSinceLast,
uniform float4 tex0Size
) : SV_Target
So I changed it accordingly. Then I got this:
Code: Select all
Ogre: ERROR: [Validation] Code 0 : Validation Error: [ UNASSIGNED-CoreValidation-Shader-InconsistentSpirv ] Object 0: handle = 0x12578cefc10, type = VK_OBJECT_TYPE_DEVICE; | MessageID = 0x6bbb14 | SPIR-V module not valid: In the Vulkan environment, the OriginLowerLeft execution mode must not be used.
OpExecutionMode %main OriginLowerLeft
Luckily, I realized that it was discussed earlier in this thread (thanks Hotshot5000 and dark_sylinc!). However, Hotshot5000's solution no longer works because I'm getting this:
Code: Select all
Ogre: ERROR: [Validation] Code 0 : Validation Error: [ UNASSIGNED-CoreValidation-Shader-InconsistentSpirv ] Object 0: handle = 0x151617f4ad0, type = VK_OBJECT_TYPE_DEVICE; | MessageID = 0x6bbb14 | SPIR-V module not valid: Invalid SPIR-V binary version 1.1 for target environment SPIR-V 1.0 (under Vulkan 1.0 semantics).
Luckily, I found I can "partially" apply his changes to remove the validation error by only adding these two lines:
Code: Select all
glslang::EShTargetClientVersion VulkanClientVersion = glslang::EShTargetVulkan_1_1;
shader.setEnvClient( glslang::EShClientVulkan, VulkanClientVersion );
Then I run into this assertion failed in VulkanProgram.cpp
Code: Select all
if( type != VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER )
{
OGRE_EXCEPT( Exception::ERR_INVALIDPARAMS,
"Error on shader " + mName + ": params buffer slot must be a uniform buffer",
"VulkanProgram::buildConstantDefinitions" );
}
After a bit of debugging, I found the reason: Ogre's expecting a VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER at binding=1, but there are multiple `SpvReflectDescriptorBinding`s with binding=1.
findBinding() finds another one with binding=1 first! I've manually checked the spirv compiled with hlsl by spirv-dis and confirmed that registers t0, s0, b0 will all compiled to binding=0! (I don't know whether this is really valid, though...)
Anywany, I changed `VulkanProgram::findBinding` to accept a descriptor_type and then it successfully finds the descriptor with VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
BTW: I have to hard-code the register to b1 (`cbuffer Params : register(b1)`) because ogre_P0 expands to `c1` instead of `b1`.
However, I got a couple of other validation error (and then crashed):
Code: Select all
Ogre: ERROR: [Validation] Code 0 : Validation Error: [ UNASSIGNED-CoreValidation-Shader-DescriptorTypeMismatch ] Object 0: handle = 0x22a68770f00, type = VK_OBJECT_TYPE_DEVICE; | MessageID = 0x790fd336 | Type mismatch on descriptor slot 0.0 (expected `VK_DESCRIPTOR_TYPE_SAMPLER, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER`) but descriptor of type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER
Ogre: ERROR: [Validation] Code 0 : Validation Error: [ UNASSIGNED-CoreValidation-Shader-DescriptorTypeMismatch ] Object 0: handle = 0x22a68770f00, type = VK_OBJECT_TYPE_DEVICE; | MessageID = 0x790fd336 | Type mismatch on descriptor slot 0.0 (expected `VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE`) but descriptor of type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER
Ogre: ERROR: [Validation] Code 0 : Validation Error: [ UNASSIGNED-CoreValidation-Shader-DescriptorTypeMismatch ] Object 0: handle = 0x22a68770f00, type = VK_OBJECT_TYPE_DEVICE; | MessageID = 0x790fd336 | Type mismatch on descriptor slot 0.1 (expected `VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE`) but descriptor of type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER
Ogre: ERROR: [Validation] Code 0 : Validation Error: [ UNASSIGNED-CoreValidation-Shader-DescriptorTypeMismatch ] Object 0: handle = 0x22a68770f00, type = VK_OBJECT_TYPE_DEVICE; | MessageID = 0x790fd336 | Type mismatch on descriptor slot 0.1 (expected `VK_DESCRIPTOR_TYPE_SAMPLER, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER`) but descriptor of type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER
Ogre: ERROR: [Validation] Code 0 : Validation Error: [ UNASSIGNED-CoreValidation-Shader-InputNotProduced ] Object 0: handle = 0x7dceed0000000068, name = HDR/DownScale03_SumLumEnd_ps_VK, type = VK_OBJECT_TYPE_SHADER_MODULE; | MessageID = 0x23e43bb7 | fragment shader consumes input location 0.0 which is not written by vertex shader
I'm running out of time today so I stopped. It would be nice if dark_sylinc can go a little bit further and make this simple change (only use DownScale03_SumLumEnd_ps.hlsl) work. And maybe you're right, we probably should go with DXC instead, but what does it mean really? Does that mean our clients must upgrade their graphics card drivers to support VK1.1 or even VK1.2? I hope not, and I have an impression that DXC supports VK1.0