Skip to content

Commit

Permalink
revert from origin
Browse files Browse the repository at this point in the history
  • Loading branch information
weihuoya committed Nov 19, 2018
1 parent 5b4d949 commit 5f4f43a
Show file tree
Hide file tree
Showing 35 changed files with 267 additions and 226 deletions.
10 changes: 0 additions & 10 deletions Source/Core/Core/HW/Memmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,17 +278,7 @@ void DoState(PointerWrap& p)
p.DoArray(m_pL1Cache, L1_CACHE_SIZE);
p.DoMarker("Memory RAM");
if (m_pFakeVMEM)
{
p.DoArray(m_pFakeVMEM, FAKEVMEM_SIZE);
}
/*else
{
u64 v = 0;
for(int i = 0; i < (FAKEVMEM_SIZE >> 8); ++i)
{
p.Do(v);
}
}*/
p.DoMarker("Memory FakeVMEM");
if (wii)
p.DoArray(m_pEXRAM, EXRAM_SIZE);
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/VideoBackends/D3D/D3DState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ ID3D11SamplerState* StateCache::Get(SamplerState state)

static constexpr std::array<D3D11_TEXTURE_ADDRESS_MODE, 3> address_modes = {
{D3D11_TEXTURE_ADDRESS_CLAMP, D3D11_TEXTURE_ADDRESS_WRAP, D3D11_TEXTURE_ADDRESS_MIRROR}};
sampdc.AddressU = address_modes[static_cast<u32>(state.wrap_u)];
sampdc.AddressV = address_modes[static_cast<u32>(state.wrap_v)];
sampdc.AddressU = address_modes[static_cast<u32>(state.wrap_u.Value())];
sampdc.AddressV = address_modes[static_cast<u32>(state.wrap_v.Value())];
sampdc.MaxLOD = state.max_lod / 16.f;
sampdc.MinLOD = state.min_lod / 16.f;
sampdc.MipLODBias = (s32)state.lod_bias / 256.f;
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/VideoBackends/OGL/RasterFont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ void RasterFont::printMultilineText(const std::string& text, float start_x, floa
std::vector<GLfloat> vertices(text.length() * 6 * 4);

int usage = 0;
#ifdef __ANDROID__
#ifdef ANDROID
GLfloat delta_x = GLfloat(2.5f * CHARACTER_WIDTH) / GLfloat(bbWidth);
GLfloat delta_y = GLfloat(2.5f * CHARACTER_HEIGHT) / GLfloat(bbHeight);

Expand Down
4 changes: 2 additions & 2 deletions Source/Core/VideoBackends/OGL/SamplerCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ void SamplerCache::SetParameters(GLuint sampler_id, const SamplerState& params)
{GL_CLAMP_TO_EDGE, GL_REPEAT, GL_MIRRORED_REPEAT}};

glSamplerParameteri(sampler_id, GL_TEXTURE_WRAP_S,
address_modes[static_cast<u32>(params.wrap_u)]);
address_modes[static_cast<u32>(params.wrap_u.Value())]);
glSamplerParameteri(sampler_id, GL_TEXTURE_WRAP_T,
address_modes[static_cast<u32>(params.wrap_v)]);
address_modes[static_cast<u32>(params.wrap_v.Value())]);

glSamplerParameterf(sampler_id, GL_TEXTURE_MIN_LOD, params.min_lod / 16.f);
glSamplerParameterf(sampler_id, GL_TEXTURE_MAX_LOD, params.max_lod / 16.f);
Expand Down
3 changes: 3 additions & 0 deletions Source/Core/VideoBackends/Software/SWVertexLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ void SWVertexLoader::vFlush()
case PrimitiveType::Triangles:
primitiveType = OpcodeDecoder::GX_DRAW_TRIANGLES;
break;
case PrimitiveType::TriangleStrip:
primitiveType = OpcodeDecoder::GX_DRAW_TRIANGLE_STRIP;
break;
}

m_setup_unit.Init(primitiveType);
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/VideoBackends/Software/TransformUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ void TransformTexCoord(const InputVertexData* src, OutputVertexData* dst, bool s
dst->texCoords[coordNum].z = 1.0f;
break;
default:
ERROR_LOG(VIDEO, "Bad tex gen type %i", texinfo.texgentype);
ERROR_LOG(VIDEO, "Bad tex gen type %i", texinfo.texgentype.Value());
}
}

