Skip to content

Commit

Permalink
D3D12/Vulkan : swizzle texture format G8B8 (#1931)
Browse files Browse the repository at this point in the history
* D3D12: swizzle texture format G8B8

* Vulkan: swizzle texture format G8B8
  • Loading branch information
raven02 committed Jul 18, 2016
1 parent 2e5b01f commit 7ac9d3b
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 8 deletions.
51 changes: 44 additions & 7 deletions rpcs3/Emu/RSX/D3D12/D3D12Texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,12 +286,51 @@ void D3D12GSRender::upload_textures(ID3D12GraphicsCommandList *command_list, siz
break;

case CELL_GCM_TEXTURE_G8B8:
shared_resource_view_desc.Shader4ComponentMapping = D3D12_ENCODE_SHADER_4_COMPONENT_MAPPING(
D3D12_SHADER_COMPONENT_MAPPING_FROM_MEMORY_COMPONENT_1,
D3D12_SHADER_COMPONENT_MAPPING_FROM_MEMORY_COMPONENT_2,
D3D12_SHADER_COMPONENT_MAPPING_FROM_MEMORY_COMPONENT_1,
D3D12_SHADER_COMPONENT_MAPPING_FROM_MEMORY_COMPONENT_2);
{
u8 remap_a = rsx::method_registers.fragment_textures[i].remap() & 0x3;
u8 remap_r = (rsx::method_registers.fragment_textures[i].remap() >> 2) & 0x3;
u8 remap_g = (rsx::method_registers.fragment_textures[i].remap() >> 4) & 0x3;
u8 remap_b = (rsx::method_registers.fragment_textures[i].remap() >> 6) & 0x3;

if (is_render_target)
{
// ARGB format
// Data comes from RTT, stored as RGBA already
const int RemapValue[4] =
{
D3D12_SHADER_COMPONENT_MAPPING_FROM_MEMORY_COMPONENT_1,
D3D12_SHADER_COMPONENT_MAPPING_FROM_MEMORY_COMPONENT_2,
D3D12_SHADER_COMPONENT_MAPPING_FROM_MEMORY_COMPONENT_1,
D3D12_SHADER_COMPONENT_MAPPING_FROM_MEMORY_COMPONENT_2
};

shared_resource_view_desc.Shader4ComponentMapping = D3D12_ENCODE_SHADER_4_COMPONENT_MAPPING(
RemapValue[remap_r],
RemapValue[remap_g],
RemapValue[remap_b],
RemapValue[remap_a]);
}
else
{
// ARGB format
// Data comes from RSX mem, stored as ARGB already
const int RemapValue[4] =
{
D3D12_SHADER_COMPONENT_MAPPING_FROM_MEMORY_COMPONENT_2,
D3D12_SHADER_COMPONENT_MAPPING_FROM_MEMORY_COMPONENT_1,
D3D12_SHADER_COMPONENT_MAPPING_FROM_MEMORY_COMPONENT_2,
D3D12_SHADER_COMPONENT_MAPPING_FROM_MEMORY_COMPONENT_1
};

shared_resource_view_desc.Shader4ComponentMapping = D3D12_ENCODE_SHADER_4_COMPONENT_MAPPING(
RemapValue[remap_r],
RemapValue[remap_g],
RemapValue[remap_b],
RemapValue[remap_a]);
}

break;
}

case CELL_GCM_TEXTURE_R6G5B5: // TODO: Remap it to another format here, so it's not glitched out
shared_resource_view_desc.Shader4ComponentMapping = D3D12_ENCODE_SHADER_4_COMPONENT_MAPPING(
Expand Down Expand Up @@ -338,8 +377,6 @@ void D3D12GSRender::upload_textures(ID3D12GraphicsCommandList *command_list, siz
case CELL_GCM_TEXTURE_A8R8G8B8:
case CELL_GCM_TEXTURE_D8R8G8B8:
{


u8 remap_a = rsx::method_registers.fragment_textures[i].remap() & 0x3;
u8 remap_r = (rsx::method_registers.fragment_textures[i].remap() >> 2) & 0x3;
u8 remap_g = (rsx::method_registers.fragment_textures[i].remap() >> 4) & 0x3;
Expand Down
5 changes: 4 additions & 1 deletion rpcs3/Emu/RSX/VK/VKFormats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,10 @@ VkComponentMapping get_component_mapping(u32 format, u8 swizzle_mask)
return { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_R };

case CELL_GCM_TEXTURE_G8B8:
return { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G };
{
VkComponentSwizzle map_table[] = { VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_R };
return{ map_table[remap_r], map_table[remap_g], map_table[remap_b], map_table[remap_a] };
}

case CELL_GCM_TEXTURE_X16:
return { VK_COMPONENT_SWIZZLE_ONE, VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_ONE, VK_COMPONENT_SWIZZLE_R };
Expand Down

0 comments on commit 7ac9d3b

Please sign in to comment.