early-access version 4037

This commit is contained in:
pineappleEA 2023-12-27 05:56:25 +01:00
parent 9cae9d0484
commit b89b2c20a4
9 changed files with 59 additions and 23 deletions

View file

@ -1,7 +1,7 @@
yuzu emulator early access yuzu emulator early access
============= =============
This is the source code for early-access 4036. This is the source code for early-access 4037.
## Legal Notice ## Legal Notice

View file

@ -74,6 +74,11 @@ std::optional<OutAttr> OutputAttrPointer(EmitContext& ctx, IR::Attribute attr) {
case IR::Attribute::ClipDistance7: { case IR::Attribute::ClipDistance7: {
const u32 base{static_cast<u32>(IR::Attribute::ClipDistance0)}; const u32 base{static_cast<u32>(IR::Attribute::ClipDistance0)};
const u32 index{static_cast<u32>(attr) - base}; const u32 index{static_cast<u32>(attr) - base};
if (index >= ctx.profile.max_user_clip_distances) {
LOG_WARNING(Shader, "Ignoring clip distance store {} >= {} supported", index,
ctx.profile.max_user_clip_distances);
return std::nullopt;
}
const Id clip_num{ctx.Const(index)}; const Id clip_num{ctx.Const(index)};
return OutputAccessChain(ctx, ctx.output_f32, ctx.clip_distances, clip_num); return OutputAccessChain(ctx, ctx.output_f32, ctx.clip_distances, clip_num);
} }

View file

@ -96,9 +96,9 @@ Id ImageType(EmitContext& ctx, const ImageDescriptor& desc, Id sampled_type) {
} }
Id DefineVariable(EmitContext& ctx, Id type, std::optional<spv::BuiltIn> builtin, Id DefineVariable(EmitContext& ctx, Id type, std::optional<spv::BuiltIn> builtin,
spv::StorageClass storage_class) { spv::StorageClass storage_class, std::optional<Id> initializer = std::nullopt) {
const Id pointer_type{ctx.TypePointer(storage_class, type)}; const Id pointer_type{ctx.TypePointer(storage_class, type)};
const Id id{ctx.AddGlobalVariable(pointer_type, storage_class)}; const Id id{ctx.AddGlobalVariable(pointer_type, storage_class, initializer)};
if (builtin) { if (builtin) {
ctx.Decorate(id, spv::Decoration::BuiltIn, *builtin); ctx.Decorate(id, spv::Decoration::BuiltIn, *builtin);
} }
@ -144,11 +144,12 @@ Id DefineInput(EmitContext& ctx, Id type, bool per_invocation,
} }
Id DefineOutput(EmitContext& ctx, Id type, std::optional<u32> invocations, Id DefineOutput(EmitContext& ctx, Id type, std::optional<u32> invocations,
std::optional<spv::BuiltIn> builtin = std::nullopt) { std::optional<spv::BuiltIn> builtin = std::nullopt,
std::optional<Id> initializer = std::nullopt) {
if (invocations && ctx.stage == Stage::TessellationControl) { if (invocations && ctx.stage == Stage::TessellationControl) {
type = ctx.TypeArray(type, ctx.Const(*invocations)); type = ctx.TypeArray(type, ctx.Const(*invocations));
} }
return DefineVariable(ctx, type, builtin, spv::StorageClass::Output); return DefineVariable(ctx, type, builtin, spv::StorageClass::Output, initializer);
} }
void DefineGenericOutput(EmitContext& ctx, size_t index, std::optional<u32> invocations) { void DefineGenericOutput(EmitContext& ctx, size_t index, std::optional<u32> invocations) {
@ -811,11 +812,15 @@ void EmitContext::DefineAttributeMemAccess(const Info& info) {
labels.push_back(OpLabel()); labels.push_back(OpLabel());
} }
if (info.stores.ClipDistances()) { if (info.stores.ClipDistances()) {
if (profile.max_user_clip_distances >= 4) {
literals.push_back(static_cast<u32>(IR::Attribute::ClipDistance0) >> 2); literals.push_back(static_cast<u32>(IR::Attribute::ClipDistance0) >> 2);
labels.push_back(OpLabel()); labels.push_back(OpLabel());
}
if (profile.max_user_clip_distances >= 8) {
literals.push_back(static_cast<u32>(IR::Attribute::ClipDistance4) >> 2); literals.push_back(static_cast<u32>(IR::Attribute::ClipDistance4) >> 2);
labels.push_back(OpLabel()); labels.push_back(OpLabel());
} }
}
OpSelectionMerge(end_block, spv::SelectionControlMask::MaskNone); OpSelectionMerge(end_block, spv::SelectionControlMask::MaskNone);
OpSwitch(compare_index, default_label, literals, labels); OpSwitch(compare_index, default_label, literals, labels);
AddLabel(default_label); AddLabel(default_label);
@ -843,18 +848,22 @@ void EmitContext::DefineAttributeMemAccess(const Info& info) {
++label_index; ++label_index;
} }
if (info.stores.ClipDistances()) { if (info.stores.ClipDistances()) {
if (profile.max_user_clip_distances >= 4) {
AddLabel(labels[label_index]); AddLabel(labels[label_index]);
const Id pointer{OpAccessChain(output_f32, clip_distances, masked_index)}; const Id pointer{OpAccessChain(output_f32, clip_distances, masked_index)};
OpStore(pointer, store_value); OpStore(pointer, store_value);
OpReturn(); OpReturn();
++label_index; ++label_index;
}
if (profile.max_user_clip_distances >= 8) {
AddLabel(labels[label_index]); AddLabel(labels[label_index]);
const Id fixed_index{OpIAdd(U32[1], masked_index, Const(4U))}; const Id fixed_index{OpIAdd(U32[1], masked_index, Const(4U))};
const Id pointer2{OpAccessChain(output_f32, clip_distances, fixed_index)}; const Id pointer{OpAccessChain(output_f32, clip_distances, fixed_index)};
OpStore(pointer2, store_value); OpStore(pointer, store_value);
OpReturn(); OpReturn();
++label_index; ++label_index;
} }
}
AddLabel(end_block); AddLabel(end_block);
OpUnreachable(); OpUnreachable();
OpFunctionEnd(); OpFunctionEnd();
@ -1532,8 +1541,16 @@ void EmitContext::DefineOutputs(const IR::Program& program) {
if (stage == Stage::Fragment) { if (stage == Stage::Fragment) {
throw NotImplementedException("Storing ClipDistance in fragment stage"); throw NotImplementedException("Storing ClipDistance in fragment stage");
} }
const Id type{TypeArray(F32[1], Const(8U))}; if (profile.max_user_clip_distances > 0) {
clip_distances = DefineOutput(*this, type, invocations, spv::BuiltIn::ClipDistance); const u32 used{std::min(profile.max_user_clip_distances, 8u)};
const std::array<Id, 8> zero{f32_zero_value, f32_zero_value, f32_zero_value,
f32_zero_value, f32_zero_value, f32_zero_value,
f32_zero_value, f32_zero_value};
const Id type{TypeArray(F32[1], Const(used))};
const Id initializer{ConstantComposite(type, std::span(zero).subspan(0, used))};
clip_distances =
DefineOutput(*this, type, invocations, spv::BuiltIn::ClipDistance, initializer);
}
} }
if (info.stores[IR::Attribute::Layer] && if (info.stores[IR::Attribute::Layer] &&
(profile.support_viewport_index_layer_non_geometry || stage == Stage::Geometry)) { (profile.support_viewport_index_layer_non_geometry || stage == Stage::Geometry)) {

View file

@ -913,7 +913,11 @@ void GatherInfoFromHeader(Environment& env, Info& info) {
} }
for (size_t index = 0; index < 8; ++index) { for (size_t index = 0; index < 8; ++index) {
const u16 mask{header.vtg.omap_systemc.clip_distances}; const u16 mask{header.vtg.omap_systemc.clip_distances};
info.stores.Set(IR::Attribute::ClipDistance0 + index, ((mask >> index) & 1) != 0); const bool used{((mask >> index) & 1) != 0};
info.stores.Set(IR::Attribute::ClipDistance0 + index, used);
if (used) {
info.used_clip_distances = static_cast<u32>(index) + 1;
}
} }
info.stores.Set(IR::Attribute::PrimitiveId, info.stores.Set(IR::Attribute::PrimitiveId,
header.vtg.omap_systemb.primitive_array_id != 0); header.vtg.omap_systemb.primitive_array_id != 0);

View file

@ -87,6 +87,8 @@ struct Profile {
bool has_broken_robust{}; bool has_broken_robust{};
u64 min_ssbo_alignment{}; u64 min_ssbo_alignment{};
u32 max_user_clip_distances{};
}; };
} // namespace Shader } // namespace Shader

