early-access version 1462

This commit is contained in:
pineappleEA
2021-02-15 20:21:49 +01:00
parent b0a8cbc743
commit 23023e6b7e
7 changed files with 351 additions and 46 deletions

View File

@@ -399,9 +399,7 @@ void AttachTexture(GLuint fbo, GLenum attachment, const ImageView* image_view) {
[[nodiscard]] bool IsPixelFormatBGR(PixelFormat format) {
switch (format) {
// TODO: B5G6R5 is currently not rendering after the compute copy.
// uncomment when this is resolved.
// case PixelFormat::B5G6R5_UNORM:
case PixelFormat::B5G6R5_UNORM:
case PixelFormat::B8G8R8A8_UNORM:
case PixelFormat::B8G8R8A8_SRGB:
return true;
@@ -410,16 +408,6 @@ void AttachTexture(GLuint fbo, GLenum attachment, const ImageView* image_view) {
}
}
[[nodiscard]] GLenum GetStorageInternalFormat(PixelFormat format) {
switch (format) {
case PixelFormat::R5G6B5_UNORM:
case PixelFormat::B5G6R5_UNORM:
return GL_RGB565;
default:
return GL_RGBA8;
}
}
} // Anonymous namespace
ImageBufferMap::~ImageBufferMap() {
@@ -803,8 +791,6 @@ GLuint Image::StorageHandle() noexcept {
switch (info.format) {
case PixelFormat::A8B8G8R8_SRGB:
case PixelFormat::B8G8R8A8_SRGB:
case PixelFormat::R5G6B5_UNORM:
case PixelFormat::B5G6R5_UNORM:
case PixelFormat::BC1_RGBA_SRGB:
case PixelFormat::BC2_SRGB:
case PixelFormat::BC3_SRGB:
@@ -824,9 +810,8 @@ GLuint Image::StorageHandle() noexcept {
return store_view.handle;
}
store_view.Create();
glTextureView(store_view.handle, ImageTarget(info), texture.handle,
GetStorageInternalFormat(info.format), 0, info.resources.levels, 0,
info.resources.layers);
glTextureView(store_view.handle, ImageTarget(info), texture.handle, GL_RGBA8, 0,
info.resources.levels, 0, info.resources.layers);
return store_view.handle;
default:
return texture.handle;

View File

@@ -40,7 +40,6 @@ using VideoCommon::SwizzleParameters;
using VideoCommon::Accelerated::MakeBlockLinearSwizzle2DParams;
using VideoCommon::Accelerated::MakeBlockLinearSwizzle3DParams;
using VideoCore::Surface::BytesPerBlock;
using VideoCore::Surface::PixelFormat;
namespace {
@@ -286,24 +285,29 @@ void UtilShaders::CopyBGR(Image& dst_image, Image& src_image,
std::span<const VideoCommon::ImageCopy> copies) {
static constexpr GLuint BINDING_INPUT_IMAGE = 0;
static constexpr GLuint BINDING_OUTPUT_IMAGE = 1;
GLenum format{};
static constexpr VideoCommon::Offset3D zero_offset{0, 0, 0};
const u32 bytes_per_block = BytesPerBlock(dst_image.info.format);
if (bytes_per_block == 2) {
// BGR565 Copy
program_manager.BindHostCompute(copy_bgr16_program.handle);
format = GL_R16UI;
for (const ImageCopy& copy : copies) {
ASSERT(copy.src_offset == zero_offset);
ASSERT(copy.dst_offset == zero_offset);
bgr_copy_pass.Execute(dst_image, src_image, copy);
}
} else if (bytes_per_block == 4) {
// BGRA8 Copy
program_manager.BindHostCompute(copy_bgra_program.handle);
format = GL_RGBA8;
}
for (const ImageCopy& copy : copies) {
glBindImageTexture(BINDING_INPUT_IMAGE, src_image.StorageHandle(),
copy.src_subresource.base_level, GL_FALSE, 0, GL_READ_ONLY, format);
glBindImageTexture(BINDING_OUTPUT_IMAGE, dst_image.StorageHandle(),
copy.dst_subresource.base_level, GL_FALSE, 0, GL_WRITE_ONLY, format);
glDispatchCompute(copy.extent.width, copy.extent.height, copy.extent.depth);
constexpr GLenum format = GL_RGBA8;
for (const ImageCopy& copy : copies) {
ASSERT(copy.src_offset == zero_offset);
ASSERT(copy.dst_offset == zero_offset);
glBindImageTexture(BINDING_INPUT_IMAGE, src_image.StorageHandle(),
copy.src_subresource.base_level, GL_FALSE, 0, GL_READ_ONLY, format);
glBindImageTexture(BINDING_OUTPUT_IMAGE, dst_image.StorageHandle(),
copy.dst_subresource.base_level, GL_FALSE, 0, GL_WRITE_ONLY, format);
glDispatchCompute(copy.extent.width, copy.extent.height, copy.extent.depth);
}
}
program_manager.RestoreGuestCompute();
}
@@ -325,4 +329,56 @@ GLenum StoreFormat(u32 bytes_per_block) {
return GL_R8UI;
}
void Bgr565CopyPass::Execute(const Image& dst_image, const Image& src_image,
const ImageCopy& copy) {
static constexpr GLuint BINDING_INPUT_IMAGE = 0;
static constexpr GLenum format = GL_RGB565;
static constexpr GLenum target = GL_TEXTURE_2D_ARRAY;
if (CopyBufferCreationNeeded(copy)) {
CreateNewCopyBuffer(copy, target, format);
}
// Copy from source to PBO
glMemoryBarrier(GL_PIXEL_BUFFER_BARRIER_BIT);
glPixelStorei(GL_PACK_ALIGNMENT, 1);
glBindBuffer(GL_PIXEL_PACK_BUFFER, bgr16_pbo.handle);
glBindTexture(target, src_image.Handle());
glFinish();
glPixelStorei(GL_PACK_ROW_LENGTH, copy.extent.width);
glGetTextureSubImage(src_image.Handle(), 0, 0, 0, 0, copy.extent.width, copy.extent.height,
copy.src_subresource.num_layers, GL_RGB, GL_UNSIGNED_SHORT_5_6_5,
static_cast<GLsizei>(bgr16_pbo_size), 0);
// Swizzle PBO in compute shader
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, BINDING_INPUT_IMAGE, bgr16_pbo.handle);
glDispatchCompute(copy.extent.width, copy.extent.height, copy.extent.depth);
// Copy from PBO to destination
glMemoryBarrier(GL_PIXEL_BUFFER_BARRIER_BIT);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, bgr16_pbo.handle);
glBindTexture(target, dst_image.Handle());
glPixelStorei(GL_UNPACK_ROW_LENGTH, copy.extent.width);
glTextureSubImage3D(dst_image.Handle(), 0, 0, 0, 0, copy.extent.width, copy.extent.height,
copy.dst_subresource.num_layers, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, 0);
// Unbind the buffer
glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
}
bool Bgr565CopyPass::CopyBufferCreationNeeded(const ImageCopy& copy) {
return bgr16_pbo_size <
(copy.extent.width * copy.extent.height * copy.src_subresource.num_layers * sizeof(u16));
}
void Bgr565CopyPass::CreateNewCopyBuffer(const ImageCopy& copy, GLenum target, GLuint format) {
bgr16_pbo.Release();
bgr16_pbo.Create();
bgr16_pbo_size =
(copy.extent.width * copy.extent.height * copy.src_subresource.num_layers * sizeof(u16));
glBindBuffer(GL_PIXEL_PACK_BUFFER, bgr16_pbo.handle);
glBufferData(GL_PIXEL_PACK_BUFFER, bgr16_pbo_size, 0, GL_STREAM_DRAW);
}
} // namespace OpenGL

View File

@@ -19,6 +19,23 @@ class ProgramManager;
struct ImageBufferMap;
class Bgr565CopyPass {
public:
Bgr565CopyPass() = default;
~Bgr565CopyPass() = default;
void Execute(const Image& dst_image, const Image& src_image,
const VideoCommon::ImageCopy& copy);
private:
OGLBuffer bgr16_pbo{};
size_t bgr16_pbo_size{};
[[nodiscard]] bool CopyBufferCreationNeeded(const VideoCommon::ImageCopy& copy);
void CreateNewCopyBuffer(const VideoCommon::ImageCopy& copy, GLenum target, GLuint format);
};
class UtilShaders {
public:
explicit UtilShaders(ProgramManager& program_manager);
@@ -55,6 +72,8 @@ private:
OGLProgram copy_bgr16_program;
OGLProgram copy_bgra_program;
OGLProgram copy_bc4_program;
Bgr565CopyPass bgr_copy_pass;
};
GLenum StoreFormat(u32 bytes_per_block);