1 /*==============================================================================
2 Copyright(c) 2017 Intel Corporation
3 
4 Permission is hereby granted, free of charge, to any person obtaining a
5 copy of this software and associated documentation files(the "Software"),
6 to deal in the Software without restriction, including without limitation
7 the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 and / or sell copies of the Software, and to permit persons to whom the
9 Software is furnished to do so, subject to the following conditions:
10 
11 The above copyright notice and this permission notice shall be included
12 in all copies or substantial portions of the Software.
13 
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 OTHER DEALINGS IN THE SOFTWARE.
21 ============================================================================*/
22 #pragma once
23 
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif /*__cplusplus*/
28 
29 #if _WIN32
30 #ifndef __GMM_KMD__
31     typedef LONG NTSTATUS;
32     #include <windows.h>
33     #include <d3d9types.h>
34     #include <d3dkmthk.h>
35 #endif
36 #endif
37 
38 // Set packing alignment
39 #pragma pack(push, 8)
40 
41 // Rotation bitmap fields
42 #define GMM_KMD_ROTATE              0x00000001  // this is to inform KMD to enable
43                                                 // rotation in Full screen case
44 
45 // Color separation textures width division factors and array size
46 #define GMM_COLOR_SEPARATION_WIDTH_DIVISION       4
47 #define GMM_COLOR_SEPARATION_RGBX_WIDTH_DIVISION  3
48 #define GMM_COLOR_SEPARATION_ARRAY_SIZE           4   // XXX: Change that to 3 once 2nd green scanout using sprites is validated
49 
50 //===========================================================================
51 // typedef:
52 //      GMM_RESOURCE_MMC_INFO
53 //
54 // Description:
55 //      This struct is used to describe Media Memory Compression information.
56 //---------------------------------------------------------------------------
57 typedef enum GMM_RESOURCE_MMC_INFO_REC
58 {
59     GMM_MMC_DISABLED = 0,
60     GMM_MMC_HORIZONTAL,
61     GMM_MMC_VERTICAL,
62 }GMM_RESOURCE_MMC_INFO;
63 
64 //===========================================================================
65 // typedef:
66 //      GMM_RESOURCE_MMC_HINT
67 //
68 // Description:
69 //      This struct is used to indicate if Media Memory Compression is needed.
70 //---------------------------------------------------------------------------
71 typedef enum GMM_RESOURCE_MMC_HINT_REC
72 {
73     GMM_MMC_HINT_ON = 0,
74     GMM_MMC_HINT_OFF,
75 }GMM_RESOURCE_MMC_HINT;
76 
77 //===========================================================================
78 // typedef:
79 //     GMM_MSAA_SAMPLE_PATTERN
80 //
81 // Description:
82 //     This enum details the sample pattern of a MSAA texture
83 //---------------------------------------------------------------------------
84 typedef enum GMM_MSAA_SAMPLE_PATTERN_REC
85 {
86     GMM_MSAA_DISABLED = 0,
87     GMM_MSAA_STANDARD,
88     GMM_MSAA_CENTEROID,
89     GMM_MSAA_REGULAR
90 
91 }GMM_MSAA_SAMPLE_PATTERN;
92 
93 typedef enum GMM_TILE_RANGE_FLAG_ENUM
94 {
95     GMM_TILE_RANGE_NULL = 0x00000001,
96     GMM_TILE_RANGE_SKIP = 0x00000002,
97     GMM_TILE_RANGE_REUSE_SINGLE_TILE = 0x00000004,
98 } GMM_TILE_RANGE_FLAG;
99 
100 //===========================================================================
101 // typedef:
102 //        GMM_RESOURCE_MSAA_INFO
103 //
104 // Description:
105 //     This struct is used to describe MSAA information.
106 //---------------------------------------------------------------------------
107 typedef struct GMM_RESOURCE_MSAA_INFO_REC
108 {
109     GMM_MSAA_SAMPLE_PATTERN     SamplePattern;
110     uint32_t                    NumSamples;
111 }GMM_RESOURCE_MSAA_INFO;
112 
113 //===========================================================================
114 // typedef:
115 //        GMM_RESOURCE_ALIGNMENT_UNITS
116 //
117 // Description:
118 //     Various alignment units of an allocation.
119 //     NOTE: H/VAlign and QPitch stored *UNCOMPRESSED* here, despite Gen9+
120 //           SURFACE_STATE using compressed!!!
121 //---------------------------------------------------------------------------
122 typedef struct GMM_RESOURCE_ALIGNMENT_REC
123 {
124     uint8_t    ArraySpacingSingleLod;  // Single-LOD/Full Array Spacing
125     uint32_t   BaseAlignment;          // Base Alignment
126     uint32_t   HAlign, VAlign, DAlign; // Alignment Unit Width/Height
127     uint32_t   MipTailStartLod;        // Mip Tail (SKL+)
128     uint32_t   PackedMipStartLod;      // Packed Mip (Pre-Gen9 / Undefined64KBSwizzle)
129     uint32_t   PackedMipWidth;         // Packed Mip Width in # of 64KB Tiles (Pre-Gen9 / Undefined64KBSwizzle)
130     uint32_t   PackedMipHeight;        // Packed Mip Height in # of 64KB Tiles (Pre-Gen9 / Undefined64KBSwizzle)
131     uint32_t   QPitch;                 // Programmable QPitch (BDW+)
132 }GMM_RESOURCE_ALIGNMENT;
133 
134 //===========================================================================
135 // typedef:
136 //        GMM_PAGETABLE_MGR
137 //
138 // Description:
139 //     This struct is used to describe page table manager.
140 //     Forward Declaration: Defined in GmmPageTableMgr.h
141 //---------------------------------------------------------------------------
142 #ifdef __cplusplus
143     namespace GmmLib
144     {
145         class GmmPageTableMgr;
146     }
147     typedef GmmLib::GmmPageTableMgr GMM_PAGETABLE_MGR;
148 #else
149     typedef struct GmmPageTableMgr GMM_PAGETABLE_MGR;
150 #endif
151 
152 #ifdef __cplusplus
153     namespace GmmLib
154     {
155         class Context;
156     } // namespace GmmLib
157     typedef GmmLib::Context GMM_LIB_CONTEXT;
158 #else
159 typedef struct GmmLibContext GMM_LIB_CONTEXT;
160 #endif
161 //===========================================================================
162 // typedef:
163 //        GMM_RESOURCE_INFO
164 //
165 // Description:
166 //     This struct is used to describe resource allocations.
167 //     Forward Declaration: Defined in GmmResourceInfo*.h
168 //---------------------------------------------------------------------------
169 #ifdef __cplusplus
170     namespace GmmLib
171     {
172         #ifdef _WIN32
173             class GmmResourceInfoWin;
174             typedef GmmResourceInfoWin GmmResourceInfo;
175         #else
176             class GmmResourceInfoLin;
177             typedef GmmResourceInfoLin GmmResourceInfo;
178         #endif
179     }
180     typedef GmmLib::GmmResourceInfo GMM_RESOURCE_INFO;
181     typedef GmmLib::GmmResourceInfo GMM_RESOURCE_INFO_REC;
182     typedef GmmLib::GmmResourceInfo* PGMM_RESOURCE_INFO;
183 
184 #else
185     typedef struct GmmResourceInfo GMM_RESOURCE_INFO;
186     typedef struct GmmResourceInfo* PGMM_RESOURCE_INFO;
187 #endif
188 
189 //===========================================================================
190 // Place holder for GMM_RESOURCE_FLAG definition.
191 //---------------------------------------------------------------------------
192 #include "GmmResourceFlags.h"
193 #ifndef _WIN32
194     #include "External/Linux/GmmResourceInfoLinExt.h"
195 #endif
196 
197 //==========================================================================
198 // typedef:
199 //     GMM_S3D_OFFSET_INFO
200 //
201 // Description:
202 //     Contains offset info for S3D resources.
203 //
204 //--------------------------------------------------------------------------
205 typedef struct GMM_S3D_OFFSET_INFO_REC
206 {
207     uint32_t           AddressOffset;
208     uint32_t           OffsetX;
209     uint32_t           OffsetY;
210     uint32_t           LineOffsetY;
211 } GMM_S3D_OFFSET_INFO;
212 
213 //==========================================================================
214 // typedef:
215 //     GMM_S3D_INFO
216 //
217 // Description:
218 //     Describes properties of S3D feature.
219 //
220 //--------------------------------------------------------------------------
221 typedef struct GMM_S3D_INFO_REC
222 {
223     uint32_t           DisplayModeHeight;    // Current display mode resolution
224     uint32_t           NumBlankActiveLines;  // Number of blank lines
225     uint32_t           RFrameOffset;         // R frame offset
226     uint32_t           BlankAreaOffset;      // Blank area offset
227     uint32_t           TallBufferHeight;     // Tall buffer height
228     uint32_t           TallBufferSize;       // Tall buffer size
229     uint8_t            IsRFrame;             // Flag indicating this is the R frame
230 } GMM_S3D_INFO;
231 
232 //===========================================================================
233 // typedef:
234 //        GMM_MULTI_TILE_ARCH
235 //
236 // Description:
237 //     This structure is provides an advanced allocation interface for 4xXeHP
238 //     multi tile Gpu support
239 //---------------------------------------------------------------------------
240 typedef struct GMM_MULTI_TILE_ARCH_REC // FtrMultiTileArch Advanced Parameters...
241 {
242 
243     uint8_t Enable          : 1;    // When FALSE, this struct is ignored
244                                     // and GMM will make such decisions
245                                     // based on the process's default
246                                     // tile assignment from KMD.
247 
248     uint8_t TileInstanced   : 1;    // When TRUE allocation is Tile
249                                     // instanced resource
250 
251     uint8_t GpuVaMappingSet;        // Bitmask indicating which tiles
252                                     // should receive page table updates
253                                     // when this allocation is mapped.
254                                     // For all tiles set ADAPTER_INFO.MultiTileArch.TileMask
255 
256     uint8_t LocalMemEligibilitySet; // Bitmask indicating which tile's
257                                     // Local Memory this allocation
258                                     // can reside in--i.e. in addition to
259                                     // its preferred set, which others
260                                     // can it be migrated to under memory
261                                     // pressure. Entirely zeroed mask
262                                     // would be used for NonLocalOnly
263                                     // allocations.
264 
265     uint8_t LocalMemPreferredSet;   // Bitmask indicating subset of above
266                                     // eligibility set that is preferred
267                                     // above the others. Entirely zeroed
268                                     // mask is equivalent to mask of all
269                                     // ones--i.e. "no preference within
270                                     // eligibility set".
271 
272     uint32_t Reserved;
273 
274 } GMM_MULTI_TILE_ARCH;
275 //===========================================================================
276 // typedef:
277 //        GMM_RESCREATE_PARAMS
278 //
279 // Description:
280 //     This structure is used to describe an resource allocation request.
281 //     Please note that AllocationReuse makes use of member order.
282 //     more info: oskl.h: AllocationReusePredicate and Functor
283 //---------------------------------------------------------------------------
284 typedef struct GMM_RESCREATE_PARAMS_REC
285 {
286     GMM_RESOURCE_TYPE                   Type;    // 1D/2D/.../SCRATCH/...
287     GMM_RESOURCE_FORMAT                 Format;  // Pixel format e.g. NV12, GENERIC_8BIT
288     GMM_RESOURCE_FLAG                   Flags;   // See substructure type.
289     GMM_RESOURCE_MSAA_INFO              MSAA;    // How to sample this resource for anti-alisaing.
290 
291     GMM_RESOURCE_USAGE_TYPE             Usage;   // Intended use for this resource. See enumerated type.
292     uint32_t                            CpTag;
293 
294     union
295     {
296         uint32_t              BaseWidth;         // Aligned width of buffer (aligned according to .Format)
297         GMM_GFX_SIZE_T        BaseWidth64;
298 
299         // The HW buffer types, BUFFER and STRBUF, are arrays of user-defined
300         // struct's. Their natural sizing parameters are (1) the struct size
301         // and (2) the numer of array elements (i.e. the number of structs).
302         // However, the GMM allows these to be allocated in either of two ways:
303         // (1) Client computes total allocation size and passes via BaseWidth
304         // (leaving ArraySize 0), or (2) Client passes natural sizing parameters
305         // via BaseWidth and ArraySize. To make the latter more readable,
306         // clients can use the BaseWidth union alias, BufferStructSize (as well
307         // as the GmmResGetBaseWidth alias, GmmResGetBufferStructSize).
308         uint32_t                           BufferStructSize; // Note: If ever de-union'ing, mind the GmmResGetBufferStructSize #define.
309     };
310 
311     uint32_t                               BaseHeight;     // Aligned height of buffer (aligned according to .Format)
312     uint32_t                               Depth;          // For 3D resources Depth>1, for 1D/2D, a default of 0 is uplifted to 1.
313 
314     uint32_t                               MaxLod;
315     uint32_t                               ArraySize;      // A number of n-dimensional buffers can be allocated together.
316 
317     uint32_t                               BaseAlignment;
318     uint32_t                               OverridePitch;
319     #if(LHDM)
320         D3DDDI_RATIONAL                 DdiRefreshRate;
321         D3DDDI_RESOURCEFLAGS            DdiD3d9Flags;
322         D3DDDIFORMAT                    DdiD3d9Format;
323         D3DDDI_VIDEO_PRESENT_SOURCE_ID  DdiVidPnSrcId;
324     #endif
325     uint32_t                            RotateInfo;
326     uint64_t                            pExistingSysMem;
327     GMM_GFX_SIZE_T                      ExistingSysMemSize;
328 #ifdef _WIN32
329     D3DKMT_HANDLE                       hParentAllocation; //For ExistingSysMem Virtual Padding
330 #endif
331 
332     #if __GMM_KMD__
333         uint32_t                           CpuAccessible; // Kernel mode clients set if CPU pointer to resource is required.
334         GMM_S3D_INFO                    S3d;
335         void                           *pDeviceContext;
336     #endif
337     uint32_t                               MaximumRenamingListLength;
338     uint8_t                             NoGfxMemory;
339     GMM_RESOURCE_INFO                   *pPreallocatedResInfo;
340     GMM_MULTI_TILE_ARCH                 MultiTileArch;
341 
342 } GMM_RESCREATE_PARAMS;
343 
344 typedef struct GMM_RESCREATE_CUSTOM_PARAMS__REC
345 {
346     GMM_RESOURCE_TYPE              Type;    // 1D/2D/.../SCRATCH/...
347     GMM_RESOURCE_FORMAT            Format;         // Pixel format e.g. NV12, GENERIC_8BIT
348     GMM_RESOURCE_FLAG              Flags;          // See substructure type.
349     GMM_RESOURCE_USAGE_TYPE        Usage;   // Intended use for this resource. See enumerated type.
350     GMM_GFX_SIZE_T                 BaseWidth64;
351     uint32_t                       BaseHeight;     // Aligned height of buffer (aligned according to .Format)
352 
353     uint32_t                       Pitch;
354     GMM_GFX_SIZE_T                 Size;
355     uint32_t                       BaseAlignment;
356 
357     struct
358     {
359         uint32_t X[GMM_MAX_PLANE];
360         uint32_t Y[GMM_MAX_PLANE];
361     }PlaneOffset;
362 
363     uint32_t NoOfPlanes;
364     uint32_t CpTag;
365 }GMM_RESCREATE_CUSTOM_PARAMS;
366 
367 //===========================================================================
368 // enum :
369 //        GMM_UNIFIED_AUX_TYPE
370 //
371 // Description:
372 //     This enumarates various aux surface types in a unified
373 //     auxiliary surface
374 //---------------------------------------------------------------------------
375 // Usage :
376 //     UMD client use this enum to request the aux offset and size.
377 //     using via GmmResGetAuxSurfaceOffset, GmmResGetSizeAuxSurface
378 //
379 //              RT buffer with Clear Color
380 //      ________________________________________________
381 //     |                                                |
382 //     |                                                |
383 //     |                                                |
384 //     |             Pixel Data                         |
385 //     |                                                |
386 //     |                                                |
387 //     |                                                |
388 //     |                                                |
389 //     |                                                |
390 //     |                                                |
391 //   A |                                                |
392 //  -->|________________________________________________|
393 //     |                                  |             |
394 //     |                                  |             |
395 //     |             Tag plane            |             |
396 //     |       (a.k.a mcs, aux-plane,ccs) | ------------|->GmmResGetSizeAuxSurface(pRes, GMM_AUX_CCS)
397 //     |                                  |             |
398 //  -->|__________________________________|             |
399 //   B | CC FV | CC NV  | ------------------------------|--->GmmResGetSizeAuxSurface(pRes, GMM_AUX_CC)
400 //     |_______|________|                               |
401 //     |                                                |
402 //     |                                                |
403 //     |   Padded to Main Surf's(TileHeight & SurfPitch)|   --> Padding needed for Global GTT aliasing
404 //  -->|________________________________________________|
405 //   C |                                                |
406 //     |             Tag plane                          |
407 //     |          for MSAA/Depth compr                  |
408 //     |       (a.k.a ccs, zcs)             ------------|->GmmResGetSizeAuxSurface(pRes, GMM_AUX_CCS or GMM_AUX_ZCS)
409 //     |________________________________________________|
410 //
411 //     Where
412 //     FV. Clear color Float Value
413 //     NV. Clear color Native Value
414 //     A. GmmResGetAuxSurfaceOffset(pRes, GMM_AUX_CCS)
415 //     B. GmmResGetAuxSurfaceOffset(pRes, GMM_AUX_CC)
416 //     C. GmmResGetAuxSurfaceOffset(pRes, GMM_AUX_CCS or GMM_AUX_ZCS)
417 typedef enum
418 {
419     GMM_AUX_INVALID,   // Main resource
420     GMM_AUX_CCS,    // RT buffer's color control surface (Unpadded)
421     GMM_AUX_Y_CCS,  // color control surface for Y-plane
422     GMM_AUX_UV_CCS, // color control surface for UV-plane
423     GMM_AUX_CC,     // clear color value (4kb granularity)
424     GMM_AUX_COMP_STATE, // Media compression state (cacheline aligned 64B)
425     GMM_AUX_HIZ,    // HiZ surface for unified Depth buffer
426     GMM_AUX_MCS,    // multi-sample control surface for unified MSAA
427     GMM_AUX_ZCS,    // CCS for Depth Z compression
428     GMM_AUX_SURF    // Total Aux Surface (CCS + CC + Padding)
429 } GMM_UNIFIED_AUX_TYPE;
430 
431 //===========================================================================
432 // enum :
433 //        GMM_SIZE_PARAM
434 //
435 // Description:
436 //     This enumarates various surface size parameters available for GetSize query.
437 //     Refer GmmResourceInfoCommon.h  GetSize() api
438 //
439 //     Note:
440 //     Below legacy API to query surface size are deprecated and will be removed in
441 //     later gmm releases.
442 //     - GmmResGetSizeSurface()/ pResInfo->GetSizeSurface()
443 //     - GmmResGetSizeMainSurface()/  pResInfo->GetSizeAllocation()
444 //     - GmmResGetSizeAllocation()/ pResInfo->GetSizeMainSurface()
445 //---------------------------------------------------------------------------
446 // Usage :
447 //     UMD client use this enum to request the surface size.
448 //===========================================================================
449 typedef enum
450 {
451     GMM_INVALID_PARAM,       // Leave 0 as invalid to force client to explictly set
452     GMM_MAIN_SURF,           // Main surface size(w/o aux data)
453     GMM_MAIN_PLUS_AUX_SURF,  // Main surface plus auxilary data, includes ccs, cc, zcs, mcs metadata. Renderable portion of the surface.
454     GMM_TOTAL_SURF,          // Main+Aux with additional padding based on hardware PageSize.
455     GMM_MAPGPUVA_SIZE = GMM_TOTAL_SURF,// To be used for mapping gpu virtual address space.
456 } GMM_SIZE_PARAM;
457 
458 
459 //===========================================================================
460 // typedef:
461 //        GMM_RES_COPY_BLT
462 //
463 // Description:
464 //     Describes a GmmResCpuBlt operation.
465 //---------------------------------------------------------------------------
466 typedef struct GMM_RES_COPY_BLT_REC
467 {
468     struct // GPU Surface Description...
469     {
470         void            *pData;         // Pointer to base of the mapped resource data (e.g. D3DDDICB_LOCK.pData).
471         uint32_t           Slice;          // Array/Volume Slice or Cube Face; zero if N/A.
472         uint32_t           MipLevel;       // Index of applicable MIP, or zero if N/A.
473         //uint32_t         MsaaSample;     // Index of applicable MSAA sample, or zero if N/A.
474         uint32_t           OffsetX;        // Pixel offset from left-edge of specified (Slice/MipLevel) subresource.
475         uint32_t           OffsetY;        // Pixel row offset from top of specified subresource.
476         uint32_t           OffsetSubpixel; // Byte offset into the surface pixel of the applicable subpixel.
477     }               Gpu;                // Surface description of GPU resource involved in BLT.
478 
479     struct // System Surface Description...
480     {
481         void            *pData;         // Pointer to system memory surface.
482         uint32_t           RowPitch;       // Row pitch in bytes of pData surface.
483         uint32_t           SlicePitch;     // Slice pitch in bytes of pData surface; ignored if Blt.Slices <= 1.
484         uint32_t           PixelPitch;     // Number of bytes from one pData pixel to its horizontal neighbor; 0 = "Same as GPU Resource".
485         //uint32_t         MsaaSamplePitch;// Number of bytes from one pData MSAA sample to the next; ignored if Blt.MsaaSamples <= 1.
486         uint32_t           BufferSize;     // Number of bytes at pData. (Value used only in asserts to catch overuns.)
487     }               Sys;                // Description of system memory surface being BLT'ed to/from the GPU surface.
488 
489     struct // BLT Description...
490     {
491         uint32_t           Width;          // Copy width in pixels; 0 = "Full Width" of specified subresource.
492         uint32_t           Height;         // Copy height in pixel rows; 0 = "Full Height" of specified subresource.
493         uint32_t           Slices;         // Number of slices being copied; 0 = 1 = "N/A or single slice".
494         uint32_t           BytesPerPixel;  // Number of bytes to copy, per pixel; 0 = "Same as Sys.PixelPitch".
495         //uint32_t         MsaaSamples;    // Number of samples to copy per pixel; 0 = 1 = "N/A or single sample".
496         uint8_t            Upload;         // true = Sys-->Gpu; false = Gpu-->Sys.
497     }               Blt;                // Description of the BLT being performed.
498 } GMM_RES_COPY_BLT;
499 
500 //===========================================================================
501 // typedef:
502 //        GMM_GET_MAPPING
503 //
504 // Description:
505 //     GmmResGetMappingSpanDesc interface and inter-call state.
506 //---------------------------------------------------------------------------
507 typedef enum
508 {
509     GMM_MAPPING_NULL = 0,
510     GMM_MAPPING_LEGACY_Y_TO_STDSWIZZLE_SHAPE,
511     GMM_MAPPING_GEN9_YS_TO_STDSWIZZLE,
512 } GMM_GET_MAPPING_TYPE;
513 
514 typedef struct GMM_GET_MAPPING_REC
515 {
516     GMM_GET_MAPPING_TYPE    Type;
517 
518     struct
519     {
520         GMM_GFX_SIZE_T      VirtualOffset;
521         GMM_GFX_SIZE_T      PhysicalOffset;
522         GMM_GFX_SIZE_T      Size;
523     }                   Span, __NextSpan;
524 
525     struct
526     {
527         struct
528         {
529             uint32_t               Width, Height, Depth; // in Uncompressed Pixels
530         }                   Element, Tile;
531         struct
532         {
533             GMM_GFX_SIZE_T      Physical, Virtual;
534         }                   Slice0MipOffset, SlicePitch;
535         uint32_t               EffectiveLodMax, Lod, Row, RowPitchVirtual, Rows, Slice, Slices;
536         GMM_YUV_PLANE       Plane, LastPlane;
537     }                   Scratch; // Zero on initial call to GmmResGetMappingSpanDesc and then let persist.
538 } GMM_GET_MAPPING;
539 
540 
541 //***************************************************************************
542 //
543 //                      GMM_RESOURCE_INFO API
544 //
545 //***************************************************************************
546 uint8_t             GMM_STDCALL GmmIsPlanar(GMM_RESOURCE_FORMAT Format);
547 uint8_t             GMM_STDCALL GmmIsP0xx(GMM_RESOURCE_FORMAT Format);
548 uint8_t             GMM_STDCALL GmmIsUVPacked(GMM_RESOURCE_FORMAT Format);
549 bool                GMM_STDCALL GmmIsYUVFormatLCUAligned(GMM_RESOURCE_FORMAT Format);
550 #define                         GmmIsYUVPlanar GmmIsPlanar // TODO(Benign): Support old name until we have a chance to correct in UMD(s) using this. No longer YUV since there are now RGB planar formats.
551 uint8_t             GMM_STDCALL GmmIsReconstructableSurface(GMM_RESOURCE_FORMAT Format);
552 uint8_t             GMM_STDCALL GmmIsCompressed(void *pLibContext, GMM_RESOURCE_FORMAT Format);
553 uint8_t             GMM_STDCALL GmmIsYUVPacked(GMM_RESOURCE_FORMAT Format);
554 uint8_t             GMM_STDCALL GmmIsRedecribedPlanes(GMM_RESOURCE_INFO *pGmmResource);
555 uint8_t             GMM_STDCALL GmmResApplyExistingSysMem(GMM_RESOURCE_INFO *pGmmResource, void *pExistingSysMem, GMM_GFX_SIZE_T ExistingSysMemSize);
556 uint8_t             GMM_STDCALL GmmGetLosslessCompressionType(void *pLibContext, GMM_RESOURCE_FORMAT Format);
557 GMM_RESOURCE_INFO*  GMM_STDCALL GmmResCopy(GMM_RESOURCE_INFO *pGmmResource);
558 void                GMM_STDCALL GmmResMemcpy(void *pDst, void *pSrc);
559 uint8_t             GMM_STDCALL GmmResCpuBlt(GMM_RESOURCE_INFO *pGmmResource, GMM_RES_COPY_BLT *pBlt);
560 GMM_RESOURCE_INFO   *GMM_STDCALL GmmResCreate(GMM_RESCREATE_PARAMS *pCreateParams, GMM_LIB_CONTEXT *pLibContext);
561 void                GMM_STDCALL GmmResFree(GMM_RESOURCE_INFO *pGmmResource);
562 GMM_GFX_SIZE_T      GMM_STDCALL GmmResGetSizeMainSurface(const GMM_RESOURCE_INFO *pResourceInfo);
563 GMM_GFX_SIZE_T      GMM_STDCALL GmmResGetSizeSurface(GMM_RESOURCE_INFO *pResourceInfo);
564 GMM_GFX_SIZE_T      GMM_STDCALL GmmResGetSizeAllocation(GMM_RESOURCE_INFO *pResourceInfo);
565 
566 uint32_t               GMM_STDCALL GmmResGetArraySize(GMM_RESOURCE_INFO *pGmmResource);
567 uint32_t               GMM_STDCALL GmmResGetAuxBitsPerPixel(GMM_RESOURCE_INFO *pGmmResource);
568 uint32_t               GMM_STDCALL GmmResGetAuxPitch(GMM_RESOURCE_INFO *pGmmResource);
569 uint32_t               GMM_STDCALL GmmResGetAuxQPitch(GMM_RESOURCE_INFO *pGmmResource);
570 uint8_t                GMM_STDCALL GmmResIs64KBPageSuitable(GMM_RESOURCE_INFO *pGmmResource);
571 uint32_t               GMM_STDCALL GmmResGetAuxSurfaceOffset(GMM_RESOURCE_INFO *pGmmResource, GMM_UNIFIED_AUX_TYPE GmmAuxType);
572 GMM_GFX_SIZE_T         GMM_STDCALL GmmResGetAuxSurfaceOffset64(GMM_RESOURCE_INFO *pGmmResource, GMM_UNIFIED_AUX_TYPE GmmAuxType);
573 GMM_GFX_SIZE_T         GMM_STDCALL GmmResGetSizeAuxSurface(GMM_RESOURCE_INFO *pGmmResource, GMM_UNIFIED_AUX_TYPE GmmAuxType);
574 uint32_t               GMM_STDCALL GmmResGetAuxHAlign(GMM_RESOURCE_INFO *pGmmResource);
575 uint32_t               GMM_STDCALL GmmResGetAuxVAlign(GMM_RESOURCE_INFO *pGmmResource);
576 uint32_t               GMM_STDCALL GmmResGetBaseAlignment(GMM_RESOURCE_INFO *pGmmResource);
577 uint32_t               GMM_STDCALL GmmResGetBaseHeight(GMM_RESOURCE_INFO *pGmmResource);
578 uint32_t               GMM_STDCALL GmmResGetBaseWidth(GMM_RESOURCE_INFO *pGmmResource);
579 GMM_GFX_SIZE_T      GMM_STDCALL GmmResGetBaseWidth64(GMM_RESOURCE_INFO *pGmmResource);
580 uint32_t               GMM_STDCALL GmmResGetBitsPerPixel(GMM_RESOURCE_INFO *pGmmResource);
581 #define                         GmmResGetBufferStructSize GmmResGetBaseWidth // See GMM_RESCREATE_PARAMS.BufferStructSize comment.
582 uint32_t               GMM_STDCALL GmmResGetCompressionBlockDepth(GMM_RESOURCE_INFO *pGmmResource);
583 uint32_t               GMM_STDCALL GmmResGetCompressionBlockHeight(GMM_RESOURCE_INFO *pGmmResource);
584 uint32_t               GMM_STDCALL GmmResGetCompressionBlockWidth(GMM_RESOURCE_INFO *pGmmResource);
585 GMM_CPU_CACHE_TYPE  GMM_STDCALL GmmResGetCpuCacheType(GMM_RESOURCE_INFO *pGmmResource);
586 uint32_t               GMM_STDCALL GmmResGetDepth(GMM_RESOURCE_INFO *pGmmResource);
587 void                GMM_STDCALL GmmResGetFlags(GMM_RESOURCE_INFO *pGmmResource, GMM_RESOURCE_FLAG *pFlags /*output*/); //TODO: Remove after changing all UMDs
588 GMM_RESOURCE_FLAG   GMM_STDCALL GmmResGetResourceFlags(const GMM_RESOURCE_INFO *pGmmResource);
589 GMM_GFX_ADDRESS     GMM_STDCALL GmmResGetGfxAddress(GMM_RESOURCE_INFO *pGmmResource);
590 uint32_t               GMM_STDCALL GmmResGetHAlign(GMM_RESOURCE_INFO *pGmmResource);
591 #define                         GmmResGetLockPitch GmmResGetRenderPitch // Support old name until UMDs drop use.
592 uint8_t                GMM_STDCALL GmmResGetMappingSpanDesc(GMM_RESOURCE_INFO *pGmmResource, GMM_GET_MAPPING *pMapping);
593 uint32_t            GMM_STDCALL GmmResGetMaxLod(GMM_RESOURCE_INFO *pGmmResource);
594 GMM_GFX_SIZE_T      GMM_STDCALL GmmResGetStdLayoutSize(GMM_RESOURCE_INFO *pGmmResource);
595 uint32_t               GMM_STDCALL GmmResGetSurfaceStateMipTailStartLod(GMM_RESOURCE_INFO *pGmmResource);
596 uint32_t               GMM_STDCALL GmmResGetSurfaceStateTileAddressMappingMode(GMM_RESOURCE_INFO *pGmmResource);
597 uint32_t               GMM_STDCALL GmmResGetSurfaceStateStdTilingModeExt(GMM_RESOURCE_INFO *pGmmResource);
598 GMM_RESOURCE_MMC_INFO GMM_STDCALL GmmResGetMmcMode(GMM_RESOURCE_INFO *pGmmResource, uint32_t ArrayIndex);
599 uint32_t               GMM_STDCALL GmmResGetNumSamples(GMM_RESOURCE_INFO *pGmmResource);
600 GMM_STATUS          GMM_STDCALL GmmResGetOffset(GMM_RESOURCE_INFO *pGmmResource, GMM_REQ_OFFSET_INFO *pReqInfo);
601 GMM_STATUS          GMM_STDCALL GmmResGetOffsetFor64KBTiles(GMM_RESOURCE_INFO *pGmmResource, GMM_REQ_OFFSET_INFO *pReqInfo);
602 uint32_t               GMM_STDCALL GmmResGetPaddedHeight(GMM_RESOURCE_INFO *pGmmResource, uint32_t MipLevel);
603 uint32_t               GMM_STDCALL GmmResGetPaddedWidth(GMM_RESOURCE_INFO *pGmmResource, uint32_t MipLevel);
604 uint32_t               GMM_STDCALL GmmResGetPaddedPitch(GMM_RESOURCE_INFO *pGmmResource, uint32_t MipLevel);
605 void*               GMM_STDCALL GmmResGetPrivateData(GMM_RESOURCE_INFO *pGmmResource);
606 uint32_t               GMM_STDCALL GmmResGetQPitch(GMM_RESOURCE_INFO *pGmmResource);
607 uint32_t               GMM_STDCALL GmmResGetQPitchPlanar(GMM_RESOURCE_INFO *pGmmResource, GMM_YUV_PLANE Plane);
608 GMM_GFX_SIZE_T      GMM_STDCALL GmmResGetQPitchInBytes(GMM_RESOURCE_INFO *pGmmResource);
609 uint32_t               GMM_STDCALL GmmResGetRenderAuxPitchTiles(GMM_RESOURCE_INFO *pGmmResource);
610 uint32_t               GMM_STDCALL GmmResGetRenderPitch(GMM_RESOURCE_INFO *pGmmResource);
611 uint32_t               GMM_STDCALL GmmResGetRenderPitchIn64KBTiles(GMM_RESOURCE_INFO *pGmmResource);
612 uint32_t               GMM_STDCALL GmmResGetRenderPitchTiles(GMM_RESOURCE_INFO *pGmmResource);
613 GMM_RESOURCE_FORMAT GMM_STDCALL GmmResGetResourceFormat(GMM_RESOURCE_INFO *pGmmResource);
614 GMM_RESOURCE_TYPE   GMM_STDCALL GmmResGetResourceType(GMM_RESOURCE_INFO *pGmmResource);
615 uint32_t                GMM_STDCALL GmmResGetRotateInfo(GMM_RESOURCE_INFO *pGmmResource);
616 GMM_MSAA_SAMPLE_PATTERN GMM_STDCALL GmmResGetSamplePattern(GMM_RESOURCE_INFO *pGmmResource);
617 uint32_t                GMM_STDCALL GmmResGetSizeOfStruct(void);
618 GMM_SURFACESTATE_FORMAT GMM_STDCALL GmmResGetSurfaceStateFormat(GMM_RESOURCE_INFO *pGmmResource);
619 GMM_SURFACESTATE_FORMAT GMM_STDCALL GmmGetSurfaceStateFormat(GMM_RESOURCE_FORMAT Format,GMM_LIB_CONTEXT* pGmmLibContext);
620 uint32_t               GMM_STDCALL GmmResGetSurfaceStateHAlign(GMM_RESOURCE_INFO *pGmmResource);
621 uint32_t               GMM_STDCALL GmmResGetSurfaceStateVAlign(GMM_RESOURCE_INFO *pGmmResource);
622 uint32_t               GMM_STDCALL GmmResGetSurfaceStateTiledResourceMode(GMM_RESOURCE_INFO *pGmmResource);
623 void*               GMM_STDCALL GmmResGetSystemMemPointer(GMM_RESOURCE_INFO *pGmmResource, uint8_t IsD3DDdiAllocation);
624 GMM_GFX_SIZE_T      GMM_STDCALL GmmResGetSystemMemSize( GMM_RESOURCE_INFO*  pRes );
625 uint32_t            GMM_STDCALL GmmResGetTallBufferHeight(GMM_RESOURCE_INFO *pResourceInfo);
626 uint32_t            GMM_STDCALL GmmResGetMipHeight(GMM_RESOURCE_INFO *pResourceInfo, uint32_t MipLevel);
627 GMM_GFX_SIZE_T      GMM_STDCALL GmmResGetMipWidth(GMM_RESOURCE_INFO *pResourceInfo, uint32_t MipLevel);
628 uint32_t            GMM_STDCALL GmmResGetMipDepth(GMM_RESOURCE_INFO *pResourceInfo, uint32_t MipLevel);
629 uint8_t                GMM_STDCALL GmmResGetCornerTexelMode(GMM_RESOURCE_INFO *pGmmResource);
630 GMM_TEXTURE_LAYOUT  GMM_STDCALL GmmResGetTextureLayout(GMM_RESOURCE_INFO *pGmmResource);
631 GMM_TILE_TYPE       GMM_STDCALL GmmResGetTileType(GMM_RESOURCE_INFO *pGmmResource);
632 uint32_t            GMM_STDCALL GmmResGetVAlign(GMM_RESOURCE_INFO *pGmmResource);
633 uint8_t             GMM_STDCALL GmmResIsArraySpacingSingleLod(GMM_RESOURCE_INFO *pGmmResource);
634 uint8_t             GMM_STDCALL GmmResIsASTC(GMM_RESOURCE_INFO *pGmmResource);
635 uint8_t             GMM_STDCALL GmmResIsLockDiscardCompatible(GMM_RESOURCE_INFO *pGmmResource);
636 uint8_t             GMM_STDCALL GmmResIsMediaMemoryCompressed(GMM_RESOURCE_INFO *pGmmResource, uint32_t ArrayIndex);
637 uint8_t             GMM_STDCALL GmmResIsMsaaFormatDepthStencil(GMM_RESOURCE_INFO *pGmmResource);
638 uint8_t             GMM_STDCALL GmmResIsSvm(GMM_RESOURCE_INFO *pGmmResource);
639 void                GMM_STDCALL GmmResSetMmcMode(GMM_RESOURCE_INFO *pGmmResource, GMM_RESOURCE_MMC_INFO Mode, uint32_t ArrayIndex);
640 void                GMM_STDCALL GmmResSetMmcHint(GMM_RESOURCE_INFO *pGmmResource, GMM_RESOURCE_MMC_HINT Hint, uint32_t ArrayIndex);
641 GMM_RESOURCE_MMC_HINT  GMM_STDCALL GmmResGetMmcHint(GMM_RESOURCE_INFO *pGmmResource, uint32_t ArrayIndex);
642 uint8_t                GMM_STDCALL GmmResIsColorSeparation(GMM_RESOURCE_INFO *pGmmResource);
643 uint32_t               GMM_STDCALL GmmResTranslateColorSeparationX(GMM_RESOURCE_INFO *pGmmResource, uint32_t x);
644 uint32_t               GMM_STDCALL GmmResGetColorSeparationArraySize(GMM_RESOURCE_INFO *pGmmResource);
645 uint32_t               GMM_STDCALL GmmResGetColorSeparationPhysicalWidth(GMM_RESOURCE_INFO *pGmmResource);
646 uint8_t                GMM_STDCALL GmmResGetSetHardwareProtection(GMM_RESOURCE_INFO *pGmmResource, uint8_t GetIsEncrypted, uint8_t SetIsEncrypted);
647 uint32_t               GMM_STDCALL GmmResGetMaxGpuVirtualAddressBits(GMM_RESOURCE_INFO *pGmmResource, GMM_LIB_CONTEXT* pGmmLibContext);
648 uint8_t                GMM_STDCALL GmmIsSurfaceFaultable(GMM_RESOURCE_INFO *pGmmResource);
649 uint32_t               GMM_STDCALL GmmResGetMaximumRenamingListLength(GMM_RESOURCE_INFO* pGmmResource);
650 GMM_GFX_SIZE_T      GMM_STDCALL GmmResGetPlanarGetXOffset(GMM_RESOURCE_INFO *pGmmResource, GMM_YUV_PLANE Plane);
651 GMM_GFX_SIZE_T      GMM_STDCALL GmmResGetPlanarGetYOffset(GMM_RESOURCE_INFO *pGmmResource, GMM_YUV_PLANE Plane);
652 GMM_GFX_SIZE_T      GMM_STDCALL GmmResGetPlanarAuxOffset(GMM_RESOURCE_INFO *pGmmResource, uint32_t ArrayIndex, GMM_UNIFIED_AUX_TYPE Plane);
653 void                GMM_STDCALL GmmResSetLibContext(GMM_RESOURCE_INFO *pGmmResource, void *pLibContext);
654 
655 // Remove when client moves to new interface
656 uint32_t            GMM_STDCALL GmmResGetRenderSize(GMM_RESOURCE_INFO *pResourceInfo);
657 
658 //=====================================================================================================
659 //forward declarations
660 struct GMM_TEXTURE_INFO_REC;
661 
662 // Hack to define and undefine typedef name to avoid redefinition of the
663 // typedef.  Part 1.
664 
665 // typedef struct GMM_TEXTURE_INFO_REC GMM_TEXTURE_INFO;
666 #define GMM_TEXTURE_INFO struct GMM_TEXTURE_INFO_REC
667 
668 
669 // TODO: Allows UMD to override some parameters. Remove these functions once GMM comprehends UMD usage model and
670 // can support them properly.
671 void                GMM_STDCALL GmmResOverrideAllocationSize(GMM_RESOURCE_INFO *pGmmResource, GMM_GFX_SIZE_T Size);
672 void                GMM_STDCALL GmmResOverrideAllocationPitch(GMM_RESOURCE_INFO *pGmmResource, GMM_GFX_SIZE_T Pitch);
673 void                GMM_STDCALL GmmResOverrideAuxAllocationPitch(GMM_RESOURCE_INFO *pGmmResource, GMM_GFX_SIZE_T Pitch);
674 void                GMM_STDCALL GmmResOverrideAllocationFlags(GMM_RESOURCE_INFO *pGmmResource, GMM_RESOURCE_FLAG *pFlags);
675 void                GMM_STDCALL GmmResOverrideAllocationHAlign(GMM_RESOURCE_INFO *pGmmResource, uint32_t HAlign);
676 void                GMM_STDCALL GmmResOverrideAllocationBaseAlignment(GMM_RESOURCE_INFO *pGmmResource, uint32_t Alignment);
677 void                GMM_STDCALL GmmResOverrideAllocationBaseWidth(GMM_RESOURCE_INFO *pGmmResource, GMM_GFX_SIZE_T BaseWidth);
678 void                GMM_STDCALL GmmResOverrideAllocationBaseHeight(GMM_RESOURCE_INFO *pGmmResource, uint32_t BaseHeight);
679 void                GMM_STDCALL GmmResOverrideAllocationDepth(GMM_RESOURCE_INFO *pGmmResource, uint32_t Depth);
680 void                GMM_STDCALL GmmResOverrideResourceTiling(GMM_RESOURCE_INFO *pGmmResource, uint32_t TileMode);
681 void                GMM_STDCALL GmmResOverrideAuxResourceTiling(GMM_RESOURCE_INFO *pGmmResource, uint32_t TileMode);
682 void                GMM_STDCALL GmmResOverrideAllocationTextureInfo(GMM_RESOURCE_INFO *pGmmResource, GMM_CLIENT Client, const GMM_TEXTURE_INFO *pTexInfo);
683 void                GMM_STDCALL GmmResOverrideAllocationFormat(GMM_RESOURCE_INFO *pGmmResource, GMM_RESOURCE_FORMAT Format);
684 void                GMM_STDCALL GmmResOverrideSurfaceType(GMM_RESOURCE_INFO *pGmmResource, GMM_RESOURCE_TYPE ResourceType);
685 void                GMM_STDCALL GmmResOverrideSvmGfxAddress(GMM_RESOURCE_INFO *pGmmResource, GMM_GFX_ADDRESS SvmGfxAddress);
686 void                GMM_STDCALL GmmResOverrideAllocationArraySize(GMM_RESOURCE_INFO *pGmmResource, uint32_t ArraySize);
687 void                GMM_STDCALL GmmResOverrideAllocationMaxLod(GMM_RESOURCE_INFO *pGmmResource, uint32_t MaxLod);
688 
689 //////////////////////////////////////////////////////////////////////////////////////
690 // GmmCachePolicy.c
691 //////////////////////////////////////////////////////////////////////////////////////
692 MEMORY_OBJECT_CONTROL_STATE GMM_STDCALL GmmCachePolicyGetMemoryObject(void *pLibContext,
693                                                                     GMM_RESOURCE_INFO *pResInfo,
694                                                                     GMM_RESOURCE_USAGE_TYPE Usage);
695 GMM_PTE_CACHE_CONTROL_BITS GMM_STDCALL GmmCachePolicyGetPteType(void *pLibContext, GMM_RESOURCE_USAGE_TYPE Usage);
696 GMM_RESOURCE_USAGE_TYPE     GMM_STDCALL GmmCachePolicyGetResourceUsage(GMM_RESOURCE_INFO *pResInfo );
697 MEMORY_OBJECT_CONTROL_STATE GMM_STDCALL GmmCachePolicyGetOriginalMemoryObject(void *pLibContext, GMM_RESOURCE_INFO *pResInfo);
698 uint8_t                     GMM_STDCALL GmmCachePolicyIsUsagePTECached(void *pLibContext, GMM_RESOURCE_USAGE_TYPE Usage);
699 uint8_t                     GMM_STDCALL GmmGetSurfaceStateL1CachePolicy(void *pLibContext, GMM_RESOURCE_USAGE_TYPE Usage);
700 void                        GMM_STDCALL GmmCachePolicyOverrideResourceUsage(GMM_RESOURCE_INFO *pResInfo, GMM_RESOURCE_USAGE_TYPE Usage);
701 uint32_t                    GMM_STDCALL GmmCachePolicyGetMaxMocsIndex(void *pLibContext);
702 uint32_t                    GMM_STDCALL GmmCachePolicyGetMaxL1HdcMocsIndex(void *pLibContext);
703 uint32_t                    GMM_STDCALL GmmCachePolicyGetMaxSpecialMocsIndex(void *pLibContext);
704 
705 
706 void                        GMM_STDCALL GmmResSetPrivateData(GMM_RESOURCE_INFO *pGmmResource, void *pPrivateData);
707 
708 #if (!defined(__GMM_KMD__) && !defined(GMM_UNIFIED_LIB))
709 /////////////////////////////////////////////////////////////////////////////////////
710 /// C wrapper functions for UMD clients Translation layer from OLD GMM APIs to New
711 /// unified GMM Lib APIs
712 /////////////////////////////////////////////////////////////////////////////////////
713 GMM_STATUS              GmmCreateGlobalClientContext(GMM_CLIENT  ClientType);
714 void                    GmmDestroyGlobalClientContext();
715 GMM_RESOURCE_INFO*      GmmResCreateThroughClientCtxt(GMM_RESCREATE_PARAMS *pCreateParams);
716 void                    GmmResFreeThroughClientCtxt(GMM_RESOURCE_INFO *pRes);
717 GMM_RESOURCE_INFO*      GmmResCopyThroughClientCtxt(GMM_RESOURCE_INFO*  pSrcRes);
718 void                    GmmResMemcpyThroughClientCtxt(void *pDst, void *pSrc);
719 #endif
720 
721 // Hack to define and undefine typedef name to avoid redefinition of the
722 // typedef.  Part 2.
723 #undef GMM_TEXTURE_INFO
724 
725 // Reset packing alignment to project default
726 #pragma pack(pop)
727 
728 #ifdef __cplusplus
729 }
730 #endif /*__cplusplus*/
731