mirror of
https://github.com/izzy2lost/dolphin.git
synced 2026-06-19 01:16:48 -07:00
Merge pull request #7592 from stenzek/imgui-prereq
VideoBackends: Share GX vertex/index/uniform buffers with utility draws
This commit is contained in:
@@ -4,7 +4,6 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "Common/Align.h"
|
||||
#include "Common/FileUtil.h"
|
||||
#include "Common/StringUtil.h"
|
||||
|
||||
@@ -18,8 +17,6 @@
|
||||
|
||||
#include "VideoCommon/Debugger.h"
|
||||
#include "VideoCommon/GeometryShaderGen.h"
|
||||
#include "VideoCommon/GeometryShaderManager.h"
|
||||
#include "VideoCommon/Statistics.h"
|
||||
#include "VideoCommon/VideoConfig.h"
|
||||
|
||||
namespace DX11
|
||||
@@ -36,25 +33,6 @@ ID3D11GeometryShader* GeometryShaderCache::GetCopyGeometryShader()
|
||||
return (g_ActiveConfig.stereo_mode != StereoMode::Off) ? CopyGeometryShader : nullptr;
|
||||
}
|
||||
|
||||
ID3D11Buffer* gscbuf = nullptr;
|
||||
|
||||
ID3D11Buffer*& GeometryShaderCache::GetConstantBuffer()
|
||||
{
|
||||
// TODO: divide the global variables of the generated shaders into about 5 constant buffers to
|
||||
// speed this up
|
||||
if (GeometryShaderManager::dirty)
|
||||
{
|
||||
D3D11_MAPPED_SUBRESOURCE map;
|
||||
D3D::context->Map(gscbuf, 0, D3D11_MAP_WRITE_DISCARD, 0, &map);
|
||||
memcpy(map.pData, &GeometryShaderManager::constants, sizeof(GeometryShaderConstants));
|
||||
D3D::context->Unmap(gscbuf, 0);
|
||||
GeometryShaderManager::dirty = false;
|
||||
|
||||
ADDSTAT(stats.thisFrame.bytesUniformStreamed, sizeof(GeometryShaderConstants));
|
||||
}
|
||||
return gscbuf;
|
||||
}
|
||||
|
||||
const char clear_shader_code[] = {
|
||||
"struct VSOUTPUT\n"
|
||||
"{\n"
|
||||
@@ -116,15 +94,6 @@ const char copy_shader_code[] = {
|
||||
|
||||
void GeometryShaderCache::Init()
|
||||
{
|
||||
unsigned int gbsize = Common::AlignUp(static_cast<unsigned int>(sizeof(GeometryShaderConstants)),
|
||||
16); // must be a multiple of 16
|
||||
D3D11_BUFFER_DESC gbdesc = CD3D11_BUFFER_DESC(gbsize, D3D11_BIND_CONSTANT_BUFFER,
|
||||
D3D11_USAGE_DYNAMIC, D3D11_CPU_ACCESS_WRITE);
|
||||
HRESULT hr = D3D::device->CreateBuffer(&gbdesc, nullptr, &gscbuf);
|
||||
CHECK(hr == S_OK, "Create geometry shader constant buffer (size=%u)", gbsize);
|
||||
D3D::SetDebugObjectName(gscbuf,
|
||||
"geometry shader constant buffer used to emulate the GX pipeline");
|
||||
|
||||
// used when drawing clear quads
|
||||
ClearGeometryShader = D3D::CompileAndCreateGeometryShader(clear_shader_code);
|
||||
CHECK(ClearGeometryShader != nullptr, "Create clear geometry shader");
|
||||
@@ -138,8 +107,6 @@ void GeometryShaderCache::Init()
|
||||
|
||||
void GeometryShaderCache::Shutdown()
|
||||
{
|
||||
SAFE_RELEASE(gscbuf);
|
||||
|
||||
SAFE_RELEASE(ClearGeometryShader);
|
||||
SAFE_RELEASE(CopyGeometryShader);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,8 @@ public:
|
||||
static ID3D11GeometryShader* GetClearGeometryShader();
|
||||
static ID3D11GeometryShader* GetCopyGeometryShader();
|
||||
|
||||
static ID3D11Buffer*& GetConstantBuffer();
|
||||
static ID3D11Buffer* GetConstantBuffer();
|
||||
static void UpdateConstantBuffer(const void* data, u32 data_size);
|
||||
};
|
||||
|
||||
} // namespace DX11
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "Common/Align.h"
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/FileUtil.h"
|
||||
#include "Common/MsgHandler.h"
|
||||
@@ -20,8 +19,6 @@
|
||||
|
||||
#include "VideoCommon/Debugger.h"
|
||||
#include "VideoCommon/PixelShaderGen.h"
|
||||
#include "VideoCommon/PixelShaderManager.h"
|
||||
#include "VideoCommon/Statistics.h"
|
||||
#include "VideoCommon/VideoConfig.h"
|
||||
|
||||
namespace DX11
|
||||
@@ -32,7 +29,6 @@ ID3D11PixelShader* s_AnaglyphProgram = nullptr;
|
||||
ID3D11PixelShader* s_DepthResolveProgram = nullptr;
|
||||
ID3D11PixelShader* s_rgba6_to_rgb8[2] = {nullptr};
|
||||
ID3D11PixelShader* s_rgb8_to_rgba6[2] = {nullptr};
|
||||
ID3D11Buffer* pscbuf = nullptr;
|
||||
|
||||
const char clear_program_code[] = {"void main(\n"
|
||||
"out float4 ocol0 : SV_Target,\n"
|
||||
@@ -277,36 +273,8 @@ ID3D11PixelShader* PixelShaderCache::GetDepthResolveProgram()
|
||||
return s_DepthResolveProgram;
|
||||
}
|
||||
|
||||
static void UpdateConstantBuffers()
|
||||
{
|
||||
if (PixelShaderManager::dirty)
|
||||
{
|
||||
D3D11_MAPPED_SUBRESOURCE map;
|
||||
D3D::context->Map(pscbuf, 0, D3D11_MAP_WRITE_DISCARD, 0, &map);
|
||||
memcpy(map.pData, &PixelShaderManager::constants, sizeof(PixelShaderConstants));
|
||||
D3D::context->Unmap(pscbuf, 0);
|
||||
PixelShaderManager::dirty = false;
|
||||
|
||||
ADDSTAT(stats.thisFrame.bytesUniformStreamed, sizeof(PixelShaderConstants));
|
||||
}
|
||||
}
|
||||
|
||||
ID3D11Buffer* PixelShaderCache::GetConstantBuffer()
|
||||
{
|
||||
UpdateConstantBuffers();
|
||||
return pscbuf;
|
||||
}
|
||||
|
||||
void PixelShaderCache::Init()
|
||||
{
|
||||
unsigned int cbsize = Common::AlignUp(static_cast<unsigned int>(sizeof(PixelShaderConstants)),
|
||||
16); // must be a multiple of 16
|
||||
D3D11_BUFFER_DESC cbdesc = CD3D11_BUFFER_DESC(cbsize, D3D11_BIND_CONSTANT_BUFFER,
|
||||
D3D11_USAGE_DYNAMIC, D3D11_CPU_ACCESS_WRITE);
|
||||
D3D::device->CreateBuffer(&cbdesc, nullptr, &pscbuf);
|
||||
CHECK(pscbuf != nullptr, "Create pixel shader constant buffer");
|
||||
D3D::SetDebugObjectName(pscbuf, "pixel shader constant buffer used to emulate the GX pipeline");
|
||||
|
||||
// used when drawing clear quads
|
||||
s_ClearProgram = D3D::CompileAndCreatePixelShader(clear_program_code);
|
||||
CHECK(s_ClearProgram != nullptr, "Create clear pixel shader");
|
||||
@@ -334,8 +302,6 @@ void PixelShaderCache::InvalidateMSAAShaders()
|
||||
|
||||
void PixelShaderCache::Shutdown()
|
||||
{
|
||||
SAFE_RELEASE(pscbuf);
|
||||
|
||||
SAFE_RELEASE(s_ClearProgram);
|
||||
SAFE_RELEASE(s_AnaglyphProgram);
|
||||
SAFE_RELEASE(s_DepthResolveProgram);
|
||||
|
||||
@@ -21,8 +21,6 @@ public:
|
||||
static void Init();
|
||||
static void Shutdown();
|
||||
|
||||
static ID3D11Buffer* GetConstantBuffer();
|
||||
|
||||
static ID3D11PixelShader* GetColorCopyProgram(bool multisampled);
|
||||
static ID3D11PixelShader* GetClearProgram();
|
||||
static ID3D11PixelShader* GetAnaglyphProgram();
|
||||
|
||||
@@ -63,7 +63,7 @@ typedef struct _Nv_Stereo_Image_Header
|
||||
#define NVSTEREO_IMAGE_SIGNATURE 0x4433564e
|
||||
|
||||
Renderer::Renderer(int backbuffer_width, int backbuffer_height)
|
||||
: ::Renderer(backbuffer_width, backbuffer_height)
|
||||
: ::Renderer(backbuffer_width, backbuffer_height, AbstractTextureFormat::RGBA8)
|
||||
{
|
||||
m_last_multisamples = g_ActiveConfig.iMultisamples;
|
||||
m_last_stereo_mode = g_ActiveConfig.stereo_mode != StereoMode::Off;
|
||||
@@ -167,16 +167,6 @@ void Renderer::SetupDeviceObjects()
|
||||
D3D::SetDebugObjectName(m_reset_rast_state, "rasterizer state for Renderer::ResetAPIState");
|
||||
|
||||
m_screenshot_texture = nullptr;
|
||||
|
||||
CD3D11_BUFFER_DESC vbo_desc(UTILITY_VBO_SIZE, D3D11_BIND_VERTEX_BUFFER, D3D11_USAGE_DYNAMIC,
|
||||
D3D11_CPU_ACCESS_WRITE);
|
||||
hr = D3D::device->CreateBuffer(&vbo_desc, nullptr, &m_utility_vertex_buffer);
|
||||
CHECK(SUCCEEDED(hr), "Create utility VBO");
|
||||
|
||||
CD3D11_BUFFER_DESC ubo_desc(UTILITY_UBO_SIZE, D3D11_BIND_CONSTANT_BUFFER, D3D11_USAGE_DYNAMIC,
|
||||
D3D11_CPU_ACCESS_WRITE);
|
||||
hr = D3D::device->CreateBuffer(&ubo_desc, nullptr, &m_utility_uniform_buffer);
|
||||
CHECK(SUCCEEDED(hr), "Create utility UBO");
|
||||
}
|
||||
|
||||
// Kill off all device objects
|
||||
@@ -196,8 +186,6 @@ void Renderer::TeardownDeviceObjects()
|
||||
SAFE_RELEASE(m_reset_rast_state);
|
||||
SAFE_RELEASE(m_screenshot_texture);
|
||||
SAFE_RELEASE(m_3d_vision_texture);
|
||||
SAFE_RELEASE(m_utility_vertex_buffer);
|
||||
SAFE_RELEASE(m_utility_uniform_buffer);
|
||||
}
|
||||
|
||||
void Renderer::Create3DVisionTexture(int width, int height)
|
||||
@@ -273,25 +261,6 @@ std::unique_ptr<AbstractPipeline> Renderer::CreatePipeline(const AbstractPipelin
|
||||
return DXPipeline::Create(config);
|
||||
}
|
||||
|
||||
void Renderer::UpdateUtilityUniformBuffer(const void* uniforms, u32 uniforms_size)
|
||||
{
|
||||
DEBUG_ASSERT(uniforms_size > 0 && uniforms_size < UTILITY_UBO_SIZE);
|
||||
D3D11_MAPPED_SUBRESOURCE mapped;
|
||||
HRESULT hr = D3D::context->Map(m_utility_uniform_buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped);
|
||||
CHECK(SUCCEEDED(hr), "Map utility UBO");
|
||||
std::memcpy(mapped.pData, uniforms, uniforms_size);
|
||||
D3D::context->Unmap(m_utility_uniform_buffer, 0);
|
||||
}
|
||||
|
||||
void Renderer::UpdateUtilityVertexBuffer(const void* vertices, u32 vertex_stride, u32 num_vertices)
|
||||
{
|
||||
D3D11_MAPPED_SUBRESOURCE mapped;
|
||||
HRESULT hr = D3D::context->Map(m_utility_vertex_buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped);
|
||||
CHECK(SUCCEEDED(hr), "Map utility VBO");
|
||||
std::memcpy(mapped.pData, vertices, num_vertices * vertex_stride);
|
||||
D3D::context->Unmap(m_utility_vertex_buffer, 0);
|
||||
}
|
||||
|
||||
void Renderer::SetPipeline(const AbstractPipeline* pipeline)
|
||||
{
|
||||
const DXPipeline* dx_pipeline = static_cast<const DXPipeline*>(pipeline);
|
||||
@@ -308,54 +277,6 @@ void Renderer::SetPipeline(const AbstractPipeline* pipeline)
|
||||
D3D::stateman->SetPixelShader(dx_pipeline->GetPixelShader());
|
||||
}
|
||||
|
||||
void Renderer::DrawUtilityPipeline(const void* uniforms, u32 uniforms_size, const void* vertices,
|
||||
u32 vertex_stride, u32 num_vertices)
|
||||
{
|
||||
// Copy in uniforms.
|
||||
if (uniforms_size > 0)
|
||||
{
|
||||
UpdateUtilityUniformBuffer(uniforms, uniforms_size);
|
||||
D3D::stateman->SetVertexConstants(m_utility_uniform_buffer);
|
||||
D3D::stateman->SetPixelConstants(m_utility_uniform_buffer);
|
||||
D3D::stateman->SetGeometryConstants(m_utility_uniform_buffer);
|
||||
}
|
||||
|
||||
// If the vertices are larger than our buffer, we need to break it up into multiple draws.
|
||||
const char* vertices_ptr = static_cast<const char*>(vertices);
|
||||
while (num_vertices > 0)
|
||||
{
|
||||
u32 vertices_this_draw = num_vertices;
|
||||
if (vertices_ptr)
|
||||
{
|
||||
vertices_this_draw = std::min(vertices_this_draw, UTILITY_VBO_SIZE / vertex_stride);
|
||||
DEBUG_ASSERT(vertices_this_draw > 0);
|
||||
UpdateUtilityVertexBuffer(vertices_ptr, vertex_stride, vertices_this_draw);
|
||||
D3D::stateman->SetVertexBuffer(m_utility_vertex_buffer, vertex_stride, 0);
|
||||
}
|
||||
|
||||
// Apply pending state and draw.
|
||||
D3D::stateman->Apply();
|
||||
D3D::context->Draw(vertices_this_draw, 0);
|
||||
vertices_ptr += vertex_stride * vertices_this_draw;
|
||||
num_vertices -= vertices_this_draw;
|
||||
}
|
||||
}
|
||||
|
||||
void Renderer::DispatchComputeShader(const AbstractShader* shader, const void* uniforms,
|
||||
u32 uniforms_size, u32 groups_x, u32 groups_y, u32 groups_z)
|
||||
{
|
||||
D3D::stateman->SetComputeShader(static_cast<const DXShader*>(shader)->GetD3DComputeShader());
|
||||
|
||||
if (uniforms_size > 0)
|
||||
{
|
||||
UpdateUtilityUniformBuffer(uniforms, uniforms_size);
|
||||
D3D::stateman->SetComputeConstants(m_utility_uniform_buffer);
|
||||
}
|
||||
|
||||
D3D::stateman->Apply();
|
||||
D3D::context->Dispatch(groups_x, groups_y, groups_z);
|
||||
}
|
||||
|
||||
TargetRectangle Renderer::ConvertEFBRectangle(const EFBRectangle& rc)
|
||||
{
|
||||
TargetRectangle result;
|
||||
@@ -549,15 +470,29 @@ void Renderer::SetViewport(float x, float y, float width, float height, float ne
|
||||
{
|
||||
// In D3D, the viewport rectangle must fit within the render target.
|
||||
D3D11_VIEWPORT vp;
|
||||
vp.TopLeftX = MathUtil::Clamp(x, 0.0f, static_cast<float>(m_target_width - 1));
|
||||
vp.TopLeftY = MathUtil::Clamp(y, 0.0f, static_cast<float>(m_target_height - 1));
|
||||
vp.Width = MathUtil::Clamp(width, 1.0f, static_cast<float>(m_target_width) - vp.TopLeftX);
|
||||
vp.Height = MathUtil::Clamp(height, 1.0f, static_cast<float>(m_target_height) - vp.TopLeftY);
|
||||
vp.TopLeftX = MathUtil::Clamp(x, 0.0f, static_cast<float>(m_current_framebuffer_width - 1));
|
||||
vp.TopLeftY = MathUtil::Clamp(y, 0.0f, static_cast<float>(m_current_framebuffer_height - 1));
|
||||
vp.Width =
|
||||
MathUtil::Clamp(width, 1.0f, static_cast<float>(m_current_framebuffer_width) - vp.TopLeftX);
|
||||
vp.Height =
|
||||
MathUtil::Clamp(height, 1.0f, static_cast<float>(m_current_framebuffer_height) - vp.TopLeftY);
|
||||
vp.MinDepth = near_depth;
|
||||
vp.MaxDepth = far_depth;
|
||||
D3D::context->RSSetViewports(1, &vp);
|
||||
}
|
||||
|
||||
void Renderer::Draw(u32 base_vertex, u32 num_vertices)
|
||||
{
|
||||
D3D::stateman->Apply();
|
||||
D3D::context->Draw(num_vertices, base_vertex);
|
||||
}
|
||||
|
||||
void Renderer::DrawIndexed(u32 base_index, u32 num_indices, u32 base_vertex)
|
||||
{
|
||||
D3D::stateman->Apply();
|
||||
D3D::context->DrawIndexed(num_indices, base_index, base_vertex);
|
||||
}
|
||||
|
||||
void Renderer::ClearScreen(const EFBRectangle& rc, bool colorEnable, bool alphaEnable, bool zEnable,
|
||||
u32 color, u32 z)
|
||||
{
|
||||
|
||||
@@ -50,6 +50,8 @@ public:
|
||||
void SetInterlacingMode() override;
|
||||
void SetViewport(float x, float y, float width, float height, float near_depth,
|
||||
float far_depth) override;
|
||||
void Draw(u32 base_vertex, u32 num_vertices) override;
|
||||
void DrawIndexed(u32 base_index, u32 num_indices, u32 base_vertex) override;
|
||||
void SetFullscreen(bool enable_fullscreen) override;
|
||||
bool IsFullscreen() const override;
|
||||
|
||||
@@ -73,11 +75,6 @@ public:
|
||||
|
||||
void ReinterpretPixelData(unsigned int convtype) override;
|
||||
|
||||
void DrawUtilityPipeline(const void* uniforms, u32 uniforms_size, const void* vertices,
|
||||
u32 vertex_stride, u32 num_vertices) override;
|
||||
void DispatchComputeShader(const AbstractShader* shader, const void* uniforms, u32 uniforms_size,
|
||||
u32 groups_x, u32 groups_y, u32 groups_z) override;
|
||||
|
||||
private:
|
||||
void SetupDeviceObjects();
|
||||
void TeardownDeviceObjects();
|
||||
@@ -89,9 +86,6 @@ private:
|
||||
void BlitScreen(TargetRectangle src, TargetRectangle dst, D3DTexture2D* src_texture,
|
||||
u32 src_width, u32 src_height);
|
||||
|
||||
void UpdateUtilityUniformBuffer(const void* uniforms, u32 uniforms_size);
|
||||
void UpdateUtilityVertexBuffer(const void* vertices, u32 vertex_stride, u32 num_vertices);
|
||||
|
||||
StateCache m_state_cache;
|
||||
|
||||
std::array<ID3D11BlendState*, 4> m_clear_blend_states{};
|
||||
@@ -103,9 +97,6 @@ private:
|
||||
ID3D11Texture2D* m_screenshot_texture = nullptr;
|
||||
D3DTexture2D* m_3d_vision_texture = nullptr;
|
||||
|
||||
ID3D11Buffer* m_utility_vertex_buffer = nullptr;
|
||||
ID3D11Buffer* m_utility_uniform_buffer = nullptr;
|
||||
|
||||
u32 m_last_multisamples = 1;
|
||||
bool m_last_stereo_mode = false;
|
||||
bool m_last_fullscreen_state = false;
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include <d3d11.h>
|
||||
|
||||
#include "Common/Align.h"
|
||||
#include "Common/CommonTypes.h"
|
||||
|
||||
#include "VideoBackends/D3D/BoundingBox.h"
|
||||
@@ -19,11 +20,14 @@
|
||||
|
||||
#include "VideoCommon/BoundingBox.h"
|
||||
#include "VideoCommon/Debugger.h"
|
||||
#include "VideoCommon/GeometryShaderManager.h"
|
||||
#include "VideoCommon/IndexGenerator.h"
|
||||
#include "VideoCommon/NativeVertexFormat.h"
|
||||
#include "VideoCommon/PixelShaderManager.h"
|
||||
#include "VideoCommon/RenderBase.h"
|
||||
#include "VideoCommon/Statistics.h"
|
||||
#include "VideoCommon/VertexLoaderManager.h"
|
||||
#include "VideoCommon/VertexShaderManager.h"
|
||||
#include "VideoCommon/VideoConfig.h"
|
||||
|
||||
namespace DX11
|
||||
@@ -33,15 +37,34 @@ const u32 MAX_IBUFFER_SIZE = VertexManager::MAXIBUFFERSIZE * sizeof(u16) * 8;
|
||||
const u32 MAX_VBUFFER_SIZE = VertexManager::MAXVBUFFERSIZE;
|
||||
const u32 MAX_BUFFER_SIZE = MAX_IBUFFER_SIZE + MAX_VBUFFER_SIZE;
|
||||
|
||||
static ID3D11Buffer* AllocateConstantBuffer(u32 size)
|
||||
{
|
||||
const u32 cbsize = Common::AlignUp(size, 16u); // must be a multiple of 16
|
||||
const CD3D11_BUFFER_DESC cbdesc(cbsize, D3D11_BIND_CONSTANT_BUFFER, D3D11_USAGE_DYNAMIC,
|
||||
D3D11_CPU_ACCESS_WRITE);
|
||||
ID3D11Buffer* cbuf;
|
||||
const HRESULT hr = D3D::device->CreateBuffer(&cbdesc, nullptr, &cbuf);
|
||||
CHECK(hr == S_OK, "shader constant buffer (size=%u)", cbsize);
|
||||
D3D::SetDebugObjectName(cbuf, "constant buffer used to emulate the GX pipeline");
|
||||
return cbuf;
|
||||
}
|
||||
|
||||
static void UpdateConstantBuffer(ID3D11Buffer* const buffer, const void* data, u32 data_size)
|
||||
{
|
||||
D3D11_MAPPED_SUBRESOURCE map;
|
||||
D3D::context->Map(buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &map);
|
||||
memcpy(map.pData, data, data_size);
|
||||
D3D::context->Unmap(buffer, 0);
|
||||
|
||||
ADDSTAT(stats.thisFrame.bytesUniformStreamed, data_size);
|
||||
}
|
||||
|
||||
void VertexManager::CreateDeviceObjects()
|
||||
{
|
||||
D3D11_BUFFER_DESC bufdesc =
|
||||
CD3D11_BUFFER_DESC(MAX_BUFFER_SIZE, D3D11_BIND_INDEX_BUFFER | D3D11_BIND_VERTEX_BUFFER,
|
||||
D3D11_USAGE_DYNAMIC, D3D11_CPU_ACCESS_WRITE);
|
||||
|
||||
m_vertexDrawOffset = 0;
|
||||
m_indexDrawOffset = 0;
|
||||
|
||||
for (int i = 0; i < MAX_BUFFER_COUNT; i++)
|
||||
{
|
||||
m_buffers[i] = nullptr;
|
||||
@@ -50,12 +73,18 @@ void VertexManager::CreateDeviceObjects()
|
||||
D3D::SetDebugObjectName(m_buffers[i], "Buffer of VertexManager");
|
||||
}
|
||||
|
||||
m_currentBuffer = 0;
|
||||
m_bufferCursor = MAX_BUFFER_SIZE;
|
||||
m_buffer_cursor = MAX_BUFFER_SIZE;
|
||||
|
||||
m_vertex_constant_buffer = AllocateConstantBuffer(sizeof(VertexShaderConstants));
|
||||
m_geometry_constant_buffer = AllocateConstantBuffer(sizeof(GeometryShaderConstants));
|
||||
m_pixel_constant_buffer = AllocateConstantBuffer(sizeof(PixelShaderConstants));
|
||||
}
|
||||
|
||||
void VertexManager::DestroyDeviceObjects()
|
||||
{
|
||||
SAFE_RELEASE(m_pixel_constant_buffer);
|
||||
SAFE_RELEASE(m_geometry_constant_buffer);
|
||||
SAFE_RELEASE(m_vertex_constant_buffer);
|
||||
for (int i = 0; i < MAX_BUFFER_COUNT; i++)
|
||||
{
|
||||
SAFE_RELEASE(m_buffers[i]);
|
||||
@@ -64,12 +93,12 @@ void VertexManager::DestroyDeviceObjects()
|
||||
|
||||
VertexManager::VertexManager()
|
||||
{
|
||||
LocalVBuffer.resize(MAXVBUFFERSIZE);
|
||||
m_staging_vertex_buffer.resize(MAXVBUFFERSIZE);
|
||||
|
||||
m_cur_buffer_pointer = m_base_buffer_pointer = &LocalVBuffer[0];
|
||||
m_end_buffer_pointer = m_base_buffer_pointer + LocalVBuffer.size();
|
||||
m_cur_buffer_pointer = m_base_buffer_pointer = &m_staging_vertex_buffer[0];
|
||||
m_end_buffer_pointer = m_base_buffer_pointer + m_staging_vertex_buffer.size();
|
||||
|
||||
LocalIBuffer.resize(MAXIBUFFERSIZE);
|
||||
m_staging_index_buffer.resize(MAXIBUFFERSIZE);
|
||||
|
||||
CreateDeviceObjects();
|
||||
}
|
||||
@@ -79,71 +108,103 @@ VertexManager::~VertexManager()
|
||||
DestroyDeviceObjects();
|
||||
}
|
||||
|
||||
void VertexManager::PrepareDrawBuffers(u32 stride)
|
||||
void VertexManager::UploadUtilityUniforms(const void* uniforms, u32 uniforms_size)
|
||||
{
|
||||
// Just use the one buffer for all three.
|
||||
UpdateConstantBuffer(m_vertex_constant_buffer, uniforms, uniforms_size);
|
||||
D3D::stateman->SetVertexConstants(m_vertex_constant_buffer);
|
||||
D3D::stateman->SetGeometryConstants(m_vertex_constant_buffer);
|
||||
D3D::stateman->SetPixelConstants(m_vertex_constant_buffer);
|
||||
VertexShaderManager::dirty = true;
|
||||
GeometryShaderManager::dirty = true;
|
||||
PixelShaderManager::dirty = true;
|
||||
}
|
||||
|
||||
void VertexManager::ResetBuffer(u32 vertex_stride, bool cull_all)
|
||||
{
|
||||
m_cur_buffer_pointer = m_base_buffer_pointer;
|
||||
IndexGenerator::Start(m_staging_index_buffer.data());
|
||||
}
|
||||
|
||||
void VertexManager::CommitBuffer(u32 num_vertices, u32 vertex_stride, u32 num_indices,
|
||||
u32* out_base_vertex, u32* out_base_index)
|
||||
{
|
||||
D3D11_MAPPED_SUBRESOURCE map;
|
||||
|
||||
u32 vertexBufferSize = u32(m_cur_buffer_pointer - m_base_buffer_pointer);
|
||||
u32 indexBufferSize = IndexGenerator::GetIndexLen() * sizeof(u16);
|
||||
u32 vertexBufferSize = Common::AlignUp(num_vertices * vertex_stride, sizeof(u16));
|
||||
u32 indexBufferSize = num_indices * sizeof(u16);
|
||||
u32 totalBufferSize = vertexBufferSize + indexBufferSize;
|
||||
|
||||
u32 cursor = m_bufferCursor;
|
||||
u32 padding = m_bufferCursor % stride;
|
||||
u32 cursor = m_buffer_cursor;
|
||||
u32 padding = vertex_stride > 0 ? (m_buffer_cursor % vertex_stride) : 0;
|
||||
if (padding)
|
||||
{
|
||||
cursor += stride - padding;
|
||||
cursor += vertex_stride - padding;
|
||||
}
|
||||
|
||||
D3D11_MAP MapType = D3D11_MAP_WRITE_NO_OVERWRITE;
|
||||
if (cursor + totalBufferSize >= MAX_BUFFER_SIZE)
|
||||
{
|
||||
// Wrap around
|
||||
m_currentBuffer = (m_currentBuffer + 1) % MAX_BUFFER_COUNT;
|
||||
m_current_buffer = (m_current_buffer + 1) % MAX_BUFFER_COUNT;
|
||||
cursor = 0;
|
||||
MapType = D3D11_MAP_WRITE_DISCARD;
|
||||
}
|
||||
|
||||
m_vertexDrawOffset = cursor;
|
||||
m_indexDrawOffset = cursor + vertexBufferSize;
|
||||
*out_base_vertex = vertex_stride > 0 ? (cursor / vertex_stride) : 0;
|
||||
*out_base_index = (cursor + vertexBufferSize) / sizeof(u16);
|
||||
|
||||
D3D::context->Map(m_buffers[m_currentBuffer], 0, MapType, 0, &map);
|
||||
D3D::context->Map(m_buffers[m_current_buffer], 0, MapType, 0, &map);
|
||||
u8* mappedData = reinterpret_cast<u8*>(map.pData);
|
||||
memcpy(mappedData + m_vertexDrawOffset, m_base_buffer_pointer, vertexBufferSize);
|
||||
memcpy(mappedData + m_indexDrawOffset, GetIndexBuffer(), indexBufferSize);
|
||||
D3D::context->Unmap(m_buffers[m_currentBuffer], 0);
|
||||
if (vertexBufferSize > 0)
|
||||
std::memcpy(mappedData + cursor, m_base_buffer_pointer, vertexBufferSize);
|
||||
if (indexBufferSize > 0)
|
||||
std::memcpy(mappedData + cursor + vertexBufferSize, m_staging_index_buffer.data(),
|
||||
indexBufferSize);
|
||||
D3D::context->Unmap(m_buffers[m_current_buffer], 0);
|
||||
|
||||
m_bufferCursor = cursor + totalBufferSize;
|
||||
m_buffer_cursor = cursor + totalBufferSize;
|
||||
|
||||
ADDSTAT(stats.thisFrame.bytesVertexStreamed, vertexBufferSize);
|
||||
ADDSTAT(stats.thisFrame.bytesIndexStreamed, indexBufferSize);
|
||||
|
||||
D3D::stateman->SetVertexBuffer(m_buffers[m_current_buffer], vertex_stride, 0);
|
||||
D3D::stateman->SetIndexBuffer(m_buffers[m_current_buffer]);
|
||||
}
|
||||
|
||||
void VertexManager::Draw(u32 stride)
|
||||
void VertexManager::UploadConstants()
|
||||
{
|
||||
u32 indices = IndexGenerator::GetIndexLen();
|
||||
if (VertexShaderManager::dirty)
|
||||
{
|
||||
UpdateConstantBuffer(m_vertex_constant_buffer, &VertexShaderManager::constants,
|
||||
sizeof(VertexShaderConstants));
|
||||
VertexShaderManager::dirty = false;
|
||||
}
|
||||
if (GeometryShaderManager::dirty)
|
||||
{
|
||||
UpdateConstantBuffer(m_geometry_constant_buffer, &GeometryShaderManager::constants,
|
||||
sizeof(GeometryShaderConstants));
|
||||
GeometryShaderManager::dirty = false;
|
||||
}
|
||||
if (PixelShaderManager::dirty)
|
||||
{
|
||||
UpdateConstantBuffer(m_pixel_constant_buffer, &PixelShaderManager::constants,
|
||||
sizeof(PixelShaderConstants));
|
||||
PixelShaderManager::dirty = false;
|
||||
}
|
||||
|
||||
D3D::stateman->SetVertexBuffer(m_buffers[m_currentBuffer], stride, 0);
|
||||
D3D::stateman->SetIndexBuffer(m_buffers[m_currentBuffer]);
|
||||
|
||||
u32 baseVertex = m_vertexDrawOffset / stride;
|
||||
u32 startIndex = m_indexDrawOffset / sizeof(u16);
|
||||
|
||||
D3D::stateman->Apply();
|
||||
D3D::context->DrawIndexed(indices, startIndex, baseVertex);
|
||||
|
||||
INCSTAT(stats.thisFrame.numDrawCalls);
|
||||
D3D::stateman->SetPixelConstants(m_pixel_constant_buffer, g_ActiveConfig.bEnablePixelLighting ?
|
||||
m_vertex_constant_buffer :
|
||||
nullptr);
|
||||
D3D::stateman->SetVertexConstants(m_vertex_constant_buffer);
|
||||
D3D::stateman->SetGeometryConstants(m_geometry_constant_buffer);
|
||||
}
|
||||
|
||||
void VertexManager::vFlush()
|
||||
void VertexManager::DrawCurrentBatch(u32 base_index, u32 num_indices, u32 base_vertex)
|
||||
{
|
||||
u32 stride = VertexLoaderManager::GetCurrentVertexFormat()->GetVertexStride();
|
||||
PrepareDrawBuffers(stride);
|
||||
|
||||
if (!m_current_pipeline_object)
|
||||
return;
|
||||
|
||||
FramebufferManager::SetIntegerEFBRenderTarget(
|
||||
m_current_pipeline_config.blending_state.logicopenable);
|
||||
|
||||
if (g_ActiveConfig.backend_info.bSupportsBBox && BoundingBox::active)
|
||||
{
|
||||
D3D::context->OMSetRenderTargetsAndUnorderedAccessViews(
|
||||
@@ -151,21 +212,7 @@ void VertexManager::vFlush()
|
||||
nullptr);
|
||||
}
|
||||
|
||||
g_renderer->SetPipeline(m_current_pipeline_object);
|
||||
|
||||
ID3D11Buffer* vertexConstants = VertexShaderCache::GetConstantBuffer();
|
||||
D3D::stateman->SetPixelConstants(PixelShaderCache::GetConstantBuffer(),
|
||||
g_ActiveConfig.bEnablePixelLighting ? vertexConstants : nullptr);
|
||||
D3D::stateman->SetVertexConstants(vertexConstants);
|
||||
D3D::stateman->SetGeometryConstants(GeometryShaderCache::GetConstantBuffer());
|
||||
|
||||
Draw(stride);
|
||||
D3D::stateman->Apply();
|
||||
D3D::context->DrawIndexed(num_indices, base_index, base_vertex);
|
||||
}
|
||||
|
||||
void VertexManager::ResetBuffer(u32 stride)
|
||||
{
|
||||
m_cur_buffer_pointer = m_base_buffer_pointer;
|
||||
IndexGenerator::Start(GetIndexBuffer());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace DX11
|
||||
|
||||
@@ -42,32 +42,32 @@ public:
|
||||
std::unique_ptr<NativeVertexFormat>
|
||||
CreateNativeVertexFormat(const PortableVertexDeclaration& vtx_decl) override;
|
||||
|
||||
void CreateDeviceObjects() override;
|
||||
void DestroyDeviceObjects() override;
|
||||
void UploadUtilityUniforms(const void* uniforms, u32 uniforms_size) override;
|
||||
|
||||
protected:
|
||||
void ResetBuffer(u32 stride) override;
|
||||
u16* GetIndexBuffer() { return &LocalIBuffer[0]; }
|
||||
void CreateDeviceObjects() override;
|
||||
void DestroyDeviceObjects() override;
|
||||
void ResetBuffer(u32 vertex_stride, bool cull_all) override;
|
||||
void CommitBuffer(u32 num_vertices, u32 vertex_stride, u32 num_indices, u32* out_base_vertex,
|
||||
u32* out_base_index) override;
|
||||
void UploadConstants() override;
|
||||
void DrawCurrentBatch(u32 base_index, u32 num_indices, u32 base_vertex) override;
|
||||
|
||||
private:
|
||||
void PrepareDrawBuffers(u32 stride);
|
||||
void Draw(u32 stride);
|
||||
// temp
|
||||
void vFlush() override;
|
||||
|
||||
u32 m_vertexDrawOffset;
|
||||
u32 m_indexDrawOffset;
|
||||
u32 m_currentBuffer;
|
||||
u32 m_bufferCursor;
|
||||
|
||||
enum
|
||||
{
|
||||
MAX_BUFFER_COUNT = 2
|
||||
};
|
||||
ID3D11Buffer* m_buffers[MAX_BUFFER_COUNT];
|
||||
ID3D11Buffer* m_buffers[MAX_BUFFER_COUNT] = {};
|
||||
u32 m_current_buffer = 0;
|
||||
u32 m_buffer_cursor = 0;
|
||||
|
||||
std::vector<u8> LocalVBuffer;
|
||||
std::vector<u16> LocalIBuffer;
|
||||
std::vector<u8> m_staging_vertex_buffer;
|
||||
std::vector<u16> m_staging_index_buffer;
|
||||
|
||||
ID3D11Buffer* m_vertex_constant_buffer = nullptr;
|
||||
ID3D11Buffer* m_geometry_constant_buffer = nullptr;
|
||||
ID3D11Buffer* m_pixel_constant_buffer = nullptr;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
} // namespace DX11
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "Common/Align.h"
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/FileUtil.h"
|
||||
#include "Common/MsgHandler.h"
|
||||
@@ -23,7 +22,6 @@
|
||||
#include "VideoCommon/UberShaderVertex.h"
|
||||
#include "VideoCommon/VertexLoaderManager.h"
|
||||
#include "VideoCommon/VertexShaderGen.h"
|
||||
#include "VideoCommon/VertexShaderManager.h"
|
||||
|
||||
namespace DX11
|
||||
{
|
||||
@@ -49,25 +47,6 @@ ID3D11InputLayout* VertexShaderCache::GetClearInputLayout()
|
||||
return ClearLayout;
|
||||
}
|
||||
|
||||
ID3D11Buffer* vscbuf = nullptr;
|
||||
|
||||
ID3D11Buffer*& VertexShaderCache::GetConstantBuffer()
|
||||
{
|
||||
// TODO: divide the global variables of the generated shaders into about 5 constant buffers to
|
||||
// speed this up
|
||||
if (VertexShaderManager::dirty)
|
||||
{
|
||||
D3D11_MAPPED_SUBRESOURCE map;
|
||||
D3D::context->Map(vscbuf, 0, D3D11_MAP_WRITE_DISCARD, 0, &map);
|
||||
memcpy(map.pData, &VertexShaderManager::constants, sizeof(VertexShaderConstants));
|
||||
D3D::context->Unmap(vscbuf, 0);
|
||||
VertexShaderManager::dirty = false;
|
||||
|
||||
ADDSTAT(stats.thisFrame.bytesUniformStreamed, sizeof(VertexShaderConstants));
|
||||
}
|
||||
return vscbuf;
|
||||
}
|
||||
|
||||
// this class will load the precompiled shaders into our cache
|
||||
template <typename UidType>
|
||||
class VertexShaderCacheInserter : public LinearDiskCacheReader<UidType, u8>
|
||||
@@ -121,14 +100,6 @@ void VertexShaderCache::Init()
|
||||
{"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0},
|
||||
};
|
||||
|
||||
unsigned int cbsize = Common::AlignUp(static_cast<unsigned int>(sizeof(VertexShaderConstants)),
|
||||
16); // must be a multiple of 16
|
||||
D3D11_BUFFER_DESC cbdesc = CD3D11_BUFFER_DESC(cbsize, D3D11_BIND_CONSTANT_BUFFER,
|
||||
D3D11_USAGE_DYNAMIC, D3D11_CPU_ACCESS_WRITE);
|
||||
HRESULT hr = D3D::device->CreateBuffer(&cbdesc, nullptr, &vscbuf);
|
||||
CHECK(hr == S_OK, "Create vertex shader constant buffer (size=%u)", cbsize);
|
||||
D3D::SetDebugObjectName(vscbuf, "vertex shader constant buffer used to emulate the GX pipeline");
|
||||
|
||||
D3DBlob* blob;
|
||||
D3D::CompileVertexShader(simple_shader_code, &blob);
|
||||
D3D::device->CreateInputLayout(simpleelems, 2, blob->Data(), blob->Size(), &SimpleLayout);
|
||||
@@ -156,8 +127,6 @@ void VertexShaderCache::Init()
|
||||
|
||||
void VertexShaderCache::Shutdown()
|
||||
{
|
||||
SAFE_RELEASE(vscbuf);
|
||||
|
||||
SAFE_RELEASE(SimpleVertexShader);
|
||||
SAFE_RELEASE(ClearVertexShader);
|
||||
|
||||
|
||||
@@ -23,8 +23,6 @@ public:
|
||||
static void Init();
|
||||
static void Shutdown();
|
||||
|
||||
static ID3D11Buffer*& GetConstantBuffer();
|
||||
|
||||
static ID3D11VertexShader* GetSimpleVertexShader();
|
||||
static ID3D11VertexShader* GetClearVertexShader();
|
||||
static ID3D11InputLayout* GetSimpleInputLayout();
|
||||
|
||||
@@ -161,7 +161,8 @@ bool VideoBackend::Initialize(const WindowSystemInfo& wsi)
|
||||
|
||||
D3D::InitUtils();
|
||||
BBox::Init();
|
||||
return true;
|
||||
|
||||
return g_renderer->Initialize();
|
||||
}
|
||||
|
||||
void VideoBackend::Shutdown()
|
||||
|
||||
@@ -64,7 +64,7 @@ bool VideoBackend::Initialize(const WindowSystemInfo& wsi)
|
||||
g_framebuffer_manager = std::make_unique<FramebufferManagerBase>();
|
||||
g_texture_cache = std::make_unique<TextureCache>();
|
||||
g_shader_cache = std::make_unique<VideoCommon::ShaderCache>();
|
||||
return g_shader_cache->Initialize();
|
||||
return g_renderer->Initialize() && g_shader_cache->Initialize();
|
||||
}
|
||||
|
||||
void VideoBackend::Shutdown()
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
namespace Null
|
||||
{
|
||||
// Init functions
|
||||
Renderer::Renderer() : ::Renderer(1, 1)
|
||||
Renderer::Renderer() : ::Renderer(1, 1, AbstractTextureFormat::RGBA8)
|
||||
{
|
||||
UpdateActiveConfig();
|
||||
}
|
||||
|
||||
@@ -22,6 +22,10 @@ VertexManager::CreateNativeVertexFormat(const PortableVertexDeclaration& vtx_dec
|
||||
return std::make_unique<NullNativeVertexFormat>(vtx_decl);
|
||||
}
|
||||
|
||||
void VertexManager::UploadUtilityUniforms(const void* uniforms, u32 uniforms_size)
|
||||
{
|
||||
}
|
||||
|
||||
VertexManager::VertexManager() : m_local_v_buffer(MAXVBUFFERSIZE), m_local_i_buffer(MAXIBUFFERSIZE)
|
||||
{
|
||||
}
|
||||
@@ -30,15 +34,24 @@ VertexManager::~VertexManager()
|
||||
{
|
||||
}
|
||||
|
||||
void VertexManager::ResetBuffer(u32 stride)
|
||||
void VertexManager::ResetBuffer(u32 vertex_stride, bool cull_all)
|
||||
{
|
||||
m_cur_buffer_pointer = m_base_buffer_pointer = m_local_v_buffer.data();
|
||||
m_end_buffer_pointer = m_cur_buffer_pointer + m_local_v_buffer.size();
|
||||
IndexGenerator::Start(&m_local_i_buffer[0]);
|
||||
}
|
||||
|
||||
void VertexManager::vFlush()
|
||||
void VertexManager::CommitBuffer(u32 num_vertices, u32 vertex_stride, u32 num_indices,
|
||||
u32* out_base_vertex, u32* out_base_index)
|
||||
{
|
||||
}
|
||||
|
||||
} // namespace
|
||||
void VertexManager::UploadConstants()
|
||||
{
|
||||
}
|
||||
|
||||
void VertexManager::DrawCurrentBatch(u32 base_index, u32 num_indices, u32 base_vertex)
|
||||
{
|
||||
}
|
||||
|
||||
} // namespace Null
|
||||
|
||||
@@ -20,11 +20,16 @@ public:
|
||||
std::unique_ptr<NativeVertexFormat>
|
||||
CreateNativeVertexFormat(const PortableVertexDeclaration& vtx_decl) override;
|
||||
|
||||
void UploadUtilityUniforms(const void* uniforms, u32 uniforms_size) override;
|
||||
|
||||
protected:
|
||||
void ResetBuffer(u32 stride) override;
|
||||
void ResetBuffer(u32 vertex_stride, bool cull_all) override;
|
||||
void CommitBuffer(u32 num_vertices, u32 vertex_stride, u32 num_indices, u32* out_base_vertex,
|
||||
u32* out_base_index) override;
|
||||
void UploadConstants() override;
|
||||
void DrawCurrentBatch(u32 base_index, u32 num_indices, u32 base_vertex) override;
|
||||
|
||||
private:
|
||||
void vFlush() override;
|
||||
std::vector<u8> m_local_v_buffer;
|
||||
std::vector<u16> m_local_i_buffer;
|
||||
};
|
||||
|
||||
@@ -259,6 +259,21 @@ void ProgramShaderCache::UploadConstants()
|
||||
}
|
||||
}
|
||||
|
||||
void ProgramShaderCache::UploadConstants(const void* data, u32 data_size)
|
||||
{
|
||||
// allocate and copy
|
||||
const u32 alloc_size = Common::AlignUp(data_size, s_ubo_align);
|
||||
auto buffer = s_buffer->Map(alloc_size, s_ubo_align);
|
||||
std::memcpy(buffer.first, data, data_size);
|
||||
s_buffer->Unmap(alloc_size);
|
||||
|
||||
// bind the same sub-buffer to all stages
|
||||
for (u32 index = 1; index <= 3; index++)
|
||||
glBindBufferRange(GL_UNIFORM_BUFFER, index, s_buffer->m_buffer, buffer.second, data_size);
|
||||
|
||||
ADDSTAT(stats.thisFrame.bytesUniformStreamed, data_size);
|
||||
}
|
||||
|
||||
bool ProgramShaderCache::CompileShader(SHADER& shader, const std::string& vcode,
|
||||
const std::string& pcode, const std::string& gcode)
|
||||
{
|
||||
@@ -539,6 +554,11 @@ void ProgramShaderCache::BindVertexFormat(const GLVertexFormat* vertex_format)
|
||||
s_last_VAO = new_VAO;
|
||||
}
|
||||
|
||||
bool ProgramShaderCache::IsValidVertexFormatBound()
|
||||
{
|
||||
return s_last_VAO != 0 && s_last_VAO != s_attributeless_VAO;
|
||||
}
|
||||
|
||||
void ProgramShaderCache::InvalidateVertexFormat()
|
||||
{
|
||||
s_last_VAO = 0;
|
||||
|
||||
@@ -69,6 +69,7 @@ class ProgramShaderCache
|
||||
{
|
||||
public:
|
||||
static void BindVertexFormat(const GLVertexFormat* vertex_format);
|
||||
static bool IsValidVertexFormatBound();
|
||||
static void InvalidateVertexFormat();
|
||||
static void InvalidateLastProgram();
|
||||
|
||||
@@ -83,6 +84,7 @@ public:
|
||||
static u32 GetUniformBufferAlignment();
|
||||
static void InvalidateConstants();
|
||||
static void UploadConstants();
|
||||
static void UploadConstants(const void* data, u32 data_size);
|
||||
|
||||
static void Init();
|
||||
static void Shutdown();
|
||||
|
||||
@@ -355,7 +355,8 @@ static void InitDriverInfo()
|
||||
// Init functions
|
||||
Renderer::Renderer(std::unique_ptr<GLContext> main_gl_context)
|
||||
: ::Renderer(static_cast<int>(std::max(main_gl_context->GetBackBufferWidth(), 1u)),
|
||||
static_cast<int>(std::max(main_gl_context->GetBackBufferHeight(), 1u))),
|
||||
static_cast<int>(std::max(main_gl_context->GetBackBufferHeight(), 1u)),
|
||||
AbstractTextureFormat::RGBA8),
|
||||
m_main_gl_context(std::move(main_gl_context))
|
||||
{
|
||||
bool bSuccess = true;
|
||||
@@ -811,6 +812,23 @@ bool Renderer::IsHeadless() const
|
||||
return m_main_gl_context->IsHeadless();
|
||||
}
|
||||
|
||||
bool Renderer::Initialize()
|
||||
{
|
||||
if (!::Renderer::Initialize())
|
||||
return false;
|
||||
|
||||
// Initialize the FramebufferManager
|
||||
g_framebuffer_manager = std::make_unique<FramebufferManager>(
|
||||
m_target_width, m_target_height, s_MSAASamples, BoundingBox::NeedsStencilBuffer());
|
||||
m_current_framebuffer_width = m_target_width;
|
||||
m_current_framebuffer_height = m_target_height;
|
||||
|
||||
m_post_processor = std::make_unique<OpenGLPostProcessing>();
|
||||
s_raster_font = std::make_unique<RasterFont>();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Renderer::Shutdown()
|
||||
{
|
||||
::Renderer::Shutdown();
|
||||
@@ -822,18 +840,6 @@ void Renderer::Shutdown()
|
||||
m_post_processor.reset();
|
||||
}
|
||||
|
||||
void Renderer::Init()
|
||||
{
|
||||
// Initialize the FramebufferManager
|
||||
g_framebuffer_manager = std::make_unique<FramebufferManager>(
|
||||
m_target_width, m_target_height, s_MSAASamples, BoundingBox::NeedsStencilBuffer());
|
||||
m_current_framebuffer_width = m_target_width;
|
||||
m_current_framebuffer_height = m_target_height;
|
||||
|
||||
m_post_processor = std::make_unique<OpenGLPostProcessing>();
|
||||
s_raster_font = std::make_unique<RasterFont>();
|
||||
}
|
||||
|
||||
std::unique_ptr<AbstractTexture> Renderer::CreateTexture(const TextureConfig& config)
|
||||
{
|
||||
return std::make_unique<OGLTexture>(config);
|
||||
@@ -1178,6 +1184,27 @@ void Renderer::SetViewport(float x, float y, float width, float height, float ne
|
||||
glDepthRangef(near_depth, far_depth);
|
||||
}
|
||||
|
||||
void Renderer::Draw(u32 base_vertex, u32 num_vertices)
|
||||
{
|
||||
glDrawArrays(static_cast<const OGLPipeline*>(m_graphics_pipeline)->GetGLPrimitive(), base_vertex,
|
||||
num_vertices);
|
||||
}
|
||||
|
||||
void Renderer::DrawIndexed(u32 base_index, u32 num_indices, u32 base_vertex)
|
||||
{
|
||||
if (g_ogl_config.bSupportsGLBaseVertex)
|
||||
{
|
||||
glDrawElementsBaseVertex(static_cast<const OGLPipeline*>(m_graphics_pipeline)->GetGLPrimitive(),
|
||||
num_indices, GL_UNSIGNED_SHORT,
|
||||
static_cast<u16*>(nullptr) + base_index, base_vertex);
|
||||
}
|
||||
else
|
||||
{
|
||||
glDrawElements(static_cast<const OGLPipeline*>(m_graphics_pipeline)->GetGLPrimitive(),
|
||||
num_indices, GL_UNSIGNED_SHORT, static_cast<u16*>(nullptr) + base_index);
|
||||
}
|
||||
}
|
||||
|
||||
void Renderer::ClearScreen(const EFBRectangle& rc, bool colorEnable, bool alphaEnable, bool zEnable,
|
||||
u32 color, u32 z)
|
||||
{
|
||||
@@ -1669,54 +1696,6 @@ void Renderer::SetInterlacingMode()
|
||||
// TODO
|
||||
}
|
||||
|
||||
void Renderer::DrawUtilityPipeline(const void* uniforms, u32 uniforms_size, const void* vertices,
|
||||
u32 vertex_stride, u32 num_vertices)
|
||||
{
|
||||
// Copy in uniforms.
|
||||
if (uniforms_size > 0)
|
||||
UploadUtilityUniforms(uniforms, uniforms_size);
|
||||
|
||||
// Draw from base index if there is vertex data.
|
||||
if (vertices)
|
||||
{
|
||||
StreamBuffer* vbuf = static_cast<VertexManager*>(g_vertex_manager.get())->GetVertexBuffer();
|
||||
auto buf = vbuf->Map(vertex_stride * num_vertices, vertex_stride);
|
||||
std::memcpy(buf.first, vertices, vertex_stride * num_vertices);
|
||||
vbuf->Unmap(vertex_stride * num_vertices);
|
||||
glDrawArrays(m_graphics_pipeline->GetGLPrimitive(), buf.second / vertex_stride, num_vertices);
|
||||
}
|
||||
else
|
||||
{
|
||||
glDrawArrays(m_graphics_pipeline->GetGLPrimitive(), 0, num_vertices);
|
||||
}
|
||||
}
|
||||
|
||||
void Renderer::UploadUtilityUniforms(const void* uniforms, u32 uniforms_size)
|
||||
{
|
||||
DEBUG_ASSERT(uniforms_size > 0);
|
||||
|
||||
auto buf = ProgramShaderCache::GetUniformBuffer()->Map(
|
||||
uniforms_size, ProgramShaderCache::GetUniformBufferAlignment());
|
||||
std::memcpy(buf.first, uniforms, uniforms_size);
|
||||
ProgramShaderCache::GetUniformBuffer()->Unmap(uniforms_size);
|
||||
glBindBufferRange(GL_UNIFORM_BUFFER, 1, ProgramShaderCache::GetUniformBuffer()->m_buffer,
|
||||
buf.second, uniforms_size);
|
||||
|
||||
// This is rather horrible, but because of how the UBOs are bound, this forces it to rebind.
|
||||
ProgramShaderCache::InvalidateConstants();
|
||||
}
|
||||
|
||||
void Renderer::DispatchComputeShader(const AbstractShader* shader, const void* uniforms,
|
||||
u32 uniforms_size, u32 groups_x, u32 groups_y, u32 groups_z)
|
||||
{
|
||||
glUseProgram(static_cast<const OGLShader*>(shader)->GetGLComputeProgramID());
|
||||
if (uniforms_size > 0)
|
||||
UploadUtilityUniforms(uniforms, uniforms_size);
|
||||
|
||||
glDispatchCompute(groups_x, groups_y, groups_z);
|
||||
ProgramShaderCache::InvalidateLastProgram();
|
||||
}
|
||||
|
||||
std::unique_ptr<VideoCommon::AsyncShaderCompiler> Renderer::CreateAsyncShaderCompiler()
|
||||
{
|
||||
return std::make_unique<SharedContextAsyncShaderCompiler>();
|
||||
|
||||
@@ -88,7 +88,7 @@ public:
|
||||
|
||||
bool IsHeadless() const override;
|
||||
|
||||
void Init();
|
||||
bool Initialize() override;
|
||||
void Shutdown() override;
|
||||
|
||||
std::unique_ptr<AbstractTexture> CreateTexture(const TextureConfig& config) override;
|
||||
@@ -116,6 +116,8 @@ public:
|
||||
void SetInterlacingMode() override;
|
||||
void SetViewport(float x, float y, float width, float height, float near_depth,
|
||||
float far_depth) override;
|
||||
void Draw(u32 base_vertex, u32 num_vertices) override;
|
||||
void DrawIndexed(u32 base_index, u32 num_indices, u32 base_vertex) override;
|
||||
|
||||
void RenderText(const std::string& text, int left, int top, u32 color) override;
|
||||
|
||||
@@ -137,18 +139,14 @@ public:
|
||||
|
||||
void ReinterpretPixelData(unsigned int convtype) override;
|
||||
|
||||
void DrawUtilityPipeline(const void* uniforms, u32 uniforms_size, const void* vertices,
|
||||
u32 vertex_stride, u32 num_vertices) override;
|
||||
|
||||
void DispatchComputeShader(const AbstractShader* shader, const void* uniforms, u32 uniforms_size,
|
||||
u32 groups_x, u32 groups_y, u32 groups_z) override;
|
||||
|
||||
std::unique_ptr<VideoCommon::AsyncShaderCompiler> CreateAsyncShaderCompiler() override;
|
||||
|
||||
// Only call methods from this on the GPU thread.
|
||||
GLContext* GetMainGLContext() const { return m_main_gl_context.get(); }
|
||||
bool IsGLES() const { return m_main_gl_context->IsGLES(); }
|
||||
|
||||
const OGLPipeline* GetCurrentGraphicsPipeline() const { return m_graphics_pipeline; }
|
||||
|
||||
private:
|
||||
void UpdateEFBCache(EFBAccessType type, u32 cacheRectIdx, const EFBRectangle& efbPixelRc,
|
||||
const TargetRectangle& targetPixelRc, const void* data);
|
||||
@@ -165,7 +163,6 @@ private:
|
||||
void ApplyBlendingState(const BlendingState state, bool force = false);
|
||||
void ApplyRasterizationState(const RasterizationState state, bool force = false);
|
||||
void ApplyDepthState(const DepthState state, bool force = false);
|
||||
void UploadUtilityUniforms(const void* uniforms, u32 uniforms_size);
|
||||
|
||||
std::unique_ptr<GLContext> m_main_gl_context;
|
||||
std::array<const AbstractTexture*, 8> m_bound_textures{};
|
||||
|
||||
@@ -19,6 +19,8 @@ public:
|
||||
static std::unique_ptr<StreamBuffer> Create(u32 type, u32 size);
|
||||
virtual ~StreamBuffer();
|
||||
|
||||
u32 GetCurrentOffset() const { return m_iterator; }
|
||||
|
||||
/* This mapping function will return a pair of:
|
||||
* - the pointer to the mapped buffer
|
||||
* - the offset into the real GPU buffer (always multiple of stride)
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user