Making texture swizzles dynamic. Seems to fix some color swap issues.
And probably exposes many more ;)
This commit is contained in:
@@ -78,8 +78,9 @@ class DrawBatcher {
|
||||
void set_ps_param_gen(int register_index) {
|
||||
active_draw_.header->ps_param_gen = register_index;
|
||||
}
|
||||
void set_texture_sampler(int index, GLuint64 handle) {
|
||||
void set_texture_sampler(int index, GLuint64 handle, uint32_t swizzle) {
|
||||
active_draw_.header->texture_samplers[index] = handle;
|
||||
active_draw_.header->texture_swizzles[index] = swizzle;
|
||||
}
|
||||
void set_index_buffer(const CircularBuffer::Allocation& allocation) {
|
||||
// Offset is used in glDrawElements.
|
||||
@@ -140,6 +141,7 @@ class DrawBatcher {
|
||||
|
||||
// TODO(benvanik): pack tightly
|
||||
GLuint64 texture_samplers[32];
|
||||
GLuint texture_swizzles[32];
|
||||
|
||||
float4 float_consts[512];
|
||||
uint32_t bool_consts[8];
|
||||
|
||||
@@ -408,7 +408,7 @@ void GL4CommandProcessor::PerformSwap(uint32_t frontbuffer_ptr,
|
||||
->blitter()
|
||||
->CopyColorTexture2D(framebuffer_texture, src_rect,
|
||||
static_cast<GLuint>(swap_state_.back_buffer_texture),
|
||||
dest_rect, GL_LINEAR);
|
||||
dest_rect, GL_LINEAR, true);
|
||||
|
||||
if (FLAGS_draw_all_framebuffers) {
|
||||
int32_t offsetx = (1280 - (1280 / 5));
|
||||
@@ -431,7 +431,7 @@ void GL4CommandProcessor::PerformSwap(uint32_t frontbuffer_ptr,
|
||||
->CopyColorTexture2D(
|
||||
tex, src_rect,
|
||||
static_cast<GLuint>(swap_state_.back_buffer_texture), dest_rect,
|
||||
GL_LINEAR);
|
||||
GL_LINEAR, true);
|
||||
|
||||
offsety += 720 / 5;
|
||||
}
|
||||
@@ -455,7 +455,7 @@ void GL4CommandProcessor::PerformSwap(uint32_t frontbuffer_ptr,
|
||||
->CopyColorTexture2D(
|
||||
tex, src_rect,
|
||||
static_cast<GLuint>(swap_state_.back_buffer_texture), dest_rect,
|
||||
GL_LINEAR);
|
||||
GL_LINEAR, false);
|
||||
|
||||
doffsetx += 1280 / 5;
|
||||
}
|
||||
@@ -1485,7 +1485,7 @@ GL4CommandProcessor::UpdateStatus GL4CommandProcessor::PopulateSampler(
|
||||
|
||||
// Reset slot.
|
||||
// If we fail, we still draw but with an invalid texture.
|
||||
draw_batcher_.set_texture_sampler(texture_binding.fetch_constant, 0);
|
||||
draw_batcher_.set_texture_sampler(texture_binding.fetch_constant, 0, 0);
|
||||
|
||||
if (FLAGS_disable_textures) {
|
||||
return UpdateStatus::kCompatible;
|
||||
@@ -1521,7 +1521,8 @@ GL4CommandProcessor::UpdateStatus GL4CommandProcessor::PopulateSampler(
|
||||
|
||||
// Shaders will use bindless to fetch right from it.
|
||||
draw_batcher_.set_texture_sampler(texture_binding.fetch_constant,
|
||||
entry_view->texture_sampler_handle);
|
||||
entry_view->texture_sampler_handle,
|
||||
fetch.swizzle);
|
||||
|
||||
return UpdateStatus::kCompatible;
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ void GL4GraphicsSystem::Swap(xe::ui::UIEvent* e) {
|
||||
static_cast<GLuint>(swap_state.front_buffer_texture),
|
||||
Rect2D(0, 0, swap_state.width, swap_state.height),
|
||||
Rect2D(0, 0, target_window_->width(), target_window_->height()),
|
||||
GL_LINEAR);
|
||||
GL_LINEAR, false);
|
||||
}
|
||||
|
||||
} // namespace gl4
|
||||
|
||||
@@ -473,25 +473,6 @@ TextureCache::TextureEntry* TextureCache::LookupOrInsertTexture(
|
||||
glTextureParameteri(entry->handle, GL_TEXTURE_BASE_LEVEL, 0);
|
||||
glTextureParameteri(entry->handle, GL_TEXTURE_MAX_LEVEL, 1);
|
||||
|
||||
// Pre-shader swizzle.
|
||||
// TODO(benvanik): can this be dynamic? Maybe per view?
|
||||
// We may have to emulate this in the shader.
|
||||
uint32_t swizzle_r = texture_info.swizzle & 0x7;
|
||||
uint32_t swizzle_g = (texture_info.swizzle >> 3) & 0x7;
|
||||
uint32_t swizzle_b = (texture_info.swizzle >> 6) & 0x7;
|
||||
uint32_t swizzle_a = (texture_info.swizzle >> 9) & 0x7;
|
||||
static const GLenum swizzle_map[] = {
|
||||
GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA, GL_ZERO, GL_ONE,
|
||||
};
|
||||
glTextureParameteri(entry->handle, GL_TEXTURE_SWIZZLE_R,
|
||||
swizzle_map[swizzle_r]);
|
||||
glTextureParameteri(entry->handle, GL_TEXTURE_SWIZZLE_G,
|
||||
swizzle_map[swizzle_g]);
|
||||
glTextureParameteri(entry->handle, GL_TEXTURE_SWIZZLE_B,
|
||||
swizzle_map[swizzle_b]);
|
||||
glTextureParameteri(entry->handle, GL_TEXTURE_SWIZZLE_A,
|
||||
swizzle_map[swizzle_a]);
|
||||
|
||||
// Upload/convert.
|
||||
bool uploaded = false;
|
||||
switch (texture_info.dimension) {
|
||||
@@ -590,7 +571,7 @@ GLuint TextureCache::ConvertTexture(Blitter* blitter, uint32_t guest_address,
|
||||
dest_rect);
|
||||
} else {
|
||||
blitter->CopyColorTexture2D(src_texture, src_rect, texture_entry->handle,
|
||||
dest_rect, GL_LINEAR);
|
||||
dest_rect, GL_LINEAR, swap_channels);
|
||||
}
|
||||
|
||||
// HACK: remove texture from write watch list so readback won't kill us.
|
||||
@@ -615,7 +596,7 @@ GLuint TextureCache::ConvertTexture(Blitter* blitter, uint32_t guest_address,
|
||||
dest_rect);
|
||||
} else {
|
||||
blitter->CopyColorTexture2D(src_texture, src_rect, entry->handle,
|
||||
dest_rect, GL_LINEAR);
|
||||
dest_rect, GL_LINEAR, swap_channels);
|
||||
}
|
||||
return entry->handle;
|
||||
}
|
||||
@@ -642,7 +623,7 @@ GLuint TextureCache::ConvertTexture(Blitter* blitter, uint32_t guest_address,
|
||||
blitter->CopyDepthTexture(src_texture, src_rect, entry->handle, dest_rect);
|
||||
} else {
|
||||
blitter->CopyColorTexture2D(src_texture, src_rect, entry->handle, dest_rect,
|
||||
GL_LINEAR);
|
||||
GL_LINEAR, swap_channels);
|
||||
}
|
||||
|
||||
GLuint handle = entry->handle;
|
||||
|
||||
Reference in New Issue
Block a user