Skip to content
Snippets Groups Projects

vkd3d-shader/hlsl: Get SM4 texture allocation order and RDEF bind count for lowered combined samplers right.

Merged Francisco Casas requested to merge fcasas/vkd3d:sort_resource_alloc into master
1 unresolved thread

First, we have to distinguish between the "bind count" and the "allocation size" of variables.

The "allocation size" affects the starting register id for the resource to be allocated next, while the "bind count" is determined by the last field actually used. The former may be larger than the latter.

Currently we are calling hlsl_reg.bind_count to what should be hlsl_reg.allocation_size. So it is renamed in 2/4.

The proper "bind count" (now computed when needed in 3/4) is important because it is what should appear in the RDEF table and some resource allocation rules depend on it

For instance, for this shader:

texture2D texs[3];
texture2D tex;

float4 main() : sv_target
{
    return texs[0].Load(int3(0, 0, 0)) + tex.Load(int3(0, 0, 0));
}

the variable "texs" should show a "bind count" of 1, even though its "allocation size" is 3:

// Resource Bindings:
//
// Name                                 Type  Format         Dim      HLSL Bind  Count
// ------------------------------ ---------- ------- ----------- -------------- ------
// texs                              texture  float4          2d             t0      1
// tex                               texture  float4          2d             t3      1

In particular, as shown in the tests in 1/4, textures go in this order:

  1. Textures created from SM1-style samples. Those whose "bind count" is larger than 1, in the order of the tex1D/tex2D/tex3D/texCube instructions that create them.
  2. Textures created from SM1-style samples. Those whose "bind count" is equal to 1, in the order of the tex1D/tex2D/tex3D/texCube instructions that create them.
  3. Regular textures in order of declaration.

Note that the difference between 1 and 2 is not given by the "allocation size" but the "bind count". This order is enforced in 4/4.

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
    • Do we know that the rule in 4/4 is correct? Could it be, instead, that variables are sorted in descending order of bind count? IIRC the latter has some form of precedent; I think that's how numeric variables are sorted for sm1.

      Also, from patch 4/4:

      +                    list_remove(&var->extern_entry);
      +                    list_add_after(insertion_point, &var->extern_entry);
      +                    insertion_point = &var->extern_entry;

      This works, but I think it might be slightly clearer to build a local list, append to its tail, and then list_move_head() to ctx->extern_vars.

    • Author Developer

      Do we know that the rule in 4/4 is correct? Could it be, instead, that variables are sorted in descending order of bind count? IIRC the latter has some form of precedent; I think that's how numeric variables are sorted for sm1.

      After even more testing I see you are right. I will update the series.

      This works, but I think it might be slightly clearer to build a local list, append to its tail, and then list_move_head() to ctx->extern_vars.

      Okay.

    • Please register or sign in to reply
  • Francisco Casas added 6 commits

    added 6 commits

    • 1a4d910c - tests: Test texture allocation ordering in complex scenarios.
    • 294bb816 - vkd3d-shader/hlsl: Rename hlsl_reg.bind_count to hlsl_reg.allocation_size.
    • 691a6ccf - vkd3d-shader/tpf: Put the actual bind count in the RDEF table.
    • 5ad80e4a - vkd3d-shader/hlsl: Sort synthetic separated samplers first for SM4.
    • f8b962c7 - vkd3d-shader/hlsl: Simplify computation of allocation size.
    • 48ccf5f9 - vkd3d-shader/d3dbc: Use the bind count instead of the allocation size in d3dbc.c.

    Compare with previous version

  • Author Developer

    I changed 4/4 (now 4/6) so that texture resources are indeed sorted in decreasing bind count and added a test on 1/6 to check for that.

    Because it was necessary to call hlsl_var_get_bind_count() several times for that, I decided to store the bind count in hlsl_var.bind_count[] instead. This also allows for patch 5/6.

    I also added 6/6, which uses the bind count instead of the allocation size in d3dbc.c. This should have no effect since both should be the same in SM1, but still, for consistency.

  • Elizabeth Figura approved this merge request

    approved this merge request

  • Giovanni Mascellani approved this merge request

    approved this merge request

  • Henri Verbeet approved this merge request

    approved this merge request

  • Alexandre Julliard added 36 commits

    added 36 commits

    • 48ccf5f9...98f63c46 - 30 commits from branch wine:master
    • 948c4145 - tests: Test texture allocation ordering in complex scenarios.
    • 7eba0631 - vkd3d-shader/hlsl: Rename hlsl_reg.bind_count to hlsl_reg.allocation_size.
    • 81afe435 - vkd3d-shader/tpf: Put the actual bind count in the RDEF table.
    • 37cfbe47 - vkd3d-shader/hlsl: Sort synthetic separated samplers first for SM4.
    • d4a49d78 - vkd3d-shader/hlsl: Simplify computation of allocation size.
    • 96f66aa4 - vkd3d-shader/d3dbc: Use the bind count instead of the allocation size in d3dbc.c.

    Compare with previous version

  • Alexandre Julliard approved this merge request

    approved this merge request

Please register or sign in to reply
Loading