View file

@ -324,6 +324,8 @@ struct Info {
bool requires_layer_emulation{}; bool requires_layer_emulation{};
IR::Attribute emulated_layer{}; IR::Attribute emulated_layer{};
u32 used_clip_distances{};
boost::container::static_vector<ConstantBufferDescriptor, MAX_CBUFS> boost::container::static_vector<ConstantBufferDescriptor, MAX_CBUFS>
constant_buffer_descriptors; constant_buffer_descriptors;
boost::container::static_vector<StorageBufferDescriptor, MAX_SSBOS> storage_buffers_descriptors; boost::container::static_vector<StorageBufferDescriptor, MAX_SSBOS> storage_buffers_descriptors;

View file

@ -233,6 +233,7 @@ ShaderCache::ShaderCache(RasterizerOpenGL& rasterizer_, Core::Frontend::EmuWindo
.ignore_nan_fp_comparisons = true, .ignore_nan_fp_comparisons = true,
.gl_max_compute_smem_size = device.GetMaxComputeSharedMemorySize(), .gl_max_compute_smem_size = device.GetMaxComputeSharedMemorySize(),
.min_ssbo_alignment = device.GetShaderStorageBufferAlignment(), .min_ssbo_alignment = device.GetShaderStorageBufferAlignment(),
.max_user_clip_distances = 8,
}, },
host_info{ host_info{
.support_float64 = true, .support_float64 = true,

View file

@ -374,6 +374,7 @@ PipelineCache::PipelineCache(RasterizerVulkan& rasterizer_, const Device& device
.has_broken_robust = .has_broken_robust =
device.IsNvidia() && device.GetNvidiaArch() <= NvidiaArchitecture::Arch_Pascal, device.IsNvidia() && device.GetNvidiaArch() <= NvidiaArchitecture::Arch_Pascal,
.min_ssbo_alignment = device.GetStorageBufferAlignment(), .min_ssbo_alignment = device.GetStorageBufferAlignment(),
.max_user_clip_distances = device.GetMaxUserClipDistances(),
}; };
host_info = Shader::HostTranslateInfo{ host_info = Shader::HostTranslateInfo{

View file

@ -651,6 +651,10 @@ public:
return properties.properties.limits.maxViewports; return properties.properties.limits.maxViewports;
} }
u32 GetMaxUserClipDistances() const {
return properties.properties.limits.maxClipDistances;
}
bool SupportsConditionalBarriers() const { bool SupportsConditionalBarriers() const {
return supports_conditional_barriers; return supports_conditional_barriers;
} }