Permalink
Browse files

Vulkan: Support wide lines if available on the GPU.

  • Loading branch information...
hrydgard committed Nov 12, 2017
1 parent afa5b23 commit 525cb40f8426ee5e0a0e9d84bbdb1116fadbc8ab
@@ -226,7 +226,6 @@ void FramebufferManagerGLES::Init() {
// Workaround for upscaling shaders where we force x1 resolution without saving it
Resized();
CompileDraw2DProgram();
SetLineWidth();
}
void FramebufferManagerGLES::SetTextureCache(TextureCacheGLES *tc) {
@@ -449,18 +448,6 @@ void FramebufferManagerGLES::RebindFramebuffer() {
glstate.viewport.restore();
}
void FramebufferManagerGLES::SetLineWidth() {
#ifndef USING_GLES2
if (g_Config.iInternalResolution == 0) {
glLineWidth(std::max(1, (int)(renderWidth_ / 480)));
glPointSize(std::max(1.0f, (float)(renderWidth_ / 480.f)));
} else {
glLineWidth(g_Config.iInternalResolution);
glPointSize((float)g_Config.iInternalResolution);
}
#endif
}
void FramebufferManagerGLES::ReformatFramebufferFrom(VirtualFramebuffer *vfb, GEBufferFormat old) {
if (!useBufferedRendering_ || !vfb->fbo) {
return;
@@ -1064,7 +1051,16 @@ void FramebufferManagerGLES::Resized() {
}
DestroyDraw2DProgram();
SetLineWidth();
#ifndef USING_GLES2
if (g_Config.iInternalResolution == 0) {
glLineWidth(std::max(1, (int)(renderWidth_ / 480)));
glPointSize(std::max(1.0f, (float)(renderWidth_ / 480.f)));
} else {
glLineWidth(g_Config.iInternalResolution);
glPointSize((float)g_Config.iInternalResolution);
}
#endif
if (!draw2dprogram_) {
CompileDraw2DProgram();
@@ -509,6 +509,10 @@ void DrawEngineVulkan::DecodeVerts(VulkanPushBuffer *push, uint32_t *bindOffset,
}
}
void DrawEngineVulkan::SetLineWidth(float lineWidth) {
pipelineManager_->SetLineWidth(lineWidth);
}
VkDescriptorSet DrawEngineVulkan::GetOrCreateDescriptorSet(VkImageView imageView, VkSampler sampler, VkBuffer base, VkBuffer light, VkBuffer bone) {
DescriptorSetKey key;
key.imageView_ = imageView;
@@ -517,12 +521,15 @@ VkDescriptorSet DrawEngineVulkan::GetOrCreateDescriptorSet(VkImageView imageView
key.base_ = base;
key.light_ = light;
key.bone_ = bone;
assert(base != VK_NULL_HANDLE);
assert(light != VK_NULL_HANDLE);
assert(bone != VK_NULL_HANDLE);
_dbg_assert_(G3D, base != VK_NULL_HANDLE);
_dbg_assert_(G3D, light != VK_NULL_HANDLE);
_dbg_assert_(G3D, bone != VK_NULL_HANDLE);
bool tess = gstate_c.bezier || gstate_c.spline;
FrameData *frame = &frame_[vulkan_->GetCurFrame()];
if (!gstate_c.bezier && !gstate_c.spline) { // Has no cache when HW tessellation.
// See if we already have this descriptor set cached.
if (!tess) { // Don't cache descriptors for HW tessellation.
VkDescriptorSet d = frame->descSets.Get(key);
if (d != VK_NULL_HANDLE)
return d;
@@ -580,7 +587,7 @@ VkDescriptorSet DrawEngineVulkan::GetOrCreateDescriptorSet(VkImageView imageView
// Skipping 2nd texture for now.
// Tessellation data textures
if (gstate_c.bezier || gstate_c.spline) {
if (tess) {
VkDescriptorImageInfo tess_tex[3]{};
VkSampler sampler = ((TessellationDataTransferVulkan *)tessDataTransfer)->GetSampler();
for (int i = 0; i < 3; i++) {
@@ -175,6 +175,8 @@ class DrawEngineVulkan : public DrawEngineCommon {
return stats_;
}
void SetLineWidth(float lineWidth);
private:
struct FrameData;
void ApplyDrawStateLate(VulkanRenderManager *renderManager, bool applyStencilRef, uint8_t stencilRef, bool useBlendConstant);
@@ -158,6 +158,9 @@ GPU_Vulkan::GPU_Vulkan(GraphicsContext *gfxCtx, Draw::DrawContext *draw)
UpdateVsyncInterval(true);
textureCacheVulkan_->NotifyConfigChanged();
if (vulkan_->GetFeaturesEnabled().wideLines) {
drawEngine_.SetLineWidth(PSP_CoreParameter().renderWidth / 480.0f);
}
}
GPU_Vulkan::~GPU_Vulkan() {
@@ -221,6 +224,9 @@ void GPU_Vulkan::BeginHostFrame() {
framebufferManager_->Resized();
drawEngine_.Resized();
textureCacheVulkan_->NotifyConfigChanged();
if (vulkan_->GetFeaturesEnabled ().wideLines) {
drawEngine_.SetLineWidth(PSP_CoreParameter().renderWidth / 480.0f);
}
}
resized_ = false;
@@ -121,7 +121,7 @@ static bool UsesBlendConstant(int factor) {
static VulkanPipeline *CreateVulkanPipeline(VkDevice device, VkPipelineCache pipelineCache,
VkPipelineLayout layout, VkRenderPass renderPass, const VulkanPipelineRasterStateKey &key,
const VertexDecoder *vtxDec, VulkanVertexShader *vs, VulkanFragmentShader *fs, bool useHwTransform) {
const VertexDecoder *vtxDec, VulkanVertexShader *vs, VulkanFragmentShader *fs, bool useHwTransform, float lineWidth) {
bool useBlendConstant = false;
VkPipelineColorBlendAttachmentState blend0 = {};
@@ -188,7 +188,7 @@ static VulkanPipeline *CreateVulkanPipeline(VkDevice device, VkPipelineCache pip
rs.depthBiasEnable = false;
rs.cullMode = key.cullMode;
rs.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
rs.lineWidth = 1.0f;
rs.lineWidth = lineWidth;
rs.rasterizerDiscardEnable = false;
rs.polygonMode = VK_POLYGON_MODE_FILL;
rs.depthClampEnable = false;
@@ -289,6 +289,7 @@ static VulkanPipeline *CreateVulkanPipeline(VkDevice device, VkPipelineCache pip
vulkanPipeline->pipeline = pipeline;
vulkanPipeline->uniformBlocks = UB_VS_FS_BASE;
vulkanPipeline->useBlendConstant = useBlendConstant;
vulkanPipeline->usesLines = key.topology == VK_PRIMITIVE_TOPOLOGY_LINE_LIST || key.topology == VK_PRIMITIVE_TOPOLOGY_LINE_STRIP;
if (useHwTransform) {
if (vs->HasLights()) {
vulkanPipeline->uniformBlocks |= UB_VS_LIGHTS;
@@ -320,7 +321,7 @@ VulkanPipeline *PipelineManagerVulkan::GetOrCreatePipeline(VkPipelineLayout layo
VulkanPipeline *pipeline = CreateVulkanPipeline(
vulkan_->GetDevice(), pipelineCache_, layout, renderPass,
rasterKey, vtxDec, vs, fs, useHwTransform);
rasterKey, vtxDec, vs, fs, useHwTransform, lineWidth_);
// Even if the result is nullptr, insert it so we don't try to create it repeatedly.
pipelines_.Insert(key, pipeline);
return pipeline;
@@ -370,3 +371,18 @@ std::string PipelineManagerVulkan::DebugGetObjectString(std::string id, DebugSha
return "N/A";
}
}
void PipelineManagerVulkan::SetLineWidth(float lineWidth) {
if (lineWidth_ == lineWidth)
return;
lineWidth_ = lineWidth;
// Wipe all line-drawing pipelines.
pipelines_.Iterate([&](const VulkanPipelineKey &key, VulkanPipeline *value) {
if (value->usesLines) {
vulkan_->Delete().QueueDeletePipeline(value->pipeline);
delete value;
pipelines_.Remove(key);
}
});
}
@@ -65,6 +65,7 @@ struct VulkanPipeline {
VkPipeline pipeline;
int uniformBlocks; // UB_ enum above.
bool useBlendConstant;
bool usesLines;
};
class VulkanContext;
@@ -81,6 +82,8 @@ class PipelineManagerVulkan {
void Clear();
void SetLineWidth(float lw);
void DeviceLost();
void DeviceRestore(VulkanContext *vulkan);
@@ -91,4 +94,5 @@ class PipelineManagerVulkan {
DenseHashMap<VulkanPipelineKey, VulkanPipeline *, nullptr> pipelines_;
VkPipelineCache pipelineCache_;
VulkanContext *vulkan_;
float lineWidth_ = 1.0f;
};

0 comments on commit 525cb40

Please sign in to comment.