Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'vulkan/vulkan-2' into experimental-vulk…
Browse files Browse the repository at this point in the history
…an-2
  • Loading branch information
DarthMDev committed Jan 11, 2023
2 parents 50ef5d0 + e2076f2 commit 673e0df
Show file tree
Hide file tree
Showing 26 changed files with 411 additions and 391 deletions.
4 changes: 4 additions & 0 deletions src/android/app/src/main/jni/emu_window/emu_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ void EmuWindow_Android::OnTouchMoved(int x, int y) {
void EmuWindow_Android::OnFramebufferSizeChanged() {
UpdateLandscapeScreenLayout();
const bool is_portrait_mode{IsPortraitMode()};

const int bigger{window_width > window_height ? window_width : window_height};
const int smaller{window_width < window_height ? window_width : window_height};
if (is_portrait_mode) {
Expand All @@ -70,6 +71,9 @@ EmuWindow_Android::EmuWindow_Android(ANativeWindow *surface) : host_window{surfa
return;
}

window_width = ANativeWindow_getWidth(surface);
window_height = ANativeWindow_getHeight(surface);

Network::Init();
}

Expand Down
4 changes: 2 additions & 2 deletions src/android/app/src/main/jni/emu_window/emu_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ class EmuWindow_Android : public Frontend::EmuWindow {
ANativeWindow* render_window{};
ANativeWindow* host_window{};

int window_width{1080};
int window_height{2220};
int window_width{};
int window_height{};

std::unique_ptr<Frontend::GraphicsContext> core_context;

Expand Down
99 changes: 83 additions & 16 deletions src/video_core/rasterizer_accelerated.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,42 @@ RasterizerAccelerated::VertexArrayInfo RasterizerAccelerated::AnalyzeVertexArray
return {vertex_min, vertex_max, vs_input_size};
}

void RasterizerAccelerated::SyncEntireState() {
// Sync renderer-specific fixed-function state
SyncFixedState();

// Sync uniforms
SyncClipCoef();
SyncDepthScale();
SyncDepthOffset();
SyncAlphaTest();
SyncCombinerColor();
auto& tev_stages = Pica::g_state.regs.texturing.GetTevStages();
for (std::size_t index = 0; index < tev_stages.size(); ++index)
SyncTevConstColor(index, tev_stages[index]);

SyncGlobalAmbient();
for (unsigned light_index = 0; light_index < 8; light_index++) {
SyncLightSpecular0(light_index);
SyncLightSpecular1(light_index);
SyncLightDiffuse(light_index);
SyncLightAmbient(light_index);
SyncLightPosition(light_index);
SyncLightDistanceAttenuationBias(light_index);
SyncLightDistanceAttenuationScale(light_index);
}

SyncFogColor();
SyncProcTexNoise();
SyncProcTexBias();
SyncShadowBias();
SyncShadowTextureBias();

for (unsigned tex_index = 0; tex_index < 3; tex_index++) {
SyncTextureLodBias(tex_index);
}
}

void RasterizerAccelerated::NotifyPicaRegisterChanged(u32 id) {
const auto& regs = Pica::g_state.regs;

Expand Down Expand Up @@ -655,6 +691,14 @@ void RasterizerAccelerated::NotifyPicaRegisterChanged(u32 id) {
SyncTextureLodBias(2);
break;

// Clipping plane
case PICA_REG_INDEX(rasterizer.clip_coef[0]):
case PICA_REG_INDEX(rasterizer.clip_coef[1]):
case PICA_REG_INDEX(rasterizer.clip_coef[2]):
case PICA_REG_INDEX(rasterizer.clip_coef[3]):
SyncClipCoef();
break;

default:
// Forward registers that map to fixed function API features to the video backend
NotifyFixedFunctionPicaRegisterChanged(id);
Expand Down Expand Up @@ -682,40 +726,52 @@ void RasterizerAccelerated::SyncDepthOffset() {
}

void RasterizerAccelerated::SyncFogColor() {
const auto& regs = Pica::g_state.regs;
uniform_block_data.data.fog_color = {
regs.texturing.fog_color.r.Value() / 255.0f,
regs.texturing.fog_color.g.Value() / 255.0f,
regs.texturing.fog_color.b.Value() / 255.0f,
const auto& fog_color_regs = Pica::g_state.regs.texturing.fog_color;
const Common::Vec3f fog_color = {
fog_color_regs.r.Value() / 255.0f,
fog_color_regs.g.Value() / 255.0f,
fog_color_regs.b.Value() / 255.0f,
};
uniform_block_data.dirty = true;

if (fog_color != uniform_block_data.data.fog_color) {
uniform_block_data.data.fog_color = fog_color;
uniform_block_data.dirty = true;
}
}

void RasterizerAccelerated::SyncProcTexNoise() {
const auto& regs = Pica::g_state.regs.texturing;
uniform_block_data.data.proctex_noise_f = {
const Common::Vec2f proctex_noise_f = {
Pica::float16::FromRaw(regs.proctex_noise_frequency.u).ToFloat32(),
Pica::float16::FromRaw(regs.proctex_noise_frequency.v).ToFloat32(),
};
uniform_block_data.data.proctex_noise_a = {
const Common::Vec2f proctex_noise_a = {
regs.proctex_noise_u.amplitude / 4095.0f,
regs.proctex_noise_v.amplitude / 4095.0f,
};
uniform_block_data.data.proctex_noise_p = {
const Common::Vec2f proctex_noise_p = {
Pica::float16::FromRaw(regs.proctex_noise_u.phase).ToFloat32(),
Pica::float16::FromRaw(regs.proctex_noise_v.phase).ToFloat32(),
};

uniform_block_data.dirty = true;
if (proctex_noise_f != uniform_block_data.data.proctex_noise_f ||
proctex_noise_a != uniform_block_data.data.proctex_noise_a ||
proctex_noise_p != uniform_block_data.data.proctex_noise_p) {
uniform_block_data.data.proctex_noise_f = proctex_noise_f;
uniform_block_data.data.proctex_noise_a = proctex_noise_a;
uniform_block_data.data.proctex_noise_p = proctex_noise_p;
uniform_block_data.dirty = true;
}
}

void RasterizerAccelerated::SyncProcTexBias() {
const auto& regs = Pica::g_state.regs.texturing;
uniform_block_data.data.proctex_bias =
Pica::float16::FromRaw(regs.proctex.bias_low | (regs.proctex_lut.bias_high << 8))
.ToFloat32();

uniform_block_data.dirty = true;
const auto proctex_bias = Pica::float16::FromRaw(regs.proctex.bias_low |
(regs.proctex_lut.bias_high << 8)).ToFloat32();
if (proctex_bias != uniform_block_data.data.proctex_bias) {
uniform_block_data.data.proctex_bias = proctex_bias;
uniform_block_data.dirty = true;
}
}

void RasterizerAccelerated::SyncAlphaTest() {
Expand Down Expand Up @@ -790,7 +846,8 @@ void RasterizerAccelerated::SyncLightPosition(int light_index) {
const Common::Vec3f position = {
Pica::float16::FromRaw(Pica::g_state.regs.lighting.light[light_index].x).ToFloat32(),
Pica::float16::FromRaw(Pica::g_state.regs.lighting.light[light_index].y).ToFloat32(),
Pica::float16::FromRaw(Pica::g_state.regs.lighting.light[light_index].z).ToFloat32()};
Pica::float16::FromRaw(Pica::g_state.regs.lighting.light[light_index].z).ToFloat32(),
};

if (position != uniform_block_data.data.light_src[light_index].position) {
uniform_block_data.data.light_src[light_index].position = position;
Expand Down Expand Up @@ -861,4 +918,14 @@ void RasterizerAccelerated::SyncTextureLodBias(int tex_index) {
}
}

void RasterizerAccelerated::SyncClipCoef() {
const auto raw_clip_coef = Pica::g_state.regs.rasterizer.GetClipCoef();
const Common::Vec4f new_clip_coef = {raw_clip_coef.x.ToFloat32(), raw_clip_coef.y.ToFloat32(),
raw_clip_coef.z.ToFloat32(), raw_clip_coef.w.ToFloat32()};
if (new_clip_coef != uniform_block_data.data.clip_coef) {
uniform_block_data.data.clip_coef = new_clip_coef;
uniform_block_data.dirty = true;
}
}

} // namespace VideoCore
9 changes: 9 additions & 0 deletions src/video_core/rasterizer_accelerated.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ class RasterizerAccelerated : public RasterizerInterface {
void NotifyPicaRegisterChanged(u32 id) override;
void ClearAll(bool flush) override;

/// Syncs entire status to match PICA registers
void SyncEntireState() override;

/// Sync fixed-function pipeline state
virtual void SyncFixedState() = 0;

protected:
/// Notifies that a fixed function PICA register changed to the video backend
virtual void NotifyFixedFunctionPicaRegisterChanged(u32 id) = 0;
Expand Down Expand Up @@ -88,6 +94,9 @@ class RasterizerAccelerated : public RasterizerInterface {
/// Syncs the texture LOD bias to match the PICA register
void SyncTextureLodBias(int tex_index);

/// Syncs the clip coefficients to match the PICA register
void SyncClipCoef();

protected:
/// Structure that keeps tracks of the uniform state
struct UniformBlockData {
Expand Down
2 changes: 1 addition & 1 deletion src/video_core/renderer_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

#pragma once

#include <memory>
#include "common/common_types.h"
#include "common/vector_math.h"
#include "video_core/rasterizer_interface.h"
#include "video_core/video_core.h"

Expand Down
91 changes: 22 additions & 69 deletions src/video_core/renderer_opengl/gl_rasterizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ RasterizerOpenGL::RasterizerOpenGL(Frontend::EmuWindow& emu_window, Driver& driv

glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, &uniform_buffer_alignment);
uniform_size_aligned_vs =
Common::AlignUp<std::size_t>(sizeof(VSUniformData), uniform_buffer_alignment);
Common::AlignUp<std::size_t>(sizeof(Pica::Shader::VSUniformData), uniform_buffer_alignment);
uniform_size_aligned_fs =
Common::AlignUp<std::size_t>(sizeof(UniformData), uniform_buffer_alignment);
Common::AlignUp<std::size_t>(sizeof(Pica::Shader::UniformData), uniform_buffer_alignment);

// Set vertex attributes for software shader path
state.draw.vertex_array = sw_vao.handle;
Expand Down Expand Up @@ -136,8 +136,7 @@ void RasterizerOpenGL::LoadDiskResources(const std::atomic_bool& stop_loading,
shader_program_manager.LoadDiskCache(stop_loading, callback);
}

void RasterizerOpenGL::SyncEntireState() {
// Sync fixed function OpenGL state
void RasterizerOpenGL::SyncFixedState() {
SyncClipEnabled();
SyncCullMode();
SyncBlendEnabled();
Expand All @@ -149,37 +148,6 @@ void RasterizerOpenGL::SyncEntireState() {
SyncColorWriteMask();
SyncStencilWriteMask();
SyncDepthWriteMask();

// Sync uniforms
SyncClipCoef();
SyncDepthScale();
SyncDepthOffset();
SyncAlphaTest();
SyncCombinerColor();
auto& tev_stages = Pica::g_state.regs.texturing.GetTevStages();
for (std::size_t index = 0; index < tev_stages.size(); ++index)
SyncTevConstColor(index, tev_stages[index]);

SyncGlobalAmbient();
for (unsigned light_index = 0; light_index < 8; light_index++) {
SyncLightSpecular0(light_index);
SyncLightSpecular1(light_index);
SyncLightDiffuse(light_index);
SyncLightAmbient(light_index);
SyncLightPosition(light_index);
SyncLightDistanceAttenuationBias(light_index);
SyncLightDistanceAttenuationScale(light_index);
}

SyncFogColor();
SyncProcTexNoise();
SyncProcTexBias();
SyncShadowBias();
SyncShadowTextureBias();

for (unsigned tex_index = 0; tex_index < 3; tex_index++) {
SyncTextureLodBias(tex_index);
}
}

static constexpr std::array<GLenum, 4> vs_attrib_types{
Expand Down Expand Up @@ -717,30 +685,22 @@ bool RasterizerOpenGL::Draw(bool accelerate, bool is_indexed) {

void RasterizerOpenGL::NotifyFixedFunctionPicaRegisterChanged(u32 id) {
switch (id) {
// Culling
case PICA_REG_INDEX(rasterizer.cull_mode):
SyncCullMode();
break;

// Clipping plane
case PICA_REG_INDEX(rasterizer.clip_enable):
SyncClipEnabled();
break;

case PICA_REG_INDEX(rasterizer.clip_coef[0]):
case PICA_REG_INDEX(rasterizer.clip_coef[1]):
case PICA_REG_INDEX(rasterizer.clip_coef[2]):
case PICA_REG_INDEX(rasterizer.clip_coef[3]):
SyncClipCoef();
// Culling
case PICA_REG_INDEX(rasterizer.cull_mode):
SyncCullMode();
break;

// Blending
case PICA_REG_INDEX(framebuffer.output_merger.alphablend_enable):
if (driver.IsOpenGLES()) {
// With GLES, we need this in the fragment shader to emulate logic operations
shader_dirty = true;
}
SyncBlendEnabled();
// Update since logic op emulation depends on alpha blend enable.
SyncLogicOp();
SyncColorWriteMask();
break;
case PICA_REG_INDEX(framebuffer.output_merger.alpha_blending):
SyncBlendFuncs();
Expand Down Expand Up @@ -783,11 +743,9 @@ void RasterizerOpenGL::NotifyFixedFunctionPicaRegisterChanged(u32 id) {

// Logic op
case PICA_REG_INDEX(framebuffer.output_merger.logic_op):
if (driver.IsOpenGLES()) {
// With GLES, we need this in the fragment shader to emulate logic operations
shader_dirty = true;
}
SyncLogicOp();
// Update since color write mask is used to emulate no-op.
SyncColorWriteMask();
break;
}
}
Expand Down Expand Up @@ -1066,16 +1024,6 @@ void RasterizerOpenGL::SyncClipEnabled() {
state.clip_distance[1] = Pica::g_state.regs.rasterizer.clip_enable != 0;
}

void RasterizerOpenGL::SyncClipCoef() {
const auto raw_clip_coef = Pica::g_state.regs.rasterizer.GetClipCoef();
const Common::Vec4f new_clip_coef = {raw_clip_coef.x.ToFloat32(), raw_clip_coef.y.ToFloat32(),
raw_clip_coef.z.ToFloat32(), raw_clip_coef.w.ToFloat32()};
if (new_clip_coef != uniform_block_data.data.clip_coef) {
uniform_block_data.data.clip_coef = new_clip_coef;
uniform_block_data.dirty = true;
}
}

void RasterizerOpenGL::SyncCullMode() {
const auto& regs = Pica::g_state.regs;

Expand Down Expand Up @@ -1132,6 +1080,11 @@ void RasterizerOpenGL::SyncBlendColor() {
}

void RasterizerOpenGL::SyncLogicOp() {
if (driver.IsOpenGLES()) {
// With GLES, we need this in the fragment shader to emulate logic operations
shader_dirty = true;
}

const auto& regs = Pica::g_state.regs;
state.logic_op = PicaToGL::LogicOp(regs.framebuffer.output_merger.logic_op);

Expand Down Expand Up @@ -1410,18 +1363,18 @@ void RasterizerOpenGL::UploadUniforms(bool accelerate_draw) {
uniform_buffer.Map(uniform_size, uniform_buffer_alignment);

if (sync_vs) {
VSUniformData vs_uniforms;
Pica::Shader::VSUniformData vs_uniforms;
vs_uniforms.uniforms.SetFromRegs(Pica::g_state.regs.vs, Pica::g_state.vs);
std::memcpy(uniforms + used_bytes, &vs_uniforms, sizeof(vs_uniforms));
glBindBufferRange(GL_UNIFORM_BUFFER, static_cast<GLuint>(UniformBindings::VS),
uniform_buffer.GetHandle(), offset + used_bytes, sizeof(VSUniformData));
glBindBufferRange(GL_UNIFORM_BUFFER, static_cast<GLuint>(Pica::Shader::UniformBindings::VS),
uniform_buffer.GetHandle(), offset + used_bytes, sizeof(vs_uniforms));
used_bytes += uniform_size_aligned_vs;
}

if (sync_fs || invalidate) {
std::memcpy(uniforms + used_bytes, &uniform_block_data.data, sizeof(UniformData));
glBindBufferRange(GL_UNIFORM_BUFFER, static_cast<GLuint>(UniformBindings::Common),
uniform_buffer.GetHandle(), offset + used_bytes, sizeof(UniformData));
std::memcpy(uniforms + used_bytes, &uniform_block_data.data, sizeof(Pica::Shader::UniformData));
glBindBufferRange(GL_UNIFORM_BUFFER, static_cast<GLuint>(Pica::Shader::UniformBindings::Common),
uniform_buffer.GetHandle(), offset + used_bytes, sizeof(Pica::Shader::UniformData));
uniform_block_data.dirty = false;
used_bytes += uniform_size_aligned_fs;
}
Expand Down
6 changes: 1 addition & 5 deletions src/video_core/renderer_opengl/gl_rasterizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ class RasterizerOpenGL : public VideoCore::RasterizerAccelerated {
u32 pixel_stride, ScreenInfo& screen_info);
bool AccelerateDrawBatch(bool is_indexed) override;

/// Syncs entire status to match PICA registers
void SyncEntireState() override;
void SyncFixedState() override;

private:
struct SamplerInfo {
Expand Down Expand Up @@ -76,9 +75,6 @@ class RasterizerOpenGL : public VideoCore::RasterizerAccelerated {
/// Syncs the clip enabled status to match the PICA register
void SyncClipEnabled();

/// Syncs the clip coefficients to match the PICA register
void SyncClipCoef();

/// Sets the OpenGL shader in accordance with the current PICA register state
void SetShader();

Expand Down
Loading

0 comments on commit 673e0df

Please sign in to comment.