[GPU] Add color_exp_bias to push constants.
This commit is contained in:
parent
16e33cf123
commit
77b097098d
|
@ -161,7 +161,7 @@ void SpirvShaderTranslator::StartTranslation() {
|
||||||
// Push constants, represented by SpirvPushConstants.
|
// Push constants, represented by SpirvPushConstants.
|
||||||
Id push_constants_type =
|
Id push_constants_type =
|
||||||
b.makeStructType({vec4_float_type_, vec4_float_type_, vec4_float_type_,
|
b.makeStructType({vec4_float_type_, vec4_float_type_, vec4_float_type_,
|
||||||
vec4_float_type_, uint_type_},
|
vec3_float_type_, float_type_, uint_type_},
|
||||||
"push_consts_type");
|
"push_consts_type");
|
||||||
b.addDecoration(push_constants_type, spv::Decoration::DecorationBlock);
|
b.addDecoration(push_constants_type, spv::Decoration::DecorationBlock);
|
||||||
|
|
||||||
|
@ -180,16 +180,21 @@ void SpirvShaderTranslator::StartTranslation() {
|
||||||
push_constants_type, 2, spv::Decoration::DecorationOffset,
|
push_constants_type, 2, spv::Decoration::DecorationOffset,
|
||||||
static_cast<int>(offsetof(SpirvPushConstants, point_size)));
|
static_cast<int>(offsetof(SpirvPushConstants, point_size)));
|
||||||
b.addMemberName(push_constants_type, 2, "point_size");
|
b.addMemberName(push_constants_type, 2, "point_size");
|
||||||
// float4 alpha_test;
|
// float3 alpha_test;
|
||||||
b.addMemberDecoration(
|
b.addMemberDecoration(
|
||||||
push_constants_type, 3, spv::Decoration::DecorationOffset,
|
push_constants_type, 3, spv::Decoration::DecorationOffset,
|
||||||
static_cast<int>(offsetof(SpirvPushConstants, alpha_test)));
|
static_cast<int>(offsetof(SpirvPushConstants, alpha_test)));
|
||||||
b.addMemberName(push_constants_type, 3, "alpha_test");
|
b.addMemberName(push_constants_type, 3, "alpha_test");
|
||||||
// uint ps_param_gen;
|
// float color_exp_bias;
|
||||||
b.addMemberDecoration(
|
b.addMemberDecoration(
|
||||||
push_constants_type, 4, spv::Decoration::DecorationOffset,
|
push_constants_type, 4, spv::Decoration::DecorationOffset,
|
||||||
|
static_cast<int>(offsetof(SpirvPushConstants, color_exp_bias)));
|
||||||
|
b.addMemberName(push_constants_type, 4, "color_exp_bias");
|
||||||
|
// uint ps_param_gen;
|
||||||
|
b.addMemberDecoration(
|
||||||
|
push_constants_type, 5, spv::Decoration::DecorationOffset,
|
||||||
static_cast<int>(offsetof(SpirvPushConstants, ps_param_gen)));
|
static_cast<int>(offsetof(SpirvPushConstants, ps_param_gen)));
|
||||||
b.addMemberName(push_constants_type, 4, "ps_param_gen");
|
b.addMemberName(push_constants_type, 5, "ps_param_gen");
|
||||||
push_consts_ = b.createVariable(spv::StorageClass::StorageClassPushConstant,
|
push_consts_ = b.createVariable(spv::StorageClass::StorageClassPushConstant,
|
||||||
push_constants_type, "push_consts");
|
push_constants_type, "push_consts");
|
||||||
|
|
||||||
|
@ -385,7 +390,7 @@ void SpirvShaderTranslator::StartTranslation() {
|
||||||
// Setup ps_param_gen
|
// Setup ps_param_gen
|
||||||
auto ps_param_gen_idx_ptr = b.createAccessChain(
|
auto ps_param_gen_idx_ptr = b.createAccessChain(
|
||||||
spv::StorageClass::StorageClassPushConstant, push_consts_,
|
spv::StorageClass::StorageClassPushConstant, push_consts_,
|
||||||
std::vector<Id>({b.makeUintConstant(4)}));
|
std::vector<Id>({b.makeUintConstant(5)}));
|
||||||
auto ps_param_gen_idx = b.createLoad(ps_param_gen_idx_ptr);
|
auto ps_param_gen_idx = b.createLoad(ps_param_gen_idx_ptr);
|
||||||
|
|
||||||
auto frag_coord = b.createVariable(spv::StorageClass::StorageClassInput,
|
auto frag_coord = b.createVariable(spv::StorageClass::StorageClassInput,
|
||||||
|
@ -547,7 +552,33 @@ std::vector<uint8_t> SpirvShaderTranslator::CompleteTranslation() {
|
||||||
|
|
||||||
b.createStore(p, pos_);
|
b.createStore(p, pos_);
|
||||||
} else {
|
} else {
|
||||||
|
// Color exponent bias
|
||||||
|
{
|
||||||
|
auto bias_ptr = b.createAccessChain(
|
||||||
|
spv::StorageClass::StorageClassPushConstant, push_consts_,
|
||||||
|
std::vector<Id>({b.makeUintConstant(4)}));
|
||||||
|
auto bias = b.createLoad(bias_ptr);
|
||||||
|
|
||||||
|
auto cond = b.createBinOp(spv::Op::OpFOrdNotEqual, bool_type_, bias,
|
||||||
|
b.makeFloatConstant(0.f));
|
||||||
|
spv::Builder::If bias_if(cond, 0, b);
|
||||||
|
|
||||||
|
auto bias_vector = b.createCompositeConstruct(vec4_float_type_,
|
||||||
|
{bias, bias, bias, bias});
|
||||||
|
|
||||||
|
auto oC0_ptr = b.createAccessChain(
|
||||||
|
spv::StorageClass::StorageClassOutput, frag_outputs_,
|
||||||
|
std::vector<Id>({b.makeUintConstant(0)}));
|
||||||
|
auto oC0_biased = b.createBinOp(spv::Op::OpFMul, vec4_float_type_,
|
||||||
|
b.createLoad(oC0_ptr), bias_vector);
|
||||||
|
|
||||||
|
b.createStore(oC0_biased, oC0_ptr);
|
||||||
|
|
||||||
|
bias_if.makeEndIf();
|
||||||
|
}
|
||||||
|
|
||||||
// Alpha test
|
// Alpha test
|
||||||
|
{
|
||||||
auto alpha_test_ptr = b.createAccessChain(
|
auto alpha_test_ptr = b.createAccessChain(
|
||||||
spv::StorageClass::StorageClassPushConstant, push_consts_,
|
spv::StorageClass::StorageClassPushConstant, push_consts_,
|
||||||
std::vector<Id>({b.makeUintConstant(3)}));
|
std::vector<Id>({b.makeUintConstant(3)}));
|
||||||
|
@ -555,8 +586,10 @@ std::vector<uint8_t> SpirvShaderTranslator::CompleteTranslation() {
|
||||||
|
|
||||||
auto alpha_test_enabled =
|
auto alpha_test_enabled =
|
||||||
b.createCompositeExtract(alpha_test, float_type_, 0);
|
b.createCompositeExtract(alpha_test, float_type_, 0);
|
||||||
auto alpha_test_func = b.createCompositeExtract(alpha_test, float_type_, 1);
|
auto alpha_test_func =
|
||||||
auto alpha_test_ref = b.createCompositeExtract(alpha_test, float_type_, 2);
|
b.createCompositeExtract(alpha_test, float_type_, 1);
|
||||||
|
auto alpha_test_ref =
|
||||||
|
b.createCompositeExtract(alpha_test, float_type_, 2);
|
||||||
|
|
||||||
alpha_test_func =
|
alpha_test_func =
|
||||||
b.createUnaryOp(spv::Op::OpConvertFToU, uint_type_, alpha_test_func);
|
b.createUnaryOp(spv::Op::OpConvertFToU, uint_type_, alpha_test_func);
|
||||||
|
@ -594,8 +627,8 @@ std::vector<uint8_t> SpirvShaderTranslator::CompleteTranslation() {
|
||||||
|
|
||||||
for (int i = 1; i < 7; i++) {
|
for (int i = 1; i < 7; i++) {
|
||||||
b.nextSwitchSegment(switch_segments, i);
|
b.nextSwitchSegment(switch_segments, i);
|
||||||
auto cond =
|
auto cond = b.createBinOp(alpha_op_map[i], bool_type_, oC0_alpha,
|
||||||
b.createBinOp(alpha_op_map[i], bool_type_, oC0_alpha, alpha_test_ref);
|
alpha_test_ref);
|
||||||
spv::Builder::If discard_if(cond, 0, b);
|
spv::Builder::If discard_if(cond, 0, b);
|
||||||
b.makeDiscard();
|
b.makeDiscard();
|
||||||
discard_if.makeEndIf();
|
discard_if.makeEndIf();
|
||||||
|
@ -608,6 +641,7 @@ std::vector<uint8_t> SpirvShaderTranslator::CompleteTranslation() {
|
||||||
|
|
||||||
alpha_if.makeEndIf();
|
alpha_if.makeEndIf();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
b.makeReturn(false);
|
b.makeReturn(false);
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,8 @@ struct SpirvPushConstants {
|
||||||
float point_size[4]; // psx, psy, unused, unused
|
float point_size[4]; // psx, psy, unused, unused
|
||||||
|
|
||||||
// Accessible to fragment shader only:
|
// Accessible to fragment shader only:
|
||||||
float alpha_test[4]; // alpha test enable, func, ref, ?
|
float alpha_test[3]; // alpha test enable, func, ref
|
||||||
|
float color_exp_bias;
|
||||||
uint32_t ps_param_gen;
|
uint32_t ps_param_gen;
|
||||||
};
|
};
|
||||||
static_assert(sizeof(SpirvPushConstants) <= 128,
|
static_assert(sizeof(SpirvPushConstants) <= 128,
|
||||||
|
|
Loading…
Reference in New Issue