shader: Properly scale image reads and add GL SPIR-V support

Thanks for everything!
This commit is contained in:
ReinUsesLisp 2021-08-01 18:57:45 -03:00 committed by Fernando Sahmkow
parent fc9bb3c3fe
commit e66d5b88a6
25 changed files with 228 additions and 77 deletions

View file

@ -5,6 +5,7 @@
#include <algorithm>
#include <span>
#include "shader_recompiler/backend/glasm/emit_glasm.h"
#include "video_core/buffer_cache/buffer_cache.h"
#include "video_core/renderer_opengl/gl_buffer_cache.h"
#include "video_core/renderer_opengl/gl_device.h"
@ -229,8 +230,10 @@ void BufferCacheRuntime::BindStorageBuffer(size_t stage, u32 binding_index, Buff
.padding = 0,
};
buffer.MakeResident(is_written ? GL_READ_WRITE : GL_READ_ONLY);
glProgramLocalParametersI4uivNV(PROGRAM_LUT[stage], binding_index, 1,
reinterpret_cast<const GLuint*>(&ssbo));
glProgramLocalParametersI4uivNV(
PROGRAM_LUT[stage],
Shader::Backend::GLASM::PROGRAM_LOCAL_PARAMETER_STORAGE_BUFFER_BASE + binding_index, 1,
reinterpret_cast<const GLuint*>(&ssbo));
}
}
@ -250,8 +253,10 @@ void BufferCacheRuntime::BindComputeStorageBuffer(u32 binding_index, Buffer& buf
.padding = 0,
};
buffer.MakeResident(is_written ? GL_READ_WRITE : GL_READ_ONLY);
glProgramLocalParametersI4uivNV(GL_COMPUTE_PROGRAM_NV, binding_index, 1,
reinterpret_cast<const GLuint*>(&ssbo));
glProgramLocalParametersI4uivNV(
GL_COMPUTE_PROGRAM_NV,
Shader::Backend::GLASM::PROGRAM_LOCAL_PARAMETER_STORAGE_BUFFER_BASE + binding_index, 1,
reinterpret_cast<const GLuint*>(&ssbo));
}
}

View file

@ -181,33 +181,40 @@ void ComputePipeline::Configure() {
texture_binding += num_texture_buffers;
image_binding += num_image_buffers;
u32 scaling_mask{};
u32 texture_scaling_mask{};
for (const auto& desc : info.texture_descriptors) {
for (u32 index = 0; index < desc.count; ++index) {
ImageView& image_view{texture_cache.GetImageView((views_it++)->id)};
textures[texture_binding] = image_view.Handle(desc.type);
if (texture_cache.IsRescaling(image_view)) {
scaling_mask |= 1u << texture_binding;
texture_scaling_mask |= 1u << texture_binding;
}
++texture_binding;
}
}
u32 image_scaling_mask{};
for (const auto& desc : info.image_descriptors) {
for (u32 index = 0; index < desc.count; ++index) {
ImageView& image_view{texture_cache.GetImageView((views_it++)->id)};
if (desc.is_written) {
texture_cache.MarkModification(image_view.image_id);
}
images[image_binding++] = image_view.StorageView(desc.type, desc.format);
images[image_binding] = image_view.StorageView(desc.type, desc.format);
if (texture_cache.IsRescaling(image_view)) {
image_scaling_mask |= 1u << image_binding;
}
++image_binding;
}
}
if (info.uses_rescaling_uniform) {
const f32 float_scaling_mask{Common::BitCast<f32>(scaling_mask)};
const f32 float_texture_scaling_mask{Common::BitCast<f32>(texture_scaling_mask)};
const f32 float_image_scaling_mask{Common::BitCast<f32>(image_scaling_mask)};
if (assembly_program.handle != 0) {
glProgramLocalParameter4fARB(GL_COMPUTE_PROGRAM_NV, 0, float_scaling_mask, 0.0f, 0.0f,
0.0f);
glProgramLocalParameter4fARB(GL_COMPUTE_PROGRAM_NV, 0, float_texture_scaling_mask,
float_image_scaling_mask, 0.0f, 0.0f);
} else {
glProgramUniform4f(source_program.handle, 0, float_scaling_mask, 0.0f, 0.0f, 0.0f);
glProgramUniform4f(source_program.handle, 0, float_texture_scaling_mask,
float_image_scaling_mask, 0.0f, 0.0f);
}
}
if (texture_binding != 0) {

View file

@ -464,8 +464,10 @@ void GraphicsPipeline::ConfigureImpl(bool is_indexed) {
views_it += num_texture_buffers[stage];
views_it += num_image_buffers[stage];
u32 scaling_mask{};
u32 texture_scaling_mask{};
u32 image_scaling_mask{};
u32 stage_texture_binding{};
u32 stage_image_binding{};
const auto& info{stage_infos[stage]};
for (const auto& desc : info.texture_descriptors) {
@ -473,7 +475,7 @@ void GraphicsPipeline::ConfigureImpl(bool is_indexed) {
ImageView& image_view{texture_cache.GetImageView((views_it++)->id)};
textures[texture_binding] = image_view.Handle(desc.type);
if (texture_cache.IsRescaling(image_view)) {
scaling_mask |= 1u << stage_texture_binding;
texture_scaling_mask |= 1u << stage_texture_binding;
}
++texture_binding;
++stage_texture_binding;
@ -485,20 +487,26 @@ void GraphicsPipeline::ConfigureImpl(bool is_indexed) {
if (desc.is_written) {
texture_cache.MarkModification(image_view.image_id);
}
images[image_binding++] = image_view.StorageView(desc.type, desc.format);
images[image_binding] = image_view.StorageView(desc.type, desc.format);
if (texture_cache.IsRescaling(image_view)) {
image_scaling_mask |= 1u << stage_image_binding;
}
++image_binding;
++stage_image_binding;
}
}
if (info.uses_rescaling_uniform) {
const f32 float_scaling_mask{Common::BitCast<f32>(scaling_mask)};
const f32 float_texture_scaling_mask{Common::BitCast<f32>(texture_scaling_mask)};
const f32 float_image_scaling_mask{Common::BitCast<f32>(image_scaling_mask)};
const bool is_rescaling{texture_cache.IsRescaling()};
const f32 config_down_factor{Settings::values.resolution_info.down_factor};
const f32 down_factor{is_rescaling ? config_down_factor : 1.0f};
if (use_assembly) {
glProgramLocalParameter4fARB(AssemblyStage(stage), 0, float_scaling_mask,
down_factor, 0.0f, 0.0f);
glProgramLocalParameter4fARB(AssemblyStage(stage), 0, float_texture_scaling_mask,
float_image_scaling_mask, down_factor, 0.0f);
} else {
glProgramUniform4f(source_programs[stage].handle, 0, float_scaling_mask,
down_factor, 0.0f, 0.0f);
glProgramUniform4f(source_programs[stage].handle, 0, float_texture_scaling_mask,
float_image_scaling_mask, down_factor, 0.0f);
}
}
}};