metal: fix gpu hang during envmap filtering
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
|
||||
#[set(everything)]
|
||||
const constants: {
|
||||
params: float4; // level, constants.params.y
|
||||
params: float4; // level, samples, alpha, pass
|
||||
};
|
||||
|
||||
#[set(everything)]
|
||||
@@ -65,13 +65,13 @@ fun cos_weighted_hemisphere_direction(n: float3, co: float2, seed: float): float
|
||||
}
|
||||
|
||||
fun prefilter_envmap_frag(input: vert_out): float4 {
|
||||
var color: float4 = float4(0.0, 0.0, 0.0, 1.0);
|
||||
var color: float4 = float4(0.0, 0.0, 0.0, constants.params.z);
|
||||
var n: float3 = reverse_equirect(input.tex);
|
||||
|
||||
//for (var i: int = 0; i < int(constants.params.y); i += 1) {
|
||||
var i: int = 0;
|
||||
while (i < int(constants.params.y)) {
|
||||
var dir: float3 = normalize(lerp3(n, cos_weighted_hemisphere_direction(n, input.tex, float(i)), constants.params.x));
|
||||
var dir: float3 = normalize(lerp3(n, cos_weighted_hemisphere_direction(n, input.tex, float(i + constants.params.w * constants.params.y)), constants.params.x));
|
||||
var sampled: float3 = sample(radiance, sampler_linear, equirect(dir)).rgb;
|
||||
sampled = min3(sampled, float3(10.0, 10.0, 10.0));
|
||||
color.rgb = color.rgb + sampled;
|
||||
|
||||
@@ -14,6 +14,8 @@ function import_envmap_run(path: string, image: gpu_texture_t) {
|
||||
import_envmap_pipeline = gpu_create_pipeline();
|
||||
import_envmap_pipeline.vertex_shader = sys_get_shader("prefilter_envmap.vert");
|
||||
import_envmap_pipeline.fragment_shader = sys_get_shader("prefilter_envmap.frag");
|
||||
import_envmap_pipeline.blend_source = gpu_blend_t.SOURCE_ALPHA;
|
||||
import_envmap_pipeline.blend_destination = gpu_blend_t.ONE;
|
||||
let vs: gpu_vertex_structure_t = {};
|
||||
gpu_vertex_struct_add(vs, "pos", gpu_vertex_data_t.F32_2X);
|
||||
import_envmap_pipeline.input_layout = vs;
|
||||
@@ -68,22 +70,29 @@ function import_envmap_run(path: string, image: gpu_texture_t) {
|
||||
}
|
||||
|
||||
function import_envmap_get_radiance_mip(mip: gpu_texture_t, level: i32, radiance: gpu_texture_t) {
|
||||
_gpu_begin(mip);
|
||||
/// if arm_metal
|
||||
let pass_count: i32 = 8; // 32;
|
||||
import_envmap_params.y = 512;
|
||||
/// else
|
||||
let pass_count: i32 = 1;
|
||||
import_envmap_params.y = 1024 * 16;
|
||||
/// end
|
||||
import_envmap_params.z = 1.0 / pass_count;
|
||||
import_envmap_params.x = (level + 1) / 10;
|
||||
|
||||
for (let i: i32 = 0; i < pass_count; ++i) {
|
||||
_gpu_begin(mip, null, null, i == 0 ? gpu_clear_t.COLOR : gpu_clear_t.NONE, 0x00000000);
|
||||
gpu_set_vertex_buffer(const_data_screen_aligned_vb);
|
||||
gpu_set_index_buffer(const_data_screen_aligned_ib);
|
||||
gpu_set_pipeline(import_envmap_pipeline);
|
||||
import_envmap_params.x = (level + 1) / 10;
|
||||
/// if (arm_macos || arm_ios)
|
||||
import_envmap_params.y = 1024 * 2; // Prevent gpu hang
|
||||
/// else
|
||||
import_envmap_params.y = 1024 * 16;
|
||||
/// end
|
||||
import_envmap_params.w = i;
|
||||
gpu_set_float4(import_envmap_params_loc, import_envmap_params.x, import_envmap_params.y, import_envmap_params.z, import_envmap_params.w);
|
||||
gpu_set_texture(import_envmap_radiance_loc, radiance);
|
||||
let noise: gpu_texture_t = data_get_image("bnoise256.k");
|
||||
gpu_set_texture(import_envmap_noise_loc, noise);
|
||||
gpu_draw();
|
||||
gpu_end();
|
||||
}
|
||||
}
|
||||
|
||||
function import_envmap_reverse_equirect(x: f32, y: f32): vec4_t {
|
||||
|
||||
Reference in New Issue
Block a user