mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-04-21 12:04:45 +00:00
shader_recompiler: using reserve() if possible
This commit is contained in:
parent
834e3a500e
commit
9dbe2f55b9
5 changed files with 21 additions and 1 deletions
|
@ -51,7 +51,7 @@ void TrophyViewer::PopulateTrophyWidget(QString title) {
|
|||
QDir iconsDir(iconsPath);
|
||||
QFileInfoList iconDirList = iconsDir.entryInfoList(QDir::Files | QDir::NoDotAndDotDot);
|
||||
std::vector<QImage> icons;
|
||||
|
||||
icons.reserve(iconDirList.count());
|
||||
for (const QFileInfo& iconInfo : iconDirList) {
|
||||
QImage icon =
|
||||
QImage(iconInfo.absoluteFilePath())
|
||||
|
|
|
@ -193,6 +193,7 @@ Id MakeDefaultValue(EmitContext& ctx, u32 default_value) {
|
|||
void EmitContext::DefineInputs() {
|
||||
switch (stage) {
|
||||
case Stage::Vertex: {
|
||||
ReserveInterfaces<3>(); // 3 define vars
|
||||
vertex_index = DefineVariable(U32[1], spv::BuiltIn::VertexIndex, spv::StorageClass::Input);
|
||||
base_vertex = DefineVariable(U32[1], spv::BuiltIn::BaseVertex, spv::StorageClass::Input);
|
||||
instance_id = DefineVariable(U32[1], spv::BuiltIn::InstanceIndex, spv::StorageClass::Input);
|
||||
|
@ -225,6 +226,7 @@ void EmitContext::DefineInputs() {
|
|||
break;
|
||||
}
|
||||
case Stage::Fragment:
|
||||
ReserveInterfaces<4>(); // 4 define vars
|
||||
subgroup_local_invocation_id = DefineVariable(
|
||||
U32[1], spv::BuiltIn::SubgroupLocalInvocationId, spv::StorageClass::Input);
|
||||
Decorate(subgroup_local_invocation_id, spv::Decoration::Flat);
|
||||
|
@ -251,6 +253,7 @@ void EmitContext::DefineInputs() {
|
|||
}
|
||||
break;
|
||||
case Stage::Compute:
|
||||
ReserveInterfaces<2>(); // 2 define vars
|
||||
workgroup_id = DefineVariable(U32[3], spv::BuiltIn::WorkgroupId, spv::StorageClass::Input);
|
||||
local_invocation_id =
|
||||
DefineVariable(U32[3], spv::BuiltIn::LocalInvocationId, spv::StorageClass::Input);
|
||||
|
@ -324,6 +327,9 @@ void EmitContext::DefinePushDataBlock() {
|
|||
|
||||
void EmitContext::DefineBuffers() {
|
||||
boost::container::small_vector<Id, 8> type_ids;
|
||||
type_ids.reserve(info.buffers.size());
|
||||
buffers.reserve(info.buffers.size());
|
||||
interfaces.reserve(info.buffers.size());
|
||||
for (u32 i = 0; const auto& buffer : info.buffers) {
|
||||
const auto* data_types = True(buffer.used_types & IR::Type::F32) ? &F32 : &U32;
|
||||
const Id data_type = (*data_types)[1];
|
||||
|
@ -449,6 +455,8 @@ Id ImageType(EmitContext& ctx, const ImageResource& desc, Id sampled_type) {
|
|||
}
|
||||
|
||||
void EmitContext::DefineImagesAndSamplers() {
|
||||
images.reserve(info.images.size());
|
||||
interfaces.reserve(info.images.size());
|
||||
for (const auto& image_desc : info.images) {
|
||||
const VectorIds* data_types = [&] {
|
||||
switch (image_desc.nfmt) {
|
||||
|
@ -487,6 +495,8 @@ void EmitContext::DefineImagesAndSamplers() {
|
|||
|
||||
sampler_type = TypeSampler();
|
||||
sampler_pointer_type = TypePointer(spv::StorageClass::UniformConstant, sampler_type);
|
||||
samplers.reserve(info.samplers.size());
|
||||
interfaces.reserve(info.samplers.size());
|
||||
for (const auto& samp_desc : info.samplers) {
|
||||
const Id id{AddGlobalVariable(sampler_pointer_type, spv::StorageClass::UniformConstant)};
|
||||
Decorate(id, spv::Decoration::Binding, binding);
|
||||
|
@ -535,6 +545,7 @@ void EmitContext::DefineSharedMemory() {
|
|||
AddCapability(spv::Capability::WorkgroupMemoryExplicitLayout16BitAccessKHR);
|
||||
std::tie(shared_memory_u16, shared_u16, std::ignore) = make(U16, 2);
|
||||
}
|
||||
ReserveInterfaces<3>();
|
||||
std::tie(shared_memory_u32, shared_u32, shared_memory_u32_type) = make(U32[1], 4);
|
||||
std::tie(shared_memory_u32x2, shared_u32x2, std::ignore) = make(U32[2], 8);
|
||||
std::tie(shared_memory_u32x4, shared_u32x4, std::ignore) = make(U32[4], 16);
|
||||
|
|
|
@ -124,6 +124,11 @@ public:
|
|||
return ConstantComposite(type, constituents);
|
||||
}
|
||||
|
||||
template <size_t N>
|
||||
[[nodiscard]] void ReserveInterfaces() {
|
||||
interfaces.reserve(N);
|
||||
}
|
||||
|
||||
Info& info;
|
||||
const Profile& profile;
|
||||
Stage stage{};
|
||||
|
|
|
@ -404,6 +404,7 @@ void Translator::EmitFetch(const GcnInst& inst) {
|
|||
file.WriteRaw<u8>(code, fetch_size);
|
||||
}
|
||||
|
||||
info.vs_inputs.reserve(attribs.size());
|
||||
for (const auto& attrib : attribs) {
|
||||
const IR::Attribute attr{IR::Attribute::Param0 + attrib.semantic};
|
||||
IR::VectorReg dst_reg{attrib.dest_vgpr};
|
||||
|
|
|
@ -23,6 +23,7 @@ ComputePipeline::ComputePipeline(const Instance& instance_, Scheduler& scheduler
|
|||
|
||||
u32 binding{};
|
||||
boost::container::small_vector<vk::DescriptorSetLayoutBinding, 32> bindings;
|
||||
bindings.reserve(info.buffers.size() + info.images.size() + info.samplers.size());
|
||||
for (const auto& buffer : info.buffers) {
|
||||
bindings.push_back({
|
||||
.binding = binding++,
|
||||
|
@ -140,6 +141,8 @@ bool ComputePipeline::BindResources(VideoCore::BufferCache& buffer_cache,
|
|||
i++;
|
||||
}
|
||||
|
||||
image_infos.reserve(info.images.size() + info.samplers.size());
|
||||
set_writes.reserve(info.images.size() + info.samplers.size());
|
||||
for (const auto& image_desc : info.images) {
|
||||
const auto tsharp =
|
||||
info.ReadUd<AmdGpu::Image>(image_desc.sgpr_base, image_desc.dword_offset);
|
||||
|
|
Loading…
Add table
Reference in a new issue