Project

General

Profile

« Previous | Next » 

Revision 80961fc1

Added by Leszek Koltunski about 3 years ago

Make the 'Component Associations' UBO (on most devices) twice smaller -
use the 'packed' layout and 'ivec2' in place of 'ivec4'.

This forces us to dynamically probe the 'Stride' - number of 4-byte entities that the UBO's 'ivec4' takes - and correct the already-constructed UniformBlockAssociation objects in case this turns out to be different than the expected 2, i.e. tightly-packed.

The point: this saves a lot of uniform space in th vertex shader, which lets us declare larger MAX_NUM_COMPONENTS - needed for the Gigaminx.

(and no, we cannot assume an UBO can hold at least 16KB since this is not the case on Samsung Galaxy J4+)

View differences:

src/main/java/org/distorted/library/uniformblock/UniformBlockAssociation.java
33 33
 */
34 34
public class UniformBlockAssociation
35 35
  {
36
  private static final int BLOCK_SIZE = 16*MAX_EFFECT_COMPONENTS;
37 36
  private static final int DEFAULT_ASSOCIATION = 0xffffffff;
37
  private static final int DEFAULT_STRIDE = 2;
38
  private static final int LOC_AND = 0;
39
  private static final int LOC_EQU = 1;
38 40

  
39 41
  private final InternalBuffer mUBO;
40
  private final int[] mAssociations;
42
  private int[] mAssociations;
43
  private int mStride;
41 44

  
42 45
///////////////////////////////////////////////////////////////////////////////////////////////////
43 46

  
44 47
  public UniformBlockAssociation()
45 48
    {
46
    mAssociations= new int[BLOCK_SIZE/4];
49
    mStride = DEFAULT_STRIDE;
50
    mAssociations= new int[mStride*MAX_EFFECT_COMPONENTS];
47 51

  
48 52
    for(int i=0; i<MAX_EFFECT_COMPONENTS; i++)
49 53
      {
50
      mAssociations[4*i  ] = DEFAULT_ASSOCIATION;
51
      mAssociations[4*i+2] = i;
54
      mAssociations[mStride*i+LOC_AND] = DEFAULT_ASSOCIATION;
55
      mAssociations[mStride*i+LOC_EQU] = i;
52 56
      }
53 57

  
54 58
    mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_READ);
......
58 62

  
59 63
  public UniformBlockAssociation(UniformBlockAssociation original)
60 64
    {
65
    mStride = original.mStride;
61 66
    int size = original.mAssociations.length;
62 67
    mAssociations= new int[size];
63 68
    System.arraycopy(original.mAssociations, 0, mAssociations, 0, size);
......
65 70
    mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_READ);
66 71
    }
67 72

  
73
///////////////////////////////////////////////////////////////////////////////////////////////////
74

  
75
  public void correctStride(int stride)
76
    {
77
    if( mStride != stride )
78
      {
79
      int[] tmp = new int[stride*MAX_EFFECT_COMPONENTS];
80

  
81
      for(int i=0; i<MAX_EFFECT_COMPONENTS; i++)
82
        {
83
        tmp[stride*i+LOC_AND] = mAssociations[mStride*i+LOC_AND];
84
        tmp[stride*i+LOC_EQU] = mAssociations[mStride*i+LOC_EQU];
85
        }
86

  
87
      mAssociations = tmp;
88
      mStride = stride;
89
      }
90
    }
91

  
68 92
///////////////////////////////////////////////////////////////////////////////////////////////////
69 93

  
70 94
  public boolean matchesAssociation( int comp, int andAssoc, int equAssoc)
71 95
    {
72
    return (andAssoc & mAssociations[4*comp]) != 0 || (equAssoc == mAssociations[4*comp+2]);
96
    return (andAssoc & mAssociations[mStride*comp+LOC_AND]) != 0 || (equAssoc == mAssociations[mStride*comp+LOC_EQU]);
73 97
    }
74 98

  
75 99
///////////////////////////////////////////////////////////////////////////////////////////////////
76 100

  
77 101
  public void setEffectAssociationNow(int comp, int andAssociation, int equAssociation)
78 102
    {
79
    mAssociations[4*comp  ] = andAssociation;
80
    mAssociations[4*comp+2] = equAssociation;
103
    mAssociations[mStride*comp+LOC_AND] = andAssociation;
104
    mAssociations[mStride*comp+LOC_EQU] = equAssociation;
81 105

  
82 106
    mUBO.invalidate();
83 107
    }
......
86 110

  
87 111
  public int getIndex()
88 112
    {
89
    return mUBO.createImmediatelyInt( BLOCK_SIZE, mAssociations);
113
    return mUBO.createImmediatelyInt( 4*mStride*MAX_EFFECT_COMPONENTS, mAssociations);
90 114
    }
91 115

  
92 116
///////////////////////////////////////////////////////////////////////////////////////////////////
93 117

  
94 118
  public void copy(int compTo, UniformBlockAssociation assocFrom, int compFrom)
95 119
    {
96
    mAssociations[4*compTo  ] = assocFrom.mAssociations[4*compFrom  ];
97
    mAssociations[4*compTo+2] = assocFrom.mAssociations[4*compFrom+2];
120
    mAssociations[mStride*compTo+LOC_AND] = assocFrom.mAssociations[mStride*compFrom+LOC_AND];
121
    mAssociations[mStride*compTo+LOC_EQU] = assocFrom.mAssociations[mStride*compFrom+LOC_EQU];
98 122
    }
99 123

  
100 124
///////////////////////////////////////////////////////////////////////////////////////////////////
......
115 139

  
116 140
    for(int i=0; i<8; i++)
117 141
      {
118
      builder.append(mAssociations[4*i]);
142
      builder.append(mAssociations[mStride*i+LOC_AND]);
119 143
      builder.append(' ');
120
      builder.append(mAssociations[4*i+2]);
144
      builder.append(mAssociations[mStride*i+LOC_EQU]);
121 145
      builder.append(' ');
122 146
      }
123 147

  

Also available in: Unified diff