mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-07-13 05:05:57 +00:00
shader_recompiler: Reduce cases where shared memory to buffer pass is needed. (#3082)
Some checks are pending
Build and Release / reuse (push) Waiting to run
Build and Release / clang-format (push) Waiting to run
Build and Release / get-info (push) Waiting to run
Build and Release / windows-sdl (push) Blocked by required conditions
Build and Release / windows-qt (push) Blocked by required conditions
Build and Release / macos-sdl (push) Blocked by required conditions
Build and Release / macos-qt (push) Blocked by required conditions
Build and Release / linux-sdl (push) Blocked by required conditions
Build and Release / linux-qt (push) Blocked by required conditions
Build and Release / linux-sdl-gcc (push) Blocked by required conditions
Build and Release / linux-qt-gcc (push) Blocked by required conditions
Build and Release / pre-release (push) Blocked by required conditions
Some checks are pending
Build and Release / reuse (push) Waiting to run
Build and Release / clang-format (push) Waiting to run
Build and Release / get-info (push) Waiting to run
Build and Release / windows-sdl (push) Blocked by required conditions
Build and Release / windows-qt (push) Blocked by required conditions
Build and Release / macos-sdl (push) Blocked by required conditions
Build and Release / macos-qt (push) Blocked by required conditions
Build and Release / linux-sdl (push) Blocked by required conditions
Build and Release / linux-qt (push) Blocked by required conditions
Build and Release / linux-sdl-gcc (push) Blocked by required conditions
Build and Release / linux-qt-gcc (push) Blocked by required conditions
Build and Release / pre-release (push) Blocked by required conditions
This commit is contained in:
parent
69a50fa713
commit
c71dc740e2
9 changed files with 232 additions and 49 deletions
|
@ -303,7 +303,8 @@ void SetupCapabilities(const Info& info, const Profile& profile, EmitContext& ct
|
|||
ctx.AddCapability(spv::Capability::PhysicalStorageBufferAddresses);
|
||||
ctx.AddExtension("SPV_KHR_physical_storage_buffer");
|
||||
}
|
||||
if (info.uses_shared && profile.supports_workgroup_explicit_memory_layout) {
|
||||
const auto shared_type_count = std::popcount(static_cast<u32>(info.shared_types));
|
||||
if (shared_type_count > 1 && profile.supports_workgroup_explicit_memory_layout) {
|
||||
ctx.AddExtension("SPV_KHR_workgroup_memory_explicit_layout");
|
||||
ctx.AddCapability(spv::Capability::WorkgroupMemoryExplicitLayoutKHR);
|
||||
ctx.AddCapability(spv::Capability::WorkgroupMemoryExplicitLayout16BitAccessKHR);
|
||||
|
|
|
@ -979,32 +979,46 @@ void EmitContext::DefineImagesAndSamplers() {
|
|||
}
|
||||
|
||||
void EmitContext::DefineSharedMemory() {
|
||||
if (!info.uses_shared) {
|
||||
const auto num_types = std::popcount(static_cast<u32>(info.shared_types));
|
||||
if (num_types == 0) {
|
||||
return;
|
||||
}
|
||||
ASSERT(info.stage == Stage::Compute);
|
||||
const u32 shared_memory_size = runtime_info.cs_info.shared_memory_size;
|
||||
|
||||
const auto make_type = [&](Id element_type, u32 element_size) {
|
||||
const auto make_type = [&](IR::Type type, Id element_type, u32 element_size,
|
||||
std::string_view name) {
|
||||
if (False(info.shared_types & type)) {
|
||||
// Skip unused shared memory types.
|
||||
return std::make_tuple(Id{}, Id{}, Id{});
|
||||
}
|
||||
|
||||
const u32 num_elements{Common::DivCeil(shared_memory_size, element_size)};
|
||||
const Id array_type{TypeArray(element_type, ConstU32(num_elements))};
|
||||
Decorate(array_type, spv::Decoration::ArrayStride, element_size);
|
||||
|
||||
const Id struct_type{TypeStruct(array_type)};
|
||||
MemberDecorate(struct_type, 0u, spv::Decoration::Offset, 0u);
|
||||
Decorate(struct_type, spv::Decoration::Block);
|
||||
|
||||
const Id pointer = TypePointer(spv::StorageClass::Workgroup, struct_type);
|
||||
const Id element_pointer = TypePointer(spv::StorageClass::Workgroup, element_type);
|
||||
const Id variable = AddGlobalVariable(pointer, spv::StorageClass::Workgroup);
|
||||
Decorate(variable, spv::Decoration::Aliased);
|
||||
Name(variable, name);
|
||||
interfaces.push_back(variable);
|
||||
|
||||
if (num_types > 1) {
|
||||
Decorate(struct_type, spv::Decoration::Block);
|
||||
Decorate(variable, spv::Decoration::Aliased);
|
||||
}
|
||||
|
||||
return std::make_tuple(variable, element_pointer, pointer);
|
||||
};
|
||||
std::tie(shared_memory_u16, shared_u16, shared_memory_u16_type) = make_type(U16, 2u);
|
||||
std::tie(shared_memory_u32, shared_u32, shared_memory_u32_type) = make_type(U32[1], 4u);
|
||||
std::tie(shared_memory_u64, shared_u64, shared_memory_u64_type) = make_type(U64, 8u);
|
||||
std::tie(shared_memory_u16, shared_u16, shared_memory_u16_type) =
|
||||
make_type(IR::Type::U16, U16, 2u, "shared_mem_u16");
|
||||
std::tie(shared_memory_u32, shared_u32, shared_memory_u32_type) =
|
||||
make_type(IR::Type::U32, U32[1], 4u, "shared_mem_u32");
|
||||
std::tie(shared_memory_u64, shared_u64, shared_memory_u64_type) =
|
||||
make_type(IR::Type::U64, U64, 8u, "shared_mem_u64");
|
||||
}
|
||||
|
||||
Id EmitContext::DefineFloat32ToUfloatM5(u32 mantissa_bits, const std::string_view name) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue