mirror of
https://github.com/obsproject/obs-studio.git
synced 2024-09-19 20:32:15 +02:00
libobs-d3d12: device create
This commit is contained in:
parent
26ad673832
commit
930d2db103
@ -23,6 +23,7 @@ add_subdirectory(libobs)
|
||||
if(OS_WINDOWS)
|
||||
add_subdirectory(libobs-d3d11)
|
||||
add_subdirectory(libobs-winrt)
|
||||
add_subdirectory(libobs-d3d12)
|
||||
endif()
|
||||
add_subdirectory(libobs-opengl)
|
||||
add_subdirectory(plugins)
|
||||
|
@ -19,12 +19,8 @@ target_link_libraries(libobs-d3d12 PRIVATE OBS::libobs)
|
||||
|
||||
set_target_properties_obs(
|
||||
libobs-d3d12
|
||||
PROPERTIES
|
||||
FOLDER
|
||||
core
|
||||
VERSION
|
||||
0
|
||||
SOVERSION
|
||||
${OBS_VERSION_MAJOR}
|
||||
COMPILE_WARNING_AS_ERROR
|
||||
FALSE)
|
||||
PROPERTIES FOLDER core
|
||||
VERSION 0
|
||||
SOVERSION ${OBS_VERSION_MAJOR}
|
||||
COMPILE_WARNING_AS_ERROR FALSE
|
||||
)
|
||||
|
@ -39,7 +39,7 @@ struct UnsupportedHWError : HRError {
|
||||
#pragma warning(disable : 4316)
|
||||
#endif
|
||||
|
||||
static inline void LogD3D11ErrorDetails(HRError error, gs_device_t *device)
|
||||
static inline void LogD3D12ErrorDetails(HRError error, gs_device_t *device)
|
||||
{
|
||||
if (error.hr == DXGI_ERROR_DEVICE_REMOVED) {
|
||||
HRESULT DeviceRemovedReason =
|
||||
@ -125,15 +125,21 @@ make_swap_desc(gs_device *device, DXGI_SWAP_CHAIN_DESC &desc,
|
||||
return space;
|
||||
}
|
||||
|
||||
void gs_device::InitFactory() {}
|
||||
void gs_device::InitFactory()
|
||||
{
|
||||
HRESULT hr = CreateDXGIFactory2(0, IID_PPV_ARGS(&factory));
|
||||
if (FAILED(hr))
|
||||
throw UnsupportedHWError("Failed to create DXGIFactory6", hr);
|
||||
}
|
||||
|
||||
void gs_device::InitAdapter(uint32_t adapterIdx) {}
|
||||
|
||||
const static D3D_FEATURE_LEVEL featureLevels[] = {
|
||||
D3D_FEATURE_LEVEL_12_0, D3D_FEATURE_LEVEL_12_1, D3D_FEATURE_LEVEL_12_2};
|
||||
|
||||
#define NV12_CX 128
|
||||
#define NV12_CY 128
|
||||
void gs_device::InitAdapter(uint32_t adapterIdx)
|
||||
{
|
||||
HRESULT hr = factory->EnumAdapterByGpuPreference(
|
||||
adapterIdx, DXGI_GPU_PREFERENCE_HIGH_PERFORMANCE,
|
||||
IID_PPV_ARGS(&adapter));
|
||||
if (FAILED(hr))
|
||||
throw UnsupportedHWError("Failed to enumerate DXGIAdapter4", hr);
|
||||
}
|
||||
|
||||
bool gs_device::HasBadNV12Output()
|
||||
try {
|
||||
@ -147,13 +153,23 @@ try {
|
||||
return false;
|
||||
}
|
||||
|
||||
void gs_device::InitDevice(uint32_t adapterIdx) {}
|
||||
void gs_device::InitDevice(uint32_t adapterIdx) {
|
||||
DXGI_ADAPTER_DESC3 desc;
|
||||
HRESULT hr = adapter->GetDesc3(&desc);
|
||||
if (hr != S_OK) {
|
||||
throw UnsupportedHWError("Adapter4 Failed to GetDesc", hr);
|
||||
}
|
||||
// todo log desc info
|
||||
hr = D3D12CreateDevice(adapter, D3D_FEATURE_LEVEL_12_2, IID_PPV_ARGS(&device));
|
||||
if (FAILED(hr)) {
|
||||
throw UnsupportedHWError("Failed to D3D12CreateDevice", hr);
|
||||
}
|
||||
}
|
||||
|
||||
void gs_device::UpdateZStencilState() {}
|
||||
void gs_device::UpdatePipelineState() {
|
||||
|
||||
void gs_device::UpdateRasterState() {}
|
||||
}
|
||||
|
||||
void gs_device::UpdateBlendState() {}
|
||||
|
||||
void gs_device::UpdateViewProjMatrix()
|
||||
{
|
||||
@ -172,7 +188,7 @@ void gs_device::UpdateViewProjMatrix()
|
||||
void gs_device::FlushOutputViews() {}
|
||||
|
||||
gs_device::gs_device(uint32_t adapterIdx)
|
||||
: curToplogy(D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED)
|
||||
: curToplogy(D3D_PRIMITIVE_TOPOLOGY_UNDEFINED)
|
||||
{
|
||||
matrix4_identity(&curProjMatrix);
|
||||
matrix4_identity(&curViewMatrix);
|
||||
@ -214,8 +230,9 @@ int device_create(gs_device_t **p_device, uint32_t adapter)
|
||||
int errorcode = GS_SUCCESS;
|
||||
|
||||
try {
|
||||
blog(LOG_INFO, "----------------------------------");
|
||||
blog(LOG_INFO, "Initializing D3D12...");
|
||||
device = new gs_device(adapter);
|
||||
|
||||
} catch (const UnsupportedHWError &error) {
|
||||
blog(LOG_ERROR, "device_create (D3D12): %s (%08lX)", error.str,
|
||||
error.hr);
|
||||
|
@ -521,7 +521,7 @@ struct gs_pixel_shader : gs_shader {
|
||||
struct gs_swap_chain : gs_obj {
|
||||
HWND hwnd;
|
||||
gs_init_data initData;
|
||||
DXGI_SWAP_CHAIN_DESC swapDesc = {};
|
||||
DXGI_SWAP_CHAIN_DESC1 swapDesc = {};
|
||||
gs_color_space space;
|
||||
|
||||
gs_texture_2d target;
|
||||
@ -534,7 +534,6 @@ struct gs_swap_chain : gs_obj {
|
||||
void Resize(uint32_t cx, uint32_t cy, gs_color_format format);
|
||||
void Init();
|
||||
// todo
|
||||
void Rebuild(ID3D12Device *dev);
|
||||
|
||||
gs_swap_chain(gs_device *device, const gs_init_data *data);
|
||||
virtual ~gs_swap_chain();
|
||||
@ -555,25 +554,24 @@ struct BlendState {
|
||||
|
||||
inline BlendState()
|
||||
: blendEnabled(true),
|
||||
srcFactorC(GS_BLEND_SRCALPHA),
|
||||
destFactorC(GS_BLEND_INVSRCALPHA),
|
||||
srcFactorA(GS_BLEND_ONE),
|
||||
destFactorA(GS_BLEND_INVSRCALPHA),
|
||||
op(GS_BLEND_OP_ADD),
|
||||
redEnabled(true),
|
||||
greenEnabled(true),
|
||||
blueEnabled(true),
|
||||
alphaEnabled(true)
|
||||
srcFactorC(GS_BLEND_SRCALPHA),
|
||||
destFactorC(GS_BLEND_INVSRCALPHA),
|
||||
srcFactorA(GS_BLEND_ONE),
|
||||
destFactorA(GS_BLEND_INVSRCALPHA),
|
||||
op(GS_BLEND_OP_ADD),
|
||||
redEnabled(true),
|
||||
greenEnabled(true),
|
||||
blueEnabled(true),
|
||||
alphaEnabled(true)
|
||||
{
|
||||
}
|
||||
|
||||
inline BlendState(const BlendState &state)
|
||||
inline BlendState(const BlendState& state)
|
||||
{
|
||||
memcpy(this, &state, sizeof(BlendState));
|
||||
}
|
||||
};
|
||||
|
||||
struct SavedBlendState : BlendState {};
|
||||
|
||||
struct StencilSide {
|
||||
gs_depth_test test;
|
||||
@ -583,9 +581,9 @@ struct StencilSide {
|
||||
|
||||
inline StencilSide()
|
||||
: test(GS_ALWAYS),
|
||||
fail(GS_KEEP),
|
||||
zfail(GS_KEEP),
|
||||
zpass(GS_KEEP)
|
||||
fail(GS_KEEP),
|
||||
zfail(GS_KEEP),
|
||||
zpass(GS_KEEP)
|
||||
{
|
||||
}
|
||||
};
|
||||
@ -602,35 +600,31 @@ struct ZStencilState {
|
||||
|
||||
inline ZStencilState()
|
||||
: depthEnabled(true),
|
||||
depthWriteEnabled(true),
|
||||
depthFunc(GS_LESS),
|
||||
stencilEnabled(false),
|
||||
stencilWriteEnabled(true)
|
||||
depthWriteEnabled(true),
|
||||
depthFunc(GS_LESS),
|
||||
stencilEnabled(false),
|
||||
stencilWriteEnabled(true)
|
||||
{
|
||||
}
|
||||
|
||||
inline ZStencilState(const ZStencilState &state)
|
||||
inline ZStencilState(const ZStencilState& state)
|
||||
{
|
||||
memcpy(this, &state, sizeof(ZStencilState));
|
||||
}
|
||||
};
|
||||
|
||||
struct SavedZStencilState : ZStencilState {};
|
||||
|
||||
struct RasterState {
|
||||
gs_cull_mode cullMode;
|
||||
bool scissorEnabled;
|
||||
|
||||
inline RasterState() : cullMode(GS_BACK), scissorEnabled(false) {}
|
||||
|
||||
inline RasterState(const RasterState &state)
|
||||
inline RasterState(const RasterState& state)
|
||||
{
|
||||
memcpy(this, &state, sizeof(RasterState));
|
||||
}
|
||||
};
|
||||
|
||||
struct SavedRasterState : RasterState {};
|
||||
|
||||
struct mat4float {
|
||||
float mat[16];
|
||||
};
|
||||
@ -649,10 +643,16 @@ struct gs_monitor_color_info {
|
||||
}
|
||||
};
|
||||
|
||||
struct SavedPipelineState {
|
||||
ComPtr<ID3D12PipelineState> pipeline_state;
|
||||
D3D12_GRAPHICS_PIPELINE_STATE_DESC desc;
|
||||
};
|
||||
|
||||
struct gs_device {
|
||||
ComPtr<IDXGIFactory6> factory;
|
||||
ComPtr<IDXGIAdapter4> adapter;
|
||||
ComPtr<ID3D12Device1> device;
|
||||
ComPtr<ID3D12CommandQueue> commandQueue;
|
||||
ComPtr<ID3D12GraphicsCommandList2> context;
|
||||
uint32_t adpIdx = 0;
|
||||
bool nv12Supported = false;
|
||||
@ -676,19 +676,16 @@ struct gs_device {
|
||||
gs_vertex_buffer *lastVertexBuffer = nullptr;
|
||||
gs_vertex_shader *lastVertexShader = nullptr;
|
||||
|
||||
// pipeline state
|
||||
bool zstencilStateChanged = true;
|
||||
bool rasterStateChanged = true;
|
||||
bool blendStateChanged = true;
|
||||
ZStencilState zstencilState;
|
||||
RasterState rasterState;
|
||||
BlendState blendState;
|
||||
std::vector<SavedZStencilState> zstencilStates;
|
||||
std::vector<SavedRasterState> rasterStates;
|
||||
std::vector<SavedBlendState> blendStates;
|
||||
// ID3D12DepthStencilState *curDepthStencilState = nullptr;
|
||||
// ID3D12RasterizerState *curRasterState = nullptr;
|
||||
// ID3D12BlendState *curBlendState = nullptr;
|
||||
std::vector<SavedPipelineState> SavedPipelineState;
|
||||
D3D_PRIMITIVE_TOPOLOGY curToplogy;
|
||||
ComPtr<ID3D12PipelineState> currentPipelineState;
|
||||
|
||||
gs_rect viewport;
|
||||
|
||||
@ -707,19 +704,10 @@ struct gs_device {
|
||||
void InitAdapter(uint32_t adapterIdx);
|
||||
void InitDevice(uint32_t adapterIdx);
|
||||
|
||||
// ID3D11DepthStencilState *AddZStencilState();
|
||||
// ID3D11RasterizerState *AddRasterState();
|
||||
// ID3D11BlendState *AddBlendState();
|
||||
void UpdateZStencilState();
|
||||
void UpdateRasterState();
|
||||
void UpdateBlendState();
|
||||
void UpdatePipelineState();
|
||||
|
||||
void LoadVertexBufferData();
|
||||
|
||||
// void CopyTex(ID3D11Texture2D *dst, uint32_t dst_x, uint32_t dst_y,
|
||||
// gs_texture_t *src, uint32_t src_x, uint32_t src_y,
|
||||
// uint32_t src_w, uint32_t src_h);
|
||||
|
||||
void UpdateViewProjMatrix();
|
||||
|
||||
void FlushOutputViews();
|
||||
|
Loading…
Reference in New Issue
Block a user