Expand Down
8 changes: 3 additions & 5 deletions Source/Core/VideoBackends/Vulkan/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,9 @@ constexpr u32 MINIMUM_DRAW_CALLS_PER_COMMAND_BUFFER_FOR_READBACK = 10;
// Multisampling state info that we don't expose in VideoCommon.
union MultisamplingState
{
struct {
u32 samples:5; // 1-16
u32 per_sample_shading:1; // SSAA
};
u32 hex;
BitField<0, 5, u32> samples; // 1-16
BitField<5, 1, u32> per_sample_shading; // SSAA
u32 hex;
};

} // namespace Vulkan
33 changes: 19 additions & 14 deletions Source/Core/VideoBackends/Vulkan/FramebufferManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,14 +368,15 @@ void FramebufferManager::ReinterpretPixelData(int convtype)

UtilityShaderDraw draw(g_command_buffer_mgr->GetCurrentCommandBuffer(),
g_object_cache->GetPipelineLayout(PIPELINE_LAYOUT_STANDARD),
m_efb_load_render_pass, g_shader_cache->GetPassthroughVertexShader(),
VK_NULL_HANDLE, pixel_shader);
m_efb_load_render_pass, g_shader_cache->GetScreenQuadVertexShader(),
g_shader_cache->GetScreenQuadGeometryShader(), pixel_shader);

VkRect2D region = {{0, 0}, {GetEFBWidth(), GetEFBHeight()}};
draw.SetMultisamplingState(GetEFBMultisamplingState());
draw.BeginRenderPass(m_efb_convert_framebuffer, region);
draw.SetPSSampler(0, m_efb_color_texture->GetView(), g_object_cache->GetPointSampler());
draw.DrawQuad(0, 0, GetEFBWidth(), GetEFBHeight());
draw.SetViewportAndScissor(0, 0, GetEFBWidth(), GetEFBHeight());
draw.DrawWithoutVertexBuffer(4);
draw.EndRenderPass();

// Swap EFB texture pointers
Expand Down Expand Up @@ -440,11 +441,13 @@ Texture2D* FramebufferManager::ResolveEFBDepthTexture(const VkRect2D& region)
// Draw using resolve shader to write the minimum depth of all samples to the resolve texture.
UtilityShaderDraw draw(g_command_buffer_mgr->GetCurrentCommandBuffer(),
g_object_cache->GetPipelineLayout(PIPELINE_LAYOUT_STANDARD),
m_depth_resolve_render_pass, g_shader_cache->GetPassthroughVertexShader(),
VK_NULL_HANDLE, m_ps_depth_resolve);
m_depth_resolve_render_pass, g_shader_cache->GetScreenQuadVertexShader(),
g_shader_cache->GetScreenQuadGeometryShader(), m_ps_depth_resolve);
draw.BeginRenderPass(m_depth_resolve_framebuffer, region);
draw.SetPSSampler(0, m_efb_depth_texture->GetView(), g_object_cache->GetPointSampler());
draw.DrawQuad(region.offset.x, region.offset.y, region.extent.width, region.extent.height);
draw.SetViewportAndScissor(region.offset.x, region.offset.y, region.extent.width,
region.extent.height);
draw.DrawWithoutVertexBuffer(4);
draw.EndRenderPass();

// Restore MSAA texture ready for rendering again
Expand Down Expand Up @@ -626,13 +629,14 @@ bool FramebufferManager::PopulateColorReadbackTexture()

UtilityShaderDraw draw(g_command_buffer_mgr->GetCurrentCommandBuffer(),
g_object_cache->GetPipelineLayout(PIPELINE_LAYOUT_STANDARD),
m_copy_color_render_pass, g_shader_cache->GetPassthroughVertexShader(),
m_copy_color_render_pass, g_shader_cache->GetScreenQuadVertexShader(),
VK_NULL_HANDLE, m_copy_color_shader);

VkRect2D rect = {{0, 0}, {EFB_WIDTH, EFB_HEIGHT}};
draw.BeginRenderPass(m_color_copy_framebuffer, rect);
draw.SetPSSampler(0, src_texture->GetView(), g_object_cache->GetPointSampler());
draw.DrawQuad(0, 0, EFB_WIDTH, EFB_HEIGHT);
draw.SetViewportAndScissor(0, 0, EFB_WIDTH, EFB_HEIGHT);
draw.DrawWithoutVertexBuffer(4);
draw.EndRenderPass();

// Restore EFB to color attachment, since we're done with it.
Expand Down Expand Up @@ -700,13 +704,14 @@ bool FramebufferManager::PopulateDepthReadbackTexture()

