svga3d_surfacedefs.h 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358
  1. /**************************************************************************
  2. *
  3. * Copyright © 2008-2015 VMware, Inc., Palo Alto, CA., USA
  4. * All Rights Reserved.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a
  7. * copy of this software and associated documentation files (the
  8. * "Software"), to deal in the Software without restriction, including
  9. * without limitation the rights to use, copy, modify, merge, publish,
  10. * distribute, sub license, and/or sell copies of the Software, and to
  11. * permit persons to whom the Software is furnished to do so, subject to
  12. * the following conditions:
  13. *
  14. * The above copyright notice and this permission notice (including the
  15. * next paragraph) shall be included in all copies or substantial portions
  16. * of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
  21. * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
  22. * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  23. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  24. * USE OR OTHER DEALINGS IN THE SOFTWARE.
  25. *
  26. **************************************************************************/
  27. /*
  28. * svga3d_surfacedefs.h --
  29. *
  30. * Surface definitions and inlineable utilities for SVGA3d.
  31. */
  32. #ifndef _SVGA3D_SURFACEDEFS_H_
  33. #define _SVGA3D_SURFACEDEFS_H_
  34. #define INCLUDE_ALLOW_USERLEVEL
  35. #define INCLUDE_ALLOW_MODULE
  36. #include "includeCheck.h"
  37. #include <linux/kernel.h>
  38. #include <drm/vmwgfx_drm.h>
  39. #include "svga3d_reg.h"
  40. #define surf_size_struct struct drm_vmw_size
  41. /*
  42. * enum svga3d_block_desc - describes generic properties about formats.
  43. */
  44. enum svga3d_block_desc {
  45. /* Nothing special can be said about this format. */
  46. SVGA3DBLOCKDESC_NONE = 0,
  47. /* Format contains Blue/U data */
  48. SVGA3DBLOCKDESC_BLUE = 1 << 0,
  49. SVGA3DBLOCKDESC_W = 1 << 0,
  50. SVGA3DBLOCKDESC_BUMP_L = 1 << 0,
  51. /* Format contains Green/V data */
  52. SVGA3DBLOCKDESC_GREEN = 1 << 1,
  53. SVGA3DBLOCKDESC_V = 1 << 1,
  54. /* Format contains Red/W/Luminance data */
  55. SVGA3DBLOCKDESC_RED = 1 << 2,
  56. SVGA3DBLOCKDESC_U = 1 << 2,
  57. SVGA3DBLOCKDESC_LUMINANCE = 1 << 2,
  58. /* Format contains Alpha/Q data */
  59. SVGA3DBLOCKDESC_ALPHA = 1 << 3,
  60. SVGA3DBLOCKDESC_Q = 1 << 3,
  61. /* Format is a buffer */
  62. SVGA3DBLOCKDESC_BUFFER = 1 << 4,
  63. /* Format is compressed */
  64. SVGA3DBLOCKDESC_COMPRESSED = 1 << 5,
  65. /* Format uses IEEE floating point */
  66. SVGA3DBLOCKDESC_FP = 1 << 6,
  67. /* Three separate blocks store data. */
  68. SVGA3DBLOCKDESC_PLANAR_YUV = 1 << 7,
  69. /* 2 planes of Y, UV, e.g., NV12. */
  70. SVGA3DBLOCKDESC_2PLANAR_YUV = 1 << 8,
  71. /* 3 planes of separate Y, U, V, e.g., YV12. */
  72. SVGA3DBLOCKDESC_3PLANAR_YUV = 1 << 9,
  73. /* Block with a stencil channel */
  74. SVGA3DBLOCKDESC_STENCIL = 1 << 11,
  75. /* Typeless format */
  76. SVGA3DBLOCKDESC_TYPELESS = 1 << 12,
  77. /* Channels are signed integers */
  78. SVGA3DBLOCKDESC_SINT = 1 << 13,
  79. /* Channels are unsigned integers */
  80. SVGA3DBLOCKDESC_UINT = 1 << 14,
  81. /* Channels are normalized (when sampling) */
  82. SVGA3DBLOCKDESC_NORM = 1 << 15,
  83. /* Channels are in SRGB */
  84. SVGA3DBLOCKDESC_SRGB = 1 << 16,
  85. /* Shared exponent */
  86. SVGA3DBLOCKDESC_EXP = 1 << 17,
  87. /* Format contains color data. */
  88. SVGA3DBLOCKDESC_COLOR = 1 << 18,
  89. /* Format contains depth data. */
  90. SVGA3DBLOCKDESC_DEPTH = 1 << 19,
  91. /* Format contains bump data. */
  92. SVGA3DBLOCKDESC_BUMP = 1 << 20,
  93. /* Format contains YUV video data. */
  94. SVGA3DBLOCKDESC_YUV_VIDEO = 1 << 21,
  95. /* For mixed unsigned/signed formats. */
  96. SVGA3DBLOCKDESC_MIXED = 1 << 22,
  97. /* For distingushing CxV8U8. */
  98. SVGA3DBLOCKDESC_CX = 1 << 23,
  99. /* Different compressed format groups. */
  100. SVGA3DBLOCKDESC_BC1 = 1 << 24,
  101. SVGA3DBLOCKDESC_BC2 = 1 << 25,
  102. SVGA3DBLOCKDESC_BC3 = 1 << 26,
  103. SVGA3DBLOCKDESC_BC4 = 1 << 27,
  104. SVGA3DBLOCKDESC_BC5 = 1 << 28,
  105. SVGA3DBLOCKDESC_A_UINT = SVGA3DBLOCKDESC_ALPHA |
  106. SVGA3DBLOCKDESC_UINT |
  107. SVGA3DBLOCKDESC_COLOR,
  108. SVGA3DBLOCKDESC_A_UNORM = SVGA3DBLOCKDESC_A_UINT |
  109. SVGA3DBLOCKDESC_NORM,
  110. SVGA3DBLOCKDESC_R_UINT = SVGA3DBLOCKDESC_RED |
  111. SVGA3DBLOCKDESC_UINT |
  112. SVGA3DBLOCKDESC_COLOR,
  113. SVGA3DBLOCKDESC_R_UNORM = SVGA3DBLOCKDESC_R_UINT |
  114. SVGA3DBLOCKDESC_NORM,
  115. SVGA3DBLOCKDESC_R_SINT = SVGA3DBLOCKDESC_RED |
  116. SVGA3DBLOCKDESC_SINT |
  117. SVGA3DBLOCKDESC_COLOR,
  118. SVGA3DBLOCKDESC_R_SNORM = SVGA3DBLOCKDESC_R_SINT |
  119. SVGA3DBLOCKDESC_NORM,
  120. SVGA3DBLOCKDESC_G_UINT = SVGA3DBLOCKDESC_GREEN |
  121. SVGA3DBLOCKDESC_UINT |
  122. SVGA3DBLOCKDESC_COLOR,
  123. SVGA3DBLOCKDESC_RG_UINT = SVGA3DBLOCKDESC_RED |
  124. SVGA3DBLOCKDESC_GREEN |
  125. SVGA3DBLOCKDESC_UINT |
  126. SVGA3DBLOCKDESC_COLOR,
  127. SVGA3DBLOCKDESC_RG_UNORM = SVGA3DBLOCKDESC_RG_UINT |
  128. SVGA3DBLOCKDESC_NORM,
  129. SVGA3DBLOCKDESC_RG_SINT = SVGA3DBLOCKDESC_RED |
  130. SVGA3DBLOCKDESC_GREEN |
  131. SVGA3DBLOCKDESC_SINT |
  132. SVGA3DBLOCKDESC_COLOR,
  133. SVGA3DBLOCKDESC_RG_SNORM = SVGA3DBLOCKDESC_RG_SINT |
  134. SVGA3DBLOCKDESC_NORM,
  135. SVGA3DBLOCKDESC_RGB_UINT = SVGA3DBLOCKDESC_RED |
  136. SVGA3DBLOCKDESC_GREEN |
  137. SVGA3DBLOCKDESC_BLUE |
  138. SVGA3DBLOCKDESC_UINT |
  139. SVGA3DBLOCKDESC_COLOR,
  140. SVGA3DBLOCKDESC_RGB_SINT = SVGA3DBLOCKDESC_RED |
  141. SVGA3DBLOCKDESC_GREEN |
  142. SVGA3DBLOCKDESC_BLUE |
  143. SVGA3DBLOCKDESC_SINT |
  144. SVGA3DBLOCKDESC_COLOR,
  145. SVGA3DBLOCKDESC_RGB_UNORM = SVGA3DBLOCKDESC_RGB_UINT |
  146. SVGA3DBLOCKDESC_NORM,
  147. SVGA3DBLOCKDESC_RGB_UNORM_SRGB = SVGA3DBLOCKDESC_RGB_UNORM |
  148. SVGA3DBLOCKDESC_SRGB,
  149. SVGA3DBLOCKDESC_RGBA_UINT = SVGA3DBLOCKDESC_RED |
  150. SVGA3DBLOCKDESC_GREEN |
  151. SVGA3DBLOCKDESC_BLUE |
  152. SVGA3DBLOCKDESC_ALPHA |
  153. SVGA3DBLOCKDESC_UINT |
  154. SVGA3DBLOCKDESC_COLOR,
  155. SVGA3DBLOCKDESC_RGBA_UNORM = SVGA3DBLOCKDESC_RGBA_UINT |
  156. SVGA3DBLOCKDESC_NORM,
  157. SVGA3DBLOCKDESC_RGBA_UNORM_SRGB = SVGA3DBLOCKDESC_RGBA_UNORM |
  158. SVGA3DBLOCKDESC_SRGB,
  159. SVGA3DBLOCKDESC_RGBA_SINT = SVGA3DBLOCKDESC_RED |
  160. SVGA3DBLOCKDESC_GREEN |
  161. SVGA3DBLOCKDESC_BLUE |
  162. SVGA3DBLOCKDESC_ALPHA |
  163. SVGA3DBLOCKDESC_SINT |
  164. SVGA3DBLOCKDESC_COLOR,
  165. SVGA3DBLOCKDESC_RGBA_SNORM = SVGA3DBLOCKDESC_RGBA_SINT |
  166. SVGA3DBLOCKDESC_NORM,
  167. SVGA3DBLOCKDESC_RGBA_FP = SVGA3DBLOCKDESC_RED |
  168. SVGA3DBLOCKDESC_GREEN |
  169. SVGA3DBLOCKDESC_BLUE |
  170. SVGA3DBLOCKDESC_ALPHA |
  171. SVGA3DBLOCKDESC_FP |
  172. SVGA3DBLOCKDESC_COLOR,
  173. SVGA3DBLOCKDESC_UV = SVGA3DBLOCKDESC_U |
  174. SVGA3DBLOCKDESC_V |
  175. SVGA3DBLOCKDESC_BUMP,
  176. SVGA3DBLOCKDESC_UVL = SVGA3DBLOCKDESC_UV |
  177. SVGA3DBLOCKDESC_BUMP_L |
  178. SVGA3DBLOCKDESC_MIXED |
  179. SVGA3DBLOCKDESC_BUMP,
  180. SVGA3DBLOCKDESC_UVW = SVGA3DBLOCKDESC_UV |
  181. SVGA3DBLOCKDESC_W |
  182. SVGA3DBLOCKDESC_BUMP,
  183. SVGA3DBLOCKDESC_UVWA = SVGA3DBLOCKDESC_UVW |
  184. SVGA3DBLOCKDESC_ALPHA |
  185. SVGA3DBLOCKDESC_MIXED |
  186. SVGA3DBLOCKDESC_BUMP,
  187. SVGA3DBLOCKDESC_UVWQ = SVGA3DBLOCKDESC_U |
  188. SVGA3DBLOCKDESC_V |
  189. SVGA3DBLOCKDESC_W |
  190. SVGA3DBLOCKDESC_Q |
  191. SVGA3DBLOCKDESC_BUMP,
  192. SVGA3DBLOCKDESC_L_UNORM = SVGA3DBLOCKDESC_LUMINANCE |
  193. SVGA3DBLOCKDESC_UINT |
  194. SVGA3DBLOCKDESC_NORM |
  195. SVGA3DBLOCKDESC_COLOR,
  196. SVGA3DBLOCKDESC_LA_UNORM = SVGA3DBLOCKDESC_LUMINANCE |
  197. SVGA3DBLOCKDESC_ALPHA |
  198. SVGA3DBLOCKDESC_UINT |
  199. SVGA3DBLOCKDESC_NORM |
  200. SVGA3DBLOCKDESC_COLOR,
  201. SVGA3DBLOCKDESC_R_FP = SVGA3DBLOCKDESC_RED |
  202. SVGA3DBLOCKDESC_FP |
  203. SVGA3DBLOCKDESC_COLOR,
  204. SVGA3DBLOCKDESC_RG_FP = SVGA3DBLOCKDESC_R_FP |
  205. SVGA3DBLOCKDESC_GREEN |
  206. SVGA3DBLOCKDESC_COLOR,
  207. SVGA3DBLOCKDESC_RGB_FP = SVGA3DBLOCKDESC_RG_FP |
  208. SVGA3DBLOCKDESC_BLUE |
  209. SVGA3DBLOCKDESC_COLOR,
  210. SVGA3DBLOCKDESC_YUV = SVGA3DBLOCKDESC_YUV_VIDEO |
  211. SVGA3DBLOCKDESC_COLOR,
  212. SVGA3DBLOCKDESC_AYUV = SVGA3DBLOCKDESC_ALPHA |
  213. SVGA3DBLOCKDESC_YUV_VIDEO |
  214. SVGA3DBLOCKDESC_COLOR,
  215. SVGA3DBLOCKDESC_RGB_EXP = SVGA3DBLOCKDESC_RED |
  216. SVGA3DBLOCKDESC_GREEN |
  217. SVGA3DBLOCKDESC_BLUE |
  218. SVGA3DBLOCKDESC_EXP |
  219. SVGA3DBLOCKDESC_COLOR,
  220. SVGA3DBLOCKDESC_COMP_TYPELESS = SVGA3DBLOCKDESC_COMPRESSED |
  221. SVGA3DBLOCKDESC_TYPELESS,
  222. SVGA3DBLOCKDESC_COMP_UNORM = SVGA3DBLOCKDESC_COMPRESSED |
  223. SVGA3DBLOCKDESC_UINT |
  224. SVGA3DBLOCKDESC_NORM |
  225. SVGA3DBLOCKDESC_COLOR,
  226. SVGA3DBLOCKDESC_COMP_SNORM = SVGA3DBLOCKDESC_COMPRESSED |
  227. SVGA3DBLOCKDESC_SINT |
  228. SVGA3DBLOCKDESC_NORM |
  229. SVGA3DBLOCKDESC_COLOR,
  230. SVGA3DBLOCKDESC_COMP_UNORM_SRGB = SVGA3DBLOCKDESC_COMP_UNORM |
  231. SVGA3DBLOCKDESC_SRGB,
  232. SVGA3DBLOCKDESC_BC1_COMP_TYPELESS = SVGA3DBLOCKDESC_BC1 |
  233. SVGA3DBLOCKDESC_COMP_TYPELESS,
  234. SVGA3DBLOCKDESC_BC1_COMP_UNORM = SVGA3DBLOCKDESC_BC1 |
  235. SVGA3DBLOCKDESC_COMP_UNORM,
  236. SVGA3DBLOCKDESC_BC1_COMP_UNORM_SRGB = SVGA3DBLOCKDESC_BC1_COMP_UNORM |
  237. SVGA3DBLOCKDESC_SRGB,
  238. SVGA3DBLOCKDESC_BC2_COMP_TYPELESS = SVGA3DBLOCKDESC_BC2 |
  239. SVGA3DBLOCKDESC_COMP_TYPELESS,
  240. SVGA3DBLOCKDESC_BC2_COMP_UNORM = SVGA3DBLOCKDESC_BC2 |
  241. SVGA3DBLOCKDESC_COMP_UNORM,
  242. SVGA3DBLOCKDESC_BC2_COMP_UNORM_SRGB = SVGA3DBLOCKDESC_BC2_COMP_UNORM |
  243. SVGA3DBLOCKDESC_SRGB,
  244. SVGA3DBLOCKDESC_BC3_COMP_TYPELESS = SVGA3DBLOCKDESC_BC3 |
  245. SVGA3DBLOCKDESC_COMP_TYPELESS,
  246. SVGA3DBLOCKDESC_BC3_COMP_UNORM = SVGA3DBLOCKDESC_BC3 |
  247. SVGA3DBLOCKDESC_COMP_UNORM,
  248. SVGA3DBLOCKDESC_BC3_COMP_UNORM_SRGB = SVGA3DBLOCKDESC_BC3_COMP_UNORM |
  249. SVGA3DBLOCKDESC_SRGB,
  250. SVGA3DBLOCKDESC_BC4_COMP_TYPELESS = SVGA3DBLOCKDESC_BC4 |
  251. SVGA3DBLOCKDESC_COMP_TYPELESS,
  252. SVGA3DBLOCKDESC_BC4_COMP_UNORM = SVGA3DBLOCKDESC_BC4 |
  253. SVGA3DBLOCKDESC_COMP_UNORM,
  254. SVGA3DBLOCKDESC_BC4_COMP_SNORM = SVGA3DBLOCKDESC_BC4 |
  255. SVGA3DBLOCKDESC_COMP_SNORM,
  256. SVGA3DBLOCKDESC_BC5_COMP_TYPELESS = SVGA3DBLOCKDESC_BC5 |
  257. SVGA3DBLOCKDESC_COMP_TYPELESS,
  258. SVGA3DBLOCKDESC_BC5_COMP_UNORM = SVGA3DBLOCKDESC_BC5 |
  259. SVGA3DBLOCKDESC_COMP_UNORM,
  260. SVGA3DBLOCKDESC_BC5_COMP_SNORM = SVGA3DBLOCKDESC_BC5 |
  261. SVGA3DBLOCKDESC_COMP_SNORM,
  262. SVGA3DBLOCKDESC_NV12 = SVGA3DBLOCKDESC_YUV_VIDEO |
  263. SVGA3DBLOCKDESC_PLANAR_YUV |
  264. SVGA3DBLOCKDESC_2PLANAR_YUV |
  265. SVGA3DBLOCKDESC_COLOR,
  266. SVGA3DBLOCKDESC_YV12 = SVGA3DBLOCKDESC_YUV_VIDEO |
  267. SVGA3DBLOCKDESC_PLANAR_YUV |
  268. SVGA3DBLOCKDESC_3PLANAR_YUV |
  269. SVGA3DBLOCKDESC_COLOR,
  270. SVGA3DBLOCKDESC_DEPTH_UINT = SVGA3DBLOCKDESC_DEPTH |
  271. SVGA3DBLOCKDESC_UINT,
  272. SVGA3DBLOCKDESC_DEPTH_UNORM = SVGA3DBLOCKDESC_DEPTH_UINT |
  273. SVGA3DBLOCKDESC_NORM,
  274. SVGA3DBLOCKDESC_DS = SVGA3DBLOCKDESC_DEPTH |
  275. SVGA3DBLOCKDESC_STENCIL,
  276. SVGA3DBLOCKDESC_DS_UINT = SVGA3DBLOCKDESC_DEPTH |
  277. SVGA3DBLOCKDESC_STENCIL |
  278. SVGA3DBLOCKDESC_UINT,
  279. SVGA3DBLOCKDESC_DS_UNORM = SVGA3DBLOCKDESC_DS_UINT |
  280. SVGA3DBLOCKDESC_NORM,
  281. SVGA3DBLOCKDESC_DEPTH_FP = SVGA3DBLOCKDESC_DEPTH |
  282. SVGA3DBLOCKDESC_FP,
  283. SVGA3DBLOCKDESC_UV_UINT = SVGA3DBLOCKDESC_UV |
  284. SVGA3DBLOCKDESC_UINT,
  285. SVGA3DBLOCKDESC_UV_SNORM = SVGA3DBLOCKDESC_UV |
  286. SVGA3DBLOCKDESC_SINT |
  287. SVGA3DBLOCKDESC_NORM,
  288. SVGA3DBLOCKDESC_UVCX_SNORM = SVGA3DBLOCKDESC_UV_SNORM |
  289. SVGA3DBLOCKDESC_CX,
  290. SVGA3DBLOCKDESC_UVWQ_SNORM = SVGA3DBLOCKDESC_UVWQ |
  291. SVGA3DBLOCKDESC_SINT |
  292. SVGA3DBLOCKDESC_NORM,
  293. };
  294. struct svga3d_channel_def {
  295. union {
  296. u8 blue;
  297. u8 w_bump;
  298. u8 l_bump;
  299. u8 uv_video;
  300. u8 u_video;
  301. };
  302. union {
  303. u8 green;
  304. u8 stencil;
  305. u8 v_bump;
  306. u8 v_video;
  307. };
  308. union {
  309. u8 red;
  310. u8 u_bump;
  311. u8 luminance;
  312. u8 y_video;
  313. u8 depth;
  314. u8 data;
  315. };
  316. union {
  317. u8 alpha;
  318. u8 q_bump;
  319. u8 exp;
  320. };
  321. };
  322. /*
  323. * struct svga3d_surface_desc - describes the actual pixel data.
  324. *
  325. * @format: Format
  326. * @block_desc: Block description
  327. * @block_size: Dimensions in pixels of a block
  328. * @bytes_per_block: Size of block in bytes
  329. * @pitch_bytes_per_block: Size of a block in bytes for purposes of pitch
  330. * @bit_depth: Channel bit depths
  331. * @bit_offset: Channel bit masks (in bits offset from the start of the pointer)
  332. */
  333. struct svga3d_surface_desc {
  334. SVGA3dSurfaceFormat format;
  335. enum svga3d_block_desc block_desc;
  336. surf_size_struct block_size;
  337. u32 bytes_per_block;
  338. u32 pitch_bytes_per_block;
  339. struct svga3d_channel_def bit_depth;
  340. struct svga3d_channel_def bit_offset;
  341. };
  342. static const struct svga3d_surface_desc svga3d_surface_descs[] = {
  343. {SVGA3D_FORMAT_INVALID, SVGA3DBLOCKDESC_NONE,
  344. {1, 1, 1}, 0, 0,
  345. {{0}, {0}, {0}, {0}},
  346. {{0}, {0}, {0}, {0}}},
  347. {SVGA3D_X8R8G8B8, SVGA3DBLOCKDESC_RGB_UNORM,
  348. {1, 1, 1}, 4, 4,
  349. {{8}, {8}, {8}, {0}},
  350. {{0}, {8}, {16}, {24}}},
  351. {SVGA3D_A8R8G8B8, SVGA3DBLOCKDESC_RGBA_UNORM,
  352. {1, 1, 1}, 4, 4,
  353. {{8}, {8}, {8}, {8}},
  354. {{0}, {8}, {16}, {24}}},
  355. {SVGA3D_R5G6B5, SVGA3DBLOCKDESC_RGB_UNORM,
  356. {1, 1, 1}, 2, 2,
  357. {{5}, {6}, {5}, {0}},
  358. {{0}, {5}, {11}, {0}}},
  359. {SVGA3D_X1R5G5B5, SVGA3DBLOCKDESC_RGB_UNORM,
  360. {1, 1, 1}, 2, 2,
  361. {{5}, {5}, {5}, {0}},
  362. {{0}, {5}, {10}, {0}}},
  363. {SVGA3D_A1R5G5B5, SVGA3DBLOCKDESC_RGBA_UNORM,
  364. {1, 1, 1}, 2, 2,
  365. {{5}, {5}, {5}, {1}},
  366. {{0}, {5}, {10}, {15}}},
  367. {SVGA3D_A4R4G4B4, SVGA3DBLOCKDESC_RGBA_UNORM,
  368. {1, 1, 1}, 2, 2,
  369. {{4}, {4}, {4}, {4}},
  370. {{0}, {4}, {8}, {12}}},
  371. {SVGA3D_Z_D32, SVGA3DBLOCKDESC_DEPTH_UNORM,
  372. {1, 1, 1}, 4, 4,
  373. {{0}, {0}, {32}, {0}},
  374. {{0}, {0}, {0}, {0}}},
  375. {SVGA3D_Z_D16, SVGA3DBLOCKDESC_DEPTH_UNORM,
  376. {1, 1, 1}, 2, 2,
  377. {{0}, {0}, {16}, {0}},
  378. {{0}, {0}, {0}, {0}}},
  379. {SVGA3D_Z_D24S8, SVGA3DBLOCKDESC_DS_UNORM,
  380. {1, 1, 1}, 4, 4,
  381. {{0}, {8}, {24}, {0}},
  382. {{0}, {0}, {8}, {0}}},
  383. {SVGA3D_Z_D15S1, SVGA3DBLOCKDESC_DS_UNORM,
  384. {1, 1, 1}, 2, 2,
  385. {{0}, {1}, {15}, {0}},
  386. {{0}, {0}, {1}, {0}}},
  387. {SVGA3D_LUMINANCE8, SVGA3DBLOCKDESC_L_UNORM,
  388. {1, 1, 1}, 1, 1,
  389. {{0}, {0}, {8}, {0}},
  390. {{0}, {0}, {0}, {0}}},
  391. {SVGA3D_LUMINANCE4_ALPHA4, SVGA3DBLOCKDESC_LA_UNORM,
  392. {1, 1, 1}, 1, 1,
  393. {{0}, {0}, {4}, {4}},
  394. {{0}, {0}, {0}, {4}}},
  395. {SVGA3D_LUMINANCE16, SVGA3DBLOCKDESC_L_UNORM,
  396. {1, 1, 1}, 2, 2,
  397. {{0}, {0}, {16}, {0}},
  398. {{0}, {0}, {0}, {0}}},
  399. {SVGA3D_LUMINANCE8_ALPHA8, SVGA3DBLOCKDESC_LA_UNORM,
  400. {1, 1, 1}, 2, 2,
  401. {{0}, {0}, {8}, {8}},
  402. {{0}, {0}, {0}, {8}}},
  403. {SVGA3D_DXT1, SVGA3DBLOCKDESC_BC1_COMP_UNORM,
  404. {4, 4, 1}, 8, 8,
  405. {{0}, {0}, {64}, {0}},
  406. {{0}, {0}, {0}, {0}}},
  407. {SVGA3D_DXT2, SVGA3DBLOCKDESC_BC2_COMP_UNORM,
  408. {4, 4, 1}, 16, 16,
  409. {{0}, {0}, {128}, {0}},
  410. {{0}, {0}, {0}, {0}}},
  411. {SVGA3D_DXT3, SVGA3DBLOCKDESC_BC2_COMP_UNORM,
  412. {4, 4, 1}, 16, 16,
  413. {{0}, {0}, {128}, {0}},
  414. {{0}, {0}, {0}, {0}}},
  415. {SVGA3D_DXT4, SVGA3DBLOCKDESC_BC3_COMP_UNORM,
  416. {4, 4, 1}, 16, 16,
  417. {{0}, {0}, {128}, {0}},
  418. {{0}, {0}, {0}, {0}}},
  419. {SVGA3D_DXT5, SVGA3DBLOCKDESC_BC3_COMP_UNORM,
  420. {4, 4, 1}, 16, 16,
  421. {{0}, {0}, {128}, {0}},
  422. {{0}, {0}, {0}, {0}}},
  423. {SVGA3D_BUMPU8V8, SVGA3DBLOCKDESC_UV_SNORM,
  424. {1, 1, 1}, 2, 2,
  425. {{0}, {8}, {8}, {0}},
  426. {{0}, {8}, {0}, {0}}},
  427. {SVGA3D_BUMPL6V5U5, SVGA3DBLOCKDESC_UVL,
  428. {1, 1, 1}, 2, 2,
  429. {{6}, {5}, {5}, {0}},
  430. {{10}, {5}, {0}, {0}}},
  431. {SVGA3D_BUMPX8L8V8U8, SVGA3DBLOCKDESC_UVL,
  432. {1, 1, 1}, 4, 4,
  433. {{8}, {8}, {8}, {0}},
  434. {{16}, {8}, {0}, {0}}},
  435. {SVGA3D_FORMAT_DEAD1, SVGA3DBLOCKDESC_UVL,
  436. {1, 1, 1}, 3, 3,
  437. {{8}, {8}, {8}, {0}},
  438. {{16}, {8}, {0}, {0}}},
  439. {SVGA3D_ARGB_S10E5, SVGA3DBLOCKDESC_RGBA_FP,
  440. {1, 1, 1}, 8, 8,
  441. {{16}, {16}, {16}, {16}},
  442. {{32}, {16}, {0}, {48}}},
  443. {SVGA3D_ARGB_S23E8, SVGA3DBLOCKDESC_RGBA_FP,
  444. {1, 1, 1}, 16, 16,
  445. {{32}, {32}, {32}, {32}},
  446. {{64}, {32}, {0}, {96}}},
  447. {SVGA3D_A2R10G10B10, SVGA3DBLOCKDESC_RGBA_UNORM,
  448. {1, 1, 1}, 4, 4,
  449. {{10}, {10}, {10}, {2}},
  450. {{0}, {10}, {20}, {30}}},
  451. {SVGA3D_V8U8, SVGA3DBLOCKDESC_UV_SNORM,
  452. {1, 1, 1}, 2, 2,
  453. {{0}, {8}, {8}, {0}},
  454. {{0}, {8}, {0}, {0}}},
  455. {SVGA3D_Q8W8V8U8, SVGA3DBLOCKDESC_UVWQ_SNORM,
  456. {1, 1, 1}, 4, 4,
  457. {{8}, {8}, {8}, {8}},
  458. {{16}, {8}, {0}, {24}}},
  459. {SVGA3D_CxV8U8, SVGA3DBLOCKDESC_UVCX_SNORM,
  460. {1, 1, 1}, 2, 2,
  461. {{0}, {8}, {8}, {0}},
  462. {{0}, {8}, {0}, {0}}},
  463. {SVGA3D_X8L8V8U8, SVGA3DBLOCKDESC_UVL,
  464. {1, 1, 1}, 4, 4,
  465. {{8}, {8}, {8}, {0}},
  466. {{16}, {8}, {0}, {0}}},
  467. {SVGA3D_A2W10V10U10, SVGA3DBLOCKDESC_UVWA,
  468. {1, 1, 1}, 4, 4,
  469. {{10}, {10}, {10}, {2}},
  470. {{20}, {10}, {0}, {30}}},
  471. {SVGA3D_ALPHA8, SVGA3DBLOCKDESC_A_UNORM,
  472. {1, 1, 1}, 1, 1,
  473. {{0}, {0}, {0}, {8}},
  474. {{0}, {0}, {0}, {0}}},
  475. {SVGA3D_R_S10E5, SVGA3DBLOCKDESC_R_FP,
  476. {1, 1, 1}, 2, 2,
  477. {{0}, {0}, {16}, {0}},
  478. {{0}, {0}, {0}, {0}}},
  479. {SVGA3D_R_S23E8, SVGA3DBLOCKDESC_R_FP,
  480. {1, 1, 1}, 4, 4,
  481. {{0}, {0}, {32}, {0}},
  482. {{0}, {0}, {0}, {0}}},
  483. {SVGA3D_RG_S10E5, SVGA3DBLOCKDESC_RG_FP,
  484. {1, 1, 1}, 4, 4,
  485. {{0}, {16}, {16}, {0}},
  486. {{0}, {16}, {0}, {0}}},
  487. {SVGA3D_RG_S23E8, SVGA3DBLOCKDESC_RG_FP,
  488. {1, 1, 1}, 8, 8,
  489. {{0}, {32}, {32}, {0}},
  490. {{0}, {32}, {0}, {0}}},
  491. {SVGA3D_BUFFER, SVGA3DBLOCKDESC_BUFFER,
  492. {1, 1, 1}, 1, 1,
  493. {{0}, {0}, {8}, {0}},
  494. {{0}, {0}, {0}, {0}}},
  495. {SVGA3D_Z_D24X8, SVGA3DBLOCKDESC_DEPTH_UNORM,
  496. {1, 1, 1}, 4, 4,
  497. {{0}, {0}, {24}, {0}},
  498. {{0}, {0}, {8}, {0}}},
  499. {SVGA3D_V16U16, SVGA3DBLOCKDESC_UV_SNORM,
  500. {1, 1, 1}, 4, 4,
  501. {{0}, {16}, {16}, {0}},
  502. {{0}, {16}, {0}, {0}}},
  503. {SVGA3D_G16R16, SVGA3DBLOCKDESC_RG_UNORM,
  504. {1, 1, 1}, 4, 4,
  505. {{0}, {16}, {16}, {0}},
  506. {{0}, {16}, {0}, {0}}},
  507. {SVGA3D_A16B16G16R16, SVGA3DBLOCKDESC_RGBA_UNORM,
  508. {1, 1, 1}, 8, 8,
  509. {{16}, {16}, {16}, {16}},
  510. {{32}, {16}, {0}, {48}}},
  511. {SVGA3D_UYVY, SVGA3DBLOCKDESC_YUV,
  512. {2, 1, 1}, 4, 4,
  513. {{8}, {0}, {8}, {0}},
  514. {{0}, {0}, {8}, {0}}},
  515. {SVGA3D_YUY2, SVGA3DBLOCKDESC_YUV,
  516. {2, 1, 1}, 4, 4,
  517. {{8}, {0}, {8}, {0}},
  518. {{8}, {0}, {0}, {0}}},
  519. {SVGA3D_NV12, SVGA3DBLOCKDESC_NV12,
  520. {2, 2, 1}, 6, 2,
  521. {{0}, {0}, {48}, {0}},
  522. {{0}, {0}, {0}, {0}}},
  523. {SVGA3D_AYUV, SVGA3DBLOCKDESC_AYUV,
  524. {1, 1, 1}, 4, 4,
  525. {{8}, {8}, {8}, {8}},
  526. {{0}, {8}, {16}, {24}}},
  527. {SVGA3D_R32G32B32A32_TYPELESS, SVGA3DBLOCKDESC_TYPELESS,
  528. {1, 1, 1}, 16, 16,
  529. {{32}, {32}, {32}, {32}},
  530. {{64}, {32}, {0}, {96}}},
  531. {SVGA3D_R32G32B32A32_UINT, SVGA3DBLOCKDESC_RGBA_UINT,
  532. {1, 1, 1}, 16, 16,
  533. {{32}, {32}, {32}, {32}},
  534. {{64}, {32}, {0}, {96}}},
  535. {SVGA3D_R32G32B32A32_SINT, SVGA3DBLOCKDESC_RGBA_SINT,
  536. {1, 1, 1}, 16, 16,
  537. {{32}, {32}, {32}, {32}},
  538. {{64}, {32}, {0}, {96}}},
  539. {SVGA3D_R32G32B32_TYPELESS, SVGA3DBLOCKDESC_TYPELESS,
  540. {1, 1, 1}, 12, 12,
  541. {{32}, {32}, {32}, {0}},
  542. {{64}, {32}, {0}, {0}}},
  543. {SVGA3D_R32G32B32_FLOAT, SVGA3DBLOCKDESC_RGB_FP,
  544. {1, 1, 1}, 12, 12,
  545. {{32}, {32}, {32}, {0}},
  546. {{64}, {32}, {0}, {0}}},
  547. {SVGA3D_R32G32B32_UINT, SVGA3DBLOCKDESC_RGB_UINT,
  548. {1, 1, 1}, 12, 12,
  549. {{32}, {32}, {32}, {0}},
  550. {{64}, {32}, {0}, {0}}},
  551. {SVGA3D_R32G32B32_SINT, SVGA3DBLOCKDESC_RGB_SINT,
  552. {1, 1, 1}, 12, 12,
  553. {{32}, {32}, {32}, {0}},
  554. {{64}, {32}, {0}, {0}}},
  555. {SVGA3D_R16G16B16A16_TYPELESS, SVGA3DBLOCKDESC_TYPELESS,
  556. {1, 1, 1}, 8, 8,
  557. {{16}, {16}, {16}, {16}},
  558. {{32}, {16}, {0}, {48}}},
  559. {SVGA3D_R16G16B16A16_UINT, SVGA3DBLOCKDESC_RGBA_UINT,
  560. {1, 1, 1}, 8, 8,
  561. {{16}, {16}, {16}, {16}},
  562. {{32}, {16}, {0}, {48}}},
  563. {SVGA3D_R16G16B16A16_SNORM, SVGA3DBLOCKDESC_RGBA_SNORM,
  564. {1, 1, 1}, 8, 8,
  565. {{16}, {16}, {16}, {16}},
  566. {{32}, {16}, {0}, {48}}},
  567. {SVGA3D_R16G16B16A16_SINT, SVGA3DBLOCKDESC_RGBA_SINT,
  568. {1, 1, 1}, 8, 8,
  569. {{16}, {16}, {16}, {16}},
  570. {{32}, {16}, {0}, {48}}},
  571. {SVGA3D_R32G32_TYPELESS, SVGA3DBLOCKDESC_TYPELESS,
  572. {1, 1, 1}, 8, 8,
  573. {{0}, {32}, {32}, {0}},
  574. {{0}, {32}, {0}, {0}}},
  575. {SVGA3D_R32G32_UINT, SVGA3DBLOCKDESC_RG_UINT,
  576. {1, 1, 1}, 8, 8,
  577. {{0}, {32}, {32}, {0}},
  578. {{0}, {32}, {0}, {0}}},
  579. {SVGA3D_R32G32_SINT, SVGA3DBLOCKDESC_RG_SINT,
  580. {1, 1, 1}, 8, 8,
  581. {{0}, {32}, {32}, {0}},
  582. {{0}, {32}, {0}, {0}}},
  583. {SVGA3D_R32G8X24_TYPELESS, SVGA3DBLOCKDESC_TYPELESS,
  584. {1, 1, 1}, 8, 8,
  585. {{0}, {8}, {32}, {0}},
  586. {{0}, {32}, {0}, {0}}},
  587. {SVGA3D_D32_FLOAT_S8X24_UINT, SVGA3DBLOCKDESC_DS,
  588. {1, 1, 1}, 8, 8,
  589. {{0}, {8}, {32}, {0}},
  590. {{0}, {32}, {0}, {0}}},
  591. {SVGA3D_R32_FLOAT_X8X24, SVGA3DBLOCKDESC_R_FP,
  592. {1, 1, 1}, 8, 8,
  593. {{0}, {0}, {32}, {0}},
  594. {{0}, {0}, {0}, {0}}},
  595. {SVGA3D_X32_G8X24_UINT, SVGA3DBLOCKDESC_G_UINT,
  596. {1, 1, 1}, 8, 8,
  597. {{0}, {8}, {0}, {0}},
  598. {{0}, {32}, {0}, {0}}},
  599. {SVGA3D_R10G10B10A2_TYPELESS, SVGA3DBLOCKDESC_TYPELESS,
  600. {1, 1, 1}, 4, 4,
  601. {{10}, {10}, {10}, {2}},
  602. {{20}, {10}, {0}, {30}}},
  603. {SVGA3D_R10G10B10A2_UINT, SVGA3DBLOCKDESC_RGBA_UINT,
  604. {1, 1, 1}, 4, 4,
  605. {{10}, {10}, {10}, {2}},
  606. {{20}, {10}, {0}, {30}}},
  607. {SVGA3D_R11G11B10_FLOAT, SVGA3DBLOCKDESC_RGB_FP,
  608. {1, 1, 1}, 4, 4,
  609. {{10}, {11}, {11}, {0}},
  610. {{22}, {11}, {0}, {0}}},
  611. {SVGA3D_R8G8B8A8_TYPELESS, SVGA3DBLOCKDESC_TYPELESS,
  612. {1, 1, 1}, 4, 4,
  613. {{8}, {8}, {8}, {8}},
  614. {{16}, {8}, {0}, {24}}},
  615. {SVGA3D_R8G8B8A8_UNORM, SVGA3DBLOCKDESC_RGBA_UNORM,
  616. {1, 1, 1}, 4, 4,
  617. {{8}, {8}, {8}, {8}},
  618. {{16}, {8}, {0}, {24}}},
  619. {SVGA3D_R8G8B8A8_UNORM_SRGB, SVGA3DBLOCKDESC_RGBA_UNORM_SRGB,
  620. {1, 1, 1}, 4, 4,
  621. {{8}, {8}, {8}, {8}},
  622. {{16}, {8}, {0}, {24}}},
  623. {SVGA3D_R8G8B8A8_UINT, SVGA3DBLOCKDESC_RGBA_UINT,
  624. {1, 1, 1}, 4, 4,
  625. {{8}, {8}, {8}, {8}},
  626. {{16}, {8}, {0}, {24}}},
  627. {SVGA3D_R8G8B8A8_SINT, SVGA3DBLOCKDESC_RGBA_SINT,
  628. {1, 1, 1}, 4, 4,
  629. {{8}, {8}, {8}, {8}},
  630. {{16}, {8}, {0}, {24}}},
  631. {SVGA3D_R16G16_TYPELESS, SVGA3DBLOCKDESC_TYPELESS,
  632. {1, 1, 1}, 4, 4,
  633. {{0}, {16}, {16}, {0}},
  634. {{0}, {16}, {0}, {0}}},
  635. {SVGA3D_R16G16_UINT, SVGA3DBLOCKDESC_RG_UINT,
  636. {1, 1, 1}, 4, 4,
  637. {{0}, {16}, {16}, {0}},
  638. {{0}, {16}, {0}, {0}}},
  639. {SVGA3D_R16G16_SINT, SVGA3DBLOCKDESC_RG_SINT,
  640. {1, 1, 1}, 4, 4,
  641. {{0}, {16}, {16}, {0}},
  642. {{0}, {16}, {0}, {0}}},
  643. {SVGA3D_R32_TYPELESS, SVGA3DBLOCKDESC_TYPELESS,
  644. {1, 1, 1}, 4, 4,
  645. {{0}, {0}, {32}, {0}},
  646. {{0}, {0}, {0}, {0}}},
  647. {SVGA3D_D32_FLOAT, SVGA3DBLOCKDESC_DEPTH_FP,
  648. {1, 1, 1}, 4, 4,
  649. {{0}, {0}, {32}, {0}},
  650. {{0}, {0}, {0}, {0}}},
  651. {SVGA3D_R32_UINT, SVGA3DBLOCKDESC_R_UINT,
  652. {1, 1, 1}, 4, 4,
  653. {{0}, {0}, {32}, {0}},
  654. {{0}, {0}, {0}, {0}}},
  655. {SVGA3D_R32_SINT, SVGA3DBLOCKDESC_R_SINT,
  656. {1, 1, 1}, 4, 4,
  657. {{0}, {0}, {32}, {0}},
  658. {{0}, {0}, {0}, {0}}},
  659. {SVGA3D_R24G8_TYPELESS, SVGA3DBLOCKDESC_TYPELESS,
  660. {1, 1, 1}, 4, 4,
  661. {{0}, {8}, {24}, {0}},
  662. {{0}, {24}, {0}, {0}}},
  663. {SVGA3D_D24_UNORM_S8_UINT, SVGA3DBLOCKDESC_DS_UNORM,
  664. {1, 1, 1}, 4, 4,
  665. {{0}, {8}, {24}, {0}},
  666. {{0}, {24}, {0}, {0}}},
  667. {SVGA3D_R24_UNORM_X8, SVGA3DBLOCKDESC_R_UNORM,
  668. {1, 1, 1}, 4, 4,
  669. {{0}, {0}, {24}, {0}},
  670. {{0}, {0}, {0}, {0}}},
  671. {SVGA3D_X24_G8_UINT, SVGA3DBLOCKDESC_G_UINT,
  672. {1, 1, 1}, 4, 4,
  673. {{0}, {8}, {0}, {0}},
  674. {{0}, {24}, {0}, {0}}},
  675. {SVGA3D_R8G8_TYPELESS, SVGA3DBLOCKDESC_TYPELESS,
  676. {1, 1, 1}, 2, 2,
  677. {{0}, {8}, {8}, {0}},
  678. {{0}, {8}, {0}, {0}}},
  679. {SVGA3D_R8G8_UNORM, SVGA3DBLOCKDESC_RG_UNORM,
  680. {1, 1, 1}, 2, 2,
  681. {{0}, {8}, {8}, {0}},
  682. {{0}, {8}, {0}, {0}}},
  683. {SVGA3D_R8G8_UINT, SVGA3DBLOCKDESC_RG_UINT,
  684. {1, 1, 1}, 2, 2,
  685. {{0}, {8}, {8}, {0}},
  686. {{0}, {8}, {0}, {0}}},
  687. {SVGA3D_R8G8_SINT, SVGA3DBLOCKDESC_RG_SINT,
  688. {1, 1, 1}, 2, 2,
  689. {{0}, {8}, {8}, {0}},
  690. {{0}, {8}, {0}, {0}}},
  691. {SVGA3D_R16_TYPELESS, SVGA3DBLOCKDESC_TYPELESS,
  692. {1, 1, 1}, 2, 2,
  693. {{0}, {0}, {16}, {0}},
  694. {{0}, {0}, {0}, {0}}},
  695. {SVGA3D_R16_UNORM, SVGA3DBLOCKDESC_R_UNORM,
  696. {1, 1, 1}, 2, 2,
  697. {{0}, {0}, {16}, {0}},
  698. {{0}, {0}, {0}, {0}}},
  699. {SVGA3D_R16_UINT, SVGA3DBLOCKDESC_R_UINT,
  700. {1, 1, 1}, 2, 2,
  701. {{0}, {0}, {16}, {0}},
  702. {{0}, {0}, {0}, {0}}},
  703. {SVGA3D_R16_SNORM, SVGA3DBLOCKDESC_R_SNORM,
  704. {1, 1, 1}, 2, 2,
  705. {{0}, {0}, {16}, {0}},
  706. {{0}, {0}, {0}, {0}}},
  707. {SVGA3D_R16_SINT, SVGA3DBLOCKDESC_R_SINT,
  708. {1, 1, 1}, 2, 2,
  709. {{0}, {0}, {16}, {0}},
  710. {{0}, {0}, {0}, {0}}},
  711. {SVGA3D_R8_TYPELESS, SVGA3DBLOCKDESC_TYPELESS,
  712. {1, 1, 1}, 1, 1,
  713. {{0}, {0}, {8}, {0}},
  714. {{0}, {0}, {0}, {0}}},
  715. {SVGA3D_R8_UNORM, SVGA3DBLOCKDESC_R_UNORM,
  716. {1, 1, 1}, 1, 1,
  717. {{0}, {0}, {8}, {0}},
  718. {{0}, {0}, {0}, {0}}},
  719. {SVGA3D_R8_UINT, SVGA3DBLOCKDESC_R_UINT,
  720. {1, 1, 1}, 1, 1,
  721. {{0}, {0}, {8}, {0}},
  722. {{0}, {0}, {0}, {0}}},
  723. {SVGA3D_R8_SNORM, SVGA3DBLOCKDESC_R_SNORM,
  724. {1, 1, 1}, 1, 1,
  725. {{0}, {0}, {8}, {0}},
  726. {{0}, {0}, {0}, {0}}},
  727. {SVGA3D_R8_SINT, SVGA3DBLOCKDESC_R_SINT,
  728. {1, 1, 1}, 1, 1,
  729. {{0}, {0}, {8}, {0}},
  730. {{0}, {0}, {0}, {0}}},
  731. {SVGA3D_P8, SVGA3DBLOCKDESC_NONE,
  732. {1, 1, 1}, 1, 1,
  733. {{0}, {0}, {8}, {0}},
  734. {{0}, {0}, {0}, {0}}},
  735. {SVGA3D_R9G9B9E5_SHAREDEXP, SVGA3DBLOCKDESC_RGB_EXP,
  736. {1, 1, 1}, 4, 4,
  737. {{9}, {9}, {9}, {5}},
  738. {{18}, {9}, {0}, {27}}},
  739. {SVGA3D_R8G8_B8G8_UNORM, SVGA3DBLOCKDESC_NONE,
  740. {2, 1, 1}, 4, 4,
  741. {{0}, {8}, {8}, {0}},
  742. {{0}, {0}, {8}, {0}}},
  743. {SVGA3D_G8R8_G8B8_UNORM, SVGA3DBLOCKDESC_NONE,
  744. {2, 1, 1}, 4, 4,
  745. {{0}, {8}, {8}, {0}},
  746. {{0}, {8}, {0}, {0}}},
  747. {SVGA3D_BC1_TYPELESS, SVGA3DBLOCKDESC_BC1_COMP_TYPELESS,
  748. {4, 4, 1}, 8, 8,
  749. {{0}, {0}, {64}, {0}},
  750. {{0}, {0}, {0}, {0}}},
  751. {SVGA3D_BC1_UNORM_SRGB, SVGA3DBLOCKDESC_BC1_COMP_UNORM_SRGB,
  752. {4, 4, 1}, 8, 8,
  753. {{0}, {0}, {64}, {0}},
  754. {{0}, {0}, {0}, {0}}},
  755. {SVGA3D_BC2_TYPELESS, SVGA3DBLOCKDESC_BC2_COMP_TYPELESS,
  756. {4, 4, 1}, 16, 16,
  757. {{0}, {0}, {128}, {0}},
  758. {{0}, {0}, {0}, {0}}},
  759. {SVGA3D_BC2_UNORM_SRGB, SVGA3DBLOCKDESC_BC2_COMP_UNORM_SRGB,
  760. {4, 4, 1}, 16, 16,
  761. {{0}, {0}, {128}, {0}},
  762. {{0}, {0}, {0}, {0}}},
  763. {SVGA3D_BC3_TYPELESS, SVGA3DBLOCKDESC_BC3_COMP_TYPELESS,
  764. {4, 4, 1}, 16, 16,
  765. {{0}, {0}, {128}, {0}},
  766. {{0}, {0}, {0}, {0}}},
  767. {SVGA3D_BC3_UNORM_SRGB, SVGA3DBLOCKDESC_BC3_COMP_UNORM_SRGB,
  768. {4, 4, 1}, 16, 16,
  769. {{0}, {0}, {128}, {0}},
  770. {{0}, {0}, {0}, {0}}},
  771. {SVGA3D_BC4_TYPELESS, SVGA3DBLOCKDESC_BC4_COMP_TYPELESS,
  772. {4, 4, 1}, 8, 8,
  773. {{0}, {0}, {64}, {0}},
  774. {{0}, {0}, {0}, {0}}},
  775. {SVGA3D_ATI1, SVGA3DBLOCKDESC_BC4_COMP_UNORM,
  776. {4, 4, 1}, 8, 8,
  777. {{0}, {0}, {64}, {0}},
  778. {{0}, {0}, {0}, {0}}},
  779. {SVGA3D_BC4_SNORM, SVGA3DBLOCKDESC_BC4_COMP_SNORM,
  780. {4, 4, 1}, 8, 8,
  781. {{0}, {0}, {64}, {0}},
  782. {{0}, {0}, {0}, {0}}},
  783. {SVGA3D_BC5_TYPELESS, SVGA3DBLOCKDESC_BC5_COMP_TYPELESS,
  784. {4, 4, 1}, 16, 16,
  785. {{0}, {0}, {128}, {0}},
  786. {{0}, {0}, {0}, {0}}},
  787. {SVGA3D_ATI2, SVGA3DBLOCKDESC_BC5_COMP_UNORM,
  788. {4, 4, 1}, 16, 16,
  789. {{0}, {0}, {128}, {0}},
  790. {{0}, {0}, {0}, {0}}},
  791. {SVGA3D_BC5_SNORM, SVGA3DBLOCKDESC_BC5_COMP_SNORM,
  792. {4, 4, 1}, 16, 16,
  793. {{0}, {0}, {128}, {0}},
  794. {{0}, {0}, {0}, {0}}},
  795. {SVGA3D_R10G10B10_XR_BIAS_A2_UNORM, SVGA3DBLOCKDESC_RGBA_UNORM,
  796. {1, 1, 1}, 4, 4,
  797. {{10}, {10}, {10}, {2}},
  798. {{20}, {10}, {0}, {30}}},
  799. {SVGA3D_B8G8R8A8_TYPELESS, SVGA3DBLOCKDESC_TYPELESS,
  800. {1, 1, 1}, 4, 4,
  801. {{8}, {8}, {8}, {8}},
  802. {{0}, {8}, {16}, {24}}},
  803. {SVGA3D_B8G8R8A8_UNORM_SRGB, SVGA3DBLOCKDESC_RGBA_UNORM_SRGB,
  804. {1, 1, 1}, 4, 4,
  805. {{8}, {8}, {8}, {8}},
  806. {{0}, {8}, {16}, {24}}},
  807. {SVGA3D_B8G8R8X8_TYPELESS, SVGA3DBLOCKDESC_TYPELESS,
  808. {1, 1, 1}, 4, 4,
  809. {{8}, {8}, {8}, {0}},
  810. {{0}, {8}, {16}, {24}}},
  811. {SVGA3D_B8G8R8X8_UNORM_SRGB, SVGA3DBLOCKDESC_RGB_UNORM_SRGB,
  812. {1, 1, 1}, 4, 4,
  813. {{8}, {8}, {8}, {0}},
  814. {{0}, {8}, {16}, {24}}},
  815. {SVGA3D_Z_DF16, SVGA3DBLOCKDESC_DEPTH_UNORM,
  816. {1, 1, 1}, 2, 2,
  817. {{0}, {0}, {16}, {0}},
  818. {{0}, {0}, {0}, {0}}},
  819. {SVGA3D_Z_DF24, SVGA3DBLOCKDESC_DEPTH_UNORM,
  820. {1, 1, 1}, 4, 4,
  821. {{0}, {0}, {24}, {0}},
  822. {{0}, {0}, {8}, {0}}},
  823. {SVGA3D_Z_D24S8_INT, SVGA3DBLOCKDESC_DS_UNORM,
  824. {1, 1, 1}, 4, 4,
  825. {{0}, {8}, {24}, {0}},
  826. {{0}, {0}, {8}, {0}}},
  827. {SVGA3D_YV12, SVGA3DBLOCKDESC_YV12,
  828. {2, 2, 1}, 6, 2,
  829. {{0}, {0}, {48}, {0}},
  830. {{0}, {0}, {0}, {0}}},
  831. {SVGA3D_R32G32B32A32_FLOAT, SVGA3DBLOCKDESC_RGBA_FP,
  832. {1, 1, 1}, 16, 16,
  833. {{32}, {32}, {32}, {32}},
  834. {{64}, {32}, {0}, {96}}},
  835. {SVGA3D_R16G16B16A16_FLOAT, SVGA3DBLOCKDESC_RGBA_FP,
  836. {1, 1, 1}, 8, 8,
  837. {{16}, {16}, {16}, {16}},
  838. {{32}, {16}, {0}, {48}}},
  839. {SVGA3D_R16G16B16A16_UNORM, SVGA3DBLOCKDESC_RGBA_UNORM,
  840. {1, 1, 1}, 8, 8,
  841. {{16}, {16}, {16}, {16}},
  842. {{32}, {16}, {0}, {48}}},
  843. {SVGA3D_R32G32_FLOAT, SVGA3DBLOCKDESC_RG_FP,
  844. {1, 1, 1}, 8, 8,
  845. {{0}, {32}, {32}, {0}},
  846. {{0}, {32}, {0}, {0}}},
  847. {SVGA3D_R10G10B10A2_UNORM, SVGA3DBLOCKDESC_RGBA_UNORM,
  848. {1, 1, 1}, 4, 4,
  849. {{10}, {10}, {10}, {2}},
  850. {{20}, {10}, {0}, {30}}},
  851. {SVGA3D_R8G8B8A8_SNORM, SVGA3DBLOCKDESC_RGBA_SNORM,
  852. {1, 1, 1}, 4, 4,
  853. {{8}, {8}, {8}, {8}},
  854. {{16}, {8}, {0}, {24}}},
  855. {SVGA3D_R16G16_FLOAT, SVGA3DBLOCKDESC_RG_FP,
  856. {1, 1, 1}, 4, 4,
  857. {{0}, {16}, {16}, {0}},
  858. {{0}, {16}, {0}, {0}}},
  859. {SVGA3D_R16G16_UNORM, SVGA3DBLOCKDESC_RG_UNORM,
  860. {1, 1, 1}, 4, 4,
  861. {{0}, {16}, {16}, {0}},
  862. {{0}, {16}, {0}, {0}}},
  863. {SVGA3D_R16G16_SNORM, SVGA3DBLOCKDESC_RG_SNORM,
  864. {1, 1, 1}, 4, 4,
  865. {{0}, {16}, {16}, {0}},
  866. {{0}, {16}, {0}, {0}}},
  867. {SVGA3D_R32_FLOAT, SVGA3DBLOCKDESC_R_FP,
  868. {1, 1, 1}, 4, 4,
  869. {{0}, {0}, {32}, {0}},
  870. {{0}, {0}, {0}, {0}}},
  871. {SVGA3D_R8G8_SNORM, SVGA3DBLOCKDESC_RG_SNORM,
  872. {1, 1, 1}, 2, 2,
  873. {{0}, {8}, {8}, {0}},
  874. {{0}, {8}, {0}, {0}}},
  875. {SVGA3D_R16_FLOAT, SVGA3DBLOCKDESC_R_FP,
  876. {1, 1, 1}, 2, 2,
  877. {{0}, {0}, {16}, {0}},
  878. {{0}, {0}, {0}, {0}}},
  879. {SVGA3D_D16_UNORM, SVGA3DBLOCKDESC_DEPTH_UNORM,
  880. {1, 1, 1}, 2, 2,
  881. {{0}, {0}, {16}, {0}},
  882. {{0}, {0}, {0}, {0}}},
  883. {SVGA3D_A8_UNORM, SVGA3DBLOCKDESC_A_UNORM,
  884. {1, 1, 1}, 1, 1,
  885. {{0}, {0}, {0}, {8}},
  886. {{0}, {0}, {0}, {0}}},
  887. {SVGA3D_BC1_UNORM, SVGA3DBLOCKDESC_BC1_COMP_UNORM,
  888. {4, 4, 1}, 8, 8,
  889. {{0}, {0}, {64}, {0}},
  890. {{0}, {0}, {0}, {0}}},
  891. {SVGA3D_BC2_UNORM, SVGA3DBLOCKDESC_BC2_COMP_UNORM,
  892. {4, 4, 1}, 16, 16,
  893. {{0}, {0}, {128}, {0}},
  894. {{0}, {0}, {0}, {0}}},
  895. {SVGA3D_BC3_UNORM, SVGA3DBLOCKDESC_BC3_COMP_UNORM,
  896. {4, 4, 1}, 16, 16,
  897. {{0}, {0}, {128}, {0}},
  898. {{0}, {0}, {0}, {0}}},
  899. {SVGA3D_B5G6R5_UNORM, SVGA3DBLOCKDESC_RGB_UNORM,
  900. {1, 1, 1}, 2, 2,
  901. {{5}, {6}, {5}, {0}},
  902. {{0}, {5}, {11}, {0}}},
  903. {SVGA3D_B5G5R5A1_UNORM, SVGA3DBLOCKDESC_RGBA_UNORM,
  904. {1, 1, 1}, 2, 2,
  905. {{5}, {5}, {5}, {1}},
  906. {{0}, {5}, {10}, {15}}},
  907. {SVGA3D_B8G8R8A8_UNORM, SVGA3DBLOCKDESC_RGBA_UNORM,
  908. {1, 1, 1}, 4, 4,
  909. {{8}, {8}, {8}, {8}},
  910. {{0}, {8}, {16}, {24}}},
  911. {SVGA3D_B8G8R8X8_UNORM, SVGA3DBLOCKDESC_RGB_UNORM,
  912. {1, 1, 1}, 4, 4,
  913. {{8}, {8}, {8}, {0}},
  914. {{0}, {8}, {16}, {24}}},
  915. {SVGA3D_BC4_UNORM, SVGA3DBLOCKDESC_BC4_COMP_UNORM,
  916. {4, 4, 1}, 8, 8,
  917. {{0}, {0}, {64}, {0}},
  918. {{0}, {0}, {0}, {0}}},
  919. {SVGA3D_BC5_UNORM, SVGA3DBLOCKDESC_BC5_COMP_UNORM,
  920. {4, 4, 1}, 16, 16,
  921. {{0}, {0}, {128}, {0}},
  922. {{0}, {0}, {0}, {0}}},
  923. };
  924. static inline u32 clamped_umul32(u32 a, u32 b)
  925. {
  926. uint64_t tmp = (uint64_t) a*b;
  927. return (tmp > (uint64_t) ((u32) -1)) ? (u32) -1 : tmp;
  928. }
  929. /**
  930. * svga3dsurface_get_desc - Look up the appropriate SVGA3dSurfaceDesc for the
  931. * given format.
  932. */
  933. static inline const struct svga3d_surface_desc *
  934. svga3dsurface_get_desc(SVGA3dSurfaceFormat format)
  935. {
  936. if (format < ARRAY_SIZE(svga3d_surface_descs))
  937. return &svga3d_surface_descs[format];
  938. return &svga3d_surface_descs[SVGA3D_FORMAT_INVALID];
  939. }
  940. /**
  941. * svga3dsurface_get_mip_size - Given a base level size and the mip level,
  942. * compute the size of the mip level.
  943. */
  944. static inline surf_size_struct
  945. svga3dsurface_get_mip_size(surf_size_struct base_level, u32 mip_level)
  946. {
  947. surf_size_struct size;
  948. size.width = max_t(u32, base_level.width >> mip_level, 1);
  949. size.height = max_t(u32, base_level.height >> mip_level, 1);
  950. size.depth = max_t(u32, base_level.depth >> mip_level, 1);
  951. size.pad64 = 0;
  952. return size;
  953. }
  954. static inline void
  955. svga3dsurface_get_size_in_blocks(const struct svga3d_surface_desc *desc,
  956. const surf_size_struct *pixel_size,
  957. surf_size_struct *block_size)
  958. {
  959. block_size->width = __KERNEL_DIV_ROUND_UP(pixel_size->width,
  960. desc->block_size.width);
  961. block_size->height = __KERNEL_DIV_ROUND_UP(pixel_size->height,
  962. desc->block_size.height);
  963. block_size->depth = __KERNEL_DIV_ROUND_UP(pixel_size->depth,
  964. desc->block_size.depth);
  965. }
  966. static inline bool
  967. svga3dsurface_is_planar_surface(const struct svga3d_surface_desc *desc)
  968. {
  969. return (desc->block_desc & SVGA3DBLOCKDESC_PLANAR_YUV) != 0;
  970. }
  971. static inline u32
  972. svga3dsurface_calculate_pitch(const struct svga3d_surface_desc *desc,
  973. const surf_size_struct *size)
  974. {
  975. u32 pitch;
  976. surf_size_struct blocks;
  977. svga3dsurface_get_size_in_blocks(desc, size, &blocks);
  978. pitch = blocks.width * desc->pitch_bytes_per_block;
  979. return pitch;
  980. }
  981. /**
  982. * svga3dsurface_get_image_buffer_size - Calculates image buffer size.
  983. *
  984. * Return the number of bytes of buffer space required to store one image of a
  985. * surface, optionally using the specified pitch.
  986. *
  987. * If pitch is zero, it is assumed that rows are tightly packed.
  988. *
  989. * This function is overflow-safe. If the result would have overflowed, instead
  990. * we return MAX_UINT32.
  991. */
  992. static inline u32
  993. svga3dsurface_get_image_buffer_size(const struct svga3d_surface_desc *desc,
  994. const surf_size_struct *size,
  995. u32 pitch)
  996. {
  997. surf_size_struct image_blocks;
  998. u32 slice_size, total_size;
  999. svga3dsurface_get_size_in_blocks(desc, size, &image_blocks);
  1000. if (svga3dsurface_is_planar_surface(desc)) {
  1001. total_size = clamped_umul32(image_blocks.width,
  1002. image_blocks.height);
  1003. total_size = clamped_umul32(total_size, image_blocks.depth);
  1004. total_size = clamped_umul32(total_size, desc->bytes_per_block);
  1005. return total_size;
  1006. }
  1007. if (pitch == 0)
  1008. pitch = svga3dsurface_calculate_pitch(desc, size);
  1009. slice_size = clamped_umul32(image_blocks.height, pitch);
  1010. total_size = clamped_umul32(slice_size, image_blocks.depth);
  1011. return total_size;
  1012. }
  1013. /**
  1014. * svga3dsurface_get_serialized_size - Get the serialized size for the image.
  1015. */
  1016. static inline u32
  1017. svga3dsurface_get_serialized_size(SVGA3dSurfaceFormat format,
  1018. surf_size_struct base_level_size,
  1019. u32 num_mip_levels,
  1020. u32 num_layers)
  1021. {
  1022. const struct svga3d_surface_desc *desc = svga3dsurface_get_desc(format);
  1023. u32 total_size = 0;
  1024. u32 mip;
  1025. for (mip = 0; mip < num_mip_levels; mip++) {
  1026. surf_size_struct size =
  1027. svga3dsurface_get_mip_size(base_level_size, mip);
  1028. total_size += svga3dsurface_get_image_buffer_size(desc,
  1029. &size, 0);
  1030. }
  1031. return total_size * num_layers;
  1032. }
  1033. /**
  1034. * svga3dsurface_get_pixel_offset - Compute the offset (in bytes) to a pixel
  1035. * in an image (or volume).
  1036. *
  1037. * @width: The image width in pixels.
  1038. * @height: The image height in pixels
  1039. */
  1040. static inline u32
  1041. svga3dsurface_get_pixel_offset(SVGA3dSurfaceFormat format,
  1042. u32 width, u32 height,
  1043. u32 x, u32 y, u32 z)
  1044. {
  1045. const struct svga3d_surface_desc *desc = svga3dsurface_get_desc(format);
  1046. const u32 bw = desc->block_size.width, bh = desc->block_size.height;
  1047. const u32 bd = desc->block_size.depth;
  1048. const u32 rowstride = __KERNEL_DIV_ROUND_UP(width, bw) *
  1049. desc->bytes_per_block;
  1050. const u32 imgstride = __KERNEL_DIV_ROUND_UP(height, bh) * rowstride;
  1051. const u32 offset = (z / bd * imgstride +
  1052. y / bh * rowstride +
  1053. x / bw * desc->bytes_per_block);
  1054. return offset;
  1055. }
  1056. static inline u32
  1057. svga3dsurface_get_image_offset(SVGA3dSurfaceFormat format,
  1058. surf_size_struct baseLevelSize,
  1059. u32 numMipLevels,
  1060. u32 face,
  1061. u32 mip)
  1062. {
  1063. u32 offset;
  1064. u32 mipChainBytes;
  1065. u32 mipChainBytesToLevel;
  1066. u32 i;
  1067. const struct svga3d_surface_desc *desc;
  1068. surf_size_struct mipSize;
  1069. u32 bytes;
  1070. desc = svga3dsurface_get_desc(format);
  1071. mipChainBytes = 0;
  1072. mipChainBytesToLevel = 0;
  1073. for (i = 0; i < numMipLevels; i++) {
  1074. mipSize = svga3dsurface_get_mip_size(baseLevelSize, i);
  1075. bytes = svga3dsurface_get_image_buffer_size(desc, &mipSize, 0);
  1076. mipChainBytes += bytes;
  1077. if (i < mip)
  1078. mipChainBytesToLevel += bytes;
  1079. }
  1080. offset = mipChainBytes * face + mipChainBytesToLevel;
  1081. return offset;
  1082. }
  1083. /**
  1084. * svga3dsurface_is_gb_screen_target_format - Is the specified format usable as
  1085. * a ScreenTarget?
  1086. * (with just the GBObjects cap-bit
  1087. * set)
  1088. * @format: format to queried
  1089. *
  1090. * RETURNS:
  1091. * true if queried format is valid for screen targets
  1092. */
  1093. static inline bool
  1094. svga3dsurface_is_gb_screen_target_format(SVGA3dSurfaceFormat format)
  1095. {
  1096. return (format == SVGA3D_X8R8G8B8 ||
  1097. format == SVGA3D_A8R8G8B8 ||
  1098. format == SVGA3D_R5G6B5 ||
  1099. format == SVGA3D_X1R5G5B5 ||
  1100. format == SVGA3D_A1R5G5B5 ||
  1101. format == SVGA3D_P8);
  1102. }
  1103. /**
  1104. * svga3dsurface_is_dx_screen_target_format - Is the specified format usable as
  1105. * a ScreenTarget?
  1106. * (with DX10 enabled)
  1107. *
  1108. * @format: format to queried
  1109. *
  1110. * Results:
  1111. * true if queried format is valid for screen targets
  1112. */
  1113. static inline bool
  1114. svga3dsurface_is_dx_screen_target_format(SVGA3dSurfaceFormat format)
  1115. {
  1116. return (format == SVGA3D_R8G8B8A8_UNORM ||
  1117. format == SVGA3D_B8G8R8A8_UNORM ||
  1118. format == SVGA3D_B8G8R8X8_UNORM);
  1119. }
  1120. /**
  1121. * svga3dsurface_is_screen_target_format - Is the specified format usable as a
  1122. * ScreenTarget?
  1123. * (for some combination of caps)
  1124. *
  1125. * @format: format to queried
  1126. *
  1127. * Results:
  1128. * true if queried format is valid for screen targets
  1129. */
  1130. static inline bool
  1131. svga3dsurface_is_screen_target_format(SVGA3dSurfaceFormat format)
  1132. {
  1133. if (svga3dsurface_is_gb_screen_target_format(format)) {
  1134. return true;
  1135. }
  1136. return svga3dsurface_is_dx_screen_target_format(format);
  1137. }
  1138. #endif /* _SVGA3D_SURFACEDEFS_H_ */