GS/HW: Simplify m_vertex/m_index

Switches DX11 to a larger streaming buffer, adds missing texture copy
counter for colclip.
This commit is contained in:
Stenzek 2023-02-02 19:14:45 +10:00 committed by refractionpcsx2
parent d10621c201
commit 1b673d9dd0
10 changed files with 74 additions and 265 deletions

View File

@ -187,14 +187,6 @@ std::unique_ptr<GSDownloadTexture> GSDevice::CreateDownloadTexture(u32 width, u3
return {}; return {};
} }
void GSDevice::EndScene()
{
m_vertex.start += m_vertex.count;
m_vertex.count = 0;
m_index.start += m_index.count;
m_index.count = 0;
}
void GSDevice::Recycle(GSTexture* t) void GSDevice::Recycle(GSTexture* t)
{ {
if (!t) if (!t)

View File

@ -744,11 +744,11 @@ protected:
struct struct
{ {
size_t stride, start, count, limit; u32 start, count;
} m_vertex = {}; } m_vertex = {};
struct struct
{ {
size_t start, count, limit; u32 start, count;
} m_index = {}; } m_index = {};
unsigned int m_frame = 0; // for ageing the pool unsigned int m_frame = 0; // for ageing the pool
bool m_rbswapped = false; bool m_rbswapped = false;
@ -799,9 +799,6 @@ public:
virtual void ResetAPIState(); virtual void ResetAPIState();
virtual void RestoreAPIState(); virtual void RestoreAPIState();
virtual void BeginScene() {}
virtual void EndScene();
virtual void ClearRenderTarget(GSTexture* t, const GSVector4& c) {} virtual void ClearRenderTarget(GSTexture* t, const GSVector4& c) {}
virtual void ClearRenderTarget(GSTexture* t, u32 c) {} virtual void ClearRenderTarget(GSTexture* t, u32 c) {}
virtual void InvalidateRenderTarget(GSTexture* t) {} virtual void InvalidateRenderTarget(GSTexture* t) {}

View File

@ -272,6 +272,27 @@ bool GSDevice11::Create()
if (!m_shadeboost.ps) if (!m_shadeboost.ps)
return false; return false;
// Vertex/Index Buffer
bd = {};
bd.ByteWidth = VERTEX_BUFFER_SIZE;
bd.Usage = D3D11_USAGE_DYNAMIC;
bd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
if (FAILED(m_dev->CreateBuffer(&bd, nullptr, m_vb.put())))
{
Console.Error("Failed to create vertex buffer.");
return false;
}
bd.ByteWidth = INDEX_BUFFER_SIZE;
bd.BindFlags = D3D11_BIND_INDEX_BUFFER;
if (FAILED(m_dev->CreateBuffer(&bd, nullptr, m_ib.put())))
{
Console.Error("Failed to create index buffer.");
return false;
}
m_ctx->IASetIndexBuffer(m_ib.get(), DXGI_FORMAT_R32_UINT, 0);
// //
memset(&rd, 0, sizeof(rd)); memset(&rd, 0, sizeof(rd));
@ -369,10 +390,9 @@ void GSDevice11::ResetAPIState()
void GSDevice11::RestoreAPIState() void GSDevice11::RestoreAPIState()
{ {
const UINT vb_stride = static_cast<UINT>(m_state.vb_stride);
const UINT vb_offset = 0; const UINT vb_offset = 0;
m_ctx->IASetVertexBuffers(0, 1, &m_state.vb, &vb_stride, &vb_offset); m_ctx->IASetVertexBuffers(0, 1, m_vb.addressof(), &m_state.vb_stride, &vb_offset);
m_ctx->IASetIndexBuffer(m_state.ib, DXGI_FORMAT_R32_UINT, 0); m_ctx->IASetIndexBuffer(m_ib.get(), DXGI_FORMAT_R32_UINT, 0);
m_ctx->IASetInputLayout(m_state.layout); m_ctx->IASetInputLayout(m_state.layout);
m_ctx->IASetPrimitiveTopology(m_state.topology); m_ctx->IASetPrimitiveTopology(m_state.topology);
m_ctx->VSSetShader(m_state.vs, nullptr, 0); m_ctx->VSSetShader(m_state.vs, nullptr, 0);
@ -616,8 +636,6 @@ void GSDevice11::StretchRect(GSTexture* sTex, const GSVector4& sRect, GSTexture*
const bool draw_in_depth = dTex && dTex->IsDepthStencil(); const bool draw_in_depth = dTex && dTex->IsDepthStencil();
BeginScene();
GSVector2i ds; GSVector2i ds;
if (dTex) if (dTex)
{ {
@ -686,8 +704,6 @@ void GSDevice11::StretchRect(GSTexture* sTex, const GSVector4& sRect, GSTexture*
// //
EndScene();
PSSetShaderResources(nullptr, nullptr); PSSetShaderResources(nullptr, nullptr);
} }
@ -695,8 +711,6 @@ void GSDevice11::PresentRect(GSTexture* sTex, const GSVector4& sRect, GSTexture*
{ {
ASSERT(sTex); ASSERT(sTex);
BeginScene();
GSVector2i ds; GSVector2i ds;
if (dTex) if (dTex)
{ {
@ -763,8 +777,6 @@ void GSDevice11::PresentRect(GSTexture* sTex, const GSVector4& sRect, GSTexture*
// //
EndScene();
PSSetShaderResources(nullptr, nullptr); PSSetShaderResources(nullptr, nullptr);
} }
@ -945,8 +957,6 @@ void GSDevice11::SetupDATE(GSTexture* rt, GSTexture* ds, const GSVertexPT1* vert
{ {
// sfex3 (after the capcom logo), vf4 (first menu fading in), ffxii shadows, rumble roses shadows, persona4 shadows // sfex3 (after the capcom logo), vf4 (first menu fading in), ffxii shadows, rumble roses shadows, persona4 shadows
BeginScene();
ClearStencil(ds, 0); ClearStencil(ds, 0);
// om // om
@ -979,156 +989,69 @@ void GSDevice11::SetupDATE(GSTexture* rt, GSTexture* ds, const GSVertexPT1* vert
DrawPrimitive(); DrawPrimitive();
// //
EndScene();
} }
void GSDevice11::IASetVertexBuffer(const void* vertex, size_t stride, size_t count) bool GSDevice11::IASetVertexBuffer(const void* vertex, u32 stride, u32 count)
{ {
void* ptr = nullptr; const u32 size = stride * count;
if (size > VERTEX_BUFFER_SIZE)
if (IAMapVertexBuffer(&ptr, stride, count)) return false;
{
GSVector4i::storent(ptr, vertex, count * stride);
IAUnmapVertexBuffer();
}
}
bool GSDevice11::IAMapVertexBuffer(void** vertex, size_t stride, size_t count)
{
ASSERT(m_vertex.count == 0);
if (count * stride > m_vertex.limit * m_vertex.stride)
{
m_vb.reset();
m_vertex.start = 0;
m_vertex.limit = std::max<int>(count * 3 / 2, 11000);
}
if (m_vb == nullptr)
{
D3D11_BUFFER_DESC bd;
memset(&bd, 0, sizeof(bd));
bd.Usage = D3D11_USAGE_DYNAMIC;
bd.ByteWidth = m_vertex.limit * stride;
bd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
const HRESULT hr = m_dev->CreateBuffer(&bd, nullptr, m_vb.put());
if (FAILED(hr))
return false;
}
D3D11_MAP type = D3D11_MAP_WRITE_NO_OVERWRITE; D3D11_MAP type = D3D11_MAP_WRITE_NO_OVERWRITE;
if (m_vertex.start + count > m_vertex.limit || stride != m_vertex.stride) m_vertex.start = (m_vb_pos + (stride - 1)) / stride;
m_vb_pos = (m_vertex.start * stride) + size;
if (m_vb_pos > VERTEX_BUFFER_SIZE)
{ {
m_vertex.start = 0; m_vertex.start = 0;
m_vb_pos = size;
type = D3D11_MAP_WRITE_DISCARD; type = D3D11_MAP_WRITE_DISCARD;
} }
D3D11_MAPPED_SUBRESOURCE m; D3D11_MAPPED_SUBRESOURCE m;
if (FAILED(m_ctx->Map(m_vb.get(), 0, type, 0, &m))) if (FAILED(m_ctx->Map(m_vb.get(), 0, type, 0, &m)))
{
return false; return false;
GSVector4i::storent(static_cast<u8*>(m.pData) + m_vertex.start * stride, vertex, count * stride);
m_ctx->Unmap(m_vb.get(), 0);
if (m_state.vb_stride != stride)
{
m_state.vb_stride = stride;
const UINT vb_offset = 0;
m_ctx->IASetVertexBuffers(0, 1, m_vb.addressof(), &stride, &vb_offset);
} }
*vertex = (u8*)m.pData + m_vertex.start * stride;
m_vertex.count = count; m_vertex.count = count;
m_vertex.stride = stride;
return true; return true;
} }
void GSDevice11::IAUnmapVertexBuffer() bool GSDevice11::IASetIndexBuffer(const void* index, u32 count)
{ {
m_ctx->Unmap(m_vb.get(), 0); if (count > (INDEX_BUFFER_SIZE / sizeof(u32)))
return false;
IASetVertexBuffer(m_vb.get(), m_vertex.stride);
}
void GSDevice11::IASetVertexBuffer(ID3D11Buffer* vb, size_t stride)
{
if (m_state.vb != vb || m_state.vb_stride != stride)
{
m_state.vb = vb;
m_state.vb_stride = stride;
const u32 stride2 = stride;
const u32 offset = 0;
m_ctx->IASetVertexBuffers(0, 1, &vb, &stride2, &offset);
}
}
void GSDevice11::IASetIndexBuffer(const void* index, size_t count)
{
ASSERT(m_index.count == 0);
if (count > m_index.limit)
{
m_ib.reset();
m_index.start = 0;
m_index.limit = std::max<int>(count * 3 / 2, 11000);
}
if (m_ib == nullptr)
{
D3D11_BUFFER_DESC bd;
memset(&bd, 0, sizeof(bd));
bd.Usage = D3D11_USAGE_DYNAMIC;
bd.ByteWidth = m_index.limit * sizeof(u32);
bd.BindFlags = D3D11_BIND_INDEX_BUFFER;
bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
HRESULT hr = m_dev->CreateBuffer(&bd, nullptr, m_ib.put());
if (FAILED(hr))
return;
}
D3D11_MAP type = D3D11_MAP_WRITE_NO_OVERWRITE; D3D11_MAP type = D3D11_MAP_WRITE_NO_OVERWRITE;
if (m_index.start + count > m_index.limit) m_index.start = m_ib_pos;
m_ib_pos += count;
if (m_ib_pos > (INDEX_BUFFER_SIZE / sizeof(u32)))
{ {
m_index.start = 0; m_index.start = 0;
m_ib_pos = count;
type = D3D11_MAP_WRITE_DISCARD; type = D3D11_MAP_WRITE_DISCARD;
} }
D3D11_MAPPED_SUBRESOURCE m; D3D11_MAPPED_SUBRESOURCE m;
if (FAILED(m_ctx->Map(m_ib.get(), 0, type, 0, &m)))
return false;
if (SUCCEEDED(m_ctx->Map(m_ib.get(), 0, type, 0, &m))) std::memcpy((u8*)m.pData + m_index.start * sizeof(u32), index, count * sizeof(u32));
{ m_ctx->Unmap(m_ib.get(), 0);
memcpy((u8*)m.pData + m_index.start * sizeof(u32), index, count * sizeof(u32));
m_ctx->Unmap(m_ib.get(), 0);
}
m_index.count = count; m_index.count = count;
return true;
IASetIndexBuffer(m_ib.get());
}
void GSDevice11::IASetIndexBuffer(ID3D11Buffer* ib)
{
if (m_state.ib != ib)
{
m_state.ib = ib;
m_ctx->IASetIndexBuffer(ib, DXGI_FORMAT_R32_UINT, 0);
}
} }
void GSDevice11::IASetInputLayout(ID3D11InputLayout* layout) void GSDevice11::IASetInputLayout(ID3D11InputLayout* layout)
@ -1407,17 +1330,15 @@ void GSDevice11::RenderHW(GSHWDrawConfig& config)
// Warning: StretchRect must be called before BeginScene otherwise // Warning: StretchRect must be called before BeginScene otherwise
// vertices will be overwritten. Trust me you don't want to do that. // vertices will be overwritten. Trust me you don't want to do that.
StretchRect(config.rt, sRect, hdr_rt, dRect, ShaderConvert::HDR_INIT, false); StretchRect(config.rt, sRect, hdr_rt, dRect, ShaderConvert::HDR_INIT, false);
g_perfmon.Put(GSPerfMon::TextureCopies, 1);
} }
BeginScene(); if (!IASetVertexBuffer(config.verts, sizeof(*config.verts), config.nverts) ||
!IASetIndexBuffer(config.indices, config.nindices))
void* ptr = nullptr;
if (IAMapVertexBuffer(&ptr, sizeof(*config.verts), config.nverts))
{ {
GSVector4i::storent(ptr, config.verts, config.nverts * sizeof(*config.verts)); Console.Error("Failed to upload vertices/indices (%u/%u)", config.nverts, config.nindices);
IAUnmapVertexBuffer(); return;
} }
IASetIndexBuffer(config.indices, config.nindices);
D3D11_PRIMITIVE_TOPOLOGY topology = D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED; D3D11_PRIMITIVE_TOPOLOGY topology = D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED;
switch (config.topology) switch (config.topology)
{ {
@ -1526,8 +1447,6 @@ void GSDevice11::RenderHW(GSHWDrawConfig& config)
} }
} }
EndScene();
if (rt_copy) if (rt_copy)
Recycle(rt_copy); Recycle(rt_copy);
if (ds_copy) if (ds_copy)
@ -1541,6 +1460,7 @@ void GSDevice11::RenderHW(GSHWDrawConfig& config)
const GSVector4 dRect(config.drawarea); const GSVector4 dRect(config.drawarea);
const GSVector4 sRect = dRect / GSVector4(size.x, size.y).xyxy(); const GSVector4 sRect = dRect / GSVector4(size.x, size.y).xyxy();
StretchRect(hdr_rt, sRect, config.rt, dRect, ShaderConvert::HDR_RESOLVE, false); StretchRect(hdr_rt, sRect, config.rt, dRect, ShaderConvert::HDR_RESOLVE, false);
g_perfmon.Put(GSPerfMon::TextureCopies, 1);
Recycle(hdr_rt); Recycle(hdr_rt);
} }
} }

View File

@ -110,8 +110,13 @@ public:
}; };
private: private:
static constexpr u32 MAX_TEXTURES = 4; enum : u32
static constexpr u32 MAX_SAMPLERS = 1; {
MAX_TEXTURES = 4,
MAX_SAMPLERS = 1,
VERTEX_BUFFER_SIZE = 32 * 1024 * 1024,
INDEX_BUFFER_SIZE = 16 * 1024 * 1024,
};
int m_d3d_texsize; int m_d3d_texsize;
@ -135,12 +140,11 @@ private:
wil::com_ptr_nothrow<IDXGISwapChain1> m_swapchain; wil::com_ptr_nothrow<IDXGISwapChain1> m_swapchain;
wil::com_ptr_nothrow<ID3D11Buffer> m_vb; wil::com_ptr_nothrow<ID3D11Buffer> m_vb;
wil::com_ptr_nothrow<ID3D11Buffer> m_ib; wil::com_ptr_nothrow<ID3D11Buffer> m_ib;
u32 m_vb_pos = 0; // bytes
u32 m_ib_pos = 0; // indices/sizeof(u32)
struct struct
{ {
ID3D11Buffer* vb;
size_t vb_stride;
ID3D11Buffer* ib;
ID3D11InputLayout* layout; ID3D11InputLayout* layout;
D3D11_PRIMITIVE_TOPOLOGY topology; D3D11_PRIMITIVE_TOPOLOGY topology;
ID3D11VertexShader* vs; ID3D11VertexShader* vs;
@ -153,6 +157,7 @@ private:
std::array<ID3D11SamplerState*, MAX_SAMPLERS> ps_ss; std::array<ID3D11SamplerState*, MAX_SAMPLERS> ps_ss;
GSVector2i viewport; GSVector2i viewport;
GSVector4i scissor; GSVector4i scissor;
u32 vb_stride;
ID3D11DepthStencilState* dss; ID3D11DepthStencilState* dss;
u8 sref; u8 sref;
ID3D11BlendState* bs; ID3D11BlendState* bs;
@ -276,12 +281,8 @@ public:
void SetupDATE(GSTexture* rt, GSTexture* ds, const GSVertexPT1* vertices, bool datm); void SetupDATE(GSTexture* rt, GSTexture* ds, const GSVertexPT1* vertices, bool datm);
void IASetVertexBuffer(const void* vertex, size_t stride, size_t count); bool IASetVertexBuffer(const void* vertex, u32 stride, u32 count);
bool IAMapVertexBuffer(void** vertex, size_t stride, size_t count); bool IASetIndexBuffer(const void* index, u32 count);
void IAUnmapVertexBuffer();
void IASetVertexBuffer(ID3D11Buffer* vb, size_t stride);
void IASetIndexBuffer(const void* index, size_t count);
void IASetIndexBuffer(ID3D11Buffer* ib);
void IASetInputLayout(ID3D11InputLayout* layout); void IASetInputLayout(ID3D11InputLayout* layout);
void IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY topology); void IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY topology);

View File

@ -842,8 +842,6 @@ void GSDevice12::IASetVertexBuffer(const void* vertex, size_t stride, size_t cou
} }
m_vertex.start = m_vertex_stream_buffer.GetCurrentOffset() / stride; m_vertex.start = m_vertex_stream_buffer.GetCurrentOffset() / stride;
m_vertex.limit = count;
m_vertex.stride = stride;
m_vertex.count = count; m_vertex.count = count;
SetVertexBuffer(m_vertex_stream_buffer.GetGPUPointer(), m_vertex_stream_buffer.GetSize(), stride); SetVertexBuffer(m_vertex_stream_buffer.GetGPUPointer(), m_vertex_stream_buffer.GetSize(), stride);
@ -851,32 +849,6 @@ void GSDevice12::IASetVertexBuffer(const void* vertex, size_t stride, size_t cou
m_vertex_stream_buffer.CommitMemory(size); m_vertex_stream_buffer.CommitMemory(size);
} }
bool GSDevice12::IAMapVertexBuffer(void** vertex, size_t stride, size_t count)
{
const u32 size = static_cast<u32>(stride) * static_cast<u32>(count);
if (!m_vertex_stream_buffer.ReserveMemory(size, static_cast<u32>(stride)))
{
ExecuteCommandListAndRestartRenderPass(false, "Mapping bytes to vertex buffer");
if (!m_vertex_stream_buffer.ReserveMemory(size, static_cast<u32>(stride)))
pxFailRel("Failed to reserve space for vertices");
}
m_vertex.start = m_vertex_stream_buffer.GetCurrentOffset() / stride;
m_vertex.limit = m_vertex_stream_buffer.GetCurrentSpace() / stride;
m_vertex.stride = stride;
m_vertex.count = count;
SetVertexBuffer(m_vertex_stream_buffer.GetGPUPointer(), m_vertex_stream_buffer.GetSize(), stride);
*vertex = m_vertex_stream_buffer.GetCurrentHostPointer();
return true;
}
void GSDevice12::IAUnmapVertexBuffer()
{
const u32 size = static_cast<u32>(m_vertex.stride) * static_cast<u32>(m_vertex.count);
m_vertex_stream_buffer.CommitMemory(size);
}
void GSDevice12::IASetIndexBuffer(const void* index, size_t count) void GSDevice12::IASetIndexBuffer(const void* index, size_t count)
{ {
const u32 size = sizeof(u32) * static_cast<u32>(count); const u32 size = sizeof(u32) * static_cast<u32>(count);
@ -888,7 +860,6 @@ void GSDevice12::IASetIndexBuffer(const void* index, size_t count)
} }
m_index.start = m_index_stream_buffer.GetCurrentOffset() / sizeof(u32); m_index.start = m_index_stream_buffer.GetCurrentOffset() / sizeof(u32);
m_index.limit = count;
m_index.count = count; m_index.count = count;
SetIndexBuffer(m_index_stream_buffer.GetGPUPointer(), m_index_stream_buffer.GetSize(), DXGI_FORMAT_R32_UINT); SetIndexBuffer(m_index_stream_buffer.GetGPUPointer(), m_index_stream_buffer.GetSize(), DXGI_FORMAT_R32_UINT);
@ -2657,8 +2628,6 @@ void GSDevice12::RenderHW(GSHWDrawConfig& config)
if (date_image) if (date_image)
Recycle(date_image); Recycle(date_image);
EndScene();
// now blit the hdr texture back to the original target // now blit the hdr texture back to the original target
if (hdr_rt) if (hdr_rt)
{ {

View File

@ -264,8 +264,6 @@ public:
GSTexture12* SetupPrimitiveTrackingDATE(GSHWDrawConfig& config, PipelineSelector& pipe); GSTexture12* SetupPrimitiveTrackingDATE(GSHWDrawConfig& config, PipelineSelector& pipe);
void IASetVertexBuffer(const void* vertex, size_t stride, size_t count); void IASetVertexBuffer(const void* vertex, size_t stride, size_t count);
bool IAMapVertexBuffer(void** vertex, size_t stride, size_t count);
void IAUnmapVertexBuffer();
void IASetIndexBuffer(const void* index, size_t count); void IASetIndexBuffer(const void* index, size_t count);
void PSSetShaderResource(int i, GSTexture* sr, bool check_state); void PSSetShaderResource(int i, GSTexture* sr, bool check_state);

View File

@ -1127,8 +1127,6 @@ void GSDeviceMTL::CopyRect(GSTexture* sTex, GSTexture* dTex, const GSVector4i& r
void GSDeviceMTL::DoStretchRect(GSTexture* sTex, const GSVector4& sRect, GSTexture* dTex, const GSVector4& dRect, id<MTLRenderPipelineState> pipeline, bool linear, LoadAction load_action, void* frag_uniform, size_t frag_uniform_len) void GSDeviceMTL::DoStretchRect(GSTexture* sTex, const GSVector4& sRect, GSTexture* dTex, const GSVector4& dRect, id<MTLRenderPipelineState> pipeline, bool linear, LoadAction load_action, void* frag_uniform, size_t frag_uniform_len)
{ {
BeginScene();
FlushClears(sTex); FlushClears(sTex);
GSTextureMTL* sT = static_cast<GSTextureMTL*>(sTex); GSTextureMTL* sT = static_cast<GSTextureMTL*>(sTex);
@ -1164,8 +1162,6 @@ void GSDeviceMTL::DoStretchRect(GSTexture* sTex, const GSVector4& sRect, GSTextu
MRESetSampler(linear ? SamplerSelector::Linear() : SamplerSelector::Point()); MRESetSampler(linear ? SamplerSelector::Linear() : SamplerSelector::Point());
DrawStretchRect(sRect, dRect, ds); DrawStretchRect(sRect, dRect, ds);
EndScene();
} }
void GSDeviceMTL::DrawStretchRect(const GSVector4& sRect, const GSVector4& dRect, const GSVector2i& ds) void GSDeviceMTL::DrawStretchRect(const GSVector4& sRect, const GSVector4& dRect, const GSVector2i& ds)
@ -1609,7 +1605,6 @@ static_assert(offsetof(GSHWDrawConfig::PSConstantBuffer, DitherMatrix) == of
void GSDeviceMTL::SetupDestinationAlpha(GSTexture* rt, GSTexture* ds, const GSVector4i& r, bool datm) void GSDeviceMTL::SetupDestinationAlpha(GSTexture* rt, GSTexture* ds, const GSVector4i& r, bool datm)
{ {
BeginScene();
FlushClears(rt); FlushClears(rt);
BeginRenderPass(@"Destination Alpha Setup", nullptr, MTLLoadActionDontCare, nullptr, MTLLoadActionDontCare, ds, MTLLoadActionDontCare); BeginRenderPass(@"Destination Alpha Setup", nullptr, MTLLoadActionDontCare, nullptr, MTLLoadActionDontCare, ds, MTLLoadActionDontCare);
[m_current_render.encoder setStencilReferenceValue:1]; [m_current_render.encoder setStencilReferenceValue:1];
@ -1617,7 +1612,6 @@ void GSDeviceMTL::SetupDestinationAlpha(GSTexture* rt, GSTexture* ds, const GSVe
RenderCopy(nullptr, m_stencil_clear_pipeline, r); RenderCopy(nullptr, m_stencil_clear_pipeline, r);
MRESetDSS(m_dss_stencil_write); MRESetDSS(m_dss_stencil_write);
RenderCopy(rt, m_datm_pipeline[datm], r); RenderCopy(rt, m_datm_pipeline[datm], r);
EndScene();
} }
static id<MTLTexture> getTexture(GSTexture* tex) static id<MTLTexture> getTexture(GSTexture* tex)
@ -1696,7 +1690,6 @@ void GSDeviceMTL::RenderHW(GSHWDrawConfig& config)
break; break;
} }
BeginScene();
GSTexture* hdr_rt = nullptr; GSTexture* hdr_rt = nullptr;
if (config.ps.hdr) if (config.ps.hdr)
{ {

View File

@ -1093,7 +1093,6 @@ void GSDeviceOGL::BlitRect(GSTexture* sTex, const GSVector4i& r, const GSVector2
const GSVector4 float_r(r); const GSVector4 float_r(r);
BeginScene();
m_convert.ps[static_cast<int>(ShaderConvert::COPY)].Bind(); m_convert.ps[static_cast<int>(ShaderConvert::COPY)].Bind();
OMSetDepthStencilState(m_convert.dss); OMSetDepthStencilState(m_convert.dss);
OMSetBlendState(); OMSetBlendState();
@ -1101,7 +1100,6 @@ void GSDeviceOGL::BlitRect(GSTexture* sTex, const GSVector4i& r, const GSVector2
PSSetShaderResource(0, sTex); PSSetShaderResource(0, sTex);
PSSetSamplerState(linear ? m_convert.ln : m_convert.pt); PSSetSamplerState(linear ? m_convert.ln : m_convert.pt);
DrawStretchRect(float_r / (GSVector4(sTex->GetSize()).xyxy()), float_r, dsize); DrawStretchRect(float_r / (GSVector4(sTex->GetSize()).xyxy()), float_r, dsize);
EndScene();
glEnable(GL_SCISSOR_TEST); glEnable(GL_SCISSOR_TEST);
} }
@ -1190,8 +1188,6 @@ void GSDeviceOGL::StretchRect(GSTexture* sTex, const GSVector4& sRect, GSTexture
// Init // Init
// ************************************ // ************************************
BeginScene();
GL_PUSH("StretchRect from %d to %d", sTex->GetID(), dTex->GetID()); GL_PUSH("StretchRect from %d to %d", sTex->GetID(), dTex->GetID());
if (draw_in_depth) if (draw_in_depth)
OMSetRenderTargets(NULL, dTex); OMSetRenderTargets(NULL, dTex);
@ -1223,20 +1219,12 @@ void GSDeviceOGL::StretchRect(GSTexture* sTex, const GSVector4& sRect, GSTexture
// Draw // Draw
// ************************************ // ************************************
DrawStretchRect(sRect, dRect, dTex->GetSize()); DrawStretchRect(sRect, dRect, dTex->GetSize());
// ************************************
// End
// ************************************
EndScene();
} }
void GSDeviceOGL::PresentRect(GSTexture* sTex, const GSVector4& sRect, GSTexture* dTex, const GSVector4& dRect, PresentShader shader, float shaderTime, bool linear) void GSDeviceOGL::PresentRect(GSTexture* sTex, const GSVector4& sRect, GSTexture* dTex, const GSVector4& dRect, PresentShader shader, float shaderTime, bool linear)
{ {
ASSERT(sTex); ASSERT(sTex);
BeginScene();
const GSVector2i ds(dTex ? dTex->GetSize() : GSVector2i(g_host_display->GetWindowWidth(), g_host_display->GetWindowHeight())); const GSVector2i ds(dTex ? dTex->GetSize() : GSVector2i(g_host_display->GetWindowWidth(), g_host_display->GetWindowHeight()));
DisplayConstantBuffer cb; DisplayConstantBuffer cb;
cb.SetSource(sRect, sTex->GetSize()); cb.SetSource(sRect, sTex->GetSize());
@ -1269,14 +1257,10 @@ void GSDeviceOGL::PresentRect(GSTexture* sTex, const GSVector4& sRect, GSTexture
// Only flipping the backbuffer is transparent (I hope)... // Only flipping the backbuffer is transparent (I hope)...
const GSVector4 flip_sr(sRect.xwzy()); const GSVector4 flip_sr(sRect.xwzy());
DrawStretchRect(flip_sr, dRect, ds); DrawStretchRect(flip_sr, dRect, ds);
EndScene();
} }
void GSDeviceOGL::UpdateCLUTTexture(GSTexture* sTex, u32 offsetX, u32 offsetY, GSTexture* dTex, u32 dOffset, u32 dSize) void GSDeviceOGL::UpdateCLUTTexture(GSTexture* sTex, u32 offsetX, u32 offsetY, GSTexture* dTex, u32 dOffset, u32 dSize)
{ {
BeginScene();
const ShaderConvert shader = (dSize == 16) ? ShaderConvert::CLUT_4 : ShaderConvert::CLUT_8; const ShaderConvert shader = (dSize == 16) ? ShaderConvert::CLUT_4 : ShaderConvert::CLUT_8;
GL::Program& prog = m_convert.ps[static_cast<int>(shader)]; GL::Program& prog = m_convert.ps[static_cast<int>(shader)];
prog.Bind(); prog.Bind();
@ -1293,8 +1277,6 @@ void GSDeviceOGL::UpdateCLUTTexture(GSTexture* sTex, u32 offsetX, u32 offsetY, G
const GSVector4 dRect(0, 0, dSize, 1); const GSVector4 dRect(0, 0, dSize, 1);
DrawStretchRect(GSVector4::zero(), dRect, dTex->GetSize()); DrawStretchRect(GSVector4::zero(), dRect, dTex->GetSize());
EndScene();
} }
void GSDeviceOGL::DrawStretchRect(const GSVector4& sRect, const GSVector4& dRect, const GSVector2i& ds) void GSDeviceOGL::DrawStretchRect(const GSVector4& sRect, const GSVector4& dRect, const GSVector2i& ds)
@ -1458,8 +1440,6 @@ void GSDeviceOGL::SetupDATE(GSTexture* rt, GSTexture* ds, const GSVertexPT1* ver
// sfex3 (after the capcom logo), vf4 (first menu fading in), ffxii shadows, rumble roses shadows, persona4 shadows // sfex3 (after the capcom logo), vf4 (first menu fading in), ffxii shadows, rumble roses shadows, persona4 shadows
BeginScene();
ClearStencil(ds, 0); ClearStencil(ds, 0);
m_convert.ps[static_cast<int>(datm ? ShaderConvert::DATM_1 : ShaderConvert::DATM_0)].Bind(); m_convert.ps[static_cast<int>(datm ? ShaderConvert::DATM_1 : ShaderConvert::DATM_0)].Bind();
@ -1490,8 +1470,6 @@ void GSDeviceOGL::SetupDATE(GSTexture* rt, GSTexture* ds, const GSVertexPT1* ver
{ {
glEnable(GL_BLEND); glEnable(GL_BLEND);
} }
EndScene();
} }
void GSDeviceOGL::IASetVertexBuffer(const void* vertices, size_t count) void GSDeviceOGL::IASetVertexBuffer(const void* vertices, size_t count)
@ -1894,8 +1872,6 @@ void GSDeviceOGL::RenderHW(GSHWDrawConfig& config)
CopyRect(config.rt, draw_rt_clone, config.drawarea, config.drawarea.left, config.drawarea.top); CopyRect(config.rt, draw_rt_clone, config.drawarea, config.drawarea.left, config.drawarea.top);
} }
BeginScene();
IASetVertexBuffer(config.verts, config.nverts); IASetVertexBuffer(config.verts, config.nverts);
IASetIndexBuffer(config.indices, config.nindices); IASetIndexBuffer(config.indices, config.nindices);
GLenum topology = 0; GLenum topology = 0;
@ -2047,10 +2023,6 @@ void GSDeviceOGL::RenderHW(GSHWDrawConfig& config)
if (draw_rt_clone) if (draw_rt_clone)
Recycle(draw_rt_clone); Recycle(draw_rt_clone);
EndScene();
// Warning: EndScene must be called before StretchRect otherwise
// vertices will be overwritten. Trust me you don't want to do that.
if (hdr_rt) if (hdr_rt)
{ {
GSVector2i size = config.rt->GetSize(); GSVector2i size = config.rt->GetSize();

View File

@ -882,8 +882,6 @@ void GSDeviceVK::IASetVertexBuffer(const void* vertex, size_t stride, size_t cou
} }
m_vertex.start = m_vertex_stream_buffer.GetCurrentOffset() / stride; m_vertex.start = m_vertex_stream_buffer.GetCurrentOffset() / stride;
m_vertex.limit = count;
m_vertex.stride = stride;
m_vertex.count = count; m_vertex.count = count;
SetVertexBuffer(m_vertex_stream_buffer.GetBuffer(), 0); SetVertexBuffer(m_vertex_stream_buffer.GetBuffer(), 0);
@ -891,32 +889,6 @@ void GSDeviceVK::IASetVertexBuffer(const void* vertex, size_t stride, size_t cou
m_vertex_stream_buffer.CommitMemory(size); m_vertex_stream_buffer.CommitMemory(size);
} }
bool GSDeviceVK::IAMapVertexBuffer(void** vertex, size_t stride, size_t count)
{
const u32 size = static_cast<u32>(stride) * static_cast<u32>(count);
if (!m_vertex_stream_buffer.ReserveMemory(size, static_cast<u32>(stride)))
{
ExecuteCommandBufferAndRestartRenderPass(false, "Mapping bytes to vertex buffer");
if (!m_vertex_stream_buffer.ReserveMemory(size, static_cast<u32>(stride)))
pxFailRel("Failed to reserve space for vertices");
}
m_vertex.start = m_vertex_stream_buffer.GetCurrentOffset() / stride;
m_vertex.limit = m_vertex_stream_buffer.GetCurrentSpace() / stride;
m_vertex.stride = stride;
m_vertex.count = count;
SetVertexBuffer(m_vertex_stream_buffer.GetBuffer(), 0);
*vertex = m_vertex_stream_buffer.GetCurrentHostPointer();
return true;
}
void GSDeviceVK::IAUnmapVertexBuffer()
{
const u32 size = static_cast<u32>(m_vertex.stride) * static_cast<u32>(m_vertex.count);
m_vertex_stream_buffer.CommitMemory(size);
}
void GSDeviceVK::IASetIndexBuffer(const void* index, size_t count) void GSDeviceVK::IASetIndexBuffer(const void* index, size_t count)
{ {
const u32 size = sizeof(u32) * static_cast<u32>(count); const u32 size = sizeof(u32) * static_cast<u32>(count);
@ -928,7 +900,6 @@ void GSDeviceVK::IASetIndexBuffer(const void* index, size_t count)
} }
m_index.start = m_index_stream_buffer.GetCurrentOffset() / sizeof(u32); m_index.start = m_index_stream_buffer.GetCurrentOffset() / sizeof(u32);
m_index.limit = count;
m_index.count = count; m_index.count = count;
SetIndexBuffer(m_index_stream_buffer.GetBuffer(), 0, VK_INDEX_TYPE_UINT32); SetIndexBuffer(m_index_stream_buffer.GetBuffer(), 0, VK_INDEX_TYPE_UINT32);
@ -3177,8 +3148,6 @@ void GSDeviceVK::RenderHW(GSHWDrawConfig& config)
if (date_image) if (date_image)
Recycle(date_image); Recycle(date_image);
EndScene();
// now blit the hdr texture back to the original target // now blit the hdr texture back to the original target
if (hdr_rt) if (hdr_rt)
{ {

View File

@ -247,8 +247,6 @@ public:
GSTextureVK* SetupPrimitiveTrackingDATE(GSHWDrawConfig& config); GSTextureVK* SetupPrimitiveTrackingDATE(GSHWDrawConfig& config);
void IASetVertexBuffer(const void* vertex, size_t stride, size_t count); void IASetVertexBuffer(const void* vertex, size_t stride, size_t count);
bool IAMapVertexBuffer(void** vertex, size_t stride, size_t count);
void IAUnmapVertexBuffer();
void IASetIndexBuffer(const void* index, size_t count); void IASetIndexBuffer(const void* index, size_t count);
void PSSetShaderResource(int i, GSTexture* sr, bool check_state); void PSSetShaderResource(int i, GSTexture* sr, bool check_state);