UtilityShaderDraw draw(g_command_buffer_mgr->GetCurrentCommandBuffer(),
g_object_cache->GetPipelineLayout(PIPELINE_LAYOUT_STANDARD),
m_copy_depth_render_pass, g_shader_cache->GetPassthroughVertexShader(),
m_copy_depth_render_pass, g_shader_cache->GetScreenQuadVertexShader(),
VK_NULL_HANDLE, m_copy_depth_shader);

VkRect2D rect = {{0, 0}, {EFB_WIDTH, EFB_HEIGHT}};
draw.BeginRenderPass(m_depth_copy_framebuffer, rect);
draw.SetPSSampler(0, src_texture->GetView(), g_object_cache->GetPointSampler());
draw.DrawQuad(0, 0, EFB_WIDTH, EFB_HEIGHT);
draw.SetViewportAndScissor(0, 0, EFB_WIDTH, EFB_HEIGHT);
draw.DrawWithoutVertexBuffer(4);
draw.EndRenderPass();

// Restore EFB to depth attachment, since we're done with it.
Expand Down Expand Up @@ -763,7 +768,7 @@ bool FramebufferManager::CreateReadbackRenderPasses()
g_vulkan_context->GetDeviceLimits().pointSizeRange[0] > 1 ||
g_vulkan_context->GetDeviceLimits().pointSizeRange[1] < 16)
{
m_poke_primitive = PrimitiveType::Triangles;
m_poke_primitive = PrimitiveType::TriangleStrip;
}
else
{
Expand Down Expand Up @@ -965,10 +970,10 @@ void FramebufferManager::CreatePokeVertices(std::vector<EFBPokeVertex>* destinat
float y2 = float(y + 1) * 2.0f / EFB_HEIGHT - 1.0f;
destination_list->push_back({{x1, y1, z, 1.0f}, color});
destination_list->push_back({{x2, y1, z, 1.0f}, color});
destination_list->push_back({{x2, y2, z, 1.0f}, color});
destination_list->push_back({{x1, y1, z, 1.0f}, color});
destination_list->push_back({{x2, y2, z, 1.0f}, color});
destination_list->push_back({{x1, y2, z, 1.0f}, color});
destination_list->push_back({{x1, y2, z, 1.0f}, color});
destination_list->push_back({{x2, y1, z, 1.0f}, color});
destination_list->push_back({{x2, y2, z, 1.0f}, color});
}

void FramebufferManager::FlushEFBPokes()
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/VideoBackends/Vulkan/FramebufferManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class FramebufferManager : public FramebufferManagerBase
std::unique_ptr<StreamBuffer> m_poke_vertex_stream_buffer;
std::vector<EFBPokeVertex> m_color_poke_vertices;
std::vector<EFBPokeVertex> m_depth_poke_vertices;
PrimitiveType m_poke_primitive = PrimitiveType::Triangles;
PrimitiveType m_poke_primitive = PrimitiveType::TriangleStrip;

VkRenderPass m_copy_color_render_pass = VK_NULL_HANDLE;
VkRenderPass m_copy_depth_render_pass = VK_NULL_HANDLE;
Expand Down
10 changes: 5 additions & 5 deletions Source/Core/VideoBackends/Vulkan/ObjectCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,11 +342,11 @@ VkSampler ObjectCache::GetSampler(const SamplerState& info)
VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO, // VkStructureType sType
nullptr, // const void* pNext
0, // VkSamplerCreateFlags flags
filters[static_cast<u32>(info.mag_filter)], // VkFilter magFilter
filters[static_cast<u32>(info.min_filter)], // VkFilter minFilter
mipmap_modes[static_cast<u32>(info.mipmap_filter)], // VkSamplerMipmapMode mipmapMode
address_modes[static_cast<u32>(info.wrap_u)], // VkSamplerAddressMode addressModeU
address_modes[static_cast<u32>(info.wrap_v)], // VkSamplerAddressMode addressModeV
filters[static_cast<u32>(info.mag_filter.Value())], // VkFilter magFilter
filters[static_cast<u32>(info.min_filter.Value())], // VkFilter minFilter
mipmap_modes[static_cast<u32>(info.mipmap_filter.Value())], // VkSamplerMipmapMode mipmapMode
address_modes[static_cast<u32>(info.wrap_u.Value())], // VkSamplerAddressMode addressModeU
address_modes[static_cast<u32>(info.wrap_v.Value())], // VkSamplerAddressMode addressModeV
VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, // VkSamplerAddressMode addressModeW
info.lod_bias / 256.0f, // float mipLodBias
VK_FALSE, // VkBool32 anisotropyEnable
Expand Down
5 changes: 4 additions & 1 deletion Source/Core/VideoBackends/Vulkan/PostProcessing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,14 @@ void VulkanPostProcessing::BlitFromTexture(const TargetRectangle& dst, const Tar
const Texture2D* src_tex, int src_layer,
VkRenderPass render_pass)
{
// If the source layer is negative we simply copy all available layers.
VkShaderModule geometry_shader =
src_layer < 0 ? g_shader_cache->GetPassthroughGeometryShader() : VK_NULL_HANDLE;
VkShaderModule fragment_shader =
m_fragment_shader != VK_NULL_HANDLE ? m_fragment_shader : m_default_fragment_shader;
UtilityShaderDraw draw(g_command_buffer_mgr->GetCurrentCommandBuffer(),
g_object_cache->GetPipelineLayout(PIPELINE_LAYOUT_STANDARD), render_pass,
g_shader_cache->GetPassthroughVertexShader(), VK_NULL_HANDLE,
g_shader_cache->GetPassthroughVertexShader(), geometry_shader,
fragment_shader);

// Source is always bound.
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/VideoBackends/Vulkan/RasterFont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ void RasterFont::PrintMultiLineText(VkRenderPass render_pass, const std::string&
size_t num_vertices = 0;
if (!vertices)
return;
#ifdef __ANDROID__
#ifdef ANDROID
float delta_x = float(2.5f * CHARACTER_WIDTH) / float(bbWidth);
float delta_y = float(2.5f * CHARACTER_HEIGHT) / float(bbHeight);

Expand Down
2 changes: 1 addition & 1 deletion Source/Core/VideoBackends/Vulkan/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ void Renderer::ClearScreen(const EFBRectangle& rc, bool color_enable, bool alpha
g_object_cache->GetPipelineLayout(PIPELINE_LAYOUT_STANDARD),
FramebufferManager::GetInstance()->GetEFBLoadRenderPass(),
g_shader_cache->GetPassthroughVertexShader(),
VK_NULL_HANDLE, m_clear_fragment_shader);
g_shader_cache->GetPassthroughGeometryShader(), m_clear_fragment_shader);

draw.SetMultisamplingState(FramebufferManager::GetInstance()->GetEFBMultisamplingState());
draw.SetDepthState(depth_state);
Expand Down
85 changes: 80 additions & 5 deletions Source/Core/VideoBackends/Vulkan/ShaderCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ GetVulkanMultisampleState(const MultisamplingState& state)
nullptr, // const void* pNext
0, // VkPipelineMultisampleStateCreateFlags flags
static_cast<VkSampleCountFlagBits>(
state.samples), // VkSampleCountFlagBits rasterizationSamples
state.samples.Value()), // VkSampleCountFlagBits rasterizationSamples
state.per_sample_shading, // VkBool32 sampleShadingEnable
1.0f, // float minSampleShading
nullptr, // const VkSampleMask* pSampleMask;
Expand Down Expand Up @@ -237,10 +237,10 @@ VkPipeline ShaderCache::CreatePipeline(const PipelineInfo& info)
// Input assembly
static constexpr std::array<VkPrimitiveTopology, 4> vk_primitive_topologies = {
{VK_PRIMITIVE_TOPOLOGY_POINT_LIST, VK_PRIMITIVE_TOPOLOGY_LINE_LIST,
VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST}};
VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP}};
VkPipelineInputAssemblyStateCreateInfo input_assembly_state = {
VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
vk_primitive_topologies[static_cast<u32>(info.rasterization_state.primitive)],
vk_primitive_topologies[static_cast<u32>(info.rasterization_state.primitive.Value())],
VK_FALSE};

