mirror of
https://git.eden-emu.dev/eden-emu/eden
synced 2026-10-21 17:03:00 -04:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4cf3d52897 |
@@ -40,12 +40,6 @@ bool IsConnectionBased(Type type) {
|
||||
}
|
||||
}
|
||||
|
||||
// Size of a real BSD sockaddr_in. The guest SockAddrIn struct is padded to 0x100 so that longer
|
||||
// input addresses can be read, but an address handed back to the game is always this long.
|
||||
// Reporting 0x100 lets a game that trusts the length copy 240 bytes past its 16-byte sockaddr
|
||||
// (suspected cause of Crysis Remastered crashing ~30 s after its getsockname() call).
|
||||
constexpr size_t GuestSockAddrInSize = 16;
|
||||
|
||||
template <typename T>
|
||||
T GetValue(std::span<const u8> buffer) {
|
||||
T t{};
|
||||
@@ -661,9 +655,6 @@ std::pair<s32, Errno> BSD_USA::AcceptImpl(s32 fd, std::vector<u8>& write_buffer)
|
||||
new_descriptor.is_connection_based = descriptor.is_connection_based;
|
||||
|
||||
const SockAddrIn guest_addr_in = Translate(result.sockaddr_in);
|
||||
if (write_buffer.size() > GuestSockAddrInSize) {
|
||||
write_buffer.resize(GuestSockAddrInSize);
|
||||
}
|
||||
PutValue(write_buffer, guest_addr_in);
|
||||
|
||||
return {new_fd, Errno::SUCCESS};
|
||||
@@ -723,8 +714,8 @@ Errno BSD_USA::GetPeerNameImpl(s32 fd, std::vector<u8>& write_buffer) {
|
||||
}
|
||||
const SockAddrIn guest_addrin = Translate(addr_in);
|
||||
|
||||
// The reported length must be that of a real sockaddr_in, not of the padded guest struct.
|
||||
write_buffer.resize(GuestSockAddrInSize);
|
||||
ASSERT(write_buffer.size() >= sizeof(guest_addrin));
|
||||
write_buffer.resize(sizeof(guest_addrin));
|
||||
PutValue(write_buffer, guest_addrin);
|
||||
return Translate(bsd_errno);
|
||||
}
|
||||
@@ -745,8 +736,8 @@ Errno BSD_USA::GetSockNameImpl(s32 fd, std::vector<u8>& write_buffer) {
|
||||
}
|
||||
const SockAddrIn guest_addrin = Translate(addr_in);
|
||||
|
||||
// The reported length must be that of a real sockaddr_in, not of the padded guest struct.
|
||||
write_buffer.resize(GuestSockAddrInSize);
|
||||
ASSERT(write_buffer.size() >= sizeof(guest_addrin));
|
||||
write_buffer.resize(sizeof(guest_addrin));
|
||||
PutValue(write_buffer, guest_addrin);
|
||||
return Translate(bsd_errno);
|
||||
}
|
||||
@@ -958,9 +949,8 @@ std::pair<s32, Errno> BSD_USA::RecvFromImpl(s32 fd, u32 flags, std::vector<u8>&
|
||||
if (ret < 0) {
|
||||
addr.clear();
|
||||
} else {
|
||||
ASSERT(addr.size() >= GuestSockAddrInSize);
|
||||
ASSERT(addr.size() >= 16);
|
||||
const SockAddrIn result = Translate(addr_in);
|
||||
addr.resize(GuestSockAddrInSize);
|
||||
PutValue(addr, result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,6 +40,8 @@ struct HostTranslateInfo {
|
||||
bool support_conditional_barrier{}; ///< True when the device supports barriers in conditional
|
||||
///< control flow
|
||||
bool single_lane_geometry_subgroups{};
|
||||
bool support_attribute_texture_handle{}; ///< True when the host binds texture handles that
|
||||
///< arrive as vertex attributes
|
||||
|
||||
void ApplyDescriptorLimitPolicy() noexcept {
|
||||
if (min_ssbo_alignment == 0) {
|
||||
|
||||
@@ -268,6 +268,10 @@ static inline u32 ReadCbufCached(Environment& env, u32 index, u32 offset) {
|
||||
return v;
|
||||
}
|
||||
|
||||
static inline bool IsAttributeHandle(const ConstBufferAddr& cbuf) {
|
||||
return cbuf.index == ATTRIBUTE_HANDLE_CBUF_INDEX;
|
||||
}
|
||||
|
||||
static inline u32 GetTextureHandleCached(Environment& env, const ConstBufferAddr& cbuf) {
|
||||
// Must all be uniquely different variables
|
||||
// If has secondary, then it will be cbuf.secondary_{index|offset}, else its 0.
|
||||
@@ -287,14 +291,23 @@ static inline u32 GetTextureHandleCached(Environment& env, const ConstBufferAddr
|
||||
|
||||
// Cached variants of existing helpers
|
||||
static inline TextureType ReadTextureTypeCached(Environment& env, const ConstBufferAddr& cbuf) {
|
||||
if (IsAttributeHandle(cbuf)) {
|
||||
return TextureType::Color2D;
|
||||
}
|
||||
return env.ReadTextureType(GetTextureHandleCached(env, cbuf));
|
||||
}
|
||||
static inline TexturePixelFormat ReadTexturePixelFormatCached(Environment& env,
|
||||
const ConstBufferAddr& cbuf) {
|
||||
if (IsAttributeHandle(cbuf)) {
|
||||
return TexturePixelFormat::A8B8G8R8_UNORM;
|
||||
}
|
||||
return env.ReadTexturePixelFormat(GetTextureHandleCached(env, cbuf));
|
||||
}
|
||||
static inline bool IsTexturePixelFormatIntegerCached(Environment& env,
|
||||
const ConstBufferAddr& cbuf) {
|
||||
if (IsAttributeHandle(cbuf)) {
|
||||
return false;
|
||||
}
|
||||
return env.IsTexturePixelFormatInteger(GetTextureHandleCached(env, cbuf));
|
||||
}
|
||||
|
||||
@@ -466,15 +479,43 @@ std::optional<ConstBufferAddr> TryGetConstBuffer(const IR::Inst* inst, Environme
|
||||
};
|
||||
}
|
||||
|
||||
bool IsAttributeSourcedHandle(const IR::Value& handle) {
|
||||
if (handle.IsImmediate()) {
|
||||
return false;
|
||||
}
|
||||
const IR::Inst* inst{handle.InstRecursive()};
|
||||
if (inst->GetOpcode() == IR::Opcode::BitCastU32F32 && !inst->Arg(0).IsImmediate()) {
|
||||
inst = inst->Arg(0).InstRecursive();
|
||||
}
|
||||
return inst->GetOpcode() == IR::Opcode::GetAttribute ||
|
||||
inst->GetOpcode() == IR::Opcode::GetAttributeU32;
|
||||
}
|
||||
|
||||
TextureInst MakeInst(Environment& env, IR::Block* block, IR::Inst& inst, const HostTranslateInfo& host_info) {
|
||||
ConstBufferAddr addr;
|
||||
if (IsBindless(inst)) {
|
||||
const std::optional<ConstBufferAddr> track_addr{TrackCached(inst.Arg(0), env, host_info)};
|
||||
|
||||
if (!track_addr) {
|
||||
throw NotImplementedException("Failed to track bindless texture constant buffer");
|
||||
} else {
|
||||
if (track_addr) {
|
||||
addr = *track_addr;
|
||||
} else if (host_info.support_attribute_texture_handle &&
|
||||
IsAttributeSourcedHandle(inst.Arg(0))) {
|
||||
// The handle travels with the vertices (sprite batches pick the texture per quad), so
|
||||
// there is no constant buffer to read it from. The host binds the handle of each run
|
||||
// of vertices that share one.
|
||||
addr = ConstBufferAddr{
|
||||
.index = ATTRIBUTE_HANDLE_CBUF_INDEX,
|
||||
.offset = 0,
|
||||
.shift_left = 0,
|
||||
.secondary_index = 0,
|
||||
.secondary_offset = 0,
|
||||
.secondary_shift_left = 0,
|
||||
.dynamic_offset = {},
|
||||
.count = 1,
|
||||
.has_secondary = false,
|
||||
};
|
||||
} else {
|
||||
throw NotImplementedException("Failed to track bindless texture constant buffer");
|
||||
}
|
||||
} else {
|
||||
addr = ConstBufferAddr{
|
||||
|
||||
@@ -38,6 +38,10 @@ enum class TextureType : u32 {
|
||||
};
|
||||
constexpr u32 NUM_TEXTURE_TYPES = 9;
|
||||
|
||||
/// Constant buffer index marking a texture handle that the shader receives as a vertex attribute
|
||||
/// instead of reading it from a constant buffer. The host supplies the handle of each draw run.
|
||||
constexpr u32 ATTRIBUTE_HANDLE_CBUF_INDEX = 0xFFFF;
|
||||
|
||||
enum class TexturePixelFormat {
|
||||
A8B8G8R8_UNORM,
|
||||
A8B8G8R8_SNORM,
|
||||
|
||||
@@ -563,8 +563,10 @@ void RecordShaderReadBarrier(Scheduler& scheduler, const ImageView& image_view)
|
||||
});
|
||||
}
|
||||
|
||||
void BeginRenderPass(vk::CommandBuffer& cmdbuf, VkRenderPass render_pass,
|
||||
VkFramebuffer framebuffer_handle, VkExtent2D render_area) {
|
||||
void BeginRenderPass(vk::CommandBuffer& cmdbuf, const Framebuffer* framebuffer) {
|
||||
const VkRenderPass render_pass = framebuffer->RenderPass();
|
||||
const VkFramebuffer framebuffer_handle = framebuffer->Handle();
|
||||
const VkExtent2D render_area = framebuffer->RenderArea();
|
||||
const VkRenderPassBeginInfo renderpass_bi{
|
||||
.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
|
||||
.pNext = nullptr,
|
||||
@@ -677,67 +679,27 @@ void BlitImageHelper::BlitColor(const Framebuffer* dst_framebuffer, const ImageV
|
||||
void BlitImageHelper::BlitColor(const Framebuffer* dst_framebuffer, VkImageView src_image_view,
|
||||
VkImage src_image, VkSampler src_sampler,
|
||||
const Region2D& dst_region, const Region2D& src_region,
|
||||
const Extent3D& src_size,
|
||||
const std::optional<VkRect2D>& scissor) {
|
||||
const Extent3D& src_size) {
|
||||
const BlitImagePipelineKey key{
|
||||
.renderpass = dst_framebuffer->RenderPass(),
|
||||
.operation = Tegra::Engines::Fermi2D::Operation::SrcCopy,
|
||||
};
|
||||
const VkPipelineLayout layout = *one_texture_pipeline_layout;
|
||||
const VkPipeline pipeline = FindOrEmplaceColorPipeline(key);
|
||||
|
||||
// Clip the destination rectangle to the scissor; the viewport keeps the full rectangle so
|
||||
// the texture coordinates are unchanged.
|
||||
std::optional<VkRect2D> clip;
|
||||
if (scissor) {
|
||||
const s64 x0 = (std::max)(s64{(std::min)(dst_region.start.x, dst_region.end.x)},
|
||||
s64{scissor->offset.x});
|
||||
const s64 y0 = (std::max)(s64{(std::min)(dst_region.start.y, dst_region.end.y)},
|
||||
s64{scissor->offset.y});
|
||||
const s64 x1 = (std::min)(s64{(std::max)(dst_region.start.x, dst_region.end.x)},
|
||||
s64{scissor->offset.x} + scissor->extent.width);
|
||||
const s64 y1 = (std::min)(s64{(std::max)(dst_region.start.y, dst_region.end.y)},
|
||||
s64{scissor->offset.y} + scissor->extent.height);
|
||||
if (x1 <= x0 || y1 <= y0) {
|
||||
return; // Fully scissored out.
|
||||
}
|
||||
clip = VkRect2D{
|
||||
.offset = {static_cast<s32>(x0), static_cast<s32>(y0)},
|
||||
.extent = {static_cast<u32>(x1 - x0), static_cast<u32>(y1 - y0)},
|
||||
};
|
||||
}
|
||||
|
||||
// Read the framebuffer now: by the time the worker runs this, the texture cache may have
|
||||
// retired it (moved into its delayed-destruction ring), leaving a null handle behind - Turnip
|
||||
// then crashed in vkCmdBeginRenderPass (Crysis Remastered, DrawTexture).
|
||||
const VkRenderPass render_pass = dst_framebuffer->RenderPass();
|
||||
const VkFramebuffer framebuffer_handle = dst_framebuffer->Handle();
|
||||
const VkExtent2D render_area = dst_framebuffer->RenderArea();
|
||||
scheduler.RequestOutsideRenderPassOperationContext();
|
||||
scheduler.Record([this, render_pass, framebuffer_handle, render_area, src_image_view,
|
||||
src_image, src_sampler, dst_region, src_region, src_size, pipeline, layout,
|
||||
clip](vk::CommandBuffer cmdbuf) {
|
||||
// Images stay in GENERAL everywhere (the descriptor below says so too): only make the
|
||||
// earlier writes visible. Moving the source to SHADER_READ_ONLY_OPTIMAL left it there
|
||||
// for good, so every later render pass used it in the wrong layout.
|
||||
TransitionImageLayout(cmdbuf, src_image, VK_IMAGE_LAYOUT_GENERAL);
|
||||
BeginRenderPass(cmdbuf, render_pass, framebuffer_handle, render_area);
|
||||
scheduler.Record([this, dst_framebuffer, src_image_view, src_image, src_sampler, dst_region,
|
||||
src_region, src_size, pipeline, layout](vk::CommandBuffer cmdbuf) {
|
||||
TransitionImageLayout(cmdbuf, src_image, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
|
||||
BeginRenderPass(cmdbuf, dst_framebuffer);
|
||||
const VkDescriptorSet descriptor_set = one_texture_descriptor_allocator.Commit();
|
||||
UpdateOneTextureDescriptorSet(device, descriptor_set, src_sampler, src_image_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, src_size);
|
||||
if (clip) {
|
||||
cmdbuf.SetScissor(0, *clip);
|
||||
}
|
||||
cmdbuf.Draw(3, 1, 0, 0);
|
||||
cmdbuf.EndRenderPass();
|
||||
});
|
||||
// The blit set its own pipeline, viewport and scissor: make the next draw set its own again,
|
||||
// as every other helper here does. Without this the next draw kept the blit's viewport and
|
||||
// scissor: Crysis Remastered drew its 256x256 minimap map over the whole screen.
|
||||
scheduler.InvalidateState();
|
||||
}
|
||||
|
||||
void BlitImageHelper::BlitImpl(const Framebuffer* dst_framebuffer,
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <deque>
|
||||
#include <optional>
|
||||
#include <span>
|
||||
|
||||
#include "video_core/engines/fermi_2d.h"
|
||||
@@ -79,12 +78,9 @@ public:
|
||||
Tegra::Engines::Fermi2D::Filter filter,
|
||||
Tegra::Engines::Fermi2D::Operation operation);
|
||||
|
||||
/// @param scissor Optional clip rectangle in framebuffer pixels (DrawTexture honours the
|
||||
/// guest scissor like any other draw).
|
||||
void BlitColor(const Framebuffer* dst_framebuffer, VkImageView src_image_view,
|
||||
VkImage src_image, VkSampler src_sampler, const Region2D& dst_region,
|
||||
const Region2D& src_region, const Extent3D& src_size,
|
||||
const std::optional<VkRect2D>& scissor = std::nullopt);
|
||||
const Region2D& src_region, const Extent3D& src_size);
|
||||
|
||||
void BlitColorMSAA(const Framebuffer* dst_framebuffer, const ImageView& src_image_view,
|
||||
const Region2D& dst_region, const Region2D& src_region);
|
||||
|
||||
@@ -276,6 +276,9 @@ GraphicsPipeline::GraphicsPipeline(
|
||||
num_textures += Shader::NumDescriptors(info->texture_descriptors);
|
||||
num_image_elements += Shader::NumDescriptors(info->texture_descriptors);
|
||||
num_image_elements += Shader::NumDescriptors(info->image_descriptors);
|
||||
for (const auto& desc : info->texture_descriptors) {
|
||||
uses_attribute_handle |= desc.cbuf_index == Shader::ATTRIBUTE_HANDLE_CBUF_INDEX;
|
||||
}
|
||||
num_descriptor_entries += NumDescriptorEntries(*info);
|
||||
}
|
||||
fragment_has_color0_output = stage_infos[NUM_STAGES - 1].stores_frag_color[0];
|
||||
@@ -375,6 +378,9 @@ bool GraphicsPipeline::ConfigureImpl(bool is_indexed) {
|
||||
}
|
||||
const auto& cbufs{maxwell3d->state.shader_stages[stage].const_buffers};
|
||||
const auto read_handle{[&](const auto& desc, u32 index) {
|
||||
if (desc.cbuf_index == Shader::ATTRIBUTE_HANDLE_CBUF_INDEX) {
|
||||
return TexturePair(attribute_handle, via_header_index);
|
||||
}
|
||||
ASSERT(cbufs[desc.cbuf_index].enabled);
|
||||
const u32 index_offset{index << desc.size_shift};
|
||||
const u32 offset{desc.cbuf_offset + index_offset};
|
||||
|
||||
@@ -110,6 +110,16 @@ public:
|
||||
return configure_func(this, is_indexed);
|
||||
}
|
||||
|
||||
/// True when a shader samples a texture whose handle arrives as a vertex attribute.
|
||||
[[nodiscard]] bool UsesAttributeHandle() const noexcept {
|
||||
return uses_attribute_handle;
|
||||
}
|
||||
|
||||
/// Handle bound to those textures by the next Configure.
|
||||
void SetAttributeHandle(u32 handle) noexcept {
|
||||
attribute_handle = handle;
|
||||
}
|
||||
|
||||
[[nodiscard]] GraphicsPipeline* Next(const GraphicsPipelineCacheKey& current_key) noexcept {
|
||||
if (key == current_key) {
|
||||
return this;
|
||||
@@ -168,6 +178,8 @@ private:
|
||||
u32 num_descriptor_entries{};
|
||||
size_t num_image_elements{};
|
||||
u32 num_textures{};
|
||||
u32 attribute_handle{};
|
||||
bool uses_attribute_handle{};
|
||||
bool fragment_has_color0_output{};
|
||||
|
||||
vk::DescriptorSetLayout descriptor_set_layout;
|
||||
|
||||
@@ -491,6 +491,7 @@ PipelineCache::PipelineCache(Tegra::MaxwellDeviceMemoryManager& device_memory_,
|
||||
.support_geometry_shader_passthrough = device.IsNvGeometryShaderPassthroughSupported(),
|
||||
.support_conditional_barrier = device.SupportsConditionalBarriers(),
|
||||
.single_lane_geometry_subgroups = !profile.SupportsSubgroupStage(Shader::Stage::Geometry),
|
||||
.support_attribute_texture_handle = true,
|
||||
};
|
||||
host_info.ApplyDescriptorLimitPolicy();
|
||||
|
||||
|
||||
@@ -248,6 +248,15 @@ void RasterizerVulkan::PrepareDraw(bool is_indexed, Func&& draw_func) {
|
||||
std::scoped_lock lock{buffer_cache.mutex, texture_cache.mutex};
|
||||
// update engine as channel may be different.
|
||||
pipeline->SetEngine(maxwell3d, gpu_memory);
|
||||
attribute_handle_pipeline = nullptr;
|
||||
attribute_handle_runs.clear();
|
||||
if (split_attribute_handles && pipeline->UsesAttributeHandle()) {
|
||||
CollectAttributeHandleRuns(is_indexed);
|
||||
if (!attribute_handle_runs.empty()) {
|
||||
attribute_handle_pipeline = pipeline;
|
||||
pipeline->SetAttributeHandle(attribute_handle_runs.front().handle);
|
||||
}
|
||||
}
|
||||
if (!pipeline->Configure(is_indexed))
|
||||
return;
|
||||
|
||||
@@ -259,22 +268,110 @@ void RasterizerVulkan::PrepareDraw(bool is_indexed, Func&& draw_func) {
|
||||
draw_func();
|
||||
}
|
||||
|
||||
void RasterizerVulkan::CollectAttributeHandleRuns(bool is_indexed) {
|
||||
using VertexAttribute = Maxwell::VertexAttribute;
|
||||
const auto& regs = maxwell3d->regs;
|
||||
const auto& draw_state = maxwell3d->draw_manager.draw_state;
|
||||
const u32 total = is_indexed ? draw_state.index_buffer.count : draw_state.vertex_buffer.count;
|
||||
if (total == 0) {
|
||||
return;
|
||||
}
|
||||
// The handle is an integer attribute; sprite batches repeat it on every vertex of a quad.
|
||||
const VertexAttribute* source{};
|
||||
for (const auto& attr : regs.vertex_attrib_format) {
|
||||
if (attr.constant || attr.size == VertexAttribute::Size::Invalid) {
|
||||
continue;
|
||||
}
|
||||
if (attr.type == VertexAttribute::Type::UInt || attr.type == VertexAttribute::Type::SInt) {
|
||||
source = &attr;
|
||||
break;
|
||||
}
|
||||
}
|
||||
const auto& stream = regs.vertex_streams[source ? source->buffer.Value() : 0];
|
||||
if (!source || !stream.IsEnabled()) {
|
||||
attribute_handle_runs.push_back({0, total, 0});
|
||||
return;
|
||||
}
|
||||
// Only plain triangle lists are split; anything else keeps the handle of its first vertex.
|
||||
const u32 primitive_size =
|
||||
draw_state.topology == Maxwell::PrimitiveTopology::Triangles ? 3 : total;
|
||||
const GPUVAddr base_address = stream.Address() + source->offset;
|
||||
const auto read_handle = [&](u32 position) {
|
||||
u32 vertex;
|
||||
if (is_indexed) {
|
||||
const auto& index_buffer = draw_state.index_buffer;
|
||||
const GPUVAddr address =
|
||||
index_buffer.IndexStart() + size_t{position} * index_buffer.FormatSizeInBytes();
|
||||
u32 index{};
|
||||
gpu_memory->ReadBlockUnsafe(address, &index, index_buffer.FormatSizeInBytes());
|
||||
vertex = static_cast<u32>(draw_state.base_index + index);
|
||||
} else {
|
||||
vertex = draw_state.vertex_buffer.first + position;
|
||||
}
|
||||
return gpu_memory->Read<u32>(base_address + static_cast<GPUVAddr>(vertex) * stream.stride);
|
||||
};
|
||||
for (u32 position = 0; position + primitive_size <= total; position += primitive_size) {
|
||||
const u32 handle = read_handle(position);
|
||||
if (!attribute_handle_runs.empty() && attribute_handle_runs.back().handle == handle) {
|
||||
attribute_handle_runs.back().count += primitive_size;
|
||||
} else {
|
||||
attribute_handle_runs.push_back({position, primitive_size, handle});
|
||||
}
|
||||
}
|
||||
if (attribute_handle_runs.empty()) {
|
||||
attribute_handle_runs.push_back({0, total, read_handle(0)});
|
||||
} else {
|
||||
const u32 covered = attribute_handle_runs.back().first + attribute_handle_runs.back().count;
|
||||
if (covered < total) {
|
||||
attribute_handle_runs.back().count += total - covered;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RasterizerVulkan::Draw(bool is_indexed, u32 instance_count) {
|
||||
split_attribute_handles = true;
|
||||
SCOPE_EXIT {
|
||||
split_attribute_handles = false;
|
||||
};
|
||||
PrepareDraw(is_indexed, [this, is_indexed, instance_count] {
|
||||
const auto& draw_state = maxwell3d->draw_manager.draw_state;
|
||||
const u32 num_instances{instance_count};
|
||||
const DrawParams draw_params{MakeDrawParams(draw_state, num_instances, is_indexed)};
|
||||
|
||||
scheduler.Record([draw_params](vk::CommandBuffer cmdbuf) {
|
||||
if (draw_params.is_indexed) {
|
||||
cmdbuf.DrawIndexed(draw_params.num_vertices, draw_params.num_instances,
|
||||
draw_params.first_index, draw_params.base_vertex,
|
||||
draw_params.base_instance);
|
||||
} else {
|
||||
cmdbuf.Draw(draw_params.num_vertices, draw_params.num_instances,
|
||||
draw_params.base_vertex, draw_params.base_instance);
|
||||
const auto record_draw = [this](const DrawParams& params) {
|
||||
scheduler.Record([params](vk::CommandBuffer cmdbuf) {
|
||||
if (params.is_indexed) {
|
||||
cmdbuf.DrawIndexed(params.num_vertices, params.num_instances,
|
||||
params.first_index, params.base_vertex,
|
||||
params.base_instance);
|
||||
} else {
|
||||
cmdbuf.Draw(params.num_vertices, params.num_instances, params.base_vertex,
|
||||
params.base_instance);
|
||||
}
|
||||
});
|
||||
};
|
||||
if (attribute_handle_pipeline && attribute_handle_runs.size() > 1) {
|
||||
// The first run is already configured, each further one binds its own texture.
|
||||
for (size_t i = 0; i < attribute_handle_runs.size(); ++i) {
|
||||
const AttributeHandleRun& run = attribute_handle_runs[i];
|
||||
if (i != 0) {
|
||||
attribute_handle_pipeline->SetAttributeHandle(run.handle);
|
||||
if (!attribute_handle_pipeline->Configure(is_indexed)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
DrawParams run_params = draw_params;
|
||||
run_params.num_vertices = run.count;
|
||||
if (is_indexed) {
|
||||
run_params.first_index += run.first;
|
||||
} else {
|
||||
run_params.base_vertex += run.first;
|
||||
}
|
||||
record_draw(run_params);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
record_draw(draw_params);
|
||||
}
|
||||
|
||||
// Log draw call
|
||||
if (GPU::Logging::IsActive() &&
|
||||
@@ -393,35 +490,8 @@ void RasterizerVulkan::DrawTexture() {
|
||||
.y = ScaleSrc(draw_texture_state.src_y1)}};
|
||||
Extent3D src_size = {static_cast<u32>(ScaleSrc(texture.size.width)),
|
||||
static_cast<u32>(ScaleSrc(texture.size.height)), texture.size.depth};
|
||||
// DrawTexture rectangles go through the fragment pipeline, scissor included.
|
||||
std::optional<VkRect2D> scissor;
|
||||
if (maxwell3d->regs.scissor_test[0].enable) {
|
||||
u32 up_scale = 1;
|
||||
u32 down_shift = 0;
|
||||
if (dst_rescaling) {
|
||||
up_scale = Settings::values.resolution_info.up_scale;
|
||||
down_shift = Settings::values.resolution_info.down_shift;
|
||||
}
|
||||
scissor = GetScissorState(maxwell3d->regs, 0, up_scale, down_shift);
|
||||
}
|
||||
|
||||
// Drawing a texture 1:1 onto itself without blending changes nothing on hardware, but here
|
||||
// it samples the image the render pass is writing to: undefined in Vulkan, and on tiled GPUs
|
||||
// it reads whatever the image memory last held. Crysis Remastered does this every frame for
|
||||
// its post-processing buffers (suspected cause of its map covering the whole screen).
|
||||
const auto& fb_images = framebuffer->Images();
|
||||
const bool src_is_target =
|
||||
std::find(fb_images.begin(), fb_images.begin() + framebuffer->NumImages(),
|
||||
texture.ImageHandle()) != fb_images.begin() + framebuffer->NumImages();
|
||||
if (src_is_target && src_rescaling == dst_rescaling &&
|
||||
src_region.start.x == dst_region.start.x && src_region.start.y == dst_region.start.y &&
|
||||
src_region.end.x == dst_region.end.x && src_region.end.y == dst_region.end.y &&
|
||||
maxwell3d->regs.blend.enable[0] == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
blit_image.BlitColor(framebuffer, texture.RenderTarget(), texture.ImageHandle(),
|
||||
sampler->Handle(), dst_region, src_region, src_size, scissor);
|
||||
sampler->Handle(), dst_region, src_region, src_size);
|
||||
}
|
||||
|
||||
void RasterizerVulkan::Clear(u32 layer_count) {
|
||||
|
||||
@@ -157,6 +157,20 @@ private:
|
||||
template <typename Func>
|
||||
void PrepareDraw(bool is_indexed, Func&&);
|
||||
|
||||
/// A stretch of a draw whose vertices all carry the same texture handle.
|
||||
struct AttributeHandleRun {
|
||||
u32 first;
|
||||
u32 count;
|
||||
u32 handle;
|
||||
};
|
||||
|
||||
/// Splits the current draw wherever the texture handle carried in the vertex data changes.
|
||||
void CollectAttributeHandleRuns(bool is_indexed);
|
||||
|
||||
std::vector<AttributeHandleRun> attribute_handle_runs;
|
||||
GraphicsPipeline* attribute_handle_pipeline{};
|
||||
bool split_attribute_handles{};
|
||||
|
||||
void FlushWork();
|
||||
|
||||
void UpdateDynamicStates();
|
||||
|
||||
Reference in New Issue
Block a user