OVR_CAPI_D3D.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /********************************************************************************//**
  2. \file OVR_CAPI_D3D.h
  3. \brief D3D specific structures used by the CAPI interface.
  4. \copyright Copyright 2014 Oculus VR, LLC All Rights reserved.
  5. ************************************************************************************/
  6. #ifndef OVR_CAPI_D3D_h
  7. #define OVR_CAPI_D3D_h
  8. #include "OVR_CAPI.h"
  9. #if defined(_MSC_VER)
  10. #pragma warning(push)
  11. #pragma warning(disable: 4324) // structure was padded due to __declspec(align())
  12. #endif
  13. //-----------------------------------------------------------------------------------
  14. // ***** D3D11 Specific
  15. #if defined(_MSC_VER)
  16. #pragma warning(push, 0)
  17. #endif
  18. #include <d3d11.h>
  19. #if defined(_MSC_VER)
  20. #pragma warning(pop)
  21. #endif
  22. /// Used to pass D3D11 eye texture data to ovr_EndFrame.
  23. typedef struct OVR_ALIGNAS(OVR_PTR_SIZE) ovrD3D11TextureData_
  24. {
  25. ovrTextureHeader Header; ///< General device settings.
  26. OVR_ON64(OVR_UNUSED_STRUCT_PAD(pad0, 4)) ///< \internal struct padding.
  27. ID3D11Texture2D* pTexture; ///< The D3D11 texture containing the undistorted eye image.
  28. ID3D11ShaderResourceView* pSRView; ///< The D3D11 shader resource view for this texture.
  29. } ovrD3D11TextureData;
  30. OVR_STATIC_ASSERT(sizeof(ovrTexture) >= sizeof(ovrD3D11TextureData), "Insufficient size.");
  31. OVR_STATIC_ASSERT(sizeof(ovrD3D11TextureData) == sizeof(ovrTextureHeader) OVR_ON64(+4) + 2 * OVR_PTR_SIZE, "size mismatch");
  32. /// Contains D3D11-specific texture information.
  33. union ovrD3D11Texture
  34. {
  35. ovrTexture Texture; ///< General device settings.
  36. ovrD3D11TextureData D3D11; ///< D3D11-specific settings.
  37. };
  38. #if defined(_MSC_VER)
  39. #pragma warning(pop)
  40. #endif
  41. /// Flags used when creating a swap texture set for a D3D11 renderer
  42. typedef enum ovrSwapTextureSetD3D11Flags_
  43. {
  44. ovrSwapTextureSetD3D11_Typeless = 0x0001, ///< Forces creation of a DXGI_*_TYPELESS texture. ShaderResourceView still uses specified format.
  45. ovrSwapTextureSetD3D11_EnumSize = 0x7fffffff ///< \internal Force type int32_t.
  46. } ovrSwapTextureSetD3D11Flags;
  47. /// Create Texture Set suitable for use with D3D11.
  48. ///
  49. /// Multiple calls to ovr_CreateSwapTextureSetD3D11 for the same ovrHmd are supported, but applications
  50. /// cannot rely on switching between ovrSwapTextureSets at runtime without a performance penalty.
  51. ///
  52. /// \param[in] session Specifies an ovrSession previously returned by ovr_Create.
  53. /// \param[in] device Specifies the associated ID3D11Device, which must be the one that the textures will be used with in the application's process.
  54. /// \param[in] desc Specifies requested texture properties. See notes for more info about texture format.
  55. /// \param[in] miscFlags Specifies misc bit flags of type \a ovrSwapTextureSetD3D11Flags used when creating the swap textures
  56. /// \param[out] outTextureSet Specifies the created ovrSwapTextureSet, which will be valid upon a successful return value, else it will be NULL.
  57. /// This texture set must be eventually destroyed via ovr_DestroySwapTextureSet before destroying the HMD with ovr_Destroy.
  58. ///
  59. /// \return Returns an ovrResult indicating success or failure. In the case of failure, use
  60. /// ovr_GetLastErrorInfo to get more information.
  61. ///
  62. /// \note The texture format provided in \a desc should be thought of as the format the distortion-compositor will use for the
  63. /// ShaderResourceView when reading the contents of the texture. To that end, it is highly recommended that the application
  64. /// requests swap-texture-set formats that are in sRGB-space (e.g. DXGI_FORMAT_R8G8B8A8_UNORM_SRGB) as the compositor
  65. /// does sRGB-correct rendering. As such, the compositor relies on the GPU's hardware sampler to do the sRGB-to-linear
  66. /// conversion. If the application still prefers to render to a linear format (e.g. DXGI_FORMAT_R8G8B8A8_UNORM) while handling the
  67. /// linear-to-gamma conversion via HLSL code, then the application must still request the corresponding sRGB format and also use
  68. /// the \a ovrSwapTextureSetD3D11_Typeless flag. This will allow the application to create a RenderTargetView that is the desired
  69. /// linear format while the compositor continues to treat it as sRGB. Failure to do so will cause the compositor to apply
  70. /// unexpected gamma conversions leading to gamma-curve artifacts. The \a ovrSwapTextureSetD3D11_Typeless flag for depth buffer
  71. /// formats (e.g. DXGI_FORMAT_D32) are ignored as they are always converted to be typeless.
  72. ///
  73. /// \see ovr_DestroySwapTextureSet
  74. ///
  75. OVR_PUBLIC_FUNCTION(ovrResult) ovr_CreateSwapTextureSetD3D11(ovrSession session,
  76. ID3D11Device* device,
  77. const D3D11_TEXTURE2D_DESC* desc,
  78. unsigned int miscFlags,
  79. ovrSwapTextureSet** outTextureSet);
  80. /// Create Mirror Texture which is auto-refreshed to mirror Rift contents produced by this application.
  81. ///
  82. /// A second call to ovr_CreateMirrorTextureD3D11 for a given ovrHmd before destroying the first one
  83. /// is not supported and will result in an error return.
  84. ///
  85. /// \param[in] session Specifies an ovrSession previously returned by ovr_Create.
  86. /// \param[in] device Specifies the associated ID3D11Device, which must be the one that the textures will be used with in the application's process.
  87. /// \param[in] desc Specifies requested texture properties. See notes for info about texture format.
  88. /// \param[in] miscFlags Specifies misc bit flags of type \a ovrSwapTextureSetD3D11Flags used when creating the swap textures
  89. /// \param[out] outMirrorTexture Specifies the created ovrTexture, which will be valid upon a successful return value, else it will be NULL.
  90. /// This texture must be eventually destroyed via ovr_DestroyMirrorTexture before destroying the HMD with ovr_Destroy.
  91. ///
  92. /// \return Returns an ovrResult indicating success or failure. In the case of failure, use
  93. /// ovr_GetLastErrorInfo to get more information.
  94. ///
  95. /// \note The texture format provided in \a desc should be thought of as the format the compositor will use for the RenderTargetView when
  96. /// writing into mirror texture. To that end, it is highly recommended that the application requests a mirror texture format that is
  97. /// in sRGB-space (e.g. DXGI_FORMAT_R8G8B8A8_UNORM_SRGB) as the compositor does sRGB-correct rendering. If however the application wants
  98. /// to still read the mirror texture as a linear format (e.g. DXGI_FORMAT_R8G8B8A8_UNORM) and handle the sRGB-to-linear conversion in
  99. /// HLSL code, then it is recommended the application still requests an sRGB format and also use the \a ovrSwapTextureSetD3D11_Typeless
  100. /// flag. This will allow the application to bind a ShaderResourceView that is a linear format while the compositor continues
  101. /// to treat is as sRGB. Failure to do so will cause the compositor to apply unexpected gamma conversions leading to
  102. /// gamma-curve artifacts.
  103. ///
  104. /// \see ovr_DestroyMirrorTexture
  105. ///
  106. OVR_PUBLIC_FUNCTION(ovrResult) ovr_CreateMirrorTextureD3D11(ovrSession session,
  107. ID3D11Device* device,
  108. const D3D11_TEXTURE2D_DESC* desc,
  109. unsigned int miscFlags,
  110. ovrTexture** outMirrorTexture);
  111. #endif // OVR_CAPI_D3D_h