// Shaders to stages
Expand Down Expand Up @@ -696,11 +696,83 @@ bool ShaderCache::CompileSharedShaders()
}
)";

static const char PASSTHROUGH_GEOMETRY_SHADER_SOURCE[] = R"(
layout(triangles) in;
layout(triangle_strip, max_vertices = EFB_LAYERS * 3) out;
layout(location = 0) in vec3 in_uv0[];
layout(location = 1) in vec4 in_col0[];
layout(location = 0) out vec3 out_uv0;
layout(location = 1) out vec4 out_col0;
void main()
{
for (int j = 0; j < EFB_LAYERS; j++)
{
for (int i = 0; i < 3; i++)
{
gl_Layer = j;
gl_Position = gl_in[i].gl_Position;
out_uv0 = vec3(in_uv0[i].xy, float(j));
out_col0 = in_col0[i];
EmitVertex();
}
EndPrimitive();
}
}
)";

static const char SCREEN_QUAD_VERTEX_SHADER_SOURCE[] = R"(
layout(location = 0) out vec3 uv0;
void main()
{
/*
* id &1 &2 clamp(*2-1)
* 0 0,0 0,0 -1,-1 TL
* 1 1,0 1,0 1,-1 TR
* 2 0,2 0,1 -1,1 BL
* 3 1,2 1,1 1,1 BR
*/
vec2 rawpos = vec2(float(gl_VertexID & 1), clamp(float(gl_VertexID & 2), 0.0f, 1.0f));
gl_Position = vec4(rawpos * 2.0f - 1.0f, 0.0f, 1.0f);
uv0 = vec3(rawpos, 0.0f);
}
)";

