Shader_IR: Address feedback.
This commit is contained in:
parent
806f569143
commit
bb8eb15d39
10 changed files with 40 additions and 36 deletions
|
@ -33,6 +33,7 @@ private:
|
||||||
// This goes with Vulkan and OpenGL standards but Nvidia GPUs can easily
|
// This goes with Vulkan and OpenGL standards but Nvidia GPUs can easily
|
||||||
// use 4 bytes instead. Thus, certain drivers may squish the size.
|
// use 4 bytes instead. Thus, certain drivers may squish the size.
|
||||||
static constexpr u32 default_texture_handler_size = 8;
|
static constexpr u32 default_texture_handler_size = 8;
|
||||||
|
|
||||||
u32 texture_handler_size = default_texture_handler_size;
|
u32 texture_handler_size = default_texture_handler_size;
|
||||||
bool texture_handler_size_deduced = false;
|
bool texture_handler_size_deduced = false;
|
||||||
};
|
};
|
||||||
|
|
|
@ -505,11 +505,11 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeclareCustomVariables() {
|
void DeclareCustomVariables() {
|
||||||
const u32 cv_num = ir.GetCustomVariablesAmount();
|
const u32 num_custom_variables = ir.GetNumCustomVariables();
|
||||||
for (u32 i = 0; i < cv_num; ++i) {
|
for (u32 i = 0; i < num_custom_variables; ++i) {
|
||||||
code.AddLine("float {} = 0.0f;", GetCustomVariable(i));
|
code.AddLine("float {} = 0.0f;", GetCustomVariable(i));
|
||||||
}
|
}
|
||||||
if (cv_num > 0) {
|
if (num_custom_variables > 0) {
|
||||||
code.AddNewLine();
|
code.AddNewLine();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -589,8 +589,8 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeclareCustomVariables() {
|
void DeclareCustomVariables() {
|
||||||
const u32 cv_num = ir.GetCustomVariablesAmount();
|
const u32 num_custom_variables = ir.GetNumCustomVariables();
|
||||||
for (u32 i = 0; i < cv_num; ++i) {
|
for (u32 i = 0; i < num_custom_variables; ++i) {
|
||||||
const Id id = OpVariable(t_prv_float, spv::StorageClass::Private, v_float_zero);
|
const Id id = OpVariable(t_prv_float, spv::StorageClass::Private, v_float_zero);
|
||||||
Name(id, fmt::format("custom_var_{}", i));
|
Name(id, fmt::format("custom_var_{}", i));
|
||||||
custom_variables.emplace(i, AddGlobalVariable(id));
|
custom_variables.emplace(i, AddGlobalVariable(id));
|
||||||
|
@ -1363,6 +1363,7 @@ private:
|
||||||
|
|
||||||
} else if (const auto cv = std::get_if<CustomVarNode>(&*dest)) {
|
} else if (const auto cv = std::get_if<CustomVarNode>(&*dest)) {
|
||||||
target = {custom_variables.at(cv->GetIndex()), Type::Float};
|
target = {custom_variables.at(cv->GetIndex()), Type::Float};
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
UNIMPLEMENTED();
|
UNIMPLEMENTED();
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,10 +77,12 @@ public:
|
||||||
return bindless_samplers;
|
return bindless_samplers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Gets bound buffer used on this shader
|
||||||
u32 GetBoundBuffer() const {
|
u32 GetBoundBuffer() const {
|
||||||
return bound_buffer;
|
return bound_buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Obtains access to the guest driver's profile.
|
||||||
VideoCore::GuestDriverProfile* AccessGuestDriverProfile() const {
|
VideoCore::GuestDriverProfile* AccessGuestDriverProfile() const {
|
||||||
if (engine) {
|
if (engine) {
|
||||||
return &engine->AccessGuestDriverProfile();
|
return &engine->AccessGuestDriverProfile();
|
||||||
|
|
|
@ -35,9 +35,9 @@ constexpr bool IsSchedInstruction(u32 offset, u32 main_offset) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeduceTextureHandlerSize(VideoCore::GuestDriverProfile* gpu_driver,
|
void DeduceTextureHandlerSize(VideoCore::GuestDriverProfile* gpu_driver,
|
||||||
std::list<Sampler>& used_samplers) {
|
const std::list<Sampler>& used_samplers) {
|
||||||
if (gpu_driver == nullptr) {
|
if (gpu_driver == nullptr) {
|
||||||
LOG_CRITICAL(HW_GPU, "GPU Driver profile has not been created yet");
|
LOG_CRITICAL(HW_GPU, "GPU driver profile has not been created yet");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (gpu_driver->TextureHandlerSizeKnown() || used_samplers.size() <= 1) {
|
if (gpu_driver->TextureHandlerSizeKnown() || used_samplers.size() <= 1) {
|
||||||
|
@ -57,9 +57,9 @@ void DeduceTextureHandlerSize(VideoCore::GuestDriverProfile* gpu_driver,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<u32> TryDeduceSamplerSize(Sampler& sampler_to_deduce,
|
std::optional<u32> TryDeduceSamplerSize(const Sampler& sampler_to_deduce,
|
||||||
VideoCore::GuestDriverProfile* gpu_driver,
|
VideoCore::GuestDriverProfile* gpu_driver,
|
||||||
std::list<Sampler>& used_samplers) {
|
const std::list<Sampler>& used_samplers) {
|
||||||
if (gpu_driver == nullptr) {
|
if (gpu_driver == nullptr) {
|
||||||
LOG_CRITICAL(HW_GPU, "GPU Driver profile has not been created yet");
|
LOG_CRITICAL(HW_GPU, "GPU Driver profile has not been created yet");
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
|
@ -367,19 +367,20 @@ void ShaderIR::PostDecode() {
|
||||||
auto gpu_driver = locker.AccessGuestDriverProfile();
|
auto gpu_driver = locker.AccessGuestDriverProfile();
|
||||||
DeduceTextureHandlerSize(gpu_driver, used_samplers);
|
DeduceTextureHandlerSize(gpu_driver, used_samplers);
|
||||||
// Deduce Indexed Samplers
|
// Deduce Indexed Samplers
|
||||||
if (uses_indexed_samplers) {
|
if (!uses_indexed_samplers) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
for (auto& sampler : used_samplers) {
|
for (auto& sampler : used_samplers) {
|
||||||
if (sampler.IsIndexed()) {
|
if (!sampler.IsIndexed()) {
|
||||||
auto size = TryDeduceSamplerSize(sampler, gpu_driver, used_samplers);
|
continue;
|
||||||
if (size) {
|
}
|
||||||
|
if (const auto size = TryDeduceSamplerSize(sampler, gpu_driver, used_samplers)) {
|
||||||
sampler.SetSize(*size);
|
sampler.SetSize(*size);
|
||||||
} else {
|
} else {
|
||||||
LOG_CRITICAL(HW_GPU, "Failed to deduce size of indexed sampler");
|
LOG_CRITICAL(HW_GPU, "Failed to deduce size of indexed sampler");
|
||||||
sampler.SetSize(1);
|
sampler.SetSize(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace VideoCommon::Shader
|
} // namespace VideoCommon::Shader
|
||||||
|
|
|
@ -201,7 +201,8 @@ u32 ShaderIR::DecodeTexture(NodeBlock& bb, u32 pc) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (u32 element = 0; element < values.size(); ++element) {
|
for (u32 element = 0; element < values.size(); ++element) {
|
||||||
MetaTexture meta{*sampler, array_node, {}, {}, {}, derivates, {}, {}, {}, element, index_var};
|
MetaTexture meta{*sampler, array_node, {}, {}, {}, derivates,
|
||||||
|
{}, {}, {}, element, index_var};
|
||||||
values[element] = Operation(OperationCode::TextureGradient, std::move(meta), coords);
|
values[element] = Operation(OperationCode::TextureGradient, std::move(meta), coords);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -291,7 +291,7 @@ public:
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetSize(u32 new_size) {
|
constexpr void SetSize(u32 new_size) {
|
||||||
size = new_size;
|
size = new_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -315,15 +315,15 @@ public:
|
||||||
explicit ArraySamplerNode(u32 index, u32 base_offset, u32 bindless_var)
|
explicit ArraySamplerNode(u32 index, u32 base_offset, u32 bindless_var)
|
||||||
: index{index}, base_offset{base_offset}, bindless_var{bindless_var} {}
|
: index{index}, base_offset{base_offset}, bindless_var{bindless_var} {}
|
||||||
|
|
||||||
u32 GetIndex() const {
|
constexpr u32 GetIndex() const {
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 GetBaseOffset() const {
|
constexpr u32 GetBaseOffset() const {
|
||||||
return base_offset;
|
return base_offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 GetIndexVar() const {
|
constexpr u32 GetIndexVar() const {
|
||||||
return bindless_var;
|
return bindless_var;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -338,11 +338,11 @@ class BindlessSamplerNode final {
|
||||||
public:
|
public:
|
||||||
explicit BindlessSamplerNode(u32 index, u32 offset) : index{index}, offset{offset} {}
|
explicit BindlessSamplerNode(u32 index, u32 offset) : index{index}, offset{offset} {}
|
||||||
|
|
||||||
u32 GetIndex() const {
|
constexpr u32 GetIndex() const {
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 GetOffset() const {
|
constexpr u32 GetOffset() const {
|
||||||
return offset;
|
return offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -557,7 +557,7 @@ class CustomVarNode final {
|
||||||
public:
|
public:
|
||||||
explicit constexpr CustomVarNode(u32 index) : index{index} {}
|
explicit constexpr CustomVarNode(u32 index) : index{index} {}
|
||||||
|
|
||||||
u32 GetIndex() const {
|
constexpr u32 GetIndex() const {
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -458,8 +458,7 @@ std::size_t ShaderIR::DeclareAmend(Node new_amend) {
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 ShaderIR::NewCustomVariable() {
|
u32 ShaderIR::NewCustomVariable() {
|
||||||
const u32 id = num_custom_variables++;
|
return num_custom_variables++;
|
||||||
return id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace VideoCommon::Shader
|
} // namespace VideoCommon::Shader
|
||||||
|
|
|
@ -180,7 +180,7 @@ public:
|
||||||
return amend_code[index];
|
return amend_code[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 GetCustomVariablesAmount() const {
|
u32 GetNumCustomVariables() const {
|
||||||
return num_custom_variables;
|
return num_custom_variables;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,6 @@ std::pair<Node, s64> FindOperation(const NodeBlock& code, s64 cursor,
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
} // Anonymous namespace
|
|
||||||
|
|
||||||
std::optional<std::pair<Node, Node>> DecoupleIndirectRead(const OperationNode& operation) {
|
std::optional<std::pair<Node, Node>> DecoupleIndirectRead(const OperationNode& operation) {
|
||||||
if (operation.GetCode() != OperationCode::UAdd) {
|
if (operation.GetCode() != OperationCode::UAdd) {
|
||||||
|
@ -44,9 +43,7 @@ std::optional<std::pair<Node, Node>> DecoupleIndirectRead(const OperationNode& o
|
||||||
}
|
}
|
||||||
Node gpr{};
|
Node gpr{};
|
||||||
Node offset{};
|
Node offset{};
|
||||||
if (operation.GetOperandsCount() != 2) {
|
ASSERT(operation.GetOperandsCount() == 2);
|
||||||
return std::nullopt;
|
|
||||||
}
|
|
||||||
for (std::size_t i = 0; i < operation.GetOperandsCount(); i++) {
|
for (std::size_t i = 0; i < operation.GetOperandsCount(); i++) {
|
||||||
Node operand = operation[i];
|
Node operand = operation[i];
|
||||||
if (std::holds_alternative<ImmediateNode>(*operand)) {
|
if (std::holds_alternative<ImmediateNode>(*operand)) {
|
||||||
|
@ -56,7 +53,7 @@ std::optional<std::pair<Node, Node>> DecoupleIndirectRead(const OperationNode& o
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (offset && gpr) {
|
if (offset && gpr) {
|
||||||
return {std::make_pair(gpr, offset)};
|
return std::make_pair(gpr, offset);
|
||||||
}
|
}
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
@ -72,6 +69,8 @@ bool AmendNodeCv(std::size_t amend_index, Node node) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // Anonymous namespace
|
||||||
|
|
||||||
std::tuple<Node, TrackSampler> ShaderIR::TrackBindlessSampler(Node tracked, const NodeBlock& code,
|
std::tuple<Node, TrackSampler> ShaderIR::TrackBindlessSampler(Node tracked, const NodeBlock& code,
|
||||||
s64 cursor) {
|
s64 cursor) {
|
||||||
if (const auto cbuf = std::get_if<CbufNode>(&*tracked)) {
|
if (const auto cbuf = std::get_if<CbufNode>(&*tracked)) {
|
||||||
|
|
Loading…
Reference in a new issue