shader: Implement indexed Position and ClipDistances

This commit is contained in:
FernandoS27 2021-04-04 09:38:15 +02:00 committed by ameerj
parent 1d51803169
commit 73cb17f41b
3 changed files with 100 additions and 11 deletions

View File

@ -327,6 +327,10 @@ void EmitContext::DefineAttributeMemAccess(const Info& info) {
const Id compare_index{OpShiftRightLogical(U32[1], base_index, Constant(U32[1], 2U))};
std::vector<Sirit::Literal> literals;
std::vector<Id> labels;
if (info.loads_position) {
literals.push_back(static_cast<u32>(IR::Attribute::PositionX) >> 2);
labels.push_back(OpLabel());
}
const u32 base_attribute_value = static_cast<u32>(IR::Attribute::Generic0X) >> 2;
for (u32 i = 0; i < info.input_generics.size(); i++) {
if (!info.input_generics[i].used) {
@ -340,6 +344,12 @@ void EmitContext::DefineAttributeMemAccess(const Info& info) {
AddLabel(default_label);
OpReturnValue(Constant(F32[1], 0.0f));
size_t label_index = 0;
if (info.loads_position) {
AddLabel(labels[label_index]);
const Id result{OpLoad(F32[1], OpAccessChain(input_f32, input_position, masked_index))};
OpReturnValue(result);
label_index++;
}
for (u32 i = 0; i < info.input_generics.size(); i++) {
if (!info.input_generics[i].used) {
continue;
@ -377,6 +387,10 @@ void EmitContext::DefineAttributeMemAccess(const Info& info) {
const Id compare_index{OpShiftRightLogical(U32[1], base_index, Constant(U32[1], 2U))};
std::vector<Sirit::Literal> literals;
std::vector<Id> labels;
if (info.stores_position) {
literals.push_back(static_cast<u32>(IR::Attribute::PositionX) >> 2);
labels.push_back(OpLabel());
}
const u32 base_attribute_value = static_cast<u32>(IR::Attribute::Generic0X) >> 2;
for (u32 i = 0; i < info.stores_generics.size(); i++) {
if (!info.stores_generics[i]) {
@ -385,11 +399,24 @@ void EmitContext::DefineAttributeMemAccess(const Info& info) {
literals.push_back(base_attribute_value + i);
labels.push_back(OpLabel());
}
if (info.stores_clip_distance) {
literals.push_back(static_cast<u32>(IR::Attribute::ClipDistance0) >> 2);
labels.push_back(OpLabel());
literals.push_back(static_cast<u32>(IR::Attribute::ClipDistance4) >> 2);
labels.push_back(OpLabel());
}
OpSelectionMerge(end_block, spv::SelectionControlMask::MaskNone);
OpSwitch(compare_index, default_label, literals, labels);
AddLabel(default_label);
OpReturn();
size_t label_index = 0;
if (info.stores_position) {
AddLabel(labels[label_index]);
const Id pointer{OpAccessChain(output_f32, output_position, masked_index)};
OpStore(pointer, store_value);
OpReturn();
label_index++;
}
for (u32 i = 0; i < info.stores_generics.size(); i++) {
if (!info.stores_generics[i]) {
continue;
@ -401,6 +428,19 @@ void EmitContext::DefineAttributeMemAccess(const Info& info) {
OpReturn();
label_index++;
}
if (info.stores_clip_distance) {
AddLabel(labels[label_index]);
const Id pointer{OpAccessChain(output_f32, clip_distances, masked_index)};
OpStore(pointer, store_value);
OpReturn();
label_index++;
AddLabel(labels[label_index]);
const Id fixed_index{OpIAdd(U32[1], masked_index, Constant(U32[1], 4))};
const Id pointer2{OpAccessChain(output_f32, clip_distances, fixed_index)};
OpStore(pointer2, store_value);
OpReturn();
label_index++;
}
AddLabel(end_block);
OpUnreachable();
OpFunctionEnd();

View File

@ -517,22 +517,32 @@ void GatherInfoFromHeader(Environment& env, Info& info) {
}
const auto& header = env.SPH();
if (stage == Stage::Fragment) {
if (!info.loads_indexed_attributes) {
return;
}
for (size_t i = 0; i < info.input_generics.size(); i++) {
info.input_generics[i].used =
info.input_generics[i].used || header.ps.IsGenericVectorActive(i);
}
info.loads_position = info.loads_position || header.ps.imap_systemb.position != 0;
return;
}
for (size_t i = 0; i < info.input_generics.size(); i++) {
info.input_generics[i].used =
info.input_generics[i].used || header.vtg.IsInputGenericVectorActive(i);
if (info.loads_indexed_attributes) {
for (size_t i = 0; i < info.input_generics.size(); i++) {
info.input_generics[i].used =
info.input_generics[i].used || header.vtg.IsInputGenericVectorActive(i);
}
}
for (size_t i = 0; i < info.stores_generics.size(); i++) {
info.stores_generics[i] =
info.stores_generics[i] || header.vtg.IsOutputGenericVectorActive(i);
if (info.stores_indexed_attributes) {
info.loads_position = info.loads_position || header.vtg.imap_systemb.position != 0;
for (size_t i = 0; i < info.stores_generics.size(); i++) {
info.stores_generics[i] =
info.stores_generics[i] || header.vtg.IsOutputGenericVectorActive(i);
}
info.stores_clip_distance =
info.stores_clip_distance || header.vtg.omap_systemc.clip_distances != 0;
info.stores_position = info.stores_position || header.vtg.omap_systemb.position != 0;
}
info.stores_clip_distance =
info.stores_clip_distance || header.vtg.omap_systemc.clip_distances != 0;
}
} // Anonymous namespace

View File

@ -69,7 +69,20 @@ struct ProgramHeader {
union {
struct {
INSERT_PADDING_BYTES_NOINIT(3); // ImapSystemValuesA
INSERT_PADDING_BYTES_NOINIT(1); // ImapSystemValuesB
union {
BitField<0, 1, u8> primitive_array_id;
BitField<1, 1, u8> rt_array_index;
BitField<2, 1, u8> viewport_index;
BitField<3, 1, u8> point_size;
BitField<4, 1, u8> position_x;
BitField<5, 1, u8> position_y;
BitField<6, 1, u8> position_z;
BitField<7, 1, u8> position_w;
BitField<0, 4, u8> first;
BitField<4, 4, u8> position;
u8 raw;
} imap_systemb;
union {
BitField<0, 1, u8> x;
@ -99,7 +112,20 @@ struct ProgramHeader {
INSERT_PADDING_BYTES_NOINIT(5); // ImapFixedFncTexture[10]
INSERT_PADDING_BYTES_NOINIT(1); // ImapReserved
INSERT_PADDING_BYTES_NOINIT(3); // OmapSystemValuesA
INSERT_PADDING_BYTES_NOINIT(1); // OmapSystemValuesB
union {
BitField<0, 1, u8> primitive_array_id;
BitField<1, 1, u8> rt_array_index;
BitField<2, 1, u8> viewport_index;
BitField<3, 1, u8> point_size;
BitField<4, 1, u8> position_x;
BitField<5, 1, u8> position_y;
BitField<6, 1, u8> position_z;
BitField<7, 1, u8> position_w;
BitField<0, 4, u8> first;
BitField<4, 4, u8> position;
u8 raw;
} omap_systemb;
union {
BitField<0, 1, u8> x;
@ -148,7 +174,20 @@ struct ProgramHeader {
struct {
INSERT_PADDING_BYTES_NOINIT(3); // ImapSystemValuesA
INSERT_PADDING_BYTES_NOINIT(1); // ImapSystemValuesB
union {
BitField<0, 1, u8> primitive_array_id;
BitField<1, 1, u8> rt_array_index;
BitField<2, 1, u8> viewport_index;
BitField<3, 1, u8> point_size;
BitField<4, 1, u8> position_x;
BitField<5, 1, u8> position_y;
BitField<6, 1, u8> position_z;
BitField<7, 1, u8> position_w;
BitField<0, 4, u8> first;
BitField<4, 4, u8> position;
u8 raw;
} imap_systemb;
union {
BitField<0, 2, PixelImap> x;