libobs-d3d11: Save all D3D11 object descriptors (for rebuilding)

master
jp9000 2016-11-03 07:30:22 -07:00
parent bab77c2afd
commit ecd5b4ee81
8 changed files with 38 additions and 28 deletions

View File

@ -19,8 +19,6 @@
void gs_index_buffer::InitBuffer()
{
D3D11_BUFFER_DESC bd;
D3D11_SUBRESOURCE_DATA srd;
HRESULT hr;
memset(&bd, 0, sizeof(bd));

View File

@ -65,7 +65,6 @@ gs_sampler_state::gs_sampler_state(gs_device_t *device,
: device (device),
info (*info)
{
D3D11_SAMPLER_DESC sd;
HRESULT hr;
vec4 v4;

View File

@ -162,11 +162,11 @@ void gs_shader::BuildConstantBuffer()
constantSize += size;
}
memset(&bd, 0, sizeof(bd));
if (constantSize) {
D3D11_BUFFER_DESC bd;
HRESULT hr;
memset(&bd, 0, sizeof(bd));
bd.ByteWidth = (constantSize+15)&0xFFFFFFF0; /* align */
bd.Usage = D3D11_USAGE_DYNAMIC;
bd.BindFlags = D3D11_BIND_CONSTANT_BUFFER;

View File

@ -25,7 +25,6 @@ gs_stage_surface::gs_stage_surface(gs_device_t *device, uint32_t width,
format (colorFormat),
dxgiFormat (ConvertGSTextureFormat(colorFormat))
{
D3D11_TEXTURE2D_DESC td;
HRESULT hr;
memset(&td, 0, sizeof(td));

View File

@ -139,7 +139,6 @@ gs_swap_chain::gs_swap_chain(gs_device *device, const gs_init_data *data)
initData (*data)
{
HRESULT hr;
DXGI_SWAP_CHAIN_DESC swapDesc;
make_swap_desc(swapDesc, data);
hr = device->factory->CreateSwapChain(device->device, &swapDesc,
@ -246,7 +245,6 @@ ID3D11DepthStencilState *gs_device::AddZStencilState()
{
HRESULT hr;
D3D11_DEPTH_STENCIL_DESC dsd;
SavedZStencilState savedState(zstencilState);
ID3D11DepthStencilState *state;
dsd.DepthEnable = zstencilState.depthEnabled;
@ -260,6 +258,7 @@ ID3D11DepthStencilState *gs_device::AddZStencilState()
ConvertStencilSide(dsd.FrontFace, zstencilState.stencilFront);
ConvertStencilSide(dsd.BackFace, zstencilState.stencilBack);
SavedZStencilState savedState(zstencilState, dsd);
hr = device->CreateDepthStencilState(&dsd, savedState.state.Assign());
if (FAILED(hr))
throw HRError("Failed to create depth stencil state", hr);
@ -274,7 +273,6 @@ ID3D11RasterizerState *gs_device::AddRasterState()
{
HRESULT hr;
D3D11_RASTERIZER_DESC rd;
SavedRasterState savedState(rasterState);
ID3D11RasterizerState *state;
memset(&rd, 0, sizeof(rd));
@ -285,6 +283,7 @@ ID3D11RasterizerState *gs_device::AddRasterState()
rd.DepthClipEnable = true;
rd.ScissorEnable = rasterState.scissorEnabled;
SavedRasterState savedState(rasterState, rd);
hr = device->CreateRasterizerState(&rd, savedState.state.Assign());
if (FAILED(hr))
throw HRError("Failed to create rasterizer state", hr);
@ -299,7 +298,6 @@ ID3D11BlendState *gs_device::AddBlendState()
{
HRESULT hr;
D3D11_BLEND_DESC bd;
SavedBlendState savedState(blendState);
ID3D11BlendState *state;
memset(&bd, 0, sizeof(bd));
@ -319,6 +317,7 @@ ID3D11BlendState *gs_device::AddBlendState()
D3D11_COLOR_WRITE_ENABLE_ALL;
}
SavedBlendState savedState(blendState, bd);
hr = device->CreateBlendState(&bd, savedState.state.Assign());
if (FAILED(hr))
throw HRError("Failed to create blend state", hr);

View File

@ -251,6 +251,9 @@ struct gs_index_buffer {
size_t num;
DataPtr indices;
D3D11_BUFFER_DESC bd = {};
D3D11_SUBRESOURCE_DATA srd = {};
void InitBuffer();
gs_index_buffer(gs_device_t *device, enum gs_index_type type,
@ -264,6 +267,7 @@ struct gs_texture {
gs_color_format format;
ComPtr<ID3D11ShaderResourceView> shaderRes;
D3D11_SHADER_RESOURCE_VIEW_DESC resourceDesc = {};
inline gs_texture() {}
@ -294,6 +298,8 @@ struct gs_texture_2d : gs_texture {
uint32_t sharedHandle = 0;
vector<vector<uint8_t>> data;
vector<D3D11_SUBRESOURCE_DATA> srd;
D3D11_TEXTURE2D_DESC td = {};
void InitSRD(vector<D3D11_SUBRESOURCE_DATA> &srd);
void InitTexture(const uint8_t **data);
@ -323,6 +329,9 @@ struct gs_zstencil_buffer {
gs_zstencil_format format;
DXGI_FORMAT dxgiFormat;
D3D11_TEXTURE2D_DESC td = {};
D3D11_DEPTH_STENCIL_VIEW_DESC dsvd = {};
void InitBuffer();
inline gs_zstencil_buffer()
@ -339,6 +348,7 @@ struct gs_zstencil_buffer {
struct gs_stage_surface {
ComPtr<ID3D11Texture2D> texture;
D3D11_TEXTURE2D_DESC td = {};
gs_device *device;
uint32_t width, height;
@ -352,6 +362,7 @@ struct gs_stage_surface {
struct gs_sampler_state {
ComPtr<ID3D11SamplerState> state;
gs_device_t *device;
D3D11_SAMPLER_DESC sd = {};
gs_sampler_info info;
gs_sampler_state(gs_device_t *device, const gs_sampler_info *info);
@ -393,6 +404,7 @@ struct gs_shader {
ComPtr<ID3D11Buffer> constants;
size_t constantSize;
D3D11_BUFFER_DESC bd = {};
vector<uint8_t> data;
inline void UpdateParam(vector<uint8_t> &constData,
@ -488,6 +500,7 @@ struct gs_swap_chain {
uint32_t numBuffers;
HWND hwnd;
gs_init_data initData;
DXGI_SWAP_CHAIN_DESC swapDesc = {};
gs_texture_2d target;
gs_zstencil_buffer zs;
@ -541,8 +554,10 @@ struct BlendState {
struct SavedBlendState : BlendState {
ComPtr<ID3D11BlendState> state;
D3D11_BLEND_DESC bd;
inline SavedBlendState(const BlendState &val) : BlendState(val)
inline SavedBlendState(const BlendState &val, D3D11_BLEND_DESC &desc)
: BlendState(val), bd(desc)
{
}
};
@ -589,9 +604,12 @@ struct ZStencilState {
struct SavedZStencilState : ZStencilState {
ComPtr<ID3D11DepthStencilState> state;
D3D11_DEPTH_STENCIL_DESC dsd;
inline SavedZStencilState(const ZStencilState &val)
: ZStencilState (val)
inline SavedZStencilState(const ZStencilState &val,
D3D11_DEPTH_STENCIL_DESC desc)
: ZStencilState (val),
dsd (desc)
{
}
};
@ -614,9 +632,12 @@ struct RasterState {
struct SavedRasterState : RasterState {
ComPtr<ID3D11RasterizerState> state;
D3D11_RASTERIZER_DESC rd;
inline SavedRasterState(const RasterState &val)
: RasterState (val)
inline SavedRasterState(const RasterState &val,
D3D11_RASTERIZER_DESC &desc)
: RasterState (val),
rd (desc)
{
}
};

View File

@ -73,8 +73,6 @@ void gs_texture_2d::BackupTexture(const uint8_t **data)
void gs_texture_2d::InitTexture(const uint8_t **data)
{
vector<D3D11_SUBRESOURCE_DATA> srd;
D3D11_TEXTURE2D_DESC td;
HRESULT hr;
memset(&td, 0, sizeof(td));
@ -118,7 +116,6 @@ void gs_texture_2d::InitTexture(const uint8_t **data)
void gs_texture_2d::InitResourceView()
{
D3D11_SHADER_RESOURCE_VIEW_DESC resourceDesc;
HRESULT hr;
memset(&resourceDesc, 0, sizeof(resourceDesc));
@ -196,20 +193,19 @@ gs_texture_2d::gs_texture_2d(gs_device_t *device, uint32_t handle)
if (FAILED(hr))
throw HRError("Failed to open resource", hr);
D3D11_TEXTURE2D_DESC desc;
texture->GetDesc(&desc);
texture->GetDesc(&td);
this->type = GS_TEXTURE_2D;
this->format = ConvertDXGITextureFormat(desc.Format);
this->format = ConvertDXGITextureFormat(td.Format);
this->levels = 1;
this->device = device;
this->width = desc.Width;
this->height = desc.Height;
this->dxgiFormat = desc.Format;
this->width = td.Width;
this->height = td.Height;
this->dxgiFormat = td.Format;
D3D11_SHADER_RESOURCE_VIEW_DESC resourceDesc = {};
resourceDesc.Format = desc.Format;
memset(&resourceDesc, 0, sizeof(resourceDesc));
resourceDesc.Format = td.Format;
resourceDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
resourceDesc.Texture2D.MipLevels = 1;

View File

@ -19,8 +19,6 @@
void gs_zstencil_buffer::InitBuffer()
{
D3D11_TEXTURE2D_DESC td;
D3D11_DEPTH_STENCIL_VIEW_DESC dsvd;
HRESULT hr;
memset(&td, 0, sizeof(td));