Shaders: Track the register count from the program control register (if available)

This commit is contained in:
Dr. Chat 2016-05-22 19:58:50 -05:00
parent 1faf5a813a
commit d94ff6eb25
3 changed files with 25 additions and 0 deletions

View File

@ -558,6 +558,9 @@ class Shader {
// True if the shader was translated and prepared without error.
bool is_valid() const { return is_valid_; }
// True if the shader has already been translated.
bool is_translated() const { return is_translated_; }
// Errors that occurred during translation.
const std::vector<Error>& errors() const { return errors_; }
@ -602,6 +605,7 @@ class Shader {
bool writes_color_targets_[4] = {false, false, false, false};
bool is_valid_ = false;
bool is_translated_ = false;
std::vector<Error> errors_;
std::string ucode_disassembly_;

View File

@ -51,6 +51,7 @@ void ShaderTranslator::Reset() {
ucode_disasm_buffer_.Reset();
ucode_disasm_line_number_ = 0;
previous_ucode_disasm_scan_offset_ = 0;
register_count_ = 64;
total_attrib_count_ = 0;
vertex_bindings_.clear();
texture_bindings_.clear();
@ -95,9 +96,21 @@ bool ShaderTranslator::GatherAllBindingInformation(Shader* shader) {
return true;
}
bool ShaderTranslator::Translate(Shader* shader,
xenos::xe_gpu_program_cntl_t cntl) {
Reset();
register_count_ = shader->type() == ShaderType::kVertex ? cntl.vs_regs + 1
: cntl.ps_regs + 1;
return TranslateInternal(shader);
}
bool ShaderTranslator::Translate(Shader* shader) {
Reset();
return TranslateInternal(shader);
}
bool ShaderTranslator::TranslateInternal(Shader* shader) {
shader_type_ = shader->type();
ucode_dwords_ = shader->ucode_dwords();
ucode_dword_count_ = shader->ucode_dword_count();
@ -155,6 +168,7 @@ bool ShaderTranslator::Translate(Shader* shader) {
}
shader->is_valid_ = true;
shader->is_translated_ = true;
for (const auto& error : shader->errors_) {
if (error.is_fatal) {
shader->is_valid_ = false;

View File

@ -30,6 +30,7 @@ class ShaderTranslator {
// DEPRECATED(benvanik): remove this when shader cache is removed.
bool GatherAllBindingInformation(Shader* shader);
bool Translate(Shader* shader, xenos::xe_gpu_program_cntl_t cntl);
bool Translate(Shader* shader);
protected:
@ -38,6 +39,8 @@ class ShaderTranslator {
// Resets translator state before beginning translation.
virtual void Reset();
// Register count.
uint32_t register_count() const { return register_count_; }
// True if the current shader is a vertex shader.
bool is_vertex_shader() const { return shader_type_ == ShaderType::kVertex; }
// True if the current shader is a pixel shader.
@ -132,6 +135,8 @@ class ShaderTranslator {
int src_swizzle_component_count;
};
bool TranslateInternal(Shader* shader);
void MarkUcodeInstruction(uint32_t dword_offset);
void AppendUcodeDisasm(char c);
void AppendUcodeDisasm(const char* value);
@ -184,6 +189,8 @@ class ShaderTranslator {
ShaderType shader_type_;
const uint32_t* ucode_dwords_;
size_t ucode_dword_count_;
xenos::xe_gpu_program_cntl_t program_cntl_;
uint32_t register_count_;
// Accumulated translation errors.
std::vector<Shader::Error> errors_;