2012-07-23 00:08:58 -04:00
|
|
|
/*
|
2015-01-01 18:04:46 -05:00
|
|
|
* Copyright 2011-2015 Branimir Karadzic. All rights reserved.
|
2012-07-23 00:08:58 -04:00
|
|
|
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
2013-11-14 00:54:36 -05:00
|
|
|
#ifndef BGFX_RENDERER_D3D11_H_HEADER_GUARD
|
|
|
|
#define BGFX_RENDERER_D3D11_H_HEADER_GUARD
|
2012-07-23 00:08:58 -04:00
|
|
|
|
2014-08-05 01:01:20 -04:00
|
|
|
#define USE_D3D11_DYNAMIC_LIB !BX_PLATFORM_WINRT
|
|
|
|
|
|
|
|
#if !USE_D3D11_DYNAMIC_LIB
|
|
|
|
# undef BGFX_CONFIG_DEBUG_PIX
|
|
|
|
# define BGFX_CONFIG_DEBUG_PIX 0
|
|
|
|
#endif // !USE_D3D11_DYNAMIC_LIB
|
|
|
|
|
2014-10-18 18:44:45 -04:00
|
|
|
BX_PRAGMA_DIAGNOSTIC_PUSH();
|
|
|
|
BX_PRAGMA_DIAGNOSTIC_IGNORED_CLANG("-Wunknown-pragmas" );
|
|
|
|
BX_PRAGMA_DIAGNOSTIC_IGNORED_GCC("-Wpragmas");
|
|
|
|
BX_PRAGMA_DIAGNOSTIC_IGNORED_MSVC(4005) // warning C4005: '' : macro redefinition
|
2012-08-19 21:50:23 -04:00
|
|
|
#define D3D11_NO_HELPERS
|
2014-11-14 08:22:32 -05:00
|
|
|
#if BX_PLATFORM_WINRT
|
|
|
|
#include <d3d11_2.h>
|
|
|
|
#else
|
2014-10-18 18:44:45 -04:00
|
|
|
#include <d3d11.h>
|
2014-11-14 08:22:32 -05:00
|
|
|
#endif
|
2014-10-18 18:44:45 -04:00
|
|
|
BX_PRAGMA_DIAGNOSTIC_POP()
|
2014-09-28 14:03:47 -04:00
|
|
|
|
2014-12-27 22:00:41 -05:00
|
|
|
#include "renderer.h"
|
2012-07-23 00:08:58 -04:00
|
|
|
#include "renderer_d3d.h"
|
2014-10-29 01:08:55 -04:00
|
|
|
#include "ovr.h"
|
2014-12-11 23:48:16 -05:00
|
|
|
#include "renderdoc.h"
|
2012-07-23 00:08:58 -04:00
|
|
|
|
2014-10-29 01:08:55 -04:00
|
|
|
#ifndef D3DCOLOR_ARGB
|
|
|
|
# define D3DCOLOR_ARGB(_a, _r, _g, _b) ( (DWORD)( ( ( (_a)&0xff)<<24)|( ( (_r)&0xff)<<16)|( ( (_g)&0xff)<<8)|( (_b)&0xff) ) )
|
|
|
|
#endif // D3DCOLOR_ARGB
|
|
|
|
|
|
|
|
#ifndef D3DCOLOR_RGBA
|
|
|
|
# define D3DCOLOR_RGBA(_r, _g, _b, _a) D3DCOLOR_ARGB(_a, _r, _g, _b)
|
|
|
|
#endif // D3DCOLOR_RGBA
|
2013-06-09 18:28:25 -04:00
|
|
|
|
2014-11-18 00:13:55 -05:00
|
|
|
#ifndef DXGI_FORMAT_B4G4R4A4_UNORM
|
|
|
|
// Win8 only BS
|
|
|
|
// https://blogs.msdn.com/b/chuckw/archive/2012/11/14/directx-11-1-and-windows-7.aspx?Redirected=true
|
|
|
|
// http://msdn.microsoft.com/en-us/library/windows/desktop/bb173059%28v=vs.85%29.aspx
|
|
|
|
# define DXGI_FORMAT_B4G4R4A4_UNORM DXGI_FORMAT(115)
|
|
|
|
#endif // DXGI_FORMAT_B4G4R4A4_UNORM
|
|
|
|
|
|
|
|
#ifndef D3D_FEATURE_LEVEL_11_1
|
|
|
|
# define D3D_FEATURE_LEVEL_11_1 D3D_FEATURE_LEVEL(0xb100)
|
|
|
|
#endif // D3D_FEATURE_LEVEL_11_1
|
|
|
|
|
2015-03-31 20:15:17 -04:00
|
|
|
#if defined(__MINGW32__)
|
2015-01-05 23:59:58 -05:00
|
|
|
// MinGW Linux/Wine missing defines...
|
2015-03-31 20:15:17 -04:00
|
|
|
# ifndef D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT
|
|
|
|
# define D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT 8
|
|
|
|
# endif // D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT
|
2015-01-05 23:59:58 -05:00
|
|
|
|
2015-03-31 20:15:17 -04:00
|
|
|
# ifndef D3D11_PS_CS_UAV_REGISTER_COUNT
|
|
|
|
# define D3D11_PS_CS_UAV_REGISTER_COUNT 8
|
|
|
|
# endif // D3D11_PS_CS_UAV_REGISTER_COUNT
|
2015-01-05 23:59:58 -05:00
|
|
|
|
2015-03-31 20:15:17 -04:00
|
|
|
# ifndef D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT
|
|
|
|
# define D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT 8
|
|
|
|
# endif
|
|
|
|
|
|
|
|
# ifndef D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT
|
|
|
|
# define D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT 8
|
|
|
|
# endif // D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT
|
|
|
|
|
|
|
|
# ifndef D3D11_APPEND_ALIGNED_ELEMENT
|
|
|
|
# define D3D11_APPEND_ALIGNED_ELEMENT UINT32_MAX
|
|
|
|
# endif // D3D11_APPEND_ALIGNED_ELEMENT
|
2015-01-05 23:59:58 -05:00
|
|
|
|
2015-03-31 20:15:17 -04:00
|
|
|
# ifndef D3D11_REQ_MAXANISOTROPY
|
|
|
|
# define D3D11_REQ_MAXANISOTROPY 16
|
|
|
|
# endif // D3D11_REQ_MAXANISOTROPY
|
2015-01-05 23:59:58 -05:00
|
|
|
|
2015-03-31 20:15:17 -04:00
|
|
|
# ifndef D3D11_FEATURE_DATA_FORMAT_SUPPORT
|
|
|
|
typedef struct D3D11_FEATURE_DATA_FORMAT_SUPPORT
|
|
|
|
{
|
|
|
|
DXGI_FORMAT InFormat;
|
|
|
|
UINT OutFormatSupport;
|
|
|
|
} D3D11_FEATURE_DATA_FORMAT_SUPPORT;
|
|
|
|
# endif // D3D11_FEATURE_DATA_FORMAT_SUPPORT
|
|
|
|
|
|
|
|
# ifndef D3D11_FEATURE_DATA_FORMAT_SUPPORT2
|
|
|
|
typedef struct D3D11_FEATURE_DATA_FORMAT_SUPPORT2
|
|
|
|
{
|
|
|
|
DXGI_FORMAT InFormat;
|
|
|
|
UINT OutFormatSupport2;
|
|
|
|
} D3D11_FEATURE_DATA_FORMAT_SUPPORT2;
|
|
|
|
# endif // D3D11_FEATURE_DATA_FORMAT_SUPPORT2
|
|
|
|
#endif // __MINGW32__
|
2015-01-05 23:59:58 -05:00
|
|
|
|
2015-03-22 01:11:59 -04:00
|
|
|
namespace bgfx { namespace d3d11
|
2012-07-23 00:08:58 -04:00
|
|
|
{
|
2015-01-10 23:38:47 -05:00
|
|
|
struct BufferD3D11
|
2012-07-23 00:08:58 -04:00
|
|
|
{
|
2015-01-10 23:38:47 -05:00
|
|
|
BufferD3D11()
|
2012-07-23 00:08:58 -04:00
|
|
|
: m_ptr(NULL)
|
2015-01-10 23:38:47 -05:00
|
|
|
, m_srv(NULL)
|
|
|
|
, m_uav(NULL)
|
2015-04-08 22:59:48 -04:00
|
|
|
, m_flags(BGFX_BUFFER_NONE)
|
2012-07-23 00:08:58 -04:00
|
|
|
, m_dynamic(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-04-08 22:59:48 -04:00
|
|
|
void create(uint32_t _size, void* _data, uint8_t _flags, uint16_t _stride = 0, bool _vertex = false);
|
2015-01-10 23:38:47 -05:00
|
|
|
void update(uint32_t _offset, uint32_t _size, void* _data, bool _discard = false);
|
2012-07-23 00:08:58 -04:00
|
|
|
|
|
|
|
void destroy()
|
|
|
|
{
|
|
|
|
if (NULL != m_ptr)
|
|
|
|
{
|
|
|
|
DX_RELEASE(m_ptr, 0);
|
|
|
|
m_dynamic = false;
|
|
|
|
}
|
2015-01-10 23:38:47 -05:00
|
|
|
|
|
|
|
DX_RELEASE(m_srv, 0);
|
|
|
|
DX_RELEASE(m_uav, 0);
|
2012-07-23 00:08:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
ID3D11Buffer* m_ptr;
|
2015-01-10 23:38:47 -05:00
|
|
|
ID3D11ShaderResourceView* m_srv;
|
|
|
|
ID3D11UnorderedAccessView* m_uav;
|
2012-07-23 00:08:58 -04:00
|
|
|
uint32_t m_size;
|
2015-04-08 22:59:48 -04:00
|
|
|
uint8_t m_flags;
|
2012-07-23 00:08:58 -04:00
|
|
|
bool m_dynamic;
|
|
|
|
};
|
|
|
|
|
2015-01-10 23:38:47 -05:00
|
|
|
typedef BufferD3D11 IndexBufferD3D11;
|
|
|
|
|
|
|
|
struct VertexBufferD3D11 : public BufferD3D11
|
2012-07-23 00:08:58 -04:00
|
|
|
{
|
2014-05-26 17:09:26 -04:00
|
|
|
VertexBufferD3D11()
|
2015-01-10 23:38:47 -05:00
|
|
|
: BufferD3D11()
|
2012-07-23 00:08:58 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-12-10 02:16:27 -05:00
|
|
|
void create(uint32_t _size, void* _data, VertexDeclHandle _declHandle, uint8_t _flags);
|
2012-07-23 00:08:58 -04:00
|
|
|
|
|
|
|
VertexDeclHandle m_decl;
|
|
|
|
};
|
|
|
|
|
2014-05-26 17:09:26 -04:00
|
|
|
struct ShaderD3D11
|
2012-07-23 00:08:58 -04:00
|
|
|
{
|
2014-05-26 17:09:26 -04:00
|
|
|
ShaderD3D11()
|
2012-07-23 00:08:58 -04:00
|
|
|
: m_ptr(NULL)
|
|
|
|
, m_code(NULL)
|
|
|
|
, m_buffer(NULL)
|
2013-09-21 01:13:58 -04:00
|
|
|
, m_constantBuffer(NULL)
|
2012-07-23 00:08:58 -04:00
|
|
|
, m_hash(0)
|
2013-09-21 01:13:58 -04:00
|
|
|
, m_numUniforms(0)
|
|
|
|
, m_numPredefined(0)
|
2012-07-23 00:08:58 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-03-29 22:42:57 -04:00
|
|
|
void create(const Memory* _mem);
|
2012-07-23 00:08:58 -04:00
|
|
|
DWORD* getShaderCode(uint8_t _fragmentBit, const Memory* _mem);
|
|
|
|
|
|
|
|
void destroy()
|
|
|
|
{
|
2013-09-21 01:13:58 -04:00
|
|
|
if (NULL != m_constantBuffer)
|
|
|
|
{
|
|
|
|
ConstantBuffer::destroy(m_constantBuffer);
|
|
|
|
m_constantBuffer = NULL;
|
|
|
|
}
|
|
|
|
|
2012-07-23 00:08:58 -04:00
|
|
|
m_numPredefined = 0;
|
|
|
|
|
|
|
|
if (NULL != m_buffer)
|
|
|
|
{
|
|
|
|
DX_RELEASE(m_buffer, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
DX_RELEASE(m_ptr, 0);
|
|
|
|
|
|
|
|
if (NULL != m_code)
|
|
|
|
{
|
|
|
|
release(m_code);
|
|
|
|
m_code = NULL;
|
|
|
|
m_hash = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-20 23:27:13 -04:00
|
|
|
union
|
|
|
|
{
|
|
|
|
ID3D11ComputeShader* m_computeShader;
|
|
|
|
ID3D11PixelShader* m_pixelShader;
|
|
|
|
ID3D11VertexShader* m_vertexShader;
|
|
|
|
IUnknown* m_ptr;
|
|
|
|
};
|
2012-07-23 00:08:58 -04:00
|
|
|
const Memory* m_code;
|
|
|
|
ID3D11Buffer* m_buffer;
|
|
|
|
ConstantBuffer* m_constantBuffer;
|
|
|
|
|
|
|
|
PredefinedUniform m_predefined[PredefinedUniform::Count];
|
2012-08-29 01:59:48 -04:00
|
|
|
uint8_t m_attrMask[Attrib::Count];
|
2012-07-23 00:08:58 -04:00
|
|
|
|
|
|
|
uint32_t m_hash;
|
|
|
|
|
|
|
|
uint16_t m_numUniforms;
|
|
|
|
uint8_t m_numPredefined;
|
|
|
|
};
|
|
|
|
|
2014-05-26 17:09:26 -04:00
|
|
|
struct ProgramD3D11
|
2012-07-23 00:08:58 -04:00
|
|
|
{
|
2014-05-26 17:09:26 -04:00
|
|
|
ProgramD3D11()
|
2012-07-23 00:08:58 -04:00
|
|
|
: m_vsh(NULL)
|
|
|
|
, m_fsh(NULL)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-07-20 23:27:13 -04:00
|
|
|
void create(const ShaderD3D11* _vsh, const ShaderD3D11* _fsh)
|
2012-07-23 00:08:58 -04:00
|
|
|
{
|
2014-07-20 23:27:13 -04:00
|
|
|
BX_CHECK(NULL != _vsh->m_ptr, "Vertex shader doesn't exist.");
|
|
|
|
m_vsh = _vsh;
|
|
|
|
memcpy(&m_predefined[0], _vsh->m_predefined, _vsh->m_numPredefined*sizeof(PredefinedUniform) );
|
|
|
|
m_numPredefined = _vsh->m_numPredefined;
|
|
|
|
|
|
|
|
if (NULL != _fsh)
|
|
|
|
{
|
|
|
|
BX_CHECK(NULL != _fsh->m_ptr, "Fragment shader doesn't exist.");
|
|
|
|
m_fsh = _fsh;
|
|
|
|
memcpy(&m_predefined[m_numPredefined], _fsh->m_predefined, _fsh->m_numPredefined*sizeof(PredefinedUniform) );
|
|
|
|
m_numPredefined += _fsh->m_numPredefined;
|
|
|
|
}
|
2012-07-23 00:08:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void destroy()
|
|
|
|
{
|
|
|
|
m_numPredefined = 0;
|
|
|
|
m_vsh = NULL;
|
|
|
|
m_fsh = NULL;
|
|
|
|
}
|
|
|
|
|
2014-05-26 17:09:26 -04:00
|
|
|
const ShaderD3D11* m_vsh;
|
|
|
|
const ShaderD3D11* m_fsh;
|
2012-07-23 00:08:58 -04:00
|
|
|
|
|
|
|
PredefinedUniform m_predefined[PredefinedUniform::Count*2];
|
|
|
|
uint8_t m_numPredefined;
|
|
|
|
};
|
|
|
|
|
2014-05-26 17:09:26 -04:00
|
|
|
struct TextureD3D11
|
2012-07-23 00:08:58 -04:00
|
|
|
{
|
|
|
|
enum Enum
|
|
|
|
{
|
|
|
|
Texture2D,
|
|
|
|
Texture3D,
|
|
|
|
TextureCube,
|
|
|
|
};
|
|
|
|
|
2014-05-26 17:09:26 -04:00
|
|
|
TextureD3D11()
|
2012-08-19 21:50:23 -04:00
|
|
|
: m_ptr(NULL)
|
|
|
|
, m_srv(NULL)
|
2014-07-20 23:27:13 -04:00
|
|
|
, m_uav(NULL)
|
2012-08-19 21:50:23 -04:00
|
|
|
, m_sampler(NULL)
|
|
|
|
, m_numMips(0)
|
2012-07-23 00:08:58 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-02-20 01:34:53 -05:00
|
|
|
void create(const Memory* _mem, uint32_t _flags, uint8_t _skip);
|
2013-02-10 21:12:52 -05:00
|
|
|
void destroy();
|
2013-11-16 13:58:15 -05:00
|
|
|
void update(uint8_t _side, uint8_t _mip, const Rect& _rect, uint16_t _z, uint16_t _depth, uint16_t _pitch, const Memory* _mem);
|
2013-07-25 00:59:59 -04:00
|
|
|
void commit(uint8_t _stage, uint32_t _flags = BGFX_SAMPLER_DEFAULT_FLAGS);
|
2014-02-06 02:07:11 -05:00
|
|
|
void resolve();
|
2012-07-23 00:08:58 -04:00
|
|
|
|
2012-08-19 21:50:23 -04:00
|
|
|
union
|
|
|
|
{
|
|
|
|
ID3D11Resource* m_ptr;
|
|
|
|
ID3D11Texture2D* m_texture2d;
|
2012-11-25 21:24:50 -05:00
|
|
|
ID3D11Texture3D* m_texture3d;
|
2012-08-19 21:50:23 -04:00
|
|
|
};
|
|
|
|
|
2012-08-13 00:02:11 -04:00
|
|
|
ID3D11ShaderResourceView* m_srv;
|
2014-07-20 23:27:13 -04:00
|
|
|
ID3D11UnorderedAccessView* m_uav;
|
2012-07-23 00:08:58 -04:00
|
|
|
ID3D11SamplerState* m_sampler;
|
2014-02-06 02:07:11 -05:00
|
|
|
uint32_t m_flags;
|
2013-09-09 00:03:03 -04:00
|
|
|
uint8_t m_type;
|
|
|
|
uint8_t m_requestedFormat;
|
|
|
|
uint8_t m_textureFormat;
|
2012-08-19 21:50:23 -04:00
|
|
|
uint8_t m_numMips;
|
2012-07-23 00:08:58 -04:00
|
|
|
};
|
|
|
|
|
2014-05-26 17:09:26 -04:00
|
|
|
struct FrameBufferD3D11
|
2012-07-23 00:08:58 -04:00
|
|
|
{
|
2014-05-26 17:09:26 -04:00
|
|
|
FrameBufferD3D11()
|
2014-09-07 20:17:38 -04:00
|
|
|
: m_denseIdx(UINT16_MAX)
|
|
|
|
, m_num(0)
|
2012-07-23 00:08:58 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-02-06 02:07:11 -05:00
|
|
|
void create(uint8_t _num, const TextureHandle* _handles);
|
2014-09-07 20:17:38 -04:00
|
|
|
void create(uint16_t _denseIdx, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _depthFormat);
|
|
|
|
uint16_t destroy();
|
2014-02-06 02:07:11 -05:00
|
|
|
void resolve();
|
2014-09-01 14:24:51 -04:00
|
|
|
void clear(const Clear& _clear, const float _palette[][4]);
|
2012-08-05 17:51:49 -04:00
|
|
|
|
2014-02-06 02:07:11 -05:00
|
|
|
ID3D11RenderTargetView* m_rtv[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS-1];
|
|
|
|
ID3D11ShaderResourceView* m_srv[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS-1];
|
2012-11-25 21:24:50 -05:00
|
|
|
ID3D11DepthStencilView* m_dsv;
|
2014-09-07 20:17:38 -04:00
|
|
|
IDXGISwapChain* m_swapChain;
|
|
|
|
uint16_t m_denseIdx;
|
2014-02-06 02:07:11 -05:00
|
|
|
uint8_t m_num;
|
2012-07-23 00:08:58 -04:00
|
|
|
};
|
|
|
|
|
2015-03-22 01:11:59 -04:00
|
|
|
} /* namespace d3d11 */ } // namespace bgfx
|
2012-07-23 00:08:58 -04:00
|
|
|
|
2013-11-14 00:54:36 -05:00
|
|
|
#endif // BGFX_RENDERER_D3D11_H_HEADER_GUARD
|