Skip to content

Commit

Permalink
shader/translator: Add null spir-v check guards.
Browse files Browse the repository at this point in the history
format: run clang-format.
  • Loading branch information
Zangetsu38 committed Jun 8, 2019
1 parent 46bed0e commit 6142543
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/emulator/gxm/include/gxm/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct SceGxmTexture {
uint32_t vaddr_mode : 3;
uint32_t uaddr_mode : 3;
uint32_t mip_filter : 1;
uint32_t min_filter: 2;
uint32_t min_filter : 2;
uint32_t mag_filter : 2;
uint32_t unk1 : 3;
uint32_t mip_count : 4;
Expand Down
2 changes: 1 addition & 1 deletion src/emulator/host/src/host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include <unordered_set>

#ifdef NDEBUG // Leave it as non-constexpr on Debug so that we can enable/disable it at will via set_log_import_calls
constexpr
constexpr
#endif
bool LOG_IMPORT_CALLS
= false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

#include <glutil/object_array.h>

#include <psp2/gxm.h>
#include <gxm/types.h>
#include <psp2/gxm.h>

#include <array>

Expand Down
23 changes: 23 additions & 0 deletions src/emulator/shader/src/translator/alu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ bool USSETranslatorVisitor::vmad(
spv::Id vsrc2 = load(inst.opr.src2, write_mask, 0);

if (vsrc0 == spv::NoResult || vsrc1 == spv::NoResult || vsrc2 == spv::NoResult) {
LOG_ERROR("Source not loaded (vsrc0: {}, vsr1: {}, vsrc2: {})", vsrc0, vsrc1, vsrc2);
return false;
}

Expand Down Expand Up @@ -251,6 +252,7 @@ bool USSETranslatorVisitor::vmad2(
spv::Id vsrc2 = load(inst.opr.src2, dest_mask, 0);

if (vsrc0 == spv::NoResult || vsrc1 == spv::NoResult || vsrc2 == spv::NoResult) {
LOG_ERROR("Source not loaded (vsrc0: {}, vsr1: {}, vsrc2: {})", vsrc0, vsrc1, vsrc2);
return false;
}

Expand Down Expand Up @@ -352,6 +354,11 @@ bool USSETranslatorVisitor::vdp(
spv::Id lhs = load(inst.opr.src0, type == 1 ? 0b0111 : 0b1111, 0);
spv::Id rhs = load(inst.opr.src1, type == 1 ? 0b0111 : 0b1111, src1_repeat_offset);

if (lhs == spv::NoResult || rhs == spv::NoResult) {
LOG_ERROR("Source not loaded (lhs: {}, rhs: {})", lhs, rhs);
return false;
}

spv::Id result = m_b.createBinOp(spv::OpDot, type_f32, lhs, rhs);

store(inst.opr.dest, result, write_mask, dest_repeat_offset);
Expand Down Expand Up @@ -650,6 +657,11 @@ bool USSETranslatorVisitor::vbw(
spv::Id src1 = load(inst.opr.src1, 0b0001);
spv::Id src2 = 0;

if (src1 == spv::NoResult) {
LOG_ERROR("Source not loaded");
return false;
}

bool immediate = src2_ext && inst.opr.src2.bank == RegisterBank::IMMEDIATE;
uint32_t value = 0;

Expand All @@ -662,6 +674,12 @@ bool USSETranslatorVisitor::vbw(
src2 = m_b.makeUintConstant(src2_invert ? ~value : value);
} else {
src2 = load(inst.opr.src2, 0b0001);

if (src2 == spv::NoResult) {
LOG_ERROR("Source 2 not loaded");
return false;
}

if (src2_invert) {
src2 = m_b.createUnaryOp(spv::Op::OpNot, type_ui32, src2);
}
Expand Down Expand Up @@ -788,6 +806,11 @@ bool USSETranslatorVisitor::vcomp(
GET_REPEAT(inst);
spv::Id result = load(inst.opr.src1, src_mask, src1_repeat_offset);

if (result == spv::NoResult) {
LOG_ERROR("Result not loaded");
return false;
}

switch (op) {
case Opcode::VRCP: {
// We have to manually divide by 1
Expand Down
10 changes: 10 additions & 0 deletions src/emulator/shader/src/translator/branch_cond.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,11 @@ bool USSETranslatorVisitor::vtst(
}
}

if (lhs == spv::NoResult || rhs == spv::NoResult) {
LOG_ERROR("Source not loaded (lhs: {}, rhs: {})", lhs, rhs);
return false;
}

pred_result = m_b.createOp(used_comp_op, m_b.makeBoolType(), { lhs, rhs });

Operand pred_op{};
Expand Down Expand Up @@ -381,6 +386,11 @@ bool USSETranslatorVisitor::br(

pred_v = load(pred_opr, 0b0001);

if (pred_v == spv::NoResult) {
LOG_ERROR("Pred not loaded");
return false;
}

if (do_neg) {
std::vector<spv::Id> ops{ pred_v };
pred_v = m_b.createOp(spv::OpLogicalNot, m_b.makeBoolType(), ops);
Expand Down
21 changes: 21 additions & 0 deletions src/emulator/shader/src/translator/data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,11 @@ bool USSETranslatorVisitor::vmov(
spv::Id src0 = load(inst.opr.src0, dest_mask, src0_repeat_offset);
spv::Id src2 = load(inst.opr.src2, dest_mask, src2_repeat_offset);

if (src0 == spv::NoResult || src2 == spv::NoResult) {
LOG_ERROR("Source not loaded (src0: {}, src2: {})", src0, src2);
return false;
}

conditional_result = m_b.createBinOp(compare_op, m_b.makeVectorType(m_b.makeBoolType(), m_b.getNumComponents(src0)),
src2, src0);

Expand All @@ -199,6 +204,12 @@ bool USSETranslatorVisitor::vmov(
}

spv::Id source = load(inst.opr.src1, dest_mask, src1_repeat_offset);

if (source == spv::NoResult) {
LOG_ERROR("Source not Loaded");
return false;
}

store(inst.opr.dest, source, dest_mask, dest_repeat_offset);

if (is_conditional) {
Expand Down Expand Up @@ -490,10 +501,20 @@ bool USSETranslatorVisitor::vpck(

spv::Id source = load(inst.opr.src1, src1_mask, src1_repeat_offset);

if (source == spv::NoResult) {
LOG_ERROR("Source not loaded");
return false;
}

if (src2_mask != 0) {
// Need to load this also, then create a merge between these twos
spv::Id source2 = load(inst.opr.src2, src2_mask, src2_repeat_offset);

if (source2 == spv::NoResult) {
LOG_ERROR("Source 2 not loaded");
return false;
}

// Merge using op vector shuffle
const int num_comp = static_cast<int>(dest_mask_to_comp_count(dest_mask));

Expand Down
5 changes: 5 additions & 0 deletions src/emulator/shader/src/translator/texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ bool USSETranslatorVisitor::smp(
// Load the coord
const spv::Id coord = load(inst.opr.src0, 0b0011);

if (coord == spv::NoResult) {
LOG_ERROR("Coord not loaded");
return false;
}

spv::Id sampler = spv::NoResult;
if (m_spirv_params.samplers.count(inst.opr.src1.num)) {
sampler = m_spirv_params.samplers.at(inst.opr.src1.num);
Expand Down
2 changes: 1 addition & 1 deletion src/emulator/shader/src/usse_utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ spv::Id shader::usse::utils::load(spv::Builder &b, const SpirvShaderParameters &
if (first_pass == spv::NoResult) {
return first_pass;
}

if (size_comp != 4) {
// Second pass: Do unpack
// We already handle shift offset above, so now let's use 0
Expand Down

0 comments on commit 6142543

Please sign in to comment.