Merge pull request #4967 from ReinUsesLisp/new-texcache
video_core/texture_cache: Rewrite the texture cachemaster
commit
d5fe722a30
@ -0,0 +1,32 @@
|
|||||||
|
// Copyright 2020 yuzu Emulator Project
|
||||||
|
// Licensed under GPLv2 or any later version
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
#include <cstddef>
|
||||||
|
#include <utility>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace VideoCommon {
|
||||||
|
|
||||||
|
/// Container to push objects to be destroyed a few ticks in the future
|
||||||
|
template <typename T, size_t TICKS_TO_DESTROY>
|
||||||
|
class DelayedDestructionRing {
|
||||||
|
public:
|
||||||
|
void Tick() {
|
||||||
|
index = (index + 1) % TICKS_TO_DESTROY;
|
||||||
|
elements[index].clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Push(T&& object) {
|
||||||
|
elements[index].push_back(std::move(object));
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
size_t index = 0;
|
||||||
|
std::array<std::vector<T>, TICKS_TO_DESTROY> elements;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace VideoCommon
|
@ -0,0 +1,122 @@
|
|||||||
|
// Copyright 2020 yuzu Emulator Project
|
||||||
|
// Licensed under GPLv2 or any later version
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#version 430
|
||||||
|
|
||||||
|
#ifdef VULKAN
|
||||||
|
|
||||||
|
#extension GL_EXT_shader_16bit_storage : require
|
||||||
|
#extension GL_EXT_shader_8bit_storage : require
|
||||||
|
#define HAS_EXTENDED_TYPES 1
|
||||||
|
#define BEGIN_PUSH_CONSTANTS layout(push_constant) uniform PushConstants {
|
||||||
|
#define END_PUSH_CONSTANTS };
|
||||||
|
#define UNIFORM(n)
|
||||||
|
#define BINDING_SWIZZLE_BUFFER 0
|
||||||
|
#define BINDING_INPUT_BUFFER 1
|
||||||
|
#define BINDING_OUTPUT_IMAGE 2
|
||||||
|
|
||||||
|
#else // ^^^ Vulkan ^^^ // vvv OpenGL vvv
|
||||||
|
|
||||||
|
#extension GL_NV_gpu_shader5 : enable
|
||||||
|
#ifdef GL_NV_gpu_shader5
|
||||||
|
#define HAS_EXTENDED_TYPES 1
|
||||||
|
#else
|
||||||
|
#define HAS_EXTENDED_TYPES 0
|
||||||
|
#endif
|
||||||
|
#define BEGIN_PUSH_CONSTANTS
|
||||||
|
#define END_PUSH_CONSTANTS
|
||||||
|
#define UNIFORM(n) layout (location = n) uniform
|
||||||
|
#define BINDING_SWIZZLE_BUFFER 0
|
||||||
|
#define BINDING_INPUT_BUFFER 1
|
||||||
|
#define BINDING_OUTPUT_IMAGE 0
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
BEGIN_PUSH_CONSTANTS
|
||||||
|
UNIFORM(0) uvec3 origin;
|
||||||
|
UNIFORM(1) ivec3 destination;
|
||||||
|
UNIFORM(2) uint bytes_per_block_log2;
|
||||||
|
UNIFORM(3) uint layer_stride;
|
||||||
|
UNIFORM(4) uint block_size;
|
||||||
|
UNIFORM(5) uint x_shift;
|
||||||
|
UNIFORM(6) uint block_height;
|
||||||
|
UNIFORM(7) uint block_height_mask;
|
||||||
|
END_PUSH_CONSTANTS
|
||||||
|
|
||||||
|
layout(binding = BINDING_SWIZZLE_BUFFER, std430) readonly buffer SwizzleTable {
|
||||||
|
uint swizzle_table[];
|
||||||
|
};
|
||||||
|
|
||||||
|
#if HAS_EXTENDED_TYPES
|
||||||
|
layout(binding = BINDING_INPUT_BUFFER, std430) buffer InputBufferU8 { uint8_t u8data[]; };
|
||||||
|
layout(binding = BINDING_INPUT_BUFFER, std430) buffer InputBufferU16 { uint16_t u16data[]; };
|
||||||
|
#endif
|
||||||
|
layout(binding = BINDING_INPUT_BUFFER, std430) buffer InputBufferU32 { uint u32data[]; };
|
||||||
|
layout(binding = BINDING_INPUT_BUFFER, std430) buffer InputBufferU64 { uvec2 u64data[]; };
|
||||||
|
layout(binding = BINDING_INPUT_BUFFER, std430) buffer InputBufferU128 { uvec4 u128data[]; };
|
||||||
|
|
||||||
|
layout(binding = BINDING_OUTPUT_IMAGE) uniform writeonly uimage2DArray output_image;
|
||||||
|
|
||||||
|
layout(local_size_x = 32, local_size_y = 32, local_size_z = 1) in;
|
||||||
|
|
||||||
|
const uint GOB_SIZE_X = 64;
|
||||||
|
const uint GOB_SIZE_Y = 8;
|
||||||
|
const uint GOB_SIZE_Z = 1;
|
||||||
|
const uint GOB_SIZE = GOB_SIZE_X * GOB_SIZE_Y * GOB_SIZE_Z;
|
||||||
|
|
||||||
|
const uint GOB_SIZE_X_SHIFT = 6;
|
||||||
|
const uint GOB_SIZE_Y_SHIFT = 3;
|
||||||
|
const uint GOB_SIZE_Z_SHIFT = 0;
|
||||||
|
const uint GOB_SIZE_SHIFT = GOB_SIZE_X_SHIFT + GOB_SIZE_Y_SHIFT + GOB_SIZE_Z_SHIFT;
|
||||||
|
|
||||||
|
const uvec2 SWIZZLE_MASK = uvec2(GOB_SIZE_X - 1, GOB_SIZE_Y - 1);
|
||||||
|
|
||||||
|
uint SwizzleOffset(uvec2 pos) {
|
||||||
|
pos = pos & SWIZZLE_MASK;
|
||||||
|
return swizzle_table[pos.y * 64 + pos.x];
|
||||||
|
}
|
||||||
|
|
||||||
|
uvec4 ReadTexel(uint offset) {
|
||||||
|
switch (bytes_per_block_log2) {
|
||||||
|
#if HAS_EXTENDED_TYPES
|
||||||
|
case 0:
|
||||||
|
return uvec4(u8data[offset], 0, 0, 0);
|
||||||
|
case 1:
|
||||||
|
return uvec4(u16data[offset / 2], 0, 0, 0);
|
||||||
|
#else
|
||||||
|
case 0:
|
||||||
|
return uvec4(bitfieldExtract(u32data[offset / 4], int((offset * 8) & 24), 8), 0, 0, 0);
|
||||||
|
case 1:
|
||||||
|
return uvec4(bitfieldExtract(u32data[offset / 4], int((offset * 8) & 16), 16), 0, 0, 0);
|
||||||
|
#endif
|
||||||
|
case 2:
|
||||||
|
return uvec4(u32data[offset / 4], 0, 0, 0);
|
||||||
|
case 3:
|
||||||
|
return uvec4(u64data[offset / 8], 0, 0);
|
||||||
|
case 4:
|
||||||
|
return u128data[offset / 16];
|
||||||
|
}
|
||||||
|
return uvec4(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
uvec3 pos = gl_GlobalInvocationID + origin;
|
||||||
|
pos.x <<= bytes_per_block_log2;
|
||||||
|
|
||||||
|
// Read as soon as possible due to its latency
|
||||||
|
const uint swizzle = SwizzleOffset(pos.xy);
|
||||||
|
|
||||||
|
const uint block_y = pos.y >> GOB_SIZE_Y_SHIFT;
|
||||||
|
|
||||||
|
uint offset = 0;
|
||||||
|
offset += pos.z * layer_stride;
|
||||||
|
offset += (block_y >> block_height) * block_size;
|
||||||
|
offset += (block_y & block_height_mask) << GOB_SIZE_SHIFT;
|
||||||
|
offset += (pos.x >> GOB_SIZE_X_SHIFT) << x_shift;
|
||||||
|
offset += swizzle;
|
||||||
|
|
||||||
|
const uvec4 texel = ReadTexel(offset);
|
||||||
|
const ivec3 coord = ivec3(gl_GlobalInvocationID) + destination;
|
||||||
|
imageStore(output_image, coord, texel);
|
||||||
|
}
|
@ -0,0 +1,125 @@
|
|||||||
|
// Copyright 2020 yuzu Emulator Project
|
||||||
|
// Licensed under GPLv2 or any later version
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#version 430
|
||||||
|
|
||||||
|
#ifdef VULKAN
|
||||||
|
|
||||||
|
#extension GL_EXT_shader_16bit_storage : require
|
||||||
|
#extension GL_EXT_shader_8bit_storage : require
|
||||||
|
#define HAS_EXTENDED_TYPES 1
|
||||||
|
#define BEGIN_PUSH_CONSTANTS layout(push_constant) uniform PushConstants {
|
||||||
|
#define END_PUSH_CONSTANTS };
|
||||||
|
#define UNIFORM(n)
|
||||||
|
#define BINDING_SWIZZLE_BUFFER 0
|
||||||
|
#define BINDING_INPUT_BUFFER 1
|
||||||
|
#define BINDING_OUTPUT_IMAGE 2
|
||||||
|
|
||||||
|
#else // ^^^ Vulkan ^^^ // vvv OpenGL vvv
|
||||||
|
|
||||||
|
#extension GL_NV_gpu_shader5 : enable
|
||||||
|
#ifdef GL_NV_gpu_shader5
|
||||||
|
#define HAS_EXTENDED_TYPES 1
|
||||||
|
#else
|
||||||
|
#define HAS_EXTENDED_TYPES 0
|
||||||
|
#endif
|
||||||
|
#define BEGIN_PUSH_CONSTANTS
|
||||||
|
#define END_PUSH_CONSTANTS
|
||||||
|
#define UNIFORM(n) layout (location = n) uniform
|
||||||
|
#define BINDING_SWIZZLE_BUFFER 0
|
||||||
|
#define BINDING_INPUT_BUFFER 1
|
||||||
|
#define BINDING_OUTPUT_IMAGE 0
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
BEGIN_PUSH_CONSTANTS
|
||||||
|
UNIFORM(0) uvec3 origin;
|
||||||
|
UNIFORM(1) ivec3 destination;
|
||||||
|
UNIFORM(2) uint bytes_per_block_log2;
|
||||||
|
UNIFORM(3) uint slice_size;
|
||||||
|
UNIFORM(4) uint block_size;
|
||||||
|
UNIFORM(5) uint x_shift;
|
||||||
|
UNIFORM(6) uint block_height;
|
||||||
|
UNIFORM(7) uint block_height_mask;
|
||||||
|
UNIFORM(8) uint block_depth;
|
||||||
|
UNIFORM(9) uint block_depth_mask;
|
||||||
|
END_PUSH_CONSTANTS
|
||||||
|
|
||||||
|
layout(binding = BINDING_SWIZZLE_BUFFER, std430) readonly buffer SwizzleTable {
|
||||||
|
uint swizzle_table[];
|
||||||
|
};
|
||||||
|
|
||||||
|
#if HAS_EXTENDED_TYPES
|
||||||
|
layout(binding = BINDING_INPUT_BUFFER, std430) buffer InputBufferU8 { uint8_t u8data[]; };
|
||||||
|
layout(binding = BINDING_INPUT_BUFFER, std430) buffer InputBufferU16 { uint16_t u16data[]; };
|
||||||
|
#endif
|
||||||
|
layout(binding = BINDING_INPUT_BUFFER, std430) buffer InputBufferU32 { uint u32data[]; };
|
||||||
|
layout(binding = BINDING_INPUT_BUFFER, std430) buffer InputBufferU64 { uvec2 u64data[]; };
|
||||||
|
layout(binding = BINDING_INPUT_BUFFER, std430) buffer InputBufferU128 { uvec4 u128data[]; };
|
||||||
|
|
||||||
|
layout(binding = BINDING_OUTPUT_IMAGE) uniform writeonly uimage3D output_image;
|
||||||
|
|
||||||
|
layout(local_size_x = 16, local_size_y = 8, local_size_z = 8) in;
|
||||||
|
|
||||||
|
const uint GOB_SIZE_X = 64;
|
||||||
|
const uint GOB_SIZE_Y = 8;
|
||||||
|
const uint GOB_SIZE_Z = 1;
|
||||||
|
const uint GOB_SIZE = GOB_SIZE_X * GOB_SIZE_Y * GOB_SIZE_Z;
|
||||||
|
|
||||||
|
const uint GOB_SIZE_X_SHIFT = 6;
|
||||||
|
const uint GOB_SIZE_Y_SHIFT = 3;
|
||||||
|
const uint GOB_SIZE_Z_SHIFT = 0;
|
||||||
|
const uint GOB_SIZE_SHIFT = GOB_SIZE_X_SHIFT + GOB_SIZE_Y_SHIFT + GOB_SIZE_Z_SHIFT;
|
||||||
|
|
||||||
|
const uvec2 SWIZZLE_MASK = uvec2(GOB_SIZE_X - 1, GOB_SIZE_Y - 1);
|
||||||
|
|
||||||
|
uint SwizzleOffset(uvec2 pos) {
|
||||||
|
pos = pos & SWIZZLE_MASK;
|
||||||
|
return swizzle_table[pos.y * 64 + pos.x];
|
||||||
|
}
|
||||||
|
|
||||||
|
uvec4 ReadTexel(uint offset) {
|
||||||
|
switch (bytes_per_block_log2) {
|
||||||
|
#if HAS_EXTENDED_TYPES
|
||||||
|
case 0:
|
||||||
|
return uvec4(u8data[offset], 0, 0, 0);
|
||||||
|
case 1:
|
||||||
|
return uvec4(u16data[offset / 2], 0, 0, 0);
|
||||||
|
#else
|
||||||
|
case 0:
|
||||||
|
return uvec4(bitfieldExtract(u32data[offset / 4], int((offset * 8) & 24), 8), 0, 0, 0);
|
||||||
|
case 1:
|
||||||
|
return uvec4(bitfieldExtract(u32data[offset / 4], int((offset * 8) & 16), 16), 0, 0, 0);
|
||||||
|
#endif
|
||||||
|
case 2:
|
||||||
|
return uvec4(u32data[offset / 4], 0, 0, 0);
|
||||||
|
case 3:
|
||||||
|
return uvec4(u64data[offset / 8], 0, 0);
|
||||||
|
case 4:
|
||||||
|
return u128data[offset / 16];
|
||||||
|
}
|
||||||
|
return uvec4(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
uvec3 pos = gl_GlobalInvocationID + origin;
|
||||||
|
pos.x <<= bytes_per_block_log2;
|
||||||
|
|
||||||
|
// Read as soon as possible due to its latency
|
||||||
|
const uint swizzle = SwizzleOffset(pos.xy);
|
||||||
|
|
||||||
|
const uint block_y = pos.y >> GOB_SIZE_Y_SHIFT;
|
||||||
|
|
||||||
|
uint offset = 0;
|
||||||
|
offset += (pos.z >> block_depth) * slice_size;
|
||||||
|
offset += (pos.z & block_depth_mask) << (GOB_SIZE_SHIFT + block_height);
|
||||||
|
offset += (block_y >> block_height) * block_size;
|
||||||
|
offset += (block_y & block_height_mask) << GOB_SIZE_SHIFT;
|
||||||
|
offset += (pos.x >> GOB_SIZE_X_SHIFT) << x_shift;
|
||||||
|
offset += swizzle;
|
||||||
|
|
||||||
|
const uvec4 texel = ReadTexel(offset);
|
||||||
|
const ivec3 coord = ivec3(gl_GlobalInvocationID) + destination;
|
||||||
|
imageStore(output_image, coord, texel);
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
// Copyright 2020 yuzu Emulator Project
|
||||||
|
// Licensed under GPLv2 or any later version
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#version 450
|
||||||
|
|
||||||
|
layout(binding = 0) uniform sampler2D depth_texture;
|
||||||
|
layout(location = 0) out float output_color;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
ivec2 coord = ivec2(gl_FragCoord.xy);
|
||||||
|
output_color = texelFetch(depth_texture, coord, 0).r;
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
// Copyright 2020 yuzu Emulator Project
|
||||||
|
// Licensed under GPLv2 or any later version
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#version 450
|
||||||
|
|
||||||
|
layout(binding = 0) uniform sampler2D color_texture;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
ivec2 coord = ivec2(gl_FragCoord.xy);
|
||||||
|
float color = texelFetch(color_texture, coord, 0).r;
|
||||||
|
gl_FragDepth = color;
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
// Copyright 2020 yuzu Emulator Project
|
||||||
|
// Licensed under GPLv2 or any later version
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#version 450
|
||||||
|
|
||||||
|
#ifdef VULKAN
|
||||||
|
#define BEGIN_PUSH_CONSTANTS layout(push_constant) uniform PushConstants {
|
||||||
|
#define END_PUSH_CONSTANTS };
|
||||||
|
#define UNIFORM(n)
|
||||||
|
#else // ^^^ Vulkan ^^^ // vvv OpenGL vvv
|
||||||
|
#define BEGIN_PUSH_CONSTANTS
|
||||||
|
#define END_PUSH_CONSTANTS
|
||||||
|
#define UNIFORM(n) layout (location = n) uniform
|
||||||
|
#endif
|
||||||
|
|
||||||
|
BEGIN_PUSH_CONSTANTS
|
||||||
|
UNIFORM(0) vec2 tex_scale;
|
||||||
|
UNIFORM(1) vec2 tex_offset;
|
||||||
|
END_PUSH_CONSTANTS
|
||||||
|
|
||||||
|
layout(location = 0) out vec2 texcoord;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
float x = float((gl_VertexIndex & 1) << 2);
|
||||||
|
float y = float((gl_VertexIndex & 2) << 1);
|
||||||
|
gl_Position = vec4(x - 1.0, y - 1.0, 0.0, 1.0);
|
||||||
|
texcoord = fma(vec2(x, y) / 2.0, tex_scale, tex_offset);
|
||||||
|
}
|
@ -0,0 +1,70 @@
|
|||||||
|
// Copyright 2020 yuzu Emulator Project
|
||||||
|
// Licensed under GPLv2 or any later version
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#version 430 core
|
||||||
|
#extension GL_ARB_gpu_shader_int64 : require
|
||||||
|
|
||||||
|
layout (local_size_x = 4, local_size_y = 4) in;
|
||||||
|
|
||||||
|
layout(binding = 0, rg32ui) readonly uniform uimage3D bc4_input;
|
||||||
|
layout(binding = 1, rgba8ui) writeonly uniform uimage3D bc4_output;
|
||||||
|
|
||||||
|
layout(location = 0) uniform uvec3 src_offset;
|
||||||
|
layout(location = 1) uniform uvec3 dst_offset;
|
||||||
|
|
||||||
|
// https://www.khronos.org/registry/OpenGL/extensions/ARB/ARB_texture_compression_rgtc.txt
|
||||||
|
uint DecompressBlock(uint64_t bits, uvec2 coord) {
|
||||||
|
const uint code_offset = 16 + 3 * (4 * coord.y + coord.x);
|
||||||
|
const uint code = uint(bits >> code_offset) & 7;
|
||||||
|
const uint red0 = uint(bits >> 0) & 0xff;
|
||||||
|
const uint red1 = uint(bits >> 8) & 0xff;
|
||||||
|
if (red0 > red1) {
|
||||||
|
switch (code) {
|
||||||
|
case 0:
|
||||||
|
return red0;
|
||||||
|
case 1:
|
||||||
|
return red1;
|
||||||
|
case 2:
|
||||||
|
return (6 * red0 + 1 * red1) / 7;
|
||||||
|
case 3:
|
||||||
|
return (5 * red0 + 2 * red1) / 7;
|
||||||
|
case 4:
|
||||||
|
return (4 * red0 + 3 * red1) / 7;
|
||||||
|
case 5:
|
||||||
|
return (3 * red0 + 4 * red1) / 7;
|
||||||
|
case 6:
|
||||||
|
return (2 * red0 + 5 * red1) / 7;
|
||||||
|
case 7:
|
||||||
|
return (1 * red0 + 6 * red1) / 7;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
switch (code) {
|
||||||
|
case 0:
|
||||||
|
return red0;
|
||||||
|
case 1:
|
||||||
|
return red1;
|
||||||
|
case 2:
|
||||||
|
return (4 * red0 + 1 * red1) / 5;
|
||||||
|
case 3:
|
||||||
|
return (3 * red0 + 2 * red1) / 5;
|
||||||
|
case 4:
|
||||||
|
return (2 * red0 + 3 * red1) / 5;
|
||||||
|
case 5:
|
||||||
|
return (1 * red0 + 4 * red1) / 5;
|
||||||
|
case 6:
|
||||||
|
return 0;
|
||||||
|
case 7:
|
||||||
|
return 0xff;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
uvec2 packed_bits = imageLoad(bc4_input, ivec3(gl_WorkGroupID + src_offset)).rg;
|
||||||
|
uint64_t bits = packUint2x32(packed_bits);
|
||||||
|
uint red = DecompressBlock(bits, gl_LocalInvocationID.xy);
|
||||||
|
uvec4 color = uvec4(red & 0xff, 0, 0, 0xff);
|
||||||
|
imageStore(bc4_output, ivec3(gl_GlobalInvocationID + dst_offset), color);
|
||||||
|
}
|
@ -0,0 +1,86 @@
|
|||||||
|
// Copyright 2020 yuzu Emulator Project
|
||||||
|
// Licensed under GPLv2 or any later version
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#version 430
|
||||||
|
|
||||||
|
#ifdef VULKAN
|
||||||
|
|
||||||
|
#extension GL_EXT_shader_16bit_storage : require
|
||||||
|
#extension GL_EXT_shader_8bit_storage : require
|
||||||
|
#define HAS_EXTENDED_TYPES 1
|
||||||
|
#define BEGIN_PUSH_CONSTANTS layout(push_constant) uniform PushConstants {
|
||||||
|
#define END_PUSH_CONSTANTS };
|
||||||
|
#define UNIFORM(n)
|
||||||
|
#define BINDING_INPUT_BUFFER 0
|
||||||
|
#define BINDING_OUTPUT_IMAGE 1
|
||||||
|
|
||||||
|
#else // ^^^ Vulkan ^^^ // vvv OpenGL vvv
|
||||||
|
|
||||||
|
#extension GL_NV_gpu_shader5 : enable
|
||||||
|
#ifdef GL_NV_gpu_shader5
|
||||||
|
#define HAS_EXTENDED_TYPES 1
|
||||||
|
#else
|
||||||
|
#define HAS_EXTENDED_TYPES 0
|
||||||
|
#endif
|
||||||
|
#define BEGIN_PUSH_CONSTANTS
|
||||||
|
#define END_PUSH_CONSTANTS
|
||||||
|
#define UNIFORM(n) layout (location = n) uniform
|
||||||
|
#define BINDING_INPUT_BUFFER 0
|
||||||
|
#define BINDING_OUTPUT_IMAGE 0
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
BEGIN_PUSH_CONSTANTS
|
||||||
|
UNIFORM(0) uvec2 origin;
|
||||||
|
UNIFORM(1) ivec2 destination;
|
||||||
|
UNIFORM(2) uint bytes_per_block;
|
||||||
|
UNIFORM(3) uint pitch;
|
||||||
|
END_PUSH_CONSTANTS
|
||||||
|
|
||||||
|
#if HAS_EXTENDED_TYPES
|
||||||
|
layout(binding = BINDING_INPUT_BUFFER, std430) readonly buffer InputBufferU8 { uint8_t u8data[]; };
|
||||||
|
layout(binding = BINDING_INPUT_BUFFER, std430) readonly buffer InputBufferU16 { uint16_t u16data[]; };
|
||||||
|
#endif
|
||||||
|
layout(binding = BINDING_INPUT_BUFFER, std430) readonly buffer InputBufferU32 { uint u32data[]; };
|
||||||
|
layout(binding = BINDING_INPUT_BUFFER, std430) readonly buffer InputBufferU64 { uvec2 u64data[]; };
|
||||||
|
layout(binding = BINDING_INPUT_BUFFER, std430) readonly buffer InputBufferU128 { uvec4 u128data[]; };
|
||||||
|
|
||||||
|
layout(binding = BINDING_OUTPUT_IMAGE) writeonly uniform uimage2D output_image;
|
||||||
|
|
||||||
|
layout(local_size_x = 32, local_size_y = 32, local_size_z = 1) in;
|
||||||
|
|
||||||
|
uvec4 ReadTexel(uint offset) {
|
||||||
|
switch (bytes_per_block) {
|
||||||
|
#if HAS_EXTENDED_TYPES
|
||||||
|
case 1:
|
||||||
|
return uvec4(u8data[offset], 0, 0, 0);
|
||||||
|
case 2:
|
||||||
|
return uvec4(u16data[offset / 2], 0, 0, 0);
|
||||||
|
#else
|
||||||
|
case 1:
|
||||||
|
return uvec4(bitfieldExtract(u32data[offset / 4], int((offset * 8) & 24), 8), 0, 0, 0);
|
||||||
|
case 2:
|
||||||
|
return uvec4(bitfieldExtract(u32data[offset / 4], int((offset * 8) & 16), 16), 0, 0, 0);
|
||||||
|
#endif
|
||||||
|
case 4:
|
||||||
|
return uvec4(u32data[offset / 4], 0, 0, 0);
|
||||||
|
case 8:
|
||||||
|
return uvec4(u64data[offset / 8], 0, 0);
|
||||||
|
case 16:
|
||||||
|
return u128data[offset / 16];
|
||||||
|
}
|
||||||
|
return uvec4(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
uvec2 pos = gl_GlobalInvocationID.xy + origin;
|
||||||
|
|
||||||
|
uint offset = 0;
|
||||||
|
offset += pos.x * bytes_per_block;
|
||||||
|
offset += pos.y * pitch;
|
||||||
|
|
||||||
|
const uvec4 texel = ReadTexel(offset);
|
||||||
|
const ivec2 coord = ivec2(gl_GlobalInvocationID.xy) + destination;
|
||||||
|
imageStore(output_image, coord, texel);
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
// Copyright 2020 yuzu Emulator Project
|
||||||
|
// Licensed under GPLv2 or any later version
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#version 450
|
||||||
|
|
||||||
|
layout(binding = 0) uniform sampler2D tex;
|
||||||
|
|
||||||
|
layout(location = 0) in vec2 texcoord;
|
||||||
|
layout(location = 0) out vec4 color;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
color = textureLod(tex, texcoord, 0);
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
// Copyright 2020 yuzu Emulator Project
|
||||||
|
// Licensed under GPLv2 or any later version
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#version 450
|
||||||
|
#extension GL_ARB_shader_stencil_export : require
|
||||||
|
|
||||||
|
layout(binding = 0) uniform sampler2D depth_tex;
|
||||||
|
layout(binding = 1) uniform isampler2D stencil_tex;
|
||||||
|
|
||||||
|
layout(location = 0) in vec2 texcoord;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
gl_FragDepth = textureLod(depth_tex, texcoord, 0).r;
|
||||||
|
gl_FragStencilRefARB = textureLod(stencil_tex, texcoord, 0).r;
|
||||||
|
}
|
@ -1,250 +0,0 @@
|
|||||||
// Copyright 2018 yuzu Emulator Project
|
|
||||||
// Licensed under GPLv2 or any later version
|
|
||||||
// Refer to the license.txt file included.
|
|
||||||
|
|
||||||
#include <array>
|
|
||||||
#include <cstring>
|
|
||||||
#include "common/assert.h"
|
|
||||||
#include "common/common_types.h"
|
|
||||||
#include "video_core/morton.h"
|
|
||||||
#include "video_core/surface.h"
|
|
||||||
#include "video_core/textures/decoders.h"
|
|
||||||
|
|
||||||
namespace VideoCore {
|
|
||||||
|
|
||||||
using Surface::GetBytesPerPixel;
|
|
||||||
using Surface::PixelFormat;
|
|
||||||
|
|
||||||
using MortonCopyFn = void (*)(u32, u32, u32, u32, u32, u32, u8*, u8*);
|
|
||||||
using ConversionArray = std::array<MortonCopyFn, Surface::MaxPixelFormat>;
|
|
||||||
|
|
||||||
template <bool morton_to_linear, PixelFormat format>
|
|
||||||
static void MortonCopy(u32 stride, u32 block_height, u32 height, u32 block_depth, u32 depth,
|
|
||||||
u32 tile_width_spacing, u8* buffer, u8* addr) {
|
|
||||||
constexpr u32 bytes_per_pixel = GetBytesPerPixel(format);
|
|
||||||
|
|
||||||
// With the BCn formats (DXT and DXN), each 4x4 tile is swizzled instead of just individual
|
|
||||||
// pixel values.
|
|
||||||
constexpr u32 tile_size_x{GetDefaultBlockWidth(format)};
|
|
||||||
constexpr u32 tile_size_y{GetDefaultBlockHeight(format)};
|
|
||||||
|
|
||||||
if constexpr (morton_to_linear) {
|
|
||||||
Tegra::Texture::UnswizzleTexture(buffer, addr, tile_size_x, tile_size_y, bytes_per_pixel,
|
|
||||||
stride, height, depth, block_height, block_depth,
|
|
||||||
tile_width_spacing);
|
|
||||||
} else {
|
|
||||||
Tegra::Texture::CopySwizzledData((stride + tile_size_x - 1) / tile_size_x,
|
|
||||||
(height + tile_size_y - 1) / tile_size_y, depth,
|
|
||||||
bytes_per_pixel, bytes_per_pixel, addr, buffer, false,
|
|
||||||
block_height, block_depth, tile_width_spacing);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static constexpr ConversionArray morton_to_linear_fns = {
|
|
||||||
MortonCopy<true, PixelFormat::A8B8G8R8_UNORM>,
|
|
||||||
MortonCopy<true, PixelFormat::A8B8G8R8_SNORM>,
|
|
||||||
MortonCopy<true, PixelFormat::A8B8G8R8_SINT>,
|
|
||||||
MortonCopy<true, PixelFormat::A8B8G8R8_UINT>,
|
|
||||||
MortonCopy<true, PixelFormat::R5G6B5_UNORM>,
|
|
||||||
MortonCopy<true, PixelFormat::B5G6R5_UNORM>,
|
|
||||||
MortonCopy<true, PixelFormat::A1R5G5B5_UNORM>,
|
|
||||||
MortonCopy<true, PixelFormat::A2B10G10R10_UNORM>,
|
|
||||||
MortonCopy<true, PixelFormat::A2B10G10R10_UINT>,
|
|
||||||
MortonCopy<true, PixelFormat::A1B5G5R5_UNORM>,
|
|
||||||
MortonCopy<true, PixelFormat::R8_UNORM>,
|
|
||||||
MortonCopy<true, PixelFormat::R8_SNORM>,
|
|
||||||
MortonCopy<true, PixelFormat::R8_SINT>,
|
|
||||||
MortonCopy<true, PixelFormat::R8_UINT>,
|
|
||||||
MortonCopy<true, PixelFormat::R16G16B16A16_FLOAT>,
|
|
||||||
MortonCopy<true, PixelFormat::R16G16B16A16_UNORM>,
|
|
||||||
MortonCopy<true, PixelFormat::R16G16B16A16_SNORM>,
|
|
||||||
MortonCopy<true, PixelFormat::R16G16B16A16_SINT>,
|
|
||||||
MortonCopy<true, PixelFormat::R16G16B16A16_UINT>,
|
|
||||||
MortonCopy<true, PixelFormat::B10G11R11_FLOAT>,
|
|
||||||
MortonCopy<true, PixelFormat::R32G32B32A32_UINT>,
|
|
||||||
MortonCopy<true, PixelFormat::BC1_RGBA_UNORM>,
|
|
||||||
MortonCopy<true, PixelFormat::BC2_UNORM>,
|
|
||||||
MortonCopy<true, PixelFormat::BC3_UNORM>,
|
|
||||||
MortonCopy<true, PixelFormat::BC4_UNORM>,
|
|
||||||
MortonCopy<true, PixelFormat::BC4_SNORM>,
|
|
||||||
MortonCopy<true, PixelFormat::BC5_UNORM>,
|
|
||||||
MortonCopy<true, PixelFormat::BC5_SNORM>,
|
|
||||||
MortonCopy<true, PixelFormat::BC7_UNORM>,
|
|
||||||
MortonCopy<true, PixelFormat::BC6H_UFLOAT>,
|
|
||||||
MortonCopy<true, PixelFormat::BC6H_SFLOAT>,
|
|
||||||
MortonCopy<true, PixelFormat::ASTC_2D_4X4_UNORM>,
|
|
||||||
MortonCopy<true, PixelFormat::B8G8R8A8_UNORM>,
|
|
||||||
MortonCopy<true, PixelFormat::R32G32B32A32_FLOAT>,
|
|
||||||
MortonCopy<true, PixelFormat::R32G32B32A32_SINT>,
|
|
||||||
MortonCopy<true, PixelFormat::R32G32_FLOAT>,
|
|
||||||
MortonCopy<true, PixelFormat::R32G32_SINT>,
|
|
||||||
MortonCopy<true, PixelFormat::R32_FLOAT>,
|
|
||||||
MortonCopy<true, PixelFormat::R16_FLOAT>,
|
|
||||||
MortonCopy<true, PixelFormat::R16_UNORM>,
|
|
||||||
MortonCopy<true, PixelFormat::R16_SNORM>,
|
|
||||||
MortonCopy<true, PixelFormat::R16_UINT>,
|
|
||||||
MortonCopy<true, PixelFormat::R16_SINT>,
|
|
||||||
MortonCopy<true, PixelFormat::R16G16_UNORM>,
|
|
||||||
MortonCopy<true, PixelFormat::R16G16_FLOAT>,
|
|
||||||
MortonCopy<true, PixelFormat::R16G16_UINT>,
|
|
||||||
MortonCopy<true, PixelFormat::R16G16_SINT>,
|
|
||||||
MortonCopy<true, PixelFormat::R16G16_SNORM>,
|
|
||||||
MortonCopy<true, PixelFormat::R32G32B32_FLOAT>,
|
|
||||||
MortonCopy<true, PixelFormat::A8B8G8R8_SRGB>,
|
|
||||||
MortonCopy<true, PixelFormat::R8G8_UNORM>,
|
|
||||||
MortonCopy<true, PixelFormat::R8G8_SNORM>,
|
|
||||||
MortonCopy<true, PixelFormat::R8G8_SINT>,
|
|
||||||
MortonCopy<true, PixelFormat::R8G8_UINT>,
|
|
||||||
MortonCopy<true, PixelFormat::R32G32_UINT>,
|
|
||||||
MortonCopy<true, PixelFormat::R16G16B16X16_FLOAT>,
|
|
||||||
MortonCopy<true, PixelFormat::R32_UINT>,
|
|
||||||
MortonCopy<true, PixelFormat::R32_SINT>,
|
|
||||||
MortonCopy<true, PixelFormat::ASTC_2D_8X8_UNORM>,
|
|
||||||
MortonCopy<true, PixelFormat::ASTC_2D_8X5_UNORM>,
|
|
||||||
MortonCopy<true, PixelFormat::ASTC_2D_5X4_UNORM>,
|
|
||||||
MortonCopy<true, PixelFormat::B8G8R8A8_SRGB>,
|
|
||||||
MortonCopy<true, PixelFormat::BC1_RGBA_SRGB>,
|
|
||||||
MortonCopy<true, PixelFormat::BC2_SRGB>,
|
|
||||||
MortonCopy<true, PixelFormat::BC3_SRGB>,
|
|
||||||
MortonCopy<true, PixelFormat::BC7_SRGB>,
|
|
||||||
MortonCopy<true, PixelFormat::A4B4G4R4_UNORM>,
|
|
||||||
MortonCopy<true, PixelFormat::ASTC_2D_4X4_SRGB>,
|
|
||||||
MortonCopy<true, PixelFormat::ASTC_2D_8X8_SRGB>,
|
|
||||||
MortonCopy<true, PixelFormat::ASTC_2D_8X5_SRGB>,
|
|
||||||
MortonCopy<true, PixelFormat::ASTC_2D_5X4_SRGB>,
|
|
||||||
MortonCopy<true, PixelFormat::ASTC_2D_5X5_UNORM>,
|
|
||||||
MortonCopy<true, PixelFormat::ASTC_2D_5X5_SRGB>,
|
|
||||||
MortonCopy<true, PixelFormat::ASTC_2D_10X8_UNORM>,
|
|
||||||
MortonCopy<true, PixelFormat::ASTC_2D_10X8_SRGB>,
|
|
||||||
MortonCopy<true, PixelFormat::ASTC_2D_6X6_UNORM>,
|
|
||||||
MortonCopy<true, PixelFormat::ASTC_2D_6X6_SRGB>,
|
|
||||||
MortonCopy<true, PixelFormat::ASTC_2D_10X10_UNORM>,
|
|
||||||
MortonCopy<true, PixelFormat::ASTC_2D_10X10_SRGB>,
|
|
||||||
MortonCopy<true, PixelFormat::ASTC_2D_12X12_UNORM>,
|
|
||||||
MortonCopy<true, PixelFormat::ASTC_2D_12X12_SRGB>,
|
|
||||||
MortonCopy<true, PixelFormat::ASTC_2D_8X6_UNORM>,
|
|
||||||
MortonCopy<true, PixelFormat::ASTC_2D_8X6_SRGB>,
|
|
||||||
MortonCopy<true, PixelFormat::ASTC_2D_6X5_UNORM>,
|
|
||||||
MortonCopy<true, PixelFormat::ASTC_2D_6X5_SRGB>,
|
|
||||||
MortonCopy<true, PixelFormat::E5B9G9R9_FLOAT>,
|
|
||||||
MortonCopy<true, PixelFormat::D32_FLOAT>,
|
|
||||||
MortonCopy<true, PixelFormat::D16_UNORM>,
|
|
||||||
MortonCopy<true, PixelFormat::D24_UNORM_S8_UINT>,
|
|
||||||
MortonCopy<true, PixelFormat::S8_UINT_D24_UNORM>,
|
|
||||||
MortonCopy<true, PixelFormat::D32_FLOAT_S8_UINT>,
|
|
||||||
};
|
|
||||||
|
|
||||||
static constexpr ConversionArray linear_to_morton_fns = {
|
|
||||||
MortonCopy<false, PixelFormat::A8B8G8R8_UNORM>,
|
|
||||||
MortonCopy<false, PixelFormat::A8B8G8R8_SNORM>,
|
|
||||||
MortonCopy<false, PixelFormat::A8B8G8R8_SINT>,
|
|
||||||
MortonCopy<false, PixelFormat::A8B8G8R8_UINT>,
|
|
||||||
MortonCopy<false, PixelFormat::R5G6B5_UNORM>,
|
|
||||||
MortonCopy<false, PixelFormat::B5G6R5_UNORM>,
|
|
||||||
MortonCopy<false, PixelFormat::A1R5G5B5_UNORM>,
|
|
||||||
MortonCopy<false, PixelFormat::A2B10G10R10_UNORM>,
|
|
||||||
MortonCopy<false, PixelFormat::A2B10G10R10_UINT>,
|
|
||||||
MortonCopy<false, PixelFormat::A1B5G5R5_UNORM>,
|
|
||||||
MortonCopy<false, PixelFormat::R8_UNORM>,
|
|
||||||
MortonCopy<false, PixelFormat::R8_SNORM>,
|
|
||||||
MortonCopy<false, PixelFormat::R8_SINT>,
|
|
||||||
MortonCopy<false, PixelFormat::R8_UINT>,
|
|
||||||
MortonCopy<false, PixelFormat::R16G16B16A16_FLOAT>,
|
|
||||||
MortonCopy<false, PixelFormat::R16G16B16A16_SNORM>,
|
|
||||||
MortonCopy<false, PixelFormat::R16G16B16A16_SINT>,
|
|
||||||
MortonCopy<false, PixelFormat::R16G16B16A16_UNORM>,
|
|
||||||
MortonCopy<false, PixelFormat::R16G16B16A16_UINT>,
|
|
||||||
MortonCopy<false, PixelFormat::B10G11R11_FLOAT>,
|
|
||||||
MortonCopy<false, PixelFormat::R32G32B32A32_UINT>,
|
|
||||||
MortonCopy<false, PixelFormat::BC1_RGBA_UNORM>,
|
|
||||||
MortonCopy<false, PixelFormat::BC2_UNORM>,
|
|
||||||
MortonCopy<false, PixelFormat::BC3_UNORM>,
|
|
||||||
MortonCopy<false, PixelFormat::BC4_UNORM>,
|
|
||||||
MortonCopy<false, PixelFormat::BC4_SNORM>,
|
|
||||||
MortonCopy<false, PixelFormat::BC5_UNORM>,
|
|
||||||
MortonCopy<false, PixelFormat::BC5_SNORM>,
|
|
||||||
MortonCopy<false, PixelFormat::BC7_UNORM>,
|
|
||||||
MortonCopy<false, PixelFormat::BC6H_UFLOAT>,
|
|
||||||
MortonCopy<false, PixelFormat::BC6H_SFLOAT>,
|
|
||||||
// TODO(Subv): Swizzling ASTC formats are not supported
|
|
||||||
nullptr,
|
|
||||||
MortonCopy<false, PixelFormat::B8G8R8A8_UNORM>,
|
|
||||||
MortonCopy<false, PixelFormat::R32G32B32A32_FLOAT>,
|
|
||||||
MortonCopy<false, PixelFormat::R32G32B32A32_SINT>,
|
|
||||||
MortonCopy<false, PixelFormat::R32G32_FLOAT>,
|
|
||||||
MortonCopy<false, PixelFormat::R32G32_SINT>,
|
|
||||||
MortonCopy<false, PixelFormat::R32_FLOAT>,
|
|
||||||
MortonCopy<false, PixelFormat::R16_FLOAT>,
|
|
||||||
MortonCopy<false, PixelFormat::R16_UNORM>,
|
|
||||||
MortonCopy<false, PixelFormat::R16_SNORM>,
|
|
||||||
MortonCopy<false, PixelFormat::R16_UINT>,
|
|
||||||
MortonCopy<false, PixelFormat::R16_SINT>,
|
|
||||||
MortonCopy<false, PixelFormat::R16G16_UNORM>,
|
|
||||||
MortonCopy<false, PixelFormat::R16G16_FLOAT>,
|
|
||||||
MortonCopy<false, PixelFormat::R16G16_UINT>,
|
|
||||||
MortonCopy<false, PixelFormat::R16G16_SINT>,
|
|
||||||
MortonCopy<false, PixelFormat::R16G16_SNORM>,
|
|
||||||
MortonCopy<false, PixelFormat::R32G32B32_FLOAT>,
|
|
||||||
MortonCopy<false, PixelFormat::A8B8G8R8_SRGB>,
|
|
||||||
MortonCopy<false, PixelFormat::R8G8_UNORM>,
|
|
||||||
MortonCopy<false, PixelFormat::R8G8_SNORM>,
|
|
||||||
MortonCopy<false, PixelFormat::R8G8_SINT>,
|
|
||||||
MortonCopy<false, PixelFormat::R8G8_UINT>,
|
|
||||||
MortonCopy<false, PixelFormat::R32G32_UINT>,
|
|
||||||
MortonCopy<false, PixelFormat::R16G16B16X16_FLOAT>,
|
|
||||||
MortonCopy<false, PixelFormat::R32_UINT>,
|
|
||||||
MortonCopy<false, PixelFormat::R32_SINT>,
|
|
||||||
nullptr,
|
|
||||||
nullptr,
|
|
||||||
nullptr,
|
|
||||||
MortonCopy<false, PixelFormat::B8G8R8A8_SRGB>,
|
|
||||||
MortonCopy<false, PixelFormat::BC1_RGBA_SRGB>,
|
|
||||||
MortonCopy<false, PixelFormat::BC2_SRGB>,
|
|
||||||
MortonCopy<false, PixelFormat::BC3_SRGB>,
|
|
||||||
MortonCopy<false, PixelFormat::BC7_SRGB>,
|
|
||||||
MortonCopy<false, PixelFormat::A4B4G4R4_UNORM>,
|
|
||||||
nullptr,
|
|
||||||
nullptr,
|
|
||||||
nullptr,
|
|
||||||
nullptr,
|
|
||||||
nullptr,
|
|
||||||
nullptr,
|
|
||||||
nullptr,
|
|
||||||
nullptr,
|
|
||||||
nullptr,
|
|
||||||
nullptr,
|
|
||||||
nullptr,
|
|
||||||
nullptr,
|
|
||||||
nullptr,
|
|
||||||
nullptr,
|
|
||||||
nullptr,
|
|
||||||
nullptr,
|
|
||||||
nullptr,
|
|
||||||
nullptr,
|
|
||||||
MortonCopy<false, PixelFormat::E5B9G9R9_FLOAT>,
|
|
||||||
MortonCopy<false, PixelFormat::D32_FLOAT>,
|
|
||||||
MortonCopy<false, PixelFormat::D16_UNORM>,
|
|
||||||
MortonCopy<false, PixelFormat::D24_UNORM_S8_UINT>,
|
|
||||||
MortonCopy<false, PixelFormat::S8_UINT_D24_UNORM>,
|
|
||||||
MortonCopy<false, PixelFormat::D32_FLOAT_S8_UINT>,
|
|
||||||
};
|
|
||||||
|
|
||||||
static MortonCopyFn GetSwizzleFunction(MortonSwizzleMode mode, Surface::PixelFormat format) {
|
|
||||||
switch (mode) {
|
|
||||||
case MortonSwizzleMode::MortonToLinear:
|
|
||||||
return morton_to_linear_fns[static_cast<std::size_t>(format)];
|
|
||||||
case MortonSwizzleMode::LinearToMorton:
|
|
||||||
return linear_to_morton_fns[static_cast<std::size_t>(format)];
|
|
||||||
}
|
|
||||||
UNREACHABLE();
|
|
||||||
return morton_to_linear_fns[static_cast<std::size_t>(format)];
|
|
||||||
}
|
|
||||||
|
|
||||||
void MortonSwizzle(MortonSwizzleMode mode, Surface::PixelFormat format, u32 stride,
|
|
||||||
u32 block_height, u32 height, u32 block_depth, u32 depth, u32 tile_width_spacing,
|
|
||||||
u8* buffer, u8* addr) {
|
|
||||||
GetSwizzleFunction(mode, format)(stride, block_height, height, block_depth, depth,
|
|
||||||
tile_width_spacing, buffer, addr);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace VideoCore
|
|
@ -1,18 +0,0 @@
|
|||||||
// Copyright 2018 yuzu Emulator Project
|
|
||||||
// Licensed under GPLv2 or any later version
|
|
||||||
// Refer to the license.txt file included.
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "common/common_types.h"
|
|
||||||
#include "video_core/surface.h"
|
|
||||||
|
|
||||||
namespace VideoCore {
|
|
||||||
|
|
||||||
enum class MortonSwizzleMode { MortonToLinear, LinearToMorton };
|
|
||||||
|
|
||||||
void MortonSwizzle(MortonSwizzleMode mode, VideoCore::Surface::PixelFormat format, u32 stride,
|
|
||||||
u32 block_height, u32 height, u32 block_depth, u32 depth, u32 tile_width_spacing,
|
|
||||||
u8* buffer, u8* addr);
|
|
||||||
|
|
||||||
} // namespace VideoCore
|
|
@ -1,85 +0,0 @@
|
|||||||
// Copyright 2019 yuzu Emulator Project
|
|
||||||
// Licensed under GPLv2 or any later version
|
|
||||||
// Refer to the license.txt file included.
|
|
||||||
|
|
||||||
#include <tuple>
|
|
||||||
#include <unordered_map>
|
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
#include <glad/glad.h>
|
|
||||||
|
|
||||||
#include "common/common_types.h"
|
|
||||||
#include "video_core/engines/maxwell_3d.h"
|
|
||||||
#include "video_core/renderer_opengl/gl_framebuffer_cache.h"
|
|
||||||
|
|
||||||
namespace OpenGL {
|
|
||||||
|
|
||||||
using Maxwell = Tegra::Engines::Maxwell3D::Regs;
|
|
||||||
using VideoCore::Surface::SurfaceType;
|
|
||||||
|
|
||||||
FramebufferCacheOpenGL::FramebufferCacheOpenGL() = default;
|
|
||||||
|
|
||||||
FramebufferCacheOpenGL::~FramebufferCacheOpenGL() = default;
|
|
||||||
|
|
||||||
GLuint FramebufferCacheOpenGL::GetFramebuffer(const FramebufferCacheKey& key) {
|
|
||||||
const auto [entry, is_cache_miss] = cache.try_emplace(key);
|
|
||||||
auto& framebuffer{entry->second};
|
|
||||||
if (is_cache_miss) {
|
|
||||||
framebuffer = CreateFramebuffer(key);
|
|
||||||
}
|
|
||||||
return framebuffer.handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
OGLFramebuffer FramebufferCacheOpenGL::CreateFramebuffer(const FramebufferCacheKey& key) {
|
|
||||||
OGLFramebuffer framebuffer;
|
|
||||||
framebuffer.Create();
|
|
||||||
|
|
||||||
// TODO(Rodrigo): Use DSA here after Nvidia fixes their framebuffer DSA bugs.
|
|
||||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebuffer.handle);
|
|
||||||
|
|
||||||
if (key.zeta) {
|
|
||||||
const bool stencil = key.zeta->GetSurfaceParams().type == SurfaceType::DepthStencil;
|
|
||||||
const GLenum attach_target = stencil ? GL_DEPTH_STENCIL_ATTACHMENT : GL_DEPTH_ATTACHMENT;
|
|
||||||
key.zeta->Attach(attach_target, GL_DRAW_FRAMEBUFFER);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::size_t num_buffers = 0;
|
|
||||||
std::array<GLenum, Maxwell::NumRenderTargets> targets;
|
|
||||||
|
|
||||||
for (std::size_t index = 0; index < Maxwell::NumRenderTargets; ++index) {
|
|
||||||
if (!key.colors[index]) {
|
|
||||||
targets[index] = GL_NONE;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
const GLenum attach_target = GL_COLOR_ATTACHMENT0 + static_cast<GLenum>(index);
|
|
||||||
key.colors[index]->Attach(attach_target, GL_DRAW_FRAMEBUFFER);
|
|
||||||
|
|
||||||
const u32 attachment = (key.color_attachments >> (BitsPerAttachment * index)) & 0b1111;
|
|
||||||
targets[index] = GL_COLOR_ATTACHMENT0 + attachment;
|
|
||||||
num_buffers = index + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (num_buffers > 0) {
|
|
||||||
glDrawBuffers(static_cast<GLsizei>(num_buffers), std::data(targets));
|
|
||||||
} else {
|
|
||||||
glDrawBuffer(GL_NONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
return framebuffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::size_t FramebufferCacheKey::Hash() const noexcept {
|
|
||||||
std::size_t hash = std::hash<View>{}(zeta);
|
|
||||||
for (const auto& color : colors) {
|
|
||||||
hash ^= std::hash<View>{}(color);
|
|
||||||
}
|
|
||||||
hash ^= static_cast<std::size_t>(color_attachments) << 16;
|
|
||||||
return hash;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool FramebufferCacheKey::operator==(const FramebufferCacheKey& rhs) const noexcept {
|
|
||||||
return std::tie(colors, zeta, color_attachments) ==
|
|
||||||
std::tie(rhs.colors, rhs.zeta, rhs.color_attachments);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace OpenGL
|
|
@ -1,68 +0,0 @@
|
|||||||
// Copyright 2019 yuzu Emulator Project
|
|
||||||
// Licensed under GPLv2 or any later version
|
|
||||||
// Refer to the license.txt file included.
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <array>
|
|
||||||
#include <cstddef>
|
|
||||||
#include <unordered_map>
|
|
||||||
|
|
||||||
#include <glad/glad.h>
|
|
||||||
|
|
||||||
#include "common/common_types.h"
|
|
||||||
#include "video_core/engines/maxwell_3d.h"
|
|
||||||
#include "video_core/renderer_opengl/gl_resource_manager.h"
|
|
||||||
#include "video_core/renderer_opengl/gl_texture_cache.h"
|
|
||||||
|
|
||||||
namespace OpenGL {
|
|
||||||
|
|
||||||
constexpr std::size_t BitsPerAttachment = 4;
|
|
||||||
|
|
||||||
struct FramebufferCacheKey {
|
|
||||||
View zeta;
|
|
||||||
std::array<View, Tegra::Engines::Maxwell3D::Regs::NumRenderTargets> colors;
|
|
||||||
u32 color_attachments = 0;
|
|
||||||
|
|
||||||
std::size_t Hash() const noexcept;
|
|
||||||
|
|
||||||
bool operator==(const FramebufferCacheKey& rhs) const noexcept;
|
|
||||||
|
|
||||||
bool operator!=(const FramebufferCacheKey& rhs) const noexcept {
|
|
||||||
return !operator==(rhs);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetAttachment(std::size_t index, u32 attachment) {
|
|
||||||
color_attachments |= attachment << (BitsPerAttachment * index);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace OpenGL
|
|
||||||
|
|
||||||
namespace std {
|
|
||||||
|
|
||||||
template <>
|
|
||||||
struct hash<OpenGL::FramebufferCacheKey> {
|
|
||||||
std::size_t operator()(const OpenGL::FramebufferCacheKey& k) const noexcept {
|
|
||||||
return k.Hash();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace std
|
|
||||||
|
|
||||||
namespace OpenGL {
|
|
||||||
|
|
||||||
class FramebufferCacheOpenGL {
|
|
||||||
public:
|
|
||||||
FramebufferCacheOpenGL();
|
|
||||||
~FramebufferCacheOpenGL();
|
|
||||||
|
|
||||||
GLuint GetFramebuffer(const FramebufferCacheKey& key);
|
|
||||||
|
|
||||||
private:
|
|
||||||
OGLFramebuffer CreateFramebuffer(const FramebufferCacheKey& key);
|
|
||||||
|
|
||||||
std::unordered_map<FramebufferCacheKey, OGLFramebuffer> cache;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace OpenGL
|
|
@ -1,52 +0,0 @@
|
|||||||
// Copyright 2019 yuzu Emulator Project
|
|
||||||
// Licensed under GPLv2 or any later version
|
|
||||||
// Refer to the license.txt file included.
|
|
||||||
|
|
||||||
#include "common/logging/log.h"
|
|
||||||
#include "video_core/renderer_opengl/gl_resource_manager.h"
|
|
||||||
#include "video_core/renderer_opengl/gl_sampler_cache.h"
|
|
||||||
#include "video_core/renderer_opengl/maxwell_to_gl.h"
|
|
||||||
|
|
||||||
namespace OpenGL {
|
|
||||||
|
|
||||||
SamplerCacheOpenGL::SamplerCacheOpenGL() = default;
|
|
||||||
|
|
||||||
SamplerCacheOpenGL::~SamplerCacheOpenGL() = default;
|
|
||||||
|
|
||||||
OGLSampler SamplerCacheOpenGL::CreateSampler(const Tegra::Texture::TSCEntry& tsc) const {
|
|
||||||
OGLSampler sampler;
|
|
||||||
sampler.Create();
|
|
||||||
|
|
||||||
const GLuint sampler_id{sampler.handle};
|
|
||||||
glSamplerParameteri(
|
|
||||||
sampler_id, GL_TEXTURE_MAG_FILTER,
|
|
||||||
MaxwellToGL::TextureFilterMode(tsc.mag_filter, Tegra::Texture::TextureMipmapFilter::None));
|
|
||||||
glSamplerParameteri(sampler_id, GL_TEXTURE_MIN_FILTER,
|
|
||||||
MaxwellToGL::TextureFilterMode(tsc.min_filter, tsc.mipmap_filter));
|
|
||||||
glSamplerParameteri(sampler_id, GL_TEXTURE_WRAP_S, MaxwellToGL::WrapMode(tsc.wrap_u));
|
|
||||||
glSamplerParameteri(sampler_id, GL_TEXTURE_WRAP_T, MaxwellToGL::WrapMode(tsc.wrap_v));
|
|
||||||
glSamplerParameteri(sampler_id, GL_TEXTURE_WRAP_R, MaxwellToGL::WrapMode(tsc.wrap_p));
|
|
||||||
glSamplerParameteri(sampler_id, GL_TEXTURE_COMPARE_MODE,
|
|
||||||
tsc.depth_compare_enabled == 1 ? GL_COMPARE_REF_TO_TEXTURE : GL_NONE);
|
|
||||||
glSamplerParameteri(sampler_id, GL_TEXTURE_COMPARE_FUNC,
|
|
||||||
MaxwellToGL::DepthCompareFunc(tsc.depth_compare_func));
|
|
||||||
glSamplerParameterfv(sampler_id, GL_TEXTURE_BORDER_COLOR, tsc.GetBorderColor().data());
|
|
||||||
glSamplerParameterf(sampler_id, GL_TEXTURE_MIN_LOD, tsc.GetMinLod());
|
|
||||||
glSamplerParameterf(sampler_id, GL_TEXTURE_MAX_LOD, tsc.GetMaxLod());
|
|
||||||
glSamplerParameterf(sampler_id, GL_TEXTURE_LOD_BIAS, tsc.GetLodBias());
|
|
||||||
if (GLAD_GL_ARB_texture_filter_anisotropic) {
|
|
||||||
glSamplerParameterf(sampler_id, GL_TEXTURE_MAX_ANISOTROPY, tsc.GetMaxAnisotropy());
|
|
||||||
} else if (GLAD_GL_EXT_texture_filter_anisotropic) {
|
|
||||||
glSamplerParameterf(sampler_id, GL_TEXTURE_MAX_ANISOTROPY_EXT, tsc.GetMaxAnisotropy());
|
|
||||||
} else {
|
|
||||||
LOG_WARNING(Render_OpenGL, "Anisotropy not supported by host GPU driver");
|
|
||||||
}
|
|
||||||
|
|
||||||
return sampler;
|
|
||||||
}
|
|
||||||
|
|
||||||
GLuint SamplerCacheOpenGL::ToSamplerType(const OGLSampler& sampler) const {
|
|
||||||
return sampler.handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace OpenGL
|
|
@ -1,25 +0,0 @@
|
|||||||
// Copyright 2019 yuzu Emulator Project
|
|
||||||
// Licensed under GPLv2 or any later version
|
|
||||||
// Refer to the license.txt file included.
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <glad/glad.h>
|
|
||||||
|
|
||||||
#include "video_core/renderer_opengl/gl_resource_manager.h"
|
|
||||||
#include "video_core/sampler_cache.h"
|
|
||||||
|
|
||||||
namespace OpenGL {
|
|
||||||
|
|
||||||
class SamplerCacheOpenGL final : public VideoCommon::SamplerCache<GLuint, OGLSampler> {
|
|
||||||
public:
|
|
||||||
explicit SamplerCacheOpenGL();
|
|
||||||
~SamplerCacheOpenGL();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
OGLSampler CreateSampler(const Tegra::Texture::TSCEntry& tsc) const override;
|
|
||||||
|
|
||||||
GLuint ToSamplerType(const OGLSampler& sampler) const override;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace OpenGL
|
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,224 @@
|
|||||||
|
// Copyright 2020 yuzu Emulator Project
|
||||||
|
// Licensed under GPLv2 or any later version
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#include <bit>
|
||||||
|
#include <span>
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
|
#include <glad/glad.h>
|
||||||
|
|
||||||
|
#include "common/assert.h"
|
||||||
|
#include "common/common_types.h"
|
||||||
|
#include "common/div_ceil.h"
|
||||||
|
#include "video_core/host_shaders/block_linear_unswizzle_2d_comp.h"
|
||||||
|
#include "video_core/host_shaders/block_linear_unswizzle_3d_comp.h"
|
||||||
|
#include "video_core/host_shaders/opengl_copy_bc4_comp.h"
|
||||||
|
#include "video_core/host_shaders/pitch_unswizzle_comp.h"
|
||||||
|
#include "video_core/renderer_opengl/gl_resource_manager.h"
|
||||||
|
#include "video_core/renderer_opengl/gl_shader_manager.h"
|
||||||
|
#include "video_core/renderer_opengl/gl_texture_cache.h"
|
||||||
|
#include "video_core/renderer_opengl/util_shaders.h"
|
||||||
|
#include "video_core/surface.h"
|
||||||
|
#include "video_core/texture_cache/accelerated_swizzle.h"
|
||||||
|
#include "video_core/texture_cache/types.h"
|
||||||
|
#include "video_core/texture_cache/util.h"
|
||||||
|
#include "video_core/textures/decoders.h"
|
||||||
|
|
||||||
|
namespace OpenGL {
|
||||||
|
|
||||||
|
using namespace HostShaders;
|
||||||
|
|
||||||
|
using VideoCommon::Extent3D;
|
||||||
|
using VideoCommon::ImageCopy;
|
||||||
|
using VideoCommon::ImageType;
|
||||||
|
using VideoCommon::SwizzleParameters;
|
||||||
|
using VideoCommon::Accelerated::MakeBlockLinearSwizzle2DParams;
|
||||||
|
using VideoCommon::Accelerated::MakeBlockLinearSwizzle3DParams;
|
||||||
|
using VideoCore::Surface::BytesPerBlock;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
OGLProgram MakeProgram(std::string_view source) {
|
||||||
|
OGLShader shader;
|
||||||
|
shader.Create(source, GL_COMPUTE_SHADER);
|
||||||
|
|
||||||
|
OGLProgram program;
|
||||||
|
program.Create(true, false, shader.handle);
|
||||||
|
return program;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // Anonymous namespace
|
||||||
|
|
||||||
|
UtilShaders::UtilShaders(ProgramManager& program_manager_)
|
||||||
|
: program_manager{program_manager_},
|
||||||
|
block_linear_unswizzle_2d_program(MakeProgram(BLOCK_LINEAR_UNSWIZZLE_2D_COMP)),
|
||||||
|
block_linear_unswizzle_3d_program(MakeProgram(BLOCK_LINEAR_UNSWIZZLE_3D_COMP)),
|
||||||
|
pitch_unswizzle_program(MakeProgram(PITCH_UNSWIZZLE_COMP)),
|
||||||
|
copy_bc4_program(MakeProgram(OPENGL_COPY_BC4_COMP)) {
|
||||||
|
const auto swizzle_table = Tegra::Texture::MakeSwizzleTable();
|
||||||
|
swizzle_table_buffer.Create();
|
||||||
|
glNamedBufferStorage(swizzle_table_buffer.handle, sizeof(swizzle_table), &swizzle_table, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
UtilShaders::~UtilShaders() = default;
|
||||||
|
|
||||||
|
void UtilShaders::BlockLinearUpload2D(Image& image, const ImageBufferMap& map, size_t buffer_offset,
|
||||||
|
std::span<const SwizzleParameters> swizzles) {
|
||||||
|
static constexpr Extent3D WORKGROUP_SIZE{32, 32, 1};
|
||||||
|
static constexpr GLuint BINDING_SWIZZLE_BUFFER = 0;
|
||||||
|
static constexpr GLuint BINDING_INPUT_BUFFER = 1;
|
||||||
|
static constexpr GLuint BINDING_OUTPUT_IMAGE = 0;
|
||||||
|
|
||||||
|
program_manager.BindHostCompute(block_linear_unswizzle_2d_program.handle);
|
||||||
|
glFlushMappedNamedBufferRange(map.Handle(), buffer_offset, image.guest_size_bytes);
|
||||||
|
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, BINDING_SWIZZLE_BUFFER, swizzle_table_buffer.handle);
|
||||||
|
|
||||||
|
const GLenum store_format = StoreFormat(BytesPerBlock(image.info.format));
|
||||||
|
for (const SwizzleParameters& swizzle : swizzles) {
|
||||||
|
const Extent3D num_tiles = swizzle.num_tiles;
|
||||||
|
const size_t input_offset = swizzle.buffer_offset + buffer_offset;
|
||||||
|
|
||||||
|
const u32 num_dispatches_x = Common::DivCeil(num_tiles.width, WORKGROUP_SIZE.width);
|
||||||
|
const u32 num_dispatches_y = Common::DivCeil(num_tiles.height, WORKGROUP_SIZE.height);
|
||||||
|
|
||||||
|
const auto params = MakeBlockLinearSwizzle2DParams(swizzle, image.info);
|
||||||
|
glUniform3uiv(0, 1, params.origin.data());
|
||||||
|
glUniform3iv(1, 1, params.destination.data());
|
||||||
|
glUniform1ui(2, params.bytes_per_block_log2);
|
||||||
|
glUniform1ui(3, params.layer_stride);
|
||||||
|
glUniform1ui(4, params.block_size);
|
||||||
|
glUniform1ui(5, params.x_shift);
|
||||||
|
glUniform1ui(6, params.block_height);
|
||||||
|
glUniform1ui(7, params.block_height_mask);
|
||||||
|
glBindBufferRange(GL_SHADER_STORAGE_BUFFER, BINDING_INPUT_BUFFER, map.Handle(),
|
||||||
|
input_offset, image.guest_size_bytes - swizzle.buffer_offset);
|
||||||
|
glBindImageTexture(BINDING_OUTPUT_IMAGE, image.Handle(), swizzle.level, GL_TRUE, 0,
|
||||||
|
GL_WRITE_ONLY, store_format);
|
||||||
|
glDispatchCompute(num_dispatches_x, num_dispatches_y, image.info.resources.layers);
|
||||||
|
}
|
||||||
|
program_manager.RestoreGuestCompute();
|
||||||
|
}
|
||||||
|
|
||||||
|
void UtilShaders::BlockLinearUpload3D(Image& image, const ImageBufferMap& map, size_t buffer_offset,
|
||||||
|
std::span<const SwizzleParameters> swizzles) {
|
||||||
|
static constexpr Extent3D WORKGROUP_SIZE{16, 8, 8};
|
||||||
|
|
||||||
|
static constexpr GLuint BINDING_SWIZZLE_BUFFER = 0;
|
||||||
|
static constexpr GLuint BINDING_INPUT_BUFFER = 1;
|
||||||
|
static constexpr GLuint BINDING_OUTPUT_IMAGE = 0;
|
||||||
|
|
||||||
|
glFlushMappedNamedBufferRange(map.Handle(), buffer_offset, image.guest_size_bytes);
|
||||||
|
program_manager.BindHostCompute(block_linear_unswizzle_3d_program.handle);
|
||||||
|
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, BINDING_SWIZZLE_BUFFER, swizzle_table_buffer.handle);
|
||||||
|
|
||||||
|
const GLenum store_format = StoreFormat(BytesPerBlock(image.info.format));
|
||||||
|
for (const SwizzleParameters& swizzle : swizzles) {
|
||||||
|
const Extent3D num_tiles = swizzle.num_tiles;
|
||||||
|
const size_t input_offset = swizzle.buffer_offset + buffer_offset;
|
||||||
|
|
||||||
|
const u32 num_dispatches_x = Common::DivCeil(num_tiles.width, WORKGROUP_SIZE.width);
|
||||||
|
const u32 num_dispatches_y = Common::DivCeil(num_tiles.height, WORKGROUP_SIZE.height);
|
||||||
|
const u32 num_dispatches_z = Common::DivCeil(num_tiles.depth, WORKGROUP_SIZE.depth);
|
||||||
|
|
||||||
|
const auto params = MakeBlockLinearSwizzle3DParams(swizzle, image.info);
|
||||||
|
glUniform3uiv(0, 1, params.origin.data());
|
||||||
|
glUniform3iv(1, 1, params.destination.data());
|
||||||
|
glUniform1ui(2, params.bytes_per_block_log2);
|
||||||
|
glUniform1ui(3, params.slice_size);
|
||||||
|
glUniform1ui(4, params.block_size);
|
||||||
|
glUniform1ui(5, params.x_shift);
|
||||||
|
glUniform1ui(6, params.block_height);
|
||||||
|
glUniform1ui(7, params.block_height_mask);
|
||||||
|
glUniform1ui(8, params.block_depth);
|
||||||
|
glUniform1ui(9, params.block_depth_mask);
|
||||||
|
glBindBufferRange(GL_SHADER_STORAGE_BUFFER, BINDING_INPUT_BUFFER, map.Handle(),
|
||||||
|
input_offset, image.guest_size_bytes - swizzle.buffer_offset);
|
||||||
|
glBindImageTexture(BINDING_OUTPUT_IMAGE, image.Handle(), swizzle.level, GL_TRUE, 0,
|
||||||
|
GL_WRITE_ONLY, store_format);
|
||||||
|
glDispatchCompute(num_dispatches_x, num_dispatches_y, num_dispatches_z);
|
||||||
|
}
|
||||||
|
program_manager.RestoreGuestCompute();
|
||||||
|
}
|
||||||
|
|
||||||
|
void UtilShaders::PitchUpload(Image& image, const ImageBufferMap& map, size_t buffer_offset,
|
||||||
|
std::span<const SwizzleParameters> swizzles) {
|
||||||
|
static constexpr Extent3D WORKGROUP_SIZE{32, 32, 1};
|
||||||
|
static constexpr GLuint BINDING_INPUT_BUFFER = 0;
|
||||||
|
static constexpr GLuint BINDING_OUTPUT_IMAGE = 0;
|
||||||
|
static constexpr GLuint LOC_ORIGIN = 0;
|
||||||
|
static constexpr GLuint LOC_DESTINATION = 1;
|
||||||
|
static constexpr GLuint LOC_BYTES_PER_BLOCK = 2;
|
||||||
|
static constexpr GLuint LOC_PITCH = 3;
|
||||||
|
|
||||||
|
const u32 bytes_per_block = BytesPerBlock(image.info.format);
|
||||||
|
const GLenum format = StoreFormat(bytes_per_block);
|
||||||
|
const u32 pitch = image.info.pitch;
|
||||||
|
|
||||||
|
UNIMPLEMENTED_IF_MSG(!std::has_single_bit(bytes_per_block),
|
||||||
|
"Non-power of two images are not implemented");
|
||||||
|
|
||||||
|
program_manager.BindHostCompute(pitch_unswizzle_program.handle);
|
||||||
|
glFlushMappedNamedBufferRange(map.Handle(), buffer_offset, image.guest_size_bytes);
|
||||||
|
glUniform2ui(LOC_ORIGIN, 0, 0);
|
||||||
|
glUniform2i(LOC_DESTINATION, 0, 0);
|
||||||
|
glUniform1ui(LOC_BYTES_PER_BLOCK, bytes_per_block);
|
||||||
|
glUniform1ui(LOC_PITCH, pitch);
|
||||||
|
glBindImageTexture(BINDING_OUTPUT_IMAGE, image.Handle(), 0, GL_FALSE, 0, GL_WRITE_ONLY, format);
|
||||||
|
for (const SwizzleParameters& swizzle : swizzles) {
|
||||||
|
const Extent3D num_tiles = swizzle.num_tiles;
|
||||||
|
const size_t input_offset = swizzle.buffer_offset + buffer_offset;
|
||||||
|
|
||||||
|
const u32 num_dispatches_x = Common::DivCeil(num_tiles.width, WORKGROUP_SIZE.width);
|
||||||
|
const u32 num_dispatches_y = Common::DivCeil(num_tiles.height, WORKGROUP_SIZE.height);
|
||||||
|
|
||||||
|
glBindBufferRange(GL_SHADER_STORAGE_BUFFER, BINDING_INPUT_BUFFER, map.Handle(),
|
||||||
|
input_offset, image.guest_size_bytes - swizzle.buffer_offset);
|
||||||
|
glDispatchCompute(num_dispatches_x, num_dispatches_y, 1);
|
||||||
|
}
|
||||||
|
program_manager.RestoreGuestCompute();
|
||||||
|
}
|
||||||
|
|
||||||
|
void UtilShaders::CopyBC4(Image& dst_image, Image& src_image, std::span<const ImageCopy> copies) {
|
||||||
|
static constexpr GLuint BINDING_INPUT_IMAGE = 0;
|
||||||
|
static constexpr GLuint BINDING_OUTPUT_IMAGE = 1;
|
||||||
|
static constexpr GLuint LOC_SRC_OFFSET = 0;
|
||||||
|
static constexpr GLuint LOC_DST_OFFSET = 1;
|
||||||
|
|
||||||
|
program_manager.BindHostCompute(copy_bc4_program.handle);
|
||||||
|
|
||||||
|
for (const ImageCopy& copy : copies) {
|
||||||
|
ASSERT(copy.src_subresource.base_layer == 0);
|
||||||
|
ASSERT(copy.src_subresource.num_layers == 1);
|
||||||
|
ASSERT(copy.dst_subresource.base_layer == 0);
|
||||||
|
ASSERT(copy.dst_subresource.num_layers == 1);
|
||||||
|
|
||||||
|
glUniform3ui(LOC_SRC_OFFSET, copy.src_offset.x, copy.src_offset.y, copy.src_offset.z);
|
||||||
|
glUniform3ui(LOC_DST_OFFSET, copy.dst_offset.x, copy.dst_offset.y, copy.dst_offset.z);
|
||||||
|
glBindImageTexture(BINDING_INPUT_IMAGE, src_image.Handle(), copy.src_subresource.base_level,
|
||||||
|
GL_FALSE, 0, GL_READ_ONLY, GL_RG32UI);
|
||||||
|
glBindImageTexture(BINDING_OUTPUT_IMAGE, dst_image.Handle(),
|
||||||
|
copy.dst_subresource.base_level, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA8UI);
|
||||||
|
glDispatchCompute(copy.extent.width, copy.extent.height, copy.extent.depth);
|
||||||
|
}
|
||||||
|
program_manager.RestoreGuestCompute();
|
||||||
|
}
|
||||||
|
|
||||||
|
GLenum StoreFormat(u32 bytes_per_block) {
|
||||||
|
switch (bytes_per_block) {
|
||||||
|
case 1:
|
||||||
|
return GL_R8UI;
|
||||||
|
case 2:
|
||||||
|
return GL_R16UI;
|
||||||
|
case 4:
|
||||||
|
return GL_R32UI;
|
||||||
|
case 8:
|
||||||
|
return GL_RG32UI;
|
||||||
|
case 16:
|
||||||
|
return GL_RGBA32UI;
|
||||||
|
}
|
||||||
|
UNREACHABLE();
|
||||||
|
return GL_R8UI;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace OpenGL
|
@ -0,0 +1,51 @@
|
|||||||
|
// Copyright 2020 yuzu Emulator Project
|
||||||
|
// Licensed under GPLv2 or any later version
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <span>
|
||||||
|
|
||||||
|
#include <glad/glad.h>
|
||||||
|
|
||||||
|
#include "common/common_types.h"
|
||||||
|
#include "video_core/renderer_opengl/gl_resource_manager.h"
|
||||||
|
#include "video_core/texture_cache/types.h"
|
||||||
|
|
||||||
|
namespace OpenGL {
|
||||||
|
|
||||||
|
class Image;
|
||||||
|
class ImageBufferMap;
|
||||||
|
class ProgramManager;
|
||||||
|
|
||||||
|
class UtilShaders {
|
||||||
|
public:
|
||||||
|
explicit UtilShaders(ProgramManager& program_manager);
|
||||||
|
~UtilShaders();
|
||||||
|
|
||||||
|
void BlockLinearUpload2D(Image& image, const ImageBufferMap& map, size_t buffer_offset,
|
||||||
|
std::span<const VideoCommon::SwizzleParameters> swizzles);
|
||||||
|
|
||||||
|
void BlockLinearUpload3D(Image& image, const ImageBufferMap& map, size_t buffer_offset,
|
||||||
|
std::span<const VideoCommon::SwizzleParameters> swizzles);
|
||||||
|
|
||||||
|
void PitchUpload(Image& image, const ImageBufferMap& map, size_t buffer_offset,
|
||||||
|
std::span<const VideoCommon::SwizzleParameters> swizzles);
|
||||||
|
|
||||||
|
void CopyBC4(Image& dst_image, Image& src_image,
|
||||||
|
std::span<const VideoCommon::ImageCopy> copies);
|
||||||
|
|
||||||
|
private:
|
||||||
|
ProgramManager& program_manager;
|
||||||
|
|
||||||
|
OGLBuffer swizzle_table_buffer;
|
||||||
|
|
||||||
|
OGLProgram block_linear_unswizzle_2d_program;
|
||||||
|
OGLProgram block_linear_unswizzle_3d_program;
|
||||||
|
OGLProgram pitch_unswizzle_program;
|
||||||
|
OGLProgram copy_bc4_program;
|
||||||
|
};
|
||||||
|
|
||||||
|
GLenum StoreFormat(u32 bytes_per_block);
|
||||||
|
|
||||||
|
} // namespace OpenGL
|
@ -1,42 +0,0 @@
|
|||||||
// Copyright 2014 Citra Emulator Project
|
|
||||||
// Licensed under GPLv2 or any later version
|
|
||||||
// Refer to the license.txt file included.
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include <fmt/format.h>
|
|
||||||
#include <glad/glad.h>
|
|
||||||
|
|
||||||
#include "common/common_types.h"
|
|
||||||
#include "video_core/renderer_opengl/gl_state_tracker.h"
|
|
||||||
#include "video_core/renderer_opengl/utils.h"
|
|
||||||
|
|
||||||
namespace OpenGL {
|
|
||||||
|
|
||||||
void LabelGLObject(GLenum identifier, GLuint handle, VAddr addr, std::string_view extra_info) {
|
|
||||||
if (!GLAD_GL_KHR_debug) {
|
|
||||||
// We don't need to throw an error as this is just for debugging
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string object_label;
|
|
||||||
if (extra_info.empty()) {
|
|
||||||
switch (identifier) {
|
|
||||||
case GL_TEXTURE:
|
|
||||||
object_label = fmt::format("Texture@0x{:016X}", addr);
|
|
||||||
break;
|
|
||||||
case GL_PROGRAM:
|
|
||||||
object_label = fmt::format("Shader@0x{:016X}", addr);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
object_label = fmt::format("Object(0x{:X})@0x{:016X}", identifier, addr);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
object_label = fmt::format("{}@0x{:016X}", extra_info, addr);
|
|
||||||
}
|
|
||||||
glObjectLabel(identifier, handle, -1, static_cast<const GLchar*>(object_label.c_str()));
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace OpenGL
|
|
@ -1,16 +0,0 @@
|
|||||||
// Copyright 2014 Citra Emulator Project
|
|
||||||
// Licensed under GPLv2 or any later version
|
|
||||||
// Refer to the license.txt file included.
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <string_view>
|
|
||||||
#include <vector>
|
|
||||||
#include <glad/glad.h>
|
|
||||||
#include "common/common_types.h"
|
|
||||||
|
|
||||||
namespace OpenGL {
|
|
||||||
|
|
||||||
void LabelGLObject(GLenum identifier, GLuint handle, VAddr addr, std::string_view extra_info = {});
|
|
||||||
|
|
||||||
} // namespace OpenGL
|
|
@ -0,0 +1,624 @@
|
|||||||
|
// Copyright 2020 yuzu Emulator Project
|
||||||
|
// Licensed under GPLv2 or any later version
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
#include "video_core/host_shaders/convert_depth_to_float_frag_spv.h"
|
||||||
|
#include "video_core/host_shaders/convert_float_to_depth_frag_spv.h"
|
||||||
|
#include "video_core/host_shaders/full_screen_triangle_vert_spv.h"
|
||||||
|
#include "video_core/host_shaders/vulkan_blit_color_float_frag_spv.h"
|
||||||
|
#include "video_core/host_shaders/vulkan_blit_depth_stencil_frag_spv.h"
|
||||||
|
#include "video_core/renderer_vulkan/blit_image.h"
|
||||||
|
#include "video_core/renderer_vulkan/maxwell_to_vk.h"
|
||||||
|
#include "video_core/renderer_vulkan/vk_device.h"
|
||||||
|
#include "video_core/renderer_vulkan/vk_scheduler.h"
|
||||||
|
#include "video_core/renderer_vulkan/vk_shader_util.h"
|
||||||
|
#include "video_core/renderer_vulkan/vk_state_tracker.h"
|
||||||
|
#include "video_core/renderer_vulkan/vk_texture_cache.h"
|
||||||
|
#include "video_core/renderer_vulkan/vk_update_descriptor.h"
|
||||||
|
#include "video_core/renderer_vulkan/wrapper.h"
|
||||||
|
#include "video_core/surface.h"
|
||||||
|
|
||||||
|
namespace Vulkan {
|
||||||
|
|
||||||
|
using VideoCommon::ImageViewType;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
struct PushConstants {
|
||||||
|
std::array<float, 2> tex_scale;
|
||||||
|
std::array<float, 2> tex_offset;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <u32 binding>
|
||||||
|
inline constexpr VkDescriptorSetLayoutBinding TEXTURE_DESCRIPTOR_SET_LAYOUT_BINDING{
|
||||||
|
.binding = binding,
|
||||||
|
.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
|
||||||
|
.descriptorCount = 1,
|
||||||
|
.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT,
|
||||||
|
.pImmutableSamplers = nullptr,
|
||||||
|
};
|
||||||
|
constexpr std::array TWO_TEXTURES_DESCRIPTOR_SET_LAYOUT_BINDINGS{
|
||||||
|
TEXTURE_DESCRIPTOR_SET_LAYOUT_BINDING<0>,
|
||||||
|
TEXTURE_DESCRIPTOR_SET_LAYOUT_BINDING<1>,
|
||||||
|
};
|
||||||
|
constexpr VkDescriptorSetLayoutCreateInfo ONE_TEXTURE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO{
|
||||||
|
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
|
||||||
|
.pNext = nullptr,
|
||||||
|
.flags = 0,
|
||||||
|
.bindingCount = 1,
|
||||||
|
.pBindings = &TEXTURE_DESCRIPTOR_SET_LAYOUT_BINDING<0>,
|
||||||
|
};
|
||||||
|
constexpr VkDescriptorSetLayoutCreateInfo TWO_TEXTURES_DESCRIPTOR_SET_LAYOUT_CREATE_INFO{
|
||||||
|
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
|
||||||
|
.pNext = nullptr,
|
||||||
|
.flags = 0,
|
||||||
|
.bindingCount = static_cast<u32>(TWO_TEXTURES_DESCRIPTOR_SET_LAYOUT_BINDINGS.size()),
|
||||||
|
.pBindings = TWO_TEXTURES_DESCRIPTOR_SET_LAYOUT_BINDINGS.data(),
|
||||||
|
};
|
||||||
|
constexpr VkPushConstantRange PUSH_CONSTANT_RANGE{
|
||||||
|
.stageFlags = VK_SHADER_STAGE_VERTEX_BIT,
|
||||||
|
.offset = 0,
|
||||||
|
.size = sizeof(PushConstants),
|
||||||
|
};
|
||||||
|
constexpr VkPipelineVertexInputStateCreateInfo PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO{
|
||||||
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,
|
||||||
|
.pNext = nullptr,
|
||||||
|
.flags = 0,
|
||||||
|
.vertexBindingDescriptionCount = 0,
|
||||||
|
.pVertexBindingDescriptions = nullptr,
|
||||||
|
.vertexAttributeDescriptionCount = 0,
|
||||||
|
.pVertexAttributeDescriptions = nullptr,
|
||||||
|
};
|
||||||
|
constexpr VkPipelineInputAssemblyStateCreateInfo PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO{
|
||||||
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
|
||||||
|
.pNext = nullptr,
|
||||||
|
.flags = 0,
|
||||||
|
.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST,
|
||||||
|
.primitiveRestartEnable = VK_FALSE,
|
||||||
|
};
|
||||||
|
constexpr VkPipelineViewportStateCreateInfo PIPELINE_VIEWPORT_STATE_CREATE_INFO{
|
||||||
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO,
|
||||||
|
.pNext = nullptr,
|
||||||
|
.flags = 0,
|
||||||
|
.viewportCount = 1,
|
||||||
|
.pViewports = nullptr,
|
||||||
|
.scissorCount = 1,
|
||||||
|
.pScissors = nullptr,
|
||||||
|
};
|
||||||
|
constexpr VkPipelineRasterizationStateCreateInfo PIPELINE_RASTERIZATION_STATE_CREATE_INFO{
|
||||||
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO,
|
||||||
|
.pNext = nullptr,
|
||||||
|
.flags = 0,
|
||||||
|
.depthClampEnable = VK_FALSE,
|
||||||
|
.rasterizerDiscardEnable = VK_FALSE,
|
||||||
|
.polygonMode = VK_POLYGON_MODE_FILL,
|
||||||
|
.cullMode = VK_CULL_MODE_BACK_BIT,
|
||||||
|
.frontFace = VK_FRONT_FACE_CLOCKWISE,
|
||||||
|
.depthBiasEnable = VK_FALSE,
|
||||||
|
.depthBiasConstantFactor = 0.0f,
|
||||||
|
.depthBiasClamp = 0.0f,
|
||||||
|
.depthBiasSlopeFactor = 0.0f,
|
||||||
|
.lineWidth = 1.0f,
|
||||||
|
};
|
||||||
|
constexpr VkPipelineMultisampleStateCreateInfo PIPELINE_MULTISAMPLE_STATE_CREATE_INFO{
|
||||||
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO,
|
||||||
|
.pNext = nullptr,
|
||||||
|
.flags = 0,
|
||||||
|
.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT,
|
||||||
|
.sampleShadingEnable = VK_FALSE,
|
||||||
|
.minSampleShading = 0.0f,
|
||||||
|
.pSampleMask = nullptr,
|
||||||
|
.alphaToCoverageEnable = VK_FALSE,
|
||||||
|
.alphaToOneEnable = VK_FALSE,
|
||||||
|
};
|
||||||
|
constexpr std::array DYNAMIC_STATES{
|
||||||
|
VK_DYNAMIC_STATE_VIEWPORT,
|
||||||
|
VK_DYNAMIC_STATE_SCISSOR,
|
||||||
|
};
|
||||||
|
constexpr VkPipelineDynamicStateCreateInfo PIPELINE_DYNAMIC_STATE_CREATE_INFO{
|
||||||
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO,
|
||||||
|
.pNext = nullptr,
|
||||||
|
.flags = 0,
|
||||||
|
.dynamicStateCount = static_cast<u32>(DYNAMIC_STATES.size()),
|
||||||
|
.pDynamicStates = DYNAMIC_STATES.data(),
|
||||||
|
};
|
||||||
|
constexpr VkPipelineColorBlendStateCreateInfo PIPELINE_COLOR_BLEND_STATE_EMPTY_CREATE_INFO{
|
||||||
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO,
|
||||||
|
.pNext = nullptr,
|
||||||
|
.flags = 0,
|
||||||
|
.logicOpEnable = VK_FALSE,
|
||||||
|
.logicOp = VK_LOGIC_OP_CLEAR,
|
||||||
|
.attachmentCount = 0,
|
||||||
|
.pAttachments = nullptr,
|
||||||
|
.blendConstants = {0.0f, 0.0f, 0.0f, 0.0f},
|
||||||
|
};
|
||||||
|
constexpr VkPipelineColorBlendAttachmentState PIPELINE_COLOR_BLEND_ATTACHMENT_STATE{
|
||||||
|
.blendEnable = VK_FALSE,
|
||||||
|
.srcColorBlendFactor = VK_BLEND_FACTOR_ZERO,
|
||||||
|
.dstColorBlendFactor = VK_BLEND_FACTOR_ZERO,
|
||||||
|
.colorBlendOp = VK_BLEND_OP_ADD,
|
||||||
|
.srcAlphaBlendFactor = VK_BLEND_FACTOR_ZERO,
|
||||||
|
.dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO,
|
||||||
|
.alphaBlendOp = VK_BLEND_OP_ADD,
|
||||||
|
.colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT |
|
||||||
|
VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT,
|
||||||
|
};
|
||||||
|
constexpr VkPipelineColorBlendStateCreateInfo PIPELINE_COLOR_BLEND_STATE_GENERIC_CREATE_INFO{
|
||||||
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO,
|
||||||
|
.pNext = nullptr,
|
||||||
|
.flags = 0,
|
||||||
|
.logicOpEnable = VK_FALSE,
|
||||||
|
.logicOp = VK_LOGIC_OP_CLEAR,
|
||||||
|
.attachmentCount = 1,
|
||||||
|
.pAttachments = &PIPELINE_COLOR_BLEND_ATTACHMENT_STATE,
|
||||||
|
.blendConstants = {0.0f, 0.0f, 0.0f, 0.0f},
|
||||||
|
};
|
||||||
|
constexpr VkPipelineDepthStencilStateCreateInfo PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO{
|
||||||
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO,
|
||||||
|
.pNext = nullptr,
|
||||||
|
.flags = 0,
|
||||||
|
.depthTestEnable = VK_TRUE,
|
||||||
|
.depthWriteEnable = VK_TRUE,
|
||||||
|
.depthCompareOp = VK_COMPARE_OP_ALWAYS,
|
||||||
|
.depthBoundsTestEnable = VK_FALSE,
|
||||||
|
.stencilTestEnable = VK_FALSE,
|
||||||
|
.front = VkStencilOpState{},
|
||||||
|
.back = VkStencilOpState{},
|
||||||
|
.minDepthBounds = 0.0f,
|
||||||
|
.maxDepthBounds = 0.0f,
|
||||||
|
};
|
||||||
|
|
||||||
|
template <VkFilter filter>
|
||||||
|
inline constexpr VkSamplerCreateInfo SAMPLER_CREATE_INFO{
|
||||||
|
.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,
|
||||||
|
.pNext = nullptr,
|
||||||
|
.flags = 0,
|
||||||
|
.magFilter = filter,
|
||||||
|
.minFilter = filter,
|
||||||
|
.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST,
|
||||||
|
.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER,
|
||||||
|
.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER,
|
||||||
|
.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER,
|
||||||
|
.mipLodBias = 0.0f,
|
||||||
|
.anisotropyEnable = VK_FALSE,
|
||||||
|
.maxAnisotropy = 0.0f,
|
||||||
|
.compareEnable = VK_FALSE,
|
||||||
|
.compareOp = VK_COMPARE_OP_NEVER,
|
||||||
|
.minLod = 0.0f,
|
||||||
|
.maxLod = 0.0f,
|
||||||
|
.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE,
|
||||||
|
.unnormalizedCoordinates = VK_TRUE,
|
||||||
|
};
|
||||||
|
|
||||||
|
constexpr VkPipelineLayoutCreateInfo PipelineLayoutCreateInfo(
|
||||||
|
const VkDescriptorSetLayout* set_layout) {
|
||||||
|
return VkPipelineLayoutCreateInfo{
|
||||||
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
|
||||||
|
.pNext = nullptr,
|
||||||
|
.flags = 0,
|
||||||
|
.setLayoutCount = 1,
|
||||||
|
.pSetLayouts = set_layout,
|
||||||
|
.pushConstantRangeCount = 1,
|
||||||
|
.pPushConstantRanges = &PUSH_CONSTANT_RANGE,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr VkPipelineShaderStageCreateInfo PipelineShaderStageCreateInfo(VkShaderStageFlagBits stage,
|
||||||
|
VkShaderModule shader) {
|
||||||
|
return VkPipelineShaderStageCreateInfo{
|
||||||
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
|
||||||
|
.pNext = nullptr,
|
||||||
|
.flags = 0,
|
||||||
|
.stage = stage,
|
||||||
|
.module = shader,
|
||||||
|
.pName = "main",
|
||||||
|
.pSpecializationInfo = nullptr,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr std::array<VkPipelineShaderStageCreateInfo, 2> MakeStages(
|
||||||
|
VkShaderModule vertex_shader, VkShaderModule fragment_shader) {
|
||||||
|
return std::array{
|
||||||
|
PipelineShaderStageCreateInfo(VK_SHADER_STAGE_VERTEX_BIT, vertex_shader),
|
||||||
|
PipelineShaderStageCreateInfo(VK_SHADER_STAGE_FRAGMENT_BIT, fragment_shader),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
void UpdateOneTextureDescriptorSet(const VKDevice& device, VkDescriptorSet descriptor_set,
|
||||||
|
VkSampler sampler, VkImageView image_view) {
|
||||||
|
const VkDescriptorImageInfo image_info{
|
||||||
|
.sampler = sampler,
|
||||||
|
.imageView = image_view,
|
||||||
|
.imageLayout = VK_IMAGE_LAYOUT_GENERAL,
|
||||||
|
};
|
||||||
|
const VkWriteDescriptorSet write_descriptor_set{
|
||||||
|
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
|
||||||
|
.pNext = nullptr,
|
||||||
|
.dstSet = descriptor_set,
|
||||||
|
.dstBinding = 0,
|
||||||
|
.dstArrayElement = 0,
|
||||||
|
.descriptorCount = 1,
|
||||||
|
.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
|
||||||
|
.pImageInfo = &image_info,
|
||||||
|
.pBufferInfo = nullptr,
|
||||||
|
.pTexelBufferView = nullptr,
|
||||||
|
};
|
||||||
|
device.GetLogical().UpdateDescriptorSets(write_descriptor_set, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UpdateTwoTexturesDescriptorSet(const VKDevice& device, VkDescriptorSet descriptor_set,
|
||||||
|
VkSampler sampler, VkImageView image_view_0,
|
||||||
|
VkImageView image_view_1) {
|
||||||
|
const VkDescriptorImageInfo image_info_0{
|
||||||
|
.sampler = sampler,
|
||||||
|
.imageView = image_view_0,
|
||||||
|
.imageLayout = VK_IMAGE_LAYOUT_GENERAL,
|
||||||
|
};
|
||||||
|
const VkDescriptorImageInfo image_info_1{
|
||||||
|
.sampler = sampler,
|
||||||
|
.imageView = image_view_1,
|
||||||
|
.imageLayout = VK_IMAGE_LAYOUT_GENERAL,
|
||||||
|
};
|
||||||
|
const std::array write_descriptor_sets{
|
||||||
|
VkWriteDescriptorSet{
|
||||||
|
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
|
||||||
|
.pNext = nullptr,
|
||||||
|
.dstSet = descriptor_set,
|
||||||
|
.dstBinding = 0,
|
||||||
|
.dstArrayElement = 0,
|
||||||
|
.descriptorCount = 1,
|
||||||
|
.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
|
||||||
|
.pImageInfo = &image_info_0,
|
||||||
|
.pBufferInfo = nullptr,
|
||||||
|
.pTexelBufferView = nullptr,
|
||||||
|
},
|
||||||
|
VkWriteDescriptorSet{
|
||||||
|
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
|
||||||
|
.pNext = nullptr,
|
||||||
|
.dstSet = descriptor_set,
|
||||||
|
.dstBinding = 1,
|
||||||
|
.dstArrayElement = 0,
|
||||||
|
.descriptorCount = 1,
|
||||||
|
.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
|
||||||
|
.pImageInfo = &image_info_1,
|
||||||
|
.pBufferInfo = nullptr,
|
||||||
|
.pTexelBufferView = nullptr,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
device.GetLogical().UpdateDescriptorSets(write_descriptor_sets, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BindBlitState(vk::CommandBuffer cmdbuf, VkPipelineLayout layout,
|
||||||
|
const std::array<Offset2D, 2>& dst_region,
|
||||||
|
const std::array<Offset2D, 2>& src_region) {
|
||||||
|
const VkOffset2D offset{
|
||||||
|
.x = std::min(dst_region[0].x, dst_region[1].x),
|
||||||
|
.y = std::min(dst_region[0].y, dst_region[1].y),
|
||||||
|
};
|
||||||
|
const VkExtent2D extent{
|
||||||
|
.width = static_cast<u32>(std::abs(dst_region[1].x - dst_region[0].x)),
|
||||||
|
.height = static_cast<u32>(std::abs(dst_region[1].y - dst_region[0].y)),
|
||||||
|
};
|
||||||
|
const VkViewport viewport{
|
||||||
|
.x = static_cast<float>(offset.x),
|
||||||
|
.y = static_cast<float>(offset.y),
|
||||||
|
.width = static_cast<float>(extent.width),
|
||||||
|
.height = static_cast<float>(extent.height),
|
||||||
|
.minDepth = 0.0f,
|
||||||
|
.maxDepth = 1.0f,
|
||||||
|
};
|
||||||
|
// TODO: Support scissored blits
|
||||||
|
const VkRect2D scissor{
|
||||||
|
.offset = offset,
|
||||||
|
.extent = extent,
|
||||||
|
};
|
||||||
|
const float scale_x = static_cast<float>(src_region[1].x - src_region[0].x);
|
||||||
|
const float scale_y = static_cast<float>(src_region[1].y - src_region[0].y);
|
||||||
|
const PushConstants push_constants{
|
||||||
|
.tex_scale = {scale_x, scale_y},
|
||||||
|
.tex_offset = {static_cast<float>(src_region[0].x), static_cast<float>(src_region[0].y)},
|
||||||
|
};
|
||||||
|
cmdbuf.SetViewport(0, viewport);
|
||||||
|
cmdbuf.SetScissor(0, scissor);
|
||||||
|
cmdbuf.PushConstants(layout, VK_SHADER_STAGE_VERTEX_BIT, push_constants);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // Anonymous namespace
|
||||||
|
|
||||||
|
BlitImageHelper::BlitImageHelper(const VKDevice& device_, VKScheduler& scheduler_,
|
||||||
|
StateTracker& state_tracker_, VKDescriptorPool& descriptor_pool)
|
||||||
|
: device{device_}, scheduler{scheduler_}, state_tracker{state_tracker_},
|
||||||
|
one_texture_set_layout(device.GetLogical().CreateDescriptorSetLayout(
|
||||||
|
ONE_TEXTURE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO)),
|
||||||
|
two_textures_set_layout(device.GetLogical().CreateDescriptorSetLayout(
|
||||||
|
TWO_TEXTURES_DESCRIPTOR_SET_LAYOUT_CREATE_INFO)),
|
||||||
|
one_texture_descriptor_allocator(descriptor_pool, *one_texture_set_layout),
|
||||||
|
two_textures_descriptor_allocator(descriptor_pool, *two_textures_set_layout),
|
||||||
|
one_texture_pipeline_layout(device.GetLogical().CreatePipelineLayout(
|
||||||
|
PipelineLayoutCreateInfo(one_texture_set_layout.address()))),
|
||||||
|
two_textures_pipeline_layout(device.GetLogical().CreatePipelineLayout(
|
||||||
|
PipelineLayoutCreateInfo(two_textures_set_layout.address()))),
|
||||||
|
full_screen_vert(BuildShader(device, FULL_SCREEN_TRIANGLE_VERT_SPV)),
|
||||||
|
blit_color_to_color_frag(BuildShader(device, VULKAN_BLIT_COLOR_FLOAT_FRAG_SPV)),
|
||||||
|
convert_depth_to_float_frag(BuildShader(device, CONVERT_DEPTH_TO_FLOAT_FRAG_SPV)),
|
||||||
|
convert_float_to_depth_frag(BuildShader(device, CONVERT_FLOAT_TO_DEPTH_FRAG_SPV)),
|
||||||
|
linear_sampler(device.GetLogical().CreateSampler(SAMPLER_CREATE_INFO<VK_FILTER_LINEAR>)),
|
||||||
|
nearest_sampler(device.GetLogical().CreateSampler(SAMPLER_CREATE_INFO<VK_FILTER_NEAREST>)) {
|
||||||
|
if (device.IsExtShaderStencilExportSupported()) {
|
||||||
|
blit_depth_stencil_frag = BuildShader(device, VULKAN_BLIT_DEPTH_STENCIL_FRAG_SPV);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BlitImageHelper::~BlitImageHelper() = default;
|
||||||
|
|
||||||
|
void BlitImageHelper::BlitColor(const Framebuffer* dst_framebuffer, const ImageView& src_image_view,
|
||||||
|
const std::array<Offset2D, 2>& dst_region,
|
||||||
|
const std::array<Offset2D, 2>& src_region,
|
||||||
|
Tegra::Engines::Fermi2D::Filter filter,
|
||||||
|
Tegra::Engines::Fermi2D::Operation operation) {
|
||||||
|
const bool is_linear = filter == Tegra::Engines::Fermi2D::Filter::Bilinear;
|
||||||
|
const BlitImagePipelineKey key{
|
||||||
|
.renderpass = dst_framebuffer->RenderPass(),
|
||||||
|
.operation = operation,
|
||||||
|
};
|
||||||
|
const VkPipelineLayout layout = *one_texture_pipeline_layout;
|
||||||
|
const VkImageView src_view = src_image_view.Handle(ImageViewType::e2D);
|
||||||
|
const VkSampler sampler = is_linear ? *linear_sampler : *nearest_sampler;
|
||||||
|
const VkPipeline pipeline = FindOrEmplacePipeline(key);
|
||||||
|
const VkDescriptorSet descriptor_set = one_texture_descriptor_allocator.Commit();
|
||||||
|
scheduler.RequestRenderpass(dst_framebuffer);
|
||||||
|
scheduler.Record([dst_region, src_region, pipeline, layout, sampler, src_view, descriptor_set,
|
||||||
|
&device = device](vk::CommandBuffer cmdbuf) {
|
||||||
|
// TODO: Barriers
|
||||||
|
UpdateOneTextureDescriptorSet(device, descriptor_set, sampler, src_view);
|
||||||
|
cmdbuf.BindPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
|
||||||
|
cmdbuf.BindDescriptorSets(VK_PIPELINE_BIND_POINT_GRAPHICS, layout, 0, descriptor_set,
|
||||||
|
nullptr);
|
||||||
|
BindBlitState(cmdbuf, layout, dst_region, src_region);
|
||||||
|
cmdbuf.Draw(3, 1, 0, 0);
|
||||||
|
});
|
||||||
|
scheduler.InvalidateState();
|
||||||
|
}
|
||||||
|
|
||||||
|
void BlitImageHelper::BlitDepthStencil(const Framebuffer* dst_framebuffer,
|
||||||
|
VkImageView src_depth_view, VkImageView src_stencil_view,
|
||||||
|
const std::array<Offset2D, 2>& dst_region,
|
||||||
|
const std::array<Offset2D, 2>& src_region,
|
||||||
|
Tegra::Engines::Fermi2D::Filter filter,
|
||||||
|
Tegra::Engines::Fermi2D::Operation operation) {
|
||||||
|
ASSERT(filter == Tegra::Engines::Fermi2D::Filter::Point);
|
||||||
|
ASSERT(operation == Tegra::Engines::Fermi2D::Operation::SrcCopy);
|
||||||
|
|
||||||
|
const VkPipelineLayout layout = *two_textures_pipeline_layout;
|
||||||
|
const VkSampler sampler = *nearest_sampler;
|
||||||
|
const VkPipeline pipeline = BlitDepthStencilPipeline(dst_framebuffer->RenderPass());
|
||||||
|
const VkDescriptorSet descriptor_set = two_textures_descriptor_allocator.Commit();
|
||||||
|
scheduler.RequestRenderpass(dst_framebuffer);
|
||||||
|
scheduler.Record([dst_region, src_region, pipeline, layout, sampler, src_depth_view,
|
||||||
|
src_stencil_view, descriptor_set,
|
||||||
|
&device = device](vk::CommandBuffer cmdbuf) {
|
||||||
|
// TODO: Barriers
|
||||||
|
UpdateTwoTexturesDescriptorSet(device, descriptor_set, sampler, src_depth_view,
|
||||||
|
src_stencil_view);
|
||||||
|
cmdbuf.BindPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
|
||||||
|
cmdbuf.BindDescriptorSets(VK_PIPELINE_BIND_POINT_GRAPHICS, layout, 0, descriptor_set,
|
||||||
|
nullptr);
|
||||||
|
BindBlitState(cmdbuf, layout, dst_region, src_region);
|
||||||
|
cmdbuf.Draw(3, 1, 0, 0);
|
||||||
|
});
|
||||||
|
scheduler.InvalidateState();
|
||||||
|
}
|
||||||
|
|
||||||
|
void BlitImageHelper::ConvertD32ToR32(const Framebuffer* dst_framebuffer,
|
||||||
|
const ImageView& src_image_view) {
|
||||||
|
ConvertDepthToColorPipeline(convert_d32_to_r32_pipeline, dst_framebuffer->RenderPass());
|
||||||
|
Convert(*convert_d32_to_r32_pipeline, dst_framebuffer, src_image_view);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BlitImageHelper::ConvertR32ToD32(const Framebuffer* dst_framebuffer,
|
||||||
|
const ImageView& src_image_view) {
|
||||||
|
|
||||||
|
ConvertColorToDepthPipeline(convert_r32_to_d32_pipeline, dst_framebuffer->RenderPass());
|
||||||
|
Convert(*convert_r32_to_d32_pipeline, dst_framebuffer, src_image_view);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BlitImageHelper::ConvertD16ToR16(const Framebuffer* dst_framebuffer,
|
||||||
|
const ImageView& src_image_view) {
|
||||||
|
ConvertDepthToColorPipeline(convert_d16_to_r16_pipeline, dst_framebuffer->RenderPass());
|
||||||
|
Convert(*convert_d16_to_r16_pipeline, dst_framebuffer, src_image_view);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BlitImageHelper::ConvertR16ToD16(const Framebuffer* dst_framebuffer,
|
||||||
|
const ImageView& src_image_view) {
|
||||||
|
ConvertColorToDepthPipeline(convert_r16_to_d16_pipeline, dst_framebuffer->RenderPass());
|
||||||
|
Convert(*convert_r16_to_d16_pipeline, dst_framebuffer, src_image_view);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BlitImageHelper::Convert(VkPipeline pipeline, const Framebuffer* dst_framebuffer,
|
||||||
|
const ImageView& src_image_view) {
|
||||||
|
const VkPipelineLayout layout = *one_texture_pipeline_layout;
|
||||||
|
const VkImageView src_view = src_image_view.Handle(ImageViewType::e2D);
|
||||||
|
const VkSampler sampler = *nearest_sampler;
|
||||||
|
const VkDescriptorSet descriptor_set = one_texture_descriptor_allocator.Commit();
|
||||||
|
const VkExtent2D extent{
|
||||||
|
.width = src_image_view.size.width,
|
||||||
|
.height = src_image_view.size.height,
|
||||||
|
};
|
||||||
|
scheduler.RequestRenderpass(dst_framebuffer);
|
||||||
|
scheduler.Record([pipeline, layout, sampler, src_view, descriptor_set, extent,
|
||||||
|
&device = device](vk::CommandBuffer cmdbuf) {
|
||||||
|
const VkOffset2D offset{
|
||||||
|
.x = 0,
|
||||||
|
.y = 0,
|
||||||
|
};
|
||||||
|
const VkViewport viewport{
|
||||||
|
.x = 0.0f,
|
||||||
|
.y = 0.0f,
|
||||||
|
.width = static_cast<float>(extent.width),
|
||||||
|
.height = static_cast<float>(extent.height),
|
||||||
|
.minDepth = 0.0f,
|
||||||
|
.maxDepth = 0.0f,
|
||||||
|
};
|
||||||
|
const VkRect2D scissor{
|
||||||
|
.offset = offset,
|
||||||
|
.extent = extent,
|
||||||
|
};
|
||||||
|
const PushConstants push_constants{
|
||||||
|
.tex_scale = {viewport.width, viewport.height},
|
||||||
|
.tex_offset = {0.0f, 0.0f},
|
||||||
|
};
|
||||||
|
UpdateOneTextureDescriptorSet(device, descriptor_set, sampler, src_view);
|
||||||
|
|
||||||
|
// TODO: Barriers
|
||||||
|
cmdbuf.BindPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
|
||||||
|
cmdbuf.BindDescriptorSets(VK_PIPELINE_BIND_POINT_GRAPHICS, layout, 0, descriptor_set,
|
||||||
|
nullptr);
|
||||||
|
cmdbuf.SetViewport(0, viewport);
|
||||||
|
cmdbuf.SetScissor(0, scissor);
|
||||||
|
cmdbuf.PushConstants(layout, VK_SHADER_STAGE_VERTEX_BIT, push_constants);
|
||||||
|
cmdbuf.Draw(3, 1, 0, 0);
|
||||||
|
});
|
||||||
|
scheduler.InvalidateState();
|
||||||
|
}
|
||||||
|
|
||||||
|
VkPipeline BlitImageHelper::FindOrEmplacePipeline(const BlitImagePipelineKey& key) {
|
||||||
|
const auto it = std::ranges::find(blit_color_keys, key);
|
||||||
|
if (it != blit_color_keys.end()) {
|
||||||
|
return *blit_color_pipelines[std::distance(blit_color_keys.begin(), it)];
|
||||||
|
}
|
||||||
|
blit_color_keys.push_back(key);
|
||||||
|
|
||||||
|
const std::array stages = MakeStages(*full_screen_vert, *blit_color_to_color_frag);
|
||||||
|
const VkPipelineColorBlendAttachmentState blend_attachment{
|
||||||
|
.blendEnable = VK_FALSE,
|
||||||
|
.srcColorBlendFactor = VK_BLEND_FACTOR_ZERO,
|
||||||
|
.dstColorBlendFactor = VK_BLEND_FACTOR_ZERO,
|
||||||
|
.colorBlendOp = VK_BLEND_OP_ADD,
|
||||||
|
.srcAlphaBlendFactor = VK_BLEND_FACTOR_ZERO,
|
||||||
|
.dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO,
|
||||||
|
.alphaBlendOp = VK_BLEND_OP_ADD,
|
||||||
|
.colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT |
|
||||||
|
VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT,
|
||||||
|
};
|
||||||
|
// TODO: programmable blending
|
||||||
|
const VkPipelineColorBlendStateCreateInfo color_blend_create_info{
|
||||||
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO,
|
||||||
|
.pNext = nullptr,
|
||||||
|
.flags = 0,
|
||||||
|
.logicOpEnable = VK_FALSE,
|
||||||
|
.logicOp = VK_LOGIC_OP_CLEAR,
|
||||||
|
.attachmentCount = 1,
|
||||||
|
.pAttachments = &blend_attachment,
|
||||||
|
.blendConstants = {0.0f, 0.0f, 0.0f, 0.0f},
|
||||||
|
};
|
||||||
|
blit_color_pipelines.push_back(device.GetLogical().CreateGraphicsPipeline({
|
||||||
|
.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
|
||||||
|
.pNext = nullptr,
|
||||||
|
.flags = 0,
|
||||||
|
.stageCount = static_cast<u32>(stages.size()),
|
||||||
|
.pStages = stages.data(),
|
||||||
|
.pVertexInputState = &PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,
|
||||||
|
.pInputAssemblyState = &PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
|
||||||
|
.pTessellationState = nullptr,
|
||||||
|
.pViewportState = &PIPELINE_VIEWPORT_STATE_CREATE_INFO,
|
||||||
|
.pRasterizationState = &PIPELINE_RASTERIZATION_STATE_CREATE_INFO,
|
||||||
|
.pMultisampleState = &PIPELINE_MULTISAMPLE_STATE_CREATE_INFO,
|
||||||
|
.pDepthStencilState = nullptr,
|
||||||
|
.pColorBlendState = &color_blend_create_info,
|
||||||
|
.pDynamicState = &PIPELINE_DYNAMIC_STATE_CREATE_INFO,
|
||||||
|
.layout = *one_texture_pipeline_layout,
|
||||||
|
.renderPass = key.renderpass,
|
||||||
|
.subpass = 0,
|
||||||
|
.basePipelineHandle = VK_NULL_HANDLE,
|
||||||
|
.basePipelineIndex = 0,
|
||||||
|
}));
|
||||||
|
return *blit_color_pipelines.back();
|
||||||
|
}
|
||||||
|
|
||||||
|
VkPipeline BlitImageHelper::BlitDepthStencilPipeline(VkRenderPass renderpass) {
|
||||||
|
if (blit_depth_stencil_pipeline) {
|
||||||
|
return *blit_depth_stencil_pipeline;
|
||||||
|
}
|
||||||
|
const std::array stages = MakeStages(*full_screen_vert, *blit_depth_stencil_frag);
|
||||||
|
blit_depth_stencil_pipeline = device.GetLogical().CreateGraphicsPipeline({
|
||||||
|
.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
|
||||||
|
.pNext = nullptr,
|
||||||
|
.flags = 0,
|
||||||
|
.stageCount = static_cast<u32>(stages.size()),
|
||||||
|
.pStages = stages.data(),
|
||||||
|
.pVertexInputState = &PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,
|
||||||
|
.pInputAssemblyState = &PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
|
||||||
|
.pTessellationState = nullptr,
|
||||||
|
.pViewportState = &PIPELINE_VIEWPORT_STATE_CREATE_INFO,
|
||||||
|
.pRasterizationState = &PIPELINE_RASTERIZATION_STATE_CREATE_INFO,
|
||||||
|
.pMultisampleState = &PIPELINE_MULTISAMPLE_STATE_CREATE_INFO,
|
||||||
|
.pDepthStencilState = &PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO,
|
||||||
|
.pColorBlendState = &PIPELINE_COLOR_BLEND_STATE_EMPTY_CREATE_INFO,
|
||||||
|
.pDynamicState = &PIPELINE_DYNAMIC_STATE_CREATE_INFO,
|
||||||
|
.layout = *two_textures_pipeline_layout,
|
||||||
|
.renderPass = renderpass,
|
||||||
|
.subpass = 0,
|
||||||
|
.basePipelineHandle = VK_NULL_HANDLE,
|
||||||
|
.basePipelineIndex = 0,
|
||||||
|
});
|
||||||
|
return *blit_depth_stencil_pipeline;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BlitImageHelper::ConvertDepthToColorPipeline(vk::Pipeline& pipeline, VkRenderPass renderpass) {
|
||||||
|
if (pipeline) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const std::array stages = MakeStages(*full_screen_vert, *convert_depth_to_float_frag);
|
||||||
|
pipeline = device.GetLogical().CreateGraphicsPipeline({
|
||||||
|
.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
|
||||||
|
.pNext = nullptr,
|
||||||
|
.flags = 0,
|
||||||
|
.stageCount = static_cast<u32>(stages.size()),
|
||||||
|
.pStages = stages.data(),
|
||||||
|
.pVertexInputState = &PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,
|
||||||
|
.pInputAssemblyState = &PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
|
||||||
|
.pTessellationState = nullptr,
|
||||||
|
.pViewportState = &PIPELINE_VIEWPORT_STATE_CREATE_INFO,
|
||||||
|
.pRasterizationState = &PIPELINE_RASTERIZATION_STATE_CREATE_INFO,
|
||||||
|
.pMultisampleState = &PIPELINE_MULTISAMPLE_STATE_CREATE_INFO,
|
||||||
|
.pDepthStencilState = nullptr,
|
||||||
|
.pColorBlendState = &PIPELINE_COLOR_BLEND_STATE_GENERIC_CREATE_INFO,
|
||||||
|
.pDynamicState = &PIPELINE_DYNAMIC_STATE_CREATE_INFO,
|
||||||
|
.layout = *one_texture_pipeline_layout,
|
||||||
|
.renderPass = renderpass,
|
||||||
|
.subpass = 0,
|
||||||
|
.basePipelineHandle = VK_NULL_HANDLE,
|
||||||
|
.basePipelineIndex = 0,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void BlitImageHelper::ConvertColorToDepthPipeline(vk::Pipeline& pipeline, VkRenderPass renderpass) {
|
||||||
|
if (pipeline) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const std::array stages = MakeStages(*full_screen_vert, *convert_float_to_depth_frag);
|
||||||
|
pipeline = device.GetLogical().CreateGraphicsPipeline({
|
||||||
|
.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
|
||||||
|
.pNext = nullptr,
|
||||||
|
.flags = 0,
|
||||||
|
.stageCount = static_cast<u32>(stages.size()),
|
||||||
|
.pStages = stages.data(),
|
||||||
|
.pVertexInputState = &PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,
|
||||||
|
.pInputAssemblyState = &PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
|
||||||
|
.pTessellationState = nullptr,
|
||||||
|
.pViewportState = &PIPELINE_VIEWPORT_STATE_CREATE_INFO,
|
||||||
|
.pRasterizationState = &PIPELINE_RASTERIZATION_STATE_CREATE_INFO,
|
||||||
|
.pMultisampleState = &PIPELINE_MULTISAMPLE_STATE_CREATE_INFO,
|
||||||
|
.pDepthStencilState = &PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO,
|
||||||
|
.pColorBlendState = &PIPELINE_COLOR_BLEND_STATE_EMPTY_CREATE_INFO,
|
||||||
|
.pDynamicState = &PIPELINE_DYNAMIC_STATE_CREATE_INFO,
|
||||||
|
.layout = *one_texture_pipeline_layout,
|
||||||
|
.renderPass = renderpass,
|
||||||
|
.subpass = 0,
|
||||||
|
.basePipelineHandle = VK_NULL_HANDLE,
|
||||||
|
.basePipelineIndex = 0,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Vulkan
|
@ -0,0 +1,97 @@
|
|||||||
|
// Copyright 2020 yuzu Emulator Project
|
||||||
|
// Licensed under GPLv2 or any later version
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <compare>
|
||||||
|
|
||||||
|
#include "video_core/engines/fermi_2d.h"
|
||||||
|
#include "video_core/renderer_vulkan/vk_descriptor_pool.h"
|
||||||
|
#include "video_core/renderer_vulkan/wrapper.h"
|
||||||
|
#include "video_core/texture_cache/types.h"
|
||||||
|
|
||||||
|
namespace Vulkan {
|
||||||
|
|
||||||
|
using VideoCommon::Offset2D;
|
||||||
|
|
||||||
|
class VKDevice;
|
||||||
|
class VKScheduler;
|
||||||
|
class StateTracker;
|
||||||
|
|
||||||
|
class Framebuffer;
|
||||||
|
class ImageView;
|
||||||
|
|
||||||
|
struct BlitImagePipelineKey {
|
||||||
|
constexpr auto operator<=>(const BlitImagePipelineKey&) const noexcept = default;
|
||||||
|
|
||||||
|
VkRenderPass renderpass;
|
||||||
|
Tegra::Engines::Fermi2D::Operation operation;
|
||||||
|
};
|
||||||
|
|
||||||
|
class BlitImageHelper {
|
||||||
|
public:
|
||||||
|
explicit BlitImageHelper(const VKDevice& device, VKScheduler& scheduler,
|
||||||
|
StateTracker& state_tracker, VKDescriptorPool& descriptor_pool);
|
||||||
|
~BlitImageHelper();
|
||||||
|
|
||||||
|
void BlitColor(const Framebuffer* dst_framebuffer, const ImageView& src_image_view,
|
||||||
|
const std::array<Offset2D, 2>& dst_region,
|
||||||
|
const std::array<Offset2D, 2>& src_region,
|
||||||
|
Tegra::Engines::Fermi2D::Filter filter,
|
||||||
|
Tegra::Engines::Fermi2D::Operation operation);
|
||||||
|
|
||||||
|
void BlitDepthStencil(const Framebuffer* dst_framebuffer, VkImageView src_depth_view,
|
||||||
|
VkImageView src_stencil_view, const std::array<Offset2D, 2>& dst_region,
|
||||||
|
const std::array<Offset2D, 2>& src_region,
|
||||||
|
Tegra::Engines::Fermi2D::Filter filter,
|
||||||
|
Tegra::Engines::Fermi2D::Operation operation);
|
||||||
|
|
||||||
|
void ConvertD32ToR32(const Framebuffer* dst_framebuffer, const ImageView& src_image_view);
|
||||||
|
|
||||||
|
void ConvertR32ToD32(const Framebuffer* dst_framebuffer, const ImageView& src_image_view);
|
||||||
|
|
||||||
|
void ConvertD16ToR16(const Framebuffer* dst_framebuffer, const ImageView& src_image_view);
|
||||||
|
|
||||||
|
void ConvertR16ToD16(const Framebuffer* dst_framebuffer, const ImageView& src_image_view);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void Convert(VkPipeline pipeline, const Framebuffer* dst_framebuffer,
|
||||||
|
const ImageView& src_image_view);
|
||||||
|
|
||||||
|
[[nodiscard]] VkPipeline FindOrEmplacePipeline(const BlitImagePipelineKey& key);
|
||||||
|
|
||||||
|
[[nodiscard]] VkPipeline BlitDepthStencilPipeline(VkRenderPass renderpass);
|
||||||
|
|
||||||
|
void ConvertDepthToColorPipeline(vk::Pipeline& pipeline, VkRenderPass renderpass);
|
||||||
|
|
||||||
|
void ConvertColorToDepthPipeline(vk::Pipeline& pipeline, VkRenderPass renderpass);
|
||||||
|
|
||||||
|
const VKDevice& device;
|
||||||
|
VKScheduler& scheduler;
|
||||||
|
StateTracker& state_tracker;
|
||||||
|
|
||||||
|
vk::DescriptorSetLayout one_texture_set_layout;
|
||||||
|
vk::DescriptorSetLayout two_textures_set_layout;
|
||||||
|
DescriptorAllocator one_texture_descriptor_allocator;
|
||||||
|
DescriptorAllocator two_textures_descriptor_allocator;
|
||||||
|
vk::PipelineLayout one_texture_pipeline_layout;
|
||||||
|
vk::PipelineLayout two_textures_pipeline_layout;
|
||||||
|
vk::ShaderModule full_screen_vert;
|
||||||
|
vk::ShaderModule blit_color_to_color_frag;
|
||||||
|
vk::ShaderModule blit_depth_stencil_frag;
|
||||||
|
vk::ShaderModule convert_depth_to_float_frag;
|
||||||
|
vk::ShaderModule convert_float_to_depth_frag;
|
||||||
|
vk::Sampler linear_sampler;
|
||||||
|
vk::Sampler nearest_sampler;
|
||||||
|
|
||||||
|
std::vector<BlitImagePipelineKey> blit_color_keys;
|
||||||
|
std::vector<vk::Pipeline> blit_color_pipelines;
|
||||||
|
vk::Pipeline blit_depth_stencil_pipeline;
|
||||||
|
vk::Pipeline convert_d32_to_r32_pipeline;
|
||||||
|
vk::Pipeline convert_r32_to_d32_pipeline;
|
||||||
|
vk::Pipeline convert_d16_to_r16_pipeline;
|
||||||
|
vk::Pipeline convert_r16_to_d16_pipeline;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Vulkan
|
@ -1,135 +0,0 @@
|
|||||||
// Copyright 2018 yuzu Emulator Project
|
|
||||||
// Licensed under GPLv2 or any later version
|
|
||||||
// Refer to the license.txt file included.
|
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "common/assert.h"
|
|
||||||
#include "video_core/renderer_vulkan/vk_device.h"
|
|
||||||
#include "video_core/renderer_vulkan/vk_image.h"
|
|
||||||
#include "video_core/renderer_vulkan/vk_scheduler.h"
|
|
||||||
#include "video_core/renderer_vulkan/wrapper.h"
|
|
||||||
|
|
||||||
namespace Vulkan {
|
|
||||||
|
|
||||||
VKImage::VKImage(const VKDevice& device_, VKScheduler& scheduler_,
|
|
||||||
const VkImageCreateInfo& image_ci_, VkImageAspectFlags aspect_mask_)
|
|
||||||
: device{device_}, scheduler{scheduler_}, format{image_ci_.format}, aspect_mask{aspect_mask_},
|
|
||||||
image_num_layers{image_ci_.arrayLayers}, image_num_levels{image_ci_.mipLevels} {
|
|
||||||
UNIMPLEMENTED_IF_MSG(image_ci_.queueFamilyIndexCount != 0,
|
|
||||||
"Queue family tracking is not implemented");
|
|
||||||
|
|
||||||
image = device_.GetLogical().CreateImage(image_ci_);
|
|
||||||
|
|
||||||
const u32 num_ranges = image_num_layers * image_num_levels;
|
|
||||||
barriers.resize(num_ranges);
|
|
||||||
subrange_states.resize(num_ranges, {{}, image_ci_.initialLayout});
|
|
||||||
}
|
|
||||||
|
|
||||||
VKImage::~VKImage() = default;
|
|
||||||
|
|
||||||
void VKImage::Transition(u32 base_layer, u32 num_layers, u32 base_level, u32 num_levels,
|
|
||||||
VkPipelineStageFlags new_stage_mask, VkAccessFlags new_access,
|
|
||||||
VkImageLayout new_layout) {
|
|
||||||
if (!HasChanged(base_layer, num_layers, base_level, num_levels, new_access, new_layout)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::size_t cursor = 0;
|
|
||||||
for (u32 layer_it = 0; layer_it < num_layers; ++layer_it) {
|
|
||||||
for (u32 level_it = 0; level_it < num_levels; ++level_it, ++cursor) {
|
|
||||||
const u32 layer = base_layer + layer_it;
|
|
||||||
const u32 level = base_level + level_it;
|
|
||||||
auto& state = GetSubrangeState(layer, level);
|
|
||||||
auto& barrier = barriers[cursor];
|
|
||||||
barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
|
|
||||||
barrier.pNext = nullptr;
|
|
||||||
barrier.srcAccessMask = state.access;
|
|
||||||
barrier.dstAccessMask = new_access;
|
|
||||||
barrier.oldLayout = state.layout;
|
|
||||||
barrier.newLayout = new_layout;
|
|
||||||
barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
|
||||||
barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
|
||||||
barrier.image = *image;
|
|
||||||
barrier.subresourceRange.aspectMask = aspect_mask;
|
|
||||||
barrier.subresourceRange.baseMipLevel = level;
|
|
||||||
barrier.subresourceRange.levelCount = 1;
|
|
||||||
barrier.subresourceRange.baseArrayLayer = layer;
|
|
||||||
barrier.subresourceRange.layerCount = 1;
|
|
||||||
state.access = new_access;
|
|
||||||
state.layout = new_layout;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
scheduler.RequestOutsideRenderPassOperationContext();
|
|
||||||
|
|
||||||
scheduler.Record([barriers = barriers, cursor](vk::CommandBuffer cmdbuf) {
|
|
||||||
// TODO(Rodrigo): Implement a way to use the latest stage across subresources.
|
|
||||||
cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
|
|
||||||
VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, {}, {},
|
|
||||||
vk::Span(barriers.data(), cursor));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
bool VKImage::HasChanged(u32 base_layer, u32 num_layers, u32 base_level, u32 num_levels,
|
|
||||||
VkAccessFlags new_access, VkImageLayout new_layout) noexcept {
|
|
||||||
const bool is_full_range = base_layer == 0 && num_layers == image_num_layers &&
|
|
||||||
base_level == 0 && num_levels == image_num_levels;
|
|
||||||
if (!is_full_range) {
|
|
||||||
state_diverged = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!state_diverged) {
|
|
||||||
auto& state = GetSubrangeState(0, 0);
|
|
||||||
if (state.access != new_access || state.layout != new_layout) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (u32 layer_it = 0; layer_it < num_layers; ++layer_it) {
|
|
||||||
for (u32 level_it = 0; level_it < num_levels; ++level_it) {
|
|
||||||
const u32 layer = base_layer + layer_it;
|
|
||||||
const u32 level = base_level + level_it;
|
|
||||||
auto& state = GetSubrangeState(layer, level);
|
|
||||||
if (state.access != new_access || state.layout != new_layout) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void VKImage::CreatePresentView() {
|
|
||||||
// Image type has to be 2D to be presented.
|
|
||||||
present_view = device.GetLogical().CreateImageView({
|
|
||||||
.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
|
|
||||||
.pNext = nullptr,
|
|
||||||
.flags = 0,
|
|
||||||
.image = *image,
|
|
||||||
.viewType = VK_IMAGE_VIEW_TYPE_2D,
|
|
||||||
.format = format,
|
|
||||||
.components =
|
|
||||||
{
|
|
||||||
.r = VK_COMPONENT_SWIZZLE_IDENTITY,
|
|
||||||
.g = VK_COMPONENT_SWIZZLE_IDENTITY,
|
|
||||||
.b = VK_COMPONENT_SWIZZLE_IDENTITY,
|
|
||||||
.a = VK_COMPONENT_SWIZZLE_IDENTITY,
|
|
||||||
},
|
|
||||||
.subresourceRange =
|
|
||||||
{
|
|
||||||
.aspectMask = aspect_mask,
|
|
||||||
.baseMipLevel = 0,
|
|
||||||
.levelCount = 1,
|
|
||||||
.baseArrayLayer = 0,
|
|
||||||
.layerCount = 1,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
VKImage::SubrangeState& VKImage::GetSubrangeState(u32 layer, u32 level) noexcept {
|
|
||||||
return subrange_states[static_cast<std::size_t>(layer * image_num_levels) +
|
|
||||||
static_cast<std::size_t>(level)];
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Vulkan
|
|
@ -1,84 +0,0 @@
|
|||||||
// Copyright 2018 yuzu Emulator Project
|
|
||||||
// Licensed under GPLv2 or any later version
|
|
||||||
// Refer to the license.txt file included.
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "common/common_types.h"
|
|
||||||
#include "video_core/renderer_vulkan/wrapper.h"
|
|
||||||
|
|
||||||
namespace Vulkan {
|
|
||||||
|
|
||||||
class VKDevice;
|
|
||||||
class VKScheduler;
|
|
||||||
|
|
||||||
class VKImage {
|
|
||||||
public:
|
|
||||||
explicit VKImage(const VKDevice& device_, VKScheduler& scheduler_,
|
|
||||||
const VkImageCreateInfo& image_ci_, VkImageAspectFlags aspect_mask_);
|
|
||||||
~VKImage();
|
|
||||||
|
|
||||||
/// Records in the passed command buffer an image transition and updates the state of the image.
|
|
||||||
void Transition(u32 base_layer, u32 num_layers, u32 base_level, u32 num_levels,
|
|
||||||
VkPipelineStageFlags new_stage_mask, VkAccessFlags new_access,
|
|
||||||
VkImageLayout new_layout);
|
|
||||||
|
|
||||||
/// Returns a view compatible with presentation, the image has to be 2D.
|
|
||||||
VkImageView GetPresentView() {
|
|
||||||
if (!present_view) {
|
|
||||||
CreatePresentView();
|
|
||||||
}
|
|
||||||
return *present_view;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the Vulkan image handler.
|
|
||||||
const vk::Image& GetHandle() const {
|
|
||||||
return image;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the Vulkan format for this image.
|
|
||||||
VkFormat GetFormat() const {
|
|
||||||
return format;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the Vulkan aspect mask.
|
|
||||||
VkImageAspectFlags GetAspectMask() const {
|
|
||||||
return aspect_mask;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
struct SubrangeState final {
|
|
||||||
VkAccessFlags access = 0; ///< Current access bits.
|
|
||||||
VkImageLayout layout = VK_IMAGE_LAYOUT_UNDEFINED; ///< Current image layout.
|
|
||||||
};
|
|
||||||
|
|
||||||
bool HasChanged(u32 base_layer, u32 num_layers, u32 base_level, u32 num_levels,
|
|
||||||
VkAccessFlags new_access, VkImageLayout new_layout) noexcept;
|
|
||||||
|
|
||||||
/// Creates a presentation view.
|
|
||||||
void CreatePresentView();
|
|
||||||
|
|
||||||
/// Returns the subrange state for a layer and layer.
|
|
||||||
SubrangeState& GetSubrangeState(u32 layer, u32 level) noexcept;
|
|
||||||
|
|
||||||
const VKDevice& device; ///< Device handler.
|
|
||||||
VKScheduler& scheduler; ///< Device scheduler.
|
|
||||||
|
|
||||||
const VkFormat format; ///< Vulkan format.
|
|
||||||
const VkImageAspectFlags aspect_mask; ///< Vulkan aspect mask.
|
|
||||||
const u32 image_num_layers; ///< Number of layers.
|
|
||||||
const u32 image_num_levels; ///< Number of mipmap levels.
|
|
||||||
|
|
||||||
vk::Image image; ///< Image handle.
|
|
||||||
vk::ImageView present_view; ///< Image view compatible with presentation.
|
|
||||||
|
|
||||||
std::vector<VkImageMemoryBarrier> barriers; ///< Pool of barriers.
|
|
||||||
std::vector<SubrangeState> subrange_states; ///< Current subrange state.
|
|
||||||
|
|
||||||
bool state_diverged = false; ///< True when subresources mismatch in layout.
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace Vulkan
|
|
File diff suppressed because it is too large
Load Diff
@ -1,158 +0,0 @@
|
|||||||
// Copyright 2019 yuzu Emulator Project
|
|
||||||
// Licensed under GPLv2 or any later version
|
|
||||||
// Refer to the license.txt file included.
|
|
||||||
|
|
||||||
#include <cstring>
|
|
||||||
#include <memory>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "common/cityhash.h"
|
|
||||||
#include "video_core/engines/maxwell_3d.h"
|
|
||||||
#include "video_core/renderer_vulkan/maxwell_to_vk.h"
|
|
||||||
#include "video_core/renderer_vulkan/vk_device.h"
|
|
||||||
#include "video_core/renderer_vulkan/vk_renderpass_cache.h"
|
|
||||||
#include "video_core/renderer_vulkan/wrapper.h"
|
|
||||||
|
|
||||||
namespace Vulkan {
|
|
||||||
|
|
||||||
std::size_t RenderPassParams::Hash() const noexcept {
|
|
||||||
const u64 hash = Common::CityHash64(reinterpret_cast<const char*>(this), sizeof *this);
|
|
||||||
return static_cast<std::size_t>(hash);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool RenderPassParams::operator==(const RenderPassParams& rhs) const noexcept {
|
|
||||||
return std::memcmp(&rhs, this, sizeof *this) == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
VKRenderPassCache::VKRenderPassCache(const VKDevice& device_) : device{device_} {}
|
|
||||||
|
|
||||||
VKRenderPassCache::~VKRenderPassCache() = default;
|
|
||||||
|
|
||||||
VkRenderPass VKRenderPassCache::GetRenderPass(const RenderPassParams& params) {
|
|
||||||
const auto [pair, is_cache_miss] = cache.try_emplace(params);
|
|
||||||
auto& entry = pair->second;
|
|
||||||
if (is_cache_miss) {
|
|
||||||
entry = CreateRenderPass(params);
|
|
||||||
}
|
|
||||||
return *entry;
|
|
||||||
}
|
|
||||||
|
|
||||||
vk::RenderPass VKRenderPassCache::CreateRenderPass(const RenderPassParams& params) const {
|
|
||||||
using namespace VideoCore::Surface;
|
|
||||||
const std::size_t num_attachments = static_cast<std::size_t>(params.num_color_attachments);
|
|
||||||
|
|
||||||
std::vector<VkAttachmentDescription> descriptors;
|
|
||||||
descriptors.reserve(num_attachments);
|
|
||||||
|
|
||||||
std::vector<VkAttachmentReference> color_references;
|
|
||||||
color_references.reserve(num_attachments);
|
|
||||||
|
|
||||||
for (std::size_t rt = 0; rt < num_attachments; ++rt) {
|
|
||||||
const auto guest_format = static_cast<Tegra::RenderTargetFormat>(params.color_formats[rt]);
|
|
||||||
const PixelFormat pixel_format = PixelFormatFromRenderTargetFormat(guest_format);
|
|
||||||
const auto format = MaxwellToVK::SurfaceFormat(device, FormatType::Optimal, pixel_format);
|
|
||||||
ASSERT_MSG(format.attachable, "Trying to attach a non-attachable format with format={}",
|
|
||||||
static_cast<int>(pixel_format));
|
|
||||||
|
|
||||||
// TODO(Rodrigo): Add MAY_ALIAS_BIT when it's needed.
|
|
||||||
const VkImageLayout color_layout = ((params.texceptions >> rt) & 1) != 0
|
|
||||||
? VK_IMAGE_LAYOUT_GENERAL
|
|
||||||
: VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
|
||||||
descriptors.push_back({
|
|
||||||
.flags = VK_ATTACHMENT_DESCRIPTION_MAY_ALIAS_BIT,
|
|
||||||
.format = format.format,
|
|
||||||
.samples = VK_SAMPLE_COUNT_1_BIT,
|
|
||||||
.loadOp = VK_ATTACHMENT_LOAD_OP_LOAD,
|
|
||||||
.storeOp = VK_ATTACHMENT_STORE_OP_STORE,
|
|
||||||
.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE,
|
|
||||||
.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE,
|
|
||||||
.initialLayout = color_layout,
|
|
||||||
.finalLayout = color_layout,
|
|
||||||
});
|
|
||||||
|
|
||||||
color_references.push_back({
|
|
||||||
.attachment = static_cast<u32>(rt),
|
|
||||||
.layout = color_layout,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
VkAttachmentReference zeta_attachment_ref;
|
|
||||||
const bool has_zeta = params.zeta_format != 0;
|
|
||||||
if (has_zeta) {
|
|
||||||
const auto guest_format = static_cast<Tegra::DepthFormat>(params.zeta_format);
|
|
||||||
const PixelFormat pixel_format = PixelFormatFromDepthFormat(guest_format);
|
|
||||||
const auto format = MaxwellToVK::SurfaceFormat(device, FormatType::Optimal, pixel_format);
|
|
||||||
ASSERT_MSG(format.attachable, "Trying to attach a non-attachable format with format={}",
|
|
||||||
static_cast<int>(pixel_format));
|
|
||||||
|
|
||||||
const VkImageLayout zeta_layout = params.zeta_texception != 0
|
|
||||||
? VK_IMAGE_LAYOUT_GENERAL
|
|
||||||
: VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
|
|
||||||
descriptors.push_back({
|
|
||||||
.flags = 0,
|
|
||||||
.format = format.format,
|
|
||||||
.samples = VK_SAMPLE_COUNT_1_BIT,
|
|
||||||
.loadOp = VK_ATTACHMENT_LOAD_OP_LOAD,
|
|
||||||
.storeOp = VK_ATTACHMENT_STORE_OP_STORE,
|
|
||||||
.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_LOAD,
|
|
||||||
.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE,
|
|
||||||
.initialLayout = zeta_layout,
|
|
||||||
.finalLayout = zeta_layout,
|
|
||||||
});
|
|
||||||
|
|
||||||
zeta_attachment_ref = {
|
|
||||||
.attachment = static_cast<u32>(num_attachments),
|
|
||||||
.layout = zeta_layout,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const VkSubpassDescription subpass_description{
|
|
||||||
.flags = 0,
|
|
||||||
.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS,
|
|
||||||
.inputAttachmentCount = 0,
|
|
||||||
.pInputAttachments = nullptr,
|
|
||||||
.colorAttachmentCount = static_cast<u32>(color_references.size()),
|
|
||||||
.pColorAttachments = color_references.data(),
|
|
||||||
.pResolveAttachments = nullptr,
|
|
||||||
.pDepthStencilAttachment = has_zeta ? &zeta_attachment_ref : nullptr,
|
|
||||||
.preserveAttachmentCount = 0,
|
|
||||||
.pPreserveAttachments = nullptr,
|
|
||||||
};
|
|
||||||
|
|
||||||
VkAccessFlags access = 0;
|
|
||||||
VkPipelineStageFlags stage = 0;
|
|
||||||
if (!color_references.empty()) {
|
|
||||||
access |= VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
|
|
||||||
stage |= VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (has_zeta) {
|
|
||||||
access |= VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT |
|
|
||||||
VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
|
|
||||||
stage |= VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT;
|
|
||||||
}
|
|
||||||
|
|
||||||
const VkSubpassDependency subpass_dependency{
|
|
||||||
.srcSubpass = VK_SUBPASS_EXTERNAL,
|
|
||||||
.dstSubpass = 0,
|
|
||||||
.srcStageMask = stage,
|
|
||||||
.dstStageMask = stage,
|
|
||||||
.srcAccessMask = 0,
|
|
||||||
.dstAccessMask = access,
|
|
||||||
.dependencyFlags = 0,
|
|
||||||
};
|
|
||||||
|
|
||||||
return device.GetLogical().CreateRenderPass({
|
|
||||||
.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
|
|
||||||
.pNext = nullptr,
|
|
||||||
.flags = 0,
|
|
||||||
.attachmentCount = static_cast<u32>(descriptors.size()),
|
|
||||||
.pAttachments = descriptors.data(),
|
|
||||||
.subpassCount = 1,
|
|
||||||
.pSubpasses = &subpass_description,
|
|
||||||
.dependencyCount = 1,
|
|
||||||
.pDependencies = &subpass_dependency,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Vulkan
|
|
@ -1,70 +0,0 @@
|
|||||||
// Copyright 2019 yuzu Emulator Project
|
|
||||||
// Licensed under GPLv2 or any later version
|
|
||||||
// Refer to the license.txt file included.
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <type_traits>
|
|
||||||
#include <unordered_map>
|
|
||||||
|
|
||||||
#include <boost/container/static_vector.hpp>
|
|
||||||
#include <boost/functional/hash.hpp>
|
|
||||||
|
|
||||||
#include "video_core/engines/maxwell_3d.h"
|
|
||||||
#include "video_core/renderer_vulkan/wrapper.h"
|
|
||||||
#include "video_core/surface.h"
|
|
||||||
|
|
||||||
namespace Vulkan {
|
|
||||||
|
|
||||||
class VKDevice;
|
|
||||||
|
|
||||||
struct RenderPassParams {
|
|
||||||
std::array<u8, Tegra::Engines::Maxwell3D::Regs::NumRenderTargets> color_formats;
|
|
||||||
u8 num_color_attachments;
|
|
||||||
u8 texceptions;
|
|
||||||
|
|
||||||
u8 zeta_format;
|
|
||||||
u8 zeta_texception;
|
|
||||||
|
|
||||||
std::size_t Hash() const noexcept;
|
|
||||||
|
|
||||||
bool operator==(const RenderPassParams& rhs) const noexcept;
|
|
||||||
|
|
||||||
bool operator!=(const RenderPassParams& rhs) const noexcept {
|
|
||||||
return !operator==(rhs);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
static_assert(std::has_unique_object_representations_v<RenderPassParams>);
|
|
||||||
static_assert(std::is_trivially_copyable_v<RenderPassParams>);
|
|
||||||
static_assert(std::is_trivially_constructible_v<RenderPassParams>);
|
|
||||||
|
|
||||||
} // namespace Vulkan
|
|
||||||
|
|
||||||
namespace std {
|
|
||||||
|
|
||||||
template <>
|
|
||||||
struct hash<Vulkan::RenderPassParams> {
|
|
||||||
std::size_t operator()(const Vulkan::RenderPassParams& k) const noexcept {
|
|
||||||
return k.Hash();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace std
|
|
||||||
|
|
||||||
namespace Vulkan {
|
|
||||||
|
|
||||||
class VKRenderPassCache final {
|
|
||||||
public:
|
|
||||||
explicit VKRenderPassCache(const VKDevice& device_);
|
|
||||||
~VKRenderPassCache();
|
|
||||||
|
|
||||||
VkRenderPass GetRenderPass(const RenderPassParams& params);
|
|
||||||
|
|
||||||
private:
|
|
||||||
vk::RenderPass CreateRenderPass(const RenderPassParams& params) const;
|
|
||||||
|
|
||||||
const VKDevice& device;
|
|
||||||
std::unordered_map<RenderPassParams, vk::RenderPass> cache;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace Vulkan
|
|
@ -1,83 +0,0 @@
|
|||||||
// Copyright 2019 yuzu Emulator Project
|
|
||||||
// Licensed under GPLv2 or any later version
|
|
||||||
// Refer to the license.txt file included.
|
|
||||||
|
|
||||||
#include <unordered_map>
|
|
||||||
|
|
||||||
#include "video_core/renderer_vulkan/maxwell_to_vk.h"
|
|
||||||
#include "video_core/renderer_vulkan/vk_sampler_cache.h"
|
|
||||||
#include "video_core/renderer_vulkan/wrapper.h"
|
|
||||||
#include "video_core/textures/texture.h"
|
|
||||||
|
|
||||||
using Tegra::Texture::TextureMipmapFilter;
|
|
||||||
|
|
||||||
namespace Vulkan {
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
VkBorderColor ConvertBorderColor(std::array<float, 4> color) {
|
|
||||||
// TODO(Rodrigo): Manage integer border colors
|
|
||||||
if (color == std::array<float, 4>{0, 0, 0, 0}) {
|
|
||||||
return VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK;
|
|
||||||
} else if (color == std::array<float, 4>{0, 0, 0, 1}) {
|
|
||||||
return VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK;
|
|
||||||
} else if (color == std::array<float, 4>{1, 1, 1, 1}) {
|
|
||||||
return VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
|
|
||||||
}
|
|
||||||
if (color[0] + color[1] + color[2] > 1.35f) {
|
|
||||||
// If color elements are brighter than roughly 0.5 average, use white border
|
|
||||||
return VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
|
|
||||||
} else if (color[3] > 0.5f) {
|
|
||||||
return VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK;
|
|
||||||
} else {
|
|
||||||
return VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} // Anonymous namespace
|
|
||||||
|
|
||||||
VKSamplerCache::VKSamplerCache(const VKDevice& device_) : device{device_} {}
|
|
||||||
|
|
||||||
VKSamplerCache::~VKSamplerCache() = default;
|
|
||||||
|
|
||||||
vk::Sampler VKSamplerCache::CreateSampler(const Tegra::Texture::TSCEntry& tsc) const {
|
|
||||||
const bool arbitrary_borders = device.IsExtCustomBorderColorSupported();
|
|
||||||
const std::array color = tsc.GetBorderColor();
|
|
||||||
|
|
||||||
VkSamplerCustomBorderColorCreateInfoEXT border{
|
|
||||||
.sType = VK_STRUCTURE_TYPE_SAMPLER_CUSTOM_BORDER_COLOR_CREATE_INFO_EXT,
|
|
||||||
.pNext = nullptr,
|
|
||||||
.customBorderColor = {},
|
|
||||||
.format = VK_FORMAT_UNDEFINED,
|
|
||||||
};
|
|
||||||
std::memcpy(&border.customBorderColor, color.data(), sizeof(color));
|
|
||||||
|
|
||||||
return device.GetLogical().CreateSampler({
|
|
||||||
.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,
|
|
||||||
.pNext = arbitrary_borders ? &border : nullptr,
|
|
||||||
.flags = 0,
|
|
||||||
.magFilter = MaxwellToVK::Sampler::Filter(tsc.mag_filter),
|
|
||||||
.minFilter = MaxwellToVK::Sampler::Filter(tsc.min_filter),
|
|
||||||
.mipmapMode = MaxwellToVK::Sampler::MipmapMode(tsc.mipmap_filter),
|
|
||||||
.addressModeU = MaxwellToVK::Sampler::WrapMode(device, tsc.wrap_u, tsc.mag_filter),
|
|
||||||
.addressModeV = MaxwellToVK::Sampler::WrapMode(device, tsc.wrap_v, tsc.mag_filter),
|
|
||||||
.addressModeW = MaxwellToVK::Sampler::WrapMode(device, tsc.wrap_p, tsc.mag_filter),
|
|
||||||
.mipLodBias = tsc.GetLodBias(),
|
|
||||||
.anisotropyEnable =
|
|
||||||
static_cast<VkBool32>(tsc.GetMaxAnisotropy() > 1.0f ? VK_TRUE : VK_FALSE),
|
|
||||||
.maxAnisotropy = tsc.GetMaxAnisotropy(),
|
|
||||||
.compareEnable = tsc.depth_compare_enabled,
|
|
||||||
.compareOp = MaxwellToVK::Sampler::DepthCompareFunction(tsc.depth_compare_func),
|
|
||||||
.minLod = tsc.mipmap_filter == TextureMipmapFilter::None ? 0.0f : tsc.GetMinLod(),
|
|
||||||
.maxLod = tsc.mipmap_filter == TextureMipmapFilter::None ? 0.25f : tsc.GetMaxLod(),
|
|
||||||
.borderColor =
|
|
||||||
arbitrary_borders ? VK_BORDER_COLOR_INT_CUSTOM_EXT : ConvertBorderColor(color),
|
|
||||||
.unnormalizedCoordinates = VK_FALSE,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
VkSampler VKSamplerCache::ToSamplerType(const vk::Sampler& sampler) const {
|
|
||||||
return *sampler;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Vulkan
|
|
@ -1,29 +0,0 @@
|
|||||||
// Copyright 2019 yuzu Emulator Project
|
|
||||||
// Licensed under GPLv2 or any later version
|
|
||||||
// Refer to the license.txt file included.
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "video_core/renderer_vulkan/wrapper.h"
|
|
||||||
#include "video_core/sampler_cache.h"
|
|
||||||
#include "video_core/textures/texture.h"
|
|
||||||
|
|
||||||
namespace Vulkan {
|
|
||||||
|
|
||||||
class VKDevice;
|
|
||||||
|
|
||||||
class VKSamplerCache final : public VideoCommon::SamplerCache<VkSampler, vk::Sampler> {
|
|
||||||
public:
|
|
||||||
explicit VKSamplerCache(const VKDevice& device_);
|
|
||||||
~VKSamplerCache();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
vk::Sampler CreateSampler(const Tegra::Texture::TSCEntry& tsc) const override;
|
|
||||||
|
|
||||||
VkSampler ToSamplerType(const vk::Sampler& sampler) const override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
const VKDevice& device;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace Vulkan
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue