mirror of
https://github.com/libretro/RetroArch
synced 2025-02-25 21:41:03 +00:00
80-char width limit style nits
This commit is contained in:
parent
f41ee75a82
commit
4bb3f35a02
@ -28,7 +28,8 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
static uint32_t find_memory_type(const VkPhysicalDeviceMemoryProperties &mem_props,
|
||||
static uint32_t find_memory_type(
|
||||
const VkPhysicalDeviceMemoryProperties &mem_props,
|
||||
uint32_t device_reqs, uint32_t host_reqs)
|
||||
{
|
||||
uint32_t i;
|
||||
@ -43,7 +44,8 @@ static uint32_t find_memory_type(const VkPhysicalDeviceMemoryProperties &mem_pro
|
||||
abort();
|
||||
}
|
||||
|
||||
static uint32_t find_memory_type_fallback(const VkPhysicalDeviceMemoryProperties &mem_props,
|
||||
static uint32_t find_memory_type_fallback(
|
||||
const VkPhysicalDeviceMemoryProperties &mem_props,
|
||||
uint32_t device_reqs, uint32_t host_reqs)
|
||||
{
|
||||
uint32_t i;
|
||||
@ -113,7 +115,8 @@ class DeferredDisposer
|
||||
class Buffer
|
||||
{
|
||||
public:
|
||||
Buffer(VkDevice device, const VkPhysicalDeviceMemoryProperties &mem_props,
|
||||
Buffer(VkDevice device,
|
||||
const VkPhysicalDeviceMemoryProperties &mem_props,
|
||||
size_t size, VkBufferUsageFlags usage);
|
||||
~Buffer();
|
||||
|
||||
@ -133,7 +136,8 @@ class Buffer
|
||||
class Framebuffer
|
||||
{
|
||||
public:
|
||||
Framebuffer(VkDevice device, const VkPhysicalDeviceMemoryProperties &mem_props,
|
||||
Framebuffer(VkDevice device,
|
||||
const VkPhysicalDeviceMemoryProperties &mem_props,
|
||||
const Size2D &max_size, VkFormat format);
|
||||
|
||||
~Framebuffer();
|
||||
@ -174,7 +178,8 @@ class Framebuffer
|
||||
class Pass
|
||||
{
|
||||
public:
|
||||
Pass(VkDevice device, const VkPhysicalDeviceMemoryProperties &memory_properties,
|
||||
Pass(VkDevice device,
|
||||
const VkPhysicalDeviceMemoryProperties &memory_properties,
|
||||
VkPipelineCache cache, unsigned num_sync_indices, bool final_pass) :
|
||||
device(device),
|
||||
memory_properties(memory_properties),
|
||||
@ -239,7 +244,8 @@ class Pass
|
||||
unsigned sync_index;
|
||||
bool final_pass;
|
||||
|
||||
Size2D get_output_size(const Size2D &original_size, const Size2D &max_source) const;
|
||||
Size2D get_output_size(const Size2D &original_size,
|
||||
const Size2D &max_source) const;
|
||||
|
||||
VkPipeline pipeline = VK_NULL_HANDLE;
|
||||
VkPipelineLayout pipeline_layout = VK_NULL_HANDLE;
|
||||
@ -302,17 +308,20 @@ struct vulkan_filter_chain
|
||||
return shader_preset.get();
|
||||
}
|
||||
|
||||
void set_pass_info(unsigned pass, const vulkan_filter_chain_pass_info &info);
|
||||
void set_pass_info(unsigned pass,
|
||||
const vulkan_filter_chain_pass_info &info);
|
||||
void set_shader(unsigned pass, VkShaderStageFlags stage,
|
||||
const uint32_t *spirv, size_t spirv_words);
|
||||
|
||||
bool init();
|
||||
bool update_swapchain_info(const vulkan_filter_chain_swapchain_info &info);
|
||||
bool update_swapchain_info(
|
||||
const vulkan_filter_chain_swapchain_info &info);
|
||||
|
||||
void notify_sync_index(unsigned index);
|
||||
void set_input_texture(const vulkan_filter_chain_texture &texture);
|
||||
void build_offscreen_passes(VkCommandBuffer cmd, const VkViewport &vp);
|
||||
void build_viewport_pass(VkCommandBuffer cmd, const VkViewport &vp, const float *mvp);
|
||||
void build_viewport_pass(VkCommandBuffer cmd,
|
||||
const VkViewport &vp, const float *mvp);
|
||||
|
||||
private:
|
||||
VkDevice device;
|
||||
@ -338,7 +347,8 @@ struct vulkan_filter_chain
|
||||
void set_swapchain_info(const vulkan_filter_chain_swapchain_info &info);
|
||||
};
|
||||
|
||||
vulkan_filter_chain::vulkan_filter_chain(const vulkan_filter_chain_create_info &info)
|
||||
vulkan_filter_chain::vulkan_filter_chain(
|
||||
const vulkan_filter_chain_create_info &info)
|
||||
: device(info.device),
|
||||
memory_properties(*info.memory_properties),
|
||||
cache(info.pipeline_cache)
|
||||
@ -353,7 +363,8 @@ vulkan_filter_chain::~vulkan_filter_chain()
|
||||
flush();
|
||||
}
|
||||
|
||||
void vulkan_filter_chain::set_swapchain_info(const vulkan_filter_chain_swapchain_info &info)
|
||||
void vulkan_filter_chain::set_swapchain_info(
|
||||
const vulkan_filter_chain_swapchain_info &info)
|
||||
{
|
||||
swapchain_info = info;
|
||||
set_num_sync_indices(info.num_indices);
|
||||
@ -389,7 +400,8 @@ void vulkan_filter_chain::set_num_passes(unsigned num_passes)
|
||||
}
|
||||
}
|
||||
|
||||
bool vulkan_filter_chain::update_swapchain_info(const vulkan_filter_chain_swapchain_info &info)
|
||||
bool vulkan_filter_chain::update_swapchain_info(
|
||||
const vulkan_filter_chain_swapchain_info &info)
|
||||
{
|
||||
flush();
|
||||
set_swapchain_info(info);
|
||||
@ -402,13 +414,17 @@ void vulkan_filter_chain::set_pass_info(unsigned pass,
|
||||
pass_info[pass] = info;
|
||||
}
|
||||
|
||||
void vulkan_filter_chain::set_shader(unsigned pass, VkShaderStageFlags stage,
|
||||
const uint32_t *spirv, size_t spirv_words)
|
||||
void vulkan_filter_chain::set_shader(
|
||||
unsigned pass,
|
||||
VkShaderStageFlags stage,
|
||||
const uint32_t *spirv,
|
||||
size_t spirv_words)
|
||||
{
|
||||
passes[pass]->set_shader(stage, spirv, spirv_words);
|
||||
}
|
||||
|
||||
void vulkan_filter_chain::set_input_texture(const vulkan_filter_chain_texture &texture)
|
||||
void vulkan_filter_chain::set_input_texture(
|
||||
const vulkan_filter_chain_texture &texture)
|
||||
{
|
||||
input_texture = texture;
|
||||
}
|
||||
@ -436,7 +452,8 @@ bool vulkan_filter_chain::init()
|
||||
for (unsigned i = 0; i < passes.size(); i++)
|
||||
{
|
||||
auto &pass = passes[i];
|
||||
source = pass->set_pass_info(max_input_size, source, swapchain_info, pass_info[i]);
|
||||
source = pass->set_pass_info(max_input_size,
|
||||
source, swapchain_info, pass_info[i]);
|
||||
if (!pass->build())
|
||||
return false;
|
||||
}
|
||||
@ -447,11 +464,14 @@ bool vulkan_filter_chain::init()
|
||||
void vulkan_filter_chain::build_offscreen_passes(VkCommandBuffer cmd,
|
||||
const VkViewport &vp)
|
||||
{
|
||||
unsigned i;
|
||||
DeferredDisposer disposer(deferred_calls[current_sync_index]);
|
||||
const Texture original = { input_texture, passes.front()->get_source_filter() };
|
||||
Texture source = { input_texture, passes.front()->get_source_filter() };
|
||||
const Texture original = {
|
||||
input_texture, passes.front()->get_source_filter() };
|
||||
Texture source = {
|
||||
input_texture, passes.front()->get_source_filter() };
|
||||
|
||||
for (unsigned i = 0; i < passes.size() - 1; i++)
|
||||
for (i = 0; i < passes.size() - 1; i++)
|
||||
{
|
||||
passes[i]->build_commands(disposer, cmd,
|
||||
original, source, vp, nullptr);
|
||||
@ -465,12 +485,13 @@ void vulkan_filter_chain::build_offscreen_passes(VkCommandBuffer cmd,
|
||||
}
|
||||
}
|
||||
|
||||
void vulkan_filter_chain::build_viewport_pass(VkCommandBuffer cmd, const VkViewport &vp, const float *mvp)
|
||||
void vulkan_filter_chain::build_viewport_pass(
|
||||
VkCommandBuffer cmd, const VkViewport &vp, const float *mvp)
|
||||
{
|
||||
DeferredDisposer disposer(deferred_calls[current_sync_index]);
|
||||
|
||||
const Texture original = { input_texture, passes.front()->get_source_filter() };
|
||||
Texture source;
|
||||
DeferredDisposer disposer(deferred_calls[current_sync_index]);
|
||||
const Texture original = {
|
||||
input_texture, passes.front()->get_source_filter() };
|
||||
|
||||
if (passes.size() == 1)
|
||||
source = { input_texture, passes.back()->get_source_filter() };
|
||||
@ -488,7 +509,8 @@ void vulkan_filter_chain::build_viewport_pass(VkCommandBuffer cmd, const VkViewp
|
||||
original, source, vp, mvp);
|
||||
}
|
||||
|
||||
Buffer::Buffer(VkDevice device, const VkPhysicalDeviceMemoryProperties &mem_props,
|
||||
Buffer::Buffer(VkDevice device,
|
||||
const VkPhysicalDeviceMemoryProperties &mem_props,
|
||||
size_t size, VkBufferUsageFlags usage) :
|
||||
device(device), size(size)
|
||||
{
|
||||
@ -504,8 +526,10 @@ Buffer::Buffer(VkDevice device, const VkPhysicalDeviceMemoryProperties &mem_prop
|
||||
VkMemoryAllocateInfo alloc = { VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO };
|
||||
alloc.allocationSize = mem_reqs.size;
|
||||
|
||||
alloc.memoryTypeIndex = find_memory_type(mem_props, mem_reqs.memoryTypeBits,
|
||||
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
|
||||
alloc.memoryTypeIndex = find_memory_type(
|
||||
mem_props, mem_reqs.memoryTypeBits,
|
||||
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
||||
| VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
|
||||
|
||||
vkAllocateMemory(device, &alloc, NULL, &memory);
|
||||
vkBindBufferMemory(device, buffer, memory, 0);
|
||||
@ -545,16 +569,19 @@ void Pass::set_shader(VkShaderStageFlags stage,
|
||||
if (stage == VK_SHADER_STAGE_VERTEX_BIT)
|
||||
{
|
||||
vertex_shader.clear();
|
||||
vertex_shader.insert(end(vertex_shader), spirv, spirv + spirv_words);
|
||||
vertex_shader.insert(end(vertex_shader),
|
||||
spirv, spirv + spirv_words);
|
||||
}
|
||||
else if (stage == VK_SHADER_STAGE_FRAGMENT_BIT)
|
||||
{
|
||||
fragment_shader.clear();
|
||||
fragment_shader.insert(end(fragment_shader), spirv, spirv + spirv_words);
|
||||
fragment_shader.insert(end(fragment_shader),
|
||||
spirv, spirv + spirv_words);
|
||||
}
|
||||
}
|
||||
|
||||
Size2D Pass::get_output_size(const Size2D &original, const Size2D &source) const
|
||||
Size2D Pass::get_output_size(const Size2D &original,
|
||||
const Size2D &source) const
|
||||
{
|
||||
float width, height;
|
||||
switch (pass_info.scale_type_x)
|
||||
@ -670,28 +697,34 @@ bool Pass::init_pipeline_layout()
|
||||
desc_counts.push_back({ VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1 });
|
||||
desc_counts.push_back({ VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1 });
|
||||
|
||||
VkDescriptorSetLayoutCreateInfo set_layout_info = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO };
|
||||
VkDescriptorSetLayoutCreateInfo set_layout_info = {
|
||||
VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO };
|
||||
set_layout_info.bindingCount = bindings.size();
|
||||
set_layout_info.pBindings = bindings.data();
|
||||
|
||||
if (vkCreateDescriptorSetLayout(device, &set_layout_info, NULL, &set_layout) != VK_SUCCESS)
|
||||
if (vkCreateDescriptorSetLayout(device,
|
||||
&set_layout_info, NULL, &set_layout) != VK_SUCCESS)
|
||||
return false;
|
||||
|
||||
VkPipelineLayoutCreateInfo layout_info = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO };
|
||||
VkPipelineLayoutCreateInfo layout_info = {
|
||||
VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO };
|
||||
layout_info.setLayoutCount = 1;
|
||||
layout_info.pSetLayouts = &set_layout;
|
||||
|
||||
if (vkCreatePipelineLayout(device, &layout_info, NULL, &pipeline_layout) != VK_SUCCESS)
|
||||
if (vkCreatePipelineLayout(device,
|
||||
&layout_info, NULL, &pipeline_layout) != VK_SUCCESS)
|
||||
return false;
|
||||
|
||||
VkDescriptorPoolCreateInfo pool_info = { VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO };
|
||||
VkDescriptorPoolCreateInfo pool_info = {
|
||||
VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO };
|
||||
pool_info.maxSets = num_sync_indices;
|
||||
pool_info.poolSizeCount = desc_counts.size();
|
||||
pool_info.pPoolSizes = desc_counts.data();
|
||||
if (vkCreateDescriptorPool(device, &pool_info, nullptr, &pool) != VK_SUCCESS)
|
||||
return false;
|
||||
|
||||
VkDescriptorSetAllocateInfo alloc_info = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO };
|
||||
VkDescriptorSetAllocateInfo alloc_info = {
|
||||
VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO };
|
||||
alloc_info.descriptorPool = pool;
|
||||
alloc_info.descriptorSetCount = 1;
|
||||
alloc_info.pSetLayouts = &set_layout;
|
||||
@ -709,7 +742,8 @@ bool Pass::init_pipeline()
|
||||
return false;
|
||||
|
||||
// Input assembly
|
||||
VkPipelineInputAssemblyStateCreateInfo input_assembly = { VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO };
|
||||
VkPipelineInputAssemblyStateCreateInfo input_assembly = {
|
||||
VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO };
|
||||
input_assembly.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
|
||||
|
||||
// VAO state
|
||||
@ -729,14 +763,16 @@ bool Pass::init_pipeline()
|
||||
binding.stride = 4 * sizeof(float);
|
||||
binding.inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
|
||||
|
||||
VkPipelineVertexInputStateCreateInfo vertex_input = { VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO };
|
||||
VkPipelineVertexInputStateCreateInfo vertex_input = {
|
||||
VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO };
|
||||
vertex_input.vertexBindingDescriptionCount = 1;
|
||||
vertex_input.pVertexBindingDescriptions = &binding;
|
||||
vertex_input.vertexAttributeDescriptionCount = 2;
|
||||
vertex_input.pVertexAttributeDescriptions = attributes;
|
||||
|
||||
// Raster state
|
||||
VkPipelineRasterizationStateCreateInfo raster = { VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO };
|
||||
VkPipelineRasterizationStateCreateInfo raster = {
|
||||
VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO };
|
||||
raster.polygonMode = VK_POLYGON_MODE_FILL;
|
||||
raster.cullMode = VK_CULL_MODE_NONE;
|
||||
raster.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
|
||||
@ -747,19 +783,22 @@ bool Pass::init_pipeline()
|
||||
|
||||
// Blend state
|
||||
VkPipelineColorBlendAttachmentState blend_attachment = {0};
|
||||
VkPipelineColorBlendStateCreateInfo blend = { VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO };
|
||||
VkPipelineColorBlendStateCreateInfo blend = {
|
||||
VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO };
|
||||
blend_attachment.blendEnable = false;
|
||||
blend_attachment.colorWriteMask = 0xf;
|
||||
blend.attachmentCount = 1;
|
||||
blend.pAttachments = &blend_attachment;
|
||||
|
||||
// Viewport state
|
||||
VkPipelineViewportStateCreateInfo viewport = { VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO };
|
||||
VkPipelineViewportStateCreateInfo viewport = {
|
||||
VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO };
|
||||
viewport.viewportCount = 1;
|
||||
viewport.scissorCount = 1;
|
||||
|
||||
// Depth-stencil state
|
||||
VkPipelineDepthStencilStateCreateInfo depth_stencil = { VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO };
|
||||
VkPipelineDepthStencilStateCreateInfo depth_stencil = {
|
||||
VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO };
|
||||
depth_stencil.depthTestEnable = false;
|
||||
depth_stencil.depthWriteEnable = false;
|
||||
depth_stencil.depthBoundsTestEnable = false;
|
||||
@ -768,12 +807,15 @@ bool Pass::init_pipeline()
|
||||
depth_stencil.maxDepthBounds = 1.0f;
|
||||
|
||||
// Multisample state
|
||||
VkPipelineMultisampleStateCreateInfo multisample = { VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO };
|
||||
VkPipelineMultisampleStateCreateInfo multisample = {
|
||||
VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO };
|
||||
multisample.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
|
||||
|
||||
// Dynamic state
|
||||
VkPipelineDynamicStateCreateInfo dynamic = { VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO };
|
||||
static const VkDynamicState dynamics[] = { VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR };
|
||||
VkPipelineDynamicStateCreateInfo dynamic = {
|
||||
VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO };
|
||||
static const VkDynamicState dynamics[] = {
|
||||
VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR };
|
||||
dynamic.pDynamicStates = dynamics;
|
||||
dynamic.dynamicStateCount = sizeof(dynamics) / sizeof(dynamics[0]);
|
||||
|
||||
@ -783,7 +825,8 @@ bool Pass::init_pipeline()
|
||||
{ VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO },
|
||||
};
|
||||
|
||||
VkShaderModuleCreateInfo module_info = { VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO };
|
||||
VkShaderModuleCreateInfo module_info = {
|
||||
VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO };
|
||||
module_info.codeSize = vertex_shader.size() * sizeof(uint32_t);
|
||||
module_info.pCode = vertex_shader.data();
|
||||
shader_stages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
|
||||
@ -796,7 +839,8 @@ bool Pass::init_pipeline()
|
||||
shader_stages[1].pName = "main";
|
||||
vkCreateShaderModule(device, &module_info, NULL, &shader_stages[1].module);
|
||||
|
||||
VkGraphicsPipelineCreateInfo pipe = { VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO };
|
||||
VkGraphicsPipelineCreateInfo pipe = {
|
||||
VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO };
|
||||
pipe.stageCount = 2;
|
||||
pipe.pStages = shader_stages;
|
||||
pipe.pVertexInputState = &vertex_input;
|
||||
@ -807,10 +851,12 @@ bool Pass::init_pipeline()
|
||||
pipe.pViewportState = &viewport;
|
||||
pipe.pDepthStencilState = &depth_stencil;
|
||||
pipe.pDynamicState = &dynamic;
|
||||
pipe.renderPass = final_pass ? swapchain_render_pass : framebuffer->get_render_pass();
|
||||
pipe.renderPass = final_pass ? swapchain_render_pass :
|
||||
framebuffer->get_render_pass();
|
||||
pipe.layout = pipeline_layout;
|
||||
|
||||
if (vkCreateGraphicsPipelines(device, cache, 1, &pipe, NULL, &pipeline) != VK_SUCCESS)
|
||||
if (vkCreateGraphicsPipelines(device,
|
||||
cache, 1, &pipe, NULL, &pipeline) != VK_SUCCESS)
|
||||
{
|
||||
vkDestroyShaderModule(device, shader_stages[0].module, NULL);
|
||||
vkDestroyShaderModule(device, shader_stages[1].module, NULL);
|
||||
@ -839,13 +885,15 @@ bool Pass::init_samplers()
|
||||
info.unnormalizedCoordinates = false;
|
||||
info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
|
||||
|
||||
if (vkCreateSampler(device, &info, NULL, &samplers[VULKAN_FILTER_CHAIN_NEAREST]) != VK_SUCCESS)
|
||||
if (vkCreateSampler(device,
|
||||
&info, NULL, &samplers[VULKAN_FILTER_CHAIN_NEAREST]) != VK_SUCCESS)
|
||||
return false;
|
||||
|
||||
info.magFilter = VK_FILTER_LINEAR;
|
||||
info.minFilter = VK_FILTER_LINEAR;
|
||||
|
||||
if (vkCreateSampler(device, &info, NULL, &samplers[VULKAN_FILTER_CHAIN_LINEAR]) != VK_SUCCESS)
|
||||
if (vkCreateSampler(device,
|
||||
&info, NULL, &samplers[VULKAN_FILTER_CHAIN_LINEAR]) != VK_SUCCESS)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
@ -853,6 +901,7 @@ bool Pass::init_samplers()
|
||||
|
||||
bool Pass::init_buffers()
|
||||
{
|
||||
unsigned i;
|
||||
// The final pass uses an MVP designed for [0, 1] range VBO.
|
||||
// For in-between passes, we just go with identity matrices, so keep it simple.
|
||||
float pos_min = final_pass ? 0.0f : -1.0f;
|
||||
@ -865,9 +914,11 @@ bool Pass::init_buffers()
|
||||
};
|
||||
|
||||
ubos.clear();
|
||||
for (unsigned i = 0; i < num_sync_indices; i++)
|
||||
ubos.emplace_back(new Buffer(device, memory_properties, sizeof(UBO), VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT));
|
||||
vbo = unique_ptr<Buffer>(new Buffer(device, memory_properties, sizeof(vbo_data), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT));
|
||||
for (i = 0; i < num_sync_indices; i++)
|
||||
ubos.emplace_back(new Buffer(device,
|
||||
memory_properties, sizeof(UBO), VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT));
|
||||
vbo = unique_ptr<Buffer>(new Buffer(device,
|
||||
memory_properties, sizeof(vbo_data), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT));
|
||||
|
||||
void *ptr = vbo->map();
|
||||
memcpy(ptr, vbo_data, sizeof(vbo_data));
|
||||
@ -880,7 +931,8 @@ bool Pass::build()
|
||||
if (!final_pass)
|
||||
{
|
||||
framebuffer = unique_ptr<Framebuffer>(
|
||||
new Framebuffer(device, memory_properties, current_framebuffer_size,
|
||||
new Framebuffer(device, memory_properties,
|
||||
current_framebuffer_size,
|
||||
pass_info.rt_format));
|
||||
}
|
||||
|
||||
@ -966,7 +1018,8 @@ void Pass::update_descriptor_set(
|
||||
const Texture &original,
|
||||
const Texture &source)
|
||||
{
|
||||
set_uniform_buffer(sets[sync_index], 0, ubos[sync_index]->get_buffer(), 0, sizeof(UBO));
|
||||
set_uniform_buffer(sets[sync_index], 0,
|
||||
ubos[sync_index]->get_buffer(), 0, sizeof(UBO));
|
||||
set_texture(sets[sync_index], 1, original);
|
||||
set_texture(sets[sync_index], 2, source);
|
||||
}
|
||||
@ -984,7 +1037,8 @@ void Pass::build_commands(
|
||||
{ original.texture.width, original.texture.height },
|
||||
{ source.texture.width, source.texture.height });
|
||||
|
||||
if (size.width != current_framebuffer_size.width || size.height != current_framebuffer_size.height)
|
||||
if ( size.width != current_framebuffer_size.width
|
||||
|| size.height != current_framebuffer_size.height)
|
||||
{
|
||||
if (framebuffer)
|
||||
framebuffer->set_size(disposer, size);
|
||||
@ -997,25 +1051,35 @@ void Pass::build_commands(
|
||||
memcpy(u->MVP, mvp, sizeof(float) * 16);
|
||||
else
|
||||
build_identity_matrix(u->MVP);
|
||||
build_vec4(u->output_size, current_framebuffer_size.width, current_framebuffer_size.height);
|
||||
build_vec4(u->original_size, original.texture.width, original.texture.height);
|
||||
build_vec4(u->source_size, source.texture.width, source.texture.height);
|
||||
build_vec4(u->output_size,
|
||||
current_framebuffer_size.width,
|
||||
current_framebuffer_size.height);
|
||||
build_vec4(u->original_size,
|
||||
original.texture.width, original.texture.height);
|
||||
build_vec4(u->source_size,
|
||||
source.texture.width, source.texture.height);
|
||||
ubos[sync_index]->unmap();
|
||||
|
||||
update_descriptor_set(original, source);
|
||||
|
||||
// The final pass is always executed inside another render pass since
|
||||
// the frontend will want to overlay various things on top for the passes that end
|
||||
// up on-screen.
|
||||
// The final pass is always executed inside
|
||||
// another render pass since the frontend will
|
||||
// want to overlay various things on top for
|
||||
// the passes that end up on-screen.
|
||||
if (!final_pass)
|
||||
{
|
||||
// Render.
|
||||
image_layout_transition(device, cmd, framebuffer->get_image(),
|
||||
VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
|
||||
VK_ACCESS_SHADER_READ_BIT, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
|
||||
VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT);
|
||||
image_layout_transition(device, cmd,
|
||||
framebuffer->get_image(),
|
||||
VK_IMAGE_LAYOUT_UNDEFINED,
|
||||
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
|
||||
VK_ACCESS_SHADER_READ_BIT,
|
||||
VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
|
||||
VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
|
||||
VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT);
|
||||
|
||||
VkRenderPassBeginInfo rp_info = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO };
|
||||
VkRenderPassBeginInfo rp_info = {
|
||||
VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO };
|
||||
VkClearValue clear_value;
|
||||
clear_value.color.float32[0] = 0.0f;
|
||||
clear_value.color.float32[1] = 0.0f;
|
||||
@ -1040,8 +1104,14 @@ void Pass::build_commands(
|
||||
if (final_pass)
|
||||
{
|
||||
const VkRect2D sci = {
|
||||
{ int32_t(current_viewport.x), int32_t(current_viewport.y) },
|
||||
{ uint32_t(current_viewport.width), uint32_t(current_viewport.height) },
|
||||
{
|
||||
int32_t(current_viewport.x),
|
||||
int32_t(current_viewport.y)
|
||||
},
|
||||
{
|
||||
uint32_t(current_viewport.width),
|
||||
uint32_t(current_viewport.height)
|
||||
},
|
||||
};
|
||||
vkCmdSetViewport(cmd, 0, 1, ¤t_viewport);
|
||||
vkCmdSetScissor(cmd, 0, 1, &sci);
|
||||
@ -1050,12 +1120,16 @@ void Pass::build_commands(
|
||||
{
|
||||
const VkViewport vp = {
|
||||
0.0f, 0.0f,
|
||||
float(current_framebuffer_size.width), float(current_framebuffer_size.height),
|
||||
float(current_framebuffer_size.width),
|
||||
float(current_framebuffer_size.height),
|
||||
0.0f, 1.0f
|
||||
};
|
||||
const VkRect2D sci = {
|
||||
{ 0, 0 },
|
||||
{ current_framebuffer_size.width, current_framebuffer_size.height },
|
||||
{
|
||||
current_framebuffer_size.width,
|
||||
current_framebuffer_size.height
|
||||
},
|
||||
};
|
||||
|
||||
vkCmdSetViewport(cmd, 0, 1, &vp);
|
||||
@ -1069,27 +1143,37 @@ void Pass::build_commands(
|
||||
vkCmdEndRenderPass(cmd);
|
||||
|
||||
// Barrier to sync with next pass.
|
||||
image_layout_transition(device, cmd, framebuffer->get_image(),
|
||||
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
|
||||
VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_SHADER_READ_BIT,
|
||||
VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
||||
image_layout_transition(
|
||||
device,
|
||||
cmd,
|
||||
framebuffer->get_image(),
|
||||
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
|
||||
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
|
||||
VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
|
||||
VK_ACCESS_SHADER_READ_BIT,
|
||||
VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT,
|
||||
VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
||||
}
|
||||
}
|
||||
|
||||
Framebuffer::Framebuffer(VkDevice device, const VkPhysicalDeviceMemoryProperties &mem_props,
|
||||
Framebuffer::Framebuffer(
|
||||
VkDevice device,
|
||||
const VkPhysicalDeviceMemoryProperties &mem_props,
|
||||
const Size2D &max_size, VkFormat format) :
|
||||
device(device),
|
||||
memory_properties(mem_props),
|
||||
size(max_size),
|
||||
format(format)
|
||||
{
|
||||
RARCH_LOG("[Vulkan filter chain]: Creating framebuffer %u x %u.\n", max_size.width, max_size.height);
|
||||
RARCH_LOG("[Vulkan filter chain]: Creating framebuffer %u x %u.\n",
|
||||
max_size.width, max_size.height);
|
||||
init_render_pass();
|
||||
init(nullptr);
|
||||
}
|
||||
|
||||
void Framebuffer::init(DeferredDisposer *disposer)
|
||||
{
|
||||
VkMemoryRequirements mem_reqs;
|
||||
VkImageCreateInfo info = { VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO };
|
||||
info.imageType = VK_IMAGE_TYPE_2D;
|
||||
info.format = format;
|
||||
@ -1100,17 +1184,18 @@ void Framebuffer::init(DeferredDisposer *disposer)
|
||||
info.arrayLayers = 1;
|
||||
info.samples = VK_SAMPLE_COUNT_1_BIT;
|
||||
info.tiling = VK_IMAGE_TILING_OPTIMAL;
|
||||
info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
|
||||
info.usage = VK_IMAGE_USAGE_SAMPLED_BIT |
|
||||
VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
|
||||
info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
|
||||
info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||
vkCreateImage(device, &info, nullptr, &image);
|
||||
|
||||
VkMemoryRequirements mem_reqs;
|
||||
vkGetImageMemoryRequirements(device, image, &mem_reqs);
|
||||
|
||||
VkMemoryAllocateInfo alloc = { VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO };
|
||||
alloc.allocationSize = mem_reqs.size;
|
||||
alloc.memoryTypeIndex = find_memory_type_fallback(memory_properties, mem_reqs.memoryTypeBits,
|
||||
alloc.memoryTypeIndex = find_memory_type_fallback(
|
||||
memory_properties, mem_reqs.memoryTypeBits,
|
||||
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
|
||||
|
||||
// Can reuse already allocated memory.
|
||||
@ -1132,7 +1217,8 @@ void Framebuffer::init(DeferredDisposer *disposer)
|
||||
|
||||
vkBindImageMemory(device, image, memory.memory, 0);
|
||||
|
||||
VkImageViewCreateInfo view_info = { VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO };
|
||||
VkImageViewCreateInfo view_info = {
|
||||
VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO };
|
||||
view_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
|
||||
view_info.format = format;
|
||||
view_info.image = image;
|
||||
@ -1152,8 +1238,10 @@ void Framebuffer::init(DeferredDisposer *disposer)
|
||||
|
||||
void Framebuffer::init_render_pass()
|
||||
{
|
||||
VkRenderPassCreateInfo rp_info = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO };
|
||||
VkAttachmentReference color_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
|
||||
VkRenderPassCreateInfo rp_info = {
|
||||
VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO };
|
||||
VkAttachmentReference color_ref = { 0,
|
||||
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
|
||||
|
||||
// We will always write to the entire framebuffer,
|
||||
// so we don't really need to clear.
|
||||
@ -1183,7 +1271,8 @@ void Framebuffer::init_render_pass()
|
||||
|
||||
void Framebuffer::init_framebuffer()
|
||||
{
|
||||
VkFramebufferCreateInfo info = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO };
|
||||
VkFramebufferCreateInfo info = {
|
||||
VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO };
|
||||
info.renderPass = render_pass;
|
||||
info.attachmentCount = 1;
|
||||
info.pAttachments = &view;
|
||||
@ -1198,7 +1287,8 @@ void Framebuffer::set_size(DeferredDisposer &disposer, const Size2D &size)
|
||||
{
|
||||
this->size = size;
|
||||
|
||||
RARCH_LOG("[Vulkan filter chain]: Updating framebuffer size %u x %u.\n", size.width, size.height);
|
||||
RARCH_LOG("[Vulkan filter chain]: Updating framebuffer size %u x %u.\n",
|
||||
size.width, size.height);
|
||||
|
||||
{
|
||||
// The current framebuffers, etc, might still be in use
|
||||
@ -1247,8 +1337,11 @@ vulkan_filter_chain_t *vulkan_filter_chain_new(
|
||||
return new vulkan_filter_chain(*info);
|
||||
}
|
||||
|
||||
vulkan_filter_chain_t *vulkan_filter_chain_create_default(const struct vulkan_filter_chain_create_info *info, vulkan_filter_chain_filter filter)
|
||||
vulkan_filter_chain_t *vulkan_filter_chain_create_default(
|
||||
const struct vulkan_filter_chain_create_info *info,
|
||||
vulkan_filter_chain_filter filter)
|
||||
{
|
||||
struct vulkan_filter_chain_pass_info pass_info;
|
||||
auto tmpinfo = *info;
|
||||
tmpinfo.num_passes = 1;
|
||||
|
||||
@ -1256,7 +1349,6 @@ vulkan_filter_chain_t *vulkan_filter_chain_create_default(const struct vulkan_fi
|
||||
if (!chain)
|
||||
return nullptr;
|
||||
|
||||
struct vulkan_filter_chain_pass_info pass_info;
|
||||
memset(&pass_info, 0, sizeof(pass_info));
|
||||
pass_info.scale_type_x = VULKAN_FILTER_CHAIN_SCALE_VIEWPORT;
|
||||
pass_info.scale_type_y = VULKAN_FILTER_CHAIN_SCALE_VIEWPORT;
|
||||
@ -1266,8 +1358,12 @@ vulkan_filter_chain_t *vulkan_filter_chain_create_default(const struct vulkan_fi
|
||||
pass_info.source_filter = filter;
|
||||
chain->set_pass_info(0, pass_info);
|
||||
|
||||
chain->set_shader(0, VK_SHADER_STAGE_VERTEX_BIT, (const uint32_t*)opaque_vert_spv, opaque_vert_spv_len / sizeof(uint32_t));
|
||||
chain->set_shader(0, VK_SHADER_STAGE_FRAGMENT_BIT, (const uint32_t*)opaque_frag_spv, opaque_frag_spv_len / sizeof(uint32_t));
|
||||
chain->set_shader(0, VK_SHADER_STAGE_VERTEX_BIT,
|
||||
(const uint32_t*)opaque_vert_spv,
|
||||
opaque_vert_spv_len / sizeof(uint32_t));
|
||||
chain->set_shader(0, VK_SHADER_STAGE_FRAGMENT_BIT,
|
||||
(const uint32_t*)opaque_frag_spv,
|
||||
opaque_frag_spv_len / sizeof(uint32_t));
|
||||
|
||||
if (!chain->init())
|
||||
return nullptr;
|
||||
@ -1284,7 +1380,8 @@ struct ConfigDeleter
|
||||
}
|
||||
};
|
||||
|
||||
vulkan_filter_chain_t *vulkan_filter_chain_create_from_preset(const struct vulkan_filter_chain_create_info *info,
|
||||
vulkan_filter_chain_t *vulkan_filter_chain_create_from_preset(
|
||||
const struct vulkan_filter_chain_create_info *info,
|
||||
const char *path, vulkan_filter_chain_filter filter)
|
||||
{
|
||||
unique_ptr<video_shader> shader{ new video_shader() };
|
||||
@ -1318,7 +1415,8 @@ vulkan_filter_chain_t *vulkan_filter_chain_create_from_preset(const struct vulka
|
||||
glslang_output output;
|
||||
if (!glslang_compile_shader(pass->source.path, &output))
|
||||
{
|
||||
RARCH_ERR("Failed to compile shader: \"%s\".\n", pass->source.path);
|
||||
RARCH_ERR("Failed to compile shader: \"%s\".\n",
|
||||
pass->source.path);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -1343,11 +1441,17 @@ vulkan_filter_chain_t *vulkan_filter_chain_create_from_preset(const struct vulka
|
||||
|
||||
if (!pass->fbo.valid)
|
||||
{
|
||||
pass_info.scale_type_x = i + 1 == shader->passes ? VULKAN_FILTER_CHAIN_SCALE_VIEWPORT : VULKAN_FILTER_CHAIN_SCALE_SOURCE;
|
||||
pass_info.scale_type_y = i + 1 == shader->passes ? VULKAN_FILTER_CHAIN_SCALE_VIEWPORT : VULKAN_FILTER_CHAIN_SCALE_SOURCE;
|
||||
pass_info.scale_type_x = i + 1 == shader->passes
|
||||
? VULKAN_FILTER_CHAIN_SCALE_VIEWPORT
|
||||
: VULKAN_FILTER_CHAIN_SCALE_SOURCE;
|
||||
pass_info.scale_type_y = i + 1 == shader->passes
|
||||
? VULKAN_FILTER_CHAIN_SCALE_VIEWPORT
|
||||
: VULKAN_FILTER_CHAIN_SCALE_SOURCE;
|
||||
pass_info.scale_x = 1.0f;
|
||||
pass_info.scale_y = 1.0f;
|
||||
pass_info.rt_format = i + 1 == shader->passes ? tmpinfo.swapchain.format : VK_FORMAT_R8G8B8A8_UNORM;
|
||||
pass_info.rt_format = i + 1 == shader->passes
|
||||
? tmpinfo.swapchain.format
|
||||
: VK_FORMAT_R8G8B8A8_UNORM;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1429,17 +1533,20 @@ vulkan_filter_chain_t *vulkan_filter_chain_create_from_preset(const struct vulka
|
||||
return chain.release();
|
||||
}
|
||||
|
||||
struct video_shader *vulkan_filter_chain_get_preset(vulkan_filter_chain_t *chain)
|
||||
struct video_shader *vulkan_filter_chain_get_preset(
|
||||
vulkan_filter_chain_t *chain)
|
||||
{
|
||||
return chain->get_shader_preset();
|
||||
}
|
||||
|
||||
void vulkan_filter_chain_free(vulkan_filter_chain_t *chain)
|
||||
void vulkan_filter_chain_free(
|
||||
vulkan_filter_chain_t *chain)
|
||||
{
|
||||
delete chain;
|
||||
}
|
||||
|
||||
void vulkan_filter_chain_set_shader(vulkan_filter_chain_t *chain,
|
||||
void vulkan_filter_chain_set_shader(
|
||||
vulkan_filter_chain_t *chain,
|
||||
unsigned pass,
|
||||
VkShaderStageFlags stage,
|
||||
const uint32_t *spirv,
|
||||
@ -1448,20 +1555,23 @@ void vulkan_filter_chain_set_shader(vulkan_filter_chain_t *chain,
|
||||
chain->set_shader(pass, stage, spirv, spirv_words);
|
||||
}
|
||||
|
||||
void vulkan_filter_chain_set_pass_info(vulkan_filter_chain_t *chain,
|
||||
void vulkan_filter_chain_set_pass_info(
|
||||
vulkan_filter_chain_t *chain,
|
||||
unsigned pass,
|
||||
const struct vulkan_filter_chain_pass_info *info)
|
||||
{
|
||||
chain->set_pass_info(pass, *info);
|
||||
}
|
||||
|
||||
bool vulkan_filter_chain_update_swapchain_info(vulkan_filter_chain_t *chain,
|
||||
bool vulkan_filter_chain_update_swapchain_info(
|
||||
vulkan_filter_chain_t *chain,
|
||||
const vulkan_filter_chain_swapchain_info *info)
|
||||
{
|
||||
return chain->update_swapchain_info(*info);
|
||||
}
|
||||
|
||||
void vulkan_filter_chain_notify_sync_index(vulkan_filter_chain_t *chain,
|
||||
void vulkan_filter_chain_notify_sync_index(
|
||||
vulkan_filter_chain_t *chain,
|
||||
unsigned index)
|
||||
{
|
||||
chain->notify_sync_index(index);
|
||||
@ -1472,19 +1582,22 @@ bool vulkan_filter_chain_init(vulkan_filter_chain_t *chain)
|
||||
return chain->init();
|
||||
}
|
||||
|
||||
void vulkan_filter_chain_set_input_texture(vulkan_filter_chain_t *chain,
|
||||
void vulkan_filter_chain_set_input_texture(
|
||||
vulkan_filter_chain_t *chain,
|
||||
const struct vulkan_filter_chain_texture *texture)
|
||||
{
|
||||
chain->set_input_texture(*texture);
|
||||
}
|
||||
|
||||
void vulkan_filter_chain_build_offscreen_passes(vulkan_filter_chain_t *chain,
|
||||
void vulkan_filter_chain_build_offscreen_passes(
|
||||
vulkan_filter_chain_t *chain,
|
||||
VkCommandBuffer cmd, const VkViewport *vp)
|
||||
{
|
||||
chain->build_offscreen_passes(cmd, *vp);
|
||||
}
|
||||
|
||||
void vulkan_filter_chain_build_viewport_pass(vulkan_filter_chain_t *chain,
|
||||
void vulkan_filter_chain_build_viewport_pass(
|
||||
vulkan_filter_chain_t *chain,
|
||||
VkCommandBuffer cmd, const VkViewport *vp, const float *mvp)
|
||||
{
|
||||
chain->build_viewport_pass(cmd, *vp, mvp);
|
||||
|
Loading…
x
Reference in New Issue
Block a user