diff options
| -rw-r--r-- | src/video_core/engines/maxwell_3d.h | 1 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer.cpp | 9 | ||||
| -rw-r--r-- | src/video_core/texture_cache/surface_params.cpp | 105 | ||||
| -rw-r--r-- | src/video_core/texture_cache/surface_params.h | 6 | ||||
| -rw-r--r-- | src/video_core/texture_cache/texture_cache.h | 17 |
5 files changed, 106 insertions, 32 deletions
diff --git a/src/video_core/engines/maxwell_3d.h b/src/video_core/engines/maxwell_3d.h index 0184342a0..3b3c82f41 100644 --- a/src/video_core/engines/maxwell_3d.h +++ b/src/video_core/engines/maxwell_3d.h | |||
| @@ -62,6 +62,7 @@ public: | |||
| 62 | static constexpr std::size_t NumVertexAttributes = 32; | 62 | static constexpr std::size_t NumVertexAttributes = 32; |
| 63 | static constexpr std::size_t NumVaryings = 31; | 63 | static constexpr std::size_t NumVaryings = 31; |
| 64 | static constexpr std::size_t NumTextureSamplers = 32; | 64 | static constexpr std::size_t NumTextureSamplers = 32; |
| 65 | static constexpr std::size_t NumImages = 8; // TODO(Rodrigo): Investigate this number | ||
| 65 | static constexpr std::size_t NumClipDistances = 8; | 66 | static constexpr std::size_t NumClipDistances = 8; |
| 66 | static constexpr std::size_t MaxShaderProgram = 6; | 67 | static constexpr std::size_t MaxShaderProgram = 6; |
| 67 | static constexpr std::size_t MaxShaderStage = 5; | 68 | static constexpr std::size_t MaxShaderStage = 5; |
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index 8a59b86e3..6636b3c74 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp | |||
| @@ -1022,7 +1022,7 @@ bool RasterizerOpenGL::SetupTexture(const Shader& shader, u32 binding, | |||
| 1022 | auto& unit{state.texture_units[binding]}; | 1022 | auto& unit{state.texture_units[binding]}; |
| 1023 | unit.sampler = sampler_cache.GetSampler(texture.tsc); | 1023 | unit.sampler = sampler_cache.GetSampler(texture.tsc); |
| 1024 | 1024 | ||
| 1025 | const auto view = texture_cache.GetImageSurface(texture.tic, entry); | 1025 | const auto view = texture_cache.GetTextureSurface(texture.tic, entry); |
| 1026 | if (!view) { | 1026 | if (!view) { |
| 1027 | // Can occur when texture addr is null or its memory is unmapped/invalid | 1027 | // Can occur when texture addr is null or its memory is unmapped/invalid |
| 1028 | unit.texture = 0; | 1028 | unit.texture = 0; |
| @@ -1054,7 +1054,12 @@ void RasterizerOpenGL::SetupComputeImages(const Shader& shader) { | |||
| 1054 | tex_handle.raw = compute.AccessConstBuffer32(cbuf.first, cbuf.second); | 1054 | tex_handle.raw = compute.AccessConstBuffer32(cbuf.first, cbuf.second); |
| 1055 | return compute.GetTextureInfo(tex_handle, entry.GetOffset()); | 1055 | return compute.GetTextureInfo(tex_handle, entry.GetOffset()); |
| 1056 | }(); | 1056 | }(); |
| 1057 | UNIMPLEMENTED(); | 1057 | const auto view = texture_cache.GetImageSurface(texture.tic, entry); |
| 1058 | if (!view) { | ||
| 1059 | state.images[bindpoint] = 0; | ||
| 1060 | continue; | ||
| 1061 | } | ||
| 1062 | state.images[bindpoint] = view->GetTexture(); | ||
| 1058 | } | 1063 | } |
| 1059 | } | 1064 | } |
| 1060 | 1065 | ||
diff --git a/src/video_core/texture_cache/surface_params.cpp b/src/video_core/texture_cache/surface_params.cpp index 2f8bd399c..1e4d3fb79 100644 --- a/src/video_core/texture_cache/surface_params.cpp +++ b/src/video_core/texture_cache/surface_params.cpp | |||
| @@ -24,45 +24,53 @@ using VideoCore::Surface::SurfaceTarget; | |||
| 24 | using VideoCore::Surface::SurfaceTargetFromTextureType; | 24 | using VideoCore::Surface::SurfaceTargetFromTextureType; |
| 25 | using VideoCore::Surface::SurfaceType; | 25 | using VideoCore::Surface::SurfaceType; |
| 26 | 26 | ||
| 27 | SurfaceTarget TextureType2SurfaceTarget(Tegra::Shader::TextureType type, bool is_array) { | 27 | namespace { |
| 28 | |||
| 29 | SurfaceTarget TextureTypeToSurfaceTarget(Tegra::Shader::TextureType type, bool is_array) { | ||
| 28 | switch (type) { | 30 | switch (type) { |
| 29 | case Tegra::Shader::TextureType::Texture1D: { | 31 | case Tegra::Shader::TextureType::Texture1D: |
| 30 | if (is_array) | 32 | return is_array ? SurfaceTarget::Texture1DArray : SurfaceTarget::Texture1D; |
| 31 | return SurfaceTarget::Texture1DArray; | 33 | case Tegra::Shader::TextureType::Texture2D: |
| 32 | else | 34 | return is_array ? SurfaceTarget::Texture2DArray : SurfaceTarget::Texture2D; |
| 33 | return SurfaceTarget::Texture1D; | 35 | case Tegra::Shader::TextureType::Texture3D: |
| 34 | } | ||
| 35 | case Tegra::Shader::TextureType::Texture2D: { | ||
| 36 | if (is_array) | ||
| 37 | return SurfaceTarget::Texture2DArray; | ||
| 38 | else | ||
| 39 | return SurfaceTarget::Texture2D; | ||
| 40 | } | ||
| 41 | case Tegra::Shader::TextureType::Texture3D: { | ||
| 42 | ASSERT(!is_array); | 36 | ASSERT(!is_array); |
| 43 | return SurfaceTarget::Texture3D; | 37 | return SurfaceTarget::Texture3D; |
| 44 | } | 38 | case Tegra::Shader::TextureType::TextureCube: |
| 45 | case Tegra::Shader::TextureType::TextureCube: { | 39 | return is_array ? SurfaceTarget::TextureCubeArray : SurfaceTarget::TextureCubemap; |
| 46 | if (is_array) | 40 | default: |
| 47 | return SurfaceTarget::TextureCubeArray; | ||
| 48 | else | ||
| 49 | return SurfaceTarget::TextureCubemap; | ||
| 50 | } | ||
| 51 | default: { | ||
| 52 | UNREACHABLE(); | 41 | UNREACHABLE(); |
| 53 | return SurfaceTarget::Texture2D; | 42 | return SurfaceTarget::Texture2D; |
| 54 | } | 43 | } |
| 44 | } | ||
| 45 | |||
| 46 | SurfaceTarget ImageTypeToSurfaceTarget(Tegra::Shader::ImageType type) { | ||
| 47 | switch (type) { | ||
| 48 | case Tegra::Shader::ImageType::Texture1D: | ||
| 49 | return SurfaceTarget::Texture1D; | ||
| 50 | case Tegra::Shader::ImageType::TextureBuffer: | ||
| 51 | return SurfaceTarget::TextureBuffer; | ||
| 52 | case Tegra::Shader::ImageType::Texture1DArray: | ||
| 53 | return SurfaceTarget::Texture1DArray; | ||
| 54 | case Tegra::Shader::ImageType::Texture2D: | ||
| 55 | return SurfaceTarget::Texture2D; | ||
| 56 | case Tegra::Shader::ImageType::Texture2DArray: | ||
| 57 | return SurfaceTarget::Texture2DArray; | ||
| 58 | case Tegra::Shader::ImageType::Texture3D: | ||
| 59 | return SurfaceTarget::Texture3D; | ||
| 60 | default: | ||
| 61 | UNREACHABLE(); | ||
| 62 | return SurfaceTarget::Texture2D; | ||
| 55 | } | 63 | } |
| 56 | } | 64 | } |
| 57 | 65 | ||
| 58 | namespace { | ||
| 59 | constexpr u32 GetMipmapSize(bool uncompressed, u32 mip_size, u32 tile) { | 66 | constexpr u32 GetMipmapSize(bool uncompressed, u32 mip_size, u32 tile) { |
| 60 | return uncompressed ? mip_size : std::max(1U, (mip_size + tile - 1) / tile); | 67 | return uncompressed ? mip_size : std::max(1U, (mip_size + tile - 1) / tile); |
| 61 | } | 68 | } |
| 69 | |||
| 62 | } // Anonymous namespace | 70 | } // Anonymous namespace |
| 63 | 71 | ||
| 64 | SurfaceParams SurfaceParams::CreateForImage(const Tegra::Texture::TICEntry& tic, | 72 | SurfaceParams SurfaceParams::CreateForTexture(const Tegra::Texture::TICEntry& tic, |
| 65 | const VideoCommon::Shader::Sampler& entry) { | 73 | const VideoCommon::Shader::Sampler& entry) { |
| 66 | SurfaceParams params; | 74 | SurfaceParams params; |
| 67 | params.is_tiled = tic.IsTiled(); | 75 | params.is_tiled = tic.IsTiled(); |
| 68 | params.srgb_conversion = tic.IsSrgbConversionEnabled(); | 76 | params.srgb_conversion = tic.IsSrgbConversionEnabled(); |
| @@ -94,8 +102,17 @@ SurfaceParams SurfaceParams::CreateForImage(const Tegra::Texture::TICEntry& tic, | |||
| 94 | params.component_type = ComponentTypeFromTexture(tic.r_type.Value()); | 102 | params.component_type = ComponentTypeFromTexture(tic.r_type.Value()); |
| 95 | params.type = GetFormatType(params.pixel_format); | 103 | params.type = GetFormatType(params.pixel_format); |
| 96 | // TODO: on 1DBuffer we should use the tic info. | 104 | // TODO: on 1DBuffer we should use the tic info. |
| 97 | if (!tic.IsBuffer()) { | 105 | if (tic.IsBuffer()) { |
| 98 | params.target = TextureType2SurfaceTarget(entry.GetType(), entry.IsArray()); | 106 | params.target = SurfaceTarget::TextureBuffer; |
| 107 | params.width = tic.Width(); | ||
| 108 | params.pitch = params.width * params.GetBytesPerPixel(); | ||
| 109 | params.height = 1; | ||
| 110 | params.depth = 1; | ||
| 111 | params.num_levels = 1; | ||
| 112 | params.emulated_levels = 1; | ||
| 113 | params.is_layered = false; | ||
| 114 | } else { | ||
| 115 | params.target = TextureTypeToSurfaceTarget(entry.GetType(), entry.IsArray()); | ||
| 99 | params.width = tic.Width(); | 116 | params.width = tic.Width(); |
| 100 | params.height = tic.Height(); | 117 | params.height = tic.Height(); |
| 101 | params.depth = tic.Depth(); | 118 | params.depth = tic.Depth(); |
| @@ -107,7 +124,27 @@ SurfaceParams SurfaceParams::CreateForImage(const Tegra::Texture::TICEntry& tic, | |||
| 107 | params.num_levels = tic.max_mip_level + 1; | 124 | params.num_levels = tic.max_mip_level + 1; |
| 108 | params.emulated_levels = std::min(params.num_levels, params.MaxPossibleMipmap()); | 125 | params.emulated_levels = std::min(params.num_levels, params.MaxPossibleMipmap()); |
| 109 | params.is_layered = params.IsLayered(); | 126 | params.is_layered = params.IsLayered(); |
| 110 | } else { | 127 | } |
| 128 | return params; | ||
| 129 | } | ||
| 130 | |||
| 131 | SurfaceParams SurfaceParams::CreateForImage(const Tegra::Texture::TICEntry& tic, | ||
| 132 | const VideoCommon::Shader::Image& entry) { | ||
| 133 | SurfaceParams params; | ||
| 134 | params.is_tiled = tic.IsTiled(); | ||
| 135 | params.srgb_conversion = tic.IsSrgbConversionEnabled(); | ||
| 136 | params.block_width = params.is_tiled ? tic.BlockWidth() : 0, | ||
| 137 | params.block_height = params.is_tiled ? tic.BlockHeight() : 0, | ||
| 138 | params.block_depth = params.is_tiled ? tic.BlockDepth() : 0, | ||
| 139 | params.tile_width_spacing = params.is_tiled ? (1 << tic.tile_width_spacing.Value()) : 1; | ||
| 140 | params.pixel_format = | ||
| 141 | PixelFormatFromTextureFormat(tic.format, tic.r_type.Value(), params.srgb_conversion); | ||
| 142 | params.type = GetFormatType(params.pixel_format); | ||
| 143 | params.component_type = ComponentTypeFromTexture(tic.r_type.Value()); | ||
| 144 | params.type = GetFormatType(params.pixel_format); | ||
| 145 | params.target = ImageTypeToSurfaceTarget(entry.GetType()); | ||
| 146 | // TODO: on 1DBuffer we should use the tic info. | ||
| 147 | if (tic.IsBuffer()) { | ||
| 111 | params.target = SurfaceTarget::TextureBuffer; | 148 | params.target = SurfaceTarget::TextureBuffer; |
| 112 | params.width = tic.Width(); | 149 | params.width = tic.Width(); |
| 113 | params.pitch = params.width * params.GetBytesPerPixel(); | 150 | params.pitch = params.width * params.GetBytesPerPixel(); |
| @@ -116,6 +153,18 @@ SurfaceParams SurfaceParams::CreateForImage(const Tegra::Texture::TICEntry& tic, | |||
| 116 | params.num_levels = 1; | 153 | params.num_levels = 1; |
| 117 | params.emulated_levels = 1; | 154 | params.emulated_levels = 1; |
| 118 | params.is_layered = false; | 155 | params.is_layered = false; |
| 156 | } else { | ||
| 157 | params.width = tic.Width(); | ||
| 158 | params.height = tic.Height(); | ||
| 159 | params.depth = tic.Depth(); | ||
| 160 | params.pitch = params.is_tiled ? 0 : tic.Pitch(); | ||
| 161 | if (params.target == SurfaceTarget::TextureCubemap || | ||
| 162 | params.target == SurfaceTarget::TextureCubeArray) { | ||
| 163 | params.depth *= 6; | ||
| 164 | } | ||
| 165 | params.num_levels = tic.max_mip_level + 1; | ||
| 166 | params.emulated_levels = std::min(params.num_levels, params.MaxPossibleMipmap()); | ||
| 167 | params.is_layered = params.IsLayered(); | ||
| 119 | } | 168 | } |
| 120 | return params; | 169 | return params; |
| 121 | } | 170 | } |
diff --git a/src/video_core/texture_cache/surface_params.h b/src/video_core/texture_cache/surface_params.h index ee2efa594..1011a4d8e 100644 --- a/src/video_core/texture_cache/surface_params.h +++ b/src/video_core/texture_cache/surface_params.h | |||
| @@ -23,8 +23,12 @@ using VideoCore::Surface::SurfaceCompression; | |||
| 23 | class SurfaceParams { | 23 | class SurfaceParams { |
| 24 | public: | 24 | public: |
| 25 | /// Creates SurfaceCachedParams from a texture configuration. | 25 | /// Creates SurfaceCachedParams from a texture configuration. |
| 26 | static SurfaceParams CreateForTexture(const Tegra::Texture::TICEntry& tic, | ||
| 27 | const VideoCommon::Shader::Sampler& entry); | ||
| 28 | |||
| 29 | /// Creates SurfaceCachedParams from an image configuration. | ||
| 26 | static SurfaceParams CreateForImage(const Tegra::Texture::TICEntry& tic, | 30 | static SurfaceParams CreateForImage(const Tegra::Texture::TICEntry& tic, |
| 27 | const VideoCommon::Shader::Sampler& entry); | 31 | const VideoCommon::Shader::Image& entry); |
| 28 | 32 | ||
| 29 | /// Creates SurfaceCachedParams for a depth buffer configuration. | 33 | /// Creates SurfaceCachedParams for a depth buffer configuration. |
| 30 | static SurfaceParams CreateForDepthBuffer( | 34 | static SurfaceParams CreateForDepthBuffer( |
diff --git a/src/video_core/texture_cache/texture_cache.h b/src/video_core/texture_cache/texture_cache.h index 623cce068..877c6635d 100644 --- a/src/video_core/texture_cache/texture_cache.h +++ b/src/video_core/texture_cache/texture_cache.h | |||
| @@ -89,8 +89,23 @@ public: | |||
| 89 | } | 89 | } |
| 90 | } | 90 | } |
| 91 | 91 | ||
| 92 | TView GetTextureSurface(const Tegra::Texture::TICEntry& tic, | ||
| 93 | const VideoCommon::Shader::Sampler& entry) { | ||
| 94 | std::lock_guard lock{mutex}; | ||
| 95 | const auto gpu_addr{tic.Address()}; | ||
| 96 | if (!gpu_addr) { | ||
| 97 | return {}; | ||
| 98 | } | ||
| 99 | const auto params{SurfaceParams::CreateForTexture(tic, entry)}; | ||
| 100 | const auto [surface, view] = GetSurface(gpu_addr, params, true, false); | ||
| 101 | if (guard_samplers) { | ||
| 102 | sampled_textures.push_back(surface); | ||
| 103 | } | ||
| 104 | return view; | ||
| 105 | } | ||
| 106 | |||
| 92 | TView GetImageSurface(const Tegra::Texture::TICEntry& tic, | 107 | TView GetImageSurface(const Tegra::Texture::TICEntry& tic, |
| 93 | const VideoCommon::Shader::Sampler& entry) { | 108 | const VideoCommon::Shader::Image& entry) { |
| 94 | std::lock_guard lock{mutex}; | 109 | std::lock_guard lock{mutex}; |
| 95 | const auto gpu_addr{tic.Address()}; | 110 | const auto gpu_addr{tic.Address()}; |
| 96 | if (!gpu_addr) { | 111 | if (!gpu_addr) { |