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

Bug Report: The expected result for vulkan vertex input test with format VK_FORMAT_R8_SRGB #506

Open
Jasonjunsu opened this issue Jan 9, 2025 · 0 comments

Comments

@Jasonjunsu
Copy link

Jasonjunsu commented Jan 9, 2025

Runing the vulkan CTS case, dEQP-VK.pipeline.monolithic.vertex_input.single_attribute.float.as_r8_srgb_rate_vertex. I got the VS as below

#version 440
layout(constant_id = 0) const int numAttributes = 16;
layout(location = 0) in float attr0;
layout(location = 0) out highp vec4 vtxColor;
out gl_PerVertex {
    vec4 gl_Position;
};

void main(void)
{
    int okCount = 0;
    if (abs(attr0 - (0.003922 * (1.0 * float(gl_VertexIndex) + 0.0))) < 0.001000)
        okCount++;

    if (okCount == 1)
    {
        if (gl_InstanceIndex == 0)
            vtxColor = vec4(1.0, 0.0, 0.0, 1.0);
        else
            vtxColor = vec4(0.0, 0.0, 1.0, 1.0);
    }
    else
    {
        vtxColor = vec4(okCount / float(1), 0.0f, 0.0f, 1.0);
    }

    if (gl_InstanceIndex == 0)
    {
        if (gl_VertexIndex == 0) gl_Position = vec4(-1.0, -1.0, 0.0, 1.0);
        else if (gl_VertexIndex == 1) gl_Position = vec4(0.0, -1.0, 0.0, 1.0);
        else if (gl_VertexIndex == 2) gl_Position = vec4(-1.0, 1.0, 0.0, 1.0);
        else if (gl_VertexIndex == 3) gl_Position = vec4(0.0, 1.0, 0.0, 1.0);
        else gl_Position = vec4(0.0);
    }
    else
    {
        if (gl_VertexIndex == 0) gl_Position = vec4(0.0, -1.0, 0.0, 1.0);
        else if (gl_VertexIndex == 1) gl_Position = vec4(1.0, -1.0, 0.0, 1.0);
        else if (gl_VertexIndex == 2) gl_Position = vec4(0.0, 1.0, 0.0, 1.0);
        else if (gl_VertexIndex == 3) gl_Position = vec4(1.0, 1.0, 0.0, 1.0);
        else gl_Position = vec4(0.0);
    }
}

But I found there is a possible issue. I think the expected vertex attribute result attr0 should be normalized and converted into linear color space.

if 0x01is the value in vertex buffer with location = 0 , and the final result of attr0 should be caculated as below:
float val_normalized = 1.0 / 255 = 0.003922
float attr0 = val_normalized / 12.92 = 0.003922 / 12.92 = 0.0003035

so the condition check statement should be fixed as below

 if (abs(attr0 - (0.003922 * (1.0 * float(gl_VertexIndex) + 0.0))) < 0.001000)

-->

float srgbToLinear(float srgbColor) {
    if (srgbColor <= 0.04045) {
        return srgbColor / 12.92;
    } else {
        return pow((srgbColor + 0.055) / 1.055, 2.4);
    }
}
 //......
 float normalized_val = 0.003922 * (1.0 * float(gl_VertexIndex) + 0.0);
 if (abs(attr0 - srgbToLinear(normalized_val)) < 0.001000)
@Jasonjunsu Jasonjunsu changed the title The expected result for vulkan input test with format VK_FORMAT_R8_SRGB The expected result for vulkan vertex input test with format VK_FORMAT_R8_SRGB Jan 9, 2025
@Jasonjunsu Jasonjunsu changed the title The expected result for vulkan vertex input test with format VK_FORMAT_R8_SRGB Bug Report: The expected result for vulkan vertex input test with format VK_FORMAT_R8_SRGB Jan 9, 2025
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

1 participant