Windows fixes

This commit is contained in:
Jack Andersen 2016-02-24 10:52:31 -10:00
parent 478b05ceb7
commit d657f3c8f8
4 changed files with 49 additions and 57 deletions

View File

@ -766,6 +766,7 @@ struct D3D11CommandQueue : IGraphicsCommandQueue
m_initcv.wait(m_initlk);
m_initlk.unlock();
ThrowIfFailed(ctx->m_dev->CreateDeferredContext1(0, &m_deferredCtx));
m_deferredCtx->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
}
void stopRenderer()
@ -846,14 +847,6 @@ struct D3D11CommandQueue : IGraphicsCommandQueue
m_deferredCtx->ClearDepthStencilView(m_boundTarget->m_dsv.Get(), D3D11_CLEAR_DEPTH, 1.0, 0);
}
void setDrawPrimitive(Primitive prim)
{
if (prim == Primitive::Triangles)
m_deferredCtx->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
else if (prim == Primitive::TriStrips)
m_deferredCtx->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
}
void draw(size_t start, size_t count)
{
m_deferredCtx->Draw(count, start);
@ -958,6 +951,7 @@ class D3D11DataFactory : public ID3DDataFactory
std::unordered_set<D3D11Data*> m_committedData;
std::mutex m_committedMutex;
std::unordered_set<D3D11Data*> m_deletedData;
uint32_t m_sampleCount;
void destroyData(IGraphicsData* d)
{
@ -996,8 +990,8 @@ class D3D11DataFactory : public ID3DDataFactory
}
public:
D3D11DataFactory(IGraphicsContext* parent, D3D11Context* ctx)
: m_parent(parent), m_ctx(ctx)
D3D11DataFactory(IGraphicsContext* parent, D3D11Context* ctx, uint32_t sampleCount)
: m_parent(parent), m_ctx(ctx), m_sampleCount(sampleCount)
{}
~D3D11DataFactory() {destroyAllData();}
@ -1035,12 +1029,12 @@ public:
GraphicsDataToken
newStaticTextureNoContext(size_t width, size_t height, size_t mips, TextureFormat fmt,
const void* data, size_t sz, ITextureS** texOut)
const void* data, size_t sz, ITextureS*& texOut)
{
D3D11TextureS* retval = new D3D11TextureS(m_ctx, width, height, mips, fmt, data, sz);
D3D11Data* tokData = new struct D3D11Data();
tokData->m_STexs.emplace_back(retval);
*texOut = retval;
texOut = retval;
std::unique_lock<std::mutex> lk(m_committedMutex);
m_committedData.insert(tokData);
@ -1067,10 +1061,10 @@ public:
return retval;
}
ITextureR* newRenderTexture(size_t width, size_t height, size_t samples)
ITextureR* newRenderTexture(size_t width, size_t height)
{
D3D11CommandQueue* q = static_cast<D3D11CommandQueue*>(m_parent->getCommandQueue());
D3D11TextureR* retval = new D3D11TextureR(m_ctx, width, height, samples);
D3D11TextureR* retval = new D3D11TextureR(m_ctx, width, height, m_sampleCount);
if (!m_deferredData)
m_deferredData = new struct D3D11Data();
static_cast<D3D11Data*>(m_deferredData)->m_RTexs.emplace_back(retval);
@ -1216,9 +1210,9 @@ IGraphicsCommandQueue* _NewD3D11CommandQueue(D3D11Context* ctx, D3D11Context::Wi
return new D3D11CommandQueue(ctx, windowCtx, parent);
}
IGraphicsDataFactory* _NewD3D11DataFactory(D3D11Context* ctx, IGraphicsContext* parent)
IGraphicsDataFactory* _NewD3D11DataFactory(D3D11Context* ctx, IGraphicsContext* parent, uint32_t sampleCount)
{
return new D3D11DataFactory(parent, ctx);
return new D3D11DataFactory(parent, ctx, sampleCount);
}
}

View File

