Merge pull request #524 from DrChat/depth_clear_fix

Fix Depth Clear / few shader fixes
This commit is contained in:
Ben Vanik 2016-01-22 17:01:24 -08:00
commit fa2ad7e445
2 changed files with 41 additions and 25 deletions

View File

@ -1625,16 +1625,22 @@ bool GL4CommandProcessor::IssueCopy() {
color_targets[copy_src_select] = GetColorRenderTarget( color_targets[copy_src_select] = GetColorRenderTarget(
surface_pitch, surface_msaa, color_base, color_format); surface_pitch, surface_msaa, color_base, color_format);
src_format = ColorRenderTargetToTextureFormat(color_format); src_format = ColorRenderTargetToTextureFormat(color_format);
} else { }
// Source from depth/stencil.
// Grab the depth/stencil if we're sourcing from it or clear is enabled.
if (copy_src_select > 3 || depth_clear_enabled) {
uint32_t depth_info = regs[XE_GPU_REG_RB_DEPTH_INFO].u32; uint32_t depth_info = regs[XE_GPU_REG_RB_DEPTH_INFO].u32;
uint32_t depth_base = depth_info & 0xFFF; uint32_t depth_base = depth_info & 0xFFF;
auto depth_format = auto depth_format =
static_cast<DepthRenderTargetFormat>((depth_info >> 16) & 0x1); static_cast<DepthRenderTargetFormat>((depth_info >> 16) & 0x1);
depth_target = GetDepthRenderTarget(surface_pitch, surface_msaa, depth_base, depth_target = GetDepthRenderTarget(surface_pitch, surface_msaa, depth_base,
depth_format); depth_format);
src_format = DepthRenderTargetToTextureFormat(depth_format);
if (copy_src_select > 3) {
src_format = DepthRenderTargetToTextureFormat(depth_format);
}
} }
auto source_framebuffer = GetFramebuffer(color_targets, depth_target); auto source_framebuffer = GetFramebuffer(color_targets, depth_target);
if (!source_framebuffer) { if (!source_framebuffer) {
// If we get here we are likely missing some state checks. // If we get here we are likely missing some state checks.
@ -1910,10 +1916,7 @@ bool GL4CommandProcessor::IssueCopy() {
old_color_mask[2], old_color_mask[3]); old_color_mask[2], old_color_mask[3]);
} }
// TODO(benvanik): figure out real condition here (maybe when color cleared?) if (depth_clear_enabled && depth_target != kAnyTarget) {
// HACK: things seem to need their depth buffer cleared a lot more
// than as indicated by the depth_clear_enabled flag.
if (depth_target != kAnyTarget) {
// Clear the current depth buffer. // Clear the current depth buffer.
// TODO(benvanik): verify format. // TODO(benvanik): verify format.
GLfloat depth = {(copy_depth_clear & 0xFFFFFF00) / GLfloat depth = {(copy_depth_clear & 0xFFFFFF00) /
@ -1928,6 +1931,7 @@ bool GL4CommandProcessor::IssueCopy() {
glDepthMask(GL_TRUE); glDepthMask(GL_TRUE);
glStencilMask(0xFF); glStencilMask(0xFF);
// HACK: this should work, but throws INVALID_ENUM on nvidia drivers. // HACK: this should work, but throws INVALID_ENUM on nvidia drivers.
// GLEW signature differs from OpenGL docs?
// glClearNamedFramebufferfi(source_framebuffer->framebuffer, // glClearNamedFramebufferfi(source_framebuffer->framebuffer,
// GL_DEPTH_STENCIL, depth, stencil); // GL_DEPTH_STENCIL, depth, stencil);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, source_framebuffer->framebuffer); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, source_framebuffer->framebuffer);

View File

@ -209,18 +209,18 @@ vec3 get_10_11_11_s(const int data_in) {
vec4 get_2_10_10_10_u(const uint data_in) { vec4 get_2_10_10_10_u(const uint data_in) {
vec4 vec; vec4 vec;
vec.x = bitfieldExtract(data_in, 0, 10); vec.w = bitfieldExtract(data_in, 0, 2 );
vec.y = bitfieldExtract(data_in, 10, 10); vec.x = bitfieldExtract(data_in, 2, 10);
vec.z = bitfieldExtract(data_in, 20, 10); vec.y = bitfieldExtract(data_in, 12, 10);
vec.w = bitfieldExtract(data_in, 30, 2 ); vec.z = bitfieldExtract(data_in, 22, 10);
return vec; return vec;
} }
vec4 get_2_10_10_10_s(const int data_in) { vec4 get_2_10_10_10_s(const int data_in) {
vec4 vec; vec4 vec;
vec.x = bitfieldExtract(data_in, 0, 10); vec.w = bitfieldExtract(data_in, 0, 2 );
vec.y = bitfieldExtract(data_in, 10, 10); vec.x = bitfieldExtract(data_in, 2, 10);
vec.z = bitfieldExtract(data_in, 20, 10); vec.y = bitfieldExtract(data_in, 12, 10);
vec.w = bitfieldExtract(data_in, 30, 2 ); vec.z = bitfieldExtract(data_in, 22, 10);
return vec; return vec;
} }
@ -326,6 +326,7 @@ void main() {
// Temporary registers. // Temporary registers.
if (is_vertex_shader()) { if (is_vertex_shader()) {
EmitSource(" vec4 r[64];\n"); EmitSource(" vec4 r[64];\n");
EmitSource(" r[0].x = gl_VertexID;\n");
} else { } else {
// Bring interpolators from vertex shader into temporary registers. // Bring interpolators from vertex shader into temporary registers.
EmitSource(" vec4 r[64];\n"); EmitSource(" vec4 r[64];\n");
@ -571,14 +572,6 @@ void GlslShaderTranslator::ProcessVertexFetchInstruction(
EmitSource("// "); EmitSource("// ");
instr.Disassemble(&source_); instr.Disassemble(&source_);
if (instr.operands[0].storage_index != 0) {
// Unimplemented for now.
EmitUnimplementedTranslationError();
EmitSourceDepth("pv.xyzw = vec4(0.0, 0.0, 0.0, 0.0);\n");
EmitStoreVectorResult(instr.result);
return;
}
if (instr.is_predicated) { if (instr.is_predicated) {
EmitSourceDepth("if (%cp0) {\n", instr.predicate_condition ? ' ' : '!'); EmitSourceDepth("if (%cp0) {\n", instr.predicate_condition ? ' ' : '!');
Indent(); Indent();
@ -594,6 +587,9 @@ void GlslShaderTranslator::ProcessVertexFetchInstruction(
switch (instr.opcode) { switch (instr.opcode) {
case FetchOpcode::kVertexFetch: { case FetchOpcode::kVertexFetch: {
EmitSourceDepth("if (src0.x == gl_VertexID) {\n");
Indent();
EmitSourceDepth("pv."); EmitSourceDepth("pv.");
for (int i = 0; for (int i = 0;
i < GetVertexFormatComponentCount(instr.attributes.data_format); i < GetVertexFormatComponentCount(instr.attributes.data_format);
@ -615,6 +611,16 @@ void GlslShaderTranslator::ProcessVertexFetchInstruction(
EmitSource(" = vf%u_%d;\n", instr.operands[1].storage_index, EmitSource(" = vf%u_%d;\n", instr.operands[1].storage_index,
instr.attributes.offset); instr.attributes.offset);
} }
Unindent();
EmitSourceDepth("} else {\n");
Indent();
EmitSourceDepth("// UNIMPLEMENTED: Indexed fetch.\n");
EmitSourceDepth("pv = vec4(0.0, 0.0, 0.0, 1.0);\n");
Unindent();
EmitSourceDepth("}\n");
} break; } break;
default: default:
assert_always(); assert_always();
@ -918,7 +924,10 @@ void GlslShaderTranslator::EmitStoreResult(const InstructionResult& result,
EmitSource("clamp("); EmitSource("clamp(");
} }
if (has_const_writes) { if (has_const_writes) {
EmitSource("vec%d(", component_write_count); if (component_write_count > 1) {
EmitSource("vec%d(", component_write_count);
}
bool has_written = false; bool has_written = false;
for (int j = 0; j < 4; ++j) { for (int j = 0; j < 4; ++j) {
if (result.write_mask[j]) { if (result.write_mask[j]) {
@ -939,7 +948,10 @@ void GlslShaderTranslator::EmitStoreResult(const InstructionResult& result,
} }
} }
} }
EmitSource(")");
if (component_write_count > 1) {
EmitSource(")");
}
} else { } else {
EmitSource(temp); EmitSource(temp);
if (!result.is_standard_swizzle()) { if (!result.is_standard_swizzle()) {