Windows build fixes and cleanups

This commit is contained in:
Jack Andersen 2018-05-24 20:30:42 -10:00
parent 721d10919b
commit 84df8af28c
24 changed files with 213 additions and 4549 deletions

View File

@ -90,7 +90,6 @@ elseif(WIN32)
lib/inputdev/HIDListenerWinUSB.cpp lib/inputdev/HIDListenerWinUSB.cpp
lib/inputdev/HIDDeviceWinUSB.cpp lib/inputdev/HIDDeviceWinUSB.cpp
lib/graphicsdev/D3D11.cpp lib/graphicsdev/D3D11.cpp
lib/graphicsdev/D3D12.cpp
lib/audiodev/WASAPI.cpp) lib/audiodev/WASAPI.cpp)
list(APPEND PLAT_HDRS list(APPEND PLAT_HDRS
@ -241,6 +240,7 @@ endif()
function(glslang_set_link_args TARGET) function(glslang_set_link_args TARGET)
endfunction(glslang_set_link_args) endfunction(glslang_set_link_args)
add_definitions("-DENABLE_OPT=0")
add_subdirectory(glslang/glslang) add_subdirectory(glslang/glslang)
add_subdirectory(glslang/OGLCompilersDLL) add_subdirectory(glslang/OGLCompilersDLL)
add_subdirectory(glslang/SPIRV) add_subdirectory(glslang/SPIRV)

View File

@ -29,7 +29,7 @@ refresh-rate.
#### Supported Graphics Backends #### Supported Graphics Backends
* OpenGL 3.3+ * OpenGL 3.3+
* Direct3D 11/12 * Direct3D 11
* Metal 1.1 (OS X 10.11 only for now, iOS coming soon) * Metal 1.1 (OS X 10.11 only for now, iOS coming soon)
* Vulkan * Vulkan

@ -1 +1 @@
Subproject commit 82ead04c39c6a4b7fa153d692b26181091c43c15 Subproject commit 8e4b496d4ad84f3524fff89395e6e6b1540c05b6

View File

@ -262,7 +262,7 @@ struct DeferredWindowEvents : public IWindowCallback
} }
if (hasResize) if (hasResize)
m_rec.resized(latestResize, latestResize); m_rec.resized(latestResize, false);
for (const Command& cmd : cmds) for (const Command& cmd : cmds)
cmd.dispatch(m_rec); cmd.dispatch(m_rec);

View File

@ -24,7 +24,6 @@ public:
OpenGL4_2 = 2, OpenGL4_2 = 2,
Vulkan = 3, Vulkan = 3,
D3D11 = 4, D3D11 = 4,
D3D12 = 5,
Metal = 6, Metal = 6,
GX = 7, GX = 7,
GX2 = 8 GX2 = 8

View File

@ -77,15 +77,13 @@ namespace boo
#define __BooTraceArgsUse , file, line #define __BooTraceArgsUse , file, line
#define __BooTraceInitializer , m_file(file), m_line(line) #define __BooTraceInitializer , m_file(file), m_line(line)
#define __BooTraceFields const char* m_file; int m_line; #define __BooTraceFields const char* m_file; int m_line;
#define BooCommitTransaction(...) commitTransaction(__VA_ARGS__, __FILE__, __LINE__) #define BooTrace , __FILE__, __LINE__
#define BooNewPoolBuffer(...) newPoolBuffer(__VA_ARGS__, __FILE__, __LINE__)
#else #else
#define __BooTraceArgs #define __BooTraceArgs
#define __BooTraceArgsUse #define __BooTraceArgsUse
#define __BooTraceInitializer #define __BooTraceInitializer
#define __BooTraceFields #define __BooTraceFields
#define BooCommitTransaction(...) commitTransaction(__VA_ARGS__) #define BooTrace
#define BooNewPoolBuffer(...) newPoolBuffer(__VA_ARGS__)
#endif #endif
} }

View File

