Skip to content

Commit

Permalink
[WIP] Videoshaders rebased on master
Browse files Browse the repository at this point in the history
  • Loading branch information
VelocityRa committed Oct 10, 2018
1 parent f468758 commit 20cc976
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 63 deletions.
22 changes: 2 additions & 20 deletions xbmc/cores/RetroPlayer/rendering/RPRenderManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,6 @@ void CRPRenderManager::AddFrame(const uint8_t* data, size_t size, unsigned int w
void CRPRenderManager::SetSpeed(double speed)
{
m_speed = speed;

for (const auto &renderer : m_renderers)
renderer->SetSpeed(speed); //! @todo Retroactive set speed for newly created renderers
}

void CRPRenderManager::FrameMove()
Expand Down Expand Up @@ -362,13 +359,7 @@ bool CRPRenderManager::SupportsScalingMethod(SCALINGMETHOD method) const
{
CRenderVideoSettings renderSettings;
renderSettings.SetScalingMethod(method);
bool hasAtLeastOneRenderer = !m_renderers.empty();
bool bufferPoolSupport = bufferPool->IsCompatible(renderSettings);
bool renderersSupport = std::all_of(m_renderers.begin(), m_renderers.end(),
[method](const std::shared_ptr<CRPBaseRenderer>& renderer) { return renderer->Supports(method); });

// If method is supported by the buffer pool and all the renderers, the manager supports it
if (hasAtLeastOneRenderer && bufferPoolSupport && renderersSupport)
if (bufferPool->IsCompatible(renderSettings))
return true;
}

Expand Down Expand Up @@ -474,7 +465,7 @@ std::shared_ptr<CRPBaseRenderer> CRPRenderManager::GetRenderer(IRenderBufferPool
// Try to create a renderer now, unless the shader preset has failed already
if (shaderPreset.empty() || m_failedShaderPresets.find(shaderPreset) == m_failedShaderPresets.end())
renderer.reset(m_processInfo.CreateRenderer(bufferPool, renderSettings));
if (renderer && renderer->Configure(m_format, m_width, m_height))
if (renderer && renderer->Configure(m_format))
{
// Ensure we have a render buffer for this renderer
CreateRenderBuffer(renderer->GetBufferPool());
Expand Down Expand Up @@ -637,8 +628,6 @@ CRenderVideoSettings CRPRenderManager::GetEffectiveSettings(const IGUIRenderSett
effectiveSettings.SetRenderStretchMode(settings->GetSettings().VideoSettings().GetRenderStretchMode());
if (settings->HasRotation())
effectiveSettings.SetRenderRotation(settings->GetSettings().VideoSettings().GetRenderRotation());
if (settings->HasShaderPreset())
effectiveSettings.SetShaderPreset(settings->GetSettings().VideoSettings().GetShaderPreset());
}

// Sanitize settings
Expand All @@ -647,12 +636,5 @@ CRenderVideoSettings CRPRenderManager::GetEffectiveSettings(const IGUIRenderSett
effectiveSettings.SetScalingMethod(m_processInfo.GetDefaultScalingMethod());
}

if (!effectiveSettings.GetShaderPreset().empty())
effectiveSettings.SetScalingMethod(VS_SCALINGMETHOD_AUTO);
ESCALINGMETHOD scalingMethod = effectiveSettings.GetScalingMethod();

// If the method is AUTO or unsupported by the manager, we need to set it to the default
if (scalingMethod == VS_SCALINGMETHOD_AUTO || !SupportsScalingMethod(scalingMethod))
effectiveSettings.SetScalingMethod(m_processInfo.GetDefaultScalingMethod());
return effectiveSettings;
}
2 changes: 0 additions & 2 deletions xbmc/cores/RetroPlayer/rendering/RPRenderManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,6 @@ namespace RETRO
// Synchronization parameters
CCriticalSection m_stateMutex;
CCriticalSection m_bufferMutex;

std::set<std::string> m_failedShaderPresets;
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ void CRPBaseRenderer::PreRender(bool clear)
if (clear)
m_context.Clear(m_context.UseLimitedColor() ? 0x101010 : 0);

ManageRenderArea();
//ManageRenderArea(*m_renderBuffer);

UpdateVideoShaders();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,6 @@ bool CRPRendererGuiTexture::Supports(RENDERFEATURE feature) const
return false;
}

bool CRPRendererGuiTexture::Supports(ESCALINGMETHOD method) const
{
if (method == VS_SCALINGMETHOD_LINEAR ||
method == VS_SCALINGMETHOD_NEAREST)
return true;

return false;
}

void CRPRendererGuiTexture::RenderInternal(bool clear, uint8_t alpha)
{
CRenderBufferGuiTexture *renderBuffer = static_cast<CRenderBufferGuiTexture*>(m_renderBuffer);
Expand Down
18 changes: 14 additions & 4 deletions xbmc/cores/RetroPlayer/rendering/VideoRenderers/RPWinRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ CWinRenderBuffer::CWinRenderBuffer(AVPixelFormat pixFormat, DXGI_FORMAT dxFormat

bool CWinRenderBuffer::CreateTexture()
{
if (!m_intermediateTarget->Create(m_width, m_height, 1, D3D11_USAGE_DYNAMIC, m_targetDxFormat))
if (!m_intermediateTarget->GetPointer()->Create(m_width, m_height, 1, D3D11_USAGE_DYNAMIC, m_targetDxFormat))
{
CLog::Log(LOGERROR, "WinRenderer: Intermediate render target creation failed");
return false;
Expand All @@ -69,7 +69,7 @@ bool CWinRenderBuffer::GetTexture(uint8_t*& data, unsigned int& stride)
{
// Scale and upload texture
D3D11_MAPPED_SUBRESOURCE destlr;
if (!m_intermediateTarget->LockRect(0, &destlr, D3D11_MAP_WRITE_DISCARD))
if (!m_intermediateTarget->GetPointer()->LockRect(0, &destlr, D3D11_MAP_WRITE_DISCARD))
{
CLog::Log(LOGERROR, "WinRenderer: Failed to lock swtarget texture into memory");
return false;
Expand All @@ -83,7 +83,7 @@ bool CWinRenderBuffer::GetTexture(uint8_t*& data, unsigned int& stride)

bool CWinRenderBuffer::ReleaseTexture()
{
if (!m_intermediateTarget->UnlockRect(0))
if (!m_intermediateTarget->GetPointer()->UnlockRect(0))
{
CLog::Log(LOGERROR, "WinRenderer: Failed to unlock swtarget texture");
return false;
Expand Down Expand Up @@ -284,6 +284,13 @@ bool CRPWinRenderer::SupportsScalingMethod(SCALINGMETHOD method)

void CRPWinRenderer::Render(CD3DTexture *target)
{
const CPoint destPoints[4] = {
m_rotatedDestCoords[0],
m_rotatedDestCoords[1],
m_rotatedDestCoords[2],
m_rotatedDestCoords[3]
};

CWinRenderBuffer *renderBuffer = static_cast<CWinRenderBuffer*>(m_renderBuffer);
if (renderBuffer == nullptr)
return;
Expand All @@ -295,8 +302,9 @@ void CRPWinRenderer::Render(CD3DTexture *target)
// Are we using video shaders?
if (m_bUseShaderPreset && m_renderBuffer != nullptr)
{
// TODO: Orientation?
/*
CPoint destPoints[4];

// select destination rectangle
if (m_renderOrientation)
{
Expand All @@ -311,6 +319,7 @@ void CRPWinRenderer::Render(CD3DTexture *target)
destPoints[2] = { destRect.x2, destRect.y2 };
destPoints[3] = { destRect.x1, destRect.y2 };
}
*/

CD3DTexture *intermediateTarget = renderBufferTarget->GetPointer();
// Render shaders and ouput to display
Expand Down Expand Up @@ -345,3 +354,4 @@ void CRPWinRenderer::Render(CD3DTexture *target)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ namespace SHADER
* \param target The target texture. The texture that the final result will be rendered in.
* \return Returns false if updating or rendering failed, true if both succeeded.
*/
virtual bool RenderUpdate(CPoint dest[], IShaderTexture* source, IShaderTexture* target) = 0;
virtual bool RenderUpdate(const CPoint dest[], IShaderTexture* source, IShaderTexture* target) = 0;

/*!
* \brief Informs about the speed of playback
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ bool CVideoShaderPresetDX::ReadPresetFile(const std::string& presetPath)
return CServiceBroker::GetGameServices().VideoShaders().LoadPreset(presetPath, *this);
}

bool CVideoShaderPresetDX::RenderUpdate(CPoint dest[], IShaderTexture* source, IShaderTexture* target)
bool CVideoShaderPresetDX::RenderUpdate(const CPoint dest[], IShaderTexture* source, IShaderTexture* target)
{
// Save the viewport
CRect viewPort;
Expand Down Expand Up @@ -422,7 +422,7 @@ bool CVideoShaderPresetDX::CreateBuffers()
return true;
}

void CVideoShaderPresetDX::PrepareParameters(const IShaderTexture* texture, CPoint dest[])
void CVideoShaderPresetDX::PrepareParameters(const IShaderTexture* texture, const CPoint dest[])
{
// prepare params for all shaders except the last (needs special flag)
for (unsigned shaderIdx = 0; shaderIdx < m_pVideoShaders.size() - 1; ++shaderIdx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class CVideoShaderPresetDX : public IVideoShaderPreset

// implementation of IVideoShaderPreset
bool ReadPresetFile(const std::string& presetPath) override;
bool RenderUpdate(CPoint dest[], IShaderTexture* source, IShaderTexture* target) override;
bool RenderUpdate(const CPoint dest[], IShaderTexture* source, IShaderTexture* target) override;
void SetSpeed(double speed) override { m_speed = speed; }
void SetVideoSize(const unsigned videoWidth, const unsigned videoHeight) override;
bool SetShaderPreset(const std::string& shaderPresetPath) override;
Expand All @@ -75,7 +75,7 @@ class CVideoShaderPresetDX : public IVideoShaderPreset
void UpdateViewPort(CRect viewPort);
void UpdateMVPs();
void DisposeVideoShaders();
void PrepareParameters(const IShaderTexture* texture, CPoint dest[]);
void PrepareParameters(const IShaderTexture* texture, const CPoint dest[]);
void RenderShader(IVideoShader* shader, IShaderTexture* source, IShaderTexture* target) const;
bool HasPathFailed(const std::string& path) const;

Expand Down
2 changes: 1 addition & 1 deletion xbmc/games/GameServices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ CGameServices::CGameServices(CControllerManager &controllerManager,
m_controllerManager(controllerManager),
m_gameRenderManager(renderManager),
m_profileManager(profileManager),
m_gameSettings(new CGameSettings())
m_gameSettings(new CGameSettings()),
m_videoShaders(new SHADER::CVideoShaderPresetFactory(addons, binaryAddons))
{
}
Expand Down
26 changes: 5 additions & 21 deletions xbmc/games/dialogs/osd/DialogGameVideoFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,27 +73,6 @@ void CDialogGameVideoFilter::PreInit()
m_bHasDescription = false;
}

void CDialogGameVideoFilter::InitVideoFilters()
{
if (m_gameVideoHandle)
{
for (const auto &scalingMethodProps : scalingMethods)
{
if (m_gameVideoHandle->SupportsScalingMethod(scalingMethodProps.scalingMethod))
{
RETRO::CRenderVideoSettings videoSettings;
videoSettings.SetScalingMethod(scalingMethodProps.scalingMethod);

CFileItemPtr item = std::make_shared<CFileItem>(g_localizeStrings.Get(scalingMethodProps.nameIndex));
item->SetLabel2(g_localizeStrings.Get(scalingMethodProps.categoryIndex));
item->SetProperty("game.videofilter", CVariant{ videoSettings.GetVideoFilter() });
item->SetProperty("game.videofilterdescription", CVariant{ g_localizeStrings.Get(scalingMethodProps.descriptionIndex) });
m_items.Add(std::move(item));
}
}
}
}

void CDialogGameVideoFilter::InitVideoFilters()
{
std::vector<VideoFilterProperties> videoFilters;
Expand Down Expand Up @@ -221,6 +200,11 @@ void CDialogGameVideoFilter::PostExit()
m_items.Clear();
}

std::string CDialogGameVideoFilter::GetLocalizedString(uint32_t code)
{
return g_localizeStrings.GetAddonString(PRESETS_ADDON_NAME, code);
}

void CDialogGameVideoFilter::GetProperties(const CFileItem &item, std::string &videoFilter, std::string &description)
{
videoFilter = item.GetProperty("game.videofilter").asString();
Expand Down
10 changes: 10 additions & 0 deletions xbmc/games/dialogs/osd/DialogGameVideoFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ namespace GAME

CFileItemList m_items;

static std::string GetLocalizedString(uint32_t code);

struct VideoFilterProperties
{
std::string path;
int nameIndex;
int categoryIndex;
int descriptionIndex;
};

//! \brief Set to true when a description has first been set
bool m_bHasDescription = false;
};
Expand Down

0 comments on commit 20cc976

Please sign in to comment.