renderer_vulkan: Remove AttribType

* Use VertexAttributeFormat to avoid unnecessary enum casts
This commit is contained in:
GPUCode
2022-10-28 16:24:03 +03:00
parent 359f97be22
commit c028a8c7c5
5 changed files with 24 additions and 39 deletions

View File

@ -19,14 +19,12 @@ namespace Vulkan {
u32 AttribBytes(VertexAttribute attrib) {
switch (attrib.type) {
case AttribType::Float:
case Pica::PipelineRegs::VertexAttributeFormat::FLOAT:
return sizeof(float) * attrib.size;
case AttribType::Int:
return sizeof(u32) * attrib.size;
case AttribType::Short:
case Pica::PipelineRegs::VertexAttributeFormat::SHORT:
return sizeof(u16) * attrib.size;
case AttribType::Byte:
case AttribType::Ubyte:
case Pica::PipelineRegs::VertexAttributeFormat::BYTE:
case Pica::PipelineRegs::VertexAttributeFormat::UBYTE:
return sizeof(u8) * attrib.size;
}
@ -35,16 +33,14 @@ u32 AttribBytes(VertexAttribute attrib) {
vk::Format ToVkAttributeFormat(VertexAttribute attrib) {
constexpr std::array attribute_formats = {
std::array{vk::Format::eR32Sfloat, vk::Format::eR32G32Sfloat, vk::Format::eR32G32B32Sfloat,
vk::Format::eR32G32B32A32Sfloat},
std::array{vk::Format::eR32Sint, vk::Format::eR32G32Sint, vk::Format::eR32G32B32Sint,
vk::Format::eR32G32B32A32Sint},
std::array{vk::Format::eR16Sint, vk::Format::eR16G16Sint, vk::Format::eR16G16B16Sint,
vk::Format::eR16G16B16A16Sint},
std::array{vk::Format::eR8Sint, vk::Format::eR8G8Sint, vk::Format::eR8G8B8Sint,
vk::Format::eR8G8B8A8Sint},
std::array{vk::Format::eR8Uint, vk::Format::eR8G8Uint, vk::Format::eR8G8B8Uint,
vk::Format::eR8G8B8A8Uint}};
vk::Format::eR8G8B8A8Uint},
std::array{vk::Format::eR16Sint, vk::Format::eR16G16Sint, vk::Format::eR16G16B16Sint,
vk::Format::eR16G16B16A16Sint},
std::array{vk::Format::eR32Sfloat, vk::Format::eR32G32Sfloat, vk::Format::eR32G32B32Sfloat,
vk::Format::eR32G32B32A32Sfloat}};
ASSERT(attrib.size <= 4);
return attribute_formats[static_cast<u32>(attrib.type.Value())][attrib.size.Value() - 1];

View File

@ -41,8 +41,6 @@ struct DepthStencilState {
BitField<12, 3, Pica::FramebufferRegs::StencilAction> stencil_depth_fail_op;
BitField<15, 3, Pica::FramebufferRegs::CompareFunc> stencil_compare_op;
};
// These are dynamic state so keep them separate
u8 stencil_reference;
u8 stencil_compare_mask;
u8 stencil_write_mask;
@ -72,7 +70,7 @@ union VertexAttribute {
u32 value = 0;
BitField<0, 4, u32> binding;
BitField<4, 4, u32> location;
BitField<8, 3, AttribType> type;
BitField<8, 3, Pica::PipelineRegs::VertexAttributeFormat> type;
BitField<11, 3, u32> size;
BitField<14, 11, u32> offset;
};
@ -95,7 +93,7 @@ struct PipelineInfo {
RasterizationState rasterization{};
DepthStencilState depth_stencil{};
bool IsDepthWriteEnabled() const {
[[nodiscard]] bool IsDepthWriteEnabled() const noexcept {
const bool has_stencil = depth_attachment == VideoCore::PixelFormat::D24S8;
const bool depth_write =
depth_stencil.depth_test_enable && depth_stencil.depth_write_enable;

View File

@ -8,6 +8,7 @@
#include "common/microprofile.h"
#include "video_core/pica_state.h"
#include "video_core/regs_framebuffer.h"
#include "video_core/regs_pipeline.h"
#include "video_core/regs_rasterizer.h"
#include "video_core/renderer_vulkan/pica_to_vk.h"
#include "video_core/renderer_vulkan/renderer_vulkan.h"
@ -175,13 +176,6 @@ void RasterizerVulkan::SyncFixedState() {
SyncDepthWriteMask();
}
static constexpr std::array vs_attrib_types = {
AttribType::Byte, // VertexAttributeFormat::BYTE
AttribType::Ubyte, // VertexAttributeFormat::UBYTE
AttribType::Short, // VertexAttributeFormat::SHORT
AttribType::Float // VertexAttributeFormat::FLOAT
};
void RasterizerVulkan::SetupVertexArray(u32 vs_input_size, u32 vs_input_index_min,
u32 vs_input_index_max) {
auto [array_ptr, array_offset, invalidate] = vertex_buffer.Map(vs_input_size, 4);
@ -215,16 +209,14 @@ void RasterizerVulkan::SetupVertexArray(u32 vs_input_size, u32 vs_input_index_mi
offset, vertex_attributes.GetElementSizeInBytes(attribute_index));
const u32 input_reg = regs.vs.GetRegisterForAttribute(attribute_index);
const u32 attrib_format =
static_cast<u32>(vertex_attributes.GetFormat(attribute_index));
const AttribType type = vs_attrib_types[attrib_format];
const Pica::PipelineRegs::VertexAttributeFormat format =
vertex_attributes.GetFormat(attribute_index);
// Define the attribute
VertexAttribute& attribute = layout.attributes[layout.attribute_count++];
attribute.binding.Assign(layout.binding_count);
attribute.location.Assign(input_reg);
attribute.offset.Assign(offset);
attribute.type.Assign(type);
attribute.type.Assign(format);
attribute.size.Assign(size);
enable_attributes[input_reg] = true;
@ -282,7 +274,7 @@ void RasterizerVulkan::SetupVertexArray(u32 vs_input_size, u32 vs_input_index_mi
attribute.binding.Assign(layout.binding_count);
attribute.location.Assign(reg);
attribute.offset.Assign(offset);
attribute.type.Assign(AttribType::Float);
attribute.type.Assign(Pica::PipelineRegs::VertexAttributeFormat::FLOAT);
attribute.size.Assign(4);
offset += data_size;
@ -304,7 +296,7 @@ void RasterizerVulkan::SetupVertexArray(u32 vs_input_size, u32 vs_input_index_mi
attribute.binding.Assign(layout.binding_count);
attribute.location.Assign(i);
attribute.offset.Assign(0);
attribute.type.Assign(AttribType::Float);
attribute.type.Assign(Pica::PipelineRegs::VertexAttributeFormat::FLOAT);
attribute.size.Assign(4);
}
}
@ -1481,7 +1473,7 @@ void RasterizerVulkan::MakeSoftwareVertexLayout() {
attribute.binding.Assign(0);
attribute.location.Assign(i);
attribute.offset.Assign(offset);
attribute.type.Assign(AttribType::Float);
attribute.type.Assign(Pica::PipelineRegs::VertexAttributeFormat::FLOAT);
attribute.size.Assign(sizes[i]);
offset += sizes[i] * sizeof(float);
}

View File

@ -1627,14 +1627,14 @@ layout (set = 0, binding = 0, std140) uniform vs_config {
if (used_regs[i]) {
std::string_view prefix;
switch (config.state.attrib_types[i]) {
case AttribType::Float:
case Pica::PipelineRegs::VertexAttributeFormat::FLOAT:
prefix = "";
break;
case AttribType::Byte:
case AttribType::Short:
case Pica::PipelineRegs::VertexAttributeFormat::BYTE:
case Pica::PipelineRegs::VertexAttributeFormat::SHORT:
prefix = "i";
break;
case AttribType::Ubyte:
case Pica::PipelineRegs::VertexAttributeFormat::UBYTE:
prefix = "u";
break;
default:

View File

@ -8,12 +8,11 @@
#include <optional>
#include "common/hash.h"
#include "video_core/regs.h"
#include "video_core/regs_pipeline.h"
#include "video_core/shader/shader.h"
namespace Vulkan {
enum class AttribType : u32 { Float = 0, Int = 1, Short = 2, Byte = 3, Ubyte = 4 };
enum Attributes {
ATTRIBUTE_POSITION,
ATTRIBUTE_COLOR,
@ -149,7 +148,7 @@ struct PicaShaderConfigCommon {
u64 swizzle_hash;
u32 main_offset;
bool sanitize_mul;
std::array<AttribType, 16> attrib_types;
std::array<Pica::PipelineRegs::VertexAttributeFormat, 16> attrib_types;
u32 num_outputs;