@ -18,10 +18,10 @@ extern pD3DCreateBlob D3DCreateBlobPROC;
namespace boo namespace boo
{ {
class ID3DDataFactory : public IGraphicsDataFactory class D3DDataFactory : public IGraphicsDataFactory
{ {
public: public:
virtual ~ID3DDataFactory() {} virtual ~D3DDataFactory() {}
class Context : public IGraphicsDataFactory::Context class Context : public IGraphicsDataFactory::Context
{ {

View File

@ -227,7 +227,6 @@ struct IGraphicsDataFactory
Null, Null,
OpenGL, OpenGL,
D3D11, D3D11,
D3D12,
Metal, Metal,
Vulkan, Vulkan,
GX, GX,

View File

@ -16,13 +16,8 @@ typedef union
#endif #endif
} TVectorUnion; } TVectorUnion;
static constexpr TVectorUnion ZeroVec = {}; static constexpr TVectorUnion Min32Vec = {{INT32_MIN, INT32_MIN, INT32_MIN, INT32_MIN}};
static constexpr TVectorUnion Min16Vec = {INT16_MIN, INT16_MIN, INT16_MIN, INT16_MIN}; static constexpr TVectorUnion Max32Vec = {{INT32_MAX, INT32_MAX, INT32_MAX, INT32_MAX}};
static constexpr TVectorUnion Max16Vec = {INT16_MAX, INT16_MAX, INT16_MAX, INT16_MAX};
static constexpr TVectorUnion Min32Vec = {INT32_MIN, INT32_MIN, INT32_MIN, INT32_MIN};
static constexpr TVectorUnion Max32Vec = {INT32_MAX, INT32_MAX, INT32_MAX, INT32_MAX};
static constexpr TVectorUnion MinFltVec = {-1.f, -1.f, -1.f, -1.f};
static constexpr TVectorUnion MaxFltVec = {1.f, 1.f, 1.f, 1.f};
void AudioMatrixMono::setDefaultMatrixCoefficients(AudioChannelSet acSet) void AudioMatrixMono::setDefaultMatrixCoefficients(AudioChannelSet acSet)
{ {

View File

@ -11,7 +11,7 @@ namespace boo
{ {
AudioSubmix::AudioSubmix(BaseAudioVoiceEngine& root, IAudioSubmixCallback* cb, int busId, bool mainOut) AudioSubmix::AudioSubmix(BaseAudioVoiceEngine& root, IAudioSubmixCallback* cb, int busId, bool mainOut)
: ListNode<AudioSubmix, BaseAudioVoiceEngine*, IAudioSubmix>(&root), m_busId(busId), m_cb(cb), m_mainOut(mainOut) : ListNode<AudioSubmix, BaseAudioVoiceEngine*, IAudioSubmix>(&root), m_busId(busId), m_mainOut(mainOut), m_cb(cb)
{ {
if (mainOut) if (mainOut)
setSendLevel(m_head->m_mainSubmix.get(), 1.f, false); setSendLevel(m_head->m_mainSubmix.get(), 1.f, false);

View File

@ -11,12 +11,12 @@ namespace boo
/** Pertinent information from audio backend about optimal mixed-audio representation */ /** Pertinent information from audio backend about optimal mixed-audio representation */
struct AudioVoiceEngineMixInfo struct AudioVoiceEngineMixInfo
{ {
double m_sampleRate; double m_sampleRate = 32000.0;
soxr_datatype_t m_sampleFormat; soxr_datatype_t m_sampleFormat = SOXR_FLOAT32_I;
unsigned m_bitsPerSample; unsigned m_bitsPerSample = 32;
AudioChannelSet m_channels; AudioChannelSet m_channels = AudioChannelSet::Stereo;
ChannelMap m_channelMap; ChannelMap m_channelMap = {2, {AudioChannel::FrontLeft, AudioChannel::FrontRight}};
size_t m_periodFrames; size_t m_periodFrames = 160;
}; };
} }

View File

@ -40,7 +40,7 @@ struct WASAPIAudioVoiceEngine : BaseAudioVoiceEngine
std::vector<float> m_5msBuffer; std::vector<float> m_5msBuffer;
#if !WINDOWS_STORE #if !WINDOWS_STORE
struct NotificationClient : public IMMNotificationClient struct NotificationClient final : public IMMNotificationClient
{ {
WASAPIAudioVoiceEngine& m_parent; WASAPIAudioVoiceEngine& m_parent;
@ -138,14 +138,14 @@ struct WASAPIAudioVoiceEngine : BaseAudioVoiceEngine
#if !WINDOWS_STORE #if !WINDOWS_STORE
if (FAILED(m_enumerator->GetDefaultAudioEndpoint(eRender, eConsole, &m_device))) if (FAILED(m_enumerator->GetDefaultAudioEndpoint(eRender, eConsole, &m_device)))
{ {
Log.report(logvisor::Fatal, L"unable to obtain default audio device"); Log.report(logvisor::Error, L"unable to obtain default audio device");
m_device.Reset(); m_device.Reset();
return; return;
} }
if (FAILED(m_device->Activate(IID_IAudioClient, CLSCTX_ALL, nullptr, &m_audClient))) if (FAILED(m_device->Activate(IID_IAudioClient, CLSCTX_ALL, nullptr, &m_audClient)))
{ {
Log.report(logvisor::Fatal, L"unable to create audio client from device"); Log.report(logvisor::Error, L"unable to create audio client from device");
m_device.Reset(); m_device.Reset();
return; return;
} }
@ -154,7 +154,7 @@ struct WASAPIAudioVoiceEngine : BaseAudioVoiceEngine
WAVEFORMATEXTENSIBLE* pwfx; WAVEFORMATEXTENSIBLE* pwfx;
if (FAILED(m_audClient->GetMixFormat((WAVEFORMATEX**)&pwfx))) if (FAILED(m_audClient->GetMixFormat((WAVEFORMATEX**)&pwfx)))
{ {
Log.report(logvisor::Fatal, L"unable to obtain audio mix format from device"); Log.report(logvisor::Error, L"unable to obtain audio mix format from device");
#if !WINDOWS_STORE #if !WINDOWS_STORE
m_device.Reset(); m_device.Reset();
#endif #endif
@ -239,7 +239,7 @@ struct WASAPIAudioVoiceEngine : BaseAudioVoiceEngine
(WAVEFORMATEX*)pwfx, (WAVEFORMATEX*)pwfx,
nullptr))) nullptr)))
{ {
Log.report(logvisor::Fatal, L"unable to initialize audio client"); Log.report(logvisor::Error, L"unable to initialize audio client");
#if !WINDOWS_STORE #if !WINDOWS_STORE
m_device.Reset(); m_device.Reset();
#endif #endif
@ -283,7 +283,7 @@ struct WASAPIAudioVoiceEngine : BaseAudioVoiceEngine
} }
else else
{ {
Log.report(logvisor::Fatal, L"unsupported floating-point bits-per-sample %d", pwfx->Format.wBitsPerSample); Log.report(logvisor::Error, L"unsupported floating-point bits-per-sample %d", pwfx->Format.wBitsPerSample);
#if !WINDOWS_STORE #if !WINDOWS_STORE
m_device.Reset(); m_device.Reset();
#endif #endif
@ -296,7 +296,7 @@ struct WASAPIAudioVoiceEngine : BaseAudioVoiceEngine
UINT32 bufferFrameCount; UINT32 bufferFrameCount;
if (FAILED(m_audClient->GetBufferSize(&bufferFrameCount))) if (FAILED(m_audClient->GetBufferSize(&bufferFrameCount)))
{ {
Log.report(logvisor::Fatal, L"unable to get audio buffer frame count"); Log.report(logvisor::Error, L"unable to get audio buffer frame count");
#if !WINDOWS_STORE #if !WINDOWS_STORE
m_device.Reset(); m_device.Reset();
#endif #endif
@ -306,7 +306,7 @@ struct WASAPIAudioVoiceEngine : BaseAudioVoiceEngine
if (FAILED(m_audClient->GetService(IID_IAudioRenderClient, &m_renderClient))) if (FAILED(m_audClient->GetService(IID_IAudioRenderClient, &m_renderClient)))
{ {
Log.report(logvisor::Fatal, L"unable to create audio render client"); Log.report(logvisor::Error, L"unable to create audio render client");
#if !WINDOWS_STORE #if !WINDOWS_STORE
m_device.Reset(); m_device.Reset();
#endif #endif
@ -385,13 +385,13 @@ struct WASAPIAudioVoiceEngine : BaseAudioVoiceEngine
CLSCTX_ALL, IID_IMMDeviceEnumerator, CLSCTX_ALL, IID_IMMDeviceEnumerator,
&m_enumerator))) &m_enumerator)))
{ {
Log.report(logvisor::Fatal, L"unable to create MMDeviceEnumerator instance"); Log.report(logvisor::Error, L"unable to create MMDeviceEnumerator instance");
return; return;
} }
if (FAILED(m_enumerator->RegisterEndpointNotificationCallback(&m_notificationClient))) if (FAILED(m_enumerator->RegisterEndpointNotificationCallback(&m_notificationClient)))
{ {
Log.report(logvisor::Fatal, L"unable to register multimedia event callback"); Log.report(logvisor::Error, L"unable to register multimedia event callback");
m_device.Reset(); m_device.Reset();
return; return;
} }
@ -431,6 +431,9 @@ struct WASAPIAudioVoiceEngine : BaseAudioVoiceEngine
#if WINDOWS_STORE #if WINDOWS_STORE
if (!m_ready) if (!m_ready)
return; return;
#else
if (!m_device)
return;
#endif #endif
int attempt = 0; int attempt = 0;
@ -821,12 +824,7 @@ struct WASAPIAudioVoiceEngine : BaseAudioVoiceEngine
std::unique_ptr<IAudioVoiceEngine> NewAudioVoiceEngine() std::unique_ptr<IAudioVoiceEngine> NewAudioVoiceEngine()
{ {
std::unique_ptr<IAudioVoiceEngine> ret = std::make_unique<WASAPIAudioVoiceEngine>(); return std::make_unique<WASAPIAudioVoiceEngine>();
#if !WINDOWS_STORE
if (!static_cast<WASAPIAudioVoiceEngine&>(*ret).m_device)
return {};
#endif
return ret;
} }
} }

View File

@ -109,10 +109,11 @@ class D3D11GraphicsBufferS : public GraphicsDataNode<IGraphicsBufferS>
BufferUse use, D3D11Context* ctx, BufferUse use, D3D11Context* ctx,
const void* data, size_t stride, size_t count) const void* data, size_t stride, size_t count)
: GraphicsDataNode<IGraphicsBufferS>(parent), : GraphicsDataNode<IGraphicsBufferS>(parent),
m_stride(stride), m_count(count), m_sz(stride * count) m_sz(stride * count), m_stride(stride), m_count(count)
{ {
D3D11_SUBRESOURCE_DATA iData = {data}; D3D11_SUBRESOURCE_DATA iData = {data};
ThrowIfFailed(ctx->m_dev->CreateBuffer(&CD3D11_BUFFER_DESC(m_sz, USE_TABLE[int(use)], D3D11_USAGE_IMMUTABLE), &iData, &m_buf)); CD3D11_BUFFER_DESC desc(m_sz, USE_TABLE[int(use)], D3D11_USAGE_IMMUTABLE);
ThrowIfFailed(ctx->m_dev->CreateBuffer(&desc, &iData, &m_buf));
} }
public: public:
size_t m_stride; size_t m_stride;
@ -140,8 +141,11 @@ class D3D11GraphicsBufferD : public GraphicsDataNode<IGraphicsBufferD, DataCls>
m_cpuSz = stride * count; m_cpuSz = stride * count;
m_cpuBuf.reset(new uint8_t[m_cpuSz]); m_cpuBuf.reset(new uint8_t[m_cpuSz]);
for (int i=0 ; i<3 ; ++i) for (int i=0 ; i<3 ; ++i)
ThrowIfFailed(ctx->m_dev->CreateBuffer(&CD3D11_BUFFER_DESC(m_cpuSz, USE_TABLE[int(use)], {
D3D11_USAGE_DYNAMIC, D3D11_CPU_ACCESS_WRITE), nullptr, &m_bufs[i])); CD3D11_BUFFER_DESC desc(m_cpuSz, USE_TABLE[int(use)],
D3D11_USAGE_DYNAMIC, D3D11_CPU_ACCESS_WRITE);
ThrowIfFailed(ctx->m_dev->CreateBuffer(&desc, nullptr, &m_bufs[i]));
}
} }
void update(ID3D11DeviceContext* ctx, int b); void update(ID3D11DeviceContext* ctx, int b);
public: public:
@ -158,14 +162,13 @@ public:
class D3D11TextureS : public GraphicsDataNode<ITextureS> class D3D11TextureS : public GraphicsDataNode<ITextureS>
{ {
friend class D3D11DataFactory; friend class D3D11DataFactory;
size_t m_sz;
D3D11TextureS(const boo::ObjToken<BaseGraphicsData>& parent, D3D11TextureS(const boo::ObjToken<BaseGraphicsData>& parent,
D3D11Context* ctx, size_t width, size_t height, size_t mips, D3D11Context* ctx, size_t width, size_t height, size_t mips,
TextureFormat fmt, const void* data, size_t sz) TextureFormat fmt, const void* data, size_t sz)
: GraphicsDataNode<ITextureS>(parent), m_sz(sz) : GraphicsDataNode<ITextureS>(parent)
{ {
DXGI_FORMAT pfmt; DXGI_FORMAT pfmt = DXGI_FORMAT_UNKNOWN;
int pxPitchNum = 1; int pxPitchNum = 1;
int pxPitchDenom = 1; int pxPitchDenom = 1;
bool compressed = false; bool compressed = false;
@ -212,8 +215,8 @@ class D3D11TextureS : public GraphicsDataNode<ITextureS>
} }
ThrowIfFailed(ctx->m_dev->CreateTexture2D(&desc, upData, &m_tex)); ThrowIfFailed(ctx->m_dev->CreateTexture2D(&desc, upData, &m_tex));
ThrowIfFailed(ctx->m_dev->CreateShaderResourceView(m_tex.Get(), CD3D11_SHADER_RESOURCE_VIEW_DESC srvDesc(m_tex.Get(), D3D_SRV_DIMENSION_TEXTURE2D, pfmt, 0, mips);
&CD3D11_SHADER_RESOURCE_VIEW_DESC(m_tex.Get(), D3D_SRV_DIMENSION_TEXTURE2D, pfmt, 0, mips), &m_srv)); ThrowIfFailed(ctx->m_dev->CreateShaderResourceView(m_tex.Get(), &srvDesc, &m_srv));
} }
public: public:
ComPtr<ID3D11Texture2D> m_tex; ComPtr<ID3D11Texture2D> m_tex;
@ -225,14 +228,13 @@ class D3D11TextureSA : public GraphicsDataNode<ITextureSA>
{ {
friend class D3D11DataFactory; friend class D3D11DataFactory;
size_t m_sz;
D3D11TextureSA(const boo::ObjToken<BaseGraphicsData>& parent, D3D11TextureSA(const boo::ObjToken<BaseGraphicsData>& parent,
D3D11Context* ctx, size_t width, size_t height, size_t layers, D3D11Context* ctx, size_t width, size_t height, size_t layers,
size_t mips, TextureFormat fmt, const void* data, size_t sz) size_t mips, TextureFormat fmt, const void* data, size_t sz)
: GraphicsDataNode<ITextureSA>(parent), m_sz(sz) : GraphicsDataNode<ITextureSA>(parent)
{ {
size_t pixelPitch; size_t pixelPitch = 0;
DXGI_FORMAT pixelFmt; DXGI_FORMAT pixelFmt = DXGI_FORMAT_UNKNOWN;
switch (fmt) switch (fmt)
{ {
case TextureFormat::RGBA8: case TextureFormat::RGBA8:
@ -247,6 +249,8 @@ class D3D11TextureSA : public GraphicsDataNode<ITextureSA>
pixelPitch = 2; pixelPitch = 2;
pixelFmt = DXGI_FORMAT_R16_UNORM; pixelFmt = DXGI_FORMAT_R16_UNORM;
break; break;
default:
Log.report(logvisor::Fatal, "unsupported tex format");
} }
CD3D11_TEXTURE2D_DESC desc(pixelFmt, width, height, layers, mips, CD3D11_TEXTURE2D_DESC desc(pixelFmt, width, height, layers, mips,
@ -272,8 +276,8 @@ class D3D11TextureSA : public GraphicsDataNode<ITextureSA>
} }
ThrowIfFailed(ctx->m_dev->CreateTexture2D(&desc, upData.get(), &m_tex)); ThrowIfFailed(ctx->m_dev->CreateTexture2D(&desc, upData.get(), &m_tex));
ThrowIfFailed(ctx->m_dev->CreateShaderResourceView(m_tex.Get(), CD3D11_SHADER_RESOURCE_VIEW_DESC srvDesc(m_tex.Get(), D3D_SRV_DIMENSION_TEXTURE2DARRAY, pixelFmt);
&CD3D11_SHADER_RESOURCE_VIEW_DESC(m_tex.Get(), D3D_SRV_DIMENSION_TEXTURE2DARRAY, pixelFmt), &m_srv)); ThrowIfFailed(ctx->m_dev->CreateShaderResourceView(m_tex.Get(), &srvDesc, &m_srv));
} }
public: public:
ComPtr<ID3D11Texture2D> m_tex; ComPtr<ID3D11Texture2D> m_tex;
@ -287,7 +291,6 @@ class D3D11TextureD : public GraphicsDataNode<ITextureD>
friend struct D3D11CommandQueue; friend struct D3D11CommandQueue;
size_t m_width = 0; size_t m_width = 0;
size_t m_height = 0;
D3D11CommandQueue* m_q; D3D11CommandQueue* m_q;
std::unique_ptr<uint8_t[]> m_cpuBuf; std::unique_ptr<uint8_t[]> m_cpuBuf;
size_t m_cpuSz; size_t m_cpuSz;
@ -296,9 +299,9 @@ class D3D11TextureD : public GraphicsDataNode<ITextureD>
D3D11TextureD(const boo::ObjToken<BaseGraphicsData>& parent, D3D11TextureD(const boo::ObjToken<BaseGraphicsData>& parent,
D3D11CommandQueue* q, D3D11Context* ctx, D3D11CommandQueue* q, D3D11Context* ctx,
size_t width, size_t height, TextureFormat fmt) size_t width, size_t height, TextureFormat fmt)
: GraphicsDataNode<ITextureD>(parent), m_width(width), m_height(height), m_q(q) : GraphicsDataNode<ITextureD>(parent), m_width(width), m_q(q)
{ {
DXGI_FORMAT pixelFmt; DXGI_FORMAT pixelFmt = DXGI_FORMAT_UNKNOWN;
switch (fmt) switch (fmt)
{ {
case TextureFormat::RGBA8: case TextureFormat::RGBA8:
@ -325,8 +328,8 @@ class D3D11TextureD : public GraphicsDataNode<ITextureD>
for (int i=0 ; i<3 ; ++i) for (int i=0 ; i<3 ; ++i)
{ {
ThrowIfFailed(ctx->m_dev->CreateTexture2D(&desc, nullptr, &m_texs[i])); ThrowIfFailed(ctx->m_dev->CreateTexture2D(&desc, nullptr, &m_texs[i]));
ThrowIfFailed(ctx->m_dev->CreateShaderResourceView(m_texs[i].Get(), CD3D11_SHADER_RESOURCE_VIEW_DESC srvDesc(m_texs[i].Get(), D3D_SRV_DIMENSION_TEXTURE2D, pixelFmt);
&CD3D11_SHADER_RESOURCE_VIEW_DESC(m_texs[i].Get(), D3D_SRV_DIMENSION_TEXTURE2D, pixelFmt), &m_srvs[i])); ThrowIfFailed(ctx->m_dev->CreateShaderResourceView(m_texs[i].Get(), &srvDesc, &m_srvs[i]));
} }
} }
void update(ID3D11DeviceContext* ctx, int b); void update(ID3D11DeviceContext* ctx, int b);
@ -355,10 +358,12 @@ class D3D11TextureR : public GraphicsDataNode<ITextureR>
void Setup(D3D11Context* ctx) void Setup(D3D11Context* ctx)
{ {
ThrowIfFailed(ctx->m_dev->CreateTexture2D(&CD3D11_TEXTURE2D_DESC(ctx->m_fbFormat, m_width, m_height, CD3D11_TEXTURE2D_DESC colorDesc(ctx->m_fbFormat, m_width, m_height,
1, 1, D3D11_BIND_RENDER_TARGET, D3D11_USAGE_DEFAULT, 0, m_samples), nullptr, &m_colorTex)); 1, 1, D3D11_BIND_RENDER_TARGET, D3D11_USAGE_DEFAULT, 0, m_samples);
ThrowIfFailed(ctx->m_dev->CreateTexture2D(&CD3D11_TEXTURE2D_DESC(DXGI_FORMAT_D24_UNORM_S8_UINT, m_width, m_height, ThrowIfFailed(ctx->m_dev->CreateTexture2D(&colorDesc, nullptr, &m_colorTex));
1, 1, D3D11_BIND_DEPTH_STENCIL, D3D11_USAGE_DEFAULT, 0, m_samples), nullptr, &m_depthTex)); CD3D11_TEXTURE2D_DESC depthDesc(DXGI_FORMAT_D32_FLOAT, m_width, m_height,
1, 1, D3D11_BIND_DEPTH_STENCIL, D3D11_USAGE_DEFAULT, 0, m_samples);
ThrowIfFailed(ctx->m_dev->CreateTexture2D(&depthDesc, nullptr, &m_depthTex));
D3D11_RTV_DIMENSION rtvDim; D3D11_RTV_DIMENSION rtvDim;
D3D11_DSV_DIMENSION dsvDim; D3D11_DSV_DIMENSION dsvDim;
@ -374,26 +379,28 @@ class D3D11TextureR : public GraphicsDataNode<ITextureR>
dsvDim = D3D11_DSV_DIMENSION_TEXTURE2D; dsvDim = D3D11_DSV_DIMENSION_TEXTURE2D;
} }
ThrowIfFailed(ctx->m_dev->CreateRenderTargetView(m_colorTex.Get(), CD3D11_RENDER_TARGET_VIEW_DESC rtvDesc(m_colorTex.Get(), rtvDim);
&CD3D11_RENDER_TARGET_VIEW_DESC(m_colorTex.Get(), rtvDim), &m_rtv)); ThrowIfFailed(ctx->m_dev->CreateRenderTargetView(m_colorTex.Get(), &rtvDesc, &m_rtv));
ThrowIfFailed(ctx->m_dev->CreateDepthStencilView(m_depthTex.Get(), CD3D11_DEPTH_STENCIL_VIEW_DESC dsvDesc(m_depthTex.Get(), dsvDim);
&CD3D11_DEPTH_STENCIL_VIEW_DESC(m_depthTex.Get(), dsvDim), &m_dsv)); ThrowIfFailed(ctx->m_dev->CreateDepthStencilView(m_depthTex.Get(), &dsvDesc, &m_dsv));
for (size_t i=0 ; i<m_colorBindCount ; ++i) for (size_t i=0 ; i<m_colorBindCount ; ++i)
{ {
ThrowIfFailed(ctx->m_dev->CreateTexture2D(&CD3D11_TEXTURE2D_DESC(ctx->m_fbFormat, m_width, m_height, CD3D11_TEXTURE2D_DESC colorBindDesc(ctx->m_fbFormat, m_width, m_height,
1, 1, D3D11_BIND_SHADER_RESOURCE, D3D11_USAGE_DEFAULT, 0, 1), nullptr, &m_colorBindTex[i])); 1, 1, D3D11_BIND_SHADER_RESOURCE, D3D11_USAGE_DEFAULT, 0, 1);
ThrowIfFailed(ctx->m_dev->CreateShaderResourceView(m_colorBindTex[i].Get(), ThrowIfFailed(ctx->m_dev->CreateTexture2D(&colorBindDesc, nullptr, &m_colorBindTex[i]));
&CD3D11_SHADER_RESOURCE_VIEW_DESC(m_colorBindTex[i].Get(), D3D11_SRV_DIMENSION_TEXTURE2D), &m_colorSrv[i])); CD3D11_SHADER_RESOURCE_VIEW_DESC colorSrvDesc(m_colorBindTex[i].Get(), D3D11_SRV_DIMENSION_TEXTURE2D);
ThrowIfFailed(ctx->m_dev->CreateShaderResourceView(m_colorBindTex[i].Get(), &colorSrvDesc, &m_colorSrv[i]));
} }
for (size_t i=0 ; i<m_depthBindCount ; ++i) for (size_t i=0 ; i<m_depthBindCount ; ++i)
{ {
ThrowIfFailed(ctx->m_dev->CreateTexture2D(&CD3D11_TEXTURE2D_DESC(DXGI_FORMAT_R24G8_TYPELESS, m_width, m_height, CD3D11_TEXTURE2D_DESC depthBindDesc(DXGI_FORMAT_R32_FLOAT, m_width, m_height,
1, 1, D3D11_BIND_SHADER_RESOURCE, D3D11_USAGE_DEFAULT, 0, 1), nullptr, &m_depthBindTex[i])); 1, 1, D3D11_BIND_SHADER_RESOURCE, D3D11_USAGE_DEFAULT, 0, 1);
ThrowIfFailed(ctx->m_dev->CreateShaderResourceView(m_depthBindTex[i].Get(), ThrowIfFailed(ctx->m_dev->CreateTexture2D(&depthBindDesc, nullptr, &m_depthBindTex[i]));
&CD3D11_SHADER_RESOURCE_VIEW_DESC(m_depthBindTex[i].Get(), D3D11_SRV_DIMENSION_TEXTURE2D, CD3D11_SHADER_RESOURCE_VIEW_DESC depthSrvDesc(m_depthBindTex[i].Get(), D3D11_SRV_DIMENSION_TEXTURE2D,
DXGI_FORMAT_R24_UNORM_X8_TYPELESS), &m_depthSrv[i])); DXGI_FORMAT_R32_FLOAT);
ThrowIfFailed(ctx->m_dev->CreateShaderResourceView(m_depthBindTex[i].Get(), &depthSrvDesc, &m_depthSrv[i]));
} }
} }
@ -1143,7 +1150,7 @@ struct D3D11CommandQueue : IGraphicsCommandQueue
if (tex->m_samples > 1) if (tex->m_samples > 1)
{ {
ctx->ResolveSubresource(tex->m_depthBindTex[bindIdx].Get(), 0, tex->m_depthTex.Get(), 0, ctx->ResolveSubresource(tex->m_depthBindTex[bindIdx].Get(), 0, tex->m_depthTex.Get(), 0,
DXGI_FORMAT_D24_UNORM_S8_UINT); DXGI_FORMAT_D32_FLOAT);
} }
else else
{ {
@ -1244,7 +1251,7 @@ void D3D11TextureD::unmap()
m_q->m_dynamicLock.unlock(); m_q->m_dynamicLock.unlock();
} }
class D3D11DataFactory : public ID3DDataFactory, public GraphicsDataFactoryHead class D3D11DataFactory : public D3DDataFactory, public GraphicsDataFactoryHead
{ {
friend struct D3D11CommandQueue; friend struct D3D11CommandQueue;
IGraphicsContext* m_parent; IGraphicsContext* m_parent;
@ -1286,7 +1293,7 @@ class D3D11DataFactory : public ID3DDataFactory, public GraphicsDataFactoryHead
m_gammaBinding = ctx.newShaderDataBinding(m_gammaShader, m_gammaVFMT, m_gammaVBO.get(), {}, {}, m_gammaBinding = ctx.newShaderDataBinding(m_gammaShader, m_gammaVFMT, m_gammaVBO.get(), {}, {},
0, nullptr, nullptr, 2, texs, nullptr, nullptr); 0, nullptr, nullptr, 2, texs, nullptr, nullptr);
return true; return true;
}); } BooTrace);
} }
public: public:
@ -1302,13 +1309,13 @@ public:
Platform platform() const {return Platform::D3D11;} Platform platform() const {return Platform::D3D11;}
const SystemChar* platformName() const {return _S("D3D11");} const SystemChar* platformName() const {return _S("D3D11");}
class Context : public ID3DDataFactory::Context class Context : public D3DDataFactory::Context
{ {
friend class D3D11DataFactory; friend class D3D11DataFactory;
D3D11DataFactory& m_parent; D3D11DataFactory& m_parent;
boo::ObjToken<BaseGraphicsData> m_data; boo::ObjToken<BaseGraphicsData> m_data;
Context(D3D11DataFactory& parent) Context(D3D11DataFactory& parent __BooTraceArgs)
: m_parent(parent), m_data(new BaseGraphicsData(parent)) {} : m_parent(parent), m_data(new BaseGraphicsData(parent __BooTraceArgsUse)) {}
public: public:
Platform platform() const {return Platform::D3D11;} Platform platform() const {return Platform::D3D11;}
const SystemChar* platformName() const {return _S("D3D11");} const SystemChar* platformName() const {return _S("D3D11");}
@ -1528,16 +1535,16 @@ public:
} }
}; };
boo::ObjToken<IGraphicsBufferD> newPoolBuffer(BufferUse use, size_t stride, size_t count) boo::ObjToken<IGraphicsBufferD> newPoolBuffer(BufferUse use, size_t stride, size_t count __BooTraceArgs)
{ {
D3D11CommandQueue* q = static_cast<D3D11CommandQueue*>(m_parent->getCommandQueue()); D3D11CommandQueue* q = static_cast<D3D11CommandQueue*>(m_parent->getCommandQueue());
boo::ObjToken<BaseGraphicsPool> pool(new BaseGraphicsPool(*this)); boo::ObjToken<BaseGraphicsPool> pool(new BaseGraphicsPool(*this __BooTraceArgsUse));
return {new D3D11GraphicsBufferD<BaseGraphicsPool>(pool, q, use, m_ctx, stride, count)}; return {new D3D11GraphicsBufferD<BaseGraphicsPool>(pool, q, use, m_ctx, stride, count)};
} }
void commitTransaction(const FactoryCommitFunc& trans) void commitTransaction(const FactoryCommitFunc& trans __BooTraceArgs)
{ {
D3D11DataFactory::Context ctx(*this); D3D11DataFactory::Context ctx(*this __BooTraceArgsUse);
trans(ctx); trans(ctx);
} }
@ -1727,14 +1734,16 @@ void D3D11CommandQueue::ProcessDynamicLoads(ID3D11DeviceContext* ctx)
} }
} }
IGraphicsCommandQueue* _NewD3D11CommandQueue(D3D11Context* ctx, D3D11Context::Window* windowCtx, IGraphicsContext* parent) std::unique_ptr<IGraphicsCommandQueue>
_NewD3D11CommandQueue(D3D11Context* ctx, D3D11Context::Window* windowCtx, IGraphicsContext* parent)
{ {
return new D3D11CommandQueue(ctx, windowCtx, parent); return std::make_unique<D3D11CommandQueue>(ctx, windowCtx, parent);
} }
IGraphicsDataFactory* _NewD3D11DataFactory(D3D11Context* ctx, IGraphicsContext* parent) std::unique_ptr<IGraphicsDataFactory>
_NewD3D11DataFactory(D3D11Context* ctx, IGraphicsContext* parent)
{ {
return new D3D11DataFactory(parent, ctx); return std::make_unique<D3D11DataFactory>(parent, ctx);
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -83,7 +83,7 @@ class GLDataFactoryImpl : public GLDataFactory, public GraphicsDataFactoryHead
ObjToken<IVertexFormat> m_gammaVFMT; ObjToken<IVertexFormat> m_gammaVFMT;
void SetupGammaResources() void SetupGammaResources()
{ {
BooCommitTransaction([this](IGraphicsDataFactory::Context& ctx) commitTransaction([this](IGraphicsDataFactory::Context& ctx)
{ {
const char* texNames[] = {"screenTex", "gammaLUT"}; const char* texNames[] = {"screenTex", "gammaLUT"};
m_gammaShader = static_cast<Context&>(ctx).newShaderPipeline(GammaVS, GammaFS, m_gammaShader = static_cast<Context&>(ctx).newShaderPipeline(GammaVS, GammaFS,
@ -106,7 +106,7 @@ class GLDataFactoryImpl : public GLDataFactory, public GraphicsDataFactoryHead
}; };
m_gammaVFMT = ctx.newVertexFormat(2, vfmt); m_gammaVFMT = ctx.newVertexFormat(2, vfmt);
return true; return true;
}); } BooTrace);
} }
public: public:
@ -390,8 +390,8 @@ class GLTextureSA : public GraphicsDataNode<ITextureSA>
SetClampMode(GL_TEXTURE_2D_ARRAY, clampMode); SetClampMode(GL_TEXTURE_2D_ARRAY, clampMode);
GLenum intFormat, format; GLenum intFormat = 0, format = 0;
int pxPitch; int pxPitch = 0;
switch (fmt) switch (fmt)
{ {
case TextureFormat::RGBA8: case TextureFormat::RGBA8:

View File

@ -96,7 +96,7 @@ class VulkanDataFactoryImpl : public VulkanDataFactory, public GraphicsDataFacto
ObjToken<IShaderDataBinding> m_gammaBinding; ObjToken<IShaderDataBinding> m_gammaBinding;
void SetupGammaResources() void SetupGammaResources()
{ {
BooCommitTransaction([this](IGraphicsDataFactory::Context& ctx) commitTransaction([this](IGraphicsDataFactory::Context& ctx)
{ {
const VertexElementDescriptor vfmt[] = { const VertexElementDescriptor vfmt[] = {
{nullptr, nullptr, VertexSemantic::Position4}, {nullptr, nullptr, VertexSemantic::Position4},
@ -122,7 +122,7 @@ class VulkanDataFactoryImpl : public VulkanDataFactory, public GraphicsDataFacto
m_gammaBinding = ctx.newShaderDataBinding(m_gammaShader, m_gammaVFMT, m_gammaVBO.get(), {}, {}, m_gammaBinding = ctx.newShaderDataBinding(m_gammaShader, m_gammaVFMT, m_gammaVBO.get(), {}, {},
0, nullptr, nullptr, 2, texs, nullptr, nullptr); 0, nullptr, nullptr, 2, texs, nullptr, nullptr);
return true; return true;
}); } BooTrace);
} }
void DestroyGammaResources() void DestroyGammaResources()

File diff suppressed because it is too large Load Diff

View File

@ -280,7 +280,7 @@ class HIDDeviceWinUSB final : public IHIDDevice
if (Error != ERROR_IO_PENDING) if (Error != ERROR_IO_PENDING)
{ {
fprintf(stderr, "Write Failed %08X\n", Error); fprintf(stderr, "Write Failed %08X\n", int(Error));
return false; return false;
} }
} }
@ -288,7 +288,7 @@ class HIDDeviceWinUSB final : public IHIDDevice
if (!GetOverlappedResult(m_hidHandle, &Overlapped, &BytesWritten, TRUE)) if (!GetOverlappedResult(m_hidHandle, &Overlapped, &BytesWritten, TRUE))
{ {
DWORD Error = GetLastError(); DWORD Error = GetLastError();
fprintf(stderr, "Write Failed %08X\n", Error); fprintf(stderr, "Write Failed %08X\n", int(Error));
return false; return false;
} }
} }
@ -297,7 +297,7 @@ class HIDDeviceWinUSB final : public IHIDDevice
DWORD useLength = DWORD(std::max(length, m_minFeatureSz)); DWORD useLength = DWORD(std::max(length, m_minFeatureSz));
if (!HidD_SetFeature(m_hidHandle, (PVOID)m_sendBuf.data(), useLength)) if (!HidD_SetFeature(m_hidHandle, (PVOID)m_sendBuf.data(), useLength))
{ {
int error = GetLastError(); //int error = GetLastError();
return false; return false;
} }
} }
@ -377,7 +377,7 @@ public:
} }
else if (Error != ERROR_IO_PENDING) else if (Error != ERROR_IO_PENDING)
{ {
fprintf(stderr, "Read Failed: %08X\n", Error); fprintf(stderr, "Read Failed: %08X\n", int(Error));
return; return;
} }
else if (!GetOverlappedResultEx(m_hidHandle, &m_overlapped, &BytesRead, 10, TRUE)) else if (!GetOverlappedResultEx(m_hidHandle, &m_overlapped, &BytesRead, 10, TRUE))