static const char SCREEN_QUAD_GEOMETRY_SHADER_SOURCE[] = R"(
layout(triangles) in;
layout(triangle_strip, max_vertices = EFB_LAYERS * 3) out;
layout(location = 0) in vec3 in_uv0[];
layout(location = 0) out vec3 out_uv0;
void main()
{
for (int j = 0; j < EFB_LAYERS; j++)
{
for (int i = 0; i < 3; i++)
{
gl_Layer = j;
gl_Position = gl_in[i].gl_Position;
out_uv0 = vec3(in_uv0[i].xy, float(j));
EmitVertex();
}
EndPrimitive();
}
}
)";

std::string header = GetUtilityShaderHeader();

m_screen_quad_vertex_shader =
Util::CompileAndCreateVertexShader(header + SCREEN_QUAD_VERTEX_SHADER_SOURCE);
m_passthrough_vertex_shader =
Util::CompileAndCreateVertexShader(header + PASSTHROUGH_VERTEX_SHADER_SOURCE);
if (m_passthrough_vertex_shader == VK_NULL_HANDLE)
if (m_screen_quad_vertex_shader == VK_NULL_HANDLE ||
m_passthrough_vertex_shader == VK_NULL_HANDLE)
{
return false;
}
Expand All @@ -718,6 +790,9 @@ void ShaderCache::DestroySharedShaders()
}
};

DestroyShader(m_screen_quad_vertex_shader);
DestroyShader(m_passthrough_vertex_shader);
DestroyShader(m_screen_quad_geometry_shader);
DestroyShader(m_passthrough_geometry_shader);
}
}
} // namespace Vulkan
6 changes: 6 additions & 0 deletions Source/Core/VideoBackends/Vulkan/ShaderCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ class ShaderCache
void ReloadPipelineCache();

// Shared shader accessors
VkShaderModule GetScreenQuadVertexShader() const { return m_screen_quad_vertex_shader; }
VkShaderModule GetPassthroughVertexShader() const { return m_passthrough_vertex_shader; }
VkShaderModule GetScreenQuadGeometryShader() const { return m_screen_quad_geometry_shader; }
VkShaderModule GetPassthroughGeometryShader() const { return m_passthrough_geometry_shader; }

private:
bool CreatePipelineCache();
Expand All @@ -129,7 +132,10 @@ class ShaderCache
std::string m_pipeline_cache_filename;

// Utility/shared shaders
VkShaderModule m_screen_quad_vertex_shader = VK_NULL_HANDLE;
VkShaderModule m_passthrough_vertex_shader = VK_NULL_HANDLE;
VkShaderModule m_screen_quad_geometry_shader = VK_NULL_HANDLE;
VkShaderModule m_passthrough_geometry_shader = VK_NULL_HANDLE;
};

extern std::unique_ptr<ShaderCache> g_shader_cache;
Expand Down
3 changes: 2 additions & 1 deletion Source/Core/VideoBackends/Vulkan/TextureCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ bool TextureCache::CompileShaders()
std::string source = header + COPY_SHADER_SOURCE;

m_copy_shader = Util::CompileAndCreateFragmentShader(source);

return m_copy_shader != VK_NULL_HANDLE;
}

Expand Down Expand Up @@ -297,7 +298,7 @@ void TextureCache::CopyEFBToCacheEntry(TCacheEntry* entry, bool is_depth_copy,
UtilityShaderDraw draw(command_buffer,
g_object_cache->GetPipelineLayout(PIPELINE_LAYOUT_STANDARD), render_pass,
g_shader_cache->GetPassthroughVertexShader(),
VK_NULL_HANDLE, shader);
g_shader_cache->GetPassthroughGeometryShader(), shader);

u8* ubo_ptr = draw.AllocatePSUniforms(sizeof(PixelUniforms));
std::memcpy(ubo_ptr, &uniforms, sizeof(PixelUniforms));
Expand Down
Loading

0 comments on commit 5f4f43a

Please sign in to comment.