1*61046927SAndroid Build Coastguard WorkerAuxiliary surface compression 2*61046927SAndroid Build Coastguard Worker============================= 3*61046927SAndroid Build Coastguard Worker 4*61046927SAndroid Build Coastguard WorkerMost lossless image compression on Intel hardware, be that CCS, MCS, or HiZ, 5*61046927SAndroid Build Coastguard Workerworks by way of some chunk of auxiliary data (often a surface) which is used 6*61046927SAndroid Build Coastguard Workertogether with the main surface to provide compression. Even though this means 7*61046927SAndroid Build Coastguard Workermore memory is allocated, the scheme allows us to reduce our over-all memory 8*61046927SAndroid Build Coastguard Workerbandwidth since the auxiliary data is much smaller than the main surface. 9*61046927SAndroid Build Coastguard Worker 10*61046927SAndroid Build Coastguard WorkerThe simplest example of this is single-sample fast clears 11*61046927SAndroid Build Coastguard Worker(:c:enumerator:`isl_aux_usage.ISL_AUX_USAGE_CCS_D`) on Ivy Bridge through 12*61046927SAndroid Build Coastguard WorkerBroadwell and later. For this scheme, the auxiliary surface stores a single 13*61046927SAndroid Build Coastguard Workerbit for each cache-line-pair in the main surface. If that bit is set, then the 14*61046927SAndroid Build Coastguard Workerentire cache line pair contains only the clear color as provided in the 15*61046927SAndroid Build Coastguard Worker``RENDER_SURFACE_STATE`` for the image. If the bit is unset, then it's not 16*61046927SAndroid Build Coastguard Workerclear and you should look at the main surface. Since a cache line is 64B, this 17*61046927SAndroid Build Coastguard Workeryields a scale-down factor of 1:1024. 18*61046927SAndroid Build Coastguard Worker 19*61046927SAndroid Build Coastguard WorkerEven the simple fast-clear scheme saves us bandwidth in two places. The first 20*61046927SAndroid Build Coastguard Workeris when we go to clear the surface. If we're doing a full-surface clear or 21*61046927SAndroid Build Coastguard Workerclearing to the same color that was used to clear before, we don't have to 22*61046927SAndroid Build Coastguard Workertouch the main surface at all. All we have to do is record the clear color and 23*61046927SAndroid Build Coastguard Workersmash the aux data to ``0xff``. The hardware then knows to ignore whatever is 24*61046927SAndroid Build Coastguard Workerin the main surface and look at the clear color instead. The second is when we 25*61046927SAndroid Build Coastguard Workergo to render. Say we're doing some color blending. Instead of the blend unit 26*61046927SAndroid Build Coastguard Workerhaving to read back actual surface contents to blend with, it looks at the 27*61046927SAndroid Build Coastguard Workerclear bit and blends with the clear color recorded with the surface state 28*61046927SAndroid Build Coastguard Workerinstead. Depending on the geometry and cache utilization, this can save as 29*61046927SAndroid Build Coastguard Workermuch as one whole read of the surface worth of bandwidth. 30*61046927SAndroid Build Coastguard Worker 31*61046927SAndroid Build Coastguard WorkerThe difficulty with a scheme like this comes when we want to do something else 32*61046927SAndroid Build Coastguard Workerwith that surface. What happens if the sampler doesn't support this fast-clear 33*61046927SAndroid Build Coastguard Workerscheme (it doesn't on IVB)? In that case, we have to do a *resolve* where we 34*61046927SAndroid Build Coastguard Workerrun a special pipeline that reads the auxiliary data and applies it to the main 35*61046927SAndroid Build Coastguard Workersurface. In the case of fast clears, this means that, for every 1 bit in the 36*61046927SAndroid Build Coastguard Workerauxiliary surface, the corresponding pair of cache lines in the main surface 37*61046927SAndroid Build Coastguard Workergets filled with the clear color. At the end of the resolve operation, the 38*61046927SAndroid Build Coastguard Workermain surface contents are the actual contents of the surface. 39*61046927SAndroid Build Coastguard Worker 40*61046927SAndroid Build Coastguard WorkerTypes of surface compression 41*61046927SAndroid Build Coastguard Worker---------------------------- 42*61046927SAndroid Build Coastguard Worker 43*61046927SAndroid Build Coastguard WorkerIntel hardware has several different compression schemes that all work along 44*61046927SAndroid Build Coastguard Workersimilar lines: 45*61046927SAndroid Build Coastguard Worker 46*61046927SAndroid Build Coastguard Worker.. c:autoenum:: isl_aux_usage 47*61046927SAndroid Build Coastguard Worker :file: src/intel/isl/isl.h 48*61046927SAndroid Build Coastguard Worker :members: 49*61046927SAndroid Build Coastguard Worker 50*61046927SAndroid Build Coastguard Worker.. c:autofunction:: isl_aux_usage_has_fast_clears 51*61046927SAndroid Build Coastguard Worker 52*61046927SAndroid Build Coastguard Worker.. c:autofunction:: isl_aux_usage_has_compression 53*61046927SAndroid Build Coastguard Worker 54*61046927SAndroid Build Coastguard Worker.. c:autofunction:: isl_aux_usage_has_hiz 55*61046927SAndroid Build Coastguard Worker 56*61046927SAndroid Build Coastguard Worker.. c:autofunction:: isl_aux_usage_has_mcs 57*61046927SAndroid Build Coastguard Worker 58*61046927SAndroid Build Coastguard Worker.. c:autofunction:: isl_aux_usage_has_ccs 59*61046927SAndroid Build Coastguard Worker 60*61046927SAndroid Build Coastguard WorkerCreating auxiliary surfaces 61*61046927SAndroid Build Coastguard Worker--------------------------- 62*61046927SAndroid Build Coastguard Worker 63*61046927SAndroid Build Coastguard WorkerEach type of data compression requires some type of auxiliary data on the side. 64*61046927SAndroid Build Coastguard WorkerFor most, this involves a second auxiliary surface. ISL provides helpers for 65*61046927SAndroid Build Coastguard Workercreating each of these types of surfaces: 66*61046927SAndroid Build Coastguard Worker 67*61046927SAndroid Build Coastguard Worker.. c:autofunction:: isl_surf_get_hiz_surf 68*61046927SAndroid Build Coastguard Worker 69*61046927SAndroid Build Coastguard Worker.. c:autofunction:: isl_surf_get_mcs_surf 70*61046927SAndroid Build Coastguard Worker 71*61046927SAndroid Build Coastguard Worker.. c:autofunction:: isl_surf_supports_ccs 72*61046927SAndroid Build Coastguard Worker 73*61046927SAndroid Build Coastguard Worker.. c:autofunction:: isl_surf_get_ccs_surf 74*61046927SAndroid Build Coastguard Worker 75*61046927SAndroid Build Coastguard WorkerCompression state tracking 76*61046927SAndroid Build Coastguard Worker-------------------------- 77*61046927SAndroid Build Coastguard Worker 78*61046927SAndroid Build Coastguard WorkerAll of the Intel auxiliary surface compression schemes share a common concept 79*61046927SAndroid Build Coastguard Workerof a main surface which may or may not contain correct up-to-date data and some 80*61046927SAndroid Build Coastguard Workerauxiliary data which says how to interpret it. The main surface is divided 81*61046927SAndroid Build Coastguard Workerinto blocks of some fixed size and some smaller block in the auxiliary data 82*61046927SAndroid Build Coastguard Workercontrols how that main surface block is to be interpreted. We then have to do 83*61046927SAndroid Build Coastguard Workerresolves depending on the different HW units which need to interact with a 84*61046927SAndroid Build Coastguard Workergiven surface. 85*61046927SAndroid Build Coastguard Worker 86*61046927SAndroid Build Coastguard WorkerTo help drivers keep track of what all is going on and when resolves need to be 87*61046927SAndroid Build Coastguard Workerinserted, ISL provides a finite state machine which tracks the current state of 88*61046927SAndroid Build Coastguard Workerthe main surface and auxiliary data and their relationship to each other. The 89*61046927SAndroid Build Coastguard Workerstates are encoded with the :c:enum:`isl_aux_state` enum. ISL also provides 90*61046927SAndroid Build Coastguard Workerhelper functions for operating the state machine and determining what aux op 91*61046927SAndroid Build Coastguard Worker(if any) is required to get to the right state for a given operation. 92*61046927SAndroid Build Coastguard Worker 93*61046927SAndroid Build Coastguard Worker.. c:autoenum:: isl_aux_state 94*61046927SAndroid Build Coastguard Worker 95*61046927SAndroid Build Coastguard Worker.. c:autofunction:: isl_aux_state_has_valid_primary 96*61046927SAndroid Build Coastguard Worker 97*61046927SAndroid Build Coastguard Worker.. c:autofunction:: isl_aux_state_has_valid_aux 98*61046927SAndroid Build Coastguard Worker 99*61046927SAndroid Build Coastguard Worker.. c:autoenum:: isl_aux_op 100*61046927SAndroid Build Coastguard Worker 101*61046927SAndroid Build Coastguard Worker.. c:autofunction:: isl_aux_prepare_access 102*61046927SAndroid Build Coastguard Worker 103*61046927SAndroid Build Coastguard Worker.. c:autofunction:: isl_aux_state_transition_aux_op 104*61046927SAndroid Build Coastguard Worker 105*61046927SAndroid Build Coastguard Worker.. c:autofunction:: isl_aux_state_transition_write 106