@ -981,6 +981,7 @@ struct D3D12CommandQueue : IGraphicsCommandQueue
ThrowIfFailed(m_ctx->m_qalloc[m_fillBuf]->Reset());
ThrowIfFailed(m_cmdList->Reset(m_ctx->m_qalloc[m_fillBuf].Get(), nullptr));
m_cmdList->SetGraphicsRootSignature(m_ctx->m_rs.Get());
m_cmdList->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
}
void resetDynamicCommandList()
@ -1027,6 +1028,7 @@ struct D3D12CommandQueue : IGraphicsCommandQueue
nullptr, __uuidof(ID3D12GraphicsCommandList), &m_cmdList));
m_renderFenceHandle = CreateEvent(nullptr, FALSE, FALSE, nullptr);
m_cmdList->SetGraphicsRootSignature(m_ctx->m_rs.Get());
m_cmdList->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
ThrowIfFailed(ctx->m_dev->CreateFence(0, D3D12_FENCE_FLAG_NONE, __uuidof(ID3D12Fence), &m_dynamicBufFence));
m_dynamicBufFenceHandle = CreateEvent(nullptr, FALSE, FALSE, nullptr);
@ -1131,14 +1133,6 @@ struct D3D12CommandQueue : IGraphicsCommandQueue
}
}
void setDrawPrimitive(Primitive prim)
{
if (prim == Primitive::Triangles)
m_cmdList->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
else if (prim == Primitive::TriStrips)
m_cmdList->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
}
void draw(size_t start, size_t count)
{
m_cmdList->DrawInstanced(count, 1, start, 0);
@ -1317,6 +1311,7 @@ class D3D12DataFactory : public ID3DDataFactory
struct D3D12Context* m_ctx;
std::unordered_set<D3D12Data*> m_committedData;
std::mutex m_committedMutex;
uint32_t m_sampleCount;
void destroyData(IGraphicsData* d)
{
@ -1334,8 +1329,8 @@ class D3D12DataFactory : public ID3DDataFactory
m_committedData.clear();
}
public:
D3D12DataFactory(IGraphicsContext* parent, D3D12Context* ctx)
: m_parent(parent), m_ctx(ctx)
D3D12DataFactory(IGraphicsContext* parent, D3D12Context* ctx, uint32_t sampleCount)
: m_parent(parent), m_ctx(ctx), m_sampleCount(sampleCount)
{
CD3DX12_DESCRIPTOR_RANGE ranges[] =
{
@ -1391,12 +1386,12 @@ public:
GraphicsDataToken
newStaticTextureNoContext(size_t width, size_t height, size_t mips, TextureFormat fmt,
const void* data, size_t sz, ITextureS** texOut)
const void* data, size_t sz, ITextureS*& texOut)
{
D3D12TextureS* retval = new D3D12TextureS(m_ctx, width, height, mips, fmt, data, sz);
D3D12Data* tokData = new struct D3D12Data();
tokData->m_STexs.emplace_back(retval);
*texOut = retval;
texOut = retval;
/* Create heap */
D3D12_RESOURCE_ALLOCATION_INFO texAllocInfo =
@ -1451,10 +1446,10 @@ public:
return retval;
}
ITextureR* newRenderTexture(size_t width, size_t height, size_t samples)
ITextureR* newRenderTexture(size_t width, size_t height)
{
D3D12CommandQueue* q = static_cast<D3D12CommandQueue*>(m_parent->getCommandQueue());
D3D12TextureR* retval = new D3D12TextureR(m_ctx, q, width, height, samples);
D3D12TextureR* retval = new D3D12TextureR(m_ctx, q, width, height, m_sampleCount);
if (!m_deferredData)
m_deferredData = new struct D3D12Data();
static_cast<D3D12Data*>(m_deferredData)->m_RTexs.emplace_back(retval);
@ -1724,9 +1719,9 @@ IGraphicsCommandQueue* _NewD3D12CommandQueue(D3D12Context* ctx, D3D12Context::Wi
return new struct D3D12CommandQueue(ctx, windowCtx, parent, cmdQueueOut);
}
IGraphicsDataFactory* _NewD3D12DataFactory(D3D12Context* ctx, IGraphicsContext* parent)
IGraphicsDataFactory* _NewD3D12DataFactory(D3D12Context* ctx, IGraphicsContext* parent, uint32_t sampleCount)
{
return new D3D12DataFactory(parent, ctx);
return new D3D12DataFactory(parent, ctx, sampleCount);
}
}

View File

@ -60,7 +60,7 @@ namespace boo
static LogVisor::LogModule Log("boo::ApplicationWin32");
Win32Cursors WIN32_CURSORS;
IWindow* _WindowWin32New(const SystemString& title, Boo3DAppContext& d3dCtx);
IWindow* _WindowWin32New(const SystemString& title, Boo3DAppContext& d3dCtx, uint32_t sampleCount);
class ApplicationWin32 final : public IApplication
{
@ -303,7 +303,7 @@ public:
/* New-window message (coalesced onto main thread) */
std::unique_lock<std::mutex> lk(m_nwmt);
const SystemString* title = reinterpret_cast<const SystemString*>(msg.wParam);
m_mwret = newWindow(*title);
m_mwret = newWindow(*title, 1);
lk.unlock();
m_nwcv.notify_one();
continue;
@ -359,7 +359,7 @@ public:
std::mutex m_nwmt;
std::condition_variable m_nwcv;
IWindow* m_mwret = nullptr;
IWindow* newWindow(const SystemString& title)
IWindow* newWindow(const SystemString& title, uint32_t sampleCount)
{
if (GetCurrentThreadId() != g_mainThreadId)
{
@ -370,7 +370,7 @@ public:
return m_mwret;
}
IWindow* window = _WindowWin32New(title, m_3dCtx);
IWindow* window = _WindowWin32New(title, m_3dCtx, sampleCount);
HWND hwnd = HWND(window->getPlatformHandle());
m_allWindows[hwnd] = window;
return window;

View File

@ -25,10 +25,10 @@ static LogVisor::LogModule Log("boo::WindowWin32");
#if _WIN32_WINNT_WIN10
IGraphicsCommandQueue* _NewD3D12CommandQueue(D3D12Context* ctx, D3D12Context::Window* windowCtx, IGraphicsContext* parent,
ID3D12CommandQueue** cmdQueueOut);
IGraphicsDataFactory* _NewD3D12DataFactory(D3D12Context* ctx, IGraphicsContext* parent);
IGraphicsDataFactory* _NewD3D12DataFactory(D3D12Context* ctx, IGraphicsContext* parent, uint32_t sampleCount);
#endif
IGraphicsCommandQueue* _NewD3D11CommandQueue(D3D11Context* ctx, D3D11Context::Window* windowCtx, IGraphicsContext* parent);
IGraphicsDataFactory* _NewD3D11DataFactory(D3D11Context* ctx, IGraphicsContext* parent);
IGraphicsDataFactory* _NewD3D11DataFactory(D3D11Context* ctx, IGraphicsContext* parent, uint32_t sampleCount);
IGraphicsCommandQueue* _NewGLCommandQueue(IGraphicsContext* parent);
struct GraphicsContextWin32 : IGraphicsContext
@ -55,7 +55,8 @@ struct GraphicsContextWin32D3D : GraphicsContextWin32
public:
IWindowCallback* m_callback;
GraphicsContextWin32D3D(EGraphicsAPI api, IWindow* parentWindow, HWND hwnd, Boo3DAppContext& b3dCtx)
GraphicsContextWin32D3D(EGraphicsAPI api, IWindow* parentWindow, HWND hwnd,
Boo3DAppContext& b3dCtx, uint32_t sampleCount)
: GraphicsContextWin32(api, parentWindow, b3dCtx)
{
/* Create Swap Chain */
@ -74,11 +75,11 @@ public:
D3D12Context::Window& w = insIt.first->second;
ID3D12CommandQueue* cmdQueue;
m_dataFactory = _NewD3D12DataFactory(&b3dCtx.m_ctx12, this);
m_dataFactory = _NewD3D12DataFactory(&b3dCtx.m_ctx12, this, sampleCount);
m_commandQueue = _NewD3D12CommandQueue(&b3dCtx.m_ctx12, &w, this, &cmdQueue);
scDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD;
HRESULT hr = b3dCtx.m_ctx12.m_dxFactory->CreateSwapChainForHwnd(cmdQueue,
HRESULT hr = b3dCtx.m_ctx12.m_dxFactory->CreateSwapChainForHwnd(cmdQueue,
hwnd, &scDesc, nullptr, nullptr, &m_swapChain);
if (FAILED(hr))
Log.report(LogVisor::FatalError, "unable to create swap chain");
@ -98,11 +99,11 @@ public:
else
#endif
{
if (FAILED(b3dCtx.m_ctx11.m_dxFactory->CreateSwapChainForHwnd(b3dCtx.m_ctx11.m_dev.Get(),
if (FAILED(b3dCtx.m_ctx11.m_dxFactory->CreateSwapChainForHwnd(b3dCtx.m_ctx11.m_dev.Get(),
hwnd, &scDesc, nullptr, nullptr, &m_swapChain)))
Log.report(LogVisor::FatalError, "unable to create swap chain");
b3dCtx.m_ctx11.m_dxFactory->MakeWindowAssociation(hwnd, DXGI_MWA_NO_ALT_ENTER);
auto insIt = b3dCtx.m_ctx11.m_windows.emplace(std::make_pair(parentWindow, D3D11Context::Window()));
D3D11Context::Window& w = insIt.first->second;
@ -113,7 +114,7 @@ public:
fbRes->GetDesc(&resDesc);
w.width = resDesc.Width;
w.height = resDesc.Height;
m_dataFactory = _NewD3D11DataFactory(&b3dCtx.m_ctx11, this);
m_dataFactory = _NewD3D11DataFactory(&b3dCtx.m_ctx11, this, sampleCount);
m_commandQueue = _NewD3D11CommandQueue(&b3dCtx.m_ctx11, &insIt.first->second, this);
if (FAILED(m_swapChain->GetContainingOutput(&m_output)))
@ -190,7 +191,8 @@ struct GraphicsContextWin32GL : GraphicsContextWin32
public:
IWindowCallback* m_callback;
GraphicsContextWin32GL(EGraphicsAPI api, IWindow* parentWindow, HWND hwnd, Boo3DAppContext& b3dCtx)
GraphicsContextWin32GL(EGraphicsAPI api, IWindow* parentWindow, HWND hwnd,
Boo3DAppContext& b3dCtx, uint32_t sampleCount)
: GraphicsContextWin32(api, parentWindow, b3dCtx)
{
@ -250,7 +252,7 @@ public:
0, 0, 0
};
int pf = ChoosePixelFormat(w.m_deviceContext, &pfd);
int pf = ChoosePixelFormat(w.m_deviceContext, &pfd);
SetPixelFormat(w.m_deviceContext, pf, &pfd);
}
@ -262,7 +264,7 @@ public:
Log.report(LogVisor::FatalError, "unable to share contexts");
m_3dCtx.m_ctxOgl.m_lastContext = w.m_mainContext;
m_dataFactory = new GLDataFactory(this);
m_dataFactory = new GLDataFactory(this, sampleCount);
m_commandQueue = _NewGLCommandQueue(this);
}
@ -295,14 +297,14 @@ public:
void initializeContext() {}
void makeCurrent()
void makeCurrent()
{
OGLContext::Window& w = m_3dCtx.m_ctxOgl.m_windows[m_parentWindow];
if (!wglMakeCurrent(w.m_deviceContext, w.m_mainContext))
Log.report(LogVisor::FatalError, "unable to make WGL context current");
}
void postInit()
void postInit()
{
OGLContext::Window& w = m_3dCtx.m_ctxOgl.m_windows[m_parentWindow];
@ -319,7 +321,7 @@ public:
wglSwapIntervalEXT(1);
}
void present()
void present()
{
OGLContext::Window& w = m_3dCtx.m_ctxOgl.m_windows[m_parentWindow];
SwapBuffers(w.m_deviceContext);
@ -676,7 +678,7 @@ static std::unique_ptr<uint8_t[]> MakeUnicodeLF(const wchar_t* data, size_t sz,
}
return ret;
}
class WindowWin32 : public IWindow
{
friend struct GraphicsContextWin32;
@ -707,7 +709,7 @@ class WindowWin32 : public IWindow
public:
WindowWin32(const SystemString& title, Boo3DAppContext& b3dCtx)
WindowWin32(const SystemString& title, Boo3DAppContext& b3dCtx, uint32_t sampleCount)
{
m_hwnd = CreateWindowW(L"BooWindow", title.c_str(), WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
@ -720,10 +722,11 @@ public:
#endif
if (b3dCtx.m_ctxOgl.m_dxFactory)
{
m_gfxCtx.reset(new GraphicsContextWin32GL(IGraphicsContext::EGraphicsAPI::OpenGL3_3, this, m_hwnd, b3dCtx));
m_gfxCtx.reset(new GraphicsContextWin32GL(IGraphicsContext::EGraphicsAPI::OpenGL3_3,
this, m_hwnd, b3dCtx, sampleCount));
return;
}
m_gfxCtx.reset(new GraphicsContextWin32D3D(api, this, m_hwnd, b3dCtx));
m_gfxCtx.reset(new GraphicsContextWin32D3D(api, this, m_hwnd, b3dCtx, sampleCount));
}
~WindowWin32()
@ -1288,9 +1291,9 @@ public:
};
IWindow* _WindowWin32New(const SystemString& title, Boo3DAppContext& d3dCtx)
IWindow* _WindowWin32New(const SystemString& title, Boo3DAppContext& d3dCtx, uint32_t sampleCount)
{
return new WindowWin32(title, d3dCtx);
return new WindowWin32(title, d3dCtx, sampleCount);
}
}