mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-05-23 11:55:00 +00:00
renderer_vulkan: Parse fetch shader per-pipeline (#1656)
* shader_recompiler: Read image format info directly from sharps instead of storing in shader info. * renderer_vulkan: Parse fetch shader per-pipeline * Few minor fixes. * shader_recompiler: Specialize on vertex attribute number types. * shader_recompiler: Move GetDrawOffsets to fetch shader
This commit is contained in:
parent
74b091fd08
commit
920acb8d8b
21 changed files with 286 additions and 182 deletions
|
@ -4,6 +4,7 @@
|
|||
#include "common/assert.h"
|
||||
#include "common/div_ceil.h"
|
||||
#include "shader_recompiler/backend/spirv/spirv_emit_context.h"
|
||||
#include "shader_recompiler/frontend/fetch_shader.h"
|
||||
#include "shader_recompiler/ir/passes/srt.h"
|
||||
#include "video_core/amdgpu/types.h"
|
||||
|
||||
|
@ -155,18 +156,12 @@ void EmitContext::DefineInterfaces() {
|
|||
}
|
||||
|
||||
const VectorIds& GetAttributeType(EmitContext& ctx, AmdGpu::NumberFormat fmt) {
|
||||
switch (fmt) {
|
||||
case AmdGpu::NumberFormat::Float:
|
||||
case AmdGpu::NumberFormat::Unorm:
|
||||
case AmdGpu::NumberFormat::Snorm:
|
||||
case AmdGpu::NumberFormat::SnormNz:
|
||||
case AmdGpu::NumberFormat::Sscaled:
|
||||
case AmdGpu::NumberFormat::Uscaled:
|
||||
case AmdGpu::NumberFormat::Srgb:
|
||||
switch (GetNumberClass(fmt)) {
|
||||
case AmdGpu::NumberClass::Float:
|
||||
return ctx.F32;
|
||||
case AmdGpu::NumberFormat::Sint:
|
||||
case AmdGpu::NumberClass::Sint:
|
||||
return ctx.S32;
|
||||
case AmdGpu::NumberFormat::Uint:
|
||||
case AmdGpu::NumberClass::Uint:
|
||||
return ctx.U32;
|
||||
default:
|
||||
break;
|
||||
|
@ -176,18 +171,12 @@ const VectorIds& GetAttributeType(EmitContext& ctx, AmdGpu::NumberFormat fmt) {
|
|||
|
||||
EmitContext::SpirvAttribute EmitContext::GetAttributeInfo(AmdGpu::NumberFormat fmt, Id id,
|
||||
u32 num_components, bool output) {
|
||||
switch (fmt) {
|
||||
case AmdGpu::NumberFormat::Float:
|
||||
case AmdGpu::NumberFormat::Unorm:
|
||||
case AmdGpu::NumberFormat::Snorm:
|
||||
case AmdGpu::NumberFormat::SnormNz:
|
||||
case AmdGpu::NumberFormat::Sscaled:
|
||||
case AmdGpu::NumberFormat::Uscaled:
|
||||
case AmdGpu::NumberFormat::Srgb:
|
||||
switch (GetNumberClass(fmt)) {
|
||||
case AmdGpu::NumberClass::Float:
|
||||
return {id, output ? output_f32 : input_f32, F32[1], num_components, false};
|
||||
case AmdGpu::NumberFormat::Uint:
|
||||
case AmdGpu::NumberClass::Uint:
|
||||
return {id, output ? output_u32 : input_u32, U32[1], num_components, true};
|
||||
case AmdGpu::NumberFormat::Sint:
|
||||
case AmdGpu::NumberClass::Sint:
|
||||
return {id, output ? output_s32 : input_s32, S32[1], num_components, true};
|
||||
default:
|
||||
break;
|
||||
|
@ -280,33 +269,42 @@ void EmitContext::DefineInputs() {
|
|||
base_vertex = DefineVariable(U32[1], spv::BuiltIn::BaseVertex, spv::StorageClass::Input);
|
||||
instance_id = DefineVariable(U32[1], spv::BuiltIn::InstanceIndex, spv::StorageClass::Input);
|
||||
|
||||
for (const auto& input : info.vs_inputs) {
|
||||
ASSERT(input.binding < IR::NumParams);
|
||||
const Id type{GetAttributeType(*this, input.fmt)[4]};
|
||||
if (input.instance_step_rate == Info::VsInput::InstanceIdType::OverStepRate0 ||
|
||||
input.instance_step_rate == Info::VsInput::InstanceIdType::OverStepRate1) {
|
||||
|
||||
const auto fetch_shader = Gcn::ParseFetchShader(info);
|
||||
if (!fetch_shader) {
|
||||
break;
|
||||
}
|
||||
for (const auto& attrib : fetch_shader->attributes) {
|
||||
ASSERT(attrib.semantic < IR::NumParams);
|
||||
const auto sharp = attrib.GetSharp(info);
|
||||
const Id type{GetAttributeType(*this, sharp.GetNumberFmt())[4]};
|
||||
if (attrib.UsesStepRates()) {
|
||||
const u32 rate_idx =
|
||||
input.instance_step_rate == Info::VsInput::InstanceIdType::OverStepRate0 ? 0
|
||||
: 1;
|
||||
attrib.GetStepRate() == Gcn::VertexAttribute::InstanceIdType::OverStepRate0 ? 0
|
||||
: 1;
|
||||
const u32 num_components = AmdGpu::NumComponents(sharp.GetDataFmt());
|
||||
const auto buffer =
|
||||
std::ranges::find_if(info.buffers, [&attrib](const auto& buffer) {
|
||||
return buffer.instance_attrib == attrib.semantic;
|
||||
});
|
||||
// Note that we pass index rather than Id
|
||||
input_params[input.binding] = SpirvAttribute{
|
||||
input_params[attrib.semantic] = SpirvAttribute{
|
||||
.id = rate_idx,
|
||||
.pointer_type = input_u32,
|
||||
.component_type = U32[1],
|
||||
.num_components = input.num_components,
|
||||
.num_components = std::min<u16>(attrib.num_elements, num_components),
|
||||
.is_integer = true,
|
||||
.is_loaded = false,
|
||||
.buffer_handle = input.instance_data_buf,
|
||||
.buffer_handle = int(buffer - info.buffers.begin()),
|
||||
};
|
||||
} else {
|
||||
Id id{DefineInput(type, input.binding)};
|
||||
if (input.instance_step_rate == Info::VsInput::InstanceIdType::Plain) {
|
||||
Name(id, fmt::format("vs_instance_attr{}", input.binding));
|
||||
Id id{DefineInput(type, attrib.semantic)};
|
||||
if (attrib.GetStepRate() == Gcn::VertexAttribute::InstanceIdType::Plain) {
|
||||
Name(id, fmt::format("vs_instance_attr{}", attrib.semantic));
|
||||
} else {
|
||||
Name(id, fmt::format("vs_in_attr{}", input.binding));
|
||||
Name(id, fmt::format("vs_in_attr{}", attrib.semantic));
|
||||
}
|
||||
input_params[input.binding] = GetAttributeInfo(input.fmt, id, 4, false);
|
||||
input_params[attrib.semantic] =
|
||||
GetAttributeInfo(sharp.GetNumberFmt(), id, 4, false);
|
||||
interfaces.push_back(id);
|
||||
}
|
||||
}
|
||||
|
@ -553,9 +551,10 @@ void EmitContext::DefineBuffers() {
|
|||
|
||||
void EmitContext::DefineTextureBuffers() {
|
||||
for (const auto& desc : info.texture_buffers) {
|
||||
const bool is_integer =
|
||||
desc.nfmt == AmdGpu::NumberFormat::Uint || desc.nfmt == AmdGpu::NumberFormat::Sint;
|
||||
const VectorIds& sampled_type{GetAttributeType(*this, desc.nfmt)};
|
||||
const auto sharp = desc.GetSharp(info);
|
||||
const auto nfmt = sharp.GetNumberFmt();
|
||||
const bool is_integer = AmdGpu::IsInteger(nfmt);
|
||||
const VectorIds& sampled_type{GetAttributeType(*this, nfmt)};
|
||||
const u32 sampled = desc.is_written ? 2 : 1;
|
||||
const Id image_type{TypeImage(sampled_type[1], spv::Dim::Buffer, false, false, false,
|
||||
sampled, spv::ImageFormat::Unknown)};
|
||||
|
@ -650,10 +649,11 @@ spv::ImageFormat GetFormat(const AmdGpu::Image& image) {
|
|||
}
|
||||
|
||||
Id ImageType(EmitContext& ctx, const ImageResource& desc, Id sampled_type) {
|
||||
const auto image = ctx.info.ReadUdSharp<AmdGpu::Image>(desc.sharp_idx);
|
||||
const auto image = desc.GetSharp(ctx.info);
|
||||
const auto format = desc.is_atomic ? GetFormat(image) : spv::ImageFormat::Unknown;
|
||||
const auto type = image.GetBoundType();
|
||||
const u32 sampled = desc.is_storage ? 2 : 1;
|
||||
switch (desc.type) {
|
||||
switch (type) {
|
||||
case AmdGpu::ImageType::Color1D:
|
||||
return ctx.TypeImage(sampled_type, spv::Dim::Dim1D, false, false, false, sampled, format);
|
||||
case AmdGpu::ImageType::Color1DArray:
|
||||
|
@ -672,14 +672,15 @@ Id ImageType(EmitContext& ctx, const ImageResource& desc, Id sampled_type) {
|
|||
default:
|
||||
break;
|
||||
}
|
||||
throw InvalidArgument("Invalid texture type {}", desc.type);
|
||||
throw InvalidArgument("Invalid texture type {}", type);
|
||||
}
|
||||
|
||||
void EmitContext::DefineImagesAndSamplers() {
|
||||
for (const auto& image_desc : info.images) {
|
||||
const bool is_integer = image_desc.nfmt == AmdGpu::NumberFormat::Uint ||
|
||||
image_desc.nfmt == AmdGpu::NumberFormat::Sint;
|
||||
const VectorIds& data_types = GetAttributeType(*this, image_desc.nfmt);
|
||||
const auto sharp = image_desc.GetSharp(info);
|
||||
const auto nfmt = sharp.GetNumberFmt();
|
||||
const bool is_integer = AmdGpu::IsInteger(nfmt);
|
||||
const VectorIds& data_types = GetAttributeType(*this, nfmt);
|
||||
const Id sampled_type = data_types[1];
|
||||
const Id image_type{ImageType(*this, image_desc, sampled_type)};
|
||||
const Id pointer_type{TypePointer(spv::StorageClass::UniformConstant, image_type)};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue