Giter Club home page Giter Club logo

Comments (4)

Akaricchi avatar Akaricchi commented on September 13, 2024 1

SDL's Renderer and GPU APIs are completely separate systems, you can't use them together on the same window. The hint you're setting is for the older Vulkan Renderer driver, it has no effect on GPU. For the GPU API, Vulkan validation layers are enabled by passing true to the debug parameter of SDL_CreateGPUDevice(), which is what you are doing.

from sdl.

thatcosmonaut avatar thatcosmonaut commented on September 13, 2024

I just verified that SDL_render_gpu sets debug mode to false by default. I'm going to need to see some code that reproduces this.

from sdl.

hsjunnesson avatar hsjunnesson commented on September 13, 2024

This is how I initialize SDL.

internal void app_init() {
	if (!SDL_Init(SDL_INIT_VIDEO)) {
		log_fatal("%s", SDL_GetError());
	}
	
	SDL_SetLogPriorities(SDL_LOG_PRIORITY_VERBOSE);
	
	// app_state->window
	{
		SDL_WindowFlags flags = SDL_WINDOW_RESIZABLE | SDL_WINDOW_VULKAN;
		
		SDL_SetHint(SDL_HINT_RENDER_VULKAN_DEBUG, "0");
		
		SDL_PropertiesID props = SDL_CreateProperties();
		SDL_SetStringProperty(props, SDL_PROP_WINDOW_CREATE_TITLE_STRING, app_state->title.str);
		SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_WIDTH_NUMBER, (S64)app_state->initial_window_resolution.Width);
		SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_HEIGHT_NUMBER, (S64)app_state->initial_window_resolution.Height);
		SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_FLAGS_NUMBER, flags);
			
		app_state->window = SDL_CreateWindowWithProperties(props);
		SDL_DestroyProperties(props);
			
		// Minimum size
		{
			int min_w = 640;
			F32 ratio = (app_state->initial_window_resolution.Height / app_state->initial_window_resolution.Width);
			int min_h = (int)SDL_ceilf(min_w * ratio);
			SDL_SetWindowMinimumSize(app_state->window, min_w, min_h);
		}
	}
	
	// app_state->renderer
	{
		app_state->renderer = SDL_CreateRenderer(app_state->window, "vulkan");
		if (!app_state->renderer) {
			log_fatal("SDL_CreateRenderer: %s", SDL_GetError());
		}
	}
	
	// app_state->render_state
	{
		app_state->render_state.gpu_device = SDL_CreateGPUDevice(
			SDL_GPU_SHADERFORMAT_SPIRV,
			SDL_TRUE,
			"vulkan"
		);

		if (!app_state->render_state.gpu_device) {
			log_fatal("SDL_CreateGPUDevice: %s", SDL_GetError());
		}

		if (!SDL_ClaimWindowForGPUDevice(app_state->render_state.gpu_device, app_state->window)) {
			log_fatal("SDL_ClaimWindowForGPUDevice: %s", SDL_GetError());
		}
	}
	
	// app_state->render_state.pipeline
	{
		SDL_GPUColorTargetDescription color_target_desc = {
			.format = SDL_GetGPUSwapchainTextureFormat(app_state->render_state.gpu_device, app_state->window),
			.blend_state = {
				.enable_blend = 0,
				.alpha_blend_op = SDL_GPU_BLENDOP_ADD,
				.color_blend_op = SDL_GPU_BLENDOP_ADD,
				.color_write_mask = 0xf,
				.src_alpha_blendfactor = SDL_GPU_BLENDFACTOR_ONE,
				.dst_alpha_blendfactor = SDL_GPU_BLENDFACTOR_ZERO,
				.src_color_blendfactor = SDL_GPU_BLENDFACTOR_ONE,
				.dst_color_blendfactor = SDL_GPU_BLENDFACTOR_ZERO,
			},
		};
		
	    SDL_GPUShader *vertex_shader = NULL;
		
		{
			SDL_GPUShaderCreateInfo create_info = {
				.format = SDL_GPU_SHADERFORMAT_SPIRV,
				.code = (const U8 *)birb_bytecode_vs,
				.code_size = sizeof(birb_bytecode_vs),
				.entrypoint = "main",
				.stage = SDL_GPU_SHADERSTAGE_VERTEX,
			};
			
			vertex_shader = SDL_CreateGPUShader(app_state->render_state.gpu_device, &create_info);
			if (!vertex_shader) {
				log_fatal("SDL_CreateGPUShader vertex shader: %s", SDL_GetError());
			}
		}
		
	    SDL_GPUShader *fragment_shader = NULL;

		{
			SDL_GPUShaderCreateInfo create_info = {
				.num_uniform_buffers = 1,
				.props = 0,
				.format = SDL_GPU_SHADERFORMAT_SPIRV,
				.code = (const U8 *)birb_bytecode_fs,
				.code_size = sizeof(birb_bytecode_fs),
				.entrypoint = "main",
				.stage = SDL_GPU_SHADERSTAGE_FRAGMENT,
			};
			
			fragment_shader = SDL_CreateGPUShader(app_state->render_state.gpu_device, &create_info);
			if (!fragment_shader) {
				log_fatal("SDL_CreateGPUShader fragment shader: %s", SDL_GetError());
			}
		}
		
		SDL_GPUGraphicsPipelineCreateInfo pipeline_desc = {
			.target_info = {
				.num_color_targets = 1,
				.color_target_descriptions = &color_target_desc,
			},
			.multisample_state = {
				.sample_count = 0,
				.sample_mask = 0xf,
			},
			.primitive_type = SDL_GPU_PRIMITIVETYPE_TRIANGLELIST,
			.vertex_shader = vertex_shader,
			.fragment_shader = fragment_shader,
		};
		
		app_state->render_state.pipeline = SDL_CreateGPUGraphicsPipeline(app_state->render_state.gpu_device, &pipeline_desc);
		
		if (!app_state->render_state.pipeline) {
			log_fatal("SDL_CreateGPUGraphicsPipeline: %s", SDL_GetError());
		}
		
		SDL_ReleaseGPUShader(app_state->render_state.gpu_device, vertex_shader);
		SDL_ReleaseGPUShader(app_state->render_state.gpu_device, fragment_shader);
	}
	
	// Default fs params
	{
		app_state->fs_params = (fs_params_t) {
			.resolution = app_state->initial_window_resolution,
			.target_aspect_ratio = app_state->initial_window_resolution.Width / app_state->initial_window_resolution.Height,
			.time = 0.0f,
			.cursor = HMM_V2(0.0f, 0.0f),
			.num_samples = NUM_SAMPLES,
			.frame_count = 0,
			.camera_target = HMM_V3(0.0f, 0.0f, 0.0f),
			.camera_origin = HMM_V3(0.0f, 4.0f, -10.0f),
		};
	}
	
	SDL_ShowWindow(app_state->window);
}

from sdl.

hsjunnesson avatar hsjunnesson commented on September 13, 2024

Excellent explanation, that solved the issue for me. Thanks.

from sdl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.