View File

@ -323,59 +323,6 @@ const char* HIDMainItem::GetUsageName() const
} }
} }
static HIDParser::ParserStatus
AdvanceIt(const uint8_t*& it, const uint8_t* end, size_t adv)
{
it += adv;
if (it > end)
{
it = end;
return HIDParser::ParserStatus::Error;
}
else if (it == end)
{
return HIDParser::ParserStatus::Done;
}
return HIDParser::ParserStatus::OK;
}
static uint8_t
GetByteValue(const uint8_t*& it, const uint8_t* end, HIDParser::ParserStatus& status)
{
const uint8_t* oldIt = it;
status = AdvanceIt(it, end, 1);
if (status == HIDParser::ParserStatus::Error)
return 0;
return *oldIt;
}
static uint32_t
GetShortValue(const uint8_t*& it, const uint8_t* end, int adv, HIDParser::ParserStatus& status)
{
const uint8_t* oldIt = it;
switch (adv)
{
case 1:
status = AdvanceIt(it, end, 1);
if (status == HIDParser::ParserStatus::Error)
return 0;
return *oldIt;
case 2:
status = AdvanceIt(it, end, 2);
if (status == HIDParser::ParserStatus::Error)
return 0;
return *reinterpret_cast<const uint16_t*>(&*oldIt);
case 3:
status = AdvanceIt(it, end, 4);
if (status == HIDParser::ParserStatus::Error)
return 0;
return *reinterpret_cast<const uint32_t*>(&*oldIt);
default:
break;
}
return 0;
}
struct HIDReports struct HIDReports
{ {
std::map<int32_t, std::vector<HIDMainItem>> m_inputReports; std::map<int32_t, std::vector<HIDMainItem>> m_inputReports;
@ -479,6 +426,59 @@ HIDParser::ParserStatus HIDParser::Parse(const PHIDP_PREPARSED_DATA descriptorDa
#endif #endif
#else #else
static HIDParser::ParserStatus
AdvanceIt(const uint8_t*& it, const uint8_t* end, size_t adv)
{
it += adv;
if (it > end)
{
it = end;
return HIDParser::ParserStatus::Error;
}
else if (it == end)
{
return HIDParser::ParserStatus::Done;
}
return HIDParser::ParserStatus::OK;
}
static uint8_t
GetByteValue(const uint8_t*& it, const uint8_t* end, HIDParser::ParserStatus& status)
{
const uint8_t* oldIt = it;
status = AdvanceIt(it, end, 1);
if (status == HIDParser::ParserStatus::Error)
return 0;
return *oldIt;
}
static uint32_t
GetShortValue(const uint8_t*& it, const uint8_t* end, int adv, HIDParser::ParserStatus& status)
{
const uint8_t* oldIt = it;
switch (adv)
{
case 1:
status = AdvanceIt(it, end, 1);
if (status == HIDParser::ParserStatus::Error)
return 0;
return *oldIt;
case 2:
status = AdvanceIt(it, end, 2);
if (status == HIDParser::ParserStatus::Error)
return 0;
return *reinterpret_cast<const uint16_t*>(&*oldIt);
case 3:
status = AdvanceIt(it, end, 4);
if (status == HIDParser::ParserStatus::Error)
return 0;
return *reinterpret_cast<const uint32_t*>(&*oldIt);
default:
break;
}
return 0;
}
HIDParser::ParserStatus HIDParser::ParserStatus
HIDParser::ParseItem(HIDReports& reportsOut, HIDParser::ParseItem(HIDReports& reportsOut,
std::stack<HIDItemState>& stateStack, std::stack<HIDItemState>& stateStack,

View File

@ -28,9 +28,6 @@ PFN_GetScaleFactorForMonitor MyGetScaleFactorForMonitor = nullptr;
DWORD g_mainThreadId = 0; DWORD g_mainThreadId = 0;
static LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); static LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
#if _WIN32_WINNT_WIN10
PFN_D3D12_SERIALIZE_ROOT_SIGNATURE D3D12SerializeRootSignaturePROC = nullptr;
#endif
pD3DCompile D3DCompilePROC = nullptr; pD3DCompile D3DCompilePROC = nullptr;
pD3DCreateBlob D3DCreateBlobPROC = nullptr; pD3DCreateBlob D3DCreateBlobPROC = nullptr;
@ -77,7 +74,6 @@ class ApplicationWin32 final : public IApplication
const SystemString m_pname; const SystemString m_pname;
const std::vector<SystemString> m_args; const std::vector<SystemString> m_args;
std::unordered_map<HWND, std::weak_ptr<IWindow>> m_allWindows; std::unordered_map<HWND, std::weak_ptr<IWindow>> m_allWindows;
bool m_singleInstance;
Boo3DAppContextWin32 m_3dCtx; Boo3DAppContextWin32 m_3dCtx;
#if BOO_HAS_VULKAN #if BOO_HAS_VULKAN
@ -105,15 +101,11 @@ public:
m_uniqueName(uniqueName), m_uniqueName(uniqueName),
m_friendlyName(friendlyName), m_friendlyName(friendlyName),
m_pname(pname), m_pname(pname),
m_args(args), m_args(args)
m_singleInstance(singleInstance)
{ {
m_3dCtx.m_ctx11.m_sampleCount = samples; m_3dCtx.m_ctx11.m_sampleCount = samples;
m_3dCtx.m_ctx11.m_anisotropy = anisotropy; m_3dCtx.m_ctx11.m_anisotropy = anisotropy;
m_3dCtx.m_ctx11.m_fbFormat = deepColor ? DXGI_FORMAT_R16G16B16A16_FLOAT : DXGI_FORMAT_R8G8B8A8_UNORM; m_3dCtx.m_ctx11.m_fbFormat = deepColor ? DXGI_FORMAT_R16G16B16A16_FLOAT : DXGI_FORMAT_R8G8B8A8_UNORM;
m_3dCtx.m_ctx12.m_sampleCount = samples;
m_3dCtx.m_ctx12.m_anisotropy = anisotropy;
m_3dCtx.m_ctx12.RGBATex2DFBViewDesc.Format = deepColor ? DXGI_FORMAT_R16G16B16A16_FLOAT : DXGI_FORMAT_R8G8B8A8_UNORM;
m_3dCtx.m_ctxOgl.m_glCtx.m_sampleCount = samples; m_3dCtx.m_ctxOgl.m_glCtx.m_sampleCount = samples;
m_3dCtx.m_ctxOgl.m_glCtx.m_anisotropy = anisotropy; m_3dCtx.m_ctxOgl.m_glCtx.m_anisotropy = anisotropy;
m_3dCtx.m_ctxOgl.m_glCtx.m_deepColor = deepColor; m_3dCtx.m_ctxOgl.m_glCtx.m_deepColor = deepColor;
@ -133,7 +125,6 @@ public:
if (!MyCreateDXGIFactory1) if (!MyCreateDXGIFactory1)
Log.report(logvisor::Fatal, "unable to find CreateDXGIFactory1 in DXGI.dll\n"); Log.report(logvisor::Fatal, "unable to find CreateDXGIFactory1 in DXGI.dll\n");
bool yes12 = false;
bool noD3d = false; bool noD3d = false;
#if BOO_HAS_VULKAN #if BOO_HAS_VULKAN
bool useVulkan = false; bool useVulkan = false;
@ -141,11 +132,6 @@ public:
if (!gfxApi.empty()) if (!gfxApi.empty())
{ {
#if BOO_HAS_VULKAN #if BOO_HAS_VULKAN
if (!gfxApi.compare("D3D12"))
{
useVulkan = false;
yes12 = true;
}
if (!gfxApi.compare("Vulkan")) if (!gfxApi.compare("Vulkan"))
{ {
noD3d = true; noD3d = true;
@ -157,8 +143,6 @@ public:
useVulkan = false; useVulkan = false;
} }
#else #else
if (!gfxApi.compare("D3D12"))
yes12 = true;
if (!gfxApi.compare("OpenGL")) if (!gfxApi.compare("OpenGL"))
noD3d = true; noD3d = true;
#endif #endif
@ -166,16 +150,9 @@ public:
for (const SystemString& arg : args) for (const SystemString& arg : args)
{ {
#if BOO_HAS_VULKAN #if BOO_HAS_VULKAN
if (!arg.compare(L"--d3d12"))
{
useVulkan = false;
yes12 = true;
noD3d = false;
}
if (!arg.compare(L"--d3d11")) if (!arg.compare(L"--d3d11"))
{ {
useVulkan = false; useVulkan = false;
yes12 = false;
noD3d = false; noD3d = false;
} }
if (!arg.compare(L"--vulkan")) if (!arg.compare(L"--vulkan"))
@ -189,109 +166,13 @@ public:
useVulkan = false; useVulkan = false;
} }
#else #else
if (!arg.compare(L"--d3d12"))
{
yes12 = true;
noD3d = false;
}
if (!arg.compare(L"--d3d11")) if (!arg.compare(L"--d3d11"))
{
yes12 = false;
noD3d = false; noD3d = false;
}
if (!arg.compare(L"--gl")) if (!arg.compare(L"--gl"))
noD3d = true; noD3d = true;
#endif #endif
} }
#if _WIN32_WINNT_WIN10
HMODULE d3d12lib = nullptr;
if (yes12 && !noD3d)
d3d12lib = LoadLibraryW(L"D3D12.dll");
if (d3d12lib)
{
#if _DEBUG
{
PFN_D3D12_GET_DEBUG_INTERFACE MyD3D12GetDebugInterface =
(PFN_D3D12_GET_DEBUG_INTERFACE)GetProcAddress(d3d12lib, "D3D12GetDebugInterface");
ComPtr<ID3D12Debug> debugController;
if (SUCCEEDED(MyD3D12GetDebugInterface(IID_PPV_ARGS(&debugController))))
{
debugController->EnableDebugLayer();
}
}
#endif
if (!FindBestD3DCompile())
Log.report(logvisor::Fatal, "unable to find D3DCompile_[43-47].dll");
D3D12SerializeRootSignaturePROC =
(PFN_D3D12_SERIALIZE_ROOT_SIGNATURE)GetProcAddress(d3d12lib, "D3D12SerializeRootSignature");
/* Create device */
PFN_D3D12_CREATE_DEVICE MyD3D12CreateDevice = (PFN_D3D12_CREATE_DEVICE)GetProcAddress(d3d12lib, "D3D12CreateDevice");
if (!MyD3D12CreateDevice)
Log.report(logvisor::Fatal, "unable to find D3D12CreateDevice in D3D12.dll");
/* Obtain DXGI Factory */
HRESULT hr = MyCreateDXGIFactory1(__uuidof(IDXGIFactory2), &m_3dCtx.m_ctx12.m_dxFactory);
if (FAILED(hr))
Log.report(logvisor::Fatal, "unable to create DXGI factory");
/* Adapter */
ComPtr<IDXGIAdapter1> ppAdapter;
for (UINT adapterIndex = 0; ; ++adapterIndex)
{
ComPtr<IDXGIAdapter1> pAdapter;
if (DXGI_ERROR_NOT_FOUND == m_3dCtx.m_ctx12.m_dxFactory->EnumAdapters1(adapterIndex, &pAdapter))
break;
// Check to see if the adapter supports Direct3D 12, but don't create the
// actual device yet.
if (SUCCEEDED(MyD3D12CreateDevice(pAdapter.Get(), D3D_FEATURE_LEVEL_11_0, _uuidof(ID3D12Device), nullptr)))
{
ppAdapter = std::move(pAdapter);
break;
}
}
/* Create device */
hr = ppAdapter ? MyD3D12CreateDevice(ppAdapter.Get(), D3D_FEATURE_LEVEL_11_0, __uuidof(ID3D12Device), &m_3dCtx.m_ctx12.m_dev) : E_FAIL;
if (!FAILED(hr))
{
/* Establish loader objects */
if (FAILED(m_3dCtx.m_ctx12.m_dev->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT,
__uuidof(ID3D12CommandAllocator), &m_3dCtx.m_ctx12.m_loadqalloc)))
Log.report(logvisor::Fatal, "unable to create loader allocator");
D3D12_COMMAND_QUEUE_DESC desc =
{
D3D12_COMMAND_LIST_TYPE_DIRECT,
D3D12_COMMAND_QUEUE_PRIORITY_NORMAL,
D3D12_COMMAND_QUEUE_FLAG_NONE
};
if (FAILED(m_3dCtx.m_ctx12.m_dev->CreateCommandQueue(&desc, __uuidof(ID3D12CommandQueue), &m_3dCtx.m_ctx12.m_loadq)))
Log.report(logvisor::Fatal, "unable to create loader queue");
if (FAILED(m_3dCtx.m_ctx12.m_dev->CreateFence(0, D3D12_FENCE_FLAG_NONE, __uuidof(ID3D12Fence), &m_3dCtx.m_ctx12.m_loadfence)))
Log.report(logvisor::Fatal, "unable to create loader fence");
m_3dCtx.m_ctx12.m_loadfencehandle = CreateEvent(nullptr, FALSE, FALSE, nullptr);
if (FAILED(m_3dCtx.m_ctx12.m_dev->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, m_3dCtx.m_ctx12.m_loadqalloc.Get(),
nullptr, __uuidof(ID3D12GraphicsCommandList), &m_3dCtx.m_ctx12.m_loadlist)))
Log.report(logvisor::Fatal, "unable to create loader list");
Log.report(logvisor::Info, "initialized D3D12 renderer");
return;
}
else
{
/* Some Win10 client HW doesn't support D3D12 (despite being supposedly HW-agnostic) */
m_3dCtx.m_ctx12.m_dev.Reset();
m_3dCtx.m_ctx12.m_dxFactory.Reset();
}
}
#endif
HMODULE d3d11lib = nullptr; HMODULE d3d11lib = nullptr;
if (!noD3d) if (!noD3d)
d3d11lib = LoadLibraryW(L"D3D11.dll"); d3d11lib = LoadLibraryW(L"D3D11.dll");
@ -621,7 +502,7 @@ int ApplicationRun(IApplication::EPlatformType platform,
}; };
wndClass.hIcon = LoadIconW(wndClass.hInstance, MAKEINTRESOURCEW(101)); wndClass.hIcon = LoadIconW(wndClass.hInstance, MAKEINTRESOURCEW(101));
wndClass.hCursor = WIN32_CURSORS.m_arrow; wndClass.hCursor = WIN32_CURSORS.m_arrow;
ATOM a = RegisterClassW(&wndClass); RegisterClassW(&wndClass);
APP = new ApplicationWin32(cb, uniqueName, friendlyName, pname, args, APP = new ApplicationWin32(cb, uniqueName, friendlyName, pname, args,
gfxApi, samples, anisotropy, deepColor, singleInstance); gfxApi, samples, anisotropy, deepColor, singleInstance);
@ -633,9 +514,7 @@ int ApplicationRun(IApplication::EPlatformType platform,
static const DEV_BROADCAST_DEVICEINTERFACE HOTPLUG_CONF = static const DEV_BROADCAST_DEVICEINTERFACE HOTPLUG_CONF =
{ {
sizeof(DEV_BROADCAST_DEVICEINTERFACE), sizeof(DEV_BROADCAST_DEVICEINTERFACE),
DBT_DEVTYP_DEVICEINTERFACE, DBT_DEVTYP_DEVICEINTERFACE
0,
0
}; };
static bool HOTPLUG_REGISTERED = false; static bool HOTPLUG_REGISTERED = false;
static LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) static LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)

View File

@ -101,15 +101,6 @@ struct Boo3DAppContextWin32 : Boo3DAppContext
} }
#endif #endif
#if _WIN32_WINNT_WIN10
if (m_ctx12.m_dev)
{
D3D12Context::Window& win = m_ctx12.m_windows[window];
BOOL isFScr;
win.m_swapChain->GetFullscreenState(&isFScr, nullptr);
return isFScr != 0;
}
#endif
if (m_ctx11.m_dev) if (m_ctx11.m_dev)
{ {
D3D11Context::Window& win = m_ctx11.m_windows[window]; D3D11Context::Window& win = m_ctx11.m_windows[window];
@ -136,34 +127,6 @@ struct Boo3DAppContextWin32 : Boo3DAppContext
} }
#endif #endif
#if _WIN32_WINNT_WIN10
if (m_ctx12.m_dev)
{
D3D12Context::Window& win = m_ctx12.m_windows[window];
BOOL isFScr;
win.m_swapChain->GetFullscreenState(&isFScr, nullptr);
if (fs && isFScr)
return false;
else if (!fs && !isFScr)
return false;
if (fs)
{
ComPtr<IDXGIOutput> out;
win.m_swapChain->GetContainingOutput(&out);
DXGI_OUTPUT_DESC outDesc;
out->GetDesc(&outDesc);
win.m_swapChain->SetFullscreenState(true, nullptr);
DXGI_MODE_DESC mdesc = {UINT(outDesc.DesktopCoordinates.right - outDesc.DesktopCoordinates.left),
UINT(outDesc.DesktopCoordinates.bottom - outDesc.DesktopCoordinates.top)};
win.m_swapChain->ResizeTarget(&mdesc);
}
else
win.m_swapChain->SetFullscreenState(false, nullptr);
return true;
}
#endif
if (m_ctx11.m_dev) if (m_ctx11.m_dev)
{ {
D3D11Context::Window& win = m_ctx11.m_windows[window]; D3D11Context::Window& win = m_ctx11.m_windows[window];

View File

@ -1,4 +1,4 @@
#ifndef BOO_WI2COMMON_HPP #ifndef BOO_WINCOMMON_HPP
#define BOO_WINCOMMON_HPP #define BOO_WINCOMMON_HPP
#include <unordered_map> #include <unordered_map>
@ -107,29 +107,14 @@ struct D3D11Context
struct Boo3DAppContext struct Boo3DAppContext
{ {
D3D11Context m_ctx11; D3D11Context m_ctx11;
#if _WIN32_WINNT_WIN10
D3D12Context m_ctx12;
#endif
void resize(boo::IWindow* window, size_t width, size_t height) void resize(boo::IWindow* window, size_t width, size_t height)
{
#if _WIN32_WINNT_WIN10
if (m_ctx12.m_dev)
{
D3D12Context::Window& win = m_ctx12.m_windows[window];
win.width = width;
win.height = height;
win.m_needsResize = true;
}
else
#endif
{ {
D3D11Context::Window& win = m_ctx11.m_windows[window]; D3D11Context::Window& win = m_ctx11.m_windows[window];
win.width = width; win.width = width;
win.height = height; win.height = height;
win.m_needsResize = true; win.m_needsResize = true;
} }
}
}; };
static inline std::string WCSTMBS(const wchar_t* wstr) static inline std::string WCSTMBS(const wchar_t* wstr)

View File

@ -32,20 +32,20 @@ static const int ContextAttribs[] =
namespace boo namespace boo
{ {
static logvisor::Module Log("boo::WindowWin32"); static logvisor::Module Log("boo::WindowWin32");
#if _WIN32_WINNT_WIN10
IGraphicsCommandQueue* _NewD3D12CommandQueue(D3D12Context* ctx, D3D12Context::Window* windowCtx, IGraphicsContext* parent, std::unique_ptr<IGraphicsCommandQueue>
ID3D12CommandQueue** cmdQueueOut); _NewD3D11CommandQueue(D3D11Context* ctx, D3D11Context::Window* windowCtx, IGraphicsContext* parent);
IGraphicsDataFactory* _NewD3D12DataFactory(D3D12Context* ctx, IGraphicsContext* parent); std::unique_ptr<IGraphicsDataFactory>
#endif _NewD3D11DataFactory(D3D11Context* ctx, IGraphicsContext* parent);
IGraphicsCommandQueue* _NewD3D11CommandQueue(D3D11Context* ctx, D3D11Context::Window* windowCtx, IGraphicsContext* parent); std::unique_ptr<IGraphicsCommandQueue>
IGraphicsDataFactory* _NewD3D11DataFactory(D3D11Context* ctx, IGraphicsContext* parent); _NewGLCommandQueue(IGraphicsContext* parent, GLContext* glCtx);
IGraphicsCommandQueue* _NewGLCommandQueue(IGraphicsContext* parent, GLContext* glCtx); std::unique_ptr<IGraphicsDataFactory>
IGraphicsDataFactory* _NewGLDataFactory(IGraphicsContext* parent, GLContext* glCtx); _NewGLDataFactory(IGraphicsContext* parent, GLContext* glCtx);
#if BOO_HAS_VULKAN #if BOO_HAS_VULKAN
IGraphicsCommandQueue* _NewVulkanCommandQueue(VulkanContext* ctx, std::unique_ptr<IGraphicsCommandQueue>
VulkanContext::Window* windowCtx, _NewVulkanCommandQueue(VulkanContext* ctx, VulkanContext::Window* windowCtx, IGraphicsContext* parent);
IGraphicsContext* parent); std::unique_ptr<IGraphicsDataFactory>
IGraphicsDataFactory* _NewVulkanDataFactory(IGraphicsContext* parent, VulkanContext* ctx); _NewVulkanDataFactory(IGraphicsContext* parent, VulkanContext* ctx);
#endif #endif
struct GraphicsContextWin32 : IGraphicsContext struct GraphicsContextWin32 : IGraphicsContext
@ -71,8 +71,8 @@ struct GraphicsContextWin32D3D : GraphicsContextWin32
{ {
ComPtr<IDXGISwapChain1> m_swapChain; ComPtr<IDXGISwapChain1> m_swapChain;
IGraphicsCommandQueue* m_commandQueue = nullptr; std::unique_ptr<IGraphicsDataFactory> m_dataFactory;
IGraphicsDataFactory* m_dataFactory = nullptr; std::unique_ptr<IGraphicsCommandQueue> m_commandQueue;
public: public:
IWindowCallback* m_callback; IWindowCallback* m_callback;
@ -89,39 +89,6 @@ public:
scDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; scDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
scDesc.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH; scDesc.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
#if _WIN32_WINNT_WIN10
if (b3dCtx.m_ctx12.m_dev)
{
auto insIt = b3dCtx.m_ctx12.m_windows.emplace(std::make_pair(parentWindow, D3D12Context::Window()));
D3D12Context::Window& w = insIt.first->second;
ID3D12CommandQueue* cmdQueue;
m_dataFactory = _NewD3D12DataFactory(&b3dCtx.m_ctx12, this);
m_commandQueue = _NewD3D12CommandQueue(&b3dCtx.m_ctx12, &w, this, &cmdQueue);
m_commandQueue->startRenderer();
scDesc.Format = b3dCtx.m_ctx12.RGBATex2DFBViewDesc.Format;
scDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD;
HRESULT hr = b3dCtx.m_ctx12.m_dxFactory->CreateSwapChainForHwnd(cmdQueue,
hwnd, &scDesc, nullptr, nullptr, &m_swapChain);
if (FAILED(hr))
Log.report(logvisor::Fatal, "unable to create swap chain");
b3dCtx.m_ctx12.m_dxFactory->MakeWindowAssociation(hwnd, DXGI_MWA_NO_ALT_ENTER);
m_swapChain.As<IDXGISwapChain3>(&w.m_swapChain);
ComPtr<ID3D12Resource> fb;
m_swapChain->GetBuffer(0, __uuidof(ID3D12Resource), &fb);
w.m_backBuf = w.m_swapChain->GetCurrentBackBufferIndex();
D3D12_RESOURCE_DESC resDesc = fb->GetDesc();
w.width = resDesc.Width;
w.height = resDesc.Height;
if (FAILED(m_swapChain->GetContainingOutput(&m_output)))
Log.report(logvisor::Fatal, "unable to get DXGI output");
}
else
#endif
{
scDesc.Format = b3dCtx.m_ctx11.m_fbFormat; scDesc.Format = b3dCtx.m_ctx11.m_fbFormat;
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))) hwnd, &scDesc, nullptr, nullptr, &m_swapChain)))
@ -139,15 +106,9 @@ public:
if (FAILED(m_swapChain->GetContainingOutput(&m_output))) if (FAILED(m_swapChain->GetContainingOutput(&m_output)))
Log.report(logvisor::Fatal, "unable to get DXGI output"); Log.report(logvisor::Fatal, "unable to get DXGI output");
} }
}
~GraphicsContextWin32D3D() ~GraphicsContextWin32D3D()
{ {
#if _WIN32_WINNT_WIN10
if (m_3dCtx.m_ctx12.m_dev)
m_3dCtx.m_ctx12.m_windows.erase(m_parentWindow);
else
#endif
m_3dCtx.m_ctx11.m_windows.erase(m_parentWindow); m_3dCtx.m_ctx11.m_windows.erase(m_parentWindow);
} }
@ -183,29 +144,29 @@ public:
IGraphicsCommandQueue* getCommandQueue() IGraphicsCommandQueue* getCommandQueue()
{ {
return m_commandQueue; return m_commandQueue.get();
} }
IGraphicsDataFactory* getDataFactory() IGraphicsDataFactory* getDataFactory()
{ {
return m_dataFactory; return m_dataFactory.get();
} }
IGraphicsDataFactory* getMainContextDataFactory() IGraphicsDataFactory* getMainContextDataFactory()
{ {
return m_dataFactory; return m_dataFactory.get();
} }
IGraphicsDataFactory* getLoadContextDataFactory() IGraphicsDataFactory* getLoadContextDataFactory()
{ {
return m_dataFactory; return m_dataFactory.get();
} }
}; };
struct GraphicsContextWin32GL : GraphicsContextWin32 struct GraphicsContextWin32GL : GraphicsContextWin32
{ {
IGraphicsCommandQueue* m_commandQueue = nullptr; std::unique_ptr<IGraphicsDataFactory> m_dataFactory;
IGraphicsDataFactory* m_dataFactory = nullptr; std::unique_ptr<IGraphicsCommandQueue> m_commandQueue;
public: public:
IWindowCallback* m_callback; IWindowCallback* m_callback;
@ -370,7 +331,7 @@ public:
void postInit() void postInit()
{ {
OGLContext::Window& w = m_3dCtx.m_ctxOgl.m_windows[m_parentWindow]; //OGLContext::Window& w = m_3dCtx.m_ctxOgl.m_windows[m_parentWindow];
//wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC) //wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)
// wglGetProcAddress("wglCreateContextAttribsARB"); // wglGetProcAddress("wglCreateContextAttribsARB");
@ -393,12 +354,12 @@ public:
IGraphicsCommandQueue* getCommandQueue() IGraphicsCommandQueue* getCommandQueue()
{ {
return m_commandQueue; return m_commandQueue.get();
} }
IGraphicsDataFactory* getDataFactory() IGraphicsDataFactory* getDataFactory()
{ {
return m_dataFactory; return m_dataFactory.get();
} }
/* Creates a new context on current thread!! Call from client loading thread */ /* Creates a new context on current thread!! Call from client loading thread */
@ -414,7 +375,7 @@ public:
} }
if (!wglMakeCurrent(w.m_deviceContext, m_mainCtx)) if (!wglMakeCurrent(w.m_deviceContext, m_mainCtx))
Log.report(logvisor::Fatal, "unable to make main WGL context current"); Log.report(logvisor::Fatal, "unable to make main WGL context current");
return m_dataFactory; return m_dataFactory.get();
} }
/* Creates a new context on current thread!! Call from client loading thread */ /* Creates a new context on current thread!! Call from client loading thread */
@ -430,7 +391,7 @@ public:
} }
if (!wglMakeCurrent(w.m_deviceContext, m_loadCtx)) if (!wglMakeCurrent(w.m_deviceContext, m_loadCtx))
Log.report(logvisor::Fatal, "unable to make load WGL context current"); Log.report(logvisor::Fatal, "unable to make load WGL context current");
return m_dataFactory; return m_dataFactory.get();
} }
}; };
@ -444,8 +405,8 @@ struct GraphicsContextWin32Vulkan : GraphicsContextWin32
VkFormat m_format = VK_FORMAT_UNDEFINED; VkFormat m_format = VK_FORMAT_UNDEFINED;
VkColorSpaceKHR m_colorspace; VkColorSpaceKHR m_colorspace;
IGraphicsCommandQueue* m_commandQueue = nullptr; std::unique_ptr<IGraphicsDataFactory> m_dataFactory;
IGraphicsDataFactory* m_dataFactory = nullptr; std::unique_ptr<IGraphicsCommandQueue> m_commandQueue;
std::thread m_vsyncThread; std::thread m_vsyncThread;
bool m_vsyncRunning; bool m_vsyncRunning;
@ -655,12 +616,12 @@ public:
IGraphicsCommandQueue* getCommandQueue() IGraphicsCommandQueue* getCommandQueue()
{ {
return m_commandQueue; return m_commandQueue.get();
} }
IGraphicsDataFactory* getDataFactory() IGraphicsDataFactory* getDataFactory()
{ {
return m_dataFactory; return m_dataFactory.get();
} }
IGraphicsDataFactory* getMainContextDataFactory() IGraphicsDataFactory* getMainContextDataFactory()
@ -1043,12 +1004,10 @@ public:
if (m_gfxCtx->initializeContext(nullptr)) if (m_gfxCtx->initializeContext(nullptr))
return; return;
} }
#else
(void)wndInstance;
#endif #endif
IGraphicsContext::EGraphicsAPI api = IGraphicsContext::EGraphicsAPI::D3D11; IGraphicsContext::EGraphicsAPI api = IGraphicsContext::EGraphicsAPI::D3D11;
#if _WIN32_WINNT_WIN10
if (b3dCtx.m_ctx12.m_dev)
api = IGraphicsContext::EGraphicsAPI::D3D12;
#endif
if (b3dCtx.m_ctxOgl.m_dxFactory) if (b3dCtx.m_ctxOgl.m_dxFactory)
{ {
m_gfxCtx.reset(new GraphicsContextWin32GL(IGraphicsContext::EGraphicsAPI::OpenGL3_3, m_gfxCtx.reset(new GraphicsContextWin32GL(IGraphicsContext::EGraphicsAPI::OpenGL3_3,

View File

@ -19,7 +19,7 @@ class DolphinSmashAdapterCallback : public IDolphinSmashAdapterCallback
{ {
// printf("CONTROLLER %u CONNECTED\n", idx); // printf("CONTROLLER %u CONNECTED\n", idx);
} }
void controllerDisconnected(unsigned idx, EDolphinControllerType) void controllerDisconnected(unsigned idx)
{ {
// printf("CONTROLLER %u DISCONNECTED\n", idx); // printf("CONTROLLER %u DISCONNECTED\n", idx);
} }
@ -281,7 +281,7 @@ struct TestApplicationCallback : IApplicationCallback
{ {
IGraphicsDataFactory* factory = self->mainWindow->getLoadContextDataFactory(); IGraphicsDataFactory* factory = self->mainWindow->getLoadContextDataFactory();
factory->BooCommitTransaction([&](IGraphicsDataFactory::Context& ctx) factory->commitTransaction([&](IGraphicsDataFactory::Context& ctx)
{ {
/* Create render target */ /* Create render target */
int x, y, w, h; int x, y, w, h;
@ -409,10 +409,9 @@ struct TestApplicationCallback : IApplicationCallback
} else } else
#endif #endif
#if _WIN32 #if _WIN32
if (plat == IGraphicsDataFactory::Platform::D3D12 || if (plat == IGraphicsDataFactory::Platform::D3D11)
plat == IGraphicsDataFactory::Platform::D3D11)
{ {
ID3DDataFactory::Context& d3dF = dynamic_cast<ID3DDataFactory::Context&>(ctx); D3DDataFactory::Context& d3dF = dynamic_cast<D3DDataFactory::Context&>(ctx);
static const char* VS = static const char* VS =
"struct VertData {float3 in_pos : POSITION; float2 in_uv : UV;};\n" "struct VertData {float3 in_pos : POSITION; float2 in_uv : UV;};\n"
@ -482,7 +481,7 @@ struct TestApplicationCallback : IApplicationCallback
1, &texture, nullptr, nullptr); 1, &texture, nullptr, nullptr);
return true; return true;
}); } BooTrace);
} }
int appMain(IApplication* app) int appMain(IApplication* app)