mirror of
https://github.com/KytyPS5/KytyPS5.git
synced 2026-10-20 10:56:58 +02:00
graphics: size compute LDS from shader state
This commit is contained in:
@@ -972,6 +972,10 @@ uint32_t EmitStorageBufferElementPointer(EmitterState& state, const IR::MemoryIn
|
||||
|
||||
uint32_t EmitLdsElementPointer(EmitterState& state, uint32_t index);
|
||||
|
||||
uint32_t LdsDwordCount(const EmitterState& state);
|
||||
|
||||
uint32_t EmitLdsElementInBounds(EmitterState& state, uint32_t index);
|
||||
|
||||
uint32_t EmitGdsElementInBounds(EmitterState& state, uint32_t index);
|
||||
|
||||
uint32_t EmitGdsElementPointer(EmitterState& state, uint32_t index);
|
||||
|
||||
@@ -495,11 +495,14 @@ uint32_t EmitLdsElementPointer(EmitterState& state, uint32_t index) {
|
||||
return pointer;
|
||||
}
|
||||
|
||||
uint32_t LdsDwordCount(const EmitterState& state) {
|
||||
return state.needs_function_lds ? 8192u : state.compute_input_info->lds_size_dwords;
|
||||
}
|
||||
|
||||
uint32_t EmitLdsElementInBounds(EmitterState& state, uint32_t index) {
|
||||
const auto in_bounds = state.builder.AllocateId();
|
||||
const auto dwords = state.needs_function_lds ? 8192u : 1024u;
|
||||
state.builder.AddFunction(
|
||||
{OpULessThan, state.bool_type, in_bounds, index, ConstantU32(state, dwords)});
|
||||
{OpULessThan, state.bool_type, in_bounds, index, ConstantU32(state, LdsDwordCount(state))});
|
||||
return in_bounds;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "graphics/shader/recompiler/backend/spirv/spirvEmitterInternal.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace Libs::Graphics::ShaderRecompiler::Spirv::Emitter {
|
||||
|
||||
const IR::DescriptorBinding* DescriptorBinding(const EmitterState& state,
|
||||
@@ -736,7 +738,8 @@ void EmitHeaderAndTypes(EmitterState& state) {
|
||||
if (state.stage == ShaderType::Compute || state.needs_function_lds) {
|
||||
const auto storage_class =
|
||||
state.needs_function_lds ? StorageClassFunction : StorageClassWorkgroup;
|
||||
const auto lds_size = ConstantU32(state, state.needs_function_lds ? 8192u : 1024u);
|
||||
const auto lds_dwords = std::max(LdsDwordCount(state), 1u);
|
||||
const auto lds_size = ConstantU32(state, lds_dwords);
|
||||
state.builder.AddType({OpTypeArray, state.lds_array_type, state.uint_type, lds_size});
|
||||
state.builder.AddType(
|
||||
{OpTypePointer, state.ptr_workgroup_array, storage_class, state.lds_array_type});
|
||||
|
||||
@@ -158,7 +158,7 @@ uint32_t DwordIndex(ValueEmitContext& ctx, const IR::Inst& inst, const IR::Memor
|
||||
|
||||
uint32_t InBounds(ValueEmitContext& ctx, const IR::MemoryInfo& mem, uint32_t index, uint32_t pc) {
|
||||
if (mem.kind == IR::ResourceKind::Lds) {
|
||||
return 0;
|
||||
return EmitLdsElementInBounds(ctx.state, index);
|
||||
}
|
||||
if (mem.kind == IR::ResourceKind::Gds) {
|
||||
return EmitGdsElementInBounds(ctx.state, index);
|
||||
@@ -546,7 +546,8 @@ uint32_t AppendConsume(ValueEmitContext& ctx, const IR::Inst& inst, bool gds, bo
|
||||
ConstantU32(state, ScopeSubgroup), ballot});
|
||||
const auto is_first =
|
||||
Binary(state, OpIEqual, state.bool_type, EmitSubgroupLocalInvocationId(state), first);
|
||||
const auto storage_bounds = gds ? EmitGdsElementInBounds(state, index) : 0u;
|
||||
const auto storage_bounds =
|
||||
gds ? EmitGdsElementInBounds(state, index) : EmitLdsElementInBounds(state, index);
|
||||
const auto m0_bounds =
|
||||
gds ? Binary(state, OpINotEqual, state.bool_type, size, ConstantU32(state, 0))
|
||||
: Binary(state, OpULessThan, state.bool_type,
|
||||
|
||||
@@ -894,15 +894,16 @@ static void ShaderGetStaticInputInfoCS(const HW::ComputeShaderInfo& regs,
|
||||
ShaderComputeInputInfo& info) {
|
||||
info = {};
|
||||
|
||||
info.threads_num[0] = regs.cs_regs.num_thread_x;
|
||||
info.threads_num[1] = regs.cs_regs.num_thread_y;
|
||||
info.threads_num[2] = regs.cs_regs.num_thread_z;
|
||||
info.group_id[0] = regs.cs_regs.tgid_x_en != 0;
|
||||
info.group_id[1] = regs.cs_regs.tgid_y_en != 0;
|
||||
info.group_id[2] = regs.cs_regs.tgid_z_en != 0;
|
||||
info.wave_size = regs.cs_regs.wave_size;
|
||||
info.thread_ids_num = regs.cs_regs.tidig_comp_cnt + 1;
|
||||
info.tg_size_en = regs.cs_regs.tg_size_en != 0;
|
||||
info.threads_num[0] = regs.cs_regs.num_thread_x;
|
||||
info.threads_num[1] = regs.cs_regs.num_thread_y;
|
||||
info.threads_num[2] = regs.cs_regs.num_thread_z;
|
||||
info.lds_size_dwords = static_cast<uint32_t>(regs.cs_regs.lds_size) * 128u;
|
||||
info.group_id[0] = regs.cs_regs.tgid_x_en != 0;
|
||||
info.group_id[1] = regs.cs_regs.tgid_y_en != 0;
|
||||
info.group_id[2] = regs.cs_regs.tgid_z_en != 0;
|
||||
info.wave_size = regs.cs_regs.wave_size;
|
||||
info.thread_ids_num = regs.cs_regs.tidig_comp_cnt + 1;
|
||||
info.tg_size_en = regs.cs_regs.tg_size_en != 0;
|
||||
|
||||
info.workgroup_register = regs.cs_regs.user_sgpr;
|
||||
}
|
||||
@@ -1330,10 +1331,12 @@ void ShaderDbgDumpInputInfo(const ShaderComputeInputInfo& info) {
|
||||
LOGF("\t workgroup_register = %d\n"
|
||||
"\t thread_ids_num = %d\n"
|
||||
"\t wave_size = %u\n"
|
||||
"\t lds_size_dwords = %u\n"
|
||||
"\t threads_num = {%u, %u, %u}\n"
|
||||
"\t tg_size_en = %s\n",
|
||||
info.workgroup_register, info.thread_ids_num, info.wave_size, info.threads_num[0],
|
||||
info.threads_num[1], info.threads_num[2], info.tg_size_en ? "true" : "false");
|
||||
info.workgroup_register, info.thread_ids_num, info.wave_size, info.lds_size_dwords,
|
||||
info.threads_num[0], info.threads_num[1], info.threads_num[2],
|
||||
info.tg_size_en ? "true" : "false");
|
||||
LOGF("\t threadgroup_id = {%s, %s, %s}\n", info.group_id[0] ? "true" : "false",
|
||||
info.group_id[1] ? "true" : "false", info.group_id[2] ? "true" : "false");
|
||||
}
|
||||
@@ -1723,6 +1726,7 @@ ShaderId ShaderGetIdCS(const HW::ComputeShaderInfo& regs, const ShaderComputeInp
|
||||
ret.ids.push_back(input_info.workgroup_register);
|
||||
ret.ids.push_back(input_info.wave_size);
|
||||
ret.ids.push_back(input_info.thread_ids_num);
|
||||
ret.ids.push_back(input_info.lds_size_dwords);
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
ret.ids.push_back(input_info.threads_num[i]);
|
||||
|
||||
@@ -91,6 +91,7 @@ struct ShaderVertexInputInfo {
|
||||
struct ShaderComputeInputInfo {
|
||||
uint32_t threads_num[3] = {0, 0, 0};
|
||||
uint32_t dispatch_threads_num[3] = {0, 0, 0};
|
||||
uint32_t lds_size_dwords = 0;
|
||||
bool group_id[3] = {false, false, false};
|
||||
bool dispatch_thread_dimensions = false;
|
||||
uint32_t wave_size = 64;
|
||||
|
||||
Reference in New Issue
Block a user