Merge pull request #3930 from ReinUsesLisp/animal-borders

vk_rasterizer: Implement constant attributes
This commit is contained in:
bunnei 2020-05-31 18:40:17 -04:00 committed by GitHub
commit e68ee43a1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 17 deletions

View File

@ -312,7 +312,9 @@ VKPipelineCache::DecompileShaders(const GraphicsPipelineCacheKey& key) {
ASSERT(point_size != 0.0f); ASSERT(point_size != 0.0f);
} }
for (std::size_t i = 0; i < Maxwell::NumVertexAttributes; ++i) { for (std::size_t i = 0; i < Maxwell::NumVertexAttributes; ++i) {
specialization.attribute_types[i] = fixed_state.vertex_input.attributes[i].Type(); const auto& attribute = fixed_state.vertex_input.attributes[i];
specialization.enabled_attributes[i] = attribute.enabled.Value() != 0;
specialization.attribute_types[i] = attribute.Type();
} }
specialization.ndc_minus_one_to_one = fixed_state.rasterizer.ndc_minus_one_to_one; specialization.ndc_minus_one_to_one = fixed_state.rasterizer.ndc_minus_one_to_one;

View File

@ -877,14 +877,10 @@ void RasterizerVulkan::SetupVertexArrays(FixedPipelineState::VertexInput& vertex
for (std::size_t index = 0; index < Maxwell::NumVertexAttributes; ++index) { for (std::size_t index = 0; index < Maxwell::NumVertexAttributes; ++index) {
const auto& attrib = regs.vertex_attrib_format[index]; const auto& attrib = regs.vertex_attrib_format[index];
if (!attrib.IsValid()) { if (attrib.IsConstant()) {
vertex_input.SetAttribute(index, false, 0, 0, {}, {}); vertex_input.SetAttribute(index, false, 0, 0, {}, {});
continue; continue;
} }
[[maybe_unused]] const auto& buffer = regs.vertex_array[attrib.buffer];
ASSERT(buffer.IsEnabled());
vertex_input.SetAttribute(index, true, attrib.buffer, attrib.offset, attrib.type.Value(), vertex_input.SetAttribute(index, true, attrib.buffer, attrib.offset, attrib.type.Value(),
attrib.size.Value()); attrib.size.Value());
} }

View File

@ -741,8 +741,10 @@ private:
if (!IsGenericAttribute(index)) { if (!IsGenericAttribute(index)) {
continue; continue;
} }
const u32 location = GetGenericAttributeLocation(index); const u32 location = GetGenericAttributeLocation(index);
if (!IsAttributeEnabled(location)) {
continue;
}
const auto type_descriptor = GetAttributeType(location); const auto type_descriptor = GetAttributeType(location);
Id type; Id type;
if (IsInputAttributeArray()) { if (IsInputAttributeArray()) {
@ -986,6 +988,10 @@ private:
return stage == ShaderType::TesselationControl; return stage == ShaderType::TesselationControl;
} }
bool IsAttributeEnabled(u32 location) const {
return stage != ShaderType::Vertex || specialization.enabled_attributes[location];
}
u32 GetNumInputVertices() const { u32 GetNumInputVertices() const {
switch (stage) { switch (stage) {
case ShaderType::Geometry: case ShaderType::Geometry:
@ -1201,8 +1207,14 @@ private:
UNIMPLEMENTED_MSG("Unmanaged FrontFacing element={}", element); UNIMPLEMENTED_MSG("Unmanaged FrontFacing element={}", element);
return {v_float_zero, Type::Float}; return {v_float_zero, Type::Float};
default: default:
if (IsGenericAttribute(attribute)) { if (!IsGenericAttribute(attribute)) {
break;
}
const u32 location = GetGenericAttributeLocation(attribute); const u32 location = GetGenericAttributeLocation(attribute);
if (!IsAttributeEnabled(location)) {
// Disabled attributes (also known as constant attributes) always return zero.
return {v_float_zero, Type::Float};
}
const auto type_descriptor = GetAttributeType(location); const auto type_descriptor = GetAttributeType(location);
const Type type = type_descriptor.type; const Type type = type_descriptor.type;
const Id attribute_id = input_attributes.at(attribute); const Id attribute_id = input_attributes.at(attribute);
@ -1210,8 +1222,6 @@ private:
const Id pointer = ArrayPass(type_descriptor.scalar, attribute_id, elements); const Id pointer = ArrayPass(type_descriptor.scalar, attribute_id, elements);
return {OpLoad(GetTypeDefinition(type), pointer), type}; return {OpLoad(GetTypeDefinition(type), pointer), type};
} }
break;
}
UNIMPLEMENTED_MSG("Unhandled input attribute: {}", static_cast<u32>(attribute)); UNIMPLEMENTED_MSG("Unhandled input attribute: {}", static_cast<u32>(attribute));
return {v_float_zero, Type::Float}; return {v_float_zero, Type::Float};
} }

View File

@ -88,7 +88,8 @@ struct Specialization final {
u32 shared_memory_size{}; u32 shared_memory_size{};
// Graphics specific // Graphics specific
std::optional<float> point_size{}; std::optional<float> point_size;
std::bitset<Maxwell::NumVertexAttributes> enabled_attributes;
std::array<Maxwell::VertexAttribute::Type, Maxwell::NumVertexAttributes> attribute_types{}; std::array<Maxwell::VertexAttribute::Type, Maxwell::NumVertexAttributes> attribute_types{};
bool ndc_minus_one_to_one{}; bool ndc_minus_one_to_one{};
}; };