2019-11-10 10:27:19 +00:00
|
|
|
/*
|
|
|
|
Created on: Nov 7, 2019
|
|
|
|
|
|
|
|
Copyright 2019 flyinghead
|
|
|
|
|
|
|
|
This file is part of Flycast.
|
|
|
|
|
|
|
|
Flycast is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Flycast is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Flycast. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#include "oit_drawer.h"
|
|
|
|
#include "hw/pvr/pvr_mem.h"
|
|
|
|
|
2020-03-28 16:58:01 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
2020-01-05 22:03:44 +00:00
|
|
|
void OITDrawer::DrawPoly(const vk::CommandBuffer& cmdBuffer, u32 listType, bool autosort, Pass pass,
|
2019-11-10 10:27:19 +00:00
|
|
|
const PolyParam& poly, u32 first, u32 count)
|
|
|
|
{
|
|
|
|
vk::Rect2D scissorRect;
|
|
|
|
TileClipping tileClip = SetTileClip(poly.tileclip, scissorRect);
|
2019-12-04 18:06:14 +00:00
|
|
|
if (tileClip == TileClipping::Outside)
|
|
|
|
SetScissor(cmdBuffer, scissorRect);
|
|
|
|
else
|
|
|
|
SetScissor(cmdBuffer, baseScissor);
|
2019-11-10 10:27:19 +00:00
|
|
|
|
|
|
|
float trilinearAlpha = 1.f;
|
2020-01-21 18:52:09 +00:00
|
|
|
if (poly.tsp.FilterMode > 1 && poly.pcw.Texture && listType != ListType_Punch_Through && poly.tcw.MipMapped == 1)
|
2019-11-10 10:27:19 +00:00
|
|
|
{
|
|
|
|
trilinearAlpha = 0.25 * (poly.tsp.MipMapD & 0x3);
|
|
|
|
if (poly.tsp.FilterMode == 2)
|
|
|
|
// Trilinear pass A
|
|
|
|
trilinearAlpha = 1.0 - trilinearAlpha;
|
|
|
|
}
|
|
|
|
|
2020-05-11 13:50:16 +00:00
|
|
|
bool twoVolumes = poly.tsp1.full != (u32)-1 || poly.tcw1.full != (u32)-1;
|
2019-11-10 10:27:19 +00:00
|
|
|
|
|
|
|
OITDescriptorSets::PushConstants pushConstants = {
|
2019-12-09 18:37:14 +00:00
|
|
|
{
|
|
|
|
(float)scissorRect.offset.x,
|
|
|
|
(float)scissorRect.offset.y,
|
|
|
|
(float)scissorRect.offset.x + (float)scissorRect.extent.width,
|
|
|
|
(float)scissorRect.offset.y + (float)scissorRect.extent.height
|
|
|
|
},
|
2020-02-06 10:39:05 +00:00
|
|
|
{ poly.tsp.SrcInstr, poly.tsp.DstInstr, 0, 0 },
|
2019-11-10 10:27:19 +00:00
|
|
|
trilinearAlpha,
|
2020-02-25 15:34:49 +00:00
|
|
|
listType == ListType_Translucent ? (int)(&poly - pvrrc.global_param_tr.head()) : 0,
|
2019-11-10 10:27:19 +00:00
|
|
|
};
|
|
|
|
if (twoVolumes)
|
|
|
|
{
|
2020-02-06 10:39:05 +00:00
|
|
|
pushConstants.blend_mode1 = { poly.tsp1.SrcInstr, poly.tsp1.DstInstr, 0, 0 };
|
2019-11-10 10:27:19 +00:00
|
|
|
pushConstants.shading_instr0 = poly.tsp.ShadInstr;
|
|
|
|
pushConstants.shading_instr1 = poly.tsp1.ShadInstr;
|
|
|
|
pushConstants.fog_control0 = poly.tsp.FogCtrl;
|
|
|
|
pushConstants.fog_control1 = poly.tsp1.FogCtrl;
|
|
|
|
pushConstants.use_alpha0 = poly.tsp.UseAlpha;
|
|
|
|
pushConstants.use_alpha1 = poly.tsp1.UseAlpha;
|
|
|
|
pushConstants.ignore_tex_alpha0 = poly.tsp.IgnoreTexA;
|
|
|
|
pushConstants.ignore_tex_alpha1 = poly.tsp1.IgnoreTexA;
|
|
|
|
}
|
|
|
|
cmdBuffer.pushConstants<OITDescriptorSets::PushConstants>(pipelineManager->GetPipelineLayout(), vk::ShaderStageFlagBits::eFragment, 0, pushConstants);
|
|
|
|
|
2019-11-12 18:39:58 +00:00
|
|
|
bool needTexture = poly.pcw.Texture;
|
|
|
|
if (needTexture)
|
2019-11-10 10:27:19 +00:00
|
|
|
GetCurrentDescSet().SetTexture(poly.texid, poly.tsp, poly.texid1, poly.tsp1);
|
|
|
|
|
|
|
|
vk::Pipeline pipeline = pipelineManager->GetPipeline(listType, autosort, poly, pass);
|
|
|
|
cmdBuffer.bindPipeline(vk::PipelineBindPoint::eGraphics, pipeline);
|
2019-11-12 18:39:58 +00:00
|
|
|
if (needTexture)
|
2019-11-10 10:27:19 +00:00
|
|
|
GetCurrentDescSet().BindPerPolyDescriptorSets(cmdBuffer, poly.texid, poly.tsp, poly.texid1, poly.tsp1);
|
|
|
|
|
|
|
|
cmdBuffer.drawIndexed(count, 1, first, 0, 0);
|
|
|
|
}
|
|
|
|
|
2020-01-05 22:03:44 +00:00
|
|
|
void OITDrawer::DrawList(const vk::CommandBuffer& cmdBuffer, u32 listType, bool sortTriangles, Pass pass,
|
2019-11-10 10:27:19 +00:00
|
|
|
const List<PolyParam>& polys, u32 first, u32 last)
|
|
|
|
{
|
2020-02-25 15:34:49 +00:00
|
|
|
const PolyParam *pp_end = polys.head() + last;
|
|
|
|
for (const PolyParam *pp = polys.head() + first; pp != pp_end; pp++)
|
|
|
|
if (pp->count > 2)
|
|
|
|
DrawPoly(cmdBuffer, listType, sortTriangles, pass, *pp, pp->first, pp->count);
|
2019-11-10 10:27:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template<bool Translucent>
|
|
|
|
void OITDrawer::DrawModifierVolumes(const vk::CommandBuffer& cmdBuffer, int first, int count)
|
|
|
|
{
|
2019-12-03 20:29:37 +00:00
|
|
|
if (count == 0 || pvrrc.modtrig.used() == 0 || !settings.rend.ModifierVolumes)
|
2019-11-10 10:27:19 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
vk::Buffer buffer = GetMainBuffer(0)->buffer.get();
|
|
|
|
cmdBuffer.bindVertexBuffers(0, 1, &buffer, &offsets.modVolOffset);
|
2019-12-04 18:06:14 +00:00
|
|
|
SetScissor(cmdBuffer, baseScissor);
|
2019-11-10 10:27:19 +00:00
|
|
|
|
|
|
|
ModifierVolumeParam* params = Translucent ? &pvrrc.global_param_mvo_tr.head()[first] : &pvrrc.global_param_mvo.head()[first];
|
|
|
|
|
|
|
|
int mod_base = -1;
|
|
|
|
vk::Pipeline pipeline;
|
|
|
|
|
2020-03-29 18:58:49 +00:00
|
|
|
for (int cmv = 0; cmv < count; cmv++)
|
2019-11-10 10:27:19 +00:00
|
|
|
{
|
|
|
|
ModifierVolumeParam& param = params[cmv];
|
|
|
|
|
|
|
|
if (param.count == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
u32 mv_mode = param.isp.DepthMode;
|
|
|
|
|
2020-05-11 13:50:16 +00:00
|
|
|
verify(param.first >= 0 && param.first + param.count <= (u32)pvrrc.modtrig.used());
|
2019-11-10 10:27:19 +00:00
|
|
|
|
|
|
|
if (mod_base == -1)
|
|
|
|
mod_base = param.first;
|
|
|
|
|
|
|
|
if (!param.isp.VolumeLast && mv_mode > 0)
|
|
|
|
{
|
|
|
|
// OR'ing (open volume or quad)
|
|
|
|
if (Translucent)
|
2019-12-05 17:48:54 +00:00
|
|
|
pipeline = pipelineManager->GetTrModifierVolumePipeline(ModVolMode::Or, param.isp.CullMode);
|
2019-11-10 10:27:19 +00:00
|
|
|
else
|
2019-12-05 17:48:54 +00:00
|
|
|
pipeline = pipelineManager->GetModifierVolumePipeline(ModVolMode::Or, param.isp.CullMode);
|
2019-11-10 10:27:19 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// XOR'ing (closed volume)
|
|
|
|
if (Translucent)
|
2019-12-05 17:48:54 +00:00
|
|
|
pipeline = pipelineManager->GetTrModifierVolumePipeline(ModVolMode::Xor, param.isp.CullMode);
|
2019-11-10 10:27:19 +00:00
|
|
|
else
|
2019-12-05 17:48:54 +00:00
|
|
|
pipeline = pipelineManager->GetModifierVolumePipeline(ModVolMode::Xor, param.isp.CullMode);
|
2019-11-10 10:27:19 +00:00
|
|
|
}
|
|
|
|
cmdBuffer.bindPipeline(vk::PipelineBindPoint::eGraphics, pipeline);
|
|
|
|
cmdBuffer.draw(param.count * 3, 1, param.first * 3, 0);
|
|
|
|
|
|
|
|
if (mv_mode == 1 || mv_mode == 2)
|
|
|
|
{
|
|
|
|
//Sum the area
|
|
|
|
if (Translucent)
|
2019-11-12 18:39:58 +00:00
|
|
|
{
|
|
|
|
vk::MemoryBarrier barrier(vk::AccessFlagBits::eShaderWrite, vk::AccessFlagBits::eShaderRead);
|
|
|
|
cmdBuffer.pipelineBarrier(vk::PipelineStageFlagBits::eFragmentShader, vk::PipelineStageFlagBits::eFragmentShader,
|
|
|
|
vk::DependencyFlagBits::eByRegion, barrier, nullptr, nullptr);
|
2019-12-05 17:48:54 +00:00
|
|
|
pipeline = pipelineManager->GetTrModifierVolumePipeline(mv_mode == 1 ? ModVolMode::Inclusion : ModVolMode::Exclusion, param.isp.CullMode);
|
2019-11-12 18:39:58 +00:00
|
|
|
}
|
2019-11-10 10:27:19 +00:00
|
|
|
else
|
2019-12-05 17:48:54 +00:00
|
|
|
pipeline = pipelineManager->GetModifierVolumePipeline(mv_mode == 1 ? ModVolMode::Inclusion : ModVolMode::Exclusion, param.isp.CullMode);
|
2019-11-10 10:27:19 +00:00
|
|
|
cmdBuffer.bindPipeline(vk::PipelineBindPoint::eGraphics, pipeline);
|
|
|
|
cmdBuffer.draw((param.first + param.count - mod_base) * 3, 1, mod_base * 3, 0);
|
|
|
|
|
|
|
|
mod_base = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const vk::DeviceSize offset = 0;
|
|
|
|
cmdBuffer.bindVertexBuffers(0, 1, &buffer, &offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OITDrawer::UploadMainBuffer(const OITDescriptorSets::VertexShaderUniforms& vertexUniforms,
|
|
|
|
const OITDescriptorSets::FragmentShaderUniforms& fragmentUniforms)
|
|
|
|
{
|
|
|
|
using VertexShaderUniforms = OITDescriptorSets::VertexShaderUniforms;
|
|
|
|
using FragmentShaderUniforms = OITDescriptorSets::FragmentShaderUniforms;
|
|
|
|
|
|
|
|
// TODO Put this logic in an allocator
|
|
|
|
std::vector<const void *> chunks;
|
|
|
|
std::vector<u32> chunkSizes;
|
|
|
|
|
|
|
|
// Vertex
|
|
|
|
chunks.push_back(pvrrc.verts.head());
|
|
|
|
chunkSizes.push_back(pvrrc.verts.bytes());
|
|
|
|
|
|
|
|
u32 padding = align(pvrrc.verts.bytes(), 4);
|
|
|
|
offsets.modVolOffset = pvrrc.verts.bytes() + padding;
|
|
|
|
chunks.push_back(nullptr);
|
|
|
|
chunkSizes.push_back(padding);
|
|
|
|
|
|
|
|
// Modifier Volumes
|
|
|
|
chunks.push_back(pvrrc.modtrig.head());
|
|
|
|
chunkSizes.push_back(pvrrc.modtrig.bytes());
|
|
|
|
padding = align(offsets.modVolOffset + pvrrc.modtrig.bytes(), 4);
|
|
|
|
offsets.indexOffset = offsets.modVolOffset + pvrrc.modtrig.bytes() + padding;
|
|
|
|
chunks.push_back(nullptr);
|
|
|
|
chunkSizes.push_back(padding);
|
|
|
|
|
|
|
|
// Index
|
|
|
|
chunks.push_back(pvrrc.idx.head());
|
|
|
|
chunkSizes.push_back(pvrrc.idx.bytes());
|
|
|
|
|
|
|
|
// Uniform buffers
|
|
|
|
u32 indexSize = pvrrc.idx.bytes();
|
|
|
|
padding = align(offsets.indexOffset + indexSize, std::max(4, (int)GetContext()->GetUniformBufferAlignment()));
|
|
|
|
offsets.vertexUniformOffset = offsets.indexOffset + indexSize + padding;
|
|
|
|
chunks.push_back(nullptr);
|
|
|
|
chunkSizes.push_back(padding);
|
|
|
|
|
|
|
|
chunks.push_back(&vertexUniforms);
|
|
|
|
chunkSizes.push_back(sizeof(vertexUniforms));
|
|
|
|
padding = align(offsets.vertexUniformOffset + sizeof(VertexShaderUniforms), std::max(4, (int)GetContext()->GetUniformBufferAlignment()));
|
|
|
|
offsets.fragmentUniformOffset = offsets.vertexUniformOffset + sizeof(VertexShaderUniforms) + padding;
|
|
|
|
chunks.push_back(nullptr);
|
|
|
|
chunkSizes.push_back(padding);
|
|
|
|
|
|
|
|
chunks.push_back(&fragmentUniforms);
|
|
|
|
chunkSizes.push_back(sizeof(fragmentUniforms));
|
|
|
|
|
|
|
|
// Translucent poly params
|
|
|
|
padding = align(offsets.fragmentUniformOffset + sizeof(FragmentShaderUniforms), std::max(4, (int)GetContext()->GetStorageBufferAlignment()));
|
|
|
|
offsets.polyParamsOffset = offsets.fragmentUniformOffset + sizeof(FragmentShaderUniforms) + padding;
|
|
|
|
chunks.push_back(nullptr);
|
|
|
|
chunkSizes.push_back(padding);
|
|
|
|
|
2019-12-05 17:48:54 +00:00
|
|
|
std::vector<u32> trPolyParams(pvrrc.global_param_tr.used() * 2);
|
2019-12-08 21:39:30 +00:00
|
|
|
if (pvrrc.global_param_tr.used() == 0)
|
|
|
|
trPolyParams.push_back(0); // makes the validation layers happy
|
|
|
|
else
|
2019-12-05 17:48:54 +00:00
|
|
|
{
|
2020-02-25 15:34:49 +00:00
|
|
|
const PolyParam *pp_end = pvrrc.global_param_tr.LastPtr(0);
|
|
|
|
const PolyParam *pp = pvrrc.global_param_tr.head();
|
|
|
|
for (int i = 0; pp != pp_end; i += 2, pp++)
|
2019-12-08 21:39:30 +00:00
|
|
|
{
|
2020-02-25 15:34:49 +00:00
|
|
|
trPolyParams[i] = (pp->tsp.full & 0xffff00c0) | ((pp->isp.full >> 16) & 0xe400) | ((pp->pcw.full >> 7) & 1);
|
|
|
|
trPolyParams[i + 1] = pp->tsp1.full;
|
2019-12-08 21:39:30 +00:00
|
|
|
}
|
2019-12-05 17:48:54 +00:00
|
|
|
}
|
2019-12-08 21:39:30 +00:00
|
|
|
offsets.polyParamsSize = trPolyParams.size() * 4;
|
2019-12-05 17:48:54 +00:00
|
|
|
chunks.push_back(trPolyParams.data());
|
2019-12-08 21:39:30 +00:00
|
|
|
chunkSizes.push_back(offsets.polyParamsSize);
|
|
|
|
u32 totalSize = offsets.polyParamsOffset + offsets.polyParamsSize;
|
2019-11-10 10:27:19 +00:00
|
|
|
|
|
|
|
BufferData *buffer = GetMainBuffer(totalSize);
|
|
|
|
buffer->upload(chunks.size(), &chunkSizes[0], &chunks[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OITDrawer::Draw(const Texture *fogTexture)
|
|
|
|
{
|
2019-11-12 18:39:58 +00:00
|
|
|
vk::CommandBuffer cmdBuffer = NewFrame();
|
2019-11-10 10:27:19 +00:00
|
|
|
|
2019-12-08 21:39:30 +00:00
|
|
|
if (needDepthTransition)
|
|
|
|
{
|
|
|
|
needDepthTransition = false;
|
|
|
|
// Not convinced that this is really needed but it makes validation layers happy
|
|
|
|
setImageLayout(cmdBuffer, depthAttachment->GetImage(), GetContext()->GetDepthFormat(), 1, vk::ImageLayout::eUndefined, vk::ImageLayout::eDepthStencilReadOnlyOptimal);
|
|
|
|
}
|
|
|
|
|
2019-11-10 10:27:19 +00:00
|
|
|
OITDescriptorSets::VertexShaderUniforms vtxUniforms;
|
|
|
|
vtxUniforms.normal_matrix = matrices.GetNormalMatrix();
|
|
|
|
|
2019-11-13 19:08:14 +00:00
|
|
|
OITDescriptorSets::FragmentShaderUniforms fragUniforms = MakeFragmentUniforms<OITDescriptorSets::FragmentShaderUniforms>();
|
2019-11-10 10:27:19 +00:00
|
|
|
fragUniforms.shade_scale_factor = FPU_SHAD_SCALE.scale_factor / 256.f;
|
|
|
|
|
|
|
|
currentScissor = vk::Rect2D();
|
|
|
|
|
2019-11-13 19:08:14 +00:00
|
|
|
oitBuffers->OnNewFrame(cmdBuffer);
|
2019-11-10 10:27:19 +00:00
|
|
|
|
2019-12-10 11:51:10 +00:00
|
|
|
SetProvokingVertices();
|
|
|
|
|
2019-11-10 10:27:19 +00:00
|
|
|
// Upload vertex and index buffers
|
|
|
|
UploadMainBuffer(vtxUniforms, fragUniforms);
|
|
|
|
|
|
|
|
quadBuffer->Update();
|
|
|
|
|
|
|
|
// Update per-frame descriptor set and bind it
|
2019-11-12 18:39:58 +00:00
|
|
|
const vk::Buffer mainBuffer = GetMainBuffer(0)->buffer.get();
|
|
|
|
GetCurrentDescSet().UpdateUniforms(mainBuffer, offsets.vertexUniformOffset, offsets.fragmentUniformOffset,
|
2019-11-13 19:08:14 +00:00
|
|
|
fogTexture->GetImageView(), offsets.polyParamsOffset,
|
2019-12-08 21:39:30 +00:00
|
|
|
offsets.polyParamsSize, depthAttachment->GetStencilView(),
|
2019-11-12 18:39:58 +00:00
|
|
|
depthAttachment->GetImageView());
|
2019-11-10 10:27:19 +00:00
|
|
|
GetCurrentDescSet().BindPerFrameDescriptorSets(cmdBuffer);
|
2019-11-12 18:39:58 +00:00
|
|
|
GetCurrentDescSet().UpdateColorInputDescSet(0, colorAttachments[0]->GetImageView());
|
|
|
|
GetCurrentDescSet().UpdateColorInputDescSet(1, colorAttachments[1]->GetImageView());
|
2019-11-13 19:08:14 +00:00
|
|
|
oitBuffers->BindDescriptorSet(cmdBuffer, pipelineManager->GetPipelineLayout(), 3);
|
2019-11-12 18:39:58 +00:00
|
|
|
|
2019-11-10 10:27:19 +00:00
|
|
|
// Reset per-poly descriptor set pool
|
|
|
|
GetCurrentDescSet().Reset();
|
|
|
|
|
2019-11-12 18:39:58 +00:00
|
|
|
// Bind vertex and index buffers
|
|
|
|
const vk::DeviceSize zeroOffset[] = { 0 };
|
|
|
|
cmdBuffer.bindVertexBuffers(0, 1, &mainBuffer, zeroOffset);
|
|
|
|
cmdBuffer.bindIndexBuffer(mainBuffer, offsets.indexOffset, vk::IndexType::eUint32);
|
|
|
|
|
2019-12-11 21:31:35 +00:00
|
|
|
// Make sure to push constants even if not used
|
|
|
|
OITDescriptorSets::PushConstants pushConstants = { };
|
|
|
|
cmdBuffer.pushConstants<OITDescriptorSets::PushConstants>(pipelineManager->GetPipelineLayout(), vk::ShaderStageFlagBits::eFragment, 0, pushConstants);
|
|
|
|
|
2019-11-12 18:39:58 +00:00
|
|
|
const std::array<vk::ClearValue, 3> clear_colors = {
|
|
|
|
vk::ClearColorValue(std::array<float, 4>{0.f, 0.f, 0.f, 1.f}),
|
|
|
|
vk::ClearColorValue(std::array<float, 4>{0.f, 0.f, 0.f, 1.f}),
|
|
|
|
vk::ClearDepthStencilValue{ 0.f, 0 },
|
|
|
|
};
|
|
|
|
|
2019-11-10 10:27:19 +00:00
|
|
|
RenderPass previous_pass = {};
|
|
|
|
for (int render_pass = 0; render_pass < pvrrc.render_passes.used(); render_pass++)
|
|
|
|
{
|
|
|
|
const RenderPass& current_pass = pvrrc.render_passes.head()[render_pass];
|
|
|
|
|
2019-12-05 17:48:54 +00:00
|
|
|
DEBUG_LOG(RENDERER, "Render pass %d OP %d PT %d TR %d MV %d TrMV %d autosort %d", render_pass + 1,
|
2019-11-10 10:27:19 +00:00
|
|
|
current_pass.op_count - previous_pass.op_count,
|
|
|
|
current_pass.pt_count - previous_pass.pt_count,
|
|
|
|
current_pass.tr_count - previous_pass.tr_count,
|
2019-12-05 17:48:54 +00:00
|
|
|
current_pass.mvo_count - previous_pass.mvo_count,
|
|
|
|
current_pass.mvo_tr_count - previous_pass.mvo_tr_count, current_pass.autosort);
|
2019-11-12 18:39:58 +00:00
|
|
|
|
|
|
|
// Reset the pixel counter
|
2019-11-13 19:08:14 +00:00
|
|
|
oitBuffers->ResetPixelCounter(cmdBuffer);
|
2019-11-12 18:39:58 +00:00
|
|
|
|
|
|
|
const bool initialPass = render_pass == 0;
|
|
|
|
const bool finalPass = render_pass == pvrrc.render_passes.used() - 1;
|
|
|
|
|
|
|
|
vk::Framebuffer targetFramebuffer;
|
|
|
|
if (!finalPass)
|
|
|
|
targetFramebuffer = *tempFramebuffers[(pvrrc.render_passes.used() - 1 - render_pass) % 2];
|
|
|
|
else
|
2019-12-04 14:51:26 +00:00
|
|
|
targetFramebuffer = GetFinalFramebuffer();
|
2019-11-12 18:39:58 +00:00
|
|
|
cmdBuffer.beginRenderPass(
|
|
|
|
vk::RenderPassBeginInfo(pipelineManager->GetRenderPass(initialPass, finalPass),
|
|
|
|
targetFramebuffer, viewport, clear_colors.size(), clear_colors.data()),
|
|
|
|
vk::SubpassContents::eInline);
|
2019-11-10 10:27:19 +00:00
|
|
|
|
|
|
|
// Depth + stencil subpass
|
2020-01-05 22:03:44 +00:00
|
|
|
DrawList(cmdBuffer, ListType_Opaque, false, Pass::Depth, pvrrc.global_param_op, previous_pass.op_count, current_pass.op_count);
|
|
|
|
DrawList(cmdBuffer, ListType_Punch_Through, false, Pass::Depth, pvrrc.global_param_pt, previous_pass.pt_count, current_pass.pt_count);
|
2019-11-10 10:27:19 +00:00
|
|
|
|
|
|
|
DrawModifierVolumes<false>(cmdBuffer, previous_pass.mvo_count, current_pass.mvo_count - previous_pass.mvo_count);
|
|
|
|
|
|
|
|
// Color subpass
|
|
|
|
cmdBuffer.nextSubpass(vk::SubpassContents::eInline);
|
|
|
|
|
|
|
|
// OP + PT
|
2020-01-05 22:03:44 +00:00
|
|
|
DrawList(cmdBuffer, ListType_Opaque, false, Pass::Color, pvrrc.global_param_op, previous_pass.op_count, current_pass.op_count);
|
|
|
|
DrawList(cmdBuffer, ListType_Punch_Through, false, Pass::Color, pvrrc.global_param_pt, previous_pass.pt_count, current_pass.pt_count);
|
2019-11-10 10:27:19 +00:00
|
|
|
|
|
|
|
// TR
|
2020-01-05 22:03:44 +00:00
|
|
|
if (current_pass.autosort)
|
|
|
|
{
|
|
|
|
if (!oitBuffers->isFirstFrameAfterInit())
|
|
|
|
DrawList(cmdBuffer, ListType_Translucent, true, Pass::OIT, pvrrc.global_param_tr, previous_pass.tr_count, current_pass.tr_count);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
DrawList(cmdBuffer, ListType_Translucent, false, Pass::Color, pvrrc.global_param_tr, previous_pass.tr_count, current_pass.tr_count);
|
2019-11-10 10:27:19 +00:00
|
|
|
|
|
|
|
// Final subpass
|
|
|
|
cmdBuffer.nextSubpass(vk::SubpassContents::eInline);
|
2019-11-12 18:39:58 +00:00
|
|
|
GetCurrentDescSet().BindColorInputDescSet(cmdBuffer, (pvrrc.render_passes.used() - 1 - render_pass) % 2);
|
2019-12-04 18:06:14 +00:00
|
|
|
SetScissor(cmdBuffer, baseScissor);
|
2019-11-10 10:27:19 +00:00
|
|
|
|
2019-11-15 10:24:00 +00:00
|
|
|
if (!oitBuffers->isFirstFrameAfterInit())
|
|
|
|
{
|
|
|
|
// Tr modifier volumes
|
2019-12-25 12:09:54 +00:00
|
|
|
if (GetContext()->GetVendorID() != VENDOR_QUALCOMM) // Adreno bug
|
2019-12-22 16:48:24 +00:00
|
|
|
DrawModifierVolumes<true>(cmdBuffer, previous_pass.mvo_tr_count, current_pass.mvo_tr_count - previous_pass.mvo_tr_count);
|
2019-11-10 10:27:19 +00:00
|
|
|
|
2020-01-05 22:03:44 +00:00
|
|
|
vk::Pipeline pipeline = pipelineManager->GetFinalPipeline();
|
2019-11-15 10:24:00 +00:00
|
|
|
cmdBuffer.bindPipeline(vk::PipelineBindPoint::eGraphics, pipeline);
|
|
|
|
quadBuffer->Bind(cmdBuffer);
|
|
|
|
quadBuffer->Draw(cmdBuffer);
|
|
|
|
}
|
2019-11-10 10:27:19 +00:00
|
|
|
|
|
|
|
// Clear
|
|
|
|
vk::MemoryBarrier memoryBarrier(vk::AccessFlagBits::eShaderRead, vk::AccessFlagBits::eShaderWrite);
|
|
|
|
cmdBuffer.pipelineBarrier(vk::PipelineStageFlagBits::eFragmentShader, vk::PipelineStageFlagBits::eFragmentShader,
|
|
|
|
vk::DependencyFlagBits::eByRegion, 1, &memoryBarrier, 0, nullptr, 0, nullptr);
|
2019-11-15 10:24:00 +00:00
|
|
|
vk::Pipeline pipeline = pipelineManager->GetClearPipeline();
|
2019-11-10 10:27:19 +00:00
|
|
|
cmdBuffer.bindPipeline(vk::PipelineBindPoint::eGraphics, pipeline);
|
|
|
|
quadBuffer->Draw(cmdBuffer);
|
|
|
|
|
2019-11-12 18:39:58 +00:00
|
|
|
if (!finalPass)
|
|
|
|
{
|
|
|
|
// Re-bind vertex and index buffers
|
|
|
|
cmdBuffer.bindVertexBuffers(0, 1, &mainBuffer, zeroOffset);
|
|
|
|
cmdBuffer.bindIndexBuffer(mainBuffer, offsets.indexOffset, vk::IndexType::eUint32);
|
|
|
|
|
|
|
|
// Tr depth-only pass
|
2020-01-05 22:03:44 +00:00
|
|
|
DrawList(cmdBuffer, ListType_Translucent, current_pass.autosort, Pass::Depth, pvrrc.global_param_tr, previous_pass.tr_count, current_pass.tr_count);
|
2019-11-12 18:39:58 +00:00
|
|
|
|
|
|
|
cmdBuffer.endRenderPass();
|
|
|
|
}
|
|
|
|
|
2019-11-10 10:27:19 +00:00
|
|
|
previous_pass = current_pass;
|
|
|
|
}
|
|
|
|
|
|
|
|
return !pvrrc.isRTT;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OITDrawer::MakeBuffers(int width, int height)
|
|
|
|
{
|
2019-11-13 19:08:14 +00:00
|
|
|
oitBuffers->Init(width, height);
|
|
|
|
|
2019-11-12 18:39:58 +00:00
|
|
|
if (width <= maxWidth && height <= maxHeight)
|
|
|
|
return;
|
|
|
|
maxWidth = std::max(maxWidth, width);
|
|
|
|
maxHeight = std::max(maxHeight, height);
|
|
|
|
|
2019-12-09 18:37:14 +00:00
|
|
|
GetContext()->WaitIdle();
|
2019-11-12 18:39:58 +00:00
|
|
|
for (auto& attachment : colorAttachments)
|
|
|
|
{
|
|
|
|
attachment.reset();
|
|
|
|
attachment = std::unique_ptr<FramebufferAttachment>(
|
2019-11-26 09:42:44 +00:00
|
|
|
new FramebufferAttachment(GetContext()->GetPhysicalDevice(), GetContext()->GetDevice()));
|
2019-11-29 18:28:22 +00:00
|
|
|
attachment->Init(maxWidth, maxHeight, GetColorFormat(),
|
|
|
|
vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eInputAttachment);
|
2019-11-12 18:39:58 +00:00
|
|
|
}
|
2019-11-10 10:27:19 +00:00
|
|
|
|
2019-11-12 18:39:58 +00:00
|
|
|
depthAttachment.reset();
|
|
|
|
depthAttachment = std::unique_ptr<FramebufferAttachment>(
|
2019-11-26 09:42:44 +00:00
|
|
|
new FramebufferAttachment(GetContext()->GetPhysicalDevice(), GetContext()->GetDevice()));
|
2019-11-29 18:28:22 +00:00
|
|
|
depthAttachment->Init(maxWidth, maxHeight, GetContext()->GetDepthFormat(),
|
|
|
|
vk::ImageUsageFlagBits::eDepthStencilAttachment | vk::ImageUsageFlagBits::eInputAttachment);
|
2019-12-08 21:39:30 +00:00
|
|
|
needDepthTransition = true;
|
2019-11-10 10:27:19 +00:00
|
|
|
|
2019-11-12 18:39:58 +00:00
|
|
|
vk::ImageView attachments[] = {
|
|
|
|
colorAttachments[1]->GetImageView(),
|
|
|
|
colorAttachments[0]->GetImageView(),
|
|
|
|
depthAttachment->GetImageView(),
|
|
|
|
};
|
|
|
|
vk::FramebufferCreateInfo createInfo(vk::FramebufferCreateFlags(), pipelineManager->GetRenderPass(true, true),
|
|
|
|
ARRAY_SIZE(attachments), attachments, width, height, 1);
|
|
|
|
tempFramebuffers[0] = GetContext()->GetDevice().createFramebufferUnique(createInfo);
|
|
|
|
attachments[0] = attachments[1];
|
|
|
|
attachments[1] = colorAttachments[1]->GetImageView();
|
|
|
|
tempFramebuffers[1] = GetContext()->GetDevice().createFramebufferUnique(createInfo);
|
2019-11-10 10:27:19 +00:00
|
|
|
}
|
|
|
|
|
2019-11-29 18:28:22 +00:00
|
|
|
void OITScreenDrawer::MakeFramebuffers()
|
2019-11-10 10:27:19 +00:00
|
|
|
{
|
2019-11-29 18:28:22 +00:00
|
|
|
if (currentScreenScaling == settings.rend.ScreenScaling)
|
|
|
|
return;
|
|
|
|
currentScreenScaling = settings.rend.ScreenScaling;
|
|
|
|
viewport.offset.x = 0;
|
|
|
|
viewport.offset.y = 0;
|
|
|
|
viewport.extent = GetContext()->GetViewPort();
|
|
|
|
viewport.extent.width = lroundf(viewport.extent.width * currentScreenScaling / 100.f);
|
|
|
|
viewport.extent.height = lroundf(viewport.extent.height * currentScreenScaling / 100.f);
|
|
|
|
|
|
|
|
MakeBuffers(viewport.extent.width, viewport.extent.height);
|
2019-12-04 14:51:26 +00:00
|
|
|
framebuffers.clear();
|
|
|
|
finalColorAttachments.clear();
|
|
|
|
while (finalColorAttachments.size() < GetContext()->GetSwapChainSize())
|
|
|
|
{
|
|
|
|
finalColorAttachments.push_back(std::unique_ptr<FramebufferAttachment>(
|
|
|
|
new FramebufferAttachment(GetContext()->GetPhysicalDevice(), GetContext()->GetDevice())));
|
|
|
|
finalColorAttachments.back()->Init(viewport.extent.width, viewport.extent.height, GetContext()->GetColorFormat(),
|
|
|
|
vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eSampled);
|
|
|
|
vk::ImageView attachments[] = {
|
|
|
|
finalColorAttachments.back()->GetImageView(),
|
|
|
|
colorAttachments[0]->GetImageView(),
|
|
|
|
depthAttachment->GetImageView(),
|
|
|
|
};
|
2019-12-09 18:37:14 +00:00
|
|
|
vk::FramebufferCreateInfo createInfo(vk::FramebufferCreateFlags(), screenPipelineManager->GetRenderPass(true, true),
|
2019-12-04 14:51:26 +00:00
|
|
|
ARRAY_SIZE(attachments), attachments, viewport.extent.width, viewport.extent.height, 1);
|
|
|
|
framebuffers.push_back(GetContext()->GetDevice().createFramebufferUnique(createInfo));
|
|
|
|
}
|
2019-11-10 10:27:19 +00:00
|
|
|
}
|
|
|
|
|
2019-11-12 18:39:58 +00:00
|
|
|
vk::CommandBuffer OITTextureDrawer::NewFrame()
|
2019-11-10 10:27:19 +00:00
|
|
|
{
|
|
|
|
DEBUG_LOG(RENDERER, "RenderToTexture packmode=%d stride=%d - %d,%d -> %d,%d", FB_W_CTRL.fb_packmode, FB_W_LINESTRIDE.stride * 8,
|
|
|
|
FB_X_CLIP.min, FB_Y_CLIP.min, FB_X_CLIP.max, FB_Y_CLIP.max);
|
2019-12-09 18:37:14 +00:00
|
|
|
NewImage();
|
2019-11-12 18:39:58 +00:00
|
|
|
|
2019-11-10 10:27:19 +00:00
|
|
|
matrices.CalcMatrices(&pvrrc);
|
|
|
|
|
|
|
|
textureAddr = FB_W_SOF1 & VRAM_MASK;
|
|
|
|
u32 origWidth = pvrrc.fb_X_CLIP.max - pvrrc.fb_X_CLIP.min + 1;
|
|
|
|
u32 origHeight = pvrrc.fb_Y_CLIP.max - pvrrc.fb_Y_CLIP.min + 1;
|
|
|
|
u32 upscaledWidth = origWidth;
|
|
|
|
u32 upscaledHeight = origHeight;
|
2020-05-11 13:50:16 +00:00
|
|
|
u32 heightPow2 = 8;
|
2019-11-10 10:27:19 +00:00
|
|
|
while (heightPow2 < upscaledHeight)
|
|
|
|
heightPow2 *= 2;
|
2020-05-11 13:50:16 +00:00
|
|
|
u32 widthPow2 = 8;
|
2019-11-10 10:27:19 +00:00
|
|
|
while (widthPow2 < upscaledWidth)
|
|
|
|
widthPow2 *= 2;
|
|
|
|
|
|
|
|
if (settings.rend.RenderToTextureUpscale > 1 && !settings.rend.RenderToTextureBuffer)
|
|
|
|
{
|
|
|
|
upscaledWidth *= settings.rend.RenderToTextureUpscale;
|
|
|
|
upscaledHeight *= settings.rend.RenderToTextureUpscale;
|
|
|
|
widthPow2 *= settings.rend.RenderToTextureUpscale;
|
|
|
|
heightPow2 *= settings.rend.RenderToTextureUpscale;
|
|
|
|
}
|
|
|
|
|
2019-12-09 18:37:14 +00:00
|
|
|
rttPipelineManager->CheckSettingsChange();
|
2019-11-10 10:27:19 +00:00
|
|
|
VulkanContext *context = GetContext();
|
|
|
|
vk::Device device = context->GetDevice();
|
|
|
|
|
|
|
|
vk::CommandBuffer commandBuffer = commandPool->Allocate();
|
|
|
|
commandBuffer.begin(vk::CommandBufferBeginInfo(vk::CommandBufferUsageFlagBits::eOneTimeSubmit));
|
|
|
|
|
2019-11-12 18:39:58 +00:00
|
|
|
MakeBuffers(widthPow2, heightPow2);
|
|
|
|
|
2019-11-10 10:27:19 +00:00
|
|
|
vk::ImageView colorImageView;
|
|
|
|
vk::ImageLayout colorImageCurrentLayout;
|
|
|
|
|
|
|
|
if (!settings.rend.RenderToTextureBuffer)
|
|
|
|
{
|
|
|
|
// TexAddr : fb_rtt.TexAddr, Reserved : 0, StrideSel : 0, ScanOrder : 1
|
|
|
|
TCW tcw = { { textureAddr >> 3, 0, 0, 1 } };
|
|
|
|
switch (FB_W_CTRL.fb_packmode) {
|
|
|
|
case 0:
|
|
|
|
case 3:
|
|
|
|
tcw.PixelFmt = Pixel1555;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
tcw.PixelFmt = Pixel565;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
tcw.PixelFmt = Pixel4444;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-03-29 18:58:49 +00:00
|
|
|
TSP tsp = {};
|
2020-05-11 13:50:16 +00:00
|
|
|
for (tsp.TexU = 0; tsp.TexU <= 7 && (8u << tsp.TexU) < origWidth; tsp.TexU++);
|
|
|
|
for (tsp.TexV = 0; tsp.TexV <= 7 && (8u << tsp.TexV) < origHeight; tsp.TexV++);
|
2019-11-10 10:27:19 +00:00
|
|
|
|
|
|
|
texture = textureCache->getTextureCacheData(tsp, tcw);
|
|
|
|
if (texture->IsNew())
|
|
|
|
{
|
|
|
|
texture->Create();
|
|
|
|
texture->SetPhysicalDevice(GetContext()->GetPhysicalDevice());
|
|
|
|
texture->SetDevice(device);
|
|
|
|
}
|
2019-12-09 18:37:14 +00:00
|
|
|
else if (textureCache->IsInFlight(texture))
|
|
|
|
{
|
|
|
|
texture->readOnlyImageView = *texture->imageView;
|
|
|
|
textureCache->DestroyLater(texture);
|
|
|
|
}
|
2019-12-08 21:39:30 +00:00
|
|
|
if (texture->format != vk::Format::eR8G8B8A8Unorm || texture->extent.width != widthPow2 || texture->extent.height != heightPow2)
|
2019-11-10 10:27:19 +00:00
|
|
|
{
|
|
|
|
texture->extent = vk::Extent2D(widthPow2, heightPow2);
|
|
|
|
texture->format = vk::Format::eR8G8B8A8Unorm;
|
|
|
|
texture->CreateImage(vk::ImageTiling::eOptimal, vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eSampled,
|
|
|
|
vk::ImageLayout::eUndefined, vk::MemoryPropertyFlags(), vk::ImageAspectFlagBits::eColor);
|
|
|
|
colorImageCurrentLayout = vk::ImageLayout::eUndefined;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
colorImageCurrentLayout = vk::ImageLayout::eShaderReadOnlyOptimal;
|
|
|
|
}
|
|
|
|
colorImage = *texture->image;
|
|
|
|
colorImageView = texture->GetImageView();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-12-09 18:37:14 +00:00
|
|
|
if (!colorAttachment || widthPow2 > colorAttachment->getExtent().width || heightPow2 > colorAttachment->getExtent().height)
|
2019-11-10 10:27:19 +00:00
|
|
|
{
|
|
|
|
if (!colorAttachment)
|
2019-12-03 20:29:37 +00:00
|
|
|
colorAttachment = std::unique_ptr<FramebufferAttachment>(new FramebufferAttachment(context->GetPhysicalDevice(), device));
|
2019-12-09 18:37:14 +00:00
|
|
|
else
|
|
|
|
GetContext()->WaitIdle();
|
2019-11-29 18:28:22 +00:00
|
|
|
colorAttachment->Init(widthPow2, heightPow2, vk::Format::eR8G8B8A8Unorm,
|
|
|
|
vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc);
|
2019-12-09 18:37:14 +00:00
|
|
|
colorImageCurrentLayout = vk::ImageLayout::eUndefined;
|
2019-11-10 10:27:19 +00:00
|
|
|
}
|
2019-12-09 18:37:14 +00:00
|
|
|
else
|
|
|
|
colorImageCurrentLayout = vk::ImageLayout::eTransferSrcOptimal;
|
2019-11-10 10:27:19 +00:00
|
|
|
colorImage = colorAttachment->GetImage();
|
|
|
|
colorImageView = colorAttachment->GetImageView();
|
|
|
|
}
|
2019-11-12 18:39:58 +00:00
|
|
|
viewport.offset.x = 0;
|
|
|
|
viewport.offset.y = 0;
|
|
|
|
viewport.extent.width = widthPow2;
|
|
|
|
viewport.extent.height = heightPow2;
|
2019-11-10 10:27:19 +00:00
|
|
|
|
2019-12-09 18:37:14 +00:00
|
|
|
setImageLayout(commandBuffer, colorImage, vk::Format::eR8G8B8A8Unorm, 1, colorImageCurrentLayout, vk::ImageLayout::eColorAttachmentOptimal);
|
|
|
|
|
2019-11-10 10:27:19 +00:00
|
|
|
vk::ImageView imageViews[] = {
|
|
|
|
colorImageView,
|
2019-11-12 18:39:58 +00:00
|
|
|
colorAttachments[0]->GetImageView(),
|
2019-11-10 10:27:19 +00:00
|
|
|
depthAttachment->GetImageView(),
|
|
|
|
};
|
2019-12-09 18:37:14 +00:00
|
|
|
framebuffers.resize(GetContext()->GetSwapChainSize());
|
|
|
|
framebuffers[GetCurrentImage()] = device.createFramebufferUnique(vk::FramebufferCreateInfo(vk::FramebufferCreateFlags(),
|
|
|
|
rttPipelineManager->GetRenderPass(true, true), ARRAY_SIZE(imageViews), imageViews, widthPow2, heightPow2, 1));
|
2019-11-10 10:27:19 +00:00
|
|
|
|
|
|
|
commandBuffer.setViewport(0, vk::Viewport(0.0f, 0.0f, (float)upscaledWidth, (float)upscaledHeight, 1.0f, 0.0f));
|
|
|
|
baseScissor = vk::Rect2D(vk::Offset2D(0, 0), vk::Extent2D(upscaledWidth, upscaledHeight));
|
|
|
|
commandBuffer.setScissor(0, baseScissor);
|
|
|
|
currentCommandBuffer = commandBuffer;
|
|
|
|
|
|
|
|
return commandBuffer;
|
|
|
|
}
|
|
|
|
|
2019-11-12 18:39:58 +00:00
|
|
|
void OITTextureDrawer::EndFrame()
|
2019-11-10 10:27:19 +00:00
|
|
|
{
|
|
|
|
currentCommandBuffer.endRenderPass();
|
|
|
|
|
2019-12-10 11:51:10 +00:00
|
|
|
u32 clippedWidth = pvrrc.fb_X_CLIP.max - pvrrc.fb_X_CLIP.min + 1;
|
|
|
|
u32 clippedHeight = pvrrc.fb_Y_CLIP.max - pvrrc.fb_Y_CLIP.min + 1;
|
|
|
|
|
|
|
|
u32 stride = FB_W_LINESTRIDE.stride * 8;
|
|
|
|
if (clippedWidth * 2 > stride)
|
|
|
|
// Happens for Virtua Tennis
|
|
|
|
clippedWidth = stride / 2;
|
|
|
|
|
2019-11-10 10:27:19 +00:00
|
|
|
if (settings.rend.RenderToTextureBuffer)
|
|
|
|
{
|
2019-12-10 11:51:10 +00:00
|
|
|
vk::BufferImageCopy copyRegion(0, clippedWidth, clippedHeight,
|
2019-11-12 18:39:58 +00:00
|
|
|
vk::ImageSubresourceLayers(vk::ImageAspectFlagBits::eColor, 0, 0, 1), vk::Offset3D(0, 0, 0),
|
2019-12-10 11:51:10 +00:00
|
|
|
vk::Extent3D(clippedWidth, clippedHeight, 1));
|
2019-11-10 10:27:19 +00:00
|
|
|
currentCommandBuffer.copyImageToBuffer(colorAttachment->GetImage(), vk::ImageLayout::eTransferSrcOptimal,
|
|
|
|
*colorAttachment->GetBufferData()->buffer, copyRegion);
|
|
|
|
|
|
|
|
vk::BufferMemoryBarrier bufferMemoryBarrier(
|
|
|
|
vk::AccessFlagBits::eTransferWrite,
|
|
|
|
vk::AccessFlagBits::eHostRead,
|
|
|
|
VK_QUEUE_FAMILY_IGNORED,
|
|
|
|
VK_QUEUE_FAMILY_IGNORED,
|
|
|
|
*colorAttachment->GetBufferData()->buffer,
|
|
|
|
0,
|
|
|
|
VK_WHOLE_SIZE);
|
|
|
|
currentCommandBuffer.pipelineBarrier(vk::PipelineStageFlagBits::eTransfer,
|
|
|
|
vk::PipelineStageFlagBits::eHost, {}, nullptr, bufferMemoryBarrier, nullptr);
|
|
|
|
}
|
|
|
|
currentCommandBuffer.end();
|
|
|
|
|
|
|
|
colorImage = nullptr;
|
|
|
|
currentCommandBuffer = nullptr;
|
|
|
|
commandPool->EndFrame();
|
|
|
|
|
|
|
|
if (settings.rend.RenderToTextureBuffer)
|
|
|
|
{
|
2019-11-29 18:28:22 +00:00
|
|
|
vk::Fence fence = commandPool->GetCurrentFence();
|
|
|
|
GetContext()->GetDevice().waitForFences(1, &fence, true, UINT64_MAX);
|
2019-11-10 10:27:19 +00:00
|
|
|
|
|
|
|
u16 *dst = (u16 *)&vram[textureAddr];
|
|
|
|
|
|
|
|
PixelBuffer<u32> tmpBuf;
|
2019-12-10 11:51:10 +00:00
|
|
|
tmpBuf.init(clippedWidth, clippedHeight);
|
|
|
|
colorAttachment->GetBufferData()->download(clippedWidth * clippedHeight * 4, tmpBuf.data());
|
|
|
|
WriteTextureToVRam(clippedWidth, clippedHeight, (u8 *)tmpBuf.data(), dst);
|
2019-11-10 10:27:19 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
//memset(&vram[fb_rtt.TexAddr << 3], '\0', size);
|
|
|
|
|
|
|
|
texture->dirty = 0;
|
|
|
|
if (texture->lock_block == NULL)
|
|
|
|
texture->lock_block = libCore_vramlock_Lock(texture->sa_tex, texture->sa + texture->size - 1, texture);
|
|
|
|
}
|
|
|
|
|
2019-11-12 18:39:58 +00:00
|
|
|
vk::CommandBuffer OITScreenDrawer::NewFrame()
|
2019-11-10 10:27:19 +00:00
|
|
|
{
|
2019-11-29 18:28:22 +00:00
|
|
|
MakeFramebuffers();
|
2019-12-09 18:37:14 +00:00
|
|
|
NewImage();
|
2019-11-29 18:28:22 +00:00
|
|
|
vk::CommandBuffer commandBuffer = commandPool->Allocate();
|
|
|
|
commandBuffer.begin(vk::CommandBufferBeginInfo(vk::CommandBufferUsageFlagBits::eOneTimeSubmit));
|
2019-11-10 10:27:19 +00:00
|
|
|
|
|
|
|
matrices.CalcMatrices(&pvrrc);
|
|
|
|
|
2019-11-13 19:08:14 +00:00
|
|
|
SetBaseScissor();
|
2019-11-10 10:27:19 +00:00
|
|
|
|
|
|
|
commandBuffer.setScissor(0, baseScissor);
|
2019-11-12 18:39:58 +00:00
|
|
|
commandBuffer.setViewport(0, vk::Viewport(viewport.offset.x, viewport.offset.y, viewport.extent.width, viewport.extent.height, 1.0f, 0.0f));
|
2019-11-29 18:28:22 +00:00
|
|
|
currentCommandBuffer = commandBuffer;
|
2019-11-12 18:39:58 +00:00
|
|
|
|
2019-11-10 10:27:19 +00:00
|
|
|
return commandBuffer;
|
|
|
|
}
|