ValveSoftware / source-sdk-2013

The 2013 edition of the Source SDK
https://developer.valvesoftware.com/wiki/SDK2013_GettingStarted
Other
3.84k stars 2.02k forks source link

'No such variable <x>' error on existing shader parameters #142

Open dsezen opened 11 years ago

dsezen commented 11 years ago

When running Black Mesa on the 2013 edition of the SDK, I'm seeing the following errors in my console:

No such variable "$C0_X" for material "dev/lumcompare"
No such variable "$C0_Y" for material "dev/lumcompare"
No such variable "$bloomamount" for material "dev/blurfiltery_nohdr"

These are VALVe supplied shaders and materials. Our code doesn't touch any of the HDR stuff so I wrote up some code to print out the variables given a VMT file. Here was the result for dev/lumcompare (note, out of order msg calls due to a separate SDK bug):

] bms_print_vmt_variables dev/lumcompare
0: $flags
3: $flags_defined2
1: $flags_defined
4: $color
2: $flags2
5: $alpha
7: $frame
6: $basetexture
8: $basetexturetransform
11: $color2
9: $flashlighttexture
12: $srgbtint
10: $flashlighttextureframe
13: $c0_x <------------------------------------------------
17: $c1_x
14: $c0_y <------------------------------------------------
18: $c1_y
15: $c0_z
19: $c1_z
16: $c0_w
20: $c1_w
22: $c2_y
21: $c2_x
23: $c2_z
28: $c3_w
24: $c2_w
29: $pixshader
25: $c3_x
30: $disable_color_writes
26: $c3_y
31: $alphatested
27: $c3_z
32: $alpha_blend_color_overlay
37: $linearread_basetexture
33: $alpha_blend
38: $linearread_texture1
34: $texture1
39: $linearread_texture2
35: $texture2
40: $linearread_texture3
36: $texture3
41: $linearwrite
42: $x360appchooser
43: $copyalpha

For dev/blurfiltery_nohdr, the result is the following:

] bms_print_vmt_variables dev/blurfiltery_nohdr
0: $flags
1: $flags_defined
2: $flags2
3: $flags_defined2
5: $alpha
4: $color
6: $basetexture
7: $frame
8: $basetexturetransform
9: $flashlighttexture
14: $frametexture
10: $flashlighttextureframe
11: $color2
12: $srgbtint
13: $bloomamount <------------------------------------------------

So the interesting thing is, I took note of the fact that the parameters were all lower case. Even after lowercasing all instances in the codebase, I still got the same error message.

I took it a step further and wrote some code to print out all loaded shaders and their variables. I came across something interesting:

Shader name: screenspace_general
    Parameter 0: $flags
    Parameter 1: $flags_defined
    Parameter 2: $flags2
    Parameter 3: $flags_defined2
    Parameter 4: $color
    Parameter 5: $alpha
    Parameter 6: $basetexture
    Parameter 7: $frame
    Parameter 8: $basetexturetransform
    Parameter 9: $flashlighttexture
    Parameter 10: $flashlighttextureframe
    Parameter 11: $color2
    Parameter 12: $srgbtint

Shader name: screenspace_general_dx9
    Parameter 0: $flags
    Parameter 1: $flags_defined
    Parameter 2: $flags2
    Parameter 3: $flags_defined2
    Parameter 4: $color
    Parameter 5: $alpha
    Parameter 6: $basetexture
    Parameter 7: $frame
    Parameter 8: $basetexturetransform
    Parameter 9: $flashlighttexture
    Parameter 10: $flashlighttextureframe
    Parameter 11: $color2
    Parameter 12: $srgbtint
    Parameter 13: $C0_X
    Parameter 14: $C0_Y
    Parameter 15: $C0_Z
    Parameter 16: $C0_W
    Parameter 17: $C1_X
    Parameter 18: $C1_Y
    Parameter 19: $C1_Z
    Parameter 20: $C1_W
    Parameter 21: $C2_X
    Parameter 22: $C2_Y
    Parameter 23: $C2_Z
    Parameter 24: $C2_W
    Parameter 25: $C3_X
    Parameter 26: $C3_Y
    Parameter 27: $C3_Z
    Parameter 28: $C3_W
    Parameter 29: $PIXSHADER
    Parameter 30: $DISABLE_COLOR_WRITES
    Parameter 31: $ALPHATESTED
    Parameter 32: $ALPHA_BLEND_COLOR_OVERLAY
    Parameter 33: $ALPHA_BLEND
    Parameter 34: $TEXTURE1
    Parameter 35: $TEXTURE2
    Parameter 36: $TEXTURE3
    Parameter 37: $LINEARREAD_BASETEXTURE
    Parameter 38: $LINEARREAD_TEXTURE1
    Parameter 39: $LINEARREAD_TEXTURE2
    Parameter 40: $LINEARREAD_TEXTURE3
    Parameter 41: $LINEARWRITE
    Parameter 42: $X360APPCHOOSER
    Parameter 43: $COPYALPHA

