vulkan: fix uniforms alignment. Use push constants for per-poly params
Fix clipping, trilinear alpha Imgui FPS counter
This commit is contained in:
parent
929976c147
commit
5b35b52fda
|
@ -34,11 +34,16 @@ static inline void ImGui_impl_RenderDrawData(ImDrawData *draw_data, bool save_ba
|
|||
if (!settings.pvr.IsOpenGL())
|
||||
{
|
||||
VulkanContext *context = VulkanContext::Instance();
|
||||
context->NewFrame();
|
||||
context->BeginRenderPass();
|
||||
bool rendering = context->IsRendering();
|
||||
if (!rendering)
|
||||
{
|
||||
context->NewFrame();
|
||||
context->BeginRenderPass();
|
||||
}
|
||||
// Record Imgui Draw Data and draw funcs into command buffer
|
||||
ImGui_ImplVulkan_RenderDrawData(draw_data, context->GetCurrentCommandBuffer());
|
||||
context->EndFrame();
|
||||
if (!rendering)
|
||||
context->EndFrame();
|
||||
}
|
||||
else
|
||||
#endif
|
||||
|
|
|
@ -190,14 +190,25 @@ void PipelineManager::CreatePipeline(u32 listType, bool sortTriangles, const Pol
|
|||
params.alphaTest = listType == ListType_Punch_Through;
|
||||
params.bumpmap = pp.tcw.PixelFmt == PixelBumpMap;
|
||||
params.clamping = pp.tsp.ColorClamp && (pvrrc.fog_clamp_min != 0 || pvrrc.fog_clamp_max != 0xffffffff);;
|
||||
params.clipTest = pp.pcw.User_Clip - 1; // TODO pass clip values as Push Constant
|
||||
switch (pp.tileclip >> 28)
|
||||
{
|
||||
case 2:
|
||||
params.clipTest = 1; // render stuff inside the region
|
||||
break;
|
||||
case 3:
|
||||
params.clipTest = -1; // render stuff outside the region
|
||||
break;
|
||||
default:
|
||||
params.clipTest = 0; // always passes
|
||||
break;
|
||||
}
|
||||
params.fog = 2; // TODO fog texture -> pp.tsp.FogCtrl;
|
||||
params.gouraud = pp.pcw.Gouraud;
|
||||
params.ignoreTexAlpha = pp.tsp.IgnoreTexA;
|
||||
params.offset = pp.pcw.Offset;
|
||||
params.shaderInstr = pp.tsp.ShadInstr;
|
||||
params.texture = pp.pcw.Texture;
|
||||
params.trilinear = false; // TODO
|
||||
params.trilinear = pp.pcw.Texture && pp.tsp.FilterMode > 1 && listType != ListType_Punch_Through;
|
||||
params.useAlpha = pp.tsp.UseAlpha;
|
||||
vk::ShaderModule fragment_module = shaderManager.GetFragmentShader(params);
|
||||
|
||||
|
|
|
@ -35,18 +35,19 @@ public:
|
|||
vk::DescriptorSetLayoutBinding perFrameBindings[] = {
|
||||
{ 0, vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex }, // vertex uniforms
|
||||
{ 1, vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eFragment }, // fragment uniforms
|
||||
{ 2, vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment },// fog texture
|
||||
};
|
||||
vk::DescriptorSetLayoutBinding perPolyBindings[] = {
|
||||
{ 0, vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment },// texture
|
||||
{ 1, vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment },// for fog
|
||||
};
|
||||
perFrameLayout = GetContext()->GetDevice()->createDescriptorSetLayoutUnique(
|
||||
vk::DescriptorSetLayoutCreateInfo(vk::DescriptorSetLayoutCreateFlags(), ARRAY_SIZE(perFrameBindings), perFrameBindings));
|
||||
perPolyLayout = GetContext()->GetDevice()->createDescriptorSetLayoutUnique(
|
||||
vk::DescriptorSetLayoutCreateInfo(vk::DescriptorSetLayoutCreateFlags(), ARRAY_SIZE(perPolyBindings), perPolyBindings));
|
||||
vk::DescriptorSetLayout layouts[] = { *perFrameLayout, *perPolyLayout };
|
||||
vk::PushConstantRange pushConstant(vk::ShaderStageFlagBits::eFragment, 0, 20);
|
||||
pipelineLayout = GetContext()->GetDevice()->createPipelineLayoutUnique(
|
||||
vk::PipelineLayoutCreateInfo(vk::PipelineLayoutCreateFlags(), ARRAY_SIZE(layouts), layouts));
|
||||
vk::PipelineLayoutCreateInfo(vk::PipelineLayoutCreateFlags(), ARRAY_SIZE(layouts), layouts, 1, &pushConstant));
|
||||
}
|
||||
|
||||
void UpdateUniforms(const vk::Buffer& vertexUniformBuffer, const vk::Buffer& fragmentUniformBuffer)
|
||||
|
@ -170,7 +171,7 @@ private:
|
|||
u32 hash(u32 listType, bool sortTriangles, const PolyParam *pp)
|
||||
{
|
||||
u32 hash = pp->pcw.Gouraud | (pp->pcw.Offset << 1) | (pp->pcw.Texture << 2) | (pp->pcw.Shadow << 3)
|
||||
| (pp->pcw.User_Clip << 4);
|
||||
| ((pp->tileclip >> 28) << 4);
|
||||
hash |= ((listType >> 1) << 6);
|
||||
hash |= (pp->tsp.ShadInstr << 8) | (pp->tsp.IgnoreTexA << 10) | (pp->tsp.UseAlpha << 11)
|
||||
| (pp->tsp.ColorClamp << 12) | (pp->tsp.FogCtrl << 13) | (pp->tsp.SrcInstr << 15)
|
||||
|
|
|
@ -89,7 +89,7 @@ static const char FragmentShaderSource[] = R"(
|
|||
#define pp_FogCtrl %d
|
||||
#define pp_Gouraud %d
|
||||
#define pp_BumpMap %d
|
||||
#define FogClamping %d
|
||||
#define ColorClamping %d
|
||||
#define pp_TriLinear %d
|
||||
#define PI 3.1415926
|
||||
|
||||
|
@ -105,17 +105,22 @@ layout (location = 0) out vec4 FragColor;
|
|||
|
||||
layout (std140, set = 0, binding = 1) uniform buffer
|
||||
{
|
||||
lowp float cp_AlphaTestValue;
|
||||
lowp vec4 pp_ClipTest;
|
||||
lowp vec3 sp_FOG_COL_RAM,sp_FOG_COL_VERT;
|
||||
vec4 colorClampMin;
|
||||
vec4 colorClampMax;
|
||||
float cp_AlphaTestValue;
|
||||
vec3 sp_FOG_COL_RAM;
|
||||
vec3 sp_FOG_COL_VERT;
|
||||
float sp_FOG_DENSITY;
|
||||
lowp float trilinear_alpha;
|
||||
lowp vec4 fog_clamp_min;
|
||||
lowp vec4 fog_clamp_max;
|
||||
float extra_depth_scale;
|
||||
} uniformBuffer;
|
||||
|
||||
#if pp_Texture==1
|
||||
layout (push_constant) uniform pushBlock
|
||||
{
|
||||
vec4 clipTest;
|
||||
float trilinearAlpha;
|
||||
} pushConstants;
|
||||
|
||||
#if pp_Texture == 1
|
||||
layout (set = 1, binding = 0) uniform sampler2D tex;
|
||||
#endif
|
||||
|
||||
|
@ -138,10 +143,10 @@ lowp float fog_mode2(float w)
|
|||
}
|
||||
#endif
|
||||
|
||||
vec4 fog_clamp(lowp vec4 col)
|
||||
vec4 colorClamp(lowp vec4 col)
|
||||
{
|
||||
#if FogClamping == 1
|
||||
return clamp(col, uniformBuffer.fog_clamp_min, uniformBuffer.fog_clamp_max);
|
||||
#if ColorClamping == 1
|
||||
return clamp(col, uniformBuffer.colorClampMin, uniformBuffer.colorClampMax);
|
||||
#else
|
||||
return col;
|
||||
#endif
|
||||
|
@ -150,28 +155,28 @@ vec4 fog_clamp(lowp vec4 col)
|
|||
void main()
|
||||
{
|
||||
// Clip outside the box
|
||||
#if pp_ClipTestMode==1
|
||||
if (gl_FragCoord.x < uniformBuffer.pp_ClipTest.x || gl_FragCoord.x > uniformBuffer.pp_ClipTest.z
|
||||
|| gl_FragCoord.y < uniformBuffer.pp_ClipTest.y || gl_FragCoord.y > uniformBuffer.pp_ClipTest.w)
|
||||
#if pp_ClipTestMode == 1
|
||||
if (gl_FragCoord.x < pushConstants.clipTest.x || gl_FragCoord.x > pushConstants.clipTest.z
|
||||
|| gl_FragCoord.y < pushConstants.clipTest.y || gl_FragCoord.y > pushConstants.clipTest.w)
|
||||
discard;
|
||||
#endif
|
||||
// Clip inside the box
|
||||
#if pp_ClipTestMode==-1
|
||||
if (gl_FragCoord.x >= uniformBuffer.pp_ClipTest.x && gl_FragCoord.x <= uniformBuffer.pp_ClipTest.z
|
||||
&& gl_FragCoord.y >= uniformBuffer.pp_ClipTest.y && gl_FragCoord.y <= uniformBuffer.pp_ClipTest.w)
|
||||
#if pp_ClipTestMode == -1
|
||||
if (gl_FragCoord.x >= pushConstants.clipTest.x && gl_FragCoord.x <= pushConstants.clipTest.z
|
||||
&& gl_FragCoord.y >= pushConstants.clipTest.y && gl_FragCoord.y <= pushConstants.clipTest.w)
|
||||
discard;
|
||||
#endif
|
||||
|
||||
lowp vec4 color=vtx_base;
|
||||
#if pp_UseAlpha==0
|
||||
color.a=1.0;
|
||||
lowp vec4 color = vtx_base;
|
||||
#if pp_UseAlpha == 0
|
||||
color.a = 1.0;
|
||||
#endif
|
||||
#if pp_FogCtrl==3
|
||||
color=vec4(uniformBuffer.sp_FOG_COL_RAM.rgb,fog_mode2(gl_FragCoord.w));
|
||||
#if pp_FogCtrl == 3
|
||||
color = vec4(uniformBuffer.sp_FOG_COL_RAM.rgb, fog_mode2(gl_FragCoord.w));
|
||||
#endif
|
||||
#if pp_Texture==1
|
||||
#if pp_Texture == 1
|
||||
{
|
||||
lowp vec4 texcol=texture(tex, vtx_uv);
|
||||
lowp vec4 texcol = texture(tex, vtx_uv);
|
||||
|
||||
#if pp_BumpMap == 1
|
||||
float s = PI / 2.0 * (texcol.a * 15.0 * 16.0 + texcol.r * 15.0) / 255.0;
|
||||
|
@ -179,8 +184,8 @@ void main()
|
|||
texcol.a = clamp(vtx_offs.a + vtx_offs.r * sin(s) + vtx_offs.g * cos(s) * cos(r - 2.0 * PI * vtx_offs.b), 0.0, 1.0);
|
||||
texcol.rgb = vec3(1.0, 1.0, 1.0);
|
||||
#else
|
||||
#if pp_IgnoreTexA==1
|
||||
texcol.a=1.0;
|
||||
#if pp_IgnoreTexA == 1
|
||||
texcol.a = 1.0;
|
||||
#endif
|
||||
|
||||
#if cp_AlphaTest == 1
|
||||
|
@ -188,57 +193,57 @@ void main()
|
|||
discard;
|
||||
#endif
|
||||
#endif
|
||||
#if pp_ShadInstr==0
|
||||
#if pp_ShadInstr == 0
|
||||
{
|
||||
color=texcol;
|
||||
color = texcol;
|
||||
}
|
||||
#endif
|
||||
#if pp_ShadInstr==1
|
||||
#if pp_ShadInstr == 1
|
||||
{
|
||||
color.rgb*=texcol.rgb;
|
||||
color.a=texcol.a;
|
||||
color.rgb *= texcol.rgb;
|
||||
color.a = texcol.a;
|
||||
}
|
||||
#endif
|
||||
#if pp_ShadInstr==2
|
||||
#if pp_ShadInstr == 2
|
||||
{
|
||||
color.rgb=mix(color.rgb,texcol.rgb,texcol.a);
|
||||
color.rgb = mix(color.rgb, texcol.rgb, texcol.a);
|
||||
}
|
||||
#endif
|
||||
#if pp_ShadInstr==3
|
||||
#if pp_ShadInstr == 3
|
||||
{
|
||||
color*=texcol;
|
||||
color *= texcol;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if pp_Offset==1 && pp_BumpMap == 0
|
||||
#if pp_Offset == 1 && pp_BumpMap == 0
|
||||
{
|
||||
color.rgb+=vtx_offs.rgb;
|
||||
color.rgb += vtx_offs.rgb;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
color = fog_clamp(color);
|
||||
color = colorClamp(color);
|
||||
|
||||
#if pp_FogCtrl == 0
|
||||
{
|
||||
color.rgb=mix(color.rgb,uniformBuffer.sp_FOG_COL_RAM.rgb,fog_mode2(gl_FragCoord.w));
|
||||
color.rgb = mix(color.rgb, uniformBuffer.sp_FOG_COL_RAM.rgb, fog_mode2(gl_FragCoord.w));
|
||||
}
|
||||
#endif
|
||||
#if pp_FogCtrl == 1 && pp_Offset==1 && pp_BumpMap == 0
|
||||
{
|
||||
color.rgb=mix(color.rgb,uniformBuffer.sp_FOG_COL_VERT.rgb,vtx_offs.a);
|
||||
color.rgb = mix(color.rgb, uniformBuffer.sp_FOG_COL_VERT.rgb, vtx_offs.a);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if pp_TriLinear == 1
|
||||
color *= uniformBuffer.trilinear_alpha;
|
||||
color *= pushConstants.trilinearAlpha;
|
||||
#endif
|
||||
|
||||
#if cp_AlphaTest == 1
|
||||
color.a=1.0;
|
||||
color.a = 1.0;
|
||||
#endif
|
||||
//color.rgb=vec3(gl_FragCoord.w * uniformBuffer.sp_FOG_DENSITY / 128.0);
|
||||
//color.rgb = vec3(gl_FragCoord.w * uniformBuffer.sp_FOG_DENSITY / 128.0);
|
||||
|
||||
float w = gl_FragCoord.w * 100000.0;
|
||||
gl_FragDepth = log2(1.0 + w) / 34.0;
|
||||
|
|
|
@ -55,30 +55,30 @@ struct FragmentShaderParams
|
|||
}
|
||||
};
|
||||
|
||||
#define ALIGN DECL_ALIGN(16)
|
||||
|
||||
struct VertexShaderUniforms
|
||||
{
|
||||
ALIGN float scale[4];
|
||||
ALIGN float extra_depth_scale;
|
||||
float scale[4];
|
||||
float extra_depth_scale;
|
||||
};
|
||||
|
||||
struct FragmentShaderUniforms
|
||||
{
|
||||
ALIGN float cp_AlphaTestValue;
|
||||
ALIGN float pp_ClipTest[4];
|
||||
ALIGN float sp_FOG_COL_RAM[3];
|
||||
ALIGN float sp_FOG_COL_VERT[3];
|
||||
ALIGN float sp_FOG_DENSITY;
|
||||
ALIGN float trilinear_alpha;
|
||||
ALIGN float fog_clamp_min[4];
|
||||
ALIGN float fog_clamp_max[4];
|
||||
ALIGN float extra_depth_scale;
|
||||
float colorClampMin[4];
|
||||
float colorClampMax[4];
|
||||
float cp_AlphaTestValue;
|
||||
float _pad0[3];
|
||||
float sp_FOG_COL_RAM[3];
|
||||
float _pad1;
|
||||
float sp_FOG_COL_VERT[3];
|
||||
float _pad2;
|
||||
float sp_FOG_DENSITY;
|
||||
float _pad3[3];
|
||||
float extra_depth_scale;
|
||||
};
|
||||
|
||||
struct ModVolShaderUniforms
|
||||
{
|
||||
ALIGN float sp_ShaderColor;
|
||||
float sp_ShaderColor;
|
||||
};
|
||||
|
||||
class ShaderManager
|
||||
|
|
|
@ -67,6 +67,7 @@ public:
|
|||
int GetSwapChainSize() const { return (int)imageViews.size(); }
|
||||
int GetCurrentImageIndex() const { return currentImage; }
|
||||
void WaitIdle() const { graphicsQueue.waitIdle(); }
|
||||
bool IsRendering() const { return rendering; }
|
||||
|
||||
static VulkanContext *Instance() { return contextInstance; }
|
||||
|
||||
|
@ -98,6 +99,7 @@ private:
|
|||
return true;
|
||||
}
|
||||
|
||||
bool rendering = false;
|
||||
u32 width = 0;
|
||||
u32 height = 0;
|
||||
vk::UniqueInstance instance;
|
||||
|
|
|
@ -473,6 +473,8 @@ void VulkanContext::NewFrame()
|
|||
device->resetCommandPool(*commandPools[currentImage], vk::CommandPoolResetFlagBits::eReleaseResources);
|
||||
vk::CommandBuffer& commandBuffer = *commandBuffers[currentImage];
|
||||
commandBuffer.begin(vk::CommandBufferBeginInfo(vk::CommandBufferUsageFlagBits::eOneTimeSubmit));
|
||||
verify(!rendering);
|
||||
rendering = true;
|
||||
}
|
||||
|
||||
void VulkanContext::BeginRenderPass()
|
||||
|
@ -491,6 +493,8 @@ void VulkanContext::EndFrame()
|
|||
vk::PipelineStageFlags wait_stage = vk::PipelineStageFlagBits::eColorAttachmentOutput;
|
||||
vk::SubmitInfo submitInfo(1, &(*imageAcquiredSemaphores[currentSemaphore]), &wait_stage, 1, &commandBuffer, 1, &(*renderCompleteSemaphores[currentSemaphore]));
|
||||
graphicsQueue.submit(1, &submitInfo, *drawFences[currentImage]);
|
||||
verify(rendering);
|
||||
rendering = false;
|
||||
}
|
||||
|
||||
void VulkanContext::Present()
|
||||
|
|
|
@ -61,6 +61,11 @@ public:
|
|||
|
||||
bool Process(TA_context* ctx) override
|
||||
{
|
||||
if (ctx->rend.isRenderFramebuffer)
|
||||
{
|
||||
// TODO RenderFramebuffer();
|
||||
return false;
|
||||
}
|
||||
GetContext()->NewFrame();
|
||||
if (ProcessFrame(ctx))
|
||||
return true;
|
||||
|
@ -74,7 +79,6 @@ public:
|
|||
|
||||
void DrawOSD(bool clear_screen) override
|
||||
{
|
||||
// TODO gui_display_osd();
|
||||
}
|
||||
|
||||
bool Render() override
|
||||
|
@ -92,8 +96,8 @@ public:
|
|||
dc_height = pvrrc.fb_Y_CLIP.max - pvrrc.fb_Y_CLIP.min + 1;
|
||||
}
|
||||
|
||||
float scale_x = 1;
|
||||
float scale_y = 1;
|
||||
scale_x = 1;
|
||||
scale_y = 1;
|
||||
|
||||
float scissoring_scale_x = 1;
|
||||
|
||||
|
@ -153,7 +157,7 @@ public:
|
|||
dc2s_scale_h = screen_height / 480.0f;
|
||||
ds2s_offs_x = (screen_width - dc2s_scale_h * 640.0f * screen_stretching) / 2;
|
||||
vtxUniforms.scale[0] = 2.0f / (screen_width / dc2s_scale_h * scale_x) * screen_stretching;
|
||||
vtxUniforms.scale[1] = 2.0f / dc_height;
|
||||
vtxUniforms.scale[1] = 1.5f / dc_height; // FIXME 1.5 WTF?
|
||||
vtxUniforms.scale[2] = 1 - 2 * ds2s_offs_x / screen_width;
|
||||
vtxUniforms.scale[3] = 1;
|
||||
}
|
||||
|
@ -181,15 +185,15 @@ public:
|
|||
s32 fog_den_exp=(s8)fog_density[0];
|
||||
fragUniforms.sp_FOG_DENSITY = fog_den_mant * powf(2.0f, fog_den_exp);
|
||||
|
||||
fragUniforms.fog_clamp_min[0] = ((pvrrc.fog_clamp_min >> 16) & 0xFF) / 255.0f;
|
||||
fragUniforms.fog_clamp_min[1] = ((pvrrc.fog_clamp_min >> 8) & 0xFF) / 255.0f;
|
||||
fragUniforms.fog_clamp_min[2] = ((pvrrc.fog_clamp_min >> 0) & 0xFF) / 255.0f;
|
||||
fragUniforms.fog_clamp_min[3] = ((pvrrc.fog_clamp_min >> 24) & 0xFF) / 255.0f;
|
||||
fragUniforms.colorClampMin[0] = ((pvrrc.fog_clamp_min >> 16) & 0xFF) / 255.0f;
|
||||
fragUniforms.colorClampMin[1] = ((pvrrc.fog_clamp_min >> 8) & 0xFF) / 255.0f;
|
||||
fragUniforms.colorClampMin[2] = ((pvrrc.fog_clamp_min >> 0) & 0xFF) / 255.0f;
|
||||
fragUniforms.colorClampMin[3] = ((pvrrc.fog_clamp_min >> 24) & 0xFF) / 255.0f;
|
||||
|
||||
fragUniforms.fog_clamp_max[0] = ((pvrrc.fog_clamp_max >> 16) & 0xFF) / 255.0f;
|
||||
fragUniforms.fog_clamp_max[1] = ((pvrrc.fog_clamp_max >> 8) & 0xFF) / 255.0f;
|
||||
fragUniforms.fog_clamp_max[2] = ((pvrrc.fog_clamp_max >> 0) & 0xFF) / 255.0f;
|
||||
fragUniforms.fog_clamp_max[3] = ((pvrrc.fog_clamp_max >> 24) & 0xFF) / 255.0f;
|
||||
fragUniforms.colorClampMax[0] = ((pvrrc.fog_clamp_max >> 16) & 0xFF) / 255.0f;
|
||||
fragUniforms.colorClampMax[1] = ((pvrrc.fog_clamp_max >> 8) & 0xFF) / 255.0f;
|
||||
fragUniforms.colorClampMax[2] = ((pvrrc.fog_clamp_max >> 0) & 0xFF) / 255.0f;
|
||||
fragUniforms.colorClampMax[3] = ((pvrrc.fog_clamp_max >> 24) & 0xFF) / 255.0f;
|
||||
|
||||
if (fog_needs_update && settings.rend.Fog)
|
||||
{
|
||||
|
@ -260,6 +264,8 @@ public:
|
|||
DrawList(cmdBuffer, ListType_Translucent, false, pvrrc.global_param_tr, previous_pass.tr_count, current_pass.tr_count - previous_pass.tr_count);
|
||||
previous_pass = current_pass;
|
||||
}
|
||||
if (!is_rtt)
|
||||
gui_display_osd();
|
||||
|
||||
GetContext()->EndFrame();
|
||||
|
||||
|
@ -293,11 +299,107 @@ private:
|
|||
VulkanContext *GetContext() const { return VulkanContext::Instance(); }
|
||||
int GetCurrentImage() const { return GetContext()->GetCurrentImageIndex(); }
|
||||
|
||||
// FIXME Code dup
|
||||
s32 SetTileClip(u32 val, float *values)
|
||||
{
|
||||
if (!settings.rend.Clipping)
|
||||
return 0;
|
||||
|
||||
u32 clipmode = val >> 28;
|
||||
s32 clip_mode;
|
||||
if (clipmode < 2)
|
||||
{
|
||||
clip_mode = 0; //always passes
|
||||
}
|
||||
else if (clipmode & 1)
|
||||
clip_mode = -1; //render stuff outside the region
|
||||
else
|
||||
clip_mode = 1; //render stuff inside the region
|
||||
|
||||
float csx = 0, csy = 0, cex = 0, cey = 0;
|
||||
|
||||
|
||||
csx = (float)(val & 63);
|
||||
cex = (float)((val >> 6) & 63);
|
||||
csy = (float)((val >> 12) & 31);
|
||||
cey = (float)((val >> 17) & 31);
|
||||
csx = csx * 32;
|
||||
cex = cex * 32 + 32;
|
||||
csy = csy * 32;
|
||||
cey = cey * 32 + 32;
|
||||
|
||||
if (csx <= 0 && csy <= 0 && cex >= 640 && cey >= 480)
|
||||
return 0;
|
||||
|
||||
if (values != nullptr && clip_mode)
|
||||
{
|
||||
if (!pvrrc.isRTT)
|
||||
{
|
||||
csx /= scale_x;
|
||||
csy /= scale_y;
|
||||
cex /= scale_x;
|
||||
cey /= scale_y;
|
||||
float dc2s_scale_h;
|
||||
float ds2s_offs_x;
|
||||
float screen_stretching = settings.rend.ScreenStretching / 100.f;
|
||||
|
||||
if (settings.rend.Rotate90)
|
||||
{
|
||||
float t = cex;
|
||||
cex = cey;
|
||||
cey = 640 - csx;
|
||||
csx = csy;
|
||||
csy = 640 - t;
|
||||
dc2s_scale_h = screen_height / 640.0f;
|
||||
ds2s_offs_x = (screen_width - dc2s_scale_h * 480.0 * screen_stretching) / 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
dc2s_scale_h = screen_height / 480.0f;
|
||||
ds2s_offs_x = (screen_width - dc2s_scale_h * 640.0 * screen_stretching) / 2;
|
||||
}
|
||||
csx = csx * dc2s_scale_h * screen_stretching + ds2s_offs_x;
|
||||
cex = cex * dc2s_scale_h * screen_stretching + ds2s_offs_x;
|
||||
csy = csy * dc2s_scale_h;
|
||||
cey = cey * dc2s_scale_h;
|
||||
}
|
||||
else if (!settings.rend.RenderToTextureBuffer)
|
||||
{
|
||||
csx *= settings.rend.RenderToTextureUpscale;
|
||||
csy *= settings.rend.RenderToTextureUpscale;
|
||||
cex *= settings.rend.RenderToTextureUpscale;
|
||||
cey *= settings.rend.RenderToTextureUpscale;
|
||||
}
|
||||
values[0] = csx;
|
||||
values[1] = csy;
|
||||
values[2] = cex;
|
||||
values[3] = cey;
|
||||
}
|
||||
|
||||
return clip_mode;
|
||||
}
|
||||
|
||||
|
||||
void DrawList(const vk::CommandBuffer& cmdBuffer, u32 listType, bool sortTriangles, const List<PolyParam>& polys, u32 first, u32 count)
|
||||
{
|
||||
for (u32 i = first; i < count; i++)
|
||||
{
|
||||
const PolyParam &pp = polys.head()[i];
|
||||
float trilinearAlpha;
|
||||
if (pp.pcw.Texture && pp.tsp.FilterMode > 1 && listType != ListType_Punch_Through)
|
||||
{
|
||||
trilinearAlpha = 0.25 * (pp.tsp.MipMapD & 0x3);
|
||||
if (pp.tsp.FilterMode == 2)
|
||||
// Trilinear pass A
|
||||
trilinearAlpha = 1.0 - trilinearAlpha;
|
||||
}
|
||||
else
|
||||
trilinearAlpha = 1.f;
|
||||
|
||||
std::array<float, 5> pushConstants = { 0, 0, 0, 0, trilinearAlpha };
|
||||
SetTileClip(pp.tileclip, &pushConstants[0]);
|
||||
cmdBuffer.pushConstants<float>(pipelineManager.GetDescriptorSets().GetPipelineLayout(), vk::ShaderStageFlagBits::eFragment, 0, pushConstants);
|
||||
|
||||
if (pp.pcw.Texture)
|
||||
pipelineManager.GetDescriptorSets().SetTexture(pp.texid, pp.tsp);
|
||||
|
||||
|
@ -360,29 +462,40 @@ private:
|
|||
if (vertexBuffers.empty())
|
||||
{
|
||||
for (int i = 0; i < GetContext()->GetSwapChainSize(); i++)
|
||||
vertexBuffers.push_back(std::unique_ptr<BufferData>(new BufferData(GetContext()->GetPhysicalDevice(), GetContext()->GetDevice().get(), vertexSize,
|
||||
vk::BufferUsageFlagBits::eVertexBuffer)));
|
||||
vertexBuffers.push_back(std::unique_ptr<BufferData>(new BufferData(GetContext()->GetPhysicalDevice(), GetContext()->GetDevice().get(),
|
||||
std::max(512 * 1024u, vertexSize), vk::BufferUsageFlagBits::eVertexBuffer)));
|
||||
}
|
||||
else if (vertexBuffers[GetCurrentImage()]->m_size < vertexSize)
|
||||
{
|
||||
INFO_LOG(RENDERER, "Increasing vertex buffer size %d -> %d", (u32)vertexBuffers[GetCurrentImage()]->m_size, vertexSize);
|
||||
vertexBuffers[GetCurrentImage()] = std::unique_ptr<BufferData>(new BufferData(GetContext()->GetPhysicalDevice(), GetContext()->GetDevice().get(), vertexSize,
|
||||
u32 newSize = vertexBuffers[GetCurrentImage()]->m_size;
|
||||
while (newSize < vertexSize)
|
||||
newSize *= 2;
|
||||
INFO_LOG(RENDERER, "Increasing vertex buffer size %d -> %d", (u32)vertexBuffers[GetCurrentImage()]->m_size, newSize);
|
||||
vertexBuffers[GetCurrentImage()] = std::unique_ptr<BufferData>(new BufferData(GetContext()->GetPhysicalDevice(), GetContext()->GetDevice().get(), newSize,
|
||||
vk::BufferUsageFlagBits::eVertexBuffer));
|
||||
}
|
||||
if (indexBuffers.empty())
|
||||
{
|
||||
for (int i = 0; i < GetContext()->GetSwapChainSize(); i++)
|
||||
indexBuffers.push_back(std::unique_ptr<BufferData>(new BufferData(GetContext()->GetPhysicalDevice(), GetContext()->GetDevice().get(), indexSize,
|
||||
indexBuffers.push_back(std::unique_ptr<BufferData>(new BufferData(GetContext()->GetPhysicalDevice(), GetContext()->GetDevice().get(),
|
||||
std::max(64 * 1024u, indexSize),
|
||||
vk::BufferUsageFlagBits::eIndexBuffer)));
|
||||
}
|
||||
else if (indexBuffers[GetCurrentImage()]->m_size < indexSize)
|
||||
{
|
||||
INFO_LOG(RENDERER, "Increasing index buffer size %d -> %d", (u32)indexBuffers[GetCurrentImage()]->m_size, indexSize);
|
||||
indexBuffers[GetCurrentImage()] = std::unique_ptr<BufferData>(new BufferData(GetContext()->GetPhysicalDevice(), GetContext()->GetDevice().get(), indexSize,
|
||||
u32 newSize = indexBuffers[GetCurrentImage()]->m_size;
|
||||
while (newSize < indexSize)
|
||||
newSize *= 2;
|
||||
INFO_LOG(RENDERER, "Increasing index buffer size %d -> %d", (u32)indexBuffers[GetCurrentImage()]->m_size, newSize);
|
||||
indexBuffers[GetCurrentImage()] = std::unique_ptr<BufferData>(new BufferData(GetContext()->GetPhysicalDevice(), GetContext()->GetDevice().get(), newSize,
|
||||
vk::BufferUsageFlagBits::eIndexBuffer));
|
||||
}
|
||||
}
|
||||
|
||||
// temp stuff
|
||||
float scale_x;
|
||||
float scale_y;
|
||||
|
||||
// Uniforms
|
||||
vk::UniqueBuffer vertexUniformBuffer;
|
||||
vk::UniqueBuffer fragmentUniformBuffer;
|
||||
|
|
Loading…
Reference in New Issue