thin3d: Merge BeginFrame and SetDebugFlags (set them every frame anyway)

This commit is contained in:
Henrik Rydgård 2023-08-10 15:53:05 +02:00
parent dec320de2d
commit 0deefb82a9
7 changed files with 44 additions and 54 deletions

View File

@ -137,7 +137,7 @@ public:
void DrawUP(const void *vdata, int vertexCount) override;
void Clear(int mask, uint32_t colorval, float depthVal, int stencilVal) override;
void BeginFrame() override;
void BeginFrame(DebugFlags debugFlags) override;
void EndFrame() override;
void Present() override;
@ -1529,7 +1529,7 @@ void D3D11DrawContext::Clear(int mask, uint32_t colorval, float depthVal, int st
}
}
void D3D11DrawContext::BeginFrame() {
void D3D11DrawContext::BeginFrame(DebugFlags debugFlags) {
context_->OMSetRenderTargets(1, &curRenderTargetView_, curDepthStencilView_);
if (curBlend_ != nullptr) {

View File

@ -329,9 +329,6 @@ public:
DrawContext::SetTargetSize(w, h);
renderManager_.Resize(w, h);
}
void SetDebugFlags(DebugFlags flags) override {
debugFlags_ = flags;
}
const DeviceCaps &GetDeviceCaps() const override {
return caps_;
@ -367,7 +364,7 @@ public:
Buffer *CreateBuffer(size_t size, uint32_t usageFlags) override;
Framebuffer *CreateFramebuffer(const FramebufferDesc &desc) override;
void BeginFrame() override;
void BeginFrame(DebugFlags debugFlags) override;
void EndFrame() override;
void Present() override;
@ -528,8 +525,6 @@ private:
GLPushBuffer *push;
};
FrameData frameData_[GLRenderManager::MAX_INFLIGHT_FRAMES]{};
DebugFlags debugFlags_ = DebugFlags::NONE;
};
static constexpr int MakeIntelSimpleVer(int v1, int v2, int v3) {
@ -794,8 +789,8 @@ OpenGLContext::~OpenGLContext() {
}
}
void OpenGLContext::BeginFrame() {
renderManager_.BeginFrame(debugFlags_ & DebugFlags::PROFILE_TIMESTAMPS);
void OpenGLContext::BeginFrame(DebugFlags debugFlags) {
renderManager_.BeginFrame(debugFlags & DebugFlags::PROFILE_TIMESTAMPS);
FrameData &frameData = frameData_[renderManager_.GetCurFrame()];
renderManager_.BeginPushBuffer(frameData.push);
}

View File

@ -388,7 +388,6 @@ public:
~VKContext();
void DebugAnnotate(const char *annotation) override;
void SetDebugFlags(DebugFlags flags) override;
const DeviceCaps &GetDeviceCaps() const override {
return caps_;
@ -479,7 +478,7 @@ public:
void Clear(int mask, uint32_t colorval, float depthVal, int stencilVal) override;
void BeginFrame() override;
void BeginFrame(DebugFlags debugFlags) override;
void EndFrame() override;
void Present() override;
@ -558,7 +557,6 @@ private:
AutoRef<VKFramebuffer> curFramebuffer_;
VkDevice device_;
DebugFlags debugFlags_ = DebugFlags::NONE;
enum {
MAX_FRAME_COMMAND_BUFFERS = 256,
@ -1105,9 +1103,9 @@ VKContext::~VKContext() {
vulkan_->Delete().QueueDeletePipelineCache(pipelineCache_);
}
void VKContext::BeginFrame() {
void VKContext::BeginFrame(DebugFlags debugFlags) {
// TODO: Bad dependency on g_Config here!
renderManager_.BeginFrame(debugFlags_ & DebugFlags::PROFILE_TIMESTAMPS, debugFlags_ & DebugFlags::PROFILE_SCOPES);
renderManager_.BeginFrame(debugFlags & DebugFlags::PROFILE_TIMESTAMPS, debugFlags & DebugFlags::PROFILE_SCOPES);
FrameData &frame = frame_[vulkan_->GetCurFrame()];
@ -1875,8 +1873,4 @@ void VKContext::DebugAnnotate(const char *annotation) {
renderManager_.DebugAnnotate(annotation);
}
void VKContext::SetDebugFlags(DebugFlags flags) {
debugFlags_ = flags;
}
} // namespace Draw

View File

@ -708,7 +708,6 @@ public:
virtual void SetErrorCallback(ErrorCallbackFn callback, void *userdata) {}
virtual void DebugAnnotate(const char *annotation) {}
virtual void SetDebugFlags(DebugFlags flags) {}
// Partial pipeline state, used to create pipelines. (in practice, in d3d11 they'll use the native state objects directly).
// TODO: Possibly ditch these and just put the descs directly in PipelineDesc since only D3D11 benefits.
@ -814,7 +813,7 @@ public:
virtual void DrawUP(const void *vdata, int vertexCount) = 0;
// Frame management (for the purposes of sync and resource management, necessary with modern APIs). Default implementations here.
virtual void BeginFrame() {}
virtual void BeginFrame(DebugFlags debugFlags) {}
virtual void EndFrame() = 0;
virtual void Present() = 0;

View File

@ -1049,6 +1049,37 @@ void RenderOverlays(UIContext *dc, void *userdata) {
}
}
static Matrix4x4 ComputeOrthoMatrix(float xres, float yres) {
Matrix4x4 ortho;
switch (GetGPUBackend()) {
case GPUBackend::VULKAN:
ortho.setOrthoD3D(0.0f, xres, 0, yres, -1.0f, 1.0f);
break;
case GPUBackend::DIRECT3D9:
ortho.setOrthoD3D(0.0f, xres, yres, 0.0f, -1.0f, 1.0f);
Matrix4x4 translation;
// Account for the small window adjustment.
translation.setTranslation(Vec3(
-0.5f * g_display.dpi_scale_x / g_display.dpi_scale_real_x,
-0.5f * g_display.dpi_scale_y / g_display.dpi_scale_real_y, 0.0f));
ortho = translation * ortho;
break;
case GPUBackend::DIRECT3D11:
ortho.setOrthoD3D(0.0f, xres, yres, 0.0f, -1.0f, 1.0f);
break;
case GPUBackend::OPENGL:
default:
ortho.setOrtho(0.0f, xres, yres, 0.0f, -1.0f, 1.0f);
break;
}
// Compensate for rotated display if needed.
if (g_display.rotation != DisplayRotation::ROTATE_0) {
ortho = ortho * g_display.rot_matrix;
}
return ortho;
}
void NativeFrame(GraphicsContext *graphicsContext) {
PROFILE_END_FRAME();
@ -1090,38 +1121,9 @@ void NativeFrame(GraphicsContext *graphicsContext) {
g_BackgroundAudio.Update();
}
float xres = g_display.dp_xres;
float yres = g_display.dp_yres;
// Apply the UIContext bounds as a 2D transformation matrix.
// TODO: This should be moved into the draw context...
Matrix4x4 ortho;
switch (GetGPUBackend()) {
case GPUBackend::VULKAN:
ortho.setOrthoD3D(0.0f, xres, 0, yres, -1.0f, 1.0f);
break;
case GPUBackend::DIRECT3D9:
ortho.setOrthoD3D(0.0f, xres, yres, 0.0f, -1.0f, 1.0f);
Matrix4x4 translation;
// Account for the small window adjustment.
translation.setTranslation(Vec3(
-0.5f * g_display.dpi_scale_x / g_display.dpi_scale_real_x,
-0.5f * g_display.dpi_scale_y / g_display.dpi_scale_real_y, 0.0f));
ortho = translation * ortho;
break;
case GPUBackend::DIRECT3D11:
ortho.setOrthoD3D(0.0f, xres, yres, 0.0f, -1.0f, 1.0f);
break;
case GPUBackend::OPENGL:
default:
ortho.setOrtho(0.0f, xres, yres, 0.0f, -1.0f, 1.0f);
break;
}
// Compensate for rotated display if needed.
if (g_display.rotation != DisplayRotation::ROTATE_0) {
ortho = ortho * g_display.rot_matrix;
}
Matrix4x4 ortho = ComputeOrthoMatrix(g_display.dp_xres, g_display.dp_yres);
Draw::DebugFlags debugFlags = Draw::DebugFlags::NONE;
if ((DebugOverlay)g_Config.iDebugOverlay == DebugOverlay::GPU_PROFILE)
@ -1129,7 +1131,7 @@ void NativeFrame(GraphicsContext *graphicsContext) {
if (g_Config.bGpuLogProfiler)
debugFlags |= Draw::DebugFlags::PROFILE_SCOPES;
g_draw->BeginFrame();
g_draw->BeginFrame(debugFlags);
ui_draw2d.PushDrawMatrix(ortho);
ui_draw2d_front.PushDrawMatrix(ortho);

View File

@ -238,7 +238,7 @@ bool RunAutoTest(HeadlessHost *headlessHost, CoreParameter &coreParameter, const
PSP_BeginHostFrame();
Draw::DrawContext *draw = coreParameter.graphicsContext ? coreParameter.graphicsContext->GetDrawContext() : nullptr;
if (draw)
draw->BeginFrame();
draw->BeginFrame(Draw::DebugFlags::NONE);
bool passed = true;
double deadline = time_now_d() + opt.timeout;

View File

@ -1163,7 +1163,7 @@ namespace Libretro
{
ctx->SetRenderTarget();
if (ctx->GetDrawContext())
ctx->GetDrawContext()->BeginFrame();
ctx->GetDrawContext()->BeginFrame(Draw::DebugFlags::NONE);
gpu->BeginHostFrame();