This is the VMT for dev/lumcompare:

"screenspace_general"
{
    "$PIXSHADER" "luminance_compare_ps20"
    "$BASETEXTURE" "_rt_FullFrameFB"
    "$ALPHATESTED" "1"
    "$DISABLE_COLOR_WRITES" "1"
    "%noToolTexture" 1
}

Note that the _DX9 version does contain the required variables. blurfiltery_nohdr.vmt uses the BlurFilterY shader which contains the following variables:

Shader name: BlurFilterY
    Parameter 5: $alpha
    Parameter 0: $flags
    Parameter 7: $frame
    Parameter 1: $flags_defined
    Parameter 8: $basetexturetransform
    Parameter 2: $flags2
    Parameter 9: $flashlighttexture
    Parameter 3: $flags_defined2
    Parameter 10: $flashlighttextureframe
    Parameter 4: $color
    Parameter 11: $color2
    Parameter 5: $alpha
    Parameter 12: $srgbtint
    Parameter 6: $basetexture
    Parameter 13: $BLOOMAMOUNT  <-------------------
    Parameter 14: $FRAMETEXTURE

Any ideas?

Update: It looks like the issue is in in the following area:

void CHistogram_entry_t::IssueQuery( int frm_num )
{
    CMatRenderContextPtr pRenderContext( materials );
    if ( !m_occ_handle )
    {
        m_occ_handle = pRenderContext->CreateOcclusionQueryObject();
    }

    int xl, yl, dest_width, dest_height;
    pRenderContext->GetViewport( xl, yl, dest_width, dest_height );

    // Find min and max gamma-space text range
    float flTestRangeMin = m_min_lum;
    float flTestRangeMax = ( m_max_lum == 1.0f ) ? 10000.0f : m_max_lum; // Count all pixels >1.0 as 1.0

    // First, set stencil bits where the colors match
    IMaterial *test_mat=materials->FindMaterial( "dev/lumcompare", TEXTURE_GROUP_OTHER, true );

        // Randomly complains here.
    IMaterialVar *pMinVar = test_mat->FindVar( "$C0_X", NULL );
    pMinVar->SetFloatValue( flTestRangeMin );

        // Randomly complains here.
    IMaterialVar *pMaxVar = test_mat->FindVar( "$C0_Y", NULL );

    pMaxVar->SetFloatValue( flTestRangeMax );
    int scrx_min = FLerp( xl, ( xl + dest_width - 1 ), 0, 1, m_minx );
    int scrx_max = FLerp( xl, ( xl + dest_width - 1 ), 0, 1, m_maxx );
    int scry_min = FLerp( yl, ( yl + dest_height - 1 ), 0, 1, m_miny );
    int scry_max = FLerp( yl, ( yl + dest_height - 1 ), 0, 1, m_maxy );

        // snip...
}
saul commented 11 years ago

Are you sure you're running mat_dxlevel 90? There's a bug(?) where if you don't have the Steampipe beta for Half-Life 2, the material system defaults to DirectX 8.

dsezen commented 11 years ago

I was running mat_dxlevel 95 actually because I am on Windows 7. I forced mat_dxlevel 90 but still have the issue.